isolate-package 1.20.0 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +51 -40
- package/dist/index.mjs.map +1 -1
- package/dist/isolate-bin.mjs +51 -40
- package/dist/isolate-bin.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// src/isolate.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import fs15 from "fs-extra";
|
|
3
|
+
import assert7 from "node:assert";
|
|
4
4
|
import path20 from "node:path";
|
|
5
5
|
import { unique as unique2 } from "remeda";
|
|
6
6
|
|
|
7
7
|
// src/lib/config.ts
|
|
8
8
|
import fs8 from "fs-extra";
|
|
9
|
-
import
|
|
9
|
+
import assert3 from "node:assert";
|
|
10
10
|
import path6 from "node:path";
|
|
11
11
|
import { isEmpty } from "remeda";
|
|
12
12
|
|
|
@@ -136,6 +136,7 @@ async function readTypedJson(filePath) {
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
// src/lib/utils/pack.ts
|
|
139
|
+
import assert2 from "node:assert";
|
|
139
140
|
import { exec } from "node:child_process";
|
|
140
141
|
import fs5 from "node:fs";
|
|
141
142
|
import path5 from "node:path";
|
|
@@ -287,7 +288,10 @@ async function pack(srcDir, dstDir) {
|
|
|
287
288
|
}
|
|
288
289
|
);
|
|
289
290
|
});
|
|
290
|
-
const
|
|
291
|
+
const lastLine = stdout.trim().split("\n").at(-1);
|
|
292
|
+
assert2(lastLine, `Failed to parse last line from stdout: ${stdout.trim()}`);
|
|
293
|
+
const fileName = path5.basename(lastLine);
|
|
294
|
+
assert2(fileName, `Failed to parse file name from: ${lastLine}`);
|
|
291
295
|
const filePath = path5.join(dstDir, fileName);
|
|
292
296
|
if (!fs5.existsSync(filePath)) {
|
|
293
297
|
log.error(
|
|
@@ -438,7 +442,7 @@ async function generateNpmLockfile({
|
|
|
438
442
|
}
|
|
439
443
|
|
|
440
444
|
// src/lib/lockfile/helpers/generate-pnpm-lockfile.ts
|
|
441
|
-
import
|
|
445
|
+
import assert4 from "node:assert";
|
|
442
446
|
import path9 from "node:path";
|
|
443
447
|
import {
|
|
444
448
|
getLockfileImporterId as getLockfileImporterId_v8,
|
|
@@ -480,10 +484,7 @@ function pnpmMapDependenciesLinks(importerPath, def, directoryByPackageName) {
|
|
|
480
484
|
if (!value.startsWith("link:")) {
|
|
481
485
|
return value;
|
|
482
486
|
}
|
|
483
|
-
const relativePath = path8.relative(
|
|
484
|
-
importerPath,
|
|
485
|
-
directoryByPackageName[key]
|
|
486
|
-
);
|
|
487
|
+
const relativePath = path8.relative(importerPath, directoryByPackageName[key]).replace(path8.sep, path8.posix.sep);
|
|
487
488
|
return relativePath.startsWith(".") ? `link:${relativePath}` : `link:./${relativePath}`;
|
|
488
489
|
});
|
|
489
490
|
}
|
|
@@ -515,12 +516,12 @@ async function generatePnpmLockfile({
|
|
|
515
516
|
ignoreIncompatible: false
|
|
516
517
|
}
|
|
517
518
|
);
|
|
518
|
-
|
|
519
|
+
assert4(lockfile, `No input lockfile found at ${workspaceRootDir}`);
|
|
519
520
|
const targetImporterId = useVersion9 ? getLockfileImporterId_v9(workspaceRootDir, targetPackageDir) : getLockfileImporterId_v8(workspaceRootDir, targetPackageDir);
|
|
520
521
|
const directoryByPackageName = Object.fromEntries(
|
|
521
522
|
internalDepPackageNames.map((name) => {
|
|
522
523
|
const pkg = packagesRegistry[name];
|
|
523
|
-
|
|
524
|
+
assert4(pkg, `Package ${name} not found in packages registry`);
|
|
524
525
|
return [name, pkg.rootRelativeDir];
|
|
525
526
|
})
|
|
526
527
|
);
|
|
@@ -531,7 +532,17 @@ async function generatePnpmLockfile({
|
|
|
531
532
|
* importer ids in the context of a lockfile.
|
|
532
533
|
*/
|
|
533
534
|
...Object.values(directoryByPackageName)
|
|
534
|
-
|
|
535
|
+
/**
|
|
536
|
+
* Split the path by the OS separator and join it back with the POSIX
|
|
537
|
+
* separator.
|
|
538
|
+
*
|
|
539
|
+
* The importerIds are built from directory names, so Windows Git Bash
|
|
540
|
+
* environments will have double backslashes in their ids:
|
|
541
|
+
* "packages\common" vs. "packages/common". Without this split & join, any
|
|
542
|
+
* packages not on the top-level will have ill-formatted importerIds and
|
|
543
|
+
* their entries will be missing from the lockfile.importers list.
|
|
544
|
+
*/
|
|
545
|
+
].map((x) => x.split(path9.sep).join(path9.posix.sep));
|
|
535
546
|
log.debug("Relevant importer ids:", relevantImporterIds);
|
|
536
547
|
const relevantImporterIdsWithPrefix = relevantImporterIds.map(
|
|
537
548
|
(x) => isRush ? `../../${x}` : x
|
|
@@ -850,7 +861,7 @@ async function adaptTargetPackageManifest({
|
|
|
850
861
|
}
|
|
851
862
|
|
|
852
863
|
// src/lib/output/get-build-output-dir.ts
|
|
853
|
-
import
|
|
864
|
+
import { getTsconfig } from "get-tsconfig";
|
|
854
865
|
import path15 from "node:path";
|
|
855
866
|
import outdent from "outdent";
|
|
856
867
|
async function getBuildOutputDir(targetPackageDir) {
|
|
@@ -861,10 +872,10 @@ async function getBuildOutputDir(targetPackageDir) {
|
|
|
861
872
|
return path15.join(targetPackageDir, config.buildDirName);
|
|
862
873
|
}
|
|
863
874
|
const tsconfigPath = path15.join(targetPackageDir, config.tsconfigPath);
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
const outDir = tsconfig.compilerOptions?.outDir;
|
|
875
|
+
const tsconfig = getTsconfig(tsconfigPath);
|
|
876
|
+
if (tsconfig) {
|
|
877
|
+
log.debug("Found tsconfig at:", tsconfig.path);
|
|
878
|
+
const outDir = tsconfig.config.compilerOptions?.outDir;
|
|
868
879
|
if (outDir) {
|
|
869
880
|
return path15.join(targetPackageDir, outDir);
|
|
870
881
|
} else {
|
|
@@ -881,7 +892,7 @@ async function getBuildOutputDir(targetPackageDir) {
|
|
|
881
892
|
}
|
|
882
893
|
|
|
883
894
|
// src/lib/output/pack-dependencies.ts
|
|
884
|
-
import
|
|
895
|
+
import assert5 from "node:assert";
|
|
885
896
|
async function packDependencies({
|
|
886
897
|
/** All packages found in the monorepo by workspaces declaration */
|
|
887
898
|
packagesRegistry,
|
|
@@ -899,7 +910,7 @@ async function packDependencies({
|
|
|
899
910
|
const packedFileByName = {};
|
|
900
911
|
for (const dependency of internalPackageNames) {
|
|
901
912
|
const def = packagesRegistry[dependency];
|
|
902
|
-
|
|
913
|
+
assert5(dependency, `Failed to find package definition for ${dependency}`);
|
|
903
914
|
const { name } = def.manifest;
|
|
904
915
|
if (packedFileByName[name]) {
|
|
905
916
|
log.debug(`Skipping ${name} because it has already been packed`);
|
|
@@ -911,7 +922,7 @@ async function packDependencies({
|
|
|
911
922
|
}
|
|
912
923
|
|
|
913
924
|
// src/lib/output/process-build-output-files.ts
|
|
914
|
-
import
|
|
925
|
+
import fs12 from "fs-extra";
|
|
915
926
|
import path16 from "node:path";
|
|
916
927
|
var TIMEOUT_MS = 5e3;
|
|
917
928
|
async function processBuildOutputFiles({
|
|
@@ -924,7 +935,7 @@ async function processBuildOutputFiles({
|
|
|
924
935
|
const unpackDir = path16.join(tmpDir, "target");
|
|
925
936
|
const now = Date.now();
|
|
926
937
|
let isWaitingYet = false;
|
|
927
|
-
while (!
|
|
938
|
+
while (!fs12.existsSync(packedFilePath) && Date.now() - now < TIMEOUT_MS) {
|
|
928
939
|
if (!isWaitingYet) {
|
|
929
940
|
log.debug(`Waiting for ${packedFilePath} to become available...`);
|
|
930
941
|
}
|
|
@@ -932,11 +943,11 @@ async function processBuildOutputFiles({
|
|
|
932
943
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
933
944
|
}
|
|
934
945
|
await unpack(packedFilePath, unpackDir);
|
|
935
|
-
await
|
|
946
|
+
await fs12.copy(path16.join(unpackDir, "package"), isolateDir);
|
|
936
947
|
}
|
|
937
948
|
|
|
938
949
|
// src/lib/output/unpack-dependencies.ts
|
|
939
|
-
import
|
|
950
|
+
import fs13 from "fs-extra";
|
|
940
951
|
import path17, { join as join2 } from "node:path";
|
|
941
952
|
async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, isolateDir) {
|
|
942
953
|
const log = useLogger();
|
|
@@ -947,8 +958,8 @@ async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, i
|
|
|
947
958
|
log.debug("Unpacking", `(temp)/${path17.basename(filePath)}`);
|
|
948
959
|
await unpack(filePath, unpackDir);
|
|
949
960
|
const destinationDir = join2(isolateDir, dir);
|
|
950
|
-
await
|
|
951
|
-
await
|
|
961
|
+
await fs13.ensureDir(destinationDir);
|
|
962
|
+
await fs13.move(join2(unpackDir, "package"), destinationDir, {
|
|
952
963
|
overwrite: true
|
|
953
964
|
});
|
|
954
965
|
log.debug(
|
|
@@ -962,12 +973,12 @@ async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, i
|
|
|
962
973
|
}
|
|
963
974
|
|
|
964
975
|
// src/lib/registry/create-packages-registry.ts
|
|
965
|
-
import
|
|
976
|
+
import fs14 from "fs-extra";
|
|
966
977
|
import { globSync } from "glob";
|
|
967
978
|
import path19 from "node:path";
|
|
968
979
|
|
|
969
980
|
// src/lib/registry/helpers/find-packages-globs.ts
|
|
970
|
-
import
|
|
981
|
+
import assert6 from "node:assert";
|
|
971
982
|
import path18 from "node:path";
|
|
972
983
|
function findPackagesGlobs(workspaceRootDir) {
|
|
973
984
|
const log = useLogger();
|
|
@@ -999,7 +1010,7 @@ function findPackagesGlobs(workspaceRootDir) {
|
|
|
999
1010
|
return workspaces;
|
|
1000
1011
|
} else {
|
|
1001
1012
|
const workspacesObject = workspaces;
|
|
1002
|
-
|
|
1013
|
+
assert6(
|
|
1003
1014
|
workspacesObject.packages,
|
|
1004
1015
|
"workspaces.packages must be an array"
|
|
1005
1016
|
);
|
|
@@ -1025,7 +1036,7 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
|
|
|
1025
1036
|
allPackages.map(async (rootRelativeDir) => {
|
|
1026
1037
|
const absoluteDir = path19.join(workspaceRootDir, rootRelativeDir);
|
|
1027
1038
|
const manifestPath = path19.join(absoluteDir, "package.json");
|
|
1028
|
-
if (!
|
|
1039
|
+
if (!fs14.existsSync(manifestPath)) {
|
|
1029
1040
|
log.warn(
|
|
1030
1041
|
`Ignoring directory ${rootRelativeDir} because it does not contain a package.json file`
|
|
1031
1042
|
);
|
|
@@ -1060,7 +1071,7 @@ function listWorkspacePackages(workspacePackagesOverride, workspaceRootDir) {
|
|
|
1060
1071
|
const currentDir = process.cwd();
|
|
1061
1072
|
process.chdir(workspaceRootDir);
|
|
1062
1073
|
const packagesGlobs = workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);
|
|
1063
|
-
const allPackages = packagesGlobs.flatMap((glob) => globSync(glob)).filter((dir) =>
|
|
1074
|
+
const allPackages = packagesGlobs.flatMap((glob) => globSync(glob)).filter((dir) => fs14.lstatSync(dir).isDirectory());
|
|
1064
1075
|
process.chdir(currentDir);
|
|
1065
1076
|
return allPackages;
|
|
1066
1077
|
}
|
|
@@ -1103,8 +1114,8 @@ async function isolate(options = {}) {
|
|
|
1103
1114
|
const targetPackageDir = config.targetPackagePath ? path20.join(process.cwd(), config.targetPackagePath) : process.cwd();
|
|
1104
1115
|
const workspaceRootDir = config.targetPackagePath ? process.cwd() : path20.join(targetPackageDir, config.workspaceRoot);
|
|
1105
1116
|
const buildOutputDir = await getBuildOutputDir(targetPackageDir);
|
|
1106
|
-
|
|
1107
|
-
|
|
1117
|
+
assert7(
|
|
1118
|
+
fs15.existsSync(buildOutputDir),
|
|
1108
1119
|
`Failed to find build output path at ${buildOutputDir}. Please make sure you build the source before isolating it.`
|
|
1109
1120
|
);
|
|
1110
1121
|
log.debug("Workspace root resolved to", workspaceRootDir);
|
|
@@ -1117,13 +1128,13 @@ async function isolate(options = {}) {
|
|
|
1117
1128
|
"Isolate output directory",
|
|
1118
1129
|
getRootRelativePath(isolateDir, workspaceRootDir)
|
|
1119
1130
|
);
|
|
1120
|
-
if (
|
|
1121
|
-
await
|
|
1131
|
+
if (fs15.existsSync(isolateDir)) {
|
|
1132
|
+
await fs15.remove(isolateDir);
|
|
1122
1133
|
log.debug("Cleaned the existing isolate output directory");
|
|
1123
1134
|
}
|
|
1124
|
-
await
|
|
1135
|
+
await fs15.ensureDir(isolateDir);
|
|
1125
1136
|
const tmpDir = path20.join(isolateDir, "__tmp");
|
|
1126
|
-
await
|
|
1137
|
+
await fs15.ensureDir(tmpDir);
|
|
1127
1138
|
const targetPackageManifest = await readTypedJson(
|
|
1128
1139
|
path20.join(targetPackageDir, "package.json")
|
|
1129
1140
|
);
|
|
@@ -1203,22 +1214,22 @@ async function isolate(options = {}) {
|
|
|
1203
1214
|
packages
|
|
1204
1215
|
});
|
|
1205
1216
|
} else {
|
|
1206
|
-
|
|
1217
|
+
fs15.copyFileSync(
|
|
1207
1218
|
path20.join(workspaceRootDir, "pnpm-workspace.yaml"),
|
|
1208
1219
|
path20.join(isolateDir, "pnpm-workspace.yaml")
|
|
1209
1220
|
);
|
|
1210
1221
|
}
|
|
1211
1222
|
}
|
|
1212
1223
|
const npmrcPath = path20.join(workspaceRootDir, ".npmrc");
|
|
1213
|
-
if (
|
|
1214
|
-
|
|
1224
|
+
if (fs15.existsSync(npmrcPath)) {
|
|
1225
|
+
fs15.copyFileSync(npmrcPath, path20.join(isolateDir, ".npmrc"));
|
|
1215
1226
|
log.debug("Copied .npmrc file to the isolate output");
|
|
1216
1227
|
}
|
|
1217
1228
|
log.debug(
|
|
1218
1229
|
"Deleting temp directory",
|
|
1219
1230
|
getRootRelativePath(tmpDir, workspaceRootDir)
|
|
1220
1231
|
);
|
|
1221
|
-
await
|
|
1232
|
+
await fs15.remove(tmpDir);
|
|
1222
1233
|
log.info("Isolate completed at", isolateDir);
|
|
1223
1234
|
return isolateDir;
|
|
1224
1235
|
}
|