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.
@@ -5,14 +5,14 @@ import console2 from "node:console";
5
5
  import sourceMaps from "source-map-support";
6
6
 
7
7
  // src/isolate.ts
8
- import fs16 from "fs-extra";
9
- import assert6 from "node:assert";
8
+ import fs15 from "fs-extra";
9
+ import assert7 from "node:assert";
10
10
  import path20 from "node:path";
11
11
  import { unique as unique2 } from "remeda";
12
12
 
13
13
  // src/lib/config.ts
14
14
  import fs8 from "fs-extra";
15
- import assert2 from "node:assert";
15
+ import assert3 from "node:assert";
16
16
  import path6 from "node:path";
17
17
  import { isEmpty } from "remeda";
18
18
 
@@ -142,6 +142,7 @@ async function readTypedJson(filePath) {
142
142
  }
143
143
 
144
144
  // src/lib/utils/pack.ts
145
+ import assert2 from "node:assert";
145
146
  import { exec } from "node:child_process";
146
147
  import fs5 from "node:fs";
147
148
  import path5 from "node:path";
@@ -293,7 +294,10 @@ async function pack(srcDir, dstDir) {
293
294
  }
294
295
  );
295
296
  });
296
- const fileName = path5.basename(stdout.trim());
297
+ const lastLine = stdout.trim().split("\n").at(-1);
298
+ assert2(lastLine, `Failed to parse last line from stdout: ${stdout.trim()}`);
299
+ const fileName = path5.basename(lastLine);
300
+ assert2(fileName, `Failed to parse file name from: ${lastLine}`);
297
301
  const filePath = path5.join(dstDir, fileName);
298
302
  if (!fs5.existsSync(filePath)) {
299
303
  log.error(
@@ -444,7 +448,7 @@ async function generateNpmLockfile({
444
448
  }
445
449
 
446
450
  // src/lib/lockfile/helpers/generate-pnpm-lockfile.ts
447
- import assert3 from "node:assert";
451
+ import assert4 from "node:assert";
448
452
  import path9 from "node:path";
449
453
  import {
450
454
  getLockfileImporterId as getLockfileImporterId_v8,
@@ -486,10 +490,7 @@ function pnpmMapDependenciesLinks(importerPath, def, directoryByPackageName) {
486
490
  if (!value.startsWith("link:")) {
487
491
  return value;
488
492
  }
489
- const relativePath = path8.relative(
490
- importerPath,
491
- directoryByPackageName[key]
492
- );
493
+ const relativePath = path8.relative(importerPath, directoryByPackageName[key]).replace(path8.sep, path8.posix.sep);
493
494
  return relativePath.startsWith(".") ? `link:${relativePath}` : `link:./${relativePath}`;
494
495
  });
495
496
  }
@@ -521,12 +522,12 @@ async function generatePnpmLockfile({
521
522
  ignoreIncompatible: false
522
523
  }
523
524
  );
524
- assert3(lockfile, `No input lockfile found at ${workspaceRootDir}`);
525
+ assert4(lockfile, `No input lockfile found at ${workspaceRootDir}`);
525
526
  const targetImporterId = useVersion9 ? getLockfileImporterId_v9(workspaceRootDir, targetPackageDir) : getLockfileImporterId_v8(workspaceRootDir, targetPackageDir);
526
527
  const directoryByPackageName = Object.fromEntries(
527
528
  internalDepPackageNames.map((name) => {
528
529
  const pkg = packagesRegistry[name];
529
- assert3(pkg, `Package ${name} not found in packages registry`);
530
+ assert4(pkg, `Package ${name} not found in packages registry`);
530
531
  return [name, pkg.rootRelativeDir];
531
532
  })
532
533
  );
@@ -537,7 +538,17 @@ async function generatePnpmLockfile({
537
538
  * importer ids in the context of a lockfile.
538
539
  */
539
540
  ...Object.values(directoryByPackageName)
540
- ];
541
+ /**
542
+ * Split the path by the OS separator and join it back with the POSIX
543
+ * separator.
544
+ *
545
+ * The importerIds are built from directory names, so Windows Git Bash
546
+ * environments will have double backslashes in their ids:
547
+ * "packages\common" vs. "packages/common". Without this split & join, any
548
+ * packages not on the top-level will have ill-formatted importerIds and
549
+ * their entries will be missing from the lockfile.importers list.
550
+ */
551
+ ].map((x) => x.split(path9.sep).join(path9.posix.sep));
541
552
  log.debug("Relevant importer ids:", relevantImporterIds);
542
553
  const relevantImporterIdsWithPrefix = relevantImporterIds.map(
543
554
  (x) => isRush ? `../../${x}` : x
@@ -856,7 +867,7 @@ async function adaptTargetPackageManifest({
856
867
  }
857
868
 
858
869
  // src/lib/output/get-build-output-dir.ts
859
- import fs12 from "fs-extra";
870
+ import { getTsconfig } from "get-tsconfig";
860
871
  import path15 from "node:path";
861
872
  import outdent from "outdent";
862
873
  async function getBuildOutputDir(targetPackageDir) {
@@ -867,10 +878,10 @@ async function getBuildOutputDir(targetPackageDir) {
867
878
  return path15.join(targetPackageDir, config.buildDirName);
868
879
  }
869
880
  const tsconfigPath = path15.join(targetPackageDir, config.tsconfigPath);
870
- if (fs12.existsSync(tsconfigPath)) {
871
- log.debug("Found tsconfig at:", config.tsconfigPath);
872
- const tsconfig = await readTypedJson(tsconfigPath);
873
- const outDir = tsconfig.compilerOptions?.outDir;
881
+ const tsconfig = getTsconfig(tsconfigPath);
882
+ if (tsconfig) {
883
+ log.debug("Found tsconfig at:", tsconfig.path);
884
+ const outDir = tsconfig.config.compilerOptions?.outDir;
874
885
  if (outDir) {
875
886
  return path15.join(targetPackageDir, outDir);
876
887
  } else {
@@ -887,7 +898,7 @@ async function getBuildOutputDir(targetPackageDir) {
887
898
  }
888
899
 
889
900
  // src/lib/output/pack-dependencies.ts
890
- import assert4 from "node:assert";
901
+ import assert5 from "node:assert";
891
902
  async function packDependencies({
892
903
  /** All packages found in the monorepo by workspaces declaration */
893
904
  packagesRegistry,
@@ -905,7 +916,7 @@ async function packDependencies({
905
916
  const packedFileByName = {};
906
917
  for (const dependency of internalPackageNames) {
907
918
  const def = packagesRegistry[dependency];
908
- assert4(dependency, `Failed to find package definition for ${dependency}`);
919
+ assert5(dependency, `Failed to find package definition for ${dependency}`);
909
920
  const { name } = def.manifest;
910
921
  if (packedFileByName[name]) {
911
922
  log.debug(`Skipping ${name} because it has already been packed`);
@@ -917,7 +928,7 @@ async function packDependencies({
917
928
  }
918
929
 
919
930
  // src/lib/output/process-build-output-files.ts
920
- import fs13 from "fs-extra";
931
+ import fs12 from "fs-extra";
921
932
  import path16 from "node:path";
922
933
  var TIMEOUT_MS = 5e3;
923
934
  async function processBuildOutputFiles({
@@ -930,7 +941,7 @@ async function processBuildOutputFiles({
930
941
  const unpackDir = path16.join(tmpDir, "target");
931
942
  const now = Date.now();
932
943
  let isWaitingYet = false;
933
- while (!fs13.existsSync(packedFilePath) && Date.now() - now < TIMEOUT_MS) {
944
+ while (!fs12.existsSync(packedFilePath) && Date.now() - now < TIMEOUT_MS) {
934
945
  if (!isWaitingYet) {
935
946
  log.debug(`Waiting for ${packedFilePath} to become available...`);
936
947
  }
@@ -938,11 +949,11 @@ async function processBuildOutputFiles({
938
949
  await new Promise((resolve) => setTimeout(resolve, 100));
939
950
  }
940
951
  await unpack(packedFilePath, unpackDir);
941
- await fs13.copy(path16.join(unpackDir, "package"), isolateDir);
952
+ await fs12.copy(path16.join(unpackDir, "package"), isolateDir);
942
953
  }
943
954
 
944
955
  // src/lib/output/unpack-dependencies.ts
945
- import fs14 from "fs-extra";
956
+ import fs13 from "fs-extra";
946
957
  import path17, { join as join2 } from "node:path";
947
958
  async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, isolateDir) {
948
959
  const log = useLogger();
@@ -953,8 +964,8 @@ async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, i
953
964
  log.debug("Unpacking", `(temp)/${path17.basename(filePath)}`);
954
965
  await unpack(filePath, unpackDir);
955
966
  const destinationDir = join2(isolateDir, dir);
956
- await fs14.ensureDir(destinationDir);
957
- await fs14.move(join2(unpackDir, "package"), destinationDir, {
967
+ await fs13.ensureDir(destinationDir);
968
+ await fs13.move(join2(unpackDir, "package"), destinationDir, {
958
969
  overwrite: true
959
970
  });
960
971
  log.debug(
@@ -968,12 +979,12 @@ async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, i
968
979
  }
969
980
 
970
981
  // src/lib/registry/create-packages-registry.ts
971
- import fs15 from "fs-extra";
982
+ import fs14 from "fs-extra";
972
983
  import { globSync } from "glob";
973
984
  import path19 from "node:path";
974
985
 
975
986
  // src/lib/registry/helpers/find-packages-globs.ts
976
- import assert5 from "node:assert";
987
+ import assert6 from "node:assert";
977
988
  import path18 from "node:path";
978
989
  function findPackagesGlobs(workspaceRootDir) {
979
990
  const log = useLogger();
@@ -1005,7 +1016,7 @@ function findPackagesGlobs(workspaceRootDir) {
1005
1016
  return workspaces;
1006
1017
  } else {
1007
1018
  const workspacesObject = workspaces;
1008
- assert5(
1019
+ assert6(
1009
1020
  workspacesObject.packages,
1010
1021
  "workspaces.packages must be an array"
1011
1022
  );
@@ -1031,7 +1042,7 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
1031
1042
  allPackages.map(async (rootRelativeDir) => {
1032
1043
  const absoluteDir = path19.join(workspaceRootDir, rootRelativeDir);
1033
1044
  const manifestPath = path19.join(absoluteDir, "package.json");
1034
- if (!fs15.existsSync(manifestPath)) {
1045
+ if (!fs14.existsSync(manifestPath)) {
1035
1046
  log.warn(
1036
1047
  `Ignoring directory ${rootRelativeDir} because it does not contain a package.json file`
1037
1048
  );
@@ -1066,7 +1077,7 @@ function listWorkspacePackages(workspacePackagesOverride, workspaceRootDir) {
1066
1077
  const currentDir = process.cwd();
1067
1078
  process.chdir(workspaceRootDir);
1068
1079
  const packagesGlobs = workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);
1069
- const allPackages = packagesGlobs.flatMap((glob) => globSync(glob)).filter((dir) => fs15.lstatSync(dir).isDirectory());
1080
+ const allPackages = packagesGlobs.flatMap((glob) => globSync(glob)).filter((dir) => fs14.lstatSync(dir).isDirectory());
1070
1081
  process.chdir(currentDir);
1071
1082
  return allPackages;
1072
1083
  }
@@ -1109,8 +1120,8 @@ async function isolate(options = {}) {
1109
1120
  const targetPackageDir = config.targetPackagePath ? path20.join(process.cwd(), config.targetPackagePath) : process.cwd();
1110
1121
  const workspaceRootDir = config.targetPackagePath ? process.cwd() : path20.join(targetPackageDir, config.workspaceRoot);
1111
1122
  const buildOutputDir = await getBuildOutputDir(targetPackageDir);
1112
- assert6(
1113
- fs16.existsSync(buildOutputDir),
1123
+ assert7(
1124
+ fs15.existsSync(buildOutputDir),
1114
1125
  `Failed to find build output path at ${buildOutputDir}. Please make sure you build the source before isolating it.`
1115
1126
  );
1116
1127
  log.debug("Workspace root resolved to", workspaceRootDir);
@@ -1123,13 +1134,13 @@ async function isolate(options = {}) {
1123
1134
  "Isolate output directory",
1124
1135
  getRootRelativePath(isolateDir, workspaceRootDir)
1125
1136
  );
1126
- if (fs16.existsSync(isolateDir)) {
1127
- await fs16.remove(isolateDir);
1137
+ if (fs15.existsSync(isolateDir)) {
1138
+ await fs15.remove(isolateDir);
1128
1139
  log.debug("Cleaned the existing isolate output directory");
1129
1140
  }
1130
- await fs16.ensureDir(isolateDir);
1141
+ await fs15.ensureDir(isolateDir);
1131
1142
  const tmpDir = path20.join(isolateDir, "__tmp");
1132
- await fs16.ensureDir(tmpDir);
1143
+ await fs15.ensureDir(tmpDir);
1133
1144
  const targetPackageManifest = await readTypedJson(
1134
1145
  path20.join(targetPackageDir, "package.json")
1135
1146
  );
@@ -1209,22 +1220,22 @@ async function isolate(options = {}) {
1209
1220
  packages
1210
1221
  });
1211
1222
  } else {
1212
- fs16.copyFileSync(
1223
+ fs15.copyFileSync(
1213
1224
  path20.join(workspaceRootDir, "pnpm-workspace.yaml"),
1214
1225
  path20.join(isolateDir, "pnpm-workspace.yaml")
1215
1226
  );
1216
1227
  }
1217
1228
  }
1218
1229
  const npmrcPath = path20.join(workspaceRootDir, ".npmrc");
1219
- if (fs16.existsSync(npmrcPath)) {
1220
- fs16.copyFileSync(npmrcPath, path20.join(isolateDir, ".npmrc"));
1230
+ if (fs15.existsSync(npmrcPath)) {
1231
+ fs15.copyFileSync(npmrcPath, path20.join(isolateDir, ".npmrc"));
1221
1232
  log.debug("Copied .npmrc file to the isolate output");
1222
1233
  }
1223
1234
  log.debug(
1224
1235
  "Deleting temp directory",
1225
1236
  getRootRelativePath(tmpDir, workspaceRootDir)
1226
1237
  );
1227
- await fs16.remove(tmpDir);
1238
+ await fs15.remove(tmpDir);
1228
1239
  log.info("Isolate completed at", isolateDir);
1229
1240
  return isolateDir;
1230
1241
  }