@shopify/cli-kit 3.61.2 → 3.63.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/api/headers.js +1 -0
- package/dist/private/node/api/headers.js.map +1 -1
- package/dist/private/node/conf-store.d.ts +2 -0
- package/dist/private/node/conf-store.js.map +1 -1
- package/dist/private/node/content-tokens.d.ts +2 -1
- package/dist/private/node/content-tokens.js +3 -2
- package/dist/private/node/content-tokens.js.map +1 -1
- package/dist/private/node/context/utilities.js +9 -0
- package/dist/private/node/context/utilities.js.map +1 -1
- package/dist/private/node/ui/components/ConcurrentOutput.d.ts +2 -1
- package/dist/private/node/ui/components/ConcurrentOutput.js +5 -4
- package/dist/private/node/ui/components/ConcurrentOutput.js.map +1 -1
- package/dist/private/node/ui/components/ConcurrentOutput.test.js +48 -3
- package/dist/private/node/ui/components/ConcurrentOutput.test.js.map +1 -1
- package/dist/public/common/lang.d.ts +0 -1
- package/dist/public/common/lang.js +0 -1
- package/dist/public/common/lang.js.map +1 -1
- package/dist/public/common/retry.d.ts +1 -0
- package/dist/public/common/retry.js +1 -0
- package/dist/public/common/retry.js.map +1 -1
- package/dist/public/common/ts/deep-required.d.ts +1 -1
- package/dist/public/common/ts/deep-required.js.map +1 -1
- package/dist/public/common/ts/pick-by-prefix.d.ts +1 -1
- package/dist/public/common/ts/pick-by-prefix.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/business-platform.d.ts +11 -0
- package/dist/public/node/api/business-platform.js +33 -8
- package/dist/public/node/api/business-platform.js.map +1 -1
- package/dist/public/node/api/graphql.d.ts +19 -4
- package/dist/public/node/api/graphql.js +30 -7
- package/dist/public/node/api/graphql.js.map +1 -1
- package/dist/public/node/api/partners.d.ts +11 -0
- package/dist/public/node/api/partners.js +36 -8
- package/dist/public/node/api/partners.js.map +1 -1
- package/dist/public/node/base-command.d.ts +3 -2
- package/dist/public/node/base-command.js +3 -0
- package/dist/public/node/base-command.js.map +1 -1
- package/dist/public/node/cli.js +1 -1
- package/dist/public/node/cli.js.map +1 -1
- package/dist/public/node/context/local.js +3 -0
- package/dist/public/node/context/local.js.map +1 -1
- package/dist/public/node/custom-oclif-loader.d.ts +0 -6
- package/dist/public/node/custom-oclif-loader.js +1 -15
- package/dist/public/node/custom-oclif-loader.js.map +1 -1
- package/dist/public/node/dot-env.js.map +1 -1
- package/dist/public/node/fs.d.ts +0 -1
- package/dist/public/node/git.d.ts +2 -0
- package/dist/public/node/git.js +2 -0
- package/dist/public/node/git.js.map +1 -1
- package/dist/public/node/is-global.d.ts +3 -5
- package/dist/public/node/is-global.js +22 -8
- package/dist/public/node/is-global.js.map +1 -1
- package/dist/public/node/json-schema.d.ts +27 -0
- package/dist/public/node/json-schema.js +197 -0
- package/dist/public/node/json-schema.js.map +1 -0
- package/dist/public/node/logs.d.ts +1 -1
- package/dist/public/node/logs.js +3 -1
- package/dist/public/node/logs.js.map +1 -1
- package/dist/public/node/monorail.d.ts +1 -1
- package/dist/public/node/monorail.js.map +1 -1
- package/dist/public/node/node-package-manager.d.ts +12 -1
- package/dist/public/node/node-package-manager.js +32 -15
- package/dist/public/node/node-package-manager.js.map +1 -1
- package/dist/public/node/output.d.ts +2 -1
- package/dist/public/node/output.js +5 -2
- package/dist/public/node/output.js.map +1 -1
- package/dist/public/node/path.d.ts +14 -0
- package/dist/public/node/path.js +27 -0
- package/dist/public/node/path.js.map +1 -1
- package/dist/public/node/ruby.d.ts +2 -0
- package/dist/public/node/ruby.js +2 -0
- package/dist/public/node/ruby.js.map +1 -1
- package/dist/public/node/schema.d.ts +20 -1
- package/dist/public/node/schema.js.map +1 -1
- package/dist/public/node/system.d.ts +4 -1
- package/dist/public/node/system.js +7 -1
- package/dist/public/node/system.js.map +1 -1
- package/dist/public/node/tcp.d.ts +1 -1
- package/dist/public/node/tcp.js +1 -1
- package/dist/public/node/tcp.js.map +1 -1
- package/dist/public/node/tree-kill.js +0 -1
- package/dist/public/node/tree-kill.js.map +1 -1
- package/dist/public/node/ui.d.ts +8 -3
- package/dist/public/node/ui.js +7 -4
- package/dist/public/node/ui.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fileExistsSync } from './fs.js';
|
|
2
|
-
import { cwd, joinPath } from './path.js';
|
|
2
|
+
import { cwd, joinPath, sniffForPath } from './path.js';
|
|
3
3
|
import { Config } from '@oclif/core';
|
|
4
4
|
export class ShopifyConfig extends Config {
|
|
5
5
|
constructor(options) {
|
|
@@ -63,18 +63,4 @@ export class ShopifyConfig extends Config {
|
|
|
63
63
|
return commandPlugins[0];
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Tries to get the value of the `--path` argument, if provided.
|
|
68
|
-
*
|
|
69
|
-
* @returns The value of the `--path` argument, if provided.
|
|
70
|
-
*/
|
|
71
|
-
export function sniffForPath() {
|
|
72
|
-
const pathFlagIndex = process.argv.indexOf('--path');
|
|
73
|
-
if (pathFlagIndex === -1)
|
|
74
|
-
return;
|
|
75
|
-
const pathFlag = process.argv[pathFlagIndex + 1];
|
|
76
|
-
if (!pathFlag || pathFlag.startsWith('-'))
|
|
77
|
-
return;
|
|
78
|
-
return pathFlag;
|
|
79
|
-
}
|
|
80
66
|
//# sourceMappingURL=custom-oclif-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-oclif-loader.js","sourceRoot":"","sources":["../../../src/public/node/custom-oclif-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,SAAS,CAAA;AACtC,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAC,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"custom-oclif-loader.js","sourceRoot":"","sources":["../../../src/public/node/custom-oclif-loader.ts"],"names":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uB,EAAE;gBACtF,8CAA8C;gBAC9C,OAAO,CAAC,CAAA;aACT;YAED,IAAI,QAAQ,CAAC,WAAW,KAAK,uBAAuB,IAAI,QAAQ,CAAC,UAAU,KAAK,MAAM,EAAE;gBACtF,8CAA8C;gBAC9C,OAAO,CAAC,CAAC,CAAA;aACV;YAED,6FAA6F;YAC7F,gEAAgE;YAChE,IAAI,QAAQ,CAAC,UAAU,KAAK,MAAM,IAAI,QAAQ,CAAC,UAAU,KAAK,MAAM,EAAE;gBACpE,wDAAwD;gBACxD,OAAO,MAAM,GAAG,MAAM,CAAA;aACvB;YAED,kDAAkD;YAClD,IAAI,QAAQ,CAAC,UAAU,KAAK,MAAM,IAAI,QAAQ,CAAC,UAAU,KAAK,MAAM,EAAE;gBACpE,OAAO,CAAC,CAAA;aACT;YAED,kDAAkD;YAClD,IAAI,QAAQ,CAAC,UAAU,KAAK,MAAM,IAAI,QAAQ,CAAC,UAAU,KAAK,MAAM,EAAE;gBACpE,OAAO,CAAC,CAAC,CAAA;aACV;YAED,iDAAiD;YACjD,IAAI,QAAQ,CAAC,UAAU,KAAK,KAAK,IAAI,QAAQ,CAAC,UAAU,KAAK,KAAK,EAAE;gBAClE,OAAO,CAAC,CAAA;aACT;YAED,iDAAiD;YACjD,IAAI,QAAQ,CAAC,UAAU,KAAK,KAAK,IAAI,QAAQ,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 {fileExistsSync} from './fs.js'\nimport {cwd, joinPath, sniffForPath} from './path.js'\nimport {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 const path = sniffForPath() ?? cwd()\n if (fileExistsSync(joinPath(`${path}`, 'package.json'))) {\n // Hydrogen is bundled, but we still want to support loading it as an external plugin for two reasons:\n // 1. To allow users to use an older version of Hydrogen. (to not force upgrades)\n // 2. To allow the Hydrogen team to load a local version for testing.\n options.pluginAdditions = {\n core: ['@shopify/cli-hydrogen'],\n path,\n }\n }\n super(options)\n\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 // If there is an external cli-hydrogen plugin, its commands should take priority over bundled ('core') commands\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"]}
|
|
@@ -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,OAAO,EAAC,KAAK,EAAC,MAAM,QAAQ,CAAA;AAgB5B;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,IAAY;IACnD,WAAW,CAAC,aAAa,CAAA,4BAA4B,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAC9E,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE;QAC7B,MAAM,IAAI,UAAU,CAAC,2BAA2B,IAAI,kBAAkB,CAAC,CAAA;KACxE;IACD,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAA;IACpC,OAAO;QACL,IAAI;QACJ,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC;KAC1B,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAgB;IAChD,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC;SAC/C,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,oBAAoB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;SACvD,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;AACz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AI,KAAK,GAAG,KAAK,GAAG,KAAK,EAAE,CAAA;KACzC;IACD,IAAI,KAAK,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;QACjC,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;QAE5E,IAAI,CAAC,cAAc,EAAE;YACnB,MAAM,IAAI,UAAU,CAAC,mFAAmF,KAAK,EAAE,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"]}
|
package/dist/public/node/fs.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
4
3
|
import { RandomNameFamily } from '../common/string.js';
|
|
5
4
|
import { OverloadParameters } from '../../private/common/ts/overloaded-parameters.js';
|
|
6
5
|
import { findUp as internalFindUp } from 'find-up';
|
|
@@ -14,6 +14,7 @@ export declare function initializeGitRepository(directory: string, initialBranch
|
|
|
14
14
|
*
|
|
15
15
|
* @param directory - The absolute path to the directory containing the files.
|
|
16
16
|
* @param files - The list of files to check against.
|
|
17
|
+
* @returns Files ignored by the lockfile.
|
|
17
18
|
*/
|
|
18
19
|
export declare function checkIfIgnoredInGitRepository(directory: string, files: string[]): Promise<string[]>;
|
|
19
20
|
export interface GitIgnoreTemplate {
|
|
@@ -109,5 +110,6 @@ export declare function ensureIsClean(directory?: string): Promise<void>;
|
|
|
109
110
|
* Returns true if the .git directory tree is clean (no uncommitted changes).
|
|
110
111
|
*
|
|
111
112
|
* @param directory - The directory to check.
|
|
113
|
+
* @returns True is the .git directory is clean.
|
|
112
114
|
*/
|
|
113
115
|
export declare function isClean(directory?: string): Promise<boolean>;
|
package/dist/public/node/git.js
CHANGED
|
@@ -28,6 +28,7 @@ export async function initializeGitRepository(directory, initialBranch = 'main')
|
|
|
28
28
|
*
|
|
29
29
|
* @param directory - The absolute path to the directory containing the files.
|
|
30
30
|
* @param files - The list of files to check against.
|
|
31
|
+
* @returns Files ignored by the lockfile.
|
|
31
32
|
*/
|
|
32
33
|
export async function checkIfIgnoredInGitRepository(directory, files) {
|
|
33
34
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -222,6 +223,7 @@ export async function ensureIsClean(directory) {
|
|
|
222
223
|
* Returns true if the .git directory tree is clean (no uncommitted changes).
|
|
223
224
|
*
|
|
224
225
|
* @param directory - The directory to check.
|
|
226
|
+
* @returns True is the .git directory is clean.
|
|
225
227
|
*/
|
|
226
228
|
export async function isClean(directory) {
|
|
227
229
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../../src/public/node/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,qBAAqB,EAAC,MAAM,oBAAoB,CAAA;AAChE,OAAO,EAAC,cAAc,EAAC,MAAM,SAAS,CAAA;AACtC,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAA;AACrC,OAAO,EAAC,GAAG,EAAC,MAAM,WAAW,CAAA;AAC7B,OAAO,EAAC,YAAY,EAAC,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAC,aAAa,EAAE,WAAW,EAAE,WAAW,EAAC,MAAM,6BAA6B,CAAA;AACnF,OAAO,GAAoF,MAAM,YAAY,CAAA;AAE7G;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,SAAiB,EAAE,aAAa,GAAG,MAAM;IACrF,WAAW,CAAC,aAAa,CAAA,kCAAkC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAC5F,MAAM,yBAAyB,EAAE,CAAA;IACjC,gHAAgH;IAChH,6DAA6D;IAC7D,aAAa;IACb,MAAM,IAAI,GAAG,GAAG,CAAC,SAAS,CAAC,CAAA;IAC3B,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;IACjB,MAAM,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAA;AAC/C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CAAC,SAAiB,E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;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,SAAkB;IAC/D,6DAA6D;IAC7D,aAAa;IACb,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,EAAC,OAAO,EAAE,SAAS,EAAC,CAAC,CAAC,WAAW,EAAE,CAAC,EAAE;QACpD,MAAM,IAAI,wBAAwB,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,IAAI,GAAG,EAAE,CAAC,yBAAyB,CAAC,CAAA;KACrG;AACH,CAAC;AAED,MAAM,OAAO,yBAA0B,SAAQ,UAAU;CAAG;AAC5D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,SAAkB;IACpD,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE;QAC/B,MAAM,IAAI,yBAAyB,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,IAAI,GAAG,EAAE,CAAC,+BAA+B,CAAC,CAAA;KAC5G;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,SAAkB;IAC9C,6DAA6D;IAC7D,aAAa;IACb,OAAO,CAAC,MAAM,GAAG,CAAC,EAAC,OAAO,EAAE,SAAS,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAA;AAC7D,CAAC","sourcesContent":["import {hasGit, isTerminalInteractive} from './context/local.js'\nimport {appendFileSync} from './fs.js'\nimport {AbortError} from './error.js'\nimport {cwd} from './path.js'\nimport {runWithTimer} from './metadata.js'\nimport {outputContent, outputToken, outputDebug} from '../../public/node/output.js'\nimport git, {TaskOptions, SimpleGitProgressEvent, DefaultLogFields, ListLogLine, SimpleGit} from 'simple-git'\n\n/**\n * Initialize a git repository at the given directory.\n *\n * @param directory - The directory where the git repository will be initialized.\n * @param initialBranch - The name of the initial branch.\n */\nexport async function initializeGitRepository(directory: string, initialBranch = 'main'): Promise<void> {\n outputDebug(outputContent`Initializing git repository at ${outputToken.path(directory)}...`)\n await ensureGitIsPresentOrAbort()\n // We use init and checkout instead of `init --initial-branch` because the latter is only supported in git 2.28+\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const repo = git(directory)\n await repo.init()\n await repo.checkoutLocalBranch(initialBranch)\n}\n\n/**\n * Given a Git repository and a list of absolute paths to files contained\n * in the repository, it filters and returns the files that are ignored\n * by the .gitignore.\n *\n * @param directory - The absolute path to the directory containing the files.\n * @param files - The list of files to check against.\n */\nexport async function checkIfIgnoredInGitRepository(directory: string, files: string[]): Promise<string[]> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const repo = git(directory)\n const ignoredLockfile = await repo.checkIgnore(files)\n return ignoredLockfile\n}\n\nexport interface GitIgnoreTemplate {\n [section: string]: string[]\n}\n/**\n * Create a .gitignore file in the given directory.\n *\n * @param directory - The directory where the .gitignore file will be created.\n * @param template - The template to use to create the .gitignore file.\n */\nexport function createGitIgnore(directory: string, template: GitIgnoreTemplate): void {\n outputDebug(outputContent`Creating .gitignore at ${outputToken.path(directory)}...`)\n const filePath = `${directory}/.gitignore`\n\n let fileContent = ''\n for (const [section, lines] of Object.entries(template)) {\n fileContent += `# ${section}\\n`\n fileContent += `${lines.join('\\n')}\\n\\n`\n }\n\n appendFileSync(filePath, fileContent)\n}\n\n/**\n * Options to use when cloning a git repository.\n *\n * @param repoUrl - The URL of the repository to clone.\n * @param destination - The directory where the repository will be cloned.\n * @param progressUpdater - A function that will be called with the progress of the clone.\n * @param shallow - Whether to clone the repository shallowly.\n * @param latestTag - Whether to clone the latest tag instead of the default branch.\n */\nexport interface GitCloneOptions {\n repoUrl: string\n destination: string\n progressUpdater?: (statusString: string) => void\n shallow?: boolean\n latestTag?: boolean\n}\n/**\n * Clone a git repository.\n *\n * @param cloneOptions - The options to use to clone the repository.\n * @returns A promise that resolves when the clone is complete.\n */\nexport async function downloadGitRepository(cloneOptions: GitCloneOptions): Promise<void> {\n return runWithTimer('cmd_all_timing_network_ms')(async () => {\n const {repoUrl, destination, progressUpdater, shallow, latestTag} = cloneOptions\n outputDebug(outputContent`Git-cloning repository ${repoUrl} into ${outputToken.path(destination)}...`)\n await ensureGitIsPresentOrAbort()\n const [repository, branch] = repoUrl.split('#')\n const options: TaskOptions = {'--recurse-submodules': null}\n\n if (branch && latestTag) {\n throw new AbortError(\"Error cloning the repository. Git can't clone the latest release with a 'branch'.\")\n }\n if (branch) {\n options['--branch'] = branch\n }\n\n if (shallow && latestTag) {\n throw new AbortError(\n \"Error cloning the repository. Git can't clone the latest release with the 'shallow' property.\",\n )\n }\n if (shallow) {\n options['--depth'] = 1\n }\n\n const progress = ({stage, progress, processed, total}: SimpleGitProgressEvent) => {\n const updateString = `${stage}, ${processed}/${total} objects (${progress}% complete)`\n if (progressUpdater) progressUpdater(updateString)\n }\n\n const simpleGitOptions = {\n progress,\n ...(!isTerminalInteractive() && {config: ['core.askpass=true']}),\n }\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n await git(simpleGitOptions).clone(repository!, destination, options)\n\n if (latestTag) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const localGitRepository = git(destination)\n const latestTag = await getLocalLatestTag(localGitRepository, repoUrl)\n await localGitRepository.checkout(latestTag)\n }\n } catch (err) {\n if (err instanceof Error) {\n const abortError = new AbortError(err.message)\n abortError.stack = err.stack\n throw abortError\n }\n throw err\n }\n })\n}\n\n/**\n * Get the most recent tag of a local git repository.\n *\n * @param repository - The local git repository.\n * @param repoUrl - The URL of the repository.\n * @returns The most recent tag of the repository.\n */\nasync function getLocalLatestTag(repository: SimpleGit, repoUrl: string): Promise<string> {\n const latest = (await repository.tags()).latest\n\n if (!latest) {\n throw new AbortError(`Couldn't obtain the most recent tag of the repository ${repoUrl}`)\n }\n\n return latest\n}\n\n/**\n * Get the latest commit of a git repository.\n *\n * @param directory - The directory of the git repository.\n * @returns The latest commit of the repository.\n */\nexport async function getLatestGitCommit(directory?: string): Promise<DefaultLogFields & ListLogLine> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const logs = await git({baseDir: directory}).log({\n maxCount: 1,\n })\n if (!logs.latest) {\n throw new AbortError(\n 'Must have at least one commit to run command',\n outputContent`Run ${outputToken.genericShellCommand(\n \"git commit -m 'Initial commit'\",\n )} to create your first commit.`,\n )\n }\n return logs.latest\n}\n\n/**\n * Add all files to the git index from the given directory.\n *\n * @param directory - The directory where the git repository is located.\n * @returns A promise that resolves when the files are added to the index.\n */\nexport async function addAllToGitFromDirectory(directory?: string): Promise<void> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const simpleGit = git({baseDir: directory})\n await simpleGit.raw('add', '--all')\n}\n\nexport interface CreateGitCommitOptions {\n directory?: string\n author?: string\n}\n\n/**\n * Create a git commit.\n *\n * @param message - The message of the commit.\n * @param options - The options to use to create the commit.\n * @returns The hash of the created commit.\n */\nexport async function createGitCommit(message: string, options?: CreateGitCommitOptions): Promise<string> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const simpleGit = git({baseDir: options?.directory})\n\n const commitOptions = options?.author ? {'--author': options.author} : undefined\n const result = await simpleGit.commit(message, commitOptions)\n\n return result.commit\n}\n\n/**\n * Get the HEAD symbolic reference of a git repository.\n *\n * @param directory - The directory of the git repository.\n * @returns The HEAD symbolic reference of the repository.\n */\nexport async function getHeadSymbolicRef(directory?: string): Promise<string> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const ref = await git({baseDir: directory}).raw('symbolic-ref', '-q', 'HEAD')\n if (!ref) {\n throw new AbortError(\n \"Git HEAD can't be detached to run command\",\n outputContent`Run ${outputToken.genericShellCommand(\n 'git checkout [branchName]',\n )} to reattach HEAD or see git ${outputToken.link(\n 'documentation',\n 'https://git-scm.com/book/en/v2/Git-Internals-Git-References',\n )} for more details`,\n )\n }\n return ref.trim()\n}\n\n/**\n * If \"git\" is not present in the environment it throws\n * an abort error.\n */\nexport async function ensureGitIsPresentOrAbort(): Promise<void> {\n if (!(await hasGit())) {\n throw new AbortError(\n `Git is necessary in the environment to continue`,\n outputContent`Install ${outputToken.link(\n 'git',\n 'https://git-scm.com/book/en/v2/Getting-Started-Installing-Git',\n )}`,\n )\n }\n}\n\nexport class OutsideGitDirectoryError extends AbortError {}\n/**\n * If command run from outside a .git directory tree\n * it throws an abort error.\n *\n * @param directory - The directory to check.\n */\nexport async function ensureInsideGitDirectory(directory?: string): Promise<void> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (!(await git({baseDir: directory}).checkIsRepo())) {\n throw new OutsideGitDirectoryError(`${outputToken.path(directory || cwd())} is not a Git directory`)\n }\n}\n\nexport class GitDirectoryNotCleanError extends AbortError {}\n/**\n * If the .git directory tree is not clean (has uncommitted changes)\n * it throws an abort error.\n *\n * @param directory - The directory to check.\n */\nexport async function ensureIsClean(directory?: string): Promise<void> {\n if (!(await isClean(directory))) {\n throw new GitDirectoryNotCleanError(`${outputToken.path(directory || cwd())} is not a clean Git directory`)\n }\n}\n\n/**\n * Returns true if the .git directory tree is clean (no uncommitted changes).\n *\n * @param directory - The directory to check.\n */\nexport async function isClean(directory?: string): Promise<boolean> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return (await git({baseDir: directory}).status()).isClean()\n}\n"]}
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../../src/public/node/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,qBAAqB,EAAC,MAAM,oBAAoB,CAAA;AAChE,OAAO,EAAC,cAAc,EAAC,MAAM,SAAS,CAAA;AACtC,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAA;AACrC,OAAO,EAAC,GAAG,EAAC,MAAM,WAAW,CAAA;AAC7B,OAAO,EAAC,YAAY,EA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AA+B,CAAC,CAAA;KAC5G;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,SAAkB;IAC9C,6DAA6D;IAC7D,aAAa;IACb,OAAO,CAAC,MAAM,GAAG,CAAC,EAAC,OAAO,EAAE,SAAS,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAA;AAC7D,CAAC","sourcesContent":["import {hasGit, isTerminalInteractive} from './context/local.js'\nimport {appendFileSync} from './fs.js'\nimport {AbortError} from './error.js'\nimport {cwd} from './path.js'\nimport {runWithTimer} from './metadata.js'\nimport {outputContent, outputToken, outputDebug} from '../../public/node/output.js'\nimport git, {TaskOptions, SimpleGitProgressEvent, DefaultLogFields, ListLogLine, SimpleGit} from 'simple-git'\n\n/**\n * Initialize a git repository at the given directory.\n *\n * @param directory - The directory where the git repository will be initialized.\n * @param initialBranch - The name of the initial branch.\n */\nexport async function initializeGitRepository(directory: string, initialBranch = 'main'): Promise<void> {\n outputDebug(outputContent`Initializing git repository at ${outputToken.path(directory)}...`)\n await ensureGitIsPresentOrAbort()\n // We use init and checkout instead of `init --initial-branch` because the latter is only supported in git 2.28+\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const repo = git(directory)\n await repo.init()\n await repo.checkoutLocalBranch(initialBranch)\n}\n\n/**\n * Given a Git repository and a list of absolute paths to files contained\n * in the repository, it filters and returns the files that are ignored\n * by the .gitignore.\n *\n * @param directory - The absolute path to the directory containing the files.\n * @param files - The list of files to check against.\n * @returns Files ignored by the lockfile.\n */\nexport async function checkIfIgnoredInGitRepository(directory: string, files: string[]): Promise<string[]> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const repo = git(directory)\n const ignoredLockfile = await repo.checkIgnore(files)\n return ignoredLockfile\n}\n\nexport interface GitIgnoreTemplate {\n [section: string]: string[]\n}\n/**\n * Create a .gitignore file in the given directory.\n *\n * @param directory - The directory where the .gitignore file will be created.\n * @param template - The template to use to create the .gitignore file.\n */\nexport function createGitIgnore(directory: string, template: GitIgnoreTemplate): void {\n outputDebug(outputContent`Creating .gitignore at ${outputToken.path(directory)}...`)\n const filePath = `${directory}/.gitignore`\n\n let fileContent = ''\n for (const [section, lines] of Object.entries(template)) {\n fileContent += `# ${section}\\n`\n fileContent += `${lines.join('\\n')}\\n\\n`\n }\n\n appendFileSync(filePath, fileContent)\n}\n\n/**\n * Options to use when cloning a git repository.\n *\n * @param repoUrl - The URL of the repository to clone.\n * @param destination - The directory where the repository will be cloned.\n * @param progressUpdater - A function that will be called with the progress of the clone.\n * @param shallow - Whether to clone the repository shallowly.\n * @param latestTag - Whether to clone the latest tag instead of the default branch.\n */\nexport interface GitCloneOptions {\n repoUrl: string\n destination: string\n progressUpdater?: (statusString: string) => void\n shallow?: boolean\n latestTag?: boolean\n}\n/**\n * Clone a git repository.\n *\n * @param cloneOptions - The options to use to clone the repository.\n * @returns A promise that resolves when the clone is complete.\n */\nexport async function downloadGitRepository(cloneOptions: GitCloneOptions): Promise<void> {\n return runWithTimer('cmd_all_timing_network_ms')(async () => {\n const {repoUrl, destination, progressUpdater, shallow, latestTag} = cloneOptions\n outputDebug(outputContent`Git-cloning repository ${repoUrl} into ${outputToken.path(destination)}...`)\n await ensureGitIsPresentOrAbort()\n const [repository, branch] = repoUrl.split('#')\n const options: TaskOptions = {'--recurse-submodules': null}\n\n if (branch && latestTag) {\n throw new AbortError(\"Error cloning the repository. Git can't clone the latest release with a 'branch'.\")\n }\n if (branch) {\n options['--branch'] = branch\n }\n\n if (shallow && latestTag) {\n throw new AbortError(\n \"Error cloning the repository. Git can't clone the latest release with the 'shallow' property.\",\n )\n }\n if (shallow) {\n options['--depth'] = 1\n }\n\n const progress = ({stage, progress, processed, total}: SimpleGitProgressEvent) => {\n const updateString = `${stage}, ${processed}/${total} objects (${progress}% complete)`\n if (progressUpdater) progressUpdater(updateString)\n }\n\n const simpleGitOptions = {\n progress,\n ...(!isTerminalInteractive() && {config: ['core.askpass=true']}),\n }\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n await git(simpleGitOptions).clone(repository!, destination, options)\n\n if (latestTag) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const localGitRepository = git(destination)\n const latestTag = await getLocalLatestTag(localGitRepository, repoUrl)\n await localGitRepository.checkout(latestTag)\n }\n } catch (err) {\n if (err instanceof Error) {\n const abortError = new AbortError(err.message)\n abortError.stack = err.stack\n throw abortError\n }\n throw err\n }\n })\n}\n\n/**\n * Get the most recent tag of a local git repository.\n *\n * @param repository - The local git repository.\n * @param repoUrl - The URL of the repository.\n * @returns The most recent tag of the repository.\n */\nasync function getLocalLatestTag(repository: SimpleGit, repoUrl: string): Promise<string> {\n const latest = (await repository.tags()).latest\n\n if (!latest) {\n throw new AbortError(`Couldn't obtain the most recent tag of the repository ${repoUrl}`)\n }\n\n return latest\n}\n\n/**\n * Get the latest commit of a git repository.\n *\n * @param directory - The directory of the git repository.\n * @returns The latest commit of the repository.\n */\nexport async function getLatestGitCommit(directory?: string): Promise<DefaultLogFields & ListLogLine> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const logs = await git({baseDir: directory}).log({\n maxCount: 1,\n })\n if (!logs.latest) {\n throw new AbortError(\n 'Must have at least one commit to run command',\n outputContent`Run ${outputToken.genericShellCommand(\n \"git commit -m 'Initial commit'\",\n )} to create your first commit.`,\n )\n }\n return logs.latest\n}\n\n/**\n * Add all files to the git index from the given directory.\n *\n * @param directory - The directory where the git repository is located.\n * @returns A promise that resolves when the files are added to the index.\n */\nexport async function addAllToGitFromDirectory(directory?: string): Promise<void> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const simpleGit = git({baseDir: directory})\n await simpleGit.raw('add', '--all')\n}\n\nexport interface CreateGitCommitOptions {\n directory?: string\n author?: string\n}\n\n/**\n * Create a git commit.\n *\n * @param message - The message of the commit.\n * @param options - The options to use to create the commit.\n * @returns The hash of the created commit.\n */\nexport async function createGitCommit(message: string, options?: CreateGitCommitOptions): Promise<string> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const simpleGit = git({baseDir: options?.directory})\n\n const commitOptions = options?.author ? {'--author': options.author} : undefined\n const result = await simpleGit.commit(message, commitOptions)\n\n return result.commit\n}\n\n/**\n * Get the HEAD symbolic reference of a git repository.\n *\n * @param directory - The directory of the git repository.\n * @returns The HEAD symbolic reference of the repository.\n */\nexport async function getHeadSymbolicRef(directory?: string): Promise<string> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const ref = await git({baseDir: directory}).raw('symbolic-ref', '-q', 'HEAD')\n if (!ref) {\n throw new AbortError(\n \"Git HEAD can't be detached to run command\",\n outputContent`Run ${outputToken.genericShellCommand(\n 'git checkout [branchName]',\n )} to reattach HEAD or see git ${outputToken.link(\n 'documentation',\n 'https://git-scm.com/book/en/v2/Git-Internals-Git-References',\n )} for more details`,\n )\n }\n return ref.trim()\n}\n\n/**\n * If \"git\" is not present in the environment it throws\n * an abort error.\n */\nexport async function ensureGitIsPresentOrAbort(): Promise<void> {\n if (!(await hasGit())) {\n throw new AbortError(\n `Git is necessary in the environment to continue`,\n outputContent`Install ${outputToken.link(\n 'git',\n 'https://git-scm.com/book/en/v2/Getting-Started-Installing-Git',\n )}`,\n )\n }\n}\n\nexport class OutsideGitDirectoryError extends AbortError {}\n/**\n * If command run from outside a .git directory tree\n * it throws an abort error.\n *\n * @param directory - The directory to check.\n */\nexport async function ensureInsideGitDirectory(directory?: string): Promise<void> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (!(await git({baseDir: directory}).checkIsRepo())) {\n throw new OutsideGitDirectoryError(`${outputToken.path(directory || cwd())} is not a Git directory`)\n }\n}\n\nexport class GitDirectoryNotCleanError extends AbortError {}\n/**\n * If the .git directory tree is not clean (has uncommitted changes)\n * it throws an abort error.\n *\n * @param directory - The directory to check.\n */\nexport async function ensureIsClean(directory?: string): Promise<void> {\n if (!(await isClean(directory))) {\n throw new GitDirectoryNotCleanError(`${outputToken.path(directory || cwd())} is not a clean Git directory`)\n }\n}\n\n/**\n * Returns true if the .git directory tree is clean (no uncommitted changes).\n *\n * @param directory - The directory to check.\n * @returns True is the .git directory is clean.\n */\nexport async function isClean(directory?: string): Promise<boolean> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return (await git({baseDir: directory}).status()).isClean()\n}\n"]}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import { PackageManager } from './node-package-manager.js';
|
|
3
2
|
/**
|
|
4
3
|
* Returns true if the current process is running in a global context.
|
|
5
4
|
*
|
|
6
|
-
* @param
|
|
5
|
+
* @param argv - The arguments passed to the process.
|
|
7
6
|
* @returns `true` if the current process is running in a global context.
|
|
8
7
|
*/
|
|
9
|
-
export declare function currentProcessIsGlobal(
|
|
8
|
+
export declare function currentProcessIsGlobal(argv?: string[]): boolean;
|
|
10
9
|
/**
|
|
11
10
|
* Returns true if the global CLI is installed.
|
|
12
11
|
*
|
|
@@ -33,7 +32,6 @@ export declare function installGlobalCLIPrompt(): Promise<InstallGlobalCLIPrompt
|
|
|
33
32
|
* Infers the package manager used by the global CLI.
|
|
34
33
|
*
|
|
35
34
|
* @param argv - The arguments passed to the process.
|
|
36
|
-
* @param env - The environment to check. Defaults to `process.env`.
|
|
37
35
|
* @returns The package manager used by the global CLI.
|
|
38
36
|
*/
|
|
39
|
-
export declare function inferPackageManagerForGlobalCLI(argv?: string[]
|
|
37
|
+
export declare function inferPackageManagerForGlobalCLI(argv?: string[]): PackageManager;
|
|
@@ -1,16 +1,31 @@
|
|
|
1
|
+
import { isUnitTest } from './context/local.js';
|
|
1
2
|
import { outputInfo } from './output.js';
|
|
3
|
+
import { cwd, sniffForPath } from './path.js';
|
|
2
4
|
import { captureOutput, exec, terminalSupportsRawMode } from './system.js';
|
|
3
5
|
import { renderSelectPrompt } from './ui.js';
|
|
6
|
+
import { execaSync } from 'execa';
|
|
7
|
+
let _isGlobal;
|
|
4
8
|
/**
|
|
5
9
|
* Returns true if the current process is running in a global context.
|
|
6
10
|
*
|
|
7
|
-
* @param
|
|
11
|
+
* @param argv - The arguments passed to the process.
|
|
8
12
|
* @returns `true` if the current process is running in a global context.
|
|
9
13
|
*/
|
|
10
|
-
export function currentProcessIsGlobal(
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
export function currentProcessIsGlobal(argv = process.argv) {
|
|
15
|
+
// If we are running tests, we need to disable the cache
|
|
16
|
+
if (_isGlobal !== undefined && !isUnitTest())
|
|
17
|
+
return _isGlobal;
|
|
18
|
+
// Path where the current project is (app/hydrogen)
|
|
19
|
+
const path = sniffForPath() ?? cwd();
|
|
20
|
+
// Closest parent directory to contain a package.json file or node_modules directory
|
|
21
|
+
// https://docs.npmjs.com/cli/v8/commands/npm-prefix#description
|
|
22
|
+
const npmPrefix = execaSync('npm', ['prefix'], { cwd: path }).stdout.trim();
|
|
23
|
+
// From node docs: "The second element [of the array] will be the path to the JavaScript file being executed"
|
|
24
|
+
const binDir = argv[1] ?? '';
|
|
25
|
+
// If binDir starts with npmPrefix, then we are running a local CLI
|
|
26
|
+
const isLocal = binDir.startsWith(npmPrefix.trim());
|
|
27
|
+
_isGlobal = !isLocal;
|
|
28
|
+
return _isGlobal;
|
|
14
29
|
}
|
|
15
30
|
/**
|
|
16
31
|
* Returns true if the global CLI is installed.
|
|
@@ -62,11 +77,10 @@ export async function installGlobalCLIPrompt() {
|
|
|
62
77
|
* Infers the package manager used by the global CLI.
|
|
63
78
|
*
|
|
64
79
|
* @param argv - The arguments passed to the process.
|
|
65
|
-
* @param env - The environment to check. Defaults to `process.env`.
|
|
66
80
|
* @returns The package manager used by the global CLI.
|
|
67
81
|
*/
|
|
68
|
-
export function inferPackageManagerForGlobalCLI(argv = process.argv
|
|
69
|
-
if (!currentProcessIsGlobal(
|
|
82
|
+
export function inferPackageManagerForGlobalCLI(argv = process.argv) {
|
|
83
|
+
if (!currentProcessIsGlobal(argv))
|
|
70
84
|
return 'unknown';
|
|
71
85
|
// argv[1] contains the path of the executed binary
|
|
72
86
|
const processArgv = argv[1] ?? '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-global.js","sourceRoot":"","sources":["../../../src/public/node/is-global.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"is-global.js","sourceRoot":"","sources":["../../../src/public/node/is-global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAA;AAE7C,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAA;AACtC,OAAO,EAAC,GAAG,EAAE,YAAY,EAAC,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAC,aAAa,EAAE,IAAI,EAAE,uBAAuB,EAAC,MAAM,aAAa,CAAA;AACxE,OAAO,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAA;AAC1C,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAA;AAE/B,IAAI,SAA8B,CAAA;AAElC;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI;IACxD,wDAAwD;IACxD,IAAI,SAAS,KAAK,SAAS,IAAI,CAAC,UAAU,EAAE;QAAE,OAAO,SAAS,CAAA;IAE9D,mDAAmD;IACnD,MAAM,IAAI,GAAG,YAAY,EAAE,IAAI,GAAG,EAAE,CAAA;IAEpC,oFAAoF;IACpF,gEAAgE;IAChE,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAC,GAAG,EAAE,IAAI,EAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;IAEzE,6GAA6G;IAC7G,MAAM,MAAM,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M,MAAM,GAAG,MAAM,kBAAkB,CAAC;QACtC,OAAO,EAAE,gGAAgG;QACzG,OAAO,EAAE;YACP,EAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAC;YAC5B,EAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,2BAA2B,EAAC;SAClD;KACF,CAAC,CAAA;IAEF,OAAO,EAAC,OAAO,EAAE,MAAM,KAAK,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAC,CAAA;AAC7D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,+BAA+B,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI;IACjE,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAA;IAEnD,mDAAmD;IACnD,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;IACjC,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAA;IAC/C,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAA;IAC/C,IAAI,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IAC7C,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import {isUnitTest} from './context/local.js'\nimport {PackageManager} from './node-package-manager.js'\nimport {outputInfo} from './output.js'\nimport {cwd, sniffForPath} from './path.js'\nimport {captureOutput, exec, terminalSupportsRawMode} from './system.js'\nimport {renderSelectPrompt} from './ui.js'\nimport {execaSync} from 'execa'\n\nlet _isGlobal: boolean | undefined\n\n/**\n * Returns true if the current process is running in a global context.\n *\n * @param argv - The arguments passed to the process.\n * @returns `true` if the current process is running in a global context.\n */\nexport function currentProcessIsGlobal(argv = process.argv): boolean {\n // If we are running tests, we need to disable the cache\n if (_isGlobal !== undefined && !isUnitTest()) return _isGlobal\n\n // Path where the current project is (app/hydrogen)\n const path = sniffForPath() ?? cwd()\n\n // Closest parent directory to contain a package.json file or node_modules directory\n // https://docs.npmjs.com/cli/v8/commands/npm-prefix#description\n const npmPrefix = execaSync('npm', ['prefix'], {cwd: path}).stdout.trim()\n\n // From node docs: \"The second element [of the array] will be the path to the JavaScript file being executed\"\n const binDir = argv[1] ?? ''\n\n // If binDir starts with npmPrefix, then we are running a local CLI\n const isLocal = binDir.startsWith(npmPrefix.trim())\n\n _isGlobal = !isLocal\n return _isGlobal\n}\n\n/**\n * Returns true if the global CLI is installed.\n *\n * @returns `true` if the global CLI is installed.\n */\nexport async function isGlobalCLIInstalled(): Promise<boolean> {\n try {\n const output = await captureOutput('shopify', ['app'])\n // Installed if `app dev` is available globally\n return output.includes('app dev')\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n return false\n }\n}\n\n/**\n * Installs the global Shopify CLI, using the provided package manager.\n *\n * @param packageManager - The package manager to use.\n */\nexport async function installGlobalShopifyCLI(packageManager: PackageManager): Promise<void> {\n const args =\n packageManager === 'yarn' ? ['global', 'add', '@shopify/cli@latest'] : ['install', '-g', '@shopify/cli@latest']\n outputInfo(`Running ${packageManager} ${args.join(' ')}...`)\n await exec(packageManager, args, {stdio: 'inherit'})\n}\n\nexport interface InstallGlobalCLIPromptResult {\n install: boolean\n alreadyInstalled: boolean\n}\n/**\n * Prompts the user to install the global CLI.\n *\n * @returns `true` if the user has installed the global CLI.\n */\nexport async function installGlobalCLIPrompt(): Promise<InstallGlobalCLIPromptResult> {\n if (!terminalSupportsRawMode()) return {install: false, alreadyInstalled: false}\n if (await isGlobalCLIInstalled()) {\n return {install: false, alreadyInstalled: true}\n }\n const result = await renderSelectPrompt({\n message: 'We recommend installing Shopify CLI globally in your system. Would you like to install it now?',\n choices: [\n {value: 'yes', label: 'Yes'},\n {value: 'no', label: 'No, just for this project'},\n ],\n })\n\n return {install: result === 'yes', alreadyInstalled: false}\n}\n\n/**\n * Infers the package manager used by the global CLI.\n *\n * @param argv - The arguments passed to the process.\n * @returns The package manager used by the global CLI.\n */\nexport function inferPackageManagerForGlobalCLI(argv = process.argv): PackageManager {\n if (!currentProcessIsGlobal(argv)) return 'unknown'\n\n // argv[1] contains the path of the executed binary\n const processArgv = argv[1] ?? ''\n if (processArgv.includes('yarn')) return 'yarn'\n if (processArgv.includes('pnpm')) return 'pnpm'\n if (processArgv.includes('bun')) return 'bun'\n return 'npm'\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ParseConfigurationResult } from './schema.js';
|
|
2
|
+
import { ErrorObject, SchemaObject } from 'ajv';
|
|
3
|
+
type AjvError = ErrorObject<string, {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}, unknown>;
|
|
6
|
+
/**
|
|
7
|
+
* Normalises a JSON Schema by standardising it's internal implementation.
|
|
8
|
+
*
|
|
9
|
+
* We prefer to not use $ref elements in our schemas, so we inline them; it's easier then to process errors.
|
|
10
|
+
*
|
|
11
|
+
* @param schema - The JSON schema (as a string) to normalise.
|
|
12
|
+
* @returns The normalised JSON schema.
|
|
13
|
+
*/
|
|
14
|
+
export declare function normaliseJsonSchema(schema: string): Promise<SchemaObject>;
|
|
15
|
+
/**
|
|
16
|
+
* Given a subject object and a JSON schema contract, validate the subject against the contract.
|
|
17
|
+
*
|
|
18
|
+
* Errors are returned in a zod-like format, and processed to better handle unions.
|
|
19
|
+
*
|
|
20
|
+
* @param subject - The object to validate.
|
|
21
|
+
* @param schema - The JSON schema to validate against.
|
|
22
|
+
* @returns The result of the validation. If the state is 'error', the errors will be in a zod-like format.
|
|
23
|
+
*/
|
|
24
|
+
export declare function jsonSchemaValidate(subject: object, schema: SchemaObject): ParseConfigurationResult<unknown> & {
|
|
25
|
+
rawErrors?: AjvError[];
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { getPathValue } from '../common/object.js';
|
|
2
|
+
import { capitalize } from '../common/string.js';
|
|
3
|
+
import { Ajv } from 'ajv';
|
|
4
|
+
import $RefParser from '@apidevtools/json-schema-ref-parser';
|
|
5
|
+
/**
|
|
6
|
+
* Normalises a JSON Schema by standardising it's internal implementation.
|
|
7
|
+
*
|
|
8
|
+
* We prefer to not use $ref elements in our schemas, so we inline them; it's easier then to process errors.
|
|
9
|
+
*
|
|
10
|
+
* @param schema - The JSON schema (as a string) to normalise.
|
|
11
|
+
* @returns The normalised JSON schema.
|
|
12
|
+
*/
|
|
13
|
+
export async function normaliseJsonSchema(schema) {
|
|
14
|
+
// we want to modify the schema, removing any $ref elements and inlining with their source
|
|
15
|
+
const parsedSchema = JSON.parse(schema);
|
|
16
|
+
await $RefParser.dereference(parsedSchema, { resolve: { external: false } });
|
|
17
|
+
return parsedSchema;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Given a subject object and a JSON schema contract, validate the subject against the contract.
|
|
21
|
+
*
|
|
22
|
+
* Errors are returned in a zod-like format, and processed to better handle unions.
|
|
23
|
+
*
|
|
24
|
+
* @param subject - The object to validate.
|
|
25
|
+
* @param schema - The JSON schema to validate against.
|
|
26
|
+
* @returns The result of the validation. If the state is 'error', the errors will be in a zod-like format.
|
|
27
|
+
*/
|
|
28
|
+
export function jsonSchemaValidate(subject, schema) {
|
|
29
|
+
const ajv = new Ajv();
|
|
30
|
+
const validator = ajv.compile(schema);
|
|
31
|
+
validator(subject);
|
|
32
|
+
// Errors from the contract are post-processed to be more zod-like and to deal with unions better
|
|
33
|
+
let jsonSchemaErrors;
|
|
34
|
+
if (validator.errors && validator.errors.length > 0) {
|
|
35
|
+
jsonSchemaErrors = convertJsonSchemaErrors(validator.errors, subject, schema);
|
|
36
|
+
return {
|
|
37
|
+
state: 'error',
|
|
38
|
+
data: undefined,
|
|
39
|
+
errors: jsonSchemaErrors,
|
|
40
|
+
rawErrors: validator.errors,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
state: 'ok',
|
|
45
|
+
data: subject,
|
|
46
|
+
errors: undefined,
|
|
47
|
+
rawErrors: undefined,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Converts errors from Ajv into a zod-like format.
|
|
52
|
+
*
|
|
53
|
+
* @param rawErrors - JSON Schema errors taken directly from Ajv.
|
|
54
|
+
* @param subject - The object being validated.
|
|
55
|
+
* @param schema - The JSON schema to validated against.
|
|
56
|
+
* @returns The errors in a zod-like format.
|
|
57
|
+
*/
|
|
58
|
+
function convertJsonSchemaErrors(rawErrors, subject, schema) {
|
|
59
|
+
// This reduces the number of errors by simplifying errors coming from different branches of a union
|
|
60
|
+
const errors = simplifyUnionErrors(rawErrors, subject, schema);
|
|
61
|
+
// Now we can remap errors to be more zod-like
|
|
62
|
+
return errors.map((error) => {
|
|
63
|
+
const path = error.instancePath.split('/').slice(1);
|
|
64
|
+
if (error.params.missingProperty) {
|
|
65
|
+
const missingProperty = error.params.missingProperty;
|
|
66
|
+
return { path: [...path, missingProperty], message: 'Required' };
|
|
67
|
+
}
|
|
68
|
+
if (error.params.type) {
|
|
69
|
+
const expectedType = error.params.type;
|
|
70
|
+
const actualType = getPathValue(subject, path.join('.'));
|
|
71
|
+
return { path, message: `Expected ${expectedType}, received ${typeof actualType}` };
|
|
72
|
+
}
|
|
73
|
+
if (error.keyword === 'anyOf' || error.keyword === 'oneOf') {
|
|
74
|
+
return { path, message: 'Invalid input' };
|
|
75
|
+
}
|
|
76
|
+
if (error.params.allowedValues) {
|
|
77
|
+
const allowedValues = error.params.allowedValues;
|
|
78
|
+
const actualValue = getPathValue(subject, path.join('.'));
|
|
79
|
+
return {
|
|
80
|
+
path,
|
|
81
|
+
message: `Invalid enum value. Expected ${allowedValues
|
|
82
|
+
.map((value) => JSON.stringify(value))
|
|
83
|
+
.join(' | ')}, received ${JSON.stringify(actualValue)}`.replace(/"/g, "'"),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (error.params.comparison) {
|
|
87
|
+
const comparison = error.params.comparison;
|
|
88
|
+
const limit = error.params.limit;
|
|
89
|
+
const actualValue = getPathValue(subject, path.join('.'));
|
|
90
|
+
let comparisonText = comparison;
|
|
91
|
+
switch (comparison) {
|
|
92
|
+
case '<=':
|
|
93
|
+
comparisonText = 'less than or equal to';
|
|
94
|
+
break;
|
|
95
|
+
case '<':
|
|
96
|
+
comparisonText = 'less than';
|
|
97
|
+
break;
|
|
98
|
+
case '>=':
|
|
99
|
+
comparisonText = 'greater than or equal to';
|
|
100
|
+
break;
|
|
101
|
+
case '>':
|
|
102
|
+
comparisonText = 'greater than';
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
path,
|
|
107
|
+
message: capitalize(`${typeof actualValue} must be ${comparisonText} ${limit}`),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
path,
|
|
112
|
+
message: error.message,
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* If a JSON schema specifies a union (anyOf, oneOf), and the subject doesn't meet any of the 'candidates' for the
|
|
118
|
+
* union, then the error list received ends up being quite long: you get an error for the union property itself, and
|
|
119
|
+
* then additional errors for each of the candidate branches.
|
|
120
|
+
*
|
|
121
|
+
* This function simplifies the error collection. By default it strips anything other than the union error itself.
|
|
122
|
+
*
|
|
123
|
+
* In some cases, it can be possible to identify what the intended branch of the union was -- for instance, maybe there
|
|
124
|
+
* is a discriminating field like `type` that is unique between the branches. We inspect each candidate branch and if
|
|
125
|
+
* one branch is less wrong than the others -- e.g. It had a valid `type`, but problems elsewhere -- then we keep the
|
|
126
|
+
* errors for that branch.
|
|
127
|
+
*
|
|
128
|
+
* This is complex but in practise gives much more actionable errors.
|
|
129
|
+
*
|
|
130
|
+
* @param rawErrors - JSON Schema errors taken directly from Ajv.
|
|
131
|
+
* @param subject - The object being validated.
|
|
132
|
+
* @param schema - The JSON schema to validated against.
|
|
133
|
+
* @returns A simplified list of errors.
|
|
134
|
+
*/
|
|
135
|
+
function simplifyUnionErrors(rawErrors, subject, schema) {
|
|
136
|
+
const ajv = new Ajv();
|
|
137
|
+
let errors = rawErrors;
|
|
138
|
+
const resolvedUnionErrors = new Set();
|
|
139
|
+
while (true) {
|
|
140
|
+
const unionError = errors.filter((error) => (error.keyword === 'oneOf' || error.keyword === 'anyOf') && !resolvedUnionErrors.has(error.instancePath))[0];
|
|
141
|
+
if (unionError === undefined) {
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
// split errors into those sharing an instance path and those not
|
|
145
|
+
const unrelatedErrors = errors.filter((error) => !error.instancePath.startsWith(unionError.instancePath));
|
|
146
|
+
// we start by assuming only the union error itself is useful, and not the errors from the candidate schemas
|
|
147
|
+
let simplifiedUnionRelatedErrors = [unionError];
|
|
148
|
+
// get the schema list from where the union issue occured
|
|
149
|
+
const dottedSchemaPath = unionError.schemaPath.replace('#/', '').replace(/\//g, '.');
|
|
150
|
+
const unionSchemas = getPathValue(schema, dottedSchemaPath);
|
|
151
|
+
// and the slice of the subject that caused the issue
|
|
152
|
+
const subjectValue = getPathValue(subject, unionError.instancePath.split('/').slice(1).join('.'));
|
|
153
|
+
if (unionSchemas !== undefined && subjectValue !== undefined) {
|
|
154
|
+
// we know that none of the union schemas are correct, but for each of them we can measure how wrong they are
|
|
155
|
+
const correctValuesAndErrors = unionSchemas
|
|
156
|
+
.map((candidateSchemaFromUnion) => {
|
|
157
|
+
const candidateSchemaValidator = ajv.compile(candidateSchemaFromUnion);
|
|
158
|
+
candidateSchemaValidator(subjectValue);
|
|
159
|
+
let score = 0;
|
|
160
|
+
if (candidateSchemaFromUnion.type === 'object') {
|
|
161
|
+
// provided the schema is an object, we can measure how many properties are good
|
|
162
|
+
const candidatesObjectProperties = Object.keys(candidateSchemaFromUnion.properties);
|
|
163
|
+
score = candidatesObjectProperties.reduce((acc, propertyName) => {
|
|
164
|
+
const subSchema = candidateSchemaFromUnion.properties[propertyName];
|
|
165
|
+
const subjectValueSlice = getPathValue(subjectValue, propertyName);
|
|
166
|
+
const subValidator = ajv.compile(subSchema);
|
|
167
|
+
if (subValidator(subjectValueSlice)) {
|
|
168
|
+
return acc + 1;
|
|
169
|
+
}
|
|
170
|
+
return acc;
|
|
171
|
+
}, score);
|
|
172
|
+
}
|
|
173
|
+
return [score, candidateSchemaValidator.errors];
|
|
174
|
+
})
|
|
175
|
+
.sort(([scoreA], [scoreB]) => scoreA - scoreB);
|
|
176
|
+
if (correctValuesAndErrors.length >= 2) {
|
|
177
|
+
const [bestScore, bestErrors] = correctValuesAndErrors[correctValuesAndErrors.length - 1];
|
|
178
|
+
const [penultimateScore] = correctValuesAndErrors[correctValuesAndErrors.length - 2];
|
|
179
|
+
if (bestScore !== penultimateScore) {
|
|
180
|
+
// If there's a winner, show the errors for the best schema as they'll likely be actionable.
|
|
181
|
+
// We got these through a nested schema, so we need to adjust the instance path
|
|
182
|
+
simplifiedUnionRelatedErrors = [
|
|
183
|
+
unionError,
|
|
184
|
+
...bestErrors.map((bestError) => ({
|
|
185
|
+
...bestError,
|
|
186
|
+
instancePath: unionError.instancePath + bestError.instancePath,
|
|
187
|
+
})),
|
|
188
|
+
];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
errors = [...unrelatedErrors, ...simplifiedUnionRelatedErrors];
|
|
193
|
+
resolvedUnionErrors.add(unionError.instancePath);
|
|
194
|
+
}
|
|
195
|
+
return errors;
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=json-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.js","sourceRoot":"","sources":["../../../src/public/node/json-schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAC,UAAU,EAAC,MAAM,qBAAqB,CAAA;AAC9C,OAAO,EAAC,GAAG,EAA4B,MAAM,KAAK,CAAA;AAClD,OAAO,UAAU,MAAM,qCAAqC,C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S,CAAC,YAAY;yBAC/D,CAAC,CAAC;qBACJ,CAAA;iBACF;aACF;SACF;QACD,MAAM,GAAG,CAAC,GAAG,eAAe,EAAE,GAAG,4BAA4B,CAAC,CAAA;QAE9D,mBAAmB,CAAC,GAAG,CAAC,UAAU,CAAC,YAAY,CAAC,CAAA;KACjD;IACD,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import {ParseConfigurationResult} from './schema.js'\nimport {getPathValue} from '../common/object.js'\nimport {capitalize} from '../common/string.js'\nimport {Ajv, ErrorObject, SchemaObject} from 'ajv'\nimport $RefParser from '@apidevtools/json-schema-ref-parser'\n\ntype AjvError = ErrorObject<string, {[key: string]: unknown}, unknown>\n\n/**\n * Normalises a JSON Schema by standardising it's internal implementation.\n *\n * We prefer to not use $ref elements in our schemas, so we inline them; it's easier then to process errors.\n *\n * @param schema - The JSON schema (as a string) to normalise.\n * @returns The normalised JSON schema.\n */\nexport async function normaliseJsonSchema(schema: string): Promise<SchemaObject> {\n // we want to modify the schema, removing any $ref elements and inlining with their source\n const parsedSchema = JSON.parse(schema)\n await $RefParser.dereference(parsedSchema, {resolve: {external: false}})\n return parsedSchema\n}\n\n/**\n * Given a subject object and a JSON schema contract, validate the subject against the contract.\n *\n * Errors are returned in a zod-like format, and processed to better handle unions.\n *\n * @param subject - The object to validate.\n * @param schema - The JSON schema to validate against.\n * @returns The result of the validation. If the state is 'error', the errors will be in a zod-like format.\n */\nexport function jsonSchemaValidate(\n subject: object,\n schema: SchemaObject,\n): ParseConfigurationResult<unknown> & {rawErrors?: AjvError[]} {\n const ajv = new Ajv()\n const validator = ajv.compile(schema)\n validator(subject)\n\n // Errors from the contract are post-processed to be more zod-like and to deal with unions better\n let jsonSchemaErrors\n if (validator.errors && validator.errors.length > 0) {\n jsonSchemaErrors = convertJsonSchemaErrors(validator.errors, subject, schema)\n return {\n state: 'error',\n data: undefined,\n errors: jsonSchemaErrors,\n rawErrors: validator.errors,\n }\n }\n return {\n state: 'ok',\n data: subject,\n errors: undefined,\n rawErrors: undefined,\n }\n}\n\n/**\n * Converts errors from Ajv into a zod-like format.\n *\n * @param rawErrors - JSON Schema errors taken directly from Ajv.\n * @param subject - The object being validated.\n * @param schema - The JSON schema to validated against.\n * @returns The errors in a zod-like format.\n */\nfunction convertJsonSchemaErrors(rawErrors: AjvError[], subject: object, schema: SchemaObject) {\n // This reduces the number of errors by simplifying errors coming from different branches of a union\n const errors = simplifyUnionErrors(rawErrors, subject, schema)\n\n // Now we can remap errors to be more zod-like\n return errors.map((error) => {\n const path: string[] = error.instancePath.split('/').slice(1)\n if (error.params.missingProperty) {\n const missingProperty = error.params.missingProperty as string\n return {path: [...path, missingProperty], message: 'Required'}\n }\n\n if (error.params.type) {\n const expectedType = error.params.type\n const actualType = getPathValue(subject, path.join('.'))\n return {path, message: `Expected ${expectedType}, received ${typeof actualType}`}\n }\n\n if (error.keyword === 'anyOf' || error.keyword === 'oneOf') {\n return {path, message: 'Invalid input'}\n }\n\n if (error.params.allowedValues) {\n const allowedValues = error.params.allowedValues as string[]\n const actualValue = getPathValue(subject, path.join('.'))\n return {\n path,\n message: `Invalid enum value. Expected ${allowedValues\n .map((value) => JSON.stringify(value))\n .join(' | ')}, received ${JSON.stringify(actualValue)}`.replace(/\"/g, \"'\"),\n }\n }\n\n if (error.params.comparison) {\n const comparison = error.params.comparison as string\n const limit = error.params.limit\n const actualValue = getPathValue(subject, path.join('.'))\n\n let comparisonText = comparison\n switch (comparison) {\n case '<=':\n comparisonText = 'less than or equal to'\n break\n case '<':\n comparisonText = 'less than'\n break\n case '>=':\n comparisonText = 'greater than or equal to'\n break\n case '>':\n comparisonText = 'greater than'\n break\n }\n\n return {\n path,\n message: capitalize(`${typeof actualValue} must be ${comparisonText} ${limit}`),\n }\n }\n\n return {\n path,\n message: error.message,\n }\n })\n}\n\n/**\n * If a JSON schema specifies a union (anyOf, oneOf), and the subject doesn't meet any of the 'candidates' for the\n * union, then the error list received ends up being quite long: you get an error for the union property itself, and\n * then additional errors for each of the candidate branches.\n *\n * This function simplifies the error collection. By default it strips anything other than the union error itself.\n *\n * In some cases, it can be possible to identify what the intended branch of the union was -- for instance, maybe there\n * is a discriminating field like `type` that is unique between the branches. We inspect each candidate branch and if\n * one branch is less wrong than the others -- e.g. It had a valid `type`, but problems elsewhere -- then we keep the\n * errors for that branch.\n *\n * This is complex but in practise gives much more actionable errors.\n *\n * @param rawErrors - JSON Schema errors taken directly from Ajv.\n * @param subject - The object being validated.\n * @param schema - The JSON schema to validated against.\n * @returns A simplified list of errors.\n */\nfunction simplifyUnionErrors(rawErrors: AjvError[], subject: object, schema: SchemaObject): AjvError[] {\n const ajv = new Ajv()\n let errors = rawErrors\n\n const resolvedUnionErrors = new Set()\n while (true) {\n const unionError = errors.filter(\n (error) =>\n (error.keyword === 'oneOf' || error.keyword === 'anyOf') && !resolvedUnionErrors.has(error.instancePath),\n )[0]\n if (unionError === undefined) {\n break\n }\n // split errors into those sharing an instance path and those not\n const unrelatedErrors = errors.filter((error) => !error.instancePath.startsWith(unionError.instancePath))\n\n // we start by assuming only the union error itself is useful, and not the errors from the candidate schemas\n let simplifiedUnionRelatedErrors: AjvError[] = [unionError]\n\n // get the schema list from where the union issue occured\n const dottedSchemaPath = unionError.schemaPath.replace('#/', '').replace(/\\//g, '.')\n const unionSchemas = getPathValue<SchemaObject[]>(schema, dottedSchemaPath)\n // and the slice of the subject that caused the issue\n const subjectValue = getPathValue(subject, unionError.instancePath.split('/').slice(1).join('.'))\n\n if (unionSchemas !== undefined && subjectValue !== undefined) {\n // we know that none of the union schemas are correct, but for each of them we can measure how wrong they are\n const correctValuesAndErrors = unionSchemas\n .map((candidateSchemaFromUnion: SchemaObject) => {\n const candidateSchemaValidator = ajv.compile(candidateSchemaFromUnion)\n candidateSchemaValidator(subjectValue)\n\n let score = 0\n if (candidateSchemaFromUnion.type === 'object') {\n // provided the schema is an object, we can measure how many properties are good\n const candidatesObjectProperties = Object.keys(candidateSchemaFromUnion.properties)\n score = candidatesObjectProperties.reduce((acc, propertyName) => {\n const subSchema = candidateSchemaFromUnion.properties[propertyName] as SchemaObject\n const subjectValueSlice = getPathValue(subjectValue, propertyName)\n\n const subValidator = ajv.compile(subSchema)\n if (subValidator(subjectValueSlice)) {\n return acc + 1\n }\n return acc\n }, score)\n }\n\n return [score, candidateSchemaValidator.errors!] as const\n })\n .sort(([scoreA], [scoreB]) => scoreA - scoreB)\n\n if (correctValuesAndErrors.length >= 2) {\n const [bestScore, bestErrors] = correctValuesAndErrors[correctValuesAndErrors.length - 1]!\n const [penultimateScore] = correctValuesAndErrors[correctValuesAndErrors.length - 2]!\n\n if (bestScore !== penultimateScore) {\n // If there's a winner, show the errors for the best schema as they'll likely be actionable.\n // We got these through a nested schema, so we need to adjust the instance path\n simplifiedUnionRelatedErrors = [\n unionError,\n ...bestErrors.map((bestError) => ({\n ...bestError,\n instancePath: unionError.instancePath + bestError.instancePath,\n })),\n ]\n }\n }\n }\n errors = [...unrelatedErrors, ...simplifiedUnionRelatedErrors]\n\n resolvedUnionErrors.add(unionError.instancePath)\n }\n return errors\n}\n"]}
|
package/dist/public/node/logs.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { logsFolder } from '../../private/node/constants.js';
|
|
2
2
|
import { joinPath } from '@shopify/cli-kit/node/path';
|
|
3
3
|
import { mkdir, writeFile } from '@shopify/cli-kit/node/fs';
|
|
4
|
-
export const getLogsDir =
|
|
4
|
+
export const getLogsDir = () => {
|
|
5
|
+
return logsFolder();
|
|
6
|
+
};
|
|
5
7
|
export const createLogsDir = async (path) => {
|
|
6
8
|
await mkdir(joinPath(logsFolder(), path));
|
|
7
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logs.js","sourceRoot":"","sources":["../../../src/public/node/logs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,iCAAiC,CAAA;AAC1D,OAAO,EAAC,QAAQ,EAAC,MAAM,4BAA4B,CAAA;AACnD,OAAO,EAAC,KAAK,EAAE,SAAS,EAAC,MAAM,0BAA0B,CAAA;AAEzD,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"logs.js","sourceRoot":"","sources":["../../../src/public/node/logs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,iCAAiC,CAAA;AAC1D,OAAO,EAAC,QAAQ,EAAC,MAAM,4BAA4B,CAAA;AACnD,OAAO,EAAC,KAAK,EAAE,SAAS,EAAC,MAAM,0BAA0B,CAAA;AAEzD,MAAM,CAAC,MAAM,UAAU,GAAG,GAAW,EAAE;IACrC,OAAO,UAAU,EAAE,CAAA;AACrB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,IAAY,EAAiB,EAAE;IACjE,MAAM,KAAK,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,CAAC,CAAA;AAC3C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAAE,IAAY,EAAE,OAAe,EAAiB,EAAE;IAC7E,MAAM,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,EAAE,OAAO,CAAC,CAAA;AACxD,CAAC,CAAA","sourcesContent":["import {logsFolder} from '../../private/node/constants.js'\nimport {joinPath} from '@shopify/cli-kit/node/path'\nimport {mkdir, writeFile} from '@shopify/cli-kit/node/fs'\n\nexport const getLogsDir = (): string => {\n return logsFolder()\n}\n\nexport const createLogsDir = async (path: string): Promise<void> => {\n await mkdir(joinPath(logsFolder(), path))\n}\n\nexport const writeLog = async (path: string, logData: string): Promise<void> => {\n await writeFile(joinPath(logsFolder(), path), logData)\n}\n"]}
|