@solid-stack/mason 1.0.22 → 1.0.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/bin.cjs +455 -136
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +454 -135
- package/dist/bin.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/commands/lint.d.ts +2 -5
- package/dist/commands/lint.d.ts.map +1 -1
- package/dist/core/lintEngine.d.ts +10 -0
- package/dist/core/lintEngine.d.ts.map +1 -1
- package/dist/index.cjs +455 -136
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +454 -135
- package/dist/index.js.map +1 -1
- package/dist/types/lint.d.ts +1 -1
- package/dist/types/lint.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs4 from 'fs';
|
|
2
2
|
import path2 from 'path';
|
|
3
3
|
import * as p14 from '@clack/prompts';
|
|
4
|
-
import
|
|
4
|
+
import pc14 from 'picocolors';
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
6
|
import { execSync } from 'child_process';
|
|
7
7
|
import { createHash } from 'crypto';
|
|
@@ -112,17 +112,17 @@ function writeFileSafely(absolutePath, content, options = {}) {
|
|
|
112
112
|
function printGeneratedFiles(files, isDryRun = false) {
|
|
113
113
|
console.log("");
|
|
114
114
|
if (isDryRun) {
|
|
115
|
-
p14.log.warn(
|
|
115
|
+
p14.log.warn(pc14.yellow(pc14.bold("[DRY RUN PREVIEW] No files were written to disk.")));
|
|
116
116
|
}
|
|
117
117
|
for (const f of files) {
|
|
118
118
|
if (f.action === "created") {
|
|
119
|
-
p14.log.success(`${
|
|
119
|
+
p14.log.success(`${pc14.bold(f.relativePath)} ${pc14.dim("(created)")}`);
|
|
120
120
|
} else if (f.action === "overwritten") {
|
|
121
|
-
p14.log.warn(`${
|
|
121
|
+
p14.log.warn(`${pc14.bold(f.relativePath)} ${pc14.dim("(overwritten)")}`);
|
|
122
122
|
} else if (f.action === "skipped") {
|
|
123
|
-
p14.log.info(`${
|
|
123
|
+
p14.log.info(`${pc14.dim(f.relativePath)} ${pc14.dim("(skipped - already exists, pass -o to overwrite)")}`);
|
|
124
124
|
} else {
|
|
125
|
-
p14.log.info(`${
|
|
125
|
+
p14.log.info(`${pc14.bold(f.relativePath)} ${pc14.dim("(preview)")}`);
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
}
|
|
@@ -332,13 +332,13 @@ function handleCancel(result) {
|
|
|
332
332
|
}
|
|
333
333
|
function printBanner() {
|
|
334
334
|
console.log("");
|
|
335
|
-
p14.intro(
|
|
335
|
+
p14.intro(pc14.bgCyan(pc14.black(" @solid-stack/mason ")));
|
|
336
336
|
}
|
|
337
337
|
async function promptProperties(options = {}) {
|
|
338
338
|
const properties = options.defaults ? [...options.defaults] : [];
|
|
339
339
|
if (properties.length > 0) {
|
|
340
340
|
const summary = properties.map((p16) => `${p16.name}: ${p16.type}${p16.optional ? "?" : ""}`).join(", ");
|
|
341
|
-
p14.log.info(
|
|
341
|
+
p14.log.info(pc14.dim(`Pre-configured fields: ${summary}`));
|
|
342
342
|
const addMore = handleCancel(
|
|
343
343
|
await p14.confirm({
|
|
344
344
|
message: "Would you like to add custom fields/properties?",
|
|
@@ -349,7 +349,7 @@ async function promptProperties(options = {}) {
|
|
|
349
349
|
return properties;
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
|
-
p14.log.info(
|
|
352
|
+
p14.log.info(pc14.cyan("Enter properties (leave name blank when finished):"));
|
|
353
353
|
while (true) {
|
|
354
354
|
const name = handleCancel(
|
|
355
355
|
await p14.text({
|
|
@@ -397,7 +397,7 @@ async function promptProperties(options = {}) {
|
|
|
397
397
|
optional
|
|
398
398
|
});
|
|
399
399
|
p14.log.success(
|
|
400
|
-
|
|
400
|
+
pc14.green(`Added: ${name.trim()}${optional ? "?" : ""}: ${finalType.trim()}`)
|
|
401
401
|
);
|
|
402
402
|
}
|
|
403
403
|
return properties;
|
|
@@ -631,7 +631,7 @@ function installNpmPackages(projectRoot, packages, pm) {
|
|
|
631
631
|
installCmd = `npm install ${packages.join(" ")}`;
|
|
632
632
|
break;
|
|
633
633
|
}
|
|
634
|
-
p14.log.info(`Installing missing dependencies with ${manager}: ${
|
|
634
|
+
p14.log.info(`Installing missing dependencies with ${manager}: ${pc14.cyan(packages.join(", "))}`);
|
|
635
635
|
execSync(installCmd, {
|
|
636
636
|
cwd: projectRoot,
|
|
637
637
|
stdio: "inherit"
|
|
@@ -2348,7 +2348,7 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
2348
2348
|
}
|
|
2349
2349
|
}
|
|
2350
2350
|
const s = p14.spinner();
|
|
2351
|
-
s.start(`Generating feature '${
|
|
2351
|
+
s.start(`Generating feature '${pc14.cyan(normalizedName)}'...`);
|
|
2352
2352
|
const options = {
|
|
2353
2353
|
name: normalizedName,
|
|
2354
2354
|
projectRoot,
|
|
@@ -2395,7 +2395,7 @@ async function runFeatureCommand(featureNameArg, flags = {}) {
|
|
|
2395
2395
|
s.stop("Feature scaffolded successfully!");
|
|
2396
2396
|
printGeneratedFiles(files, options.dryRun);
|
|
2397
2397
|
p14.outro(
|
|
2398
|
-
|
|
2398
|
+
pc14.green(
|
|
2399
2399
|
`\u2713 Feature '${normalizedName}' initialized in ${path2.relative(projectRoot, targetDir)} (uncommitted, unregistered)`
|
|
2400
2400
|
)
|
|
2401
2401
|
);
|
|
@@ -2551,7 +2551,7 @@ async function runSharedCommand(sharedNameArg, flags = {}) {
|
|
|
2551
2551
|
);
|
|
2552
2552
|
}
|
|
2553
2553
|
const s = p14.spinner();
|
|
2554
|
-
s.start(`Generating shared module '${
|
|
2554
|
+
s.start(`Generating shared module '${pc14.cyan(normalizedName)}'...`);
|
|
2555
2555
|
const files = generateShared({
|
|
2556
2556
|
name: normalizedName,
|
|
2557
2557
|
description,
|
|
@@ -2565,7 +2565,7 @@ async function runSharedCommand(sharedNameArg, flags = {}) {
|
|
|
2565
2565
|
s.stop("Shared module generated successfully!");
|
|
2566
2566
|
printGeneratedFiles(files, Boolean(flags.dryRun));
|
|
2567
2567
|
p14.outro(
|
|
2568
|
-
|
|
2568
|
+
pc14.green(
|
|
2569
2569
|
`\u2713 Shared module '${normalizedName}' initialized in ${path2.relative(projectRoot, targetDir)} (uncommitted, unregistered)`
|
|
2570
2570
|
)
|
|
2571
2571
|
);
|
|
@@ -2693,7 +2693,7 @@ async function runUseCaseCommand(useCaseNameArg, flags = {}) {
|
|
|
2693
2693
|
}
|
|
2694
2694
|
}
|
|
2695
2695
|
const s = p14.spinner();
|
|
2696
|
-
s.start(`Generating use case '${
|
|
2696
|
+
s.start(`Generating use case '${pc14.cyan(ucName)}'...`);
|
|
2697
2697
|
const options = {
|
|
2698
2698
|
name: ucName,
|
|
2699
2699
|
feature,
|
|
@@ -2725,7 +2725,7 @@ async function runUseCaseCommand(useCaseNameArg, flags = {}) {
|
|
|
2725
2725
|
}
|
|
2726
2726
|
s.stop("Use case generated successfully!");
|
|
2727
2727
|
printGeneratedFiles(files, options.dryRun);
|
|
2728
|
-
p14.outro(
|
|
2728
|
+
p14.outro(pc14.green(`Use case '${ucName}' created in feature '${feature}'!`));
|
|
2729
2729
|
}
|
|
2730
2730
|
async function runDomainCommand(domainNameArg, flags = {}) {
|
|
2731
2731
|
const projectRoot = findProjectRoot();
|
|
@@ -2796,7 +2796,7 @@ async function runDomainCommand(domainNameArg, flags = {}) {
|
|
|
2796
2796
|
});
|
|
2797
2797
|
}
|
|
2798
2798
|
const s = p14.spinner();
|
|
2799
|
-
s.start(`Generating domain model '${
|
|
2799
|
+
s.start(`Generating domain model '${pc14.cyan(entityName)}'...`);
|
|
2800
2800
|
const options = {
|
|
2801
2801
|
name: entityName,
|
|
2802
2802
|
feature,
|
|
@@ -2809,7 +2809,7 @@ async function runDomainCommand(domainNameArg, flags = {}) {
|
|
|
2809
2809
|
const file = generateDomain(options);
|
|
2810
2810
|
s.stop("Domain model generated successfully!");
|
|
2811
2811
|
printGeneratedFiles([file], options.dryRun);
|
|
2812
|
-
p14.outro(
|
|
2812
|
+
p14.outro(pc14.green(`Domain model '${entityName}' created in feature '${feature}'!`));
|
|
2813
2813
|
}
|
|
2814
2814
|
async function runInfrastructureCommand(classNameArg, flags = {}) {
|
|
2815
2815
|
const projectRoot = findProjectRoot();
|
|
@@ -2978,7 +2978,7 @@ async function runInfrastructureCommand(classNameArg, flags = {}) {
|
|
|
2978
2978
|
registerInProvider = !flags.noProvider;
|
|
2979
2979
|
}
|
|
2980
2980
|
const s = p14.spinner();
|
|
2981
|
-
s.start(`Generating infrastructure class '${
|
|
2981
|
+
s.start(`Generating infrastructure class '${pc14.cyan(className)}'...`);
|
|
2982
2982
|
const files = [];
|
|
2983
2983
|
const options = {
|
|
2984
2984
|
name: className,
|
|
@@ -3013,7 +3013,7 @@ async function runInfrastructureCommand(classNameArg, flags = {}) {
|
|
|
3013
3013
|
}
|
|
3014
3014
|
s.stop("Infrastructure class generated successfully!");
|
|
3015
3015
|
printGeneratedFiles(files, options.dryRun);
|
|
3016
|
-
p14.outro(
|
|
3016
|
+
p14.outro(pc14.green(`Infrastructure class '${className}' created!`));
|
|
3017
3017
|
}
|
|
3018
3018
|
async function runInterfaceCommand(interfaceNameArg, flags = {}) {
|
|
3019
3019
|
const projectRoot = findProjectRoot();
|
|
@@ -3126,7 +3126,7 @@ async function runInterfaceCommand(interfaceNameArg, flags = {}) {
|
|
|
3126
3126
|
}
|
|
3127
3127
|
}
|
|
3128
3128
|
const s = p14.spinner();
|
|
3129
|
-
s.start(`Generating interface '${
|
|
3129
|
+
s.start(`Generating interface '${pc14.cyan(ifaceName)}'...`);
|
|
3130
3130
|
const files = [];
|
|
3131
3131
|
const options = {
|
|
3132
3132
|
name: ifaceName,
|
|
@@ -3175,7 +3175,7 @@ async function runInterfaceCommand(interfaceNameArg, flags = {}) {
|
|
|
3175
3175
|
}
|
|
3176
3176
|
s.stop("Interface generated successfully!");
|
|
3177
3177
|
printGeneratedFiles(files, options.dryRun);
|
|
3178
|
-
p14.outro(
|
|
3178
|
+
p14.outro(pc14.green(`Interface '${ifaceName}' created in feature '${feature}'!`));
|
|
3179
3179
|
}
|
|
3180
3180
|
async function runHttpHandlerCommand(handlerNameArg, flags = {}) {
|
|
3181
3181
|
const projectRoot = findProjectRoot();
|
|
@@ -3292,7 +3292,7 @@ async function runHttpHandlerCommand(handlerNameArg, flags = {}) {
|
|
|
3292
3292
|
}
|
|
3293
3293
|
}
|
|
3294
3294
|
const s = p14.spinner();
|
|
3295
|
-
s.start(`Generating HTTP handler '${
|
|
3295
|
+
s.start(`Generating HTTP handler '${pc14.cyan(className)}'...`);
|
|
3296
3296
|
const options = {
|
|
3297
3297
|
name: className,
|
|
3298
3298
|
feature,
|
|
@@ -3310,7 +3310,7 @@ async function runHttpHandlerCommand(handlerNameArg, flags = {}) {
|
|
|
3310
3310
|
const files = generateHttpHandler(options);
|
|
3311
3311
|
s.stop("HTTP handler generated successfully!");
|
|
3312
3312
|
printGeneratedFiles(files, options.dryRun);
|
|
3313
|
-
p14.outro(
|
|
3313
|
+
p14.outro(pc14.green(`HTTP handler '${className}' created in feature '${feature}'!`));
|
|
3314
3314
|
}
|
|
3315
3315
|
function generateInjectableCode(className, dependencies = [], methods = [], implementsInterface) {
|
|
3316
3316
|
const formattedDeps = dependencies.map((dep) => ({
|
|
@@ -3466,7 +3466,7 @@ async function runInjectableCommand(classNameArg, flags = {}) {
|
|
|
3466
3466
|
);
|
|
3467
3467
|
}
|
|
3468
3468
|
const s = p14.spinner();
|
|
3469
|
-
s.start(`Generating injectable '${
|
|
3469
|
+
s.start(`Generating injectable '${pc14.cyan(className)}'...`);
|
|
3470
3470
|
const options = {
|
|
3471
3471
|
name: className,
|
|
3472
3472
|
feature,
|
|
@@ -3480,7 +3480,7 @@ async function runInjectableCommand(classNameArg, flags = {}) {
|
|
|
3480
3480
|
const files = generateInjectable(options);
|
|
3481
3481
|
s.stop("Injectable class generated successfully!");
|
|
3482
3482
|
printGeneratedFiles(files, options.dryRun);
|
|
3483
|
-
p14.outro(
|
|
3483
|
+
p14.outro(pc14.green(`Injectable '${className}' created successfully!`));
|
|
3484
3484
|
}
|
|
3485
3485
|
async function runInteractiveMenu(flags = {}) {
|
|
3486
3486
|
printBanner();
|
|
@@ -3594,7 +3594,7 @@ async function handleCreate(type, name, flags = {}) {
|
|
|
3594
3594
|
break;
|
|
3595
3595
|
default:
|
|
3596
3596
|
p14.log.error(
|
|
3597
|
-
|
|
3597
|
+
pc14.red(
|
|
3598
3598
|
`Unknown component type: "${type}". Allowed types: feature, shared, usecase, domain, infrastructure, interface, httpHandler, injectable.`
|
|
3599
3599
|
)
|
|
3600
3600
|
);
|
|
@@ -3714,19 +3714,19 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3714
3714
|
);
|
|
3715
3715
|
}
|
|
3716
3716
|
if (type !== "shared" && type !== "feature") {
|
|
3717
|
-
p14.log.error(
|
|
3717
|
+
p14.log.error(pc14.red(`Invalid module type: "${typeArg}". Must be "shared" or "feature".`));
|
|
3718
3718
|
process.exit(1);
|
|
3719
3719
|
}
|
|
3720
3720
|
const registryBase = getRegistryBase(projectRoot, flags.registry);
|
|
3721
3721
|
const s = p14.spinner();
|
|
3722
|
-
s.start(`Connecting to registry at ${
|
|
3722
|
+
s.start(`Connecting to registry at ${pc14.dim(registryBase)}...`);
|
|
3723
3723
|
let index;
|
|
3724
3724
|
try {
|
|
3725
3725
|
index = await fetchRegistryIndex(registryBase);
|
|
3726
3726
|
s.stop("Registry index loaded.");
|
|
3727
3727
|
} catch (err) {
|
|
3728
|
-
s.stop(
|
|
3729
|
-
p14.log.error(
|
|
3728
|
+
s.stop(pc14.red("Failed to load registry index."));
|
|
3729
|
+
p14.log.error(pc14.red(err.message || String(err)));
|
|
3730
3730
|
process.exit(1);
|
|
3731
3731
|
}
|
|
3732
3732
|
const availableList = type === "shared" ? index.shared : index.features;
|
|
@@ -3750,9 +3750,9 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3750
3750
|
}
|
|
3751
3751
|
if (!candidateNames.includes(name)) {
|
|
3752
3752
|
const closest = findClosestMatch(name, candidateNames);
|
|
3753
|
-
p14.log.error(
|
|
3753
|
+
p14.log.error(pc14.red(`\u274C Module '${name}' not found in the ${type} registry.`));
|
|
3754
3754
|
if (closest) {
|
|
3755
|
-
p14.log.info(
|
|
3755
|
+
p14.log.info(pc14.yellow(`Did you mean '${pc14.cyan(closest)}'?`));
|
|
3756
3756
|
}
|
|
3757
3757
|
process.exit(1);
|
|
3758
3758
|
}
|
|
@@ -3764,7 +3764,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3764
3764
|
try {
|
|
3765
3765
|
manifest = await fetchModuleManifest(registryBase, modType, modName);
|
|
3766
3766
|
} catch (err) {
|
|
3767
|
-
p14.log.error(
|
|
3767
|
+
p14.log.error(pc14.red(`Failed to fetch manifest for ${modType} '${modName}': ${err.message}`));
|
|
3768
3768
|
process.exit(1);
|
|
3769
3769
|
}
|
|
3770
3770
|
nodes.set(key, {
|
|
@@ -3804,7 +3804,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3804
3804
|
buildTopologicalOrder(rootKey);
|
|
3805
3805
|
const resolutions = /* @__PURE__ */ new Map();
|
|
3806
3806
|
const globalAliasMap = /* @__PURE__ */ new Map();
|
|
3807
|
-
p14.log.step(`Importing ${type}: ${
|
|
3807
|
+
p14.log.step(`Importing ${type}: ${pc14.cyan(name)}...`);
|
|
3808
3808
|
for (const key of orderedKeys) {
|
|
3809
3809
|
const node = nodes.get(key);
|
|
3810
3810
|
const { type: modType, name: registryName, manifest } = node;
|
|
@@ -3837,7 +3837,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3837
3837
|
if (programmaticPointTo) {
|
|
3838
3838
|
if (!checkModuleExists(projectRoot, modType, programmaticPointTo)) {
|
|
3839
3839
|
p14.log.error(
|
|
3840
|
-
|
|
3840
|
+
pc14.red(
|
|
3841
3841
|
`Module '${programmaticPointTo}' specified in --point-to does not exist in ${folder}.`
|
|
3842
3842
|
)
|
|
3843
3843
|
);
|
|
@@ -3873,7 +3873,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
3873
3873
|
}
|
|
3874
3874
|
const existingDir = getExistingModuleDir(projectRoot, modType, registryName);
|
|
3875
3875
|
if (!existingDir) {
|
|
3876
|
-
p14.log.info(` \u21B3 Resolving required ${modType} dependency: ${
|
|
3876
|
+
p14.log.info(` \u21B3 Resolving required ${modType} dependency: ${pc14.cyan(registryName)}`);
|
|
3877
3877
|
resolutions.set(key, {
|
|
3878
3878
|
type: modType,
|
|
3879
3879
|
registryName,
|
|
@@ -4104,7 +4104,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
4104
4104
|
const isOverwrite = Boolean(flags.overwrite || res.action === "overwrite");
|
|
4105
4105
|
if (key !== rootKey) {
|
|
4106
4106
|
p14.log.step(
|
|
4107
|
-
`Importing ${res.type}: ${
|
|
4107
|
+
`Importing ${res.type}: ${pc14.cyan(res.targetName)}${res.targetName !== res.registryName ? pc14.dim(` (from ${res.registryName})`) : ""}...`
|
|
4108
4108
|
);
|
|
4109
4109
|
}
|
|
4110
4110
|
if (res.action === "overwrite" && !flags.dryRun) {
|
|
@@ -4123,7 +4123,7 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
4123
4123
|
const localFilePath = path2.join(targetDir, file);
|
|
4124
4124
|
if (fs4.existsSync(localFilePath) && !isOverwrite) {
|
|
4125
4125
|
p14.log.warn(
|
|
4126
|
-
` \u21B3 Skipping existing file: ${
|
|
4126
|
+
` \u21B3 Skipping existing file: ${pc14.dim(path2.relative(projectRoot, localFilePath))} (use --overwrite to replace)`
|
|
4127
4127
|
);
|
|
4128
4128
|
continue;
|
|
4129
4129
|
}
|
|
@@ -4135,13 +4135,13 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
4135
4135
|
}
|
|
4136
4136
|
const displayPath = path2.relative(projectRoot, localFilePath);
|
|
4137
4137
|
totalWrittenFiles.push(displayPath);
|
|
4138
|
-
p14.log.message(` ${
|
|
4138
|
+
p14.log.message(` ${pc14.green("+")} ${displayPath}`);
|
|
4139
4139
|
}
|
|
4140
4140
|
}
|
|
4141
4141
|
const missingNpm = getMissingNpmPackages(projectRoot, Array.from(requiredNpmPackages));
|
|
4142
4142
|
if (missingNpm.length > 0) {
|
|
4143
4143
|
if (flags.skipInstall || flags.dryRun) {
|
|
4144
|
-
p14.log.info(`Required npm dependencies to install: ${
|
|
4144
|
+
p14.log.info(`Required npm dependencies to install: ${pc14.cyan(missingNpm.join(", "))}`);
|
|
4145
4145
|
} else {
|
|
4146
4146
|
try {
|
|
4147
4147
|
installNpmPackages(projectRoot, missingNpm);
|
|
@@ -4155,13 +4155,13 @@ async function handleImport(typeArg, nameArg, flags = {}) {
|
|
|
4155
4155
|
}
|
|
4156
4156
|
}
|
|
4157
4157
|
if (flags.dryRun) {
|
|
4158
|
-
p14.log.info(
|
|
4158
|
+
p14.log.info(pc14.yellow("Dry run complete: No files were written to disk."));
|
|
4159
4159
|
} else {
|
|
4160
4160
|
const rootRes = resolutions.get(rootKey);
|
|
4161
4161
|
const baseDir = getModuleBaseDir(projectRoot, type);
|
|
4162
4162
|
const displayTarget = path2.relative(projectRoot, path2.join(baseDir, rootRes.targetName));
|
|
4163
4163
|
p14.log.success(
|
|
4164
|
-
|
|
4164
|
+
pc14.green(
|
|
4165
4165
|
`Successfully imported ${type} '${name}' (${totalWrittenFiles.length} file${totalWrittenFiles.length === 1 ? "" : "s"} placed in ${displayTarget})`
|
|
4166
4166
|
)
|
|
4167
4167
|
);
|
|
@@ -4410,6 +4410,350 @@ function discoverAllFeatures(projectRoot) {
|
|
|
4410
4410
|
dir: path2.join(featuresBase, e.name)
|
|
4411
4411
|
})).sort((a, b) => a.name.localeCompare(b.name));
|
|
4412
4412
|
}
|
|
4413
|
+
function extractClassMethods(content, className) {
|
|
4414
|
+
let clean = "";
|
|
4415
|
+
let inLineComment = false;
|
|
4416
|
+
let inBlockComment = false;
|
|
4417
|
+
let inString = null;
|
|
4418
|
+
let escaped = false;
|
|
4419
|
+
for (let i = 0; i < content.length; i++) {
|
|
4420
|
+
const c = content[i];
|
|
4421
|
+
const next = content[i + 1];
|
|
4422
|
+
if (inLineComment) {
|
|
4423
|
+
if (c === "\n") {
|
|
4424
|
+
inLineComment = false;
|
|
4425
|
+
clean += "\n";
|
|
4426
|
+
} else {
|
|
4427
|
+
clean += " ";
|
|
4428
|
+
}
|
|
4429
|
+
continue;
|
|
4430
|
+
}
|
|
4431
|
+
if (inBlockComment) {
|
|
4432
|
+
if (c === "*" && next === "/") {
|
|
4433
|
+
inBlockComment = false;
|
|
4434
|
+
clean += " ";
|
|
4435
|
+
i++;
|
|
4436
|
+
} else {
|
|
4437
|
+
clean += c === "\n" ? "\n" : " ";
|
|
4438
|
+
}
|
|
4439
|
+
continue;
|
|
4440
|
+
}
|
|
4441
|
+
if (inString) {
|
|
4442
|
+
clean += c === "\n" ? "\n" : " ";
|
|
4443
|
+
if (escaped) {
|
|
4444
|
+
escaped = false;
|
|
4445
|
+
} else if (c === "\\") {
|
|
4446
|
+
escaped = true;
|
|
4447
|
+
} else if (c === inString) {
|
|
4448
|
+
inString = null;
|
|
4449
|
+
}
|
|
4450
|
+
continue;
|
|
4451
|
+
}
|
|
4452
|
+
if (c === "/" && next === "/") {
|
|
4453
|
+
inLineComment = true;
|
|
4454
|
+
clean += " ";
|
|
4455
|
+
i++;
|
|
4456
|
+
continue;
|
|
4457
|
+
}
|
|
4458
|
+
if (c === "/" && next === "*") {
|
|
4459
|
+
inBlockComment = true;
|
|
4460
|
+
clean += " ";
|
|
4461
|
+
i++;
|
|
4462
|
+
continue;
|
|
4463
|
+
}
|
|
4464
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
4465
|
+
inString = c;
|
|
4466
|
+
clean += " ";
|
|
4467
|
+
continue;
|
|
4468
|
+
}
|
|
4469
|
+
clean += c;
|
|
4470
|
+
}
|
|
4471
|
+
const classDeclRegex = new RegExp(`(?:export\\s+(?:default\\s+)?)?class\\s+${className}\\b[^{]*\\{`);
|
|
4472
|
+
const match = classDeclRegex.exec(clean);
|
|
4473
|
+
if (!match) return null;
|
|
4474
|
+
const classBodyStart = match.index + match[0].length - 1;
|
|
4475
|
+
const methods = [];
|
|
4476
|
+
let depth = 1;
|
|
4477
|
+
let parenDepth = 0;
|
|
4478
|
+
let atMemberStart = true;
|
|
4479
|
+
const methodRegex = /^\s*(?:@[a-zA-Z0-9_$]+(?:\([^)]*\))?\s+)*(?:(public|private|protected|static)\s+)*(?:(async)\s+)?(?:(get|set)\s+)?(#?[a-zA-Z0-9_$]+)\s*(?:<[^>]+>)?\s*\(/;
|
|
4480
|
+
const arrowRegex = /^\s*(?:(public|private|protected|static)\s+)?(#?[a-zA-Z0-9_$]+)\s*=\s*(?:async\s*)?\(/;
|
|
4481
|
+
for (let i = classBodyStart + 1; i < clean.length && depth > 0; i++) {
|
|
4482
|
+
const c = clean[i];
|
|
4483
|
+
if (c === "{") {
|
|
4484
|
+
depth++;
|
|
4485
|
+
atMemberStart = false;
|
|
4486
|
+
continue;
|
|
4487
|
+
}
|
|
4488
|
+
if (c === "}") {
|
|
4489
|
+
depth--;
|
|
4490
|
+
if (depth === 1) {
|
|
4491
|
+
atMemberStart = true;
|
|
4492
|
+
}
|
|
4493
|
+
continue;
|
|
4494
|
+
}
|
|
4495
|
+
if (depth === 1) {
|
|
4496
|
+
if (c === ";") {
|
|
4497
|
+
atMemberStart = true;
|
|
4498
|
+
parenDepth = 0;
|
|
4499
|
+
continue;
|
|
4500
|
+
}
|
|
4501
|
+
if (c === "(") {
|
|
4502
|
+
parenDepth++;
|
|
4503
|
+
} else if (c === ")") {
|
|
4504
|
+
parenDepth = Math.max(0, parenDepth - 1);
|
|
4505
|
+
}
|
|
4506
|
+
if (atMemberStart && parenDepth === 0) {
|
|
4507
|
+
if (/\s/.test(c)) continue;
|
|
4508
|
+
const slice = clean.slice(i);
|
|
4509
|
+
const methodMatch = slice.match(methodRegex);
|
|
4510
|
+
if (methodMatch) {
|
|
4511
|
+
const fullMatch = methodMatch[0];
|
|
4512
|
+
const beforeParen = fullMatch.slice(0, fullMatch.lastIndexOf("(")).trim();
|
|
4513
|
+
const tokens = beforeParen.split(/\s+/).filter(Boolean);
|
|
4514
|
+
const rawName = tokens[tokens.length - 1] || "";
|
|
4515
|
+
const methodName = rawName.replace(/<.*$/, "");
|
|
4516
|
+
const controlKeywords = ["if", "for", "while", "switch", "catch", "with"];
|
|
4517
|
+
if (!controlKeywords.includes(methodName)) {
|
|
4518
|
+
const isPrivate = tokens.includes("private") || tokens.includes("protected") || methodName.startsWith("#");
|
|
4519
|
+
const isAsync = tokens.includes("async");
|
|
4520
|
+
const isPublic = !isPrivate;
|
|
4521
|
+
const lineNum = content.slice(0, i).split("\n").length;
|
|
4522
|
+
const lineCode = content.split("\n")[lineNum - 1]?.trim() || "";
|
|
4523
|
+
methods.push({
|
|
4524
|
+
name: methodName,
|
|
4525
|
+
isAsync,
|
|
4526
|
+
isPublic,
|
|
4527
|
+
line: lineNum,
|
|
4528
|
+
code: lineCode
|
|
4529
|
+
});
|
|
4530
|
+
i += fullMatch.length - 1;
|
|
4531
|
+
parenDepth = 1;
|
|
4532
|
+
atMemberStart = false;
|
|
4533
|
+
continue;
|
|
4534
|
+
}
|
|
4535
|
+
}
|
|
4536
|
+
const arrowMatch = slice.match(arrowRegex);
|
|
4537
|
+
if (arrowMatch) {
|
|
4538
|
+
const fullMatch = arrowMatch[0];
|
|
4539
|
+
const beforeEquals = fullMatch.split("=")[0].trim();
|
|
4540
|
+
const tokens = beforeEquals.split(/\s+/).filter(Boolean);
|
|
4541
|
+
const rawName = tokens[tokens.length - 1] || "";
|
|
4542
|
+
const isPrivate = tokens.includes("private") || tokens.includes("protected") || rawName.startsWith("#");
|
|
4543
|
+
const isAsync = fullMatch.includes("async");
|
|
4544
|
+
const isPublic = !isPrivate;
|
|
4545
|
+
const lineNum = content.slice(0, i).split("\n").length;
|
|
4546
|
+
const lineCode = content.split("\n")[lineNum - 1]?.trim() || "";
|
|
4547
|
+
methods.push({
|
|
4548
|
+
name: rawName,
|
|
4549
|
+
isAsync,
|
|
4550
|
+
isPublic,
|
|
4551
|
+
line: lineNum,
|
|
4552
|
+
code: lineCode
|
|
4553
|
+
});
|
|
4554
|
+
i += fullMatch.length - 1;
|
|
4555
|
+
parenDepth = 1;
|
|
4556
|
+
atMemberStart = false;
|
|
4557
|
+
continue;
|
|
4558
|
+
}
|
|
4559
|
+
atMemberStart = false;
|
|
4560
|
+
}
|
|
4561
|
+
}
|
|
4562
|
+
}
|
|
4563
|
+
return methods;
|
|
4564
|
+
}
|
|
4565
|
+
function checkUseCaseShape(featureName, filePath, relativePath, content, addViolation) {
|
|
4566
|
+
const fileName = path2.basename(filePath);
|
|
4567
|
+
const lines = content.split(/\r?\n/);
|
|
4568
|
+
const classMatch = content.match(/(?:export\s+(?:default\s+)?)?class\s+([A-Za-z0-9_]+)/);
|
|
4569
|
+
if (!classMatch) {
|
|
4570
|
+
addViolation({
|
|
4571
|
+
feature: featureName,
|
|
4572
|
+
layer: "useCases",
|
|
4573
|
+
file: filePath,
|
|
4574
|
+
relativePath,
|
|
4575
|
+
line: 1,
|
|
4576
|
+
category: "Use Case Shape Violation",
|
|
4577
|
+
code: lines[0]?.trim() || "",
|
|
4578
|
+
ruleId: "U_SHAPE_CLASS",
|
|
4579
|
+
severity: "error",
|
|
4580
|
+
advice: `Use case file '${fileName}' must define and export a class.`,
|
|
4581
|
+
fixExample: {
|
|
4582
|
+
bad: "// Missing class definition",
|
|
4583
|
+
good: `export class ${fileName.replace(/\.(ts|js)$/, "")} { ... }`
|
|
4584
|
+
}
|
|
4585
|
+
});
|
|
4586
|
+
return;
|
|
4587
|
+
}
|
|
4588
|
+
const className = classMatch[1];
|
|
4589
|
+
let classLine = 1;
|
|
4590
|
+
for (let i = 0; i < lines.length; i++) {
|
|
4591
|
+
if (new RegExp(`(?:export\\s+(?:default\\s+)?)?class\\s+${className}\\b`).test(lines[i])) {
|
|
4592
|
+
classLine = i + 1;
|
|
4593
|
+
break;
|
|
4594
|
+
}
|
|
4595
|
+
}
|
|
4596
|
+
if (!/@MakeInjectable\b/.test(content)) {
|
|
4597
|
+
addViolation({
|
|
4598
|
+
feature: featureName,
|
|
4599
|
+
layer: "useCases",
|
|
4600
|
+
file: filePath,
|
|
4601
|
+
relativePath,
|
|
4602
|
+
line: classLine,
|
|
4603
|
+
category: "Use Case Shape Violation",
|
|
4604
|
+
code: lines[classLine - 1]?.trim() || `class ${className}`,
|
|
4605
|
+
ruleId: "U_SHAPE_DECORATOR",
|
|
4606
|
+
severity: "error",
|
|
4607
|
+
advice: `Use case class '${className}' in '${fileName}' must be decorated with @MakeInjectable.`,
|
|
4608
|
+
fixExample: {
|
|
4609
|
+
bad: lines[classLine - 1]?.trim() || `class ${className}`,
|
|
4610
|
+
good: `@MakeInjectable
|
|
4611
|
+
export class ${className} { ... }`
|
|
4612
|
+
}
|
|
4613
|
+
});
|
|
4614
|
+
}
|
|
4615
|
+
const hasAsyncExecute = /(?:public\s+)?async\s+execute\s*(?:<[^>]+>)?\s*\(/.test(content);
|
|
4616
|
+
if (!hasAsyncExecute) {
|
|
4617
|
+
const hasSyncExecute = /(?:public\s+)?execute\s*(?:<[^>]+>)?\s*\(/.test(content);
|
|
4618
|
+
addViolation({
|
|
4619
|
+
feature: featureName,
|
|
4620
|
+
layer: "useCases",
|
|
4621
|
+
file: filePath,
|
|
4622
|
+
relativePath,
|
|
4623
|
+
line: classLine,
|
|
4624
|
+
category: "Use Case Shape Violation",
|
|
4625
|
+
code: lines[classLine - 1]?.trim() || `class ${className}`,
|
|
4626
|
+
ruleId: "U_SHAPE_EXECUTE",
|
|
4627
|
+
severity: "error",
|
|
4628
|
+
advice: hasSyncExecute ? `Use case class '${className}' in '${fileName}' must have an 'async execute' method (found synchronous 'execute').` : `Use case class '${className}' in '${fileName}' must implement an 'async execute(...)' method.`,
|
|
4629
|
+
fixExample: {
|
|
4630
|
+
bad: hasSyncExecute ? "execute(props: ...) { ... }" : `class ${className} { ... }`,
|
|
4631
|
+
good: "async execute(props: ...): Promise<...> { ... }"
|
|
4632
|
+
}
|
|
4633
|
+
});
|
|
4634
|
+
}
|
|
4635
|
+
const classMethods = extractClassMethods(content, className);
|
|
4636
|
+
if (classMethods) {
|
|
4637
|
+
const extraPublicMethods = classMethods.filter(
|
|
4638
|
+
(m) => m.isPublic && m.name !== "constructor" && m.name !== "execute"
|
|
4639
|
+
);
|
|
4640
|
+
for (const m of extraPublicMethods) {
|
|
4641
|
+
addViolation({
|
|
4642
|
+
feature: featureName,
|
|
4643
|
+
layer: "useCases",
|
|
4644
|
+
file: filePath,
|
|
4645
|
+
relativePath,
|
|
4646
|
+
line: m.line,
|
|
4647
|
+
category: "Use Case Shape Violation",
|
|
4648
|
+
code: m.code || `public ${m.name}(...)`,
|
|
4649
|
+
ruleId: "U_SHAPE_ONLY_EXECUTE",
|
|
4650
|
+
severity: "error",
|
|
4651
|
+
advice: `Use case class '${className}' in '${fileName}' has disallowed public method '${m.name}'. The only allowed public methods are constructor and async execute. Extract extra methods into their own use cases, or make them private.`,
|
|
4652
|
+
fixExample: {
|
|
4653
|
+
bad: m.code || `${m.name}(...) { ... }`,
|
|
4654
|
+
good: `// Extract '${m.name}' into its own dedicated Use Case, or make it private if it is internal helper logic:
|
|
4655
|
+
private ${m.name}(...) { ... }`
|
|
4656
|
+
}
|
|
4657
|
+
});
|
|
4658
|
+
}
|
|
4659
|
+
}
|
|
4660
|
+
}
|
|
4661
|
+
function checkServiceShape(featureName, filePath, relativePath, content, addViolation) {
|
|
4662
|
+
const fileName = path2.basename(filePath);
|
|
4663
|
+
const lines = content.split(/\r?\n/);
|
|
4664
|
+
const classMatch = content.match(/(?:export\s+(?:default\s+)?)?class\s+([A-Za-z0-9_]+)/);
|
|
4665
|
+
if (!classMatch) {
|
|
4666
|
+
addViolation({
|
|
4667
|
+
feature: featureName,
|
|
4668
|
+
layer: "services",
|
|
4669
|
+
file: filePath,
|
|
4670
|
+
relativePath,
|
|
4671
|
+
line: 1,
|
|
4672
|
+
category: "Service Shape Violation",
|
|
4673
|
+
code: lines[0]?.trim() || "",
|
|
4674
|
+
ruleId: "S_SHAPE_CLASS",
|
|
4675
|
+
severity: "error",
|
|
4676
|
+
advice: `Service file '${fileName}' must define and export a class.`,
|
|
4677
|
+
fixExample: {
|
|
4678
|
+
bad: "// Missing class definition",
|
|
4679
|
+
good: `export class ${fileName.replace(/\.(ts|js)$/, "")} { ... }`
|
|
4680
|
+
}
|
|
4681
|
+
});
|
|
4682
|
+
return;
|
|
4683
|
+
}
|
|
4684
|
+
const className = classMatch[1];
|
|
4685
|
+
let classLine = 1;
|
|
4686
|
+
for (let i = 0; i < lines.length; i++) {
|
|
4687
|
+
if (new RegExp(`(?:export\\s+(?:default\\s+)?)?class\\s+${className}\\b`).test(lines[i])) {
|
|
4688
|
+
classLine = i + 1;
|
|
4689
|
+
break;
|
|
4690
|
+
}
|
|
4691
|
+
}
|
|
4692
|
+
if (!/@MakeInjectable\b/.test(content)) {
|
|
4693
|
+
addViolation({
|
|
4694
|
+
feature: featureName,
|
|
4695
|
+
layer: "services",
|
|
4696
|
+
file: filePath,
|
|
4697
|
+
relativePath,
|
|
4698
|
+
line: classLine,
|
|
4699
|
+
category: "Service Shape Violation",
|
|
4700
|
+
code: lines[classLine - 1]?.trim() || `class ${className}`,
|
|
4701
|
+
ruleId: "S_SHAPE_DECORATOR",
|
|
4702
|
+
severity: "error",
|
|
4703
|
+
advice: `Service class '${className}' in '${fileName}' must be decorated with @MakeInjectable.`,
|
|
4704
|
+
fixExample: {
|
|
4705
|
+
bad: lines[classLine - 1]?.trim() || `class ${className}`,
|
|
4706
|
+
good: `@MakeInjectable
|
|
4707
|
+
export class ${className} { ... }`
|
|
4708
|
+
}
|
|
4709
|
+
});
|
|
4710
|
+
}
|
|
4711
|
+
const hasAsyncExecute = /(?:public\s+)?async\s+execute\s*(?:<[^>]+>)?\s*\(/.test(content);
|
|
4712
|
+
if (!hasAsyncExecute) {
|
|
4713
|
+
const hasSyncExecute = /(?:public\s+)?execute\s*(?:<[^>]+>)?\s*\(/.test(content);
|
|
4714
|
+
addViolation({
|
|
4715
|
+
feature: featureName,
|
|
4716
|
+
layer: "services",
|
|
4717
|
+
file: filePath,
|
|
4718
|
+
relativePath,
|
|
4719
|
+
line: classLine,
|
|
4720
|
+
category: "Service Shape Violation",
|
|
4721
|
+
code: lines[classLine - 1]?.trim() || `class ${className}`,
|
|
4722
|
+
ruleId: "S_SHAPE_EXECUTE",
|
|
4723
|
+
severity: "error",
|
|
4724
|
+
advice: hasSyncExecute ? `Service class '${className}' in '${fileName}' must have an 'async execute' method (found synchronous 'execute').` : `Service class '${className}' in '${fileName}' must implement an 'async execute(...)' method.`,
|
|
4725
|
+
fixExample: {
|
|
4726
|
+
bad: hasSyncExecute ? "execute(props: ...) { ... }" : `class ${className} { ... }`,
|
|
4727
|
+
good: "async execute(props: ...): Promise<...> { ... }"
|
|
4728
|
+
}
|
|
4729
|
+
});
|
|
4730
|
+
}
|
|
4731
|
+
const classMethods = extractClassMethods(content, className);
|
|
4732
|
+
if (classMethods) {
|
|
4733
|
+
const extraPublicMethods = classMethods.filter(
|
|
4734
|
+
(m) => m.isPublic && m.name !== "constructor" && m.name !== "execute"
|
|
4735
|
+
);
|
|
4736
|
+
for (const m of extraPublicMethods) {
|
|
4737
|
+
addViolation({
|
|
4738
|
+
feature: featureName,
|
|
4739
|
+
layer: "services",
|
|
4740
|
+
file: filePath,
|
|
4741
|
+
relativePath,
|
|
4742
|
+
line: m.line,
|
|
4743
|
+
category: "Service Shape Violation",
|
|
4744
|
+
code: m.code || `public ${m.name}(...)`,
|
|
4745
|
+
ruleId: "S_SHAPE_ONLY_EXECUTE",
|
|
4746
|
+
severity: "error",
|
|
4747
|
+
advice: `Service class '${className}' in '${fileName}' has disallowed public method '${m.name}'. The only allowed public methods are constructor and async execute. If a service has multiple public methods, those should be on their own services instead of being cramped in a single service.`,
|
|
4748
|
+
fixExample: {
|
|
4749
|
+
bad: m.code || `${m.name}(...) { ... }`,
|
|
4750
|
+
good: `// Extract '${m.name}' into its own dedicated Service, or make it private if it is internal helper logic:
|
|
4751
|
+
private ${m.name}(...) { ... }`
|
|
4752
|
+
}
|
|
4753
|
+
});
|
|
4754
|
+
}
|
|
4755
|
+
}
|
|
4756
|
+
}
|
|
4413
4757
|
function lintCodebase(options = {}) {
|
|
4414
4758
|
const startTime = Date.now();
|
|
4415
4759
|
const projectRoot = options.projectRoot || findProjectRoot(options.targetDir || process.cwd());
|
|
@@ -4427,13 +4771,9 @@ function lintCodebase(options = {}) {
|
|
|
4427
4771
|
featureResult.passed = false;
|
|
4428
4772
|
}
|
|
4429
4773
|
if (failFast) {
|
|
4430
|
-
const errorMsg = `
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
Rule: ${v.ruleId}
|
|
4434
|
-
Location: ${v.relativePath}:${v.line}
|
|
4435
|
-
Code: ${v.code}
|
|
4436
|
-
Explanation: ${v.advice}`;
|
|
4774
|
+
const errorMsg = `Dependency rule violation detected in ${v.relativePath}:${v.line}:
|
|
4775
|
+
[${v.category}] ${v.advice}
|
|
4776
|
+
Code: ${v.code}`;
|
|
4437
4777
|
throw new DependencyRuleError(errorMsg, [v], true);
|
|
4438
4778
|
}
|
|
4439
4779
|
};
|
|
@@ -4457,6 +4797,14 @@ function lintCodebase(options = {}) {
|
|
|
4457
4797
|
if (!layer) continue;
|
|
4458
4798
|
const content = fs4.readFileSync(file, "utf-8");
|
|
4459
4799
|
const statements = extractImportStatements(content);
|
|
4800
|
+
const baseName = path2.basename(file);
|
|
4801
|
+
const isBarrel = baseName === "index.ts" || baseName === "index.js";
|
|
4802
|
+
if (layer === "useCases" && !isBarrel) {
|
|
4803
|
+
checkUseCaseShape(feat.name, file, relPath, content, addViolation);
|
|
4804
|
+
}
|
|
4805
|
+
if (layer === "services" && !isBarrel) {
|
|
4806
|
+
checkServiceShape(feat.name, file, relPath, content, addViolation);
|
|
4807
|
+
}
|
|
4460
4808
|
if (layer === "domain") {
|
|
4461
4809
|
const lines = content.split(/\r?\n/);
|
|
4462
4810
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -4867,6 +5215,24 @@ function lintCodebase(options = {}) {
|
|
|
4867
5215
|
}
|
|
4868
5216
|
});
|
|
4869
5217
|
}
|
|
5218
|
+
if (target.targetLayer === "services") {
|
|
5219
|
+
addViolation({
|
|
5220
|
+
feature: feat.name,
|
|
5221
|
+
layer,
|
|
5222
|
+
file,
|
|
5223
|
+
relativePath: relPath,
|
|
5224
|
+
line: stmt.line,
|
|
5225
|
+
category: "Presentation Layer Violation",
|
|
5226
|
+
code: stmt.rawCode,
|
|
5227
|
+
ruleId: "P4_DIRECT_SERVICE",
|
|
5228
|
+
severity: "error",
|
|
5229
|
+
advice: "Presentation handlers must not depend on services directly. They must use use cases, and use cases will then depend on the service.",
|
|
5230
|
+
fixExample: {
|
|
5231
|
+
bad: stmt.rawCode,
|
|
5232
|
+
good: "// Inject a Use Case via static deps instead of a Service."
|
|
5233
|
+
}
|
|
5234
|
+
});
|
|
5235
|
+
}
|
|
4870
5236
|
}
|
|
4871
5237
|
}
|
|
4872
5238
|
}
|
|
@@ -4921,87 +5287,23 @@ ${compiledDetails}
|
|
|
4921
5287
|
}
|
|
4922
5288
|
|
|
4923
5289
|
// src/commands/lint.ts
|
|
4924
|
-
function
|
|
4925
|
-
console.log("");
|
|
4926
|
-
const title = " Mason Clean Architecture Dependency Linter ";
|
|
4927
|
-
const line = "\u2501".repeat(title.length + 2);
|
|
4928
|
-
console.log(pc15.cyan(` \u250F${line}\u2513`));
|
|
4929
|
-
console.log(` ${pc15.cyan("\u2503")} ${pc15.bgCyan(pc15.black(title))} ${pc15.cyan("\u2503")}`);
|
|
4930
|
-
console.log(pc15.cyan(` \u2517${line}\u251B`));
|
|
4931
|
-
const modeText = mode === "failFast" ? `${pc15.yellow("Fail-Fast")} ${pc15.dim("(default: stops at first error)")}` : `${pc15.magenta("Complete")} ${pc15.dim("(--complete: compiles all errors)")}`;
|
|
4932
|
-
console.log(` Mode: ${modeText}`);
|
|
4933
|
-
console.log("");
|
|
4934
|
-
}
|
|
4935
|
-
function formatViolation(v, showFixHint = true) {
|
|
5290
|
+
function formatViolation(v) {
|
|
4936
5291
|
const lines = [];
|
|
4937
|
-
|
|
4938
|
-
const
|
|
4939
|
-
lines.push(
|
|
4940
|
-
|
|
4941
|
-
lines.push(
|
|
4942
|
-
|
|
4943
|
-
if (showFixHint && v.fixExample) {
|
|
4944
|
-
lines.push(` ${pc15.dim("Example:")}`);
|
|
4945
|
-
lines.push(` ${pc15.red(`- ${v.fixExample.bad}`)}`);
|
|
4946
|
-
lines.push(` ${pc15.green(`+ ${v.fixExample.good}`)}`);
|
|
4947
|
-
}
|
|
4948
|
-
return lines.join("\n");
|
|
4949
|
-
}
|
|
4950
|
-
function formatFeatureResult(res, options = {}) {
|
|
4951
|
-
const lines = [];
|
|
4952
|
-
if (res.passed) {
|
|
4953
|
-
lines.push(
|
|
4954
|
-
` ${pc15.green("\u2714")} ${pc15.bold(res.featureName)} ${pc15.dim(
|
|
4955
|
-
`(${res.scannedFilesCount} files checked - clean)`
|
|
4956
|
-
)}`
|
|
4957
|
-
);
|
|
4958
|
-
return lines.join("\n");
|
|
4959
|
-
}
|
|
4960
|
-
const countBadge = pc15.red(
|
|
4961
|
-
`(${res.violations.length} violation${res.violations.length > 1 ? "s" : ""})`
|
|
5292
|
+
lines.push(pc14.underline(pc14.cyan(v.relativePath)) + pc14.dim(":") + pc14.yellow(String(v.line)));
|
|
5293
|
+
const gutter = `${String(v.line).padStart(4, " ")} | `;
|
|
5294
|
+
lines.push(pc14.dim(gutter) + v.code);
|
|
5295
|
+
const categoryShort = v.category.replace(" Violation", "");
|
|
5296
|
+
lines.push(
|
|
5297
|
+
" " + pc14.red(pc14.bold("\u2716")) + " " + pc14.red(`[${categoryShort}]`) + " " + v.advice
|
|
4962
5298
|
);
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
lines.push(` ${pc15.dim("Path:")} ${res.featureDir}`);
|
|
4966
|
-
lines.push("");
|
|
4967
|
-
for (const v of res.violations) {
|
|
4968
|
-
lines.push(formatViolation(v, options.fixHint !== false));
|
|
4969
|
-
lines.push("");
|
|
5299
|
+
if (v.fixExample?.good) {
|
|
5300
|
+
lines.push(" " + pc14.dim("\u2192") + " " + pc14.dim(v.fixExample.good));
|
|
4970
5301
|
}
|
|
4971
5302
|
return lines.join("\n");
|
|
4972
5303
|
}
|
|
4973
|
-
function printTerminalReport(summary, options = {}) {
|
|
4974
|
-
for (const res of summary.results) {
|
|
4975
|
-
const formatted = formatFeatureResult(res, options);
|
|
4976
|
-
if (formatted.trim()) {
|
|
4977
|
-
console.log(formatted);
|
|
4978
|
-
}
|
|
4979
|
-
}
|
|
4980
|
-
console.log("\u2501".repeat(70));
|
|
4981
|
-
const statusIcon = summary.totalViolations === 0 ? pc15.green("\u2714 PASS") : pc15.red("\u2716 FAIL");
|
|
4982
|
-
console.log(
|
|
4983
|
-
` ${statusIcon} ${pc15.bold("Dependency Rules Audit Result")} ${pc15.dim(
|
|
4984
|
-
`(${summary.durationMs}ms)`
|
|
4985
|
-
)}`
|
|
4986
|
-
);
|
|
4987
|
-
console.log(
|
|
4988
|
-
` ${pc15.bold("Features:")} ${pc15.cyan(String(summary.totalFeatures))} total | ${pc15.green(
|
|
4989
|
-
String(summary.cleanFeatures)
|
|
4990
|
-
)} clean | ${summary.violatedFeatures > 0 ? pc15.red(String(summary.violatedFeatures)) : pc15.green("0")} with violations`
|
|
4991
|
-
);
|
|
4992
|
-
console.log(
|
|
4993
|
-
` ${pc15.bold("Violations:")} ${summary.totalViolations > 0 ? pc15.red(pc15.bold(String(summary.totalViolations))) : pc15.green("0")} rule violations found`
|
|
4994
|
-
);
|
|
4995
|
-
console.log("\u2501".repeat(70));
|
|
4996
|
-
console.log("");
|
|
4997
|
-
}
|
|
4998
5304
|
async function handleLint(flags = {}) {
|
|
4999
5305
|
const complete = Boolean(flags.complete);
|
|
5000
|
-
const mode = complete ? "complete" : "failFast";
|
|
5001
5306
|
const quiet = Boolean(flags.quiet);
|
|
5002
|
-
if (!quiet) {
|
|
5003
|
-
printLintBanner(mode);
|
|
5004
|
-
}
|
|
5005
5307
|
const options = {
|
|
5006
5308
|
complete,
|
|
5007
5309
|
quiet,
|
|
@@ -5012,14 +5314,23 @@ async function handleLint(flags = {}) {
|
|
|
5012
5314
|
};
|
|
5013
5315
|
try {
|
|
5014
5316
|
const summary = lintCodebase(options);
|
|
5015
|
-
if (!quiet) {
|
|
5016
|
-
printTerminalReport(summary, options);
|
|
5017
|
-
}
|
|
5018
5317
|
if (summary.totalViolations > 0) {
|
|
5318
|
+
if (!quiet) {
|
|
5319
|
+
console.log("");
|
|
5320
|
+
for (const v of summary.allViolations) {
|
|
5321
|
+
console.log(formatViolation(v));
|
|
5322
|
+
console.log("");
|
|
5323
|
+
}
|
|
5324
|
+
console.log(
|
|
5325
|
+
pc14.red(
|
|
5326
|
+
`\u2716 Dependency rules check failed with ${summary.totalViolations} error${summary.totalViolations > 1 ? "s" : ""} across ${summary.violatedFeatures} feature${summary.violatedFeatures > 1 ? "s" : ""} (${summary.totalFeatures} features scanned).`
|
|
5327
|
+
)
|
|
5328
|
+
);
|
|
5329
|
+
console.log("");
|
|
5330
|
+
}
|
|
5019
5331
|
const errorHeader = `Dependency rule audit failed with ${summary.totalViolations} violation(s) across ${summary.violatedFeatures} feature(s):`;
|
|
5020
5332
|
const compiledDetails = summary.allViolations.map(
|
|
5021
5333
|
(v, i) => `${i + 1}. [${v.category}] ${v.relativePath}:${v.line}
|
|
5022
|
-
Rule: ${v.ruleId}
|
|
5023
5334
|
Code: ${v.code}
|
|
5024
5335
|
Advice: ${v.advice}`
|
|
5025
5336
|
).join("\n\n");
|
|
@@ -5030,20 +5341,22 @@ ${compiledDetails}
|
|
|
5030
5341
|
}
|
|
5031
5342
|
if (!quiet) {
|
|
5032
5343
|
console.log(
|
|
5033
|
-
|
|
5344
|
+
pc14.green(
|
|
5345
|
+
`\u2714 Dependency rules verified across ${summary.totalFeatures} feature${summary.totalFeatures === 1 ? "" : "s"}.`
|
|
5346
|
+
)
|
|
5034
5347
|
);
|
|
5035
|
-
console.log("");
|
|
5036
5348
|
}
|
|
5037
5349
|
return summary;
|
|
5038
5350
|
} catch (err) {
|
|
5039
5351
|
if (err instanceof DependencyRuleError && err.isFailFast) {
|
|
5040
5352
|
if (!quiet) {
|
|
5041
|
-
console.log(
|
|
5042
|
-
\u2716 [FAIL FAST] Terminating on first detected dependency rule violation:`));
|
|
5353
|
+
console.log("");
|
|
5043
5354
|
const v = err.violations[0];
|
|
5044
5355
|
if (v) {
|
|
5045
|
-
console.log(formatViolation(v
|
|
5356
|
+
console.log(formatViolation(v));
|
|
5357
|
+
console.log("");
|
|
5046
5358
|
}
|
|
5359
|
+
console.log(pc14.red(`\u2716 Dependency rules check failed (1 error).`));
|
|
5047
5360
|
console.log("");
|
|
5048
5361
|
}
|
|
5049
5362
|
}
|
|
@@ -5057,7 +5370,7 @@ function createCli() {
|
|
|
5057
5370
|
cli.command("[...args]", "Interactive scaffolding and import wizard").option("-d, --dry-run", "Preview changes without writing to disk").option("-o, --overwrite", "Overwrite existing files").option("-y, --yes", "Accept defaults and skip interactive prompts").option("--registry", "Run in registry mode").option("--point-to <mapping>", "Point a dependency to an existing local module (e.g. --point-to time:mytime)").option("--alias <mapping>", "Import a dependency fresh under an alias name (e.g. --alias time:time-mason)").option("--tests", "Include test files (use --no-tests to exclude)").action(async (args, flags) => {
|
|
5058
5371
|
if (args && args.length > 0) {
|
|
5059
5372
|
p14.log.error(
|
|
5060
|
-
|
|
5373
|
+
pc14.red(
|
|
5061
5374
|
`Unknown command: "${args.join(" ")}". Use --help to list available commands.`
|
|
5062
5375
|
)
|
|
5063
5376
|
);
|
|
@@ -5176,6 +5489,12 @@ function createCli() {
|
|
|
5176
5489
|
targetDir: target || flags.target || flags.dest
|
|
5177
5490
|
});
|
|
5178
5491
|
} catch (err) {
|
|
5492
|
+
if (err instanceof DependencyRuleError) {
|
|
5493
|
+
if (process.env.VITEST) {
|
|
5494
|
+
throw err;
|
|
5495
|
+
}
|
|
5496
|
+
process.exit(1);
|
|
5497
|
+
}
|
|
5179
5498
|
handleCliError(err);
|
|
5180
5499
|
}
|
|
5181
5500
|
});
|
|
@@ -5210,7 +5529,7 @@ function handleCliError(err) {
|
|
|
5210
5529
|
process.exit(0);
|
|
5211
5530
|
}
|
|
5212
5531
|
const message = err instanceof Error ? err.message : String(err);
|
|
5213
|
-
p14.log.error(
|
|
5532
|
+
p14.log.error(pc14.red(`Error: ${message}`));
|
|
5214
5533
|
if (process.env.VITEST) {
|
|
5215
5534
|
throw err;
|
|
5216
5535
|
}
|