{"version":3,"sources":["../../src/lib/verify-partytown-setup.ts"],"sourcesContent":["import { promises } from 'fs'\nimport { bold, cyan, red } from './picocolors'\n\nimport path from 'path'\nimport { hasNecessaryDependencies } from './has-necessary-dependencies'\nimport type { NecessaryDependencies } from './has-necessary-dependencies'\nimport { fileExists, FileType } from './file-exists'\nimport * as Log from '../build/output/log'\nimport { getPkgManager } from './helpers/get-pkg-manager'\n\nasync function missingDependencyError(dir: string) {\n  const packageManager = getPkgManager(dir)\n\n  throw new Error(\n    bold(\n      red(\n        \"It looks like you're trying to use Partytown with next/script but do not have the required package(s) installed.\"\n      )\n    ) +\n      '\\n\\n' +\n      bold(`Please install Partytown by running:`) +\n      '\\n\\n' +\n      `\\t${bold(\n        cyan(\n          (packageManager === 'yarn'\n            ? 'yarn add --dev'\n            : packageManager === 'pnpm'\n              ? 'pnpm install --save-dev'\n              : 'npm install --save-dev') + ' @builder.io/partytown'\n        )\n      )}` +\n      '\\n\\n' +\n      bold(\n        `If you are not trying to use Partytown, please disable the experimental ${cyan(\n          '\"nextScriptWorkers\"'\n        )} flag in next.config.js.`\n      ) +\n      '\\n'\n  )\n}\n\nasync function copyPartytownStaticFiles(\n  deps: NecessaryDependencies,\n  staticDir: string\n) {\n  const partytownLibDir = path.join(staticDir, '~partytown')\n  const hasPartytownLibDir = await fileExists(\n    partytownLibDir,\n    FileType.Directory\n  )\n\n  if (hasPartytownLibDir) {\n    await promises.rm(partytownLibDir, { recursive: true, force: true })\n  }\n\n  const { copyLibFiles } = await Promise.resolve(\n    require(path.join(deps.resolved.get('@builder.io/partytown')!, '../utils'))\n  )\n\n  await copyLibFiles(partytownLibDir)\n}\n\nexport async function verifyPartytownSetup(\n  dir: string,\n  targetDir: string\n): Promise<void> {\n  const partytownDeps: NecessaryDependencies = hasNecessaryDependencies(dir, [\n    {\n      file: '@builder.io/partytown',\n      pkg: '@builder.io/partytown',\n      exportsRestrict: false,\n    },\n  ])\n\n  if (partytownDeps.missing?.length > 0) {\n    await missingDependencyError(dir)\n  } else {\n    try {\n      await copyPartytownStaticFiles(partytownDeps, targetDir)\n    } catch (err) {\n      Log.warn(\n        `Partytown library files could not be copied to the static directory. Please ensure that ${bold(\n          cyan('@builder.io/partytown')\n        )} is installed as a dependency.`\n      )\n    }\n  }\n}\n"],"names":["verifyPartytownSetup","missingDependencyError","dir","packageManager","getPkgManager","Error","bold","red","cyan","copyPartytownStaticFiles","deps","staticDir","partytownLibDir","path","join","hasPartytownLibDir","fileExists","FileType","Directory","promises","rm","recursive","force","copyLibFiles","Promise","resolve","require","resolved","get","targetDir","partytownDeps","hasNecessaryDependencies","file","pkg","exportsRestrict","missing","length","err","Log","warn"],"mappings":";;;;+BA8DsBA;;;eAAAA;;;oBA9DG;4BACO;6DAEf;0CACwB;4BAEJ;6DAChB;+BACS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9B,eAAeC,uBAAuBC,GAAW;IAC/C,MAAMC,iBAAiBC,IAAAA,4BAAa,EAACF;IAErC,MAAM,qBAyBL,CAzBK,IAAIG,MACRC,IAAAA,gBAAI,EACFC,IAAAA,eAAG,EACD,uHAGF,SACAD,IAAAA,gBAAI,EAAC,CAAC,oCAAoC,CAAC,IAC3C,SACA,CAAC,EAAE,EAAEA,IAAAA,gBAAI,EACPE,IAAAA,gBAAI,EACF,AAACL,CAAAA,mBAAmB,SAChB,mBACAA,mBAAmB,SACjB,4BACA,wBAAuB,IAAK,4BAEnC,GACH,SACAG,IAAAA,gBAAI,EACF,CAAC,wEAAwE,EAAEE,IAAAA,gBAAI,EAC7E,uBACA,wBAAwB,CAAC,IAE7B,OAxBE,qBAAA;eAAA;oBAAA;sBAAA;IAyBN;AACF;AAEA,eAAeC,yBACbC,IAA2B,EAC3BC,SAAiB;IAEjB,MAAMC,kBAAkBC,aAAI,CAACC,IAAI,CAACH,WAAW;IAC7C,MAAMI,qBAAqB,MAAMC,IAAAA,sBAAU,EACzCJ,iBACAK,oBAAQ,CAACC,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