@shopify/cli-kit 3.57.1 → 3.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/private/node/session/exchange.js +7 -2
- package/dist/private/node/session/exchange.js.map +1 -1
- package/dist/private/node/ui/components/SelectInput.js +1 -3
- package/dist/private/node/ui/components/SelectInput.js.map +1 -1
- package/dist/public/common/array.d.ts +7 -0
- package/dist/public/common/array.js +11 -4
- package/dist/public/common/array.js.map +1 -1
- package/dist/public/common/collection.js +3 -5
- package/dist/public/common/collection.js.map +1 -1
- package/dist/public/common/function.js +3 -5
- package/dist/public/common/function.js.map +1 -1
- package/dist/public/common/lang.js +1 -3
- package/dist/public/common/lang.js.map +1 -1
- package/dist/public/common/object.d.ts +8 -1
- package/dist/public/common/object.js +19 -13
- package/dist/public/common/object.js.map +1 -1
- package/dist/public/common/version.d.ts +1 -1
- package/dist/public/common/version.js +1 -1
- package/dist/public/common/version.js.map +1 -1
- package/dist/public/node/api/shopify-developers.d.ts +18 -0
- package/dist/public/node/api/shopify-developers.js +52 -0
- package/dist/public/node/api/shopify-developers.js.map +1 -0
- package/dist/public/node/base-command.d.ts +1 -0
- package/dist/public/node/base-command.js +5 -0
- package/dist/public/node/base-command.js.map +1 -1
- package/dist/public/node/cli.js +7 -1
- package/dist/public/node/cli.js.map +1 -1
- package/dist/public/node/context/fqdn.d.ts +6 -0
- package/dist/public/node/context/fqdn.js +17 -0
- package/dist/public/node/context/fqdn.js.map +1 -1
- package/dist/public/node/context/spin.d.ts +13 -0
- package/dist/public/node/context/spin.js +42 -1
- package/dist/public/node/context/spin.js.map +1 -1
- package/dist/public/node/custom-oclif-loader.d.ts +6 -0
- package/dist/public/node/custom-oclif-loader.js +54 -0
- package/dist/public/node/custom-oclif-loader.js.map +1 -0
- package/dist/public/node/dot-env.d.ts +1 -0
- package/dist/public/node/dot-env.js +51 -9
- package/dist/public/node/dot-env.js.map +1 -1
- package/dist/public/node/error-handler.js +4 -1
- package/dist/public/node/error-handler.js.map +1 -1
- package/dist/public/node/fs.d.ts +11 -0
- package/dist/public/node/fs.js +11 -0
- package/dist/public/node/fs.js.map +1 -1
- package/dist/public/node/is-global.d.ts +8 -0
- package/dist/public/node/is-global.js +12 -0
- package/dist/public/node/is-global.js.map +1 -0
- package/dist/public/node/node-package-manager.js +2 -2
- package/dist/public/node/node-package-manager.js.map +1 -1
- package/dist/public/node/output.js +4 -0
- package/dist/public/node/output.js.map +1 -1
- package/dist/public/node/ruby.js +5 -5
- package/dist/public/node/ruby.js.map +1 -1
- package/dist/public/node/themes/api.d.ts +3 -3
- package/dist/public/node/themes/api.js +1 -4
- package/dist/public/node/themes/api.js.map +1 -1
- package/dist/public/node/themes/factories.d.ts +8 -5
- package/dist/public/node/themes/factories.js +16 -9
- package/dist/public/node/themes/factories.js.map +1 -1
- package/dist/public/node/themes/theme-manager.d.ts +2 -1
- package/dist/public/node/themes/theme-manager.js +3 -3
- package/dist/public/node/themes/theme-manager.js.map +1 -1
- package/dist/public/node/themes/types.d.ts +15 -11
- package/dist/public/node/themes/types.js +5 -1
- package/dist/public/node/themes/types.js.map +1 -1
- package/dist/public/node/themes/utils.d.ts +3 -0
- package/dist/public/node/themes/utils.js +2 -0
- package/dist/public/node/themes/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -2
- package/dist/private/node/error-handler.d.ts +0 -2
- package/dist/private/node/error-handler.js +0 -5
- package/dist/private/node/error-handler.js.map +0 -1
- package/dist/private/node/semver.d.ts +0 -3
- package/dist/private/node/semver.js +0 -6
- package/dist/private/node/semver.js.map +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Command } from '@oclif/core';
|
|
2
2
|
import { FlagOutput, Input, ParserOutput, ArgOutput } from '@oclif/core/lib/interfaces/parser.js';
|
|
3
3
|
declare abstract class BaseCommand extends Command {
|
|
4
|
+
static descriptionWithoutMarkdown(): string | undefined;
|
|
4
5
|
static analyticsNameOverride(): string | undefined;
|
|
5
6
|
static analyticsStopCommand(): string | undefined;
|
|
6
7
|
catch(error: Error & {
|
|
@@ -11,6 +11,11 @@ import { isTruthy } from './context/utilities.js';
|
|
|
11
11
|
import { underscore } from '../common/string.js';
|
|
12
12
|
import { Command, Errors } from '@oclif/core';
|
|
13
13
|
class BaseCommand extends Command {
|
|
14
|
+
// Replace markdown links to plain text like: "link label" (url)
|
|
15
|
+
static descriptionWithoutMarkdown() {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
return (this.descriptionWithMarkdown ?? '').replace(/(\[)(.*?)(])(\()(.*?)(\))/gm, '"$2" ($5)');
|
|
18
|
+
}
|
|
14
19
|
static analyticsNameOverride() {
|
|
15
20
|
return undefined;
|
|
16
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-command.js","sourceRoot":"","sources":["../../../src/public/node/base-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,2CAA2C,EAAC,MAAM,oBAAoB,CAAA;AAC5F,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAA;AACrC,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,SAAS,CAAA;AACjD,OAAO,EAAC,aAAa,EAAE,UAAU,EAAE,WAAW,EAAC,MAAM,aAAa,CAAA;AAClE,OAAO,EAAC,uBAAuB,EAAC,MAAM,aAAa,CAAA;AACnD,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAA;AACtC,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAA;AAE/C,OAAO,EAAC,UAAU,EAAC,MAAM,qBAAqB,CAAA;AAC9C,OAAO,EAAC,OAAO,EAAE,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AAI,UAAU,CAClB,aAAa,CAAA,0EAA0E,WAAW,CAAC,MAAM,CACvG,KAAK,CACN,YAAY,CACd,CAAA;iBACF;aACF;iBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBAC/B,KAAK,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAA;aAClE;iBAAM;gBACL,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,CAAC,CAAA;aACpC;SACF;KACF;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,eAAe,WAAW,CAAA","sourcesContent":["import {errorHandler, registerCleanBugsnagErrorsFromWithinPlugins} from './error-handler.js'\nimport {loadEnvironment} from './environments.js'\nimport {isDevelopment} from './context/local.js'\nimport {addPublicMetadata} from './metadata.js'\nimport {AbortError} from './error.js'\nimport {renderInfo, renderWarning} from './ui.js'\nimport {outputContent, outputInfo, outputToken} from './output.js'\nimport {terminalSupportsRawMode} from './system.js'\nimport {hashString} from './crypto.js'\nimport {isTruthy} from './context/utilities.js'\nimport {JsonMap} from '../../private/common/json.js'\nimport {underscore} from '../common/string.js'\nimport {Command, Errors} from '@oclif/core'\nimport {FlagOutput, Input, ParserOutput, FlagInput, ArgOutput} from '@oclif/core/lib/interfaces/parser.js'\n\ninterface EnvironmentFlags {\n environment?: string\n path?: string\n}\n\nabstract class BaseCommand extends Command {\n public static analyticsNameOverride(): string | undefined {\n return undefined\n }\n\n public static analyticsStopCommand(): string | undefined {\n return undefined\n }\n\n async catch(error: Error & {exitCode?: number | undefined}): Promise<void> {\n await errorHandler(error, this.config)\n return Errors.handle(error)\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected async init(): Promise<any> {\n this.exitWithTimestampWhenEnvVariablePresent()\n if (!isDevelopment()) {\n // This function runs just prior to `run`\n await registerCleanBugsnagErrorsFromWithinPlugins(this.config)\n }\n this.showNpmFlagWarning()\n return super.init()\n }\n\n // NPM creates an environment variable for every flag passed to a script.\n // This function checks for the presence of any of the available CLI flags\n // and warns the user to use the `--` separator.\n protected showNpmFlagWarning(): void {\n const commandVariables = this.constructor as unknown as {flags: JsonMap}\n const commandFlags = Object.keys(commandVariables.flags || {})\n const possibleNpmEnvVars = commandFlags.map((key) => `npm_config_${underscore(key).replace(/^no_/, '')}`)\n\n if (possibleNpmEnvVars.some((flag) => process.env[flag] !== undefined)) {\n renderWarning({\n body: [\n 'NPM scripts require an extra',\n {command: '--'},\n 'separator to pass the flags. Example:',\n {command: 'npm run dev -- --reset'},\n ],\n })\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n protected exitWithTimestampWhenEnvVariablePresent() {\n if (isTruthy(process.env.SHOPIFY_CLI_ENV_STARTUP_PERFORMANCE_RUN)) {\n outputInfo(`\n SHOPIFY_CLI_TIMESTAMP_START\n { \"timestamp\": ${Date.now()} }\n SHOPIFY_CLI_TIMESTAMP_END\n `)\n process.exit(0)\n }\n }\n\n protected async parse<\n TFlags extends FlagOutput & {path?: string; verbose?: boolean},\n TGlobalFlags extends FlagOutput,\n TArgs extends ArgOutput,\n >(\n options?: Input<TFlags, TGlobalFlags, TArgs>,\n argv?: string[],\n ): Promise<ParserOutput<TFlags, TGlobalFlags, TArgs> & {argv: string[]}> {\n let result = await super.parse<TFlags, TGlobalFlags, TArgs>(options, argv)\n result = await this.resultWithEnvironment<TFlags, TGlobalFlags, TArgs>(result, options, argv)\n await addFromParsedFlags(result.flags)\n return {...result, ...{argv: result.argv as string[]}}\n }\n\n protected environmentsFilename(): string | undefined {\n // To be re-implemented if needed\n return undefined\n }\n\n protected failMissingNonTTYFlags(flags: FlagOutput, requiredFlags: string[]): void {\n if (terminalSupportsRawMode()) return\n\n requiredFlags.forEach((name: string) => {\n if (!(name in flags)) {\n throw new AbortError(\n outputContent`Flag not specified:\n\n${outputToken.cyan(name)}\n\nThis flag is required in non-interactive terminal environments, such as a CI environment, or when piping input from another process.`,\n 'To resolve this, specify the option in the command, or run the command in an interactive environment such as your local terminal.',\n )\n }\n })\n }\n\n private async resultWithEnvironment<\n TFlags extends FlagOutput & {path?: string; verbose?: boolean},\n TGlobalFlags extends FlagOutput,\n TArgs extends ArgOutput,\n >(\n originalResult: ParserOutput<TFlags, TGlobalFlags, TArgs>,\n options?: Input<TFlags, TGlobalFlags, TArgs>,\n argv?: string[],\n ): Promise<ParserOutput<TFlags, TGlobalFlags, TArgs>> {\n // If no environment is specified, don't modify the results\n const flags = originalResult.flags as EnvironmentFlags\n const environmentsFileName = this.environmentsFilename()\n if (!flags.environment || !environmentsFileName) return originalResult\n\n // If the specified environment isn't found, don't modify the results\n const environment = await loadEnvironment(flags.environment, environmentsFileName, {from: flags.path})\n if (!environment) return originalResult\n\n // Parse using noDefaultsOptions to derive a list of flags specified as\n // command-line arguments.\n const noDefaultsResult = await super.parse<TFlags, TGlobalFlags, TArgs>(noDefaultsOptions(options), argv)\n\n // Add the environment's settings to argv and pass them to `super.parse`. This\n // invokes oclif's validation system without breaking the oclif black box.\n // Replace the original result with this one.\n const result = await super.parse<TFlags, TGlobalFlags, TArgs>(options, [\n // Need to specify argv default because we're merging with argsFromEnvironment.\n ...(argv || this.argv),\n ...argsFromEnvironment<TFlags, TGlobalFlags, TArgs>(environment, options, noDefaultsResult),\n ])\n\n // Report successful application of the environment.\n reportEnvironmentApplication<TFlags, TGlobalFlags, TArgs>(\n noDefaultsResult.flags,\n result.flags,\n flags.environment,\n environment,\n )\n\n return result\n }\n}\n\nexport async function addFromParsedFlags(flags: {path?: string; verbose?: boolean}): Promise<void> {\n await addPublicMetadata(() => ({\n cmd_all_verbose: flags.verbose,\n cmd_all_path_override: flags.path !== undefined,\n cmd_all_path_override_hash: flags.path === undefined ? undefined : hashString(flags.path),\n }))\n}\n\n/**\n * Any flag which is:\n *\n * 1. Present in the final set of flags\n * 2. Specified in the environment\n * 3. Not specified by the user as a command line argument\n *\n * should be reported.\n *\n * It doesn't matter if the environment flag's value was the same as the default; from\n * the user's perspective, they want to know their environment was applied.\n */\nfunction reportEnvironmentApplication<\n TFlags extends FlagOutput,\n TGlobalFlags extends FlagOutput,\n TArgs extends ArgOutput,\n>(\n noDefaultsFlags: ParserOutput<TFlags, TGlobalFlags, TArgs>['flags'],\n flagsWithEnvironments: ParserOutput<TFlags, TGlobalFlags, TArgs>['flags'],\n environmentName: string,\n environment: JsonMap,\n): void {\n const changes: JsonMap = {}\n for (const [name, value] of Object.entries(flagsWithEnvironments)) {\n const userSpecifiedThisFlag = Object.prototype.hasOwnProperty.call(noDefaultsFlags, name)\n const environmentContainsFlag = Object.prototype.hasOwnProperty.call(environment, name)\n if (!userSpecifiedThisFlag && environmentContainsFlag) {\n const valueToReport = name === 'password' ? `********${value.substr(-4)}` : value\n changes[name] = valueToReport\n }\n }\n if (Object.keys(changes).length === 0) return\n\n const items = Object.entries(changes).map(([name, value]) => `${name}: ${value}`)\n renderInfo({\n headline: ['Using applicable flags from', {userInput: environmentName}, 'environment:'],\n body: [{list: {items}}],\n })\n}\n\n/**\n * Strips the defaults from configured flags. For example, if flags contains:\n *\n * ```\n * someFlag: Flags.boolean({\n * description: 'some flag',\n * default: false\n * })\n * ```\n *\n * it becomes:\n *\n * ```\n * someFlag: Flags.boolean({\n * description: 'some flag'\n * })\n * ```\n *\n * If we parse using this configuration, the only specified flags will be those\n * the user actually passed on the command line.\n */\nfunction noDefaultsOptions<TFlags extends FlagOutput, TGlobalFlags extends FlagOutput, TArgs extends ArgOutput>(\n options: Input<TFlags, TGlobalFlags, TArgs> | undefined,\n): Input<TFlags, TGlobalFlags, TArgs> | undefined {\n if (!options?.flags) return options\n return {\n ...options,\n flags: Object.fromEntries(\n Object.entries(options.flags).map(([label, settings]) => {\n const copiedSettings = {...(settings as {default?: unknown})}\n delete copiedSettings.default\n return [label, copiedSettings]\n }),\n ) as FlagInput<TFlags>,\n }\n}\n\n/**\n * Converts the environment's settings to arguments as though passed on the command\n * line, skipping any arguments the user specified on the command line.\n */\nfunction argsFromEnvironment<TFlags extends FlagOutput, TGlobalFlags extends FlagOutput, TArgs extends ArgOutput>(\n environment: JsonMap,\n options: Input<TFlags, TGlobalFlags, TArgs> | undefined,\n noDefaultsResult: ParserOutput<TFlags, TArgs>,\n): string[] {\n const args: string[] = []\n for (const [label, value] of Object.entries(environment)) {\n const flagIsRelevantToCommand = options?.flags && Object.prototype.hasOwnProperty.call(options.flags, label)\n const userSpecifiedThisFlag =\n noDefaultsResult.flags && Object.prototype.hasOwnProperty.call(noDefaultsResult.flags, label)\n if (flagIsRelevantToCommand && !userSpecifiedThisFlag) {\n if (typeof value === 'boolean') {\n if (value === true) {\n args.push(`--${label}`)\n } else {\n throw new AbortError(\n outputContent`Environments can only specify true for boolean flags. Attempted to set ${outputToken.yellow(\n label,\n )} to false.`,\n )\n }\n } else if (Array.isArray(value)) {\n value.forEach((element) => args.push(`--${label}`, `${element}`))\n } else {\n args.push(`--${label}`, `${value}`)\n }\n }\n }\n return args\n}\n\nexport default BaseCommand\n"]}
|
|
1
|
+
{"version":3,"file":"base-command.js","sourceRoot":"","sources":["../../../src/public/node/base-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,2CAA2C,EAAC,MAAM,oBAAoB,CAAA;AAC5F,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAA;AACrC,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,SAAS,CAAA;AACjD,OAAO,EAAC,aAAa,EAAE,UAAU,EAAE,WAAW,EAAC,MAAM,aAAa,CAAA;AAClE,OAAO,EAAC,uBAAuB,EAAC,MAAM,aAA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AA;QAC5G,MAAM,qBAAqB,GACzB,gBAAgB,CAAC,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;QAC/F,IAAI,uBAAuB,IAAI,CAAC,qBAAqB,EAAE;YACrD,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE;gBAC9B,IAAI,KAAK,KAAK,IAAI,EAAE;oBAClB,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC,CAAA;iBACxB;qBAAM;oBACL,MAAM,IAAI,UAAU,CAClB,aAAa,CAAA,0EAA0E,WAAW,CAAC,MAAM,CACvG,KAAK,CACN,YAAY,CACd,CAAA;iBACF;aACF;iBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBAC/B,KAAK,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAA;aAClE;iBAAM;gBACL,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,CAAC,CAAA;aACpC;SACF;KACF;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,eAAe,WAAW,CAAA","sourcesContent":["import {errorHandler, registerCleanBugsnagErrorsFromWithinPlugins} from './error-handler.js'\nimport {loadEnvironment} from './environments.js'\nimport {isDevelopment} from './context/local.js'\nimport {addPublicMetadata} from './metadata.js'\nimport {AbortError} from './error.js'\nimport {renderInfo, renderWarning} from './ui.js'\nimport {outputContent, outputInfo, outputToken} from './output.js'\nimport {terminalSupportsRawMode} from './system.js'\nimport {hashString} from './crypto.js'\nimport {isTruthy} from './context/utilities.js'\nimport {JsonMap} from '../../private/common/json.js'\nimport {underscore} from '../common/string.js'\nimport {Command, Errors} from '@oclif/core'\nimport {FlagOutput, Input, ParserOutput, FlagInput, ArgOutput} from '@oclif/core/lib/interfaces/parser.js'\n\ninterface EnvironmentFlags {\n environment?: string\n path?: string\n}\n\nabstract class BaseCommand extends Command {\n // Replace markdown links to plain text like: \"link label\" (url)\n public static descriptionWithoutMarkdown(): string | undefined {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return ((this as any).descriptionWithMarkdown ?? '').replace(/(\\[)(.*?)(])(\\()(.*?)(\\))/gm, '\"$2\" ($5)')\n }\n\n public static analyticsNameOverride(): string | undefined {\n return undefined\n }\n\n public static analyticsStopCommand(): string | undefined {\n return undefined\n }\n\n async catch(error: Error & {exitCode?: number | undefined}): Promise<void> {\n await errorHandler(error, this.config)\n return Errors.handle(error)\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected async init(): Promise<any> {\n this.exitWithTimestampWhenEnvVariablePresent()\n if (!isDevelopment()) {\n // This function runs just prior to `run`\n await registerCleanBugsnagErrorsFromWithinPlugins(this.config)\n }\n this.showNpmFlagWarning()\n return super.init()\n }\n\n // NPM creates an environment variable for every flag passed to a script.\n // This function checks for the presence of any of the available CLI flags\n // and warns the user to use the `--` separator.\n protected showNpmFlagWarning(): void {\n const commandVariables = this.constructor as unknown as {flags: JsonMap}\n const commandFlags = Object.keys(commandVariables.flags || {})\n const possibleNpmEnvVars = commandFlags.map((key) => `npm_config_${underscore(key).replace(/^no_/, '')}`)\n\n if (possibleNpmEnvVars.some((flag) => process.env[flag] !== undefined)) {\n renderWarning({\n body: [\n 'NPM scripts require an extra',\n {command: '--'},\n 'separator to pass the flags. Example:',\n {command: 'npm run dev -- --reset'},\n ],\n })\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n protected exitWithTimestampWhenEnvVariablePresent() {\n if (isTruthy(process.env.SHOPIFY_CLI_ENV_STARTUP_PERFORMANCE_RUN)) {\n outputInfo(`\n SHOPIFY_CLI_TIMESTAMP_START\n { \"timestamp\": ${Date.now()} }\n SHOPIFY_CLI_TIMESTAMP_END\n `)\n process.exit(0)\n }\n }\n\n protected async parse<\n TFlags extends FlagOutput & {path?: string; verbose?: boolean},\n TGlobalFlags extends FlagOutput,\n TArgs extends ArgOutput,\n >(\n options?: Input<TFlags, TGlobalFlags, TArgs>,\n argv?: string[],\n ): Promise<ParserOutput<TFlags, TGlobalFlags, TArgs> & {argv: string[]}> {\n let result = await super.parse<TFlags, TGlobalFlags, TArgs>(options, argv)\n result = await this.resultWithEnvironment<TFlags, TGlobalFlags, TArgs>(result, options, argv)\n await addFromParsedFlags(result.flags)\n return {...result, ...{argv: result.argv as string[]}}\n }\n\n protected environmentsFilename(): string | undefined {\n // To be re-implemented if needed\n return undefined\n }\n\n protected failMissingNonTTYFlags(flags: FlagOutput, requiredFlags: string[]): void {\n if (terminalSupportsRawMode()) return\n\n requiredFlags.forEach((name: string) => {\n if (!(name in flags)) {\n throw new AbortError(\n outputContent`Flag not specified:\n\n${outputToken.cyan(name)}\n\nThis flag is required in non-interactive terminal environments, such as a CI environment, or when piping input from another process.`,\n 'To resolve this, specify the option in the command, or run the command in an interactive environment such as your local terminal.',\n )\n }\n })\n }\n\n private async resultWithEnvironment<\n TFlags extends FlagOutput & {path?: string; verbose?: boolean},\n TGlobalFlags extends FlagOutput,\n TArgs extends ArgOutput,\n >(\n originalResult: ParserOutput<TFlags, TGlobalFlags, TArgs>,\n options?: Input<TFlags, TGlobalFlags, TArgs>,\n argv?: string[],\n ): Promise<ParserOutput<TFlags, TGlobalFlags, TArgs>> {\n // If no environment is specified, don't modify the results\n const flags = originalResult.flags as EnvironmentFlags\n const environmentsFileName = this.environmentsFilename()\n if (!flags.environment || !environmentsFileName) return originalResult\n\n // If the specified environment isn't found, don't modify the results\n const environment = await loadEnvironment(flags.environment, environmentsFileName, {from: flags.path})\n if (!environment) return originalResult\n\n // Parse using noDefaultsOptions to derive a list of flags specified as\n // command-line arguments.\n const noDefaultsResult = await super.parse<TFlags, TGlobalFlags, TArgs>(noDefaultsOptions(options), argv)\n\n // Add the environment's settings to argv and pass them to `super.parse`. This\n // invokes oclif's validation system without breaking the oclif black box.\n // Replace the original result with this one.\n const result = await super.parse<TFlags, TGlobalFlags, TArgs>(options, [\n // Need to specify argv default because we're merging with argsFromEnvironment.\n ...(argv || this.argv),\n ...argsFromEnvironment<TFlags, TGlobalFlags, TArgs>(environment, options, noDefaultsResult),\n ])\n\n // Report successful application of the environment.\n reportEnvironmentApplication<TFlags, TGlobalFlags, TArgs>(\n noDefaultsResult.flags,\n result.flags,\n flags.environment,\n environment,\n )\n\n return result\n }\n}\n\nexport async function addFromParsedFlags(flags: {path?: string; verbose?: boolean}): Promise<void> {\n await addPublicMetadata(() => ({\n cmd_all_verbose: flags.verbose,\n cmd_all_path_override: flags.path !== undefined,\n cmd_all_path_override_hash: flags.path === undefined ? undefined : hashString(flags.path),\n }))\n}\n\n/**\n * Any flag which is:\n *\n * 1. Present in the final set of flags\n * 2. Specified in the environment\n * 3. Not specified by the user as a command line argument\n *\n * should be reported.\n *\n * It doesn't matter if the environment flag's value was the same as the default; from\n * the user's perspective, they want to know their environment was applied.\n */\nfunction reportEnvironmentApplication<\n TFlags extends FlagOutput,\n TGlobalFlags extends FlagOutput,\n TArgs extends ArgOutput,\n>(\n noDefaultsFlags: ParserOutput<TFlags, TGlobalFlags, TArgs>['flags'],\n flagsWithEnvironments: ParserOutput<TFlags, TGlobalFlags, TArgs>['flags'],\n environmentName: string,\n environment: JsonMap,\n): void {\n const changes: JsonMap = {}\n for (const [name, value] of Object.entries(flagsWithEnvironments)) {\n const userSpecifiedThisFlag = Object.prototype.hasOwnProperty.call(noDefaultsFlags, name)\n const environmentContainsFlag = Object.prototype.hasOwnProperty.call(environment, name)\n if (!userSpecifiedThisFlag && environmentContainsFlag) {\n const valueToReport = name === 'password' ? `********${value.substr(-4)}` : value\n changes[name] = valueToReport\n }\n }\n if (Object.keys(changes).length === 0) return\n\n const items = Object.entries(changes).map(([name, value]) => `${name}: ${value}`)\n renderInfo({\n headline: ['Using applicable flags from', {userInput: environmentName}, 'environment:'],\n body: [{list: {items}}],\n })\n}\n\n/**\n * Strips the defaults from configured flags. For example, if flags contains:\n *\n * ```\n * someFlag: Flags.boolean({\n * description: 'some flag',\n * default: false\n * })\n * ```\n *\n * it becomes:\n *\n * ```\n * someFlag: Flags.boolean({\n * description: 'some flag'\n * })\n * ```\n *\n * If we parse using this configuration, the only specified flags will be those\n * the user actually passed on the command line.\n */\nfunction noDefaultsOptions<TFlags extends FlagOutput, TGlobalFlags extends FlagOutput, TArgs extends ArgOutput>(\n options: Input<TFlags, TGlobalFlags, TArgs> | undefined,\n): Input<TFlags, TGlobalFlags, TArgs> | undefined {\n if (!options?.flags) return options\n return {\n ...options,\n flags: Object.fromEntries(\n Object.entries(options.flags).map(([label, settings]) => {\n const copiedSettings = {...(settings as {default?: unknown})}\n delete copiedSettings.default\n return [label, copiedSettings]\n }),\n ) as FlagInput<TFlags>,\n }\n}\n\n/**\n * Converts the environment's settings to arguments as though passed on the command\n * line, skipping any arguments the user specified on the command line.\n */\nfunction argsFromEnvironment<TFlags extends FlagOutput, TGlobalFlags extends FlagOutput, TArgs extends ArgOutput>(\n environment: JsonMap,\n options: Input<TFlags, TGlobalFlags, TArgs> | undefined,\n noDefaultsResult: ParserOutput<TFlags, TArgs>,\n): string[] {\n const args: string[] = []\n for (const [label, value] of Object.entries(environment)) {\n const flagIsRelevantToCommand = options?.flags && Object.prototype.hasOwnProperty.call(options.flags, label)\n const userSpecifiedThisFlag =\n noDefaultsResult.flags && Object.prototype.hasOwnProperty.call(noDefaultsResult.flags, label)\n if (flagIsRelevantToCommand && !userSpecifiedThisFlag) {\n if (typeof value === 'boolean') {\n if (value === true) {\n args.push(`--${label}`)\n } else {\n throw new AbortError(\n outputContent`Environments can only specify true for boolean flags. Attempted to set ${outputToken.yellow(\n label,\n )} to false.`,\n )\n }\n } else if (Array.isArray(value)) {\n value.forEach((element) => args.push(`--${label}`, `${element}`))\n } else {\n args.push(`--${label}`, `${value}`)\n }\n }\n }\n return args\n}\n\nexport default BaseCommand\n"]}
|
package/dist/public/node/cli.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { isTruthy } from './context/utilities.js';
|
|
2
2
|
import { printEventsJson } from '../../private/node/demo-recorder.js';
|
|
3
3
|
import { Flags } from '@oclif/core';
|
|
4
|
+
// eslint-disable-next-line @shopify/cli/specific-imports-in-bootstrap-code
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
4
6
|
async function warnIfOldNodeVersion() {
|
|
5
7
|
const nodeVersion = process.versions.node;
|
|
6
8
|
const nodeMajorVersion = Number(nodeVersion.split('.')[0]);
|
|
@@ -61,11 +63,15 @@ export async function runCLI(options) {
|
|
|
61
63
|
const { errorHandler } = await import('./error-handler.js');
|
|
62
64
|
const { isDevelopment } = await import('./context/local.js');
|
|
63
65
|
const { run, settings, flush, Errors } = await import('@oclif/core');
|
|
66
|
+
const { ShopifyConfig } = await import('./custom-oclif-loader.js');
|
|
64
67
|
if (isDevelopment()) {
|
|
65
68
|
settings.debug = true;
|
|
66
69
|
}
|
|
67
70
|
try {
|
|
68
|
-
|
|
71
|
+
// Use a custom OCLIF config to customize the behavior of the CLI
|
|
72
|
+
const config = new ShopifyConfig({ root: fileURLToPath(options.moduleURL) });
|
|
73
|
+
await config.load();
|
|
74
|
+
await run(undefined, config);
|
|
69
75
|
await flush();
|
|
70
76
|
printEventsJson();
|
|
71
77
|
// eslint-disable-next-line no-catch-all/no-catch-all
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/public/node/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAA;AAC/C,OAAO,EAAC,eAAe,EAAC,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAA;AAajC,KAAK,UAAU,oBAAoB;IACjC,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,CAA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AAC,CAAA;AACzC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC;QACxB,MAAM,EAAE,KAAK;QACb,WAAW,EAAE,uBAAuB;QACpC,GAAG,EAAE,uBAAuB;KAC7B,CAAC;IACF,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;QACrB,MAAM,EAAE,KAAK;QACb,WAAW,EAAE,qCAAqC;QAClD,GAAG,EAAE,sBAAsB;KAC5B,CAAC;CACH,CAAA;AAED,eAAe,MAAM,CAAA","sourcesContent":["import {isTruthy} from './context/utilities.js'\nimport {printEventsJson} from '../../private/node/demo-recorder.js'\nimport {Flags} from '@oclif/core'\n\n/**\n * IMPORTANT NOTE: Imports in this module are dynamic to ensure that \"setupEnvironmentVariables\" can dynamically\n * set the DEBUG environment variable before the 'debug' package sets up its configuration when modules\n * are loaded statically.\n */\ninterface RunCLIOptions {\n /** The value of import.meta.url of the CLI executable module */\n moduleURL: string\n development: boolean\n}\n\nasync function warnIfOldNodeVersion() {\n const nodeVersion = process.versions.node\n const nodeMajorVersion = Number(nodeVersion.split('.')[0])\n\n const currentSupportedNodeVersion = 18\n if (nodeMajorVersion < currentSupportedNodeVersion) {\n const {renderWarning} = await import('./ui.js')\n renderWarning({\n headline: 'Upgrade to a supported Node version now.',\n body: [\n `Node ${nodeMajorVersion} has reached end-of-life and poses security risks. When you upgrade to a`,\n {\n link: {\n url: 'https://nodejs.dev/en/about/previous-releases',\n label: 'supported version',\n },\n },\n {char: ','},\n \"you'll be able to use Shopify CLI without interruption.\",\n ],\n })\n }\n}\n\nfunction setupEnvironmentVariables(options: Pick<RunCLIOptions, 'development'>) {\n /**\n * By setting DEBUG=* when --verbose is passed we are increasing the\n * verbosity of oclif. Oclif uses debug (https://www.npmjs.com/package/debug)\n * for logging, and it's configured through the DEBUG= environment variable.\n */\n if (process.argv.includes('--verbose')) {\n process.env.DEBUG = process.env.DEBUG ?? '*'\n }\n if (options.development) {\n process.env.SHOPIFY_CLI_ENV = process.env.SHOPIFY_CLI_ENV ?? 'development'\n }\n}\n\nfunction forceNoColor() {\n if (\n process.argv.includes('--no-color') ||\n isTruthy(process.env.NO_COLOR) ||\n isTruthy(process.env.SHOPIFY_FLAG_NO_COLOR) ||\n process.env.TERM === 'dumb'\n ) {\n process.env.FORCE_COLOR = '0'\n }\n}\n\n/**\n * A function that abstracts away setting up the environment and running\n * a CLI\n * @param options - Options.\n */\nexport async function runCLI(options: RunCLIOptions): Promise<void> {\n setupEnvironmentVariables(options)\n forceNoColor()\n await warnIfOldNodeVersion()\n /**\n * These imports need to be dynamic because if they are static\n * they are loaded before we set the DEBUG=* environment variable\n * and therefore it has no effect.\n */\n const {errorHandler} = await import('./error-handler.js')\n const {isDevelopment} = await import('./context/local.js')\n const {run, settings, flush, Errors} = await import('@oclif/core')\n\n if (isDevelopment()) {\n settings.debug = true\n }\n\n try {\n await run(undefined, options.moduleURL)\n await flush()\n printEventsJson()\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n await errorHandler(error as Error)\n return Errors.handle(error as Error)\n }\n}\n\n/**\n * A function for create-x CLIs that automatically runs the \"init\" command.\n */\nexport async function runCreateCLI(options: RunCLIOptions): Promise<void> {\n setupEnvironmentVariables(options)\n\n const {findUpAndReadPackageJson} = await import('./node-package-manager.js')\n const {moduleDirectory} = await import('./path.js')\n\n const packageJson = await findUpAndReadPackageJson(moduleDirectory(options.moduleURL))\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const packageName = (packageJson.content as any).name as string\n const name = packageName.replace('@shopify/create-', '')\n const initIndex = process.argv.findIndex((arg) => arg.includes('init'))\n if (initIndex === -1) {\n const initIndex =\n process.argv.findIndex((arg) => arg.match(new RegExp(`bin(\\\\/|\\\\\\\\)+(create-${name}|dev|run)`))) + 1\n process.argv.splice(initIndex, 0, 'init')\n }\n await runCLI(options)\n}\n\nexport async function useLocalCLIIfDetected(filepath: string): Promise<boolean> {\n const {environmentVariables} = await import('../../private/node/constants.js')\n const {joinPath: join} = await import('./path.js')\n const {exec} = await import('./system.js')\n\n // Temporary flag while we test out this feature and ensure it won't break anything!\n if (!isTruthy(process.env[environmentVariables.enableCliRedirect])) return false\n\n // Setting an env variable in the child process prevents accidental recursion.\n if (isTruthy(process.env[environmentVariables.skipCliRedirect])) return false\n\n // If already running via package manager, we can assume it's running correctly already.\n if (process.env.npm_config_user_agent) return false\n\n const cliPackage = await localCliPackage()\n if (!cliPackage) return false\n\n const correctExecutablePath = join(cliPackage.path, cliPackage.bin.shopify)\n if (correctExecutablePath === filepath) return false\n try {\n await exec(correctExecutablePath, process.argv.slice(2, process.argv.length), {\n stdio: 'inherit',\n env: {[environmentVariables.skipCliRedirect]: '1'},\n })\n // eslint-disable-next-line no-catch-all/no-catch-all, @typescript-eslint/no-explicit-any\n } catch (processError: any) {\n process.exit(processError.exitCode)\n }\n return true\n}\n\ninterface CliPackageInfo {\n path: string\n bin: {shopify: string}\n}\n\ninterface PackageJSON {\n dependencies?: {[packageName: string]: CliPackageInfo}\n devDependencies?: {[packageName: string]: CliPackageInfo}\n peerDependencies?: {[packageName: string]: CliPackageInfo}\n}\n\nexport async function localCliPackage(): Promise<CliPackageInfo | undefined> {\n const {captureOutput} = await import('./system.js')\n\n let npmListOutput = ''\n let localShopifyCLI: PackageJSON = {}\n try {\n npmListOutput = await captureOutput('npm', ['list', '@shopify/cli', '--json', '-l'])\n localShopifyCLI = JSON.parse(npmListOutput)\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (err) {\n return\n }\n const dependenciesList = {\n ...localShopifyCLI.peerDependencies,\n ...localShopifyCLI.devDependencies,\n ...localShopifyCLI.dependencies,\n }\n return dependenciesList['@shopify/cli']\n}\n\n/**\n * An object that contains the flags that\n * are shared across all the commands.\n */\nexport const globalFlags = {\n 'no-color': Flags.boolean({\n hidden: false,\n description: 'Disable color output.',\n env: 'SHOPIFY_FLAG_NO_COLOR',\n }),\n verbose: Flags.boolean({\n hidden: false,\n description: 'Increase the verbosity of the logs.',\n env: 'SHOPIFY_FLAG_VERBOSE',\n }),\n}\n\nexport default runCLI\n"]}
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/public/node/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAA;AAC/C,OAAO,EAAC,eAAe,EAAC,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAA;AACjC,2EAA2E;AAC3E,OAAO,EAAC,aAAa,EAAC,MAAM,KAAK,CAAA;AAajC,KAAK,UAAU,oBAAoB;IACjC,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAA;IACzC,MAAM,gBAAgB,GAAG,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAE1D,MAAM,2BAA2B,GAAG,EAAE,CAAA;IACtC,IAAI,gBAAgB,GAAG,2BAA2B,EAAE;QAClD,MAAM,EAAC,aAAa,EAAC,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAA;QAC/C,aAAa,CAAC;YACZ,QAAQ,EAAE,0CAA0C;YACpD,IAAI,EAAE;gBACJ,QAAQ,gBAAgB,0EAA0E;gBAClG;oBACE,IAAI,EAAE;wBACJ,GAAG,EAAE,+CAA+C;wBACpD,KAAK,EAAE,mBAAmB;qBAC3B;iBACF;gBACD,EAAC,IAAI,EAAE,GAAG,EAAC;gBACX,yDAAyD;aAC1D;SACF,CAAC,CAAA;KACH;AACH,CAAC;AAED,SAAS,yBAAyB,CAAC,OAA2C;IAC5E;;;;OAIG;IACH,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;QACtC,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,CAAA;KA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AAiB,EAAE;QAC1B,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;KACpC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAaD,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,MAAM,EAAC,aAAa,EAAC,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAA;IAEnD,IAAI,aAAa,GAAG,EAAE,CAAA;IACtB,IAAI,eAAe,GAAgB,EAAE,CAAA;IACrC,IAAI;QACF,aAAa,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAA;QACpF,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;QAC3C,qDAAqD;KACtD;IAAC,OAAO,GAAG,EAAE;QACZ,OAAM;KACP;IACD,MAAM,gBAAgB,GAAG;QACvB,GAAG,eAAe,CAAC,gBAAgB;QACnC,GAAG,eAAe,CAAC,eAAe;QAClC,GAAG,eAAe,CAAC,YAAY;KAChC,CAAA;IACD,OAAO,gBAAgB,CAAC,cAAc,CAAC,CAAA;AACzC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC;QACxB,MAAM,EAAE,KAAK;QACb,WAAW,EAAE,uBAAuB;QACpC,GAAG,EAAE,uBAAuB;KAC7B,CAAC;IACF,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;QACrB,MAAM,EAAE,KAAK;QACb,WAAW,EAAE,qCAAqC;QAClD,GAAG,EAAE,sBAAsB;KAC5B,CAAC;CACH,CAAA;AAED,eAAe,MAAM,CAAA","sourcesContent":["import {isTruthy} from './context/utilities.js'\nimport {printEventsJson} from '../../private/node/demo-recorder.js'\nimport {Flags} from '@oclif/core'\n// eslint-disable-next-line @shopify/cli/specific-imports-in-bootstrap-code\nimport {fileURLToPath} from 'url'\n\n/**\n * IMPORTANT NOTE: Imports in this module are dynamic to ensure that \"setupEnvironmentVariables\" can dynamically\n * set the DEBUG environment variable before the 'debug' package sets up its configuration when modules\n * are loaded statically.\n */\ninterface RunCLIOptions {\n /** The value of import.meta.url of the CLI executable module */\n moduleURL: string\n development: boolean\n}\n\nasync function warnIfOldNodeVersion() {\n const nodeVersion = process.versions.node\n const nodeMajorVersion = Number(nodeVersion.split('.')[0])\n\n const currentSupportedNodeVersion = 18\n if (nodeMajorVersion < currentSupportedNodeVersion) {\n const {renderWarning} = await import('./ui.js')\n renderWarning({\n headline: 'Upgrade to a supported Node version now.',\n body: [\n `Node ${nodeMajorVersion} has reached end-of-life and poses security risks. When you upgrade to a`,\n {\n link: {\n url: 'https://nodejs.dev/en/about/previous-releases',\n label: 'supported version',\n },\n },\n {char: ','},\n \"you'll be able to use Shopify CLI without interruption.\",\n ],\n })\n }\n}\n\nfunction setupEnvironmentVariables(options: Pick<RunCLIOptions, 'development'>) {\n /**\n * By setting DEBUG=* when --verbose is passed we are increasing the\n * verbosity of oclif. Oclif uses debug (https://www.npmjs.com/package/debug)\n * for logging, and it's configured through the DEBUG= environment variable.\n */\n if (process.argv.includes('--verbose')) {\n process.env.DEBUG = process.env.DEBUG ?? '*'\n }\n if (options.development) {\n process.env.SHOPIFY_CLI_ENV = process.env.SHOPIFY_CLI_ENV ?? 'development'\n }\n}\n\nfunction forceNoColor() {\n if (\n process.argv.includes('--no-color') ||\n isTruthy(process.env.NO_COLOR) ||\n isTruthy(process.env.SHOPIFY_FLAG_NO_COLOR) ||\n process.env.TERM === 'dumb'\n ) {\n process.env.FORCE_COLOR = '0'\n }\n}\n\n/**\n * A function that abstracts away setting up the environment and running\n * a CLI\n * @param options - Options.\n */\nexport async function runCLI(options: RunCLIOptions): Promise<void> {\n setupEnvironmentVariables(options)\n forceNoColor()\n await warnIfOldNodeVersion()\n /**\n * These imports need to be dynamic because if they are static\n * they are loaded before we set the DEBUG=* environment variable\n * and therefore it has no effect.\n */\n const {errorHandler} = await import('./error-handler.js')\n const {isDevelopment} = await import('./context/local.js')\n const {run, settings, flush, Errors} = await import('@oclif/core')\n const {ShopifyConfig} = await import('./custom-oclif-loader.js')\n\n if (isDevelopment()) {\n settings.debug = true\n }\n\n try {\n // Use a custom OCLIF config to customize the behavior of the CLI\n const config = new ShopifyConfig({root: fileURLToPath(options.moduleURL)})\n await config.load()\n\n await run(undefined, config)\n await flush()\n printEventsJson()\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n await errorHandler(error as Error)\n return Errors.handle(error as Error)\n }\n}\n\n/**\n * A function for create-x CLIs that automatically runs the \"init\" command.\n */\nexport async function runCreateCLI(options: RunCLIOptions): Promise<void> {\n setupEnvironmentVariables(options)\n\n const {findUpAndReadPackageJson} = await import('./node-package-manager.js')\n const {moduleDirectory} = await import('./path.js')\n\n const packageJson = await findUpAndReadPackageJson(moduleDirectory(options.moduleURL))\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const packageName = (packageJson.content as any).name as string\n const name = packageName.replace('@shopify/create-', '')\n const initIndex = process.argv.findIndex((arg) => arg.includes('init'))\n if (initIndex === -1) {\n const initIndex =\n process.argv.findIndex((arg) => arg.match(new RegExp(`bin(\\\\/|\\\\\\\\)+(create-${name}|dev|run)`))) + 1\n process.argv.splice(initIndex, 0, 'init')\n }\n await runCLI(options)\n}\n\nexport async function useLocalCLIIfDetected(filepath: string): Promise<boolean> {\n const {environmentVariables} = await import('../../private/node/constants.js')\n const {joinPath: join} = await import('./path.js')\n const {exec} = await import('./system.js')\n\n // Temporary flag while we test out this feature and ensure it won't break anything!\n if (!isTruthy(process.env[environmentVariables.enableCliRedirect])) return false\n\n // Setting an env variable in the child process prevents accidental recursion.\n if (isTruthy(process.env[environmentVariables.skipCliRedirect])) return false\n\n // If already running via package manager, we can assume it's running correctly already.\n if (process.env.npm_config_user_agent) return false\n\n const cliPackage = await localCliPackage()\n if (!cliPackage) return false\n\n const correctExecutablePath = join(cliPackage.path, cliPackage.bin.shopify)\n if (correctExecutablePath === filepath) return false\n try {\n await exec(correctExecutablePath, process.argv.slice(2, process.argv.length), {\n stdio: 'inherit',\n env: {[environmentVariables.skipCliRedirect]: '1'},\n })\n // eslint-disable-next-line no-catch-all/no-catch-all, @typescript-eslint/no-explicit-any\n } catch (processError: any) {\n process.exit(processError.exitCode)\n }\n return true\n}\n\ninterface CliPackageInfo {\n path: string\n bin: {shopify: string}\n}\n\ninterface PackageJSON {\n dependencies?: {[packageName: string]: CliPackageInfo}\n devDependencies?: {[packageName: string]: CliPackageInfo}\n peerDependencies?: {[packageName: string]: CliPackageInfo}\n}\n\nexport async function localCliPackage(): Promise<CliPackageInfo | undefined> {\n const {captureOutput} = await import('./system.js')\n\n let npmListOutput = ''\n let localShopifyCLI: PackageJSON = {}\n try {\n npmListOutput = await captureOutput('npm', ['list', '@shopify/cli', '--json', '-l'])\n localShopifyCLI = JSON.parse(npmListOutput)\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (err) {\n return\n }\n const dependenciesList = {\n ...localShopifyCLI.peerDependencies,\n ...localShopifyCLI.devDependencies,\n ...localShopifyCLI.dependencies,\n }\n return dependenciesList['@shopify/cli']\n}\n\n/**\n * An object that contains the flags that\n * are shared across all the commands.\n */\nexport const globalFlags = {\n 'no-color': Flags.boolean({\n hidden: false,\n description: 'Disable color output.',\n env: 'SHOPIFY_FLAG_NO_COLOR',\n }),\n verbose: Flags.boolean({\n hidden: false,\n description: 'Increase the verbosity of the logs.',\n env: 'SHOPIFY_FLAG_VERBOSE',\n }),\n}\n\nexport default runCLI\n"]}
|
|
@@ -9,6 +9,12 @@ export declare const NotProvidedStoreFQDNError: AbortError;
|
|
|
9
9
|
* @returns Fully-qualified domain of the partners service we should interact with.
|
|
10
10
|
*/
|
|
11
11
|
export declare function partnersFqdn(): Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* It returns the Shopify Developers' API service we should interact with.
|
|
14
|
+
*
|
|
15
|
+
* @returns Fully-qualified domain of the Shopify Developers service we should interact with.
|
|
16
|
+
*/
|
|
17
|
+
export declare function shopifyDevelopersFqdn(): Promise<string>;
|
|
12
18
|
/**
|
|
13
19
|
* It returns the BusinessPlatform' API service we should interact with.
|
|
14
20
|
*
|
|
@@ -22,6 +22,23 @@ export async function partnersFqdn() {
|
|
|
22
22
|
return productionFqdn;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* It returns the Shopify Developers' API service we should interact with.
|
|
27
|
+
*
|
|
28
|
+
* @returns Fully-qualified domain of the Shopify Developers service we should interact with.
|
|
29
|
+
*/
|
|
30
|
+
export async function shopifyDevelopersFqdn() {
|
|
31
|
+
const environment = serviceEnvironment();
|
|
32
|
+
const productionFqdn = 'shopify.com';
|
|
33
|
+
switch (environment) {
|
|
34
|
+
case 'local':
|
|
35
|
+
return 'app.shopify.myshopify.io';
|
|
36
|
+
case 'spin':
|
|
37
|
+
return `app.shopify.${await spinFqdn()}`;
|
|
38
|
+
default:
|
|
39
|
+
return productionFqdn;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
25
42
|
/**
|
|
26
43
|
* It returns the BusinessPlatform' API service we should interact with.
|
|
27
44
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fqdn.js","sourceRoot":"","sources":["../../../../src/public/node/context/fqdn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAE,QAAQ,EAAC,MAAM,WAAW,CAAA;AACrD,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAA;AACtC,OAAO,EAAC,kBAAkB,EAAC,MAAM,0CAA0C,CAAA;AAE3E,MAAM,CAAC,MAAM,kCAAkC,GAAG,IAAI,UAAU,CAC9D,iGAAiG,CAClG,CAAA;AACD,MAAM,CAAC,MAAM,kCAAkC,GAAG,IAAI,UAAU,CAC9D,iGAAiG,CAClG,CAAA;AACD,MAAM,CAAC,MAAM,iCAAiC,GAAG,IAAI,UAAU,CAC7D,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ACtE,MAAM,SAAS,GAAG,KAAK,EAAE,SAAiB,EAAE,EAAE,CAC5C,iBAAiB,EAAE,CAAC,CAAC,CAAC,GAAG,SAAS,YAAY,MAAM,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,SAAS,gBAAgB,CAAA;IACjG,MAAM,aAAa,GAAG,CAAC,SAAiB,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAA;IACnH,OAAO,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;AACpE,CAAC","sourcesContent":["import {isSpinEnvironment, spinFqdn} from './spin.js'\nimport {AbortError} from '../error.js'\nimport {serviceEnvironment} from '../../../private/node/context/service.js'\n\nexport const CouldntObtainPartnersSpinFQDNError = new AbortError(\n \"Couldn't obtain the Spin FQDN for Partners when the CLI is not running from a Spin environment.\",\n)\nexport const CouldntObtainIdentitySpinFQDNError = new AbortError(\n \"Couldn't obtain the Spin FQDN for Identity when the CLI is not running from a Spin environment.\",\n)\nexport const CouldntObtainShopifySpinFQDNError = new AbortError(\n \"Couldn't obtain the Spin FQDN for Shopify when the CLI is not running from a Spin environment.\",\n)\nexport const NotProvidedStoreFQDNError = new AbortError(\n \"Couldn't obtain the Shopify FQDN because the store FQDN was not provided.\",\n)\n\n/**\n * It returns the Partners' API service we should interact with.\n *\n * @returns Fully-qualified domain of the partners service we should interact with.\n */\nexport async function partnersFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'partners.shopify.com'\n switch (environment) {\n case 'local':\n return 'partners.myshopify.io'\n case 'spin':\n return `partners.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the BusinessPlatform' API service we should interact with.\n *\n * @returns Fully-qualified domain of the partners service we should interact with.\n */\nexport async function businessPlatformFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'destinations.shopifysvc.com'\n switch (environment) {\n case 'local':\n return 'business-platform.myshopify.io'\n case 'spin':\n return `business-platform.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the Identity service we should interact with.\n *\n * @returns Fully-qualified domain of the Identity service we should interact with.\n */\nexport async function identityFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'accounts.shopify.com'\n switch (environment) {\n case 'local':\n return 'identity.myshopify.io'\n case 'spin':\n return `identity.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * Normalize the store name to be used in the CLI.\n * It will add the .myshopify.com domain if it's not present.\n * It will add the spin domain if it's not present and we're in a Spin environment.\n *\n * @param store - Store name.\n * @returns Normalized store name.\n */\nexport async function normalizeStoreFqdn(store: string): Promise<string> {\n const storeFqdn = store.replace(/^https?:\\/\\//, '').replace(/\\/$/, '')\n const addDomain = async (storeFqdn: string) =>\n isSpinEnvironment() ? `${storeFqdn}.shopify.${await spinFqdn()}` : `${storeFqdn}.myshopify.com`\n const containDomain = (storeFqdn: string) => storeFqdn.includes('.myshopify.com') || storeFqdn.includes('spin.dev')\n return containDomain(storeFqdn) ? storeFqdn : addDomain(storeFqdn)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fqdn.js","sourceRoot":"","sources":["../../../../src/public/node/context/fqdn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAE,QAAQ,EAAC,MAAM,WAAW,CAAA;AACrD,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAA;AACtC,OAAO,EAAC,kBAAkB,EAAC,MAAM,0CAA0C,CAAA;AAE3E,MAAM,CAAC,MAAM,kCAAkC,GAAG,IAAI,UAAU,CAC9D,iGAAiG,CAClG,CAAA;AACD,MAAM,CAAC,MAAM,kCAAkC,GAAG,IAAI,UAAU,CAC9D,iGAAiG,CAClG,CAAA;AACD,MAAM,CAAC,MAAM,iCAAiC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B,KAAK,OAAO;YACV,OAAO,uBAAuB,CAAA;QAChC,KAAK,MAAM;YACT,OAAO,YAAY,MAAM,QAAQ,EAAE,EAAE,CAAA;QACvC;YACE,OAAO,cAAc,CAAA;KACxB;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,KAAa;IACpD,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IACtE,MAAM,SAAS,GAAG,KAAK,EAAE,SAAiB,EAAE,EAAE,CAC5C,iBAAiB,EAAE,CAAC,CAAC,CAAC,GAAG,SAAS,YAAY,MAAM,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,SAAS,gBAAgB,CAAA;IACjG,MAAM,aAAa,GAAG,CAAC,SAAiB,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAA;IACnH,OAAO,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;AACpE,CAAC","sourcesContent":["import {isSpinEnvironment, spinFqdn} from './spin.js'\nimport {AbortError} from '../error.js'\nimport {serviceEnvironment} from '../../../private/node/context/service.js'\n\nexport const CouldntObtainPartnersSpinFQDNError = new AbortError(\n \"Couldn't obtain the Spin FQDN for Partners when the CLI is not running from a Spin environment.\",\n)\nexport const CouldntObtainIdentitySpinFQDNError = new AbortError(\n \"Couldn't obtain the Spin FQDN for Identity when the CLI is not running from a Spin environment.\",\n)\nexport const CouldntObtainShopifySpinFQDNError = new AbortError(\n \"Couldn't obtain the Spin FQDN for Shopify when the CLI is not running from a Spin environment.\",\n)\nexport const NotProvidedStoreFQDNError = new AbortError(\n \"Couldn't obtain the Shopify FQDN because the store FQDN was not provided.\",\n)\n\n/**\n * It returns the Partners' API service we should interact with.\n *\n * @returns Fully-qualified domain of the partners service we should interact with.\n */\nexport async function partnersFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'partners.shopify.com'\n switch (environment) {\n case 'local':\n return 'partners.myshopify.io'\n case 'spin':\n return `partners.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the Shopify Developers' API service we should interact with.\n *\n * @returns Fully-qualified domain of the Shopify Developers service we should interact with.\n */\nexport async function shopifyDevelopersFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'shopify.com'\n switch (environment) {\n case 'local':\n return 'app.shopify.myshopify.io'\n case 'spin':\n return `app.shopify.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the BusinessPlatform' API service we should interact with.\n *\n * @returns Fully-qualified domain of the partners service we should interact with.\n */\nexport async function businessPlatformFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'destinations.shopifysvc.com'\n switch (environment) {\n case 'local':\n return 'business-platform.myshopify.io'\n case 'spin':\n return `business-platform.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the Identity service we should interact with.\n *\n * @returns Fully-qualified domain of the Identity service we should interact with.\n */\nexport async function identityFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'accounts.shopify.com'\n switch (environment) {\n case 'local':\n return 'identity.myshopify.io'\n case 'spin':\n return `identity.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * Normalize the store name to be used in the CLI.\n * It will add the .myshopify.com domain if it's not present.\n * It will add the spin domain if it's not present and we're in a Spin environment.\n *\n * @param store - Store name.\n * @returns Normalized store name.\n */\nexport async function normalizeStoreFqdn(store: string): Promise<string> {\n const storeFqdn = store.replace(/^https?:\\/\\//, '').replace(/\\/$/, '')\n const addDomain = async (storeFqdn: string) =>\n isSpinEnvironment() ? `${storeFqdn}.shopify.${await spinFqdn()}` : `${storeFqdn}.myshopify.com`\n const containDomain = (storeFqdn: string) => storeFqdn.includes('.myshopify.com') || storeFqdn.includes('spin.dev')\n return containDomain(storeFqdn) ? storeFqdn : addDomain(storeFqdn)\n}\n"]}
|
|
@@ -55,3 +55,16 @@ export declare function appPort(env?: NodeJS.ProcessEnv): number | undefined;
|
|
|
55
55
|
* @returns The value of the SPIN_APP_HOST environment variable.
|
|
56
56
|
*/
|
|
57
57
|
export declare function appHost(env?: NodeJS.ProcessEnv): string | undefined;
|
|
58
|
+
export declare const spinVariables: {
|
|
59
|
+
partnersSpinService: string;
|
|
60
|
+
manualCliSpinPortName: string;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Fetches the port for a given spin service and port environment variable.
|
|
64
|
+
*
|
|
65
|
+
* @param service - The name of the spin service to fetch the port for.
|
|
66
|
+
* @param portEnvName - The name of the environment variable to fetch the port from.
|
|
67
|
+
* @param basePath - The base path to look for the port file.
|
|
68
|
+
* @returns The port number or undefined if the port could not be found.
|
|
69
|
+
*/
|
|
70
|
+
export declare function fetchSpinPort(service: string, portEnvName: string, basePath?: string): Promise<number | undefined>;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { isTruthy } from './utilities.js';
|
|
2
|
-
import { fileExists, readFileSync } from '../fs.js';
|
|
2
|
+
import { fileExists, readFile, readFileSync } from '../fs.js';
|
|
3
3
|
import { environmentVariables } from '../../../private/node/constants.js';
|
|
4
4
|
import { captureOutput } from '../system.js';
|
|
5
5
|
import { outputContent, outputToken } from '../output.js';
|
|
6
6
|
import { getCachedSpinFqdn, setCachedSpinFqdn } from '../../../private/node/context/spin-cache.js';
|
|
7
7
|
import { AbortError } from '../error.js';
|
|
8
8
|
import { Environment, serviceEnvironment } from '../../../private/node/context/service.js';
|
|
9
|
+
import { joinPath } from '../path.js';
|
|
9
10
|
const SpinInstanceNotFoundMessages = (spinInstance, error) => {
|
|
10
11
|
const errorMessage = outputContent `${outputToken.genericShellCommand(`spin`)} yielded the following error trying to obtain the fully qualified domain name of the Spin instance:
|
|
11
12
|
${error}
|
|
@@ -108,4 +109,44 @@ export function appPort(env = process.env) {
|
|
|
108
109
|
export function appHost(env = process.env) {
|
|
109
110
|
return env[environmentVariables.spinAppHost];
|
|
110
111
|
}
|
|
112
|
+
export const spinVariables = {
|
|
113
|
+
partnersSpinService: 'shopify--partners',
|
|
114
|
+
manualCliSpinPortName: 'CLI_EXTENSION_SERVER',
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Fetches the port for a given spin service and port environment variable.
|
|
118
|
+
*
|
|
119
|
+
* @param service - The name of the spin service to fetch the port for.
|
|
120
|
+
* @param portEnvName - The name of the environment variable to fetch the port from.
|
|
121
|
+
* @param basePath - The base path to look for the port file.
|
|
122
|
+
* @returns The port number or undefined if the port could not be found.
|
|
123
|
+
*/
|
|
124
|
+
export async function fetchSpinPort(service, portEnvName, basePath = '/run') {
|
|
125
|
+
const spinVersionConfigurations = [
|
|
126
|
+
{
|
|
127
|
+
path: joinPath(basePath, 'ports2', service, 'custom', portEnvName),
|
|
128
|
+
contentPattern: /\[{"internal":(\d+)}\]/,
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
path: joinPath(basePath, 'ports', service, 'proc', portEnvName),
|
|
132
|
+
contentPattern: /(\d+)/,
|
|
133
|
+
},
|
|
134
|
+
];
|
|
135
|
+
for (const config of spinVersionConfigurations) {
|
|
136
|
+
let fileContent;
|
|
137
|
+
try {
|
|
138
|
+
// eslint-disable-next-line no-await-in-loop
|
|
139
|
+
fileContent = await readFile(config.path);
|
|
140
|
+
// eslint-disable-next-line no-catch-all/no-catch-all
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const match = config.contentPattern.exec(fileContent);
|
|
146
|
+
if (match && match[1] && !isNaN(parseInt(match[1], 10))) {
|
|
147
|
+
return parseInt(match[1], 10);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
111
152
|
//# sourceMappingURL=spin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spin.js","sourceRoot":"","sources":["../../../../src/public/node/context/spin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAC,UAAU,EAAE,YAAY,EAAC,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"spin.js","sourceRoot":"","sources":["../../../../src/public/node/context/spin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAC,MAAM,UAAU,CAAA;AAC3D,OAAO,EAAC,oBAAoB,EAAC,MAAM,oCAAoC,CAAA;AACvE,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAC,aAAa,EAAE,WAAW,EAAC,MAAM,cAAc,CAAA;AACvD,OAAO,EAAC,iBAAiB,EAAE,iBAAiB,EAAC,MAAM,6CAA6C,CAAA;AAChG,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAA;AACtC,OAAO,EAAC,WAAW,EAAE,kBAAkB,EAAC,MAAM,0CAA0C,CAAA;AACxF,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAA;AAEnC,MAAM,4BAA4B,GAAG,CAAC,YAAgC,EAAE,KAAa,EAAE,EAAE;IACvF,MAAM,YAAY,GAAG,aAAa,CAAA,GAAG,WAAW,CAAC,mBAAmB,CAClE,MAAM,CACP;EACD,KAAK;GACJ,CAAA;IACD,IAAI,SAA6B,CAAA;IACjC,IAAI,YAAY,EAAE;QAChB,SAAS,GAAG,aAAa,YAAY,6DAA6D,CAAA;KACnG;IACD,OAAO,EAAC,YAAY,EAAE,SAAS,EAAC,CAAA;AAClC,CAAC,CAAA;AAED,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E,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,CAAC;YAClE,cAAc,EAAE,wBAAwB;SACzC;QACD;YACE,IAAI,EAAE,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC;YAC/D,cAAc,EAAE,OAAO;SACxB;KACF,CAAA;IACD,KAAK,MAAM,MAAM,IAAI,yBAAyB,EAAE;QAC9C,IAAI,WAAmB,CAAA;QAEvB,IAAI;YACF,4CAA4C;YAC5C,WAAW,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YACzC,qDAAqD;SACtD;QAAC,OAAO,KAAK,EAAE;YACd,SAAQ;SACT;QAED,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;QACrD,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE;YACvD,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;SAC9B;KACF;IAED,OAAO,SAAS,CAAA;AAClB,CAAC","sourcesContent":["import {isTruthy} from './utilities.js'\nimport {fileExists, readFile, readFileSync} from '../fs.js'\nimport {environmentVariables} from '../../../private/node/constants.js'\nimport {captureOutput} from '../system.js'\nimport {outputContent, outputToken} from '../output.js'\nimport {getCachedSpinFqdn, setCachedSpinFqdn} from '../../../private/node/context/spin-cache.js'\nimport {AbortError} from '../error.js'\nimport {Environment, serviceEnvironment} from '../../../private/node/context/service.js'\nimport {joinPath} from '../path.js'\n\nconst SpinInstanceNotFoundMessages = (spinInstance: string | undefined, error: string) => {\n const errorMessage = outputContent`${outputToken.genericShellCommand(\n `spin`,\n )} yielded the following error trying to obtain the fully qualified domain name of the Spin instance:\n${error}\n `\n let nextSteps: string | undefined\n if (spinInstance) {\n nextSteps = `Make sure ${spinInstance} is the instance name and not a fully qualified domain name`\n }\n return {errorMessage, nextSteps}\n}\n\nconst spinFqdnFilePath = '/etc/spin/machine/fqdn'\n\n/**\n * When ran in a Spin environment, it returns the fqdn of the instance.\n *\n * Will cache the value of the Spin FQDN during the execution of the CLI.\n * To avoid multiple calls to `readSync` or `show`.\n *\n * @param env - Environment variables.\n * @returns Fqdn of the Spin environment.\n */\nexport async function spinFqdn(env = process.env): Promise<string> {\n let spinFqdn = getCachedSpinFqdn()\n if (spinFqdn) return spinFqdn\n\n if (await fileExists(spinFqdnFilePath)) {\n spinFqdn = await readFileSync(spinFqdnFilePath).toString()\n } else {\n const spinInstance = await instance(env)\n const showResponse = await show(spinInstance, env)\n\n spinFqdn = showResponse.fqdn\n }\n setCachedSpinFqdn(spinFqdn)\n return spinFqdn\n}\n\n/**\n * Runs \"spin show\" and returns the JSON-parsed output.\n *\n * @param spinInstance - When it's undefined, we'll fetch the latest one.\n * @param env - Environment variables.\n * @returns The JSON-parsed output of the Spin CLI.\n * @throws Any error raised from the underlying Spin CLI.\n */\nexport async function show(spinInstance: string | undefined, env = process.env): Promise<{fqdn: string}> {\n const latest = spinInstance === undefined\n const args = latest ? ['show', '--latest', '--json'] : ['show', '--json']\n const output = await captureOutput('spin', args, {env})\n const json = JSON.parse(output)\n if (json.error) {\n const {errorMessage, nextSteps} = SpinInstanceNotFoundMessages(spinInstance, json.error)\n throw new AbortError(errorMessage, nextSteps)\n } else {\n return json\n }\n}\n\n/**\n * Returns true if the CLI is running in a Spin environment.\n *\n * @param env - Environment variables.\n * @returns True if the CLI is running in a Spin environment.\n */\nexport function isSpin(env = process.env): boolean {\n return isTruthy(env[environmentVariables.spin])\n}\n\n/**\n * Returns the value of the SPIN_INSTANCE environment variable.\n *\n * @param env - Environment variables.\n * @returns The value of the SPIN_INSTANCE environment variable.\n */\nexport function instance(env = process.env): string | undefined {\n return env[environmentVariables.spinInstance]\n}\n\n/**\n * Returns true if the CLI is running in a Spin environment.\n *\n * @param env - Environment variables.\n * @returns True if the CLI is running in a Spin environment.\n */\nexport function isSpinEnvironment(env = process.env): boolean {\n return serviceEnvironment(env) === Environment.Spin\n}\n\n/**\n * Returns the value of the SERVER_PORT environment variable.\n *\n * @param env - Environment variables.\n * @returns The value of the SERVER_PORT environment variable.\n */\nexport function appPort(env = process.env): number | undefined {\n const port = Number(env[environmentVariables.spinAppPort])\n return (!isNaN(port) && port) || undefined\n}\n\n/**\n * Returns the value of the SPIN_APP_HOST environment variable.\n *\n * @param env - Environment variables.\n * @returns The value of the SPIN_APP_HOST environment variable.\n */\nexport function appHost(env = process.env): string | undefined {\n return env[environmentVariables.spinAppHost]\n}\n\nexport const spinVariables = {\n partnersSpinService: 'shopify--partners',\n manualCliSpinPortName: 'CLI_EXTENSION_SERVER',\n}\n/**\n * Fetches the port for a given spin service and port environment variable.\n *\n * @param service - The name of the spin service to fetch the port for.\n * @param portEnvName - The name of the environment variable to fetch the port from.\n * @param basePath - The base path to look for the port file.\n * @returns The port number or undefined if the port could not be found.\n */\nexport async function fetchSpinPort(\n service: string,\n portEnvName: string,\n basePath = '/run',\n): Promise<number | undefined> {\n const spinVersionConfigurations = [\n {\n path: joinPath(basePath, 'ports2', service, 'custom', portEnvName),\n contentPattern: /\\[{\"internal\":(\\d+)}\\]/,\n },\n {\n path: joinPath(basePath, 'ports', service, 'proc', portEnvName),\n contentPattern: /(\\d+)/,\n },\n ]\n for (const config of spinVersionConfigurations) {\n let fileContent: string\n\n try {\n // eslint-disable-next-line no-await-in-loop\n fileContent = await readFile(config.path)\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n continue\n }\n\n const match = config.contentPattern.exec(fileContent)\n if (match && match[1] && !isNaN(parseInt(match[1], 10))) {\n return parseInt(match[1], 10)\n }\n }\n\n return undefined\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Command, Config } from '@oclif/core';
|
|
2
|
+
import { Options } from '@oclif/core/lib/interfaces/plugin.js';
|
|
3
|
+
export declare class ShopifyConfig extends Config {
|
|
4
|
+
constructor(options: Options);
|
|
5
|
+
customPriority(commands: Command.Loadable[]): Command.Loadable | undefined;
|
|
6
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Config } from '@oclif/core';
|
|
2
|
+
export class ShopifyConfig extends Config {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
super(options);
|
|
5
|
+
// eslint-disable-next-line dot-notation
|
|
6
|
+
this['determinePriority'] = this.customPriority;
|
|
7
|
+
}
|
|
8
|
+
customPriority(commands) {
|
|
9
|
+
const oclifPlugins = this.pjson.oclif?.plugins ?? [];
|
|
10
|
+
const commandPlugins = commands.sort((aCommand, bCommand) => {
|
|
11
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
12
|
+
const pluginAliasA = aCommand.pluginAlias ?? 'A-Cannot-Find-This';
|
|
13
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
14
|
+
const pluginAliasB = bCommand.pluginAlias ?? 'B-Cannot-Find-This';
|
|
15
|
+
const aIndex = oclifPlugins.indexOf(pluginAliasA);
|
|
16
|
+
const bIndex = oclifPlugins.indexOf(pluginAliasB);
|
|
17
|
+
// Hydrogen has higher priority than core plugins to override the custom init method.
|
|
18
|
+
if (aCommand.pluginType === 'core' && bCommand.pluginAlias === '@shopify/cli-hydrogen') {
|
|
19
|
+
// If b is hydrogen and a is core sort b first
|
|
20
|
+
return 1;
|
|
21
|
+
}
|
|
22
|
+
if (aCommand.pluginAlias === '@shopify/cli-hydrogen' && bCommand.pluginType === 'core') {
|
|
23
|
+
// If a is hydrogen and b is core sort a first
|
|
24
|
+
return -1;
|
|
25
|
+
}
|
|
26
|
+
// All other cases are the default implementation from the private `determinePriority` method
|
|
27
|
+
// When both plugin types are 'core' plugins sort based on index
|
|
28
|
+
if (aCommand.pluginType === 'core' && bCommand.pluginType === 'core') {
|
|
29
|
+
// If b appears first in the pjson.plugins sort it first
|
|
30
|
+
return aIndex - bIndex;
|
|
31
|
+
}
|
|
32
|
+
// if b is a core plugin and a is not sort b first
|
|
33
|
+
if (bCommand.pluginType === 'core' && aCommand.pluginType !== 'core') {
|
|
34
|
+
return 1;
|
|
35
|
+
}
|
|
36
|
+
// if a is a core plugin and b is not sort a first
|
|
37
|
+
if (aCommand.pluginType === 'core' && bCommand.pluginType !== 'core') {
|
|
38
|
+
return -1;
|
|
39
|
+
}
|
|
40
|
+
// if a is a jit plugin and b is not sort b first
|
|
41
|
+
if (aCommand.pluginType === 'jit' && bCommand.pluginType !== 'jit') {
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
// if b is a jit plugin and a is not sort a first
|
|
45
|
+
if (bCommand.pluginType === 'jit' && aCommand.pluginType !== 'jit') {
|
|
46
|
+
return -1;
|
|
47
|
+
}
|
|
48
|
+
// neither plugin is core, so do not change the order
|
|
49
|
+
return 0;
|
|
50
|
+
});
|
|
51
|
+
return commandPlugins[0];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=custom-oclif-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-oclif-loader.js","sourceRoot":"","sources":["../../../src/public/node/custom-oclif-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,EAAC,MAAM,aAAa,CAAA;AAG3C,MAAM,OAAO,aAAc,SAAQ,MAAM;IACvC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,wCAAwC;QACxC,IAAI,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAAC,cAAc,CAAA;IACjD,CAAC;IAED,cAAc,CAAC,QAA4B;QACzC,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,IAAI,EAAE,CAAA;QACpD,MAAM,cAAc,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,QAAQ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Q,CAAC,UAAU,KAAK,KAAK,EAAE;gBAClE,OAAO,CAAC,CAAC,CAAA;aACV;YAED,qDAAqD;YACrD,OAAO,CAAC,CAAA;QACV,CAAC,CAAC,CAAA;QACF,OAAO,cAAc,CAAC,CAAC,CAAC,CAAA;IAC1B,CAAC;CACF","sourcesContent":["import {Command, Config} from '@oclif/core'\nimport {Options} from '@oclif/core/lib/interfaces/plugin.js'\n\nexport class ShopifyConfig extends Config {\n constructor(options: Options) {\n super(options)\n // eslint-disable-next-line dot-notation\n this['determinePriority'] = this.customPriority\n }\n\n customPriority(commands: Command.Loadable[]): Command.Loadable | undefined {\n const oclifPlugins = this.pjson.oclif?.plugins ?? []\n const commandPlugins = commands.sort((aCommand, bCommand) => {\n // eslint-disable-next-line no-restricted-syntax\n const pluginAliasA = aCommand.pluginAlias ?? 'A-Cannot-Find-This'\n // eslint-disable-next-line no-restricted-syntax\n const pluginAliasB = bCommand.pluginAlias ?? 'B-Cannot-Find-This'\n const aIndex = oclifPlugins.indexOf(pluginAliasA)\n const bIndex = oclifPlugins.indexOf(pluginAliasB)\n\n // Hydrogen has higher priority than core plugins to override the custom init method.\n if (aCommand.pluginType === 'core' && bCommand.pluginAlias === '@shopify/cli-hydrogen') {\n // If b is hydrogen and a is core sort b first\n return 1\n }\n\n if (aCommand.pluginAlias === '@shopify/cli-hydrogen' && bCommand.pluginType === 'core') {\n // If a is hydrogen and b is core sort a first\n return -1\n }\n\n // All other cases are the default implementation from the private `determinePriority` method\n // When both plugin types are 'core' plugins sort based on index\n if (aCommand.pluginType === 'core' && bCommand.pluginType === 'core') {\n // If b appears first in the pjson.plugins sort it first\n return aIndex - bIndex\n }\n\n // if b is a core plugin and a is not sort b first\n if (bCommand.pluginType === 'core' && aCommand.pluginType !== 'core') {\n return 1\n }\n\n // if a is a core plugin and b is not sort a first\n if (aCommand.pluginType === 'core' && bCommand.pluginType !== 'core') {\n return -1\n }\n\n // if a is a jit plugin and b is not sort b first\n if (aCommand.pluginType === 'jit' && bCommand.pluginType !== 'jit') {\n return 1\n }\n\n // if b is a jit plugin and a is not sort a first\n if (bCommand.pluginType === 'jit' && aCommand.pluginType !== 'jit') {\n return -1\n }\n\n // neither plugin is core, so do not change the order\n return 0\n })\n return commandPlugins[0]\n }\n}\n"]}
|
|
@@ -33,3 +33,4 @@ export declare function writeDotEnv(file: DotEnvFile): Promise<void>;
|
|
|
33
33
|
export declare function patchEnvFile(envFileContent: string | null, updatedValues: {
|
|
34
34
|
[key: string]: string | undefined;
|
|
35
35
|
}): string;
|
|
36
|
+
export declare function createDotEnvFileLine(key: string, value?: string, quote?: string): string;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { AbortError } from './error.js';
|
|
2
2
|
import { fileExists, readFile, writeFile } from './fs.js';
|
|
3
3
|
import { outputDebug, outputContent, outputToken } from '../../public/node/output.js';
|
|
4
|
-
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import { parse, stringify } from 'envfile';
|
|
4
|
+
import { parse } from 'dotenv';
|
|
7
5
|
/**
|
|
8
6
|
* Reads and parses a .env file.
|
|
9
7
|
* @param path - Path to the .env file
|
|
@@ -25,7 +23,10 @@ export async function readAndParseDotEnv(path) {
|
|
|
25
23
|
* @param file - .env file to be written.
|
|
26
24
|
*/
|
|
27
25
|
export async function writeDotEnv(file) {
|
|
28
|
-
|
|
26
|
+
const fileContent = Object.entries(file.variables)
|
|
27
|
+
.map(([key, value]) => createDotEnvFileLine(key, value))
|
|
28
|
+
.join('\n');
|
|
29
|
+
await writeFile(file.path, fileContent);
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
32
|
* Given an .env file content, generates a new one with new values
|
|
@@ -35,27 +36,68 @@ export async function writeDotEnv(file) {
|
|
|
35
36
|
*/
|
|
36
37
|
export function patchEnvFile(envFileContent, updatedValues) {
|
|
37
38
|
const outputLines = [];
|
|
38
|
-
const
|
|
39
|
+
const envFileLines = envFileContent === null ? [] : envFileContent.split('\n');
|
|
39
40
|
const alreadyPresentKeys = [];
|
|
40
|
-
|
|
41
|
-
for (const line of
|
|
41
|
+
let multilineVariable;
|
|
42
|
+
for (const line of envFileLines) {
|
|
43
|
+
if (multilineVariable) {
|
|
44
|
+
if (line.endsWith(multilineVariable.quote)) {
|
|
45
|
+
let lineToWrite = createDotEnvFileLine(multilineVariable.key, multilineVariable.value + line.slice(0, -1), multilineVariable.quote);
|
|
46
|
+
const newValue = updatedValues[multilineVariable.key];
|
|
47
|
+
if (newValue) {
|
|
48
|
+
alreadyPresentKeys.push(multilineVariable.key);
|
|
49
|
+
lineToWrite = createDotEnvFileLine(multilineVariable.key, newValue);
|
|
50
|
+
}
|
|
51
|
+
outputLines.push(lineToWrite);
|
|
52
|
+
multilineVariable = undefined;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
multilineVariable.value += `${line}\n`;
|
|
56
|
+
}
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
42
59
|
const match = line.match(/^([^=:#]+?)[=:](.*)/);
|
|
43
60
|
let lineToWrite = line;
|
|
44
61
|
if (match) {
|
|
45
62
|
const key = match[1].trim();
|
|
63
|
+
const value = (match[2] || '').trim();
|
|
64
|
+
if (/^["'`]/.test(value) && !value.endsWith(value[0])) {
|
|
65
|
+
multilineVariable = {
|
|
66
|
+
key,
|
|
67
|
+
value: `${value.slice(1)}\n`,
|
|
68
|
+
quote: value[0],
|
|
69
|
+
};
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
46
72
|
const newValue = updatedValues[key];
|
|
47
73
|
if (newValue) {
|
|
48
74
|
alreadyPresentKeys.push(key);
|
|
49
|
-
lineToWrite =
|
|
75
|
+
lineToWrite = createDotEnvFileLine(key, newValue);
|
|
50
76
|
}
|
|
51
77
|
}
|
|
52
78
|
outputLines.push(lineToWrite);
|
|
53
79
|
}
|
|
80
|
+
if (multilineVariable) {
|
|
81
|
+
throw new AbortError(`Multi-line environment variable '${multilineVariable.key}' is not properly enclosed.`);
|
|
82
|
+
}
|
|
54
83
|
for (const [patchKey, updatedValue] of Object.entries(updatedValues)) {
|
|
55
84
|
if (!alreadyPresentKeys.includes(patchKey)) {
|
|
56
|
-
outputLines.push(
|
|
85
|
+
outputLines.push(createDotEnvFileLine(patchKey, updatedValue));
|
|
57
86
|
}
|
|
58
87
|
}
|
|
59
88
|
return outputLines.join('\n');
|
|
60
89
|
}
|
|
90
|
+
export function createDotEnvFileLine(key, value, quote) {
|
|
91
|
+
if (quote) {
|
|
92
|
+
return `${key}=${quote}${value}${quote}`;
|
|
93
|
+
}
|
|
94
|
+
if (value && value.includes('\n')) {
|
|
95
|
+
const quoteCharacter = ['"', "'", '`'].find((char) => !value.includes(char));
|
|
96
|
+
if (!quoteCharacter) {
|
|
97
|
+
throw new AbortError(`The environment file patch has an env value that can't be surrounded by quotes: ${value}`);
|
|
98
|
+
}
|
|
99
|
+
return `${key}=${quoteCharacter}${value}${quoteCharacter}`;
|
|
100
|
+
}
|
|
101
|
+
return `${key}=${value}`;
|
|
102
|
+
}
|
|
61
103
|
//# sourceMappingURL=dot-env.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dot-env.js","sourceRoot":"","sources":["../../../src/public/node/dot-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAA;AACrC,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AACvD,OAAO,EAAC,WAAW,EAAE,aAAa,EAAE,WAAW,EAAC,MAAM,6BAA6B,CAAA;AACnF,
|
|
1
|
+
{"version":3,"file":"dot-env.js","sourceRoot":"","sources":["../../../src/public/node/dot-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAA;AACrC,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AACvD,OAAO,EAAC,WAAW,EAAE,aAAa,EAAE,WAAW,EAAC,MAAM,6BAA6B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E,CAAC,CAAA;SACjH;QAED,OAAO,GAAG,GAAG,IAAI,cAAc,GAAG,KAAK,GAAG,cAAc,EAAE,CAAA;KAC3D;IACD,OAAO,GAAG,GAAG,IAAI,KAAK,EAAE,CAAA;AAC1B,CAAC","sourcesContent":["import {AbortError} from './error.js'\nimport {fileExists, readFile, writeFile} from './fs.js'\nimport {outputDebug, outputContent, outputToken} from '../../public/node/output.js'\nimport {parse} from 'dotenv'\n\n/**\n * This interface represents a .env file.\n */\nexport interface DotEnvFile {\n /**\n * Path to the .env file.\n */\n path: string\n /**\n * Variables of the .env file.\n */\n variables: {[name: string]: string}\n}\n\n/**\n * Reads and parses a .env file.\n * @param path - Path to the .env file\n * @returns An in-memory representation of the .env file.\n */\nexport async function readAndParseDotEnv(path: string): Promise<DotEnvFile> {\n outputDebug(outputContent`Reading the .env file at ${outputToken.path(path)}`)\n if (!(await fileExists(path))) {\n throw new AbortError(`The environment file at ${path} does not exist.`)\n }\n const content = await readFile(path)\n return {\n path,\n variables: parse(content),\n }\n}\n\n/**\n * Writes a .env file to disk.\n * @param file - .env file to be written.\n */\nexport async function writeDotEnv(file: DotEnvFile): Promise<void> {\n const fileContent = Object.entries(file.variables)\n .map(([key, value]) => createDotEnvFileLine(key, value))\n .join('\\n')\n\n await writeFile(file.path, fileContent)\n}\n\n/**\n * Given an .env file content, generates a new one with new values\n * without removing already existing lines.\n * @param envFileContent - .env file contents.\n * @param updatedValues - object containing new env variables values.\n */\nexport function patchEnvFile(\n envFileContent: string | null,\n updatedValues: {[key: string]: string | undefined},\n): string {\n const outputLines: string[] = []\n const envFileLines = envFileContent === null ? [] : envFileContent.split('\\n')\n\n const alreadyPresentKeys: string[] = []\n\n let multilineVariable:\n | {\n key: string\n value: string\n quote: string\n }\n | undefined\n\n for (const line of envFileLines) {\n if (multilineVariable) {\n if (line.endsWith(multilineVariable.quote)) {\n let lineToWrite = createDotEnvFileLine(\n multilineVariable.key,\n multilineVariable.value + line.slice(0, -1),\n multilineVariable.quote,\n )\n const newValue = updatedValues[multilineVariable.key]\n if (newValue) {\n alreadyPresentKeys.push(multilineVariable.key)\n lineToWrite = createDotEnvFileLine(multilineVariable.key, newValue)\n }\n outputLines.push(lineToWrite)\n multilineVariable = undefined\n } else {\n multilineVariable.value += `${line}\\n`\n }\n continue\n }\n\n const match = line.match(/^([^=:#]+?)[=:](.*)/)\n let lineToWrite = line\n\n if (match) {\n const key = match[1]!.trim()\n const value = (match[2] || '')!.trim()\n\n if (/^[\"'`]/.test(value) && !value.endsWith(value[0]!)) {\n multilineVariable = {\n key,\n value: `${value.slice(1)}\\n`,\n quote: value[0]!,\n }\n continue\n }\n\n const newValue = updatedValues[key]\n if (newValue) {\n alreadyPresentKeys.push(key)\n lineToWrite = createDotEnvFileLine(key, newValue)\n }\n }\n\n outputLines.push(lineToWrite)\n }\n\n if (multilineVariable) {\n throw new AbortError(`Multi-line environment variable '${multilineVariable.key}' is not properly enclosed.`)\n }\n\n for (const [patchKey, updatedValue] of Object.entries(updatedValues)) {\n if (!alreadyPresentKeys.includes(patchKey)) {\n outputLines.push(createDotEnvFileLine(patchKey, updatedValue))\n }\n }\n\n return outputLines.join('\\n')\n}\n\nexport function createDotEnvFileLine(key: string, value?: string, quote?: string): string {\n if (quote) {\n return `${key}=${quote}${value}${quote}`\n }\n if (value && value.includes('\\n')) {\n const quoteCharacter = ['\"', \"'\", '`'].find((char) => !value.includes(char))\n\n if (!quoteCharacter) {\n throw new AbortError(`The environment file patch has an env value that can't be surrounded by quotes: ${value}`)\n }\n\n return `${key}=${quoteCharacter}${value}${quoteCharacter}`\n }\n return `${key}=${value}`\n}\n"]}
|