@xylabs/toolchain 7.10.1 → 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/actions/index.mjs +162 -30
- package/dist/actions/index.mjs.map +1 -1
- package/dist/actions/package/compile/XyConfig.mjs.map +1 -1
- package/dist/actions/package/compile/index.mjs.map +1 -1
- package/dist/actions/package/index.mjs.map +1 -1
- package/dist/actions/package/publint.mjs.map +1 -1
- package/dist/actions/packman/index.mjs +270 -112
- package/dist/actions/packman/index.mjs.map +1 -1
- package/dist/actions/packman/lint.mjs +203 -36
- package/dist/actions/packman/lint.mjs.map +1 -1
- package/dist/actions/publint.mjs.map +1 -1
- package/dist/bin/package/publint.mjs.map +1 -1
- package/dist/bin/xy.mjs +164 -32
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.d.ts +21 -2
- package/dist/index.mjs +250 -92
- package/dist/index.mjs.map +1 -1
- package/dist/lib/deprecationMigrate.mjs +81 -46
- package/dist/lib/deprecationMigrate.mjs.map +1 -1
- package/dist/lib/index.mjs +75 -49
- package/dist/lib/index.mjs.map +1 -1
- package/dist/xy/common/checkCommand.mjs.map +1 -1
- package/dist/xy/common/index.mjs +164 -32
- package/dist/xy/common/index.mjs.map +1 -1
- package/dist/xy/common/packmanCommand.mjs +272 -114
- package/dist/xy/common/packmanCommand.mjs.map +1 -1
- package/dist/xy/index.mjs +164 -32
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/lint/index.mjs.map +1 -1
- package/dist/xy/lint/publintCommand.mjs.map +1 -1
- package/dist/xy/xy.mjs +164 -32
- package/dist/xy/xy.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
// src/lib/deprecationMigrate.ts
|
|
2
|
+
import { spawnSync } from "child_process";
|
|
2
3
|
import {
|
|
3
|
-
existsSync,
|
|
4
|
+
existsSync as existsSync2,
|
|
4
5
|
readFileSync,
|
|
5
6
|
writeFileSync
|
|
6
7
|
} from "fs";
|
|
7
8
|
import PATH from "path";
|
|
8
9
|
import { createInterface } from "readline";
|
|
9
10
|
import chalk from "chalk";
|
|
11
|
+
|
|
12
|
+
// src/pm/detectPackageManager.ts
|
|
13
|
+
import { existsSync } from "fs";
|
|
14
|
+
function detectPackageManager() {
|
|
15
|
+
if (existsSync("pnpm-lock.yaml") || existsSync("pnpm-workspace.yaml")) return "pnpm";
|
|
16
|
+
return "yarn";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/lib/deprecationMigrate.ts
|
|
20
|
+
var DEPRECATED_PACKAGES = [
|
|
21
|
+
"@xylabs/ts-scripts-common",
|
|
22
|
+
"@xylabs/ts-scripts-yarn3",
|
|
23
|
+
"@xylabs/ts-scripts-pnpm",
|
|
24
|
+
"@xylabs/ts-scripts-react-yarn3"
|
|
25
|
+
];
|
|
10
26
|
function findProjectRoot() {
|
|
11
27
|
return process.env.INIT_CWD ?? process.cwd();
|
|
12
28
|
}
|
|
@@ -19,79 +35,98 @@ function askYesNo(question) {
|
|
|
19
35
|
});
|
|
20
36
|
});
|
|
21
37
|
}
|
|
22
|
-
function
|
|
23
|
-
if (!
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
function replaceAllOldPackagesInFile(filePath) {
|
|
39
|
+
if (!existsSync2(filePath)) return false;
|
|
40
|
+
let content = readFileSync(filePath, "utf8");
|
|
41
|
+
let changed = false;
|
|
42
|
+
for (const oldPkg of DEPRECATED_PACKAGES) {
|
|
43
|
+
if (content.includes(oldPkg)) {
|
|
44
|
+
content = content.replaceAll(oldPkg, "@xylabs/toolchain");
|
|
45
|
+
changed = true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (changed) {
|
|
49
|
+
writeFileSync(filePath, content, "utf8");
|
|
50
|
+
}
|
|
51
|
+
return changed;
|
|
36
52
|
}
|
|
37
|
-
function
|
|
38
|
-
if (!
|
|
39
|
-
const
|
|
53
|
+
function migratePackageJson(pkgPath, label) {
|
|
54
|
+
if (!existsSync2(pkgPath)) return false;
|
|
55
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
40
56
|
let changed = false;
|
|
41
57
|
for (const field of ["dependencies", "devDependencies", "peerDependencies"]) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
58
|
+
for (const oldPkg of DEPRECATED_PACKAGES) {
|
|
59
|
+
if (pkg[field]?.[oldPkg]) {
|
|
60
|
+
const ver = pkg[field][oldPkg];
|
|
61
|
+
delete pkg[field][oldPkg];
|
|
62
|
+
if (!pkg[field]["@xylabs/toolchain"]) {
|
|
63
|
+
pkg[field]["@xylabs/toolchain"] = ver;
|
|
64
|
+
}
|
|
65
|
+
changed = true;
|
|
66
|
+
}
|
|
47
67
|
}
|
|
48
68
|
}
|
|
49
69
|
if (changed) {
|
|
50
|
-
writeFileSync(
|
|
70
|
+
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
51
71
|
`, "utf8");
|
|
52
|
-
console.warn(chalk.green(` \u2713 Updated ${
|
|
72
|
+
console.warn(chalk.green(` \u2713 Updated ${label}`));
|
|
53
73
|
}
|
|
74
|
+
return changed;
|
|
54
75
|
}
|
|
55
|
-
async function migrateWorkspaces(root
|
|
56
|
-
if (!Array.isArray(workspacesGlob)) return;
|
|
76
|
+
async function migrateWorkspaces(root) {
|
|
57
77
|
const { globSync } = await import("glob");
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
78
|
+
const packageJsonFiles = globSync("**/package.json", {
|
|
79
|
+
cwd: root,
|
|
80
|
+
ignore: ["node_modules/**", "**/node_modules/**", "dist/**", "**/dist/**"]
|
|
81
|
+
});
|
|
82
|
+
for (const relPath of packageJsonFiles) {
|
|
83
|
+
if (relPath === "package.json") continue;
|
|
84
|
+
const dir = PATH.dirname(relPath);
|
|
85
|
+
migratePackageJson(PATH.join(root, relPath), relPath);
|
|
86
|
+
const xyConfigPath = PATH.join(root, dir, "xy.config.ts");
|
|
87
|
+
if (replaceAllOldPackagesInFile(xyConfigPath)) {
|
|
88
|
+
console.warn(chalk.green(` \u2713 Updated ${dir}/xy.config.ts`));
|
|
65
89
|
}
|
|
66
90
|
}
|
|
67
91
|
}
|
|
68
|
-
function printManualInstructions(
|
|
92
|
+
function printManualInstructions() {
|
|
69
93
|
console.warn(chalk.gray(" Skipped. To migrate manually:\n"));
|
|
70
|
-
console.warn(chalk.gray(
|
|
71
|
-
console.warn(chalk.gray(" 2. Update xy.config.ts
|
|
94
|
+
console.warn(chalk.gray(" 1. Replace all @xylabs/ts-scripts-* deps with @xylabs/toolchain in package.json"));
|
|
95
|
+
console.warn(chalk.gray(" 2. Update imports in xy.config.ts files"));
|
|
72
96
|
console.warn(chalk.gray(" 3. Run your package manager install\n"));
|
|
73
97
|
}
|
|
74
98
|
async function deprecationMigrate(oldPackage) {
|
|
75
99
|
const root = findProjectRoot();
|
|
76
100
|
const pkgPath = PATH.join(root, "package.json");
|
|
77
|
-
if (!
|
|
101
|
+
if (!existsSync2(pkgPath)) return;
|
|
78
102
|
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
79
|
-
const
|
|
80
|
-
if (!
|
|
103
|
+
const hasOldDep = DEPRECATED_PACKAGES.some((dep) => pkg.dependencies?.[dep] || pkg.devDependencies?.[dep]);
|
|
104
|
+
if (!hasOldDep) return;
|
|
81
105
|
console.warn(chalk.yellow(`
|
|
82
106
|
\u26A0 ${oldPackage} is deprecated. Use @xylabs/toolchain instead.
|
|
83
107
|
`));
|
|
84
108
|
const shouldMigrate = await askYesNo(chalk.cyan(" Auto-migrate to @xylabs/toolchain? [y/N] "));
|
|
85
109
|
if (!shouldMigrate) {
|
|
86
|
-
printManualInstructions(
|
|
110
|
+
printManualInstructions();
|
|
87
111
|
return;
|
|
88
112
|
}
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
console.warn(chalk.green(" \u2713 Updated xy.config.ts
|
|
113
|
+
migratePackageJson(pkgPath, "package.json");
|
|
114
|
+
if (replaceAllOldPackagesInFile(PATH.join(root, "xy.config.ts"))) {
|
|
115
|
+
console.warn(chalk.green(" \u2713 Updated xy.config.ts"));
|
|
116
|
+
}
|
|
117
|
+
await migrateWorkspaces(root);
|
|
118
|
+
const pm = detectPackageManager();
|
|
119
|
+
console.warn(chalk.cyan(`
|
|
120
|
+
Running ${pm} install...
|
|
121
|
+
`));
|
|
122
|
+
const result = spawnSync(pm, ["install"], { cwd: root, stdio: "inherit" });
|
|
123
|
+
if (result.status === 0) {
|
|
124
|
+
console.warn(chalk.green(" \u2713 Migration complete. Re-run your command.\n"));
|
|
125
|
+
} else {
|
|
126
|
+
console.warn(chalk.red(` Install failed (exit ${result.status}). Run "${pm} install" manually.
|
|
127
|
+
`));
|
|
92
128
|
}
|
|
93
|
-
|
|
94
|
-
console.warn(chalk.yellow("\n Run your package manager install to complete the migration.\n"));
|
|
129
|
+
process.exit(result.status ?? 1);
|
|
95
130
|
}
|
|
96
131
|
export {
|
|
97
132
|
deprecationMigrate
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/deprecationMigrate.ts"],"sourcesContent":["import {\n existsSync, readFileSync, writeFileSync,\n} from 'node:fs'\nimport PATH from 'node:path'\nimport { createInterface } from 'node:readline'\n\nimport chalk from 'chalk'\n\nfunction findProjectRoot(): string {\n return process.env.INIT_CWD ?? process.cwd()\n}\n\nfunction askYesNo(question: string): Promise<boolean> {\n const rl = createInterface({ input: process.stdin, output: process.stderr })\n return new Promise((resolve) => {\n rl.question(question, (answer) => {\n rl.close()\n resolve(answer.trim().toLowerCase().startsWith('y'))\n })\n })\n}\n\nfunction
|
|
1
|
+
{"version":3,"sources":["../../src/lib/deprecationMigrate.ts","../../src/pm/detectPackageManager.ts"],"sourcesContent":["import { spawnSync } from 'node:child_process'\nimport {\n existsSync, readFileSync, writeFileSync,\n} from 'node:fs'\nimport PATH from 'node:path'\nimport { createInterface } from 'node:readline'\n\nimport chalk from 'chalk'\n\nimport { detectPackageManager } from '../pm/index.ts'\n\nconst DEPRECATED_PACKAGES = [\n '@xylabs/ts-scripts-common',\n '@xylabs/ts-scripts-yarn3',\n '@xylabs/ts-scripts-pnpm',\n '@xylabs/ts-scripts-react-yarn3',\n]\n\nfunction findProjectRoot(): string {\n return process.env.INIT_CWD ?? process.cwd()\n}\n\nfunction askYesNo(question: string): Promise<boolean> {\n const rl = createInterface({ input: process.stdin, output: process.stderr })\n return new Promise((resolve) => {\n rl.question(question, (answer) => {\n rl.close()\n resolve(answer.trim().toLowerCase().startsWith('y'))\n })\n })\n}\n\nfunction replaceAllOldPackagesInFile(filePath: string): boolean {\n if (!existsSync(filePath)) return false\n let content = readFileSync(filePath, 'utf8')\n let changed = false\n for (const oldPkg of DEPRECATED_PACKAGES) {\n if (content.includes(oldPkg)) {\n content = content.replaceAll(oldPkg, '@xylabs/toolchain')\n changed = true\n }\n }\n if (changed) {\n writeFileSync(filePath, content, 'utf8')\n }\n return changed\n}\n\nfunction migratePackageJson(pkgPath: string, label: string): boolean {\n if (!existsSync(pkgPath)) return false\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as Record<string, Record<string, string>>\n let changed = false\n\n for (const field of ['dependencies', 'devDependencies', 'peerDependencies'] as const) {\n for (const oldPkg of DEPRECATED_PACKAGES) {\n if (pkg[field]?.[oldPkg]) {\n const ver = pkg[field][oldPkg]\n delete pkg[field][oldPkg]\n // Only add toolchain if not already present in this field\n if (!pkg[field]['@xylabs/toolchain']) {\n pkg[field]['@xylabs/toolchain'] = ver\n }\n changed = true\n }\n }\n }\n\n if (changed) {\n writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\\n`, 'utf8')\n console.warn(chalk.green(` ✓ Updated ${label}`))\n }\n return changed\n}\n\nasync function migrateWorkspaces(root: string): Promise<void> {\n const { globSync } = await import('glob')\n const packageJsonFiles = globSync('**/package.json', {\n cwd: root,\n ignore: ['node_modules/**', '**/node_modules/**', 'dist/**', '**/dist/**'],\n })\n\n for (const relPath of packageJsonFiles) {\n // Skip root package.json (already handled)\n if (relPath === 'package.json') continue\n\n const dir = PATH.dirname(relPath)\n migratePackageJson(PATH.join(root, relPath), relPath)\n\n const xyConfigPath = PATH.join(root, dir, 'xy.config.ts')\n if (replaceAllOldPackagesInFile(xyConfigPath)) {\n console.warn(chalk.green(` ✓ Updated ${dir}/xy.config.ts`))\n }\n }\n}\n\nfunction printManualInstructions(): void {\n console.warn(chalk.gray(' Skipped. To migrate manually:\\n'))\n console.warn(chalk.gray(' 1. Replace all @xylabs/ts-scripts-* deps with @xylabs/toolchain in package.json'))\n console.warn(chalk.gray(' 2. Update imports in xy.config.ts files'))\n console.warn(chalk.gray(' 3. Run your package manager install\\n'))\n}\n\nexport async function deprecationMigrate(oldPackage: string): Promise<void> {\n const root = findProjectRoot()\n const pkgPath = PATH.join(root, 'package.json')\n\n if (!existsSync(pkgPath)) return\n\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as Record<string, Record<string, string>>\n\n // Check if any deprecated package is present\n const hasOldDep = DEPRECATED_PACKAGES.some(dep =>\n pkg.dependencies?.[dep] || pkg.devDependencies?.[dep])\n if (!hasOldDep) return\n\n console.warn(chalk.yellow(`\\n⚠ ${oldPackage} is deprecated. Use @xylabs/toolchain instead.\\n`))\n\n const shouldMigrate = await askYesNo(chalk.cyan(' Auto-migrate to @xylabs/toolchain? [y/N] '))\n\n if (!shouldMigrate) {\n printManualInstructions()\n return\n }\n\n // Migrate root package.json (all old packages at once)\n migratePackageJson(pkgPath, 'package.json')\n\n // Migrate root xy.config.ts\n if (replaceAllOldPackagesInFile(PATH.join(root, 'xy.config.ts'))) {\n console.warn(chalk.green(' ✓ Updated xy.config.ts'))\n }\n\n // Migrate all workspace files\n await migrateWorkspaces(root)\n\n // Run install to resolve the new dependency\n const pm = detectPackageManager()\n console.warn(chalk.cyan(`\\n Running ${pm} install...\\n`))\n const result = spawnSync(pm, ['install'], { cwd: root, stdio: 'inherit' })\n\n if (result.status === 0) {\n console.warn(chalk.green(' ✓ Migration complete. Re-run your command.\\n'))\n } else {\n console.warn(chalk.red(` Install failed (exit ${result.status}). Run \"${pm} install\" manually.\\n`))\n }\n\n process.exit(result.status ?? 1)\n}\n","import { existsSync } from 'node:fs'\n\nexport type PackageManagerName = 'pnpm' | 'yarn'\n\nexport function detectPackageManager(): PackageManagerName {\n if (existsSync('pnpm-lock.yaml') || existsSync('pnpm-workspace.yaml')) return 'pnpm'\n return 'yarn'\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B;AAAA,EACE,cAAAA;AAAA,EAAY;AAAA,EAAc;AAAA,OACrB;AACP,OAAO,UAAU;AACjB,SAAS,uBAAuB;AAEhC,OAAO,WAAW;;;ACPlB,SAAS,kBAAkB;AAIpB,SAAS,uBAA2C;AACzD,MAAI,WAAW,gBAAgB,KAAK,WAAW,qBAAqB,EAAG,QAAO;AAC9E,SAAO;AACT;;;ADIA,IAAM,sBAAsB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAAS,kBAA0B;AACjC,SAAO,QAAQ,IAAI,YAAY,QAAQ,IAAI;AAC7C;AAEA,SAAS,SAAS,UAAoC;AACpD,QAAM,KAAK,gBAAgB,EAAE,OAAO,QAAQ,OAAO,QAAQ,QAAQ,OAAO,CAAC;AAC3E,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,OAAG,SAAS,UAAU,CAAC,WAAW;AAChC,SAAG,MAAM;AACT,cAAQ,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,GAAG,CAAC;AAAA,IACrD,CAAC;AAAA,EACH,CAAC;AACH;AAEA,SAAS,4BAA4B,UAA2B;A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CAAe,CAAC;AACzD,QAAM,SAAS,UAAU,IAAI,CAAC,SAAS,GAAG,EAAE,KAAK,MAAM,OAAO,UAAU,CAAC;AAEzE,MAAI,OAAO,WAAW,GAAG;AACvB,YAAQ,KAAK,MAAM,MAAM,qDAAgD,CAAC;AAAA,EAC5E,OAAO;AACL,YAAQ,KAAK,MAAM,IAAI,0BAA0B,OAAO,MAAM,WAAW,EAAE;AAAA,CAAuB,CAAC;AAAA,EACrG;AAEA,UAAQ,KAAK,OAAO,UAAU,CAAC;AACjC;","names":["existsSync","existsSync"]}
|
package/dist/lib/index.mjs
CHANGED
|
@@ -484,6 +484,7 @@ function printWorkspaceCycles(cycles) {
|
|
|
484
484
|
}
|
|
485
485
|
|
|
486
486
|
// src/lib/deprecationMigrate.ts
|
|
487
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
487
488
|
import {
|
|
488
489
|
existsSync as existsSync2,
|
|
489
490
|
readFileSync as readFileSync4,
|
|
@@ -492,6 +493,12 @@ import {
|
|
|
492
493
|
import PATH3 from "path";
|
|
493
494
|
import { createInterface } from "readline";
|
|
494
495
|
import chalk5 from "chalk";
|
|
496
|
+
var DEPRECATED_PACKAGES = [
|
|
497
|
+
"@xylabs/ts-scripts-common",
|
|
498
|
+
"@xylabs/ts-scripts-yarn3",
|
|
499
|
+
"@xylabs/ts-scripts-pnpm",
|
|
500
|
+
"@xylabs/ts-scripts-react-yarn3"
|
|
501
|
+
];
|
|
495
502
|
function findProjectRoot() {
|
|
496
503
|
return process.env.INIT_CWD ?? process.cwd();
|
|
497
504
|
}
|
|
@@ -504,56 +511,64 @@ function askYesNo(question) {
|
|
|
504
511
|
});
|
|
505
512
|
});
|
|
506
513
|
}
|
|
507
|
-
function
|
|
514
|
+
function replaceAllOldPackagesInFile(filePath) {
|
|
508
515
|
if (!existsSync2(filePath)) return false;
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
516
|
+
let content = readFileSync4(filePath, "utf8");
|
|
517
|
+
let changed = false;
|
|
518
|
+
for (const oldPkg of DEPRECATED_PACKAGES) {
|
|
519
|
+
if (content.includes(oldPkg)) {
|
|
520
|
+
content = content.replaceAll(oldPkg, "@xylabs/toolchain");
|
|
521
|
+
changed = true;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (changed) {
|
|
525
|
+
writeFileSync(filePath, content, "utf8");
|
|
526
|
+
}
|
|
527
|
+
return changed;
|
|
521
528
|
}
|
|
522
|
-
function
|
|
523
|
-
if (!existsSync2(
|
|
524
|
-
const
|
|
529
|
+
function migratePackageJson(pkgPath, label) {
|
|
530
|
+
if (!existsSync2(pkgPath)) return false;
|
|
531
|
+
const pkg = JSON.parse(readFileSync4(pkgPath, "utf8"));
|
|
525
532
|
let changed = false;
|
|
526
533
|
for (const field of ["dependencies", "devDependencies", "peerDependencies"]) {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
534
|
+
for (const oldPkg of DEPRECATED_PACKAGES) {
|
|
535
|
+
if (pkg[field]?.[oldPkg]) {
|
|
536
|
+
const ver = pkg[field][oldPkg];
|
|
537
|
+
delete pkg[field][oldPkg];
|
|
538
|
+
if (!pkg[field]["@xylabs/toolchain"]) {
|
|
539
|
+
pkg[field]["@xylabs/toolchain"] = ver;
|
|
540
|
+
}
|
|
541
|
+
changed = true;
|
|
542
|
+
}
|
|
532
543
|
}
|
|
533
544
|
}
|
|
534
545
|
if (changed) {
|
|
535
|
-
writeFileSync(
|
|
546
|
+
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
536
547
|
`, "utf8");
|
|
537
|
-
console.warn(chalk5.green(` \u2713 Updated ${
|
|
548
|
+
console.warn(chalk5.green(` \u2713 Updated ${label}`));
|
|
538
549
|
}
|
|
550
|
+
return changed;
|
|
539
551
|
}
|
|
540
|
-
async function migrateWorkspaces(root
|
|
541
|
-
if (!Array.isArray(workspacesGlob)) return;
|
|
552
|
+
async function migrateWorkspaces(root) {
|
|
542
553
|
const { globSync } = await import("glob");
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
554
|
+
const packageJsonFiles = globSync("**/package.json", {
|
|
555
|
+
cwd: root,
|
|
556
|
+
ignore: ["node_modules/**", "**/node_modules/**", "dist/**", "**/dist/**"]
|
|
557
|
+
});
|
|
558
|
+
for (const relPath of packageJsonFiles) {
|
|
559
|
+
if (relPath === "package.json") continue;
|
|
560
|
+
const dir = PATH3.dirname(relPath);
|
|
561
|
+
migratePackageJson(PATH3.join(root, relPath), relPath);
|
|
562
|
+
const xyConfigPath = PATH3.join(root, dir, "xy.config.ts");
|
|
563
|
+
if (replaceAllOldPackagesInFile(xyConfigPath)) {
|
|
564
|
+
console.warn(chalk5.green(` \u2713 Updated ${dir}/xy.config.ts`));
|
|
550
565
|
}
|
|
551
566
|
}
|
|
552
567
|
}
|
|
553
|
-
function printManualInstructions(
|
|
568
|
+
function printManualInstructions() {
|
|
554
569
|
console.warn(chalk5.gray(" Skipped. To migrate manually:\n"));
|
|
555
|
-
console.warn(chalk5.gray(
|
|
556
|
-
console.warn(chalk5.gray(" 2. Update xy.config.ts
|
|
570
|
+
console.warn(chalk5.gray(" 1. Replace all @xylabs/ts-scripts-* deps with @xylabs/toolchain in package.json"));
|
|
571
|
+
console.warn(chalk5.gray(" 2. Update imports in xy.config.ts files"));
|
|
557
572
|
console.warn(chalk5.gray(" 3. Run your package manager install\n"));
|
|
558
573
|
}
|
|
559
574
|
async function deprecationMigrate(oldPackage) {
|
|
@@ -561,22 +576,33 @@ async function deprecationMigrate(oldPackage) {
|
|
|
561
576
|
const pkgPath = PATH3.join(root, "package.json");
|
|
562
577
|
if (!existsSync2(pkgPath)) return;
|
|
563
578
|
const pkg = JSON.parse(readFileSync4(pkgPath, "utf8"));
|
|
564
|
-
const
|
|
565
|
-
if (!
|
|
579
|
+
const hasOldDep = DEPRECATED_PACKAGES.some((dep) => pkg.dependencies?.[dep] || pkg.devDependencies?.[dep]);
|
|
580
|
+
if (!hasOldDep) return;
|
|
566
581
|
console.warn(chalk5.yellow(`
|
|
567
582
|
\u26A0 ${oldPackage} is deprecated. Use @xylabs/toolchain instead.
|
|
568
583
|
`));
|
|
569
584
|
const shouldMigrate = await askYesNo(chalk5.cyan(" Auto-migrate to @xylabs/toolchain? [y/N] "));
|
|
570
585
|
if (!shouldMigrate) {
|
|
571
|
-
printManualInstructions(
|
|
586
|
+
printManualInstructions();
|
|
572
587
|
return;
|
|
573
588
|
}
|
|
574
|
-
|
|
575
|
-
if (
|
|
576
|
-
console.warn(chalk5.green(" \u2713 Updated xy.config.ts
|
|
589
|
+
migratePackageJson(pkgPath, "package.json");
|
|
590
|
+
if (replaceAllOldPackagesInFile(PATH3.join(root, "xy.config.ts"))) {
|
|
591
|
+
console.warn(chalk5.green(" \u2713 Updated xy.config.ts"));
|
|
577
592
|
}
|
|
578
|
-
await migrateWorkspaces(root
|
|
579
|
-
|
|
593
|
+
await migrateWorkspaces(root);
|
|
594
|
+
const pm = detectPackageManager();
|
|
595
|
+
console.warn(chalk5.cyan(`
|
|
596
|
+
Running ${pm} install...
|
|
597
|
+
`));
|
|
598
|
+
const result = spawnSync3(pm, ["install"], { cwd: root, stdio: "inherit" });
|
|
599
|
+
if (result.status === 0) {
|
|
600
|
+
console.warn(chalk5.green(" \u2713 Migration complete. Re-run your command.\n"));
|
|
601
|
+
} else {
|
|
602
|
+
console.warn(chalk5.red(` Install failed (exit ${result.status}). Run "${pm} install" manually.
|
|
603
|
+
`));
|
|
604
|
+
}
|
|
605
|
+
process.exit(result.status ?? 1);
|
|
580
606
|
}
|
|
581
607
|
|
|
582
608
|
// src/lib/file/constants.ts
|
|
@@ -1044,12 +1070,12 @@ function listRepoTemplates() {
|
|
|
1044
1070
|
}
|
|
1045
1071
|
|
|
1046
1072
|
// src/lib/runInstall.ts
|
|
1047
|
-
import { spawnSync as
|
|
1073
|
+
import { spawnSync as spawnSync4 } from "child_process";
|
|
1048
1074
|
import chalk9 from "chalk";
|
|
1049
1075
|
function runInstall(cwd) {
|
|
1050
1076
|
const pm = detectPackageManager();
|
|
1051
1077
|
console.log(chalk9.gray(`Running ${pm} install...`));
|
|
1052
|
-
const result =
|
|
1078
|
+
const result = spawnSync4(pm, ["install"], {
|
|
1053
1079
|
cwd,
|
|
1054
1080
|
stdio: "inherit"
|
|
1055
1081
|
});
|
|
@@ -1062,7 +1088,7 @@ function runInstall(cwd) {
|
|
|
1062
1088
|
}
|
|
1063
1089
|
|
|
1064
1090
|
// src/lib/runSteps.ts
|
|
1065
|
-
import { spawnSync as
|
|
1091
|
+
import { spawnSync as spawnSync5 } from "child_process";
|
|
1066
1092
|
import { existsSync as existsSync5 } from "fs";
|
|
1067
1093
|
import chalk10 from "chalk";
|
|
1068
1094
|
var runSteps = (name, steps, exitOnFail = true, messages) => {
|
|
@@ -1078,7 +1104,7 @@ var runSteps = (name, steps, exitOnFail = true, messages) => {
|
|
|
1078
1104
|
if (command === "node" && !existsSync5(argList[0])) {
|
|
1079
1105
|
throw new Error(`File not found [${argList[0]}]`);
|
|
1080
1106
|
}
|
|
1081
|
-
const status =
|
|
1107
|
+
const status = spawnSync5(command, Array.isArray(args) ? args : args.split(" "), {
|
|
1082
1108
|
...config2,
|
|
1083
1109
|
encoding: "utf8",
|
|
1084
1110
|
env: { FORCE_COLOR: "3", ...process.env },
|
|
@@ -1161,7 +1187,7 @@ var runXyWithWarning = (command) => {
|
|
|
1161
1187
|
};
|
|
1162
1188
|
|
|
1163
1189
|
// src/lib/tryRunLocalScript.ts
|
|
1164
|
-
import { spawnSync as
|
|
1190
|
+
import { spawnSync as spawnSync6 } from "child_process";
|
|
1165
1191
|
import { readFileSync as readFileSync12 } from "fs";
|
|
1166
1192
|
import PATH7 from "path";
|
|
1167
1193
|
import chalk13 from "chalk";
|
|
@@ -1178,7 +1204,7 @@ function tryRunLocalScript(commandName) {
|
|
|
1178
1204
|
const extraArgs = process.argv.slice(process.argv.indexOf(commandName) + 1);
|
|
1179
1205
|
console.log(chalk13.blue(`Delegating "${commandName}" to local script`));
|
|
1180
1206
|
const pm = getPackageManager();
|
|
1181
|
-
const result =
|
|
1207
|
+
const result = spawnSync6(pm.command, ["run", commandName, ...extraArgs], {
|
|
1182
1208
|
cwd: process.cwd(),
|
|
1183
1209
|
encoding: "utf8",
|
|
1184
1210
|
env: {
|