@domain-first/project-structure 8.10.1 → 8.11.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/115.js +142 -141
- package/dist/201.js +10 -1
- package/dist/287.js +983 -434
- package/dist/364.js +79 -0
- package/dist/38.js +29 -13
- package/dist/561.js +167 -93
- package/dist/agent-cli.d.ts +13 -2
- package/dist/agent-requests.d.ts +76 -2
- package/dist/config-file.d.ts +25 -1
- package/dist/frontend-cli.d.ts +3 -0
- package/dist/frontend-modules.d.ts +9 -0
- package/dist/graph.cjs +10 -1
- package/dist/index.cjs +3470 -2913
- package/dist/init.cjs +325 -83
- package/dist/integration.cjs +3470 -2913
- package/dist/integrations/openapi.d.ts +9 -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 +40 -15
- package/dist/lint.js +1 -1
- package/dist/page-router.d.ts +18 -0
- package/dist/react-module-move.d.ts +27 -12
- package/dist/react.cjs +1577 -993
- 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 +7311 -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.cjs +12 -2
- 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 +22 -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 +49 -0
- package/skills/df-ps-svelte/references/generators.md +56 -0
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ The full technical specification lives in [API.md](./API.md).
|
|
|
29
29
|
|
|
30
30
|
### Non-interactive mode for agents
|
|
31
31
|
|
|
32
|
-
`df-scaffold`, `df-react` and `df-integration` accept JSON requests. Humans can keep using the interactive menus. Agents can discover schemas and project IDs first:
|
|
32
|
+
`df-scaffold`, `df-react`, `df-svelte` and `df-integration` accept JSON requests. Humans can keep using the interactive menus. Agents can discover schemas and project IDs first:
|
|
33
33
|
|
|
34
34
|
```bash
|
|
35
35
|
npx df-scaffold --describe
|
|
@@ -53,7 +53,7 @@ npx df-init --section backend
|
|
|
53
53
|
npx df-init --section frontend
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
Project asks for the source folder. Backend asks for the `@domain-first` packages, the [`envBranchedWire` branches](#how-to-switch-implementations) with `wire`, shared in-memory DB and testing library, then adds the required Shared Kernel files. With `@domain-first/handlers-rest`, it adds the [endpoint generator](#how-to-add-a-rest-endpoint). Frontend offers **React
|
|
56
|
+
Project asks for the source folder. Backend asks for the `@domain-first` packages, the [`envBranchedWire` branches](#how-to-switch-implementations) with `wire`, shared in-memory DB and testing library, then adds the required Shared Kernel files. With `@domain-first/handlers-rest`, it adds the [endpoint generator](#how-to-add-a-rest-endpoint). Frontend offers **React**, **Next.js**, **Svelte** or **SvelteKit**, then Storybook. Enabling Storybook runs the existing React + Vite integration: it creates `.storybook` configs, package scripts and the build-output `.gitignore` entry. Selecting Next.js with a configured backend asks **Use @domain-first/handlers-next for REST endpoints** once. Yes adds `handlers-rest` to the backend packages if needed, connects `nextAdapter` and creates the catch-all route. SvelteKit asks **Use @domain-first/handlers-svelte for REST endpoints** the same way: `svelteAdapter` and `src/routes/api/[...path]/+server.ts` with `svelteEndpoints`. This works before `next` is installed. With backend deferred, REST setup waits until backend configuration. Missing packages are printed as an install command; nothing is installed automatically.
|
|
57
57
|
|
|
58
58
|
All settings and saved implementation types live in `domain-first.project-structure.config.json`:
|
|
59
59
|
|
|
@@ -99,7 +99,7 @@ All settings and saved implementation types live in `domain-first.project-struct
|
|
|
99
99
|
}
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
Commit the config to share it with your team. Rerunning `df-init` offers **Project**, **Backend**, **Frontend** and **All sections**, using current values as defaults. A single-section update keeps the other sections and saved choices. Backend setup writes all standard dependency lists and enabled lint checks into `backend.rules`, so they can be edited directly. On reconfiguration, only missing rules are filled; existing lists, `add`/`remove` patches and disabled checks are preserved. Backend setup preserves existing support files and restores missing ones. Changing the source folder affects future generation; existing source is not moved. React is enabled by the presence of `frontend.react`; its `framework` is `react` or `next`, so Next.js uses the same React generators. Frontend selection is prefilled from the saved value, falling back to Next.js when `next` is declared in `package.json`. Both choices use `@storybook/react-vite` from the Storybook integration; there is no separate Storybook framework prompt. Framework settings remain grouped under `frontend.<framework>`.
|
|
102
|
+
Commit the config to share it with your team. Rerunning `df-init` offers **Project**, **Backend**, **Frontend** and **All sections**, using current values as defaults. A single-section update keeps the other sections and saved choices. Backend setup writes all standard dependency lists and enabled lint checks into `backend.rules`, so they can be edited directly. On reconfiguration, only missing rules are filled; existing lists, `add`/`remove` patches and disabled checks are preserved. Backend setup preserves existing support files and restores missing ones. Changing the source folder affects future generation; existing source is not moved. React is enabled by the presence of `frontend.react`; its `framework` is `react` or `next`, so Next.js uses the same React generators. Frontend selection is prefilled from the saved value, falling back to Next.js when `next` is declared in `package.json`. Both choices use `@storybook/react-vite` from the Storybook integration; there is no separate Storybook framework prompt. Svelte is enabled by `frontend.svelte` the same way: its `framework` is `svelte` or `sveltekit`, both use `df-svelte`, and stories use `@storybook/svelte-vite` or `@storybook/sveltekit`. A project has one of the two sections; selecting the other framework replaces it. Framework settings remain grouped under `frontend.<framework>`.
|
|
103
103
|
|
|
104
104
|
A config of an earlier major version is not read: commands stop and ask you to run [`df-upgrade`](#how-to-upgrade-to-a-new-major-version). An absent backend or React section produces a message pointing to the corresponding `df-init --section` command. Initialization and configuration are performed by the project owner; agent skills only read these settings and ask the owner to configure missing sections.
|
|
105
105
|
|
|
@@ -274,9 +274,19 @@ With Next.js, a new page also gets its App Router route, `app/admin/panel/users/
|
|
|
274
274
|
|
|
275
275
|
**Move or rename page** and **Move or rename widget** move the files and update every import in the project. **Delete page** and **Delete widget** remove them once nothing imports them, a Next.js page's own route included if you say so. UI-kit components and shared hooks can be moved, renamed and deleted the same way. With Next.js, moving a page also offers to move its route, `app/admin/users/` → `app/backoffice/users/`, since its URL changes with it.
|
|
276
276
|
|
|
277
|
+
### How to scaffold Svelte modules
|
|
278
|
+
|
|
279
|
+
With `frontend.svelte` configured (Svelte or SvelteKit), run `npx df-svelte`: the same pages, widgets, UI-kit components and shared hooks as `df-react`, written as Svelte 5 components with runes into `presentation/svelte`. Shared hooks and widget UI models are `.svelte.ts` modules, components export their props types from `<script lang="ts" module>`, and stories follow `@storybook/svelte-vite` or `@storybook/sveltekit`.
|
|
280
|
+
|
|
281
|
+
```text
|
|
282
|
+
admin/panel/users → pages/admin/panel/admin-panel-users-page.svelte (AdminPanelUsersPage)
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
With SvelteKit, a new page also gets its route, `src/routes/admin/panel/users/+page.svelte`, which renders `AdminPanelUsersPage`. Moving and deleting work as in `df-react`, and a SvelteKit page's route folder can follow the page.
|
|
286
|
+
|
|
277
287
|
### How to add tooling
|
|
278
288
|
|
|
279
|
-
Run `npx df-integration` to configure one or several of the REST endpoint generator, the shared in-memory DB, Storybook, Prisma 8, Drizzle, Vitest, Playwright, integration tests on PostgreSQL in Testcontainers, OpenAPI generation or an Orval API client (typed client and React Query hooks). Integrations add config files, package scripts and `.gitignore` entries, then print one install command to copy. Nothing is installed or run for you.
|
|
289
|
+
Run `npx df-integration` to configure one or several of the REST endpoint generator, the shared in-memory DB, Storybook, Prisma 8, Drizzle, Vitest, Playwright, integration tests on PostgreSQL in Testcontainers, OpenAPI generation or an Orval API client (typed client and React Query or Svelte Query hooks). Integrations add config files, package scripts and `.gitignore` entries, then print one install command to copy. Nothing is installed or run for you.
|
|
280
290
|
|
|
281
291
|
The endpoint generator and the in-memory DB are what `df-init` scaffolds; as integrations they add them later or restore missing files, and never overwrite existing ones.
|
|
282
292
|
|
|
@@ -288,13 +298,13 @@ With Testcontainers, the CLI asks which implementation types get integration tes
|
|
|
288
298
|
npx df-lint
|
|
289
299
|
```
|
|
290
300
|
|
|
291
|
-
It reports what breaks the Domain-First rules: forbidden imports between bounded contexts, imports against the layers, modules using kinds the dependency rules don't allow (in imports and in wiring), React modules importing what they shouldn't, and reading the time or environment variables without the clock and config ports. It exits with 1 when something is found, so you can run it in CI.
|
|
301
|
+
It reports what breaks the Domain-First rules: forbidden imports between bounded contexts, imports against the layers, modules using kinds the dependency rules don't allow (in imports and in wiring), React and Svelte modules importing what they shouldn't, and reading the time or environment variables without the clock and config ports. It exits with 1 when something is found, so you can run it in CI.
|
|
292
302
|
|
|
293
303
|
`df-init` scaffolds all standard rules into `backend.rules` during backend setup. Teams can edit these entries directly: what each kind of module may depend on (`backend.rules.dependencies`) and which checks run (`backend.rules.lint`). `df-scaffold` offers dependencies by the same rules. For older or manually shortened configs without `backend.rules`, the defaults apply and every check runs; kinds and checks you don't mention keep their defaults.
|
|
294
304
|
|
|
295
305
|
- Kinds in `backend.rules.dependencies` (as keys and in lists): `repositories`, `domain-services`, `application-ports`, `application-services`, `use-cases`, `commands`, `queries`, `infrastructure-services`, `presentation-services`.
|
|
296
306
|
- A kind's value: a list that replaces its defaults, or `{ "add": [...], "remove": [...] }`.
|
|
297
|
-
- Checks in `backend.rules.lint`: `context-isolation`, `shared-kernel`, `layers`, `dependencies`, `react`, `clock`, `config`.
|
|
307
|
+
- Checks in `backend.rules.lint`: `context-isolation`, `shared-kernel`, `layers`, `dependencies`, `react`, `svelte`, `clock`, `config`.
|
|
298
308
|
|
|
299
309
|
Defaults and details: [Dependency rules](API.md#dependency-rules), [`df-lint`](API.md#df-lint).
|
|
300
310
|
|
|
@@ -343,7 +353,7 @@ From 7.x it splits the config into `project`, `backend` and `frontend`, records
|
|
|
343
353
|
|
|
344
354
|
### How to teach your coding agent
|
|
345
355
|
|
|
346
|
-
The package ships skills that teach coding agents to plan features, scaffold with `df-scaffold`, build the React part with `df-react` and implement the generated code.
|
|
356
|
+
The package ships skills that teach coding agents to plan features, scaffold with `df-scaffold`, build the React part with `df-react` or the Svelte part with `df-svelte` and implement the generated code.
|
|
347
357
|
|
|
348
358
|
```
|
|
349
359
|
npx df-skills --claude
|
package/dist/115.js
CHANGED
|
@@ -228,6 +228,148 @@ const missingPackages = (packages)=>{
|
|
|
228
228
|
] : [];
|
|
229
229
|
};
|
|
230
230
|
const missingDomainFirstPackages = ()=>missingPackages(ConfigFile.backend.domainFirstPackages);
|
|
231
|
+
const ignoredFolders = new Set([
|
|
232
|
+
'node_modules',
|
|
233
|
+
'.git',
|
|
234
|
+
'.next',
|
|
235
|
+
'.svelte-kit',
|
|
236
|
+
'dist',
|
|
237
|
+
'build',
|
|
238
|
+
'out',
|
|
239
|
+
'coverage',
|
|
240
|
+
'storybook-static'
|
|
241
|
+
]);
|
|
242
|
+
const codeExtension = /\.(?:tsx?|mts|cts|jsx?|mjs|cjs|mdx|svelte)$/;
|
|
243
|
+
const escapeRegExp = (value)=>value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
244
|
+
const walk = (folder)=>{
|
|
245
|
+
if (!node_fs.existsSync(folder)) return [];
|
|
246
|
+
return node_fs.readdirSync(folder, {
|
|
247
|
+
withFileTypes: true
|
|
248
|
+
}).flatMap((entry)=>{
|
|
249
|
+
const entryPath = node_path.join(folder, entry.name);
|
|
250
|
+
if (entry.isDirectory()) return ignoredFolders.has(entry.name) ? [] : walk(entryPath);
|
|
251
|
+
return entry.isFile() ? [
|
|
252
|
+
entryPath
|
|
253
|
+
] : [];
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
const toPosix = (value)=>value.split(node_path.sep).join('/');
|
|
257
|
+
const readAliases = (projectRoot)=>{
|
|
258
|
+
const tsconfig = node_path.join(projectRoot, 'tsconfig.json');
|
|
259
|
+
if (!node_fs.existsSync(tsconfig)) return [];
|
|
260
|
+
try {
|
|
261
|
+
const { compilerOptions = {} } = JSON.parse(stripJsonComments(node_fs.readFileSync(tsconfig, 'utf8')));
|
|
262
|
+
const base = node_path.resolve(projectRoot, compilerOptions.baseUrl ?? '.');
|
|
263
|
+
return Object.entries(compilerOptions.paths ?? {}).filter(([pattern, targets])=>pattern.endsWith('*') && targets[0]?.endsWith('*')).map(([pattern, [target]])=>({
|
|
264
|
+
prefix: pattern.slice(0, -1),
|
|
265
|
+
target: node_path.resolve(base, target.slice(0, -1))
|
|
266
|
+
}));
|
|
267
|
+
} catch {
|
|
268
|
+
return [];
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
const specifierPattern = /(\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*|\bmock\s*\(\s*)(['"])([^'"\n]+)\2/g;
|
|
272
|
+
const reExportPattern = /\bexport\s+(?:type\s+)?(?:\*(?:\s+as\s+[\w$]+)?|\{[^}]*\})\s*from\s*(['"])([^'"\n]+)\1/g;
|
|
273
|
+
const importPaths = (file)=>{
|
|
274
|
+
const withoutExtension = file.replace(codeExtension, '');
|
|
275
|
+
return 'index' === node_path.basename(withoutExtension) ? [
|
|
276
|
+
withoutExtension,
|
|
277
|
+
node_path.dirname(withoutExtension)
|
|
278
|
+
] : [
|
|
279
|
+
withoutExtension
|
|
280
|
+
];
|
|
281
|
+
};
|
|
282
|
+
const projectImports = (projectRoot)=>{
|
|
283
|
+
const aliases = readAliases(projectRoot);
|
|
284
|
+
const resolve = (specifier, fromFile)=>{
|
|
285
|
+
if (specifier.startsWith('.')) return {
|
|
286
|
+
resolved: node_path.resolve(node_path.dirname(fromFile), specifier),
|
|
287
|
+
alias: void 0
|
|
288
|
+
};
|
|
289
|
+
const alias = aliases.find(({ prefix })=>specifier.startsWith(prefix));
|
|
290
|
+
return alias ? {
|
|
291
|
+
resolved: node_path.resolve(alias.target, specifier.slice(alias.prefix.length)),
|
|
292
|
+
alias
|
|
293
|
+
} : void 0;
|
|
294
|
+
};
|
|
295
|
+
const specifierFor = (fromFile, toPath, alias)=>{
|
|
296
|
+
const aliased = alias && toPosix(node_path.relative(alias.target, toPath));
|
|
297
|
+
if (aliased && !aliased.startsWith('..')) return `${alias.prefix}${aliased}`;
|
|
298
|
+
const relative = toPosix(node_path.relative(node_path.dirname(fromFile), toPath));
|
|
299
|
+
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
300
|
+
};
|
|
301
|
+
const codeFiles = new Map(walk(projectRoot).filter((file)=>codeExtension.test(file)).map((file)=>[
|
|
302
|
+
file,
|
|
303
|
+
node_fs.readFileSync(file, 'utf8')
|
|
304
|
+
]));
|
|
305
|
+
const importsOf = (file)=>[
|
|
306
|
+
...(codeFiles.get(file) ?? '').matchAll(specifierPattern)
|
|
307
|
+
].map(([, , , specifier])=>resolve(specifier, file)?.resolved).filter((resolved)=>!!resolved);
|
|
308
|
+
return {
|
|
309
|
+
resolve,
|
|
310
|
+
specifierFor,
|
|
311
|
+
codeFiles,
|
|
312
|
+
importsOf
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyFile = (content)=>content, stopAtFor })=>{
|
|
316
|
+
const stopFor = (file)=>stopAtFor?.(file) ?? stopAt;
|
|
317
|
+
const { resolve, specifierFor, codeFiles } = projectImports(projectRoot);
|
|
318
|
+
const barrels = new Set();
|
|
319
|
+
const isBarrel = (resolved)=>barrels.has(resolved.replace(codeExtension, ''));
|
|
320
|
+
for(let found = true; found;){
|
|
321
|
+
found = false;
|
|
322
|
+
for (const [file, content] of codeFiles){
|
|
323
|
+
if (moves.has(file) || isBarrel(file)) continue;
|
|
324
|
+
const reExportsModule = [
|
|
325
|
+
...content.matchAll(reExportPattern)
|
|
326
|
+
].some(([, , specifier])=>{
|
|
327
|
+
const resolution = resolve(specifier, file);
|
|
328
|
+
return !!resolution && (!!movedPath(resolution.resolved) || isBarrel(resolution.resolved));
|
|
329
|
+
});
|
|
330
|
+
if (reExportsModule) {
|
|
331
|
+
for (const importPath of importPaths(file))barrels.add(importPath);
|
|
332
|
+
found = true;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const rewrite = (content, oldFile, newFile)=>{
|
|
337
|
+
let referencesModule = false;
|
|
338
|
+
const rewritten = content.replace(specifierPattern, (match, keyword, quote, specifier)=>{
|
|
339
|
+
const resolution = resolve(specifier, oldFile);
|
|
340
|
+
if (!resolution) return match;
|
|
341
|
+
const moved = movedPath(resolution.resolved);
|
|
342
|
+
if (moved || isBarrel(resolution.resolved)) referencesModule = true;
|
|
343
|
+
if (!moved && oldFile === newFile) return match;
|
|
344
|
+
const next = specifierFor(newFile, moved ?? resolution.resolved, resolution.alias);
|
|
345
|
+
return `${keyword}${quote}${next}${quote}`;
|
|
346
|
+
});
|
|
347
|
+
const changed = everyFile(rewritten);
|
|
348
|
+
if (!referencesModule && !moves.has(oldFile)) return changed;
|
|
349
|
+
return rename(changed, {
|
|
350
|
+
moved: moves.has(oldFile)
|
|
351
|
+
});
|
|
352
|
+
};
|
|
353
|
+
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new File(file).moveTo(newFile, stopFor(file));
|
|
354
|
+
const updated = [];
|
|
355
|
+
for (const [file, content] of codeFiles){
|
|
356
|
+
const newFile = moves.get(file);
|
|
357
|
+
const next = rewrite(content, file, newFile ?? file);
|
|
358
|
+
if (newFile && newFile !== file) {
|
|
359
|
+
new File(newFile).data = next;
|
|
360
|
+
new File(file).delete(stopFor(file));
|
|
361
|
+
} else if (next !== content) {
|
|
362
|
+
new File(file).update(next);
|
|
363
|
+
if (!newFile) updated.push(file);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return {
|
|
367
|
+
moves: [
|
|
368
|
+
...moves
|
|
369
|
+
].filter(([from, to])=>from !== to),
|
|
370
|
+
updated
|
|
371
|
+
};
|
|
372
|
+
};
|
|
231
373
|
const openapiExtractorPath = "scripts/extract-open-api-data-from-endpoint.ts";
|
|
232
374
|
const rootFolderSegments = (rootFolder, indent = 20)=>rootFolder.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment && '.' !== segment).map((segment)=>`'${segment}',\n${' '.repeat(indent)}`).join('');
|
|
233
375
|
const legacyEndpointFileLookup = (rootFolder)=>` // The controller, if any, is the first folder of the path:
|
|
@@ -442,147 +584,6 @@ ${endpointFileLookup(rootFolder)}
|
|
|
442
584
|
};
|
|
443
585
|
};
|
|
444
586
|
`;
|
|
445
|
-
const ignoredFolders = new Set([
|
|
446
|
-
'node_modules',
|
|
447
|
-
'.git',
|
|
448
|
-
'.next',
|
|
449
|
-
'dist',
|
|
450
|
-
'build',
|
|
451
|
-
'out',
|
|
452
|
-
'coverage',
|
|
453
|
-
'storybook-static'
|
|
454
|
-
]);
|
|
455
|
-
const codeExtension = /\.(?:tsx?|mts|cts|jsx?|mjs|cjs|mdx)$/;
|
|
456
|
-
const escapeRegExp = (value)=>value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
457
|
-
const walk = (folder)=>{
|
|
458
|
-
if (!node_fs.existsSync(folder)) return [];
|
|
459
|
-
return node_fs.readdirSync(folder, {
|
|
460
|
-
withFileTypes: true
|
|
461
|
-
}).flatMap((entry)=>{
|
|
462
|
-
const entryPath = node_path.join(folder, entry.name);
|
|
463
|
-
if (entry.isDirectory()) return ignoredFolders.has(entry.name) ? [] : walk(entryPath);
|
|
464
|
-
return entry.isFile() ? [
|
|
465
|
-
entryPath
|
|
466
|
-
] : [];
|
|
467
|
-
});
|
|
468
|
-
};
|
|
469
|
-
const toPosix = (value)=>value.split(node_path.sep).join('/');
|
|
470
|
-
const readAliases = (projectRoot)=>{
|
|
471
|
-
const tsconfig = node_path.join(projectRoot, 'tsconfig.json');
|
|
472
|
-
if (!node_fs.existsSync(tsconfig)) return [];
|
|
473
|
-
try {
|
|
474
|
-
const { compilerOptions = {} } = JSON.parse(stripJsonComments(node_fs.readFileSync(tsconfig, 'utf8')));
|
|
475
|
-
const base = node_path.resolve(projectRoot, compilerOptions.baseUrl ?? '.');
|
|
476
|
-
return Object.entries(compilerOptions.paths ?? {}).filter(([pattern, targets])=>pattern.endsWith('*') && targets[0]?.endsWith('*')).map(([pattern, [target]])=>({
|
|
477
|
-
prefix: pattern.slice(0, -1),
|
|
478
|
-
target: node_path.resolve(base, target.slice(0, -1))
|
|
479
|
-
}));
|
|
480
|
-
} catch {
|
|
481
|
-
return [];
|
|
482
|
-
}
|
|
483
|
-
};
|
|
484
|
-
const specifierPattern = /(\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*|\bmock\s*\(\s*)(['"])([^'"\n]+)\2/g;
|
|
485
|
-
const reExportPattern = /\bexport\s+(?:type\s+)?(?:\*(?:\s+as\s+[\w$]+)?|\{[^}]*\})\s*from\s*(['"])([^'"\n]+)\1/g;
|
|
486
|
-
const importPaths = (file)=>{
|
|
487
|
-
const withoutExtension = file.replace(codeExtension, '');
|
|
488
|
-
return 'index' === node_path.basename(withoutExtension) ? [
|
|
489
|
-
withoutExtension,
|
|
490
|
-
node_path.dirname(withoutExtension)
|
|
491
|
-
] : [
|
|
492
|
-
withoutExtension
|
|
493
|
-
];
|
|
494
|
-
};
|
|
495
|
-
const projectImports = (projectRoot)=>{
|
|
496
|
-
const aliases = readAliases(projectRoot);
|
|
497
|
-
const resolve = (specifier, fromFile)=>{
|
|
498
|
-
if (specifier.startsWith('.')) return {
|
|
499
|
-
resolved: node_path.resolve(node_path.dirname(fromFile), specifier),
|
|
500
|
-
alias: void 0
|
|
501
|
-
};
|
|
502
|
-
const alias = aliases.find(({ prefix })=>specifier.startsWith(prefix));
|
|
503
|
-
return alias ? {
|
|
504
|
-
resolved: node_path.resolve(alias.target, specifier.slice(alias.prefix.length)),
|
|
505
|
-
alias
|
|
506
|
-
} : void 0;
|
|
507
|
-
};
|
|
508
|
-
const specifierFor = (fromFile, toPath, alias)=>{
|
|
509
|
-
const aliased = alias && toPosix(node_path.relative(alias.target, toPath));
|
|
510
|
-
if (aliased && !aliased.startsWith('..')) return `${alias.prefix}${aliased}`;
|
|
511
|
-
const relative = toPosix(node_path.relative(node_path.dirname(fromFile), toPath));
|
|
512
|
-
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
513
|
-
};
|
|
514
|
-
const codeFiles = new Map(walk(projectRoot).filter((file)=>codeExtension.test(file)).map((file)=>[
|
|
515
|
-
file,
|
|
516
|
-
node_fs.readFileSync(file, 'utf8')
|
|
517
|
-
]));
|
|
518
|
-
const importsOf = (file)=>[
|
|
519
|
-
...(codeFiles.get(file) ?? '').matchAll(specifierPattern)
|
|
520
|
-
].map(([, , , specifier])=>resolve(specifier, file)?.resolved).filter((resolved)=>!!resolved);
|
|
521
|
-
return {
|
|
522
|
-
resolve,
|
|
523
|
-
specifierFor,
|
|
524
|
-
codeFiles,
|
|
525
|
-
importsOf
|
|
526
|
-
};
|
|
527
|
-
};
|
|
528
|
-
const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyFile = (content)=>content, stopAtFor })=>{
|
|
529
|
-
const stopFor = (file)=>stopAtFor?.(file) ?? stopAt;
|
|
530
|
-
const { resolve, specifierFor, codeFiles } = projectImports(projectRoot);
|
|
531
|
-
const barrels = new Set();
|
|
532
|
-
const isBarrel = (resolved)=>barrels.has(resolved.replace(codeExtension, ''));
|
|
533
|
-
for(let found = true; found;){
|
|
534
|
-
found = false;
|
|
535
|
-
for (const [file, content] of codeFiles){
|
|
536
|
-
if (moves.has(file) || isBarrel(file)) continue;
|
|
537
|
-
const reExportsModule = [
|
|
538
|
-
...content.matchAll(reExportPattern)
|
|
539
|
-
].some(([, , specifier])=>{
|
|
540
|
-
const resolution = resolve(specifier, file);
|
|
541
|
-
return !!resolution && (!!movedPath(resolution.resolved) || isBarrel(resolution.resolved));
|
|
542
|
-
});
|
|
543
|
-
if (reExportsModule) {
|
|
544
|
-
for (const importPath of importPaths(file))barrels.add(importPath);
|
|
545
|
-
found = true;
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
const rewrite = (content, oldFile, newFile)=>{
|
|
550
|
-
let referencesModule = false;
|
|
551
|
-
const rewritten = content.replace(specifierPattern, (match, keyword, quote, specifier)=>{
|
|
552
|
-
const resolution = resolve(specifier, oldFile);
|
|
553
|
-
if (!resolution) return match;
|
|
554
|
-
const moved = movedPath(resolution.resolved);
|
|
555
|
-
if (moved || isBarrel(resolution.resolved)) referencesModule = true;
|
|
556
|
-
if (!moved && oldFile === newFile) return match;
|
|
557
|
-
const next = specifierFor(newFile, moved ?? resolution.resolved, resolution.alias);
|
|
558
|
-
return `${keyword}${quote}${next}${quote}`;
|
|
559
|
-
});
|
|
560
|
-
const changed = everyFile(rewritten);
|
|
561
|
-
if (!referencesModule && !moves.has(oldFile)) return changed;
|
|
562
|
-
return rename(changed, {
|
|
563
|
-
moved: moves.has(oldFile)
|
|
564
|
-
});
|
|
565
|
-
};
|
|
566
|
-
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new File(file).moveTo(newFile, stopFor(file));
|
|
567
|
-
const updated = [];
|
|
568
|
-
for (const [file, content] of codeFiles){
|
|
569
|
-
const newFile = moves.get(file);
|
|
570
|
-
const next = rewrite(content, file, newFile ?? file);
|
|
571
|
-
if (newFile && newFile !== file) {
|
|
572
|
-
new File(newFile).data = next;
|
|
573
|
-
new File(file).delete(stopFor(file));
|
|
574
|
-
} else if (next !== content) {
|
|
575
|
-
new File(file).update(next);
|
|
576
|
-
if (!newFile) updated.push(file);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
return {
|
|
580
|
-
moves: [
|
|
581
|
-
...moves
|
|
582
|
-
].filter(([from, to])=>from !== to),
|
|
583
|
-
updated
|
|
584
|
-
};
|
|
585
|
-
};
|
|
586
587
|
const rootControllerFolder = '(root)';
|
|
587
588
|
const pathParameterAsName = (segment)=>segment.startsWith(':') ? `_${segment.slice(1)}_` : segment;
|
|
588
589
|
const isPathParameterName = (name)=>name.startsWith(':') || /^_.+_$/.test(name);
|
package/dist/201.js
CHANGED
|
@@ -472,6 +472,7 @@ const lintChecks = [
|
|
|
472
472
|
'layers',
|
|
473
473
|
'dependencies',
|
|
474
474
|
'react',
|
|
475
|
+
'svelte',
|
|
475
476
|
'clock',
|
|
476
477
|
'config'
|
|
477
478
|
];
|
|
@@ -516,8 +517,16 @@ const reactConfigSchema = zod.object({
|
|
|
516
517
|
]).optional(),
|
|
517
518
|
storybookFramework: zod.string().optional()
|
|
518
519
|
}).passthrough();
|
|
520
|
+
const svelteConfigSchema = zod.object({
|
|
521
|
+
framework: zod["enum"]([
|
|
522
|
+
'svelte',
|
|
523
|
+
'sveltekit'
|
|
524
|
+
]).optional(),
|
|
525
|
+
storybookFramework: zod.string().optional()
|
|
526
|
+
}).passthrough();
|
|
519
527
|
const frontendConfigSchema = zod.object({
|
|
520
|
-
react: reactConfigSchema.optional()
|
|
528
|
+
react: reactConfigSchema.optional(),
|
|
529
|
+
svelte: svelteConfigSchema.optional()
|
|
521
530
|
}).passthrough();
|
|
522
531
|
const configSchema = zod.object({
|
|
523
532
|
project: projectConfigSchema,
|