@domain-first/project-structure 8.10.1 → 8.12.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 +17 -7
- package/dist/287.js +406 -788
- package/dist/364.js +79 -0
- package/dist/38.js +31 -14
- package/dist/561.js +179 -96
- package/dist/783.js +1147 -0
- package/dist/{201.js → 878.js} +465 -2
- package/dist/agent-cli.d.ts +17 -6
- package/dist/agent-requests.d.ts +82 -8
- package/dist/config-file.d.ts +25 -1
- package/dist/frontend-cli.d.ts +3 -0
- package/dist/frontend-modules.d.ts +14 -0
- package/dist/graph.cjs +125 -5
- package/dist/graph.js +1 -1
- package/dist/index.cjs +3545 -2930
- package/dist/index.js +1 -1
- package/dist/init.cjs +368 -83
- package/dist/init.js +1 -1
- package/dist/integration.cjs +3545 -2930
- package/dist/integration.js +1 -1
- package/dist/integrations/openapi.d.ts +19 -2
- package/dist/integrations/orval.d.ts +31 -4
- package/dist/integrations/rest-endpoint-generator.d.ts +11 -7
- package/dist/integrations/storybook.d.ts +19 -1
- package/dist/lint.cjs +159 -22
- package/dist/lint.js +2 -2
- package/dist/page-router.d.ts +18 -0
- package/dist/react-module-move.d.ts +47 -14
- package/dist/react.cjs +1645 -999
- package/dist/react.js +2 -102
- package/dist/rest-adapters.d.ts +13 -0
- package/dist/svelte-agent-cli.spec.d.ts +1 -0
- package/dist/svelte.cjs +7373 -0
- package/dist/svelte.d.ts +2 -0
- package/dist/svelte.js +3 -0
- package/dist/sveltekit-app.d.ts +7 -0
- package/dist/upgrade-steps.d.ts +6 -1
- package/dist/upgrade-svelte.d.ts +15 -0
- package/dist/upgrade-svelte.spec.d.ts +1 -0
- package/dist/upgrade.cjs +307 -42
- package/dist/upgrade.js +132 -13
- package/dist/use-cases/add-integration.d.ts +1 -1
- package/dist/use-cases/delete-react-module.d.ts +4 -4
- package/dist/use-cases/index.d.ts +1 -0
- package/dist/use-cases/move-react-module.d.ts +2 -2
- package/dist/use-cases/rest-endpoint-generator.d.ts +6 -4
- package/dist/use-cases/scaffold-svelte-modules.d.ts +27 -0
- package/package.json +2 -1
- package/skills/df-ps-implement/SKILL.md +3 -3
- package/skills/df-ps-plan-feature/SKILL.md +1 -1
- package/skills/df-ps-scaffold/SKILL.md +9 -8
- package/skills/df-ps-scaffold/references/agent-mode.md +1 -1
- package/skills/df-ps-scaffold/references/agent-operations.md +8 -4
- package/skills/df-ps-scaffold/references/generators.md +1 -1
- package/skills/df-ps-scaffold/references/work-plan.md +1 -1
- package/skills/df-ps-svelte/SKILL.md +54 -0
- package/skills/df-ps-svelte/references/generators.md +56 -0
- package/dist/115.js +0 -615
package/dist/integration.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
3
|
import { runCLI } from "./561.js";
|
|
4
|
-
import { ConfigFile, outdatedConfigMessage } from "./
|
|
4
|
+
import { ConfigFile, outdatedConfigMessage } from "./878.js";
|
|
5
5
|
import { addIntegration } from "./287.js";
|
|
6
6
|
runCLI('df-integration', async ()=>{
|
|
7
7
|
const help = `Usage: df-integration
|
|
@@ -1,12 +1,29 @@
|
|
|
1
|
+
import type { FrontendFramework } from '../react-module-move';
|
|
1
2
|
export declare const openapiScriptPath = "scripts/generate-openapi.ts";
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
3
|
+
/** The static assets folder of Next.js or SvelteKit, so the app can serve it. */
|
|
4
|
+
export declare const defaultOpenapiPath: () => "public/openapi.json" | "static/openapi.json" | "openapi.json";
|
|
5
|
+
export declare const swaggerPagePath: (rootFolder: string, framework?: FrontendFramework) => string;
|
|
4
6
|
/**
|
|
5
7
|
* A React page rendering the OpenAPI document with Swagger UI. With
|
|
6
8
|
* Next.js it is a client component: Swagger UI keeps state and its App
|
|
7
9
|
* Router route is a server component.
|
|
8
10
|
*/
|
|
9
11
|
export declare const swaggerPage: (rootFolder: string, outputPath: string, withNext?: boolean) => string;
|
|
12
|
+
/**
|
|
13
|
+
* The URL SvelteKit serves the document at, when it is in `static/`:
|
|
14
|
+
* `static/docs/openapi.json` → `/docs/openapi.json`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const svelteKitStaticUrl: (outputPath: string) => string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* A Svelte page rendering the OpenAPI document with Swagger UI. It uses
|
|
19
|
+
* the self-contained bundle of `swagger-ui-dist`, with its own React
|
|
20
|
+
* inside: `swagger-ui` takes React from the project, where Storybook may
|
|
21
|
+
* bring React 19 without the `createRoot` it calls. The bundle needs the
|
|
22
|
+
* browser, so it is loaded on mount and never runs during SSR. A document
|
|
23
|
+
* served from SvelteKit's `static/` is fetched by its `url`, so a
|
|
24
|
+
* regenerated one shows on reload and no JSON import is needed.
|
|
25
|
+
*/
|
|
26
|
+
export declare const svelteSwaggerPage: (rootFolder: string, outputPath: string, url?: string) => string;
|
|
10
27
|
export declare const openapiScripts: {
|
|
11
28
|
openapi: string;
|
|
12
29
|
};
|
|
@@ -1,14 +1,41 @@
|
|
|
1
|
+
import type { FrontendFramework } from '../react-module-move';
|
|
1
2
|
export type OrvalTarget = 'hooks' | 'client';
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Query hooks go to the data layer of the frontend framework (React Query
|
|
5
|
+
* or Svelte Query), the typed client to the shared one.
|
|
6
|
+
*/
|
|
7
|
+
export declare const dataLayerFolder: (rootFolder: string, target: OrvalTarget, framework?: FrontendFramework) => string;
|
|
8
|
+
export declare const orvalScripts: (rootFolder: string, targets: OrvalTarget[], framework?: FrontendFramework) => {
|
|
5
9
|
'client:orval': string;
|
|
6
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* The base URL of requests, read at runtime: `NEXT_PUBLIC_API_BASE_URL`
|
|
13
|
+
* with Next.js, `VITE_API_BASE_URL` with Svelte, both empty by default, so
|
|
14
|
+
* requests go to the app's own origin.
|
|
15
|
+
*/
|
|
16
|
+
export declare const orvalBaseUrls: {
|
|
17
|
+
readonly next: "process.env.NEXT_PUBLIC_API_BASE_URL ?? \"\"";
|
|
18
|
+
readonly svelte: "import.meta.env.VITE_API_BASE_URL ?? \"\"";
|
|
19
|
+
};
|
|
20
|
+
export type OrvalBaseUrl = keyof typeof orvalBaseUrls;
|
|
7
21
|
/**
|
|
8
22
|
* Orval resolves paths relative to the config, which lives in the data layer
|
|
9
23
|
* folder next to the generated code. `mutatorPath` is relative to the config.
|
|
10
24
|
*/
|
|
11
|
-
export declare const orvalConfig: (rootFolder: string, openapiPath: string,
|
|
25
|
+
export declare const orvalConfig: (rootFolder: string, openapiPath: string, baseUrlSource: OrvalBaseUrl | undefined, target?: OrvalTarget, mutatorPath?: string, framework?: FrontendFramework) => string;
|
|
26
|
+
/**
|
|
27
|
+
* Orval picks the Svelte Query API by the version it finds in a
|
|
28
|
+
* package.json: this one declares version 6, so the hooks use runes.
|
|
29
|
+
*/
|
|
30
|
+
export declare const svelteQueryPackageJsonFile = "orval.package.json";
|
|
31
|
+
export declare const svelteQueryPackageJson: string;
|
|
12
32
|
export declare const orvalMutator = "/** Error of the generated requests, with the parsed response body. */\nexport class ApiError<Body = unknown> extends Error {\n constructor(\n public readonly status: number,\n public readonly body: Body\n ) {\n super(`API error ${status}`);\n this.name = 'ApiError';\n }\n}\n\n/** Error type of the generated requests, typed per endpoint by Orval. */\nexport type ErrorType<Body> = ApiError<Body>;\n\n/** Every generated request goes through here: add auth headers, token refresh, logging. */\nexport const customInstance = async <T>(\n url: string,\n init?: RequestInit\n): Promise<T> => {\n const response = await fetch(url, init);\n const text = await response.text();\n const body = text ? JSON.parse(text) : undefined;\n\n if (!response.ok) {\n throw new ApiError(response.status, body);\n }\n\n return body as T;\n};\n";
|
|
13
33
|
export declare const queryProvider = "'use client';\n\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { type FC, type ReactNode, useState } from 'react';\n\nexport const QueryProvider: FC<{ children: ReactNode }> = ({ children }) => {\n // One client per browser session; a module-level client would be shared between requests on the server\n const [queryClient] = useState(() => new QueryClient());\n\n return (\n <QueryClientProvider client={queryClient}>\n {children}\n </QueryClientProvider>\n );\n};\n";
|
|
34
|
+
/**
|
|
35
|
+
* The Svelte Query provider. With SvelteKit, queries run only in the
|
|
36
|
+
* browser: a page rendered on the server has no client of its own yet.
|
|
37
|
+
*/
|
|
38
|
+
export declare const svelteQueryProvider: (withSvelteKit: boolean) => string;
|
|
39
|
+
/** The root SvelteKit layout wrapping every page in the query provider. */
|
|
40
|
+
export declare const svelteKitQueryLayout: (providerImport: string) => string;
|
|
14
41
|
export declare const addOrval: () => Promise<string[]>;
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
+
import { type RestAdapter } from '../rest-adapters';
|
|
1
2
|
/**
|
|
2
3
|
* The catch-all route serving every endpoint, relative to the project root.
|
|
3
4
|
*/
|
|
4
5
|
export declare const nextRoutePath: (root: string) => string;
|
|
6
|
+
/** The adapter of the configured framework: Next.js or SvelteKit. */
|
|
7
|
+
export declare const frameworkRestAdapter: () => RestAdapter | undefined;
|
|
5
8
|
/**
|
|
6
|
-
* Offered only when the config selects Next.js (or the caller
|
|
9
|
+
* Offered only when the config selects Next.js or SvelteKit (or the caller
|
|
10
|
+
* names the framework's adapter).
|
|
7
11
|
*/
|
|
8
|
-
export declare const
|
|
9
|
-
|
|
10
|
-
}) => Promise<
|
|
12
|
+
export declare const askRestAdapter: ({ adapter }?: {
|
|
13
|
+
adapter?: RestAdapter;
|
|
14
|
+
}) => Promise<RestAdapter | undefined>;
|
|
11
15
|
/**
|
|
12
|
-
* The Shared Kernel endpoint generator and, with
|
|
16
|
+
* The Shared Kernel endpoint generator and, with a framework adapter, the
|
|
13
17
|
* catch-all route. Existing files are kept: the generator is edited by
|
|
14
18
|
* hand.
|
|
15
19
|
*/
|
|
16
|
-
export declare const scaffoldRestEndpointGeneratorFiles: ({
|
|
17
|
-
|
|
20
|
+
export declare const scaffoldRestEndpointGeneratorFiles: ({ adapter }: {
|
|
21
|
+
adapter?: RestAdapter;
|
|
18
22
|
}) => string[];
|
|
19
23
|
export declare const addRestEndpointGenerator: () => Promise<string[]>;
|
|
20
24
|
export declare const restEndpointGeneratorApplied: () => boolean;
|
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
export declare const storybookFrameworkPackage = "@storybook/react-vite";
|
|
2
|
+
export declare const svelteStorybookPackages: {
|
|
3
|
+
readonly svelte: "@storybook/svelte-vite";
|
|
4
|
+
readonly sveltekit: "@storybook/sveltekit";
|
|
5
|
+
};
|
|
6
|
+
/** The Storybook framework of a frontend choice; Next.js uses React + Vite. */
|
|
7
|
+
export declare const storybookPackageFor: (framework: "react" | "next" | "svelte" | "sveltekit") => "@storybook/react-vite" | "@storybook/svelte-vite" | "@storybook/sveltekit";
|
|
8
|
+
/** How the Storybook integration is named in menus. */
|
|
9
|
+
export declare const storybookTitle: () => "Storybook (SvelteKit)" | "Storybook (Svelte + Vite)" | "Storybook (React + Vite)";
|
|
10
|
+
/** The Storybook config folder relative to the root folder. */
|
|
11
|
+
export declare const storybookFolder: () => string;
|
|
12
|
+
/**
|
|
13
|
+
* Svelte + Vite needs the Svelte plugin unless the project's Vite config
|
|
14
|
+
* has it; SvelteKit's framework reads the project's Vite config.
|
|
15
|
+
*/
|
|
16
|
+
export declare const svelteStorybookFiles: (relativeProjectRoot: string, frameworkPackage: (typeof svelteStorybookPackages)[keyof typeof svelteStorybookPackages]) => {
|
|
17
|
+
'main.ts': string;
|
|
18
|
+
'preview.ts': string;
|
|
19
|
+
};
|
|
2
20
|
export declare const storybookFiles: (relativeProjectRoot: string) => {
|
|
3
21
|
'main.ts': string;
|
|
4
22
|
'preview.ts': string;
|
|
5
23
|
};
|
|
6
|
-
export declare const storybookScripts: (rootFolder: string) => {
|
|
24
|
+
export declare const storybookScripts: (rootFolder: string, family?: "react" | "svelte") => {
|
|
7
25
|
storybook: string;
|
|
8
26
|
'build-storybook': string;
|
|
9
27
|
};
|
package/dist/lint.cjs
CHANGED
|
@@ -246,6 +246,7 @@ const lintChecks = [
|
|
|
246
246
|
'layers',
|
|
247
247
|
'dependencies',
|
|
248
248
|
'react',
|
|
249
|
+
'svelte',
|
|
249
250
|
'clock',
|
|
250
251
|
'config'
|
|
251
252
|
];
|
|
@@ -290,8 +291,16 @@ const reactConfigSchema = external_zod_default().object({
|
|
|
290
291
|
]).optional(),
|
|
291
292
|
storybookFramework: external_zod_default().string().optional()
|
|
292
293
|
}).passthrough();
|
|
294
|
+
const svelteConfigSchema = external_zod_default().object({
|
|
295
|
+
framework: external_zod_default()["enum"]([
|
|
296
|
+
'svelte',
|
|
297
|
+
'sveltekit'
|
|
298
|
+
]).optional(),
|
|
299
|
+
storybookFramework: external_zod_default().string().optional()
|
|
300
|
+
}).passthrough();
|
|
293
301
|
const frontendConfigSchema = external_zod_default().object({
|
|
294
|
-
react: reactConfigSchema.optional()
|
|
302
|
+
react: reactConfigSchema.optional(),
|
|
303
|
+
svelte: svelteConfigSchema.optional()
|
|
295
304
|
}).passthrough();
|
|
296
305
|
const configSchema = external_zod_default().object({
|
|
297
306
|
project: projectConfigSchema,
|
|
@@ -424,7 +433,7 @@ const context_dependencies_crossContextImportAllowed = (from, to)=>{
|
|
|
424
433
|
].includes(targetKind) && (isCrossContextImplementation(from) && 'application' === targetLayer || 'wiring' === layer && 'application-ports' === kind && 'wiring' === targetLayer);
|
|
425
434
|
};
|
|
426
435
|
const external_node_module_namespaceObject = require("node:module");
|
|
427
|
-
const
|
|
436
|
+
const tsconfig_stripJsonComments = (source)=>source.replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (_, text)=>text ? text : '').replace(/,(\s*[}\]])/g, '$1');
|
|
428
437
|
const resolveExtends = (fromFile, target)=>{
|
|
429
438
|
if (target.startsWith('.') || external_node_path_default().isAbsolute(target)) {
|
|
430
439
|
const resolved = external_node_path_default().resolve(external_node_path_default().dirname(fromFile), target);
|
|
@@ -443,7 +452,7 @@ const compilerOption = (configFile, name, seen = new Set())=>{
|
|
|
443
452
|
seen.add(configFile);
|
|
444
453
|
let config;
|
|
445
454
|
try {
|
|
446
|
-
config = JSON.parse(
|
|
455
|
+
config = JSON.parse(tsconfig_stripJsonComments(external_node_fs_default().readFileSync(configFile, 'utf8')));
|
|
447
456
|
} catch {
|
|
448
457
|
return null;
|
|
449
458
|
}
|
|
@@ -457,6 +466,117 @@ const compilerOption = (configFile, name, seen = new Set())=>{
|
|
|
457
466
|
if (void 0 !== value) return value;
|
|
458
467
|
}
|
|
459
468
|
};
|
|
469
|
+
new Set([
|
|
470
|
+
'node_modules',
|
|
471
|
+
'.git',
|
|
472
|
+
'.next',
|
|
473
|
+
'.svelte-kit',
|
|
474
|
+
'dist',
|
|
475
|
+
'build',
|
|
476
|
+
'out',
|
|
477
|
+
'coverage',
|
|
478
|
+
'storybook-static'
|
|
479
|
+
]);
|
|
480
|
+
const module_move_escapeRegExp = (value)=>value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
481
|
+
const frontendExtensions = {
|
|
482
|
+
react: {
|
|
483
|
+
component: '.tsx',
|
|
484
|
+
hook: '.ts'
|
|
485
|
+
},
|
|
486
|
+
svelte: {
|
|
487
|
+
component: '.svelte',
|
|
488
|
+
hook: '.svelte.ts'
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
const frontendLogicNaming = {
|
|
492
|
+
react: {
|
|
493
|
+
prefix: 'use',
|
|
494
|
+
shared: [
|
|
495
|
+
'hooks'
|
|
496
|
+
],
|
|
497
|
+
widgetModel: 'hooks'
|
|
498
|
+
},
|
|
499
|
+
svelte: {
|
|
500
|
+
prefix: 'create',
|
|
501
|
+
shared: [
|
|
502
|
+
'shared',
|
|
503
|
+
'model'
|
|
504
|
+
],
|
|
505
|
+
widgetModel: 'model'
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
const kindLayouts = (framework)=>{
|
|
509
|
+
const { component, hook } = frontendExtensions[framework];
|
|
510
|
+
const { prefix, shared } = frontendLogicNaming[framework];
|
|
511
|
+
return {
|
|
512
|
+
page: {
|
|
513
|
+
folder: 'pages',
|
|
514
|
+
nested: true,
|
|
515
|
+
inFolder: false,
|
|
516
|
+
ownFile: (fileBase)=>new RegExp(`^${module_move_escapeRegExp(fileBase)}-page(?:\\.|$)`),
|
|
517
|
+
target: (reactFolder, { folders, fileName })=>external_node_path_default().join(reactFolder, 'pages', ...folders, `${fileName}-page${component}`),
|
|
518
|
+
classPrefix: `(${prefix})?`,
|
|
519
|
+
classSuffix: 'Page'
|
|
520
|
+
},
|
|
521
|
+
widget: {
|
|
522
|
+
folder: 'widgets',
|
|
523
|
+
nested: true,
|
|
524
|
+
inFolder: true,
|
|
525
|
+
target: (reactFolder, { folders, folderName })=>external_node_path_default().join(reactFolder, 'widgets', ...folders, folderName),
|
|
526
|
+
classPrefix: `(${prefix})?`,
|
|
527
|
+
classSuffix: 'Widget|UIModel',
|
|
528
|
+
storyTitle: (segments)=>[
|
|
529
|
+
'Widgets',
|
|
530
|
+
...segments
|
|
531
|
+
].join('/')
|
|
532
|
+
},
|
|
533
|
+
'ui-kit': {
|
|
534
|
+
folder: 'ui-kit',
|
|
535
|
+
nested: false,
|
|
536
|
+
inFolder: true,
|
|
537
|
+
target: (reactFolder, { fileName })=>external_node_path_default().join(reactFolder, 'ui-kit', fileName),
|
|
538
|
+
classPrefix: '()',
|
|
539
|
+
classSuffix: 'Props(?![\\w$])|(?![\\w$])',
|
|
540
|
+
storyTitle: (segments)=>`UI-kit/${segments.join('')}`
|
|
541
|
+
},
|
|
542
|
+
hook: {
|
|
543
|
+
folder: shared.join('/'),
|
|
544
|
+
nested: false,
|
|
545
|
+
inFolder: false,
|
|
546
|
+
ownFile: (fileBase)=>new RegExp(`^${prefix}-${module_move_escapeRegExp(fileBase)}(?:\\.|$)`),
|
|
547
|
+
target: (reactFolder, { fileName })=>external_node_path_default().join(reactFolder, ...shared, `${prefix}-${fileName}${hook}`),
|
|
548
|
+
classPrefix: `(${prefix})`,
|
|
549
|
+
classSuffix: '(?![\\w$])'
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
};
|
|
553
|
+
kindLayouts('react');
|
|
554
|
+
kindLayouts('svelte');
|
|
555
|
+
const reactKindTitles = {
|
|
556
|
+
page: [
|
|
557
|
+
'Page',
|
|
558
|
+
'pages'
|
|
559
|
+
],
|
|
560
|
+
widget: [
|
|
561
|
+
'Widget',
|
|
562
|
+
'widgets'
|
|
563
|
+
],
|
|
564
|
+
'ui-kit': [
|
|
565
|
+
'UI-kit component',
|
|
566
|
+
'UI-kit components'
|
|
567
|
+
],
|
|
568
|
+
hook: [
|
|
569
|
+
'Shared hook',
|
|
570
|
+
'shared hooks'
|
|
571
|
+
]
|
|
572
|
+
};
|
|
573
|
+
({
|
|
574
|
+
...reactKindTitles,
|
|
575
|
+
hook: [
|
|
576
|
+
'Shared model',
|
|
577
|
+
'shared models'
|
|
578
|
+
]
|
|
579
|
+
});
|
|
460
580
|
class UnknownFormatNaming {
|
|
461
581
|
rawSource;
|
|
462
582
|
camelCase;
|
|
@@ -729,7 +849,7 @@ const wiredDependencyNames = (source, className)=>{
|
|
|
729
849
|
const { openIndex, closeIndex } = wireListRange(source, className);
|
|
730
850
|
return splitTopLevel(source.slice(openIndex + 1, closeIndex));
|
|
731
851
|
};
|
|
732
|
-
const
|
|
852
|
+
const project_lint_readAliases = (projectRoot)=>{
|
|
733
853
|
const tsconfig = external_node_path_default().join(projectRoot, 'tsconfig.json');
|
|
734
854
|
const paths = compilerOption(tsconfig, 'paths');
|
|
735
855
|
if (!paths || 'object' != typeof paths) return [];
|
|
@@ -759,14 +879,14 @@ const sourceFiles = (folder)=>{
|
|
|
759
879
|
}).flatMap((entry)=>{
|
|
760
880
|
const entryPath = external_node_path_default().join(folder, entry.name);
|
|
761
881
|
if (entry.isDirectory()) return 'node_modules' === entry.name ? [] : sourceFiles(entryPath);
|
|
762
|
-
return /\.(c|m)?tsx
|
|
882
|
+
return /\.((c|m)?tsx?|svelte)$/.test(entry.name) && !entry.name.endsWith('.d.ts') ? [
|
|
763
883
|
entryPath
|
|
764
884
|
] : [];
|
|
765
885
|
});
|
|
766
886
|
};
|
|
767
887
|
const importPattern = /\b(?:(import|export)\s+(type\s+)?(?:(?!\b(?:import|export)\b)[\w*{}\s,$])*?\s*from\s*|import\s*\(\s*|require\s*\(\s*|import\s*)(['"])([^'"\n]+)\3/g;
|
|
768
888
|
const lineAt = (source, index)=>source.slice(0, index).split('\n').length;
|
|
769
|
-
const
|
|
889
|
+
const project_lint_importsOf = (source, file, aliases)=>[
|
|
770
890
|
...source.matchAll(importPattern)
|
|
771
891
|
].map((match)=>({
|
|
772
892
|
typeOnly: 'import' === match[1] && Boolean(match[2]),
|
|
@@ -825,12 +945,25 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
825
945
|
const root = external_node_path_default().resolve(projectRoot, rootFolder);
|
|
826
946
|
const contextsFolder = external_node_path_default().join(root, 'bounded-contexts');
|
|
827
947
|
const sharedFolder = external_node_path_default().join(root, 'shared-kernel');
|
|
828
|
-
const
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
948
|
+
const frontends = [
|
|
949
|
+
'react',
|
|
950
|
+
'svelte'
|
|
951
|
+
].map((framework)=>{
|
|
952
|
+
const folder = external_node_path_default().join(root, 'presentation', framework);
|
|
953
|
+
return {
|
|
954
|
+
check: framework,
|
|
955
|
+
label: `presentation/${framework}`,
|
|
956
|
+
folder,
|
|
957
|
+
uiKit: external_node_path_default().join(folder, 'ui-kit'),
|
|
958
|
+
widgets: external_node_path_default().join(folder, 'widgets'),
|
|
959
|
+
hooks: external_node_path_default().join(folder, ...frontendLogicNaming[framework].shared),
|
|
960
|
+
hooksLabel: 'svelte' === framework ? "[presentation/svelte/shared/model] a shared model imports a bounded context, UI-kit, widget or page:" : "[presentation/react/hooks] a shared hook imports a bounded context, UI-kit, widget or page:",
|
|
961
|
+
widgetFile: 'svelte' === framework ? '-widget.svelte' : '-widget.tsx'
|
|
962
|
+
};
|
|
963
|
+
});
|
|
964
|
+
const frontendOf = (file)=>frontends.find((frontend)=>inside(frontend.folder, file));
|
|
832
965
|
const inMemoryDbFile = external_node_path_default().join(sharedFolder, 'infrastructure', 'services', 'in-memory-db-infrastructure-service.ts');
|
|
833
|
-
const aliases =
|
|
966
|
+
const aliases = project_lint_readAliases(projectRoot);
|
|
834
967
|
const violations = [];
|
|
835
968
|
const contextOf = (file)=>{
|
|
836
969
|
const segments = inside(contextsFolder, file);
|
|
@@ -858,16 +991,18 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
858
991
|
].includes(part) && !/-repository(\.tsx?)?$/.test(external_node_path_default().basename(target));
|
|
859
992
|
const widgetFolders = new Map();
|
|
860
993
|
const isWidgetFolder = (folder)=>{
|
|
861
|
-
if (!widgetFolders.has(folder)) widgetFolders.set(folder, external_node_fs_default().existsSync(folder) && external_node_fs_default().statSync(folder).isDirectory() && external_node_fs_default().readdirSync(folder).some((name)=>name.endsWith(
|
|
994
|
+
if (!widgetFolders.has(folder)) widgetFolders.set(folder, external_node_fs_default().existsSync(folder) && external_node_fs_default().statSync(folder).isDirectory() && external_node_fs_default().readdirSync(folder).some((name)=>frontends.some(({ widgetFile })=>name.endsWith(widgetFile))));
|
|
862
995
|
return widgetFolders.get(folder);
|
|
863
996
|
};
|
|
864
997
|
const widgetOf = (file)=>{
|
|
998
|
+
const widgetsFolder = frontendOf(file)?.widgets;
|
|
999
|
+
if (!widgetsFolder) return;
|
|
865
1000
|
for(let folder = file; inside(widgetsFolder, folder); folder = external_node_path_default().dirname(folder))if (isWidgetFolder(folder)) return folder;
|
|
866
1001
|
};
|
|
867
1002
|
const files = [
|
|
868
1003
|
contextsFolder,
|
|
869
1004
|
sharedFolder,
|
|
870
|
-
|
|
1005
|
+
...frontends.map(({ folder })=>folder)
|
|
871
1006
|
].flatMap(sourceFiles);
|
|
872
1007
|
for (const file of files){
|
|
873
1008
|
const source = external_node_fs_default().readFileSync(file, 'utf8');
|
|
@@ -881,6 +1016,7 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
881
1016
|
text: external_node_path_default().basename(file)
|
|
882
1017
|
});
|
|
883
1018
|
const ownContext = contextOf(file);
|
|
1019
|
+
const frontend = frontendOf(file);
|
|
884
1020
|
const directWiring = ownContext && from?.segments[0] === 'wiring' && readWiredModule(file, boundedContextPath(contextsFolder, ownContext))?.implementations.some((implementation)=>isCrossContextImplementation(implementation.file));
|
|
885
1021
|
const report = (check, rule, imported)=>violations.push({
|
|
886
1022
|
check,
|
|
@@ -889,7 +1025,7 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
889
1025
|
line: imported.line,
|
|
890
1026
|
text: imported.statement
|
|
891
1027
|
});
|
|
892
|
-
for (const imported of
|
|
1028
|
+
for (const imported of project_lint_importsOf(source, file, aliases)){
|
|
893
1029
|
const target = imported.target;
|
|
894
1030
|
if (!target) continue;
|
|
895
1031
|
const to = locate(target);
|
|
@@ -900,9 +1036,10 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
900
1036
|
} else if (inside(sharedFolder, file)) {
|
|
901
1037
|
const allowed = !to || 'shared-kernel' === to.owner || 'domain' === to.segments[0] && 'errors' === to.segments[1] || file === inMemoryDbFile && isDomainModel(to.segments, target);
|
|
902
1038
|
if (!allowed) report('shared-kernel', '[shared-kernel] imports a bounded context outside its domain/errors (and domain models for the in-memory DB):', imported);
|
|
903
|
-
} else if (inside(
|
|
904
|
-
const [area] = inside(
|
|
905
|
-
const
|
|
1039
|
+
} else if (frontend && (inside(frontend.uiKit, file) || inside(frontend.hooks, file))) {
|
|
1040
|
+
const [area] = inside(frontend.folder, target) ?? [];
|
|
1041
|
+
const inUiKit = inside(frontend.uiKit, file);
|
|
1042
|
+
const forbidden = inUiKit ? [
|
|
906
1043
|
'widgets',
|
|
907
1044
|
'pages'
|
|
908
1045
|
] : [
|
|
@@ -910,11 +1047,11 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
910
1047
|
'widgets',
|
|
911
1048
|
'pages'
|
|
912
1049
|
];
|
|
913
|
-
if (targetContext || forbidden.includes(area)) report(
|
|
914
|
-
} else if (targetContext && !(imported.typeOnly && to?.segments[0] === 'presentation' && 'rest' === to.segments[1])) report(
|
|
1050
|
+
if (targetContext || forbidden.includes(area)) report(frontend.check, inUiKit ? `[${frontend.label}/ui-kit] imports a bounded context, widget or page:` : frontend.hooksLabel, imported);
|
|
1051
|
+
} else if (frontend && targetContext && !(imported.typeOnly && to?.segments[0] === 'presentation' && 'rest' === to.segments[1])) report(frontend.check, `[${frontend.label}] imports a context other than \`import type\` from presentation/rest:`, imported);
|
|
915
1052
|
const ownWidget = widgetOf(file);
|
|
916
1053
|
const targetWidget = widgetOf(target);
|
|
917
|
-
if (ownWidget && targetWidget && targetWidget !== ownWidget) report(
|
|
1054
|
+
if (frontend && ownWidget && targetWidget && targetWidget !== ownWidget) report(frontend.check, `[${frontend.label}/widgets] a widget imports another widget:`, imported);
|
|
918
1055
|
if (!from || !to) continue;
|
|
919
1056
|
if (crossContextAllowed) continue;
|
|
920
1057
|
if (isSpec(file)) continue;
|
|
@@ -952,7 +1089,7 @@ const wiringViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
952
1089
|
module.wireFile,
|
|
953
1090
|
module
|
|
954
1091
|
]));
|
|
955
|
-
const aliases =
|
|
1092
|
+
const aliases = project_lint_readAliases(projectRoot);
|
|
956
1093
|
for (const { name, modules } of owners){
|
|
957
1094
|
const visible = new Map([
|
|
958
1095
|
...sharedModules,
|
|
@@ -1046,7 +1183,7 @@ const help = `Usage: df-lint [rootFolder]
|
|
|
1046
1183
|
|
|
1047
1184
|
Reports what breaks the Domain-First rules in the project:
|
|
1048
1185
|
bounded context isolation, layers, dependency rules (imports and wiring),
|
|
1049
|
-
React modules, and reading the time or environment variables without
|
|
1186
|
+
React and Svelte modules, and reading the time or environment variables without
|
|
1050
1187
|
the clock and config ports.
|
|
1051
1188
|
rootFolder defaults to the one in domain-first.project-structure.config.json,
|
|
1052
1189
|
whose optional \`backend.rules\` change the dependency rules and turn checks off.
|
package/dist/lint.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
|
-
import { configuredDependencyRules, ProjectRoot, outdatedConfigMessage, ConfigFile } from "./
|
|
3
|
+
import { configuredDependencyRules, ProjectRoot, outdatedConfigMessage, ConfigFile } from "./878.js";
|
|
4
4
|
import { lintProject, formatViolations } from "./38.js";
|
|
5
5
|
const help = `Usage: df-lint [rootFolder]
|
|
6
6
|
|
|
7
7
|
Reports what breaks the Domain-First rules in the project:
|
|
8
8
|
bounded context isolation, layers, dependency rules (imports and wiring),
|
|
9
|
-
React modules, and reading the time or environment variables without
|
|
9
|
+
React and Svelte modules, and reading the time or environment variables without
|
|
10
10
|
the clock and config ports.
|
|
11
11
|
rootFolder defaults to the one in domain-first.project-structure.config.json,
|
|
12
12
|
whose optional \`backend.rules\` change the dependency rules and turn checks off.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FrontendFramework } from './react-module-move';
|
|
2
|
+
/**
|
|
3
|
+
* The file-based router pages get routes in: the Next.js App Router for
|
|
4
|
+
* React, SvelteKit for Svelte. Undefined without one.
|
|
5
|
+
*/
|
|
6
|
+
export type PageRouter = {
|
|
7
|
+
title: 'Next.js' | 'SvelteKit';
|
|
8
|
+
/** The routes folder relative to the project root. */
|
|
9
|
+
folder: (root: string) => string;
|
|
10
|
+
/** The file of a route that renders the page. */
|
|
11
|
+
pageFile: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const pageRouter: (framework: FrontendFramework) => PageRouter | undefined;
|
|
14
|
+
/** How messages name modules of each framework. */
|
|
15
|
+
export declare const frameworkTitles: Record<FrontendFramework, {
|
|
16
|
+
title: string;
|
|
17
|
+
cli: string;
|
|
18
|
+
}>;
|
|
@@ -2,6 +2,29 @@ import { type MovePlan } from './module-move';
|
|
|
2
2
|
import { NestedName } from './nested-name';
|
|
3
3
|
export type { MovePlan } from './module-move';
|
|
4
4
|
export type ReactModuleKind = 'page' | 'widget' | 'ui-kit' | 'hook';
|
|
5
|
+
/**
|
|
6
|
+
* Frontend modules of `presentation/react` and `presentation/svelte` share
|
|
7
|
+
* kinds and layouts; only file extensions and routes differ.
|
|
8
|
+
*/
|
|
9
|
+
export type FrontendFramework = 'react' | 'svelte';
|
|
10
|
+
/** Extensions of components (pages, widgets, UI-kit) and shared hooks. */
|
|
11
|
+
export declare const frontendExtensions: Record<FrontendFramework, {
|
|
12
|
+
component: string;
|
|
13
|
+
hook: string;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Naming of reusable logic: React hooks (`hooks/use-n.ts`, `useN`) and
|
|
17
|
+
* Svelte 5 models (`shared/model/create-n.svelte.ts`, `createN`). In
|
|
18
|
+
* SvelteKit "hooks" are `hooks.server.ts`, so Svelte has no hooks.
|
|
19
|
+
*/
|
|
20
|
+
export declare const frontendLogicNaming: Record<FrontendFramework, {
|
|
21
|
+
/** Function name prefix: `useN`, `createN`. */
|
|
22
|
+
prefix: 'use' | 'create';
|
|
23
|
+
/** Folder of shared hooks (models), under `presentation/<framework>`. */
|
|
24
|
+
shared: string[];
|
|
25
|
+
/** Folder of a widget's UI model, inside the widget. */
|
|
26
|
+
widgetModel: string;
|
|
27
|
+
}>;
|
|
5
28
|
export type ReactModule = {
|
|
6
29
|
kind: ReactModuleKind;
|
|
7
30
|
/** Name, nested for pages and widgets, e.g. `admin/users`. */
|
|
@@ -30,15 +53,22 @@ type ReactKindLayout = {
|
|
|
30
53
|
storyTitle?: (segments: string[]) => string;
|
|
31
54
|
};
|
|
32
55
|
export declare const reactKindLayouts: Record<ReactModuleKind, ReactKindLayout>;
|
|
56
|
+
/** Svelte: shared models in `shared/model/create-n.svelte.ts`. */
|
|
57
|
+
export declare const svelteKindLayouts: Record<ReactModuleKind, ReactKindLayout>;
|
|
58
|
+
export declare const frontendKindLayouts: (framework: FrontendFramework) => Record<ReactModuleKind, ReactKindLayout>;
|
|
33
59
|
/** How menus name each kind, singular and plural. */
|
|
34
60
|
export declare const reactKindTitles: Record<ReactModuleKind, [string, string]>;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
61
|
+
export declare const frontendKindTitles: (framework: FrontendFramework) => Record<ReactModuleKind, [string, string]>;
|
|
62
|
+
/**
|
|
63
|
+
* A shared hook's (model's) name is entered without `use-` (`create-`), as
|
|
64
|
+
* its generator takes it.
|
|
65
|
+
*/
|
|
66
|
+
export declare const reactModuleName: (kind: ReactModuleKind, rawName: string, framework?: FrontendFramework) => string;
|
|
67
|
+
export declare const findReactModules: (reactFolder: string, kind: ReactModuleKind, framework?: FrontendFramework) => ReactModule[];
|
|
68
|
+
export declare const validateMove: (reactFolder: string, module: ReactModule, rawName: string, framework?: FrontendFramework) => string | true;
|
|
69
|
+
/** A Next.js App Router or SvelteKit route folder moved with a page. */
|
|
40
70
|
export type RouteMove = {
|
|
41
|
-
/** The
|
|
71
|
+
/** The routes folder, e.g. `<root>/app` or `<root>/src/routes`. */
|
|
42
72
|
appFolder: string;
|
|
43
73
|
from: string;
|
|
44
74
|
to: string;
|
|
@@ -53,14 +83,17 @@ export declare const routeFiles: (folder: string) => string[];
|
|
|
53
83
|
/**
|
|
54
84
|
* Stages the move with pending changes: files of the module, its imports
|
|
55
85
|
* of other files, and every import of it in the project. With `route`, the
|
|
56
|
-
* files of that
|
|
86
|
+
* files of that route folder move too.
|
|
57
87
|
*/
|
|
58
|
-
export declare const moveReactModule: (projectRoot: string, reactFolder: string, module: ReactModule, rawName: string, route?: RouteMove) => MovePlan;
|
|
88
|
+
export declare const moveReactModule: (projectRoot: string, reactFolder: string, module: ReactModule, rawName: string, route?: RouteMove, framework?: FrontendFramework) => MovePlan;
|
|
89
|
+
/** The file of a route that renders its page, by framework. */
|
|
90
|
+
export declare const routePageFile: Record<FrontendFramework, string>;
|
|
59
91
|
/**
|
|
60
|
-
* The route folder of a page with Next.js: `<
|
|
61
|
-
* `page.tsx` renders the page. Undefined for
|
|
92
|
+
* The route folder of a page with Next.js or SvelteKit: `<routes>/<name>/`
|
|
93
|
+
* when its `page.tsx` (`+page.svelte`) renders the page. Undefined for
|
|
94
|
+
* other routes or none.
|
|
62
95
|
*/
|
|
63
|
-
export declare const pageRouteFolder: (appFolder: string, page: ReactModule) => string | undefined;
|
|
96
|
+
export declare const pageRouteFolder: (appFolder: string, page: ReactModule, framework?: FrontendFramework) => string | undefined;
|
|
64
97
|
export type ReactDeleteResult = {
|
|
65
98
|
/** Files outside the module that still import it: [file, import]. */
|
|
66
99
|
usedBy: [string, string][];
|
|
@@ -70,10 +103,10 @@ export type ReactDeleteResult = {
|
|
|
70
103
|
};
|
|
71
104
|
/**
|
|
72
105
|
* Stages the deletion of a page or widget with its files, and with `route`
|
|
73
|
-
* the files of that
|
|
74
|
-
*
|
|
106
|
+
* the files of that route folder too. Nothing is staged while other files
|
|
107
|
+
* still import the module; those imports are returned instead.
|
|
75
108
|
*/
|
|
76
109
|
export declare const deleteReactModule: (projectRoot: string, reactFolder: string, module: ReactModule, route?: {
|
|
77
110
|
appFolder: string;
|
|
78
111
|
folder: string;
|
|
79
|
-
}) => ReactDeleteResult;
|
|
112
|
+
}, framework?: FrontendFramework) => ReactDeleteResult;
|