isolate-package 1.21.0-1 → 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 +49 -42
- package/dist/index.mjs.map +1 -1
- package/dist/isolate-bin.mjs +49 -42
- 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";
|
|
@@ -288,10 +289,9 @@ async function pack(srcDir, dstDir) {
|
|
|
288
289
|
);
|
|
289
290
|
});
|
|
290
291
|
const lastLine = stdout.trim().split("\n").at(-1);
|
|
291
|
-
|
|
292
|
-
throw new Error(`Failed to parse last line from stdout: ${stdout.trim()}`);
|
|
293
|
-
}
|
|
292
|
+
assert2(lastLine, `Failed to parse last line from stdout: ${stdout.trim()}`);
|
|
294
293
|
const fileName = path5.basename(lastLine);
|
|
294
|
+
assert2(fileName, `Failed to parse file name from: ${lastLine}`);
|
|
295
295
|
const filePath = path5.join(dstDir, fileName);
|
|
296
296
|
if (!fs5.existsSync(filePath)) {
|
|
297
297
|
log.error(
|
|
@@ -442,7 +442,7 @@ async function generateNpmLockfile({
|
|
|
442
442
|
}
|
|
443
443
|
|
|
444
444
|
// src/lib/lockfile/helpers/generate-pnpm-lockfile.ts
|
|
445
|
-
import
|
|
445
|
+
import assert4 from "node:assert";
|
|
446
446
|
import path9 from "node:path";
|
|
447
447
|
import {
|
|
448
448
|
getLockfileImporterId as getLockfileImporterId_v8,
|
|
@@ -484,10 +484,7 @@ function pnpmMapDependenciesLinks(importerPath, def, directoryByPackageName) {
|
|
|
484
484
|
if (!value.startsWith("link:")) {
|
|
485
485
|
return value;
|
|
486
486
|
}
|
|
487
|
-
const relativePath = path8.relative(
|
|
488
|
-
importerPath,
|
|
489
|
-
directoryByPackageName[key]
|
|
490
|
-
);
|
|
487
|
+
const relativePath = path8.relative(importerPath, directoryByPackageName[key]).replace(path8.sep, path8.posix.sep);
|
|
491
488
|
return relativePath.startsWith(".") ? `link:${relativePath}` : `link:./${relativePath}`;
|
|
492
489
|
});
|
|
493
490
|
}
|
|
@@ -519,12 +516,12 @@ async function generatePnpmLockfile({
|
|
|
519
516
|
ignoreIncompatible: false
|
|
520
517
|
}
|
|
521
518
|
);
|
|
522
|
-
|
|
519
|
+
assert4(lockfile, `No input lockfile found at ${workspaceRootDir}`);
|
|
523
520
|
const targetImporterId = useVersion9 ? getLockfileImporterId_v9(workspaceRootDir, targetPackageDir) : getLockfileImporterId_v8(workspaceRootDir, targetPackageDir);
|
|
524
521
|
const directoryByPackageName = Object.fromEntries(
|
|
525
522
|
internalDepPackageNames.map((name) => {
|
|
526
523
|
const pkg = packagesRegistry[name];
|
|
527
|
-
|
|
524
|
+
assert4(pkg, `Package ${name} not found in packages registry`);
|
|
528
525
|
return [name, pkg.rootRelativeDir];
|
|
529
526
|
})
|
|
530
527
|
);
|
|
@@ -535,7 +532,17 @@ async function generatePnpmLockfile({
|
|
|
535
532
|
* importer ids in the context of a lockfile.
|
|
536
533
|
*/
|
|
537
534
|
...Object.values(directoryByPackageName)
|
|
538
|
-
|
|
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));
|
|
539
546
|
log.debug("Relevant importer ids:", relevantImporterIds);
|
|
540
547
|
const relevantImporterIdsWithPrefix = relevantImporterIds.map(
|
|
541
548
|
(x) => isRush ? `../../${x}` : x
|
|
@@ -854,7 +861,7 @@ async function adaptTargetPackageManifest({
|
|
|
854
861
|
}
|
|
855
862
|
|
|
856
863
|
// src/lib/output/get-build-output-dir.ts
|
|
857
|
-
import
|
|
864
|
+
import { getTsconfig } from "get-tsconfig";
|
|
858
865
|
import path15 from "node:path";
|
|
859
866
|
import outdent from "outdent";
|
|
860
867
|
async function getBuildOutputDir(targetPackageDir) {
|
|
@@ -865,10 +872,10 @@ async function getBuildOutputDir(targetPackageDir) {
|
|
|
865
872
|
return path15.join(targetPackageDir, config.buildDirName);
|
|
866
873
|
}
|
|
867
874
|
const tsconfigPath = path15.join(targetPackageDir, config.tsconfigPath);
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
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;
|
|
872
879
|
if (outDir) {
|
|
873
880
|
return path15.join(targetPackageDir, outDir);
|
|
874
881
|
} else {
|
|
@@ -885,7 +892,7 @@ async function getBuildOutputDir(targetPackageDir) {
|
|
|
885
892
|
}
|
|
886
893
|
|
|
887
894
|
// src/lib/output/pack-dependencies.ts
|
|
888
|
-
import
|
|
895
|
+
import assert5 from "node:assert";
|
|
889
896
|
async function packDependencies({
|
|
890
897
|
/** All packages found in the monorepo by workspaces declaration */
|
|
891
898
|
packagesRegistry,
|
|
@@ -903,7 +910,7 @@ async function packDependencies({
|
|
|
903
910
|
const packedFileByName = {};
|
|
904
911
|
for (const dependency of internalPackageNames) {
|
|
905
912
|
const def = packagesRegistry[dependency];
|
|
906
|
-
|
|
913
|
+
assert5(dependency, `Failed to find package definition for ${dependency}`);
|
|
907
914
|
const { name } = def.manifest;
|
|
908
915
|
if (packedFileByName[name]) {
|
|
909
916
|
log.debug(`Skipping ${name} because it has already been packed`);
|
|
@@ -915,7 +922,7 @@ async function packDependencies({
|
|
|
915
922
|
}
|
|
916
923
|
|
|
917
924
|
// src/lib/output/process-build-output-files.ts
|
|
918
|
-
import
|
|
925
|
+
import fs12 from "fs-extra";
|
|
919
926
|
import path16 from "node:path";
|
|
920
927
|
var TIMEOUT_MS = 5e3;
|
|
921
928
|
async function processBuildOutputFiles({
|
|
@@ -928,7 +935,7 @@ async function processBuildOutputFiles({
|
|
|
928
935
|
const unpackDir = path16.join(tmpDir, "target");
|
|
929
936
|
const now = Date.now();
|
|
930
937
|
let isWaitingYet = false;
|
|
931
|
-
while (!
|
|
938
|
+
while (!fs12.existsSync(packedFilePath) && Date.now() - now < TIMEOUT_MS) {
|
|
932
939
|
if (!isWaitingYet) {
|
|
933
940
|
log.debug(`Waiting for ${packedFilePath} to become available...`);
|
|
934
941
|
}
|
|
@@ -936,11 +943,11 @@ async function processBuildOutputFiles({
|
|
|
936
943
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
937
944
|
}
|
|
938
945
|
await unpack(packedFilePath, unpackDir);
|
|
939
|
-
await
|
|
946
|
+
await fs12.copy(path16.join(unpackDir, "package"), isolateDir);
|
|
940
947
|
}
|
|
941
948
|
|
|
942
949
|
// src/lib/output/unpack-dependencies.ts
|
|
943
|
-
import
|
|
950
|
+
import fs13 from "fs-extra";
|
|
944
951
|
import path17, { join as join2 } from "node:path";
|
|
945
952
|
async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, isolateDir) {
|
|
946
953
|
const log = useLogger();
|
|
@@ -951,8 +958,8 @@ async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, i
|
|
|
951
958
|
log.debug("Unpacking", `(temp)/${path17.basename(filePath)}`);
|
|
952
959
|
await unpack(filePath, unpackDir);
|
|
953
960
|
const destinationDir = join2(isolateDir, dir);
|
|
954
|
-
await
|
|
955
|
-
await
|
|
961
|
+
await fs13.ensureDir(destinationDir);
|
|
962
|
+
await fs13.move(join2(unpackDir, "package"), destinationDir, {
|
|
956
963
|
overwrite: true
|
|
957
964
|
});
|
|
958
965
|
log.debug(
|
|
@@ -966,12 +973,12 @@ async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, i
|
|
|
966
973
|
}
|
|
967
974
|
|
|
968
975
|
// src/lib/registry/create-packages-registry.ts
|
|
969
|
-
import
|
|
976
|
+
import fs14 from "fs-extra";
|
|
970
977
|
import { globSync } from "glob";
|
|
971
978
|
import path19 from "node:path";
|
|
972
979
|
|
|
973
980
|
// src/lib/registry/helpers/find-packages-globs.ts
|
|
974
|
-
import
|
|
981
|
+
import assert6 from "node:assert";
|
|
975
982
|
import path18 from "node:path";
|
|
976
983
|
function findPackagesGlobs(workspaceRootDir) {
|
|
977
984
|
const log = useLogger();
|
|
@@ -1003,7 +1010,7 @@ function findPackagesGlobs(workspaceRootDir) {
|
|
|
1003
1010
|
return workspaces;
|
|
1004
1011
|
} else {
|
|
1005
1012
|
const workspacesObject = workspaces;
|
|
1006
|
-
|
|
1013
|
+
assert6(
|
|
1007
1014
|
workspacesObject.packages,
|
|
1008
1015
|
"workspaces.packages must be an array"
|
|
1009
1016
|
);
|
|
@@ -1029,7 +1036,7 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
|
|
|
1029
1036
|
allPackages.map(async (rootRelativeDir) => {
|
|
1030
1037
|
const absoluteDir = path19.join(workspaceRootDir, rootRelativeDir);
|
|
1031
1038
|
const manifestPath = path19.join(absoluteDir, "package.json");
|
|
1032
|
-
if (!
|
|
1039
|
+
if (!fs14.existsSync(manifestPath)) {
|
|
1033
1040
|
log.warn(
|
|
1034
1041
|
`Ignoring directory ${rootRelativeDir} because it does not contain a package.json file`
|
|
1035
1042
|
);
|
|
@@ -1064,7 +1071,7 @@ function listWorkspacePackages(workspacePackagesOverride, workspaceRootDir) {
|
|
|
1064
1071
|
const currentDir = process.cwd();
|
|
1065
1072
|
process.chdir(workspaceRootDir);
|
|
1066
1073
|
const packagesGlobs = workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);
|
|
1067
|
-
const allPackages = packagesGlobs.flatMap((glob) => globSync(glob)).filter((dir) =>
|
|
1074
|
+
const allPackages = packagesGlobs.flatMap((glob) => globSync(glob)).filter((dir) => fs14.lstatSync(dir).isDirectory());
|
|
1068
1075
|
process.chdir(currentDir);
|
|
1069
1076
|
return allPackages;
|
|
1070
1077
|
}
|
|
@@ -1107,8 +1114,8 @@ async function isolate(options = {}) {
|
|
|
1107
1114
|
const targetPackageDir = config.targetPackagePath ? path20.join(process.cwd(), config.targetPackagePath) : process.cwd();
|
|
1108
1115
|
const workspaceRootDir = config.targetPackagePath ? process.cwd() : path20.join(targetPackageDir, config.workspaceRoot);
|
|
1109
1116
|
const buildOutputDir = await getBuildOutputDir(targetPackageDir);
|
|
1110
|
-
|
|
1111
|
-
|
|
1117
|
+
assert7(
|
|
1118
|
+
fs15.existsSync(buildOutputDir),
|
|
1112
1119
|
`Failed to find build output path at ${buildOutputDir}. Please make sure you build the source before isolating it.`
|
|
1113
1120
|
);
|
|
1114
1121
|
log.debug("Workspace root resolved to", workspaceRootDir);
|
|
@@ -1121,13 +1128,13 @@ async function isolate(options = {}) {
|
|
|
1121
1128
|
"Isolate output directory",
|
|
1122
1129
|
getRootRelativePath(isolateDir, workspaceRootDir)
|
|
1123
1130
|
);
|
|
1124
|
-
if (
|
|
1125
|
-
await
|
|
1131
|
+
if (fs15.existsSync(isolateDir)) {
|
|
1132
|
+
await fs15.remove(isolateDir);
|
|
1126
1133
|
log.debug("Cleaned the existing isolate output directory");
|
|
1127
1134
|
}
|
|
1128
|
-
await
|
|
1135
|
+
await fs15.ensureDir(isolateDir);
|
|
1129
1136
|
const tmpDir = path20.join(isolateDir, "__tmp");
|
|
1130
|
-
await
|
|
1137
|
+
await fs15.ensureDir(tmpDir);
|
|
1131
1138
|
const targetPackageManifest = await readTypedJson(
|
|
1132
1139
|
path20.join(targetPackageDir, "package.json")
|
|
1133
1140
|
);
|
|
@@ -1207,22 +1214,22 @@ async function isolate(options = {}) {
|
|
|
1207
1214
|
packages
|
|
1208
1215
|
});
|
|
1209
1216
|
} else {
|
|
1210
|
-
|
|
1217
|
+
fs15.copyFileSync(
|
|
1211
1218
|
path20.join(workspaceRootDir, "pnpm-workspace.yaml"),
|
|
1212
1219
|
path20.join(isolateDir, "pnpm-workspace.yaml")
|
|
1213
1220
|
);
|
|
1214
1221
|
}
|
|
1215
1222
|
}
|
|
1216
1223
|
const npmrcPath = path20.join(workspaceRootDir, ".npmrc");
|
|
1217
|
-
if (
|
|
1218
|
-
|
|
1224
|
+
if (fs15.existsSync(npmrcPath)) {
|
|
1225
|
+
fs15.copyFileSync(npmrcPath, path20.join(isolateDir, ".npmrc"));
|
|
1219
1226
|
log.debug("Copied .npmrc file to the isolate output");
|
|
1220
1227
|
}
|
|
1221
1228
|
log.debug(
|
|
1222
1229
|
"Deleting temp directory",
|
|
1223
1230
|
getRootRelativePath(tmpDir, workspaceRootDir)
|
|
1224
1231
|
);
|
|
1225
|
-
await
|
|
1232
|
+
await fs15.remove(tmpDir);
|
|
1226
1233
|
log.info("Isolate completed at", isolateDir);
|
|
1227
1234
|
return isolateDir;
|
|
1228
1235
|
}
|