{
  "version": 3,
  "sources": ["../../../../src/packages/plugin-commands-script-runners/runDepsStatusCheck.ts"],
  "sourcesContent": ["import type { VerifyDepsBeforeRun } from '../config/index.ts';\nimport { PnpmError } from '../error/index.ts';\nimport { runPnpmCli } from '../exec.pnpm-cli-runner/index.ts';\nimport { globalWarn } from '../logger/index.ts';\nimport {\n  checkDepsStatus,\n  type CheckDepsStatusOptions,\n  type WorkspaceStateSettings,\n} from '../deps.status/index.ts';\nimport { prompt } from 'enquirer';\n\nexport type RunDepsStatusCheckOptions = CheckDepsStatusOptions & {\n  dir: string;\n  verifyDepsBeforeRun?: VerifyDepsBeforeRun | undefined;\n};\n\nexport async function runDepsStatusCheck(\n  opts: RunDepsStatusCheckOptions\n): Promise<void> {\n  // the following flags are always the default values during `pnpm run` and `pnpm exec`,\n  // so they may not match the workspace state after `pnpm install --production|--no-optional`\n  const ignoredWorkspaceStateSettings = [\n    'dev',\n    'optional',\n    'production',\n  ] satisfies Array<keyof WorkspaceStateSettings>;\n  opts.ignoredWorkspaceStateSettings = ignoredWorkspaceStateSettings;\n\n  const { upToDate, issue, workspaceState } = await checkDepsStatus(opts);\n\n  if (upToDate === true) {\n    return;\n  }\n\n  const command = ['install', ...createInstallArgs(workspaceState?.settings)];\n\n  const install = runPnpmCli.bind(null, command, { cwd: opts.dir });\n\n  switch (opts.verifyDepsBeforeRun) {\n    case 'install': {\n      install();\n\n      break;\n    }\n\n    case 'prompt': {\n      const confirmed = await prompt<{ runInstall: boolean }>({\n        type: 'confirm',\n        name: 'runInstall',\n        message: `Your \"node_modules\" directory is out of sync with the \"pnpm-lock.yaml\" file. This can lead to issues during scripts execution.\n\nWould you like to run \"pnpm ${command.join(' ')}\" to update your \"node_modules\"?`,\n        initial: true,\n      });\n\n      if (confirmed.runInstall) {\n        install();\n      }\n\n      break;\n    }\n\n    case 'error': {\n      throw new PnpmError(\n        'VERIFY_DEPS_BEFORE_RUN',\n        issue ?? 'Your node_modules are out of sync with your lockfile',\n        {\n          hint: 'Run \"pnpm install\"',\n        }\n      );\n    }\n\n    case 'warn': {\n      globalWarn(\n        `Your node_modules are out of sync with your lockfile. ${issue}`\n      );\n\n      break;\n    }\n  }\n}\n\nexport function createInstallArgs(\n  opts:\n    | Pick<WorkspaceStateSettings, 'dev' | 'optional' | 'production'>\n    | undefined\n): string[] {\n  const args: string[] = [];\n\n  if (!opts) {\n    return args;\n  }\n\n  const { dev, optional, production } = opts;\n\n  if (production === true && dev !== true) {\n    args.push('--production');\n  } else if (dev === true && production !== true) {\n    args.push('--dev');\n  }\n\n  if (optional !== true) {\n    args.push('--no-optional');\n  }\n\n  return args;\n}\n"],
  "mappings": "AACA,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,OAGK;AACP,SAAS,cAAc;AAOvB,eAAsB,mBACpB,MACe;AAGf,QAAM,gCAAgC;AAAA,IACpC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,OAAK,gCAAgC;AAErC,QAAM,EAAE,UAAU,OAAO,eAAe,IAAI,MAAM,gBAAgB,IAAI;AAEtE,MAAI,aAAa,MAAM;AACrB;AAAA,EACF;AAEA,QAAM,UAAU,CAAC,WAAW,GAAG,kBAAkB,gBAAgB,QAAQ,CAAC;AAE1E,QAAM,UAAU,WAAW,KAAK,MAAM,SAAS,EAAE,KAAK,KAAK,IAAI,CAAC;AAEhE,UAAQ,KAAK,qBAAqB;AAAA,IAChC,KAAK,WAAW;AACd,cAAQ;AAER;AAAA,IACF;AAAA,IAEA,KAAK,UAAU;AACb,YAAM,YAAY,MAAM,OAAgC;AAAA,QACtD,MAAM;AAAA,QACN,MAAM;AAAA,QACN,SAAS;AAAA;AAAA,8BAEa,QAAQ,KAAK,GAAG,CAAC;AAAA,QACvC,SAAS;AAAA,MACX,CAAC;AAED,UAAI,UAAU,YAAY;AACxB,gBAAQ;AAAA,MACV;AAEA;AAAA,IACF;AAAA,IAEA,KAAK,SAAS;AACZ,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