isolate-package 1.19.0 → 1.20.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,7 +26,8 @@ integrated, check out [mono-ts](https://github.com/0x80/mono-ts)
26
26
  deployments.
27
27
  - Preserve packages file structure, without code bundling
28
28
  - Should work with any package manager, and tested with NPM, PNPM, and Yarn
29
- (both classic and modern)
29
+ (both classic and modern). Bun is partially supported; the output will
30
+ generate an NPM lockfile.
30
31
  - Zero-config for the vast majority of use-cases
31
32
  - Isolates dependencies recursively. If package A depends on internal package B
32
33
  which depends on internal package C, all of them will be included
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import fs16 from "fs-extra";
3
3
  import assert6 from "node:assert";
4
4
  import path20 from "node:path";
5
- import { unique } from "remeda";
5
+ import { unique as unique2 } from "remeda";
6
6
 
7
7
  // src/lib/config.ts
8
8
  import fs8 from "fs-extra";
@@ -73,8 +73,7 @@ function isErrorWithMessage(error) {
73
73
  return typeof error === "object" && error !== null && "message" in error;
74
74
  }
75
75
  function toErrorWithMessage(maybeError) {
76
- if (isErrorWithMessage(maybeError))
77
- return maybeError;
76
+ if (isErrorWithMessage(maybeError)) return maybeError;
78
77
  try {
79
78
  return new Error(JSON.stringify(maybeError));
80
79
  } catch {
@@ -155,9 +154,16 @@ function getMajorVersion(version) {
155
154
  }
156
155
 
157
156
  // src/lib/package-manager/names.ts
158
- var supportedPackageManagerNames = ["pnpm", "yarn", "npm"];
157
+ var supportedPackageManagerNames = [
158
+ "pnpm",
159
+ "yarn",
160
+ "npm",
161
+ "bun"
162
+ ];
159
163
  function getLockfileFileName(name) {
160
164
  switch (name) {
165
+ case "bun":
166
+ return "bun.lockb";
161
167
  case "pnpm":
162
168
  return "pnpm-lock.yaml";
163
169
  case "yarn":
@@ -472,13 +478,13 @@ async function generatePnpmLockfile({
472
478
  targetPackageManifest,
473
479
  majorVersion
474
480
  }) {
475
- const useVersion9 = majorVersion >= 9;
481
+ const useReadVersion9 = majorVersion >= 9;
476
482
  const { includeDevDependencies, includePatchedDependencies } = useConfig();
477
483
  const log = useLogger();
478
484
  log.debug("Generating PNPM lockfile...");
479
485
  try {
480
486
  const isRush = isRushWorkspace(workspaceRootDir);
481
- const lockfile = useVersion9 ? await readWantedLockfile_v9(
487
+ const lockfile = useReadVersion9 ? await readWantedLockfile_v9(
482
488
  isRush ? path9.join(workspaceRootDir, "common/config/rush") : workspaceRootDir,
483
489
  {
484
490
  ignoreIncompatible: false
@@ -490,7 +496,9 @@ async function generatePnpmLockfile({
490
496
  }
491
497
  );
492
498
  assert3(lockfile, `No input lockfile found at ${workspaceRootDir}`);
493
- const targetImporterId = useVersion9 ? getLockfileImporterId_v9(workspaceRootDir, targetPackageDir) : getLockfileImporterId_v8(workspaceRootDir, targetPackageDir);
499
+ const [lockfileMajorVersion] = String(lockfile.lockfileVersion).split(".");
500
+ const useLockfileVersion9 = lockfileMajorVersion >= "9";
501
+ const targetImporterId = useLockfileVersion9 ? getLockfileImporterId_v9(workspaceRootDir, targetPackageDir) : getLockfileImporterId_v8(workspaceRootDir, targetPackageDir);
494
502
  const directoryByPackageName = Object.fromEntries(
495
503
  internalDepPackageNames.map((name) => {
496
504
  const pkg = packagesRegistry[name];
@@ -538,12 +546,12 @@ async function generatePnpmLockfile({
538
546
  })
539
547
  );
540
548
  log.debug("Pruning the lockfile");
541
- const prunedLockfile = useVersion9 ? await pruneLockfile_v9(lockfile, targetPackageManifest, ".") : await pruneLockfile_v8(lockfile, targetPackageManifest, ".");
549
+ const prunedLockfile = useLockfileVersion9 ? await pruneLockfile_v9(lockfile, targetPackageManifest, ".") : await pruneLockfile_v8(lockfile, targetPackageManifest, ".");
542
550
  if (lockfile.overrides) {
543
551
  prunedLockfile.overrides = lockfile.overrides;
544
552
  }
545
553
  const patchedDependencies = includePatchedDependencies ? lockfile.patchedDependencies : void 0;
546
- useVersion9 ? await writeWantedLockfile_v9(isolateDir, {
554
+ useLockfileVersion9 ? await writeWantedLockfile_v9(isolateDir, {
547
555
  ...prunedLockfile,
548
556
  patchedDependencies
549
557
  }) : await writeWantedLockfile_v8(isolateDir, {
@@ -634,6 +642,17 @@ async function processLockfile({
634
642
  });
635
643
  break;
636
644
  }
645
+ case "bun": {
646
+ log.warn(
647
+ `Ouput lockfiles for Bun are not yet supported. Using NPM for output`
648
+ );
649
+ await generateNpmLockfile({
650
+ workspaceRootDir,
651
+ isolateDir
652
+ });
653
+ usedFallbackToNpm = true;
654
+ break;
655
+ }
637
656
  default:
638
657
  log.warn(`Unexpected package manager ${name}. Using NPM for output`);
639
658
  await generateNpmLockfile({
@@ -932,6 +951,7 @@ function findPackagesGlobs(workspaceRootDir) {
932
951
  log.debug("Detected pnpm packages globs:", inspectValue(globs));
933
952
  return globs;
934
953
  }
954
+ case "bun":
935
955
  case "yarn":
936
956
  case "npm": {
937
957
  const workspaceRootManifestPath = path18.join(
@@ -1018,7 +1038,7 @@ function listWorkspacePackages(workspacePackagesOverride, workspaceRootDir) {
1018
1038
  }
1019
1039
 
1020
1040
  // src/lib/registry/list-internal-packages.ts
1021
- import { uniq } from "remeda";
1041
+ import { unique } from "remeda";
1022
1042
  function listInternalPackages(manifest, packagesRegistry, { includeDevDependencies = false } = {}) {
1023
1043
  const allWorkspacePackageNames = Object.keys(packagesRegistry);
1024
1044
  const internalPackageNames = (includeDevDependencies ? [
@@ -1032,7 +1052,7 @@ function listInternalPackages(manifest, packagesRegistry, { includeDevDependenci
1032
1052
  { includeDevDependencies }
1033
1053
  )
1034
1054
  );
1035
- return uniq(internalPackageNames.concat(nestedInternalPackageNames));
1055
+ return unique(internalPackageNames.concat(nestedInternalPackageNames));
1036
1056
  }
1037
1057
 
1038
1058
  // src/isolate.ts
@@ -1142,7 +1162,7 @@ async function isolate(options = {}) {
1142
1162
  }
1143
1163
  if (packageManager2.name === "pnpm") {
1144
1164
  if (isRushWorkspace(workspaceRootDir)) {
1145
- const packagesFolderNames = unique(
1165
+ const packagesFolderNames = unique2(
1146
1166
  internalPackageNames.map(
1147
1167
  (name) => path20.parse(packagesRegistry[name].rootRelativeDir).dir
1148
1168
  )
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/isolate.ts","../src/lib/config.ts","../src/lib/logger.ts","../src/lib/utils/get-dirname.ts","../src/lib/utils/get-error-message.ts","../src/lib/utils/get-relative-path.ts","../src/lib/utils/inspect-value.ts","../src/lib/utils/is-rush-workspace.ts","../src/lib/utils/json.ts","../src/lib/utils/pack.ts","../src/lib/package-manager/index.ts","../src/lib/package-manager/helpers/infer-from-files.ts","../src/lib/utils/get-major-version.ts","../src/lib/package-manager/names.ts","../src/lib/package-manager/helpers/infer-from-manifest.ts","../src/lib/utils/unpack.ts","../src/lib/utils/yaml.ts","../src/lib/lockfile/helpers/generate-npm-lockfile.ts","../src/lib/lockfile/helpers/generate-pnpm-lockfile.ts","../src/lib/lockfile/helpers/pnpm-map-importer.ts","../src/lib/lockfile/helpers/generate-yarn-lockfile.ts","../src/lib/lockfile/process-lockfile.ts","../src/lib/manifest/adapt-target-package-manifest.ts","../src/lib/manifest/helpers/adapt-internal-package-manifests.ts","../src/lib/manifest/io.ts","../src/lib/manifest/helpers/patch-internal-entries.ts","../src/lib/manifest/helpers/adapt-manifest-internal-deps.ts","../src/lib/manifest/helpers/adopt-pnpm-fields-from-root.ts","../src/lib/output/get-build-output-dir.ts","../src/lib/output/pack-dependencies.ts","../src/lib/output/process-build-output-files.ts","../src/lib/output/unpack-dependencies.ts","../src/lib/registry/create-packages-registry.ts","../src/lib/registry/helpers/find-packages-globs.ts","../src/lib/registry/list-internal-packages.ts"],"sourcesContent":["import fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport { unique } from \"remeda\";\nimport type { IsolateConfig } from \"./lib/config\";\nimport { resolveConfig, setUserConfig } from \"./lib/config\";\nimport { processLockfile } from \"./lib/lockfile\";\nimport type { Logger } from \"./lib/logger\";\nimport { setLogLevel, setLogger, useLogger } from \"./lib/logger\";\nimport {\n adaptInternalPackageManifests,\n adaptTargetPackageManifest,\n readManifest,\n writeManifest,\n} from \"./lib/manifest\";\nimport {\n getBuildOutputDir,\n packDependencies,\n processBuildOutputFiles,\n unpackDependencies,\n} from \"./lib/output\";\nimport { detectPackageManager, shouldUsePnpmPack } from \"./lib/package-manager\";\nimport { getVersion } from \"./lib/package-manager/helpers/infer-from-files\";\nimport { createPackagesRegistry, listInternalPackages } from \"./lib/registry\";\nimport type { PackageManifest } from \"./lib/types\";\nimport {\n getDirname,\n getRootRelativePath,\n isRushWorkspace,\n readTypedJson,\n writeTypedYamlSync,\n} from \"./lib/utils\";\n\nconst __dirname = getDirname(import.meta.url);\n\nexport async function isolate(\n options: { config?: IsolateConfig; logger?: Logger } = {}\n) {\n if (options.logger) {\n setLogger(options.logger);\n }\n\n if (options.config) {\n setUserConfig(options.config);\n }\n\n const config = resolveConfig();\n\n setLogLevel(config.logLevel);\n\n const log = useLogger();\n\n const { version: libraryVersion } = await readTypedJson<PackageManifest>(\n path.join(path.join(__dirname, \"..\", \"package.json\"))\n );\n\n log.info(\"Using isolate-package version\", libraryVersion);\n\n /**\n * If a targetPackagePath is set, we assume the configuration lives in the\n * root of the workspace. If targetPackagePath is undefined (the default), we\n * assume that the configuration lives in the target package directory.\n */\n const targetPackageDir = config.targetPackagePath\n ? path.join(process.cwd(), config.targetPackagePath)\n : process.cwd();\n\n const workspaceRootDir = config.targetPackagePath\n ? process.cwd()\n : path.join(targetPackageDir, config.workspaceRoot);\n\n const buildOutputDir = await getBuildOutputDir(targetPackageDir);\n\n assert(\n fs.existsSync(buildOutputDir),\n `Failed to find build output path at ${buildOutputDir}. Please make sure you build the source before isolating it.`\n );\n\n log.debug(\"Workspace root resolved to\", workspaceRootDir);\n log.debug(\n \"Isolate target package\",\n getRootRelativePath(targetPackageDir, workspaceRootDir)\n );\n\n const isolateDir = path.join(targetPackageDir, config.isolateDirName);\n\n log.debug(\n \"Isolate output directory\",\n getRootRelativePath(isolateDir, workspaceRootDir)\n );\n\n if (fs.existsSync(isolateDir)) {\n await fs.remove(isolateDir);\n log.debug(\"Cleaned the existing isolate output directory\");\n }\n\n await fs.ensureDir(isolateDir);\n\n const tmpDir = path.join(isolateDir, \"__tmp\");\n await fs.ensureDir(tmpDir);\n\n const targetPackageManifest = await readTypedJson<PackageManifest>(\n path.join(targetPackageDir, \"package.json\")\n );\n\n const packageManager = detectPackageManager(workspaceRootDir);\n\n log.debug(\n \"Detected package manager\",\n packageManager.name,\n packageManager.version\n );\n\n if (shouldUsePnpmPack()) {\n log.debug(\"Use PNPM pack instead of NPM pack\");\n }\n\n /**\n * Build a packages registry so we can find the workspace packages by name and\n * have access to their manifest files and relative paths.\n */\n const packagesRegistry = await createPackagesRegistry(\n workspaceRootDir,\n config.workspacePackages\n );\n\n const internalPackageNames = listInternalPackages(\n targetPackageManifest,\n packagesRegistry,\n {\n includeDevDependencies: config.includeDevDependencies,\n }\n );\n\n const packedFilesByName = await packDependencies({\n internalPackageNames,\n packagesRegistry,\n packDestinationDir: tmpDir,\n });\n\n await unpackDependencies(\n packedFilesByName,\n packagesRegistry,\n tmpDir,\n isolateDir\n );\n\n /** Adapt the manifest files for all the unpacked local dependencies */\n await adaptInternalPackageManifests(\n internalPackageNames,\n packagesRegistry,\n isolateDir\n );\n\n /** Pack the target package directory, and unpack it in the isolate location */\n await processBuildOutputFiles({\n targetPackageDir,\n tmpDir,\n isolateDir,\n });\n\n /**\n * Copy the target manifest file to the isolate location and adapt its\n * workspace dependencies to point to the isolated packages.\n */\n const outputManifest = await adaptTargetPackageManifest({\n manifest: targetPackageManifest,\n packagesRegistry,\n workspaceRootDir,\n });\n\n await writeManifest(isolateDir, outputManifest);\n\n /** Generate an isolated lockfile based on the original one */\n const usedFallbackToNpm = await processLockfile({\n workspaceRootDir,\n isolateDir,\n packagesRegistry,\n internalDepPackageNames: internalPackageNames,\n targetPackageDir,\n targetPackageName: targetPackageManifest.name,\n targetPackageManifest: outputManifest,\n });\n\n if (usedFallbackToNpm) {\n /**\n * When we fall back to NPM, we set the manifest package manager to the\n * available NPM version.\n */\n const manifest = await readManifest(isolateDir);\n\n const npmVersion = getVersion(\"npm\");\n manifest.packageManager = `npm@${npmVersion}`;\n\n await writeManifest(isolateDir, manifest);\n }\n\n if (packageManager.name === \"pnpm\") {\n /**\n * PNPM doesn't install dependencies of packages that are linked via link:\n * or file: specifiers. It requires the directory to be configured as a\n * workspace, so we copy the workspace config file to the isolate output.\n *\n * Rush doesn't have a pnpm-workspace.yaml file, so we generate one.\n */\n if (isRushWorkspace(workspaceRootDir)) {\n const packagesFolderNames = unique(\n internalPackageNames.map(\n (name) => path.parse(packagesRegistry[name].rootRelativeDir).dir\n )\n );\n\n log.debug(\"Generating pnpm-workspace.yaml for Rush workspace\");\n log.debug(\"Packages folder names:\", packagesFolderNames);\n\n const packages = packagesFolderNames.map((x) => path.join(x, \"/*\"));\n\n await writeTypedYamlSync(path.join(isolateDir, \"pnpm-workspace.yaml\"), {\n packages,\n });\n } else {\n fs.copyFileSync(\n path.join(workspaceRootDir, \"pnpm-workspace.yaml\"),\n path.join(isolateDir, \"pnpm-workspace.yaml\")\n );\n }\n }\n /**\n * If there is an .npmrc file in the workspace root, copy it to the isolate\n * because the settings there could affect how the lockfile is resolved. Note\n * that .npmrc is used by both NPM and PNPM for configuration.\n *\n * See also: https://pnpm.io/npmrc\n */\n const npmrcPath = path.join(workspaceRootDir, \".npmrc\");\n\n if (fs.existsSync(npmrcPath)) {\n fs.copyFileSync(npmrcPath, path.join(isolateDir, \".npmrc\"));\n log.debug(\"Copied .npmrc file to the isolate output\");\n }\n\n /**\n * Clean up. Only so this in the happy path, so we can look at the temp folder\n * when thing go wrong.\n */\n log.debug(\n \"Deleting temp directory\",\n getRootRelativePath(tmpDir, workspaceRootDir)\n );\n await fs.remove(tmpDir);\n\n log.info(\"Isolate completed at\", isolateDir);\n\n return isolateDir;\n}\n","import fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport { isEmpty } from \"remeda\";\nimport { setLogLevel, useLogger } from \"./logger\";\nimport { inspectValue, readTypedJsonSync } from \"./utils\";\n\nexport type IsolateConfigResolved = {\n buildDirName?: string;\n includeDevDependencies: boolean;\n includePatchedDependencies: boolean;\n isolateDirName: string;\n logLevel: \"info\" | \"debug\" | \"warn\" | \"error\";\n targetPackagePath?: string;\n tsconfigPath: string;\n workspacePackages?: string[];\n workspaceRoot: string;\n forceNpm: boolean;\n pickFromScripts?: string[];\n omitFromScripts?: string[];\n omitPackageManager?: boolean;\n};\n\nexport type IsolateConfig = Partial<IsolateConfigResolved>;\n\nconst configDefaults: IsolateConfigResolved = {\n buildDirName: undefined,\n includeDevDependencies: false,\n includePatchedDependencies: false,\n isolateDirName: \"isolate\",\n logLevel: \"info\",\n targetPackagePath: undefined,\n tsconfigPath: \"./tsconfig.json\",\n workspacePackages: undefined,\n workspaceRoot: \"../..\",\n forceNpm: false,\n pickFromScripts: undefined,\n omitFromScripts: undefined,\n omitPackageManager: false,\n};\n\n/**\n * Only initialize the configuration once, and keeping it here for subsequent\n * calls to getConfig.\n */\nlet _resolvedConfig: IsolateConfigResolved | undefined;\n\nlet _user_defined_config: IsolateConfig | undefined;\n\nconst validConfigKeys = Object.keys(configDefaults);\n\nconst CONFIG_FILE_NAME = \"isolate.config.json\";\n\nexport type LogLevel = IsolateConfigResolved[\"logLevel\"];\n\nexport function setUserConfig(config: IsolateConfig) {\n _user_defined_config = config;\n\n if (config.logLevel) {\n setLogLevel(config.logLevel);\n }\n}\n\nexport function useConfig() {\n if (_resolvedConfig) {\n return _resolvedConfig;\n } else {\n throw new Error(\"Called useConfig before config was made available\");\n }\n}\n\n/**\n * Resolve configuration based on user config and defaults. If setConfig was\n * called before this, it does not attempt to read a config file from disk.\n */\nexport function resolveConfig(): IsolateConfigResolved {\n if (_resolvedConfig) {\n return _resolvedConfig;\n }\n\n setLogLevel(process.env.DEBUG_ISOLATE_CONFIG ? \"debug\" : \"info\");\n\n const log = useLogger();\n\n const configFilePath = path.join(process.cwd(), CONFIG_FILE_NAME);\n\n if (_user_defined_config) {\n log.debug(`Using user defined config:`, inspectValue(_user_defined_config));\n } else {\n log.debug(`Attempting to load config from ${configFilePath}`);\n\n _user_defined_config = fs.existsSync(configFilePath)\n ? readTypedJsonSync<IsolateConfig>(configFilePath)\n : {};\n }\n\n const foreignKeys = Object.keys(_user_defined_config).filter(\n (key) => !validConfigKeys.includes(key)\n );\n\n if (!isEmpty(foreignKeys)) {\n log.warn(`Found invalid config settings:`, foreignKeys.join(\", \"));\n }\n\n const config = Object.assign(\n {},\n configDefaults,\n _user_defined_config\n ) satisfies IsolateConfigResolved;\n\n log.debug(\"Using configuration:\", inspectValue(config));\n\n _resolvedConfig = config;\n return config;\n}\n\n/**\n * Get only the configuration that the user set explicitly in the config file or\n * passed via arguments to isolate().\n */\nexport function getUserDefinedConfig(): IsolateConfig {\n assert(\n _user_defined_config,\n \"Called getUserDefinedConfig before user config was made available\"\n );\n\n return _user_defined_config;\n}\n","import chalk from \"chalk\";\nimport type { IsolateConfigResolved, LogLevel } from \"./config\";\n/**\n * The Logger defines an interface that can be used to pass in a different\n * logger object in order to intercept all the logging output. We keep the\n * handlers separate from the logger object itself, so that we can change the\n * handlers but do not bother the user with having to handle logLevel.\n */\nexport type Logger = {\n debug(...args: unknown[]): void;\n info(...args: unknown[]): void;\n warn(...args: unknown[]): void;\n error(...args: unknown[]): void;\n};\n\nlet _loggerHandlers: Logger = {\n debug(...args: unknown[]) {\n console.log(chalk.blue(\"debug\"), ...args);\n },\n info(...args: unknown[]) {\n console.log(chalk.green(\"info\"), ...args);\n },\n warn(...args: unknown[]) {\n console.log(chalk.yellow(\"warning\"), ...args);\n },\n error(...args: unknown[]) {\n console.log(chalk.red(\"error\"), ...args);\n },\n};\n\nconst _logger: Logger = {\n debug(...args: unknown[]) {\n if (_logLevel === \"debug\") {\n _loggerHandlers.debug(...args);\n }\n },\n info(...args: unknown[]) {\n if (_logLevel === \"debug\" || _logLevel === \"info\") {\n _loggerHandlers.info(...args);\n }\n },\n warn(...args: unknown[]) {\n if (_logLevel === \"debug\" || _logLevel === \"info\" || _logLevel === \"warn\") {\n _loggerHandlers.warn(...args);\n }\n },\n error(...args: unknown[]) {\n _loggerHandlers.error(...args);\n },\n};\n\nlet _logLevel: LogLevel = \"info\";\n\nexport function setLogger(logger: Logger) {\n _loggerHandlers = logger;\n return _logger;\n}\n\nexport function setLogLevel(\n logLevel: IsolateConfigResolved[\"logLevel\"]\n): Logger {\n _logLevel = logLevel;\n return _logger;\n}\n\nexport function useLogger() {\n return _logger;\n}\n","import { fileURLToPath } from \"url\";\n\n/**\n * Calling context should pass in import.meta.url and the function will return\n * the equivalent of __dirname in Node/CommonJs.\n */\nexport function getDirname(importMetaUrl: string) {\n return fileURLToPath(new URL(\".\", importMetaUrl));\n}\n","type ErrorWithMessage = {\n message: string;\n};\n\nexport function getErrorMessage(error: unknown) {\n return toErrorWithMessage(error).message;\n}\n\nfunction isErrorWithMessage(error: unknown): error is ErrorWithMessage {\n return typeof error === \"object\" && error !== null && \"message\" in error;\n}\n\nfunction toErrorWithMessage(maybeError: unknown): ErrorWithMessage {\n if (isErrorWithMessage(maybeError)) return maybeError;\n\n try {\n return new Error(JSON.stringify(maybeError));\n } catch {\n /**\n * Fallback in case there’s an error in stringify which can happen with\n * circular references.\n */\n return new Error(String(maybeError));\n }\n}\n","import { join } from \"node:path\";\n\nexport function getRootRelativePath(path: string, rootPath: string) {\n const strippedPath = path.replace(rootPath, \"\");\n\n return join(\"(root)\", strippedPath);\n}\n\nexport function getIsolateRelativePath(path: string, isolatePath: string) {\n const strippedPath = path.replace(isolatePath, \"\");\n\n return join(\"(isolate)\", strippedPath);\n}\n","import { inspect } from \"node:util\";\n\nexport function inspectValue(value: unknown) {\n return inspect(value, false, 16, true);\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Detect if this is a Rush monorepo. They use a very different structure so\n * there are multiple places where we need to make exceptions based on this.\n */\nexport function isRushWorkspace(workspaceRootDir: string) {\n return fs.existsSync(path.join(workspaceRootDir, \"rush.json\"));\n}\n","import fs from \"fs-extra\";\nimport stripJsonComments from \"strip-json-comments\";\nimport { getErrorMessage } from \"./get-error-message\";\n\n/** @todo Pass in zod schema and validate */\nexport function readTypedJsonSync<T>(filePath: string) {\n try {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const data = JSON.parse(\n stripJsonComments(rawContent, { trailingCommas: true })\n ) as T;\n return data;\n } catch (err) {\n throw new Error(\n `Failed to read JSON from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n\nexport async function readTypedJson<T>(filePath: string) {\n try {\n const rawContent = await fs.readFile(filePath, \"utf-8\");\n const data = JSON.parse(\n stripJsonComments(rawContent, { trailingCommas: true })\n ) as T;\n return data;\n } catch (err) {\n throw new Error(\n `Failed to read JSON from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n","import { exec } from \"node:child_process\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { useLogger } from \"../logger\";\nimport { shouldUsePnpmPack } from \"../package-manager\";\nimport { getErrorMessage } from \"./get-error-message\";\n\nexport async function pack(srcDir: string, dstDir: string) {\n const log = useLogger();\n\n const execOptions = {\n maxBuffer: 10 * 1024 * 1024,\n };\n\n const previousCwd = process.cwd();\n process.chdir(srcDir);\n\n /**\n * PNPM pack seems to be a lot faster than NPM pack, so when PNPM is detected\n * we use that instead.\n */\n const stdout = shouldUsePnpmPack()\n ? await new Promise<string>((resolve, reject) => {\n exec(\n `pnpm pack --pack-destination \"${dstDir}\"`,\n execOptions,\n (err, stdout) => {\n if (err) {\n log.error(getErrorMessage(err));\n return reject(err);\n }\n\n resolve(stdout);\n }\n );\n })\n : await new Promise<string>((resolve, reject) => {\n exec(\n `npm pack --pack-destination \"${dstDir}\"`,\n execOptions,\n (err, stdout) => {\n if (err) {\n return reject(err);\n }\n\n resolve(stdout);\n }\n );\n });\n\n const fileName = path.basename(stdout.trim());\n\n const filePath = path.join(dstDir, fileName);\n\n if (!fs.existsSync(filePath)) {\n log.error(\n `The response from pack could not be resolved to an existing file: ${filePath}`\n );\n } else {\n log.debug(`Packed (temp)/${fileName}`);\n }\n\n process.chdir(previousCwd);\n\n /**\n * Return the path anyway even if it doesn't validate. A later stage will wait\n * for the file to occur still. Not sure if this makes sense. Maybe we should\n * stop at the validation error...\n */\n return filePath;\n}\n","import path from \"node:path\";\nimport { isRushWorkspace } from \"../utils/is-rush-workspace\";\nimport { inferFromFiles, inferFromManifest } from \"./helpers\";\nimport type { PackageManager } from \"./names\";\n\nexport * from \"./names\";\n\nlet packageManager: PackageManager | undefined;\n\nexport function usePackageManager() {\n if (!packageManager) {\n throw Error(\n \"No package manager detected. Make sure to call detectPackageManager() before usePackageManager()\"\n );\n }\n\n return packageManager;\n}\n\n/**\n * First we check if the package manager is declared in the manifest. If it is,\n * we get the name and version from there. Otherwise we'll search for the\n * different lockfiles and ask the OS to report the installed version.\n */\nexport function detectPackageManager(workspaceRootDir: string): PackageManager {\n if (isRushWorkspace(workspaceRootDir)) {\n packageManager = inferFromFiles(\n path.join(workspaceRootDir, \"common/config/rush\")\n );\n } else {\n /**\n * Disable infer from manifest for now. I doubt it is useful after all but\n * I'll keep the code as a reminder.\n */\n packageManager =\n inferFromManifest(workspaceRootDir) ?? inferFromFiles(workspaceRootDir);\n }\n\n return packageManager;\n}\n\nexport function shouldUsePnpmPack() {\n const { name, majorVersion } = usePackageManager();\n\n return name === \"pnpm\" && majorVersion >= 8;\n}\n","import fs from \"fs-extra\";\nimport { execSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport { getErrorMessage } from \"~/lib/utils\";\nimport { getMajorVersion } from \"~/lib/utils/get-major-version\";\nimport type { PackageManager, PackageManagerName } from \"../names\";\nimport { getLockfileFileName, supportedPackageManagerNames } from \"../names\";\n\nexport function inferFromFiles(workspaceRoot: string): PackageManager {\n for (const name of supportedPackageManagerNames) {\n const lockfileName = getLockfileFileName(name);\n\n if (fs.existsSync(path.join(workspaceRoot, lockfileName))) {\n try {\n const version = getVersion(name);\n\n return { name, version, majorVersion: getMajorVersion(version) };\n } catch (err) {\n throw new Error(\n `Failed to find package manager version for ${name}: ${getErrorMessage(err)}`\n );\n }\n }\n }\n\n /** If no lockfile was found, it could be that there is an npm shrinkwrap file. */\n if (fs.existsSync(path.join(workspaceRoot, \"npm-shrinkwrap.json\"))) {\n const version = getVersion(\"npm\");\n\n return { name: \"npm\", version, majorVersion: getMajorVersion(version) };\n }\n\n throw new Error(`Failed to detect package manager`);\n}\n\nexport function getVersion(packageManagerName: PackageManagerName): string {\n const buffer = execSync(`${packageManagerName} --version`);\n return buffer.toString().trim();\n}\n","export function getMajorVersion(version: string) {\n return parseInt(version.split(\".\")[0], 10);\n}\n","export const supportedPackageManagerNames = [\"pnpm\", \"yarn\", \"npm\"] as const;\n\nexport type PackageManagerName = (typeof supportedPackageManagerNames)[number];\n\nexport type PackageManager = {\n name: PackageManagerName;\n version: string;\n majorVersion: number;\n packageManagerString?: string;\n};\n\nexport function getLockfileFileName(name: PackageManagerName) {\n switch (name) {\n case \"pnpm\":\n return \"pnpm-lock.yaml\";\n case \"yarn\":\n return \"yarn.lock\";\n case \"npm\":\n return \"package-lock.json\";\n }\n}\n","import fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport { useLogger } from \"~/lib/logger\";\nimport { getMajorVersion } from \"~/lib/utils/get-major-version\";\nimport type { PackageManifest } from \"../../types\";\nimport { readTypedJsonSync } from \"../../utils\";\nimport type { PackageManagerName } from \"../names\";\nimport { getLockfileFileName, supportedPackageManagerNames } from \"../names\";\n\nexport function inferFromManifest(workspaceRoot: string) {\n const log = useLogger();\n\n const { packageManager: packageManagerString } =\n readTypedJsonSync<PackageManifest>(\n path.join(workspaceRoot, \"package.json\")\n );\n\n if (!packageManagerString) {\n log.debug(\"No packageManager field found in root manifest\");\n return;\n }\n\n const [name, version = \"*\"] = packageManagerString.split(\"@\") as [\n PackageManagerName,\n string,\n ];\n\n assert(\n supportedPackageManagerNames.includes(name),\n `Package manager \"${name}\" is not currently supported`\n );\n\n const lockfileName = getLockfileFileName(name);\n\n assert(\n fs.existsSync(path.join(workspaceRoot, lockfileName)),\n `Manifest declares ${name} to be the packageManager, but failed to find ${lockfileName} in workspace root`\n );\n\n return {\n name,\n version,\n majorVersion: getMajorVersion(version),\n packageManagerString,\n };\n}\n","import fs from \"fs-extra\";\nimport tar from \"tar-fs\";\nimport { createGunzip } from \"zlib\";\n\nexport async function unpack(filePath: string, unpackDir: string) {\n await new Promise<void>((resolve, reject) => {\n fs.createReadStream(filePath)\n .pipe(createGunzip())\n .pipe(tar.extract(unpackDir))\n .on(\"finish\", () => resolve())\n .on(\"error\", (err) => reject(err));\n });\n}\n","import fs from \"fs-extra\";\nimport yaml from \"yaml\";\nimport { getErrorMessage } from \"./get-error-message\";\n\nexport function readTypedYamlSync<T>(filePath: string) {\n try {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const data = yaml.parse(rawContent);\n /** @todo Add some zod validation maybe */\n return data as T;\n } catch (err) {\n throw new Error(\n `Failed to read YAML from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n\nexport function writeTypedYamlSync<T>(filePath: string, content: T) {\n /** @todo Add some zod validation maybe */\n fs.writeFileSync(filePath, yaml.stringify(content), \"utf-8\");\n}\n","import Arborist from \"@npmcli/arborist\";\nimport fs from \"fs-extra\";\nimport path from \"node:path\";\nimport { useLogger } from \"~/lib/logger\";\nimport { getErrorMessage } from \"~/lib/utils\";\n\n/**\n * Generate an isolated / pruned lockfile, based on the contents of installed\n * node_modules from the monorepo root plus the adapted package manifest in the\n * isolate directory.\n */\nexport async function generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n}: {\n workspaceRootDir: string;\n isolateDir: string;\n}) {\n const log = useLogger();\n\n log.debug(\"Generating NPM lockfile...\");\n\n const nodeModulesPath = path.join(workspaceRootDir, \"node_modules\");\n\n try {\n if (!fs.existsSync(nodeModulesPath)) {\n throw new Error(`Failed to find node_modules at ${nodeModulesPath}`);\n }\n\n const arborist = new Arborist({ path: isolateDir });\n\n const { meta } = await arborist.buildIdealTree();\n\n meta?.commit();\n\n const lockfilePath = path.join(isolateDir, \"package-lock.json\");\n\n await fs.writeFile(lockfilePath, String(meta));\n\n log.debug(\"Created lockfile at\", lockfilePath);\n } catch (err) {\n log.error(`Failed to generate lockfile: ${getErrorMessage(err)}`);\n throw err;\n }\n}\n","import assert from \"node:assert\";\nimport path from \"node:path\";\nimport {\n getLockfileImporterId as getLockfileImporterId_v8,\n readWantedLockfile as readWantedLockfile_v8,\n writeWantedLockfile as writeWantedLockfile_v8,\n} from \"pnpm_lockfile_file_v8\";\nimport {\n getLockfileImporterId as getLockfileImporterId_v9,\n readWantedLockfile as readWantedLockfile_v9,\n writeWantedLockfile as writeWantedLockfile_v9,\n} from \"pnpm_lockfile_file_v9\";\nimport { pruneLockfile as pruneLockfile_v8 } from \"pnpm_prune_lockfile_v8\";\nimport { pruneLockfile as pruneLockfile_v9 } from \"pnpm_prune_lockfile_v9\";\nimport { pick } from \"remeda\";\nimport { useConfig } from \"~/lib/config\";\nimport { useLogger } from \"~/lib/logger\";\nimport type { PackageManifest, PackagesRegistry } from \"~/lib/types\";\nimport { getErrorMessage, isRushWorkspace } from \"~/lib/utils\";\nimport { pnpmMapImporter } from \"./pnpm-map-importer\";\n\nexport async function generatePnpmLockfile({\n workspaceRootDir,\n targetPackageDir,\n isolateDir,\n internalDepPackageNames,\n packagesRegistry,\n targetPackageManifest,\n majorVersion,\n}: {\n workspaceRootDir: string;\n targetPackageDir: string;\n isolateDir: string;\n internalDepPackageNames: string[];\n packagesRegistry: PackagesRegistry;\n targetPackageManifest: PackageManifest;\n majorVersion: number;\n}) {\n /**\n * For now we will assume that the lockfile format might not change in the\n * versions after 9, because we might get lucky. If it does change, things\n * would break either way.\n */\n const useVersion9 = majorVersion >= 9;\n\n const { includeDevDependencies, includePatchedDependencies } = useConfig();\n const log = useLogger();\n\n log.debug(\"Generating PNPM lockfile...\");\n\n try {\n const isRush = isRushWorkspace(workspaceRootDir);\n\n const lockfile = useVersion9\n ? await readWantedLockfile_v9(\n isRush\n ? path.join(workspaceRootDir, \"common/config/rush\")\n : workspaceRootDir,\n {\n ignoreIncompatible: false,\n }\n )\n : await readWantedLockfile_v8(\n isRush\n ? path.join(workspaceRootDir, \"common/config/rush\")\n : workspaceRootDir,\n {\n ignoreIncompatible: false,\n }\n );\n\n assert(lockfile, `No input lockfile found at ${workspaceRootDir}`);\n\n const targetImporterId = useVersion9\n ? getLockfileImporterId_v9(workspaceRootDir, targetPackageDir)\n : getLockfileImporterId_v8(workspaceRootDir, targetPackageDir);\n\n const directoryByPackageName = Object.fromEntries(\n internalDepPackageNames.map((name) => {\n const pkg = packagesRegistry[name];\n assert(pkg, `Package ${name} not found in packages registry`);\n\n return [name, pkg.rootRelativeDir];\n })\n );\n\n const relevantImporterIds = [\n targetImporterId,\n /**\n * The directory paths happen to correspond with what PNPM calls the\n * importer ids in the context of a lockfile.\n */\n ...Object.values(directoryByPackageName),\n ];\n\n log.debug(\"Relevant importer ids:\", relevantImporterIds);\n\n /**\n * In a Rush workspace the original lockfile is not in the root, so the\n * importerIds have to be prefixed with `../../`, but that's not how they\n * should be stored in the isolated lockfile, so we use the prefixed ids\n * only for parsing.\n */\n const relevantImporterIdsWithPrefix = relevantImporterIds.map((x) =>\n isRush ? `../../${x}` : x\n );\n\n lockfile.importers = Object.fromEntries(\n Object.entries(\n pick(lockfile.importers, relevantImporterIdsWithPrefix)\n ).map(([prefixedImporterId, importer]) => {\n const importerId = isRush\n ? prefixedImporterId.replace(\"../../\", \"\")\n : prefixedImporterId;\n\n if (importerId === targetImporterId) {\n log.debug(\"Setting target package importer on root\");\n\n return [\n \".\",\n pnpmMapImporter(\".\", importer, {\n includeDevDependencies,\n includePatchedDependencies,\n directoryByPackageName,\n }),\n ];\n }\n\n log.debug(\"Setting internal package importer:\", importerId);\n\n return [\n importerId,\n pnpmMapImporter(importerId, importer, {\n includeDevDependencies,\n includePatchedDependencies,\n directoryByPackageName,\n }),\n ];\n })\n );\n\n log.debug(\"Pruning the lockfile\");\n\n const prunedLockfile = useVersion9\n ? await pruneLockfile_v9(lockfile, targetPackageManifest, \".\")\n : await pruneLockfile_v8(lockfile, targetPackageManifest, \".\");\n\n /** Pruning seems to remove the overrides from the lockfile */\n if (lockfile.overrides) {\n prunedLockfile.overrides = lockfile.overrides;\n }\n\n /**\n * Don't know how to map the patched dependencies yet, so we just include\n * them but I don't think it would work like this. The important thing for\n * now is that they are omitted by default, because that is the most common\n * use case.\n */\n const patchedDependencies = includePatchedDependencies\n ? lockfile.patchedDependencies\n : undefined;\n\n useVersion9\n ? await writeWantedLockfile_v9(isolateDir, {\n ...prunedLockfile,\n patchedDependencies,\n })\n : await writeWantedLockfile_v8(isolateDir, {\n ...prunedLockfile,\n patchedDependencies,\n });\n\n log.debug(\"Created lockfile at\", path.join(isolateDir, \"pnpm-lock.yaml\"));\n } catch (err) {\n log.error(`Failed to generate lockfile: ${getErrorMessage(err)}`);\n throw err;\n }\n}\n","import path from \"node:path\";\nimport type {\n ProjectSnapshot,\n ResolvedDependencies,\n} from \"pnpm_lockfile_file_v8\";\n\nimport { mapValues } from \"remeda\";\n\n/** Convert dependency links */\nexport function pnpmMapImporter(\n importerPath: string,\n { dependencies, devDependencies, ...rest }: ProjectSnapshot,\n {\n includeDevDependencies,\n directoryByPackageName,\n }: {\n includeDevDependencies: boolean;\n includePatchedDependencies: boolean;\n directoryByPackageName: { [packageName: string]: string };\n }\n): ProjectSnapshot {\n return {\n dependencies: dependencies\n ? pnpmMapDependenciesLinks(\n importerPath,\n dependencies,\n directoryByPackageName\n )\n : undefined,\n devDependencies:\n includeDevDependencies && devDependencies\n ? pnpmMapDependenciesLinks(\n importerPath,\n devDependencies,\n directoryByPackageName\n )\n : undefined,\n ...rest,\n };\n}\n\nfunction pnpmMapDependenciesLinks(\n importerPath: string,\n def: ResolvedDependencies,\n directoryByPackageName: { [packageName: string]: string }\n): ResolvedDependencies {\n return mapValues(def, (value, key) => {\n if (!value.startsWith(\"link:\")) {\n return value;\n }\n\n const relativePath = path.relative(\n importerPath,\n directoryByPackageName[key]\n );\n\n return relativePath.startsWith(\".\")\n ? `link:${relativePath}`\n : `link:./${relativePath}`;\n });\n}\n","import fs from \"fs-extra\";\nimport { execSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport { useLogger } from \"~/lib/logger\";\nimport { getErrorMessage, isRushWorkspace } from \"~/lib/utils\";\n\n/**\n * Generate an isolated / pruned lockfile, based on the existing lockfile from\n * the monorepo root plus the adapted package manifest in the isolate\n * directory.\n */\nexport async function generateYarnLockfile({\n workspaceRootDir,\n isolateDir,\n}: {\n workspaceRootDir: string;\n isolateDir: string;\n}) {\n const log = useLogger();\n\n log.debug(\"Generating Yarn lockfile...\");\n\n const origLockfilePath = isRushWorkspace(workspaceRootDir)\n ? path.join(workspaceRootDir, \"common/config/rush\", \"yarn.lock\")\n : path.join(workspaceRootDir, \"yarn.lock\");\n\n const newLockfilePath = path.join(isolateDir, \"yarn.lock\");\n\n if (!fs.existsSync(origLockfilePath)) {\n throw new Error(`Failed to find lockfile at ${origLockfilePath}`);\n }\n\n log.debug(`Copy original yarn.lock to the isolate output`);\n\n try {\n await fs.copyFile(origLockfilePath, newLockfilePath);\n\n /**\n * Running install with the original lockfile in the same directory will\n * generate a pruned version of the lockfile.\n */\n log.debug(`Running local install`);\n execSync(`yarn install --cwd ${isolateDir}`);\n\n log.debug(\"Generated lockfile at\", newLockfilePath);\n } catch (err) {\n log.error(`Failed to generate lockfile: ${getErrorMessage(err)}`);\n throw err;\n }\n}\n","import { useLogger } from \"../logger\";\nimport { usePackageManager } from \"../package-manager\";\nimport type { PackageManifest, PackagesRegistry } from \"../types\";\nimport {\n generateNpmLockfile,\n generatePnpmLockfile,\n generateYarnLockfile,\n} from \"./helpers\";\n\n/**\n * Adapt the lockfile and write it to the isolate directory. Because we keep the\n * structure of packages in the isolate directory the same as they were in the\n * monorepo, the lockfile is largely still correct. The only things that need to\n * be done is to remove the root dependencies and devDependencies, and rename\n * the path to the target package to act as the new root.\n */\nexport async function processLockfile({\n workspaceRootDir,\n packagesRegistry,\n isolateDir,\n internalDepPackageNames,\n targetPackageDir,\n targetPackageManifest,\n}: {\n workspaceRootDir: string;\n packagesRegistry: PackagesRegistry;\n isolateDir: string;\n internalDepPackageNames: string[];\n targetPackageDir: string;\n targetPackageName: string;\n targetPackageManifest: PackageManifest;\n}) {\n const log = useLogger();\n\n const { name, majorVersion } = usePackageManager();\n let usedFallbackToNpm = false;\n\n switch (name) {\n case \"npm\": {\n await generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n });\n\n break;\n }\n case \"yarn\": {\n if (majorVersion === 1) {\n await generateYarnLockfile({\n workspaceRootDir,\n isolateDir,\n });\n } else {\n log.warn(\n \"Detected modern version of Yarn. Using NPM lockfile fallback.\"\n );\n\n await generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n });\n\n usedFallbackToNpm = true;\n }\n\n break;\n }\n case \"pnpm\": {\n await generatePnpmLockfile({\n workspaceRootDir,\n targetPackageDir,\n isolateDir,\n internalDepPackageNames,\n packagesRegistry,\n targetPackageManifest,\n majorVersion,\n });\n break;\n }\n default:\n log.warn(`Unexpected package manager ${name}. Using NPM for output`);\n await generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n });\n\n usedFallbackToNpm = true;\n }\n\n return usedFallbackToNpm;\n}\n","import { omit, pick } from \"remeda\";\nimport { useConfig } from \"../config\";\nimport { usePackageManager } from \"../package-manager\";\nimport type { PackageManifest, PackagesRegistry } from \"../types\";\nimport { adaptManifestInternalDeps, adoptPnpmFieldsFromRoot } from \"./helpers\";\n\n/**\n * Adapt the output package manifest, so that:\n *\n * - Its internal dependencies point to the isolated ./packages/* directory.\n * - The devDependencies are possibly removed\n * - Scripts are picked or omitted and otherwise removed\n */\nexport async function adaptTargetPackageManifest({\n manifest,\n packagesRegistry,\n workspaceRootDir,\n}: {\n manifest: PackageManifest;\n packagesRegistry: PackagesRegistry;\n workspaceRootDir: string;\n}) {\n const packageManager = usePackageManager();\n const {\n includeDevDependencies,\n pickFromScripts,\n omitFromScripts,\n omitPackageManager,\n } = useConfig();\n\n /** Dev dependencies are omitted by default */\n const inputManifest = includeDevDependencies\n ? manifest\n : omit(manifest, [\"devDependencies\"]);\n\n const adaptedManifest =\n packageManager.name === \"pnpm\"\n ? /**\n * For PNPM the output itself is a workspace so we can preserve the specifiers\n * with \"workspace:*\" in the output manifest, but we do want to adopt the\n * pnpm.overrides field from the root package.json.\n */\n await adoptPnpmFieldsFromRoot(inputManifest, workspaceRootDir)\n : /** For other package managers we replace the links to internal dependencies */\n adaptManifestInternalDeps({\n manifest: inputManifest,\n packagesRegistry,\n });\n\n return {\n ...adaptedManifest,\n /**\n * Adopt the package manager definition from the root manifest if available.\n * The option to omit is there because some platforms might not handle it\n * properly (Cloud Run, April 24th 2024, does not handle pnpm v9)\n */\n packageManager: omitPackageManager\n ? undefined\n : packageManager.packageManagerString,\n /**\n * Scripts are removed by default if not explicitly picked or omitted via\n * config.\n */\n scripts: pickFromScripts\n ? pick(manifest.scripts ?? {}, pickFromScripts)\n : omitFromScripts\n ? omit(manifest.scripts ?? {}, omitFromScripts)\n : undefined,\n };\n}\n","import path from \"node:path\";\nimport { omit } from \"remeda\";\nimport { usePackageManager } from \"~/lib/package-manager\";\nimport type { PackagesRegistry } from \"~/lib/types\";\nimport { writeManifest } from \"../io\";\nimport { adaptManifestInternalDeps } from \"./adapt-manifest-internal-deps\";\n\n/**\n * Adapt the manifest files of all the isolated internal packages (excluding the\n * target package), so that their dependencies point to the other isolated\n * packages in the same folder.\n */\nexport async function adaptInternalPackageManifests(\n internalPackageNames: string[],\n packagesRegistry: PackagesRegistry,\n isolateDir: string\n) {\n const packageManager = usePackageManager();\n\n await Promise.all(\n internalPackageNames.map(async (packageName) => {\n const { manifest, rootRelativeDir } = packagesRegistry[packageName];\n\n /** Dev dependencies and scripts are never included for internal deps */\n const strippedManifest = omit(manifest, [\"scripts\", \"devDependencies\"]);\n\n const outputManifest =\n packageManager.name === \"pnpm\"\n ? /**\n * For PNPM the output itself is a workspace so we can preserve the specifiers\n * with \"workspace:*\" in the output manifest.\n */\n strippedManifest\n : /** For other package managers we replace the links to internal dependencies */\n adaptManifestInternalDeps({\n manifest: strippedManifest,\n packagesRegistry,\n parentRootRelativeDir: rootRelativeDir,\n });\n\n await writeManifest(\n path.join(isolateDir, rootRelativeDir),\n outputManifest\n );\n })\n );\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport type { PackageManifest } from \"../types\";\nimport { readTypedJson } from \"../utils\";\n\nexport async function readManifest(packageDir: string) {\n return readTypedJson<PackageManifest>(path.join(packageDir, \"package.json\"));\n}\n\nexport async function writeManifest(\n outputDir: string,\n manifest: PackageManifest\n) {\n await fs.writeFile(\n path.join(outputDir, \"package.json\"),\n JSON.stringify(manifest, null, 2)\n );\n}\n","import path from \"node:path\";\nimport { useLogger } from \"../../logger\";\nimport type { PackagesRegistry } from \"../../types\";\n\nexport function patchInternalEntries(\n dependencies: Record<string, string>,\n packagesRegistry: PackagesRegistry,\n parentRootRelativeDir?: string\n) {\n const log = useLogger();\n const allWorkspacePackageNames = Object.keys(packagesRegistry);\n\n return Object.fromEntries(\n Object.entries(dependencies).map(([key, value]) => {\n if (allWorkspacePackageNames.includes(key)) {\n const def = packagesRegistry[key];\n\n /**\n * When nested internal dependencies are used (internal packages linking\n * to other internal packages), the parentRootRelativeDir will be passed\n * in, and we store the relative path to the isolate/packages\n * directory.\n *\n * For consistency we also write the other file paths starting with ./,\n * but it doesn't seem to be necessary for any package manager.\n */\n const relativePath = parentRootRelativeDir\n ? path.relative(parentRootRelativeDir, `./${def.rootRelativeDir}`)\n : `./${def.rootRelativeDir}`;\n\n const linkPath = `file:${relativePath}`;\n\n log.debug(`Linking dependency ${key} to ${linkPath}`);\n\n return [key, linkPath];\n } else {\n return [key, value];\n }\n })\n );\n}\n","import type { PackageManifest, PackagesRegistry } from \"~/lib/types\";\nimport { patchInternalEntries } from \"./patch-internal-entries\";\n\n/**\n * Replace the workspace version specifiers for internal dependency with file:\n * paths. Not needed for PNPM (because we configure the isolated output as a\n * workspace), but maybe still for NPM and Yarn.\n */\nexport function adaptManifestInternalDeps({\n manifest,\n packagesRegistry,\n parentRootRelativeDir,\n}: {\n manifest: PackageManifest;\n packagesRegistry: PackagesRegistry;\n parentRootRelativeDir?: string;\n}): PackageManifest {\n const { dependencies, devDependencies } = manifest;\n\n return {\n ...manifest,\n dependencies: dependencies\n ? patchInternalEntries(\n dependencies,\n packagesRegistry,\n parentRootRelativeDir\n )\n : undefined,\n devDependencies: devDependencies\n ? patchInternalEntries(\n devDependencies,\n packagesRegistry,\n parentRootRelativeDir\n )\n : undefined,\n };\n}\n","import type { ProjectManifest } from \"@pnpm/types\";\nimport path from \"path\";\nimport type { PackageManifest } from \"~/lib/types\";\nimport { isRushWorkspace, readTypedJson } from \"~/lib/utils\";\n\n/**\n * Adopts the `pnpm` fields from the root package manifest. Currently it only\n * takes overrides, because I don't know if any of the others are useful or\n * desired.\n */\nexport async function adoptPnpmFieldsFromRoot(\n targetPackageManifest: PackageManifest,\n workspaceRootDir: string\n) {\n if (isRushWorkspace(workspaceRootDir)) {\n return targetPackageManifest;\n }\n\n const rootPackageManifest = await readTypedJson<ProjectManifest>(\n path.join(workspaceRootDir, \"package.json\")\n );\n\n const overrides = rootPackageManifest.pnpm?.overrides;\n\n if (!overrides) {\n return targetPackageManifest;\n }\n\n return {\n ...targetPackageManifest,\n pnpm: {\n overrides,\n },\n };\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport outdent from \"outdent\";\nimport { useConfig } from \"../config\";\nimport { useLogger } from \"../logger\";\nimport { readTypedJson } from \"../utils\";\n\nexport async function getBuildOutputDir(targetPackageDir: string) {\n const config = useConfig();\n const log = useLogger();\n\n if (config.buildDirName) {\n log.debug(\"Using buildDirName from config:\", config.buildDirName);\n return path.join(targetPackageDir, config.buildDirName);\n }\n\n const tsconfigPath = path.join(targetPackageDir, config.tsconfigPath);\n\n if (fs.existsSync(tsconfigPath)) {\n log.debug(\"Found tsconfig at:\", config.tsconfigPath);\n\n const tsconfig = await readTypedJson<{\n compilerOptions?: { outDir?: string };\n }>(tsconfigPath);\n\n const outDir = tsconfig.compilerOptions?.outDir;\n\n if (outDir) {\n return path.join(targetPackageDir, outDir);\n } else {\n throw new Error(outdent`\n Failed to find outDir in tsconfig. If you are executing isolate from the root of a monorepo you should specify the buildDirName in isolate.config.json.\n `);\n }\n } else {\n log.warn(\"Failed to find tsconfig at:\", tsconfigPath);\n\n throw new Error(outdent`\n Failed to infer the build output directory from either the isolate config buildDirName or a Typescript config file. See the documentation on how to configure one of these options.\n `);\n }\n}\n","import assert from \"node:assert\";\nimport { useLogger } from \"../logger\";\nimport type { PackagesRegistry } from \"../types\";\nimport { pack } from \"../utils\";\n\n/**\n * Pack dependencies so that we extract only the files that are supposed to be\n * published by the packages.\n *\n * @returns A map of package names to the path of the packed file\n */\nexport async function packDependencies({\n /** All packages found in the monorepo by workspaces declaration */\n packagesRegistry,\n /** The dependencies that appear to be internal packages */\n internalPackageNames,\n /**\n * The directory where the isolated package and all its dependencies will end\n * up. This is also the directory from where the package will be deployed. By\n * default it is a subfolder in targetPackageDir called \"isolate\" but you can\n * configure it.\n */\n packDestinationDir,\n}: {\n packagesRegistry: PackagesRegistry;\n internalPackageNames: string[];\n packDestinationDir: string;\n}) {\n const log = useLogger();\n\n const packedFileByName: Record<string, string> = {};\n\n for (const dependency of internalPackageNames) {\n const def = packagesRegistry[dependency];\n\n assert(dependency, `Failed to find package definition for ${dependency}`);\n\n const { name } = def.manifest;\n\n /**\n * If this dependency has already been packed, we skip it. It could happen\n * because we are packing workspace dependencies recursively.\n */\n if (packedFileByName[name]) {\n log.debug(`Skipping ${name} because it has already been packed`);\n continue;\n }\n\n packedFileByName[name] = await pack(def.absoluteDir, packDestinationDir);\n }\n\n return packedFileByName;\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport { useLogger } from \"../logger\";\nimport { pack, unpack } from \"../utils\";\n\nconst TIMEOUT_MS = 5000;\n\nexport async function processBuildOutputFiles({\n targetPackageDir,\n tmpDir,\n isolateDir,\n}: {\n targetPackageDir: string;\n tmpDir: string;\n isolateDir: string;\n}) {\n const log = useLogger();\n\n const packedFilePath = await pack(targetPackageDir, tmpDir);\n const unpackDir = path.join(tmpDir, \"target\");\n\n const now = Date.now();\n let isWaitingYet = false;\n\n while (!fs.existsSync(packedFilePath) && Date.now() - now < TIMEOUT_MS) {\n if (!isWaitingYet) {\n log.debug(`Waiting for ${packedFilePath} to become available...`);\n }\n isWaitingYet = true;\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n\n await unpack(packedFilePath, unpackDir);\n await fs.copy(path.join(unpackDir, \"package\"), isolateDir);\n}\n","import fs from \"fs-extra\";\nimport path, { join } from \"node:path\";\nimport { useLogger } from \"../logger\";\nimport type { PackagesRegistry } from \"../types\";\nimport { getIsolateRelativePath, unpack } from \"../utils\";\n\nexport async function unpackDependencies(\n packedFilesByName: Record<string, string>,\n packagesRegistry: PackagesRegistry,\n tmpDir: string,\n isolateDir: string\n) {\n const log = useLogger();\n\n await Promise.all(\n Object.entries(packedFilesByName).map(async ([packageName, filePath]) => {\n const dir = packagesRegistry[packageName].rootRelativeDir;\n const unpackDir = join(tmpDir, dir);\n\n log.debug(\"Unpacking\", `(temp)/${path.basename(filePath)}`);\n\n await unpack(filePath, unpackDir);\n\n const destinationDir = join(isolateDir, dir);\n\n await fs.ensureDir(destinationDir);\n\n await fs.move(join(unpackDir, \"package\"), destinationDir, {\n overwrite: true,\n });\n\n log.debug(\n `Moved package files to ${getIsolateRelativePath(\n destinationDir,\n isolateDir\n )}`\n );\n })\n );\n}\n","import fs from \"fs-extra\";\nimport { globSync } from \"glob\";\nimport path from \"node:path\";\nimport { useLogger } from \"../logger\";\nimport type { PackageManifest, PackagesRegistry } from \"../types\";\nimport { isRushWorkspace, readTypedJson, readTypedJsonSync } from \"../utils\";\nimport { findPackagesGlobs } from \"./helpers\";\n\n/**\n * Build a list of all packages in the workspace, depending on the package\n * manager used, with a possible override from the config file. The list\n * contains the manifest with some directory info mapped by module name.\n */\nexport async function createPackagesRegistry(\n workspaceRootDir: string,\n workspacePackagesOverride: string[] | undefined\n): Promise<PackagesRegistry> {\n const log = useLogger();\n\n if (workspacePackagesOverride) {\n log.debug(\n `Override workspace packages via config: ${workspacePackagesOverride}`\n );\n }\n\n const allPackages = listWorkspacePackages(\n workspacePackagesOverride,\n workspaceRootDir\n );\n\n const registry: PackagesRegistry = (\n await Promise.all(\n allPackages.map(async (rootRelativeDir) => {\n const absoluteDir = path.join(workspaceRootDir, rootRelativeDir);\n const manifestPath = path.join(absoluteDir, \"package.json\");\n\n if (!fs.existsSync(manifestPath)) {\n log.warn(\n `Ignoring directory ${rootRelativeDir} because it does not contain a package.json file`\n );\n return;\n } else {\n log.debug(`Registering package ${rootRelativeDir}`);\n\n const manifest = await readTypedJson<PackageManifest>(\n path.join(absoluteDir, \"package.json\")\n );\n\n return {\n manifest,\n rootRelativeDir,\n absoluteDir,\n };\n }\n })\n )\n ).reduce<PackagesRegistry>((acc, info) => {\n if (info) {\n acc[info.manifest.name] = info;\n }\n return acc;\n }, {});\n\n return registry;\n}\n\ntype RushConfig = {\n projects: { packageName: string; projectFolder: string }[];\n};\n\nfunction listWorkspacePackages(\n workspacePackagesOverride: string[] | undefined,\n workspaceRootDir: string\n) {\n if (isRushWorkspace(workspaceRootDir)) {\n const rushConfig = readTypedJsonSync<RushConfig>(\n path.join(workspaceRootDir, \"rush.json\")\n );\n\n return rushConfig.projects.map(({ projectFolder }) => projectFolder);\n } else {\n const currentDir = process.cwd();\n process.chdir(workspaceRootDir);\n\n const packagesGlobs =\n workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);\n\n const allPackages = packagesGlobs\n .flatMap((glob) => globSync(glob))\n /** Make sure to filter any loose files that might hang around. */\n .filter((dir) => fs.lstatSync(dir).isDirectory());\n\n process.chdir(currentDir);\n return allPackages;\n }\n}\n","import assert from \"node:assert\";\nimport path from \"node:path\";\nimport { useLogger } from \"../../logger\";\nimport { usePackageManager } from \"../../package-manager\";\nimport {\n inspectValue,\n readTypedJsonSync,\n readTypedYamlSync,\n} from \"../../utils\";\n\n/**\n * Find the globs that define where the packages are located within the\n * monorepo. This configuration is dependent on the package manager used, and I\n * don't know if we're covering all cases yet...\n */\nexport function findPackagesGlobs(workspaceRootDir: string) {\n const log = useLogger();\n\n const packageManager = usePackageManager();\n\n switch (packageManager.name) {\n case \"pnpm\": {\n const { packages: globs } = readTypedYamlSync<{ packages: string[] }>(\n path.join(workspaceRootDir, \"pnpm-workspace.yaml\")\n );\n\n log.debug(\"Detected pnpm packages globs:\", inspectValue(globs));\n return globs;\n }\n case \"yarn\":\n case \"npm\": {\n const workspaceRootManifestPath = path.join(\n workspaceRootDir,\n \"package.json\"\n );\n\n const { workspaces } = readTypedJsonSync<{ workspaces: string[] }>(\n workspaceRootManifestPath\n );\n\n if (!workspaces) {\n throw new Error(\n `No workspaces field found in ${workspaceRootManifestPath}`\n );\n }\n\n if (Array.isArray(workspaces)) {\n return workspaces;\n } else {\n /**\n * For Yarn, workspaces could be defined as an object with { packages:\n * [], nohoist: [] }. See\n * https://classic.yarnpkg.com/blog/2018/02/15/nohoist/\n */\n const workspacesObject = workspaces as { packages?: string[] };\n\n assert(\n workspacesObject.packages,\n \"workspaces.packages must be an array\"\n );\n\n return workspacesObject.packages;\n }\n }\n }\n}\n","import { uniq } from \"remeda\";\nimport type { PackageManifest, PackagesRegistry } from \"../types\";\n\n/**\n * Recursively list all the packages from dependencies (and optionally\n * devDependencies) that are found in the monorepo.\n *\n * Here we do not need to rely on packages being declared with \"workspace:\" in\n * the package manifest. We can simply compare the package names with the list\n * of packages that were found via the workspace glob patterns and add them to\n * the registry.\n */\nexport function listInternalPackages(\n manifest: PackageManifest,\n packagesRegistry: PackagesRegistry,\n { includeDevDependencies = false } = {}\n): string[] {\n const allWorkspacePackageNames = Object.keys(packagesRegistry);\n\n const internalPackageNames = (\n includeDevDependencies\n ? [\n ...Object.keys(manifest.dependencies ?? {}),\n ...Object.keys(manifest.devDependencies ?? {}),\n ]\n : Object.keys(manifest.dependencies ?? {})\n ).filter((name) => allWorkspacePackageNames.includes(name));\n\n const nestedInternalPackageNames = internalPackageNames.flatMap(\n (packageName) =>\n listInternalPackages(\n packagesRegistry[packageName].manifest,\n packagesRegistry,\n { includeDevDependencies }\n )\n );\n\n return uniq(internalPackageNames.concat(nestedInternalPackageNames));\n}\n"],"mappings":";AAAA,OAAOA,UAAQ;AACf,OAAOC,aAAY;AACnB,OAAOC,YAAU;AACjB,SAAS,cAAc;;;ACHvB,OAAOC,SAAQ;AACf,OAAOC,aAAY;AACnB,OAAOC,WAAU;AACjB,SAAS,eAAe;;;ACHxB,OAAO,WAAW;AAelB,IAAI,kBAA0B;AAAA,EAC5B,SAAS,MAAiB;AACxB,YAAQ,IAAI,MAAM,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC1C;AAAA,EACA,QAAQ,MAAiB;AACvB,YAAQ,IAAI,MAAM,MAAM,MAAM,GAAG,GAAG,IAAI;AAAA,EAC1C;AAAA,EACA,QAAQ,MAAiB;AACvB,YAAQ,IAAI,MAAM,OAAO,SAAS,GAAG,GAAG,IAAI;AAAA,EAC9C;AAAA,EACA,SAAS,MAAiB;AACxB,YAAQ,IAAI,MAAM,IAAI,OAAO,GAAG,GAAG,IAAI;AAAA,EACzC;AACF;AAEA,IAAM,UAAkB;AAAA,EACtB,SAAS,MAAiB;AACxB,QAAI,cAAc,SAAS;AACzB,sBAAgB,MAAM,GAAG,IAAI;AAAA,IAC/B;AAAA,EACF;AAAA,EACA,QAAQ,MAAiB;AACvB,QAAI,cAAc,WAAW,cAAc,QAAQ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AAA,QAC1B,qBAAqB;AAAA,UACnB,CAAC,SAASH,OAAK,MAAM,iBAAiB,IAAI,EAAE,eAAe,EAAE;AAAA,QAC/D;AAAA,MACF;AAEA,UAAI,MAAM,mDAAmD;AAC7D,UAAI,MAAM,0BAA0B,mBAAmB;AAEvD,YAAM,WAAW,oBAAoB,IAAI,CAAC,MAAMA,OAAK,KAAK,GAAG,IAAI,CAAC;AAElE,YAAM,mBAAmBA,OAAK,KAAK,YAAY,qBAAqB,GAAG;AAAA,QACrE;AAAA,MACF,CAAC;AAAA,IACH,OAAO;AACL,MAAAE,KAAG;AAAA,QACDF,OAAK,KAAK,kBAAkB,qBAAqB;AAAA,QACjDA,OAAK,KAAK,YAAY,qBAAqB;AAAA,MAC7C;AAAA,IACF;AAAA,EACF;AAQA,QAAM,YAAYA,OAAK,KAAK,kBAAkB,QAAQ;AAEtD,MAAIE,KAAG,WAAW,SAAS,GAAG;AAC5B,IAAAA,KAAG,aAAa,WAAWF,OAAK,KAAK,YAAY,QAAQ,CAAC;AAC1D,QAAI,MAAM,0CAA0C;AAAA,EACtD;AAMA,MAAI;AAAA,IACF;AAAA,IACA,oBAAoB,QAAQ,gBAAgB;AAAA,EAC9C;AACA,QAAME,KAAG,OAAO,MAAM;AAEtB,MAAI,KAAK,wBAAwB,UAAU;AAE3C,SAAO;AACT;","names":["fs","assert","path","fs","assert","path","path","fs","fs","fs","path","path","fs","path","fs","path","fs","path","path","fs","path","stdout","path","fs","fs","fs","fs","path","fs","fs","path","path","fs","assert","path","path","path","assert","fs","execSync","path","path","fs","execSync","omit","pick","path","fs","path","path","fs","path","path","packageManager","path","path","path","packageManager","omit","pick","fs","path","path","fs","assert","assert","fs","path","path","fs","fs","path","join","join","path","fs","fs","path","assert","path","packageManager","path","assert","path","fs","path","assert","fs","packageManager"]}
1
+ {"version":3,"sources":["../src/isolate.ts","../src/lib/config.ts","../src/lib/logger.ts","../src/lib/utils/get-dirname.ts","../src/lib/utils/get-error-message.ts","../src/lib/utils/get-relative-path.ts","../src/lib/utils/inspect-value.ts","../src/lib/utils/is-rush-workspace.ts","../src/lib/utils/json.ts","../src/lib/utils/pack.ts","../src/lib/package-manager/index.ts","../src/lib/package-manager/helpers/infer-from-files.ts","../src/lib/utils/get-major-version.ts","../src/lib/package-manager/names.ts","../src/lib/package-manager/helpers/infer-from-manifest.ts","../src/lib/utils/unpack.ts","../src/lib/utils/yaml.ts","../src/lib/lockfile/helpers/generate-npm-lockfile.ts","../src/lib/lockfile/helpers/generate-pnpm-lockfile.ts","../src/lib/lockfile/helpers/pnpm-map-importer.ts","../src/lib/lockfile/helpers/generate-yarn-lockfile.ts","../src/lib/lockfile/process-lockfile.ts","../src/lib/manifest/adapt-target-package-manifest.ts","../src/lib/manifest/helpers/adapt-internal-package-manifests.ts","../src/lib/manifest/io.ts","../src/lib/manifest/helpers/patch-internal-entries.ts","../src/lib/manifest/helpers/adapt-manifest-internal-deps.ts","../src/lib/manifest/helpers/adopt-pnpm-fields-from-root.ts","../src/lib/output/get-build-output-dir.ts","../src/lib/output/pack-dependencies.ts","../src/lib/output/process-build-output-files.ts","../src/lib/output/unpack-dependencies.ts","../src/lib/registry/create-packages-registry.ts","../src/lib/registry/helpers/find-packages-globs.ts","../src/lib/registry/list-internal-packages.ts"],"sourcesContent":["import fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport { unique } from \"remeda\";\nimport type { IsolateConfig } from \"./lib/config\";\nimport { resolveConfig, setUserConfig } from \"./lib/config\";\nimport { processLockfile } from \"./lib/lockfile\";\nimport type { Logger } from \"./lib/logger\";\nimport { setLogLevel, setLogger, useLogger } from \"./lib/logger\";\nimport {\n adaptInternalPackageManifests,\n adaptTargetPackageManifest,\n readManifest,\n writeManifest,\n} from \"./lib/manifest\";\nimport {\n getBuildOutputDir,\n packDependencies,\n processBuildOutputFiles,\n unpackDependencies,\n} from \"./lib/output\";\nimport { detectPackageManager, shouldUsePnpmPack } from \"./lib/package-manager\";\nimport { getVersion } from \"./lib/package-manager/helpers/infer-from-files\";\nimport { createPackagesRegistry, listInternalPackages } from \"./lib/registry\";\nimport type { PackageManifest } from \"./lib/types\";\nimport {\n getDirname,\n getRootRelativePath,\n isRushWorkspace,\n readTypedJson,\n writeTypedYamlSync,\n} from \"./lib/utils\";\n\nconst __dirname = getDirname(import.meta.url);\n\nexport async function isolate(\n options: { config?: IsolateConfig; logger?: Logger } = {}\n) {\n if (options.logger) {\n setLogger(options.logger);\n }\n\n if (options.config) {\n setUserConfig(options.config);\n }\n\n const config = resolveConfig();\n\n setLogLevel(config.logLevel);\n\n const log = useLogger();\n\n const { version: libraryVersion } = await readTypedJson<PackageManifest>(\n path.join(path.join(__dirname, \"..\", \"package.json\"))\n );\n\n log.info(\"Using isolate-package version\", libraryVersion);\n\n /**\n * If a targetPackagePath is set, we assume the configuration lives in the\n * root of the workspace. If targetPackagePath is undefined (the default), we\n * assume that the configuration lives in the target package directory.\n */\n const targetPackageDir = config.targetPackagePath\n ? path.join(process.cwd(), config.targetPackagePath)\n : process.cwd();\n\n const workspaceRootDir = config.targetPackagePath\n ? process.cwd()\n : path.join(targetPackageDir, config.workspaceRoot);\n\n const buildOutputDir = await getBuildOutputDir(targetPackageDir);\n\n assert(\n fs.existsSync(buildOutputDir),\n `Failed to find build output path at ${buildOutputDir}. Please make sure you build the source before isolating it.`\n );\n\n log.debug(\"Workspace root resolved to\", workspaceRootDir);\n log.debug(\n \"Isolate target package\",\n getRootRelativePath(targetPackageDir, workspaceRootDir)\n );\n\n const isolateDir = path.join(targetPackageDir, config.isolateDirName);\n\n log.debug(\n \"Isolate output directory\",\n getRootRelativePath(isolateDir, workspaceRootDir)\n );\n\n if (fs.existsSync(isolateDir)) {\n await fs.remove(isolateDir);\n log.debug(\"Cleaned the existing isolate output directory\");\n }\n\n await fs.ensureDir(isolateDir);\n\n const tmpDir = path.join(isolateDir, \"__tmp\");\n await fs.ensureDir(tmpDir);\n\n const targetPackageManifest = await readTypedJson<PackageManifest>(\n path.join(targetPackageDir, \"package.json\")\n );\n\n const packageManager = detectPackageManager(workspaceRootDir);\n\n log.debug(\n \"Detected package manager\",\n packageManager.name,\n packageManager.version\n );\n\n if (shouldUsePnpmPack()) {\n log.debug(\"Use PNPM pack instead of NPM pack\");\n }\n\n /**\n * Build a packages registry so we can find the workspace packages by name and\n * have access to their manifest files and relative paths.\n */\n const packagesRegistry = await createPackagesRegistry(\n workspaceRootDir,\n config.workspacePackages\n );\n\n const internalPackageNames = listInternalPackages(\n targetPackageManifest,\n packagesRegistry,\n {\n includeDevDependencies: config.includeDevDependencies,\n }\n );\n\n const packedFilesByName = await packDependencies({\n internalPackageNames,\n packagesRegistry,\n packDestinationDir: tmpDir,\n });\n\n await unpackDependencies(\n packedFilesByName,\n packagesRegistry,\n tmpDir,\n isolateDir\n );\n\n /** Adapt the manifest files for all the unpacked local dependencies */\n await adaptInternalPackageManifests(\n internalPackageNames,\n packagesRegistry,\n isolateDir\n );\n\n /** Pack the target package directory, and unpack it in the isolate location */\n await processBuildOutputFiles({\n targetPackageDir,\n tmpDir,\n isolateDir,\n });\n\n /**\n * Copy the target manifest file to the isolate location and adapt its\n * workspace dependencies to point to the isolated packages.\n */\n const outputManifest = await adaptTargetPackageManifest({\n manifest: targetPackageManifest,\n packagesRegistry,\n workspaceRootDir,\n });\n\n await writeManifest(isolateDir, outputManifest);\n\n /** Generate an isolated lockfile based on the original one */\n const usedFallbackToNpm = await processLockfile({\n workspaceRootDir,\n isolateDir,\n packagesRegistry,\n internalDepPackageNames: internalPackageNames,\n targetPackageDir,\n targetPackageName: targetPackageManifest.name,\n targetPackageManifest: outputManifest,\n });\n\n if (usedFallbackToNpm) {\n /**\n * When we fall back to NPM, we set the manifest package manager to the\n * available NPM version.\n */\n const manifest = await readManifest(isolateDir);\n\n const npmVersion = getVersion(\"npm\");\n manifest.packageManager = `npm@${npmVersion}`;\n\n await writeManifest(isolateDir, manifest);\n }\n\n if (packageManager.name === \"pnpm\") {\n /**\n * PNPM doesn't install dependencies of packages that are linked via link:\n * or file: specifiers. It requires the directory to be configured as a\n * workspace, so we copy the workspace config file to the isolate output.\n *\n * Rush doesn't have a pnpm-workspace.yaml file, so we generate one.\n */\n if (isRushWorkspace(workspaceRootDir)) {\n const packagesFolderNames = unique(\n internalPackageNames.map(\n (name) => path.parse(packagesRegistry[name].rootRelativeDir).dir\n )\n );\n\n log.debug(\"Generating pnpm-workspace.yaml for Rush workspace\");\n log.debug(\"Packages folder names:\", packagesFolderNames);\n\n const packages = packagesFolderNames.map((x) => path.join(x, \"/*\"));\n\n await writeTypedYamlSync(path.join(isolateDir, \"pnpm-workspace.yaml\"), {\n packages,\n });\n } else {\n fs.copyFileSync(\n path.join(workspaceRootDir, \"pnpm-workspace.yaml\"),\n path.join(isolateDir, \"pnpm-workspace.yaml\")\n );\n }\n }\n /**\n * If there is an .npmrc file in the workspace root, copy it to the isolate\n * because the settings there could affect how the lockfile is resolved. Note\n * that .npmrc is used by both NPM and PNPM for configuration.\n *\n * See also: https://pnpm.io/npmrc\n */\n const npmrcPath = path.join(workspaceRootDir, \".npmrc\");\n\n if (fs.existsSync(npmrcPath)) {\n fs.copyFileSync(npmrcPath, path.join(isolateDir, \".npmrc\"));\n log.debug(\"Copied .npmrc file to the isolate output\");\n }\n\n /**\n * Clean up. Only so this in the happy path, so we can look at the temp folder\n * when thing go wrong.\n */\n log.debug(\n \"Deleting temp directory\",\n getRootRelativePath(tmpDir, workspaceRootDir)\n );\n await fs.remove(tmpDir);\n\n log.info(\"Isolate completed at\", isolateDir);\n\n return isolateDir;\n}\n","import fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport { isEmpty } from \"remeda\";\nimport { setLogLevel, useLogger } from \"./logger\";\nimport { inspectValue, readTypedJsonSync } from \"./utils\";\n\nexport type IsolateConfigResolved = {\n buildDirName?: string;\n includeDevDependencies: boolean;\n includePatchedDependencies: boolean;\n isolateDirName: string;\n logLevel: \"info\" | \"debug\" | \"warn\" | \"error\";\n targetPackagePath?: string;\n tsconfigPath: string;\n workspacePackages?: string[];\n workspaceRoot: string;\n forceNpm: boolean;\n pickFromScripts?: string[];\n omitFromScripts?: string[];\n omitPackageManager?: boolean;\n};\n\nexport type IsolateConfig = Partial<IsolateConfigResolved>;\n\nconst configDefaults: IsolateConfigResolved = {\n buildDirName: undefined,\n includeDevDependencies: false,\n includePatchedDependencies: false,\n isolateDirName: \"isolate\",\n logLevel: \"info\",\n targetPackagePath: undefined,\n tsconfigPath: \"./tsconfig.json\",\n workspacePackages: undefined,\n workspaceRoot: \"../..\",\n forceNpm: false,\n pickFromScripts: undefined,\n omitFromScripts: undefined,\n omitPackageManager: false,\n};\n\n/**\n * Only initialize the configuration once, and keeping it here for subsequent\n * calls to getConfig.\n */\nlet _resolvedConfig: IsolateConfigResolved | undefined;\n\nlet _user_defined_config: IsolateConfig | undefined;\n\nconst validConfigKeys = Object.keys(configDefaults);\n\nconst CONFIG_FILE_NAME = \"isolate.config.json\";\n\nexport type LogLevel = IsolateConfigResolved[\"logLevel\"];\n\nexport function setUserConfig(config: IsolateConfig) {\n _user_defined_config = config;\n\n if (config.logLevel) {\n setLogLevel(config.logLevel);\n }\n}\n\nexport function useConfig() {\n if (_resolvedConfig) {\n return _resolvedConfig;\n } else {\n throw new Error(\"Called useConfig before config was made available\");\n }\n}\n\n/**\n * Resolve configuration based on user config and defaults. If setConfig was\n * called before this, it does not attempt to read a config file from disk.\n */\nexport function resolveConfig(): IsolateConfigResolved {\n if (_resolvedConfig) {\n return _resolvedConfig;\n }\n\n setLogLevel(process.env.DEBUG_ISOLATE_CONFIG ? \"debug\" : \"info\");\n\n const log = useLogger();\n\n const configFilePath = path.join(process.cwd(), CONFIG_FILE_NAME);\n\n if (_user_defined_config) {\n log.debug(`Using user defined config:`, inspectValue(_user_defined_config));\n } else {\n log.debug(`Attempting to load config from ${configFilePath}`);\n\n _user_defined_config = fs.existsSync(configFilePath)\n ? readTypedJsonSync<IsolateConfig>(configFilePath)\n : {};\n }\n\n const foreignKeys = Object.keys(_user_defined_config).filter(\n (key) => !validConfigKeys.includes(key)\n );\n\n if (!isEmpty(foreignKeys)) {\n log.warn(`Found invalid config settings:`, foreignKeys.join(\", \"));\n }\n\n const config = Object.assign(\n {},\n configDefaults,\n _user_defined_config\n ) satisfies IsolateConfigResolved;\n\n log.debug(\"Using configuration:\", inspectValue(config));\n\n _resolvedConfig = config;\n return config;\n}\n\n/**\n * Get only the configuration that the user set explicitly in the config file or\n * passed via arguments to isolate().\n */\nexport function getUserDefinedConfig(): IsolateConfig {\n assert(\n _user_defined_config,\n \"Called getUserDefinedConfig before user config was made available\"\n );\n\n return _user_defined_config;\n}\n","import chalk from \"chalk\";\nimport type { IsolateConfigResolved, LogLevel } from \"./config\";\n/**\n * The Logger defines an interface that can be used to pass in a different\n * logger object in order to intercept all the logging output. We keep the\n * handlers separate from the logger object itself, so that we can change the\n * handlers but do not bother the user with having to handle logLevel.\n */\nexport type Logger = {\n debug(...args: unknown[]): void;\n info(...args: unknown[]): void;\n warn(...args: unknown[]): void;\n error(...args: unknown[]): void;\n};\n\nlet _loggerHandlers: Logger = {\n debug(...args: unknown[]) {\n console.log(chalk.blue(\"debug\"), ...args);\n },\n info(...args: unknown[]) {\n console.log(chalk.green(\"info\"), ...args);\n },\n warn(...args: unknown[]) {\n console.log(chalk.yellow(\"warning\"), ...args);\n },\n error(...args: unknown[]) {\n console.log(chalk.red(\"error\"), ...args);\n },\n};\n\nconst _logger: Logger = {\n debug(...args: unknown[]) {\n if (_logLevel === \"debug\") {\n _loggerHandlers.debug(...args);\n }\n },\n info(...args: unknown[]) {\n if (_logLevel === \"debug\" || _logLevel === \"info\") {\n _loggerHandlers.info(...args);\n }\n },\n warn(...args: unknown[]) {\n if (_logLevel === \"debug\" || _logLevel === \"info\" || _logLevel === \"warn\") {\n _loggerHandlers.warn(...args);\n }\n },\n error(...args: unknown[]) {\n _loggerHandlers.error(...args);\n },\n};\n\nlet _logLevel: LogLevel = \"info\";\n\nexport function setLogger(logger: Logger) {\n _loggerHandlers = logger;\n return _logger;\n}\n\nexport function setLogLevel(\n logLevel: IsolateConfigResolved[\"logLevel\"]\n): Logger {\n _logLevel = logLevel;\n return _logger;\n}\n\nexport function useLogger() {\n return _logger;\n}\n","import { fileURLToPath } from \"url\";\n\n/**\n * Calling context should pass in import.meta.url and the function will return\n * the equivalent of __dirname in Node/CommonJs.\n */\nexport function getDirname(importMetaUrl: string) {\n return fileURLToPath(new URL(\".\", importMetaUrl));\n}\n","type ErrorWithMessage = {\n message: string;\n};\n\nexport function getErrorMessage(error: unknown) {\n return toErrorWithMessage(error).message;\n}\n\nfunction isErrorWithMessage(error: unknown): error is ErrorWithMessage {\n return typeof error === \"object\" && error !== null && \"message\" in error;\n}\n\nfunction toErrorWithMessage(maybeError: unknown): ErrorWithMessage {\n if (isErrorWithMessage(maybeError)) return maybeError;\n\n try {\n return new Error(JSON.stringify(maybeError));\n } catch {\n /**\n * Fallback in case there’s an error in stringify which can happen with\n * circular references.\n */\n return new Error(String(maybeError));\n }\n}\n","import { join } from \"node:path\";\n\nexport function getRootRelativePath(path: string, rootPath: string) {\n const strippedPath = path.replace(rootPath, \"\");\n\n return join(\"(root)\", strippedPath);\n}\n\nexport function getIsolateRelativePath(path: string, isolatePath: string) {\n const strippedPath = path.replace(isolatePath, \"\");\n\n return join(\"(isolate)\", strippedPath);\n}\n","import { inspect } from \"node:util\";\n\nexport function inspectValue(value: unknown) {\n return inspect(value, false, 16, true);\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Detect if this is a Rush monorepo. They use a very different structure so\n * there are multiple places where we need to make exceptions based on this.\n */\nexport function isRushWorkspace(workspaceRootDir: string) {\n return fs.existsSync(path.join(workspaceRootDir, \"rush.json\"));\n}\n","import fs from \"fs-extra\";\nimport stripJsonComments from \"strip-json-comments\";\nimport { getErrorMessage } from \"./get-error-message\";\n\n/** @todo Pass in zod schema and validate */\nexport function readTypedJsonSync<T>(filePath: string) {\n try {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const data = JSON.parse(\n stripJsonComments(rawContent, { trailingCommas: true })\n ) as T;\n return data;\n } catch (err) {\n throw new Error(\n `Failed to read JSON from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n\nexport async function readTypedJson<T>(filePath: string) {\n try {\n const rawContent = await fs.readFile(filePath, \"utf-8\");\n const data = JSON.parse(\n stripJsonComments(rawContent, { trailingCommas: true })\n ) as T;\n return data;\n } catch (err) {\n throw new Error(\n `Failed to read JSON from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n","import { exec } from \"node:child_process\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { useLogger } from \"../logger\";\nimport { shouldUsePnpmPack } from \"../package-manager\";\nimport { getErrorMessage } from \"./get-error-message\";\n\nexport async function pack(srcDir: string, dstDir: string) {\n const log = useLogger();\n\n const execOptions = {\n maxBuffer: 10 * 1024 * 1024,\n };\n\n const previousCwd = process.cwd();\n process.chdir(srcDir);\n\n /**\n * PNPM pack seems to be a lot faster than NPM pack, so when PNPM is detected\n * we use that instead.\n */\n const stdout = shouldUsePnpmPack()\n ? await new Promise<string>((resolve, reject) => {\n exec(\n `pnpm pack --pack-destination \"${dstDir}\"`,\n execOptions,\n (err, stdout) => {\n if (err) {\n log.error(getErrorMessage(err));\n return reject(err);\n }\n\n resolve(stdout);\n }\n );\n })\n : await new Promise<string>((resolve, reject) => {\n exec(\n `npm pack --pack-destination \"${dstDir}\"`,\n execOptions,\n (err, stdout) => {\n if (err) {\n return reject(err);\n }\n\n resolve(stdout);\n }\n );\n });\n\n const fileName = path.basename(stdout.trim());\n\n const filePath = path.join(dstDir, fileName);\n\n if (!fs.existsSync(filePath)) {\n log.error(\n `The response from pack could not be resolved to an existing file: ${filePath}`\n );\n } else {\n log.debug(`Packed (temp)/${fileName}`);\n }\n\n process.chdir(previousCwd);\n\n /**\n * Return the path anyway even if it doesn't validate. A later stage will wait\n * for the file to occur still. Not sure if this makes sense. Maybe we should\n * stop at the validation error...\n */\n return filePath;\n}\n","import path from \"node:path\";\nimport { isRushWorkspace } from \"../utils/is-rush-workspace\";\nimport { inferFromFiles, inferFromManifest } from \"./helpers\";\nimport type { PackageManager } from \"./names\";\n\nexport * from \"./names\";\n\nlet packageManager: PackageManager | undefined;\n\nexport function usePackageManager() {\n if (!packageManager) {\n throw Error(\n \"No package manager detected. Make sure to call detectPackageManager() before usePackageManager()\"\n );\n }\n\n return packageManager;\n}\n\n/**\n * First we check if the package manager is declared in the manifest. If it is,\n * we get the name and version from there. Otherwise we'll search for the\n * different lockfiles and ask the OS to report the installed version.\n */\nexport function detectPackageManager(workspaceRootDir: string): PackageManager {\n if (isRushWorkspace(workspaceRootDir)) {\n packageManager = inferFromFiles(\n path.join(workspaceRootDir, \"common/config/rush\")\n );\n } else {\n /**\n * Disable infer from manifest for now. I doubt it is useful after all but\n * I'll keep the code as a reminder.\n */\n packageManager =\n inferFromManifest(workspaceRootDir) ?? inferFromFiles(workspaceRootDir);\n }\n\n return packageManager;\n}\n\nexport function shouldUsePnpmPack() {\n const { name, majorVersion } = usePackageManager();\n\n return name === \"pnpm\" && majorVersion >= 8;\n}\n","import fs from \"fs-extra\";\nimport { execSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport { getErrorMessage } from \"~/lib/utils\";\nimport { getMajorVersion } from \"~/lib/utils/get-major-version\";\nimport type { PackageManager, PackageManagerName } from \"../names\";\nimport { getLockfileFileName, supportedPackageManagerNames } from \"../names\";\n\nexport function inferFromFiles(workspaceRoot: string): PackageManager {\n for (const name of supportedPackageManagerNames) {\n const lockfileName = getLockfileFileName(name);\n\n if (fs.existsSync(path.join(workspaceRoot, lockfileName))) {\n try {\n const version = getVersion(name);\n\n return { name, version, majorVersion: getMajorVersion(version) };\n } catch (err) {\n throw new Error(\n `Failed to find package manager version for ${name}: ${getErrorMessage(err)}`\n );\n }\n }\n }\n\n /** If no lockfile was found, it could be that there is an npm shrinkwrap file. */\n if (fs.existsSync(path.join(workspaceRoot, \"npm-shrinkwrap.json\"))) {\n const version = getVersion(\"npm\");\n\n return { name: \"npm\", version, majorVersion: getMajorVersion(version) };\n }\n\n throw new Error(`Failed to detect package manager`);\n}\n\nexport function getVersion(packageManagerName: PackageManagerName): string {\n const buffer = execSync(`${packageManagerName} --version`);\n return buffer.toString().trim();\n}\n","export function getMajorVersion(version: string) {\n return parseInt(version.split(\".\")[0], 10);\n}\n","export const supportedPackageManagerNames = [\n \"pnpm\",\n \"yarn\",\n \"npm\",\n \"bun\",\n] as const;\n\nexport type PackageManagerName = (typeof supportedPackageManagerNames)[number];\n\nexport type PackageManager = {\n name: PackageManagerName;\n version: string;\n majorVersion: number;\n packageManagerString?: string;\n};\n\nexport function getLockfileFileName(name: PackageManagerName) {\n switch (name) {\n case \"bun\":\n return \"bun.lockb\";\n case \"pnpm\":\n return \"pnpm-lock.yaml\";\n case \"yarn\":\n return \"yarn.lock\";\n case \"npm\":\n return \"package-lock.json\";\n }\n}\n","import fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport { useLogger } from \"~/lib/logger\";\nimport { getMajorVersion } from \"~/lib/utils/get-major-version\";\nimport type { PackageManifest } from \"../../types\";\nimport { readTypedJsonSync } from \"../../utils\";\nimport type { PackageManagerName } from \"../names\";\nimport { getLockfileFileName, supportedPackageManagerNames } from \"../names\";\n\nexport function inferFromManifest(workspaceRoot: string) {\n const log = useLogger();\n\n const { packageManager: packageManagerString } =\n readTypedJsonSync<PackageManifest>(\n path.join(workspaceRoot, \"package.json\")\n );\n\n if (!packageManagerString) {\n log.debug(\"No packageManager field found in root manifest\");\n return;\n }\n\n const [name, version = \"*\"] = packageManagerString.split(\"@\") as [\n PackageManagerName,\n string,\n ];\n\n assert(\n supportedPackageManagerNames.includes(name),\n `Package manager \"${name}\" is not currently supported`\n );\n\n const lockfileName = getLockfileFileName(name);\n\n assert(\n fs.existsSync(path.join(workspaceRoot, lockfileName)),\n `Manifest declares ${name} to be the packageManager, but failed to find ${lockfileName} in workspace root`\n );\n\n return {\n name,\n version,\n majorVersion: getMajorVersion(version),\n packageManagerString,\n };\n}\n","import fs from \"fs-extra\";\nimport tar from \"tar-fs\";\nimport { createGunzip } from \"zlib\";\n\nexport async function unpack(filePath: string, unpackDir: string) {\n await new Promise<void>((resolve, reject) => {\n fs.createReadStream(filePath)\n .pipe(createGunzip())\n .pipe(tar.extract(unpackDir))\n .on(\"finish\", () => resolve())\n .on(\"error\", (err) => reject(err));\n });\n}\n","import fs from \"fs-extra\";\nimport yaml from \"yaml\";\nimport { getErrorMessage } from \"./get-error-message\";\n\nexport function readTypedYamlSync<T>(filePath: string) {\n try {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const data = yaml.parse(rawContent);\n /** @todo Add some zod validation maybe */\n return data as T;\n } catch (err) {\n throw new Error(\n `Failed to read YAML from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n\nexport function writeTypedYamlSync<T>(filePath: string, content: T) {\n /** @todo Add some zod validation maybe */\n fs.writeFileSync(filePath, yaml.stringify(content), \"utf-8\");\n}\n","import Arborist from \"@npmcli/arborist\";\nimport fs from \"fs-extra\";\nimport path from \"node:path\";\nimport { useLogger } from \"~/lib/logger\";\nimport { getErrorMessage } from \"~/lib/utils\";\n\n/**\n * Generate an isolated / pruned lockfile, based on the contents of installed\n * node_modules from the monorepo root plus the adapted package manifest in the\n * isolate directory.\n */\nexport async function generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n}: {\n workspaceRootDir: string;\n isolateDir: string;\n}) {\n const log = useLogger();\n\n log.debug(\"Generating NPM lockfile...\");\n\n const nodeModulesPath = path.join(workspaceRootDir, \"node_modules\");\n\n try {\n if (!fs.existsSync(nodeModulesPath)) {\n throw new Error(`Failed to find node_modules at ${nodeModulesPath}`);\n }\n\n const arborist = new Arborist({ path: isolateDir });\n\n const { meta } = await arborist.buildIdealTree();\n\n meta?.commit();\n\n const lockfilePath = path.join(isolateDir, \"package-lock.json\");\n\n await fs.writeFile(lockfilePath, String(meta));\n\n log.debug(\"Created lockfile at\", lockfilePath);\n } catch (err) {\n log.error(`Failed to generate lockfile: ${getErrorMessage(err)}`);\n throw err;\n }\n}\n","import assert from \"node:assert\";\nimport path from \"node:path\";\nimport {\n getLockfileImporterId as getLockfileImporterId_v8,\n readWantedLockfile as readWantedLockfile_v8,\n writeWantedLockfile as writeWantedLockfile_v8,\n} from \"pnpm_lockfile_file_v8\";\nimport {\n getLockfileImporterId as getLockfileImporterId_v9,\n readWantedLockfile as readWantedLockfile_v9,\n writeWantedLockfile as writeWantedLockfile_v9,\n} from \"pnpm_lockfile_file_v9\";\nimport { pruneLockfile as pruneLockfile_v8 } from \"pnpm_prune_lockfile_v8\";\nimport { pruneLockfile as pruneLockfile_v9 } from \"pnpm_prune_lockfile_v9\";\nimport { pick } from \"remeda\";\nimport { useConfig } from \"~/lib/config\";\nimport { useLogger } from \"~/lib/logger\";\nimport type { PackageManifest, PackagesRegistry } from \"~/lib/types\";\nimport { getErrorMessage, isRushWorkspace } from \"~/lib/utils\";\nimport { pnpmMapImporter } from \"./pnpm-map-importer\";\n\nexport async function generatePnpmLockfile({\n workspaceRootDir,\n targetPackageDir,\n isolateDir,\n internalDepPackageNames,\n packagesRegistry,\n targetPackageManifest,\n majorVersion,\n}: {\n workspaceRootDir: string;\n targetPackageDir: string;\n isolateDir: string;\n internalDepPackageNames: string[];\n packagesRegistry: PackagesRegistry;\n targetPackageManifest: PackageManifest;\n majorVersion: number;\n}) {\n /**\n * For now we will assume that the lockfile format might not change in the\n * versions after 9, because we might get lucky. If it does change, things\n * would break either way.\n */\n const useReadVersion9 = majorVersion >= 9;\n\n const { includeDevDependencies, includePatchedDependencies } = useConfig();\n const log = useLogger();\n\n log.debug(\"Generating PNPM lockfile...\");\n\n try {\n const isRush = isRushWorkspace(workspaceRootDir);\n\n const lockfile = useReadVersion9\n ? await readWantedLockfile_v9(\n isRush\n ? path.join(workspaceRootDir, \"common/config/rush\")\n : workspaceRootDir,\n {\n ignoreIncompatible: false,\n }\n )\n : await readWantedLockfile_v8(\n isRush\n ? path.join(workspaceRootDir, \"common/config/rush\")\n : workspaceRootDir,\n {\n ignoreIncompatible: false,\n }\n );\n\n assert(lockfile, `No input lockfile found at ${workspaceRootDir}`);\n\n const [lockfileMajorVersion] = String(lockfile.lockfileVersion).split(\".\");\n\n const useLockfileVersion9 = lockfileMajorVersion >= \"9\";\n\n const targetImporterId = useLockfileVersion9\n ? getLockfileImporterId_v9(workspaceRootDir, targetPackageDir)\n : getLockfileImporterId_v8(workspaceRootDir, targetPackageDir);\n\n const directoryByPackageName = Object.fromEntries(\n internalDepPackageNames.map((name) => {\n const pkg = packagesRegistry[name];\n assert(pkg, `Package ${name} not found in packages registry`);\n\n return [name, pkg.rootRelativeDir];\n })\n );\n\n const relevantImporterIds = [\n targetImporterId,\n /**\n * The directory paths happen to correspond with what PNPM calls the\n * importer ids in the context of a lockfile.\n */\n ...Object.values(directoryByPackageName),\n ];\n\n log.debug(\"Relevant importer ids:\", relevantImporterIds);\n\n /**\n * In a Rush workspace the original lockfile is not in the root, so the\n * importerIds have to be prefixed with `../../`, but that's not how they\n * should be stored in the isolated lockfile, so we use the prefixed ids\n * only for parsing.\n */\n const relevantImporterIdsWithPrefix = relevantImporterIds.map((x) =>\n isRush ? `../../${x}` : x\n );\n\n lockfile.importers = Object.fromEntries(\n Object.entries(\n pick(lockfile.importers, relevantImporterIdsWithPrefix)\n ).map(([prefixedImporterId, importer]) => {\n const importerId = isRush\n ? prefixedImporterId.replace(\"../../\", \"\")\n : prefixedImporterId;\n\n if (importerId === targetImporterId) {\n log.debug(\"Setting target package importer on root\");\n\n return [\n \".\",\n pnpmMapImporter(\".\", importer, {\n includeDevDependencies,\n includePatchedDependencies,\n directoryByPackageName,\n }),\n ];\n }\n\n log.debug(\"Setting internal package importer:\", importerId);\n\n return [\n importerId,\n pnpmMapImporter(importerId, importer, {\n includeDevDependencies,\n includePatchedDependencies,\n directoryByPackageName,\n }),\n ];\n })\n );\n\n log.debug(\"Pruning the lockfile\");\n\n const prunedLockfile = useLockfileVersion9\n ? await pruneLockfile_v9(lockfile, targetPackageManifest, \".\")\n : await pruneLockfile_v8(lockfile, targetPackageManifest, \".\");\n\n /** Pruning seems to remove the overrides from the lockfile */\n if (lockfile.overrides) {\n prunedLockfile.overrides = lockfile.overrides;\n }\n\n /**\n * Don't know how to map the patched dependencies yet, so we just include\n * them but I don't think it would work like this. The important thing for\n * now is that they are omitted by default, because that is the most common\n * use case.\n */\n const patchedDependencies = includePatchedDependencies\n ? lockfile.patchedDependencies\n : undefined;\n\n useLockfileVersion9\n ? await writeWantedLockfile_v9(isolateDir, {\n ...prunedLockfile,\n patchedDependencies,\n })\n : await writeWantedLockfile_v8(isolateDir, {\n ...prunedLockfile,\n patchedDependencies,\n });\n\n log.debug(\"Created lockfile at\", path.join(isolateDir, \"pnpm-lock.yaml\"));\n } catch (err) {\n log.error(`Failed to generate lockfile: ${getErrorMessage(err)}`);\n throw err;\n }\n}\n","import path from \"node:path\";\nimport type {\n ProjectSnapshot,\n ResolvedDependencies,\n} from \"pnpm_lockfile_file_v8\";\n\nimport { mapValues } from \"remeda\";\n\n/** Convert dependency links */\nexport function pnpmMapImporter(\n importerPath: string,\n { dependencies, devDependencies, ...rest }: ProjectSnapshot,\n {\n includeDevDependencies,\n directoryByPackageName,\n }: {\n includeDevDependencies: boolean;\n includePatchedDependencies: boolean;\n directoryByPackageName: { [packageName: string]: string };\n }\n): ProjectSnapshot {\n return {\n dependencies: dependencies\n ? pnpmMapDependenciesLinks(\n importerPath,\n dependencies,\n directoryByPackageName\n )\n : undefined,\n devDependencies:\n includeDevDependencies && devDependencies\n ? pnpmMapDependenciesLinks(\n importerPath,\n devDependencies,\n directoryByPackageName\n )\n : undefined,\n ...rest,\n };\n}\n\nfunction pnpmMapDependenciesLinks(\n importerPath: string,\n def: ResolvedDependencies,\n directoryByPackageName: { [packageName: string]: string }\n): ResolvedDependencies {\n return mapValues(def, (value, key) => {\n if (!value.startsWith(\"link:\")) {\n return value;\n }\n\n const relativePath = path.relative(\n importerPath,\n directoryByPackageName[key]\n );\n\n return relativePath.startsWith(\".\")\n ? `link:${relativePath}`\n : `link:./${relativePath}`;\n });\n}\n","import fs from \"fs-extra\";\nimport { execSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport { useLogger } from \"~/lib/logger\";\nimport { getErrorMessage, isRushWorkspace } from \"~/lib/utils\";\n\n/**\n * Generate an isolated / pruned lockfile, based on the existing lockfile from\n * the monorepo root plus the adapted package manifest in the isolate\n * directory.\n */\nexport async function generateYarnLockfile({\n workspaceRootDir,\n isolateDir,\n}: {\n workspaceRootDir: string;\n isolateDir: string;\n}) {\n const log = useLogger();\n\n log.debug(\"Generating Yarn lockfile...\");\n\n const origLockfilePath = isRushWorkspace(workspaceRootDir)\n ? path.join(workspaceRootDir, \"common/config/rush\", \"yarn.lock\")\n : path.join(workspaceRootDir, \"yarn.lock\");\n\n const newLockfilePath = path.join(isolateDir, \"yarn.lock\");\n\n if (!fs.existsSync(origLockfilePath)) {\n throw new Error(`Failed to find lockfile at ${origLockfilePath}`);\n }\n\n log.debug(`Copy original yarn.lock to the isolate output`);\n\n try {\n await fs.copyFile(origLockfilePath, newLockfilePath);\n\n /**\n * Running install with the original lockfile in the same directory will\n * generate a pruned version of the lockfile.\n */\n log.debug(`Running local install`);\n execSync(`yarn install --cwd ${isolateDir}`);\n\n log.debug(\"Generated lockfile at\", newLockfilePath);\n } catch (err) {\n log.error(`Failed to generate lockfile: ${getErrorMessage(err)}`);\n throw err;\n }\n}\n","import { useLogger } from \"../logger\";\nimport { usePackageManager } from \"../package-manager\";\nimport type { PackageManifest, PackagesRegistry } from \"../types\";\nimport {\n generateNpmLockfile,\n generatePnpmLockfile,\n generateYarnLockfile,\n} from \"./helpers\";\n\n/**\n * Adapt the lockfile and write it to the isolate directory. Because we keep the\n * structure of packages in the isolate directory the same as they were in the\n * monorepo, the lockfile is largely still correct. The only things that need to\n * be done is to remove the root dependencies and devDependencies, and rename\n * the path to the target package to act as the new root.\n */\nexport async function processLockfile({\n workspaceRootDir,\n packagesRegistry,\n isolateDir,\n internalDepPackageNames,\n targetPackageDir,\n targetPackageManifest,\n}: {\n workspaceRootDir: string;\n packagesRegistry: PackagesRegistry;\n isolateDir: string;\n internalDepPackageNames: string[];\n targetPackageDir: string;\n targetPackageName: string;\n targetPackageManifest: PackageManifest;\n}) {\n const log = useLogger();\n\n const { name, majorVersion } = usePackageManager();\n let usedFallbackToNpm = false;\n\n switch (name) {\n case \"npm\": {\n await generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n });\n\n break;\n }\n case \"yarn\": {\n if (majorVersion === 1) {\n await generateYarnLockfile({\n workspaceRootDir,\n isolateDir,\n });\n } else {\n log.warn(\n \"Detected modern version of Yarn. Using NPM lockfile fallback.\"\n );\n\n await generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n });\n\n usedFallbackToNpm = true;\n }\n\n break;\n }\n case \"pnpm\": {\n await generatePnpmLockfile({\n workspaceRootDir,\n targetPackageDir,\n isolateDir,\n internalDepPackageNames,\n packagesRegistry,\n targetPackageManifest,\n majorVersion,\n });\n break;\n }\n case \"bun\": {\n log.warn(\n `Ouput lockfiles for Bun are not yet supported. Using NPM for output`\n );\n await generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n });\n\n usedFallbackToNpm = true;\n break;\n }\n default:\n log.warn(`Unexpected package manager ${name}. Using NPM for output`);\n await generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n });\n\n usedFallbackToNpm = true;\n }\n\n return usedFallbackToNpm;\n}\n","import { omit, pick } from \"remeda\";\nimport { useConfig } from \"../config\";\nimport { usePackageManager } from \"../package-manager\";\nimport type { PackageManifest, PackagesRegistry } from \"../types\";\nimport { adaptManifestInternalDeps, adoptPnpmFieldsFromRoot } from \"./helpers\";\n\n/**\n * Adapt the output package manifest, so that:\n *\n * - Its internal dependencies point to the isolated ./packages/* directory.\n * - The devDependencies are possibly removed\n * - Scripts are picked or omitted and otherwise removed\n */\nexport async function adaptTargetPackageManifest({\n manifest,\n packagesRegistry,\n workspaceRootDir,\n}: {\n manifest: PackageManifest;\n packagesRegistry: PackagesRegistry;\n workspaceRootDir: string;\n}) {\n const packageManager = usePackageManager();\n const {\n includeDevDependencies,\n pickFromScripts,\n omitFromScripts,\n omitPackageManager,\n } = useConfig();\n\n /** Dev dependencies are omitted by default */\n const inputManifest = includeDevDependencies\n ? manifest\n : omit(manifest, [\"devDependencies\"]);\n\n const adaptedManifest =\n packageManager.name === \"pnpm\"\n ? /**\n * For PNPM the output itself is a workspace so we can preserve the specifiers\n * with \"workspace:*\" in the output manifest, but we do want to adopt the\n * pnpm.overrides field from the root package.json.\n */\n await adoptPnpmFieldsFromRoot(inputManifest, workspaceRootDir)\n : /** For other package managers we replace the links to internal dependencies */\n adaptManifestInternalDeps({\n manifest: inputManifest,\n packagesRegistry,\n });\n\n return {\n ...adaptedManifest,\n /**\n * Adopt the package manager definition from the root manifest if available.\n * The option to omit is there because some platforms might not handle it\n * properly (Cloud Run, April 24th 2024, does not handle pnpm v9)\n */\n packageManager: omitPackageManager\n ? undefined\n : packageManager.packageManagerString,\n /**\n * Scripts are removed by default if not explicitly picked or omitted via\n * config.\n */\n scripts: pickFromScripts\n ? pick(manifest.scripts ?? {}, pickFromScripts)\n : omitFromScripts\n ? omit(manifest.scripts ?? {}, omitFromScripts)\n : undefined,\n };\n}\n","import path from \"node:path\";\nimport { omit } from \"remeda\";\nimport { usePackageManager } from \"~/lib/package-manager\";\nimport type { PackagesRegistry } from \"~/lib/types\";\nimport { writeManifest } from \"../io\";\nimport { adaptManifestInternalDeps } from \"./adapt-manifest-internal-deps\";\n\n/**\n * Adapt the manifest files of all the isolated internal packages (excluding the\n * target package), so that their dependencies point to the other isolated\n * packages in the same folder.\n */\nexport async function adaptInternalPackageManifests(\n internalPackageNames: string[],\n packagesRegistry: PackagesRegistry,\n isolateDir: string\n) {\n const packageManager = usePackageManager();\n\n await Promise.all(\n internalPackageNames.map(async (packageName) => {\n const { manifest, rootRelativeDir } = packagesRegistry[packageName];\n\n /** Dev dependencies and scripts are never included for internal deps */\n const strippedManifest = omit(manifest, [\"scripts\", \"devDependencies\"]);\n\n const outputManifest =\n packageManager.name === \"pnpm\"\n ? /**\n * For PNPM the output itself is a workspace so we can preserve the specifiers\n * with \"workspace:*\" in the output manifest.\n */\n strippedManifest\n : /** For other package managers we replace the links to internal dependencies */\n adaptManifestInternalDeps({\n manifest: strippedManifest,\n packagesRegistry,\n parentRootRelativeDir: rootRelativeDir,\n });\n\n await writeManifest(\n path.join(isolateDir, rootRelativeDir),\n outputManifest\n );\n })\n );\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport type { PackageManifest } from \"../types\";\nimport { readTypedJson } from \"../utils\";\n\nexport async function readManifest(packageDir: string) {\n return readTypedJson<PackageManifest>(path.join(packageDir, \"package.json\"));\n}\n\nexport async function writeManifest(\n outputDir: string,\n manifest: PackageManifest\n) {\n await fs.writeFile(\n path.join(outputDir, \"package.json\"),\n JSON.stringify(manifest, null, 2)\n );\n}\n","import path from \"node:path\";\nimport { useLogger } from \"../../logger\";\nimport type { PackagesRegistry } from \"../../types\";\n\nexport function patchInternalEntries(\n dependencies: Record<string, string>,\n packagesRegistry: PackagesRegistry,\n parentRootRelativeDir?: string\n) {\n const log = useLogger();\n const allWorkspacePackageNames = Object.keys(packagesRegistry);\n\n return Object.fromEntries(\n Object.entries(dependencies).map(([key, value]) => {\n if (allWorkspacePackageNames.includes(key)) {\n const def = packagesRegistry[key];\n\n /**\n * When nested internal dependencies are used (internal packages linking\n * to other internal packages), the parentRootRelativeDir will be passed\n * in, and we store the relative path to the isolate/packages\n * directory.\n *\n * For consistency we also write the other file paths starting with ./,\n * but it doesn't seem to be necessary for any package manager.\n */\n const relativePath = parentRootRelativeDir\n ? path.relative(parentRootRelativeDir, `./${def.rootRelativeDir}`)\n : `./${def.rootRelativeDir}`;\n\n const linkPath = `file:${relativePath}`;\n\n log.debug(`Linking dependency ${key} to ${linkPath}`);\n\n return [key, linkPath];\n } else {\n return [key, value];\n }\n })\n );\n}\n","import type { PackageManifest, PackagesRegistry } from \"~/lib/types\";\nimport { patchInternalEntries } from \"./patch-internal-entries\";\n\n/**\n * Replace the workspace version specifiers for internal dependency with file:\n * paths. Not needed for PNPM (because we configure the isolated output as a\n * workspace), but maybe still for NPM and Yarn.\n */\nexport function adaptManifestInternalDeps({\n manifest,\n packagesRegistry,\n parentRootRelativeDir,\n}: {\n manifest: PackageManifest;\n packagesRegistry: PackagesRegistry;\n parentRootRelativeDir?: string;\n}): PackageManifest {\n const { dependencies, devDependencies } = manifest;\n\n return {\n ...manifest,\n dependencies: dependencies\n ? patchInternalEntries(\n dependencies,\n packagesRegistry,\n parentRootRelativeDir\n )\n : undefined,\n devDependencies: devDependencies\n ? patchInternalEntries(\n devDependencies,\n packagesRegistry,\n parentRootRelativeDir\n )\n : undefined,\n };\n}\n","import type { ProjectManifest } from \"@pnpm/types\";\nimport path from \"path\";\nimport type { PackageManifest } from \"~/lib/types\";\nimport { isRushWorkspace, readTypedJson } from \"~/lib/utils\";\n\n/**\n * Adopts the `pnpm` fields from the root package manifest. Currently it only\n * takes overrides, because I don't know if any of the others are useful or\n * desired.\n */\nexport async function adoptPnpmFieldsFromRoot(\n targetPackageManifest: PackageManifest,\n workspaceRootDir: string\n) {\n if (isRushWorkspace(workspaceRootDir)) {\n return targetPackageManifest;\n }\n\n const rootPackageManifest = await readTypedJson<ProjectManifest>(\n path.join(workspaceRootDir, \"package.json\")\n );\n\n const overrides = rootPackageManifest.pnpm?.overrides;\n\n if (!overrides) {\n return targetPackageManifest;\n }\n\n return {\n ...targetPackageManifest,\n pnpm: {\n overrides,\n },\n };\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport outdent from \"outdent\";\nimport { useConfig } from \"../config\";\nimport { useLogger } from \"../logger\";\nimport { readTypedJson } from \"../utils\";\n\nexport async function getBuildOutputDir(targetPackageDir: string) {\n const config = useConfig();\n const log = useLogger();\n\n if (config.buildDirName) {\n log.debug(\"Using buildDirName from config:\", config.buildDirName);\n return path.join(targetPackageDir, config.buildDirName);\n }\n\n const tsconfigPath = path.join(targetPackageDir, config.tsconfigPath);\n\n if (fs.existsSync(tsconfigPath)) {\n log.debug(\"Found tsconfig at:\", config.tsconfigPath);\n\n const tsconfig = await readTypedJson<{\n compilerOptions?: { outDir?: string };\n }>(tsconfigPath);\n\n const outDir = tsconfig.compilerOptions?.outDir;\n\n if (outDir) {\n return path.join(targetPackageDir, outDir);\n } else {\n throw new Error(outdent`\n Failed to find outDir in tsconfig. If you are executing isolate from the root of a monorepo you should specify the buildDirName in isolate.config.json.\n `);\n }\n } else {\n log.warn(\"Failed to find tsconfig at:\", tsconfigPath);\n\n throw new Error(outdent`\n Failed to infer the build output directory from either the isolate config buildDirName or a Typescript config file. See the documentation on how to configure one of these options.\n `);\n }\n}\n","import assert from \"node:assert\";\nimport { useLogger } from \"../logger\";\nimport type { PackagesRegistry } from \"../types\";\nimport { pack } from \"../utils\";\n\n/**\n * Pack dependencies so that we extract only the files that are supposed to be\n * published by the packages.\n *\n * @returns A map of package names to the path of the packed file\n */\nexport async function packDependencies({\n /** All packages found in the monorepo by workspaces declaration */\n packagesRegistry,\n /** The dependencies that appear to be internal packages */\n internalPackageNames,\n /**\n * The directory where the isolated package and all its dependencies will end\n * up. This is also the directory from where the package will be deployed. By\n * default it is a subfolder in targetPackageDir called \"isolate\" but you can\n * configure it.\n */\n packDestinationDir,\n}: {\n packagesRegistry: PackagesRegistry;\n internalPackageNames: string[];\n packDestinationDir: string;\n}) {\n const log = useLogger();\n\n const packedFileByName: Record<string, string> = {};\n\n for (const dependency of internalPackageNames) {\n const def = packagesRegistry[dependency];\n\n assert(dependency, `Failed to find package definition for ${dependency}`);\n\n const { name } = def.manifest;\n\n /**\n * If this dependency has already been packed, we skip it. It could happen\n * because we are packing workspace dependencies recursively.\n */\n if (packedFileByName[name]) {\n log.debug(`Skipping ${name} because it has already been packed`);\n continue;\n }\n\n packedFileByName[name] = await pack(def.absoluteDir, packDestinationDir);\n }\n\n return packedFileByName;\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport { useLogger } from \"../logger\";\nimport { pack, unpack } from \"../utils\";\n\nconst TIMEOUT_MS = 5000;\n\nexport async function processBuildOutputFiles({\n targetPackageDir,\n tmpDir,\n isolateDir,\n}: {\n targetPackageDir: string;\n tmpDir: string;\n isolateDir: string;\n}) {\n const log = useLogger();\n\n const packedFilePath = await pack(targetPackageDir, tmpDir);\n const unpackDir = path.join(tmpDir, \"target\");\n\n const now = Date.now();\n let isWaitingYet = false;\n\n while (!fs.existsSync(packedFilePath) && Date.now() - now < TIMEOUT_MS) {\n if (!isWaitingYet) {\n log.debug(`Waiting for ${packedFilePath} to become available...`);\n }\n isWaitingYet = true;\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n\n await unpack(packedFilePath, unpackDir);\n await fs.copy(path.join(unpackDir, \"package\"), isolateDir);\n}\n","import fs from \"fs-extra\";\nimport path, { join } from \"node:path\";\nimport { useLogger } from \"../logger\";\nimport type { PackagesRegistry } from \"../types\";\nimport { getIsolateRelativePath, unpack } from \"../utils\";\n\nexport async function unpackDependencies(\n packedFilesByName: Record<string, string>,\n packagesRegistry: PackagesRegistry,\n tmpDir: string,\n isolateDir: string\n) {\n const log = useLogger();\n\n await Promise.all(\n Object.entries(packedFilesByName).map(async ([packageName, filePath]) => {\n const dir = packagesRegistry[packageName].rootRelativeDir;\n const unpackDir = join(tmpDir, dir);\n\n log.debug(\"Unpacking\", `(temp)/${path.basename(filePath)}`);\n\n await unpack(filePath, unpackDir);\n\n const destinationDir = join(isolateDir, dir);\n\n await fs.ensureDir(destinationDir);\n\n await fs.move(join(unpackDir, \"package\"), destinationDir, {\n overwrite: true,\n });\n\n log.debug(\n `Moved package files to ${getIsolateRelativePath(\n destinationDir,\n isolateDir\n )}`\n );\n })\n );\n}\n","import fs from \"fs-extra\";\nimport { globSync } from \"glob\";\nimport path from \"node:path\";\nimport { useLogger } from \"../logger\";\nimport type { PackageManifest, PackagesRegistry } from \"../types\";\nimport { isRushWorkspace, readTypedJson, readTypedJsonSync } from \"../utils\";\nimport { findPackagesGlobs } from \"./helpers\";\n\n/**\n * Build a list of all packages in the workspace, depending on the package\n * manager used, with a possible override from the config file. The list\n * contains the manifest with some directory info mapped by module name.\n */\nexport async function createPackagesRegistry(\n workspaceRootDir: string,\n workspacePackagesOverride: string[] | undefined\n): Promise<PackagesRegistry> {\n const log = useLogger();\n\n if (workspacePackagesOverride) {\n log.debug(\n `Override workspace packages via config: ${workspacePackagesOverride}`\n );\n }\n\n const allPackages = listWorkspacePackages(\n workspacePackagesOverride,\n workspaceRootDir\n );\n\n const registry: PackagesRegistry = (\n await Promise.all(\n allPackages.map(async (rootRelativeDir) => {\n const absoluteDir = path.join(workspaceRootDir, rootRelativeDir);\n const manifestPath = path.join(absoluteDir, \"package.json\");\n\n if (!fs.existsSync(manifestPath)) {\n log.warn(\n `Ignoring directory ${rootRelativeDir} because it does not contain a package.json file`\n );\n return;\n } else {\n log.debug(`Registering package ${rootRelativeDir}`);\n\n const manifest = await readTypedJson<PackageManifest>(\n path.join(absoluteDir, \"package.json\")\n );\n\n return {\n manifest,\n rootRelativeDir,\n absoluteDir,\n };\n }\n })\n )\n ).reduce<PackagesRegistry>((acc, info) => {\n if (info) {\n acc[info.manifest.name] = info;\n }\n return acc;\n }, {});\n\n return registry;\n}\n\ntype RushConfig = {\n projects: { packageName: string; projectFolder: string }[];\n};\n\nfunction listWorkspacePackages(\n workspacePackagesOverride: string[] | undefined,\n workspaceRootDir: string\n) {\n if (isRushWorkspace(workspaceRootDir)) {\n const rushConfig = readTypedJsonSync<RushConfig>(\n path.join(workspaceRootDir, \"rush.json\")\n );\n\n return rushConfig.projects.map(({ projectFolder }) => projectFolder);\n } else {\n const currentDir = process.cwd();\n process.chdir(workspaceRootDir);\n\n const packagesGlobs =\n workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);\n\n const allPackages = packagesGlobs\n .flatMap((glob) => globSync(glob))\n /** Make sure to filter any loose files that might hang around. */\n .filter((dir) => fs.lstatSync(dir).isDirectory());\n\n process.chdir(currentDir);\n return allPackages;\n }\n}\n","import assert from \"node:assert\";\nimport path from \"node:path\";\nimport { useLogger } from \"../../logger\";\nimport { usePackageManager } from \"../../package-manager\";\nimport {\n inspectValue,\n readTypedJsonSync,\n readTypedYamlSync,\n} from \"../../utils\";\n\n/**\n * Find the globs that define where the packages are located within the\n * monorepo. This configuration is dependent on the package manager used, and I\n * don't know if we're covering all cases yet...\n */\nexport function findPackagesGlobs(workspaceRootDir: string) {\n const log = useLogger();\n\n const packageManager = usePackageManager();\n\n switch (packageManager.name) {\n case \"pnpm\": {\n const { packages: globs } = readTypedYamlSync<{ packages: string[] }>(\n path.join(workspaceRootDir, \"pnpm-workspace.yaml\")\n );\n\n log.debug(\"Detected pnpm packages globs:\", inspectValue(globs));\n return globs;\n }\n case \"bun\":\n case \"yarn\":\n case \"npm\": {\n const workspaceRootManifestPath = path.join(\n workspaceRootDir,\n \"package.json\"\n );\n\n const { workspaces } = readTypedJsonSync<{ workspaces: string[] }>(\n workspaceRootManifestPath\n );\n\n if (!workspaces) {\n throw new Error(\n `No workspaces field found in ${workspaceRootManifestPath}`\n );\n }\n\n if (Array.isArray(workspaces)) {\n return workspaces;\n } else {\n /**\n * For Yarn, workspaces could be defined as an object with { packages:\n * [], nohoist: [] }. See\n * https://classic.yarnpkg.com/blog/2018/02/15/nohoist/\n */\n const workspacesObject = workspaces as { packages?: string[] };\n\n assert(\n workspacesObject.packages,\n \"workspaces.packages must be an array\"\n );\n\n return workspacesObject.packages;\n }\n }\n }\n}\n","import { unique } from \"remeda\";\nimport type { PackageManifest, PackagesRegistry } from \"../types\";\n\n/**\n * Recursively list all the packages from dependencies (and optionally\n * devDependencies) that are found in the monorepo.\n *\n * Here we do not need to rely on packages being declared with \"workspace:\" in\n * the package manifest. We can simply compare the package names with the list\n * of packages that were found via the workspace glob patterns and add them to\n * the registry.\n */\nexport function listInternalPackages(\n manifest: PackageManifest,\n packagesRegistry: PackagesRegistry,\n { includeDevDependencies = false } = {}\n): string[] {\n const allWorkspacePackageNames = Object.keys(packagesRegistry);\n\n const internalPackageNames = (\n includeDevDependencies\n ? [\n ...Object.keys(manifest.dependencies ?? {}),\n ...Object.keys(manifest.devDependencies ?? {}),\n ]\n : Object.keys(manifest.dependencies ?? {})\n ).filter((name) => allWorkspacePackageNames.includes(name));\n\n const nestedInternalPackageNames = internalPackageNames.flatMap(\n (packageName) =>\n listInternalPackages(\n packagesRegistry[packageName].manifest,\n packagesRegistry,\n { includeDevDependencies }\n )\n );\n\n return unique(internalPackageNames.concat(nestedInternalPackageNames));\n}\n"],"mappings":";AAAA,OAAOA,UAAQ;AACf,OAAOC,aAAY;AACnB,OAAOC,YAAU;AACjB,SAAS,UAAAC,eAAc;;;ACHvB,OAAOC,SAAQ;AACf,OAAOC,aAAY;AACnB,OAAOC,WAAU;AACjB,SAAS,eAAe;;;ACHxB,OAAO,WAAW;AAelB,IAAI,kBAA0B;AAAA,EAC5B,SAAS,MAAiB;AACxB,YAAQ,IAAI,MAAM,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC1C;AAAA,EACA,QAAQ,MAAiB;AACvB,YAAQ,IAAI,MAAM,MAAM,MAAM,GAAG,GAAG,IAAI;AAAA,EAC1C;AAAA,EACA,QAAQ,MAAiB;AACvB,YAAQ,IAAI,MAAM,OAAO,SAAS,GAAG,GAAG,IAAI;AAAA,EAC9C;AAAA,EACA,SAAS,MAAiB;AACxB,YAAQ,IAAI,MAAM,IAAI,OAAO,GAAG,GAAG,IAAI;AAAA,EACzC;AACF;AAEA,IAAM,UAAkB;AAAA,EACtB,SAAS,MAAiB;AACxB,QAAI,cAAc,SAAS;AACzB,sBAAgB,MAAM,GAAG,IAAI;AAAA,IAC/B;A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","unique","fs","assert","path","path","fs","fs","fs","path","path","fs","path","fs","path","fs","path","path","fs","path","stdout","path","fs","fs","fs","fs","path","fs","fs","path","path","fs","assert","path","path","path","assert","fs","execSync","path","path","fs","execSync","omit","pick","path","fs","path","path","fs","path","path","packageManager","path","path","path","packageManager","omit","pick","fs","path","path","fs","assert","assert","fs","path","path","fs","fs","path","join","join","path","fs","fs","path","assert","path","packageManager","path","assert","path","fs","path","assert","fs","packageManager","unique"]}
@@ -8,7 +8,7 @@ import sourceMaps from "source-map-support";
8
8
  import fs16 from "fs-extra";
9
9
  import assert6 from "node:assert";
10
10
  import path20 from "node:path";
11
- import { unique } from "remeda";
11
+ import { unique as unique2 } from "remeda";
12
12
 
13
13
  // src/lib/config.ts
14
14
  import fs8 from "fs-extra";
@@ -79,8 +79,7 @@ function isErrorWithMessage(error) {
79
79
  return typeof error === "object" && error !== null && "message" in error;
80
80
  }
81
81
  function toErrorWithMessage(maybeError) {
82
- if (isErrorWithMessage(maybeError))
83
- return maybeError;
82
+ if (isErrorWithMessage(maybeError)) return maybeError;
84
83
  try {
85
84
  return new Error(JSON.stringify(maybeError));
86
85
  } catch {
@@ -161,9 +160,16 @@ function getMajorVersion(version) {
161
160
  }
162
161
 
163
162
  // src/lib/package-manager/names.ts
164
- var supportedPackageManagerNames = ["pnpm", "yarn", "npm"];
163
+ var supportedPackageManagerNames = [
164
+ "pnpm",
165
+ "yarn",
166
+ "npm",
167
+ "bun"
168
+ ];
165
169
  function getLockfileFileName(name) {
166
170
  switch (name) {
171
+ case "bun":
172
+ return "bun.lockb";
167
173
  case "pnpm":
168
174
  return "pnpm-lock.yaml";
169
175
  case "yarn":
@@ -478,13 +484,13 @@ async function generatePnpmLockfile({
478
484
  targetPackageManifest,
479
485
  majorVersion
480
486
  }) {
481
- const useVersion9 = majorVersion >= 9;
487
+ const useReadVersion9 = majorVersion >= 9;
482
488
  const { includeDevDependencies, includePatchedDependencies } = useConfig();
483
489
  const log = useLogger();
484
490
  log.debug("Generating PNPM lockfile...");
485
491
  try {
486
492
  const isRush = isRushWorkspace(workspaceRootDir);
487
- const lockfile = useVersion9 ? await readWantedLockfile_v9(
493
+ const lockfile = useReadVersion9 ? await readWantedLockfile_v9(
488
494
  isRush ? path9.join(workspaceRootDir, "common/config/rush") : workspaceRootDir,
489
495
  {
490
496
  ignoreIncompatible: false
@@ -496,7 +502,9 @@ async function generatePnpmLockfile({
496
502
  }
497
503
  );
498
504
  assert3(lockfile, `No input lockfile found at ${workspaceRootDir}`);
499
- const targetImporterId = useVersion9 ? getLockfileImporterId_v9(workspaceRootDir, targetPackageDir) : getLockfileImporterId_v8(workspaceRootDir, targetPackageDir);
505
+ const [lockfileMajorVersion] = String(lockfile.lockfileVersion).split(".");
506
+ const useLockfileVersion9 = lockfileMajorVersion >= "9";
507
+ const targetImporterId = useLockfileVersion9 ? getLockfileImporterId_v9(workspaceRootDir, targetPackageDir) : getLockfileImporterId_v8(workspaceRootDir, targetPackageDir);
500
508
  const directoryByPackageName = Object.fromEntries(
501
509
  internalDepPackageNames.map((name) => {
502
510
  const pkg = packagesRegistry[name];
@@ -544,12 +552,12 @@ async function generatePnpmLockfile({
544
552
  })
545
553
  );
546
554
  log.debug("Pruning the lockfile");
547
- const prunedLockfile = useVersion9 ? await pruneLockfile_v9(lockfile, targetPackageManifest, ".") : await pruneLockfile_v8(lockfile, targetPackageManifest, ".");
555
+ const prunedLockfile = useLockfileVersion9 ? await pruneLockfile_v9(lockfile, targetPackageManifest, ".") : await pruneLockfile_v8(lockfile, targetPackageManifest, ".");
548
556
  if (lockfile.overrides) {
549
557
  prunedLockfile.overrides = lockfile.overrides;
550
558
  }
551
559
  const patchedDependencies = includePatchedDependencies ? lockfile.patchedDependencies : void 0;
552
- useVersion9 ? await writeWantedLockfile_v9(isolateDir, {
560
+ useLockfileVersion9 ? await writeWantedLockfile_v9(isolateDir, {
553
561
  ...prunedLockfile,
554
562
  patchedDependencies
555
563
  }) : await writeWantedLockfile_v8(isolateDir, {
@@ -640,6 +648,17 @@ async function processLockfile({
640
648
  });
641
649
  break;
642
650
  }
651
+ case "bun": {
652
+ log.warn(
653
+ `Ouput lockfiles for Bun are not yet supported. Using NPM for output`
654
+ );
655
+ await generateNpmLockfile({
656
+ workspaceRootDir,
657
+ isolateDir
658
+ });
659
+ usedFallbackToNpm = true;
660
+ break;
661
+ }
643
662
  default:
644
663
  log.warn(`Unexpected package manager ${name}. Using NPM for output`);
645
664
  await generateNpmLockfile({
@@ -938,6 +957,7 @@ function findPackagesGlobs(workspaceRootDir) {
938
957
  log.debug("Detected pnpm packages globs:", inspectValue(globs));
939
958
  return globs;
940
959
  }
960
+ case "bun":
941
961
  case "yarn":
942
962
  case "npm": {
943
963
  const workspaceRootManifestPath = path18.join(
@@ -1024,7 +1044,7 @@ function listWorkspacePackages(workspacePackagesOverride, workspaceRootDir) {
1024
1044
  }
1025
1045
 
1026
1046
  // src/lib/registry/list-internal-packages.ts
1027
- import { uniq } from "remeda";
1047
+ import { unique } from "remeda";
1028
1048
  function listInternalPackages(manifest, packagesRegistry, { includeDevDependencies = false } = {}) {
1029
1049
  const allWorkspacePackageNames = Object.keys(packagesRegistry);
1030
1050
  const internalPackageNames = (includeDevDependencies ? [
@@ -1038,7 +1058,7 @@ function listInternalPackages(manifest, packagesRegistry, { includeDevDependenci
1038
1058
  { includeDevDependencies }
1039
1059
  )
1040
1060
  );
1041
- return uniq(internalPackageNames.concat(nestedInternalPackageNames));
1061
+ return unique(internalPackageNames.concat(nestedInternalPackageNames));
1042
1062
  }
1043
1063
 
1044
1064
  // src/isolate.ts
@@ -1148,7 +1168,7 @@ async function isolate(options = {}) {
1148
1168
  }
1149
1169
  if (packageManager2.name === "pnpm") {
1150
1170
  if (isRushWorkspace(workspaceRootDir)) {
1151
- const packagesFolderNames = unique(
1171
+ const packagesFolderNames = unique2(
1152
1172
  internalPackageNames.map(
1153
1173
  (name) => path20.parse(packagesRegistry[name].rootRelativeDir).dir
1154
1174
  )
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/isolate-bin.ts","../src/isolate.ts","../src/lib/config.ts","../src/lib/logger.ts","../src/lib/utils/get-dirname.ts","../src/lib/utils/get-error-message.ts","../src/lib/utils/get-relative-path.ts","../src/lib/utils/inspect-value.ts","../src/lib/utils/is-rush-workspace.ts","../src/lib/utils/json.ts","../src/lib/utils/pack.ts","../src/lib/package-manager/index.ts","../src/lib/package-manager/helpers/infer-from-files.ts","../src/lib/utils/get-major-version.ts","../src/lib/package-manager/names.ts","../src/lib/package-manager/helpers/infer-from-manifest.ts","../src/lib/utils/unpack.ts","../src/lib/utils/yaml.ts","../src/lib/lockfile/helpers/generate-npm-lockfile.ts","../src/lib/lockfile/helpers/generate-pnpm-lockfile.ts","../src/lib/lockfile/helpers/pnpm-map-importer.ts","../src/lib/lockfile/helpers/generate-yarn-lockfile.ts","../src/lib/lockfile/process-lockfile.ts","../src/lib/manifest/adapt-target-package-manifest.ts","../src/lib/manifest/helpers/adapt-internal-package-manifests.ts","../src/lib/manifest/io.ts","../src/lib/manifest/helpers/patch-internal-entries.ts","../src/lib/manifest/helpers/adapt-manifest-internal-deps.ts","../src/lib/manifest/helpers/adopt-pnpm-fields-from-root.ts","../src/lib/output/get-build-output-dir.ts","../src/lib/output/pack-dependencies.ts","../src/lib/output/process-build-output-files.ts","../src/lib/output/unpack-dependencies.ts","../src/lib/registry/create-packages-registry.ts","../src/lib/registry/helpers/find-packages-globs.ts","../src/lib/registry/list-internal-packages.ts"],"sourcesContent":["#!/usr/bin/env node\nimport console from \"node:console\";\nimport sourceMaps from \"source-map-support\";\nimport { isolate } from \"./isolate\";\n\nsourceMaps.install();\n\nasync function run() {\n await isolate();\n}\n\nrun().catch((err) => {\n if (err instanceof Error) {\n console.error(err.stack);\n process.exit(1);\n } else {\n console.error(err);\n }\n});\n","import fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport { unique } from \"remeda\";\nimport type { IsolateConfig } from \"./lib/config\";\nimport { resolveConfig, setUserConfig } from \"./lib/config\";\nimport { processLockfile } from \"./lib/lockfile\";\nimport type { Logger } from \"./lib/logger\";\nimport { setLogLevel, setLogger, useLogger } from \"./lib/logger\";\nimport {\n adaptInternalPackageManifests,\n adaptTargetPackageManifest,\n readManifest,\n writeManifest,\n} from \"./lib/manifest\";\nimport {\n getBuildOutputDir,\n packDependencies,\n processBuildOutputFiles,\n unpackDependencies,\n} from \"./lib/output\";\nimport { detectPackageManager, shouldUsePnpmPack } from \"./lib/package-manager\";\nimport { getVersion } from \"./lib/package-manager/helpers/infer-from-files\";\nimport { createPackagesRegistry, listInternalPackages } from \"./lib/registry\";\nimport type { PackageManifest } from \"./lib/types\";\nimport {\n getDirname,\n getRootRelativePath,\n isRushWorkspace,\n readTypedJson,\n writeTypedYamlSync,\n} from \"./lib/utils\";\n\nconst __dirname = getDirname(import.meta.url);\n\nexport async function isolate(\n options: { config?: IsolateConfig; logger?: Logger } = {}\n) {\n if (options.logger) {\n setLogger(options.logger);\n }\n\n if (options.config) {\n setUserConfig(options.config);\n }\n\n const config = resolveConfig();\n\n setLogLevel(config.logLevel);\n\n const log = useLogger();\n\n const { version: libraryVersion } = await readTypedJson<PackageManifest>(\n path.join(path.join(__dirname, \"..\", \"package.json\"))\n );\n\n log.info(\"Using isolate-package version\", libraryVersion);\n\n /**\n * If a targetPackagePath is set, we assume the configuration lives in the\n * root of the workspace. If targetPackagePath is undefined (the default), we\n * assume that the configuration lives in the target package directory.\n */\n const targetPackageDir = config.targetPackagePath\n ? path.join(process.cwd(), config.targetPackagePath)\n : process.cwd();\n\n const workspaceRootDir = config.targetPackagePath\n ? process.cwd()\n : path.join(targetPackageDir, config.workspaceRoot);\n\n const buildOutputDir = await getBuildOutputDir(targetPackageDir);\n\n assert(\n fs.existsSync(buildOutputDir),\n `Failed to find build output path at ${buildOutputDir}. Please make sure you build the source before isolating it.`\n );\n\n log.debug(\"Workspace root resolved to\", workspaceRootDir);\n log.debug(\n \"Isolate target package\",\n getRootRelativePath(targetPackageDir, workspaceRootDir)\n );\n\n const isolateDir = path.join(targetPackageDir, config.isolateDirName);\n\n log.debug(\n \"Isolate output directory\",\n getRootRelativePath(isolateDir, workspaceRootDir)\n );\n\n if (fs.existsSync(isolateDir)) {\n await fs.remove(isolateDir);\n log.debug(\"Cleaned the existing isolate output directory\");\n }\n\n await fs.ensureDir(isolateDir);\n\n const tmpDir = path.join(isolateDir, \"__tmp\");\n await fs.ensureDir(tmpDir);\n\n const targetPackageManifest = await readTypedJson<PackageManifest>(\n path.join(targetPackageDir, \"package.json\")\n );\n\n const packageManager = detectPackageManager(workspaceRootDir);\n\n log.debug(\n \"Detected package manager\",\n packageManager.name,\n packageManager.version\n );\n\n if (shouldUsePnpmPack()) {\n log.debug(\"Use PNPM pack instead of NPM pack\");\n }\n\n /**\n * Build a packages registry so we can find the workspace packages by name and\n * have access to their manifest files and relative paths.\n */\n const packagesRegistry = await createPackagesRegistry(\n workspaceRootDir,\n config.workspacePackages\n );\n\n const internalPackageNames = listInternalPackages(\n targetPackageManifest,\n packagesRegistry,\n {\n includeDevDependencies: config.includeDevDependencies,\n }\n );\n\n const packedFilesByName = await packDependencies({\n internalPackageNames,\n packagesRegistry,\n packDestinationDir: tmpDir,\n });\n\n await unpackDependencies(\n packedFilesByName,\n packagesRegistry,\n tmpDir,\n isolateDir\n );\n\n /** Adapt the manifest files for all the unpacked local dependencies */\n await adaptInternalPackageManifests(\n internalPackageNames,\n packagesRegistry,\n isolateDir\n );\n\n /** Pack the target package directory, and unpack it in the isolate location */\n await processBuildOutputFiles({\n targetPackageDir,\n tmpDir,\n isolateDir,\n });\n\n /**\n * Copy the target manifest file to the isolate location and adapt its\n * workspace dependencies to point to the isolated packages.\n */\n const outputManifest = await adaptTargetPackageManifest({\n manifest: targetPackageManifest,\n packagesRegistry,\n workspaceRootDir,\n });\n\n await writeManifest(isolateDir, outputManifest);\n\n /** Generate an isolated lockfile based on the original one */\n const usedFallbackToNpm = await processLockfile({\n workspaceRootDir,\n isolateDir,\n packagesRegistry,\n internalDepPackageNames: internalPackageNames,\n targetPackageDir,\n targetPackageName: targetPackageManifest.name,\n targetPackageManifest: outputManifest,\n });\n\n if (usedFallbackToNpm) {\n /**\n * When we fall back to NPM, we set the manifest package manager to the\n * available NPM version.\n */\n const manifest = await readManifest(isolateDir);\n\n const npmVersion = getVersion(\"npm\");\n manifest.packageManager = `npm@${npmVersion}`;\n\n await writeManifest(isolateDir, manifest);\n }\n\n if (packageManager.name === \"pnpm\") {\n /**\n * PNPM doesn't install dependencies of packages that are linked via link:\n * or file: specifiers. It requires the directory to be configured as a\n * workspace, so we copy the workspace config file to the isolate output.\n *\n * Rush doesn't have a pnpm-workspace.yaml file, so we generate one.\n */\n if (isRushWorkspace(workspaceRootDir)) {\n const packagesFolderNames = unique(\n internalPackageNames.map(\n (name) => path.parse(packagesRegistry[name].rootRelativeDir).dir\n )\n );\n\n log.debug(\"Generating pnpm-workspace.yaml for Rush workspace\");\n log.debug(\"Packages folder names:\", packagesFolderNames);\n\n const packages = packagesFolderNames.map((x) => path.join(x, \"/*\"));\n\n await writeTypedYamlSync(path.join(isolateDir, \"pnpm-workspace.yaml\"), {\n packages,\n });\n } else {\n fs.copyFileSync(\n path.join(workspaceRootDir, \"pnpm-workspace.yaml\"),\n path.join(isolateDir, \"pnpm-workspace.yaml\")\n );\n }\n }\n /**\n * If there is an .npmrc file in the workspace root, copy it to the isolate\n * because the settings there could affect how the lockfile is resolved. Note\n * that .npmrc is used by both NPM and PNPM for configuration.\n *\n * See also: https://pnpm.io/npmrc\n */\n const npmrcPath = path.join(workspaceRootDir, \".npmrc\");\n\n if (fs.existsSync(npmrcPath)) {\n fs.copyFileSync(npmrcPath, path.join(isolateDir, \".npmrc\"));\n log.debug(\"Copied .npmrc file to the isolate output\");\n }\n\n /**\n * Clean up. Only so this in the happy path, so we can look at the temp folder\n * when thing go wrong.\n */\n log.debug(\n \"Deleting temp directory\",\n getRootRelativePath(tmpDir, workspaceRootDir)\n );\n await fs.remove(tmpDir);\n\n log.info(\"Isolate completed at\", isolateDir);\n\n return isolateDir;\n}\n","import fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport { isEmpty } from \"remeda\";\nimport { setLogLevel, useLogger } from \"./logger\";\nimport { inspectValue, readTypedJsonSync } from \"./utils\";\n\nexport type IsolateConfigResolved = {\n buildDirName?: string;\n includeDevDependencies: boolean;\n includePatchedDependencies: boolean;\n isolateDirName: string;\n logLevel: \"info\" | \"debug\" | \"warn\" | \"error\";\n targetPackagePath?: string;\n tsconfigPath: string;\n workspacePackages?: string[];\n workspaceRoot: string;\n forceNpm: boolean;\n pickFromScripts?: string[];\n omitFromScripts?: string[];\n omitPackageManager?: boolean;\n};\n\nexport type IsolateConfig = Partial<IsolateConfigResolved>;\n\nconst configDefaults: IsolateConfigResolved = {\n buildDirName: undefined,\n includeDevDependencies: false,\n includePatchedDependencies: false,\n isolateDirName: \"isolate\",\n logLevel: \"info\",\n targetPackagePath: undefined,\n tsconfigPath: \"./tsconfig.json\",\n workspacePackages: undefined,\n workspaceRoot: \"../..\",\n forceNpm: false,\n pickFromScripts: undefined,\n omitFromScripts: undefined,\n omitPackageManager: false,\n};\n\n/**\n * Only initialize the configuration once, and keeping it here for subsequent\n * calls to getConfig.\n */\nlet _resolvedConfig: IsolateConfigResolved | undefined;\n\nlet _user_defined_config: IsolateConfig | undefined;\n\nconst validConfigKeys = Object.keys(configDefaults);\n\nconst CONFIG_FILE_NAME = \"isolate.config.json\";\n\nexport type LogLevel = IsolateConfigResolved[\"logLevel\"];\n\nexport function setUserConfig(config: IsolateConfig) {\n _user_defined_config = config;\n\n if (config.logLevel) {\n setLogLevel(config.logLevel);\n }\n}\n\nexport function useConfig() {\n if (_resolvedConfig) {\n return _resolvedConfig;\n } else {\n throw new Error(\"Called useConfig before config was made available\");\n }\n}\n\n/**\n * Resolve configuration based on user config and defaults. If setConfig was\n * called before this, it does not attempt to read a config file from disk.\n */\nexport function resolveConfig(): IsolateConfigResolved {\n if (_resolvedConfig) {\n return _resolvedConfig;\n }\n\n setLogLevel(process.env.DEBUG_ISOLATE_CONFIG ? \"debug\" : \"info\");\n\n const log = useLogger();\n\n const configFilePath = path.join(process.cwd(), CONFIG_FILE_NAME);\n\n if (_user_defined_config) {\n log.debug(`Using user defined config:`, inspectValue(_user_defined_config));\n } else {\n log.debug(`Attempting to load config from ${configFilePath}`);\n\n _user_defined_config = fs.existsSync(configFilePath)\n ? readTypedJsonSync<IsolateConfig>(configFilePath)\n : {};\n }\n\n const foreignKeys = Object.keys(_user_defined_config).filter(\n (key) => !validConfigKeys.includes(key)\n );\n\n if (!isEmpty(foreignKeys)) {\n log.warn(`Found invalid config settings:`, foreignKeys.join(\", \"));\n }\n\n const config = Object.assign(\n {},\n configDefaults,\n _user_defined_config\n ) satisfies IsolateConfigResolved;\n\n log.debug(\"Using configuration:\", inspectValue(config));\n\n _resolvedConfig = config;\n return config;\n}\n\n/**\n * Get only the configuration that the user set explicitly in the config file or\n * passed via arguments to isolate().\n */\nexport function getUserDefinedConfig(): IsolateConfig {\n assert(\n _user_defined_config,\n \"Called getUserDefinedConfig before user config was made available\"\n );\n\n return _user_defined_config;\n}\n","import chalk from \"chalk\";\nimport type { IsolateConfigResolved, LogLevel } from \"./config\";\n/**\n * The Logger defines an interface that can be used to pass in a different\n * logger object in order to intercept all the logging output. We keep the\n * handlers separate from the logger object itself, so that we can change the\n * handlers but do not bother the user with having to handle logLevel.\n */\nexport type Logger = {\n debug(...args: unknown[]): void;\n info(...args: unknown[]): void;\n warn(...args: unknown[]): void;\n error(...args: unknown[]): void;\n};\n\nlet _loggerHandlers: Logger = {\n debug(...args: unknown[]) {\n console.log(chalk.blue(\"debug\"), ...args);\n },\n info(...args: unknown[]) {\n console.log(chalk.green(\"info\"), ...args);\n },\n warn(...args: unknown[]) {\n console.log(chalk.yellow(\"warning\"), ...args);\n },\n error(...args: unknown[]) {\n console.log(chalk.red(\"error\"), ...args);\n },\n};\n\nconst _logger: Logger = {\n debug(...args: unknown[]) {\n if (_logLevel === \"debug\") {\n _loggerHandlers.debug(...args);\n }\n },\n info(...args: unknown[]) {\n if (_logLevel === \"debug\" || _logLevel === \"info\") {\n _loggerHandlers.info(...args);\n }\n },\n warn(...args: unknown[]) {\n if (_logLevel === \"debug\" || _logLevel === \"info\" || _logLevel === \"warn\") {\n _loggerHandlers.warn(...args);\n }\n },\n error(...args: unknown[]) {\n _loggerHandlers.error(...args);\n },\n};\n\nlet _logLevel: LogLevel = \"info\";\n\nexport function setLogger(logger: Logger) {\n _loggerHandlers = logger;\n return _logger;\n}\n\nexport function setLogLevel(\n logLevel: IsolateConfigResolved[\"logLevel\"]\n): Logger {\n _logLevel = logLevel;\n return _logger;\n}\n\nexport function useLogger() {\n return _logger;\n}\n","import { fileURLToPath } from \"url\";\n\n/**\n * Calling context should pass in import.meta.url and the function will return\n * the equivalent of __dirname in Node/CommonJs.\n */\nexport function getDirname(importMetaUrl: string) {\n return fileURLToPath(new URL(\".\", importMetaUrl));\n}\n","type ErrorWithMessage = {\n message: string;\n};\n\nexport function getErrorMessage(error: unknown) {\n return toErrorWithMessage(error).message;\n}\n\nfunction isErrorWithMessage(error: unknown): error is ErrorWithMessage {\n return typeof error === \"object\" && error !== null && \"message\" in error;\n}\n\nfunction toErrorWithMessage(maybeError: unknown): ErrorWithMessage {\n if (isErrorWithMessage(maybeError)) return maybeError;\n\n try {\n return new Error(JSON.stringify(maybeError));\n } catch {\n /**\n * Fallback in case there’s an error in stringify which can happen with\n * circular references.\n */\n return new Error(String(maybeError));\n }\n}\n","import { join } from \"node:path\";\n\nexport function getRootRelativePath(path: string, rootPath: string) {\n const strippedPath = path.replace(rootPath, \"\");\n\n return join(\"(root)\", strippedPath);\n}\n\nexport function getIsolateRelativePath(path: string, isolatePath: string) {\n const strippedPath = path.replace(isolatePath, \"\");\n\n return join(\"(isolate)\", strippedPath);\n}\n","import { inspect } from \"node:util\";\n\nexport function inspectValue(value: unknown) {\n return inspect(value, false, 16, true);\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Detect if this is a Rush monorepo. They use a very different structure so\n * there are multiple places where we need to make exceptions based on this.\n */\nexport function isRushWorkspace(workspaceRootDir: string) {\n return fs.existsSync(path.join(workspaceRootDir, \"rush.json\"));\n}\n","import fs from \"fs-extra\";\nimport stripJsonComments from \"strip-json-comments\";\nimport { getErrorMessage } from \"./get-error-message\";\n\n/** @todo Pass in zod schema and validate */\nexport function readTypedJsonSync<T>(filePath: string) {\n try {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const data = JSON.parse(\n stripJsonComments(rawContent, { trailingCommas: true })\n ) as T;\n return data;\n } catch (err) {\n throw new Error(\n `Failed to read JSON from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n\nexport async function readTypedJson<T>(filePath: string) {\n try {\n const rawContent = await fs.readFile(filePath, \"utf-8\");\n const data = JSON.parse(\n stripJsonComments(rawContent, { trailingCommas: true })\n ) as T;\n return data;\n } catch (err) {\n throw new Error(\n `Failed to read JSON from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n","import { exec } from \"node:child_process\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { useLogger } from \"../logger\";\nimport { shouldUsePnpmPack } from \"../package-manager\";\nimport { getErrorMessage } from \"./get-error-message\";\n\nexport async function pack(srcDir: string, dstDir: string) {\n const log = useLogger();\n\n const execOptions = {\n maxBuffer: 10 * 1024 * 1024,\n };\n\n const previousCwd = process.cwd();\n process.chdir(srcDir);\n\n /**\n * PNPM pack seems to be a lot faster than NPM pack, so when PNPM is detected\n * we use that instead.\n */\n const stdout = shouldUsePnpmPack()\n ? await new Promise<string>((resolve, reject) => {\n exec(\n `pnpm pack --pack-destination \"${dstDir}\"`,\n execOptions,\n (err, stdout) => {\n if (err) {\n log.error(getErrorMessage(err));\n return reject(err);\n }\n\n resolve(stdout);\n }\n );\n })\n : await new Promise<string>((resolve, reject) => {\n exec(\n `npm pack --pack-destination \"${dstDir}\"`,\n execOptions,\n (err, stdout) => {\n if (err) {\n return reject(err);\n }\n\n resolve(stdout);\n }\n );\n });\n\n const fileName = path.basename(stdout.trim());\n\n const filePath = path.join(dstDir, fileName);\n\n if (!fs.existsSync(filePath)) {\n log.error(\n `The response from pack could not be resolved to an existing file: ${filePath}`\n );\n } else {\n log.debug(`Packed (temp)/${fileName}`);\n }\n\n process.chdir(previousCwd);\n\n /**\n * Return the path anyway even if it doesn't validate. A later stage will wait\n * for the file to occur still. Not sure if this makes sense. Maybe we should\n * stop at the validation error...\n */\n return filePath;\n}\n","import path from \"node:path\";\nimport { isRushWorkspace } from \"../utils/is-rush-workspace\";\nimport { inferFromFiles, inferFromManifest } from \"./helpers\";\nimport type { PackageManager } from \"./names\";\n\nexport * from \"./names\";\n\nlet packageManager: PackageManager | undefined;\n\nexport function usePackageManager() {\n if (!packageManager) {\n throw Error(\n \"No package manager detected. Make sure to call detectPackageManager() before usePackageManager()\"\n );\n }\n\n return packageManager;\n}\n\n/**\n * First we check if the package manager is declared in the manifest. If it is,\n * we get the name and version from there. Otherwise we'll search for the\n * different lockfiles and ask the OS to report the installed version.\n */\nexport function detectPackageManager(workspaceRootDir: string): PackageManager {\n if (isRushWorkspace(workspaceRootDir)) {\n packageManager = inferFromFiles(\n path.join(workspaceRootDir, \"common/config/rush\")\n );\n } else {\n /**\n * Disable infer from manifest for now. I doubt it is useful after all but\n * I'll keep the code as a reminder.\n */\n packageManager =\n inferFromManifest(workspaceRootDir) ?? inferFromFiles(workspaceRootDir);\n }\n\n return packageManager;\n}\n\nexport function shouldUsePnpmPack() {\n const { name, majorVersion } = usePackageManager();\n\n return name === \"pnpm\" && majorVersion >= 8;\n}\n","import fs from \"fs-extra\";\nimport { execSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport { getErrorMessage } from \"~/lib/utils\";\nimport { getMajorVersion } from \"~/lib/utils/get-major-version\";\nimport type { PackageManager, PackageManagerName } from \"../names\";\nimport { getLockfileFileName, supportedPackageManagerNames } from \"../names\";\n\nexport function inferFromFiles(workspaceRoot: string): PackageManager {\n for (const name of supportedPackageManagerNames) {\n const lockfileName = getLockfileFileName(name);\n\n if (fs.existsSync(path.join(workspaceRoot, lockfileName))) {\n try {\n const version = getVersion(name);\n\n return { name, version, majorVersion: getMajorVersion(version) };\n } catch (err) {\n throw new Error(\n `Failed to find package manager version for ${name}: ${getErrorMessage(err)}`\n );\n }\n }\n }\n\n /** If no lockfile was found, it could be that there is an npm shrinkwrap file. */\n if (fs.existsSync(path.join(workspaceRoot, \"npm-shrinkwrap.json\"))) {\n const version = getVersion(\"npm\");\n\n return { name: \"npm\", version, majorVersion: getMajorVersion(version) };\n }\n\n throw new Error(`Failed to detect package manager`);\n}\n\nexport function getVersion(packageManagerName: PackageManagerName): string {\n const buffer = execSync(`${packageManagerName} --version`);\n return buffer.toString().trim();\n}\n","export function getMajorVersion(version: string) {\n return parseInt(version.split(\".\")[0], 10);\n}\n","export const supportedPackageManagerNames = [\"pnpm\", \"yarn\", \"npm\"] as const;\n\nexport type PackageManagerName = (typeof supportedPackageManagerNames)[number];\n\nexport type PackageManager = {\n name: PackageManagerName;\n version: string;\n majorVersion: number;\n packageManagerString?: string;\n};\n\nexport function getLockfileFileName(name: PackageManagerName) {\n switch (name) {\n case \"pnpm\":\n return \"pnpm-lock.yaml\";\n case \"yarn\":\n return \"yarn.lock\";\n case \"npm\":\n return \"package-lock.json\";\n }\n}\n","import fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport { useLogger } from \"~/lib/logger\";\nimport { getMajorVersion } from \"~/lib/utils/get-major-version\";\nimport type { PackageManifest } from \"../../types\";\nimport { readTypedJsonSync } from \"../../utils\";\nimport type { PackageManagerName } from \"../names\";\nimport { getLockfileFileName, supportedPackageManagerNames } from \"../names\";\n\nexport function inferFromManifest(workspaceRoot: string) {\n const log = useLogger();\n\n const { packageManager: packageManagerString } =\n readTypedJsonSync<PackageManifest>(\n path.join(workspaceRoot, \"package.json\")\n );\n\n if (!packageManagerString) {\n log.debug(\"No packageManager field found in root manifest\");\n return;\n }\n\n const [name, version = \"*\"] = packageManagerString.split(\"@\") as [\n PackageManagerName,\n string,\n ];\n\n assert(\n supportedPackageManagerNames.includes(name),\n `Package manager \"${name}\" is not currently supported`\n );\n\n const lockfileName = getLockfileFileName(name);\n\n assert(\n fs.existsSync(path.join(workspaceRoot, lockfileName)),\n `Manifest declares ${name} to be the packageManager, but failed to find ${lockfileName} in workspace root`\n );\n\n return {\n name,\n version,\n majorVersion: getMajorVersion(version),\n packageManagerString,\n };\n}\n","import fs from \"fs-extra\";\nimport tar from \"tar-fs\";\nimport { createGunzip } from \"zlib\";\n\nexport async function unpack(filePath: string, unpackDir: string) {\n await new Promise<void>((resolve, reject) => {\n fs.createReadStream(filePath)\n .pipe(createGunzip())\n .pipe(tar.extract(unpackDir))\n .on(\"finish\", () => resolve())\n .on(\"error\", (err) => reject(err));\n });\n}\n","import fs from \"fs-extra\";\nimport yaml from \"yaml\";\nimport { getErrorMessage } from \"./get-error-message\";\n\nexport function readTypedYamlSync<T>(filePath: string) {\n try {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const data = yaml.parse(rawContent);\n /** @todo Add some zod validation maybe */\n return data as T;\n } catch (err) {\n throw new Error(\n `Failed to read YAML from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n\nexport function writeTypedYamlSync<T>(filePath: string, content: T) {\n /** @todo Add some zod validation maybe */\n fs.writeFileSync(filePath, yaml.stringify(content), \"utf-8\");\n}\n","import Arborist from \"@npmcli/arborist\";\nimport fs from \"fs-extra\";\nimport path from \"node:path\";\nimport { useLogger } from \"~/lib/logger\";\nimport { getErrorMessage } from \"~/lib/utils\";\n\n/**\n * Generate an isolated / pruned lockfile, based on the contents of installed\n * node_modules from the monorepo root plus the adapted package manifest in the\n * isolate directory.\n */\nexport async function generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n}: {\n workspaceRootDir: string;\n isolateDir: string;\n}) {\n const log = useLogger();\n\n log.debug(\"Generating NPM lockfile...\");\n\n const nodeModulesPath = path.join(workspaceRootDir, \"node_modules\");\n\n try {\n if (!fs.existsSync(nodeModulesPath)) {\n throw new Error(`Failed to find node_modules at ${nodeModulesPath}`);\n }\n\n const arborist = new Arborist({ path: isolateDir });\n\n const { meta } = await arborist.buildIdealTree();\n\n meta?.commit();\n\n const lockfilePath = path.join(isolateDir, \"package-lock.json\");\n\n await fs.writeFile(lockfilePath, String(meta));\n\n log.debug(\"Created lockfile at\", lockfilePath);\n } catch (err) {\n log.error(`Failed to generate lockfile: ${getErrorMessage(err)}`);\n throw err;\n }\n}\n","import assert from \"node:assert\";\nimport path from \"node:path\";\nimport {\n getLockfileImporterId as getLockfileImporterId_v8,\n readWantedLockfile as readWantedLockfile_v8,\n writeWantedLockfile as writeWantedLockfile_v8,\n} from \"pnpm_lockfile_file_v8\";\nimport {\n getLockfileImporterId as getLockfileImporterId_v9,\n readWantedLockfile as readWantedLockfile_v9,\n writeWantedLockfile as writeWantedLockfile_v9,\n} from \"pnpm_lockfile_file_v9\";\nimport { pruneLockfile as pruneLockfile_v8 } from \"pnpm_prune_lockfile_v8\";\nimport { pruneLockfile as pruneLockfile_v9 } from \"pnpm_prune_lockfile_v9\";\nimport { pick } from \"remeda\";\nimport { useConfig } from \"~/lib/config\";\nimport { useLogger } from \"~/lib/logger\";\nimport type { PackageManifest, PackagesRegistry } from \"~/lib/types\";\nimport { getErrorMessage, isRushWorkspace } from \"~/lib/utils\";\nimport { pnpmMapImporter } from \"./pnpm-map-importer\";\n\nexport async function generatePnpmLockfile({\n workspaceRootDir,\n targetPackageDir,\n isolateDir,\n internalDepPackageNames,\n packagesRegistry,\n targetPackageManifest,\n majorVersion,\n}: {\n workspaceRootDir: string;\n targetPackageDir: string;\n isolateDir: string;\n internalDepPackageNames: string[];\n packagesRegistry: PackagesRegistry;\n targetPackageManifest: PackageManifest;\n majorVersion: number;\n}) {\n /**\n * For now we will assume that the lockfile format might not change in the\n * versions after 9, because we might get lucky. If it does change, things\n * would break either way.\n */\n const useVersion9 = majorVersion >= 9;\n\n const { includeDevDependencies, includePatchedDependencies } = useConfig();\n const log = useLogger();\n\n log.debug(\"Generating PNPM lockfile...\");\n\n try {\n const isRush = isRushWorkspace(workspaceRootDir);\n\n const lockfile = useVersion9\n ? await readWantedLockfile_v9(\n isRush\n ? path.join(workspaceRootDir, \"common/config/rush\")\n : workspaceRootDir,\n {\n ignoreIncompatible: false,\n }\n )\n : await readWantedLockfile_v8(\n isRush\n ? path.join(workspaceRootDir, \"common/config/rush\")\n : workspaceRootDir,\n {\n ignoreIncompatible: false,\n }\n );\n\n assert(lockfile, `No input lockfile found at ${workspaceRootDir}`);\n\n const targetImporterId = useVersion9\n ? getLockfileImporterId_v9(workspaceRootDir, targetPackageDir)\n : getLockfileImporterId_v8(workspaceRootDir, targetPackageDir);\n\n const directoryByPackageName = Object.fromEntries(\n internalDepPackageNames.map((name) => {\n const pkg = packagesRegistry[name];\n assert(pkg, `Package ${name} not found in packages registry`);\n\n return [name, pkg.rootRelativeDir];\n })\n );\n\n const relevantImporterIds = [\n targetImporterId,\n /**\n * The directory paths happen to correspond with what PNPM calls the\n * importer ids in the context of a lockfile.\n */\n ...Object.values(directoryByPackageName),\n ];\n\n log.debug(\"Relevant importer ids:\", relevantImporterIds);\n\n /**\n * In a Rush workspace the original lockfile is not in the root, so the\n * importerIds have to be prefixed with `../../`, but that's not how they\n * should be stored in the isolated lockfile, so we use the prefixed ids\n * only for parsing.\n */\n const relevantImporterIdsWithPrefix = relevantImporterIds.map((x) =>\n isRush ? `../../${x}` : x\n );\n\n lockfile.importers = Object.fromEntries(\n Object.entries(\n pick(lockfile.importers, relevantImporterIdsWithPrefix)\n ).map(([prefixedImporterId, importer]) => {\n const importerId = isRush\n ? prefixedImporterId.replace(\"../../\", \"\")\n : prefixedImporterId;\n\n if (importerId === targetImporterId) {\n log.debug(\"Setting target package importer on root\");\n\n return [\n \".\",\n pnpmMapImporter(\".\", importer, {\n includeDevDependencies,\n includePatchedDependencies,\n directoryByPackageName,\n }),\n ];\n }\n\n log.debug(\"Setting internal package importer:\", importerId);\n\n return [\n importerId,\n pnpmMapImporter(importerId, importer, {\n includeDevDependencies,\n includePatchedDependencies,\n directoryByPackageName,\n }),\n ];\n })\n );\n\n log.debug(\"Pruning the lockfile\");\n\n const prunedLockfile = useVersion9\n ? await pruneLockfile_v9(lockfile, targetPackageManifest, \".\")\n : await pruneLockfile_v8(lockfile, targetPackageManifest, \".\");\n\n /** Pruning seems to remove the overrides from the lockfile */\n if (lockfile.overrides) {\n prunedLockfile.overrides = lockfile.overrides;\n }\n\n /**\n * Don't know how to map the patched dependencies yet, so we just include\n * them but I don't think it would work like this. The important thing for\n * now is that they are omitted by default, because that is the most common\n * use case.\n */\n const patchedDependencies = includePatchedDependencies\n ? lockfile.patchedDependencies\n : undefined;\n\n useVersion9\n ? await writeWantedLockfile_v9(isolateDir, {\n ...prunedLockfile,\n patchedDependencies,\n })\n : await writeWantedLockfile_v8(isolateDir, {\n ...prunedLockfile,\n patchedDependencies,\n });\n\n log.debug(\"Created lockfile at\", path.join(isolateDir, \"pnpm-lock.yaml\"));\n } catch (err) {\n log.error(`Failed to generate lockfile: ${getErrorMessage(err)}`);\n throw err;\n }\n}\n","import path from \"node:path\";\nimport type {\n ProjectSnapshot,\n ResolvedDependencies,\n} from \"pnpm_lockfile_file_v8\";\n\nimport { mapValues } from \"remeda\";\n\n/** Convert dependency links */\nexport function pnpmMapImporter(\n importerPath: string,\n { dependencies, devDependencies, ...rest }: ProjectSnapshot,\n {\n includeDevDependencies,\n directoryByPackageName,\n }: {\n includeDevDependencies: boolean;\n includePatchedDependencies: boolean;\n directoryByPackageName: { [packageName: string]: string };\n }\n): ProjectSnapshot {\n return {\n dependencies: dependencies\n ? pnpmMapDependenciesLinks(\n importerPath,\n dependencies,\n directoryByPackageName\n )\n : undefined,\n devDependencies:\n includeDevDependencies && devDependencies\n ? pnpmMapDependenciesLinks(\n importerPath,\n devDependencies,\n directoryByPackageName\n )\n : undefined,\n ...rest,\n };\n}\n\nfunction pnpmMapDependenciesLinks(\n importerPath: string,\n def: ResolvedDependencies,\n directoryByPackageName: { [packageName: string]: string }\n): ResolvedDependencies {\n return mapValues(def, (value, key) => {\n if (!value.startsWith(\"link:\")) {\n return value;\n }\n\n const relativePath = path.relative(\n importerPath,\n directoryByPackageName[key]\n );\n\n return relativePath.startsWith(\".\")\n ? `link:${relativePath}`\n : `link:./${relativePath}`;\n });\n}\n","import fs from \"fs-extra\";\nimport { execSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport { useLogger } from \"~/lib/logger\";\nimport { getErrorMessage, isRushWorkspace } from \"~/lib/utils\";\n\n/**\n * Generate an isolated / pruned lockfile, based on the existing lockfile from\n * the monorepo root plus the adapted package manifest in the isolate\n * directory.\n */\nexport async function generateYarnLockfile({\n workspaceRootDir,\n isolateDir,\n}: {\n workspaceRootDir: string;\n isolateDir: string;\n}) {\n const log = useLogger();\n\n log.debug(\"Generating Yarn lockfile...\");\n\n const origLockfilePath = isRushWorkspace(workspaceRootDir)\n ? path.join(workspaceRootDir, \"common/config/rush\", \"yarn.lock\")\n : path.join(workspaceRootDir, \"yarn.lock\");\n\n const newLockfilePath = path.join(isolateDir, \"yarn.lock\");\n\n if (!fs.existsSync(origLockfilePath)) {\n throw new Error(`Failed to find lockfile at ${origLockfilePath}`);\n }\n\n log.debug(`Copy original yarn.lock to the isolate output`);\n\n try {\n await fs.copyFile(origLockfilePath, newLockfilePath);\n\n /**\n * Running install with the original lockfile in the same directory will\n * generate a pruned version of the lockfile.\n */\n log.debug(`Running local install`);\n execSync(`yarn install --cwd ${isolateDir}`);\n\n log.debug(\"Generated lockfile at\", newLockfilePath);\n } catch (err) {\n log.error(`Failed to generate lockfile: ${getErrorMessage(err)}`);\n throw err;\n }\n}\n","import { useLogger } from \"../logger\";\nimport { usePackageManager } from \"../package-manager\";\nimport type { PackageManifest, PackagesRegistry } from \"../types\";\nimport {\n generateNpmLockfile,\n generatePnpmLockfile,\n generateYarnLockfile,\n} from \"./helpers\";\n\n/**\n * Adapt the lockfile and write it to the isolate directory. Because we keep the\n * structure of packages in the isolate directory the same as they were in the\n * monorepo, the lockfile is largely still correct. The only things that need to\n * be done is to remove the root dependencies and devDependencies, and rename\n * the path to the target package to act as the new root.\n */\nexport async function processLockfile({\n workspaceRootDir,\n packagesRegistry,\n isolateDir,\n internalDepPackageNames,\n targetPackageDir,\n targetPackageManifest,\n}: {\n workspaceRootDir: string;\n packagesRegistry: PackagesRegistry;\n isolateDir: string;\n internalDepPackageNames: string[];\n targetPackageDir: string;\n targetPackageName: string;\n targetPackageManifest: PackageManifest;\n}) {\n const log = useLogger();\n\n const { name, majorVersion } = usePackageManager();\n let usedFallbackToNpm = false;\n\n switch (name) {\n case \"npm\": {\n await generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n });\n\n break;\n }\n case \"yarn\": {\n if (majorVersion === 1) {\n await generateYarnLockfile({\n workspaceRootDir,\n isolateDir,\n });\n } else {\n log.warn(\n \"Detected modern version of Yarn. Using NPM lockfile fallback.\"\n );\n\n await generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n });\n\n usedFallbackToNpm = true;\n }\n\n break;\n }\n case \"pnpm\": {\n await generatePnpmLockfile({\n workspaceRootDir,\n targetPackageDir,\n isolateDir,\n internalDepPackageNames,\n packagesRegistry,\n targetPackageManifest,\n majorVersion,\n });\n break;\n }\n default:\n log.warn(`Unexpected package manager ${name}. Using NPM for output`);\n await generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n });\n\n usedFallbackToNpm = true;\n }\n\n return usedFallbackToNpm;\n}\n","import { omit, pick } from \"remeda\";\nimport { useConfig } from \"../config\";\nimport { usePackageManager } from \"../package-manager\";\nimport type { PackageManifest, PackagesRegistry } from \"../types\";\nimport { adaptManifestInternalDeps, adoptPnpmFieldsFromRoot } from \"./helpers\";\n\n/**\n * Adapt the output package manifest, so that:\n *\n * - Its internal dependencies point to the isolated ./packages/* directory.\n * - The devDependencies are possibly removed\n * - Scripts are picked or omitted and otherwise removed\n */\nexport async function adaptTargetPackageManifest({\n manifest,\n packagesRegistry,\n workspaceRootDir,\n}: {\n manifest: PackageManifest;\n packagesRegistry: PackagesRegistry;\n workspaceRootDir: string;\n}) {\n const packageManager = usePackageManager();\n const {\n includeDevDependencies,\n pickFromScripts,\n omitFromScripts,\n omitPackageManager,\n } = useConfig();\n\n /** Dev dependencies are omitted by default */\n const inputManifest = includeDevDependencies\n ? manifest\n : omit(manifest, [\"devDependencies\"]);\n\n const adaptedManifest =\n packageManager.name === \"pnpm\"\n ? /**\n * For PNPM the output itself is a workspace so we can preserve the specifiers\n * with \"workspace:*\" in the output manifest, but we do want to adopt the\n * pnpm.overrides field from the root package.json.\n */\n await adoptPnpmFieldsFromRoot(inputManifest, workspaceRootDir)\n : /** For other package managers we replace the links to internal dependencies */\n adaptManifestInternalDeps({\n manifest: inputManifest,\n packagesRegistry,\n });\n\n return {\n ...adaptedManifest,\n /**\n * Adopt the package manager definition from the root manifest if available.\n * The option to omit is there because some platforms might not handle it\n * properly (Cloud Run, April 24th 2024, does not handle pnpm v9)\n */\n packageManager: omitPackageManager\n ? undefined\n : packageManager.packageManagerString,\n /**\n * Scripts are removed by default if not explicitly picked or omitted via\n * config.\n */\n scripts: pickFromScripts\n ? pick(manifest.scripts ?? {}, pickFromScripts)\n : omitFromScripts\n ? omit(manifest.scripts ?? {}, omitFromScripts)\n : undefined,\n };\n}\n","import path from \"node:path\";\nimport { omit } from \"remeda\";\nimport { usePackageManager } from \"~/lib/package-manager\";\nimport type { PackagesRegistry } from \"~/lib/types\";\nimport { writeManifest } from \"../io\";\nimport { adaptManifestInternalDeps } from \"./adapt-manifest-internal-deps\";\n\n/**\n * Adapt the manifest files of all the isolated internal packages (excluding the\n * target package), so that their dependencies point to the other isolated\n * packages in the same folder.\n */\nexport async function adaptInternalPackageManifests(\n internalPackageNames: string[],\n packagesRegistry: PackagesRegistry,\n isolateDir: string\n) {\n const packageManager = usePackageManager();\n\n await Promise.all(\n internalPackageNames.map(async (packageName) => {\n const { manifest, rootRelativeDir } = packagesRegistry[packageName];\n\n /** Dev dependencies and scripts are never included for internal deps */\n const strippedManifest = omit(manifest, [\"scripts\", \"devDependencies\"]);\n\n const outputManifest =\n packageManager.name === \"pnpm\"\n ? /**\n * For PNPM the output itself is a workspace so we can preserve the specifiers\n * with \"workspace:*\" in the output manifest.\n */\n strippedManifest\n : /** For other package managers we replace the links to internal dependencies */\n adaptManifestInternalDeps({\n manifest: strippedManifest,\n packagesRegistry,\n parentRootRelativeDir: rootRelativeDir,\n });\n\n await writeManifest(\n path.join(isolateDir, rootRelativeDir),\n outputManifest\n );\n })\n );\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport type { PackageManifest } from \"../types\";\nimport { readTypedJson } from \"../utils\";\n\nexport async function readManifest(packageDir: string) {\n return readTypedJson<PackageManifest>(path.join(packageDir, \"package.json\"));\n}\n\nexport async function writeManifest(\n outputDir: string,\n manifest: PackageManifest\n) {\n await fs.writeFile(\n path.join(outputDir, \"package.json\"),\n JSON.stringify(manifest, null, 2)\n );\n}\n","import path from \"node:path\";\nimport { useLogger } from \"../../logger\";\nimport type { PackagesRegistry } from \"../../types\";\n\nexport function patchInternalEntries(\n dependencies: Record<string, string>,\n packagesRegistry: PackagesRegistry,\n parentRootRelativeDir?: string\n) {\n const log = useLogger();\n const allWorkspacePackageNames = Object.keys(packagesRegistry);\n\n return Object.fromEntries(\n Object.entries(dependencies).map(([key, value]) => {\n if (allWorkspacePackageNames.includes(key)) {\n const def = packagesRegistry[key];\n\n /**\n * When nested internal dependencies are used (internal packages linking\n * to other internal packages), the parentRootRelativeDir will be passed\n * in, and we store the relative path to the isolate/packages\n * directory.\n *\n * For consistency we also write the other file paths starting with ./,\n * but it doesn't seem to be necessary for any package manager.\n */\n const relativePath = parentRootRelativeDir\n ? path.relative(parentRootRelativeDir, `./${def.rootRelativeDir}`)\n : `./${def.rootRelativeDir}`;\n\n const linkPath = `file:${relativePath}`;\n\n log.debug(`Linking dependency ${key} to ${linkPath}`);\n\n return [key, linkPath];\n } else {\n return [key, value];\n }\n })\n );\n}\n","import type { PackageManifest, PackagesRegistry } from \"~/lib/types\";\nimport { patchInternalEntries } from \"./patch-internal-entries\";\n\n/**\n * Replace the workspace version specifiers for internal dependency with file:\n * paths. Not needed for PNPM (because we configure the isolated output as a\n * workspace), but maybe still for NPM and Yarn.\n */\nexport function adaptManifestInternalDeps({\n manifest,\n packagesRegistry,\n parentRootRelativeDir,\n}: {\n manifest: PackageManifest;\n packagesRegistry: PackagesRegistry;\n parentRootRelativeDir?: string;\n}): PackageManifest {\n const { dependencies, devDependencies } = manifest;\n\n return {\n ...manifest,\n dependencies: dependencies\n ? patchInternalEntries(\n dependencies,\n packagesRegistry,\n parentRootRelativeDir\n )\n : undefined,\n devDependencies: devDependencies\n ? patchInternalEntries(\n devDependencies,\n packagesRegistry,\n parentRootRelativeDir\n )\n : undefined,\n };\n}\n","import type { ProjectManifest } from \"@pnpm/types\";\nimport path from \"path\";\nimport type { PackageManifest } from \"~/lib/types\";\nimport { isRushWorkspace, readTypedJson } from \"~/lib/utils\";\n\n/**\n * Adopts the `pnpm` fields from the root package manifest. Currently it only\n * takes overrides, because I don't know if any of the others are useful or\n * desired.\n */\nexport async function adoptPnpmFieldsFromRoot(\n targetPackageManifest: PackageManifest,\n workspaceRootDir: string\n) {\n if (isRushWorkspace(workspaceRootDir)) {\n return targetPackageManifest;\n }\n\n const rootPackageManifest = await readTypedJson<ProjectManifest>(\n path.join(workspaceRootDir, \"package.json\")\n );\n\n const overrides = rootPackageManifest.pnpm?.overrides;\n\n if (!overrides) {\n return targetPackageManifest;\n }\n\n return {\n ...targetPackageManifest,\n pnpm: {\n overrides,\n },\n };\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport outdent from \"outdent\";\nimport { useConfig } from \"../config\";\nimport { useLogger } from \"../logger\";\nimport { readTypedJson } from \"../utils\";\n\nexport async function getBuildOutputDir(targetPackageDir: string) {\n const config = useConfig();\n const log = useLogger();\n\n if (config.buildDirName) {\n log.debug(\"Using buildDirName from config:\", config.buildDirName);\n return path.join(targetPackageDir, config.buildDirName);\n }\n\n const tsconfigPath = path.join(targetPackageDir, config.tsconfigPath);\n\n if (fs.existsSync(tsconfigPath)) {\n log.debug(\"Found tsconfig at:\", config.tsconfigPath);\n\n const tsconfig = await readTypedJson<{\n compilerOptions?: { outDir?: string };\n }>(tsconfigPath);\n\n const outDir = tsconfig.compilerOptions?.outDir;\n\n if (outDir) {\n return path.join(targetPackageDir, outDir);\n } else {\n throw new Error(outdent`\n Failed to find outDir in tsconfig. If you are executing isolate from the root of a monorepo you should specify the buildDirName in isolate.config.json.\n `);\n }\n } else {\n log.warn(\"Failed to find tsconfig at:\", tsconfigPath);\n\n throw new Error(outdent`\n Failed to infer the build output directory from either the isolate config buildDirName or a Typescript config file. See the documentation on how to configure one of these options.\n `);\n }\n}\n","import assert from \"node:assert\";\nimport { useLogger } from \"../logger\";\nimport type { PackagesRegistry } from \"../types\";\nimport { pack } from \"../utils\";\n\n/**\n * Pack dependencies so that we extract only the files that are supposed to be\n * published by the packages.\n *\n * @returns A map of package names to the path of the packed file\n */\nexport async function packDependencies({\n /** All packages found in the monorepo by workspaces declaration */\n packagesRegistry,\n /** The dependencies that appear to be internal packages */\n internalPackageNames,\n /**\n * The directory where the isolated package and all its dependencies will end\n * up. This is also the directory from where the package will be deployed. By\n * default it is a subfolder in targetPackageDir called \"isolate\" but you can\n * configure it.\n */\n packDestinationDir,\n}: {\n packagesRegistry: PackagesRegistry;\n internalPackageNames: string[];\n packDestinationDir: string;\n}) {\n const log = useLogger();\n\n const packedFileByName: Record<string, string> = {};\n\n for (const dependency of internalPackageNames) {\n const def = packagesRegistry[dependency];\n\n assert(dependency, `Failed to find package definition for ${dependency}`);\n\n const { name } = def.manifest;\n\n /**\n * If this dependency has already been packed, we skip it. It could happen\n * because we are packing workspace dependencies recursively.\n */\n if (packedFileByName[name]) {\n log.debug(`Skipping ${name} because it has already been packed`);\n continue;\n }\n\n packedFileByName[name] = await pack(def.absoluteDir, packDestinationDir);\n }\n\n return packedFileByName;\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport { useLogger } from \"../logger\";\nimport { pack, unpack } from \"../utils\";\n\nconst TIMEOUT_MS = 5000;\n\nexport async function processBuildOutputFiles({\n targetPackageDir,\n tmpDir,\n isolateDir,\n}: {\n targetPackageDir: string;\n tmpDir: string;\n isolateDir: string;\n}) {\n const log = useLogger();\n\n const packedFilePath = await pack(targetPackageDir, tmpDir);\n const unpackDir = path.join(tmpDir, \"target\");\n\n const now = Date.now();\n let isWaitingYet = false;\n\n while (!fs.existsSync(packedFilePath) && Date.now() - now < TIMEOUT_MS) {\n if (!isWaitingYet) {\n log.debug(`Waiting for ${packedFilePath} to become available...`);\n }\n isWaitingYet = true;\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n\n await unpack(packedFilePath, unpackDir);\n await fs.copy(path.join(unpackDir, \"package\"), isolateDir);\n}\n","import fs from \"fs-extra\";\nimport path, { join } from \"node:path\";\nimport { useLogger } from \"../logger\";\nimport type { PackagesRegistry } from \"../types\";\nimport { getIsolateRelativePath, unpack } from \"../utils\";\n\nexport async function unpackDependencies(\n packedFilesByName: Record<string, string>,\n packagesRegistry: PackagesRegistry,\n tmpDir: string,\n isolateDir: string\n) {\n const log = useLogger();\n\n await Promise.all(\n Object.entries(packedFilesByName).map(async ([packageName, filePath]) => {\n const dir = packagesRegistry[packageName].rootRelativeDir;\n const unpackDir = join(tmpDir, dir);\n\n log.debug(\"Unpacking\", `(temp)/${path.basename(filePath)}`);\n\n await unpack(filePath, unpackDir);\n\n const destinationDir = join(isolateDir, dir);\n\n await fs.ensureDir(destinationDir);\n\n await fs.move(join(unpackDir, \"package\"), destinationDir, {\n overwrite: true,\n });\n\n log.debug(\n `Moved package files to ${getIsolateRelativePath(\n destinationDir,\n isolateDir\n )}`\n );\n })\n );\n}\n","import fs from \"fs-extra\";\nimport { globSync } from \"glob\";\nimport path from \"node:path\";\nimport { useLogger } from \"../logger\";\nimport type { PackageManifest, PackagesRegistry } from \"../types\";\nimport { isRushWorkspace, readTypedJson, readTypedJsonSync } from \"../utils\";\nimport { findPackagesGlobs } from \"./helpers\";\n\n/**\n * Build a list of all packages in the workspace, depending on the package\n * manager used, with a possible override from the config file. The list\n * contains the manifest with some directory info mapped by module name.\n */\nexport async function createPackagesRegistry(\n workspaceRootDir: string,\n workspacePackagesOverride: string[] | undefined\n): Promise<PackagesRegistry> {\n const log = useLogger();\n\n if (workspacePackagesOverride) {\n log.debug(\n `Override workspace packages via config: ${workspacePackagesOverride}`\n );\n }\n\n const allPackages = listWorkspacePackages(\n workspacePackagesOverride,\n workspaceRootDir\n );\n\n const registry: PackagesRegistry = (\n await Promise.all(\n allPackages.map(async (rootRelativeDir) => {\n const absoluteDir = path.join(workspaceRootDir, rootRelativeDir);\n const manifestPath = path.join(absoluteDir, \"package.json\");\n\n if (!fs.existsSync(manifestPath)) {\n log.warn(\n `Ignoring directory ${rootRelativeDir} because it does not contain a package.json file`\n );\n return;\n } else {\n log.debug(`Registering package ${rootRelativeDir}`);\n\n const manifest = await readTypedJson<PackageManifest>(\n path.join(absoluteDir, \"package.json\")\n );\n\n return {\n manifest,\n rootRelativeDir,\n absoluteDir,\n };\n }\n })\n )\n ).reduce<PackagesRegistry>((acc, info) => {\n if (info) {\n acc[info.manifest.name] = info;\n }\n return acc;\n }, {});\n\n return registry;\n}\n\ntype RushConfig = {\n projects: { packageName: string; projectFolder: string }[];\n};\n\nfunction listWorkspacePackages(\n workspacePackagesOverride: string[] | undefined,\n workspaceRootDir: string\n) {\n if (isRushWorkspace(workspaceRootDir)) {\n const rushConfig = readTypedJsonSync<RushConfig>(\n path.join(workspaceRootDir, \"rush.json\")\n );\n\n return rushConfig.projects.map(({ projectFolder }) => projectFolder);\n } else {\n const currentDir = process.cwd();\n process.chdir(workspaceRootDir);\n\n const packagesGlobs =\n workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);\n\n const allPackages = packagesGlobs\n .flatMap((glob) => globSync(glob))\n /** Make sure to filter any loose files that might hang around. */\n .filter((dir) => fs.lstatSync(dir).isDirectory());\n\n process.chdir(currentDir);\n return allPackages;\n }\n}\n","import assert from \"node:assert\";\nimport path from \"node:path\";\nimport { useLogger } from \"../../logger\";\nimport { usePackageManager } from \"../../package-manager\";\nimport {\n inspectValue,\n readTypedJsonSync,\n readTypedYamlSync,\n} from \"../../utils\";\n\n/**\n * Find the globs that define where the packages are located within the\n * monorepo. This configuration is dependent on the package manager used, and I\n * don't know if we're covering all cases yet...\n */\nexport function findPackagesGlobs(workspaceRootDir: string) {\n const log = useLogger();\n\n const packageManager = usePackageManager();\n\n switch (packageManager.name) {\n case \"pnpm\": {\n const { packages: globs } = readTypedYamlSync<{ packages: string[] }>(\n path.join(workspaceRootDir, \"pnpm-workspace.yaml\")\n );\n\n log.debug(\"Detected pnpm packages globs:\", inspectValue(globs));\n return globs;\n }\n case \"yarn\":\n case \"npm\": {\n const workspaceRootManifestPath = path.join(\n workspaceRootDir,\n \"package.json\"\n );\n\n const { workspaces } = readTypedJsonSync<{ workspaces: string[] }>(\n workspaceRootManifestPath\n );\n\n if (!workspaces) {\n throw new Error(\n `No workspaces field found in ${workspaceRootManifestPath}`\n );\n }\n\n if (Array.isArray(workspaces)) {\n return workspaces;\n } else {\n /**\n * For Yarn, workspaces could be defined as an object with { packages:\n * [], nohoist: [] }. See\n * https://classic.yarnpkg.com/blog/2018/02/15/nohoist/\n */\n const workspacesObject = workspaces as { packages?: string[] };\n\n assert(\n workspacesObject.packages,\n \"workspaces.packages must be an array\"\n );\n\n return workspacesObject.packages;\n }\n }\n }\n}\n","import { uniq } from \"remeda\";\nimport type { PackageManifest, PackagesRegistry } from \"../types\";\n\n/**\n * Recursively list all the packages from dependencies (and optionally\n * devDependencies) that are found in the monorepo.\n *\n * Here we do not need to rely on packages being declared with \"workspace:\" in\n * the package manifest. We can simply compare the package names with the list\n * of packages that were found via the workspace glob patterns and add them to\n * the registry.\n */\nexport function listInternalPackages(\n manifest: PackageManifest,\n packagesRegistry: PackagesRegistry,\n { includeDevDependencies = false } = {}\n): string[] {\n const allWorkspacePackageNames = Object.keys(packagesRegistry);\n\n const internalPackageNames = (\n includeDevDependencies\n ? [\n ...Object.keys(manifest.dependencies ?? {}),\n ...Object.keys(manifest.devDependencies ?? {}),\n ]\n : Object.keys(manifest.dependencies ?? {})\n ).filter((name) => allWorkspacePackageNames.includes(name));\n\n const nestedInternalPackageNames = internalPackageNames.flatMap(\n (packageName) =>\n listInternalPackages(\n packagesRegistry[packageName].manifest,\n packagesRegistry,\n { includeDevDependencies }\n )\n );\n\n return uniq(internalPackageNames.concat(nestedInternalPackageNames));\n}\n"],"mappings":";;;AACA,OAAOA,cAAa;AACpB,OAAO,gBAAgB;;;ACFvB,OAAOC,UAAQ;AACf,OAAOC,aAAY;AACnB,OAAOC,YAAU;AACjB,SAAS,cAAc;;;ACHvB,OAAOC,SAAQ;AACf,OAAOC,aAAY;AACnB,OAAOC,WAAU;AACjB,SAAS,eAAe;;;ACHxB,OAAO,WAAW;AAelB,IAAI,kBAA0B;AAAA,EAC5B,SAAS,MAAiB;AACxB,YAAQ,IAAI,MAAM,KAAK,OAAO,GAAG,GAAG,IAAI;AAAA,EAC1C;AAAA,EACA,QAAQ,MAAiB;AACvB,YAAQ,IAAI,MAAM,MAAM,MAAM,GAAG,GAAG,IAAI;AAAA,EAC1C;AAAA,EACA,QAAQ,MAAiB;AACvB,YAAQ,IAAI,MAAM,OAAO,SAAS,GAAG,GAAG,IAAI;AAAA,EAC9C;AAAA,EACA,SAAS,MAAiB;AACxB,YAAQ,IAAI,MAAM,IAAI,OAAO,GAAG,GAAG,IAAI;AAAA,EACzC;AACF;AAEA,IAAM,UAAkB;AAAA,EACtB,SAAS,MAAiB;AACxB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":["console","fs","assert","path","fs","assert","path","path","fs","fs","fs","path","path","fs","path","fs","path","fs","path","path","fs","path","stdout","path","fs","fs","fs","fs","path","fs","fs","path","path","fs","assert","path","path","path","assert","fs","execSync","path","path","fs","execSync","omit","pick","path","fs","path","path","fs","path","path","packageManager","path","path","path","packageManager","omit","pick","fs","path","path","fs","assert","assert","fs","path","path","fs","fs","path","join","join","path","fs","fs","path","assert","path","packageManager","path","assert","path","fs","path","assert","fs","packageManager","console"]}
1
+ {"version":3,"sources":["../src/isolate-bin.ts","../src/isolate.ts","../src/lib/config.ts","../src/lib/logger.ts","../src/lib/utils/get-dirname.ts","../src/lib/utils/get-error-message.ts","../src/lib/utils/get-relative-path.ts","../src/lib/utils/inspect-value.ts","../src/lib/utils/is-rush-workspace.ts","../src/lib/utils/json.ts","../src/lib/utils/pack.ts","../src/lib/package-manager/index.ts","../src/lib/package-manager/helpers/infer-from-files.ts","../src/lib/utils/get-major-version.ts","../src/lib/package-manager/names.ts","../src/lib/package-manager/helpers/infer-from-manifest.ts","../src/lib/utils/unpack.ts","../src/lib/utils/yaml.ts","../src/lib/lockfile/helpers/generate-npm-lockfile.ts","../src/lib/lockfile/helpers/generate-pnpm-lockfile.ts","../src/lib/lockfile/helpers/pnpm-map-importer.ts","../src/lib/lockfile/helpers/generate-yarn-lockfile.ts","../src/lib/lockfile/process-lockfile.ts","../src/lib/manifest/adapt-target-package-manifest.ts","../src/lib/manifest/helpers/adapt-internal-package-manifests.ts","../src/lib/manifest/io.ts","../src/lib/manifest/helpers/patch-internal-entries.ts","../src/lib/manifest/helpers/adapt-manifest-internal-deps.ts","../src/lib/manifest/helpers/adopt-pnpm-fields-from-root.ts","../src/lib/output/get-build-output-dir.ts","../src/lib/output/pack-dependencies.ts","../src/lib/output/process-build-output-files.ts","../src/lib/output/unpack-dependencies.ts","../src/lib/registry/create-packages-registry.ts","../src/lib/registry/helpers/find-packages-globs.ts","../src/lib/registry/list-internal-packages.ts"],"sourcesContent":["#!/usr/bin/env node\nimport console from \"node:console\";\nimport sourceMaps from \"source-map-support\";\nimport { isolate } from \"./isolate\";\n\nsourceMaps.install();\n\nasync function run() {\n await isolate();\n}\n\nrun().catch((err) => {\n if (err instanceof Error) {\n console.error(err.stack);\n process.exit(1);\n } else {\n console.error(err);\n }\n});\n","import fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport { unique } from \"remeda\";\nimport type { IsolateConfig } from \"./lib/config\";\nimport { resolveConfig, setUserConfig } from \"./lib/config\";\nimport { processLockfile } from \"./lib/lockfile\";\nimport type { Logger } from \"./lib/logger\";\nimport { setLogLevel, setLogger, useLogger } from \"./lib/logger\";\nimport {\n adaptInternalPackageManifests,\n adaptTargetPackageManifest,\n readManifest,\n writeManifest,\n} from \"./lib/manifest\";\nimport {\n getBuildOutputDir,\n packDependencies,\n processBuildOutputFiles,\n unpackDependencies,\n} from \"./lib/output\";\nimport { detectPackageManager, shouldUsePnpmPack } from \"./lib/package-manager\";\nimport { getVersion } from \"./lib/package-manager/helpers/infer-from-files\";\nimport { createPackagesRegistry, listInternalPackages } from \"./lib/registry\";\nimport type { PackageManifest } from \"./lib/types\";\nimport {\n getDirname,\n getRootRelativePath,\n isRushWorkspace,\n readTypedJson,\n writeTypedYamlSync,\n} from \"./lib/utils\";\n\nconst __dirname = getDirname(import.meta.url);\n\nexport async function isolate(\n options: { config?: IsolateConfig; logger?: Logger } = {}\n) {\n if (options.logger) {\n setLogger(options.logger);\n }\n\n if (options.config) {\n setUserConfig(options.config);\n }\n\n const config = resolveConfig();\n\n setLogLevel(config.logLevel);\n\n const log = useLogger();\n\n const { version: libraryVersion } = await readTypedJson<PackageManifest>(\n path.join(path.join(__dirname, \"..\", \"package.json\"))\n );\n\n log.info(\"Using isolate-package version\", libraryVersion);\n\n /**\n * If a targetPackagePath is set, we assume the configuration lives in the\n * root of the workspace. If targetPackagePath is undefined (the default), we\n * assume that the configuration lives in the target package directory.\n */\n const targetPackageDir = config.targetPackagePath\n ? path.join(process.cwd(), config.targetPackagePath)\n : process.cwd();\n\n const workspaceRootDir = config.targetPackagePath\n ? process.cwd()\n : path.join(targetPackageDir, config.workspaceRoot);\n\n const buildOutputDir = await getBuildOutputDir(targetPackageDir);\n\n assert(\n fs.existsSync(buildOutputDir),\n `Failed to find build output path at ${buildOutputDir}. Please make sure you build the source before isolating it.`\n );\n\n log.debug(\"Workspace root resolved to\", workspaceRootDir);\n log.debug(\n \"Isolate target package\",\n getRootRelativePath(targetPackageDir, workspaceRootDir)\n );\n\n const isolateDir = path.join(targetPackageDir, config.isolateDirName);\n\n log.debug(\n \"Isolate output directory\",\n getRootRelativePath(isolateDir, workspaceRootDir)\n );\n\n if (fs.existsSync(isolateDir)) {\n await fs.remove(isolateDir);\n log.debug(\"Cleaned the existing isolate output directory\");\n }\n\n await fs.ensureDir(isolateDir);\n\n const tmpDir = path.join(isolateDir, \"__tmp\");\n await fs.ensureDir(tmpDir);\n\n const targetPackageManifest = await readTypedJson<PackageManifest>(\n path.join(targetPackageDir, \"package.json\")\n );\n\n const packageManager = detectPackageManager(workspaceRootDir);\n\n log.debug(\n \"Detected package manager\",\n packageManager.name,\n packageManager.version\n );\n\n if (shouldUsePnpmPack()) {\n log.debug(\"Use PNPM pack instead of NPM pack\");\n }\n\n /**\n * Build a packages registry so we can find the workspace packages by name and\n * have access to their manifest files and relative paths.\n */\n const packagesRegistry = await createPackagesRegistry(\n workspaceRootDir,\n config.workspacePackages\n );\n\n const internalPackageNames = listInternalPackages(\n targetPackageManifest,\n packagesRegistry,\n {\n includeDevDependencies: config.includeDevDependencies,\n }\n );\n\n const packedFilesByName = await packDependencies({\n internalPackageNames,\n packagesRegistry,\n packDestinationDir: tmpDir,\n });\n\n await unpackDependencies(\n packedFilesByName,\n packagesRegistry,\n tmpDir,\n isolateDir\n );\n\n /** Adapt the manifest files for all the unpacked local dependencies */\n await adaptInternalPackageManifests(\n internalPackageNames,\n packagesRegistry,\n isolateDir\n );\n\n /** Pack the target package directory, and unpack it in the isolate location */\n await processBuildOutputFiles({\n targetPackageDir,\n tmpDir,\n isolateDir,\n });\n\n /**\n * Copy the target manifest file to the isolate location and adapt its\n * workspace dependencies to point to the isolated packages.\n */\n const outputManifest = await adaptTargetPackageManifest({\n manifest: targetPackageManifest,\n packagesRegistry,\n workspaceRootDir,\n });\n\n await writeManifest(isolateDir, outputManifest);\n\n /** Generate an isolated lockfile based on the original one */\n const usedFallbackToNpm = await processLockfile({\n workspaceRootDir,\n isolateDir,\n packagesRegistry,\n internalDepPackageNames: internalPackageNames,\n targetPackageDir,\n targetPackageName: targetPackageManifest.name,\n targetPackageManifest: outputManifest,\n });\n\n if (usedFallbackToNpm) {\n /**\n * When we fall back to NPM, we set the manifest package manager to the\n * available NPM version.\n */\n const manifest = await readManifest(isolateDir);\n\n const npmVersion = getVersion(\"npm\");\n manifest.packageManager = `npm@${npmVersion}`;\n\n await writeManifest(isolateDir, manifest);\n }\n\n if (packageManager.name === \"pnpm\") {\n /**\n * PNPM doesn't install dependencies of packages that are linked via link:\n * or file: specifiers. It requires the directory to be configured as a\n * workspace, so we copy the workspace config file to the isolate output.\n *\n * Rush doesn't have a pnpm-workspace.yaml file, so we generate one.\n */\n if (isRushWorkspace(workspaceRootDir)) {\n const packagesFolderNames = unique(\n internalPackageNames.map(\n (name) => path.parse(packagesRegistry[name].rootRelativeDir).dir\n )\n );\n\n log.debug(\"Generating pnpm-workspace.yaml for Rush workspace\");\n log.debug(\"Packages folder names:\", packagesFolderNames);\n\n const packages = packagesFolderNames.map((x) => path.join(x, \"/*\"));\n\n await writeTypedYamlSync(path.join(isolateDir, \"pnpm-workspace.yaml\"), {\n packages,\n });\n } else {\n fs.copyFileSync(\n path.join(workspaceRootDir, \"pnpm-workspace.yaml\"),\n path.join(isolateDir, \"pnpm-workspace.yaml\")\n );\n }\n }\n /**\n * If there is an .npmrc file in the workspace root, copy it to the isolate\n * because the settings there could affect how the lockfile is resolved. Note\n * that .npmrc is used by both NPM and PNPM for configuration.\n *\n * See also: https://pnpm.io/npmrc\n */\n const npmrcPath = path.join(workspaceRootDir, \".npmrc\");\n\n if (fs.existsSync(npmrcPath)) {\n fs.copyFileSync(npmrcPath, path.join(isolateDir, \".npmrc\"));\n log.debug(\"Copied .npmrc file to the isolate output\");\n }\n\n /**\n * Clean up. Only so this in the happy path, so we can look at the temp folder\n * when thing go wrong.\n */\n log.debug(\n \"Deleting temp directory\",\n getRootRelativePath(tmpDir, workspaceRootDir)\n );\n await fs.remove(tmpDir);\n\n log.info(\"Isolate completed at\", isolateDir);\n\n return isolateDir;\n}\n","import fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport { isEmpty } from \"remeda\";\nimport { setLogLevel, useLogger } from \"./logger\";\nimport { inspectValue, readTypedJsonSync } from \"./utils\";\n\nexport type IsolateConfigResolved = {\n buildDirName?: string;\n includeDevDependencies: boolean;\n includePatchedDependencies: boolean;\n isolateDirName: string;\n logLevel: \"info\" | \"debug\" | \"warn\" | \"error\";\n targetPackagePath?: string;\n tsconfigPath: string;\n workspacePackages?: string[];\n workspaceRoot: string;\n forceNpm: boolean;\n pickFromScripts?: string[];\n omitFromScripts?: string[];\n omitPackageManager?: boolean;\n};\n\nexport type IsolateConfig = Partial<IsolateConfigResolved>;\n\nconst configDefaults: IsolateConfigResolved = {\n buildDirName: undefined,\n includeDevDependencies: false,\n includePatchedDependencies: false,\n isolateDirName: \"isolate\",\n logLevel: \"info\",\n targetPackagePath: undefined,\n tsconfigPath: \"./tsconfig.json\",\n workspacePackages: undefined,\n workspaceRoot: \"../..\",\n forceNpm: false,\n pickFromScripts: undefined,\n omitFromScripts: undefined,\n omitPackageManager: false,\n};\n\n/**\n * Only initialize the configuration once, and keeping it here for subsequent\n * calls to getConfig.\n */\nlet _resolvedConfig: IsolateConfigResolved | undefined;\n\nlet _user_defined_config: IsolateConfig | undefined;\n\nconst validConfigKeys = Object.keys(configDefaults);\n\nconst CONFIG_FILE_NAME = \"isolate.config.json\";\n\nexport type LogLevel = IsolateConfigResolved[\"logLevel\"];\n\nexport function setUserConfig(config: IsolateConfig) {\n _user_defined_config = config;\n\n if (config.logLevel) {\n setLogLevel(config.logLevel);\n }\n}\n\nexport function useConfig() {\n if (_resolvedConfig) {\n return _resolvedConfig;\n } else {\n throw new Error(\"Called useConfig before config was made available\");\n }\n}\n\n/**\n * Resolve configuration based on user config and defaults. If setConfig was\n * called before this, it does not attempt to read a config file from disk.\n */\nexport function resolveConfig(): IsolateConfigResolved {\n if (_resolvedConfig) {\n return _resolvedConfig;\n }\n\n setLogLevel(process.env.DEBUG_ISOLATE_CONFIG ? \"debug\" : \"info\");\n\n const log = useLogger();\n\n const configFilePath = path.join(process.cwd(), CONFIG_FILE_NAME);\n\n if (_user_defined_config) {\n log.debug(`Using user defined config:`, inspectValue(_user_defined_config));\n } else {\n log.debug(`Attempting to load config from ${configFilePath}`);\n\n _user_defined_config = fs.existsSync(configFilePath)\n ? readTypedJsonSync<IsolateConfig>(configFilePath)\n : {};\n }\n\n const foreignKeys = Object.keys(_user_defined_config).filter(\n (key) => !validConfigKeys.includes(key)\n );\n\n if (!isEmpty(foreignKeys)) {\n log.warn(`Found invalid config settings:`, foreignKeys.join(\", \"));\n }\n\n const config = Object.assign(\n {},\n configDefaults,\n _user_defined_config\n ) satisfies IsolateConfigResolved;\n\n log.debug(\"Using configuration:\", inspectValue(config));\n\n _resolvedConfig = config;\n return config;\n}\n\n/**\n * Get only the configuration that the user set explicitly in the config file or\n * passed via arguments to isolate().\n */\nexport function getUserDefinedConfig(): IsolateConfig {\n assert(\n _user_defined_config,\n \"Called getUserDefinedConfig before user config was made available\"\n );\n\n return _user_defined_config;\n}\n","import chalk from \"chalk\";\nimport type { IsolateConfigResolved, LogLevel } from \"./config\";\n/**\n * The Logger defines an interface that can be used to pass in a different\n * logger object in order to intercept all the logging output. We keep the\n * handlers separate from the logger object itself, so that we can change the\n * handlers but do not bother the user with having to handle logLevel.\n */\nexport type Logger = {\n debug(...args: unknown[]): void;\n info(...args: unknown[]): void;\n warn(...args: unknown[]): void;\n error(...args: unknown[]): void;\n};\n\nlet _loggerHandlers: Logger = {\n debug(...args: unknown[]) {\n console.log(chalk.blue(\"debug\"), ...args);\n },\n info(...args: unknown[]) {\n console.log(chalk.green(\"info\"), ...args);\n },\n warn(...args: unknown[]) {\n console.log(chalk.yellow(\"warning\"), ...args);\n },\n error(...args: unknown[]) {\n console.log(chalk.red(\"error\"), ...args);\n },\n};\n\nconst _logger: Logger = {\n debug(...args: unknown[]) {\n if (_logLevel === \"debug\") {\n _loggerHandlers.debug(...args);\n }\n },\n info(...args: unknown[]) {\n if (_logLevel === \"debug\" || _logLevel === \"info\") {\n _loggerHandlers.info(...args);\n }\n },\n warn(...args: unknown[]) {\n if (_logLevel === \"debug\" || _logLevel === \"info\" || _logLevel === \"warn\") {\n _loggerHandlers.warn(...args);\n }\n },\n error(...args: unknown[]) {\n _loggerHandlers.error(...args);\n },\n};\n\nlet _logLevel: LogLevel = \"info\";\n\nexport function setLogger(logger: Logger) {\n _loggerHandlers = logger;\n return _logger;\n}\n\nexport function setLogLevel(\n logLevel: IsolateConfigResolved[\"logLevel\"]\n): Logger {\n _logLevel = logLevel;\n return _logger;\n}\n\nexport function useLogger() {\n return _logger;\n}\n","import { fileURLToPath } from \"url\";\n\n/**\n * Calling context should pass in import.meta.url and the function will return\n * the equivalent of __dirname in Node/CommonJs.\n */\nexport function getDirname(importMetaUrl: string) {\n return fileURLToPath(new URL(\".\", importMetaUrl));\n}\n","type ErrorWithMessage = {\n message: string;\n};\n\nexport function getErrorMessage(error: unknown) {\n return toErrorWithMessage(error).message;\n}\n\nfunction isErrorWithMessage(error: unknown): error is ErrorWithMessage {\n return typeof error === \"object\" && error !== null && \"message\" in error;\n}\n\nfunction toErrorWithMessage(maybeError: unknown): ErrorWithMessage {\n if (isErrorWithMessage(maybeError)) return maybeError;\n\n try {\n return new Error(JSON.stringify(maybeError));\n } catch {\n /**\n * Fallback in case there’s an error in stringify which can happen with\n * circular references.\n */\n return new Error(String(maybeError));\n }\n}\n","import { join } from \"node:path\";\n\nexport function getRootRelativePath(path: string, rootPath: string) {\n const strippedPath = path.replace(rootPath, \"\");\n\n return join(\"(root)\", strippedPath);\n}\n\nexport function getIsolateRelativePath(path: string, isolatePath: string) {\n const strippedPath = path.replace(isolatePath, \"\");\n\n return join(\"(isolate)\", strippedPath);\n}\n","import { inspect } from \"node:util\";\n\nexport function inspectValue(value: unknown) {\n return inspect(value, false, 16, true);\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Detect if this is a Rush monorepo. They use a very different structure so\n * there are multiple places where we need to make exceptions based on this.\n */\nexport function isRushWorkspace(workspaceRootDir: string) {\n return fs.existsSync(path.join(workspaceRootDir, \"rush.json\"));\n}\n","import fs from \"fs-extra\";\nimport stripJsonComments from \"strip-json-comments\";\nimport { getErrorMessage } from \"./get-error-message\";\n\n/** @todo Pass in zod schema and validate */\nexport function readTypedJsonSync<T>(filePath: string) {\n try {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const data = JSON.parse(\n stripJsonComments(rawContent, { trailingCommas: true })\n ) as T;\n return data;\n } catch (err) {\n throw new Error(\n `Failed to read JSON from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n\nexport async function readTypedJson<T>(filePath: string) {\n try {\n const rawContent = await fs.readFile(filePath, \"utf-8\");\n const data = JSON.parse(\n stripJsonComments(rawContent, { trailingCommas: true })\n ) as T;\n return data;\n } catch (err) {\n throw new Error(\n `Failed to read JSON from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n","import { exec } from \"node:child_process\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { useLogger } from \"../logger\";\nimport { shouldUsePnpmPack } from \"../package-manager\";\nimport { getErrorMessage } from \"./get-error-message\";\n\nexport async function pack(srcDir: string, dstDir: string) {\n const log = useLogger();\n\n const execOptions = {\n maxBuffer: 10 * 1024 * 1024,\n };\n\n const previousCwd = process.cwd();\n process.chdir(srcDir);\n\n /**\n * PNPM pack seems to be a lot faster than NPM pack, so when PNPM is detected\n * we use that instead.\n */\n const stdout = shouldUsePnpmPack()\n ? await new Promise<string>((resolve, reject) => {\n exec(\n `pnpm pack --pack-destination \"${dstDir}\"`,\n execOptions,\n (err, stdout) => {\n if (err) {\n log.error(getErrorMessage(err));\n return reject(err);\n }\n\n resolve(stdout);\n }\n );\n })\n : await new Promise<string>((resolve, reject) => {\n exec(\n `npm pack --pack-destination \"${dstDir}\"`,\n execOptions,\n (err, stdout) => {\n if (err) {\n return reject(err);\n }\n\n resolve(stdout);\n }\n );\n });\n\n const fileName = path.basename(stdout.trim());\n\n const filePath = path.join(dstDir, fileName);\n\n if (!fs.existsSync(filePath)) {\n log.error(\n `The response from pack could not be resolved to an existing file: ${filePath}`\n );\n } else {\n log.debug(`Packed (temp)/${fileName}`);\n }\n\n process.chdir(previousCwd);\n\n /**\n * Return the path anyway even if it doesn't validate. A later stage will wait\n * for the file to occur still. Not sure if this makes sense. Maybe we should\n * stop at the validation error...\n */\n return filePath;\n}\n","import path from \"node:path\";\nimport { isRushWorkspace } from \"../utils/is-rush-workspace\";\nimport { inferFromFiles, inferFromManifest } from \"./helpers\";\nimport type { PackageManager } from \"./names\";\n\nexport * from \"./names\";\n\nlet packageManager: PackageManager | undefined;\n\nexport function usePackageManager() {\n if (!packageManager) {\n throw Error(\n \"No package manager detected. Make sure to call detectPackageManager() before usePackageManager()\"\n );\n }\n\n return packageManager;\n}\n\n/**\n * First we check if the package manager is declared in the manifest. If it is,\n * we get the name and version from there. Otherwise we'll search for the\n * different lockfiles and ask the OS to report the installed version.\n */\nexport function detectPackageManager(workspaceRootDir: string): PackageManager {\n if (isRushWorkspace(workspaceRootDir)) {\n packageManager = inferFromFiles(\n path.join(workspaceRootDir, \"common/config/rush\")\n );\n } else {\n /**\n * Disable infer from manifest for now. I doubt it is useful after all but\n * I'll keep the code as a reminder.\n */\n packageManager =\n inferFromManifest(workspaceRootDir) ?? inferFromFiles(workspaceRootDir);\n }\n\n return packageManager;\n}\n\nexport function shouldUsePnpmPack() {\n const { name, majorVersion } = usePackageManager();\n\n return name === \"pnpm\" && majorVersion >= 8;\n}\n","import fs from \"fs-extra\";\nimport { execSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport { getErrorMessage } from \"~/lib/utils\";\nimport { getMajorVersion } from \"~/lib/utils/get-major-version\";\nimport type { PackageManager, PackageManagerName } from \"../names\";\nimport { getLockfileFileName, supportedPackageManagerNames } from \"../names\";\n\nexport function inferFromFiles(workspaceRoot: string): PackageManager {\n for (const name of supportedPackageManagerNames) {\n const lockfileName = getLockfileFileName(name);\n\n if (fs.existsSync(path.join(workspaceRoot, lockfileName))) {\n try {\n const version = getVersion(name);\n\n return { name, version, majorVersion: getMajorVersion(version) };\n } catch (err) {\n throw new Error(\n `Failed to find package manager version for ${name}: ${getErrorMessage(err)}`\n );\n }\n }\n }\n\n /** If no lockfile was found, it could be that there is an npm shrinkwrap file. */\n if (fs.existsSync(path.join(workspaceRoot, \"npm-shrinkwrap.json\"))) {\n const version = getVersion(\"npm\");\n\n return { name: \"npm\", version, majorVersion: getMajorVersion(version) };\n }\n\n throw new Error(`Failed to detect package manager`);\n}\n\nexport function getVersion(packageManagerName: PackageManagerName): string {\n const buffer = execSync(`${packageManagerName} --version`);\n return buffer.toString().trim();\n}\n","export function getMajorVersion(version: string) {\n return parseInt(version.split(\".\")[0], 10);\n}\n","export const supportedPackageManagerNames = [\n \"pnpm\",\n \"yarn\",\n \"npm\",\n \"bun\",\n] as const;\n\nexport type PackageManagerName = (typeof supportedPackageManagerNames)[number];\n\nexport type PackageManager = {\n name: PackageManagerName;\n version: string;\n majorVersion: number;\n packageManagerString?: string;\n};\n\nexport function getLockfileFileName(name: PackageManagerName) {\n switch (name) {\n case \"bun\":\n return \"bun.lockb\";\n case \"pnpm\":\n return \"pnpm-lock.yaml\";\n case \"yarn\":\n return \"yarn.lock\";\n case \"npm\":\n return \"package-lock.json\";\n }\n}\n","import fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport { useLogger } from \"~/lib/logger\";\nimport { getMajorVersion } from \"~/lib/utils/get-major-version\";\nimport type { PackageManifest } from \"../../types\";\nimport { readTypedJsonSync } from \"../../utils\";\nimport type { PackageManagerName } from \"../names\";\nimport { getLockfileFileName, supportedPackageManagerNames } from \"../names\";\n\nexport function inferFromManifest(workspaceRoot: string) {\n const log = useLogger();\n\n const { packageManager: packageManagerString } =\n readTypedJsonSync<PackageManifest>(\n path.join(workspaceRoot, \"package.json\")\n );\n\n if (!packageManagerString) {\n log.debug(\"No packageManager field found in root manifest\");\n return;\n }\n\n const [name, version = \"*\"] = packageManagerString.split(\"@\") as [\n PackageManagerName,\n string,\n ];\n\n assert(\n supportedPackageManagerNames.includes(name),\n `Package manager \"${name}\" is not currently supported`\n );\n\n const lockfileName = getLockfileFileName(name);\n\n assert(\n fs.existsSync(path.join(workspaceRoot, lockfileName)),\n `Manifest declares ${name} to be the packageManager, but failed to find ${lockfileName} in workspace root`\n );\n\n return {\n name,\n version,\n majorVersion: getMajorVersion(version),\n packageManagerString,\n };\n}\n","import fs from \"fs-extra\";\nimport tar from \"tar-fs\";\nimport { createGunzip } from \"zlib\";\n\nexport async function unpack(filePath: string, unpackDir: string) {\n await new Promise<void>((resolve, reject) => {\n fs.createReadStream(filePath)\n .pipe(createGunzip())\n .pipe(tar.extract(unpackDir))\n .on(\"finish\", () => resolve())\n .on(\"error\", (err) => reject(err));\n });\n}\n","import fs from \"fs-extra\";\nimport yaml from \"yaml\";\nimport { getErrorMessage } from \"./get-error-message\";\n\nexport function readTypedYamlSync<T>(filePath: string) {\n try {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const data = yaml.parse(rawContent);\n /** @todo Add some zod validation maybe */\n return data as T;\n } catch (err) {\n throw new Error(\n `Failed to read YAML from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n\nexport function writeTypedYamlSync<T>(filePath: string, content: T) {\n /** @todo Add some zod validation maybe */\n fs.writeFileSync(filePath, yaml.stringify(content), \"utf-8\");\n}\n","import Arborist from \"@npmcli/arborist\";\nimport fs from \"fs-extra\";\nimport path from \"node:path\";\nimport { useLogger } from \"~/lib/logger\";\nimport { getErrorMessage } from \"~/lib/utils\";\n\n/**\n * Generate an isolated / pruned lockfile, based on the contents of installed\n * node_modules from the monorepo root plus the adapted package manifest in the\n * isolate directory.\n */\nexport async function generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n}: {\n workspaceRootDir: string;\n isolateDir: string;\n}) {\n const log = useLogger();\n\n log.debug(\"Generating NPM lockfile...\");\n\n const nodeModulesPath = path.join(workspaceRootDir, \"node_modules\");\n\n try {\n if (!fs.existsSync(nodeModulesPath)) {\n throw new Error(`Failed to find node_modules at ${nodeModulesPath}`);\n }\n\n const arborist = new Arborist({ path: isolateDir });\n\n const { meta } = await arborist.buildIdealTree();\n\n meta?.commit();\n\n const lockfilePath = path.join(isolateDir, \"package-lock.json\");\n\n await fs.writeFile(lockfilePath, String(meta));\n\n log.debug(\"Created lockfile at\", lockfilePath);\n } catch (err) {\n log.error(`Failed to generate lockfile: ${getErrorMessage(err)}`);\n throw err;\n }\n}\n","import assert from \"node:assert\";\nimport path from \"node:path\";\nimport {\n getLockfileImporterId as getLockfileImporterId_v8,\n readWantedLockfile as readWantedLockfile_v8,\n writeWantedLockfile as writeWantedLockfile_v8,\n} from \"pnpm_lockfile_file_v8\";\nimport {\n getLockfileImporterId as getLockfileImporterId_v9,\n readWantedLockfile as readWantedLockfile_v9,\n writeWantedLockfile as writeWantedLockfile_v9,\n} from \"pnpm_lockfile_file_v9\";\nimport { pruneLockfile as pruneLockfile_v8 } from \"pnpm_prune_lockfile_v8\";\nimport { pruneLockfile as pruneLockfile_v9 } from \"pnpm_prune_lockfile_v9\";\nimport { pick } from \"remeda\";\nimport { useConfig } from \"~/lib/config\";\nimport { useLogger } from \"~/lib/logger\";\nimport type { PackageManifest, PackagesRegistry } from \"~/lib/types\";\nimport { getErrorMessage, isRushWorkspace } from \"~/lib/utils\";\nimport { pnpmMapImporter } from \"./pnpm-map-importer\";\n\nexport async function generatePnpmLockfile({\n workspaceRootDir,\n targetPackageDir,\n isolateDir,\n internalDepPackageNames,\n packagesRegistry,\n targetPackageManifest,\n majorVersion,\n}: {\n workspaceRootDir: string;\n targetPackageDir: string;\n isolateDir: string;\n internalDepPackageNames: string[];\n packagesRegistry: PackagesRegistry;\n targetPackageManifest: PackageManifest;\n majorVersion: number;\n}) {\n /**\n * For now we will assume that the lockfile format might not change in the\n * versions after 9, because we might get lucky. If it does change, things\n * would break either way.\n */\n const useReadVersion9 = majorVersion >= 9;\n\n const { includeDevDependencies, includePatchedDependencies } = useConfig();\n const log = useLogger();\n\n log.debug(\"Generating PNPM lockfile...\");\n\n try {\n const isRush = isRushWorkspace(workspaceRootDir);\n\n const lockfile = useReadVersion9\n ? await readWantedLockfile_v9(\n isRush\n ? path.join(workspaceRootDir, \"common/config/rush\")\n : workspaceRootDir,\n {\n ignoreIncompatible: false,\n }\n )\n : await readWantedLockfile_v8(\n isRush\n ? path.join(workspaceRootDir, \"common/config/rush\")\n : workspaceRootDir,\n {\n ignoreIncompatible: false,\n }\n );\n\n assert(lockfile, `No input lockfile found at ${workspaceRootDir}`);\n\n const [lockfileMajorVersion] = String(lockfile.lockfileVersion).split(\".\");\n\n const useLockfileVersion9 = lockfileMajorVersion >= \"9\";\n\n const targetImporterId = useLockfileVersion9\n ? getLockfileImporterId_v9(workspaceRootDir, targetPackageDir)\n : getLockfileImporterId_v8(workspaceRootDir, targetPackageDir);\n\n const directoryByPackageName = Object.fromEntries(\n internalDepPackageNames.map((name) => {\n const pkg = packagesRegistry[name];\n assert(pkg, `Package ${name} not found in packages registry`);\n\n return [name, pkg.rootRelativeDir];\n })\n );\n\n const relevantImporterIds = [\n targetImporterId,\n /**\n * The directory paths happen to correspond with what PNPM calls the\n * importer ids in the context of a lockfile.\n */\n ...Object.values(directoryByPackageName),\n ];\n\n log.debug(\"Relevant importer ids:\", relevantImporterIds);\n\n /**\n * In a Rush workspace the original lockfile is not in the root, so the\n * importerIds have to be prefixed with `../../`, but that's not how they\n * should be stored in the isolated lockfile, so we use the prefixed ids\n * only for parsing.\n */\n const relevantImporterIdsWithPrefix = relevantImporterIds.map((x) =>\n isRush ? `../../${x}` : x\n );\n\n lockfile.importers = Object.fromEntries(\n Object.entries(\n pick(lockfile.importers, relevantImporterIdsWithPrefix)\n ).map(([prefixedImporterId, importer]) => {\n const importerId = isRush\n ? prefixedImporterId.replace(\"../../\", \"\")\n : prefixedImporterId;\n\n if (importerId === targetImporterId) {\n log.debug(\"Setting target package importer on root\");\n\n return [\n \".\",\n pnpmMapImporter(\".\", importer, {\n includeDevDependencies,\n includePatchedDependencies,\n directoryByPackageName,\n }),\n ];\n }\n\n log.debug(\"Setting internal package importer:\", importerId);\n\n return [\n importerId,\n pnpmMapImporter(importerId, importer, {\n includeDevDependencies,\n includePatchedDependencies,\n directoryByPackageName,\n }),\n ];\n })\n );\n\n log.debug(\"Pruning the lockfile\");\n\n const prunedLockfile = useLockfileVersion9\n ? await pruneLockfile_v9(lockfile, targetPackageManifest, \".\")\n : await pruneLockfile_v8(lockfile, targetPackageManifest, \".\");\n\n /** Pruning seems to remove the overrides from the lockfile */\n if (lockfile.overrides) {\n prunedLockfile.overrides = lockfile.overrides;\n }\n\n /**\n * Don't know how to map the patched dependencies yet, so we just include\n * them but I don't think it would work like this. The important thing for\n * now is that they are omitted by default, because that is the most common\n * use case.\n */\n const patchedDependencies = includePatchedDependencies\n ? lockfile.patchedDependencies\n : undefined;\n\n useLockfileVersion9\n ? await writeWantedLockfile_v9(isolateDir, {\n ...prunedLockfile,\n patchedDependencies,\n })\n : await writeWantedLockfile_v8(isolateDir, {\n ...prunedLockfile,\n patchedDependencies,\n });\n\n log.debug(\"Created lockfile at\", path.join(isolateDir, \"pnpm-lock.yaml\"));\n } catch (err) {\n log.error(`Failed to generate lockfile: ${getErrorMessage(err)}`);\n throw err;\n }\n}\n","import path from \"node:path\";\nimport type {\n ProjectSnapshot,\n ResolvedDependencies,\n} from \"pnpm_lockfile_file_v8\";\n\nimport { mapValues } from \"remeda\";\n\n/** Convert dependency links */\nexport function pnpmMapImporter(\n importerPath: string,\n { dependencies, devDependencies, ...rest }: ProjectSnapshot,\n {\n includeDevDependencies,\n directoryByPackageName,\n }: {\n includeDevDependencies: boolean;\n includePatchedDependencies: boolean;\n directoryByPackageName: { [packageName: string]: string };\n }\n): ProjectSnapshot {\n return {\n dependencies: dependencies\n ? pnpmMapDependenciesLinks(\n importerPath,\n dependencies,\n directoryByPackageName\n )\n : undefined,\n devDependencies:\n includeDevDependencies && devDependencies\n ? pnpmMapDependenciesLinks(\n importerPath,\n devDependencies,\n directoryByPackageName\n )\n : undefined,\n ...rest,\n };\n}\n\nfunction pnpmMapDependenciesLinks(\n importerPath: string,\n def: ResolvedDependencies,\n directoryByPackageName: { [packageName: string]: string }\n): ResolvedDependencies {\n return mapValues(def, (value, key) => {\n if (!value.startsWith(\"link:\")) {\n return value;\n }\n\n const relativePath = path.relative(\n importerPath,\n directoryByPackageName[key]\n );\n\n return relativePath.startsWith(\".\")\n ? `link:${relativePath}`\n : `link:./${relativePath}`;\n });\n}\n","import fs from \"fs-extra\";\nimport { execSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport { useLogger } from \"~/lib/logger\";\nimport { getErrorMessage, isRushWorkspace } from \"~/lib/utils\";\n\n/**\n * Generate an isolated / pruned lockfile, based on the existing lockfile from\n * the monorepo root plus the adapted package manifest in the isolate\n * directory.\n */\nexport async function generateYarnLockfile({\n workspaceRootDir,\n isolateDir,\n}: {\n workspaceRootDir: string;\n isolateDir: string;\n}) {\n const log = useLogger();\n\n log.debug(\"Generating Yarn lockfile...\");\n\n const origLockfilePath = isRushWorkspace(workspaceRootDir)\n ? path.join(workspaceRootDir, \"common/config/rush\", \"yarn.lock\")\n : path.join(workspaceRootDir, \"yarn.lock\");\n\n const newLockfilePath = path.join(isolateDir, \"yarn.lock\");\n\n if (!fs.existsSync(origLockfilePath)) {\n throw new Error(`Failed to find lockfile at ${origLockfilePath}`);\n }\n\n log.debug(`Copy original yarn.lock to the isolate output`);\n\n try {\n await fs.copyFile(origLockfilePath, newLockfilePath);\n\n /**\n * Running install with the original lockfile in the same directory will\n * generate a pruned version of the lockfile.\n */\n log.debug(`Running local install`);\n execSync(`yarn install --cwd ${isolateDir}`);\n\n log.debug(\"Generated lockfile at\", newLockfilePath);\n } catch (err) {\n log.error(`Failed to generate lockfile: ${getErrorMessage(err)}`);\n throw err;\n }\n}\n","import { useLogger } from \"../logger\";\nimport { usePackageManager } from \"../package-manager\";\nimport type { PackageManifest, PackagesRegistry } from \"../types\";\nimport {\n generateNpmLockfile,\n generatePnpmLockfile,\n generateYarnLockfile,\n} from \"./helpers\";\n\n/**\n * Adapt the lockfile and write it to the isolate directory. Because we keep the\n * structure of packages in the isolate directory the same as they were in the\n * monorepo, the lockfile is largely still correct. The only things that need to\n * be done is to remove the root dependencies and devDependencies, and rename\n * the path to the target package to act as the new root.\n */\nexport async function processLockfile({\n workspaceRootDir,\n packagesRegistry,\n isolateDir,\n internalDepPackageNames,\n targetPackageDir,\n targetPackageManifest,\n}: {\n workspaceRootDir: string;\n packagesRegistry: PackagesRegistry;\n isolateDir: string;\n internalDepPackageNames: string[];\n targetPackageDir: string;\n targetPackageName: string;\n targetPackageManifest: PackageManifest;\n}) {\n const log = useLogger();\n\n const { name, majorVersion } = usePackageManager();\n let usedFallbackToNpm = false;\n\n switch (name) {\n case \"npm\": {\n await generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n });\n\n break;\n }\n case \"yarn\": {\n if (majorVersion === 1) {\n await generateYarnLockfile({\n workspaceRootDir,\n isolateDir,\n });\n } else {\n log.warn(\n \"Detected modern version of Yarn. Using NPM lockfile fallback.\"\n );\n\n await generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n });\n\n usedFallbackToNpm = true;\n }\n\n break;\n }\n case \"pnpm\": {\n await generatePnpmLockfile({\n workspaceRootDir,\n targetPackageDir,\n isolateDir,\n internalDepPackageNames,\n packagesRegistry,\n targetPackageManifest,\n majorVersion,\n });\n break;\n }\n case \"bun\": {\n log.warn(\n `Ouput lockfiles for Bun are not yet supported. Using NPM for output`\n );\n await generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n });\n\n usedFallbackToNpm = true;\n break;\n }\n default:\n log.warn(`Unexpected package manager ${name}. Using NPM for output`);\n await generateNpmLockfile({\n workspaceRootDir,\n isolateDir,\n });\n\n usedFallbackToNpm = true;\n }\n\n return usedFallbackToNpm;\n}\n","import { omit, pick } from \"remeda\";\nimport { useConfig } from \"../config\";\nimport { usePackageManager } from \"../package-manager\";\nimport type { PackageManifest, PackagesRegistry } from \"../types\";\nimport { adaptManifestInternalDeps, adoptPnpmFieldsFromRoot } from \"./helpers\";\n\n/**\n * Adapt the output package manifest, so that:\n *\n * - Its internal dependencies point to the isolated ./packages/* directory.\n * - The devDependencies are possibly removed\n * - Scripts are picked or omitted and otherwise removed\n */\nexport async function adaptTargetPackageManifest({\n manifest,\n packagesRegistry,\n workspaceRootDir,\n}: {\n manifest: PackageManifest;\n packagesRegistry: PackagesRegistry;\n workspaceRootDir: string;\n}) {\n const packageManager = usePackageManager();\n const {\n includeDevDependencies,\n pickFromScripts,\n omitFromScripts,\n omitPackageManager,\n } = useConfig();\n\n /** Dev dependencies are omitted by default */\n const inputManifest = includeDevDependencies\n ? manifest\n : omit(manifest, [\"devDependencies\"]);\n\n const adaptedManifest =\n packageManager.name === \"pnpm\"\n ? /**\n * For PNPM the output itself is a workspace so we can preserve the specifiers\n * with \"workspace:*\" in the output manifest, but we do want to adopt the\n * pnpm.overrides field from the root package.json.\n */\n await adoptPnpmFieldsFromRoot(inputManifest, workspaceRootDir)\n : /** For other package managers we replace the links to internal dependencies */\n adaptManifestInternalDeps({\n manifest: inputManifest,\n packagesRegistry,\n });\n\n return {\n ...adaptedManifest,\n /**\n * Adopt the package manager definition from the root manifest if available.\n * The option to omit is there because some platforms might not handle it\n * properly (Cloud Run, April 24th 2024, does not handle pnpm v9)\n */\n packageManager: omitPackageManager\n ? undefined\n : packageManager.packageManagerString,\n /**\n * Scripts are removed by default if not explicitly picked or omitted via\n * config.\n */\n scripts: pickFromScripts\n ? pick(manifest.scripts ?? {}, pickFromScripts)\n : omitFromScripts\n ? omit(manifest.scripts ?? {}, omitFromScripts)\n : undefined,\n };\n}\n","import path from \"node:path\";\nimport { omit } from \"remeda\";\nimport { usePackageManager } from \"~/lib/package-manager\";\nimport type { PackagesRegistry } from \"~/lib/types\";\nimport { writeManifest } from \"../io\";\nimport { adaptManifestInternalDeps } from \"./adapt-manifest-internal-deps\";\n\n/**\n * Adapt the manifest files of all the isolated internal packages (excluding the\n * target package), so that their dependencies point to the other isolated\n * packages in the same folder.\n */\nexport async function adaptInternalPackageManifests(\n internalPackageNames: string[],\n packagesRegistry: PackagesRegistry,\n isolateDir: string\n) {\n const packageManager = usePackageManager();\n\n await Promise.all(\n internalPackageNames.map(async (packageName) => {\n const { manifest, rootRelativeDir } = packagesRegistry[packageName];\n\n /** Dev dependencies and scripts are never included for internal deps */\n const strippedManifest = omit(manifest, [\"scripts\", \"devDependencies\"]);\n\n const outputManifest =\n packageManager.name === \"pnpm\"\n ? /**\n * For PNPM the output itself is a workspace so we can preserve the specifiers\n * with \"workspace:*\" in the output manifest.\n */\n strippedManifest\n : /** For other package managers we replace the links to internal dependencies */\n adaptManifestInternalDeps({\n manifest: strippedManifest,\n packagesRegistry,\n parentRootRelativeDir: rootRelativeDir,\n });\n\n await writeManifest(\n path.join(isolateDir, rootRelativeDir),\n outputManifest\n );\n })\n );\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport type { PackageManifest } from \"../types\";\nimport { readTypedJson } from \"../utils\";\n\nexport async function readManifest(packageDir: string) {\n return readTypedJson<PackageManifest>(path.join(packageDir, \"package.json\"));\n}\n\nexport async function writeManifest(\n outputDir: string,\n manifest: PackageManifest\n) {\n await fs.writeFile(\n path.join(outputDir, \"package.json\"),\n JSON.stringify(manifest, null, 2)\n );\n}\n","import path from \"node:path\";\nimport { useLogger } from \"../../logger\";\nimport type { PackagesRegistry } from \"../../types\";\n\nexport function patchInternalEntries(\n dependencies: Record<string, string>,\n packagesRegistry: PackagesRegistry,\n parentRootRelativeDir?: string\n) {\n const log = useLogger();\n const allWorkspacePackageNames = Object.keys(packagesRegistry);\n\n return Object.fromEntries(\n Object.entries(dependencies).map(([key, value]) => {\n if (allWorkspacePackageNames.includes(key)) {\n const def = packagesRegistry[key];\n\n /**\n * When nested internal dependencies are used (internal packages linking\n * to other internal packages), the parentRootRelativeDir will be passed\n * in, and we store the relative path to the isolate/packages\n * directory.\n *\n * For consistency we also write the other file paths starting with ./,\n * but it doesn't seem to be necessary for any package manager.\n */\n const relativePath = parentRootRelativeDir\n ? path.relative(parentRootRelativeDir, `./${def.rootRelativeDir}`)\n : `./${def.rootRelativeDir}`;\n\n const linkPath = `file:${relativePath}`;\n\n log.debug(`Linking dependency ${key} to ${linkPath}`);\n\n return [key, linkPath];\n } else {\n return [key, value];\n }\n })\n );\n}\n","import type { PackageManifest, PackagesRegistry } from \"~/lib/types\";\nimport { patchInternalEntries } from \"./patch-internal-entries\";\n\n/**\n * Replace the workspace version specifiers for internal dependency with file:\n * paths. Not needed for PNPM (because we configure the isolated output as a\n * workspace), but maybe still for NPM and Yarn.\n */\nexport function adaptManifestInternalDeps({\n manifest,\n packagesRegistry,\n parentRootRelativeDir,\n}: {\n manifest: PackageManifest;\n packagesRegistry: PackagesRegistry;\n parentRootRelativeDir?: string;\n}): PackageManifest {\n const { dependencies, devDependencies } = manifest;\n\n return {\n ...manifest,\n dependencies: dependencies\n ? patchInternalEntries(\n dependencies,\n packagesRegistry,\n parentRootRelativeDir\n )\n : undefined,\n devDependencies: devDependencies\n ? patchInternalEntries(\n devDependencies,\n packagesRegistry,\n parentRootRelativeDir\n )\n : undefined,\n };\n}\n","import type { ProjectManifest } from \"@pnpm/types\";\nimport path from \"path\";\nimport type { PackageManifest } from \"~/lib/types\";\nimport { isRushWorkspace, readTypedJson } from \"~/lib/utils\";\n\n/**\n * Adopts the `pnpm` fields from the root package manifest. Currently it only\n * takes overrides, because I don't know if any of the others are useful or\n * desired.\n */\nexport async function adoptPnpmFieldsFromRoot(\n targetPackageManifest: PackageManifest,\n workspaceRootDir: string\n) {\n if (isRushWorkspace(workspaceRootDir)) {\n return targetPackageManifest;\n }\n\n const rootPackageManifest = await readTypedJson<ProjectManifest>(\n path.join(workspaceRootDir, \"package.json\")\n );\n\n const overrides = rootPackageManifest.pnpm?.overrides;\n\n if (!overrides) {\n return targetPackageManifest;\n }\n\n return {\n ...targetPackageManifest,\n pnpm: {\n overrides,\n },\n };\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport outdent from \"outdent\";\nimport { useConfig } from \"../config\";\nimport { useLogger } from \"../logger\";\nimport { readTypedJson } from \"../utils\";\n\nexport async function getBuildOutputDir(targetPackageDir: string) {\n const config = useConfig();\n const log = useLogger();\n\n if (config.buildDirName) {\n log.debug(\"Using buildDirName from config:\", config.buildDirName);\n return path.join(targetPackageDir, config.buildDirName);\n }\n\n const tsconfigPath = path.join(targetPackageDir, config.tsconfigPath);\n\n if (fs.existsSync(tsconfigPath)) {\n log.debug(\"Found tsconfig at:\", config.tsconfigPath);\n\n const tsconfig = await readTypedJson<{\n compilerOptions?: { outDir?: string };\n }>(tsconfigPath);\n\n const outDir = tsconfig.compilerOptions?.outDir;\n\n if (outDir) {\n return path.join(targetPackageDir, outDir);\n } else {\n throw new Error(outdent`\n Failed to find outDir in tsconfig. If you are executing isolate from the root of a monorepo you should specify the buildDirName in isolate.config.json.\n `);\n }\n } else {\n log.warn(\"Failed to find tsconfig at:\", tsconfigPath);\n\n throw new Error(outdent`\n Failed to infer the build output directory from either the isolate config buildDirName or a Typescript config file. See the documentation on how to configure one of these options.\n `);\n }\n}\n","import assert from \"node:assert\";\nimport { useLogger } from \"../logger\";\nimport type { PackagesRegistry } from \"../types\";\nimport { pack } from \"../utils\";\n\n/**\n * Pack dependencies so that we extract only the files that are supposed to be\n * published by the packages.\n *\n * @returns A map of package names to the path of the packed file\n */\nexport async function packDependencies({\n /** All packages found in the monorepo by workspaces declaration */\n packagesRegistry,\n /** The dependencies that appear to be internal packages */\n internalPackageNames,\n /**\n * The directory where the isolated package and all its dependencies will end\n * up. This is also the directory from where the package will be deployed. By\n * default it is a subfolder in targetPackageDir called \"isolate\" but you can\n * configure it.\n */\n packDestinationDir,\n}: {\n packagesRegistry: PackagesRegistry;\n internalPackageNames: string[];\n packDestinationDir: string;\n}) {\n const log = useLogger();\n\n const packedFileByName: Record<string, string> = {};\n\n for (const dependency of internalPackageNames) {\n const def = packagesRegistry[dependency];\n\n assert(dependency, `Failed to find package definition for ${dependency}`);\n\n const { name } = def.manifest;\n\n /**\n * If this dependency has already been packed, we skip it. It could happen\n * because we are packing workspace dependencies recursively.\n */\n if (packedFileByName[name]) {\n log.debug(`Skipping ${name} because it has already been packed`);\n continue;\n }\n\n packedFileByName[name] = await pack(def.absoluteDir, packDestinationDir);\n }\n\n return packedFileByName;\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport { useLogger } from \"../logger\";\nimport { pack, unpack } from \"../utils\";\n\nconst TIMEOUT_MS = 5000;\n\nexport async function processBuildOutputFiles({\n targetPackageDir,\n tmpDir,\n isolateDir,\n}: {\n targetPackageDir: string;\n tmpDir: string;\n isolateDir: string;\n}) {\n const log = useLogger();\n\n const packedFilePath = await pack(targetPackageDir, tmpDir);\n const unpackDir = path.join(tmpDir, \"target\");\n\n const now = Date.now();\n let isWaitingYet = false;\n\n while (!fs.existsSync(packedFilePath) && Date.now() - now < TIMEOUT_MS) {\n if (!isWaitingYet) {\n log.debug(`Waiting for ${packedFilePath} to become available...`);\n }\n isWaitingYet = true;\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n\n await unpack(packedFilePath, unpackDir);\n await fs.copy(path.join(unpackDir, \"package\"), isolateDir);\n}\n","import fs from \"fs-extra\";\nimport path, { join } from \"node:path\";\nimport { useLogger } from \"../logger\";\nimport type { PackagesRegistry } from \"../types\";\nimport { getIsolateRelativePath, unpack } from \"../utils\";\n\nexport async function unpackDependencies(\n packedFilesByName: Record<string, string>,\n packagesRegistry: PackagesRegistry,\n tmpDir: string,\n isolateDir: string\n) {\n const log = useLogger();\n\n await Promise.all(\n Object.entries(packedFilesByName).map(async ([packageName, filePath]) => {\n const dir = packagesRegistry[packageName].rootRelativeDir;\n const unpackDir = join(tmpDir, dir);\n\n log.debug(\"Unpacking\", `(temp)/${path.basename(filePath)}`);\n\n await unpack(filePath, unpackDir);\n\n const destinationDir = join(isolateDir, dir);\n\n await fs.ensureDir(destinationDir);\n\n await fs.move(join(unpackDir, \"package\"), destinationDir, {\n overwrite: true,\n });\n\n log.debug(\n `Moved package files to ${getIsolateRelativePath(\n destinationDir,\n isolateDir\n )}`\n );\n })\n );\n}\n","import fs from \"fs-extra\";\nimport { globSync } from \"glob\";\nimport path from \"node:path\";\nimport { useLogger } from \"../logger\";\nimport type { PackageManifest, PackagesRegistry } from \"../types\";\nimport { isRushWorkspace, readTypedJson, readTypedJsonSync } from \"../utils\";\nimport { findPackagesGlobs } from \"./helpers\";\n\n/**\n * Build a list of all packages in the workspace, depending on the package\n * manager used, with a possible override from the config file. The list\n * contains the manifest with some directory info mapped by module name.\n */\nexport async function createPackagesRegistry(\n workspaceRootDir: string,\n workspacePackagesOverride: string[] | undefined\n): Promise<PackagesRegistry> {\n const log = useLogger();\n\n if (workspacePackagesOverride) {\n log.debug(\n `Override workspace packages via config: ${workspacePackagesOverride}`\n );\n }\n\n const allPackages = listWorkspacePackages(\n workspacePackagesOverride,\n workspaceRootDir\n );\n\n const registry: PackagesRegistry = (\n await Promise.all(\n allPackages.map(async (rootRelativeDir) => {\n const absoluteDir = path.join(workspaceRootDir, rootRelativeDir);\n const manifestPath = path.join(absoluteDir, \"package.json\");\n\n if (!fs.existsSync(manifestPath)) {\n log.warn(\n `Ignoring directory ${rootRelativeDir} because it does not contain a package.json file`\n );\n return;\n } else {\n log.debug(`Registering package ${rootRelativeDir}`);\n\n const manifest = await readTypedJson<PackageManifest>(\n path.join(absoluteDir, \"package.json\")\n );\n\n return {\n manifest,\n rootRelativeDir,\n absoluteDir,\n };\n }\n })\n )\n ).reduce<PackagesRegistry>((acc, info) => {\n if (info) {\n acc[info.manifest.name] = info;\n }\n return acc;\n }, {});\n\n return registry;\n}\n\ntype RushConfig = {\n projects: { packageName: string; projectFolder: string }[];\n};\n\nfunction listWorkspacePackages(\n workspacePackagesOverride: string[] | undefined,\n workspaceRootDir: string\n) {\n if (isRushWorkspace(workspaceRootDir)) {\n const rushConfig = readTypedJsonSync<RushConfig>(\n path.join(workspaceRootDir, \"rush.json\")\n );\n\n return rushConfig.projects.map(({ projectFolder }) => projectFolder);\n } else {\n const currentDir = process.cwd();\n process.chdir(workspaceRootDir);\n\n const packagesGlobs =\n workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);\n\n const allPackages = packagesGlobs\n .flatMap((glob) => globSync(glob))\n /** Make sure to filter any loose files that might hang around. */\n .filter((dir) => fs.lstatSync(dir).isDirectory());\n\n process.chdir(currentDir);\n return allPackages;\n }\n}\n","import assert from \"node:assert\";\nimport path from \"node:path\";\nimport { useLogger } from \"../../logger\";\nimport { usePackageManager } from \"../../package-manager\";\nimport {\n inspectValue,\n readTypedJsonSync,\n readTypedYamlSync,\n} from \"../../utils\";\n\n/**\n * Find the globs that define where the packages are located within the\n * monorepo. This configuration is dependent on the package manager used, and I\n * don't know if we're covering all cases yet...\n */\nexport function findPackagesGlobs(workspaceRootDir: string) {\n const log = useLogger();\n\n const packageManager = usePackageManager();\n\n switch (packageManager.name) {\n case \"pnpm\": {\n const { packages: globs } = readTypedYamlSync<{ packages: string[] }>(\n path.join(workspaceRootDir, \"pnpm-workspace.yaml\")\n );\n\n log.debug(\"Detected pnpm packages globs:\", inspectValue(globs));\n return globs;\n }\n case \"bun\":\n case \"yarn\":\n case \"npm\": {\n const workspaceRootManifestPath = path.join(\n workspaceRootDir,\n \"package.json\"\n );\n\n const { workspaces } = readTypedJsonSync<{ workspaces: string[] }>(\n workspaceRootManifestPath\n );\n\n if (!workspaces) {\n throw new Error(\n `No workspaces field found in ${workspaceRootManifestPath}`\n );\n }\n\n if (Array.isArray(workspaces)) {\n return workspaces;\n } else {\n /**\n * For Yarn, workspaces could be defined as an object with { packages:\n * [], nohoist: [] }. See\n * https://classic.yarnpkg.com/blog/2018/02/15/nohoist/\n */\n const workspacesObject = workspaces as { packages?: string[] };\n\n assert(\n workspacesObject.packages,\n \"workspaces.packages must be an array\"\n );\n\n return workspacesObject.packages;\n }\n }\n }\n}\n","import { unique } from \"remeda\";\nimport type { PackageManifest, PackagesRegistry } from \"../types\";\n\n/**\n * Recursively list all the packages from dependencies (and optionally\n * devDependencies) that are found in the monorepo.\n *\n * Here we do not need to rely on packages being declared with \"workspace:\" in\n * the package manifest. We can simply compare the package names with the list\n * of packages that were found via the workspace glob patterns and add them to\n * the registry.\n */\nexport function listInternalPackages(\n manifest: PackageManifest,\n packagesRegistry: PackagesRegistry,\n { includeDevDependencies = false } = {}\n): string[] {\n const allWorkspacePackageNames = Object.keys(packagesRegistry);\n\n const internalPackageNames = (\n includeDevDependencies\n ? [\n ...Object.keys(manifest.dependencies ?? {}),\n ...Object.keys(manifest.devDependencies ?? {}),\n ]\n : Object.keys(manifest.dependencies ?? {})\n ).filter((name) => allWorkspacePackageNames.includes(name));\n\n const nestedInternalPackageNames = internalPackageNames.flatMap(\n (packageName) =>\n listInternalPackages(\n packagesRegistry[packageName].manifest,\n packagesRegistry,\n { includeDevDependencies }\n )\n );\n\n return unique(internalPackageNames.concat(nestedInternalPackageNames));\n}\n"],"mappings":";;;AACA,OAAOA,cAAa;AACpB,OAAO,gBAAgB;;;ACFvB,OAAOC,UAAQ;AACf,OAAOC,aA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AEvD,YAAM,WAAW,oBAAoB,IAAI,CAAC,MAAMA,OAAK,KAAK,GAAG,IAAI,CAAC;AAElE,YAAM,mBAAmBA,OAAK,KAAK,YAAY,qBAAqB,GAAG;AAAA,QACrE;AAAA,MACF,CAAC;AAAA,IACH,OAAO;AACL,MAAAE,KAAG;AAAA,QACDF,OAAK,KAAK,kBAAkB,qBAAqB;AAAA,QACjDA,OAAK,KAAK,YAAY,qBAAqB;AAAA,MAC7C;AAAA,IACF;AAAA,EACF;AAQA,QAAM,YAAYA,OAAK,KAAK,kBAAkB,QAAQ;AAEtD,MAAIE,KAAG,WAAW,SAAS,GAAG;AAC5B,IAAAA,KAAG,aAAa,WAAWF,OAAK,KAAK,YAAY,QAAQ,CAAC;AAC1D,QAAI,MAAM,0CAA0C;AAAA,EACtD;AAMA,MAAI;AAAA,IACF;AAAA,IACA,oBAAoB,QAAQ,gBAAgB;AAAA,EAC9C;AACA,QAAME,KAAG,OAAO,MAAM;AAEtB,MAAI,KAAK,wBAAwB,UAAU;AAE3C,SAAO;AACT;;;ADzPA,WAAW,QAAQ;AAEnB,eAAe,MAAM;AACnB,QAAM,QAAQ;AAChB;AAEA,IAAI,EAAE,MAAM,CAAC,QAAQ;AACnB,MAAI,eAAe,OAAO;AACxB,IAAAG,SAAQ,MAAM,IAAI,KAAK;AACvB,YAAQ,KAAK,CAAC;AAAA,EAChB,OAAO;AACL,IAAAA,SAAQ,MAAM,GAAG;AAAA,EACnB;AACF,CAAC;","names":["console","fs","assert","path","unique","fs","assert","path","path","fs","fs","fs","path","path","fs","path","fs","path","fs","path","path","fs","path","stdout","path","fs","fs","fs","fs","path","fs","fs","path","path","fs","assert","path","path","path","assert","fs","execSync","path","path","fs","execSync","omit","pick","path","fs","path","path","fs","path","path","packageManager","path","path","path","packageManager","omit","pick","fs","path","path","fs","assert","assert","fs","path","path","fs","fs","path","join","join","path","fs","fs","path","assert","path","packageManager","path","assert","path","fs","path","assert","fs","packageManager","unique","console"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isolate-package",
3
- "version": "1.19.0",
3
+ "version": "1.20.0-0",
4
4
  "description": "Isolate a monorepo package with its shared dependencies to form a self-contained directory, compatible with Firebase deploy",
5
5
  "author": "Thijs Koerselman",
6
6
  "license": "MIT",
@@ -33,7 +33,7 @@
33
33
  "isolate": "dist/isolate-bin.mjs"
34
34
  },
35
35
  "dependencies": {
36
- "@npmcli/arborist": "^7.4.0",
36
+ "@npmcli/arborist": "^7.5.4",
37
37
  "@pnpm/logger": "^5.0.0",
38
38
  "@pnpm/types": "^9.4.2",
39
39
  "chalk": "^5.3.0",
@@ -44,25 +44,25 @@
44
44
  "pnpm_lockfile_file_v9": "npm:@pnpm/lockfile-file@9",
45
45
  "pnpm_prune_lockfile_v8": "npm:@pnpm/prune-lockfile@5",
46
46
  "pnpm_prune_lockfile_v9": "npm:@pnpm/prune-lockfile@6",
47
- "remeda": "^1.56.0",
47
+ "remeda": "^2.7.0",
48
48
  "rename-overwrite": "^5.0.0",
49
49
  "source-map-support": "^0.5.21",
50
50
  "strip-json-comments": "^5.0.1",
51
- "tar-fs": "^3.0.5",
52
- "type-fest": "^4.14.0",
53
- "yaml": "^2.4.1"
51
+ "tar-fs": "^3.0.6",
52
+ "type-fest": "^4.23.0",
53
+ "yaml": "^2.5.0"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/fs-extra": "^11.0.4",
57
- "@types/node": "^20.12.2",
57
+ "@types/node": "^22.1.0",
58
58
  "@types/source-map-support": "^0.5.10",
59
59
  "@types/tar-fs": "^2.0.4",
60
60
  "eslint": "^8",
61
61
  "eslint-config-0x80": "^0.0.0",
62
- "prettier": "^3.2.5",
62
+ "prettier": "^3.3.3",
63
63
  "prettier-plugin-jsdoc": "^1.3.0",
64
- "tsup": "^8.0.2",
65
- "typescript": "^5.4.3",
64
+ "tsup": "^8.2.4",
65
+ "typescript": "^5.5.4",
66
66
  "vitest": "^1.4.0"
67
67
  },
68
68
  "scripts": {
@@ -72,6 +72,6 @@
72
72
  "format": "prettier --write .",
73
73
  "lint": "eslint . --max-warnings 0",
74
74
  "lint:format": "prettier --check .",
75
- "type-check": "tsc --noEmit"
75
+ "compile": "tsc --noEmit"
76
76
  }
77
77
  }