@domain-first/project-structure 7.1.1 → 8.0.0
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/README.md +128 -25
- package/dist/201.js +146 -342
- package/dist/287.js +1304 -568
- package/dist/561.js +518 -0
- package/dist/711.js +22 -0
- package/dist/870.js +438 -0
- package/dist/agent-cli.d.ts +378 -0
- package/dist/agent-cli.spec.d.ts +1 -0
- package/dist/agent-identifiers.d.ts +4 -0
- package/dist/agent-requests.d.ts +488 -0
- package/dist/backend-module-move.d.ts +1 -0
- package/dist/config-file.d.ts +231 -26
- package/dist/config-file.spec.d.ts +1 -0
- package/dist/context-dependencies.d.ts +16 -0
- package/dist/dependency-rules.d.ts +17 -17
- package/dist/file-system.d.ts +10 -1
- package/dist/implementation-choices.d.ts +8 -0
- package/dist/implementation-choices.spec.d.ts +1 -0
- package/dist/implementation-options-schema.d.ts +14 -0
- package/dist/implementations.d.ts +48 -0
- package/dist/index.cjs +3768 -574
- package/dist/index.js +25 -9
- package/dist/init.cjs +717 -122
- package/dist/init.js +24 -12
- package/dist/integration.cjs +3737 -186
- package/dist/integration.js +29 -17
- package/dist/integrations/rest-endpoint-generator.d.ts +4 -2
- package/dist/integrations/storybook.d.ts +1 -0
- package/dist/interaction.d.ts +41 -0
- package/dist/lint.cjs +173 -46
- package/dist/lint.js +22 -7
- package/dist/next-app.d.ts +7 -0
- package/dist/react.cjs +5128 -414
- package/dist/react.js +72 -60
- package/dist/system-implementations.d.ts +6 -0
- package/dist/upgrade-steps.d.ts +81 -0
- package/dist/upgrade-steps.spec.d.ts +1 -0
- package/dist/upgrade.cjs +593 -0
- package/dist/upgrade.d.ts +2 -0
- package/dist/upgrade.js +235 -0
- package/dist/use-cases/add-integration.d.ts +16 -1
- package/dist/use-cases/cross-context-dependencies.spec.d.ts +1 -0
- package/dist/use-cases/index.d.ts +1 -0
- package/dist/use-cases/initialize.d.ts +4 -4
- package/dist/use-cases/initialize.spec.d.ts +1 -0
- package/dist/use-cases/prompt-implementation-type.d.ts +20 -0
- package/dist/use-cases/scaffold-new-aggregate.d.ts +1 -1
- package/dist/use-cases/scaffold-new-implementation.d.ts +6 -0
- package/dist/use-cases/scaffold-new-implementation.spec.d.ts +1 -0
- package/dist/use-cases/scaffold-react-page.d.ts +3 -1
- package/dist/use-cases/wire-dependency.d.ts +5 -0
- package/dist/wire-branches.d.ts +26 -0
- package/dist/wiring.d.ts +24 -2
- package/package.json +3 -2
- package/skills/df-ps-implement/SKILL.md +9 -8
- package/skills/df-ps-plan-feature/SKILL.md +8 -7
- package/skills/df-ps-react/SKILL.md +13 -7
- package/skills/df-ps-react/references/generators.md +6 -2
- package/skills/df-ps-scaffold/SKILL.md +31 -19
- package/skills/df-ps-scaffold/references/agent-mode.md +72 -0
- package/skills/df-ps-scaffold/references/agent-operations.md +155 -0
- package/skills/df-ps-scaffold/references/choosing-components.md +14 -13
- package/skills/df-ps-scaffold/references/generators.md +20 -3
- package/skills/df-ps-scaffold/references/units/aggregate.md +4 -3
- package/skills/df-ps-scaffold/references/units/bounded-context.md +1 -1
- package/skills/df-ps-scaffold/references/units/command-query.md +12 -12
- package/skills/df-ps-scaffold/references/units/implementation.md +20 -0
- package/skills/df-ps-scaffold/references/units/move-or-rename.md +1 -1
- package/skills/df-ps-scaffold/references/units/port.md +7 -4
- package/skills/df-ps-scaffold/references/units/use-case.md +1 -1
- package/skills/df-ps-scaffold/scripts/drive.mjs +9 -1
package/dist/integration.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
|
-
import {
|
|
3
|
+
import { runCLI } from "./561.js";
|
|
4
|
+
import { ConfigFile, outdatedConfigMessage } from "./870.js";
|
|
4
5
|
import { addIntegration } from "./287.js";
|
|
5
|
-
|
|
6
|
+
runCLI('df-integration', async ()=>{
|
|
7
|
+
const help = `Usage: df-integration
|
|
6
8
|
|
|
7
9
|
Adds integrations to a Domain-First project: the REST endpoint generator,
|
|
8
10
|
the in-memory DB, Storybook, Prisma, Vitest, Playwright, integration tests,
|
|
@@ -10,22 +12,32 @@ OpenAPI and Orval. Several can be selected at once. Changes project files and pr
|
|
|
10
12
|
the install commands; nothing is installed or run.
|
|
11
13
|
|
|
12
14
|
Options:
|
|
15
|
+
--request <json|-> execute an operation without prompts; - reads stdin
|
|
16
|
+
--describe output request schema and project IDs as JSON
|
|
13
17
|
-h, --help show this help`;
|
|
14
|
-
const { values
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const { values } = parseArgs({
|
|
19
|
+
options: {
|
|
20
|
+
help: {
|
|
21
|
+
type: 'boolean',
|
|
22
|
+
short: 'h',
|
|
23
|
+
default: false
|
|
24
|
+
}
|
|
20
25
|
}
|
|
26
|
+
});
|
|
27
|
+
if (values.help) {
|
|
28
|
+
console.log(help);
|
|
29
|
+
process.exit(0);
|
|
21
30
|
}
|
|
31
|
+
if (!ConfigFile.exists) {
|
|
32
|
+
console.log('No domain-first.project-structure.config.json found: run df-init first to initialize the project.');
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
if (ConfigFile.outdated) {
|
|
36
|
+
console.log(outdatedConfigMessage);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
await addIntegration();
|
|
40
|
+
}).catch((error)=>{
|
|
41
|
+
console.error(error);
|
|
42
|
+
process.exitCode = 1;
|
|
22
43
|
});
|
|
23
|
-
if (values.help) {
|
|
24
|
-
console.log(help);
|
|
25
|
-
process.exit(0);
|
|
26
|
-
}
|
|
27
|
-
if (!ConfigFile.exists) {
|
|
28
|
-
console.log('No domain-first.project-structure.config.json found: run df-init first to initialize the project.');
|
|
29
|
-
process.exit(1);
|
|
30
|
-
}
|
|
31
|
-
addIntegration();
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export declare const nextRoutePath: (root: string) => string;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Offered only when the config selects Next.js (or the caller says so).
|
|
7
7
|
*/
|
|
8
|
-
export declare const askNextAdapter: (
|
|
8
|
+
export declare const askNextAdapter: ({ nextSelected }?: {
|
|
9
|
+
nextSelected?: boolean;
|
|
10
|
+
}) => Promise<boolean>;
|
|
9
11
|
/**
|
|
10
12
|
* The Shared Kernel endpoint generator and, with the Next adapter, the
|
|
11
13
|
* catch-all route. Existing files are kept: the generator is edited by
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { confirm as interactiveConfirm, input as interactiveInput, Separator } from '@inquirer/prompts';
|
|
2
|
+
export { Separator };
|
|
3
|
+
export declare class RequestError extends Error {
|
|
4
|
+
readonly code: string;
|
|
5
|
+
readonly details?: unknown | undefined;
|
|
6
|
+
constructor(code: string, message: string, details?: unknown | undefined);
|
|
7
|
+
}
|
|
8
|
+
export declare const isNonInteractive: () => boolean;
|
|
9
|
+
export declare const runWithAnswers: <T>(answers: Record<string, unknown>, defaults: Record<string, unknown>, run: () => Promise<T>) => Promise<{
|
|
10
|
+
result: Awaited<T>;
|
|
11
|
+
messages: string[];
|
|
12
|
+
}>;
|
|
13
|
+
export declare const assertAnswersConsumed: () => void;
|
|
14
|
+
export declare const answerFor: (key: string, fallback?: unknown) => unknown;
|
|
15
|
+
export declare const report: (...values: unknown[]) => void;
|
|
16
|
+
export declare const input: (config: Parameters<typeof interactiveInput>[0] & {
|
|
17
|
+
key?: string;
|
|
18
|
+
}) => Promise<string>;
|
|
19
|
+
export declare const confirm: (config: Parameters<typeof interactiveConfirm>[0] & {
|
|
20
|
+
key?: string;
|
|
21
|
+
requestRequired?: boolean;
|
|
22
|
+
}) => Promise<boolean>;
|
|
23
|
+
type Choice<T> = {
|
|
24
|
+
value: T;
|
|
25
|
+
name?: string;
|
|
26
|
+
disabled?: boolean | string;
|
|
27
|
+
checked?: boolean;
|
|
28
|
+
};
|
|
29
|
+
type SelectConfig<T> = {
|
|
30
|
+
message: string;
|
|
31
|
+
key?: string;
|
|
32
|
+
choices: readonly (T | Choice<T> | Separator)[];
|
|
33
|
+
default?: NoInfer<T>;
|
|
34
|
+
pageSize?: number;
|
|
35
|
+
loop?: boolean;
|
|
36
|
+
id?: (value: T) => string;
|
|
37
|
+
};
|
|
38
|
+
export declare const select: <T>(config: SelectConfig<T>) => Promise<T>;
|
|
39
|
+
export declare const checkbox: <T>(config: Omit<SelectConfig<T>, "default"> & {
|
|
40
|
+
required?: boolean;
|
|
41
|
+
}) => Promise<T[]>;
|
package/dist/lint.cjs
CHANGED
|
@@ -55,7 +55,7 @@ const infrastructure = [
|
|
|
55
55
|
'application-ports',
|
|
56
56
|
'infrastructure-services'
|
|
57
57
|
];
|
|
58
|
-
const
|
|
58
|
+
const dependency_rules_defaultDependencies = {
|
|
59
59
|
'domain-services': [
|
|
60
60
|
'domain-services'
|
|
61
61
|
],
|
|
@@ -107,7 +107,7 @@ const resolveDependencyRules = (config = {})=>{
|
|
|
107
107
|
new Set(override)
|
|
108
108
|
];
|
|
109
109
|
const kinds = new Set([
|
|
110
|
-
...
|
|
110
|
+
...dependency_rules_defaultDependencies[kind],
|
|
111
111
|
...override?.add ?? []
|
|
112
112
|
]);
|
|
113
113
|
for (const removed of override?.remove ?? [])kinds.delete(removed);
|
|
@@ -207,6 +207,17 @@ class file_system_File extends FileSystemItem {
|
|
|
207
207
|
if (!alreadyAdded) this.addLine(newLine, separator);
|
|
208
208
|
};
|
|
209
209
|
}
|
|
210
|
+
const implementationKinds = [
|
|
211
|
+
'repositories',
|
|
212
|
+
'commands',
|
|
213
|
+
'queries',
|
|
214
|
+
'ports'
|
|
215
|
+
];
|
|
216
|
+
const implementationLabelSchema = external_zod_default().string().regex(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/);
|
|
217
|
+
const implementationOptionsSchema = external_zod_default().partialRecord(external_zod_default()["enum"](implementationKinds), external_zod_default().object({
|
|
218
|
+
primary: external_zod_default().array(implementationLabelSchema).default([]),
|
|
219
|
+
test: external_zod_default().array(implementationLabelSchema).default([])
|
|
220
|
+
}).strict());
|
|
210
221
|
class ProjectRoot {
|
|
211
222
|
path;
|
|
212
223
|
constructor(){
|
|
@@ -230,48 +241,141 @@ const lintChecks = [
|
|
|
230
241
|
'clock'
|
|
231
242
|
];
|
|
232
243
|
const configFileName = 'domain-first.project-structure.config.json';
|
|
233
|
-
const
|
|
234
|
-
rootFolder: external_zod_default().string()
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
244
|
+
const projectConfigSchema = external_zod_default().object({
|
|
245
|
+
rootFolder: external_zod_default().string().min(1)
|
|
246
|
+
}).passthrough();
|
|
247
|
+
const domainFirstPackages = [
|
|
248
|
+
'@domain-first/types',
|
|
249
|
+
'@domain-first/errors',
|
|
250
|
+
'@domain-first/handlers',
|
|
251
|
+
'@domain-first/wire',
|
|
252
|
+
'@domain-first/handlers-rest'
|
|
253
|
+
];
|
|
254
|
+
const rulesSchema = external_zod_default().object({
|
|
255
|
+
dependencies: dependencyRulesSchema.optional(),
|
|
256
|
+
lint: external_zod_default().partialRecord(external_zod_default()["enum"](lintChecks), external_zod_default().boolean()).optional()
|
|
257
|
+
});
|
|
258
|
+
const branchNameSchema = external_zod_default().string().regex(/^[a-z][a-z0-9]*$/, 'Use lowercase letters and digits, e.g. staging.');
|
|
259
|
+
const envBranchesSchema = external_zod_default().object({
|
|
260
|
+
names: external_zod_default().array(branchNameSchema).min(1),
|
|
261
|
+
test: branchNameSchema.optional()
|
|
262
|
+
}).refine(({ names })=>new Set(names).size === names.length, {
|
|
263
|
+
message: 'Branch names must be unique.'
|
|
264
|
+
}).refine(({ names, test })=>void 0 === test || names.includes(test), {
|
|
265
|
+
message: 'The test branch must be one of the branches.'
|
|
266
|
+
}).refine(({ names, test })=>void 0 === test || names.length > 1, {
|
|
267
|
+
message: 'The primary implementation needs a branch besides the test one.'
|
|
268
|
+
});
|
|
269
|
+
const backendConfigSchema = external_zod_default().object({
|
|
270
|
+
domainFirstPackages: external_zod_default().array(external_zod_default()["enum"](domainFirstPackages)),
|
|
271
|
+
envBranches: envBranchesSchema.optional(),
|
|
243
272
|
withInMemoryDb: external_zod_default().boolean().optional(),
|
|
244
|
-
useReact: external_zod_default().boolean(),
|
|
245
|
-
storybookFramework: external_zod_default().string().optional(),
|
|
246
273
|
testingLibrary: external_zod_default().string().optional(),
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
274
|
+
implementations: implementationOptionsSchema.optional(),
|
|
275
|
+
rules: rulesSchema.optional()
|
|
276
|
+
}).passthrough();
|
|
277
|
+
const reactConfigSchema = external_zod_default().object({
|
|
278
|
+
framework: external_zod_default()["enum"]([
|
|
279
|
+
'react',
|
|
280
|
+
'next'
|
|
281
|
+
]).optional(),
|
|
282
|
+
storybookFramework: external_zod_default().string().optional()
|
|
283
|
+
}).passthrough();
|
|
284
|
+
const frontendConfigSchema = external_zod_default().object({
|
|
285
|
+
react: reactConfigSchema.optional()
|
|
286
|
+
}).passthrough();
|
|
287
|
+
const configSchema = external_zod_default().object({
|
|
288
|
+
project: projectConfigSchema,
|
|
289
|
+
backend: backendConfigSchema.optional(),
|
|
290
|
+
frontend: frontendConfigSchema.optional()
|
|
291
|
+
}).passthrough();
|
|
292
|
+
const isOutdatedConfig = (value)=>'object' == typeof value && null !== value && !Array.isArray(value) && !('project' in value);
|
|
293
|
+
const outdatedConfigMessage = `${configFileName} uses the format of an earlier major version: run npx df-upgrade.`;
|
|
294
|
+
class ConfigOutdatedError extends Error {
|
|
295
|
+
constructor(){
|
|
296
|
+
super(outdatedConfigMessage);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
252
299
|
class ConfigFile {
|
|
253
300
|
data;
|
|
254
301
|
constructor(){
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
this.data = configSchema.parse(configObject);
|
|
302
|
+
const raw = JSON.parse(new file_system_File(ConfigFile.path).data);
|
|
303
|
+
if (isOutdatedConfig(raw)) throw new ConfigOutdatedError();
|
|
304
|
+
this.data = configSchema.parse(raw);
|
|
259
305
|
}
|
|
260
306
|
static get Instance() {
|
|
261
307
|
return new ConfigFile();
|
|
262
308
|
}
|
|
309
|
+
static get backend() {
|
|
310
|
+
const backend = ConfigFile.Instance.data.backend;
|
|
311
|
+
if (!backend) throw new Error('Backend is not configured: run df-init --section backend.');
|
|
312
|
+
return backend;
|
|
313
|
+
}
|
|
263
314
|
static get path() {
|
|
264
|
-
|
|
265
|
-
return external_node_path_default().resolve(root, configFileName);
|
|
315
|
+
return external_node_path_default().resolve(new ProjectRoot().path, configFileName);
|
|
266
316
|
}
|
|
267
317
|
static get exists() {
|
|
268
318
|
return new file_system_File(ConfigFile.path).exists;
|
|
269
319
|
}
|
|
320
|
+
static get outdated() {
|
|
321
|
+
if (!ConfigFile.exists) return false;
|
|
322
|
+
try {
|
|
323
|
+
return isOutdatedConfig(JSON.parse(new file_system_File(ConfigFile.path).data));
|
|
324
|
+
} catch {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
270
328
|
static write = (config)=>{
|
|
271
|
-
|
|
329
|
+
ConfigFile.stage(configSchema.parse(config));
|
|
330
|
+
};
|
|
331
|
+
static update = (sections)=>{
|
|
332
|
+
ConfigFile.stage(configSchema.parse({
|
|
333
|
+
...ConfigFile.Instance.data,
|
|
334
|
+
...sections
|
|
335
|
+
}));
|
|
272
336
|
};
|
|
337
|
+
static stage(config) {
|
|
338
|
+
new file_system_File(ConfigFile.path).update(`${JSON.stringify(config, null, 4)}\n`);
|
|
339
|
+
}
|
|
273
340
|
}
|
|
274
|
-
const config_file_configuredDependencyRules = ()=>resolveDependencyRules(ConfigFile.exists ? ConfigFile.Instance.data.rules?.dependencies : void 0);
|
|
341
|
+
const config_file_configuredDependencyRules = ()=>resolveDependencyRules(ConfigFile.exists ? ConfigFile.Instance.data.backend?.rules?.dependencies : void 0);
|
|
342
|
+
const crossContextImplementation = 'cross-context';
|
|
343
|
+
const context_dependencies_boundedContextLocation = (file)=>{
|
|
344
|
+
const parts = external_node_path_default().resolve(file).split(external_node_path_default().sep);
|
|
345
|
+
const index = parts.lastIndexOf('bounded-contexts');
|
|
346
|
+
if (-1 === index || parts.length < index + 3) return;
|
|
347
|
+
return {
|
|
348
|
+
root: parts.slice(0, index).join(external_node_path_default().sep),
|
|
349
|
+
name: parts[index + 1],
|
|
350
|
+
segments: parts.slice(index + 2)
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
const isCrossContextImplementation = (file)=>{
|
|
354
|
+
const location = context_dependencies_boundedContextLocation(file);
|
|
355
|
+
const [layer, kind, label] = location?.segments ?? [];
|
|
356
|
+
return 'infrastructure' === layer && 'application-adapters' === kind && label === crossContextImplementation;
|
|
357
|
+
};
|
|
358
|
+
const context_dependencies_crossContextImportAllowed = (from, to)=>{
|
|
359
|
+
const source = context_dependencies_boundedContextLocation(from);
|
|
360
|
+
const target = context_dependencies_boundedContextLocation(to);
|
|
361
|
+
if (!source || !target || source.name === target.name) return;
|
|
362
|
+
if (source.root !== target.root) return false;
|
|
363
|
+
const [layer, kind] = source.segments;
|
|
364
|
+
const [targetLayer, targetKind] = target.segments;
|
|
365
|
+
if ('wiring' === targetLayer && !external_node_path_default().basename(to).startsWith('wire-')) return false;
|
|
366
|
+
if (/\.(spec|test)\.[^.]+$/.test(to)) return false;
|
|
367
|
+
const suffix = {
|
|
368
|
+
queries: '-query',
|
|
369
|
+
commands: '-command',
|
|
370
|
+
'use-cases': '-use-case'
|
|
371
|
+
}[targetKind];
|
|
372
|
+
if (!suffix || !new RegExp(`${suffix}(\\.(?:c|m)?[jt]sx?)?$`).test(to)) return false;
|
|
373
|
+
return [
|
|
374
|
+
'queries',
|
|
375
|
+
'commands',
|
|
376
|
+
'use-cases'
|
|
377
|
+
].includes(targetKind) && (isCrossContextImplementation(from) && 'application' === targetLayer || 'wiring' === layer && 'application-ports' === kind && 'wiring' === targetLayer);
|
|
378
|
+
};
|
|
275
379
|
const external_node_module_namespaceObject = require("node:module");
|
|
276
380
|
const stripJsonComments = (source)=>source.replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (_, text)=>text ? text : '').replace(/,(\s*[}\]])/g, '$1');
|
|
277
381
|
const resolveExtends = (fromFile, target)=>{
|
|
@@ -306,7 +410,7 @@ const compilerOption = (configFile, name, seen = new Set())=>{
|
|
|
306
410
|
if (void 0 !== value) return value;
|
|
307
411
|
}
|
|
308
412
|
};
|
|
309
|
-
class
|
|
413
|
+
class unknown_format_naming_UnknownFormatNaming {
|
|
310
414
|
rawSource;
|
|
311
415
|
camelCase;
|
|
312
416
|
PascalCase;
|
|
@@ -385,11 +489,15 @@ const layerOf = (file, contextPath)=>{
|
|
|
385
489
|
const [firstSegment] = external_node_path_default().relative(contextPath, file).split(external_node_path_default().sep);
|
|
386
490
|
return wiring_layers.find((layer)=>layer === firstSegment);
|
|
387
491
|
};
|
|
388
|
-
const
|
|
492
|
+
const withoutScriptExtension = (file)=>file.replace(/\.(?:c|m)?[jt]s$/, '');
|
|
493
|
+
const namedImportFiles = (source, fromFile, resolve = (specifier, file)=>specifier.startsWith('.') ? external_node_path_default().resolve(external_node_path_default().dirname(file), specifier) : void 0)=>{
|
|
389
494
|
const result = new Map();
|
|
390
|
-
for (const [, names, importPath] of source.matchAll(/import\s*(?:type\s*)?\{([^}]*)\}\s*from\s*['"]([^'"]+)['"]/g))
|
|
391
|
-
const
|
|
392
|
-
if (
|
|
495
|
+
for (const [, names, importPath] of source.matchAll(/import\s*(?:type\s*)?\{([^}]*)\}\s*from\s*['"]([^'"]+)['"]/g)){
|
|
496
|
+
const target = resolve(importPath, fromFile);
|
|
497
|
+
if (target) for (const name of names.split(',')){
|
|
498
|
+
const cleanName = name.replace(/^\s*type\s+/, '').trim().split(/\s+as\s+/).at(-1);
|
|
499
|
+
if (cleanName) result.set(cleanName, `${withoutScriptExtension(target)}.ts`);
|
|
500
|
+
}
|
|
393
501
|
}
|
|
394
502
|
return result;
|
|
395
503
|
};
|
|
@@ -415,11 +523,11 @@ const readWiredModule = (wireFile, contextPath)=>{
|
|
|
415
523
|
const wiringRelativePath = external_node_path_default().relative(external_node_path_default().join(contextPath, 'wiring'), wireFile);
|
|
416
524
|
if (isEndpointWire(wiringRelativePath)) return;
|
|
417
525
|
const source = new file_system_File(wireFile).data;
|
|
418
|
-
const wireName = `wire${new
|
|
526
|
+
const wireName = `wire${new unknown_format_naming_UnknownFormatNaming(external_node_path_default().basename(wireFile, '.ts').replace(/^wire-/, '')).ClassName}`;
|
|
419
527
|
const exportMatch = new RegExp(`export\\s+const\\s+${wireName}\\s*=\\s*`).exec(source);
|
|
420
528
|
if (!exportMatch) return;
|
|
421
529
|
const branched = source.slice(exportMatch.index + exportMatch[0].length).startsWith('envBranchedWire(');
|
|
422
|
-
const imports =
|
|
530
|
+
const imports = namedImportFiles(source, wireFile);
|
|
423
531
|
const implementations = wiredClassNames(source, wireName, exportMatch.index + exportMatch[0].length, branched).flatMap((className)=>{
|
|
424
532
|
const file = imports.get(className);
|
|
425
533
|
return file ? [
|
|
@@ -469,7 +577,9 @@ const findWiredModules = (contextPath)=>{
|
|
|
469
577
|
};
|
|
470
578
|
const moduleKindOf = (module)=>wiredModuleKind(module.kind);
|
|
471
579
|
const wiring_layerRule = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && ('infrastructure' !== consumer.implementationsLayer || 'application' !== candidate.layer || 'application-ports' === candidate.kind);
|
|
472
|
-
const canDependOn = (consumer, candidate, rules = defaultDependencyRules)=>{
|
|
580
|
+
const canDependOn = (consumer, candidate, rules = defaultDependencyRules, implementation = consumer.implementations[0])=>{
|
|
581
|
+
const crossContext = context_dependencies_crossContextImportAllowed(consumer.wireFile, candidate.wireFile);
|
|
582
|
+
if (void 0 !== crossContext) return crossContext && 'infrastructure' === consumer.implementationsLayer && 'application' === candidate.layer && !!implementation && true === context_dependencies_crossContextImportAllowed(implementation.file, candidate.typeFile);
|
|
473
583
|
const consumerKind = moduleKindOf(consumer);
|
|
474
584
|
const candidateKind = moduleKindOf(candidate);
|
|
475
585
|
return consumerKind && candidateKind ? rules[consumerKind].has(candidateKind) : wiring_layerRule(consumer, candidate);
|
|
@@ -522,9 +632,9 @@ const closingIndex = (source, openIndex)=>{
|
|
|
522
632
|
}
|
|
523
633
|
return -1;
|
|
524
634
|
};
|
|
525
|
-
const
|
|
635
|
+
const topLevelItemRanges = (content)=>{
|
|
526
636
|
const code = codeOnly(content);
|
|
527
|
-
const
|
|
637
|
+
const ranges = [];
|
|
528
638
|
let depth = 0;
|
|
529
639
|
let itemStart = 0;
|
|
530
640
|
for(let index = 0; index <= code.length; index++){
|
|
@@ -532,16 +642,19 @@ const splitTopLevel = (content)=>{
|
|
|
532
642
|
if (void 0 !== char && char in brackets) depth++;
|
|
533
643
|
else if (Object.values(brackets).includes(char)) depth--;
|
|
534
644
|
if (index === code.length || ',' === char && 0 === depth) {
|
|
535
|
-
const item = content.slice(itemStart, index);
|
|
536
645
|
const itemCode = code.slice(itemStart, index);
|
|
537
646
|
const first = itemCode.search(/\S/);
|
|
538
647
|
const last = itemCode.search(/\S\s*$/);
|
|
539
|
-
if (-1 !== first)
|
|
648
|
+
if (-1 !== first) ranges.push({
|
|
649
|
+
start: itemStart + first,
|
|
650
|
+
end: itemStart + last + 1
|
|
651
|
+
});
|
|
540
652
|
itemStart = index + 1;
|
|
541
653
|
}
|
|
542
654
|
}
|
|
543
|
-
return
|
|
655
|
+
return ranges;
|
|
544
656
|
};
|
|
657
|
+
const splitTopLevel = (content)=>topLevelItemRanges(content).map(({ start, end })=>content.slice(start, end));
|
|
545
658
|
const wireListRange = (source, className)=>{
|
|
546
659
|
const match = new RegExp(`wireClass\\(\\s*${className}\\s*,\\s*\\[`).exec(codeOnly(source));
|
|
547
660
|
if (!match) throw new Error(`wireClass(${className}, [...]) not found`);
|
|
@@ -669,6 +782,7 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
669
782
|
const source = external_node_fs_default().readFileSync(file, 'utf8');
|
|
670
783
|
const from = locate(file);
|
|
671
784
|
const ownContext = inside(contextsFolder, file)?.[0];
|
|
785
|
+
const directWiring = ownContext && from?.segments[0] === 'wiring' && readWiredModule(file, external_node_path_default().join(contextsFolder, ownContext))?.implementations.some((implementation)=>isCrossContextImplementation(implementation.file));
|
|
672
786
|
const report = (check, rule, imported)=>violations.push({
|
|
673
787
|
check,
|
|
674
788
|
rule,
|
|
@@ -681,8 +795,9 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
681
795
|
if (!target) continue;
|
|
682
796
|
const to = locate(target);
|
|
683
797
|
const targetContext = inside(contextsFolder, target)?.[0];
|
|
798
|
+
const crossContextAllowed = true === context_dependencies_crossContextImportAllowed(file, target) && (from?.segments[0] !== 'wiring' || directWiring);
|
|
684
799
|
if (ownContext) {
|
|
685
|
-
if (targetContext && targetContext !== ownContext) report('context-isolation', `[${ownContext}] imports another context:`, imported);
|
|
800
|
+
if (targetContext && targetContext !== ownContext && !crossContextAllowed) report('context-isolation', `[${ownContext}] imports another context:`, imported);
|
|
686
801
|
} else if (inside(sharedFolder, file)) {
|
|
687
802
|
const allowed = !to || 'shared-kernel' === to.owner || 'domain' === to.segments[0] && 'errors' === to.segments[1] || file === inMemoryDbFile && isDomainModel(to.segments, target);
|
|
688
803
|
if (!allowed) report('shared-kernel', '[shared-kernel] imports a bounded context outside its domain/errors (and domain models for the in-memory DB):', imported);
|
|
@@ -702,6 +817,7 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
702
817
|
const targetWidget = widgetOf(target);
|
|
703
818
|
if (ownWidget && targetWidget && targetWidget !== ownWidget) report('react', '[presentation/react/widgets] a widget imports another widget:', imported);
|
|
704
819
|
if (!from || !to) continue;
|
|
820
|
+
if (crossContextAllowed) continue;
|
|
705
821
|
if (isSpec(file)) continue;
|
|
706
822
|
const fromKind = fileModuleKind(from.segments);
|
|
707
823
|
const toKind = fileModuleKind(to.segments);
|
|
@@ -733,6 +849,11 @@ const wiringViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
733
849
|
})) : []
|
|
734
850
|
];
|
|
735
851
|
const violations = [];
|
|
852
|
+
const allModules = new Map(owners.flatMap(({ modules })=>modules).map((module)=>[
|
|
853
|
+
module.wireFile,
|
|
854
|
+
module
|
|
855
|
+
]));
|
|
856
|
+
const aliases = readAliases(projectRoot);
|
|
736
857
|
for (const { name, modules } of owners){
|
|
737
858
|
const visible = new Map([
|
|
738
859
|
...sharedModules,
|
|
@@ -743,6 +864,7 @@ const wiringViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
743
864
|
]));
|
|
744
865
|
for (const consumer of modules){
|
|
745
866
|
const source = external_node_fs_default().readFileSync(consumer.wireFile, 'utf8');
|
|
867
|
+
const imported = namedImportFiles(source, consumer.wireFile, (specifier, file)=>resolveSpecifier(specifier, file, aliases));
|
|
746
868
|
for (const implementation of consumer.implementations){
|
|
747
869
|
let dependencies;
|
|
748
870
|
try {
|
|
@@ -752,8 +874,9 @@ const wiringViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
752
874
|
}
|
|
753
875
|
const listStart = source.search(new RegExp(`wireClass\\(\\s*${implementation.className}\\b`));
|
|
754
876
|
for (const dependency of dependencies){
|
|
755
|
-
const
|
|
756
|
-
|
|
877
|
+
const target = imported.get(dependency);
|
|
878
|
+
const candidate = (target ? allModules.get(target) : void 0) ?? visible.get(dependency);
|
|
879
|
+
if (!candidate || canDependOn(consumer, candidate, rules, implementation)) continue;
|
|
757
880
|
const index = source.indexOf(dependency, listStart);
|
|
758
881
|
violations.push({
|
|
759
882
|
check: 'dependencies',
|
|
@@ -814,7 +937,7 @@ Reports what breaks the Domain-First rules in the project:
|
|
|
814
937
|
bounded context isolation, layers, dependency rules (imports and wiring),
|
|
815
938
|
React modules, and reading the time without the clock port.
|
|
816
939
|
rootFolder defaults to the one in domain-first.project-structure.config.json,
|
|
817
|
-
whose optional \`rules\` change the dependency rules and turn checks off.
|
|
940
|
+
whose optional \`backend.rules\` change the dependency rules and turn checks off.
|
|
818
941
|
Exits with 1 when something is found.
|
|
819
942
|
|
|
820
943
|
Options:
|
|
@@ -834,11 +957,15 @@ if (values.help) {
|
|
|
834
957
|
process.exit(0);
|
|
835
958
|
}
|
|
836
959
|
const lint_projectRoot = new ProjectRoot().path;
|
|
960
|
+
if (ConfigFile.outdated) {
|
|
961
|
+
console.log(outdatedConfigMessage);
|
|
962
|
+
process.exit(1);
|
|
963
|
+
}
|
|
837
964
|
const lint_config = ConfigFile.exists ? ConfigFile.Instance.data : void 0;
|
|
838
|
-
const lint_rootFolder = positionals[0] ?? lint_config?.rootFolder ?? 'src';
|
|
965
|
+
const lint_rootFolder = positionals[0] ?? lint_config?.project.rootFolder ?? 'src';
|
|
839
966
|
const lint_violations = lintProject(lint_projectRoot, lint_rootFolder, {
|
|
840
967
|
rules: config_file_configuredDependencyRules(),
|
|
841
|
-
checks: lint_config?.rules?.lint
|
|
968
|
+
checks: lint_config?.backend?.rules?.lint
|
|
842
969
|
});
|
|
843
970
|
if (lint_violations.length) {
|
|
844
971
|
console.log(formatViolations(lint_violations, lint_projectRoot));
|
package/dist/lint.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
3
|
import node_fs from "node:fs";
|
|
4
4
|
import node_path from "node:path";
|
|
5
|
-
import {
|
|
5
|
+
import { canDependOn, namedImportFiles, isCrossContextImplementation, findWiredModules, moduleKindOf, readWiredModule, crossContextImportAllowed, compilerOption, wiredDependencyNames } from "./201.js";
|
|
6
|
+
import { defaultDependencyRules, fileModuleKind, configuredDependencyRules, ProjectRoot, ConfigFile, outdatedConfigMessage } from "./870.js";
|
|
6
7
|
const readAliases = (projectRoot)=>{
|
|
7
8
|
const tsconfig = node_path.join(projectRoot, 'tsconfig.json');
|
|
8
9
|
const paths = compilerOption(tsconfig, 'paths');
|
|
@@ -117,6 +118,7 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
117
118
|
const source = node_fs.readFileSync(file, 'utf8');
|
|
118
119
|
const from = locate(file);
|
|
119
120
|
const ownContext = inside(contextsFolder, file)?.[0];
|
|
121
|
+
const directWiring = ownContext && from?.segments[0] === 'wiring' && readWiredModule(file, node_path.join(contextsFolder, ownContext))?.implementations.some((implementation)=>isCrossContextImplementation(implementation.file));
|
|
120
122
|
const report = (check, rule, imported)=>violations.push({
|
|
121
123
|
check,
|
|
122
124
|
rule,
|
|
@@ -129,8 +131,9 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
129
131
|
if (!target) continue;
|
|
130
132
|
const to = locate(target);
|
|
131
133
|
const targetContext = inside(contextsFolder, target)?.[0];
|
|
134
|
+
const crossContextAllowed = true === crossContextImportAllowed(file, target) && (from?.segments[0] !== 'wiring' || directWiring);
|
|
132
135
|
if (ownContext) {
|
|
133
|
-
if (targetContext && targetContext !== ownContext) report('context-isolation', `[${ownContext}] imports another context:`, imported);
|
|
136
|
+
if (targetContext && targetContext !== ownContext && !crossContextAllowed) report('context-isolation', `[${ownContext}] imports another context:`, imported);
|
|
134
137
|
} else if (inside(sharedFolder, file)) {
|
|
135
138
|
const allowed = !to || 'shared-kernel' === to.owner || 'domain' === to.segments[0] && 'errors' === to.segments[1] || file === inMemoryDbFile && isDomainModel(to.segments, target);
|
|
136
139
|
if (!allowed) report('shared-kernel', '[shared-kernel] imports a bounded context outside its domain/errors (and domain models for the in-memory DB):', imported);
|
|
@@ -150,6 +153,7 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
150
153
|
const targetWidget = widgetOf(target);
|
|
151
154
|
if (ownWidget && targetWidget && targetWidget !== ownWidget) report('react', '[presentation/react/widgets] a widget imports another widget:', imported);
|
|
152
155
|
if (!from || !to) continue;
|
|
156
|
+
if (crossContextAllowed) continue;
|
|
153
157
|
if (isSpec(file)) continue;
|
|
154
158
|
const fromKind = fileModuleKind(from.segments);
|
|
155
159
|
const toKind = fileModuleKind(to.segments);
|
|
@@ -181,6 +185,11 @@ const wiringViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
181
185
|
})) : []
|
|
182
186
|
];
|
|
183
187
|
const violations = [];
|
|
188
|
+
const allModules = new Map(owners.flatMap(({ modules })=>modules).map((module)=>[
|
|
189
|
+
module.wireFile,
|
|
190
|
+
module
|
|
191
|
+
]));
|
|
192
|
+
const aliases = readAliases(projectRoot);
|
|
184
193
|
for (const { name, modules } of owners){
|
|
185
194
|
const visible = new Map([
|
|
186
195
|
...sharedModules,
|
|
@@ -191,6 +200,7 @@ const wiringViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
191
200
|
]));
|
|
192
201
|
for (const consumer of modules){
|
|
193
202
|
const source = node_fs.readFileSync(consumer.wireFile, 'utf8');
|
|
203
|
+
const imported = namedImportFiles(source, consumer.wireFile, (specifier, file)=>resolveSpecifier(specifier, file, aliases));
|
|
194
204
|
for (const implementation of consumer.implementations){
|
|
195
205
|
let dependencies;
|
|
196
206
|
try {
|
|
@@ -200,8 +210,9 @@ const wiringViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
200
210
|
}
|
|
201
211
|
const listStart = source.search(new RegExp(`wireClass\\(\\s*${implementation.className}\\b`));
|
|
202
212
|
for (const dependency of dependencies){
|
|
203
|
-
const
|
|
204
|
-
|
|
213
|
+
const target = imported.get(dependency);
|
|
214
|
+
const candidate = (target ? allModules.get(target) : void 0) ?? visible.get(dependency);
|
|
215
|
+
if (!candidate || canDependOn(consumer, candidate, rules, implementation)) continue;
|
|
205
216
|
const index = source.indexOf(dependency, listStart);
|
|
206
217
|
violations.push({
|
|
207
218
|
check: 'dependencies',
|
|
@@ -262,7 +273,7 @@ Reports what breaks the Domain-First rules in the project:
|
|
|
262
273
|
bounded context isolation, layers, dependency rules (imports and wiring),
|
|
263
274
|
React modules, and reading the time without the clock port.
|
|
264
275
|
rootFolder defaults to the one in domain-first.project-structure.config.json,
|
|
265
|
-
whose optional \`rules\` change the dependency rules and turn checks off.
|
|
276
|
+
whose optional \`backend.rules\` change the dependency rules and turn checks off.
|
|
266
277
|
Exits with 1 when something is found.
|
|
267
278
|
|
|
268
279
|
Options:
|
|
@@ -282,11 +293,15 @@ if (values.help) {
|
|
|
282
293
|
process.exit(0);
|
|
283
294
|
}
|
|
284
295
|
const lint_projectRoot = new ProjectRoot().path;
|
|
296
|
+
if (ConfigFile.outdated) {
|
|
297
|
+
console.log(outdatedConfigMessage);
|
|
298
|
+
process.exit(1);
|
|
299
|
+
}
|
|
285
300
|
const config = ConfigFile.exists ? ConfigFile.Instance.data : void 0;
|
|
286
|
-
const lint_rootFolder = positionals[0] ?? config?.rootFolder ?? 'src';
|
|
301
|
+
const lint_rootFolder = positionals[0] ?? config?.project.rootFolder ?? 'src';
|
|
287
302
|
const lint_violations = lintProject(lint_projectRoot, lint_rootFolder, {
|
|
288
303
|
rules: configuredDependencyRules(),
|
|
289
|
-
checks: config?.rules?.lint
|
|
304
|
+
checks: config?.backend?.rules?.lint
|
|
290
305
|
});
|
|
291
306
|
if (lint_violations.length) {
|
|
292
307
|
console.log(formatViolations(lint_violations, lint_projectRoot));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Next.js is used only when the config selects it explicitly. */
|
|
2
|
+
export declare const usesNext: () => boolean;
|
|
3
|
+
/**
|
|
4
|
+
* The App Router folder: `app` or `src/app`, whichever exists, `app` by
|
|
5
|
+
* default.
|
|
6
|
+
*/
|
|
7
|
+
export declare const nextAppFolder: (root: string) => string;
|