@xylabs/ts-scripts-yarn3 7.4.22 → 7.4.24
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/claude-settings.mjs +2 -2
- package/dist/actions/claude-settings.mjs.map +1 -1
- package/dist/actions/index.mjs +168 -12
- package/dist/actions/index.mjs.map +1 -1
- package/dist/actions/package-lint.mjs +178 -0
- package/dist/actions/package-lint.mjs.map +1 -0
- package/dist/bin/xy.mjs +204 -32
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +205 -32
- package/dist/index.mjs.map +1 -1
- package/dist/xy/common/claude/index.mjs +2 -2
- package/dist/xy/common/claude/index.mjs.map +1 -1
- package/dist/xy/common/claude/initCommand.mjs +2 -2
- package/dist/xy/common/claude/initCommand.mjs.map +1 -1
- package/dist/xy/common/claude/settingsCommand.mjs +2 -2
- package/dist/xy/common/claude/settingsCommand.mjs.map +1 -1
- package/dist/xy/common/index.mjs +2 -2
- package/dist/xy/common/index.mjs.map +1 -1
- package/dist/xy/index.mjs +204 -32
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/lint/index.mjs +200 -22
- package/dist/xy/lint/index.mjs.map +1 -1
- package/dist/xy/lint/packageLintCommand.mjs +193 -0
- package/dist/xy/lint/packageLintCommand.mjs.map +1 -0
- package/dist/xy/xy.mjs +204 -32
- package/dist/xy/xy.mjs.map +1 -1
- package/package.json +2 -2
- package/templates/gitignore/template.gitignore +11 -0
package/dist/xy/lint/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/xy/lint/cycleCommand.ts
|
|
2
|
-
import
|
|
2
|
+
import chalk15 from "chalk";
|
|
3
3
|
|
|
4
4
|
// src/lib/checkResult.ts
|
|
5
5
|
import chalk from "chalk";
|
|
@@ -90,6 +90,12 @@ var yarnWorkspace = (pkg) => {
|
|
|
90
90
|
return workspace;
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
+
// src/lib/yarn/yarnInitCwd.ts
|
|
94
|
+
var INIT_CWD = () => {
|
|
95
|
+
if (!process.env.INIT_CWD) console.error("Missing INIT_CWD");
|
|
96
|
+
return process.env.INIT_CWD;
|
|
97
|
+
};
|
|
98
|
+
|
|
93
99
|
// src/lib/loadConfig.ts
|
|
94
100
|
import chalk3 from "chalk";
|
|
95
101
|
import { cosmiconfig } from "cosmiconfig";
|
|
@@ -1015,6 +1021,161 @@ var knip = () => {
|
|
|
1015
1021
|
return runSteps("Knip", [["yarn", ["knip", "--dependencies", "--no-exit-code"]]]);
|
|
1016
1022
|
};
|
|
1017
1023
|
|
|
1024
|
+
// src/actions/package-lint.ts
|
|
1025
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
1026
|
+
import PATH from "path";
|
|
1027
|
+
import chalk13 from "chalk";
|
|
1028
|
+
import picomatch from "picomatch";
|
|
1029
|
+
function emptyResult() {
|
|
1030
|
+
return {
|
|
1031
|
+
errors: [],
|
|
1032
|
+
fixable: [],
|
|
1033
|
+
warnings: []
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
function readRootPackageJson(cwd) {
|
|
1037
|
+
const raw = readFileSync(PATH.resolve(cwd, "package.json"), "utf8");
|
|
1038
|
+
return JSON.parse(raw);
|
|
1039
|
+
}
|
|
1040
|
+
function writeRootPackageJson(cwd, pkg) {
|
|
1041
|
+
const path6 = PATH.resolve(cwd, "package.json");
|
|
1042
|
+
writeFileSync(path6, `${JSON.stringify(pkg, null, 2)}
|
|
1043
|
+
`, "utf8");
|
|
1044
|
+
}
|
|
1045
|
+
function isMonorepo(pkg) {
|
|
1046
|
+
const workspaces = pkg.workspaces;
|
|
1047
|
+
return Array.isArray(workspaces) && workspaces.length > 0;
|
|
1048
|
+
}
|
|
1049
|
+
function checkPackagesFolder(workspaces) {
|
|
1050
|
+
const result = emptyResult();
|
|
1051
|
+
for (const { location, name } of workspaces) {
|
|
1052
|
+
if (location === ".") continue;
|
|
1053
|
+
if (!location.startsWith("packages/") && !location.startsWith("packages\\")) {
|
|
1054
|
+
result.errors.push(`${name} (${location}) is not inside a packages/ folder`);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
return result;
|
|
1058
|
+
}
|
|
1059
|
+
function checkRootPrivate(pkg) {
|
|
1060
|
+
const result = emptyResult();
|
|
1061
|
+
if (!pkg.private) {
|
|
1062
|
+
result.fixable.push("Root package.json must be private to prevent accidental publishing");
|
|
1063
|
+
}
|
|
1064
|
+
return result;
|
|
1065
|
+
}
|
|
1066
|
+
function fixRootPrivate(cwd, pkg) {
|
|
1067
|
+
pkg.private = true;
|
|
1068
|
+
writeRootPackageJson(cwd, pkg);
|
|
1069
|
+
console.log(chalk13.green(' \u2714 Fixed: set "private": true in root package.json'));
|
|
1070
|
+
}
|
|
1071
|
+
function checkNoPublishConfigOnPrivate(pkg) {
|
|
1072
|
+
const result = emptyResult();
|
|
1073
|
+
if (pkg.private && pkg.publishConfig) {
|
|
1074
|
+
result.fixable.push("Root package.json has publishConfig but is private \u2014 publishConfig is unnecessary");
|
|
1075
|
+
}
|
|
1076
|
+
return result;
|
|
1077
|
+
}
|
|
1078
|
+
function fixNoPublishConfigOnPrivate(cwd, pkg) {
|
|
1079
|
+
delete pkg.publishConfig;
|
|
1080
|
+
writeRootPackageJson(cwd, pkg);
|
|
1081
|
+
console.log(chalk13.green(" \u2714 Fixed: removed publishConfig from private root package.json"));
|
|
1082
|
+
}
|
|
1083
|
+
function checkDiscoverable(pkg, workspaces) {
|
|
1084
|
+
const result = emptyResult();
|
|
1085
|
+
const globs = pkg.workspaces;
|
|
1086
|
+
const matchers = globs.map((glob) => picomatch(glob));
|
|
1087
|
+
const isMatch = (location) => matchers.some((m) => m(location));
|
|
1088
|
+
for (const { location, name } of workspaces) {
|
|
1089
|
+
if (location === ".") continue;
|
|
1090
|
+
if (!isMatch(location)) {
|
|
1091
|
+
result.errors.push(`${name} (${location}) is not matched by any workspace glob in package.json`);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
return result;
|
|
1095
|
+
}
|
|
1096
|
+
function logResults(label, result, fix2) {
|
|
1097
|
+
let errors = 0;
|
|
1098
|
+
let fixed = 0;
|
|
1099
|
+
for (const error of result.errors) {
|
|
1100
|
+
console.log(chalk13.red(` \u2717 ${error}`));
|
|
1101
|
+
errors++;
|
|
1102
|
+
}
|
|
1103
|
+
for (const fixable of result.fixable) {
|
|
1104
|
+
if (fix2) {
|
|
1105
|
+
fixed++;
|
|
1106
|
+
} else {
|
|
1107
|
+
console.log(chalk13.red(` \u2717 ${fixable} (fixable)`));
|
|
1108
|
+
errors++;
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
for (const warning of result.warnings) {
|
|
1112
|
+
console.log(chalk13.yellow(` \u26A0 ${warning}`));
|
|
1113
|
+
}
|
|
1114
|
+
if (errors === 0 && fixed === 0 && result.warnings.length === 0) {
|
|
1115
|
+
console.log(chalk13.green(` \u2713 ${label}`));
|
|
1116
|
+
}
|
|
1117
|
+
return { errors, fixed };
|
|
1118
|
+
}
|
|
1119
|
+
function runChecks(entries, cwd, pkg, fix2) {
|
|
1120
|
+
let totalErrors = 0;
|
|
1121
|
+
let totalFixed = 0;
|
|
1122
|
+
for (const entry of entries) {
|
|
1123
|
+
const result = entry.check();
|
|
1124
|
+
const log = logResults(entry.label, result, fix2);
|
|
1125
|
+
if (fix2 && entry.fix && result.fixable.length > 0) {
|
|
1126
|
+
entry.fix(cwd, pkg);
|
|
1127
|
+
}
|
|
1128
|
+
totalErrors += log.errors;
|
|
1129
|
+
totalFixed += log.fixed;
|
|
1130
|
+
}
|
|
1131
|
+
return { errors: totalErrors, fixed: totalFixed };
|
|
1132
|
+
}
|
|
1133
|
+
function logSummary(errors, fixed) {
|
|
1134
|
+
if (fixed > 0) {
|
|
1135
|
+
console.log(chalk13.green(`
|
|
1136
|
+
Fixed ${fixed} issue(s)`));
|
|
1137
|
+
}
|
|
1138
|
+
if (errors > 0) {
|
|
1139
|
+
console.log(chalk13.red(`
|
|
1140
|
+
${errors} error(s) found`));
|
|
1141
|
+
} else if (fixed === 0) {
|
|
1142
|
+
console.log(chalk13.green("\n All checks passed"));
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
function packageLintMonorepo(fix2 = false) {
|
|
1146
|
+
const cwd = INIT_CWD() ?? process.cwd();
|
|
1147
|
+
let pkg;
|
|
1148
|
+
try {
|
|
1149
|
+
pkg = readRootPackageJson(cwd);
|
|
1150
|
+
} catch {
|
|
1151
|
+
console.error(chalk13.red("Could not read package.json"));
|
|
1152
|
+
return 1;
|
|
1153
|
+
}
|
|
1154
|
+
if (!isMonorepo(pkg)) {
|
|
1155
|
+
console.log(chalk13.gray("Not a monorepo \u2014 skipping package-lint checks"));
|
|
1156
|
+
return 0;
|
|
1157
|
+
}
|
|
1158
|
+
console.log(chalk13.green("Package Lint"));
|
|
1159
|
+
const workspaces = yarnWorkspaces();
|
|
1160
|
+
const checks = [
|
|
1161
|
+
{
|
|
1162
|
+
check: () => checkRootPrivate(pkg),
|
|
1163
|
+
fix: fixRootPrivate,
|
|
1164
|
+
label: "Root package is private"
|
|
1165
|
+
},
|
|
1166
|
+
{
|
|
1167
|
+
check: () => checkNoPublishConfigOnPrivate(pkg),
|
|
1168
|
+
fix: fixNoPublishConfigOnPrivate,
|
|
1169
|
+
label: "No publishConfig on private root"
|
|
1170
|
+
},
|
|
1171
|
+
{ check: () => checkPackagesFolder(workspaces), label: "All packages are in packages/ folder" },
|
|
1172
|
+
{ check: () => checkDiscoverable(pkg, workspaces), label: "All packages are discoverable from workspace globs" }
|
|
1173
|
+
];
|
|
1174
|
+
const { errors, fixed } = runChecks(checks, cwd, pkg, fix2);
|
|
1175
|
+
logSummary(errors, fixed);
|
|
1176
|
+
return errors > 0 ? 1 : 0;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1018
1179
|
// src/actions/publint.ts
|
|
1019
1180
|
var publint = async ({ verbose, pkg }) => {
|
|
1020
1181
|
return pkg === void 0 ? publintAll({ verbose }) : await publintPackage({ pkg, verbose });
|
|
@@ -1028,13 +1189,13 @@ var publintAll = ({ verbose }) => {
|
|
|
1028
1189
|
};
|
|
1029
1190
|
|
|
1030
1191
|
// src/actions/relint.ts
|
|
1031
|
-
import
|
|
1192
|
+
import chalk14 from "chalk";
|
|
1032
1193
|
var relintPackage = ({
|
|
1033
1194
|
pkg,
|
|
1034
1195
|
fix: fix2,
|
|
1035
1196
|
verbose
|
|
1036
1197
|
}) => {
|
|
1037
|
-
console.log(
|
|
1198
|
+
console.log(chalk14.gray(`${fix2 ? "Fix" : "Lint"} [${pkg}]`));
|
|
1038
1199
|
const start = Date.now();
|
|
1039
1200
|
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [${pkg}]`, [
|
|
1040
1201
|
["yarn", [
|
|
@@ -1044,7 +1205,7 @@ var relintPackage = ({
|
|
|
1044
1205
|
fix2 ? "package-fix" : verbose ? "package-lint-verbose" : "package-lint"
|
|
1045
1206
|
]]
|
|
1046
1207
|
]);
|
|
1047
|
-
console.log(
|
|
1208
|
+
console.log(chalk14.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk14.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk14.gray("seconds")}`));
|
|
1048
1209
|
return result;
|
|
1049
1210
|
};
|
|
1050
1211
|
var relint = ({
|
|
@@ -1064,13 +1225,13 @@ var relint = ({
|
|
|
1064
1225
|
});
|
|
1065
1226
|
};
|
|
1066
1227
|
var relintAllPackages = ({ fix: fix2 = false } = {}) => {
|
|
1067
|
-
console.log(
|
|
1228
|
+
console.log(chalk14.gray(`${fix2 ? "Fix" : "Lint"} [All-Packages]`));
|
|
1068
1229
|
const start = Date.now();
|
|
1069
1230
|
const fixOptions = fix2 ? ["--fix"] : [];
|
|
1070
1231
|
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [All-Packages]`, [
|
|
1071
1232
|
["yarn", ["eslint", ...fixOptions]]
|
|
1072
1233
|
]);
|
|
1073
|
-
console.log(
|
|
1234
|
+
console.log(chalk14.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk14.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk14.gray("seconds")}`));
|
|
1074
1235
|
return result;
|
|
1075
1236
|
};
|
|
1076
1237
|
|
|
@@ -1095,12 +1256,12 @@ var cycleCommand = {
|
|
|
1095
1256
|
const start = Date.now();
|
|
1096
1257
|
if (argv.verbose) console.log("Cycle");
|
|
1097
1258
|
process.exitCode = await cycle({ pkg: argv.package });
|
|
1098
|
-
console.log(
|
|
1259
|
+
console.log(chalk15.blue(`Finished in ${Date.now() - start}ms`));
|
|
1099
1260
|
}
|
|
1100
1261
|
};
|
|
1101
1262
|
|
|
1102
1263
|
// src/xy/lint/deplintCommand.ts
|
|
1103
|
-
import
|
|
1264
|
+
import chalk16 from "chalk";
|
|
1104
1265
|
var deplintCommand = {
|
|
1105
1266
|
command: "deplint [package]",
|
|
1106
1267
|
describe: "Deplint - Run Deplint",
|
|
@@ -1138,12 +1299,12 @@ var deplintCommand = {
|
|
|
1138
1299
|
peerDeps: !!argv.peerDeps,
|
|
1139
1300
|
verbose: !!argv.verbose
|
|
1140
1301
|
});
|
|
1141
|
-
console.log(
|
|
1302
|
+
console.log(chalk16.blue(`Finished in ${Date.now() - start}ms`));
|
|
1142
1303
|
}
|
|
1143
1304
|
};
|
|
1144
1305
|
|
|
1145
1306
|
// src/xy/lint/fixCommand.ts
|
|
1146
|
-
import
|
|
1307
|
+
import chalk17 from "chalk";
|
|
1147
1308
|
var fixCommand = {
|
|
1148
1309
|
command: "fix [package]",
|
|
1149
1310
|
describe: "Fix - Run Eslint w/fix",
|
|
@@ -1154,12 +1315,12 @@ var fixCommand = {
|
|
|
1154
1315
|
const start = Date.now();
|
|
1155
1316
|
if (argv.verbose) console.log("Fix");
|
|
1156
1317
|
process.exitCode = fix();
|
|
1157
|
-
console.log(
|
|
1318
|
+
console.log(chalk17.blue(`Finished in ${Date.now() - start}ms`));
|
|
1158
1319
|
}
|
|
1159
1320
|
};
|
|
1160
1321
|
|
|
1161
1322
|
// src/xy/lint/knipCommand.ts
|
|
1162
|
-
import
|
|
1323
|
+
import chalk18 from "chalk";
|
|
1163
1324
|
var knipCommand = {
|
|
1164
1325
|
command: "knip",
|
|
1165
1326
|
describe: "Knip - Run Knip",
|
|
@@ -1170,12 +1331,12 @@ var knipCommand = {
|
|
|
1170
1331
|
if (argv.verbose) console.log("Knip");
|
|
1171
1332
|
const start = Date.now();
|
|
1172
1333
|
process.exitCode = knip();
|
|
1173
|
-
console.log(
|
|
1334
|
+
console.log(chalk18.blue(`Knip finished in ${Date.now() - start}ms`));
|
|
1174
1335
|
}
|
|
1175
1336
|
};
|
|
1176
1337
|
|
|
1177
1338
|
// src/xy/lint/lintCommand.ts
|
|
1178
|
-
import
|
|
1339
|
+
import chalk19 from "chalk";
|
|
1179
1340
|
var lintCommand = {
|
|
1180
1341
|
command: "lint [package]",
|
|
1181
1342
|
describe: "Lint - Run Eslint",
|
|
@@ -1204,12 +1365,29 @@ var lintCommand = {
|
|
|
1204
1365
|
cache: argv.cache,
|
|
1205
1366
|
verbose: !!argv.verbose
|
|
1206
1367
|
});
|
|
1207
|
-
console.log(
|
|
1368
|
+
console.log(chalk19.blue(`Finished in ${Date.now() - start}ms`));
|
|
1369
|
+
}
|
|
1370
|
+
};
|
|
1371
|
+
|
|
1372
|
+
// src/xy/lint/packageLintCommand.ts
|
|
1373
|
+
var packageLintCommand = {
|
|
1374
|
+
builder: (yargs) => {
|
|
1375
|
+
return yargs.option("fix", {
|
|
1376
|
+
default: false,
|
|
1377
|
+
description: "Auto-fix fixable issues",
|
|
1378
|
+
type: "boolean"
|
|
1379
|
+
});
|
|
1380
|
+
},
|
|
1381
|
+
command: "package-lint",
|
|
1382
|
+
describe: "Package Lint - Check monorepo package structure",
|
|
1383
|
+
handler: (argv) => {
|
|
1384
|
+
if (argv.verbose) console.log("Package Lint");
|
|
1385
|
+
process.exitCode = packageLintMonorepo(!!argv.fix);
|
|
1208
1386
|
}
|
|
1209
1387
|
};
|
|
1210
1388
|
|
|
1211
1389
|
// src/xy/lint/publintCommand.ts
|
|
1212
|
-
import
|
|
1390
|
+
import chalk20 from "chalk";
|
|
1213
1391
|
var publintCommand = {
|
|
1214
1392
|
command: "publint [package]",
|
|
1215
1393
|
describe: "Publint - Run Publint",
|
|
@@ -1220,12 +1398,12 @@ var publintCommand = {
|
|
|
1220
1398
|
if (argv.verbose) console.log("Publint");
|
|
1221
1399
|
const start = Date.now();
|
|
1222
1400
|
process.exitCode = await publint({ pkg: argv.package, verbose: !!argv.verbose });
|
|
1223
|
-
console.log(
|
|
1401
|
+
console.log(chalk20.blue(`Finished in ${Date.now() - start}ms`));
|
|
1224
1402
|
}
|
|
1225
1403
|
};
|
|
1226
1404
|
|
|
1227
1405
|
// src/xy/lint/relintCommand.ts
|
|
1228
|
-
import
|
|
1406
|
+
import chalk21 from "chalk";
|
|
1229
1407
|
var relintCommand = {
|
|
1230
1408
|
command: "relint [package]",
|
|
1231
1409
|
describe: "Relint - Clean & Lint",
|
|
@@ -1236,12 +1414,12 @@ var relintCommand = {
|
|
|
1236
1414
|
if (argv.verbose) console.log("Relinting");
|
|
1237
1415
|
const start = Date.now();
|
|
1238
1416
|
process.exitCode = relint();
|
|
1239
|
-
console.log(
|
|
1417
|
+
console.log(chalk21.blue(`Finished in ${Date.now() - start}ms`));
|
|
1240
1418
|
}
|
|
1241
1419
|
};
|
|
1242
1420
|
|
|
1243
1421
|
// src/xy/lint/sonarCommand.ts
|
|
1244
|
-
import
|
|
1422
|
+
import chalk22 from "chalk";
|
|
1245
1423
|
var sonarCommand = {
|
|
1246
1424
|
command: "sonar",
|
|
1247
1425
|
describe: "Sonar - Run Sonar Check",
|
|
@@ -1252,13 +1430,13 @@ var sonarCommand = {
|
|
|
1252
1430
|
const start = Date.now();
|
|
1253
1431
|
if (argv.verbose) console.log("Sonar Check");
|
|
1254
1432
|
process.exitCode = sonar();
|
|
1255
|
-
console.log(
|
|
1433
|
+
console.log(chalk22.blue(`Finished in ${Date.now() - start}ms`));
|
|
1256
1434
|
}
|
|
1257
1435
|
};
|
|
1258
1436
|
|
|
1259
1437
|
// src/xy/lint/index.ts
|
|
1260
1438
|
var xyLintCommands = (args) => {
|
|
1261
|
-
return args.command(cycleCommand).command(lintCommand).command(deplintCommand).command(fixCommand).command(relintCommand).command(publintCommand).command(knipCommand).command(sonarCommand);
|
|
1439
|
+
return args.command(cycleCommand).command(lintCommand).command(deplintCommand).command(fixCommand).command(relintCommand).command(publintCommand).command(knipCommand).command(packageLintCommand).command(sonarCommand);
|
|
1262
1440
|
};
|
|
1263
1441
|
export {
|
|
1264
1442
|
xyLintCommands
|