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/isolate-bin.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import sourceMaps from "source-map-support";
|
|
|
7
7
|
// src/isolate.ts
|
|
8
8
|
import fs15 from "fs-extra";
|
|
9
9
|
import assert6 from "node:assert";
|
|
10
|
-
import
|
|
10
|
+
import path17 from "node:path";
|
|
11
11
|
|
|
12
12
|
// src/lib/config.ts
|
|
13
13
|
import fs5 from "fs-extra";
|
|
@@ -88,12 +88,12 @@ function toErrorWithMessage(maybeError) {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
// src/lib/utils/get-relative-path.ts
|
|
91
|
-
function getRootRelativePath(
|
|
92
|
-
const strippedPath =
|
|
91
|
+
function getRootRelativePath(path18, rootPath) {
|
|
92
|
+
const strippedPath = path18.replace(rootPath, "");
|
|
93
93
|
return strippedPath.startsWith("/") ? `(root)${strippedPath}` : `(root)/${strippedPath}`;
|
|
94
94
|
}
|
|
95
|
-
function getIsolateRelativePath(
|
|
96
|
-
const strippedPath =
|
|
95
|
+
function getIsolateRelativePath(path18, isolatePath) {
|
|
96
|
+
const strippedPath = path18.replace(isolatePath, "");
|
|
97
97
|
return strippedPath.startsWith("/") ? `(isolate)${strippedPath}` : `(isolate)/${strippedPath}`;
|
|
98
98
|
}
|
|
99
99
|
|
|
@@ -109,7 +109,9 @@ import stripJsonComments from "strip-json-comments";
|
|
|
109
109
|
function readTypedJsonSync(filePath) {
|
|
110
110
|
try {
|
|
111
111
|
const rawContent = fs.readFileSync(filePath, "utf-8");
|
|
112
|
-
const data = JSON.parse(
|
|
112
|
+
const data = JSON.parse(
|
|
113
|
+
stripJsonComments(rawContent, { trailingCommas: true })
|
|
114
|
+
);
|
|
113
115
|
return data;
|
|
114
116
|
} catch (err) {
|
|
115
117
|
throw new Error(
|
|
@@ -120,7 +122,9 @@ function readTypedJsonSync(filePath) {
|
|
|
120
122
|
async function readTypedJson(filePath) {
|
|
121
123
|
try {
|
|
122
124
|
const rawContent = await fs.readFile(filePath, "utf-8");
|
|
123
|
-
const data = JSON.parse(
|
|
125
|
+
const data = JSON.parse(
|
|
126
|
+
stripJsonComments(rawContent, { trailingCommas: true })
|
|
127
|
+
);
|
|
124
128
|
return data;
|
|
125
129
|
} catch (err) {
|
|
126
130
|
throw new Error(
|
|
@@ -458,7 +462,16 @@ async function generatePnpmLockfile({
|
|
|
458
462
|
}
|
|
459
463
|
)
|
|
460
464
|
);
|
|
461
|
-
await writeWantedLockfile(isolateDir,
|
|
465
|
+
await writeWantedLockfile(isolateDir, {
|
|
466
|
+
...lockfile,
|
|
467
|
+
/**
|
|
468
|
+
* Don't know how to map the patched dependencies yet, so we just include
|
|
469
|
+
* them but I don't think it would work like this. The important thing for
|
|
470
|
+
* now is that they are omitted by default, because that is the most
|
|
471
|
+
* common use case.
|
|
472
|
+
*/
|
|
473
|
+
patchedDependencies: includePatchedDependencies ? lockfile.patchedDependencies : void 0
|
|
474
|
+
});
|
|
462
475
|
log.debug("Created lockfile at", path6.join(isolateDir, "pnpm-lock.yaml"));
|
|
463
476
|
} catch (err) {
|
|
464
477
|
throw new Error(`Failed to generate lockfile: ${getErrorMessage(err)}`);
|
|
@@ -492,26 +505,13 @@ async function generateYarnLockfile({
|
|
|
492
505
|
}
|
|
493
506
|
|
|
494
507
|
// src/lib/lockfile/process-lockfile.ts
|
|
495
|
-
function pnpmMapImporter({
|
|
496
|
-
dependencies,
|
|
497
|
-
devDependencies,
|
|
498
|
-
patchedDependencies,
|
|
499
|
-
...rest
|
|
500
|
-
}, {
|
|
508
|
+
function pnpmMapImporter({ dependencies, devDependencies, ...rest }, {
|
|
501
509
|
includeDevDependencies,
|
|
502
|
-
includePatchedDependencies,
|
|
503
510
|
directoryByPackageName
|
|
504
511
|
}) {
|
|
505
512
|
return {
|
|
506
513
|
dependencies: dependencies ? pnpmMapDependenciesLinks(dependencies, directoryByPackageName) : void 0,
|
|
507
514
|
devDependencies: includeDevDependencies && devDependencies ? pnpmMapDependenciesLinks(devDependencies, directoryByPackageName) : void 0,
|
|
508
|
-
/**
|
|
509
|
-
* Don't know how to map the patched dependencies yet, so we just include
|
|
510
|
-
* them but I don't think it would work like this. The important thing for
|
|
511
|
-
* now is that they are omitted by default, because that is the most common
|
|
512
|
-
* use case.
|
|
513
|
-
*/
|
|
514
|
-
patchedDependencies: includePatchedDependencies ? patchedDependencies : void 0,
|
|
515
515
|
...rest
|
|
516
516
|
};
|
|
517
517
|
}
|
|
@@ -653,22 +653,25 @@ function adaptManifestInternalDeps({
|
|
|
653
653
|
// src/lib/manifest/helpers/adapt-internal-package-manifests.ts
|
|
654
654
|
async function adaptInternalPackageManifests(internalPackageNames, packagesRegistry, isolateDir) {
|
|
655
655
|
const packageManager2 = usePackageManager();
|
|
656
|
-
const {
|
|
656
|
+
const { forceNpm } = useConfig();
|
|
657
657
|
await Promise.all(
|
|
658
658
|
internalPackageNames.map(async (packageName) => {
|
|
659
659
|
const { manifest, rootRelativeDir } = packagesRegistry[packageName];
|
|
660
|
-
const
|
|
660
|
+
const strippedManifest = omit(manifest, ["scripts", "devDependencies"]);
|
|
661
661
|
const outputManifest = packageManager2.name === "pnpm" && !forceNpm ? (
|
|
662
662
|
/**
|
|
663
663
|
* For PNPM the output itself is a workspace so we can preserve the specifiers
|
|
664
664
|
* with "workspace:*" in the output manifest.
|
|
665
665
|
*/
|
|
666
|
-
|
|
667
|
-
) :
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
666
|
+
strippedManifest
|
|
667
|
+
) : (
|
|
668
|
+
/** For other package managers we replace the links to internal dependencies */
|
|
669
|
+
adaptManifestInternalDeps({
|
|
670
|
+
manifest: strippedManifest,
|
|
671
|
+
packagesRegistry,
|
|
672
|
+
parentRootRelativeDir: rootRelativeDir
|
|
673
|
+
})
|
|
674
|
+
);
|
|
672
675
|
await writeManifest(
|
|
673
676
|
path10.join(isolateDir, rootRelativeDir),
|
|
674
677
|
outputManifest
|
|
@@ -677,17 +680,41 @@ async function adaptInternalPackageManifests(internalPackageNames, packagesRegis
|
|
|
677
680
|
);
|
|
678
681
|
}
|
|
679
682
|
|
|
683
|
+
// src/lib/manifest/helpers/adopt-pnpm-fields-from-root.ts
|
|
684
|
+
import path11 from "path";
|
|
685
|
+
async function adoptPnpmFieldsFromRoot(targetPackageManifest, workspaceRootDir) {
|
|
686
|
+
const rootPackageManifest = await readTypedJson(
|
|
687
|
+
path11.join(workspaceRootDir, "package.json")
|
|
688
|
+
);
|
|
689
|
+
const overrides = rootPackageManifest.pnpm?.overrides;
|
|
690
|
+
if (!overrides) {
|
|
691
|
+
return targetPackageManifest;
|
|
692
|
+
}
|
|
693
|
+
return {
|
|
694
|
+
...targetPackageManifest,
|
|
695
|
+
pnpm: {
|
|
696
|
+
overrides
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
|
|
680
701
|
// src/lib/manifest/adapt-target-package-manifest.ts
|
|
681
|
-
async function adaptTargetPackageManifest(
|
|
702
|
+
async function adaptTargetPackageManifest({
|
|
703
|
+
manifest,
|
|
704
|
+
packagesRegistry,
|
|
705
|
+
isolateDir,
|
|
706
|
+
workspaceRootDir
|
|
707
|
+
}) {
|
|
682
708
|
const packageManager2 = usePackageManager();
|
|
683
709
|
const { includeDevDependencies, forceNpm, pickFromScripts, omitFromScripts } = useConfig();
|
|
684
710
|
const inputManifest = includeDevDependencies ? manifest : omit2(manifest, ["devDependencies"]);
|
|
685
711
|
const adaptedManifest = packageManager2.name === "pnpm" && !forceNpm ? (
|
|
686
712
|
/**
|
|
687
713
|
* For PNPM the output itself is a workspace so we can preserve the specifiers
|
|
688
|
-
* with "workspace:*" in the output manifest
|
|
714
|
+
* with "workspace:*" in the output manifest, but we do want to adopt the
|
|
715
|
+
* pnpm.overrides field from the root package.json.
|
|
689
716
|
*/
|
|
690
|
-
inputManifest
|
|
717
|
+
await adoptPnpmFieldsFromRoot(inputManifest, workspaceRootDir)
|
|
691
718
|
) : (
|
|
692
719
|
/** For other package managers we replace the links to internal dependencies */
|
|
693
720
|
adaptManifestInternalDeps({
|
|
@@ -708,22 +735,22 @@ async function adaptTargetPackageManifest(manifest, packagesRegistry, isolateDir
|
|
|
708
735
|
|
|
709
736
|
// src/lib/output/get-build-output-dir.ts
|
|
710
737
|
import fs11 from "fs-extra";
|
|
711
|
-
import
|
|
738
|
+
import path12 from "node:path";
|
|
712
739
|
import outdent from "outdent";
|
|
713
740
|
async function getBuildOutputDir(targetPackageDir) {
|
|
714
741
|
const config = useConfig();
|
|
715
742
|
const log = useLogger();
|
|
716
743
|
if (config.buildDirName) {
|
|
717
744
|
log.debug("Using buildDirName from config:", config.buildDirName);
|
|
718
|
-
return
|
|
745
|
+
return path12.join(targetPackageDir, config.buildDirName);
|
|
719
746
|
}
|
|
720
|
-
const tsconfigPath =
|
|
747
|
+
const tsconfigPath = path12.join(targetPackageDir, config.tsconfigPath);
|
|
721
748
|
if (fs11.existsSync(tsconfigPath)) {
|
|
722
749
|
log.debug("Found tsconfig at:", config.tsconfigPath);
|
|
723
750
|
const tsconfig = await readTypedJson(tsconfigPath);
|
|
724
751
|
const outDir = tsconfig.compilerOptions?.outDir;
|
|
725
752
|
if (outDir) {
|
|
726
|
-
return
|
|
753
|
+
return path12.join(targetPackageDir, outDir);
|
|
727
754
|
} else {
|
|
728
755
|
throw new Error(outdent`
|
|
729
756
|
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.
|
|
@@ -779,7 +806,7 @@ async function packDependencies({
|
|
|
779
806
|
|
|
780
807
|
// src/lib/output/process-build-output-files.ts
|
|
781
808
|
import fs12 from "fs-extra";
|
|
782
|
-
import
|
|
809
|
+
import path13 from "node:path";
|
|
783
810
|
var TIMEOUT_MS = 5e3;
|
|
784
811
|
async function processBuildOutputFiles({
|
|
785
812
|
targetPackageDir,
|
|
@@ -788,7 +815,7 @@ async function processBuildOutputFiles({
|
|
|
788
815
|
}) {
|
|
789
816
|
const log = useLogger();
|
|
790
817
|
const packedFilePath = await pack(targetPackageDir, tmpDir);
|
|
791
|
-
const unpackDir =
|
|
818
|
+
const unpackDir = path13.join(tmpDir, "target");
|
|
792
819
|
const now = Date.now();
|
|
793
820
|
let isWaitingYet = false;
|
|
794
821
|
while (!fs12.existsSync(packedFilePath) && Date.now() - now < TIMEOUT_MS) {
|
|
@@ -799,19 +826,19 @@ async function processBuildOutputFiles({
|
|
|
799
826
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
800
827
|
}
|
|
801
828
|
await unpack(packedFilePath, unpackDir);
|
|
802
|
-
await fs12.copy(
|
|
829
|
+
await fs12.copy(path13.join(unpackDir, "package"), isolateDir);
|
|
803
830
|
}
|
|
804
831
|
|
|
805
832
|
// src/lib/output/unpack-dependencies.ts
|
|
806
833
|
import fs13 from "fs-extra";
|
|
807
|
-
import
|
|
834
|
+
import path14, { join } from "node:path";
|
|
808
835
|
async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, isolateDir) {
|
|
809
836
|
const log = useLogger();
|
|
810
837
|
await Promise.all(
|
|
811
838
|
Object.entries(packedFilesByName).map(async ([packageName, filePath]) => {
|
|
812
839
|
const dir = packagesRegistry[packageName].rootRelativeDir;
|
|
813
840
|
const unpackDir = join(tmpDir, dir);
|
|
814
|
-
log.debug("Unpacking", `(temp)/${
|
|
841
|
+
log.debug("Unpacking", `(temp)/${path14.basename(filePath)}`);
|
|
815
842
|
await unpack(filePath, unpackDir);
|
|
816
843
|
const destinationDir = join(isolateDir, dir);
|
|
817
844
|
await fs13.ensureDir(destinationDir);
|
|
@@ -831,25 +858,25 @@ async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, i
|
|
|
831
858
|
// src/lib/registry/create-packages-registry.ts
|
|
832
859
|
import fs14 from "fs-extra";
|
|
833
860
|
import { globSync } from "glob";
|
|
834
|
-
import
|
|
861
|
+
import path16 from "node:path";
|
|
835
862
|
|
|
836
863
|
// src/lib/registry/helpers/find-packages-globs.ts
|
|
837
864
|
import assert5 from "node:assert";
|
|
838
|
-
import
|
|
865
|
+
import path15 from "node:path";
|
|
839
866
|
function findPackagesGlobs(workspaceRootDir) {
|
|
840
867
|
const log = useLogger();
|
|
841
868
|
const packageManager2 = usePackageManager();
|
|
842
869
|
switch (packageManager2.name) {
|
|
843
870
|
case "pnpm": {
|
|
844
871
|
const { packages: globs } = readTypedYamlSync(
|
|
845
|
-
|
|
872
|
+
path15.join(workspaceRootDir, "pnpm-workspace.yaml")
|
|
846
873
|
);
|
|
847
874
|
log.debug("Detected pnpm packages globs:", inspectValue(globs));
|
|
848
875
|
return globs;
|
|
849
876
|
}
|
|
850
877
|
case "yarn":
|
|
851
878
|
case "npm": {
|
|
852
|
-
const workspaceRootManifestPath =
|
|
879
|
+
const workspaceRootManifestPath = path15.join(
|
|
853
880
|
workspaceRootDir,
|
|
854
881
|
"package.json"
|
|
855
882
|
);
|
|
@@ -889,7 +916,7 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
|
|
|
889
916
|
const allPackages = packagesGlobs.flatMap((glob) => globSync(glob)).filter((dir) => fs14.lstatSync(dir).isDirectory());
|
|
890
917
|
const registry = (await Promise.all(
|
|
891
918
|
allPackages.map(async (rootRelativeDir) => {
|
|
892
|
-
const manifestPath =
|
|
919
|
+
const manifestPath = path16.join(rootRelativeDir, "package.json");
|
|
893
920
|
if (!fs14.existsSync(manifestPath)) {
|
|
894
921
|
log.warn(
|
|
895
922
|
`Ignoring directory ./${rootRelativeDir} because it does not contain a package.json file`
|
|
@@ -898,12 +925,12 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
|
|
|
898
925
|
} else {
|
|
899
926
|
log.debug(`Registering package ./${rootRelativeDir}`);
|
|
900
927
|
const manifest = await readTypedJson(
|
|
901
|
-
|
|
928
|
+
path16.join(rootRelativeDir, "package.json")
|
|
902
929
|
);
|
|
903
930
|
return {
|
|
904
931
|
manifest,
|
|
905
932
|
rootRelativeDir,
|
|
906
|
-
absoluteDir:
|
|
933
|
+
absoluteDir: path16.join(workspaceRootDir, rootRelativeDir)
|
|
907
934
|
};
|
|
908
935
|
}
|
|
909
936
|
})
|
|
@@ -948,11 +975,11 @@ async function isolate(options = {}) {
|
|
|
948
975
|
setLogLevel(config.logLevel);
|
|
949
976
|
const log = useLogger();
|
|
950
977
|
const thisPackageManifest = await readTypedJson(
|
|
951
|
-
|
|
978
|
+
path17.join(path17.join(__dirname, "..", "package.json"))
|
|
952
979
|
);
|
|
953
980
|
log.debug("Using isolate-package version", thisPackageManifest.version);
|
|
954
|
-
const targetPackageDir = config.targetPackagePath ?
|
|
955
|
-
const workspaceRootDir = config.targetPackagePath ? process.cwd() :
|
|
981
|
+
const targetPackageDir = config.targetPackagePath ? path17.join(process.cwd(), config.targetPackagePath) : process.cwd();
|
|
982
|
+
const workspaceRootDir = config.targetPackagePath ? process.cwd() : path17.join(targetPackageDir, config.workspaceRoot);
|
|
956
983
|
const buildOutputDir = await getBuildOutputDir(targetPackageDir);
|
|
957
984
|
assert6(
|
|
958
985
|
fs15.existsSync(buildOutputDir),
|
|
@@ -963,7 +990,7 @@ async function isolate(options = {}) {
|
|
|
963
990
|
"Isolate target package",
|
|
964
991
|
getRootRelativePath(targetPackageDir, workspaceRootDir)
|
|
965
992
|
);
|
|
966
|
-
const isolateDir =
|
|
993
|
+
const isolateDir = path17.join(targetPackageDir, config.isolateDirName);
|
|
967
994
|
log.debug(
|
|
968
995
|
"Isolate output directory",
|
|
969
996
|
getRootRelativePath(isolateDir, workspaceRootDir)
|
|
@@ -973,10 +1000,10 @@ async function isolate(options = {}) {
|
|
|
973
1000
|
log.debug("Cleaned the existing isolate output directory");
|
|
974
1001
|
}
|
|
975
1002
|
await fs15.ensureDir(isolateDir);
|
|
976
|
-
const tmpDir =
|
|
1003
|
+
const tmpDir = path17.join(isolateDir, "__tmp");
|
|
977
1004
|
await fs15.ensureDir(tmpDir);
|
|
978
1005
|
const targetPackageManifest = await readTypedJson(
|
|
979
|
-
|
|
1006
|
+
path17.join(targetPackageDir, "package.json")
|
|
980
1007
|
);
|
|
981
1008
|
const packageManager2 = detectPackageManager(workspaceRootDir);
|
|
982
1009
|
log.debug(
|
|
@@ -1016,11 +1043,12 @@ async function isolate(options = {}) {
|
|
|
1016
1043
|
tmpDir,
|
|
1017
1044
|
isolateDir
|
|
1018
1045
|
});
|
|
1019
|
-
await adaptTargetPackageManifest(
|
|
1020
|
-
targetPackageManifest,
|
|
1046
|
+
await adaptTargetPackageManifest({
|
|
1047
|
+
manifest: targetPackageManifest,
|
|
1021
1048
|
packagesRegistry,
|
|
1022
|
-
isolateDir
|
|
1023
|
-
|
|
1049
|
+
isolateDir,
|
|
1050
|
+
workspaceRootDir
|
|
1051
|
+
});
|
|
1024
1052
|
const usedFallbackToNpm = await processLockfile({
|
|
1025
1053
|
workspaceRootDir,
|
|
1026
1054
|
isolateDir,
|
|
@@ -1037,13 +1065,13 @@ async function isolate(options = {}) {
|
|
|
1037
1065
|
}
|
|
1038
1066
|
if (packageManager2.name === "pnpm" && !config.forceNpm) {
|
|
1039
1067
|
fs15.copyFileSync(
|
|
1040
|
-
|
|
1041
|
-
|
|
1068
|
+
path17.join(workspaceRootDir, "pnpm-workspace.yaml"),
|
|
1069
|
+
path17.join(isolateDir, "pnpm-workspace.yaml")
|
|
1042
1070
|
);
|
|
1043
1071
|
}
|
|
1044
|
-
const npmrcPath =
|
|
1072
|
+
const npmrcPath = path17.join(workspaceRootDir, ".npmrc");
|
|
1045
1073
|
if (fs15.existsSync(npmrcPath)) {
|
|
1046
|
-
fs15.copyFileSync(npmrcPath,
|
|
1074
|
+
fs15.copyFileSync(npmrcPath, path17.join(isolateDir, ".npmrc"));
|
|
1047
1075
|
log.debug("Copied .npmrc file to the isolate output");
|
|
1048
1076
|
}
|
|
1049
1077
|
log.debug(
|