{
  "version": 3,
  "sources": ["../../../../src/packages/plugin-commands-installation/add.ts"],
  "sourcesContent": ["import { docsUrl } from '../cli-utils/index.ts';\nimport {\n  FILTERING,\n  OPTIONS,\n  UNIVERSAL_OPTIONS,\n} from '../common-cli-options-help/index.ts';\nimport { types as allTypes } from '../config/index.ts';\nimport { PnpmError } from '../error/index.ts';\nimport { prepareExecutionEnv } from '../plugin-commands-env/index.ts';\nimport pick from 'ramda/src/pick';\nimport renderHelp from 'render-help';\nimport { createProjectManifestWriter } from './createProjectManifestWriter.ts';\nimport type { InstallCommandOptions } from './install.ts';\nimport { installDeps } from './installDeps.ts';\nimport type { ProjectManifest } from '../types/index.ts';\n\nexport function rcOptionsTypes(): Record<string, unknown> {\n  return pick.default(\n    [\n      'cache-dir',\n      'child-concurrency',\n      'engine-strict',\n      'fetch-retries',\n      'fetch-retry-factor',\n      'fetch-retry-maxtimeout',\n      'fetch-retry-mintimeout',\n      'fetch-timeout',\n      'force',\n      'global-bin-dir',\n      'global-dir',\n      'global-pnpmfile',\n      'global',\n      'hoist',\n      'hoist-pattern',\n      'https-proxy',\n      'ignore-pnpmfile',\n      'ignore-scripts',\n      'ignore-workspace-root-check',\n      'link-workspace-packages',\n      'lockfile-dir',\n      'lockfile-directory',\n      'lockfile-only',\n      'lockfile',\n      'modules-dir',\n      'network-concurrency',\n      'node-linker',\n      'noproxy',\n      'npm-path',\n      'package-import-method',\n      'pnpmfile',\n      'prefer-offline',\n      'production',\n      'proxy',\n      'public-hoist-pattern',\n      'registry',\n      'reporter',\n      'save-dev',\n      'save-exact',\n      'save-optional',\n      'save-peer',\n      'save-prefix',\n      'save-prod',\n      'save-workspace-protocol',\n      'shamefully-flatten',\n      'shamefully-hoist',\n      'shared-workspace-lockfile',\n      'side-effects-cache-readonly',\n      'side-effects-cache',\n      'store-dir',\n      'strict-peer-dependencies',\n      'unsafe-perm',\n      'offline',\n      'only',\n      'optional',\n      'use-running-store-server',\n      'use-store-server',\n      'verify-store-integrity',\n      'virtual-store-dir',\n    ],\n    allTypes\n  );\n}\n\nexport function cliOptionsTypes(): Record<string, unknown> {\n  return {\n    ...rcOptionsTypes(),\n    'allow-build': [String, Array],\n    recursive: Boolean,\n    save: Boolean,\n    workspace: Boolean,\n  };\n}\n\nexport const commandNames = ['add'];\n\nexport function help(): string {\n  return renderHelp({\n    description: 'Installs a package and any packages that it depends on.',\n    descriptionLists: [\n      {\n        title: 'Options',\n\n        list: [\n          {\n            description:\n              'Save package to your `dependencies`. The default behavior',\n            name: '--save-prod',\n            shortAlias: '-P',\n          },\n          {\n            description: 'Save package to your `devDependencies`',\n            name: '--save-dev',\n            shortAlias: '-D',\n          },\n          {\n            description: 'Save package to your `optionalDependencies`',\n            name: '--save-optional',\n            shortAlias: '-O',\n          },\n          {\n            description:\n              'Save package to your `peerDependencies` and `devDependencies`',\n            name: '--save-peer',\n          },\n          {\n            description: 'Install exact version',\n            name: '--[no-]save-exact',\n            shortAlias: '-E',\n          },\n          {\n            description:\n              'Save packages from the workspace with a \"workspace:\" protocol. True by default',\n            name: '--[no-]save-workspace-protocol',\n          },\n          {\n            description: 'Install as a global package',\n            name: '--global',\n            shortAlias: '-g',\n          },\n          {\n            description:\n              'Run installation recursively in every package found in subdirectories \\\nor in every workspace package, when executed inside a workspace. \\\nFor options that may be used with `-r`, see \"pnpm help recursive\"',\n            name: '--recursive',\n            shortAlias: '-r',\n          },\n          {\n            description:\n              'Only adds the new dependency if it is found in the workspace',\n            name: '--workspace',\n          },\n          OPTIONS.ignoreScripts,\n          OPTIONS.offline,\n          OPTIONS.preferOffline,\n          OPTIONS.storeDir,\n          OPTIONS.virtualStoreDir,\n          OPTIONS.globalDir,\n          ...UNIVERSAL_OPTIONS,\n          {\n            description:\n              'A list of package names that are allowed to run postinstall scripts during installation',\n            name: '--allow-build',\n          },\n        ],\n      },\n      FILTERING,\n    ],\n    url: docsUrl('add'),\n    usages: [\n      'pnpm add <name>',\n      'pnpm add <name>@<tag>',\n      'pnpm add <name>@<version>',\n      'pnpm add <name>@<version range>',\n      'pnpm add <git host>:<git user>/<repo name>',\n      'pnpm add <git repo url>',\n      'pnpm add <tarball file>',\n      'pnpm add <tarball url>',\n      'pnpm add <dir>',\n    ],\n  });\n}\n\nexport type AddCommandOptions = InstallCommandOptions & {\n  allowBuild?: string[] | undefined;\n  allowNew?: boolean | undefined;\n  ignoreWorkspaceRootCheck?: boolean | undefined;\n  save?: boolean | undefined;\n  update?: boolean | undefined;\n  useBetaCli?: boolean | undefined;\n  workspaceRoot?: boolean | undefined;\n};\n\nexport async function handler(\n  opts: AddCommandOptions,\n  params: string[]\n): Promise<void> {\n  if (opts.cliOptions['save'] === false) {\n    throw new PnpmError(\n      'OPTION_NOT_SUPPORTED',\n      'The \"add\" command currently does not support the no-save option'\n    );\n  }\n\n  if (params.length === 0) {\n    throw new PnpmError(\n      'MISSING_PACKAGE_NAME',\n      '`pnpm add` requires the package name'\n    );\n  }\n\n  if (\n    opts.recursive !== true &&\n    opts.workspaceDir === opts.dir &&\n    opts.ignoreWorkspaceRootCheck !== true &&\n    opts.workspaceRoot !== true &&\n    opts.workspacePackagePatterns &&\n    opts.workspacePackagePatterns.length > 1\n  ) {\n    throw new PnpmError(\n      'ADDING_TO_ROOT',\n      'Running this command will add the dependency to the workspace root, ' +\n        'which might not be what you want - if you really meant it, ' +\n        'make it explicit by running this command again with the -w flag (or --workspace-root). ' +\n        \"If you don't want to see this warning anymore, you may set the ignore-workspace-root-check setting to true.\"\n    );\n  }\n  if (opts.global === true) {\n    if (!opts.bin) {\n      throw new PnpmError(\n        'NO_GLOBAL_BIN_DIR',\n        'Unable to find the global bin directory',\n        {\n          hint: 'Run \"pnpm setup\" to create it automatically, or set the global-bin-dir setting, or the PNPM_HOME env variable. The global bin directory should be in the PATH.',\n        }\n      );\n    }\n\n    if (params.includes('pnpm') || params.includes('@pnpm/exe')) {\n      throw new PnpmError(\n        'GLOBAL_PNPM_INSTALL',\n        'Use the \"pnpm self-update\" command to install or update pnpm'\n      );\n    }\n  }\n\n  const include = {\n    dependencies: opts.production !== false,\n    devDependencies: opts.dev !== false,\n    optionalDependencies: opts.optional !== false,\n  };\n\n  if (typeof opts.allowBuild !== 'undefined' && opts.allowBuild.length > 0) {\n    if (\n      typeof opts.rootProjectManifest?.pnpm?.ignoredBuiltDependencies !==\n        'undefined' &&\n      opts.rootProjectManifest.pnpm.ignoredBuiltDependencies.length\n    ) {\n      const overlapDependencies =\n        opts.rootProjectManifest.pnpm.ignoredBuiltDependencies.filter(\n          (dep): boolean => {\n            return opts.allowBuild?.includes(dep) === true;\n          }\n        );\n\n      if (overlapDependencies.length) {\n        throw new PnpmError(\n          'OVERRIDING_IGNORED_BUILT_DEPENDENCIES',\n          `The following dependencies are ignored by the root project, but are allowed to be built by the current command: ${overlapDependencies.join(', ')}`,\n          {\n            hint: 'If you are sure you want to allow those dependencies to run installation scripts, remove them from the pnpm.ignoredBuiltDependencies list.',\n          }\n        );\n      }\n    }\n\n    opts.onlyBuiltDependencies = Array.from(\n      new Set([...(opts.onlyBuiltDependencies ?? []), ...opts.allowBuild])\n    ).sort((a: string, b: string): number => {\n      return a.localeCompare(b);\n    });\n\n    const manifest: ProjectManifest = opts.rootProjectManifest ?? {\n      name: '',\n      version: '0.0.1',\n      pnpm: {\n        onlyBuiltDependencies: opts.onlyBuiltDependencies,\n      },\n    };\n\n    manifest.pnpm = manifest.pnpm ??\n      opts.rootProjectManifest?.pnpm ?? {\n        onlyBuiltDependencies: opts.onlyBuiltDependencies,\n      };\n\n    // opts.rootProjectManifest.pnpm = opts.rootProjectManifest.pnpm ?? {};\n\n    manifest.pnpm.onlyBuiltDependencies =\n      manifest.pnpm.onlyBuiltDependencies ?? opts.onlyBuiltDependencies;\n\n    const writeProjectManifest = await createProjectManifestWriter(\n      opts.rootProjectManifestDir\n    );\n\n    await writeProjectManifest(manifest);\n  }\n\n  return installDeps(\n    {\n      ...opts,\n      include,\n      update: opts.update ?? false,\n      includeDirect: include,\n      prepareExecutionEnv: prepareExecutionEnv.bind(null, opts),\n    },\n    params\n  );\n}\n"],
  "mappings": "AAAA,SAAS,eAAe;AACxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS,gBAAgB;AAClC,SAAS,iBAAiB;AAC1B,SAAS,2BAA2B;AACpC,OAAO,UAAU;AACjB,OAAO,gBAAgB;AACvB,SAAS,mCAAmC;AAE5C,SAAS,mBAAmB;AAGrB,SAAS,iBAA0C;AACxD,SAAO,KAAK;AAAA,IACV;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,kBAA2C;AACzD,SAAO;AAAA,IACL,GAAG,eAAe;AAAA,IAClB,eAAe,CAAC,QAAQ,KAAK;AAAA,IAC7B,WAAW;AAAA,IACX,MAAM;AAAA,IACN,WAAW;AAAA,EACb;AACF;AAEO,MAAM,eAAe,CAAC,KAAK;AAE3B,SAAS,OAAe;AAC7B,SAAO,WAAW;AAAA,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