isolate-package 1.10.0 → 1.11.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 +91 -63
- package/dist/index.mjs.map +1 -1
- package/dist/isolate-bin.mjs +91 -63
- package/dist/isolate-bin.mjs.map +1 -1
- package/package.json +14 -12
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/isolate.ts
|
|
2
2
|
import fs15 from "fs-extra";
|
|
3
3
|
import assert6 from "node:assert";
|
|
4
|
-
import
|
|
4
|
+
import path17 from "node:path";
|
|
5
5
|
|
|
6
6
|
// src/lib/config.ts
|
|
7
7
|
import fs5 from "fs-extra";
|
|
@@ -82,12 +82,12 @@ function toErrorWithMessage(maybeError) {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
// src/lib/utils/get-relative-path.ts
|
|
85
|
-
function getRootRelativePath(
|
|
86
|
-
const strippedPath =
|
|
85
|
+
function getRootRelativePath(path18, rootPath) {
|
|
86
|
+
const strippedPath = path18.replace(rootPath, "");
|
|
87
87
|
return strippedPath.startsWith("/") ? `(root)${strippedPath}` : `(root)/${strippedPath}`;
|
|
88
88
|
}
|
|
89
|
-
function getIsolateRelativePath(
|
|
90
|
-
const strippedPath =
|
|
89
|
+
function getIsolateRelativePath(path18, isolatePath) {
|
|
90
|
+
const strippedPath = path18.replace(isolatePath, "");
|
|
91
91
|
return strippedPath.startsWith("/") ? `(isolate)${strippedPath}` : `(isolate)/${strippedPath}`;
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -103,7 +103,9 @@ import stripJsonComments from "strip-json-comments";
|
|
|
103
103
|
function readTypedJsonSync(filePath) {
|
|
104
104
|
try {
|
|
105
105
|
const rawContent = fs.readFileSync(filePath, "utf-8");
|
|
106
|
-
const data = JSON.parse(
|
|
106
|
+
const data = JSON.parse(
|
|
107
|
+
stripJsonComments(rawContent, { trailingCommas: true })
|
|
108
|
+
);
|
|
107
109
|
return data;
|
|
108
110
|
} catch (err) {
|
|
109
111
|
throw new Error(
|
|
@@ -114,7 +116,9 @@ function readTypedJsonSync(filePath) {
|
|
|
114
116
|
async function readTypedJson(filePath) {
|
|
115
117
|
try {
|
|
116
118
|
const rawContent = await fs.readFile(filePath, "utf-8");
|
|
117
|
-
const data = JSON.parse(
|
|
119
|
+
const data = JSON.parse(
|
|
120
|
+
stripJsonComments(rawContent, { trailingCommas: true })
|
|
121
|
+
);
|
|
118
122
|
return data;
|
|
119
123
|
} catch (err) {
|
|
120
124
|
throw new Error(
|
|
@@ -452,7 +456,16 @@ async function generatePnpmLockfile({
|
|
|
452
456
|
}
|
|
453
457
|
)
|
|
454
458
|
);
|
|
455
|
-
await writeWantedLockfile(isolateDir,
|
|
459
|
+
await writeWantedLockfile(isolateDir, {
|
|
460
|
+
...lockfile,
|
|
461
|
+
/**
|
|
462
|
+
* Don't know how to map the patched dependencies yet, so we just include
|
|
463
|
+
* them but I don't think it would work like this. The important thing for
|
|
464
|
+
* now is that they are omitted by default, because that is the most
|
|
465
|
+
* common use case.
|
|
466
|
+
*/
|
|
467
|
+
patchedDependencies: includePatchedDependencies ? lockfile.patchedDependencies : void 0
|
|
468
|
+
});
|
|
456
469
|
log.debug("Created lockfile at", path6.join(isolateDir, "pnpm-lock.yaml"));
|
|
457
470
|
} catch (err) {
|
|
458
471
|
throw new Error(`Failed to generate lockfile: ${getErrorMessage(err)}`);
|
|
@@ -486,26 +499,13 @@ async function generateYarnLockfile({
|
|
|
486
499
|
}
|
|
487
500
|
|
|
488
501
|
// src/lib/lockfile/process-lockfile.ts
|
|
489
|
-
function pnpmMapImporter({
|
|
490
|
-
dependencies,
|
|
491
|
-
devDependencies,
|
|
492
|
-
patchedDependencies,
|
|
493
|
-
...rest
|
|
494
|
-
}, {
|
|
502
|
+
function pnpmMapImporter({ dependencies, devDependencies, ...rest }, {
|
|
495
503
|
includeDevDependencies,
|
|
496
|
-
includePatchedDependencies,
|
|
497
504
|
directoryByPackageName
|
|
498
505
|
}) {
|
|
499
506
|
return {
|
|
500
507
|
dependencies: dependencies ? pnpmMapDependenciesLinks(dependencies, directoryByPackageName) : void 0,
|
|
501
508
|
devDependencies: includeDevDependencies && devDependencies ? pnpmMapDependenciesLinks(devDependencies, directoryByPackageName) : void 0,
|
|
502
|
-
/**
|
|
503
|
-
* Don't know how to map the patched dependencies yet, so we just include
|
|
504
|
-
* them but I don't think it would work like this. The important thing for
|
|
505
|
-
* now is that they are omitted by default, because that is the most common
|
|
506
|
-
* use case.
|
|
507
|
-
*/
|
|
508
|
-
patchedDependencies: includePatchedDependencies ? patchedDependencies : void 0,
|
|
509
509
|
...rest
|
|
510
510
|
};
|
|
511
511
|
}
|
|
@@ -647,22 +647,25 @@ function adaptManifestInternalDeps({
|
|
|
647
647
|
// src/lib/manifest/helpers/adapt-internal-package-manifests.ts
|
|
648
648
|
async function adaptInternalPackageManifests(internalPackageNames, packagesRegistry, isolateDir) {
|
|
649
649
|
const packageManager2 = usePackageManager();
|
|
650
|
-
const {
|
|
650
|
+
const { forceNpm } = useConfig();
|
|
651
651
|
await Promise.all(
|
|
652
652
|
internalPackageNames.map(async (packageName) => {
|
|
653
653
|
const { manifest, rootRelativeDir } = packagesRegistry[packageName];
|
|
654
|
-
const
|
|
654
|
+
const strippedManifest = omit(manifest, ["scripts", "devDependencies"]);
|
|
655
655
|
const outputManifest = packageManager2.name === "pnpm" && !forceNpm ? (
|
|
656
656
|
/**
|
|
657
657
|
* For PNPM the output itself is a workspace so we can preserve the specifiers
|
|
658
658
|
* with "workspace:*" in the output manifest.
|
|
659
659
|
*/
|
|
660
|
-
|
|
661
|
-
) :
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
660
|
+
strippedManifest
|
|
661
|
+
) : (
|
|
662
|
+
/** For other package managers we replace the links to internal dependencies */
|
|
663
|
+
adaptManifestInternalDeps({
|
|
664
|
+
manifest: strippedManifest,
|
|
665
|
+
packagesRegistry,
|
|
666
|
+
parentRootRelativeDir: rootRelativeDir
|
|
667
|
+
})
|
|
668
|
+
);
|
|
666
669
|
await writeManifest(
|
|
667
670
|
path10.join(isolateDir, rootRelativeDir),
|
|
668
671
|
outputManifest
|
|
@@ -671,17 +674,41 @@ async function adaptInternalPackageManifests(internalPackageNames, packagesRegis
|
|
|
671
674
|
);
|
|
672
675
|
}
|
|
673
676
|
|
|
677
|
+
// src/lib/manifest/helpers/adopt-pnpm-fields-from-root.ts
|
|
678
|
+
import path11 from "path";
|
|
679
|
+
async function adoptPnpmFieldsFromRoot(targetPackageManifest, workspaceRootDir) {
|
|
680
|
+
const rootPackageManifest = await readTypedJson(
|
|
681
|
+
path11.join(workspaceRootDir, "package.json")
|
|
682
|
+
);
|
|
683
|
+
const overrides = rootPackageManifest.pnpm?.overrides;
|
|
684
|
+
if (!overrides) {
|
|
685
|
+
return targetPackageManifest;
|
|
686
|
+
}
|
|
687
|
+
return {
|
|
688
|
+
...targetPackageManifest,
|
|
689
|
+
pnpm: {
|
|
690
|
+
overrides
|
|
691
|
+
}
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
|
|
674
695
|
// src/lib/manifest/adapt-target-package-manifest.ts
|
|
675
|
-
async function adaptTargetPackageManifest(
|
|
696
|
+
async function adaptTargetPackageManifest({
|
|
697
|
+
manifest,
|
|
698
|
+
packagesRegistry,
|
|
699
|
+
isolateDir,
|
|
700
|
+
workspaceRootDir
|
|
701
|
+
}) {
|
|
676
702
|
const packageManager2 = usePackageManager();
|
|
677
703
|
const { includeDevDependencies, forceNpm, pickFromScripts, omitFromScripts } = useConfig();
|
|
678
704
|
const inputManifest = includeDevDependencies ? manifest : omit2(manifest, ["devDependencies"]);
|
|
679
705
|
const adaptedManifest = packageManager2.name === "pnpm" && !forceNpm ? (
|
|
680
706
|
/**
|
|
681
707
|
* For PNPM the output itself is a workspace so we can preserve the specifiers
|
|
682
|
-
* with "workspace:*" in the output manifest
|
|
708
|
+
* with "workspace:*" in the output manifest, but we do want to adopt the
|
|
709
|
+
* pnpm.overrides field from the root package.json.
|
|
683
710
|
*/
|
|
684
|
-
inputManifest
|
|
711
|
+
await adoptPnpmFieldsFromRoot(inputManifest, workspaceRootDir)
|
|
685
712
|
) : (
|
|
686
713
|
/** For other package managers we replace the links to internal dependencies */
|
|
687
714
|
adaptManifestInternalDeps({
|
|
@@ -702,22 +729,22 @@ async function adaptTargetPackageManifest(manifest, packagesRegistry, isolateDir
|
|
|
702
729
|
|
|
703
730
|
// src/lib/output/get-build-output-dir.ts
|
|
704
731
|
import fs11 from "fs-extra";
|
|
705
|
-
import
|
|
732
|
+
import path12 from "node:path";
|
|
706
733
|
import outdent from "outdent";
|
|
707
734
|
async function getBuildOutputDir(targetPackageDir) {
|
|
708
735
|
const config = useConfig();
|
|
709
736
|
const log = useLogger();
|
|
710
737
|
if (config.buildDirName) {
|
|
711
738
|
log.debug("Using buildDirName from config:", config.buildDirName);
|
|
712
|
-
return
|
|
739
|
+
return path12.join(targetPackageDir, config.buildDirName);
|
|
713
740
|
}
|
|
714
|
-
const tsconfigPath =
|
|
741
|
+
const tsconfigPath = path12.join(targetPackageDir, config.tsconfigPath);
|
|
715
742
|
if (fs11.existsSync(tsconfigPath)) {
|
|
716
743
|
log.debug("Found tsconfig at:", config.tsconfigPath);
|
|
717
744
|
const tsconfig = await readTypedJson(tsconfigPath);
|
|
718
745
|
const outDir = tsconfig.compilerOptions?.outDir;
|
|
719
746
|
if (outDir) {
|
|
720
|
-
return
|
|
747
|
+
return path12.join(targetPackageDir, outDir);
|
|
721
748
|
} else {
|
|
722
749
|
throw new Error(outdent`
|
|
723
750
|
Failed to find outDir in tsconfig. If you are executing isolate from the root of a monorepo you should specify the buildDirName in isolate.config.json.
|
|
@@ -773,7 +800,7 @@ async function packDependencies({
|
|
|
773
800
|
|
|
774
801
|
// src/lib/output/process-build-output-files.ts
|
|
775
802
|
import fs12 from "fs-extra";
|
|
776
|
-
import
|
|
803
|
+
import path13 from "node:path";
|
|
777
804
|
var TIMEOUT_MS = 5e3;
|
|
778
805
|
async function processBuildOutputFiles({
|
|
779
806
|
targetPackageDir,
|
|
@@ -782,7 +809,7 @@ async function processBuildOutputFiles({
|
|
|
782
809
|
}) {
|
|
783
810
|
const log = useLogger();
|
|
784
811
|
const packedFilePath = await pack(targetPackageDir, tmpDir);
|
|
785
|
-
const unpackDir =
|
|
812
|
+
const unpackDir = path13.join(tmpDir, "target");
|
|
786
813
|
const now = Date.now();
|
|
787
814
|
let isWaitingYet = false;
|
|
788
815
|
while (!fs12.existsSync(packedFilePath) && Date.now() - now < TIMEOUT_MS) {
|
|
@@ -793,19 +820,19 @@ async function processBuildOutputFiles({
|
|
|
793
820
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
794
821
|
}
|
|
795
822
|
await unpack(packedFilePath, unpackDir);
|
|
796
|
-
await fs12.copy(
|
|
823
|
+
await fs12.copy(path13.join(unpackDir, "package"), isolateDir);
|
|
797
824
|
}
|
|
798
825
|
|
|
799
826
|
// src/lib/output/unpack-dependencies.ts
|
|
800
827
|
import fs13 from "fs-extra";
|
|
801
|
-
import
|
|
828
|
+
import path14, { join } from "node:path";
|
|
802
829
|
async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, isolateDir) {
|
|
803
830
|
const log = useLogger();
|
|
804
831
|
await Promise.all(
|
|
805
832
|
Object.entries(packedFilesByName).map(async ([packageName, filePath]) => {
|
|
806
833
|
const dir = packagesRegistry[packageName].rootRelativeDir;
|
|
807
834
|
const unpackDir = join(tmpDir, dir);
|
|
808
|
-
log.debug("Unpacking", `(temp)/${
|
|
835
|
+
log.debug("Unpacking", `(temp)/${path14.basename(filePath)}`);
|
|
809
836
|
await unpack(filePath, unpackDir);
|
|
810
837
|
const destinationDir = join(isolateDir, dir);
|
|
811
838
|
await fs13.ensureDir(destinationDir);
|
|
@@ -825,25 +852,25 @@ async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, i
|
|
|
825
852
|
// src/lib/registry/create-packages-registry.ts
|
|
826
853
|
import fs14 from "fs-extra";
|
|
827
854
|
import { globSync } from "glob";
|
|
828
|
-
import
|
|
855
|
+
import path16 from "node:path";
|
|
829
856
|
|
|
830
857
|
// src/lib/registry/helpers/find-packages-globs.ts
|
|
831
858
|
import assert5 from "node:assert";
|
|
832
|
-
import
|
|
859
|
+
import path15 from "node:path";
|
|
833
860
|
function findPackagesGlobs(workspaceRootDir) {
|
|
834
861
|
const log = useLogger();
|
|
835
862
|
const packageManager2 = usePackageManager();
|
|
836
863
|
switch (packageManager2.name) {
|
|
837
864
|
case "pnpm": {
|
|
838
865
|
const { packages: globs } = readTypedYamlSync(
|
|
839
|
-
|
|
866
|
+
path15.join(workspaceRootDir, "pnpm-workspace.yaml")
|
|
840
867
|
);
|
|
841
868
|
log.debug("Detected pnpm packages globs:", inspectValue(globs));
|
|
842
869
|
return globs;
|
|
843
870
|
}
|
|
844
871
|
case "yarn":
|
|
845
872
|
case "npm": {
|
|
846
|
-
const workspaceRootManifestPath =
|
|
873
|
+
const workspaceRootManifestPath = path15.join(
|
|
847
874
|
workspaceRootDir,
|
|
848
875
|
"package.json"
|
|
849
876
|
);
|
|
@@ -883,7 +910,7 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
|
|
|
883
910
|
const allPackages = packagesGlobs.flatMap((glob) => globSync(glob)).filter((dir) => fs14.lstatSync(dir).isDirectory());
|
|
884
911
|
const registry = (await Promise.all(
|
|
885
912
|
allPackages.map(async (rootRelativeDir) => {
|
|
886
|
-
const manifestPath =
|
|
913
|
+
const manifestPath = path16.join(rootRelativeDir, "package.json");
|
|
887
914
|
if (!fs14.existsSync(manifestPath)) {
|
|
888
915
|
log.warn(
|
|
889
916
|
`Ignoring directory ./${rootRelativeDir} because it does not contain a package.json file`
|
|
@@ -892,12 +919,12 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
|
|
|
892
919
|
} else {
|
|
893
920
|
log.debug(`Registering package ./${rootRelativeDir}`);
|
|
894
921
|
const manifest = await readTypedJson(
|
|
895
|
-
|
|
922
|
+
path16.join(rootRelativeDir, "package.json")
|
|
896
923
|
);
|
|
897
924
|
return {
|
|
898
925
|
manifest,
|
|
899
926
|
rootRelativeDir,
|
|
900
|
-
absoluteDir:
|
|
927
|
+
absoluteDir: path16.join(workspaceRootDir, rootRelativeDir)
|
|
901
928
|
};
|
|
902
929
|
}
|
|
903
930
|
})
|
|
@@ -942,11 +969,11 @@ async function isolate(options = {}) {
|
|
|
942
969
|
setLogLevel(config.logLevel);
|
|
943
970
|
const log = useLogger();
|
|
944
971
|
const thisPackageManifest = await readTypedJson(
|
|
945
|
-
|
|
972
|
+
path17.join(path17.join(__dirname, "..", "package.json"))
|
|
946
973
|
);
|
|
947
974
|
log.debug("Using isolate-package version", thisPackageManifest.version);
|
|
948
|
-
const targetPackageDir = config.targetPackagePath ?
|
|
949
|
-
const workspaceRootDir = config.targetPackagePath ? process.cwd() :
|
|
975
|
+
const targetPackageDir = config.targetPackagePath ? path17.join(process.cwd(), config.targetPackagePath) : process.cwd();
|
|
976
|
+
const workspaceRootDir = config.targetPackagePath ? process.cwd() : path17.join(targetPackageDir, config.workspaceRoot);
|
|
950
977
|
const buildOutputDir = await getBuildOutputDir(targetPackageDir);
|
|
951
978
|
assert6(
|
|
952
979
|
fs15.existsSync(buildOutputDir),
|
|
@@ -957,7 +984,7 @@ async function isolate(options = {}) {
|
|
|
957
984
|
"Isolate target package",
|
|
958
985
|
getRootRelativePath(targetPackageDir, workspaceRootDir)
|
|
959
986
|
);
|
|
960
|
-
const isolateDir =
|
|
987
|
+
const isolateDir = path17.join(targetPackageDir, config.isolateDirName);
|
|
961
988
|
log.debug(
|
|
962
989
|
"Isolate output directory",
|
|
963
990
|
getRootRelativePath(isolateDir, workspaceRootDir)
|
|
@@ -967,10 +994,10 @@ async function isolate(options = {}) {
|
|
|
967
994
|
log.debug("Cleaned the existing isolate output directory");
|
|
968
995
|
}
|
|
969
996
|
await fs15.ensureDir(isolateDir);
|
|
970
|
-
const tmpDir =
|
|
997
|
+
const tmpDir = path17.join(isolateDir, "__tmp");
|
|
971
998
|
await fs15.ensureDir(tmpDir);
|
|
972
999
|
const targetPackageManifest = await readTypedJson(
|
|
973
|
-
|
|
1000
|
+
path17.join(targetPackageDir, "package.json")
|
|
974
1001
|
);
|
|
975
1002
|
const packageManager2 = detectPackageManager(workspaceRootDir);
|
|
976
1003
|
log.debug(
|
|
@@ -1010,11 +1037,12 @@ async function isolate(options = {}) {
|
|
|
1010
1037
|
tmpDir,
|
|
1011
1038
|
isolateDir
|
|
1012
1039
|
});
|
|
1013
|
-
await adaptTargetPackageManifest(
|
|
1014
|
-
targetPackageManifest,
|
|
1040
|
+
await adaptTargetPackageManifest({
|
|
1041
|
+
manifest: targetPackageManifest,
|
|
1015
1042
|
packagesRegistry,
|
|
1016
|
-
isolateDir
|
|
1017
|
-
|
|
1043
|
+
isolateDir,
|
|
1044
|
+
workspaceRootDir
|
|
1045
|
+
});
|
|
1018
1046
|
const usedFallbackToNpm = await processLockfile({
|
|
1019
1047
|
workspaceRootDir,
|
|
1020
1048
|
isolateDir,
|
|
@@ -1031,13 +1059,13 @@ async function isolate(options = {}) {
|
|
|
1031
1059
|
}
|
|
1032
1060
|
if (packageManager2.name === "pnpm" && !config.forceNpm) {
|
|
1033
1061
|
fs15.copyFileSync(
|
|
1034
|
-
|
|
1035
|
-
|
|
1062
|
+
path17.join(workspaceRootDir, "pnpm-workspace.yaml"),
|
|
1063
|
+
path17.join(isolateDir, "pnpm-workspace.yaml")
|
|
1036
1064
|
);
|
|
1037
1065
|
}
|
|
1038
|
-
const npmrcPath =
|
|
1066
|
+
const npmrcPath = path17.join(workspaceRootDir, ".npmrc");
|
|
1039
1067
|
if (fs15.existsSync(npmrcPath)) {
|
|
1040
|
-
fs15.copyFileSync(npmrcPath,
|
|
1068
|
+
fs15.copyFileSync(npmrcPath, path17.join(isolateDir, ".npmrc"));
|
|
1041
1069
|
log.debug("Copied .npmrc file to the isolate output");
|
|
1042
1070
|
}
|
|
1043
1071
|
log.debug(
|