isolate-package 1.12.2 → 1.13.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/dist/index.mjs +186 -125
- package/dist/index.mjs.map +1 -1
- package/dist/isolate-bin.mjs +186 -125
- package/dist/isolate-bin.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// src/isolate.ts
|
|
2
|
-
import
|
|
2
|
+
import fs16 from "fs-extra";
|
|
3
3
|
import assert6 from "node:assert";
|
|
4
|
-
import
|
|
4
|
+
import path19 from "node:path";
|
|
5
|
+
import { unique } from "remeda";
|
|
5
6
|
|
|
6
7
|
// src/lib/config.ts
|
|
7
|
-
import
|
|
8
|
+
import fs6 from "fs-extra";
|
|
8
9
|
import assert from "node:assert";
|
|
9
|
-
import
|
|
10
|
+
import path3 from "node:path";
|
|
10
11
|
import { isEmpty } from "remeda";
|
|
11
12
|
|
|
12
13
|
// src/lib/logger.ts
|
|
@@ -82,12 +83,12 @@ function toErrorWithMessage(maybeError) {
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
// src/lib/utils/get-relative-path.ts
|
|
85
|
-
function getRootRelativePath(
|
|
86
|
-
const strippedPath =
|
|
86
|
+
function getRootRelativePath(path20, rootPath) {
|
|
87
|
+
const strippedPath = path20.replace(rootPath, "");
|
|
87
88
|
return strippedPath.startsWith("/") ? `(root)${strippedPath}` : `(root)/${strippedPath}`;
|
|
88
89
|
}
|
|
89
|
-
function getIsolateRelativePath(
|
|
90
|
-
const strippedPath =
|
|
90
|
+
function getIsolateRelativePath(path20, isolatePath) {
|
|
91
|
+
const strippedPath = path20.replace(isolatePath, "");
|
|
91
92
|
return strippedPath.startsWith("/") ? `(isolate)${strippedPath}` : `(isolate)/${strippedPath}`;
|
|
92
93
|
}
|
|
93
94
|
|
|
@@ -97,12 +98,19 @@ function inspectValue(value) {
|
|
|
97
98
|
return inspect(value, false, 16, true);
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
// src/lib/utils/is-rush-workspace.ts
|
|
102
|
+
import fs from "node:fs";
|
|
103
|
+
import path from "node:path";
|
|
104
|
+
function isRushWorkspace(workspaceRootDir) {
|
|
105
|
+
return fs.existsSync(path.join(workspaceRootDir, "rush.json"));
|
|
106
|
+
}
|
|
107
|
+
|
|
100
108
|
// src/lib/utils/json.ts
|
|
101
|
-
import
|
|
109
|
+
import fs2 from "fs-extra";
|
|
102
110
|
import stripJsonComments from "strip-json-comments";
|
|
103
111
|
function readTypedJsonSync(filePath) {
|
|
104
112
|
try {
|
|
105
|
-
const rawContent =
|
|
113
|
+
const rawContent = fs2.readFileSync(filePath, "utf-8");
|
|
106
114
|
const data = JSON.parse(
|
|
107
115
|
stripJsonComments(rawContent, { trailingCommas: true })
|
|
108
116
|
);
|
|
@@ -115,7 +123,7 @@ function readTypedJsonSync(filePath) {
|
|
|
115
123
|
}
|
|
116
124
|
async function readTypedJson(filePath) {
|
|
117
125
|
try {
|
|
118
|
-
const rawContent = await
|
|
126
|
+
const rawContent = await fs2.readFile(filePath, "utf-8");
|
|
119
127
|
const data = JSON.parse(
|
|
120
128
|
stripJsonComments(rawContent, { trailingCommas: true })
|
|
121
129
|
);
|
|
@@ -129,8 +137,8 @@ async function readTypedJson(filePath) {
|
|
|
129
137
|
|
|
130
138
|
// src/lib/utils/pack.ts
|
|
131
139
|
import { exec } from "node:child_process";
|
|
132
|
-
import
|
|
133
|
-
import
|
|
140
|
+
import fs3 from "node:fs";
|
|
141
|
+
import path2 from "node:path";
|
|
134
142
|
async function pack(srcDir, dstDir, usePnpmPack) {
|
|
135
143
|
const execOptions = {
|
|
136
144
|
maxBuffer: 10 * 1024 * 1024
|
|
@@ -162,9 +170,9 @@ async function pack(srcDir, dstDir, usePnpmPack) {
|
|
|
162
170
|
}
|
|
163
171
|
);
|
|
164
172
|
});
|
|
165
|
-
const fileName =
|
|
166
|
-
const filePath =
|
|
167
|
-
if (!
|
|
173
|
+
const fileName = path2.basename(stdout.trim());
|
|
174
|
+
const filePath = path2.join(dstDir, fileName);
|
|
175
|
+
if (!fs3.existsSync(filePath)) {
|
|
168
176
|
log.error(
|
|
169
177
|
`The response from pack could not be resolved to an existing file: ${filePath}`
|
|
170
178
|
);
|
|
@@ -176,21 +184,21 @@ async function pack(srcDir, dstDir, usePnpmPack) {
|
|
|
176
184
|
}
|
|
177
185
|
|
|
178
186
|
// src/lib/utils/unpack.ts
|
|
179
|
-
import
|
|
187
|
+
import fs4 from "fs-extra";
|
|
180
188
|
import tar from "tar-fs";
|
|
181
189
|
import { createGunzip } from "zlib";
|
|
182
190
|
async function unpack(filePath, unpackDir) {
|
|
183
191
|
await new Promise((resolve, reject) => {
|
|
184
|
-
|
|
192
|
+
fs4.createReadStream(filePath).pipe(createGunzip()).pipe(tar.extract(unpackDir)).on("finish", () => resolve()).on("error", (err) => reject(err));
|
|
185
193
|
});
|
|
186
194
|
}
|
|
187
195
|
|
|
188
196
|
// src/lib/utils/yaml.ts
|
|
189
|
-
import
|
|
197
|
+
import fs5 from "fs-extra";
|
|
190
198
|
import yaml from "yaml";
|
|
191
199
|
function readTypedYamlSync(filePath) {
|
|
192
200
|
try {
|
|
193
|
-
const rawContent =
|
|
201
|
+
const rawContent = fs5.readFileSync(filePath, "utf-8");
|
|
194
202
|
const data = yaml.parse(rawContent);
|
|
195
203
|
return data;
|
|
196
204
|
} catch (err) {
|
|
@@ -199,6 +207,9 @@ function readTypedYamlSync(filePath) {
|
|
|
199
207
|
);
|
|
200
208
|
}
|
|
201
209
|
}
|
|
210
|
+
function writeTypedYamlSync(filePath, content) {
|
|
211
|
+
fs5.writeFileSync(filePath, yaml.stringify(content), "utf-8");
|
|
212
|
+
}
|
|
202
213
|
|
|
203
214
|
// src/lib/config.ts
|
|
204
215
|
var configDefaults = {
|
|
@@ -238,12 +249,12 @@ function resolveConfig() {
|
|
|
238
249
|
}
|
|
239
250
|
setLogLevel(process.env.DEBUG_ISOLATE_CONFIG ? "debug" : "info");
|
|
240
251
|
const log = useLogger();
|
|
241
|
-
const configFilePath =
|
|
252
|
+
const configFilePath = path3.join(process.cwd(), CONFIG_FILE_NAME);
|
|
242
253
|
if (_user_defined_config) {
|
|
243
254
|
log.debug(`Using user defined config:`, inspectValue(_user_defined_config));
|
|
244
255
|
} else {
|
|
245
256
|
log.debug(`Attempting to load config from ${configFilePath}`);
|
|
246
|
-
_user_defined_config =
|
|
257
|
+
_user_defined_config = fs6.existsSync(configFilePath) ? readTypedJsonSync(configFilePath) : {};
|
|
247
258
|
}
|
|
248
259
|
const foreignKeys = Object.keys(_user_defined_config).filter(
|
|
249
260
|
(key) => !validConfigKeys.includes(key)
|
|
@@ -261,10 +272,13 @@ function resolveConfig() {
|
|
|
261
272
|
return config;
|
|
262
273
|
}
|
|
263
274
|
|
|
275
|
+
// src/lib/package-manager/index.ts
|
|
276
|
+
import path6 from "node:path";
|
|
277
|
+
|
|
264
278
|
// src/lib/package-manager/helpers/infer-from-files.ts
|
|
265
|
-
import
|
|
279
|
+
import fs7 from "fs-extra";
|
|
266
280
|
import { execSync } from "node:child_process";
|
|
267
|
-
import
|
|
281
|
+
import path4 from "node:path";
|
|
268
282
|
|
|
269
283
|
// src/lib/package-manager/names.ts
|
|
270
284
|
var supportedPackageManagerNames = ["pnpm", "yarn", "npm"];
|
|
@@ -283,11 +297,11 @@ function getLockfileFileName(name) {
|
|
|
283
297
|
function inferFromFiles(workspaceRoot) {
|
|
284
298
|
for (const name of supportedPackageManagerNames) {
|
|
285
299
|
const lockfileName = getLockfileFileName(name);
|
|
286
|
-
if (
|
|
300
|
+
if (fs7.existsSync(path4.join(workspaceRoot, lockfileName))) {
|
|
287
301
|
return { name, version: getVersion(name) };
|
|
288
302
|
}
|
|
289
303
|
}
|
|
290
|
-
if (
|
|
304
|
+
if (fs7.existsSync(path4.join(workspaceRoot, "npm-shrinkwrap.json"))) {
|
|
291
305
|
return { name: "npm", version: getVersion("npm") };
|
|
292
306
|
}
|
|
293
307
|
throw new Error(`Failed to detect package manager`);
|
|
@@ -298,13 +312,13 @@ function getVersion(packageManagerName) {
|
|
|
298
312
|
}
|
|
299
313
|
|
|
300
314
|
// src/lib/package-manager/helpers/infer-from-manifest.ts
|
|
301
|
-
import
|
|
315
|
+
import fs8 from "fs-extra";
|
|
302
316
|
import assert2 from "node:assert";
|
|
303
|
-
import
|
|
317
|
+
import path5 from "node:path";
|
|
304
318
|
function inferFromManifest(workspaceRoot) {
|
|
305
319
|
const log = useLogger();
|
|
306
320
|
const rootManifest = readTypedJsonSync(
|
|
307
|
-
|
|
321
|
+
path5.join(workspaceRoot, "package.json")
|
|
308
322
|
);
|
|
309
323
|
if (!rootManifest.packageManager) {
|
|
310
324
|
log.debug("No packageManager field found in root manifest");
|
|
@@ -317,7 +331,7 @@ function inferFromManifest(workspaceRoot) {
|
|
|
317
331
|
);
|
|
318
332
|
const lockfileName = getLockfileFileName(name);
|
|
319
333
|
assert2(
|
|
320
|
-
|
|
334
|
+
fs8.existsSync(path5.join(workspaceRoot, lockfileName)),
|
|
321
335
|
`Manifest declares ${name} to be the packageManager, but failed to find ${lockfileName} in workspace root`
|
|
322
336
|
);
|
|
323
337
|
return { name, version };
|
|
@@ -333,40 +347,46 @@ function usePackageManager() {
|
|
|
333
347
|
}
|
|
334
348
|
return packageManager;
|
|
335
349
|
}
|
|
336
|
-
function detectPackageManager(
|
|
337
|
-
|
|
350
|
+
function detectPackageManager(workspaceRootDir) {
|
|
351
|
+
if (isRushWorkspace(workspaceRootDir)) {
|
|
352
|
+
packageManager = inferFromFiles(
|
|
353
|
+
path6.join(workspaceRootDir, "common/config/rush")
|
|
354
|
+
);
|
|
355
|
+
} else {
|
|
356
|
+
packageManager = inferFromManifest(workspaceRootDir) ?? inferFromFiles(workspaceRootDir);
|
|
357
|
+
}
|
|
338
358
|
return packageManager;
|
|
339
359
|
}
|
|
340
360
|
|
|
341
361
|
// src/lib/lockfile/helpers/generate-npm-lockfile.ts
|
|
342
362
|
import Arborist from "@npmcli/arborist";
|
|
343
|
-
import
|
|
344
|
-
import
|
|
363
|
+
import fs9 from "fs-extra";
|
|
364
|
+
import path7 from "node:path";
|
|
345
365
|
async function generateNpmLockfile({
|
|
346
366
|
workspaceRootDir,
|
|
347
367
|
isolateDir
|
|
348
368
|
}) {
|
|
349
369
|
const log = useLogger();
|
|
350
370
|
log.info("Generating NPM lockfile...");
|
|
351
|
-
const origRootNodeModulesPath =
|
|
352
|
-
const tempRootNodeModulesPath =
|
|
371
|
+
const origRootNodeModulesPath = path7.join(workspaceRootDir, "node_modules");
|
|
372
|
+
const tempRootNodeModulesPath = path7.join(isolateDir, "node_modules");
|
|
353
373
|
let hasMovedNodeModules = false;
|
|
354
374
|
let hasError = false;
|
|
355
375
|
try {
|
|
356
|
-
if (!
|
|
376
|
+
if (!fs9.existsSync(origRootNodeModulesPath)) {
|
|
357
377
|
throw new Error(
|
|
358
378
|
`Failed to find node_modules at ${origRootNodeModulesPath}`
|
|
359
379
|
);
|
|
360
380
|
}
|
|
361
381
|
log.debug(`Temporarily moving node_modules to the isolate output`);
|
|
362
|
-
await
|
|
382
|
+
await fs9.move(origRootNodeModulesPath, tempRootNodeModulesPath);
|
|
363
383
|
hasMovedNodeModules = true;
|
|
364
384
|
const arborist = new Arborist({ path: isolateDir });
|
|
365
385
|
log.debug(`Building tree...`);
|
|
366
386
|
const { meta } = await arborist.buildIdealTree();
|
|
367
387
|
meta?.commit();
|
|
368
|
-
const lockfilePath =
|
|
369
|
-
await
|
|
388
|
+
const lockfilePath = path7.join(isolateDir, "package-lock.json");
|
|
389
|
+
await fs9.writeFile(lockfilePath, String(meta));
|
|
370
390
|
log.debug("Created lockfile at", lockfilePath);
|
|
371
391
|
} catch (err) {
|
|
372
392
|
console.error(inspectValue(err));
|
|
@@ -375,7 +395,7 @@ async function generateNpmLockfile({
|
|
|
375
395
|
} finally {
|
|
376
396
|
if (hasMovedNodeModules) {
|
|
377
397
|
log.debug(`Restoring node_modules to the workspace root`);
|
|
378
|
-
await
|
|
398
|
+
await fs9.move(tempRootNodeModulesPath, origRootNodeModulesPath);
|
|
379
399
|
}
|
|
380
400
|
}
|
|
381
401
|
if (hasError) {
|
|
@@ -391,7 +411,7 @@ import {
|
|
|
391
411
|
} from "@pnpm/lockfile-file";
|
|
392
412
|
import { pruneLockfile } from "@pnpm/prune-lockfile";
|
|
393
413
|
import assert3 from "node:assert";
|
|
394
|
-
import
|
|
414
|
+
import path8 from "node:path";
|
|
395
415
|
import { pick } from "remeda";
|
|
396
416
|
|
|
397
417
|
// src/lib/lockfile/helpers/pnpm-map-importer.ts
|
|
@@ -426,9 +446,13 @@ async function generatePnpmLockfile({
|
|
|
426
446
|
const log = useLogger();
|
|
427
447
|
log.info("Generating PNPM lockfile...");
|
|
428
448
|
try {
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
|
|
449
|
+
const isRush = isRushWorkspace(workspaceRootDir);
|
|
450
|
+
const lockfile = await readWantedLockfile(
|
|
451
|
+
isRush ? path8.join(workspaceRootDir, "common/config/rush") : workspaceRootDir,
|
|
452
|
+
{
|
|
453
|
+
ignoreIncompatible: false
|
|
454
|
+
}
|
|
455
|
+
);
|
|
432
456
|
assert3(lockfile, `No input lockfile found at ${workspaceRootDir}`);
|
|
433
457
|
const targetImporterId = getLockfileImporterId(
|
|
434
458
|
workspaceRootDir,
|
|
@@ -438,6 +462,7 @@ async function generatePnpmLockfile({
|
|
|
438
462
|
internalDepPackageNames.map((name) => {
|
|
439
463
|
const pkg = packagesRegistry[name];
|
|
440
464
|
assert3(pkg, `Package ${name} not found in packages registry`);
|
|
465
|
+
console.log("pkg.rootRelativeDir", pkg.rootRelativeDir);
|
|
441
466
|
return [name, pkg.rootRelativeDir];
|
|
442
467
|
})
|
|
443
468
|
);
|
|
@@ -450,23 +475,18 @@ async function generatePnpmLockfile({
|
|
|
450
475
|
...Object.values(directoryByPackageName)
|
|
451
476
|
];
|
|
452
477
|
log.debug("Relevant importer ids:", relevantImporterIds);
|
|
478
|
+
const relevantImporterIdsWithPrefix = relevantImporterIds.map(
|
|
479
|
+
(x) => isRush ? `../../${x}` : x
|
|
480
|
+
);
|
|
453
481
|
lockfile.importers = Object.fromEntries(
|
|
454
|
-
Object.entries(
|
|
455
|
-
(
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
pnpmMapImporter(importer, {
|
|
461
|
-
includeDevDependencies,
|
|
462
|
-
includePatchedDependencies,
|
|
463
|
-
directoryByPackageName
|
|
464
|
-
})
|
|
465
|
-
];
|
|
466
|
-
}
|
|
467
|
-
log.debug("Setting internal package importer:", importerId);
|
|
482
|
+
Object.entries(
|
|
483
|
+
pick(lockfile.importers, relevantImporterIdsWithPrefix)
|
|
484
|
+
).map(([prefixedImporterId, importer]) => {
|
|
485
|
+
const importerId = isRush ? prefixedImporterId.replace("../../", "") : prefixedImporterId;
|
|
486
|
+
if (importerId === targetImporterId) {
|
|
487
|
+
log.debug("Setting target package importer on root");
|
|
468
488
|
return [
|
|
469
|
-
|
|
489
|
+
".",
|
|
470
490
|
pnpmMapImporter(importer, {
|
|
471
491
|
includeDevDependencies,
|
|
472
492
|
includePatchedDependencies,
|
|
@@ -474,7 +494,16 @@ async function generatePnpmLockfile({
|
|
|
474
494
|
})
|
|
475
495
|
];
|
|
476
496
|
}
|
|
477
|
-
|
|
497
|
+
log.debug("Setting internal package importer:", importerId);
|
|
498
|
+
return [
|
|
499
|
+
importerId,
|
|
500
|
+
pnpmMapImporter(importer, {
|
|
501
|
+
includeDevDependencies,
|
|
502
|
+
includePatchedDependencies,
|
|
503
|
+
directoryByPackageName
|
|
504
|
+
})
|
|
505
|
+
];
|
|
506
|
+
})
|
|
478
507
|
);
|
|
479
508
|
log.debug("Pruning the lockfile");
|
|
480
509
|
const prunedLockfile = await pruneLockfile(
|
|
@@ -492,30 +521,30 @@ async function generatePnpmLockfile({
|
|
|
492
521
|
*/
|
|
493
522
|
patchedDependencies: includePatchedDependencies ? lockfile.patchedDependencies : void 0
|
|
494
523
|
});
|
|
495
|
-
log.debug("Created lockfile at",
|
|
524
|
+
log.debug("Created lockfile at", path8.join(isolateDir, "pnpm-lock.yaml"));
|
|
496
525
|
} catch (err) {
|
|
497
526
|
throw new Error(`Failed to generate lockfile: ${getErrorMessage(err)}`);
|
|
498
527
|
}
|
|
499
528
|
}
|
|
500
529
|
|
|
501
530
|
// src/lib/lockfile/helpers/generate-yarn-lockfile.ts
|
|
502
|
-
import
|
|
531
|
+
import fs10 from "fs-extra";
|
|
503
532
|
import { execSync as execSync2 } from "node:child_process";
|
|
504
|
-
import
|
|
533
|
+
import path9 from "node:path";
|
|
505
534
|
async function generateYarnLockfile({
|
|
506
535
|
workspaceRootDir,
|
|
507
536
|
isolateDir
|
|
508
537
|
}) {
|
|
509
538
|
const log = useLogger();
|
|
510
539
|
log.info("Generating Yarn lockfile...");
|
|
511
|
-
const origLockfilePath =
|
|
512
|
-
const newLockfilePath =
|
|
513
|
-
if (!
|
|
540
|
+
const origLockfilePath = path9.join(workspaceRootDir, "yarn.lock");
|
|
541
|
+
const newLockfilePath = path9.join(isolateDir, "yarn.lock");
|
|
542
|
+
if (!fs10.existsSync(origLockfilePath)) {
|
|
514
543
|
throw new Error(`Failed to find lockfile at ${origLockfilePath}`);
|
|
515
544
|
}
|
|
516
545
|
log.debug(`Copy original yarn.lock to the isolate output`);
|
|
517
546
|
try {
|
|
518
|
-
await
|
|
547
|
+
await fs10.copyFile(origLockfilePath, newLockfilePath);
|
|
519
548
|
log.debug(`Running local install`);
|
|
520
549
|
execSync2(`yarn install --cwd ${isolateDir}`);
|
|
521
550
|
log.debug("Generated lockfile at", newLockfilePath);
|
|
@@ -598,24 +627,24 @@ async function processLockfile({
|
|
|
598
627
|
import { omit as omit2, pick as pick2 } from "remeda";
|
|
599
628
|
|
|
600
629
|
// src/lib/manifest/helpers/adapt-internal-package-manifests.ts
|
|
601
|
-
import
|
|
630
|
+
import path12 from "node:path";
|
|
602
631
|
import { omit } from "remeda";
|
|
603
632
|
|
|
604
633
|
// src/lib/manifest/io.ts
|
|
605
|
-
import
|
|
606
|
-
import
|
|
634
|
+
import fs11 from "fs-extra";
|
|
635
|
+
import path10 from "node:path";
|
|
607
636
|
async function readManifest(packageDir) {
|
|
608
|
-
return readTypedJson(
|
|
637
|
+
return readTypedJson(path10.join(packageDir, "package.json"));
|
|
609
638
|
}
|
|
610
639
|
async function writeManifest(outputDir, manifest) {
|
|
611
|
-
await
|
|
612
|
-
|
|
640
|
+
await fs11.writeFile(
|
|
641
|
+
path10.join(outputDir, "package.json"),
|
|
613
642
|
JSON.stringify(manifest, null, 2)
|
|
614
643
|
);
|
|
615
644
|
}
|
|
616
645
|
|
|
617
646
|
// src/lib/manifest/helpers/patch-internal-entries.ts
|
|
618
|
-
import
|
|
647
|
+
import path11 from "node:path";
|
|
619
648
|
function patchInternalEntries(dependencies, packagesRegistry, parentRootRelativeDir) {
|
|
620
649
|
const log = useLogger();
|
|
621
650
|
const allWorkspacePackageNames = Object.keys(packagesRegistry);
|
|
@@ -623,7 +652,7 @@ function patchInternalEntries(dependencies, packagesRegistry, parentRootRelative
|
|
|
623
652
|
Object.entries(dependencies).map(([key, value]) => {
|
|
624
653
|
if (allWorkspacePackageNames.includes(key)) {
|
|
625
654
|
const def = packagesRegistry[key];
|
|
626
|
-
const relativePath = parentRootRelativeDir ?
|
|
655
|
+
const relativePath = parentRootRelativeDir ? path11.relative(parentRootRelativeDir, `./${def.rootRelativeDir}`) : `./${def.rootRelativeDir}`;
|
|
627
656
|
const linkPath = `file:${relativePath}`;
|
|
628
657
|
log.debug(`Linking dependency ${key} to ${linkPath}`);
|
|
629
658
|
return [key, linkPath];
|
|
@@ -679,7 +708,7 @@ async function adaptInternalPackageManifests(internalPackageNames, packagesRegis
|
|
|
679
708
|
})
|
|
680
709
|
);
|
|
681
710
|
await writeManifest(
|
|
682
|
-
|
|
711
|
+
path12.join(isolateDir, rootRelativeDir),
|
|
683
712
|
outputManifest
|
|
684
713
|
);
|
|
685
714
|
})
|
|
@@ -687,10 +716,13 @@ async function adaptInternalPackageManifests(internalPackageNames, packagesRegis
|
|
|
687
716
|
}
|
|
688
717
|
|
|
689
718
|
// src/lib/manifest/helpers/adopt-pnpm-fields-from-root.ts
|
|
690
|
-
import
|
|
719
|
+
import path13 from "path";
|
|
691
720
|
async function adoptPnpmFieldsFromRoot(targetPackageManifest, workspaceRootDir) {
|
|
721
|
+
if (isRushWorkspace(workspaceRootDir)) {
|
|
722
|
+
return targetPackageManifest;
|
|
723
|
+
}
|
|
692
724
|
const rootPackageManifest = await readTypedJson(
|
|
693
|
-
|
|
725
|
+
path13.join(workspaceRootDir, "package.json")
|
|
694
726
|
);
|
|
695
727
|
const overrides = rootPackageManifest.pnpm?.overrides;
|
|
696
728
|
if (!overrides) {
|
|
@@ -738,23 +770,23 @@ async function adaptTargetPackageManifest({
|
|
|
738
770
|
}
|
|
739
771
|
|
|
740
772
|
// src/lib/output/get-build-output-dir.ts
|
|
741
|
-
import
|
|
742
|
-
import
|
|
773
|
+
import fs12 from "fs-extra";
|
|
774
|
+
import path14 from "node:path";
|
|
743
775
|
import outdent from "outdent";
|
|
744
776
|
async function getBuildOutputDir(targetPackageDir) {
|
|
745
777
|
const config = useConfig();
|
|
746
778
|
const log = useLogger();
|
|
747
779
|
if (config.buildDirName) {
|
|
748
780
|
log.debug("Using buildDirName from config:", config.buildDirName);
|
|
749
|
-
return
|
|
781
|
+
return path14.join(targetPackageDir, config.buildDirName);
|
|
750
782
|
}
|
|
751
|
-
const tsconfigPath =
|
|
752
|
-
if (
|
|
783
|
+
const tsconfigPath = path14.join(targetPackageDir, config.tsconfigPath);
|
|
784
|
+
if (fs12.existsSync(tsconfigPath)) {
|
|
753
785
|
log.debug("Found tsconfig at:", config.tsconfigPath);
|
|
754
786
|
const tsconfig = await readTypedJson(tsconfigPath);
|
|
755
787
|
const outDir = tsconfig.compilerOptions?.outDir;
|
|
756
788
|
if (outDir) {
|
|
757
|
-
return
|
|
789
|
+
return path14.join(targetPackageDir, outDir);
|
|
758
790
|
} else {
|
|
759
791
|
throw new Error(outdent`
|
|
760
792
|
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.
|
|
@@ -809,8 +841,8 @@ async function packDependencies({
|
|
|
809
841
|
}
|
|
810
842
|
|
|
811
843
|
// src/lib/output/process-build-output-files.ts
|
|
812
|
-
import
|
|
813
|
-
import
|
|
844
|
+
import fs13 from "fs-extra";
|
|
845
|
+
import path15 from "node:path";
|
|
814
846
|
var TIMEOUT_MS = 5e3;
|
|
815
847
|
async function processBuildOutputFiles({
|
|
816
848
|
targetPackageDir,
|
|
@@ -819,10 +851,10 @@ async function processBuildOutputFiles({
|
|
|
819
851
|
}) {
|
|
820
852
|
const log = useLogger();
|
|
821
853
|
const packedFilePath = await pack(targetPackageDir, tmpDir);
|
|
822
|
-
const unpackDir =
|
|
854
|
+
const unpackDir = path15.join(tmpDir, "target");
|
|
823
855
|
const now = Date.now();
|
|
824
856
|
let isWaitingYet = false;
|
|
825
|
-
while (!
|
|
857
|
+
while (!fs13.existsSync(packedFilePath) && Date.now() - now < TIMEOUT_MS) {
|
|
826
858
|
if (!isWaitingYet) {
|
|
827
859
|
log.debug(`Waiting for ${packedFilePath} to become available...`);
|
|
828
860
|
}
|
|
@@ -830,23 +862,23 @@ async function processBuildOutputFiles({
|
|
|
830
862
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
831
863
|
}
|
|
832
864
|
await unpack(packedFilePath, unpackDir);
|
|
833
|
-
await
|
|
865
|
+
await fs13.copy(path15.join(unpackDir, "package"), isolateDir);
|
|
834
866
|
}
|
|
835
867
|
|
|
836
868
|
// src/lib/output/unpack-dependencies.ts
|
|
837
|
-
import
|
|
838
|
-
import
|
|
869
|
+
import fs14 from "fs-extra";
|
|
870
|
+
import path16, { join } from "node:path";
|
|
839
871
|
async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, isolateDir) {
|
|
840
872
|
const log = useLogger();
|
|
841
873
|
await Promise.all(
|
|
842
874
|
Object.entries(packedFilesByName).map(async ([packageName, filePath]) => {
|
|
843
875
|
const dir = packagesRegistry[packageName].rootRelativeDir;
|
|
844
876
|
const unpackDir = join(tmpDir, dir);
|
|
845
|
-
log.debug("Unpacking", `(temp)/${
|
|
877
|
+
log.debug("Unpacking", `(temp)/${path16.basename(filePath)}`);
|
|
846
878
|
await unpack(filePath, unpackDir);
|
|
847
879
|
const destinationDir = join(isolateDir, dir);
|
|
848
|
-
await
|
|
849
|
-
await
|
|
880
|
+
await fs14.ensureDir(destinationDir);
|
|
881
|
+
await fs14.move(join(unpackDir, "package"), destinationDir, {
|
|
850
882
|
overwrite: true
|
|
851
883
|
});
|
|
852
884
|
log.debug(
|
|
@@ -860,27 +892,27 @@ async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, i
|
|
|
860
892
|
}
|
|
861
893
|
|
|
862
894
|
// src/lib/registry/create-packages-registry.ts
|
|
863
|
-
import
|
|
895
|
+
import fs15 from "fs-extra";
|
|
864
896
|
import { globSync } from "glob";
|
|
865
|
-
import
|
|
897
|
+
import path18 from "node:path";
|
|
866
898
|
|
|
867
899
|
// src/lib/registry/helpers/find-packages-globs.ts
|
|
868
900
|
import assert5 from "node:assert";
|
|
869
|
-
import
|
|
901
|
+
import path17 from "node:path";
|
|
870
902
|
function findPackagesGlobs(workspaceRootDir) {
|
|
871
903
|
const log = useLogger();
|
|
872
904
|
const packageManager2 = usePackageManager();
|
|
873
905
|
switch (packageManager2.name) {
|
|
874
906
|
case "pnpm": {
|
|
875
907
|
const { packages: globs } = readTypedYamlSync(
|
|
876
|
-
|
|
908
|
+
path17.join(workspaceRootDir, "pnpm-workspace.yaml")
|
|
877
909
|
);
|
|
878
910
|
log.debug("Detected pnpm packages globs:", inspectValue(globs));
|
|
879
911
|
return globs;
|
|
880
912
|
}
|
|
881
913
|
case "yarn":
|
|
882
914
|
case "npm": {
|
|
883
|
-
const workspaceRootManifestPath =
|
|
915
|
+
const workspaceRootManifestPath = path17.join(
|
|
884
916
|
workspaceRootDir,
|
|
885
917
|
"package.json"
|
|
886
918
|
);
|
|
@@ -914,14 +946,16 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
|
|
|
914
946
|
`Override workspace packages via config: ${workspacePackagesOverride}`
|
|
915
947
|
);
|
|
916
948
|
}
|
|
917
|
-
const
|
|
949
|
+
const allPackages = listWorkspacePackages(
|
|
950
|
+
workspacePackagesOverride,
|
|
951
|
+
workspaceRootDir
|
|
952
|
+
);
|
|
918
953
|
const cwd = process.cwd();
|
|
919
954
|
process.chdir(workspaceRootDir);
|
|
920
|
-
const allPackages = packagesGlobs.flatMap((glob) => globSync(glob)).filter((dir) => fs14.lstatSync(dir).isDirectory());
|
|
921
955
|
const registry = (await Promise.all(
|
|
922
956
|
allPackages.map(async (rootRelativeDir) => {
|
|
923
|
-
const manifestPath =
|
|
924
|
-
if (!
|
|
957
|
+
const manifestPath = path18.join(rootRelativeDir, "package.json");
|
|
958
|
+
if (!fs15.existsSync(manifestPath)) {
|
|
925
959
|
log.warn(
|
|
926
960
|
`Ignoring directory ./${rootRelativeDir} because it does not contain a package.json file`
|
|
927
961
|
);
|
|
@@ -929,12 +963,12 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
|
|
|
929
963
|
} else {
|
|
930
964
|
log.debug(`Registering package ./${rootRelativeDir}`);
|
|
931
965
|
const manifest = await readTypedJson(
|
|
932
|
-
|
|
966
|
+
path18.join(rootRelativeDir, "package.json")
|
|
933
967
|
);
|
|
934
968
|
return {
|
|
935
969
|
manifest,
|
|
936
970
|
rootRelativeDir,
|
|
937
|
-
absoluteDir:
|
|
971
|
+
absoluteDir: path18.join(workspaceRootDir, rootRelativeDir)
|
|
938
972
|
};
|
|
939
973
|
}
|
|
940
974
|
})
|
|
@@ -947,6 +981,18 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
|
|
|
947
981
|
process.chdir(cwd);
|
|
948
982
|
return registry;
|
|
949
983
|
}
|
|
984
|
+
function listWorkspacePackages(workspacePackagesOverride, workspaceRootDir) {
|
|
985
|
+
if (isRushWorkspace(workspaceRootDir)) {
|
|
986
|
+
const rushConfig = readTypedJsonSync(
|
|
987
|
+
path18.join(workspaceRootDir, "rush.json")
|
|
988
|
+
);
|
|
989
|
+
return rushConfig.projects.map(({ projectFolder }) => projectFolder);
|
|
990
|
+
} else {
|
|
991
|
+
const packagesGlobs = workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);
|
|
992
|
+
const allPackages = packagesGlobs.flatMap((glob) => globSync(glob)).filter((dir) => fs15.lstatSync(dir).isDirectory());
|
|
993
|
+
return allPackages;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
950
996
|
|
|
951
997
|
// src/lib/registry/list-internal-packages.ts
|
|
952
998
|
import { uniq } from "remeda";
|
|
@@ -979,14 +1025,14 @@ async function isolate(options = {}) {
|
|
|
979
1025
|
setLogLevel(config.logLevel);
|
|
980
1026
|
const log = useLogger();
|
|
981
1027
|
const thisPackageManifest = await readTypedJson(
|
|
982
|
-
|
|
1028
|
+
path19.join(path19.join(__dirname, "..", "package.json"))
|
|
983
1029
|
);
|
|
984
1030
|
log.debug("Using isolate-package version", thisPackageManifest.version);
|
|
985
|
-
const targetPackageDir = config.targetPackagePath ?
|
|
986
|
-
const workspaceRootDir = config.targetPackagePath ? process.cwd() :
|
|
1031
|
+
const targetPackageDir = config.targetPackagePath ? path19.join(process.cwd(), config.targetPackagePath) : process.cwd();
|
|
1032
|
+
const workspaceRootDir = config.targetPackagePath ? process.cwd() : path19.join(targetPackageDir, config.workspaceRoot);
|
|
987
1033
|
const buildOutputDir = await getBuildOutputDir(targetPackageDir);
|
|
988
1034
|
assert6(
|
|
989
|
-
|
|
1035
|
+
fs16.existsSync(buildOutputDir),
|
|
990
1036
|
`Failed to find build output path at ${buildOutputDir}. Please make sure you build the source before isolating it.`
|
|
991
1037
|
);
|
|
992
1038
|
log.debug("Workspace root resolved to", workspaceRootDir);
|
|
@@ -994,20 +1040,20 @@ async function isolate(options = {}) {
|
|
|
994
1040
|
"Isolate target package",
|
|
995
1041
|
getRootRelativePath(targetPackageDir, workspaceRootDir)
|
|
996
1042
|
);
|
|
997
|
-
const isolateDir =
|
|
1043
|
+
const isolateDir = path19.join(targetPackageDir, config.isolateDirName);
|
|
998
1044
|
log.debug(
|
|
999
1045
|
"Isolate output directory",
|
|
1000
1046
|
getRootRelativePath(isolateDir, workspaceRootDir)
|
|
1001
1047
|
);
|
|
1002
|
-
if (
|
|
1003
|
-
await
|
|
1048
|
+
if (fs16.existsSync(isolateDir)) {
|
|
1049
|
+
await fs16.remove(isolateDir);
|
|
1004
1050
|
log.debug("Cleaned the existing isolate output directory");
|
|
1005
1051
|
}
|
|
1006
|
-
await
|
|
1007
|
-
const tmpDir =
|
|
1008
|
-
await
|
|
1052
|
+
await fs16.ensureDir(isolateDir);
|
|
1053
|
+
const tmpDir = path19.join(isolateDir, "__tmp");
|
|
1054
|
+
await fs16.ensureDir(tmpDir);
|
|
1009
1055
|
const targetPackageManifest = await readTypedJson(
|
|
1010
|
-
|
|
1056
|
+
path19.join(targetPackageDir, "package.json")
|
|
1011
1057
|
);
|
|
1012
1058
|
const packageManager2 = detectPackageManager(workspaceRootDir);
|
|
1013
1059
|
log.debug(
|
|
@@ -1069,21 +1115,36 @@ async function isolate(options = {}) {
|
|
|
1069
1115
|
await writeManifest(isolateDir, manifest);
|
|
1070
1116
|
}
|
|
1071
1117
|
if (packageManager2.name === "pnpm" && !config.forceNpm) {
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1118
|
+
if (isRushWorkspace(workspaceRootDir)) {
|
|
1119
|
+
const packagesFolderNames = unique(
|
|
1120
|
+
internalPackageNames.map(
|
|
1121
|
+
(name) => path19.parse(packagesRegistry[name].rootRelativeDir).dir
|
|
1122
|
+
)
|
|
1123
|
+
);
|
|
1124
|
+
log.debug("Generating pnpm-workspace.yaml for Rush workspace");
|
|
1125
|
+
log.debug("Packages folder names:", packagesFolderNames);
|
|
1126
|
+
const workspaceConfig = packagesFolderNames.map((x) => x + "/*");
|
|
1127
|
+
await writeTypedYamlSync(
|
|
1128
|
+
path19.join(isolateDir, "pnpm-workspace.yaml"),
|
|
1129
|
+
workspaceConfig
|
|
1130
|
+
);
|
|
1131
|
+
} else {
|
|
1132
|
+
fs16.copyFileSync(
|
|
1133
|
+
path19.join(workspaceRootDir, "pnpm-workspace.yaml"),
|
|
1134
|
+
path19.join(isolateDir, "pnpm-workspace.yaml")
|
|
1135
|
+
);
|
|
1136
|
+
}
|
|
1076
1137
|
}
|
|
1077
|
-
const npmrcPath =
|
|
1078
|
-
if (
|
|
1079
|
-
|
|
1138
|
+
const npmrcPath = path19.join(workspaceRootDir, ".npmrc");
|
|
1139
|
+
if (fs16.existsSync(npmrcPath)) {
|
|
1140
|
+
fs16.copyFileSync(npmrcPath, path19.join(isolateDir, ".npmrc"));
|
|
1080
1141
|
log.debug("Copied .npmrc file to the isolate output");
|
|
1081
1142
|
}
|
|
1082
1143
|
log.debug(
|
|
1083
1144
|
"Deleting temp directory",
|
|
1084
1145
|
getRootRelativePath(tmpDir, workspaceRootDir)
|
|
1085
1146
|
);
|
|
1086
|
-
await
|
|
1147
|
+
await fs16.remove(tmpDir);
|
|
1087
1148
|
log.info("Isolate completed at", isolateDir);
|
|
1088
1149
|
return isolateDir;
|
|
1089
1150
|
}
|