isolate-package 1.6.2 → 1.7.1
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 +8 -5
- package/dist/index.mjs +400 -356
- package/dist/index.mjs.map +1 -1
- package/dist/isolate-bin.mjs +400 -356
- package/dist/isolate-bin.mjs.map +1 -1
- package/package.json +1 -1
package/dist/isolate-bin.mjs
CHANGED
|
@@ -5,32 +5,79 @@ import console2 from "node:console";
|
|
|
5
5
|
import sourceMaps from "source-map-support";
|
|
6
6
|
|
|
7
7
|
// src/isolate.ts
|
|
8
|
-
import
|
|
8
|
+
import fs16 from "fs-extra";
|
|
9
9
|
import assert6 from "node:assert";
|
|
10
|
-
import
|
|
10
|
+
import path17 from "node:path";
|
|
11
11
|
|
|
12
|
-
// src/
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
12
|
+
// src/lib/config.ts
|
|
13
|
+
import fs5 from "fs-extra";
|
|
14
|
+
import assert from "node:assert";
|
|
15
|
+
import path2 from "node:path";
|
|
16
|
+
import { isEmpty } from "ramda";
|
|
16
17
|
|
|
17
|
-
// src/
|
|
18
|
-
import
|
|
18
|
+
// src/lib/logger.ts
|
|
19
|
+
import chalk from "chalk";
|
|
20
|
+
var _loggerHandlers = {
|
|
21
|
+
debug(...args) {
|
|
22
|
+
console.log(chalk.blue("debug"), ...args);
|
|
23
|
+
},
|
|
24
|
+
info(...args) {
|
|
25
|
+
console.log(chalk.green("info"), ...args);
|
|
26
|
+
},
|
|
27
|
+
warn(...args) {
|
|
28
|
+
console.log(chalk.yellow("warning"), ...args);
|
|
29
|
+
},
|
|
30
|
+
error(...args) {
|
|
31
|
+
console.log(chalk.red("error"), ...args);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var _logger = {
|
|
35
|
+
debug(...args) {
|
|
36
|
+
if (_logLevel === "debug") {
|
|
37
|
+
_loggerHandlers.debug(...args);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
info(...args) {
|
|
41
|
+
if (_logLevel === "debug" || _logLevel === "info") {
|
|
42
|
+
_loggerHandlers.info(...args);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
warn(...args) {
|
|
46
|
+
if (_logLevel === "debug" || _logLevel === "info" || _logLevel === "warn") {
|
|
47
|
+
_loggerHandlers.warn(...args);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
error(...args) {
|
|
51
|
+
_loggerHandlers.error(...args);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var _logLevel = "info";
|
|
55
|
+
function setLogger(logger) {
|
|
56
|
+
_loggerHandlers = logger;
|
|
57
|
+
return _logger;
|
|
58
|
+
}
|
|
59
|
+
function setLogLevel(logLevel) {
|
|
60
|
+
_logLevel = logLevel;
|
|
61
|
+
return _logger;
|
|
62
|
+
}
|
|
63
|
+
function useLogger() {
|
|
64
|
+
return _logger;
|
|
65
|
+
}
|
|
19
66
|
|
|
20
|
-
// src/utils/filter-object-undefined.ts
|
|
67
|
+
// src/lib/utils/filter-object-undefined.ts
|
|
21
68
|
function filterObjectUndefined(object) {
|
|
22
69
|
return Object.fromEntries(
|
|
23
70
|
Object.entries(object).filter(([_, value]) => value !== void 0)
|
|
24
71
|
);
|
|
25
72
|
}
|
|
26
73
|
|
|
27
|
-
// src/utils/get-dirname.ts
|
|
74
|
+
// src/lib/utils/get-dirname.ts
|
|
28
75
|
import { fileURLToPath } from "url";
|
|
29
76
|
function getDirname(importMetaUrl) {
|
|
30
77
|
return fileURLToPath(new URL(".", importMetaUrl));
|
|
31
78
|
}
|
|
32
79
|
|
|
33
|
-
// src/utils/get-error-message.ts
|
|
80
|
+
// src/lib/utils/get-error-message.ts
|
|
34
81
|
function getErrorMessage(error) {
|
|
35
82
|
return toErrorWithMessage(error).message;
|
|
36
83
|
}
|
|
@@ -47,28 +94,28 @@ function toErrorWithMessage(maybeError) {
|
|
|
47
94
|
}
|
|
48
95
|
}
|
|
49
96
|
|
|
50
|
-
// src/utils/get-relative-path.ts
|
|
51
|
-
function getRootRelativePath(
|
|
52
|
-
const strippedPath =
|
|
97
|
+
// src/lib/utils/get-relative-path.ts
|
|
98
|
+
function getRootRelativePath(path18, rootPath) {
|
|
99
|
+
const strippedPath = path18.replace(rootPath, "");
|
|
53
100
|
return strippedPath.startsWith("/") ? `(root)${strippedPath}` : `(root)/${strippedPath}`;
|
|
54
101
|
}
|
|
55
|
-
function getIsolateRelativePath(
|
|
56
|
-
const strippedPath =
|
|
102
|
+
function getIsolateRelativePath(path18, isolatePath) {
|
|
103
|
+
const strippedPath = path18.replace(isolatePath, "");
|
|
57
104
|
return strippedPath.startsWith("/") ? `(isolate)${strippedPath}` : `(isolate)/${strippedPath}`;
|
|
58
105
|
}
|
|
59
106
|
|
|
60
|
-
// src/utils/inspect-value.ts
|
|
107
|
+
// src/lib/utils/inspect-value.ts
|
|
61
108
|
import { inspect } from "node:util";
|
|
62
109
|
function inspectValue(value) {
|
|
63
110
|
return inspect(value, false, 4, true);
|
|
64
111
|
}
|
|
65
112
|
|
|
66
|
-
// src/utils/is-present.ts
|
|
113
|
+
// src/lib/utils/is-present.ts
|
|
67
114
|
function isDefined(t) {
|
|
68
115
|
return t !== void 0;
|
|
69
116
|
}
|
|
70
117
|
|
|
71
|
-
// src/utils/json.ts
|
|
118
|
+
// src/lib/utils/json.ts
|
|
72
119
|
import fs from "fs-extra";
|
|
73
120
|
import stripJsonComments from "strip-json-comments";
|
|
74
121
|
function readTypedJsonSync(filePath) {
|
|
@@ -94,56 +141,7 @@ async function readTypedJson(filePath) {
|
|
|
94
141
|
}
|
|
95
142
|
}
|
|
96
143
|
|
|
97
|
-
// src/utils/
|
|
98
|
-
import chalk from "chalk";
|
|
99
|
-
var _loggerHandlers = {
|
|
100
|
-
debug(...args) {
|
|
101
|
-
console.log(chalk.blue("debug"), ...args);
|
|
102
|
-
},
|
|
103
|
-
info(...args) {
|
|
104
|
-
console.log(chalk.green("info"), ...args);
|
|
105
|
-
},
|
|
106
|
-
warn(...args) {
|
|
107
|
-
console.log(chalk.yellow("warning"), ...args);
|
|
108
|
-
},
|
|
109
|
-
error(...args) {
|
|
110
|
-
console.log(chalk.red("error"), ...args);
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
var _logger = {
|
|
114
|
-
debug(...args) {
|
|
115
|
-
if (_logLevel === "debug") {
|
|
116
|
-
_loggerHandlers.debug(...args);
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
info(...args) {
|
|
120
|
-
if (_logLevel === "debug" || _logLevel === "info") {
|
|
121
|
-
_loggerHandlers.info(...args);
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
warn(...args) {
|
|
125
|
-
if (_logLevel === "debug" || _logLevel === "info" || _logLevel === "warn") {
|
|
126
|
-
_loggerHandlers.warn(...args);
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
error(...args) {
|
|
130
|
-
_loggerHandlers.error(...args);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
var _logLevel = "info";
|
|
134
|
-
function setLogger(logger) {
|
|
135
|
-
_loggerHandlers = logger;
|
|
136
|
-
return _logger;
|
|
137
|
-
}
|
|
138
|
-
function setLogLevel(logLevel) {
|
|
139
|
-
_logLevel = logLevel;
|
|
140
|
-
return _logger;
|
|
141
|
-
}
|
|
142
|
-
function useLogger() {
|
|
143
|
-
return _logger;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// src/utils/pack.ts
|
|
144
|
+
// src/lib/utils/pack.ts
|
|
147
145
|
import fs2 from "fs-extra";
|
|
148
146
|
import { exec } from "node:child_process";
|
|
149
147
|
import path from "node:path";
|
|
@@ -191,7 +189,7 @@ async function pack(srcDir, dstDir, usePnpmPack = false) {
|
|
|
191
189
|
return filePath;
|
|
192
190
|
}
|
|
193
191
|
|
|
194
|
-
// src/utils/unpack.ts
|
|
192
|
+
// src/lib/utils/unpack.ts
|
|
195
193
|
import fs3 from "fs-extra";
|
|
196
194
|
import tar from "tar-fs";
|
|
197
195
|
import { createGunzip } from "zlib";
|
|
@@ -201,7 +199,7 @@ async function unpack(filePath, unpackDir) {
|
|
|
201
199
|
});
|
|
202
200
|
}
|
|
203
201
|
|
|
204
|
-
// src/utils/yaml.ts
|
|
202
|
+
// src/lib/utils/yaml.ts
|
|
205
203
|
import fs4 from "fs-extra";
|
|
206
204
|
import yaml from "yaml";
|
|
207
205
|
function readTypedYamlSync(filePath) {
|
|
@@ -216,54 +214,7 @@ function readTypedYamlSync(filePath) {
|
|
|
216
214
|
}
|
|
217
215
|
}
|
|
218
216
|
|
|
219
|
-
// src/
|
|
220
|
-
import path2 from "node:path";
|
|
221
|
-
function patchInternalEntries(dependencies, packagesRegistry, parentRootRelativeDir) {
|
|
222
|
-
const log = useLogger();
|
|
223
|
-
const allWorkspacePackageNames = Object.keys(packagesRegistry);
|
|
224
|
-
return Object.fromEntries(
|
|
225
|
-
Object.entries(dependencies).map(([key, value]) => {
|
|
226
|
-
if (allWorkspacePackageNames.includes(key)) {
|
|
227
|
-
const def = packagesRegistry[key];
|
|
228
|
-
const relativePath = parentRootRelativeDir ? path2.relative(parentRootRelativeDir, `./${def.rootRelativeDir}`) : `./${def.rootRelativeDir}`;
|
|
229
|
-
const linkPath = `file:${relativePath}`;
|
|
230
|
-
log.debug(`Linking dependency ${key} to ${linkPath}`);
|
|
231
|
-
return [key, linkPath];
|
|
232
|
-
} else {
|
|
233
|
-
return [key, value];
|
|
234
|
-
}
|
|
235
|
-
})
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// src/helpers/adapt-manifest-internal-deps.ts
|
|
240
|
-
function adaptManifestInternalDeps({
|
|
241
|
-
manifest,
|
|
242
|
-
packagesRegistry,
|
|
243
|
-
parentRootRelativeDir
|
|
244
|
-
}, opts = {}) {
|
|
245
|
-
return Object.assign(
|
|
246
|
-
omit(["devDependencies"], manifest),
|
|
247
|
-
filterObjectUndefined({
|
|
248
|
-
dependencies: manifest.dependencies ? patchInternalEntries(
|
|
249
|
-
manifest.dependencies,
|
|
250
|
-
packagesRegistry,
|
|
251
|
-
parentRootRelativeDir
|
|
252
|
-
) : void 0,
|
|
253
|
-
devDependencies: opts.includeDevDependencies && manifest.devDependencies ? patchInternalEntries(
|
|
254
|
-
manifest.devDependencies,
|
|
255
|
-
packagesRegistry,
|
|
256
|
-
parentRootRelativeDir
|
|
257
|
-
) : void 0
|
|
258
|
-
})
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// src/helpers/config.ts
|
|
263
|
-
import fs5 from "fs-extra";
|
|
264
|
-
import assert from "node:assert";
|
|
265
|
-
import path3 from "node:path";
|
|
266
|
-
import { isEmpty } from "ramda";
|
|
217
|
+
// src/lib/config.ts
|
|
267
218
|
var configDefaults = {
|
|
268
219
|
buildDirName: void 0,
|
|
269
220
|
includeDevDependencies: false,
|
|
@@ -299,7 +250,7 @@ function resolveConfig() {
|
|
|
299
250
|
}
|
|
300
251
|
setLogLevel(process.env.DEBUG_ISOLATE_CONFIG ? "debug" : "info");
|
|
301
252
|
const log = useLogger();
|
|
302
|
-
const configFilePath =
|
|
253
|
+
const configFilePath = path2.join(process.cwd(), CONFIG_FILE_NAME);
|
|
303
254
|
if (_user_defined_config) {
|
|
304
255
|
log.debug(`Using user defined config:`, inspectValue(_user_defined_config));
|
|
305
256
|
} else {
|
|
@@ -329,42 +280,134 @@ function getUserDefinedConfig() {
|
|
|
329
280
|
return _user_defined_config;
|
|
330
281
|
}
|
|
331
282
|
|
|
332
|
-
// src/
|
|
333
|
-
import
|
|
334
|
-
import assert3 from "node:assert";
|
|
335
|
-
import { execSync } from "node:child_process";
|
|
283
|
+
// src/lib/lockfile/process-lockfile.ts
|
|
284
|
+
import fs9 from "fs-extra";
|
|
336
285
|
import path7 from "node:path";
|
|
286
|
+
import { mapObjIndexed } from "ramda";
|
|
287
|
+
|
|
288
|
+
// src/lib/package-manager/helpers/infer-from-files.ts
|
|
289
|
+
import fs6 from "fs-extra";
|
|
290
|
+
import { execSync } from "node:child_process";
|
|
291
|
+
import path3 from "node:path";
|
|
292
|
+
|
|
293
|
+
// src/lib/package-manager/names.ts
|
|
294
|
+
var supportedPackageManagerNames = ["pnpm", "yarn", "npm"];
|
|
295
|
+
function getLockfileFileName(name) {
|
|
296
|
+
switch (name) {
|
|
297
|
+
case "pnpm":
|
|
298
|
+
return "pnpm-lock.yaml";
|
|
299
|
+
case "yarn":
|
|
300
|
+
return "yarn.lock";
|
|
301
|
+
case "npm":
|
|
302
|
+
return "package-lock.json";
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// src/lib/package-manager/helpers/infer-from-files.ts
|
|
307
|
+
function inferFromFiles(workspaceRoot) {
|
|
308
|
+
for (const name of supportedPackageManagerNames) {
|
|
309
|
+
const lockfileName = getLockfileFileName(name);
|
|
310
|
+
if (fs6.existsSync(path3.join(workspaceRoot, lockfileName))) {
|
|
311
|
+
return { name, version: getVersion(name) };
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (fs6.existsSync(path3.join(workspaceRoot, "npm-shrinkwrap.json"))) {
|
|
315
|
+
return { name: "npm", version: getVersion("npm") };
|
|
316
|
+
}
|
|
317
|
+
throw new Error(`Failed to detect package manager`);
|
|
318
|
+
}
|
|
319
|
+
function getVersion(packageManagerName) {
|
|
320
|
+
const buffer = execSync(`${packageManagerName} --version`);
|
|
321
|
+
return buffer.toString().trim();
|
|
322
|
+
}
|
|
337
323
|
|
|
338
|
-
// src/helpers/
|
|
324
|
+
// src/lib/package-manager/helpers/infer-from-manifest.ts
|
|
339
325
|
import fs7 from "fs-extra";
|
|
340
|
-
import
|
|
341
|
-
import
|
|
326
|
+
import assert2 from "node:assert";
|
|
327
|
+
import path4 from "node:path";
|
|
328
|
+
function inferFromManifest(workspaceRoot) {
|
|
329
|
+
const log = useLogger();
|
|
330
|
+
const rootManifest = readTypedJsonSync(
|
|
331
|
+
path4.join(workspaceRoot, "package.json")
|
|
332
|
+
);
|
|
333
|
+
if (!rootManifest.packageManager) {
|
|
334
|
+
log.debug("No packageManager field found in root manifest");
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const [name, version = "*"] = rootManifest.packageManager.split("@");
|
|
338
|
+
assert2(
|
|
339
|
+
supportedPackageManagerNames.includes(name),
|
|
340
|
+
`Package manager "${name}" is not currently supported`
|
|
341
|
+
);
|
|
342
|
+
const lockfileName = getLockfileFileName(name);
|
|
343
|
+
assert2(
|
|
344
|
+
fs7.existsSync(path4.join(workspaceRoot, lockfileName)),
|
|
345
|
+
`Manifest declares ${name} to be the packageManager, but failed to find ${lockfileName} in workspace root`
|
|
346
|
+
);
|
|
347
|
+
return { name, version };
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// src/lib/package-manager/index.ts
|
|
351
|
+
var packageManager;
|
|
352
|
+
function usePackageManager() {
|
|
353
|
+
if (!packageManager) {
|
|
354
|
+
throw Error(
|
|
355
|
+
"No package manager detected. Make sure to call detectPackageManager() before usePackageManager()"
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
return packageManager;
|
|
359
|
+
}
|
|
360
|
+
function detectPackageManager(workspaceRoot) {
|
|
361
|
+
packageManager = inferFromManifest(workspaceRoot) ?? inferFromFiles(workspaceRoot);
|
|
362
|
+
return packageManager;
|
|
363
|
+
}
|
|
342
364
|
|
|
343
|
-
// src/helpers/generate-npm-lockfile.ts
|
|
365
|
+
// src/lib/lockfile/helpers/generate-npm-lockfile.ts
|
|
344
366
|
import Arborist from "@npmcli/arborist";
|
|
345
|
-
import
|
|
346
|
-
import
|
|
367
|
+
import fs8 from "fs-extra";
|
|
368
|
+
import path5 from "node:path";
|
|
347
369
|
async function generateNpmLockfile({
|
|
370
|
+
workspaceRootDir,
|
|
348
371
|
isolateDir
|
|
349
372
|
}) {
|
|
350
373
|
const log = useLogger();
|
|
351
|
-
log.
|
|
352
|
-
const
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
374
|
+
log.info("Generating NPM lockfile...");
|
|
375
|
+
const origRootNodeModulesPath = path5.join(workspaceRootDir, "node_modules");
|
|
376
|
+
const tempRootNodeModulesPath = path5.join(isolateDir, "node_modules");
|
|
377
|
+
if (!fs8.existsSync(origRootNodeModulesPath)) {
|
|
378
|
+
throw new Error(
|
|
379
|
+
`Failed to find node_modules at ${origRootNodeModulesPath}`
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
log.debug(`Temporarily moving node_modules to the isolate output`);
|
|
383
|
+
let hasMovedNodeModules = false;
|
|
384
|
+
try {
|
|
385
|
+
await fs8.move(origRootNodeModulesPath, tempRootNodeModulesPath);
|
|
386
|
+
hasMovedNodeModules = true;
|
|
387
|
+
const arborist = new Arborist({ path: isolateDir });
|
|
388
|
+
const { meta } = await arborist.buildIdealTree();
|
|
389
|
+
meta?.commit();
|
|
390
|
+
const lockfilePath = path5.join(isolateDir, "package-lock.json");
|
|
391
|
+
await fs8.writeFile(lockfilePath, String(meta));
|
|
392
|
+
log.debug("Created lockfile at", lockfilePath);
|
|
393
|
+
} catch (err) {
|
|
394
|
+
log.error(getErrorMessage(err));
|
|
395
|
+
} finally {
|
|
396
|
+
if (hasMovedNodeModules) {
|
|
397
|
+
log.debug(`Restoring node_modules to the workspace root`);
|
|
398
|
+
await fs8.move(tempRootNodeModulesPath, origRootNodeModulesPath);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
358
401
|
}
|
|
359
402
|
|
|
360
|
-
// src/helpers/generate-pnpm-lockfile.ts
|
|
403
|
+
// src/lib/lockfile/helpers/generate-pnpm-lockfile.ts
|
|
361
404
|
import {
|
|
362
405
|
getLockfileImporterId,
|
|
363
406
|
readWantedLockfile,
|
|
364
407
|
writeWantedLockfile
|
|
365
408
|
} from "@pnpm/lockfile-file";
|
|
366
|
-
import
|
|
367
|
-
import
|
|
409
|
+
import assert3 from "node:assert";
|
|
410
|
+
import path6 from "node:path";
|
|
368
411
|
import { pick } from "ramda";
|
|
369
412
|
async function generatePnpmLockfile({
|
|
370
413
|
workspaceRootDir,
|
|
@@ -375,11 +418,11 @@ async function generatePnpmLockfile({
|
|
|
375
418
|
}) {
|
|
376
419
|
const { includeDevDependencies } = useConfig();
|
|
377
420
|
const log = useLogger();
|
|
378
|
-
log.
|
|
421
|
+
log.info("Generating PNPM lockfile...");
|
|
379
422
|
const lockfile = await readWantedLockfile(workspaceRootDir, {
|
|
380
423
|
ignoreIncompatible: false
|
|
381
424
|
});
|
|
382
|
-
|
|
425
|
+
assert3(lockfile, `No input lockfile found at ${workspaceRootDir}`);
|
|
383
426
|
const targetImporterId = getLockfileImporterId(
|
|
384
427
|
workspaceRootDir,
|
|
385
428
|
targetPackageDir
|
|
@@ -387,7 +430,7 @@ async function generatePnpmLockfile({
|
|
|
387
430
|
const directoryByPackageName = Object.fromEntries(
|
|
388
431
|
internalDepPackageNames.map((name) => {
|
|
389
432
|
const pkg = packagesRegistry[name];
|
|
390
|
-
|
|
433
|
+
assert3(pkg, `Package ${name} not found in packages registry`);
|
|
391
434
|
return [name, pkg.rootRelativeDir];
|
|
392
435
|
})
|
|
393
436
|
);
|
|
@@ -425,20 +468,10 @@ async function generatePnpmLockfile({
|
|
|
425
468
|
)
|
|
426
469
|
);
|
|
427
470
|
await writeWantedLockfile(isolateDir, lockfile);
|
|
428
|
-
log.debug("Created lockfile at",
|
|
471
|
+
log.debug("Created lockfile at", path6.join(isolateDir, "pnpm-lock.yaml"));
|
|
429
472
|
}
|
|
430
473
|
|
|
431
|
-
// src/
|
|
432
|
-
function getLockfileFileName(name) {
|
|
433
|
-
switch (name) {
|
|
434
|
-
case "pnpm":
|
|
435
|
-
return "pnpm-lock.yaml";
|
|
436
|
-
case "yarn":
|
|
437
|
-
return "yarn.lock";
|
|
438
|
-
case "npm":
|
|
439
|
-
return "package-lock.json";
|
|
440
|
-
}
|
|
441
|
-
}
|
|
474
|
+
// src/lib/lockfile/process-lockfile.ts
|
|
442
475
|
function pnpmMapImporter({ dependencies, devDependencies, ...rest }, {
|
|
443
476
|
includeDevDependencies,
|
|
444
477
|
directoryByPackageName
|
|
@@ -468,16 +501,15 @@ async function processLockfile({
|
|
|
468
501
|
switch (name) {
|
|
469
502
|
case "npm": {
|
|
470
503
|
await generateNpmLockfile({
|
|
471
|
-
|
|
472
|
-
isolateDir
|
|
473
|
-
packagesRegistry
|
|
504
|
+
workspaceRootDir,
|
|
505
|
+
isolateDir
|
|
474
506
|
});
|
|
475
507
|
break;
|
|
476
508
|
}
|
|
477
509
|
case "yarn": {
|
|
478
|
-
const lockfileSrcPath =
|
|
479
|
-
const lockfileDstPath =
|
|
480
|
-
|
|
510
|
+
const lockfileSrcPath = path7.join(workspaceRootDir, fileName);
|
|
511
|
+
const lockfileDstPath = path7.join(isolateDir, fileName);
|
|
512
|
+
fs9.copyFileSync(lockfileSrcPath, lockfileDstPath);
|
|
481
513
|
log.debug("Copied lockfile to", lockfileDstPath);
|
|
482
514
|
break;
|
|
483
515
|
}
|
|
@@ -496,60 +528,63 @@ async function processLockfile({
|
|
|
496
528
|
}
|
|
497
529
|
}
|
|
498
530
|
|
|
499
|
-
// src/
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
531
|
+
// src/lib/manifest/adapt-target-package-manifest.ts
|
|
532
|
+
import fs11 from "fs-extra";
|
|
533
|
+
import path10 from "node:path";
|
|
534
|
+
import { omit as omit3 } from "ramda";
|
|
535
|
+
|
|
536
|
+
// src/lib/manifest/helpers/adapt-internal-package-manifests.ts
|
|
537
|
+
import fs10 from "fs-extra";
|
|
538
|
+
import path9 from "node:path";
|
|
539
|
+
import { omit as omit2 } from "ramda";
|
|
540
|
+
|
|
541
|
+
// src/lib/manifest/helpers/adapt-manifest-internal-deps.ts
|
|
542
|
+
import { omit } from "ramda";
|
|
543
|
+
|
|
544
|
+
// src/lib/manifest/helpers/patch-internal-entries.ts
|
|
545
|
+
import path8 from "node:path";
|
|
546
|
+
function patchInternalEntries(dependencies, packagesRegistry, parentRootRelativeDir) {
|
|
547
|
+
const log = useLogger();
|
|
548
|
+
const allWorkspacePackageNames = Object.keys(packagesRegistry);
|
|
549
|
+
return Object.fromEntries(
|
|
550
|
+
Object.entries(dependencies).map(([key, value]) => {
|
|
551
|
+
if (allWorkspacePackageNames.includes(key)) {
|
|
552
|
+
const def = packagesRegistry[key];
|
|
553
|
+
const relativePath = parentRootRelativeDir ? path8.relative(parentRootRelativeDir, `./${def.rootRelativeDir}`) : `./${def.rootRelativeDir}`;
|
|
554
|
+
const linkPath = `file:${relativePath}`;
|
|
555
|
+
log.debug(`Linking dependency ${key} to ${linkPath}`);
|
|
556
|
+
return [key, linkPath];
|
|
557
|
+
} else {
|
|
558
|
+
return [key, value];
|
|
559
|
+
}
|
|
560
|
+
})
|
|
524
561
|
);
|
|
525
|
-
return { name, version };
|
|
526
|
-
}
|
|
527
|
-
function inferFromFiles(workspaceRoot) {
|
|
528
|
-
for (const name of supportedPackageManagerNames) {
|
|
529
|
-
const lockfileName = getLockfileFileName(name);
|
|
530
|
-
if (fs8.existsSync(path7.join(workspaceRoot, lockfileName))) {
|
|
531
|
-
return { name, version: getVersion(name) };
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
if (fs8.existsSync(path7.join(workspaceRoot, "npm-shrinkwrap.json"))) {
|
|
535
|
-
return { name: "npm", version: getVersion("npm") };
|
|
536
|
-
}
|
|
537
|
-
throw new Error(`Failed to detect package manager`);
|
|
538
562
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
)
|
|
548
|
-
|
|
549
|
-
|
|
563
|
+
|
|
564
|
+
// src/lib/manifest/helpers/adapt-manifest-internal-deps.ts
|
|
565
|
+
function adaptManifestInternalDeps({
|
|
566
|
+
manifest,
|
|
567
|
+
packagesRegistry,
|
|
568
|
+
parentRootRelativeDir
|
|
569
|
+
}, opts = {}) {
|
|
570
|
+
return Object.assign(
|
|
571
|
+
omit(["devDependencies"], manifest),
|
|
572
|
+
filterObjectUndefined({
|
|
573
|
+
dependencies: manifest.dependencies ? patchInternalEntries(
|
|
574
|
+
manifest.dependencies,
|
|
575
|
+
packagesRegistry,
|
|
576
|
+
parentRootRelativeDir
|
|
577
|
+
) : void 0,
|
|
578
|
+
devDependencies: opts.includeDevDependencies && manifest.devDependencies ? patchInternalEntries(
|
|
579
|
+
manifest.devDependencies,
|
|
580
|
+
packagesRegistry,
|
|
581
|
+
parentRootRelativeDir
|
|
582
|
+
) : void 0
|
|
583
|
+
})
|
|
584
|
+
);
|
|
550
585
|
}
|
|
551
586
|
|
|
552
|
-
// src/helpers/adapt-internal-package-manifests.ts
|
|
587
|
+
// src/lib/manifest/helpers/adapt-internal-package-manifests.ts
|
|
553
588
|
async function adaptInternalPackageManifests(internalPackageNames, packagesRegistry, isolateDir) {
|
|
554
589
|
const packageManager2 = usePackageManager();
|
|
555
590
|
const { includeDevDependencies } = useConfig();
|
|
@@ -577,126 +612,46 @@ async function adaptInternalPackageManifests(internalPackageNames, packagesRegis
|
|
|
577
612
|
},
|
|
578
613
|
{ includeDevDependencies }
|
|
579
614
|
);
|
|
580
|
-
await
|
|
581
|
-
|
|
615
|
+
await fs10.writeFile(
|
|
616
|
+
path9.join(isolateDir, rootRelativeDir, "package.json"),
|
|
582
617
|
JSON.stringify(outputManifest, null, 2)
|
|
583
618
|
);
|
|
584
619
|
})
|
|
585
620
|
);
|
|
586
621
|
}
|
|
587
622
|
|
|
588
|
-
// src/
|
|
589
|
-
import fs10 from "fs-extra";
|
|
590
|
-
import path9 from "node:path";
|
|
591
|
-
import { omit as omit3 } from "ramda";
|
|
623
|
+
// src/lib/manifest/adapt-target-package-manifest.ts
|
|
592
624
|
async function adaptTargetPackageManifest(manifest, packagesRegistry, isolateDir) {
|
|
593
625
|
const packageManager2 = usePackageManager();
|
|
594
626
|
const { includeDevDependencies } = useConfig();
|
|
595
|
-
const outputManifest = packageManager2.name === "pnpm" ?
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
627
|
+
const outputManifest = packageManager2.name === "pnpm" ? (
|
|
628
|
+
/**
|
|
629
|
+
* For PNPM the output itself is a workspace so we can preserve the specifiers
|
|
630
|
+
* with "workspace:*" in the output manifest.
|
|
631
|
+
*/
|
|
632
|
+
Object.assign(omit3(["devDependencies", "scripts"], manifest), {
|
|
633
|
+
devDependencies: includeDevDependencies ? manifest.devDependencies : void 0
|
|
634
|
+
})
|
|
635
|
+
) : (
|
|
636
|
+
/** For other package managers we replace the links to internal dependencies */
|
|
637
|
+
adaptManifestInternalDeps(
|
|
638
|
+
{
|
|
639
|
+
manifest,
|
|
640
|
+
packagesRegistry
|
|
641
|
+
},
|
|
642
|
+
{ includeDevDependencies }
|
|
643
|
+
)
|
|
603
644
|
);
|
|
604
|
-
await
|
|
605
|
-
|
|
645
|
+
await fs11.writeFile(
|
|
646
|
+
path10.join(isolateDir, "package.json"),
|
|
606
647
|
JSON.stringify(outputManifest, null, 2)
|
|
607
648
|
);
|
|
608
649
|
}
|
|
609
650
|
|
|
610
|
-
// src/
|
|
611
|
-
import fs11 from "fs-extra";
|
|
612
|
-
import { globSync } from "glob";
|
|
651
|
+
// src/lib/manifest/import-manifest.ts
|
|
613
652
|
import path11 from "node:path";
|
|
614
653
|
|
|
615
|
-
// src/
|
|
616
|
-
import assert4 from "node:assert";
|
|
617
|
-
import path10 from "node:path";
|
|
618
|
-
function findPackagesGlobs(workspaceRootDir) {
|
|
619
|
-
const log = useLogger();
|
|
620
|
-
const packageManager2 = usePackageManager();
|
|
621
|
-
switch (packageManager2.name) {
|
|
622
|
-
case "pnpm": {
|
|
623
|
-
const { packages: globs } = readTypedYamlSync(
|
|
624
|
-
path10.join(workspaceRootDir, "pnpm-workspace.yaml")
|
|
625
|
-
);
|
|
626
|
-
log.debug("Detected pnpm packages globs:", inspectValue(globs));
|
|
627
|
-
return globs;
|
|
628
|
-
}
|
|
629
|
-
case "yarn":
|
|
630
|
-
case "npm": {
|
|
631
|
-
const workspaceRootManifestPath = path10.join(
|
|
632
|
-
workspaceRootDir,
|
|
633
|
-
"package.json"
|
|
634
|
-
);
|
|
635
|
-
const { workspaces } = readTypedJsonSync(
|
|
636
|
-
workspaceRootManifestPath
|
|
637
|
-
);
|
|
638
|
-
if (!workspaces) {
|
|
639
|
-
throw new Error(
|
|
640
|
-
`No workspaces field found in ${workspaceRootManifestPath}`
|
|
641
|
-
);
|
|
642
|
-
}
|
|
643
|
-
if (Array.isArray(workspaces)) {
|
|
644
|
-
return workspaces;
|
|
645
|
-
} else {
|
|
646
|
-
const workspacesObject = workspaces;
|
|
647
|
-
assert4(
|
|
648
|
-
workspacesObject.packages,
|
|
649
|
-
"workspaces.packages must be an array"
|
|
650
|
-
);
|
|
651
|
-
return workspacesObject.packages;
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
// src/helpers/create-packages-registry.ts
|
|
658
|
-
async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverride) {
|
|
659
|
-
const log = useLogger();
|
|
660
|
-
if (workspacePackagesOverride) {
|
|
661
|
-
log.debug(
|
|
662
|
-
`Override workspace packages via config: ${workspacePackagesOverride}`
|
|
663
|
-
);
|
|
664
|
-
}
|
|
665
|
-
const packagesGlobs = workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);
|
|
666
|
-
const cwd = process.cwd();
|
|
667
|
-
process.chdir(workspaceRootDir);
|
|
668
|
-
const allPackages = packagesGlobs.flatMap((glob) => globSync(glob)).filter((dir) => fs11.lstatSync(dir).isDirectory());
|
|
669
|
-
const registry = (await Promise.all(
|
|
670
|
-
allPackages.map(async (rootRelativeDir) => {
|
|
671
|
-
const manifestPath = path11.join(rootRelativeDir, "package.json");
|
|
672
|
-
if (!fs11.existsSync(manifestPath)) {
|
|
673
|
-
log.warn(
|
|
674
|
-
`Ignoring directory ./${rootRelativeDir} because it does not contain a package.json file`
|
|
675
|
-
);
|
|
676
|
-
return;
|
|
677
|
-
} else {
|
|
678
|
-
log.debug(`Registering package ./${rootRelativeDir}`);
|
|
679
|
-
const manifest = await readTypedJson(
|
|
680
|
-
path11.join(rootRelativeDir, "package.json")
|
|
681
|
-
);
|
|
682
|
-
return {
|
|
683
|
-
manifest,
|
|
684
|
-
rootRelativeDir,
|
|
685
|
-
absoluteDir: path11.join(workspaceRootDir, rootRelativeDir)
|
|
686
|
-
};
|
|
687
|
-
}
|
|
688
|
-
})
|
|
689
|
-
)).reduce((acc, info) => {
|
|
690
|
-
if (info) {
|
|
691
|
-
acc[info.manifest.name] = info;
|
|
692
|
-
}
|
|
693
|
-
return acc;
|
|
694
|
-
}, {});
|
|
695
|
-
process.chdir(cwd);
|
|
696
|
-
return registry;
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
// src/helpers/get-build-output-dir.ts
|
|
654
|
+
// src/lib/output/get-build-output-dir.ts
|
|
700
655
|
import fs12 from "fs-extra";
|
|
701
656
|
import path12 from "node:path";
|
|
702
657
|
import outdent from "outdent";
|
|
@@ -727,26 +682,8 @@ async function getBuildOutputDir(targetPackageDir) {
|
|
|
727
682
|
}
|
|
728
683
|
}
|
|
729
684
|
|
|
730
|
-
// src/
|
|
731
|
-
import
|
|
732
|
-
function listInternalPackages(manifest, packagesRegistry, { includeDevDependencies = false } = {}) {
|
|
733
|
-
const allWorkspacePackageNames = Object.keys(packagesRegistry);
|
|
734
|
-
const internalPackageNames = (includeDevDependencies ? [
|
|
735
|
-
...Object.keys(manifest.dependencies ?? {}),
|
|
736
|
-
...Object.keys(manifest.devDependencies ?? {})
|
|
737
|
-
] : Object.keys(manifest.dependencies ?? {})).filter((name) => allWorkspacePackageNames.includes(name));
|
|
738
|
-
const nestedInternalPackageNames = internalPackageNames.flatMap(
|
|
739
|
-
(packageName) => listInternalPackages(
|
|
740
|
-
packagesRegistry[packageName].manifest,
|
|
741
|
-
packagesRegistry,
|
|
742
|
-
{ includeDevDependencies }
|
|
743
|
-
)
|
|
744
|
-
);
|
|
745
|
-
return uniq(internalPackageNames.concat(nestedInternalPackageNames));
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
// src/helpers/pack-dependencies.ts
|
|
749
|
-
import assert5 from "node:assert";
|
|
685
|
+
// src/lib/output/pack-dependencies.ts
|
|
686
|
+
import assert4 from "node:assert";
|
|
750
687
|
async function packDependencies({
|
|
751
688
|
/** All packages found in the monorepo by workspaces declaration */
|
|
752
689
|
packagesRegistry,
|
|
@@ -771,7 +708,7 @@ async function packDependencies({
|
|
|
771
708
|
}
|
|
772
709
|
for (const dependency of internalPackageNames) {
|
|
773
710
|
const def = packagesRegistry[dependency];
|
|
774
|
-
|
|
711
|
+
assert4(dependency, `Failed to find package definition for ${dependency}`);
|
|
775
712
|
const { name: name2 } = def.manifest;
|
|
776
713
|
if (packedFileByName[name2]) {
|
|
777
714
|
log.debug(`Skipping ${name2} because it has already been packed`);
|
|
@@ -786,7 +723,7 @@ async function packDependencies({
|
|
|
786
723
|
return packedFileByName;
|
|
787
724
|
}
|
|
788
725
|
|
|
789
|
-
// src/
|
|
726
|
+
// src/lib/output/process-build-output-files.ts
|
|
790
727
|
import fs13 from "fs-extra";
|
|
791
728
|
import path13 from "node:path";
|
|
792
729
|
var TIMEOUT_MS = 5e3;
|
|
@@ -811,7 +748,7 @@ async function processBuildOutputFiles({
|
|
|
811
748
|
await fs13.copy(path13.join(unpackDir, "package"), isolateDir);
|
|
812
749
|
}
|
|
813
750
|
|
|
814
|
-
// src/
|
|
751
|
+
// src/lib/output/unpack-dependencies.ts
|
|
815
752
|
import fs14 from "fs-extra";
|
|
816
753
|
import path14, { join } from "node:path";
|
|
817
754
|
async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, isolateDir) {
|
|
@@ -837,6 +774,113 @@ async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, i
|
|
|
837
774
|
);
|
|
838
775
|
}
|
|
839
776
|
|
|
777
|
+
// src/lib/registry/create-packages-registry.ts
|
|
778
|
+
import fs15 from "fs-extra";
|
|
779
|
+
import { globSync } from "glob";
|
|
780
|
+
import path16 from "node:path";
|
|
781
|
+
|
|
782
|
+
// src/lib/registry/helpers/find-packages-globs.ts
|
|
783
|
+
import assert5 from "node:assert";
|
|
784
|
+
import path15 from "node:path";
|
|
785
|
+
function findPackagesGlobs(workspaceRootDir) {
|
|
786
|
+
const log = useLogger();
|
|
787
|
+
const packageManager2 = usePackageManager();
|
|
788
|
+
switch (packageManager2.name) {
|
|
789
|
+
case "pnpm": {
|
|
790
|
+
const { packages: globs } = readTypedYamlSync(
|
|
791
|
+
path15.join(workspaceRootDir, "pnpm-workspace.yaml")
|
|
792
|
+
);
|
|
793
|
+
log.debug("Detected pnpm packages globs:", inspectValue(globs));
|
|
794
|
+
return globs;
|
|
795
|
+
}
|
|
796
|
+
case "yarn":
|
|
797
|
+
case "npm": {
|
|
798
|
+
const workspaceRootManifestPath = path15.join(
|
|
799
|
+
workspaceRootDir,
|
|
800
|
+
"package.json"
|
|
801
|
+
);
|
|
802
|
+
const { workspaces } = readTypedJsonSync(
|
|
803
|
+
workspaceRootManifestPath
|
|
804
|
+
);
|
|
805
|
+
if (!workspaces) {
|
|
806
|
+
throw new Error(
|
|
807
|
+
`No workspaces field found in ${workspaceRootManifestPath}`
|
|
808
|
+
);
|
|
809
|
+
}
|
|
810
|
+
if (Array.isArray(workspaces)) {
|
|
811
|
+
return workspaces;
|
|
812
|
+
} else {
|
|
813
|
+
const workspacesObject = workspaces;
|
|
814
|
+
assert5(
|
|
815
|
+
workspacesObject.packages,
|
|
816
|
+
"workspaces.packages must be an array"
|
|
817
|
+
);
|
|
818
|
+
return workspacesObject.packages;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// src/lib/registry/create-packages-registry.ts
|
|
825
|
+
async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverride) {
|
|
826
|
+
const log = useLogger();
|
|
827
|
+
if (workspacePackagesOverride) {
|
|
828
|
+
log.debug(
|
|
829
|
+
`Override workspace packages via config: ${workspacePackagesOverride}`
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
const packagesGlobs = workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);
|
|
833
|
+
const cwd = process.cwd();
|
|
834
|
+
process.chdir(workspaceRootDir);
|
|
835
|
+
const allPackages = packagesGlobs.flatMap((glob) => globSync(glob)).filter((dir) => fs15.lstatSync(dir).isDirectory());
|
|
836
|
+
const registry = (await Promise.all(
|
|
837
|
+
allPackages.map(async (rootRelativeDir) => {
|
|
838
|
+
const manifestPath = path16.join(rootRelativeDir, "package.json");
|
|
839
|
+
if (!fs15.existsSync(manifestPath)) {
|
|
840
|
+
log.warn(
|
|
841
|
+
`Ignoring directory ./${rootRelativeDir} because it does not contain a package.json file`
|
|
842
|
+
);
|
|
843
|
+
return;
|
|
844
|
+
} else {
|
|
845
|
+
log.debug(`Registering package ./${rootRelativeDir}`);
|
|
846
|
+
const manifest = await readTypedJson(
|
|
847
|
+
path16.join(rootRelativeDir, "package.json")
|
|
848
|
+
);
|
|
849
|
+
return {
|
|
850
|
+
manifest,
|
|
851
|
+
rootRelativeDir,
|
|
852
|
+
absoluteDir: path16.join(workspaceRootDir, rootRelativeDir)
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
})
|
|
856
|
+
)).reduce((acc, info) => {
|
|
857
|
+
if (info) {
|
|
858
|
+
acc[info.manifest.name] = info;
|
|
859
|
+
}
|
|
860
|
+
return acc;
|
|
861
|
+
}, {});
|
|
862
|
+
process.chdir(cwd);
|
|
863
|
+
return registry;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
// src/lib/registry/list-internal-packages.ts
|
|
867
|
+
import { uniq } from "ramda";
|
|
868
|
+
function listInternalPackages(manifest, packagesRegistry, { includeDevDependencies = false } = {}) {
|
|
869
|
+
const allWorkspacePackageNames = Object.keys(packagesRegistry);
|
|
870
|
+
const internalPackageNames = (includeDevDependencies ? [
|
|
871
|
+
...Object.keys(manifest.dependencies ?? {}),
|
|
872
|
+
...Object.keys(manifest.devDependencies ?? {})
|
|
873
|
+
] : Object.keys(manifest.dependencies ?? {})).filter((name) => allWorkspacePackageNames.includes(name));
|
|
874
|
+
const nestedInternalPackageNames = internalPackageNames.flatMap(
|
|
875
|
+
(packageName) => listInternalPackages(
|
|
876
|
+
packagesRegistry[packageName].manifest,
|
|
877
|
+
packagesRegistry,
|
|
878
|
+
{ includeDevDependencies }
|
|
879
|
+
)
|
|
880
|
+
);
|
|
881
|
+
return uniq(internalPackageNames.concat(nestedInternalPackageNames));
|
|
882
|
+
}
|
|
883
|
+
|
|
840
884
|
// src/isolate.ts
|
|
841
885
|
var __dirname = getDirname(import.meta.url);
|
|
842
886
|
async function isolate(options = {}) {
|
|
@@ -850,14 +894,14 @@ async function isolate(options = {}) {
|
|
|
850
894
|
setLogLevel(config.logLevel);
|
|
851
895
|
const log = useLogger();
|
|
852
896
|
const thisPackageManifest = await readTypedJson(
|
|
853
|
-
|
|
897
|
+
path17.join(path17.join(__dirname, "..", "package.json"))
|
|
854
898
|
);
|
|
855
899
|
log.debug("Using isolate-package version", thisPackageManifest.version);
|
|
856
|
-
const targetPackageDir = config.targetPackagePath ?
|
|
857
|
-
const workspaceRootDir = config.targetPackagePath ? process.cwd() :
|
|
900
|
+
const targetPackageDir = config.targetPackagePath ? path17.join(process.cwd(), config.targetPackagePath) : process.cwd();
|
|
901
|
+
const workspaceRootDir = config.targetPackagePath ? process.cwd() : path17.join(targetPackageDir, config.workspaceRoot);
|
|
858
902
|
const buildOutputDir = await getBuildOutputDir(targetPackageDir);
|
|
859
903
|
assert6(
|
|
860
|
-
|
|
904
|
+
fs16.existsSync(buildOutputDir),
|
|
861
905
|
`Failed to find build output path at ${buildOutputDir}. Please make sure you build the source before isolating it.`
|
|
862
906
|
);
|
|
863
907
|
log.debug("Workspace root resolved to", workspaceRootDir);
|
|
@@ -865,20 +909,20 @@ async function isolate(options = {}) {
|
|
|
865
909
|
"Isolate target package",
|
|
866
910
|
getRootRelativePath(targetPackageDir, workspaceRootDir)
|
|
867
911
|
);
|
|
868
|
-
const isolateDir =
|
|
912
|
+
const isolateDir = path17.join(targetPackageDir, config.isolateDirName);
|
|
869
913
|
log.debug(
|
|
870
914
|
"Isolate output directory",
|
|
871
915
|
getRootRelativePath(isolateDir, workspaceRootDir)
|
|
872
916
|
);
|
|
873
|
-
if (
|
|
874
|
-
await
|
|
917
|
+
if (fs16.existsSync(isolateDir)) {
|
|
918
|
+
await fs16.remove(isolateDir);
|
|
875
919
|
log.debug("Cleaned the existing isolate output directory");
|
|
876
920
|
}
|
|
877
|
-
await
|
|
878
|
-
const tmpDir =
|
|
879
|
-
await
|
|
921
|
+
await fs16.ensureDir(isolateDir);
|
|
922
|
+
const tmpDir = path17.join(isolateDir, "__tmp");
|
|
923
|
+
await fs16.ensureDir(tmpDir);
|
|
880
924
|
const targetPackageManifest = await readTypedJson(
|
|
881
|
-
|
|
925
|
+
path17.join(targetPackageDir, "package.json")
|
|
882
926
|
);
|
|
883
927
|
const packageManager2 = detectPackageManager(workspaceRootDir);
|
|
884
928
|
log.debug(
|
|
@@ -942,21 +986,21 @@ async function isolate(options = {}) {
|
|
|
942
986
|
});
|
|
943
987
|
}
|
|
944
988
|
if (packageManager2.name === "pnpm") {
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
989
|
+
fs16.copyFileSync(
|
|
990
|
+
path17.join(workspaceRootDir, "pnpm-workspace.yaml"),
|
|
991
|
+
path17.join(isolateDir, "pnpm-workspace.yaml")
|
|
948
992
|
);
|
|
949
993
|
}
|
|
950
|
-
const npmrcPath =
|
|
951
|
-
if (
|
|
952
|
-
|
|
994
|
+
const npmrcPath = path17.join(workspaceRootDir, ".npmrc");
|
|
995
|
+
if (fs16.existsSync(npmrcPath)) {
|
|
996
|
+
fs16.copyFileSync(npmrcPath, path17.join(isolateDir, ".npmrc"));
|
|
953
997
|
log.debug("Copied .npmrc file to the isolate output");
|
|
954
998
|
}
|
|
955
999
|
log.debug(
|
|
956
1000
|
"Deleting temp directory",
|
|
957
1001
|
getRootRelativePath(tmpDir, workspaceRootDir)
|
|
958
1002
|
);
|
|
959
|
-
await
|
|
1003
|
+
await fs16.remove(tmpDir);
|
|
960
1004
|
log.info("Isolate completed at", isolateDir);
|
|
961
1005
|
return isolateDir;
|
|
962
1006
|
}
|