Skip to content

Commit 34cf4a5

Browse files
authored
Merge pull request #780 from mk3008/778-scaffold-ルート境界をまたぐ-import-を-root-alias-に統一する
fix(ztd-cli): align scaffold cross-root imports with root aliases
2 parents 3b96bc5 + 3f9cab6 commit 34cf4a5

12 files changed

Lines changed: 132 additions & 8 deletions

File tree

.changeset/ten-soft-camels-jump.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@rawsql-ts/ztd-cli": patch
3+
---
4+
5+
Align generated project root aliases across `package.json`, `tsconfig.json`, and `vitest.config.ts` so scaffolded code can use `#features/*`, `#libraries/*`, `#adapters/*`, and `#tests/*` consistently.
6+
7+
Starter and scaffold templates now use root aliases for imports that cross canonical roots instead of deep relative paths, which makes generated projects easier to move and reorganize without rewriting import depth.

packages/ztd-cli/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,9 @@ As boundary depth grows, avoid making every import depth-sensitive by default.
166166

167167
- The goal is boundary-change safety, not a blanket root-alias migration.
168168
- Keep local, nearby references relative when they move with the same boundary.
169-
- Stabilize only shared references that are likely to break when work is split horizontally and moved into a deeper child boundary, such as `src/features/_shared/*` or `tests/support/*`.
170-
- One workable tactic is package `imports` or an equivalent alias that works in both TypeScript and runtime resolution, but that is a means, not the architectural goal.
171-
- Minimum rule: imports that cross boundaries should make the target boundary explicit and go through its `boundary.ts` entrypoint.
172-
- Pragmatic exception: designated shared seams such as `src/features/_shared/*` and `tests/support/*` may use stabilized root-level aliases or package-style imports because they are shared support seams, not another boundary's private internals.
173-
- Do not treat this issue as a reason to rewrite every scaffolded import to one style.
169+
- When an import crosses canonical roots, use the matching root alias so the target root stays explicit: `#features/*`, `#libraries/*`, `#adapters/*`, and `#tests/*`.
170+
- Feature-to-feature imports should still go through the target boundary's `boundary.ts` entrypoint rather than deep private files.
171+
- Root aliases are for cross-root references and shared seams, not a reason to rewrite every same-root local import to one style.
174172

175173
## Troubleshooting
176174

packages/ztd-cli/src/commands/init.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,6 +2076,14 @@ function ensurePackageJsonFormatting(
20762076
types: './src/features/*.ts',
20772077
default: './dist/features/*.js'
20782078
},
2079+
'#libraries/*.js': {
2080+
types: './src/libraries/*.ts',
2081+
default: './dist/libraries/*.js'
2082+
},
2083+
'#adapters/*.js': {
2084+
types: './src/adapters/*.ts',
2085+
default: './dist/adapters/*.js'
2086+
},
20792087
'#tests/*.js': {
20802088
types: './tests/*.ts',
20812089
default: './tests/*.ts'

packages/ztd-cli/templates/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ The starter keeps `ztdRootDir`, `ddlDir`, `defaultSchema`, and `searchPath` in `
3636

3737
`src/features/<feature>/tests/` is where feature-root boundary tests live. Query-local ZTD assets live under `src/features/<feature>/queries/<query>/tests/{generated,cases}` with the thin entrypoint beside them. Starter-owned shared support lives at `tests/support/ztd/`, while `.ztd/` is the tool-managed workspace for generated metadata and support files. Keep `FeatureQueryExecutor` in `src/features/_shared/`, keep the driver-neutral `SqlClient` contract in `src/libraries/sql/sql-client.ts`, and put driver or sink bindings under `src/adapters/<tech>/`.
3838

39+
When an import crosses one of the canonical roots, use the root alias instead of a depth-sensitive relative path:
40+
41+
- `#features/*` for `src/features/*`
42+
- `#libraries/*` for `src/libraries/*`
43+
- `#adapters/*` for `src/adapters/*`
44+
- `#tests/*` for `tests/*`
45+
46+
Keep local same-root references relative when they move with the same boundary. Use the alias when the import crosses a root boundary or points at shared support.
47+
3948
## Getting Started with AI
4049

4150
Use this short prompt:

packages/ztd-cli/templates/src/adapters/console/repositoryTelemetry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {
22
RepositoryTelemetry,
33
RepositoryTelemetryConsoleOptions,
44
RepositoryTelemetryEvent,
5-
} from '../../libraries/telemetry/types.js';
5+
} from '#libraries/telemetry/types.js';
66

77
/**
88
* Create a conservative console-backed telemetry hook for repositories.

packages/ztd-cli/templates/src/adapters/pg/sql-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { SqlClient } from '../../libraries/sql/sql-client.js';
1+
import type { SqlClient } from '#libraries/sql/sql-client.js';
22

33
/**
44
* Adapt a `pg`-style queryable (Client or Pool) into a SqlClient.

packages/ztd-cli/templates/tests/support/testkit-client.webapi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { SqlClient } from '../../src/libraries/sql/sql-client.js';
1+
import type { SqlClient } from '#libraries/sql/sql-client.js';
22

33
export type TestkitClient = SqlClient & {
44
close(): Promise<void>;

packages/ztd-cli/templates/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"baseUrl": ".",
88
"paths": {
99
"#features/*": ["src/features/*"],
10+
"#libraries/*": ["src/libraries/*"],
11+
"#adapters/*": ["src/adapters/*"],
1012
"#tests/*": ["tests/*"]
1113
},
1214
"strict": true,

packages/ztd-cli/templates/vitest.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export default defineConfig({
55
resolve: {
66
alias: {
77
'#features': fileURLToPath(new URL('./src/features', import.meta.url)),
8+
'#libraries': fileURLToPath(new URL('./src/libraries', import.meta.url)),
9+
'#adapters': fileURLToPath(new URL('./src/adapters', import.meta.url)),
810
'#tests': fileURLToPath(new URL('./tests', import.meta.url)),
911
},
1012
},

packages/ztd-cli/tests/directoryFinding.docs.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ test('feature guidance centers the sample feature and recursive boundary folders
103103
);
104104
expect(readNormalizedFile('packages/ztd-cli/templates/src/libraries/sql/sql-client.ts')).toContain('SqlClient');
105105
expect(readNormalizedFile('packages/ztd-cli/templates/src/adapters/pg/sql-client.ts')).toContain('fromPg');
106+
expect(readNormalizedFile('packages/ztd-cli/templates/src/adapters/pg/sql-client.ts')).toContain(
107+
"from '#libraries/sql/sql-client.js'"
108+
);
109+
expect(readNormalizedFile('packages/ztd-cli/templates/src/adapters/console/repositoryTelemetry.ts')).toContain(
110+
"from '#libraries/telemetry/types.js'"
111+
);
112+
expect(readNormalizedFile('packages/ztd-cli/templates/tests/support/testkit-client.webapi.ts')).toContain(
113+
"from '#libraries/sql/sql-client.js'"
114+
);
106115
});
107116

108117
test('feature-first scaffold files exist in the template bundle', () => {

0 commit comments

Comments
 (0)