isolate-package 1.30.0-0 → 1.30.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/dist/index.d.mts +7 -1
- package/dist/index.mjs +2 -3
- package/dist/index.mjs.map +1 -1
- package/dist/{isolate-BZjQHi0U.mjs → isolate-CJy3YyKG.mjs} +85 -69
- package/dist/isolate-CJy3YyKG.mjs.map +1 -0
- package/dist/isolate-bin.mjs +3 -5
- package/dist/isolate-bin.mjs.map +1 -1
- package/package.json +21 -20
- package/src/index.ts +6 -0
- package/src/isolate.ts +13 -5
- package/src/lib/lockfile/helpers/generate-bun-lockfile.ts +17 -3
- package/src/lib/manifest/adapt-target-package-manifest.ts +2 -1
- package/src/lib/manifest/helpers/adapt-internal-package-manifests.test.ts +181 -0
- package/src/lib/manifest/helpers/adapt-internal-package-manifests.ts +17 -5
- package/src/lib/manifest/helpers/adopt-pnpm-fields-from-root.test.ts +61 -0
- package/src/lib/manifest/helpers/adopt-pnpm-fields-from-root.ts +42 -3
- package/src/lib/manifest/validate-manifest.test.ts +19 -10
- package/src/lib/manifest/validate-manifest.ts +13 -1
- package/src/lib/patches/copy-patches.test.ts +316 -243
- package/src/lib/patches/copy-patches.ts +54 -15
- package/src/lib/types.ts +6 -0
- package/dist/isolate-BZjQHi0U.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -45,5 +45,11 @@ declare function isolate(config?: IsolateConfig): Promise<string>;
|
|
|
45
45
|
*/
|
|
46
46
|
declare function getInternalPackageNames(config?: IsolateConfig): Promise<string[]>;
|
|
47
47
|
//#endregion
|
|
48
|
-
|
|
48
|
+
//#region src/index.d.ts
|
|
49
|
+
/** Used by firebase-tools-with-isolate to type the dynamic import */
|
|
50
|
+
type IsolateExports = {
|
|
51
|
+
isolate: typeof isolate;
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
export { type IsolateConfig, IsolateExports, type Logger, defineConfig, getInternalPackageNames, isolate };
|
|
49
55
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { c as detectPackageManager, i as defineConfig, l as readTypedJson, n as listInternalPackages, o as resolveConfig, r as createPackagesRegistry, s as resolveWorkspacePaths, t as isolate } from "./isolate-
|
|
1
|
+
import { c as detectPackageManager, i as defineConfig, l as readTypedJson, n as listInternalPackages, o as resolveConfig, r as createPackagesRegistry, s as resolveWorkspacePaths, t as isolate } from "./isolate-CJy3YyKG.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
|
|
4
3
|
//#region src/get-internal-package-names.ts
|
|
5
4
|
/**
|
|
6
5
|
* Get the names of all internal workspace packages that the target package
|
|
@@ -16,7 +15,7 @@ async function getInternalPackageNames(config) {
|
|
|
16
15
|
detectPackageManager(workspaceRootDir);
|
|
17
16
|
return listInternalPackages(await readTypedJson(path.join(targetPackageDir, "package.json")), await createPackagesRegistry(workspaceRootDir, resolvedConfig.workspacePackages), { includeDevDependencies: resolvedConfig.includeDevDependencies });
|
|
18
17
|
}
|
|
19
|
-
|
|
20
18
|
//#endregion
|
|
21
19
|
export { defineConfig, getInternalPackageNames, isolate };
|
|
20
|
+
|
|
22
21
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/get-internal-package-names.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { IsolateConfig } from \"./lib/config\";\nimport { resolveConfig, resolveWorkspacePaths } from \"./lib/config\";\nimport { detectPackageManager } from \"./lib/package-manager\";\nimport { createPackagesRegistry, listInternalPackages } from \"./lib/registry\";\nimport type { PackageManifest } from \"./lib/types\";\nimport { readTypedJson } from \"./lib/utils\";\n\n/**\n * Get the names of all internal workspace packages that the target package\n * depends on. This is useful for tools like tsup that need a list of internal\n * packages to include in `noExternal`.\n *\n * If no config is passed, it reads from `isolate.config.{ts,js,json}` in the\n * current working directory.\n */\nexport async function getInternalPackageNames(\n config?: IsolateConfig,\n): Promise<string[]> {\n const resolvedConfig = resolveConfig(config);\n const { targetPackageDir, workspaceRootDir } =\n resolveWorkspacePaths(resolvedConfig);\n\n detectPackageManager(workspaceRootDir);\n\n const targetPackageManifest = await readTypedJson<PackageManifest>(\n path.join(targetPackageDir, \"package.json\"),\n );\n\n const packagesRegistry = await createPackagesRegistry(\n workspaceRootDir,\n resolvedConfig.workspacePackages,\n );\n\n return listInternalPackages(targetPackageManifest, packagesRegistry, {\n includeDevDependencies: resolvedConfig.includeDevDependencies,\n });\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/get-internal-package-names.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { IsolateConfig } from \"./lib/config\";\nimport { resolveConfig, resolveWorkspacePaths } from \"./lib/config\";\nimport { detectPackageManager } from \"./lib/package-manager\";\nimport { createPackagesRegistry, listInternalPackages } from \"./lib/registry\";\nimport type { PackageManifest } from \"./lib/types\";\nimport { readTypedJson } from \"./lib/utils\";\n\n/**\n * Get the names of all internal workspace packages that the target package\n * depends on. This is useful for tools like tsup that need a list of internal\n * packages to include in `noExternal`.\n *\n * If no config is passed, it reads from `isolate.config.{ts,js,json}` in the\n * current working directory.\n */\nexport async function getInternalPackageNames(\n config?: IsolateConfig,\n): Promise<string[]> {\n const resolvedConfig = resolveConfig(config);\n const { targetPackageDir, workspaceRootDir } =\n resolveWorkspacePaths(resolvedConfig);\n\n detectPackageManager(workspaceRootDir);\n\n const targetPackageManifest = await readTypedJson<PackageManifest>(\n path.join(targetPackageDir, \"package.json\"),\n );\n\n const packagesRegistry = await createPackagesRegistry(\n workspaceRootDir,\n resolvedConfig.workspacePackages,\n );\n\n return listInternalPackages(targetPackageManifest, packagesRegistry, {\n includeDevDependencies: resolvedConfig.includeDevDependencies,\n });\n}\n"],"mappings":";;;;;;;;;;;AAgBA,eAAsB,wBACpB,QACmB;CACnB,MAAM,iBAAiB,cAAc,OAAO;CAC5C,MAAM,EAAE,kBAAkB,qBACxB,sBAAsB,eAAe;AAEvC,sBAAqB,iBAAiB;AAWtC,QAAO,qBATuB,MAAM,cAClC,KAAK,KAAK,kBAAkB,eAAe,CAC5C,EAEwB,MAAM,uBAC7B,kBACA,eAAe,kBAChB,EAEoE,EACnE,wBAAwB,eAAe,wBACxC,CAAC"}
|
|
@@ -24,7 +24,6 @@ import path$1 from "path";
|
|
|
24
24
|
import { getTsconfig } from "get-tsconfig";
|
|
25
25
|
import outdent$1 from "outdent";
|
|
26
26
|
import { globSync } from "glob";
|
|
27
|
-
|
|
28
27
|
//#region src/lib/logger.ts
|
|
29
28
|
/**
|
|
30
29
|
* Map our log levels to consola's numeric levels. Consola levels:
|
|
@@ -56,13 +55,11 @@ function setLogLevel(logLevel) {
|
|
|
56
55
|
function useLogger() {
|
|
57
56
|
return _logger;
|
|
58
57
|
}
|
|
59
|
-
|
|
60
58
|
//#endregion
|
|
61
59
|
//#region src/lib/utils/filter-object-undefined.ts
|
|
62
60
|
function filterObjectUndefined(object) {
|
|
63
61
|
return Object.fromEntries(Object.entries(object).filter(([_, value]) => value !== void 0));
|
|
64
62
|
}
|
|
65
|
-
|
|
66
63
|
//#endregion
|
|
67
64
|
//#region src/lib/utils/get-package-name.ts
|
|
68
65
|
/**
|
|
@@ -74,7 +71,6 @@ function getPackageName(packageSpec) {
|
|
|
74
71
|
/** Regular packages: package@version -> package */
|
|
75
72
|
return packageSpec.split("@")[0] ?? "";
|
|
76
73
|
}
|
|
77
|
-
|
|
78
74
|
//#endregion
|
|
79
75
|
//#region src/lib/utils/filter-patched-dependencies.ts
|
|
80
76
|
/**
|
|
@@ -115,7 +111,6 @@ function filterPatchedDependencies({ patchedDependencies, targetPackageManifest,
|
|
|
115
111
|
log.debug(`Filtered patches: ${includedCount} included, ${excludedCount} excluded`);
|
|
116
112
|
return Object.keys(filteredPatches).length > 0 ? filteredPatches : void 0;
|
|
117
113
|
}
|
|
118
|
-
|
|
119
114
|
//#endregion
|
|
120
115
|
//#region src/lib/utils/get-dirname.ts
|
|
121
116
|
/**
|
|
@@ -125,7 +120,6 @@ function filterPatchedDependencies({ patchedDependencies, targetPackageManifest,
|
|
|
125
120
|
function getDirname(importMetaUrl) {
|
|
126
121
|
return fileURLToPath(new URL(".", importMetaUrl));
|
|
127
122
|
}
|
|
128
|
-
|
|
129
123
|
//#endregion
|
|
130
124
|
//#region src/lib/utils/get-error-message.ts
|
|
131
125
|
function getErrorMessage(error) {
|
|
@@ -146,13 +140,11 @@ function toErrorWithMessage(maybeError) {
|
|
|
146
140
|
return new Error(String(maybeError));
|
|
147
141
|
}
|
|
148
142
|
}
|
|
149
|
-
|
|
150
143
|
//#endregion
|
|
151
144
|
//#region src/lib/utils/inspect-value.ts
|
|
152
145
|
function inspectValue(value) {
|
|
153
146
|
return inspect(value, false, 16, true);
|
|
154
147
|
}
|
|
155
|
-
|
|
156
148
|
//#endregion
|
|
157
149
|
//#region src/lib/utils/is-rush-workspace.ts
|
|
158
150
|
/**
|
|
@@ -162,7 +154,6 @@ function inspectValue(value) {
|
|
|
162
154
|
function isRushWorkspace(workspaceRootDir) {
|
|
163
155
|
return fs$1.existsSync(path.join(workspaceRootDir, "rush.json"));
|
|
164
156
|
}
|
|
165
|
-
|
|
166
157
|
//#endregion
|
|
167
158
|
//#region src/lib/utils/json.ts
|
|
168
159
|
/** @todo Pass in zod schema and validate */
|
|
@@ -182,7 +173,6 @@ async function readTypedJson(filePath) {
|
|
|
182
173
|
throw new Error(`Failed to read JSON from ${filePath}: ${getErrorMessage(err)}`, { cause: err });
|
|
183
174
|
}
|
|
184
175
|
}
|
|
185
|
-
|
|
186
176
|
//#endregion
|
|
187
177
|
//#region src/lib/utils/log-paths.ts
|
|
188
178
|
function getRootRelativeLogPath(path, rootPath) {
|
|
@@ -191,13 +181,11 @@ function getRootRelativeLogPath(path, rootPath) {
|
|
|
191
181
|
function getIsolateRelativeLogPath(path, isolatePath) {
|
|
192
182
|
return join("(isolate)", path.replace(isolatePath, ""));
|
|
193
183
|
}
|
|
194
|
-
|
|
195
184
|
//#endregion
|
|
196
185
|
//#region src/lib/utils/get-major-version.ts
|
|
197
186
|
function getMajorVersion(version) {
|
|
198
187
|
return parseInt(version.split(".").at(0) ?? "0", 10);
|
|
199
188
|
}
|
|
200
|
-
|
|
201
189
|
//#endregion
|
|
202
190
|
//#region src/lib/package-manager/names.ts
|
|
203
191
|
const supportedPackageManagerNames = [
|
|
@@ -214,7 +202,6 @@ function getLockfileFileName(name) {
|
|
|
214
202
|
case "npm": return "package-lock.json";
|
|
215
203
|
}
|
|
216
204
|
}
|
|
217
|
-
|
|
218
205
|
//#endregion
|
|
219
206
|
//#region src/lib/package-manager/helpers/infer-from-files.ts
|
|
220
207
|
function inferFromFiles(workspaceRoot) {
|
|
@@ -245,7 +232,6 @@ function inferFromFiles(workspaceRoot) {
|
|
|
245
232
|
function getVersion(packageManagerName) {
|
|
246
233
|
return execSync(`${packageManagerName} --version`).toString().trim();
|
|
247
234
|
}
|
|
248
|
-
|
|
249
235
|
//#endregion
|
|
250
236
|
//#region src/lib/package-manager/helpers/infer-from-manifest.ts
|
|
251
237
|
function inferFromManifest(workspaceRoot) {
|
|
@@ -266,7 +252,6 @@ function inferFromManifest(workspaceRoot) {
|
|
|
266
252
|
packageManagerString
|
|
267
253
|
};
|
|
268
254
|
}
|
|
269
|
-
|
|
270
255
|
//#endregion
|
|
271
256
|
//#region src/lib/package-manager/index.ts
|
|
272
257
|
let packageManager;
|
|
@@ -293,7 +278,6 @@ function shouldUsePnpmPack() {
|
|
|
293
278
|
const { name, majorVersion } = usePackageManager();
|
|
294
279
|
return name === "pnpm" && majorVersion >= 8;
|
|
295
280
|
}
|
|
296
|
-
|
|
297
281
|
//#endregion
|
|
298
282
|
//#region src/lib/utils/pack.ts
|
|
299
283
|
async function pack(srcDir, dstDir) {
|
|
@@ -334,7 +318,6 @@ async function pack(srcDir, dstDir) {
|
|
|
334
318
|
*/
|
|
335
319
|
return filePath;
|
|
336
320
|
}
|
|
337
|
-
|
|
338
321
|
//#endregion
|
|
339
322
|
//#region src/lib/utils/unpack.ts
|
|
340
323
|
async function unpack(filePath, unpackDir) {
|
|
@@ -342,7 +325,6 @@ async function unpack(filePath, unpackDir) {
|
|
|
342
325
|
fs.createReadStream(filePath).pipe(createGunzip()).pipe(tar.extract(unpackDir)).on("finish", () => resolve()).on("error", (err) => reject(err));
|
|
343
326
|
});
|
|
344
327
|
}
|
|
345
|
-
|
|
346
328
|
//#endregion
|
|
347
329
|
//#region src/lib/utils/yaml.ts
|
|
348
330
|
function readTypedYamlSync(filePath) {
|
|
@@ -358,7 +340,6 @@ function writeTypedYamlSync(filePath, content) {
|
|
|
358
340
|
/** @todo Add some zod validation maybe */
|
|
359
341
|
fs.writeFileSync(filePath, yaml.stringify(content), "utf-8");
|
|
360
342
|
}
|
|
361
|
-
|
|
362
343
|
//#endregion
|
|
363
344
|
//#region src/lib/config.ts
|
|
364
345
|
const configDefaults = {
|
|
@@ -474,7 +455,6 @@ function resolveConfig(initialConfig) {
|
|
|
474
455
|
log.debug("Using configuration:", inspectValue(config));
|
|
475
456
|
return config;
|
|
476
457
|
}
|
|
477
|
-
|
|
478
458
|
//#endregion
|
|
479
459
|
//#region src/lib/lockfile/helpers/generate-bun-lockfile.ts
|
|
480
460
|
/**
|
|
@@ -578,14 +558,16 @@ async function generateBunLockfile({ workspaceRootDir, targetPackageDir, isolate
|
|
|
578
558
|
const targetWorkspaceKey = path.relative(workspaceRootDir, targetPackageDir).split(path.sep).join(path.posix.sep);
|
|
579
559
|
const internalDepWorkspaceKeys = /* @__PURE__ */ new Map();
|
|
580
560
|
for (const name of internalDepPackageNames) {
|
|
581
|
-
|
|
582
|
-
|
|
561
|
+
/** Normalize to POSIX separators for matching bun.lock workspace keys */
|
|
562
|
+
const workspaceKey = got(packagesRegistry, name).rootRelativeDir.split(path.sep).join(path.posix.sep);
|
|
563
|
+
internalDepWorkspaceKeys.set(name, workspaceKey);
|
|
583
564
|
}
|
|
584
565
|
/** Build the filtered workspaces object */
|
|
585
566
|
const filteredWorkspaces = {};
|
|
586
567
|
/** Remap the target workspace to root ("") */
|
|
587
568
|
const targetEntry = lockfile.workspaces[targetWorkspaceKey];
|
|
588
|
-
if (targetEntry) {
|
|
569
|
+
if (!targetEntry) throw new Error(`Target workspace "${targetWorkspaceKey}" not found in bun.lock. Available workspaces: ${Object.keys(lockfile.workspaces).join(", ")}`);
|
|
570
|
+
{
|
|
589
571
|
const entry = { ...targetEntry };
|
|
590
572
|
if (!includeDevDependencies) delete entry.devDependencies;
|
|
591
573
|
filteredWorkspaces[""] = entry;
|
|
@@ -645,14 +627,14 @@ async function generateBunLockfile({ workspaceRootDir, targetPackageDir, isolate
|
|
|
645
627
|
if (Object.keys(outputPatches).length > 0) outputLockfile.patchedDependencies = outputPatches;
|
|
646
628
|
}
|
|
647
629
|
const outputPath = path.join(isolateDir, "bun.lock");
|
|
648
|
-
|
|
630
|
+
/** Append trailing newline to match Bun's native output format */
|
|
631
|
+
await fs.writeFile(outputPath, serializeWithTrailingCommas(outputLockfile) + "\n");
|
|
649
632
|
log.debug("Created lockfile at", outputPath);
|
|
650
633
|
} catch (err) {
|
|
651
634
|
log.error(`Failed to generate lockfile: ${getErrorMessage(err)}`);
|
|
652
635
|
throw err;
|
|
653
636
|
}
|
|
654
637
|
}
|
|
655
|
-
|
|
656
638
|
//#endregion
|
|
657
639
|
//#region src/lib/lockfile/helpers/load-npm-config.ts
|
|
658
640
|
async function loadNpmConfig({ npmPath }) {
|
|
@@ -665,7 +647,6 @@ async function loadNpmConfig({ npmPath }) {
|
|
|
665
647
|
await config.load();
|
|
666
648
|
return config;
|
|
667
649
|
}
|
|
668
|
-
|
|
669
650
|
//#endregion
|
|
670
651
|
//#region src/lib/lockfile/helpers/generate-npm-lockfile.ts
|
|
671
652
|
/**
|
|
@@ -692,7 +673,6 @@ async function generateNpmLockfile({ workspaceRootDir, isolateDir }) {
|
|
|
692
673
|
throw err;
|
|
693
674
|
}
|
|
694
675
|
}
|
|
695
|
-
|
|
696
676
|
//#endregion
|
|
697
677
|
//#region src/lib/lockfile/helpers/pnpm-map-importer.ts
|
|
698
678
|
/** Convert dependency links */
|
|
@@ -723,7 +703,6 @@ function pnpmMapDependenciesLinks(importerPath, def, directoryByPackageName) {
|
|
|
723
703
|
return [[key, relativePath.startsWith(".") ? `link:${relativePath}` : `link:./${relativePath}`]];
|
|
724
704
|
}));
|
|
725
705
|
}
|
|
726
|
-
|
|
727
706
|
//#endregion
|
|
728
707
|
//#region src/lib/lockfile/helpers/generate-pnpm-lockfile.ts
|
|
729
708
|
async function generatePnpmLockfile({ workspaceRootDir, targetPackageDir, isolateDir, internalDepPackageNames, packagesRegistry, targetPackageManifest, majorVersion, includeDevDependencies, patchedDependencies }) {
|
|
@@ -794,7 +773,6 @@ async function generatePnpmLockfile({ workspaceRootDir, targetPackageDir, isolat
|
|
|
794
773
|
throw err;
|
|
795
774
|
}
|
|
796
775
|
}
|
|
797
|
-
|
|
798
776
|
//#endregion
|
|
799
777
|
//#region src/lib/lockfile/helpers/generate-yarn-lockfile.ts
|
|
800
778
|
/**
|
|
@@ -823,7 +801,6 @@ async function generateYarnLockfile({ workspaceRootDir, isolateDir }) {
|
|
|
823
801
|
throw err;
|
|
824
802
|
}
|
|
825
803
|
}
|
|
826
|
-
|
|
827
804
|
//#endregion
|
|
828
805
|
//#region src/lib/lockfile/process-lockfile.ts
|
|
829
806
|
/**
|
|
@@ -899,7 +876,6 @@ async function processLockfile({ workspaceRootDir, packagesRegistry, isolateDir,
|
|
|
899
876
|
}
|
|
900
877
|
return usedFallbackToNpm;
|
|
901
878
|
}
|
|
902
|
-
|
|
903
879
|
//#endregion
|
|
904
880
|
//#region src/lib/manifest/io.ts
|
|
905
881
|
async function readManifest(packageDir) {
|
|
@@ -908,7 +884,6 @@ async function readManifest(packageDir) {
|
|
|
908
884
|
async function writeManifest(outputDir, manifest) {
|
|
909
885
|
await fs.writeFile(path.join(outputDir, "package.json"), JSON.stringify(manifest, null, 2));
|
|
910
886
|
}
|
|
911
|
-
|
|
912
887
|
//#endregion
|
|
913
888
|
//#region src/lib/manifest/helpers/patch-internal-entries.ts
|
|
914
889
|
function patchInternalEntries(dependencies, packagesRegistry, parentRootRelativeDir) {
|
|
@@ -923,7 +898,6 @@ function patchInternalEntries(dependencies, packagesRegistry, parentRootRelative
|
|
|
923
898
|
} else return [key, value];
|
|
924
899
|
}));
|
|
925
900
|
}
|
|
926
|
-
|
|
927
901
|
//#endregion
|
|
928
902
|
//#region src/lib/manifest/helpers/adapt-manifest-internal-deps.ts
|
|
929
903
|
/**
|
|
@@ -939,7 +913,6 @@ function adaptManifestInternalDeps({ manifest, packagesRegistry, parentRootRelat
|
|
|
939
913
|
devDependencies: devDependencies ? patchInternalEntries(devDependencies, packagesRegistry, parentRootRelativeDir) : void 0
|
|
940
914
|
};
|
|
941
915
|
}
|
|
942
|
-
|
|
943
916
|
//#endregion
|
|
944
917
|
//#region src/lib/manifest/helpers/resolve-catalog-dependencies.ts
|
|
945
918
|
/**
|
|
@@ -973,7 +946,6 @@ async function resolveCatalogDependencies(dependencies, workspaceRootDir) {
|
|
|
973
946
|
}
|
|
974
947
|
return resolved;
|
|
975
948
|
}
|
|
976
|
-
|
|
977
949
|
//#endregion
|
|
978
950
|
//#region src/lib/manifest/helpers/adapt-internal-package-manifests.ts
|
|
979
951
|
/**
|
|
@@ -985,14 +957,22 @@ async function adaptInternalPackageManifests({ internalPackageNames, packagesReg
|
|
|
985
957
|
const packageManager = usePackageManager();
|
|
986
958
|
await Promise.all(internalPackageNames.map(async (packageName) => {
|
|
987
959
|
const { manifest, rootRelativeDir } = got(packagesRegistry, packageName);
|
|
988
|
-
/** Dev dependencies
|
|
989
|
-
const strippedManifest = omit(manifest, ["
|
|
960
|
+
/** Dev dependencies are never included for internal deps */
|
|
961
|
+
const strippedManifest = omit(manifest, ["devDependencies"]);
|
|
962
|
+
/**
|
|
963
|
+
* Strip the `prepare` script because it runs during `pnpm install` and
|
|
964
|
+
* typically depends on devDependency binaries (e.g. tsdown, del-cli)
|
|
965
|
+
* which are not available in the isolated output. Other lifecycle
|
|
966
|
+
* scripts like `postinstall` are preserved because they handle runtime
|
|
967
|
+
* setup (e.g. Prisma client generation).
|
|
968
|
+
*/
|
|
969
|
+
if (strippedManifest.scripts) strippedManifest.scripts = omit(strippedManifest.scripts, ["prepare"]);
|
|
990
970
|
/** Resolve catalog dependencies before adapting internal deps */
|
|
991
971
|
const manifestWithResolvedCatalogs = {
|
|
992
972
|
...strippedManifest,
|
|
993
973
|
dependencies: await resolveCatalogDependencies(strippedManifest.dependencies, workspaceRootDir)
|
|
994
974
|
};
|
|
995
|
-
const outputManifest = packageManager.name === "pnpm" && !forceNpm ? manifestWithResolvedCatalogs : adaptManifestInternalDeps({
|
|
975
|
+
const outputManifest = (packageManager.name === "pnpm" || packageManager.name === "bun") && !forceNpm ? manifestWithResolvedCatalogs : adaptManifestInternalDeps({
|
|
996
976
|
manifest: manifestWithResolvedCatalogs,
|
|
997
977
|
packagesRegistry,
|
|
998
978
|
parentRootRelativeDir: rootRelativeDir
|
|
@@ -1000,17 +980,36 @@ async function adaptInternalPackageManifests({ internalPackageNames, packagesReg
|
|
|
1000
980
|
await writeManifest(path.join(isolateDir, rootRelativeDir), outputManifest);
|
|
1001
981
|
}));
|
|
1002
982
|
}
|
|
1003
|
-
|
|
1004
983
|
//#endregion
|
|
1005
984
|
//#region src/lib/manifest/helpers/adopt-pnpm-fields-from-root.ts
|
|
1006
985
|
/**
|
|
1007
|
-
* Adopts
|
|
1008
|
-
* overrides, onlyBuiltDependencies, and ignoredBuiltDependencies
|
|
1009
|
-
*
|
|
986
|
+
* Adopts workspace-level fields from the root package manifest. For pnpm this
|
|
987
|
+
* reads overrides, onlyBuiltDependencies, and ignoredBuiltDependencies from the
|
|
988
|
+
* `pnpm` key. For Bun it reads `overrides` from the top level.
|
|
1010
989
|
*/
|
|
1011
990
|
async function adoptPnpmFieldsFromRoot(targetPackageManifest, workspaceRootDir) {
|
|
1012
991
|
if (isRushWorkspace(workspaceRootDir)) return targetPackageManifest;
|
|
1013
|
-
const
|
|
992
|
+
const rootPackageManifest = await readTypedJson(path$1.join(workspaceRootDir, "package.json"));
|
|
993
|
+
if (usePackageManager().name === "bun") return adoptBunFieldsFromRoot(targetPackageManifest, rootPackageManifest);
|
|
994
|
+
return adoptPnpmFieldsOnly(targetPackageManifest, rootPackageManifest);
|
|
995
|
+
}
|
|
996
|
+
/** Adopt Bun's top-level overrides from the root manifest */
|
|
997
|
+
function adoptBunFieldsFromRoot(targetPackageManifest, rootPackageManifest) {
|
|
998
|
+
/**
|
|
999
|
+
* Bun supports `overrides` at the top level of package.json (same as npm).
|
|
1000
|
+
* Read from the root manifest and set them on the output manifest so that
|
|
1001
|
+
* `bun install --frozen-lockfile` succeeds.
|
|
1002
|
+
*/
|
|
1003
|
+
const overrides = rootPackageManifest["overrides"];
|
|
1004
|
+
if (!overrides) return targetPackageManifest;
|
|
1005
|
+
return {
|
|
1006
|
+
...targetPackageManifest,
|
|
1007
|
+
overrides
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
1010
|
+
/** Adopt pnpm-specific fields from the root manifest */
|
|
1011
|
+
function adoptPnpmFieldsOnly(targetPackageManifest, rootPackageManifest) {
|
|
1012
|
+
const { overrides, onlyBuiltDependencies, ignoredBuiltDependencies } = rootPackageManifest.pnpm || {};
|
|
1014
1013
|
/** If no pnpm fields are present, return the original manifest */
|
|
1015
1014
|
if (!overrides && !onlyBuiltDependencies && !ignoredBuiltDependencies) return targetPackageManifest;
|
|
1016
1015
|
const pnpmConfig = {};
|
|
@@ -1022,7 +1021,6 @@ async function adoptPnpmFieldsFromRoot(targetPackageManifest, workspaceRootDir)
|
|
|
1022
1021
|
pnpm: pnpmConfig
|
|
1023
1022
|
};
|
|
1024
1023
|
}
|
|
1025
|
-
|
|
1026
1024
|
//#endregion
|
|
1027
1025
|
//#region src/lib/manifest/adapt-target-package-manifest.ts
|
|
1028
1026
|
/**
|
|
@@ -1051,9 +1049,13 @@ async function adaptTargetPackageManifest({ manifest, packagesRegistry, workspac
|
|
|
1051
1049
|
scripts: pickFromScripts ? pick(manifest.scripts ?? {}, pickFromScripts) : omitFromScripts ? omit(manifest.scripts ?? {}, omitFromScripts) : {}
|
|
1052
1050
|
};
|
|
1053
1051
|
}
|
|
1054
|
-
|
|
1055
1052
|
//#endregion
|
|
1056
1053
|
//#region src/lib/manifest/validate-manifest.ts
|
|
1054
|
+
/** Maps field names to their documentation URLs */
|
|
1055
|
+
const fieldDocUrls = {
|
|
1056
|
+
version: "https://isolate-package.codecompose.dev/getting-started#define-version-field-in-each-package-manifest",
|
|
1057
|
+
files: "https://isolate-package.codecompose.dev/getting-started#define-files-field-in-each-package-manifest"
|
|
1058
|
+
};
|
|
1057
1059
|
/**
|
|
1058
1060
|
* Validate that mandatory fields are present in the package manifest. These
|
|
1059
1061
|
* fields are required for the isolate process to work properly.
|
|
@@ -1075,13 +1077,13 @@ function validateManifestMandatoryFields(manifest, packagePath, requireFilesFiel
|
|
|
1075
1077
|
*/
|
|
1076
1078
|
if (requireFilesField && (!manifest.files || !Array.isArray(manifest.files) || manifest.files.length === 0)) missingFields.push("files");
|
|
1077
1079
|
if (missingFields.length > 0) {
|
|
1078
|
-
const
|
|
1080
|
+
const field = missingFields[0];
|
|
1081
|
+
const errorMessage = missingFields.length === 1 ? `Package at ${packagePath} is missing the "${field}" field in its package.json. See ${fieldDocUrls[field] ?? "https://isolate-package.codecompose.dev/getting-started#prerequisites"}` : `Package at ${packagePath} is missing mandatory fields in its package.json: ${missingFields.join(", ")}. See https://isolate-package.codecompose.dev/getting-started#prerequisites`;
|
|
1079
1082
|
log.error(errorMessage);
|
|
1080
1083
|
throw new Error(errorMessage);
|
|
1081
1084
|
}
|
|
1082
1085
|
log.debug(`Validated mandatory fields for package at ${packagePath}`);
|
|
1083
1086
|
}
|
|
1084
|
-
|
|
1085
1087
|
//#endregion
|
|
1086
1088
|
//#region src/lib/output/get-build-output-dir.ts
|
|
1087
1089
|
async function getBuildOutputDir({ targetPackageDir, buildDirName, tsconfigPath }) {
|
|
@@ -1106,7 +1108,6 @@ async function getBuildOutputDir({ targetPackageDir, buildDirName, tsconfigPath
|
|
|
1106
1108
|
`);
|
|
1107
1109
|
}
|
|
1108
1110
|
}
|
|
1109
|
-
|
|
1110
1111
|
//#endregion
|
|
1111
1112
|
//#region src/lib/output/pack-dependencies.ts
|
|
1112
1113
|
/**
|
|
@@ -1134,7 +1135,6 @@ async function packDependencies({ packagesRegistry, internalPackageNames, packDe
|
|
|
1134
1135
|
}
|
|
1135
1136
|
return packedFileByName;
|
|
1136
1137
|
}
|
|
1137
|
-
|
|
1138
1138
|
//#endregion
|
|
1139
1139
|
//#region src/lib/output/process-build-output-files.ts
|
|
1140
1140
|
const TIMEOUT_MS = 5e3;
|
|
@@ -1152,7 +1152,6 @@ async function processBuildOutputFiles({ targetPackageDir, tmpDir, isolateDir })
|
|
|
1152
1152
|
await unpack(packedFilePath, unpackDir);
|
|
1153
1153
|
await fs.copy(path.join(unpackDir, "package"), isolateDir);
|
|
1154
1154
|
}
|
|
1155
|
-
|
|
1156
1155
|
//#endregion
|
|
1157
1156
|
//#region src/lib/output/unpack-dependencies.ts
|
|
1158
1157
|
async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, isolateDir) {
|
|
@@ -1168,19 +1167,32 @@ async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, i
|
|
|
1168
1167
|
log.debug(`Moved package files to ${getIsolateRelativeLogPath(destinationDir, isolateDir)}`);
|
|
1169
1168
|
}));
|
|
1170
1169
|
}
|
|
1171
|
-
|
|
1172
1170
|
//#endregion
|
|
1173
1171
|
//#region src/lib/patches/copy-patches.ts
|
|
1174
1172
|
async function copyPatches({ workspaceRootDir, targetPackageManifest, isolateDir, includeDevDependencies }) {
|
|
1175
1173
|
const log = useLogger();
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1174
|
+
const { name: packageManagerName } = usePackageManager();
|
|
1175
|
+
let patchedDependencies;
|
|
1176
|
+
/**
|
|
1177
|
+
* Only try reading pnpm-workspace.yaml for pnpm workspaces. Bun workspaces
|
|
1178
|
+
* don't have this file and the warning would be noisy.
|
|
1179
|
+
*/
|
|
1180
|
+
if (packageManagerName === "pnpm") try {
|
|
1181
|
+
patchedDependencies = readTypedYamlSync(path.join(workspaceRootDir, "pnpm-workspace.yaml"))?.patchedDependencies;
|
|
1179
1182
|
} catch (error) {
|
|
1180
|
-
log.warn(`Could not read workspace
|
|
1181
|
-
|
|
1183
|
+
log.warn(`Could not read pnpm-workspace.yaml: ${error instanceof Error ? error.message : String(error)}`);
|
|
1184
|
+
}
|
|
1185
|
+
if (!patchedDependencies || Object.keys(patchedDependencies).length === 0) {
|
|
1186
|
+
if (packageManagerName === "pnpm") log.debug("No patched dependencies found in pnpm-workspace.yaml; Falling back to workspace root package.json");
|
|
1187
|
+
else log.debug("Reading patched dependencies from workspace root package.json");
|
|
1188
|
+
try {
|
|
1189
|
+
const workspaceRootManifest = await readTypedJson(path.join(workspaceRootDir, "package.json"));
|
|
1190
|
+
/** PNPM stores patches under pnpm.patchedDependencies, Bun at the top level */
|
|
1191
|
+
patchedDependencies = workspaceRootManifest?.pnpm?.patchedDependencies ?? workspaceRootManifest?.patchedDependencies;
|
|
1192
|
+
} catch (error) {
|
|
1193
|
+
log.warn(`Could not read workspace root package.json: ${error instanceof Error ? error.message : String(error)}`);
|
|
1194
|
+
}
|
|
1182
1195
|
}
|
|
1183
|
-
const patchedDependencies = workspaceRootManifest.pnpm?.patchedDependencies;
|
|
1184
1196
|
if (!patchedDependencies || Object.keys(patchedDependencies).length === 0) {
|
|
1185
1197
|
log.debug("No patched dependencies found in workspace root package.json");
|
|
1186
1198
|
return {};
|
|
@@ -1192,8 +1204,11 @@ async function copyPatches({ workspaceRootDir, targetPackageManifest, isolateDir
|
|
|
1192
1204
|
includeDevDependencies
|
|
1193
1205
|
});
|
|
1194
1206
|
if (!filteredPatches) return {};
|
|
1195
|
-
/**
|
|
1196
|
-
|
|
1207
|
+
/**
|
|
1208
|
+
* Read the pnpm lockfile to get patch hashes. Bun doesn't store hashes in
|
|
1209
|
+
* its lockfile so we skip this for Bun.
|
|
1210
|
+
*/
|
|
1211
|
+
const lockfilePatchedDependencies = packageManagerName === "pnpm" ? await readLockfilePatchedDependencies(workspaceRootDir) : void 0;
|
|
1197
1212
|
const copiedPatches = {};
|
|
1198
1213
|
for (const [packageSpec, patchPath] of Object.entries(filteredPatches)) {
|
|
1199
1214
|
const sourcePatchPath = path.resolve(workspaceRootDir, patchPath);
|
|
@@ -1207,7 +1222,7 @@ async function copyPatches({ workspaceRootDir, targetPackageManifest, isolateDir
|
|
|
1207
1222
|
await fs.copy(sourcePatchPath, targetPatchPath);
|
|
1208
1223
|
log.debug(`Copied patch for ${packageSpec}: ${patchPath}`);
|
|
1209
1224
|
const hash = (lockfilePatchedDependencies?.[packageSpec])?.hash ?? "";
|
|
1210
|
-
if (!hash) log.warn(`No hash found for patch ${packageSpec} in lockfile`);
|
|
1225
|
+
if (packageManagerName === "pnpm" && !hash) log.warn(`No hash found for patch ${packageSpec} in lockfile`);
|
|
1211
1226
|
copiedPatches[packageSpec] = {
|
|
1212
1227
|
path: patchPath,
|
|
1213
1228
|
hash
|
|
@@ -1231,7 +1246,6 @@ async function readLockfilePatchedDependencies(workspaceRootDir) {
|
|
|
1231
1246
|
return;
|
|
1232
1247
|
}
|
|
1233
1248
|
}
|
|
1234
|
-
|
|
1235
1249
|
//#endregion
|
|
1236
1250
|
//#region src/lib/registry/helpers/find-packages-globs.ts
|
|
1237
1251
|
/**
|
|
@@ -1270,7 +1284,6 @@ function findPackagesGlobs(workspaceRootDir) {
|
|
|
1270
1284
|
}
|
|
1271
1285
|
}
|
|
1272
1286
|
}
|
|
1273
|
-
|
|
1274
1287
|
//#endregion
|
|
1275
1288
|
//#region src/lib/registry/create-packages-registry.ts
|
|
1276
1289
|
/**
|
|
@@ -1305,7 +1318,6 @@ function listWorkspacePackages(workspacePackagesOverride, workspaceRootDir) {
|
|
|
1305
1318
|
if (isRushWorkspace(workspaceRootDir)) return readTypedJsonSync(path.join(workspaceRootDir, "rush.json")).projects.map(({ projectFolder }) => projectFolder);
|
|
1306
1319
|
else return (workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir)).flatMap((glob) => globSync(glob, { cwd: workspaceRootDir })).filter((dir) => fs.lstatSync(path.join(workspaceRootDir, dir)).isDirectory());
|
|
1307
1320
|
}
|
|
1308
|
-
|
|
1309
1321
|
//#endregion
|
|
1310
1322
|
//#region src/lib/registry/list-internal-packages.ts
|
|
1311
1323
|
/**
|
|
@@ -1350,7 +1362,6 @@ function listInternalPackages(manifest, packagesRegistry, { includeDevDependenci
|
|
|
1350
1362
|
const result = collectInternalPackages(manifest, packagesRegistry, includeDevDependencies, /* @__PURE__ */ new Set(), new Set(manifest.name ? [manifest.name] : []));
|
|
1351
1363
|
return [...new Set(result)];
|
|
1352
1364
|
}
|
|
1353
|
-
|
|
1354
1365
|
//#endregion
|
|
1355
1366
|
//#region src/isolate.ts
|
|
1356
1367
|
const __dirname = getDirname(import.meta.url);
|
|
@@ -1456,12 +1467,17 @@ function createIsolator(config) {
|
|
|
1456
1467
|
if (hasCopiedPatches || usedFallbackToNpm) {
|
|
1457
1468
|
const manifest = await readManifest(isolateDir);
|
|
1458
1469
|
if (hasCopiedPatches) {
|
|
1459
|
-
if (!manifest.pnpm) manifest.pnpm = {};
|
|
1460
1470
|
/**
|
|
1461
1471
|
* Extract just the paths for the manifest (lockfile needs full
|
|
1462
|
-
* PatchFile)
|
|
1472
|
+
* PatchFile). PNPM stores patches under pnpm.patchedDependencies, Bun
|
|
1473
|
+
* at the top level.
|
|
1463
1474
|
*/
|
|
1464
|
-
|
|
1475
|
+
const patchEntries = Object.fromEntries(Object.entries(copiedPatches).map(([spec, patchFile]) => [spec, patchFile.path]));
|
|
1476
|
+
if (packageManager.name === "bun") manifest.patchedDependencies = patchEntries;
|
|
1477
|
+
else {
|
|
1478
|
+
if (!manifest.pnpm) manifest.pnpm = {};
|
|
1479
|
+
manifest.pnpm.patchedDependencies = patchEntries;
|
|
1480
|
+
}
|
|
1465
1481
|
log.debug(`Added ${Object.keys(copiedPatches).length} patches to isolated package.json`);
|
|
1466
1482
|
}
|
|
1467
1483
|
if (usedFallbackToNpm) manifest.packageManager = `npm@${getVersion("npm")}`;
|
|
@@ -1521,7 +1537,7 @@ function createIsolator(config) {
|
|
|
1521
1537
|
async function isolate(config) {
|
|
1522
1538
|
return createIsolator(config)();
|
|
1523
1539
|
}
|
|
1524
|
-
|
|
1525
1540
|
//#endregion
|
|
1526
1541
|
export { loadConfigFromFile as a, detectPackageManager as c, defineConfig as i, readTypedJson as l, listInternalPackages as n, resolveConfig as o, createPackagesRegistry as r, resolveWorkspacePaths as s, isolate as t, filterObjectUndefined as u };
|
|
1527
|
-
|
|
1542
|
+
|
|
1543
|
+
//# sourceMappingURL=isolate-CJy3YyKG.mjs.map
|