isolate-package 1.10.1 → 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 +72 -43
- package/dist/index.mjs.map +1 -1
- package/dist/isolate-bin.mjs +72 -43
- package/dist/isolate-bin.mjs.map +1 -1
- package/package.json +5 -2
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(
|
|
@@ -653,17 +657,17 @@ async function adaptInternalPackageManifests(internalPackageNames, packagesRegis
|
|
|
653
657
|
await Promise.all(
|
|
654
658
|
internalPackageNames.map(async (packageName) => {
|
|
655
659
|
const { manifest, rootRelativeDir } = packagesRegistry[packageName];
|
|
656
|
-
const
|
|
660
|
+
const strippedManifest = omit(manifest, ["scripts", "devDependencies"]);
|
|
657
661
|
const outputManifest = packageManager2.name === "pnpm" && !forceNpm ? (
|
|
658
662
|
/**
|
|
659
663
|
* For PNPM the output itself is a workspace so we can preserve the specifiers
|
|
660
664
|
* with "workspace:*" in the output manifest.
|
|
661
665
|
*/
|
|
662
|
-
|
|
666
|
+
strippedManifest
|
|
663
667
|
) : (
|
|
664
668
|
/** For other package managers we replace the links to internal dependencies */
|
|
665
669
|
adaptManifestInternalDeps({
|
|
666
|
-
manifest:
|
|
670
|
+
manifest: strippedManifest,
|
|
667
671
|
packagesRegistry,
|
|
668
672
|
parentRootRelativeDir: rootRelativeDir
|
|
669
673
|
})
|
|
@@ -676,17 +680,41 @@ async function adaptInternalPackageManifests(internalPackageNames, packagesRegis
|
|
|
676
680
|
);
|
|
677
681
|
}
|
|
678
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
|
+
|
|
679
701
|
// src/lib/manifest/adapt-target-package-manifest.ts
|
|
680
|
-
async function adaptTargetPackageManifest(
|
|
702
|
+
async function adaptTargetPackageManifest({
|
|
703
|
+
manifest,
|
|
704
|
+
packagesRegistry,
|
|
705
|
+
isolateDir,
|
|
706
|
+
workspaceRootDir
|
|
707
|
+
}) {
|
|
681
708
|
const packageManager2 = usePackageManager();
|
|
682
709
|
const { includeDevDependencies, forceNpm, pickFromScripts, omitFromScripts } = useConfig();
|
|
683
710
|
const inputManifest = includeDevDependencies ? manifest : omit2(manifest, ["devDependencies"]);
|
|
684
711
|
const adaptedManifest = packageManager2.name === "pnpm" && !forceNpm ? (
|
|
685
712
|
/**
|
|
686
713
|
* For PNPM the output itself is a workspace so we can preserve the specifiers
|
|
687
|
-
* 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.
|
|
688
716
|
*/
|
|
689
|
-
inputManifest
|
|
717
|
+
await adoptPnpmFieldsFromRoot(inputManifest, workspaceRootDir)
|
|
690
718
|
) : (
|
|
691
719
|
/** For other package managers we replace the links to internal dependencies */
|
|
692
720
|
adaptManifestInternalDeps({
|
|
@@ -707,22 +735,22 @@ async function adaptTargetPackageManifest(manifest, packagesRegistry, isolateDir
|
|
|
707
735
|
|
|
708
736
|
// src/lib/output/get-build-output-dir.ts
|
|
709
737
|
import fs11 from "fs-extra";
|
|
710
|
-
import
|
|
738
|
+
import path12 from "node:path";
|
|
711
739
|
import outdent from "outdent";
|
|
712
740
|
async function getBuildOutputDir(targetPackageDir) {
|
|
713
741
|
const config = useConfig();
|
|
714
742
|
const log = useLogger();
|
|
715
743
|
if (config.buildDirName) {
|
|
716
744
|
log.debug("Using buildDirName from config:", config.buildDirName);
|
|
717
|
-
return
|
|
745
|
+
return path12.join(targetPackageDir, config.buildDirName);
|
|
718
746
|
}
|
|
719
|
-
const tsconfigPath =
|
|
747
|
+
const tsconfigPath = path12.join(targetPackageDir, config.tsconfigPath);
|
|
720
748
|
if (fs11.existsSync(tsconfigPath)) {
|
|
721
749
|
log.debug("Found tsconfig at:", config.tsconfigPath);
|
|
722
750
|
const tsconfig = await readTypedJson(tsconfigPath);
|
|
723
751
|
const outDir = tsconfig.compilerOptions?.outDir;
|
|
724
752
|
if (outDir) {
|
|
725
|
-
return
|
|
753
|
+
return path12.join(targetPackageDir, outDir);
|
|
726
754
|
} else {
|
|
727
755
|
throw new Error(outdent`
|
|
728
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.
|
|
@@ -778,7 +806,7 @@ async function packDependencies({
|
|
|
778
806
|
|
|
779
807
|
// src/lib/output/process-build-output-files.ts
|
|
780
808
|
import fs12 from "fs-extra";
|
|
781
|
-
import
|
|
809
|
+
import path13 from "node:path";
|
|
782
810
|
var TIMEOUT_MS = 5e3;
|
|
783
811
|
async function processBuildOutputFiles({
|
|
784
812
|
targetPackageDir,
|
|
@@ -787,7 +815,7 @@ async function processBuildOutputFiles({
|
|
|
787
815
|
}) {
|
|
788
816
|
const log = useLogger();
|
|
789
817
|
const packedFilePath = await pack(targetPackageDir, tmpDir);
|
|
790
|
-
const unpackDir =
|
|
818
|
+
const unpackDir = path13.join(tmpDir, "target");
|
|
791
819
|
const now = Date.now();
|
|
792
820
|
let isWaitingYet = false;
|
|
793
821
|
while (!fs12.existsSync(packedFilePath) && Date.now() - now < TIMEOUT_MS) {
|
|
@@ -798,19 +826,19 @@ async function processBuildOutputFiles({
|
|
|
798
826
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
799
827
|
}
|
|
800
828
|
await unpack(packedFilePath, unpackDir);
|
|
801
|
-
await fs12.copy(
|
|
829
|
+
await fs12.copy(path13.join(unpackDir, "package"), isolateDir);
|
|
802
830
|
}
|
|
803
831
|
|
|
804
832
|
// src/lib/output/unpack-dependencies.ts
|
|
805
833
|
import fs13 from "fs-extra";
|
|
806
|
-
import
|
|
834
|
+
import path14, { join } from "node:path";
|
|
807
835
|
async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, isolateDir) {
|
|
808
836
|
const log = useLogger();
|
|
809
837
|
await Promise.all(
|
|
810
838
|
Object.entries(packedFilesByName).map(async ([packageName, filePath]) => {
|
|
811
839
|
const dir = packagesRegistry[packageName].rootRelativeDir;
|
|
812
840
|
const unpackDir = join(tmpDir, dir);
|
|
813
|
-
log.debug("Unpacking", `(temp)/${
|
|
841
|
+
log.debug("Unpacking", `(temp)/${path14.basename(filePath)}`);
|
|
814
842
|
await unpack(filePath, unpackDir);
|
|
815
843
|
const destinationDir = join(isolateDir, dir);
|
|
816
844
|
await fs13.ensureDir(destinationDir);
|
|
@@ -830,25 +858,25 @@ async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, i
|
|
|
830
858
|
// src/lib/registry/create-packages-registry.ts
|
|
831
859
|
import fs14 from "fs-extra";
|
|
832
860
|
import { globSync } from "glob";
|
|
833
|
-
import
|
|
861
|
+
import path16 from "node:path";
|
|
834
862
|
|
|
835
863
|
// src/lib/registry/helpers/find-packages-globs.ts
|
|
836
864
|
import assert5 from "node:assert";
|
|
837
|
-
import
|
|
865
|
+
import path15 from "node:path";
|
|
838
866
|
function findPackagesGlobs(workspaceRootDir) {
|
|
839
867
|
const log = useLogger();
|
|
840
868
|
const packageManager2 = usePackageManager();
|
|
841
869
|
switch (packageManager2.name) {
|
|
842
870
|
case "pnpm": {
|
|
843
871
|
const { packages: globs } = readTypedYamlSync(
|
|
844
|
-
|
|
872
|
+
path15.join(workspaceRootDir, "pnpm-workspace.yaml")
|
|
845
873
|
);
|
|
846
874
|
log.debug("Detected pnpm packages globs:", inspectValue(globs));
|
|
847
875
|
return globs;
|
|
848
876
|
}
|
|
849
877
|
case "yarn":
|
|
850
878
|
case "npm": {
|
|
851
|
-
const workspaceRootManifestPath =
|
|
879
|
+
const workspaceRootManifestPath = path15.join(
|
|
852
880
|
workspaceRootDir,
|
|
853
881
|
"package.json"
|
|
854
882
|
);
|
|
@@ -888,7 +916,7 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
|
|
|
888
916
|
const allPackages = packagesGlobs.flatMap((glob) => globSync(glob)).filter((dir) => fs14.lstatSync(dir).isDirectory());
|
|
889
917
|
const registry = (await Promise.all(
|
|
890
918
|
allPackages.map(async (rootRelativeDir) => {
|
|
891
|
-
const manifestPath =
|
|
919
|
+
const manifestPath = path16.join(rootRelativeDir, "package.json");
|
|
892
920
|
if (!fs14.existsSync(manifestPath)) {
|
|
893
921
|
log.warn(
|
|
894
922
|
`Ignoring directory ./${rootRelativeDir} because it does not contain a package.json file`
|
|
@@ -897,12 +925,12 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
|
|
|
897
925
|
} else {
|
|
898
926
|
log.debug(`Registering package ./${rootRelativeDir}`);
|
|
899
927
|
const manifest = await readTypedJson(
|
|
900
|
-
|
|
928
|
+
path16.join(rootRelativeDir, "package.json")
|
|
901
929
|
);
|
|
902
930
|
return {
|
|
903
931
|
manifest,
|
|
904
932
|
rootRelativeDir,
|
|
905
|
-
absoluteDir:
|
|
933
|
+
absoluteDir: path16.join(workspaceRootDir, rootRelativeDir)
|
|
906
934
|
};
|
|
907
935
|
}
|
|
908
936
|
})
|
|
@@ -947,11 +975,11 @@ async function isolate(options = {}) {
|
|
|
947
975
|
setLogLevel(config.logLevel);
|
|
948
976
|
const log = useLogger();
|
|
949
977
|
const thisPackageManifest = await readTypedJson(
|
|
950
|
-
|
|
978
|
+
path17.join(path17.join(__dirname, "..", "package.json"))
|
|
951
979
|
);
|
|
952
980
|
log.debug("Using isolate-package version", thisPackageManifest.version);
|
|
953
|
-
const targetPackageDir = config.targetPackagePath ?
|
|
954
|
-
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);
|
|
955
983
|
const buildOutputDir = await getBuildOutputDir(targetPackageDir);
|
|
956
984
|
assert6(
|
|
957
985
|
fs15.existsSync(buildOutputDir),
|
|
@@ -962,7 +990,7 @@ async function isolate(options = {}) {
|
|
|
962
990
|
"Isolate target package",
|
|
963
991
|
getRootRelativePath(targetPackageDir, workspaceRootDir)
|
|
964
992
|
);
|
|
965
|
-
const isolateDir =
|
|
993
|
+
const isolateDir = path17.join(targetPackageDir, config.isolateDirName);
|
|
966
994
|
log.debug(
|
|
967
995
|
"Isolate output directory",
|
|
968
996
|
getRootRelativePath(isolateDir, workspaceRootDir)
|
|
@@ -972,10 +1000,10 @@ async function isolate(options = {}) {
|
|
|
972
1000
|
log.debug("Cleaned the existing isolate output directory");
|
|
973
1001
|
}
|
|
974
1002
|
await fs15.ensureDir(isolateDir);
|
|
975
|
-
const tmpDir =
|
|
1003
|
+
const tmpDir = path17.join(isolateDir, "__tmp");
|
|
976
1004
|
await fs15.ensureDir(tmpDir);
|
|
977
1005
|
const targetPackageManifest = await readTypedJson(
|
|
978
|
-
|
|
1006
|
+
path17.join(targetPackageDir, "package.json")
|
|
979
1007
|
);
|
|
980
1008
|
const packageManager2 = detectPackageManager(workspaceRootDir);
|
|
981
1009
|
log.debug(
|
|
@@ -1015,11 +1043,12 @@ async function isolate(options = {}) {
|
|
|
1015
1043
|
tmpDir,
|
|
1016
1044
|
isolateDir
|
|
1017
1045
|
});
|
|
1018
|
-
await adaptTargetPackageManifest(
|
|
1019
|
-
targetPackageManifest,
|
|
1046
|
+
await adaptTargetPackageManifest({
|
|
1047
|
+
manifest: targetPackageManifest,
|
|
1020
1048
|
packagesRegistry,
|
|
1021
|
-
isolateDir
|
|
1022
|
-
|
|
1049
|
+
isolateDir,
|
|
1050
|
+
workspaceRootDir
|
|
1051
|
+
});
|
|
1023
1052
|
const usedFallbackToNpm = await processLockfile({
|
|
1024
1053
|
workspaceRootDir,
|
|
1025
1054
|
isolateDir,
|
|
@@ -1036,13 +1065,13 @@ async function isolate(options = {}) {
|
|
|
1036
1065
|
}
|
|
1037
1066
|
if (packageManager2.name === "pnpm" && !config.forceNpm) {
|
|
1038
1067
|
fs15.copyFileSync(
|
|
1039
|
-
|
|
1040
|
-
|
|
1068
|
+
path17.join(workspaceRootDir, "pnpm-workspace.yaml"),
|
|
1069
|
+
path17.join(isolateDir, "pnpm-workspace.yaml")
|
|
1041
1070
|
);
|
|
1042
1071
|
}
|
|
1043
|
-
const npmrcPath =
|
|
1072
|
+
const npmrcPath = path17.join(workspaceRootDir, ".npmrc");
|
|
1044
1073
|
if (fs15.existsSync(npmrcPath)) {
|
|
1045
|
-
fs15.copyFileSync(npmrcPath,
|
|
1074
|
+
fs15.copyFileSync(npmrcPath, path17.join(isolateDir, ".npmrc"));
|
|
1046
1075
|
log.debug("Copied .npmrc file to the isolate output");
|
|
1047
1076
|
}
|
|
1048
1077
|
log.debug(
|