isolate-package 1.6.2-0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -5
- package/dist/index.mjs +403 -359
- package/dist/index.mjs.map +1 -1
- package/dist/isolate-bin.mjs +403 -359
- 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,47 +280,138 @@ 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({
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
370
|
+
workspaceRootDir,
|
|
371
|
+
isolateDir,
|
|
372
|
+
packagesRegistry
|
|
351
373
|
}) {
|
|
352
374
|
const log = useLogger();
|
|
353
|
-
log.
|
|
354
|
-
const
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
375
|
+
log.info("Generating NPM lockfile...");
|
|
376
|
+
const origRootNodeModulesPath = path5.join(workspaceRootDir, "node_modules");
|
|
377
|
+
const tempRootNodeModulesPath = path5.join(isolateDir, "node_modules");
|
|
378
|
+
if (!fs8.existsSync(origRootNodeModulesPath)) {
|
|
379
|
+
throw new Error(
|
|
380
|
+
`Failed to find node_modules at ${origRootNodeModulesPath}`
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
log.debug(`Temporarily moving node_modules to the isolate output`);
|
|
384
|
+
let hasMovedNodeModules = false;
|
|
385
|
+
try {
|
|
386
|
+
await fs8.move(origRootNodeModulesPath, tempRootNodeModulesPath);
|
|
387
|
+
hasMovedNodeModules = true;
|
|
388
|
+
const internalPackageNames = Object.keys(packagesRegistry);
|
|
389
|
+
const arborist = new Arborist({ path: isolateDir });
|
|
390
|
+
const { meta } = await arborist.buildIdealTree({
|
|
391
|
+
rm: internalPackageNames
|
|
392
|
+
});
|
|
393
|
+
meta?.commit();
|
|
394
|
+
const lockfilePath = path5.join(isolateDir, "package-lock.json");
|
|
395
|
+
await fs8.writeFile(lockfilePath, String(meta));
|
|
396
|
+
log.debug("Created lockfile at", lockfilePath);
|
|
397
|
+
} catch (err) {
|
|
398
|
+
log.error(getErrorMessage(err));
|
|
399
|
+
} finally {
|
|
400
|
+
if (hasMovedNodeModules) {
|
|
401
|
+
log.debug(`Restoring node_modules to the workspace root`);
|
|
402
|
+
await fs8.move(tempRootNodeModulesPath, origRootNodeModulesPath);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
363
405
|
}
|
|
364
406
|
|
|
365
|
-
// src/helpers/generate-pnpm-lockfile.ts
|
|
407
|
+
// src/lib/lockfile/helpers/generate-pnpm-lockfile.ts
|
|
366
408
|
import {
|
|
367
409
|
getLockfileImporterId,
|
|
368
410
|
readWantedLockfile,
|
|
369
411
|
writeWantedLockfile
|
|
370
412
|
} from "@pnpm/lockfile-file";
|
|
371
|
-
import
|
|
372
|
-
import
|
|
413
|
+
import assert3 from "node:assert";
|
|
414
|
+
import path6 from "node:path";
|
|
373
415
|
import { pick } from "ramda";
|
|
374
416
|
async function generatePnpmLockfile({
|
|
375
417
|
workspaceRootDir,
|
|
@@ -380,11 +422,11 @@ async function generatePnpmLockfile({
|
|
|
380
422
|
}) {
|
|
381
423
|
const { includeDevDependencies } = useConfig();
|
|
382
424
|
const log = useLogger();
|
|
383
|
-
log.
|
|
425
|
+
log.info("Generating PNPM lockfile...");
|
|
384
426
|
const lockfile = await readWantedLockfile(workspaceRootDir, {
|
|
385
427
|
ignoreIncompatible: false
|
|
386
428
|
});
|
|
387
|
-
|
|
429
|
+
assert3(lockfile, `No input lockfile found at ${workspaceRootDir}`);
|
|
388
430
|
const targetImporterId = getLockfileImporterId(
|
|
389
431
|
workspaceRootDir,
|
|
390
432
|
targetPackageDir
|
|
@@ -392,7 +434,7 @@ async function generatePnpmLockfile({
|
|
|
392
434
|
const directoryByPackageName = Object.fromEntries(
|
|
393
435
|
internalDepPackageNames.map((name) => {
|
|
394
436
|
const pkg = packagesRegistry[name];
|
|
395
|
-
|
|
437
|
+
assert3(pkg, `Package ${name} not found in packages registry`);
|
|
396
438
|
return [name, pkg.rootRelativeDir];
|
|
397
439
|
})
|
|
398
440
|
);
|
|
@@ -430,20 +472,10 @@ async function generatePnpmLockfile({
|
|
|
430
472
|
)
|
|
431
473
|
);
|
|
432
474
|
await writeWantedLockfile(isolateDir, lockfile);
|
|
433
|
-
log.debug("Created lockfile at",
|
|
475
|
+
log.debug("Created lockfile at", path6.join(isolateDir, "pnpm-lock.yaml"));
|
|
434
476
|
}
|
|
435
477
|
|
|
436
|
-
// src/
|
|
437
|
-
function getLockfileFileName(name) {
|
|
438
|
-
switch (name) {
|
|
439
|
-
case "pnpm":
|
|
440
|
-
return "pnpm-lock.yaml";
|
|
441
|
-
case "yarn":
|
|
442
|
-
return "yarn.lock";
|
|
443
|
-
case "npm":
|
|
444
|
-
return "package-lock.json";
|
|
445
|
-
}
|
|
446
|
-
}
|
|
478
|
+
// src/lib/lockfile/process-lockfile.ts
|
|
447
479
|
function pnpmMapImporter({ dependencies, devDependencies, ...rest }, {
|
|
448
480
|
includeDevDependencies,
|
|
449
481
|
directoryByPackageName
|
|
@@ -473,16 +505,16 @@ async function processLockfile({
|
|
|
473
505
|
switch (name) {
|
|
474
506
|
case "npm": {
|
|
475
507
|
await generateNpmLockfile({
|
|
476
|
-
|
|
508
|
+
workspaceRootDir,
|
|
477
509
|
isolateDir,
|
|
478
510
|
packagesRegistry
|
|
479
511
|
});
|
|
480
512
|
break;
|
|
481
513
|
}
|
|
482
514
|
case "yarn": {
|
|
483
|
-
const lockfileSrcPath =
|
|
484
|
-
const lockfileDstPath =
|
|
485
|
-
|
|
515
|
+
const lockfileSrcPath = path7.join(workspaceRootDir, fileName);
|
|
516
|
+
const lockfileDstPath = path7.join(isolateDir, fileName);
|
|
517
|
+
fs9.copyFileSync(lockfileSrcPath, lockfileDstPath);
|
|
486
518
|
log.debug("Copied lockfile to", lockfileDstPath);
|
|
487
519
|
break;
|
|
488
520
|
}
|
|
@@ -501,60 +533,63 @@ async function processLockfile({
|
|
|
501
533
|
}
|
|
502
534
|
}
|
|
503
535
|
|
|
504
|
-
// src/
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
536
|
+
// src/lib/manifest/adapt-target-package-manifest.ts
|
|
537
|
+
import fs11 from "fs-extra";
|
|
538
|
+
import path10 from "node:path";
|
|
539
|
+
import { omit as omit3 } from "ramda";
|
|
540
|
+
|
|
541
|
+
// src/lib/manifest/helpers/adapt-internal-package-manifests.ts
|
|
542
|
+
import fs10 from "fs-extra";
|
|
543
|
+
import path9 from "node:path";
|
|
544
|
+
import { omit as omit2 } from "ramda";
|
|
545
|
+
|
|
546
|
+
// src/lib/manifest/helpers/adapt-manifest-internal-deps.ts
|
|
547
|
+
import { omit } from "ramda";
|
|
548
|
+
|
|
549
|
+
// src/lib/manifest/helpers/patch-internal-entries.ts
|
|
550
|
+
import path8 from "node:path";
|
|
551
|
+
function patchInternalEntries(dependencies, packagesRegistry, parentRootRelativeDir) {
|
|
512
552
|
const log = useLogger();
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
assert3(
|
|
527
|
-
fs8.existsSync(path7.join(workspaceRoot, lockfileName)),
|
|
528
|
-
`Manifest declares ${name} to be the packageManager, but failed to find ${lockfileName} in workspace root`
|
|
553
|
+
const allWorkspacePackageNames = Object.keys(packagesRegistry);
|
|
554
|
+
return Object.fromEntries(
|
|
555
|
+
Object.entries(dependencies).map(([key, value]) => {
|
|
556
|
+
if (allWorkspacePackageNames.includes(key)) {
|
|
557
|
+
const def = packagesRegistry[key];
|
|
558
|
+
const relativePath = parentRootRelativeDir ? path8.relative(parentRootRelativeDir, `./${def.rootRelativeDir}`) : `./${def.rootRelativeDir}`;
|
|
559
|
+
const linkPath = `file:${relativePath}`;
|
|
560
|
+
log.debug(`Linking dependency ${key} to ${linkPath}`);
|
|
561
|
+
return [key, linkPath];
|
|
562
|
+
} else {
|
|
563
|
+
return [key, value];
|
|
564
|
+
}
|
|
565
|
+
})
|
|
529
566
|
);
|
|
530
|
-
return { name, version };
|
|
531
|
-
}
|
|
532
|
-
function inferFromFiles(workspaceRoot) {
|
|
533
|
-
for (const name of supportedPackageManagerNames) {
|
|
534
|
-
const lockfileName = getLockfileFileName(name);
|
|
535
|
-
if (fs8.existsSync(path7.join(workspaceRoot, lockfileName))) {
|
|
536
|
-
return { name, version: getVersion(name) };
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
if (fs8.existsSync(path7.join(workspaceRoot, "npm-shrinkwrap.json"))) {
|
|
540
|
-
return { name: "npm", version: getVersion("npm") };
|
|
541
|
-
}
|
|
542
|
-
throw new Error(`Failed to detect package manager`);
|
|
543
567
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
)
|
|
553
|
-
|
|
554
|
-
|
|
568
|
+
|
|
569
|
+
// src/lib/manifest/helpers/adapt-manifest-internal-deps.ts
|
|
570
|
+
function adaptManifestInternalDeps({
|
|
571
|
+
manifest,
|
|
572
|
+
packagesRegistry,
|
|
573
|
+
parentRootRelativeDir
|
|
574
|
+
}, opts = {}) {
|
|
575
|
+
return Object.assign(
|
|
576
|
+
omit(["devDependencies"], manifest),
|
|
577
|
+
filterObjectUndefined({
|
|
578
|
+
dependencies: manifest.dependencies ? patchInternalEntries(
|
|
579
|
+
manifest.dependencies,
|
|
580
|
+
packagesRegistry,
|
|
581
|
+
parentRootRelativeDir
|
|
582
|
+
) : void 0,
|
|
583
|
+
devDependencies: opts.includeDevDependencies && manifest.devDependencies ? patchInternalEntries(
|
|
584
|
+
manifest.devDependencies,
|
|
585
|
+
packagesRegistry,
|
|
586
|
+
parentRootRelativeDir
|
|
587
|
+
) : void 0
|
|
588
|
+
})
|
|
589
|
+
);
|
|
555
590
|
}
|
|
556
591
|
|
|
557
|
-
// src/helpers/adapt-internal-package-manifests.ts
|
|
592
|
+
// src/lib/manifest/helpers/adapt-internal-package-manifests.ts
|
|
558
593
|
async function adaptInternalPackageManifests(internalPackageNames, packagesRegistry, isolateDir) {
|
|
559
594
|
const packageManager2 = usePackageManager();
|
|
560
595
|
const { includeDevDependencies } = useConfig();
|
|
@@ -582,126 +617,46 @@ async function adaptInternalPackageManifests(internalPackageNames, packagesRegis
|
|
|
582
617
|
},
|
|
583
618
|
{ includeDevDependencies }
|
|
584
619
|
);
|
|
585
|
-
await
|
|
586
|
-
|
|
620
|
+
await fs10.writeFile(
|
|
621
|
+
path9.join(isolateDir, rootRelativeDir, "package.json"),
|
|
587
622
|
JSON.stringify(outputManifest, null, 2)
|
|
588
623
|
);
|
|
589
624
|
})
|
|
590
625
|
);
|
|
591
626
|
}
|
|
592
627
|
|
|
593
|
-
// src/
|
|
594
|
-
import fs10 from "fs-extra";
|
|
595
|
-
import path9 from "node:path";
|
|
596
|
-
import { omit as omit3 } from "ramda";
|
|
628
|
+
// src/lib/manifest/adapt-target-package-manifest.ts
|
|
597
629
|
async function adaptTargetPackageManifest(manifest, packagesRegistry, isolateDir) {
|
|
598
630
|
const packageManager2 = usePackageManager();
|
|
599
631
|
const { includeDevDependencies } = useConfig();
|
|
600
|
-
const outputManifest = packageManager2.name === "pnpm" ?
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
632
|
+
const outputManifest = packageManager2.name === "pnpm" ? (
|
|
633
|
+
/**
|
|
634
|
+
* For PNPM the output itself is a workspace so we can preserve the specifiers
|
|
635
|
+
* with "workspace:*" in the output manifest.
|
|
636
|
+
*/
|
|
637
|
+
Object.assign(omit3(["devDependencies", "scripts"], manifest), {
|
|
638
|
+
devDependencies: includeDevDependencies ? manifest.devDependencies : void 0
|
|
639
|
+
})
|
|
640
|
+
) : (
|
|
641
|
+
/** For other package managers we replace the links to internal dependencies */
|
|
642
|
+
adaptManifestInternalDeps(
|
|
643
|
+
{
|
|
644
|
+
manifest,
|
|
645
|
+
packagesRegistry
|
|
646
|
+
},
|
|
647
|
+
{ includeDevDependencies }
|
|
648
|
+
)
|
|
608
649
|
);
|
|
609
|
-
await
|
|
610
|
-
|
|
650
|
+
await fs11.writeFile(
|
|
651
|
+
path10.join(isolateDir, "package.json"),
|
|
611
652
|
JSON.stringify(outputManifest, null, 2)
|
|
612
653
|
);
|
|
613
654
|
}
|
|
614
655
|
|
|
615
|
-
// src/
|
|
616
|
-
import fs11 from "fs-extra";
|
|
617
|
-
import { globSync } from "glob";
|
|
656
|
+
// src/lib/manifest/import-manifest.ts
|
|
618
657
|
import path11 from "node:path";
|
|
619
658
|
|
|
620
|
-
// src/
|
|
621
|
-
import assert4 from "node:assert";
|
|
622
|
-
import path10 from "node:path";
|
|
623
|
-
function findPackagesGlobs(workspaceRootDir) {
|
|
624
|
-
const log = useLogger();
|
|
625
|
-
const packageManager2 = usePackageManager();
|
|
626
|
-
switch (packageManager2.name) {
|
|
627
|
-
case "pnpm": {
|
|
628
|
-
const { packages: globs } = readTypedYamlSync(
|
|
629
|
-
path10.join(workspaceRootDir, "pnpm-workspace.yaml")
|
|
630
|
-
);
|
|
631
|
-
log.debug("Detected pnpm packages globs:", inspectValue(globs));
|
|
632
|
-
return globs;
|
|
633
|
-
}
|
|
634
|
-
case "yarn":
|
|
635
|
-
case "npm": {
|
|
636
|
-
const workspaceRootManifestPath = path10.join(
|
|
637
|
-
workspaceRootDir,
|
|
638
|
-
"package.json"
|
|
639
|
-
);
|
|
640
|
-
const { workspaces } = readTypedJsonSync(
|
|
641
|
-
workspaceRootManifestPath
|
|
642
|
-
);
|
|
643
|
-
if (!workspaces) {
|
|
644
|
-
throw new Error(
|
|
645
|
-
`No workspaces field found in ${workspaceRootManifestPath}`
|
|
646
|
-
);
|
|
647
|
-
}
|
|
648
|
-
if (Array.isArray(workspaces)) {
|
|
649
|
-
return workspaces;
|
|
650
|
-
} else {
|
|
651
|
-
const workspacesObject = workspaces;
|
|
652
|
-
assert4(
|
|
653
|
-
workspacesObject.packages,
|
|
654
|
-
"workspaces.packages must be an array"
|
|
655
|
-
);
|
|
656
|
-
return workspacesObject.packages;
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
// src/helpers/create-packages-registry.ts
|
|
663
|
-
async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverride) {
|
|
664
|
-
const log = useLogger();
|
|
665
|
-
if (workspacePackagesOverride) {
|
|
666
|
-
log.debug(
|
|
667
|
-
`Override workspace packages via config: ${workspacePackagesOverride}`
|
|
668
|
-
);
|
|
669
|
-
}
|
|
670
|
-
const packagesGlobs = workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);
|
|
671
|
-
const cwd = process.cwd();
|
|
672
|
-
process.chdir(workspaceRootDir);
|
|
673
|
-
const allPackages = packagesGlobs.flatMap((glob) => globSync(glob)).filter((dir) => fs11.lstatSync(dir).isDirectory());
|
|
674
|
-
const registry = (await Promise.all(
|
|
675
|
-
allPackages.map(async (rootRelativeDir) => {
|
|
676
|
-
const manifestPath = path11.join(rootRelativeDir, "package.json");
|
|
677
|
-
if (!fs11.existsSync(manifestPath)) {
|
|
678
|
-
log.warn(
|
|
679
|
-
`Ignoring directory ./${rootRelativeDir} because it does not contain a package.json file`
|
|
680
|
-
);
|
|
681
|
-
return;
|
|
682
|
-
} else {
|
|
683
|
-
log.debug(`Registering package ./${rootRelativeDir}`);
|
|
684
|
-
const manifest = await readTypedJson(
|
|
685
|
-
path11.join(rootRelativeDir, "package.json")
|
|
686
|
-
);
|
|
687
|
-
return {
|
|
688
|
-
manifest,
|
|
689
|
-
rootRelativeDir,
|
|
690
|
-
absoluteDir: path11.join(workspaceRootDir, rootRelativeDir)
|
|
691
|
-
};
|
|
692
|
-
}
|
|
693
|
-
})
|
|
694
|
-
)).reduce((acc, info) => {
|
|
695
|
-
if (info) {
|
|
696
|
-
acc[info.manifest.name] = info;
|
|
697
|
-
}
|
|
698
|
-
return acc;
|
|
699
|
-
}, {});
|
|
700
|
-
process.chdir(cwd);
|
|
701
|
-
return registry;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
// src/helpers/get-build-output-dir.ts
|
|
659
|
+
// src/lib/output/get-build-output-dir.ts
|
|
705
660
|
import fs12 from "fs-extra";
|
|
706
661
|
import path12 from "node:path";
|
|
707
662
|
import outdent from "outdent";
|
|
@@ -732,26 +687,8 @@ async function getBuildOutputDir(targetPackageDir) {
|
|
|
732
687
|
}
|
|
733
688
|
}
|
|
734
689
|
|
|
735
|
-
// src/
|
|
736
|
-
import
|
|
737
|
-
function listInternalPackages(manifest, packagesRegistry, { includeDevDependencies = false } = {}) {
|
|
738
|
-
const allWorkspacePackageNames = Object.keys(packagesRegistry);
|
|
739
|
-
const internalPackageNames = (includeDevDependencies ? [
|
|
740
|
-
...Object.keys(manifest.dependencies ?? {}),
|
|
741
|
-
...Object.keys(manifest.devDependencies ?? {})
|
|
742
|
-
] : Object.keys(manifest.dependencies ?? {})).filter((name) => allWorkspacePackageNames.includes(name));
|
|
743
|
-
const nestedInternalPackageNames = internalPackageNames.flatMap(
|
|
744
|
-
(packageName) => listInternalPackages(
|
|
745
|
-
packagesRegistry[packageName].manifest,
|
|
746
|
-
packagesRegistry,
|
|
747
|
-
{ includeDevDependencies }
|
|
748
|
-
)
|
|
749
|
-
);
|
|
750
|
-
return uniq(internalPackageNames.concat(nestedInternalPackageNames));
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
// src/helpers/pack-dependencies.ts
|
|
754
|
-
import assert5 from "node:assert";
|
|
690
|
+
// src/lib/output/pack-dependencies.ts
|
|
691
|
+
import assert4 from "node:assert";
|
|
755
692
|
async function packDependencies({
|
|
756
693
|
/** All packages found in the monorepo by workspaces declaration */
|
|
757
694
|
packagesRegistry,
|
|
@@ -776,7 +713,7 @@ async function packDependencies({
|
|
|
776
713
|
}
|
|
777
714
|
for (const dependency of internalPackageNames) {
|
|
778
715
|
const def = packagesRegistry[dependency];
|
|
779
|
-
|
|
716
|
+
assert4(dependency, `Failed to find package definition for ${dependency}`);
|
|
780
717
|
const { name: name2 } = def.manifest;
|
|
781
718
|
if (packedFileByName[name2]) {
|
|
782
719
|
log.debug(`Skipping ${name2} because it has already been packed`);
|
|
@@ -791,7 +728,7 @@ async function packDependencies({
|
|
|
791
728
|
return packedFileByName;
|
|
792
729
|
}
|
|
793
730
|
|
|
794
|
-
// src/
|
|
731
|
+
// src/lib/output/process-build-output-files.ts
|
|
795
732
|
import fs13 from "fs-extra";
|
|
796
733
|
import path13 from "node:path";
|
|
797
734
|
var TIMEOUT_MS = 5e3;
|
|
@@ -816,7 +753,7 @@ async function processBuildOutputFiles({
|
|
|
816
753
|
await fs13.copy(path13.join(unpackDir, "package"), isolateDir);
|
|
817
754
|
}
|
|
818
755
|
|
|
819
|
-
// src/
|
|
756
|
+
// src/lib/output/unpack-dependencies.ts
|
|
820
757
|
import fs14 from "fs-extra";
|
|
821
758
|
import path14, { join } from "node:path";
|
|
822
759
|
async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, isolateDir) {
|
|
@@ -842,6 +779,113 @@ async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, i
|
|
|
842
779
|
);
|
|
843
780
|
}
|
|
844
781
|
|
|
782
|
+
// src/lib/registry/create-packages-registry.ts
|
|
783
|
+
import fs15 from "fs-extra";
|
|
784
|
+
import { globSync } from "glob";
|
|
785
|
+
import path16 from "node:path";
|
|
786
|
+
|
|
787
|
+
// src/lib/registry/helpers/find-packages-globs.ts
|
|
788
|
+
import assert5 from "node:assert";
|
|
789
|
+
import path15 from "node:path";
|
|
790
|
+
function findPackagesGlobs(workspaceRootDir) {
|
|
791
|
+
const log = useLogger();
|
|
792
|
+
const packageManager2 = usePackageManager();
|
|
793
|
+
switch (packageManager2.name) {
|
|
794
|
+
case "pnpm": {
|
|
795
|
+
const { packages: globs } = readTypedYamlSync(
|
|
796
|
+
path15.join(workspaceRootDir, "pnpm-workspace.yaml")
|
|
797
|
+
);
|
|
798
|
+
log.debug("Detected pnpm packages globs:", inspectValue(globs));
|
|
799
|
+
return globs;
|
|
800
|
+
}
|
|
801
|
+
case "yarn":
|
|
802
|
+
case "npm": {
|
|
803
|
+
const workspaceRootManifestPath = path15.join(
|
|
804
|
+
workspaceRootDir,
|
|
805
|
+
"package.json"
|
|
806
|
+
);
|
|
807
|
+
const { workspaces } = readTypedJsonSync(
|
|
808
|
+
workspaceRootManifestPath
|
|
809
|
+
);
|
|
810
|
+
if (!workspaces) {
|
|
811
|
+
throw new Error(
|
|
812
|
+
`No workspaces field found in ${workspaceRootManifestPath}`
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
if (Array.isArray(workspaces)) {
|
|
816
|
+
return workspaces;
|
|
817
|
+
} else {
|
|
818
|
+
const workspacesObject = workspaces;
|
|
819
|
+
assert5(
|
|
820
|
+
workspacesObject.packages,
|
|
821
|
+
"workspaces.packages must be an array"
|
|
822
|
+
);
|
|
823
|
+
return workspacesObject.packages;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// src/lib/registry/create-packages-registry.ts
|
|
830
|
+
async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverride) {
|
|
831
|
+
const log = useLogger();
|
|
832
|
+
if (workspacePackagesOverride) {
|
|
833
|
+
log.debug(
|
|
834
|
+
`Override workspace packages via config: ${workspacePackagesOverride}`
|
|
835
|
+
);
|
|
836
|
+
}
|
|
837
|
+
const packagesGlobs = workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);
|
|
838
|
+
const cwd = process.cwd();
|
|
839
|
+
process.chdir(workspaceRootDir);
|
|
840
|
+
const allPackages = packagesGlobs.flatMap((glob) => globSync(glob)).filter((dir) => fs15.lstatSync(dir).isDirectory());
|
|
841
|
+
const registry = (await Promise.all(
|
|
842
|
+
allPackages.map(async (rootRelativeDir) => {
|
|
843
|
+
const manifestPath = path16.join(rootRelativeDir, "package.json");
|
|
844
|
+
if (!fs15.existsSync(manifestPath)) {
|
|
845
|
+
log.warn(
|
|
846
|
+
`Ignoring directory ./${rootRelativeDir} because it does not contain a package.json file`
|
|
847
|
+
);
|
|
848
|
+
return;
|
|
849
|
+
} else {
|
|
850
|
+
log.debug(`Registering package ./${rootRelativeDir}`);
|
|
851
|
+
const manifest = await readTypedJson(
|
|
852
|
+
path16.join(rootRelativeDir, "package.json")
|
|
853
|
+
);
|
|
854
|
+
return {
|
|
855
|
+
manifest,
|
|
856
|
+
rootRelativeDir,
|
|
857
|
+
absoluteDir: path16.join(workspaceRootDir, rootRelativeDir)
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
})
|
|
861
|
+
)).reduce((acc, info) => {
|
|
862
|
+
if (info) {
|
|
863
|
+
acc[info.manifest.name] = info;
|
|
864
|
+
}
|
|
865
|
+
return acc;
|
|
866
|
+
}, {});
|
|
867
|
+
process.chdir(cwd);
|
|
868
|
+
return registry;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
// src/lib/registry/list-internal-packages.ts
|
|
872
|
+
import { uniq } from "ramda";
|
|
873
|
+
function listInternalPackages(manifest, packagesRegistry, { includeDevDependencies = false } = {}) {
|
|
874
|
+
const allWorkspacePackageNames = Object.keys(packagesRegistry);
|
|
875
|
+
const internalPackageNames = (includeDevDependencies ? [
|
|
876
|
+
...Object.keys(manifest.dependencies ?? {}),
|
|
877
|
+
...Object.keys(manifest.devDependencies ?? {})
|
|
878
|
+
] : Object.keys(manifest.dependencies ?? {})).filter((name) => allWorkspacePackageNames.includes(name));
|
|
879
|
+
const nestedInternalPackageNames = internalPackageNames.flatMap(
|
|
880
|
+
(packageName) => listInternalPackages(
|
|
881
|
+
packagesRegistry[packageName].manifest,
|
|
882
|
+
packagesRegistry,
|
|
883
|
+
{ includeDevDependencies }
|
|
884
|
+
)
|
|
885
|
+
);
|
|
886
|
+
return uniq(internalPackageNames.concat(nestedInternalPackageNames));
|
|
887
|
+
}
|
|
888
|
+
|
|
845
889
|
// src/isolate.ts
|
|
846
890
|
var __dirname = getDirname(import.meta.url);
|
|
847
891
|
async function isolate(options = {}) {
|
|
@@ -855,14 +899,14 @@ async function isolate(options = {}) {
|
|
|
855
899
|
setLogLevel(config.logLevel);
|
|
856
900
|
const log = useLogger();
|
|
857
901
|
const thisPackageManifest = await readTypedJson(
|
|
858
|
-
|
|
902
|
+
path17.join(path17.join(__dirname, "..", "package.json"))
|
|
859
903
|
);
|
|
860
904
|
log.debug("Using isolate-package version", thisPackageManifest.version);
|
|
861
|
-
const targetPackageDir = config.targetPackagePath ?
|
|
862
|
-
const workspaceRootDir = config.targetPackagePath ? process.cwd() :
|
|
905
|
+
const targetPackageDir = config.targetPackagePath ? path17.join(process.cwd(), config.targetPackagePath) : process.cwd();
|
|
906
|
+
const workspaceRootDir = config.targetPackagePath ? process.cwd() : path17.join(targetPackageDir, config.workspaceRoot);
|
|
863
907
|
const buildOutputDir = await getBuildOutputDir(targetPackageDir);
|
|
864
908
|
assert6(
|
|
865
|
-
|
|
909
|
+
fs16.existsSync(buildOutputDir),
|
|
866
910
|
`Failed to find build output path at ${buildOutputDir}. Please make sure you build the source before isolating it.`
|
|
867
911
|
);
|
|
868
912
|
log.debug("Workspace root resolved to", workspaceRootDir);
|
|
@@ -870,20 +914,20 @@ async function isolate(options = {}) {
|
|
|
870
914
|
"Isolate target package",
|
|
871
915
|
getRootRelativePath(targetPackageDir, workspaceRootDir)
|
|
872
916
|
);
|
|
873
|
-
const isolateDir =
|
|
917
|
+
const isolateDir = path17.join(targetPackageDir, config.isolateDirName);
|
|
874
918
|
log.debug(
|
|
875
919
|
"Isolate output directory",
|
|
876
920
|
getRootRelativePath(isolateDir, workspaceRootDir)
|
|
877
921
|
);
|
|
878
|
-
if (
|
|
879
|
-
await
|
|
922
|
+
if (fs16.existsSync(isolateDir)) {
|
|
923
|
+
await fs16.remove(isolateDir);
|
|
880
924
|
log.debug("Cleaned the existing isolate output directory");
|
|
881
925
|
}
|
|
882
|
-
await
|
|
883
|
-
const tmpDir =
|
|
884
|
-
await
|
|
926
|
+
await fs16.ensureDir(isolateDir);
|
|
927
|
+
const tmpDir = path17.join(isolateDir, "__tmp");
|
|
928
|
+
await fs16.ensureDir(tmpDir);
|
|
885
929
|
const targetPackageManifest = await readTypedJson(
|
|
886
|
-
|
|
930
|
+
path17.join(targetPackageDir, "package.json")
|
|
887
931
|
);
|
|
888
932
|
const packageManager2 = detectPackageManager(workspaceRootDir);
|
|
889
933
|
log.debug(
|
|
@@ -947,21 +991,21 @@ async function isolate(options = {}) {
|
|
|
947
991
|
});
|
|
948
992
|
}
|
|
949
993
|
if (packageManager2.name === "pnpm") {
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
994
|
+
fs16.copyFileSync(
|
|
995
|
+
path17.join(workspaceRootDir, "pnpm-workspace.yaml"),
|
|
996
|
+
path17.join(isolateDir, "pnpm-workspace.yaml")
|
|
953
997
|
);
|
|
954
998
|
}
|
|
955
|
-
const npmrcPath =
|
|
956
|
-
if (
|
|
957
|
-
|
|
999
|
+
const npmrcPath = path17.join(workspaceRootDir, ".npmrc");
|
|
1000
|
+
if (fs16.existsSync(npmrcPath)) {
|
|
1001
|
+
fs16.copyFileSync(npmrcPath, path17.join(isolateDir, ".npmrc"));
|
|
958
1002
|
log.debug("Copied .npmrc file to the isolate output");
|
|
959
1003
|
}
|
|
960
1004
|
log.debug(
|
|
961
1005
|
"Deleting temp directory",
|
|
962
1006
|
getRootRelativePath(tmpDir, workspaceRootDir)
|
|
963
1007
|
);
|
|
964
|
-
await
|
|
1008
|
+
await fs16.remove(tmpDir);
|
|
965
1009
|
log.info("Isolate completed at", isolateDir);
|
|
966
1010
|
return isolateDir;
|
|
967
1011
|
}
|