@domain-first/project-structure 7.2.0 → 8.1.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 +125 -26
- package/dist/201.js +87 -338
- package/dist/287.js +1235 -575
- package/dist/561.js +519 -0
- package/dist/711.js +22 -0
- package/dist/870.js +438 -0
- package/dist/agent-cli.d.ts +379 -0
- package/dist/agent-cli.spec.d.ts +1 -0
- package/dist/agent-identifiers.d.ts +4 -0
- package/dist/agent-requests.d.ts +490 -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/index.cjs +3645 -584
- package/dist/index.js +20 -7
- package/dist/init.cjs +717 -122
- package/dist/init.js +24 -12
- package/dist/integration.cjs +3783 -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 +165 -41
- package/dist/lint.js +22 -7
- package/dist/module-move.d.ts +6 -2
- package/dist/next-app.d.ts +7 -0
- package/dist/react-module-move.d.ts +17 -2
- package/dist/react.cjs +5181 -421
- 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/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-react-page.d.ts +3 -1
- package/dist/wire-branches.d.ts +26 -0
- package/dist/wiring.d.ts +3 -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 +14 -8
- package/skills/df-ps-react/references/generators.md +6 -2
- package/skills/df-ps-scaffold/SKILL.md +28 -17
- 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 +13 -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 +2 -2
- 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);
|
|
@@ -672,6 +782,7 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
672
782
|
const source = external_node_fs_default().readFileSync(file, 'utf8');
|
|
673
783
|
const from = locate(file);
|
|
674
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));
|
|
675
786
|
const report = (check, rule, imported)=>violations.push({
|
|
676
787
|
check,
|
|
677
788
|
rule,
|
|
@@ -684,8 +795,9 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
684
795
|
if (!target) continue;
|
|
685
796
|
const to = locate(target);
|
|
686
797
|
const targetContext = inside(contextsFolder, target)?.[0];
|
|
798
|
+
const crossContextAllowed = true === context_dependencies_crossContextImportAllowed(file, target) && (from?.segments[0] !== 'wiring' || directWiring);
|
|
687
799
|
if (ownContext) {
|
|
688
|
-
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);
|
|
689
801
|
} else if (inside(sharedFolder, file)) {
|
|
690
802
|
const allowed = !to || 'shared-kernel' === to.owner || 'domain' === to.segments[0] && 'errors' === to.segments[1] || file === inMemoryDbFile && isDomainModel(to.segments, target);
|
|
691
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);
|
|
@@ -705,6 +817,7 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
705
817
|
const targetWidget = widgetOf(target);
|
|
706
818
|
if (ownWidget && targetWidget && targetWidget !== ownWidget) report('react', '[presentation/react/widgets] a widget imports another widget:', imported);
|
|
707
819
|
if (!from || !to) continue;
|
|
820
|
+
if (crossContextAllowed) continue;
|
|
708
821
|
if (isSpec(file)) continue;
|
|
709
822
|
const fromKind = fileModuleKind(from.segments);
|
|
710
823
|
const toKind = fileModuleKind(to.segments);
|
|
@@ -736,6 +849,11 @@ const wiringViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
736
849
|
})) : []
|
|
737
850
|
];
|
|
738
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);
|
|
739
857
|
for (const { name, modules } of owners){
|
|
740
858
|
const visible = new Map([
|
|
741
859
|
...sharedModules,
|
|
@@ -746,6 +864,7 @@ const wiringViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
746
864
|
]));
|
|
747
865
|
for (const consumer of modules){
|
|
748
866
|
const source = external_node_fs_default().readFileSync(consumer.wireFile, 'utf8');
|
|
867
|
+
const imported = namedImportFiles(source, consumer.wireFile, (specifier, file)=>resolveSpecifier(specifier, file, aliases));
|
|
749
868
|
for (const implementation of consumer.implementations){
|
|
750
869
|
let dependencies;
|
|
751
870
|
try {
|
|
@@ -755,8 +874,9 @@ const wiringViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
755
874
|
}
|
|
756
875
|
const listStart = source.search(new RegExp(`wireClass\\(\\s*${implementation.className}\\b`));
|
|
757
876
|
for (const dependency of dependencies){
|
|
758
|
-
const
|
|
759
|
-
|
|
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;
|
|
760
880
|
const index = source.indexOf(dependency, listStart);
|
|
761
881
|
violations.push({
|
|
762
882
|
check: 'dependencies',
|
|
@@ -817,7 +937,7 @@ Reports what breaks the Domain-First rules in the project:
|
|
|
817
937
|
bounded context isolation, layers, dependency rules (imports and wiring),
|
|
818
938
|
React modules, and reading the time without the clock port.
|
|
819
939
|
rootFolder defaults to the one in domain-first.project-structure.config.json,
|
|
820
|
-
whose optional \`rules\` change the dependency rules and turn checks off.
|
|
940
|
+
whose optional \`backend.rules\` change the dependency rules and turn checks off.
|
|
821
941
|
Exits with 1 when something is found.
|
|
822
942
|
|
|
823
943
|
Options:
|
|
@@ -837,11 +957,15 @@ if (values.help) {
|
|
|
837
957
|
process.exit(0);
|
|
838
958
|
}
|
|
839
959
|
const lint_projectRoot = new ProjectRoot().path;
|
|
960
|
+
if (ConfigFile.outdated) {
|
|
961
|
+
console.log(outdatedConfigMessage);
|
|
962
|
+
process.exit(1);
|
|
963
|
+
}
|
|
840
964
|
const lint_config = ConfigFile.exists ? ConfigFile.Instance.data : void 0;
|
|
841
|
-
const lint_rootFolder = positionals[0] ?? lint_config?.rootFolder ?? 'src';
|
|
965
|
+
const lint_rootFolder = positionals[0] ?? lint_config?.project.rootFolder ?? 'src';
|
|
842
966
|
const lint_violations = lintProject(lint_projectRoot, lint_rootFolder, {
|
|
843
967
|
rules: config_file_configuredDependencyRules(),
|
|
844
|
-
checks: lint_config?.rules?.lint
|
|
968
|
+
checks: lint_config?.backend?.rules?.lint
|
|
845
969
|
});
|
|
846
970
|
if (lint_violations.length) {
|
|
847
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));
|
package/dist/module-move.d.ts
CHANGED
|
@@ -31,8 +31,12 @@ export type MovePlan = {
|
|
|
31
31
|
};
|
|
32
32
|
export type ModuleMove = {
|
|
33
33
|
projectRoot: string;
|
|
34
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Folders emptied by the move are removed up to this one (exclusive),
|
|
36
|
+
* or up to the folder `stopAtFor` gives for a file outside it.
|
|
37
|
+
*/
|
|
35
38
|
stopAt: string;
|
|
39
|
+
stopAtFor?: (file: string) => string | undefined;
|
|
36
40
|
/** Old path → new path of every file of the module. */
|
|
37
41
|
moves: Map<string, string>;
|
|
38
42
|
/**
|
|
@@ -54,5 +58,5 @@ export type ModuleMove = {
|
|
|
54
58
|
* Stages the move with pending changes: files of the module, its imports
|
|
55
59
|
* of other files, and every import of it in the project.
|
|
56
60
|
*/
|
|
57
|
-
export declare const stageModuleMove: ({ projectRoot, stopAt, moves, movedPath, rename, everyFile }: ModuleMove) => MovePlan;
|
|
61
|
+
export declare const stageModuleMove: ({ projectRoot, stopAt, moves, movedPath, rename, everyFile, stopAtFor }: ModuleMove) => MovePlan;
|
|
58
62
|
export {};
|
|
@@ -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;
|
|
@@ -13,8 +13,23 @@ export type ReactModule = {
|
|
|
13
13
|
};
|
|
14
14
|
export declare const findReactModules: (reactFolder: string, kind: ReactModuleKind) => ReactModule[];
|
|
15
15
|
export declare const validateMove: (reactFolder: string, module: ReactModule, rawName: string) => string | true;
|
|
16
|
+
/** A Next.js App Router route folder moved with a page. */
|
|
17
|
+
export type RouteMove = {
|
|
18
|
+
/** The App Router folder, e.g. `<root>/app`. */
|
|
19
|
+
appFolder: string;
|
|
20
|
+
from: string;
|
|
21
|
+
to: string;
|
|
22
|
+
};
|
|
23
|
+
/** The route folder of a nested page name: `admin/users` → `<app>/admin/users`. */
|
|
24
|
+
export declare const routeFolder: (appFolder: string, rawName: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* The files of a route segment itself: `page.tsx`, `layout.tsx` and the
|
|
27
|
+
* like. Subfolders are other routes and stay.
|
|
28
|
+
*/
|
|
29
|
+
export declare const routeFiles: (folder: string) => string[];
|
|
16
30
|
/**
|
|
17
31
|
* Stages the move with pending changes: files of the module, its imports
|
|
18
|
-
* of other files, and every import of it in the project.
|
|
32
|
+
* of other files, and every import of it in the project. With `route`, the
|
|
33
|
+
* files of that Next.js route folder move too.
|
|
19
34
|
*/
|
|
20
|
-
export declare const moveReactModule: (projectRoot: string, reactFolder: string, module: ReactModule, rawName: string) => MovePlan;
|
|
35
|
+
export declare const moveReactModule: (projectRoot: string, reactFolder: string, module: ReactModule, rawName: string, route?: RouteMove) => MovePlan;
|