@xylabs/ts-scripts-yarn3 7.4.22 → 7.4.23

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/xy/index.mjs CHANGED
@@ -988,8 +988,8 @@ var DEFAULT_SETTINGS = {
988
988
  "Skill"
989
989
  ],
990
990
  deny: [
991
- "Bash(git push --force*)",
992
- "Bash(git reset --hard*)",
991
+ "Bash(git push --force *)",
992
+ "Bash(git reset --hard *)",
993
993
  "Bash(rm -rf /*)"
994
994
  ]
995
995
  }
@@ -2417,6 +2417,161 @@ var license = async (pkg) => {
2417
2417
  var filename = ".npmignore";
2418
2418
  var npmignoreGen = (pkg) => generateIgnoreFiles(filename, pkg);
2419
2419
 
2420
+ // src/actions/package-lint.ts
2421
+ import { readFileSync as readFileSync13, writeFileSync as writeFileSync6 } from "fs";
2422
+ import PATH9 from "path";
2423
+ import chalk30 from "chalk";
2424
+ import picomatch from "picomatch";
2425
+ function emptyResult() {
2426
+ return {
2427
+ errors: [],
2428
+ fixable: [],
2429
+ warnings: []
2430
+ };
2431
+ }
2432
+ function readRootPackageJson(cwd) {
2433
+ const raw = readFileSync13(PATH9.resolve(cwd, "package.json"), "utf8");
2434
+ return JSON.parse(raw);
2435
+ }
2436
+ function writeRootPackageJson(cwd, pkg) {
2437
+ const path8 = PATH9.resolve(cwd, "package.json");
2438
+ writeFileSync6(path8, `${JSON.stringify(pkg, null, 2)}
2439
+ `, "utf8");
2440
+ }
2441
+ function isMonorepo(pkg) {
2442
+ const workspaces = pkg.workspaces;
2443
+ return Array.isArray(workspaces) && workspaces.length > 0;
2444
+ }
2445
+ function checkPackagesFolder(workspaces) {
2446
+ const result = emptyResult();
2447
+ for (const { location, name } of workspaces) {
2448
+ if (location === ".") continue;
2449
+ if (!location.startsWith("packages/") && !location.startsWith("packages\\")) {
2450
+ result.errors.push(`${name} (${location}) is not inside a packages/ folder`);
2451
+ }
2452
+ }
2453
+ return result;
2454
+ }
2455
+ function checkRootPrivate(pkg) {
2456
+ const result = emptyResult();
2457
+ if (!pkg.private) {
2458
+ result.fixable.push("Root package.json must be private to prevent accidental publishing");
2459
+ }
2460
+ return result;
2461
+ }
2462
+ function fixRootPrivate(cwd, pkg) {
2463
+ pkg.private = true;
2464
+ writeRootPackageJson(cwd, pkg);
2465
+ console.log(chalk30.green(' \u2714 Fixed: set "private": true in root package.json'));
2466
+ }
2467
+ function checkNoPublishConfigOnPrivate(pkg) {
2468
+ const result = emptyResult();
2469
+ if (pkg.private && pkg.publishConfig) {
2470
+ result.fixable.push("Root package.json has publishConfig but is private \u2014 publishConfig is unnecessary");
2471
+ }
2472
+ return result;
2473
+ }
2474
+ function fixNoPublishConfigOnPrivate(cwd, pkg) {
2475
+ delete pkg.publishConfig;
2476
+ writeRootPackageJson(cwd, pkg);
2477
+ console.log(chalk30.green(" \u2714 Fixed: removed publishConfig from private root package.json"));
2478
+ }
2479
+ function checkDiscoverable(pkg, workspaces) {
2480
+ const result = emptyResult();
2481
+ const globs = pkg.workspaces;
2482
+ const matchers = globs.map((glob2) => picomatch(glob2));
2483
+ const isMatch = (location) => matchers.some((m) => m(location));
2484
+ for (const { location, name } of workspaces) {
2485
+ if (location === ".") continue;
2486
+ if (!isMatch(location)) {
2487
+ result.errors.push(`${name} (${location}) is not matched by any workspace glob in package.json`);
2488
+ }
2489
+ }
2490
+ return result;
2491
+ }
2492
+ function logResults(label, result, fix2) {
2493
+ let errors = 0;
2494
+ let fixed = 0;
2495
+ for (const error of result.errors) {
2496
+ console.log(chalk30.red(` \u2717 ${error}`));
2497
+ errors++;
2498
+ }
2499
+ for (const fixable of result.fixable) {
2500
+ if (fix2) {
2501
+ fixed++;
2502
+ } else {
2503
+ console.log(chalk30.red(` \u2717 ${fixable} (fixable)`));
2504
+ errors++;
2505
+ }
2506
+ }
2507
+ for (const warning of result.warnings) {
2508
+ console.log(chalk30.yellow(` \u26A0 ${warning}`));
2509
+ }
2510
+ if (errors === 0 && fixed === 0 && result.warnings.length === 0) {
2511
+ console.log(chalk30.green(` \u2713 ${label}`));
2512
+ }
2513
+ return { errors, fixed };
2514
+ }
2515
+ function runChecks(entries, cwd, pkg, fix2) {
2516
+ let totalErrors = 0;
2517
+ let totalFixed = 0;
2518
+ for (const entry of entries) {
2519
+ const result = entry.check();
2520
+ const log = logResults(entry.label, result, fix2);
2521
+ if (fix2 && entry.fix && result.fixable.length > 0) {
2522
+ entry.fix(cwd, pkg);
2523
+ }
2524
+ totalErrors += log.errors;
2525
+ totalFixed += log.fixed;
2526
+ }
2527
+ return { errors: totalErrors, fixed: totalFixed };
2528
+ }
2529
+ function logSummary(errors, fixed) {
2530
+ if (fixed > 0) {
2531
+ console.log(chalk30.green(`
2532
+ Fixed ${fixed} issue(s)`));
2533
+ }
2534
+ if (errors > 0) {
2535
+ console.log(chalk30.red(`
2536
+ ${errors} error(s) found`));
2537
+ } else if (fixed === 0) {
2538
+ console.log(chalk30.green("\n All checks passed"));
2539
+ }
2540
+ }
2541
+ function packageLintMonorepo(fix2 = false) {
2542
+ const cwd = INIT_CWD() ?? process.cwd();
2543
+ let pkg;
2544
+ try {
2545
+ pkg = readRootPackageJson(cwd);
2546
+ } catch {
2547
+ console.error(chalk30.red("Could not read package.json"));
2548
+ return 1;
2549
+ }
2550
+ if (!isMonorepo(pkg)) {
2551
+ console.log(chalk30.gray("Not a monorepo \u2014 skipping package-lint checks"));
2552
+ return 0;
2553
+ }
2554
+ console.log(chalk30.green("Package Lint"));
2555
+ const workspaces = yarnWorkspaces();
2556
+ const checks = [
2557
+ {
2558
+ check: () => checkRootPrivate(pkg),
2559
+ fix: fixRootPrivate,
2560
+ label: "Root package is private"
2561
+ },
2562
+ {
2563
+ check: () => checkNoPublishConfigOnPrivate(pkg),
2564
+ fix: fixNoPublishConfigOnPrivate,
2565
+ label: "No publishConfig on private root"
2566
+ },
2567
+ { check: () => checkPackagesFolder(workspaces), label: "All packages are in packages/ folder" },
2568
+ { check: () => checkDiscoverable(pkg, workspaces), label: "All packages are discoverable from workspace globs" }
2569
+ ];
2570
+ const { errors, fixed } = runChecks(checks, cwd, pkg, fix2);
2571
+ logSummary(errors, fixed);
2572
+ return errors > 0 ? 1 : 0;
2573
+ }
2574
+
2420
2575
  // src/actions/publint.ts
2421
2576
  var publint = async ({ verbose, pkg }) => {
2422
2577
  return pkg === void 0 ? publintAll({ verbose }) : await publintPackage({ pkg, verbose });
@@ -2470,7 +2625,7 @@ var rebuild = ({ target }) => {
2470
2625
  };
2471
2626
 
2472
2627
  // src/actions/recompile.ts
2473
- import chalk30 from "chalk";
2628
+ import chalk31 from "chalk";
2474
2629
  var recompile = async ({
2475
2630
  verbose,
2476
2631
  target,
@@ -2506,7 +2661,7 @@ var recompileAll = async ({
2506
2661
  const incrementalOptions = incremental ? ["--since", "-Apt", "--topological-dev"] : ["--parallel", "-Apt", "--topological-dev"];
2507
2662
  const jobsOptions = jobs ? ["-j", `${jobs}`] : [];
2508
2663
  if (jobs) {
2509
- console.log(chalk30.blue(`Jobs set to [${jobs}]`));
2664
+ console.log(chalk31.blue(`Jobs set to [${jobs}]`));
2510
2665
  }
2511
2666
  const result = await runStepsAsync(`Recompile${incremental ? "-Incremental" : ""} [All]`, [
2512
2667
  [
@@ -2537,7 +2692,7 @@ var recompileAll = async ({
2537
2692
  ]
2538
2693
  ]);
2539
2694
  console.log(
2540
- `${chalk30.gray("Recompiled in")} [${chalk30.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk30.gray("seconds")}`
2695
+ `${chalk31.gray("Recompiled in")} [${chalk31.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk31.gray("seconds")}`
2541
2696
  );
2542
2697
  return result;
2543
2698
  };
@@ -2568,13 +2723,13 @@ var reinstall = () => {
2568
2723
  };
2569
2724
 
2570
2725
  // src/actions/relint.ts
2571
- import chalk31 from "chalk";
2726
+ import chalk32 from "chalk";
2572
2727
  var relintPackage = ({
2573
2728
  pkg,
2574
2729
  fix: fix2,
2575
2730
  verbose
2576
2731
  }) => {
2577
- console.log(chalk31.gray(`${fix2 ? "Fix" : "Lint"} [${pkg}]`));
2732
+ console.log(chalk32.gray(`${fix2 ? "Fix" : "Lint"} [${pkg}]`));
2578
2733
  const start = Date.now();
2579
2734
  const result = runSteps(`${fix2 ? "Fix" : "Lint"} [${pkg}]`, [
2580
2735
  ["yarn", [
@@ -2584,7 +2739,7 @@ var relintPackage = ({
2584
2739
  fix2 ? "package-fix" : verbose ? "package-lint-verbose" : "package-lint"
2585
2740
  ]]
2586
2741
  ]);
2587
- console.log(chalk31.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk31.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk31.gray("seconds")}`));
2742
+ console.log(chalk32.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk32.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk32.gray("seconds")}`));
2588
2743
  return result;
2589
2744
  };
2590
2745
  var relint = ({
@@ -2604,13 +2759,13 @@ var relint = ({
2604
2759
  });
2605
2760
  };
2606
2761
  var relintAllPackages = ({ fix: fix2 = false } = {}) => {
2607
- console.log(chalk31.gray(`${fix2 ? "Fix" : "Lint"} [All-Packages]`));
2762
+ console.log(chalk32.gray(`${fix2 ? "Fix" : "Lint"} [All-Packages]`));
2608
2763
  const start = Date.now();
2609
2764
  const fixOptions = fix2 ? ["--fix"] : [];
2610
2765
  const result = runSteps(`${fix2 ? "Fix" : "Lint"} [All-Packages]`, [
2611
2766
  ["yarn", ["eslint", ...fixOptions]]
2612
2767
  ]);
2613
- console.log(chalk31.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk31.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk31.gray("seconds")}`));
2768
+ console.log(chalk32.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk32.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk32.gray("seconds")}`));
2614
2769
  return result;
2615
2770
  };
2616
2771
 
@@ -2628,10 +2783,10 @@ var sonar = () => {
2628
2783
  };
2629
2784
 
2630
2785
  // src/actions/statics.ts
2631
- import chalk32 from "chalk";
2786
+ import chalk33 from "chalk";
2632
2787
  var DefaultDependencies = ["axios", "@xylabs/pixel", "react", "graphql", "react-router", "@mui/material", "@mui/system"];
2633
2788
  var statics = () => {
2634
- console.log(chalk32.green("Check Required Static Dependencies"));
2789
+ console.log(chalk33.green("Check Required Static Dependencies"));
2635
2790
  const statics2 = parsedPackageJSON()?.xy?.deps?.statics;
2636
2791
  return detectDuplicateDependencies(statics2, DefaultDependencies);
2637
2792
  };
@@ -3212,7 +3367,7 @@ var xyInstallCommands = (args) => {
3212
3367
  };
3213
3368
 
3214
3369
  // src/xy/lint/cycleCommand.ts
3215
- import chalk33 from "chalk";
3370
+ import chalk34 from "chalk";
3216
3371
  var cycleCommand = {
3217
3372
  command: "cycle [package]",
3218
3373
  describe: "Cycle - Check for dependency cycles",
@@ -3223,12 +3378,12 @@ var cycleCommand = {
3223
3378
  const start = Date.now();
3224
3379
  if (argv.verbose) console.log("Cycle");
3225
3380
  process.exitCode = await cycle({ pkg: argv.package });
3226
- console.log(chalk33.blue(`Finished in ${Date.now() - start}ms`));
3381
+ console.log(chalk34.blue(`Finished in ${Date.now() - start}ms`));
3227
3382
  }
3228
3383
  };
3229
3384
 
3230
3385
  // src/xy/lint/deplintCommand.ts
3231
- import chalk34 from "chalk";
3386
+ import chalk35 from "chalk";
3232
3387
  var deplintCommand = {
3233
3388
  command: "deplint [package]",
3234
3389
  describe: "Deplint - Run Deplint",
@@ -3266,12 +3421,12 @@ var deplintCommand = {
3266
3421
  peerDeps: !!argv.peerDeps,
3267
3422
  verbose: !!argv.verbose
3268
3423
  });
3269
- console.log(chalk34.blue(`Finished in ${Date.now() - start}ms`));
3424
+ console.log(chalk35.blue(`Finished in ${Date.now() - start}ms`));
3270
3425
  }
3271
3426
  };
3272
3427
 
3273
3428
  // src/xy/lint/fixCommand.ts
3274
- import chalk35 from "chalk";
3429
+ import chalk36 from "chalk";
3275
3430
  var fixCommand = {
3276
3431
  command: "fix [package]",
3277
3432
  describe: "Fix - Run Eslint w/fix",
@@ -3282,12 +3437,12 @@ var fixCommand = {
3282
3437
  const start = Date.now();
3283
3438
  if (argv.verbose) console.log("Fix");
3284
3439
  process.exitCode = fix();
3285
- console.log(chalk35.blue(`Finished in ${Date.now() - start}ms`));
3440
+ console.log(chalk36.blue(`Finished in ${Date.now() - start}ms`));
3286
3441
  }
3287
3442
  };
3288
3443
 
3289
3444
  // src/xy/lint/knipCommand.ts
3290
- import chalk36 from "chalk";
3445
+ import chalk37 from "chalk";
3291
3446
  var knipCommand = {
3292
3447
  command: "knip",
3293
3448
  describe: "Knip - Run Knip",
@@ -3298,12 +3453,12 @@ var knipCommand = {
3298
3453
  if (argv.verbose) console.log("Knip");
3299
3454
  const start = Date.now();
3300
3455
  process.exitCode = knip();
3301
- console.log(chalk36.blue(`Knip finished in ${Date.now() - start}ms`));
3456
+ console.log(chalk37.blue(`Knip finished in ${Date.now() - start}ms`));
3302
3457
  }
3303
3458
  };
3304
3459
 
3305
3460
  // src/xy/lint/lintCommand.ts
3306
- import chalk37 from "chalk";
3461
+ import chalk38 from "chalk";
3307
3462
  var lintCommand = {
3308
3463
  command: "lint [package]",
3309
3464
  describe: "Lint - Run Eslint",
@@ -3332,12 +3487,29 @@ var lintCommand = {
3332
3487
  cache: argv.cache,
3333
3488
  verbose: !!argv.verbose
3334
3489
  });
3335
- console.log(chalk37.blue(`Finished in ${Date.now() - start}ms`));
3490
+ console.log(chalk38.blue(`Finished in ${Date.now() - start}ms`));
3491
+ }
3492
+ };
3493
+
3494
+ // src/xy/lint/packageLintCommand.ts
3495
+ var packageLintCommand = {
3496
+ builder: (yargs2) => {
3497
+ return yargs2.option("fix", {
3498
+ default: false,
3499
+ description: "Auto-fix fixable issues",
3500
+ type: "boolean"
3501
+ });
3502
+ },
3503
+ command: "package-lint",
3504
+ describe: "Package Lint - Check monorepo package structure",
3505
+ handler: (argv) => {
3506
+ if (argv.verbose) console.log("Package Lint");
3507
+ process.exitCode = packageLintMonorepo(!!argv.fix);
3336
3508
  }
3337
3509
  };
3338
3510
 
3339
3511
  // src/xy/lint/publintCommand.ts
3340
- import chalk38 from "chalk";
3512
+ import chalk39 from "chalk";
3341
3513
  var publintCommand = {
3342
3514
  command: "publint [package]",
3343
3515
  describe: "Publint - Run Publint",
@@ -3348,12 +3520,12 @@ var publintCommand = {
3348
3520
  if (argv.verbose) console.log("Publint");
3349
3521
  const start = Date.now();
3350
3522
  process.exitCode = await publint({ pkg: argv.package, verbose: !!argv.verbose });
3351
- console.log(chalk38.blue(`Finished in ${Date.now() - start}ms`));
3523
+ console.log(chalk39.blue(`Finished in ${Date.now() - start}ms`));
3352
3524
  }
3353
3525
  };
3354
3526
 
3355
3527
  // src/xy/lint/relintCommand.ts
3356
- import chalk39 from "chalk";
3528
+ import chalk40 from "chalk";
3357
3529
  var relintCommand = {
3358
3530
  command: "relint [package]",
3359
3531
  describe: "Relint - Clean & Lint",
@@ -3364,12 +3536,12 @@ var relintCommand = {
3364
3536
  if (argv.verbose) console.log("Relinting");
3365
3537
  const start = Date.now();
3366
3538
  process.exitCode = relint();
3367
- console.log(chalk39.blue(`Finished in ${Date.now() - start}ms`));
3539
+ console.log(chalk40.blue(`Finished in ${Date.now() - start}ms`));
3368
3540
  }
3369
3541
  };
3370
3542
 
3371
3543
  // src/xy/lint/sonarCommand.ts
3372
- import chalk40 from "chalk";
3544
+ import chalk41 from "chalk";
3373
3545
  var sonarCommand = {
3374
3546
  command: "sonar",
3375
3547
  describe: "Sonar - Run Sonar Check",
@@ -3380,17 +3552,17 @@ var sonarCommand = {
3380
3552
  const start = Date.now();
3381
3553
  if (argv.verbose) console.log("Sonar Check");
3382
3554
  process.exitCode = sonar();
3383
- console.log(chalk40.blue(`Finished in ${Date.now() - start}ms`));
3555
+ console.log(chalk41.blue(`Finished in ${Date.now() - start}ms`));
3384
3556
  }
3385
3557
  };
3386
3558
 
3387
3559
  // src/xy/lint/index.ts
3388
3560
  var xyLintCommands = (args) => {
3389
- return args.command(cycleCommand).command(lintCommand).command(deplintCommand).command(fixCommand).command(relintCommand).command(publintCommand).command(knipCommand).command(sonarCommand);
3561
+ return args.command(cycleCommand).command(lintCommand).command(deplintCommand).command(fixCommand).command(relintCommand).command(publintCommand).command(knipCommand).command(packageLintCommand).command(sonarCommand);
3390
3562
  };
3391
3563
 
3392
3564
  // src/xy/xy.ts
3393
- import chalk41 from "chalk";
3565
+ import chalk42 from "chalk";
3394
3566
 
3395
3567
  // src/xy/xyParseOptions.ts
3396
3568
  import yargs from "yargs";
@@ -3423,8 +3595,8 @@ var xyParseOptions = () => {
3423
3595
  var xy = async () => {
3424
3596
  const options = xyParseOptions();
3425
3597
  return await xyBuildCommands(xyCommonCommands(xyInstallCommands(xyDeployCommands(xyLintCommands(options))))).demandCommand(1).command("*", "", () => {
3426
- console.error(chalk41.yellow(`Command not found [${chalk41.magenta(process.argv[2])}]`));
3427
- console.log(chalk41.gray("Try 'yarn xy --help' for list of commands"));
3598
+ console.error(chalk42.yellow(`Command not found [${chalk42.magenta(process.argv[2])}]`));
3599
+ console.log(chalk42.gray("Try 'yarn xy --help' for list of commands"));
3428
3600
  }).version().help().argv;
3429
3601
  };
3430
3602
  export {