@shopify/cli-kit 3.72.1 → 3.73.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.
Files changed (47) hide show
  1. package/dist/cli/api/graphql/admin/generated/get_theme.d.ts +16 -0
  2. package/dist/cli/api/graphql/admin/generated/get_theme.js +44 -0
  3. package/dist/cli/api/graphql/admin/generated/get_theme.js.map +1 -0
  4. package/dist/cli/api/graphql/admin/generated/get_themes.d.ts +22 -0
  5. package/dist/cli/api/graphql/admin/generated/get_themes.js +67 -0
  6. package/dist/cli/api/graphql/admin/generated/get_themes.js.map +1 -0
  7. package/dist/cli/api/graphql/admin/generated/metafield_definitions_by_owner_type.d.ts +22 -0
  8. package/dist/cli/api/graphql/admin/generated/metafield_definitions_by_owner_type.js +67 -0
  9. package/dist/cli/api/graphql/admin/generated/metafield_definitions_by_owner_type.js.map +1 -0
  10. package/dist/private/node/request-ids.d.ts +24 -0
  11. package/dist/private/node/request-ids.js +38 -0
  12. package/dist/private/node/request-ids.js.map +1 -0
  13. package/dist/private/node/ui/components/AutocompletePrompt.test.js +76 -0
  14. package/dist/private/node/ui/components/AutocompletePrompt.test.js.map +1 -1
  15. package/dist/private/node/ui/components/SelectInput.js +9 -1
  16. package/dist/private/node/ui/components/SelectInput.js.map +1 -1
  17. package/dist/public/common/version.d.ts +1 -1
  18. package/dist/public/common/version.js +1 -1
  19. package/dist/public/common/version.js.map +1 -1
  20. package/dist/public/node/analytics.js +2 -0
  21. package/dist/public/node/analytics.js.map +1 -1
  22. package/dist/public/node/api/graphql.js +34 -14
  23. package/dist/public/node/api/graphql.js.map +1 -1
  24. package/dist/public/node/error.js +3 -1
  25. package/dist/public/node/error.js.map +1 -1
  26. package/dist/public/node/fs.d.ts +8 -1
  27. package/dist/public/node/fs.js +12 -3
  28. package/dist/public/node/fs.js.map +1 -1
  29. package/dist/public/node/git.d.ts +7 -0
  30. package/dist/public/node/git.js +12 -1
  31. package/dist/public/node/git.js.map +1 -1
  32. package/dist/public/node/is-global.js +18 -12
  33. package/dist/public/node/is-global.js.map +1 -1
  34. package/dist/public/node/monorail.d.ts +1 -1
  35. package/dist/public/node/monorail.js +1 -1
  36. package/dist/public/node/monorail.js.map +1 -1
  37. package/dist/public/node/node-package-manager.d.ts +3 -0
  38. package/dist/public/node/node-package-manager.js +7 -0
  39. package/dist/public/node/node-package-manager.js.map +1 -1
  40. package/dist/public/node/themes/api.d.ts +11 -0
  41. package/dist/public/node/themes/api.js +67 -7
  42. package/dist/public/node/themes/api.js.map +1 -1
  43. package/dist/tsconfig.tsbuildinfo +1 -1
  44. package/package.json +1 -1
  45. package/dist/public/node/api/http.d.ts +0 -1
  46. package/dist/public/node/api/http.js +0 -2
  47. package/dist/public/node/api/http.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"node-package-manager.js","sourceRoot":"","sources":["../../../src/public/node/node-package-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAC,eAAe,EAAc,MAAM,YAAY,CAAA;AACvD,OAAO,EAAC,aAAa,EAAE,IAAI,EAAC,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAC,MAAM,SAAS,CAAA;AACzE,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAC,YAAY,EAAC,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAC,+BAA+B,EAAC,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAC,WAAW,EAAE,aAAa,EAAE,WAAW,EAAC,MAAM,6BAA6B,CAAA;AACnF,OAAO,EAAoB,aAAa,EAAE,yBAAyB,EAAC,MAAM,kCAAkC,CAAA;AAC5G,OAAO,aAAa,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAC,MAAM,EAAE,SAAS,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,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,mBAAmB,CAAC,qBAAyC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG;IAC9F,IAAI,qBAAqB,IAAI,cAAc,CAAC,QAAQ,CAAC,qBAAuC,CAAC,EAAE;QAC7F,OAAO,qBAAuC,CAAA;KAC/C;IACD,MAAM,kBAAkB,GAAG,2BAA2B,CAAC,GAAG,CAAC,CAAA;IAC3D,IAAI,kBAAkB,KAAK,SAAS;QAAE,OAAO,kBAAkB,CAAA;IAE/D,MAAM,oBAAoB,GAAG,+BAA+B,EAAE,CAAA;IAC9D,IAAI,oBAAoB,KAAK,SAAS;QAAE,OAAO,oBAAoB,CAAA;IAEnE,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import {AbortError, BugError} from './error.js'\nimport {AbortController, AbortSignal} from './abort.js'\nimport {captureOutput, exec} from './system.js'\nimport {fileExists, readFile, writeFile, findPathUp, glob} from './fs.js'\nimport {dirname, joinPath} from './path.js'\nimport {runWithTimer} from './metadata.js'\nimport {inferPackageManagerForGlobalCLI} from './is-global.js'\nimport {outputToken, outputContent, outputDebug} from '../../public/node/output.js'\nimport {PackageVersionKey, cacheRetrieve, cacheRetrieveOrRepopulate} from '../../private/node/conf-store.js'\nimport latestVersion from 'latest-version'\nimport {SemVer, satisfies as semverSatisfies} from 'semver'\nimport type {Writable} from 'stream'\nimport type {ExecOptions} from './system.js'\n\n/** The name of the Yarn lock file */\nexport const yarnLockfile = 'yarn.lock'\n\n/** The name of the npm lock file */\nexport const npmLockfile = 'package-lock.json'\n\n/** The name of the pnpm lock file */\nexport const pnpmLockfile = 'pnpm-lock.yaml'\n\n/** The name of the bun lock file */\nexport const bunLockfile = 'bun.lockb'\n\n/** The name of the pnpm workspace file */\nexport const pnpmWorkspaceFile = 'pnpm-workspace.yaml'\n\n/** An array containing the lockfiles from all the package managers */\nexport const lockfiles: Lockfile[] = [yarnLockfile, pnpmLockfile, npmLockfile, bunLockfile]\nexport type Lockfile = 'yarn.lock' | 'package-lock.json' | 'pnpm-lock.yaml' | 'bun.lockb'\n\n/**\n * A union type that represents the type of dependencies in the package.json\n * - dev: devDependencies\n * - prod: dependencies\n * - peer: peerDependencies\n */\nexport type DependencyType = 'dev' | 'prod' | 'peer'\n\n/**\n * A union that represents the package managers available.\n */\nexport const packageManager = ['yarn', 'npm', 'pnpm', 'bun', 'unknown'] as const\nexport type PackageManager = (typeof packageManager)[number]\n\n/**\n * Returns an abort error that's thrown when the package manager can't be determined.\n * @returns An abort error.\n */\nexport class UnknownPackageManagerError extends AbortError {\n constructor() {\n super('Unknown package manager')\n }\n}\n\n/**\n * Returns an abort error that's thrown when a directory that's expected to have\n * a package.json doesn't have it.\n * @param directory - The path to the directory that should contain a package.json\n * @returns An abort error.\n */\nexport class PackageJsonNotFoundError extends AbortError {\n constructor(directory: string) {\n super(outputContent`The directory ${outputToken.path(directory)} doesn't have a package.json.`)\n }\n}\n\n/**\n * Returns a bug error that's thrown when the lookup of the package.json traversing the directory\n * hierarchy up can't find a package.json\n * @param directory - The directory from which the traverse has been done\n * @returns An abort error.\n */\nexport class FindUpAndReadPackageJsonNotFoundError extends BugError {\n constructor(directory: string) {\n super(outputContent`Couldn't find a a package.json traversing directories from ${outputToken.path(directory)}`)\n }\n}\n\n/**\n * Returns the dependency manager used to run the create workflow.\n * @param env - The environment variables of the process in which the CLI runs.\n * @returns The dependency manager\n */\nexport function packageManagerFromUserAgent(env = process.env): PackageManager {\n if (env.npm_config_user_agent?.includes('yarn')) {\n return 'yarn'\n } else if (env.npm_config_user_agent?.includes('pnpm')) {\n return 'pnpm'\n } else if (env.npm_config_user_agent?.includes('bun')) {\n return 'bun'\n } else if (env.npm_config_user_agent?.includes('npm')) {\n return 'npm'\n }\n return 'unknown'\n}\n\n/**\n * Returns the dependency manager used in a directory.\n * @param fromDirectory - The starting directory\n * @returns The dependency manager\n */\nexport async function getPackageManager(fromDirectory: string): Promise<PackageManager> {\n const directory = await captureOutput('npm', ['prefix'], {cwd: fromDirectory})\n outputDebug(outputContent`Obtaining the dependency manager in directory ${outputToken.path(directory)}...`)\n const packageJson = joinPath(directory, 'package.json')\n if (!(await fileExists(packageJson))) {\n return packageManagerFromUserAgent()\n }\n const yarnLockPath = joinPath(directory, yarnLockfile)\n const pnpmLockPath = joinPath(directory, pnpmLockfile)\n const bunLockPath = joinPath(directory, bunLockfile)\n if (await fileExists(yarnLockPath)) {\n return 'yarn'\n } else if (await fileExists(pnpmLockPath)) {\n return 'pnpm'\n } else if (await fileExists(bunLockPath)) {\n return 'bun'\n } else {\n return 'npm'\n }\n}\n\ninterface InstallNPMDependenciesRecursivelyOptions {\n /**\n * The dependency manager to use to install the dependencies.\n */\n packageManager: PackageManager\n /**\n * The directory from where we'll find package.json's recursively\n */\n directory: string\n\n /**\n * Specifies the maximum depth of the glob search.\n */\n deep?: number\n}\n\n/**\n * This function traverses down a directory tree to find directories containing a package.json\n * and installs the dependencies if needed. To know if it's needed, it uses the \"check\" command\n * provided by dependency managers.\n * @param options - Options to install dependencies recursively.\n */\nexport async function installNPMDependenciesRecursively(\n options: InstallNPMDependenciesRecursivelyOptions,\n): Promise<void> {\n const packageJsons = await glob(joinPath(options.directory, '**/package.json'), {\n ignore: [joinPath(options.directory, 'node_modules/**/package.json')],\n cwd: options.directory,\n onlyFiles: true,\n deep: options.deep,\n })\n const abortController = new AbortController()\n try {\n await Promise.all(\n packageJsons.map(async (packageJsonPath) => {\n const directory = dirname(packageJsonPath)\n await installNodeModules({\n directory,\n packageManager: options.packageManager,\n stdout: undefined,\n stderr: undefined,\n signal: abortController.signal,\n args: [],\n })\n }),\n )\n } catch (error) {\n abortController.abort()\n throw error\n }\n}\n\ninterface InstallNodeModulesOptions {\n directory: string\n args?: string[]\n packageManager: PackageManager\n stdout?: Writable\n stderr?: Writable\n signal?: AbortSignal\n}\n\nexport async function installNodeModules(options: InstallNodeModulesOptions): Promise<void> {\n const execOptions: ExecOptions = {\n cwd: options.directory,\n stdin: undefined,\n stdout: options.stdout,\n stderr: options.stderr,\n signal: options.signal,\n }\n let args = ['install']\n if (options.args) {\n args = args.concat(options.args)\n }\n await runWithTimer('cmd_all_timing_network_ms')(async () => {\n await exec(options.packageManager, args, execOptions)\n })\n}\n\n/**\n * Returns the name of the package configured in its package.json\n * @param packageJsonPath - Path to the package.json file\n * @returns A promise that resolves with the name.\n */\nexport async function getPackageName(packageJsonPath: string): Promise<string | undefined> {\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n return packageJsonContent.name\n}\n/**\n * Returns the version of the package configured in its package.json\n * @param packageJsonPath - Path to the package.json file\n * @returns A promise that resolves with the version.\n */\nexport async function getPackageVersion(packageJsonPath: string): Promise<string | undefined> {\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n return packageJsonContent.version\n}\n\n/**\n * Returns the list of production and dev dependencies of a package.json\n * @param packageJsonPath - Path to the package.json file\n * @returns A promise that resolves with the list of dependencies.\n */\nexport async function getDependencies(packageJsonPath: string): Promise<{[key: string]: string}> {\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n const dependencies: {[key: string]: string} = packageJsonContent.dependencies ?? {}\n const devDependencies: {[key: string]: string} = packageJsonContent.devDependencies ?? {}\n\n return {...dependencies, ...devDependencies}\n}\n\n/**\n * Returns true if the app uses workspaces, false otherwise.\n * @param packageJsonPath - Path to the package.json file\n * @param pnpmWorkspacePath - Path to the pnpm-workspace.yaml file\n * @returns A promise that resolves with true if the app uses workspaces, false otherwise.\n */\nexport async function usesWorkspaces(appDirectory: string): Promise<boolean> {\n const packageJsonPath = joinPath(appDirectory, 'package.json')\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n const pnpmWorkspacePath = joinPath(appDirectory, pnpmWorkspaceFile)\n return Boolean(packageJsonContent.workspaces) || fileExists(pnpmWorkspacePath)\n}\n\n/**\n * Given an NPM dependency, it checks if there's a more recent version, and if there is, it returns its value.\n * @param dependency - The dependency name (e.g. react)\n * @param currentVersion - The current version.\n * @param cacheExpiryInHours - If the last check was done more than this amount of hours ago, it will\n * refresh the cache. Defaults to always refreshing.\n * @returns A promise that resolves with a more recent version or undefined if there's no more recent version.\n */\nexport async function checkForNewVersion(\n dependency: string,\n currentVersion: string,\n {cacheExpiryInHours = 0} = {},\n): Promise<string | undefined> {\n const getLatestVersion = async () => {\n outputDebug(outputContent`Checking if there's a version of ${dependency} newer than ${currentVersion}`)\n return getLatestNPMPackageVersion(dependency)\n }\n\n const cacheKey: PackageVersionKey = `npm-package-${dependency}`\n let lastVersion\n try {\n lastVersion = await cacheRetrieveOrRepopulate(cacheKey, getLatestVersion, cacheExpiryInHours * 3600 * 1000)\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n return undefined\n }\n\n if (lastVersion && new SemVer(currentVersion).compare(lastVersion) < 0) {\n return lastVersion\n } else {\n return undefined\n }\n}\n\n/**\n * Given an NPM dependency, it checks if there's a cached more recent version, and if there is, it returns its value.\n * @param dependency - The dependency name (e.g. react)\n * @param currentVersion - The current version.\n * @returns A more recent version or undefined if there's no more recent version.\n */\nexport function checkForCachedNewVersion(dependency: string, currentVersion: string): string | undefined {\n const cacheKey: PackageVersionKey = `npm-package-${dependency}`\n const lastVersion = cacheRetrieve(cacheKey)?.value\n\n if (lastVersion && new SemVer(currentVersion).compare(lastVersion) < 0) {\n return lastVersion\n } else {\n return undefined\n }\n}\n\n/**\n * Utility function used to check whether a package version satisfies some requirements\n * @param version - The version to check\n * @param requirements - The requirements to check against, e.g. \"\\>=1.0.0\" - see https://www.npmjs.com/package/semver#ranges\n * @returns A boolean indicating whether the version satisfies the requirements\n */\nexport function versionSatisfies(version: string, requirements: string): boolean {\n return semverSatisfies(version, requirements)\n}\n\n/**\n * An interface that represents a package.json\n */\nexport interface PackageJson {\n /**\n * The name attribute of the package.json\n */\n name?: string\n\n /**\n * The author attribute of the package.json\n */\n author?: string\n\n /**\n * The version attribute of the package.json\n */\n version?: string\n\n /**\n * The scripts attribute of the package.json\n */\n scripts?: {[key: string]: string}\n\n /**\n * The dependencies attribute of the package.json\n */\n dependencies?: {[key: string]: string}\n\n /**\n * The devDependencies attribute of the package.json\n */\n devDependencies?: {[key: string]: string}\n\n /**\n * The peerDependencies attribute of the package.json\n */\n peerDependencies?: {[key: string]: string}\n\n /**\n * The optional oclif settings attribute of the package.json\n */\n oclif?: {\n plugins?: string[]\n }\n\n /**\n * The workspaces attribute of the package.json\n */\n workspaces?: string[]\n\n /**\n * The resolutions attribute of the package.json. Only useful when using yarn as package manager\n */\n resolutions?: {[key: string]: string}\n\n /**\n * The overrides attribute of the package.json. Only useful when using npm o npmn as package managers\n */\n overrides?: {[key: string]: string}\n\n /**\n * The prettier attribute of the package.json\n */\n prettier?: string\n\n /**\n * The private attribute of the package.json.\n * https://docs.npmjs.com/cli/v9/configuring-npm/package-json#private\n */\n private?: boolean\n}\n\n/**\n * Reads and parses a package.json\n * @param packageJsonPath - Path to the package.json\n * @returns An promise that resolves with an in-memory representation\n * of the package.json or rejects with an error if the file is not found or the content is\n * not decodable.\n */\nexport async function readAndParsePackageJson(packageJsonPath: string): Promise<PackageJson> {\n if (!(await fileExists(packageJsonPath))) {\n throw new PackageJsonNotFoundError(dirname(packageJsonPath))\n }\n return JSON.parse(await readFile(packageJsonPath))\n}\n\ninterface AddNPMDependenciesIfNeededOptions {\n /** How dependencies should be added */\n type: DependencyType\n\n /** The dependency manager to use to add dependencies */\n packageManager: PackageManager\n\n /** The directory that contains the package.json where dependencies will be added */\n directory: string\n\n /** Standard output coming from the underlying installation process */\n stdout?: Writable\n\n /** Standard error coming from the underlying installation process */\n stderr?: Writable\n\n /** Abort signal to stop the process */\n signal?: AbortSignal\n\n /** Whether to add the dependencies to the root package.json or to the package.json of the directory */\n addToRootDirectory?: boolean\n}\n\n/**\n * An interface that represents a dependency name with its version\n */\nexport interface DependencyVersion {\n /**\n * The name of the NPM dependency as it's reflected in the package.json:\n *\n * @example\n * In the example below name would be \"react\"\n * ```\n * {\n * \"react\": \"1.2.3\"\n * }\n * ```\n */\n name: string\n\n /**\n * The version of the NPM dependency as it's reflected in the package.json:\n *\n * @example\n * In the example below version would be \"1.2.3\"\n * ```\n * {\n * \"react\": \"1.2.3\"\n * }\n * ```\n */\n version: string | undefined\n}\n\n/**\n * Adds dependencies to a Node project (i.e. a project that has a package.json)\n * @param dependencies - List of dependencies to be added.\n * @param options - Options for adding dependencies.\n */\nexport async function addNPMDependenciesIfNeeded(\n dependencies: DependencyVersion[],\n options: AddNPMDependenciesIfNeededOptions,\n): Promise<void> {\n outputDebug(outputContent`Adding the following dependencies if needed:\n${outputToken.json(dependencies)}\nWith options:\n${outputToken.json(options)}\n `)\n const packageJsonPath = joinPath(options.directory, 'package.json')\n if (!(await fileExists(packageJsonPath))) {\n throw new PackageJsonNotFoundError(options.directory)\n }\n const existingDependencies = Object.keys(await getDependencies(packageJsonPath))\n const dependenciesToAdd = dependencies.filter((dep) => {\n return !existingDependencies.includes(dep.name)\n })\n if (dependenciesToAdd.length === 0) {\n return\n }\n await addNPMDependencies(dependenciesToAdd, options)\n}\n\nexport async function addNPMDependencies(\n dependencies: DependencyVersion[],\n options: AddNPMDependenciesIfNeededOptions,\n): Promise<void> {\n const dependenciesWithVersion = dependencies.map((dep) => {\n return dep.version ? `${dep.name}@${dep.version}` : dep.name\n })\n options.stdout?.write(`Installing ${[dependenciesWithVersion].join(' ')} with ${options.packageManager}`)\n switch (options.packageManager) {\n case 'npm':\n // npm isn't too smart when resolving the dependency tree. For example, admin ui extensions include react as\n // a peer dependency, but npm can't figure out the relationship and fails. Installing dependencies one by one\n // makes the task easier and npm can then proceed.\n for (const dep of dependenciesWithVersion) {\n // eslint-disable-next-line no-await-in-loop\n await installDependencies(options, argumentsToAddDependenciesWithNPM(dep, options.type))\n }\n break\n case 'yarn':\n await installDependencies(\n options,\n argumentsToAddDependenciesWithYarn(dependenciesWithVersion, options.type, Boolean(options.addToRootDirectory)),\n )\n break\n case 'pnpm':\n await installDependencies(\n options,\n argumentsToAddDependenciesWithPNPM(dependenciesWithVersion, options.type, Boolean(options.addToRootDirectory)),\n )\n break\n case 'bun':\n await installDependencies(options, argumentsToAddDependenciesWithBun(dependenciesWithVersion, options.type))\n await installDependencies(options, ['install'])\n break\n case 'unknown':\n throw new UnknownPackageManagerError()\n }\n}\n\nasync function installDependencies(options: AddNPMDependenciesIfNeededOptions, args: string[]) {\n return runWithTimer('cmd_all_timing_network_ms')(async () => {\n return exec(options.packageManager, args, {\n cwd: options.directory,\n stdout: options.stdout,\n stderr: options.stderr,\n signal: options.signal,\n })\n })\n}\n\nexport async function addNPMDependenciesWithoutVersionIfNeeded(\n dependencies: string[],\n options: AddNPMDependenciesIfNeededOptions,\n): Promise<void> {\n await addNPMDependenciesIfNeeded(\n dependencies.map((dependency) => {\n return {name: dependency, version: undefined}\n }),\n options,\n )\n}\n\n/**\n * Returns the arguments to add dependencies using NPM.\n * @param dependencies - The list of dependencies to add\n * @param type - The dependency type.\n * @returns An array with the arguments.\n */\nfunction argumentsToAddDependenciesWithNPM(dependency: string, type: DependencyType): string[] {\n let command = ['install']\n command = command.concat(dependency)\n switch (type) {\n case 'dev':\n command.push('--save-dev')\n break\n case 'peer':\n command.push('--save-peer')\n break\n case 'prod':\n command.push('--save-prod')\n break\n }\n // NPM adds ^ to the installed version by default. We want to install exact versions unless specified otherwise.\n if (dependency.match(/@\\d/g)) {\n command.push('--save-exact')\n }\n return command\n}\n\n/**\n * Returns the arguments to add dependencies using Yarn.\n * @param dependencies - The list of dependencies to add\n * @param type - The dependency type.\n * @param addAtRoot - Force to install the dependencies in the workspace root (optional, default = false)\n * @returns An array with the arguments.\n */\nfunction argumentsToAddDependenciesWithYarn(dependencies: string[], type: DependencyType, addAtRoot = false): string[] {\n let command = ['add']\n\n if (addAtRoot) {\n command.push('-W')\n }\n\n command = command.concat(dependencies)\n switch (type) {\n case 'dev':\n command.push('--dev')\n break\n case 'peer':\n command.push('--peer')\n break\n case 'prod':\n command.push('--prod')\n break\n }\n return command\n}\n\n/**\n * Returns the arguments to add dependencies using PNPM.\n * @param dependencies - The list of dependencies to add\n * @param type - The dependency type.\n * @param addAtRoot - Force to install the dependencies in the workspace root (optional, default = false)\n * @returns An array with the arguments.\n */\nfunction argumentsToAddDependenciesWithPNPM(dependencies: string[], type: DependencyType, addAtRoot = false): string[] {\n let command = ['add']\n\n if (addAtRoot) {\n command.push('-w')\n }\n\n command = command.concat(dependencies)\n\n switch (type) {\n case 'dev':\n command.push('--save-dev')\n break\n case 'peer':\n command.push('--save-peer')\n break\n case 'prod':\n command.push('--save-prod')\n break\n }\n return command\n}\n\n/**\n * Returns the arguments to add dependencies using Bun.\n * @param dependencies - The list of dependencies to add\n * @param type - The dependency type.\n * @returns An array with the arguments.\n */\nfunction argumentsToAddDependenciesWithBun(dependencies: string[], type: DependencyType): string[] {\n let command = ['add']\n\n command = command.concat(dependencies)\n\n switch (type) {\n case 'dev':\n command.push('--development')\n break\n case 'peer':\n command.push('--optional')\n break\n case 'prod':\n break\n }\n return command\n}\n\n/**\n * Given a directory it traverses the directory up looking for a package.json and if found, it reads it\n * decodes the JSON, and returns its content as a Javascript object.\n * @param options - The directory from which traverse up.\n * @returns If found, the promise resolves with the path to the\n * package.json and its content. If not found, it throws a FindUpAndReadPackageJsonNotFoundError error.\n */\nexport async function findUpAndReadPackageJson(fromDirectory: string): Promise<{path: string; content: PackageJson}> {\n const packageJsonPath = await findPathUp('package.json', {cwd: fromDirectory, type: 'file'})\n if (packageJsonPath) {\n const packageJson = JSON.parse(await readFile(packageJsonPath))\n return {path: packageJsonPath, content: packageJson}\n } else {\n throw new FindUpAndReadPackageJsonNotFoundError(fromDirectory)\n }\n}\n\nexport async function addResolutionOrOverride(directory: string, dependencies: {[key: string]: string}): Promise<void> {\n const packageManager = await getPackageManager(directory)\n const packageJsonPath = joinPath(directory, 'package.json')\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n\n if (packageManager === 'yarn') {\n packageJsonContent.resolutions = packageJsonContent.resolutions\n ? {...packageJsonContent.resolutions, ...dependencies}\n : dependencies\n }\n if (packageManager === 'npm' || packageManager === 'pnpm' || packageManager === 'bun') {\n packageJsonContent.overrides = packageJsonContent.overrides\n ? {...packageJsonContent.overrides, ...dependencies}\n : dependencies\n }\n\n await writeFile(packageJsonPath, JSON.stringify(packageJsonContent, null, 2))\n}\n\n/**\n * Returns the latest available version of an NPM package.\n * @param name - The name of the NPM package.\n * @returns A promise to get the latest available version of a package.\n */\nasync function getLatestNPMPackageVersion(name: string) {\n outputDebug(outputContent`Getting the latest version of NPM package: ${outputToken.raw(name)}`)\n return runWithTimer('cmd_all_timing_network_ms')(() => {\n return latestVersion(name)\n })\n}\n\n/**\n * Writes the package.json file to the given directory.\n *\n * @param directory - Directory where the package.json file will be written.\n * @param packageJSON - Package.json file to write.\n */\nexport async function writePackageJSON(directory: string, packageJSON: PackageJson): Promise<void> {\n outputDebug(outputContent`JSON-encoding and writing content to package.json at ${outputToken.path(directory)}...`)\n const packagePath = joinPath(directory, 'package.json')\n await writeFile(packagePath, JSON.stringify(packageJSON, null, 2))\n}\n\n/**\n * Infers the package manager to be used based on the provided options and environment.\n *\n * This function determines the package manager in the following order of precedence:\n * 1. Uses the package manager specified in the options, if valid.\n * 2. Infers the package manager from the user agent string.\n * 3. Infers the package manager used for the global CLI installation.\n * 4. Defaults to 'npm' if no other method succeeds.\n *\n * @param optionsPackageManager - The package manager specified in the options (if any).\n * @returns The inferred package manager as a PackageManager type.\n */\nexport function inferPackageManager(optionsPackageManager: string | undefined, env = process.env): PackageManager {\n if (optionsPackageManager && packageManager.includes(optionsPackageManager as PackageManager)) {\n return optionsPackageManager as PackageManager\n }\n const usedPackageManager = packageManagerFromUserAgent(env)\n if (usedPackageManager !== 'unknown') return usedPackageManager\n\n const globalPackageManager = inferPackageManagerForGlobalCLI()\n if (globalPackageManager !== 'unknown') return globalPackageManager\n\n return 'npm'\n}\n"]}
1
+ {"version":3,"file":"node-package-manager.js","sourceRoot":"","sources":["../../../src/public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AA;IAC9D,IAAI,oBAAoB,KAAK,SAAS;QAAE,OAAO,oBAAoB,CAAA;IAEnE,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import {AbortError, BugError} from './error.js'\nimport {AbortController, AbortSignal} from './abort.js'\nimport {captureOutput, exec} from './system.js'\nimport {fileExists, readFile, writeFile, findPathUp, glob} from './fs.js'\nimport {dirname, joinPath} from './path.js'\nimport {runWithTimer} from './metadata.js'\nimport {inferPackageManagerForGlobalCLI} from './is-global.js'\nimport {outputToken, outputContent, outputDebug} from '../../public/node/output.js'\nimport {PackageVersionKey, cacheRetrieve, cacheRetrieveOrRepopulate} from '../../private/node/conf-store.js'\nimport latestVersion from 'latest-version'\nimport {SemVer, satisfies as semverSatisfies} from 'semver'\nimport type {Writable} from 'stream'\nimport type {ExecOptions} from './system.js'\n\n/** The name of the Yarn lock file */\nexport const yarnLockfile = 'yarn.lock'\n\n/** The name of the npm lock file */\nexport const npmLockfile = 'package-lock.json'\n\n/** The name of the pnpm lock file */\nexport const pnpmLockfile = 'pnpm-lock.yaml'\n\n/** The name of the bun lock file */\nexport const bunLockfile = 'bun.lockb'\n\n/** The name of the pnpm workspace file */\nexport const pnpmWorkspaceFile = 'pnpm-workspace.yaml'\n\n/** An array containing the lockfiles from all the package managers */\nexport const lockfiles: Lockfile[] = [yarnLockfile, pnpmLockfile, npmLockfile, bunLockfile]\nexport const lockfilesByManager: {[key in PackageManager]: Lockfile | undefined} = {\n yarn: yarnLockfile,\n npm: npmLockfile,\n pnpm: pnpmLockfile,\n bun: bunLockfile,\n unknown: undefined,\n}\nexport type Lockfile = 'yarn.lock' | 'package-lock.json' | 'pnpm-lock.yaml' | 'bun.lockb'\n\n/**\n * A union type that represents the type of dependencies in the package.json\n * - dev: devDependencies\n * - prod: dependencies\n * - peer: peerDependencies\n */\nexport type DependencyType = 'dev' | 'prod' | 'peer'\n\n/**\n * A union that represents the package managers available.\n */\nexport const packageManager = ['yarn', 'npm', 'pnpm', 'bun', 'unknown'] as const\nexport type PackageManager = (typeof packageManager)[number]\n\n/**\n * Returns an abort error that's thrown when the package manager can't be determined.\n * @returns An abort error.\n */\nexport class UnknownPackageManagerError extends AbortError {\n constructor() {\n super('Unknown package manager')\n }\n}\n\n/**\n * Returns an abort error that's thrown when a directory that's expected to have\n * a package.json doesn't have it.\n * @param directory - The path to the directory that should contain a package.json\n * @returns An abort error.\n */\nexport class PackageJsonNotFoundError extends AbortError {\n constructor(directory: string) {\n super(outputContent`The directory ${outputToken.path(directory)} doesn't have a package.json.`)\n }\n}\n\n/**\n * Returns a bug error that's thrown when the lookup of the package.json traversing the directory\n * hierarchy up can't find a package.json\n * @param directory - The directory from which the traverse has been done\n * @returns An abort error.\n */\nexport class FindUpAndReadPackageJsonNotFoundError extends BugError {\n constructor(directory: string) {\n super(outputContent`Couldn't find a a package.json traversing directories from ${outputToken.path(directory)}`)\n }\n}\n\n/**\n * Returns the dependency manager used to run the create workflow.\n * @param env - The environment variables of the process in which the CLI runs.\n * @returns The dependency manager\n */\nexport function packageManagerFromUserAgent(env = process.env): PackageManager {\n if (env.npm_config_user_agent?.includes('yarn')) {\n return 'yarn'\n } else if (env.npm_config_user_agent?.includes('pnpm')) {\n return 'pnpm'\n } else if (env.npm_config_user_agent?.includes('bun')) {\n return 'bun'\n } else if (env.npm_config_user_agent?.includes('npm')) {\n return 'npm'\n }\n return 'unknown'\n}\n\n/**\n * Returns the dependency manager used in a directory.\n * @param fromDirectory - The starting directory\n * @returns The dependency manager\n */\nexport async function getPackageManager(fromDirectory: string): Promise<PackageManager> {\n const directory = await captureOutput('npm', ['prefix'], {cwd: fromDirectory})\n outputDebug(outputContent`Obtaining the dependency manager in directory ${outputToken.path(directory)}...`)\n const packageJson = joinPath(directory, 'package.json')\n if (!(await fileExists(packageJson))) {\n return packageManagerFromUserAgent()\n }\n const yarnLockPath = joinPath(directory, yarnLockfile)\n const pnpmLockPath = joinPath(directory, pnpmLockfile)\n const bunLockPath = joinPath(directory, bunLockfile)\n if (await fileExists(yarnLockPath)) {\n return 'yarn'\n } else if (await fileExists(pnpmLockPath)) {\n return 'pnpm'\n } else if (await fileExists(bunLockPath)) {\n return 'bun'\n } else {\n return 'npm'\n }\n}\n\ninterface InstallNPMDependenciesRecursivelyOptions {\n /**\n * The dependency manager to use to install the dependencies.\n */\n packageManager: PackageManager\n /**\n * The directory from where we'll find package.json's recursively\n */\n directory: string\n\n /**\n * Specifies the maximum depth of the glob search.\n */\n deep?: number\n}\n\n/**\n * This function traverses down a directory tree to find directories containing a package.json\n * and installs the dependencies if needed. To know if it's needed, it uses the \"check\" command\n * provided by dependency managers.\n * @param options - Options to install dependencies recursively.\n */\nexport async function installNPMDependenciesRecursively(\n options: InstallNPMDependenciesRecursivelyOptions,\n): Promise<void> {\n const packageJsons = await glob(joinPath(options.directory, '**/package.json'), {\n ignore: [joinPath(options.directory, 'node_modules/**/package.json')],\n cwd: options.directory,\n onlyFiles: true,\n deep: options.deep,\n })\n const abortController = new AbortController()\n try {\n await Promise.all(\n packageJsons.map(async (packageJsonPath) => {\n const directory = dirname(packageJsonPath)\n await installNodeModules({\n directory,\n packageManager: options.packageManager,\n stdout: undefined,\n stderr: undefined,\n signal: abortController.signal,\n args: [],\n })\n }),\n )\n } catch (error) {\n abortController.abort()\n throw error\n }\n}\n\ninterface InstallNodeModulesOptions {\n directory: string\n args?: string[]\n packageManager: PackageManager\n stdout?: Writable\n stderr?: Writable\n signal?: AbortSignal\n}\n\nexport async function installNodeModules(options: InstallNodeModulesOptions): Promise<void> {\n const execOptions: ExecOptions = {\n cwd: options.directory,\n stdin: undefined,\n stdout: options.stdout,\n stderr: options.stderr,\n signal: options.signal,\n }\n let args = ['install']\n if (options.args) {\n args = args.concat(options.args)\n }\n await runWithTimer('cmd_all_timing_network_ms')(async () => {\n await exec(options.packageManager, args, execOptions)\n })\n}\n\n/**\n * Returns the name of the package configured in its package.json\n * @param packageJsonPath - Path to the package.json file\n * @returns A promise that resolves with the name.\n */\nexport async function getPackageName(packageJsonPath: string): Promise<string | undefined> {\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n return packageJsonContent.name\n}\n/**\n * Returns the version of the package configured in its package.json\n * @param packageJsonPath - Path to the package.json file\n * @returns A promise that resolves with the version.\n */\nexport async function getPackageVersion(packageJsonPath: string): Promise<string | undefined> {\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n return packageJsonContent.version\n}\n\n/**\n * Returns the list of production and dev dependencies of a package.json\n * @param packageJsonPath - Path to the package.json file\n * @returns A promise that resolves with the list of dependencies.\n */\nexport async function getDependencies(packageJsonPath: string): Promise<{[key: string]: string}> {\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n const dependencies: {[key: string]: string} = packageJsonContent.dependencies ?? {}\n const devDependencies: {[key: string]: string} = packageJsonContent.devDependencies ?? {}\n\n return {...dependencies, ...devDependencies}\n}\n\n/**\n * Returns true if the app uses workspaces, false otherwise.\n * @param packageJsonPath - Path to the package.json file\n * @param pnpmWorkspacePath - Path to the pnpm-workspace.yaml file\n * @returns A promise that resolves with true if the app uses workspaces, false otherwise.\n */\nexport async function usesWorkspaces(appDirectory: string): Promise<boolean> {\n const packageJsonPath = joinPath(appDirectory, 'package.json')\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n const pnpmWorkspacePath = joinPath(appDirectory, pnpmWorkspaceFile)\n return Boolean(packageJsonContent.workspaces) || fileExists(pnpmWorkspacePath)\n}\n\n/**\n * Given an NPM dependency, it checks if there's a more recent version, and if there is, it returns its value.\n * @param dependency - The dependency name (e.g. react)\n * @param currentVersion - The current version.\n * @param cacheExpiryInHours - If the last check was done more than this amount of hours ago, it will\n * refresh the cache. Defaults to always refreshing.\n * @returns A promise that resolves with a more recent version or undefined if there's no more recent version.\n */\nexport async function checkForNewVersion(\n dependency: string,\n currentVersion: string,\n {cacheExpiryInHours = 0} = {},\n): Promise<string | undefined> {\n const getLatestVersion = async () => {\n outputDebug(outputContent`Checking if there's a version of ${dependency} newer than ${currentVersion}`)\n return getLatestNPMPackageVersion(dependency)\n }\n\n const cacheKey: PackageVersionKey = `npm-package-${dependency}`\n let lastVersion\n try {\n lastVersion = await cacheRetrieveOrRepopulate(cacheKey, getLatestVersion, cacheExpiryInHours * 3600 * 1000)\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n return undefined\n }\n\n if (lastVersion && new SemVer(currentVersion).compare(lastVersion) < 0) {\n return lastVersion\n } else {\n return undefined\n }\n}\n\n/**\n * Given an NPM dependency, it checks if there's a cached more recent version, and if there is, it returns its value.\n * @param dependency - The dependency name (e.g. react)\n * @param currentVersion - The current version.\n * @returns A more recent version or undefined if there's no more recent version.\n */\nexport function checkForCachedNewVersion(dependency: string, currentVersion: string): string | undefined {\n const cacheKey: PackageVersionKey = `npm-package-${dependency}`\n const lastVersion = cacheRetrieve(cacheKey)?.value\n\n if (lastVersion && new SemVer(currentVersion).compare(lastVersion) < 0) {\n return lastVersion\n } else {\n return undefined\n }\n}\n\n/**\n * Utility function used to check whether a package version satisfies some requirements\n * @param version - The version to check\n * @param requirements - The requirements to check against, e.g. \"\\>=1.0.0\" - see https://www.npmjs.com/package/semver#ranges\n * @returns A boolean indicating whether the version satisfies the requirements\n */\nexport function versionSatisfies(version: string, requirements: string): boolean {\n return semverSatisfies(version, requirements)\n}\n\n/**\n * An interface that represents a package.json\n */\nexport interface PackageJson {\n /**\n * The name attribute of the package.json\n */\n name?: string\n\n /**\n * The author attribute of the package.json\n */\n author?: string\n\n /**\n * The version attribute of the package.json\n */\n version?: string\n\n /**\n * The scripts attribute of the package.json\n */\n scripts?: {[key: string]: string}\n\n /**\n * The dependencies attribute of the package.json\n */\n dependencies?: {[key: string]: string}\n\n /**\n * The devDependencies attribute of the package.json\n */\n devDependencies?: {[key: string]: string}\n\n /**\n * The peerDependencies attribute of the package.json\n */\n peerDependencies?: {[key: string]: string}\n\n /**\n * The optional oclif settings attribute of the package.json\n */\n oclif?: {\n plugins?: string[]\n }\n\n /**\n * The workspaces attribute of the package.json\n */\n workspaces?: string[]\n\n /**\n * The resolutions attribute of the package.json. Only useful when using yarn as package manager\n */\n resolutions?: {[key: string]: string}\n\n /**\n * The overrides attribute of the package.json. Only useful when using npm o npmn as package managers\n */\n overrides?: {[key: string]: string}\n\n /**\n * The prettier attribute of the package.json\n */\n prettier?: string\n\n /**\n * The private attribute of the package.json.\n * https://docs.npmjs.com/cli/v9/configuring-npm/package-json#private\n */\n private?: boolean\n}\n\n/**\n * Reads and parses a package.json\n * @param packageJsonPath - Path to the package.json\n * @returns An promise that resolves with an in-memory representation\n * of the package.json or rejects with an error if the file is not found or the content is\n * not decodable.\n */\nexport async function readAndParsePackageJson(packageJsonPath: string): Promise<PackageJson> {\n if (!(await fileExists(packageJsonPath))) {\n throw new PackageJsonNotFoundError(dirname(packageJsonPath))\n }\n return JSON.parse(await readFile(packageJsonPath))\n}\n\ninterface AddNPMDependenciesIfNeededOptions {\n /** How dependencies should be added */\n type: DependencyType\n\n /** The dependency manager to use to add dependencies */\n packageManager: PackageManager\n\n /** The directory that contains the package.json where dependencies will be added */\n directory: string\n\n /** Standard output coming from the underlying installation process */\n stdout?: Writable\n\n /** Standard error coming from the underlying installation process */\n stderr?: Writable\n\n /** Abort signal to stop the process */\n signal?: AbortSignal\n\n /** Whether to add the dependencies to the root package.json or to the package.json of the directory */\n addToRootDirectory?: boolean\n}\n\n/**\n * An interface that represents a dependency name with its version\n */\nexport interface DependencyVersion {\n /**\n * The name of the NPM dependency as it's reflected in the package.json:\n *\n * @example\n * In the example below name would be \"react\"\n * ```\n * {\n * \"react\": \"1.2.3\"\n * }\n * ```\n */\n name: string\n\n /**\n * The version of the NPM dependency as it's reflected in the package.json:\n *\n * @example\n * In the example below version would be \"1.2.3\"\n * ```\n * {\n * \"react\": \"1.2.3\"\n * }\n * ```\n */\n version: string | undefined\n}\n\n/**\n * Adds dependencies to a Node project (i.e. a project that has a package.json)\n * @param dependencies - List of dependencies to be added.\n * @param options - Options for adding dependencies.\n */\nexport async function addNPMDependenciesIfNeeded(\n dependencies: DependencyVersion[],\n options: AddNPMDependenciesIfNeededOptions,\n): Promise<void> {\n outputDebug(outputContent`Adding the following dependencies if needed:\n${outputToken.json(dependencies)}\nWith options:\n${outputToken.json(options)}\n `)\n const packageJsonPath = joinPath(options.directory, 'package.json')\n if (!(await fileExists(packageJsonPath))) {\n throw new PackageJsonNotFoundError(options.directory)\n }\n const existingDependencies = Object.keys(await getDependencies(packageJsonPath))\n const dependenciesToAdd = dependencies.filter((dep) => {\n return !existingDependencies.includes(dep.name)\n })\n if (dependenciesToAdd.length === 0) {\n return\n }\n await addNPMDependencies(dependenciesToAdd, options)\n}\n\nexport async function addNPMDependencies(\n dependencies: DependencyVersion[],\n options: AddNPMDependenciesIfNeededOptions,\n): Promise<void> {\n const dependenciesWithVersion = dependencies.map((dep) => {\n return dep.version ? `${dep.name}@${dep.version}` : dep.name\n })\n options.stdout?.write(`Installing ${[dependenciesWithVersion].join(' ')} with ${options.packageManager}`)\n switch (options.packageManager) {\n case 'npm':\n // npm isn't too smart when resolving the dependency tree. For example, admin ui extensions include react as\n // a peer dependency, but npm can't figure out the relationship and fails. Installing dependencies one by one\n // makes the task easier and npm can then proceed.\n for (const dep of dependenciesWithVersion) {\n // eslint-disable-next-line no-await-in-loop\n await installDependencies(options, argumentsToAddDependenciesWithNPM(dep, options.type))\n }\n break\n case 'yarn':\n await installDependencies(\n options,\n argumentsToAddDependenciesWithYarn(dependenciesWithVersion, options.type, Boolean(options.addToRootDirectory)),\n )\n break\n case 'pnpm':\n await installDependencies(\n options,\n argumentsToAddDependenciesWithPNPM(dependenciesWithVersion, options.type, Boolean(options.addToRootDirectory)),\n )\n break\n case 'bun':\n await installDependencies(options, argumentsToAddDependenciesWithBun(dependenciesWithVersion, options.type))\n await installDependencies(options, ['install'])\n break\n case 'unknown':\n throw new UnknownPackageManagerError()\n }\n}\n\nasync function installDependencies(options: AddNPMDependenciesIfNeededOptions, args: string[]) {\n return runWithTimer('cmd_all_timing_network_ms')(async () => {\n return exec(options.packageManager, args, {\n cwd: options.directory,\n stdout: options.stdout,\n stderr: options.stderr,\n signal: options.signal,\n })\n })\n}\n\nexport async function addNPMDependenciesWithoutVersionIfNeeded(\n dependencies: string[],\n options: AddNPMDependenciesIfNeededOptions,\n): Promise<void> {\n await addNPMDependenciesIfNeeded(\n dependencies.map((dependency) => {\n return {name: dependency, version: undefined}\n }),\n options,\n )\n}\n\n/**\n * Returns the arguments to add dependencies using NPM.\n * @param dependencies - The list of dependencies to add\n * @param type - The dependency type.\n * @returns An array with the arguments.\n */\nfunction argumentsToAddDependenciesWithNPM(dependency: string, type: DependencyType): string[] {\n let command = ['install']\n command = command.concat(dependency)\n switch (type) {\n case 'dev':\n command.push('--save-dev')\n break\n case 'peer':\n command.push('--save-peer')\n break\n case 'prod':\n command.push('--save-prod')\n break\n }\n // NPM adds ^ to the installed version by default. We want to install exact versions unless specified otherwise.\n if (dependency.match(/@\\d/g)) {\n command.push('--save-exact')\n }\n return command\n}\n\n/**\n * Returns the arguments to add dependencies using Yarn.\n * @param dependencies - The list of dependencies to add\n * @param type - The dependency type.\n * @param addAtRoot - Force to install the dependencies in the workspace root (optional, default = false)\n * @returns An array with the arguments.\n */\nfunction argumentsToAddDependenciesWithYarn(dependencies: string[], type: DependencyType, addAtRoot = false): string[] {\n let command = ['add']\n\n if (addAtRoot) {\n command.push('-W')\n }\n\n command = command.concat(dependencies)\n switch (type) {\n case 'dev':\n command.push('--dev')\n break\n case 'peer':\n command.push('--peer')\n break\n case 'prod':\n command.push('--prod')\n break\n }\n return command\n}\n\n/**\n * Returns the arguments to add dependencies using PNPM.\n * @param dependencies - The list of dependencies to add\n * @param type - The dependency type.\n * @param addAtRoot - Force to install the dependencies in the workspace root (optional, default = false)\n * @returns An array with the arguments.\n */\nfunction argumentsToAddDependenciesWithPNPM(dependencies: string[], type: DependencyType, addAtRoot = false): string[] {\n let command = ['add']\n\n if (addAtRoot) {\n command.push('-w')\n }\n\n command = command.concat(dependencies)\n\n switch (type) {\n case 'dev':\n command.push('--save-dev')\n break\n case 'peer':\n command.push('--save-peer')\n break\n case 'prod':\n command.push('--save-prod')\n break\n }\n return command\n}\n\n/**\n * Returns the arguments to add dependencies using Bun.\n * @param dependencies - The list of dependencies to add\n * @param type - The dependency type.\n * @returns An array with the arguments.\n */\nfunction argumentsToAddDependenciesWithBun(dependencies: string[], type: DependencyType): string[] {\n let command = ['add']\n\n command = command.concat(dependencies)\n\n switch (type) {\n case 'dev':\n command.push('--development')\n break\n case 'peer':\n command.push('--optional')\n break\n case 'prod':\n break\n }\n return command\n}\n\n/**\n * Given a directory it traverses the directory up looking for a package.json and if found, it reads it\n * decodes the JSON, and returns its content as a Javascript object.\n * @param options - The directory from which traverse up.\n * @returns If found, the promise resolves with the path to the\n * package.json and its content. If not found, it throws a FindUpAndReadPackageJsonNotFoundError error.\n */\nexport async function findUpAndReadPackageJson(fromDirectory: string): Promise<{path: string; content: PackageJson}> {\n const packageJsonPath = await findPathUp('package.json', {cwd: fromDirectory, type: 'file'})\n if (packageJsonPath) {\n const packageJson = JSON.parse(await readFile(packageJsonPath))\n return {path: packageJsonPath, content: packageJson}\n } else {\n throw new FindUpAndReadPackageJsonNotFoundError(fromDirectory)\n }\n}\n\nexport async function addResolutionOrOverride(directory: string, dependencies: {[key: string]: string}): Promise<void> {\n const packageManager = await getPackageManager(directory)\n const packageJsonPath = joinPath(directory, 'package.json')\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n\n if (packageManager === 'yarn') {\n packageJsonContent.resolutions = packageJsonContent.resolutions\n ? {...packageJsonContent.resolutions, ...dependencies}\n : dependencies\n }\n if (packageManager === 'npm' || packageManager === 'pnpm' || packageManager === 'bun') {\n packageJsonContent.overrides = packageJsonContent.overrides\n ? {...packageJsonContent.overrides, ...dependencies}\n : dependencies\n }\n\n await writeFile(packageJsonPath, JSON.stringify(packageJsonContent, null, 2))\n}\n\n/**\n * Returns the latest available version of an NPM package.\n * @param name - The name of the NPM package.\n * @returns A promise to get the latest available version of a package.\n */\nasync function getLatestNPMPackageVersion(name: string) {\n outputDebug(outputContent`Getting the latest version of NPM package: ${outputToken.raw(name)}`)\n return runWithTimer('cmd_all_timing_network_ms')(() => {\n return latestVersion(name)\n })\n}\n\n/**\n * Writes the package.json file to the given directory.\n *\n * @param directory - Directory where the package.json file will be written.\n * @param packageJSON - Package.json file to write.\n */\nexport async function writePackageJSON(directory: string, packageJSON: PackageJson): Promise<void> {\n outputDebug(outputContent`JSON-encoding and writing content to package.json at ${outputToken.path(directory)}...`)\n const packagePath = joinPath(directory, 'package.json')\n await writeFile(packagePath, JSON.stringify(packageJSON, null, 2))\n}\n\n/**\n * Infers the package manager to be used based on the provided options and environment.\n *\n * This function determines the package manager in the following order of precedence:\n * 1. Uses the package manager specified in the options, if valid.\n * 2. Infers the package manager from the user agent string.\n * 3. Infers the package manager used for the global CLI installation.\n * 4. Defaults to 'npm' if no other method succeeds.\n *\n * @param optionsPackageManager - The package manager specified in the options (if any).\n * @returns The inferred package manager as a PackageManager type.\n */\nexport function inferPackageManager(optionsPackageManager: string | undefined, env = process.env): PackageManager {\n if (optionsPackageManager && packageManager.includes(optionsPackageManager as PackageManager)) {\n return optionsPackageManager as PackageManager\n }\n const usedPackageManager = packageManagerFromUserAgent(env)\n if (usedPackageManager !== 'unknown') return usedPackageManager\n\n const globalPackageManager = inferPackageManagerForGlobalCLI()\n if (globalPackageManager !== 'unknown') return globalPackageManager\n\n return 'npm'\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { MetafieldOwnerType } from '../../../cli/api/graphql/admin/generated/types.js';
1
2
  import { AdminSession } from '@shopify/cli-kit/node/session';
2
3
  import { Result, Checksum, Key, Theme, ThemeAsset } from '@shopify/cli-kit/node/themes/types';
3
4
  export type ThemeParams = Partial<Pick<Theme, 'name' | 'role' | 'processing' | 'src'>>;
@@ -12,3 +13,13 @@ export declare function fetchChecksums(id: number, session: AdminSession): Promi
12
13
  export declare function themeUpdate(id: number, params: ThemeParams, session: AdminSession): Promise<Theme | undefined>;
13
14
  export declare function themePublish(id: number, session: AdminSession): Promise<Theme | undefined>;
14
15
  export declare function themeDelete(id: number, session: AdminSession): Promise<boolean | undefined>;
16
+ export declare function metafieldDefinitionsByOwnerType(type: MetafieldOwnerType, session: AdminSession): Promise<{
17
+ key: string;
18
+ namespace: string;
19
+ name: string;
20
+ description: string | null | undefined;
21
+ type: {
22
+ name: string;
23
+ category: string;
24
+ };
25
+ }[]>;
@@ -7,22 +7,67 @@ import { ThemePublish } from '../../../cli/api/graphql/admin/generated/theme_pub
7
7
  import { GetThemeFileBodies } from '../../../cli/api/graphql/admin/generated/get_theme_file_bodies.js';
8
8
  import { GetThemeFileChecksums } from '../../../cli/api/graphql/admin/generated/get_theme_file_checksums.js';
9
9
  import { ThemeFilesUpsert, } from '../../../cli/api/graphql/admin/generated/theme_files_upsert.js';
10
+ import { MetafieldDefinitionsByOwnerType } from '../../../cli/api/graphql/admin/generated/metafield_definitions_by_owner_type.js';
11
+ import { GetThemes } from '../../../cli/api/graphql/admin/generated/get_themes.js';
12
+ import { GetTheme } from '../../../cli/api/graphql/admin/generated/get_theme.js';
10
13
  import { restRequest, adminRequestDoc } from '@shopify/cli-kit/node/api/admin';
11
14
  import { AbortError } from '@shopify/cli-kit/node/error';
12
15
  import { buildTheme } from '@shopify/cli-kit/node/themes/factories';
13
16
  import { Operation } from '@shopify/cli-kit/node/themes/types';
14
17
  import { outputDebug } from '@shopify/cli-kit/node/output';
15
18
  import { sleep } from '@shopify/cli-kit/node/system';
19
+ import { ClientError } from 'graphql-request';
16
20
  export async function fetchTheme(id, session) {
17
- const response = await request('GET', `/themes/${id}`, session, undefined, { fields: 'id,name,role,processing' });
18
- return buildTheme(response.json.theme);
21
+ try {
22
+ const response = await adminRequestDoc(GetTheme, session, { id: composeThemeGid(id) }, undefined, {
23
+ handleErrors: false,
24
+ });
25
+ const { theme } = response;
26
+ if (!theme) {
27
+ return undefined;
28
+ }
29
+ return buildTheme({
30
+ id: parseGid(theme.id),
31
+ processing: theme.processing,
32
+ role: theme.role.toLowerCase(),
33
+ name: theme.name,
34
+ });
35
+ }
36
+ catch (error) {
37
+ if (error instanceof ClientError) {
38
+ if (error.response?.errors?.[0]?.message === 'Theme does not exist') {
39
+ return undefined;
40
+ }
41
+ }
42
+ throw new AbortError(`Failed to fetch theme: ${id}`);
43
+ }
19
44
  }
20
45
  export async function fetchThemes(session) {
21
- const response = await request('GET', '/themes', session, undefined, { fields: 'id,name,role,processing' });
22
- const themes = response.json?.themes;
23
- if (themes?.length > 0)
24
- return themes.map(buildTheme);
25
- return [];
46
+ const themes = [];
47
+ let after = null;
48
+ while (true) {
49
+ // eslint-disable-next-line no-await-in-loop
50
+ const response = await adminRequestDoc(GetThemes, session, { after });
51
+ if (!response.themes) {
52
+ unexpectedGraphQLError('Failed to fetch themes');
53
+ }
54
+ const { nodes, pageInfo } = response.themes;
55
+ nodes.forEach((theme) => {
56
+ const t = buildTheme({
57
+ id: parseGid(theme.id),
58
+ processing: theme.processing,
59
+ role: theme.role.toLowerCase(),
60
+ name: theme.name,
61
+ });
62
+ if (t) {
63
+ themes.push(t);
64
+ }
65
+ });
66
+ if (!pageInfo.hasNextPage) {
67
+ return themes;
68
+ }
69
+ after = pageInfo.endCursor;
70
+ }
26
71
  }
27
72
  export async function createTheme(params, session) {
28
73
  const response = await request('POST', '/themes', session, { theme: { ...params } });
@@ -221,6 +266,21 @@ export async function themeDelete(id, session) {
221
266
  }
222
267
  return true;
223
268
  }
269
+ export async function metafieldDefinitionsByOwnerType(type, session) {
270
+ const { metafieldDefinitions } = await adminRequestDoc(MetafieldDefinitionsByOwnerType, session, {
271
+ ownerType: type,
272
+ });
273
+ return metafieldDefinitions.nodes.map((definition) => ({
274
+ key: definition.key,
275
+ namespace: definition.namespace,
276
+ name: definition.name,
277
+ description: definition.description,
278
+ type: {
279
+ name: definition.type.name,
280
+ category: definition.type.category,
281
+ },
282
+ }));
283
+ }
224
284
  async function request(method, path, session, params, searchParams = {}, retries = 1) {
225
285
  const response = await throttler.throttle(() => restRequest(method, path, session, params, searchParams));
226
286
  const status = response.status;
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../src/public/node/themes/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,WAAW,CAAA;AACvC,OAAO,EAAC,eAAe,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAA;AACpD,OAAO,KAAK,SAAS,MAAM,8BAA8B,CAAA;AACzD,OAAO,EAAC,WAAW,EAAC,MAAM,0DAA0D,CAAA;AACpF,OAAO,EAAC,WAAW,EAAC,MAAM,0DAA0D,CAAA;AACpF,OAAO,EAAC,YAAY,EAAC,MAAM,2DAA2D,CAAA;AACtF,OAAO,EAAC,kBAAkB,EAAC,MAAM,mEAAmE,CAAA;AACpG,OAAO,EAAC,qBAAqB,EAAC,MAAM,sEAAsE,CAAA;AAC1G,OAAO,EACL,gBAAgB,GAEjB,MAAM,gEAAgE,CAAA;AAKvE,OAAO,EAAC,WAAW,EAAgB,eAAe,EAAC,MAAM,iCAAiC,CAAA;AAE1F,OAAO,EAAC,UAAU,EAAC,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAC,UAAU,EAAC,MAAM,wCAAwC,CAAA;AACjE,OAAO,EAA2C,SAAS,EAAC,MAAM,oCAAoC,CAAA;AACtG,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAA;AACxD,OAAO,EAAC,KAAK,EAAC,MAAM,8BAA8B,CAAA;AAKlD,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,EAAU,EAAE,OAAqB;IAChE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,EAAC,MAAM,EAAE,yBAAyB,EAAC,CAAC,CAAA;IAC/G,OAAO,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK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AC,CAAC,QAAQ,EAAE,CAAA;QAC7D,KAAK,6BAA6B;YAChC,IAAI;gBACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;gBACtC,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;aAC7B;YAAC,OAAO,KAAK,EAAE;gBACd,4CAA4C;gBAC5C,MAAM,IAAI,UAAU,CAAC,uCAAuC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;aACxE;KACJ;AACH,CAAC","sourcesContent":["import {storeAdminUrl} from './urls.js'\nimport {composeThemeGid, parseGid} from './utils.js'\nimport * as throttler from '../api/rest-api-throttler.js'\nimport {ThemeUpdate} from '../../../cli/api/graphql/admin/generated/theme_update.js'\nimport {ThemeDelete} from '../../../cli/api/graphql/admin/generated/theme_delete.js'\nimport {ThemePublish} from '../../../cli/api/graphql/admin/generated/theme_publish.js'\nimport {GetThemeFileBodies} from '../../../cli/api/graphql/admin/generated/get_theme_file_bodies.js'\nimport {GetThemeFileChecksums} from '../../../cli/api/graphql/admin/generated/get_theme_file_checksums.js'\nimport {\n ThemeFilesUpsert,\n ThemeFilesUpsertMutation,\n} from '../../../cli/api/graphql/admin/generated/theme_files_upsert.js'\nimport {\n OnlineStoreThemeFileBodyInputType,\n OnlineStoreThemeFilesUpsertFileInput,\n} from '../../../cli/api/graphql/admin/generated/types.js'\nimport {restRequest, RestResponse, adminRequestDoc} from '@shopify/cli-kit/node/api/admin'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\nimport {AbortError} from '@shopify/cli-kit/node/error'\nimport {buildTheme} from '@shopify/cli-kit/node/themes/factories'\nimport {Result, Checksum, Key, Theme, ThemeAsset, Operation} from '@shopify/cli-kit/node/themes/types'\nimport {outputDebug} from '@shopify/cli-kit/node/output'\nimport {sleep} from '@shopify/cli-kit/node/system'\n\nexport type ThemeParams = Partial<Pick<Theme, 'name' | 'role' | 'processing' | 'src'>>\nexport type AssetParams = Pick<ThemeAsset, 'key'> & Partial<Pick<ThemeAsset, 'value' | 'attachment'>>\n\nexport async function fetchTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('GET', `/themes/${id}`, session, undefined, {fields: 'id,name,role,processing'})\n return buildTheme(response.json.theme)\n}\n\nexport async function fetchThemes(session: AdminSession): Promise<Theme[]> {\n const response = await request('GET', '/themes', session, undefined, {fields: 'id,name,role,processing'})\n const themes = response.json?.themes\n if (themes?.length > 0) return themes.map(buildTheme)\n return []\n}\n\nexport async function createTheme(params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('POST', '/themes', session, {theme: {...params}})\n\n if (!params.src) {\n const minimumThemeAssets = [\n {key: 'config/settings_schema.json', value: '[]'},\n {key: 'layout/password.liquid', value: '{{ content_for_header }}{{ content_for_layout }}'},\n {key: 'layout/theme.liquid', value: '{{ content_for_header }}{{ content_for_layout }}'},\n ]\n\n await bulkUploadThemeAssets(response.json.theme.id, minimumThemeAssets, session)\n }\n\n return buildTheme({...response.json.theme, createdAtRuntime: true})\n}\n\nexport async function fetchThemeAssets(id: number, filenames: Key[], session: AdminSession): Promise<ThemeAsset[]> {\n const assets: ThemeAsset[] = []\n let after: string | null = null\n\n while (true) {\n // eslint-disable-next-line no-await-in-loop\n const response = await adminRequestDoc(GetThemeFileBodies, session, {\n id: themeGid(id),\n filenames,\n after,\n })\n\n if (!response.theme?.files?.nodes || !response.theme?.files?.pageInfo) {\n const userErrors = response.theme?.files?.userErrors.map((error) => error.filename).join(', ')\n unexpectedGraphQLError(`Error fetching assets: ${userErrors}`)\n }\n\n const {nodes, pageInfo} = response.theme.files\n\n assets.push(\n // eslint-disable-next-line no-await-in-loop\n ...(await Promise.all(\n nodes.map(async (file) => {\n const content = await parseThemeFileContent(file.body)\n return {\n key: file.filename,\n checksum: file.checksumMd5 as string,\n value: content,\n }\n }),\n )),\n )\n\n if (!pageInfo.hasNextPage) {\n return assets\n }\n\n after = pageInfo.endCursor as string\n }\n}\n\nexport async function deleteThemeAsset(id: number, key: Key, session: AdminSession): Promise<boolean> {\n const response = await request('DELETE', `/themes/${id}/assets`, session, undefined, {\n 'asset[key]': key,\n })\n return response.status === 200\n}\n\nexport async function bulkUploadThemeAssets(\n id: number,\n assets: AssetParams[],\n session: AdminSession,\n): Promise<Result[]> {\n const results: Result[] = []\n for (let i = 0; i < assets.length; i += 50) {\n const chunk = assets.slice(i, i + 50)\n const files = prepareFilesForUpload(chunk)\n // eslint-disable-next-line no-await-in-loop\n const uploadResults = await uploadFiles(id, files, session)\n results.push(...processUploadResults(uploadResults))\n }\n return results\n}\n\nfunction prepareFilesForUpload(assets: AssetParams[]): OnlineStoreThemeFilesUpsertFileInput[] {\n return assets.map((asset) => {\n if (asset.attachment) {\n return {\n filename: asset.key,\n body: {\n type: 'BASE64' as const,\n value: asset.attachment,\n },\n }\n } else {\n return {\n filename: asset.key,\n body: {\n type: 'TEXT' as const,\n value: asset.value ?? '',\n },\n }\n }\n })\n}\n\nasync function uploadFiles(\n themeId: number,\n files: {filename: string; body: {type: OnlineStoreThemeFileBodyInputType; value: string}}[],\n session: AdminSession,\n): Promise<ThemeFilesUpsertMutation> {\n return adminRequestDoc(ThemeFilesUpsert, session, {themeId: themeGid(themeId), files})\n}\n\nfunction processUploadResults(uploadResults: ThemeFilesUpsertMutation): Result[] {\n const {themeFilesUpsert} = uploadResults\n\n if (!themeFilesUpsert) {\n unexpectedGraphQLError('Failed to upload theme files')\n }\n\n const {upsertedThemeFiles, userErrors} = themeFilesUpsert\n\n const results: Result[] = []\n\n upsertedThemeFiles?.forEach((file) => {\n results.push({\n key: file.filename,\n success: true,\n operation: Operation.Upload,\n })\n })\n\n userErrors.forEach((error) => {\n if (!error.filename) {\n unexpectedGraphQLError(`Error uploading theme files: ${error.message}`)\n }\n results.push({\n key: error.filename,\n success: false,\n operation: Operation.Upload,\n errors: {asset: [error.message]},\n })\n })\n\n return results\n}\n\nexport async function fetchChecksums(id: number, session: AdminSession): Promise<Checksum[]> {\n const checksums: Checksum[] = []\n let after: string | null = null\n\n while (true) {\n // eslint-disable-next-line no-await-in-loop\n const response = await adminRequestDoc(GetThemeFileChecksums, session, {id: themeGid(id), after})\n\n if (!response?.theme?.files?.nodes || !response?.theme?.files?.pageInfo) {\n const userErrors = response.theme?.files?.userErrors.map((error) => error.filename).join(', ')\n throw new AbortError(`Failed to fetch checksums for: ${userErrors}`)\n }\n\n const {nodes, pageInfo} = response.theme.files\n\n checksums.push(\n ...nodes.map((file) => ({\n key: file.filename,\n checksum: file.checksumMd5 as string,\n })),\n )\n\n if (!pageInfo.hasNextPage) {\n return checksums\n }\n\n after = pageInfo.endCursor as string\n }\n}\n\nexport async function themeUpdate(id: number, params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const name = params.name\n const input: {[key: string]: string} = {}\n if (name) {\n input.name = name\n }\n\n const {themeUpdate} = await adminRequestDoc(ThemeUpdate, session, {id: composeThemeGid(id), input})\n if (!themeUpdate) {\n // An unexpected error occurred during the GraphQL request execution\n unexpectedGraphQLError('Failed to update theme')\n }\n\n const {theme, userErrors} = themeUpdate\n if (userErrors.length) {\n const userErrors = themeUpdate.userErrors.map((error) => error.message).join(', ')\n throw new AbortError(userErrors)\n }\n\n if (!theme) {\n // An unexpected error if neither theme nor userErrors are returned\n unexpectedGraphQLError('Failed to update theme')\n }\n\n return buildTheme({\n id: parseGid(theme.id),\n name: theme.name,\n role: theme.role.toLowerCase(),\n })\n}\n\nexport async function themePublish(id: number, session: AdminSession): Promise<Theme | undefined> {\n const {themePublish} = await adminRequestDoc(ThemePublish, session, {id: composeThemeGid(id)})\n if (!themePublish) {\n // An unexpected error occurred during the GraphQL request execution\n unexpectedGraphQLError('Failed to update theme')\n }\n\n const {theme, userErrors} = themePublish\n if (userErrors.length) {\n const userErrors = themePublish.userErrors.map((error) => error.message).join(', ')\n throw new AbortError(userErrors)\n }\n\n if (!theme) {\n // An unexpected error if neither theme nor userErrors are returned\n unexpectedGraphQLError('Failed to update theme')\n }\n\n return buildTheme({\n id: parseGid(theme.id),\n name: theme.name,\n role: theme.role.toLowerCase(),\n })\n}\n\nexport async function themeDelete(id: number, session: AdminSession): Promise<boolean | undefined> {\n const {themeDelete} = await adminRequestDoc(ThemeDelete, session, {id: composeThemeGid(id)})\n if (!themeDelete) {\n // An unexpected error occurred during the GraphQL request execution\n unexpectedGraphQLError('Failed to update theme')\n }\n\n const {deletedThemeId, userErrors} = themeDelete\n if (userErrors.length) {\n const userErrors = themeDelete.userErrors.map((error) => error.message).join(', ')\n throw new AbortError(userErrors)\n }\n\n if (!deletedThemeId) {\n // An unexpected error if neither theme nor userErrors are returned\n unexpectedGraphQLError('Failed to update theme')\n }\n\n return true\n}\n\nasync function request<T>(\n method: string,\n path: string,\n session: AdminSession,\n params?: T,\n searchParams: {[name: string]: string} = {},\n retries = 1,\n): Promise<RestResponse> {\n const response = await throttler.throttle(() => restRequest(method, path, session, params, searchParams))\n\n const status = response.status\n\n throttler.updateApiCallLimitFromResponse(response)\n\n switch (true) {\n case status >= 200 && status <= 399:\n // Returns the successful reponse\n return response\n case status === 404:\n // Defer the decision when a resource is not found\n return response\n case status === 429:\n // Retry following the \"retry-after\" header\n return throttler.delayAwareRetry(response, () => request(method, path, session, params, searchParams))\n case status === 403:\n return handleForbiddenError(response, session)\n case status === 401:\n /**\n * We need to resolve the call to the refresh function at runtime to\n * avoid a circular reference.\n *\n * This won't be necessary when https://github.com/Shopify/cli/issues/4769\n * gets resolved, and this condition must be removed then.\n */\n if ('refresh' in session) {\n const refresh = session.refresh as () => Promise<void>\n await refresh()\n }\n\n // Retry 401 errors to be resilient to authentication errors.\n return handleRetriableError({\n path,\n retries,\n retry: () => {\n return request(method, path, session, params, searchParams, retries + 1)\n },\n fail: () => {\n throw new AbortError(`[${status}] API request unauthorized error`)\n },\n })\n case status === 422:\n throw new AbortError(`[${status}] API request unprocessable content: ${errors(response)}`)\n case status >= 400 && status <= 499:\n throw new AbortError(`[${status}] API request client error`)\n case status >= 500 && status <= 599:\n // Retry 500-family of errors as that may solve the issue (especially in 503 errors)\n return handleRetriableError({\n path,\n retries,\n retry: () => {\n return request(method, path, session, params, searchParams, retries + 1)\n },\n fail: () => {\n throw new AbortError(`[${status}] API request server error`)\n },\n })\n default:\n throw new AbortError(`[${status}] API request unexpected error`)\n }\n}\n\nfunction handleForbiddenError(response: RestResponse, session: AdminSession): never {\n const store = session.storeFqdn\n const adminUrl = storeAdminUrl(session)\n const error = errorMessage(response)\n\n if (error.match(/Cannot delete generated asset/) !== null) {\n throw new AbortError(error)\n }\n\n throw new AbortError(\n `You are not authorized to edit themes on \"${store}\".`,\n \"You can't use Shopify CLI with development stores if you only have Partner staff \" +\n 'member access. If you want to use Shopify CLI to work on a development store, then ' +\n 'you should be the store owner or create a staff account on the store.' +\n '\\n\\n' +\n \"If you're the store owner, then you need to log in to the store directly using the \" +\n `store URL at least once (for example, using \"${adminUrl}\") before you log in using ` +\n 'Shopify CLI. Logging in to the Shopify admin directly connects the development ' +\n 'store with your Shopify login.',\n )\n}\n\nfunction errors(response: RestResponse) {\n return JSON.stringify(response.json?.errors)\n}\n\nfunction errorMessage(response: RestResponse): string {\n const message = response.json?.message\n\n if (typeof message === 'string') {\n return message\n }\n\n return ''\n}\n\nfunction unexpectedGraphQLError(message: string): never {\n throw new AbortError(message)\n}\n\ninterface RetriableErrorOptions {\n path: string\n retries: number\n retry: () => Promise<RestResponse>\n fail: () => never\n}\n\nasync function handleRetriableError({path, retries, retry, fail}: RetriableErrorOptions): Promise<RestResponse> {\n if (retries >= 3) {\n fail()\n }\n\n outputDebug(`[${retries}] Retrying '${path}' request...`)\n\n await sleep(0.2)\n return retry()\n}\n\nfunction themeGid(id: number): string {\n return `gid://shopify/OnlineStoreTheme/${id}`\n}\n\ntype OnlineStoreThemeFileBody =\n | {__typename: 'OnlineStoreThemeFileBodyBase64'; contentBase64: string}\n | {__typename: 'OnlineStoreThemeFileBodyText'; content: string}\n | {__typename: 'OnlineStoreThemeFileBodyUrl'; url: string}\n\nasync function parseThemeFileContent(body: OnlineStoreThemeFileBody): Promise<string> {\n switch (body.__typename) {\n case 'OnlineStoreThemeFileBodyText':\n return body.content\n case 'OnlineStoreThemeFileBodyBase64':\n return Buffer.from(body.contentBase64, 'base64').toString()\n case 'OnlineStoreThemeFileBodyUrl':\n try {\n const response = await fetch(body.url)\n return await response.text()\n } catch (error) {\n // Raise error if we can't download the file\n throw new AbortError(`Error downloading content from URL: ${body.url}`)\n }\n }\n}\n"]}
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../src/public/node/themes/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,WAAW,CAAA;AACvC,OAAO,EAAC,eAAe,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAA;AACpD,OAAO,KAAK,SAAS,MAAM,8BAA8B,CAAA;AACzD,OAAO,EAAC,WAAW,EAAC,MAAM,0DAA0D,CAAA;AACpF,OAAO,EAAC,WAAW,EAAC,MAAM,0DAA0D,CAAA;AACpF,OAAO,EAAC,YAAY,EAAC,MAAM,2DAA2D,CAAA;AACtF,OAAO,EAAC,kBAAkB,EAAC,MAAM,mEAAmE,CAAA;AACpG,OAAO,EAAC,qBAAqB,EAAC,MAAM,sEAAsE,CAAA;AAC1G,OAAO,EACL,gBAAgB,GAEjB,MAAM,gEAAgE,CAAA;AAMvE,OAAO,EAAC,+BAA+B,EAAC,MAAM,iFAAiF,CAAA;AAC/H,OAAO,EAAC,SAAS,EAAC,MAAM,wDAAwD,CAAA;AAChF,OAAO,EAAC,QAAQ,EAAC,MAAM,uDAAuD,CAAA;AAC9E,OAAO,EAAC,WAAW,EAAgB,eAAe,EAAC,MAAM,iCAAiC,CAAA;AAE1F,OAAO,EAAC,UAAU,EAAC,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAC,UAAU,EAAC,MAAM,wCAAwC,CAAA;AACjE,OAAO,EAA2C,SAAS,EAAC,MAAM,oCAAoC,CAAA;AACtG,OAAO,EA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Content":["import {storeAdminUrl} from './urls.js'\nimport {composeThemeGid, parseGid} from './utils.js'\nimport * as throttler from '../api/rest-api-throttler.js'\nimport {ThemeUpdate} from '../../../cli/api/graphql/admin/generated/theme_update.js'\nimport {ThemeDelete} from '../../../cli/api/graphql/admin/generated/theme_delete.js'\nimport {ThemePublish} from '../../../cli/api/graphql/admin/generated/theme_publish.js'\nimport {GetThemeFileBodies} from '../../../cli/api/graphql/admin/generated/get_theme_file_bodies.js'\nimport {GetThemeFileChecksums} from '../../../cli/api/graphql/admin/generated/get_theme_file_checksums.js'\nimport {\n ThemeFilesUpsert,\n ThemeFilesUpsertMutation,\n} from '../../../cli/api/graphql/admin/generated/theme_files_upsert.js'\nimport {\n OnlineStoreThemeFileBodyInputType,\n OnlineStoreThemeFilesUpsertFileInput,\n MetafieldOwnerType,\n} from '../../../cli/api/graphql/admin/generated/types.js'\nimport {MetafieldDefinitionsByOwnerType} from '../../../cli/api/graphql/admin/generated/metafield_definitions_by_owner_type.js'\nimport {GetThemes} from '../../../cli/api/graphql/admin/generated/get_themes.js'\nimport {GetTheme} from '../../../cli/api/graphql/admin/generated/get_theme.js'\nimport {restRequest, RestResponse, adminRequestDoc} from '@shopify/cli-kit/node/api/admin'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\nimport {AbortError} from '@shopify/cli-kit/node/error'\nimport {buildTheme} from '@shopify/cli-kit/node/themes/factories'\nimport {Result, Checksum, Key, Theme, ThemeAsset, Operation} from '@shopify/cli-kit/node/themes/types'\nimport {outputDebug} from '@shopify/cli-kit/node/output'\nimport {sleep} from '@shopify/cli-kit/node/system'\nimport {ClientError} from 'graphql-request'\n\nexport type ThemeParams = Partial<Pick<Theme, 'name' | 'role' | 'processing' | 'src'>>\nexport type AssetParams = Pick<ThemeAsset, 'key'> & Partial<Pick<ThemeAsset, 'value' | 'attachment'>>\n\nexport async function fetchTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n try {\n const response = await adminRequestDoc(GetTheme, session, {id: composeThemeGid(id)}, undefined, {\n handleErrors: false,\n })\n const {theme} = response\n if (!theme) {\n return undefined\n }\n return buildTheme({\n id: parseGid(theme.id),\n processing: theme.processing,\n role: theme.role.toLowerCase(),\n name: theme.name,\n })\n } catch (error) {\n if (error instanceof ClientError) {\n if (error.response?.errors?.[0]?.message === 'Theme does not exist') {\n return undefined\n }\n }\n throw new AbortError(`Failed to fetch theme: ${id}`)\n }\n}\n\nexport async function fetchThemes(session: AdminSession): Promise<Theme[]> {\n const themes: Theme[] = []\n let after: string | null = null\n\n while (true) {\n // eslint-disable-next-line no-await-in-loop\n const response = await adminRequestDoc(GetThemes, session, {after})\n if (!response.themes) {\n unexpectedGraphQLError('Failed to fetch themes')\n }\n const {nodes, pageInfo} = response.themes\n nodes.forEach((theme) => {\n const t = buildTheme({\n id: parseGid(theme.id),\n processing: theme.processing,\n role: theme.role.toLowerCase(),\n name: theme.name,\n })\n if (t) {\n themes.push(t)\n }\n })\n if (!pageInfo.hasNextPage) {\n return themes\n }\n\n after = pageInfo.endCursor as string\n }\n}\n\nexport async function createTheme(params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('POST', '/themes', session, {theme: {...params}})\n\n if (!params.src) {\n const minimumThemeAssets = [\n {key: 'config/settings_schema.json', value: '[]'},\n {key: 'layout/password.liquid', value: '{{ content_for_header }}{{ content_for_layout }}'},\n {key: 'layout/theme.liquid', value: '{{ content_for_header }}{{ content_for_layout }}'},\n ]\n\n await bulkUploadThemeAssets(response.json.theme.id, minimumThemeAssets, session)\n }\n\n return buildTheme({...response.json.theme, createdAtRuntime: true})\n}\n\nexport async function fetchThemeAssets(id: number, filenames: Key[], session: AdminSession): Promise<ThemeAsset[]> {\n const assets: ThemeAsset[] = []\n let after: string | null = null\n\n while (true) {\n // eslint-disable-next-line no-await-in-loop\n const response = await adminRequestDoc(GetThemeFileBodies, session, {\n id: themeGid(id),\n filenames,\n after,\n })\n\n if (!response.theme?.files?.nodes || !response.theme?.files?.pageInfo) {\n const userErrors = response.theme?.files?.userErrors.map((error) => error.filename).join(', ')\n unexpectedGraphQLError(`Error fetching assets: ${userErrors}`)\n }\n\n const {nodes, pageInfo} = response.theme.files\n\n assets.push(\n // eslint-disable-next-line no-await-in-loop\n ...(await Promise.all(\n nodes.map(async (file) => {\n const content = await parseThemeFileContent(file.body)\n return {\n key: file.filename,\n checksum: file.checksumMd5 as string,\n value: content,\n }\n }),\n )),\n )\n\n if (!pageInfo.hasNextPage) {\n return assets\n }\n\n after = pageInfo.endCursor as string\n }\n}\n\nexport async function deleteThemeAsset(id: number, key: Key, session: AdminSession): Promise<boolean> {\n const response = await request('DELETE', `/themes/${id}/assets`, session, undefined, {\n 'asset[key]': key,\n })\n return response.status === 200\n}\n\nexport async function bulkUploadThemeAssets(\n id: number,\n assets: AssetParams[],\n session: AdminSession,\n): Promise<Result[]> {\n const results: Result[] = []\n for (let i = 0; i < assets.length; i += 50) {\n const chunk = assets.slice(i, i + 50)\n const files = prepareFilesForUpload(chunk)\n // eslint-disable-next-line no-await-in-loop\n const uploadResults = await uploadFiles(id, files, session)\n results.push(...processUploadResults(uploadResults))\n }\n return results\n}\n\nfunction prepareFilesForUpload(assets: AssetParams[]): OnlineStoreThemeFilesUpsertFileInput[] {\n return assets.map((asset) => {\n if (asset.attachment) {\n return {\n filename: asset.key,\n body: {\n type: 'BASE64' as const,\n value: asset.attachment,\n },\n }\n } else {\n return {\n filename: asset.key,\n body: {\n type: 'TEXT' as const,\n value: asset.value ?? '',\n },\n }\n }\n })\n}\n\nasync function uploadFiles(\n themeId: number,\n files: {filename: string; body: {type: OnlineStoreThemeFileBodyInputType; value: string}}[],\n session: AdminSession,\n): Promise<ThemeFilesUpsertMutation> {\n return adminRequestDoc(ThemeFilesUpsert, session, {themeId: themeGid(themeId), files})\n}\n\nfunction processUploadResults(uploadResults: ThemeFilesUpsertMutation): Result[] {\n const {themeFilesUpsert} = uploadResults\n\n if (!themeFilesUpsert) {\n unexpectedGraphQLError('Failed to upload theme files')\n }\n\n const {upsertedThemeFiles, userErrors} = themeFilesUpsert\n\n const results: Result[] = []\n\n upsertedThemeFiles?.forEach((file) => {\n results.push({\n key: file.filename,\n success: true,\n operation: Operation.Upload,\n })\n })\n\n userErrors.forEach((error) => {\n if (!error.filename) {\n unexpectedGraphQLError(`Error uploading theme files: ${error.message}`)\n }\n results.push({\n key: error.filename,\n success: false,\n operation: Operation.Upload,\n errors: {asset: [error.message]},\n })\n })\n\n return results\n}\n\nexport async function fetchChecksums(id: number, session: AdminSession): Promise<Checksum[]> {\n const checksums: Checksum[] = []\n let after: string | null = null\n\n while (true) {\n // eslint-disable-next-line no-await-in-loop\n const response = await adminRequestDoc(GetThemeFileChecksums, session, {id: themeGid(id), after})\n\n if (!response?.theme?.files?.nodes || !response?.theme?.files?.pageInfo) {\n const userErrors = response.theme?.files?.userErrors.map((error) => error.filename).join(', ')\n throw new AbortError(`Failed to fetch checksums for: ${userErrors}`)\n }\n\n const {nodes, pageInfo} = response.theme.files\n\n checksums.push(\n ...nodes.map((file) => ({\n key: file.filename,\n checksum: file.checksumMd5 as string,\n })),\n )\n\n if (!pageInfo.hasNextPage) {\n return checksums\n }\n\n after = pageInfo.endCursor as string\n }\n}\n\nexport async function themeUpdate(id: number, params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const name = params.name\n const input: {[key: string]: string} = {}\n if (name) {\n input.name = name\n }\n\n const {themeUpdate} = await adminRequestDoc(ThemeUpdate, session, {id: composeThemeGid(id), input})\n if (!themeUpdate) {\n // An unexpected error occurred during the GraphQL request execution\n unexpectedGraphQLError('Failed to update theme')\n }\n\n const {theme, userErrors} = themeUpdate\n if (userErrors.length) {\n const userErrors = themeUpdate.userErrors.map((error) => error.message).join(', ')\n throw new AbortError(userErrors)\n }\n\n if (!theme) {\n // An unexpected error if neither theme nor userErrors are returned\n unexpectedGraphQLError('Failed to update theme')\n }\n\n return buildTheme({\n id: parseGid(theme.id),\n name: theme.name,\n role: theme.role.toLowerCase(),\n })\n}\n\nexport async function themePublish(id: number, session: AdminSession): Promise<Theme | undefined> {\n const {themePublish} = await adminRequestDoc(ThemePublish, session, {id: composeThemeGid(id)})\n if (!themePublish) {\n // An unexpected error occurred during the GraphQL request execution\n unexpectedGraphQLError('Failed to update theme')\n }\n\n const {theme, userErrors} = themePublish\n if (userErrors.length) {\n const userErrors = themePublish.userErrors.map((error) => error.message).join(', ')\n throw new AbortError(userErrors)\n }\n\n if (!theme) {\n // An unexpected error if neither theme nor userErrors are returned\n unexpectedGraphQLError('Failed to update theme')\n }\n\n return buildTheme({\n id: parseGid(theme.id),\n name: theme.name,\n role: theme.role.toLowerCase(),\n })\n}\n\nexport async function themeDelete(id: number, session: AdminSession): Promise<boolean | undefined> {\n const {themeDelete} = await adminRequestDoc(ThemeDelete, session, {id: composeThemeGid(id)})\n if (!themeDelete) {\n // An unexpected error occurred during the GraphQL request execution\n unexpectedGraphQLError('Failed to update theme')\n }\n\n const {deletedThemeId, userErrors} = themeDelete\n if (userErrors.length) {\n const userErrors = themeDelete.userErrors.map((error) => error.message).join(', ')\n throw new AbortError(userErrors)\n }\n\n if (!deletedThemeId) {\n // An unexpected error if neither theme nor userErrors are returned\n unexpectedGraphQLError('Failed to update theme')\n }\n\n return true\n}\n\nexport async function metafieldDefinitionsByOwnerType(type: MetafieldOwnerType, session: AdminSession) {\n const {metafieldDefinitions} = await adminRequestDoc(MetafieldDefinitionsByOwnerType, session, {\n ownerType: type,\n })\n\n return metafieldDefinitions.nodes.map((definition) => ({\n key: definition.key,\n namespace: definition.namespace,\n name: definition.name,\n description: definition.description,\n type: {\n name: definition.type.name,\n category: definition.type.category,\n },\n }))\n}\n\nasync function request<T>(\n method: string,\n path: string,\n session: AdminSession,\n params?: T,\n searchParams: {[name: string]: string} = {},\n retries = 1,\n): Promise<RestResponse> {\n const response = await throttler.throttle(() => restRequest(method, path, session, params, searchParams))\n\n const status = response.status\n\n throttler.updateApiCallLimitFromResponse(response)\n\n switch (true) {\n case status >= 200 && status <= 399:\n // Returns the successful reponse\n return response\n case status === 404:\n // Defer the decision when a resource is not found\n return response\n case status === 429:\n // Retry following the \"retry-after\" header\n return throttler.delayAwareRetry(response, () => request(method, path, session, params, searchParams))\n case status === 403:\n return handleForbiddenError(response, session)\n case status === 401:\n /**\n * We need to resolve the call to the refresh function at runtime to\n * avoid a circular reference.\n *\n * This won't be necessary when https://github.com/Shopify/cli/issues/4769\n * gets resolved, and this condition must be removed then.\n */\n if ('refresh' in session) {\n const refresh = session.refresh as () => Promise<void>\n await refresh()\n }\n\n // Retry 401 errors to be resilient to authentication errors.\n return handleRetriableError({\n path,\n retries,\n retry: () => {\n return request(method, path, session, params, searchParams, retries + 1)\n },\n fail: () => {\n throw new AbortError(`[${status}] API request unauthorized error`)\n },\n })\n case status === 422:\n throw new AbortError(`[${status}] API request unprocessable content: ${errors(response)}`)\n case status >= 400 && status <= 499:\n throw new AbortError(`[${status}] API request client error`)\n case status >= 500 && status <= 599:\n // Retry 500-family of errors as that may solve the issue (especially in 503 errors)\n return handleRetriableError({\n path,\n retries,\n retry: () => {\n return request(method, path, session, params, searchParams, retries + 1)\n },\n fail: () => {\n throw new AbortError(`[${status}] API request server error`)\n },\n })\n default:\n throw new AbortError(`[${status}] API request unexpected error`)\n }\n}\n\nfunction handleForbiddenError(response: RestResponse, session: AdminSession): never {\n const store = session.storeFqdn\n const adminUrl = storeAdminUrl(session)\n const error = errorMessage(response)\n\n if (error.match(/Cannot delete generated asset/) !== null) {\n throw new AbortError(error)\n }\n\n throw new AbortError(\n `You are not authorized to edit themes on \"${store}\".`,\n \"You can't use Shopify CLI with development stores if you only have Partner staff \" +\n 'member access. If you want to use Shopify CLI to work on a development store, then ' +\n 'you should be the store owner or create a staff account on the store.' +\n '\\n\\n' +\n \"If you're the store owner, then you need to log in to the store directly using the \" +\n `store URL at least once (for example, using \"${adminUrl}\") before you log in using ` +\n 'Shopify CLI. Logging in to the Shopify admin directly connects the development ' +\n 'store with your Shopify login.',\n )\n}\n\nfunction errors(response: RestResponse) {\n return JSON.stringify(response.json?.errors)\n}\n\nfunction errorMessage(response: RestResponse): string {\n const message = response.json?.message\n\n if (typeof message === 'string') {\n return message\n }\n\n return ''\n}\n\nfunction unexpectedGraphQLError(message: string): never {\n throw new AbortError(message)\n}\n\ninterface RetriableErrorOptions {\n path: string\n retries: number\n retry: () => Promise<RestResponse>\n fail: () => never\n}\n\nasync function handleRetriableError({path, retries, retry, fail}: RetriableErrorOptions): Promise<RestResponse> {\n if (retries >= 3) {\n fail()\n }\n\n outputDebug(`[${retries}] Retrying '${path}' request...`)\n\n await sleep(0.2)\n return retry()\n}\n\nfunction themeGid(id: number): string {\n return `gid://shopify/OnlineStoreTheme/${id}`\n}\n\ntype OnlineStoreThemeFileBody =\n | {__typename: 'OnlineStoreThemeFileBodyBase64'; contentBase64: string}\n | {__typename: 'OnlineStoreThemeFileBodyText'; content: string}\n | {__typename: 'OnlineStoreThemeFileBodyUrl'; url: string}\n\nasync function parseThemeFileContent(body: OnlineStoreThemeFileBody): Promise<string> {\n switch (body.__typename) {\n case 'OnlineStoreThemeFileBodyText':\n return body.content\n case 'OnlineStoreThemeFileBodyBase64':\n return Buffer.from(body.contentBase64, 'base64').toString()\n case 'OnlineStoreThemeFileBodyUrl':\n try {\n const response = await fetch(body.url)\n return await response.text()\n } catch (error) {\n // Raise error if we can't download the file\n throw new AbortError(`Error downloading content from URL: ${body.url}`)\n }\n }\n}\n"]}