isolate-package 1.13.2 → 1.14.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 +7 -42
- package/dist/index.mjs +169 -162
- package/dist/index.mjs.map +1 -1
- package/dist/isolate-bin.mjs +169 -162
- package/dist/isolate-bin.mjs.map +1 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -68,10 +68,9 @@ integrated, check out [mono-ts](https://github.com/0x80/mono-ts)
|
|
|
68
68
|
|
|
69
69
|
Run `pnpm install isolate-package --dev` or the equivalent for `npm` or `yarn`.
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
is
|
|
74
|
-
package manager should work.
|
|
71
|
+
It is recommended to use `pnpm` over `npm` or `yarn`. Apart from being fast and
|
|
72
|
+
efficient, PNPM has better support for monorepos, and the the lockfile isolation
|
|
73
|
+
code is solid and works in parallel for multiple packages, [unlike NPM](#npm)
|
|
75
74
|
|
|
76
75
|
## Usage
|
|
77
76
|
|
|
@@ -210,30 +209,6 @@ Because the configuration loader depends on this setting, its output is not
|
|
|
210
209
|
affected by this setting. If you want to debug the configuration set
|
|
211
210
|
`DEBUG_ISOLATE_CONFIG=true` before you run `isolate`
|
|
212
211
|
|
|
213
|
-
### forceNpm
|
|
214
|
-
|
|
215
|
-
Type: `boolean`, default: `false`
|
|
216
|
-
|
|
217
|
-
By default the isolate process will generate output based on the package manager
|
|
218
|
-
that you are using for your monorepo. But your deployment target might not be
|
|
219
|
-
compatible with that package manager, or it might not be the best choice given
|
|
220
|
-
the available tooling.
|
|
221
|
-
|
|
222
|
-
Also, it should not really matter what package manager is used in de deployment
|
|
223
|
-
as long as the versions match your original lockfile.
|
|
224
|
-
|
|
225
|
-
By setting this option to `true` you are forcing the isolate output to use NPM.
|
|
226
|
-
A package-lock file will be generated based on the contents of node_modules and
|
|
227
|
-
therefore should match the versions in your original lockfile.
|
|
228
|
-
|
|
229
|
-
This way you can enjoy using PNPM or Yarn for your monorepo, while your
|
|
230
|
-
deployment uses NPM with modules locked to the same versions.
|
|
231
|
-
|
|
232
|
-
> !! Warning: Generating an NPM lockfile currently requires moving the
|
|
233
|
-
> node_modules from the root of the monorepo temporarily into the isolate
|
|
234
|
-
> directory. This will not be compatible with setups that run multiple isolation
|
|
235
|
-
> processes in parallel.
|
|
236
|
-
|
|
237
212
|
### buildDirName
|
|
238
213
|
|
|
239
214
|
Type: `string | undefined`, default: `undefined`
|
|
@@ -341,13 +316,8 @@ When you use the `targetPackagePath` option, this setting will be ignored.
|
|
|
341
316
|
## Lockfiles
|
|
342
317
|
|
|
343
318
|
The isolate process tries to generate an isolated / pruned lockfile for the
|
|
344
|
-
package manager that you use in your monorepo.
|
|
345
|
-
|
|
346
|
-
based on the installed versions in node_modules.
|
|
347
|
-
|
|
348
|
-
In case your package manager is not supported by your deployment target you can
|
|
349
|
-
also choose NPM to be used by setting the `makeNpmLockfile` to `true` in your
|
|
350
|
-
configuration.
|
|
319
|
+
package manager that you use in your monorepo. The strategy is different for
|
|
320
|
+
each package manager, with NPM currently being the least attractive.
|
|
351
321
|
|
|
352
322
|
### NPM
|
|
353
323
|
|
|
@@ -366,13 +336,8 @@ after Arborist has finished doing its thing.
|
|
|
366
336
|
|
|
367
337
|
### PNPM
|
|
368
338
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
It turns out, at least up to v10, that the isolated output has to be formatted
|
|
373
|
-
as a workspace itself, otherwise dependencies of internally linked packages are
|
|
374
|
-
not installed by PNPM. Therefore, the output looks a bit different from other
|
|
375
|
-
package managers:
|
|
339
|
+
For PNPM, the isolated output will be formatted as a workspace itself, otherwise
|
|
340
|
+
dependencies of internally linked packages are not installed by PNPM.
|
|
376
341
|
|
|
377
342
|
- Links are preserved
|
|
378
343
|
- Versions specifiers like "workspace:\*" are preserved
|
package/dist/index.mjs
CHANGED
|
@@ -5,9 +5,9 @@ import path19 from "node:path";
|
|
|
5
5
|
import { unique } from "remeda";
|
|
6
6
|
|
|
7
7
|
// src/lib/config.ts
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
8
|
+
import fs8 from "fs-extra";
|
|
9
|
+
import assert2 from "node:assert";
|
|
10
|
+
import path6 from "node:path";
|
|
11
11
|
import { isEmpty } from "remeda";
|
|
12
12
|
|
|
13
13
|
// src/lib/logger.ts
|
|
@@ -137,16 +137,120 @@ async function readTypedJson(filePath) {
|
|
|
137
137
|
|
|
138
138
|
// src/lib/utils/pack.ts
|
|
139
139
|
import { exec } from "node:child_process";
|
|
140
|
-
import
|
|
140
|
+
import fs5 from "node:fs";
|
|
141
|
+
import path5 from "node:path";
|
|
142
|
+
|
|
143
|
+
// src/lib/package-manager/index.ts
|
|
144
|
+
import path4 from "node:path";
|
|
145
|
+
|
|
146
|
+
// src/lib/package-manager/helpers/infer-from-files.ts
|
|
147
|
+
import fs3 from "fs-extra";
|
|
148
|
+
import { execSync } from "node:child_process";
|
|
141
149
|
import path2 from "node:path";
|
|
142
|
-
|
|
150
|
+
|
|
151
|
+
// src/lib/utils/get-major-version.ts
|
|
152
|
+
function getMajorVersion(version) {
|
|
153
|
+
return parseInt(version.split(".")[0], 10);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/lib/package-manager/names.ts
|
|
157
|
+
var supportedPackageManagerNames = ["pnpm", "yarn", "npm"];
|
|
158
|
+
function getLockfileFileName(name) {
|
|
159
|
+
switch (name) {
|
|
160
|
+
case "pnpm":
|
|
161
|
+
return "pnpm-lock.yaml";
|
|
162
|
+
case "yarn":
|
|
163
|
+
return "yarn.lock";
|
|
164
|
+
case "npm":
|
|
165
|
+
return "package-lock.json";
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// src/lib/package-manager/helpers/infer-from-files.ts
|
|
170
|
+
function inferFromFiles(workspaceRoot) {
|
|
171
|
+
for (const name of supportedPackageManagerNames) {
|
|
172
|
+
const lockfileName = getLockfileFileName(name);
|
|
173
|
+
const version = getVersion(name);
|
|
174
|
+
if (fs3.existsSync(path2.join(workspaceRoot, lockfileName))) {
|
|
175
|
+
return { name, version, majorVersion: getMajorVersion(version) };
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (fs3.existsSync(path2.join(workspaceRoot, "npm-shrinkwrap.json"))) {
|
|
179
|
+
const version = getVersion("npm");
|
|
180
|
+
return { name: "npm", version, majorVersion: getMajorVersion(version) };
|
|
181
|
+
}
|
|
182
|
+
throw new Error(`Failed to detect package manager`);
|
|
183
|
+
}
|
|
184
|
+
function getVersion(packageManagerName) {
|
|
185
|
+
const buffer = execSync(`${packageManagerName} --version`);
|
|
186
|
+
return buffer.toString().trim();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// src/lib/package-manager/helpers/infer-from-manifest.ts
|
|
190
|
+
import fs4 from "fs-extra";
|
|
191
|
+
import assert from "node:assert";
|
|
192
|
+
import path3 from "node:path";
|
|
193
|
+
function inferFromManifest(workspaceRoot) {
|
|
194
|
+
const log = useLogger();
|
|
195
|
+
const { packageManager: packageManagerString } = readTypedJsonSync(
|
|
196
|
+
path3.join(workspaceRoot, "package.json")
|
|
197
|
+
);
|
|
198
|
+
if (!packageManagerString) {
|
|
199
|
+
log.debug("No packageManager field found in root manifest");
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const [name, version = "*"] = packageManagerString.split("@");
|
|
203
|
+
assert(
|
|
204
|
+
supportedPackageManagerNames.includes(name),
|
|
205
|
+
`Package manager "${name}" is not currently supported`
|
|
206
|
+
);
|
|
207
|
+
const lockfileName = getLockfileFileName(name);
|
|
208
|
+
assert(
|
|
209
|
+
fs4.existsSync(path3.join(workspaceRoot, lockfileName)),
|
|
210
|
+
`Manifest declares ${name} to be the packageManager, but failed to find ${lockfileName} in workspace root`
|
|
211
|
+
);
|
|
212
|
+
return {
|
|
213
|
+
name,
|
|
214
|
+
version,
|
|
215
|
+
majorVersion: getMajorVersion(version),
|
|
216
|
+
packageManagerString
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/lib/package-manager/index.ts
|
|
221
|
+
var packageManager;
|
|
222
|
+
function usePackageManager() {
|
|
223
|
+
if (!packageManager) {
|
|
224
|
+
throw Error(
|
|
225
|
+
"No package manager detected. Make sure to call detectPackageManager() before usePackageManager()"
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
return packageManager;
|
|
229
|
+
}
|
|
230
|
+
function detectPackageManager(workspaceRootDir) {
|
|
231
|
+
if (isRushWorkspace(workspaceRootDir)) {
|
|
232
|
+
packageManager = inferFromFiles(
|
|
233
|
+
path4.join(workspaceRootDir, "common/config/rush")
|
|
234
|
+
);
|
|
235
|
+
} else {
|
|
236
|
+
packageManager = inferFromManifest(workspaceRootDir) ?? inferFromFiles(workspaceRootDir);
|
|
237
|
+
}
|
|
238
|
+
return packageManager;
|
|
239
|
+
}
|
|
240
|
+
function shouldUsePnpmPack() {
|
|
241
|
+
const { name, majorVersion } = usePackageManager();
|
|
242
|
+
return name === "pnpm" && majorVersion >= 8;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// src/lib/utils/pack.ts
|
|
246
|
+
async function pack(srcDir, dstDir) {
|
|
247
|
+
const log = useLogger();
|
|
143
248
|
const execOptions = {
|
|
144
249
|
maxBuffer: 10 * 1024 * 1024
|
|
145
250
|
};
|
|
146
|
-
const log = useLogger();
|
|
147
251
|
const previousCwd = process.cwd();
|
|
148
252
|
process.chdir(srcDir);
|
|
149
|
-
const stdout =
|
|
253
|
+
const stdout = shouldUsePnpmPack() ? await new Promise((resolve, reject) => {
|
|
150
254
|
exec(
|
|
151
255
|
`pnpm pack --pack-destination "${dstDir}"`,
|
|
152
256
|
execOptions,
|
|
@@ -170,9 +274,9 @@ async function pack(srcDir, dstDir, usePnpmPack) {
|
|
|
170
274
|
}
|
|
171
275
|
);
|
|
172
276
|
});
|
|
173
|
-
const fileName =
|
|
174
|
-
const filePath =
|
|
175
|
-
if (!
|
|
277
|
+
const fileName = path5.basename(stdout.trim());
|
|
278
|
+
const filePath = path5.join(dstDir, fileName);
|
|
279
|
+
if (!fs5.existsSync(filePath)) {
|
|
176
280
|
log.error(
|
|
177
281
|
`The response from pack could not be resolved to an existing file: ${filePath}`
|
|
178
282
|
);
|
|
@@ -184,21 +288,21 @@ async function pack(srcDir, dstDir, usePnpmPack) {
|
|
|
184
288
|
}
|
|
185
289
|
|
|
186
290
|
// src/lib/utils/unpack.ts
|
|
187
|
-
import
|
|
291
|
+
import fs6 from "fs-extra";
|
|
188
292
|
import tar from "tar-fs";
|
|
189
293
|
import { createGunzip } from "zlib";
|
|
190
294
|
async function unpack(filePath, unpackDir) {
|
|
191
295
|
await new Promise((resolve, reject) => {
|
|
192
|
-
|
|
296
|
+
fs6.createReadStream(filePath).pipe(createGunzip()).pipe(tar.extract(unpackDir)).on("finish", () => resolve()).on("error", (err) => reject(err));
|
|
193
297
|
});
|
|
194
298
|
}
|
|
195
299
|
|
|
196
300
|
// src/lib/utils/yaml.ts
|
|
197
|
-
import
|
|
301
|
+
import fs7 from "fs-extra";
|
|
198
302
|
import yaml from "yaml";
|
|
199
303
|
function readTypedYamlSync(filePath) {
|
|
200
304
|
try {
|
|
201
|
-
const rawContent =
|
|
305
|
+
const rawContent = fs7.readFileSync(filePath, "utf-8");
|
|
202
306
|
const data = yaml.parse(rawContent);
|
|
203
307
|
return data;
|
|
204
308
|
} catch (err) {
|
|
@@ -208,7 +312,7 @@ function readTypedYamlSync(filePath) {
|
|
|
208
312
|
}
|
|
209
313
|
}
|
|
210
314
|
function writeTypedYamlSync(filePath, content) {
|
|
211
|
-
|
|
315
|
+
fs7.writeFileSync(filePath, yaml.stringify(content), "utf-8");
|
|
212
316
|
}
|
|
213
317
|
|
|
214
318
|
// src/lib/config.ts
|
|
@@ -249,12 +353,12 @@ function resolveConfig() {
|
|
|
249
353
|
}
|
|
250
354
|
setLogLevel(process.env.DEBUG_ISOLATE_CONFIG ? "debug" : "info");
|
|
251
355
|
const log = useLogger();
|
|
252
|
-
const configFilePath =
|
|
356
|
+
const configFilePath = path6.join(process.cwd(), CONFIG_FILE_NAME);
|
|
253
357
|
if (_user_defined_config) {
|
|
254
358
|
log.debug(`Using user defined config:`, inspectValue(_user_defined_config));
|
|
255
359
|
} else {
|
|
256
360
|
log.debug(`Attempting to load config from ${configFilePath}`);
|
|
257
|
-
_user_defined_config =
|
|
361
|
+
_user_defined_config = fs8.existsSync(configFilePath) ? readTypedJsonSync(configFilePath) : {};
|
|
258
362
|
}
|
|
259
363
|
const foreignKeys = Object.keys(_user_defined_config).filter(
|
|
260
364
|
(key) => !validConfigKeys.includes(key)
|
|
@@ -272,92 +376,6 @@ function resolveConfig() {
|
|
|
272
376
|
return config;
|
|
273
377
|
}
|
|
274
378
|
|
|
275
|
-
// src/lib/package-manager/index.ts
|
|
276
|
-
import path6 from "node:path";
|
|
277
|
-
|
|
278
|
-
// src/lib/package-manager/helpers/infer-from-files.ts
|
|
279
|
-
import fs7 from "fs-extra";
|
|
280
|
-
import { execSync } from "node:child_process";
|
|
281
|
-
import path4 from "node:path";
|
|
282
|
-
|
|
283
|
-
// src/lib/package-manager/names.ts
|
|
284
|
-
var supportedPackageManagerNames = ["pnpm", "yarn", "npm"];
|
|
285
|
-
function getLockfileFileName(name) {
|
|
286
|
-
switch (name) {
|
|
287
|
-
case "pnpm":
|
|
288
|
-
return "pnpm-lock.yaml";
|
|
289
|
-
case "yarn":
|
|
290
|
-
return "yarn.lock";
|
|
291
|
-
case "npm":
|
|
292
|
-
return "package-lock.json";
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// src/lib/package-manager/helpers/infer-from-files.ts
|
|
297
|
-
function inferFromFiles(workspaceRoot) {
|
|
298
|
-
for (const name of supportedPackageManagerNames) {
|
|
299
|
-
const lockfileName = getLockfileFileName(name);
|
|
300
|
-
if (fs7.existsSync(path4.join(workspaceRoot, lockfileName))) {
|
|
301
|
-
return { name, version: getVersion(name) };
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
if (fs7.existsSync(path4.join(workspaceRoot, "npm-shrinkwrap.json"))) {
|
|
305
|
-
return { name: "npm", version: getVersion("npm") };
|
|
306
|
-
}
|
|
307
|
-
throw new Error(`Failed to detect package manager`);
|
|
308
|
-
}
|
|
309
|
-
function getVersion(packageManagerName) {
|
|
310
|
-
const buffer = execSync(`${packageManagerName} --version`);
|
|
311
|
-
return buffer.toString().trim();
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// src/lib/package-manager/helpers/infer-from-manifest.ts
|
|
315
|
-
import fs8 from "fs-extra";
|
|
316
|
-
import assert2 from "node:assert";
|
|
317
|
-
import path5 from "node:path";
|
|
318
|
-
function inferFromManifest(workspaceRoot) {
|
|
319
|
-
const log = useLogger();
|
|
320
|
-
const rootManifest = readTypedJsonSync(
|
|
321
|
-
path5.join(workspaceRoot, "package.json")
|
|
322
|
-
);
|
|
323
|
-
if (!rootManifest.packageManager) {
|
|
324
|
-
log.debug("No packageManager field found in root manifest");
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
const [name, version = "*"] = rootManifest.packageManager.split("@");
|
|
328
|
-
assert2(
|
|
329
|
-
supportedPackageManagerNames.includes(name),
|
|
330
|
-
`Package manager "${name}" is not currently supported`
|
|
331
|
-
);
|
|
332
|
-
const lockfileName = getLockfileFileName(name);
|
|
333
|
-
assert2(
|
|
334
|
-
fs8.existsSync(path5.join(workspaceRoot, lockfileName)),
|
|
335
|
-
`Manifest declares ${name} to be the packageManager, but failed to find ${lockfileName} in workspace root`
|
|
336
|
-
);
|
|
337
|
-
return { name, version };
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// src/lib/package-manager/index.ts
|
|
341
|
-
var packageManager;
|
|
342
|
-
function usePackageManager() {
|
|
343
|
-
if (!packageManager) {
|
|
344
|
-
throw Error(
|
|
345
|
-
"No package manager detected. Make sure to call detectPackageManager() before usePackageManager()"
|
|
346
|
-
);
|
|
347
|
-
}
|
|
348
|
-
return packageManager;
|
|
349
|
-
}
|
|
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
|
-
}
|
|
358
|
-
return packageManager;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
379
|
// src/lib/lockfile/helpers/generate-npm-lockfile.ts
|
|
362
380
|
import Arborist from "@npmcli/arborist";
|
|
363
381
|
import fs9 from "fs-extra";
|
|
@@ -404,14 +422,20 @@ async function generateNpmLockfile({
|
|
|
404
422
|
}
|
|
405
423
|
|
|
406
424
|
// src/lib/lockfile/helpers/generate-pnpm-lockfile.ts
|
|
407
|
-
import {
|
|
408
|
-
getLockfileImporterId,
|
|
409
|
-
readWantedLockfile,
|
|
410
|
-
writeWantedLockfile
|
|
411
|
-
} from "@pnpm/lockfile-file";
|
|
412
|
-
import { pruneLockfile } from "@pnpm/prune-lockfile";
|
|
413
425
|
import assert3 from "node:assert";
|
|
414
426
|
import path8 from "node:path";
|
|
427
|
+
import {
|
|
428
|
+
getLockfileImporterId as getLockfileImporterId_v8,
|
|
429
|
+
readWantedLockfile as readWantedLockfile_v8,
|
|
430
|
+
writeWantedLockfile as writeWantedLockfile_v8
|
|
431
|
+
} from "pnpm_lockfile_file_v8";
|
|
432
|
+
import {
|
|
433
|
+
getLockfileImporterId as getLockfileImporterId_v9,
|
|
434
|
+
readWantedLockfile as readWantedLockfile_v9,
|
|
435
|
+
writeWantedLockfile as writeWantedLockfile_v9
|
|
436
|
+
} from "pnpm_lockfile_file_v9";
|
|
437
|
+
import { pruneLockfile as pruneLockfile_v8 } from "pnpm_prune_lockfile_v8";
|
|
438
|
+
import { pruneLockfile as pruneLockfile_v9 } from "pnpm_prune_lockfile_v9";
|
|
415
439
|
import { pick } from "remeda";
|
|
416
440
|
|
|
417
441
|
// src/lib/lockfile/helpers/pnpm-map-importer.ts
|
|
@@ -440,24 +464,28 @@ async function generatePnpmLockfile({
|
|
|
440
464
|
isolateDir,
|
|
441
465
|
internalDepPackageNames,
|
|
442
466
|
packagesRegistry,
|
|
443
|
-
targetPackageManifest
|
|
467
|
+
targetPackageManifest,
|
|
468
|
+
majorVersion
|
|
444
469
|
}) {
|
|
470
|
+
const useVersion9 = majorVersion >= 9;
|
|
445
471
|
const { includeDevDependencies, includePatchedDependencies } = useConfig();
|
|
446
472
|
const log = useLogger();
|
|
447
473
|
log.info("Generating PNPM lockfile...");
|
|
448
474
|
try {
|
|
449
475
|
const isRush = isRushWorkspace(workspaceRootDir);
|
|
450
|
-
const lockfile = await
|
|
476
|
+
const lockfile = useVersion9 ? await readWantedLockfile_v9(
|
|
477
|
+
isRush ? path8.join(workspaceRootDir, "common/config/rush") : workspaceRootDir,
|
|
478
|
+
{
|
|
479
|
+
ignoreIncompatible: false
|
|
480
|
+
}
|
|
481
|
+
) : await readWantedLockfile_v8(
|
|
451
482
|
isRush ? path8.join(workspaceRootDir, "common/config/rush") : workspaceRootDir,
|
|
452
483
|
{
|
|
453
484
|
ignoreIncompatible: false
|
|
454
485
|
}
|
|
455
486
|
);
|
|
456
487
|
assert3(lockfile, `No input lockfile found at ${workspaceRootDir}`);
|
|
457
|
-
const targetImporterId =
|
|
458
|
-
workspaceRootDir,
|
|
459
|
-
targetPackageDir
|
|
460
|
-
);
|
|
488
|
+
const targetImporterId = useVersion9 ? getLockfileImporterId_v9(workspaceRootDir, targetPackageDir) : getLockfileImporterId_v8(workspaceRootDir, targetPackageDir);
|
|
461
489
|
const directoryByPackageName = Object.fromEntries(
|
|
462
490
|
internalDepPackageNames.map((name) => {
|
|
463
491
|
const pkg = packagesRegistry[name];
|
|
@@ -505,20 +533,14 @@ async function generatePnpmLockfile({
|
|
|
505
533
|
})
|
|
506
534
|
);
|
|
507
535
|
log.debug("Pruning the lockfile");
|
|
508
|
-
const prunedLockfile = await
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
"."
|
|
512
|
-
);
|
|
513
|
-
await writeWantedLockfile(isolateDir, {
|
|
536
|
+
const prunedLockfile = useVersion9 ? await pruneLockfile_v9(lockfile, targetPackageManifest, ".") : await pruneLockfile_v8(lockfile, targetPackageManifest, ".");
|
|
537
|
+
const patchedDependencies = includePatchedDependencies ? lockfile.patchedDependencies : void 0;
|
|
538
|
+
useVersion9 ? await writeWantedLockfile_v9(isolateDir, {
|
|
514
539
|
...prunedLockfile,
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
* common use case.
|
|
520
|
-
*/
|
|
521
|
-
patchedDependencies: includePatchedDependencies ? lockfile.patchedDependencies : void 0
|
|
540
|
+
patchedDependencies
|
|
541
|
+
}) : await writeWantedLockfile_v8(isolateDir, {
|
|
542
|
+
...prunedLockfile,
|
|
543
|
+
patchedDependencies
|
|
522
544
|
});
|
|
523
545
|
log.debug("Created lockfile at", path8.join(isolateDir, "pnpm-lock.yaml"));
|
|
524
546
|
} catch (err) {
|
|
@@ -562,16 +584,7 @@ async function processLockfile({
|
|
|
562
584
|
targetPackageManifest
|
|
563
585
|
}) {
|
|
564
586
|
const log = useLogger();
|
|
565
|
-
const {
|
|
566
|
-
if (forceNpm) {
|
|
567
|
-
log.info("Forcing to use NPM for isolate output");
|
|
568
|
-
await generateNpmLockfile({
|
|
569
|
-
workspaceRootDir,
|
|
570
|
-
isolateDir
|
|
571
|
-
});
|
|
572
|
-
return true;
|
|
573
|
-
}
|
|
574
|
-
const { name, version } = usePackageManager();
|
|
587
|
+
const { name, majorVersion } = usePackageManager();
|
|
575
588
|
let usedFallbackToNpm = false;
|
|
576
589
|
switch (name) {
|
|
577
590
|
case "npm": {
|
|
@@ -582,8 +595,7 @@ async function processLockfile({
|
|
|
582
595
|
break;
|
|
583
596
|
}
|
|
584
597
|
case "yarn": {
|
|
585
|
-
|
|
586
|
-
if (versionMajor === 1) {
|
|
598
|
+
if (majorVersion === 1) {
|
|
587
599
|
await generateYarnLockfile({
|
|
588
600
|
workspaceRootDir,
|
|
589
601
|
isolateDir
|
|
@@ -607,7 +619,8 @@ async function processLockfile({
|
|
|
607
619
|
isolateDir,
|
|
608
620
|
internalDepPackageNames,
|
|
609
621
|
packagesRegistry,
|
|
610
|
-
targetPackageManifest
|
|
622
|
+
targetPackageManifest,
|
|
623
|
+
majorVersion
|
|
611
624
|
});
|
|
612
625
|
break;
|
|
613
626
|
}
|
|
@@ -687,12 +700,11 @@ function adaptManifestInternalDeps({
|
|
|
687
700
|
// src/lib/manifest/helpers/adapt-internal-package-manifests.ts
|
|
688
701
|
async function adaptInternalPackageManifests(internalPackageNames, packagesRegistry, isolateDir) {
|
|
689
702
|
const packageManager2 = usePackageManager();
|
|
690
|
-
const { forceNpm } = useConfig();
|
|
691
703
|
await Promise.all(
|
|
692
704
|
internalPackageNames.map(async (packageName) => {
|
|
693
705
|
const { manifest, rootRelativeDir } = packagesRegistry[packageName];
|
|
694
706
|
const strippedManifest = omit(manifest, ["scripts", "devDependencies"]);
|
|
695
|
-
const outputManifest = packageManager2.name === "pnpm"
|
|
707
|
+
const outputManifest = packageManager2.name === "pnpm" ? (
|
|
696
708
|
/**
|
|
697
709
|
* For PNPM the output itself is a workspace so we can preserve the specifiers
|
|
698
710
|
* with "workspace:*" in the output manifest.
|
|
@@ -742,9 +754,9 @@ async function adaptTargetPackageManifest({
|
|
|
742
754
|
workspaceRootDir
|
|
743
755
|
}) {
|
|
744
756
|
const packageManager2 = usePackageManager();
|
|
745
|
-
const { includeDevDependencies,
|
|
757
|
+
const { includeDevDependencies, pickFromScripts, omitFromScripts } = useConfig();
|
|
746
758
|
const inputManifest = includeDevDependencies ? manifest : omit2(manifest, ["devDependencies"]);
|
|
747
|
-
const adaptedManifest = packageManager2.name === "pnpm"
|
|
759
|
+
const adaptedManifest = packageManager2.name === "pnpm" ? (
|
|
748
760
|
/**
|
|
749
761
|
* For PNPM the output itself is a workspace so we can preserve the specifiers
|
|
750
762
|
* with "workspace:*" in the output manifest, but we do want to adopt the
|
|
@@ -760,6 +772,8 @@ async function adaptTargetPackageManifest({
|
|
|
760
772
|
);
|
|
761
773
|
return {
|
|
762
774
|
...adaptedManifest,
|
|
775
|
+
/** Adopt the package manager definition from the root manifest if available. */
|
|
776
|
+
packageManager: packageManager2.packageManagerString,
|
|
763
777
|
/**
|
|
764
778
|
* Scripts are removed by default if not explicitly picked or omitted via
|
|
765
779
|
* config.
|
|
@@ -816,25 +830,15 @@ async function packDependencies({
|
|
|
816
830
|
}) {
|
|
817
831
|
const log = useLogger();
|
|
818
832
|
const packedFileByName = {};
|
|
819
|
-
const { name, version } = usePackageManager();
|
|
820
|
-
const versionMajor = parseInt(version.split(".")[0], 10);
|
|
821
|
-
const usePnpmPack = name === "pnpm" && versionMajor >= 8;
|
|
822
|
-
if (usePnpmPack) {
|
|
823
|
-
log.debug("Using PNPM pack instead of NPM pack");
|
|
824
|
-
}
|
|
825
833
|
for (const dependency of internalPackageNames) {
|
|
826
834
|
const def = packagesRegistry[dependency];
|
|
827
835
|
assert4(dependency, `Failed to find package definition for ${dependency}`);
|
|
828
|
-
const { name
|
|
829
|
-
if (packedFileByName[
|
|
830
|
-
log.debug(`Skipping ${
|
|
836
|
+
const { name } = def.manifest;
|
|
837
|
+
if (packedFileByName[name]) {
|
|
838
|
+
log.debug(`Skipping ${name} because it has already been packed`);
|
|
831
839
|
continue;
|
|
832
840
|
}
|
|
833
|
-
packedFileByName[
|
|
834
|
-
def.absoluteDir,
|
|
835
|
-
packDestinationDir,
|
|
836
|
-
usePnpmPack
|
|
837
|
-
);
|
|
841
|
+
packedFileByName[name] = await pack(def.absoluteDir, packDestinationDir);
|
|
838
842
|
}
|
|
839
843
|
return packedFileByName;
|
|
840
844
|
}
|
|
@@ -1024,10 +1028,10 @@ async function isolate(options = {}) {
|
|
|
1024
1028
|
const config = resolveConfig();
|
|
1025
1029
|
setLogLevel(config.logLevel);
|
|
1026
1030
|
const log = useLogger();
|
|
1027
|
-
const
|
|
1031
|
+
const { version: libraryVersion } = await readTypedJson(
|
|
1028
1032
|
path19.join(path19.join(__dirname, "..", "package.json"))
|
|
1029
1033
|
);
|
|
1030
|
-
log.debug("Using isolate-package version",
|
|
1034
|
+
log.debug("Using isolate-package version", libraryVersion);
|
|
1031
1035
|
const targetPackageDir = config.targetPackagePath ? path19.join(process.cwd(), config.targetPackagePath) : process.cwd();
|
|
1032
1036
|
const workspaceRootDir = config.targetPackagePath ? process.cwd() : path19.join(targetPackageDir, config.workspaceRoot);
|
|
1033
1037
|
const buildOutputDir = await getBuildOutputDir(targetPackageDir);
|
|
@@ -1061,6 +1065,9 @@ async function isolate(options = {}) {
|
|
|
1061
1065
|
packageManager2.name,
|
|
1062
1066
|
packageManager2.version
|
|
1063
1067
|
);
|
|
1068
|
+
if (shouldUsePnpmPack()) {
|
|
1069
|
+
log.debug("Use PNPM pack instead of NPM pack");
|
|
1070
|
+
}
|
|
1064
1071
|
const packagesRegistry = await createPackagesRegistry(
|
|
1065
1072
|
workspaceRootDir,
|
|
1066
1073
|
config.workspacePackages
|
|
@@ -1114,7 +1121,7 @@ async function isolate(options = {}) {
|
|
|
1114
1121
|
manifest.packageManager = `npm@${npmVersion}`;
|
|
1115
1122
|
await writeManifest(isolateDir, manifest);
|
|
1116
1123
|
}
|
|
1117
|
-
if (packageManager2.name === "pnpm"
|
|
1124
|
+
if (packageManager2.name === "pnpm") {
|
|
1118
1125
|
if (isRushWorkspace(workspaceRootDir)) {
|
|
1119
1126
|
const packagesFolderNames = unique(
|
|
1120
1127
|
internalPackageNames.map(
|