@xylabs/toolchain 7.10.2 → 7.10.3

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
@@ -700,6 +700,7 @@ function printWorkspaceCycles(cycles) {
700
700
  }
701
701
 
702
702
  // src/lib/deprecationMigrate.ts
703
+ import { spawnSync as spawnSync5 } from "child_process";
703
704
  import {
704
705
  existsSync as existsSync2,
705
706
  readFileSync as readFileSync5,
@@ -708,6 +709,12 @@ import {
708
709
  import PATH4 from "path";
709
710
  import { createInterface } from "readline";
710
711
  import chalk5 from "chalk";
712
+ var DEPRECATED_PACKAGES = [
713
+ "@xylabs/ts-scripts-common",
714
+ "@xylabs/ts-scripts-yarn3",
715
+ "@xylabs/ts-scripts-pnpm",
716
+ "@xylabs/ts-scripts-react-yarn3"
717
+ ];
711
718
  function findProjectRoot() {
712
719
  return process.env.INIT_CWD ?? process.cwd();
713
720
  }
@@ -720,56 +727,64 @@ function askYesNo(question) {
720
727
  });
721
728
  });
722
729
  }
723
- function replaceInFile(filePath, oldStr, newStr) {
730
+ function replaceAllOldPackagesInFile(filePath) {
724
731
  if (!existsSync2(filePath)) return false;
725
- const content = readFileSync5(filePath, "utf8");
726
- if (!content.includes(oldStr)) return false;
727
- writeFileSync(filePath, content.replaceAll(oldStr, newStr), "utf8");
728
- return true;
729
- }
730
- function migrateRootPackageJson(pkg, pkgPath, oldPackage, depField) {
731
- const version = pkg[depField][oldPackage];
732
- delete pkg[depField][oldPackage];
733
- pkg[depField]["@xylabs/toolchain"] = version;
734
- writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}
735
- `, "utf8");
736
- console.warn(chalk5.green(` \u2713 Replaced ${oldPackage} \u2192 @xylabs/toolchain in ${depField}`));
732
+ let content = readFileSync5(filePath, "utf8");
733
+ let changed = false;
734
+ for (const oldPkg of DEPRECATED_PACKAGES) {
735
+ if (content.includes(oldPkg)) {
736
+ content = content.replaceAll(oldPkg, "@xylabs/toolchain");
737
+ changed = true;
738
+ }
739
+ }
740
+ if (changed) {
741
+ writeFileSync(filePath, content, "utf8");
742
+ }
743
+ return changed;
737
744
  }
738
- function migrateWorkspacePackageJson(wsPkgPath, dir, oldPackage) {
739
- if (!existsSync2(wsPkgPath)) return;
740
- const wsPkg = JSON.parse(readFileSync5(wsPkgPath, "utf8"));
745
+ function migratePackageJson(pkgPath, label) {
746
+ if (!existsSync2(pkgPath)) return false;
747
+ const pkg = JSON.parse(readFileSync5(pkgPath, "utf8"));
741
748
  let changed = false;
742
749
  for (const field of ["dependencies", "devDependencies", "peerDependencies"]) {
743
- if (wsPkg[field]?.[oldPackage]) {
744
- const ver = wsPkg[field][oldPackage];
745
- delete wsPkg[field][oldPackage];
746
- wsPkg[field]["@xylabs/toolchain"] = ver;
747
- changed = true;
750
+ for (const oldPkg of DEPRECATED_PACKAGES) {
751
+ if (pkg[field]?.[oldPkg]) {
752
+ const ver = pkg[field][oldPkg];
753
+ delete pkg[field][oldPkg];
754
+ if (!pkg[field]["@xylabs/toolchain"]) {
755
+ pkg[field]["@xylabs/toolchain"] = ver;
756
+ }
757
+ changed = true;
758
+ }
748
759
  }
749
760
  }
750
761
  if (changed) {
751
- writeFileSync(wsPkgPath, `${JSON.stringify(wsPkg, null, 2)}
762
+ writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}
752
763
  `, "utf8");
753
- console.warn(chalk5.green(` \u2713 Updated ${dir}/package.json`));
764
+ console.warn(chalk5.green(` \u2713 Updated ${label}`));
754
765
  }
766
+ return changed;
755
767
  }
756
- async function migrateWorkspaces(root, workspacesGlob, oldPackage) {
757
- if (!Array.isArray(workspacesGlob)) return;
768
+ async function migrateWorkspaces(root) {
758
769
  const { globSync: globSync5 } = await import("glob");
759
- for (const pattern of workspacesGlob) {
760
- const dirs = globSync5(pattern, { cwd: root });
761
- for (const dir of dirs) {
762
- if (replaceInFile(PATH4.join(root, dir, "xy.config.ts"), oldPackage, "@xylabs/toolchain")) {
763
- console.warn(chalk5.green(` \u2713 Updated ${dir}/xy.config.ts imports`));
764
- }
765
- migrateWorkspacePackageJson(PATH4.join(root, dir, "package.json"), dir, oldPackage);
770
+ const packageJsonFiles = globSync5("**/package.json", {
771
+ cwd: root,
772
+ ignore: ["node_modules/**", "**/node_modules/**", "dist/**", "**/dist/**"]
773
+ });
774
+ for (const relPath of packageJsonFiles) {
775
+ if (relPath === "package.json") continue;
776
+ const dir = PATH4.dirname(relPath);
777
+ migratePackageJson(PATH4.join(root, relPath), relPath);
778
+ const xyConfigPath = PATH4.join(root, dir, "xy.config.ts");
779
+ if (replaceAllOldPackagesInFile(xyConfigPath)) {
780
+ console.warn(chalk5.green(` \u2713 Updated ${dir}/xy.config.ts`));
766
781
  }
767
782
  }
768
783
  }
769
- function printManualInstructions(oldPackage) {
784
+ function printManualInstructions() {
770
785
  console.warn(chalk5.gray(" Skipped. To migrate manually:\n"));
771
- console.warn(chalk5.gray(` 1. Replace "${oldPackage}" with "@xylabs/toolchain" in package.json`));
772
- console.warn(chalk5.gray(" 2. Update xy.config.ts imports"));
786
+ console.warn(chalk5.gray(" 1. Replace all @xylabs/ts-scripts-* deps with @xylabs/toolchain in package.json"));
787
+ console.warn(chalk5.gray(" 2. Update imports in xy.config.ts files"));
773
788
  console.warn(chalk5.gray(" 3. Run your package manager install\n"));
774
789
  }
775
790
  async function deprecationMigrate(oldPackage) {
@@ -777,22 +792,33 @@ async function deprecationMigrate(oldPackage) {
777
792
  const pkgPath = PATH4.join(root, "package.json");
778
793
  if (!existsSync2(pkgPath)) return;
779
794
  const pkg = JSON.parse(readFileSync5(pkgPath, "utf8"));
780
- const depField = pkg.dependencies?.[oldPackage] ? "dependencies" : pkg.devDependencies?.[oldPackage] ? "devDependencies" : void 0;
781
- if (!depField) return;
795
+ const hasOldDep = DEPRECATED_PACKAGES.some((dep) => pkg.dependencies?.[dep] || pkg.devDependencies?.[dep]);
796
+ if (!hasOldDep) return;
782
797
  console.warn(chalk5.yellow(`
783
798
  \u26A0 ${oldPackage} is deprecated. Use @xylabs/toolchain instead.
784
799
  `));
785
800
  const shouldMigrate = await askYesNo(chalk5.cyan(" Auto-migrate to @xylabs/toolchain? [y/N] "));
786
801
  if (!shouldMigrate) {
787
- printManualInstructions(oldPackage);
802
+ printManualInstructions();
788
803
  return;
789
804
  }
790
- migrateRootPackageJson(pkg, pkgPath, oldPackage, depField);
791
- if (replaceInFile(PATH4.join(root, "xy.config.ts"), oldPackage, "@xylabs/toolchain")) {
792
- console.warn(chalk5.green(" \u2713 Updated xy.config.ts imports"));
805
+ migratePackageJson(pkgPath, "package.json");
806
+ if (replaceAllOldPackagesInFile(PATH4.join(root, "xy.config.ts"))) {
807
+ console.warn(chalk5.green(" \u2713 Updated xy.config.ts"));
793
808
  }
794
- await migrateWorkspaces(root, pkg.workspaces, oldPackage);
795
- console.warn(chalk5.yellow("\n Run your package manager install to complete the migration.\n"));
809
+ await migrateWorkspaces(root);
810
+ const pm = detectPackageManager();
811
+ console.warn(chalk5.cyan(`
812
+ Running ${pm} install...
813
+ `));
814
+ const result = spawnSync5(pm, ["install"], { cwd: root, stdio: "inherit" });
815
+ if (result.status === 0) {
816
+ console.warn(chalk5.green(" \u2713 Migration complete. Re-run your command.\n"));
817
+ } else {
818
+ console.warn(chalk5.red(` Install failed (exit ${result.status}). Run "${pm} install" manually.
819
+ `));
820
+ }
821
+ process.exit(result.status ?? 1);
796
822
  }
797
823
 
798
824
  // src/lib/file/constants.ts
@@ -1260,12 +1286,12 @@ function listRepoTemplates() {
1260
1286
  }
1261
1287
 
1262
1288
  // src/lib/runInstall.ts
1263
- import { spawnSync as spawnSync5 } from "child_process";
1289
+ import { spawnSync as spawnSync6 } from "child_process";
1264
1290
  import chalk9 from "chalk";
1265
1291
  function runInstall(cwd6) {
1266
1292
  const pm = detectPackageManager();
1267
1293
  console.log(chalk9.gray(`Running ${pm} install...`));
1268
- const result = spawnSync5(pm, ["install"], {
1294
+ const result = spawnSync6(pm, ["install"], {
1269
1295
  cwd: cwd6,
1270
1296
  stdio: "inherit"
1271
1297
  });
@@ -1278,7 +1304,7 @@ function runInstall(cwd6) {
1278
1304
  }
1279
1305
 
1280
1306
  // src/lib/runSteps.ts
1281
- import { spawnSync as spawnSync6 } from "child_process";
1307
+ import { spawnSync as spawnSync7 } from "child_process";
1282
1308
  import { existsSync as existsSync5 } from "fs";
1283
1309
  import chalk10 from "chalk";
1284
1310
  var runSteps = (name, steps, exitOnFail = true, messages) => {
@@ -1294,7 +1320,7 @@ var runSteps = (name, steps, exitOnFail = true, messages) => {
1294
1320
  if (command === "node" && !existsSync5(argList[0])) {
1295
1321
  throw new Error(`File not found [${argList[0]}]`);
1296
1322
  }
1297
- const status = spawnSync6(command, Array.isArray(args) ? args : args.split(" "), {
1323
+ const status = spawnSync7(command, Array.isArray(args) ? args : args.split(" "), {
1298
1324
  ...config2,
1299
1325
  encoding: "utf8",
1300
1326
  env: { FORCE_COLOR: "3", ...process.env },
@@ -1377,7 +1403,7 @@ var runXyWithWarning = (command) => {
1377
1403
  };
1378
1404
 
1379
1405
  // src/lib/tryRunLocalScript.ts
1380
- import { spawnSync as spawnSync7 } from "child_process";
1406
+ import { spawnSync as spawnSync8 } from "child_process";
1381
1407
  import { readFileSync as readFileSync13 } from "fs";
1382
1408
  import PATH8 from "path";
1383
1409
  import chalk13 from "chalk";
@@ -1394,7 +1420,7 @@ function tryRunLocalScript(commandName) {
1394
1420
  const extraArgs = process.argv.slice(process.argv.indexOf(commandName) + 1);
1395
1421
  console.log(chalk13.blue(`Delegating "${commandName}" to local script`));
1396
1422
  const pm = getPackageManager();
1397
- const result = spawnSync7(pm.command, ["run", commandName, ...extraArgs], {
1423
+ const result = spawnSync8(pm.command, ["run", commandName, ...extraArgs], {
1398
1424
  cwd: process.cwd(),
1399
1425
  encoding: "utf8",
1400
1426
  env: {
@@ -2163,7 +2189,7 @@ var claudeCommands = () => {
2163
2189
  };
2164
2190
 
2165
2191
  // src/actions/claude-rules.ts
2166
- import { spawnSync as spawnSync8 } from "child_process";
2192
+ import { spawnSync as spawnSync9 } from "child_process";
2167
2193
  import {
2168
2194
  existsSync as existsSync10,
2169
2195
  mkdirSync as mkdirSync2,
@@ -2231,7 +2257,7 @@ var ensureProjectClaudeMd = (cwd6, force) => {
2231
2257
  console.log(chalk21.yellow("Regenerating CLAUDE.md"));
2232
2258
  }
2233
2259
  console.log(chalk21.green("Generating CLAUDE.md via claude /init..."));
2234
- const result = spawnSync8("claude", ["-p", "/init", "--allowedTools", "Read", "Write", "Glob", "Grep"], {
2260
+ const result = spawnSync9("claude", ["-p", "/init", "--allowedTools", "Read", "Write", "Glob", "Grep"], {
2235
2261
  cwd: cwd6,
2236
2262
  shell: true,
2237
2263
  stdio: "inherit"
@@ -5415,7 +5441,7 @@ async function lintInit({ verbose } = {}) {
5415
5441
  }
5416
5442
 
5417
5443
  // src/actions/lintlint.ts
5418
- import { spawnSync as spawnSync9 } from "child_process";
5444
+ import { spawnSync as spawnSync10 } from "child_process";
5419
5445
  import {
5420
5446
  existsSync as existsSync14,
5421
5447
  readFileSync as readFileSync23,
@@ -5620,7 +5646,7 @@ Fixed: removed ${redundant.length} redundant rule(s)`));
5620
5646
  }
5621
5647
  }
5622
5648
  function formatConfigFile(eslintConfigPath) {
5623
- spawnSync9("eslint", ["--fix", eslintConfigPath], { stdio: "inherit" });
5649
+ spawnSync10("eslint", ["--fix", eslintConfigPath], { stdio: "inherit" });
5624
5650
  }
5625
5651
  function fixConfigMismatch(eslintConfigPath, configDir, source, sharedPkg, expectedPkg) {
5626
5652
  const updated = source.replaceAll(sharedPkg, expectedPkg);
@@ -7302,7 +7328,7 @@ import PATH24 from "path";
7302
7328
  import chalk65 from "chalk";
7303
7329
 
7304
7330
  // src/actions/packman/convertToPnpm.ts
7305
- import { spawnSync as spawnSync10 } from "child_process";
7331
+ import { spawnSync as spawnSync11 } from "child_process";
7306
7332
  import {
7307
7333
  existsSync as existsSync19,
7308
7334
  mkdirSync as mkdirSync5,
@@ -7579,7 +7605,7 @@ function convertToPnpm(cwd6, workspacePackageJsonPaths) {
7579
7605
  rewriteSourceImports(cwd6, "yarn-to-pnpm");
7580
7606
  deleteYarnArtifacts(cwd6);
7581
7607
  console.log(chalk63.blue("\nRunning pnpm install..."));
7582
- const install = spawnSync10("pnpm", ["install"], {
7608
+ const install = spawnSync11("pnpm", ["install"], {
7583
7609
  cwd: cwd6,
7584
7610
  encoding: "utf8",
7585
7611
  shell: true,
@@ -7594,7 +7620,7 @@ function convertToPnpm(cwd6, workspacePackageJsonPaths) {
7594
7620
  }
7595
7621
 
7596
7622
  // src/actions/packman/convertToYarn.ts
7597
- import { spawnSync as spawnSync11 } from "child_process";
7623
+ import { spawnSync as spawnSync12 } from "child_process";
7598
7624
  import {
7599
7625
  existsSync as existsSync20,
7600
7626
  readFileSync as readFileSync28,
@@ -7722,7 +7748,7 @@ function convertToYarn(cwd6, workspacePackageJsonPaths) {
7722
7748
  rewriteSourceImports(cwd6, "pnpm-to-yarn");
7723
7749
  deletePnpmArtifacts(cwd6);
7724
7750
  console.log(chalk64.blue("\nRunning yarn install..."));
7725
- const install = spawnSync11("yarn", ["install"], {
7751
+ const install = spawnSync12("yarn", ["install"], {
7726
7752
  cwd: cwd6,
7727
7753
  encoding: "utf8",
7728
7754
  shell: true,
@@ -8524,7 +8550,7 @@ var relintAllPackages = ({ fix: fix2 = false } = {}) => {
8524
8550
  };
8525
8551
 
8526
8552
  // src/actions/repo-init.ts
8527
- import { spawnSync as spawnSync12 } from "child_process";
8553
+ import { spawnSync as spawnSync13 } from "child_process";
8528
8554
  import {
8529
8555
  existsSync as existsSync25,
8530
8556
  mkdirSync as mkdirSync6,
@@ -8627,7 +8653,7 @@ function scaffoldFiles(templateName, layer, outputDir, pm, variables, verbose) {
8627
8653
  }
8628
8654
  function initGitRepo(projectDir, verbose) {
8629
8655
  if (verbose) console.log(chalk70.gray("Initializing git repository..."));
8630
- const result = spawnSync12("git", ["init", "-b", "main"], {
8656
+ const result = spawnSync13("git", ["init", "-b", "main"], {
8631
8657
  cwd: projectDir,
8632
8658
  stdio: verbose ? "inherit" : "pipe"
8633
8659
  });
@@ -8639,7 +8665,7 @@ function initGitRepo(projectDir, verbose) {
8639
8665
  }
8640
8666
  function installDependencies(projectDir, pm) {
8641
8667
  console.log(chalk70.gray(`Running ${pm} install...`));
8642
- const result = spawnSync12(pm, ["install"], {
8668
+ const result = spawnSync13(pm, ["install"], {
8643
8669
  cwd: projectDir,
8644
8670
  stdio: "inherit"
8645
8671
  });