isolate-package 1.18.0 → 1.19.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/isolate.ts
2
2
  import fs16 from "fs-extra";
3
3
  import assert6 from "node:assert";
4
- import path19 from "node:path";
4
+ import path20 from "node:path";
5
5
  import { unique } from "remeda";
6
6
 
7
7
  // src/lib/config.ts
@@ -84,12 +84,12 @@ function toErrorWithMessage(maybeError) {
84
84
 
85
85
  // src/lib/utils/get-relative-path.ts
86
86
  import { join } from "node:path";
87
- function getRootRelativePath(path20, rootPath) {
88
- const strippedPath = path20.replace(rootPath, "");
87
+ function getRootRelativePath(path21, rootPath) {
88
+ const strippedPath = path21.replace(rootPath, "");
89
89
  return join("(root)", strippedPath);
90
90
  }
91
- function getIsolateRelativePath(path20, isolatePath) {
92
- const strippedPath = path20.replace(isolatePath, "");
91
+ function getIsolateRelativePath(path21, isolatePath) {
92
+ const strippedPath = path21.replace(isolatePath, "");
93
93
  return join("(isolate)", strippedPath);
94
94
  }
95
95
 
@@ -406,13 +406,14 @@ async function generateNpmLockfile({
406
406
  await fs9.writeFile(lockfilePath, String(meta));
407
407
  log.debug("Created lockfile at", lockfilePath);
408
408
  } catch (err) {
409
- throw new Error(`Failed to generate lockfile: ${getErrorMessage(err)}`);
409
+ log.error(`Failed to generate lockfile: ${getErrorMessage(err)}`);
410
+ throw err;
410
411
  }
411
412
  }
412
413
 
413
414
  // src/lib/lockfile/helpers/generate-pnpm-lockfile.ts
414
415
  import assert3 from "node:assert";
415
- import path8 from "node:path";
416
+ import path9 from "node:path";
416
417
  import {
417
418
  getLockfileImporterId as getLockfileImporterId_v8,
418
419
  readWantedLockfile as readWantedLockfile_v8,
@@ -428,22 +429,37 @@ import { pruneLockfile as pruneLockfile_v9 } from "pnpm_prune_lockfile_v9";
428
429
  import { pick } from "remeda";
429
430
 
430
431
  // src/lib/lockfile/helpers/pnpm-map-importer.ts
432
+ import path8 from "node:path";
431
433
  import { mapValues } from "remeda";
432
- function pnpmMapImporter({ dependencies, devDependencies, ...rest }, {
434
+ function pnpmMapImporter(importerPath, { dependencies, devDependencies, ...rest }, {
433
435
  includeDevDependencies,
434
436
  directoryByPackageName
435
437
  }) {
436
438
  return {
437
- dependencies: dependencies ? pnpmMapDependenciesLinks(dependencies, directoryByPackageName) : void 0,
438
- devDependencies: includeDevDependencies && devDependencies ? pnpmMapDependenciesLinks(devDependencies, directoryByPackageName) : void 0,
439
+ dependencies: dependencies ? pnpmMapDependenciesLinks(
440
+ importerPath,
441
+ dependencies,
442
+ directoryByPackageName
443
+ ) : void 0,
444
+ devDependencies: includeDevDependencies && devDependencies ? pnpmMapDependenciesLinks(
445
+ importerPath,
446
+ devDependencies,
447
+ directoryByPackageName
448
+ ) : void 0,
439
449
  ...rest
440
450
  };
441
451
  }
442
- function pnpmMapDependenciesLinks(def, directoryByPackageName) {
443
- return mapValues(
444
- def,
445
- (value, key) => value.startsWith("link:") ? `link:./${directoryByPackageName[key]}` : value
446
- );
452
+ function pnpmMapDependenciesLinks(importerPath, def, directoryByPackageName) {
453
+ return mapValues(def, (value, key) => {
454
+ if (!value.startsWith("link:")) {
455
+ return value;
456
+ }
457
+ const relativePath = path8.relative(
458
+ importerPath,
459
+ directoryByPackageName[key]
460
+ );
461
+ return relativePath.startsWith(".") ? `link:${relativePath}` : `link:./${relativePath}`;
462
+ });
447
463
  }
448
464
 
449
465
  // src/lib/lockfile/helpers/generate-pnpm-lockfile.ts
@@ -463,12 +479,12 @@ async function generatePnpmLockfile({
463
479
  try {
464
480
  const isRush = isRushWorkspace(workspaceRootDir);
465
481
  const lockfile = useVersion9 ? await readWantedLockfile_v9(
466
- isRush ? path8.join(workspaceRootDir, "common/config/rush") : workspaceRootDir,
482
+ isRush ? path9.join(workspaceRootDir, "common/config/rush") : workspaceRootDir,
467
483
  {
468
484
  ignoreIncompatible: false
469
485
  }
470
486
  ) : await readWantedLockfile_v8(
471
- isRush ? path8.join(workspaceRootDir, "common/config/rush") : workspaceRootDir,
487
+ isRush ? path9.join(workspaceRootDir, "common/config/rush") : workspaceRootDir,
472
488
  {
473
489
  ignoreIncompatible: false
474
490
  }
@@ -503,7 +519,7 @@ async function generatePnpmLockfile({
503
519
  log.debug("Setting target package importer on root");
504
520
  return [
505
521
  ".",
506
- pnpmMapImporter(importer, {
522
+ pnpmMapImporter(".", importer, {
507
523
  includeDevDependencies,
508
524
  includePatchedDependencies,
509
525
  directoryByPackageName
@@ -513,7 +529,7 @@ async function generatePnpmLockfile({
513
529
  log.debug("Setting internal package importer:", importerId);
514
530
  return [
515
531
  importerId,
516
- pnpmMapImporter(importer, {
532
+ pnpmMapImporter(importerId, importer, {
517
533
  includeDevDependencies,
518
534
  includePatchedDependencies,
519
535
  directoryByPackageName
@@ -534,24 +550,25 @@ async function generatePnpmLockfile({
534
550
  ...prunedLockfile,
535
551
  patchedDependencies
536
552
  });
537
- log.debug("Created lockfile at", path8.join(isolateDir, "pnpm-lock.yaml"));
553
+ log.debug("Created lockfile at", path9.join(isolateDir, "pnpm-lock.yaml"));
538
554
  } catch (err) {
539
- throw new Error(`Failed to generate lockfile: ${getErrorMessage(err)}`);
555
+ log.error(`Failed to generate lockfile: ${getErrorMessage(err)}`);
556
+ throw err;
540
557
  }
541
558
  }
542
559
 
543
560
  // src/lib/lockfile/helpers/generate-yarn-lockfile.ts
544
561
  import fs10 from "fs-extra";
545
562
  import { execSync as execSync2 } from "node:child_process";
546
- import path9 from "node:path";
563
+ import path10 from "node:path";
547
564
  async function generateYarnLockfile({
548
565
  workspaceRootDir,
549
566
  isolateDir
550
567
  }) {
551
568
  const log = useLogger();
552
569
  log.debug("Generating Yarn lockfile...");
553
- const origLockfilePath = isRushWorkspace(workspaceRootDir) ? path9.join(workspaceRootDir, "common/config/rush", "yarn.lock") : path9.join(workspaceRootDir, "yarn.lock");
554
- const newLockfilePath = path9.join(isolateDir, "yarn.lock");
570
+ const origLockfilePath = isRushWorkspace(workspaceRootDir) ? path10.join(workspaceRootDir, "common/config/rush", "yarn.lock") : path10.join(workspaceRootDir, "yarn.lock");
571
+ const newLockfilePath = path10.join(isolateDir, "yarn.lock");
555
572
  if (!fs10.existsSync(origLockfilePath)) {
556
573
  throw new Error(`Failed to find lockfile at ${origLockfilePath}`);
557
574
  }
@@ -562,7 +579,8 @@ async function generateYarnLockfile({
562
579
  execSync2(`yarn install --cwd ${isolateDir}`);
563
580
  log.debug("Generated lockfile at", newLockfilePath);
564
581
  } catch (err) {
565
- throw new Error(`Failed to generate lockfile: ${getErrorMessage(err)}`);
582
+ log.error(`Failed to generate lockfile: ${getErrorMessage(err)}`);
583
+ throw err;
566
584
  }
567
585
  }
568
586
 
@@ -631,24 +649,24 @@ async function processLockfile({
631
649
  import { omit as omit2, pick as pick2 } from "remeda";
632
650
 
633
651
  // src/lib/manifest/helpers/adapt-internal-package-manifests.ts
634
- import path12 from "node:path";
652
+ import path13 from "node:path";
635
653
  import { omit } from "remeda";
636
654
 
637
655
  // src/lib/manifest/io.ts
638
656
  import fs11 from "fs-extra";
639
- import path10 from "node:path";
657
+ import path11 from "node:path";
640
658
  async function readManifest(packageDir) {
641
- return readTypedJson(path10.join(packageDir, "package.json"));
659
+ return readTypedJson(path11.join(packageDir, "package.json"));
642
660
  }
643
661
  async function writeManifest(outputDir, manifest) {
644
662
  await fs11.writeFile(
645
- path10.join(outputDir, "package.json"),
663
+ path11.join(outputDir, "package.json"),
646
664
  JSON.stringify(manifest, null, 2)
647
665
  );
648
666
  }
649
667
 
650
668
  // src/lib/manifest/helpers/patch-internal-entries.ts
651
- import path11 from "node:path";
669
+ import path12 from "node:path";
652
670
  function patchInternalEntries(dependencies, packagesRegistry, parentRootRelativeDir) {
653
671
  const log = useLogger();
654
672
  const allWorkspacePackageNames = Object.keys(packagesRegistry);
@@ -656,7 +674,7 @@ function patchInternalEntries(dependencies, packagesRegistry, parentRootRelative
656
674
  Object.entries(dependencies).map(([key, value]) => {
657
675
  if (allWorkspacePackageNames.includes(key)) {
658
676
  const def = packagesRegistry[key];
659
- const relativePath = parentRootRelativeDir ? path11.relative(parentRootRelativeDir, `./${def.rootRelativeDir}`) : `./${def.rootRelativeDir}`;
677
+ const relativePath = parentRootRelativeDir ? path12.relative(parentRootRelativeDir, `./${def.rootRelativeDir}`) : `./${def.rootRelativeDir}`;
660
678
  const linkPath = `file:${relativePath}`;
661
679
  log.debug(`Linking dependency ${key} to ${linkPath}`);
662
680
  return [key, linkPath];
@@ -711,7 +729,7 @@ async function adaptInternalPackageManifests(internalPackageNames, packagesRegis
711
729
  })
712
730
  );
713
731
  await writeManifest(
714
- path12.join(isolateDir, rootRelativeDir),
732
+ path13.join(isolateDir, rootRelativeDir),
715
733
  outputManifest
716
734
  );
717
735
  })
@@ -719,13 +737,13 @@ async function adaptInternalPackageManifests(internalPackageNames, packagesRegis
719
737
  }
720
738
 
721
739
  // src/lib/manifest/helpers/adopt-pnpm-fields-from-root.ts
722
- import path13 from "path";
740
+ import path14 from "path";
723
741
  async function adoptPnpmFieldsFromRoot(targetPackageManifest, workspaceRootDir) {
724
742
  if (isRushWorkspace(workspaceRootDir)) {
725
743
  return targetPackageManifest;
726
744
  }
727
745
  const rootPackageManifest = await readTypedJson(
728
- path13.join(workspaceRootDir, "package.json")
746
+ path14.join(workspaceRootDir, "package.json")
729
747
  );
730
748
  const overrides = rootPackageManifest.pnpm?.overrides;
731
749
  if (!overrides) {
@@ -785,22 +803,22 @@ async function adaptTargetPackageManifest({
785
803
 
786
804
  // src/lib/output/get-build-output-dir.ts
787
805
  import fs12 from "fs-extra";
788
- import path14 from "node:path";
806
+ import path15 from "node:path";
789
807
  import outdent from "outdent";
790
808
  async function getBuildOutputDir(targetPackageDir) {
791
809
  const config = useConfig();
792
810
  const log = useLogger();
793
811
  if (config.buildDirName) {
794
812
  log.debug("Using buildDirName from config:", config.buildDirName);
795
- return path14.join(targetPackageDir, config.buildDirName);
813
+ return path15.join(targetPackageDir, config.buildDirName);
796
814
  }
797
- const tsconfigPath = path14.join(targetPackageDir, config.tsconfigPath);
815
+ const tsconfigPath = path15.join(targetPackageDir, config.tsconfigPath);
798
816
  if (fs12.existsSync(tsconfigPath)) {
799
817
  log.debug("Found tsconfig at:", config.tsconfigPath);
800
818
  const tsconfig = await readTypedJson(tsconfigPath);
801
819
  const outDir = tsconfig.compilerOptions?.outDir;
802
820
  if (outDir) {
803
- return path14.join(targetPackageDir, outDir);
821
+ return path15.join(targetPackageDir, outDir);
804
822
  } else {
805
823
  throw new Error(outdent`
806
824
  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.
@@ -846,7 +864,7 @@ async function packDependencies({
846
864
 
847
865
  // src/lib/output/process-build-output-files.ts
848
866
  import fs13 from "fs-extra";
849
- import path15 from "node:path";
867
+ import path16 from "node:path";
850
868
  var TIMEOUT_MS = 5e3;
851
869
  async function processBuildOutputFiles({
852
870
  targetPackageDir,
@@ -855,7 +873,7 @@ async function processBuildOutputFiles({
855
873
  }) {
856
874
  const log = useLogger();
857
875
  const packedFilePath = await pack(targetPackageDir, tmpDir);
858
- const unpackDir = path15.join(tmpDir, "target");
876
+ const unpackDir = path16.join(tmpDir, "target");
859
877
  const now = Date.now();
860
878
  let isWaitingYet = false;
861
879
  while (!fs13.existsSync(packedFilePath) && Date.now() - now < TIMEOUT_MS) {
@@ -866,19 +884,19 @@ async function processBuildOutputFiles({
866
884
  await new Promise((resolve) => setTimeout(resolve, 100));
867
885
  }
868
886
  await unpack(packedFilePath, unpackDir);
869
- await fs13.copy(path15.join(unpackDir, "package"), isolateDir);
887
+ await fs13.copy(path16.join(unpackDir, "package"), isolateDir);
870
888
  }
871
889
 
872
890
  // src/lib/output/unpack-dependencies.ts
873
891
  import fs14 from "fs-extra";
874
- import path16, { join as join2 } from "node:path";
892
+ import path17, { join as join2 } from "node:path";
875
893
  async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, isolateDir) {
876
894
  const log = useLogger();
877
895
  await Promise.all(
878
896
  Object.entries(packedFilesByName).map(async ([packageName, filePath]) => {
879
897
  const dir = packagesRegistry[packageName].rootRelativeDir;
880
898
  const unpackDir = join2(tmpDir, dir);
881
- log.debug("Unpacking", `(temp)/${path16.basename(filePath)}`);
899
+ log.debug("Unpacking", `(temp)/${path17.basename(filePath)}`);
882
900
  await unpack(filePath, unpackDir);
883
901
  const destinationDir = join2(isolateDir, dir);
884
902
  await fs14.ensureDir(destinationDir);
@@ -898,25 +916,25 @@ async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, i
898
916
  // src/lib/registry/create-packages-registry.ts
899
917
  import fs15 from "fs-extra";
900
918
  import { globSync } from "glob";
901
- import path18 from "node:path";
919
+ import path19 from "node:path";
902
920
 
903
921
  // src/lib/registry/helpers/find-packages-globs.ts
904
922
  import assert5 from "node:assert";
905
- import path17 from "node:path";
923
+ import path18 from "node:path";
906
924
  function findPackagesGlobs(workspaceRootDir) {
907
925
  const log = useLogger();
908
926
  const packageManager2 = usePackageManager();
909
927
  switch (packageManager2.name) {
910
928
  case "pnpm": {
911
929
  const { packages: globs } = readTypedYamlSync(
912
- path17.join(workspaceRootDir, "pnpm-workspace.yaml")
930
+ path18.join(workspaceRootDir, "pnpm-workspace.yaml")
913
931
  );
914
932
  log.debug("Detected pnpm packages globs:", inspectValue(globs));
915
933
  return globs;
916
934
  }
917
935
  case "yarn":
918
936
  case "npm": {
919
- const workspaceRootManifestPath = path17.join(
937
+ const workspaceRootManifestPath = path18.join(
920
938
  workspaceRootDir,
921
939
  "package.json"
922
940
  );
@@ -956,8 +974,8 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
956
974
  );
957
975
  const registry = (await Promise.all(
958
976
  allPackages.map(async (rootRelativeDir) => {
959
- const absoluteDir = path18.join(workspaceRootDir, rootRelativeDir);
960
- const manifestPath = path18.join(absoluteDir, "package.json");
977
+ const absoluteDir = path19.join(workspaceRootDir, rootRelativeDir);
978
+ const manifestPath = path19.join(absoluteDir, "package.json");
961
979
  if (!fs15.existsSync(manifestPath)) {
962
980
  log.warn(
963
981
  `Ignoring directory ${rootRelativeDir} because it does not contain a package.json file`
@@ -966,7 +984,7 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
966
984
  } else {
967
985
  log.debug(`Registering package ${rootRelativeDir}`);
968
986
  const manifest = await readTypedJson(
969
- path18.join(absoluteDir, "package.json")
987
+ path19.join(absoluteDir, "package.json")
970
988
  );
971
989
  return {
972
990
  manifest,
@@ -986,7 +1004,7 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
986
1004
  function listWorkspacePackages(workspacePackagesOverride, workspaceRootDir) {
987
1005
  if (isRushWorkspace(workspaceRootDir)) {
988
1006
  const rushConfig = readTypedJsonSync(
989
- path18.join(workspaceRootDir, "rush.json")
1007
+ path19.join(workspaceRootDir, "rush.json")
990
1008
  );
991
1009
  return rushConfig.projects.map(({ projectFolder }) => projectFolder);
992
1010
  } else {
@@ -1030,11 +1048,11 @@ async function isolate(options = {}) {
1030
1048
  setLogLevel(config.logLevel);
1031
1049
  const log = useLogger();
1032
1050
  const { version: libraryVersion } = await readTypedJson(
1033
- path19.join(path19.join(__dirname, "..", "package.json"))
1051
+ path20.join(path20.join(__dirname, "..", "package.json"))
1034
1052
  );
1035
1053
  log.info("Using isolate-package version", libraryVersion);
1036
- const targetPackageDir = config.targetPackagePath ? path19.join(process.cwd(), config.targetPackagePath) : process.cwd();
1037
- const workspaceRootDir = config.targetPackagePath ? process.cwd() : path19.join(targetPackageDir, config.workspaceRoot);
1054
+ const targetPackageDir = config.targetPackagePath ? path20.join(process.cwd(), config.targetPackagePath) : process.cwd();
1055
+ const workspaceRootDir = config.targetPackagePath ? process.cwd() : path20.join(targetPackageDir, config.workspaceRoot);
1038
1056
  const buildOutputDir = await getBuildOutputDir(targetPackageDir);
1039
1057
  assert6(
1040
1058
  fs16.existsSync(buildOutputDir),
@@ -1045,7 +1063,7 @@ async function isolate(options = {}) {
1045
1063
  "Isolate target package",
1046
1064
  getRootRelativePath(targetPackageDir, workspaceRootDir)
1047
1065
  );
1048
- const isolateDir = path19.join(targetPackageDir, config.isolateDirName);
1066
+ const isolateDir = path20.join(targetPackageDir, config.isolateDirName);
1049
1067
  log.debug(
1050
1068
  "Isolate output directory",
1051
1069
  getRootRelativePath(isolateDir, workspaceRootDir)
@@ -1055,10 +1073,10 @@ async function isolate(options = {}) {
1055
1073
  log.debug("Cleaned the existing isolate output directory");
1056
1074
  }
1057
1075
  await fs16.ensureDir(isolateDir);
1058
- const tmpDir = path19.join(isolateDir, "__tmp");
1076
+ const tmpDir = path20.join(isolateDir, "__tmp");
1059
1077
  await fs16.ensureDir(tmpDir);
1060
1078
  const targetPackageManifest = await readTypedJson(
1061
- path19.join(targetPackageDir, "package.json")
1079
+ path20.join(targetPackageDir, "package.json")
1062
1080
  );
1063
1081
  const packageManager2 = detectPackageManager(workspaceRootDir);
1064
1082
  log.debug(
@@ -1126,25 +1144,25 @@ async function isolate(options = {}) {
1126
1144
  if (isRushWorkspace(workspaceRootDir)) {
1127
1145
  const packagesFolderNames = unique(
1128
1146
  internalPackageNames.map(
1129
- (name) => path19.parse(packagesRegistry[name].rootRelativeDir).dir
1147
+ (name) => path20.parse(packagesRegistry[name].rootRelativeDir).dir
1130
1148
  )
1131
1149
  );
1132
1150
  log.debug("Generating pnpm-workspace.yaml for Rush workspace");
1133
1151
  log.debug("Packages folder names:", packagesFolderNames);
1134
- const packages = packagesFolderNames.map((x) => path19.join(x, "/*"));
1135
- await writeTypedYamlSync(path19.join(isolateDir, "pnpm-workspace.yaml"), {
1152
+ const packages = packagesFolderNames.map((x) => path20.join(x, "/*"));
1153
+ await writeTypedYamlSync(path20.join(isolateDir, "pnpm-workspace.yaml"), {
1136
1154
  packages
1137
1155
  });
1138
1156
  } else {
1139
1157
  fs16.copyFileSync(
1140
- path19.join(workspaceRootDir, "pnpm-workspace.yaml"),
1141
- path19.join(isolateDir, "pnpm-workspace.yaml")
1158
+ path20.join(workspaceRootDir, "pnpm-workspace.yaml"),
1159
+ path20.join(isolateDir, "pnpm-workspace.yaml")
1142
1160
  );
1143
1161
  }
1144
1162
  }
1145
- const npmrcPath = path19.join(workspaceRootDir, ".npmrc");
1163
+ const npmrcPath = path20.join(workspaceRootDir, ".npmrc");
1146
1164
  if (fs16.existsSync(npmrcPath)) {
1147
- fs16.copyFileSync(npmrcPath, path19.join(isolateDir, ".npmrc"));
1165
+ fs16.copyFileSync(npmrcPath, path20.join(isolateDir, ".npmrc"));
1148
1166
  log.debug("Copied .npmrc file to the isolate output");
1149
1167
  }
1150
1168
  log.debug(