@yearofthedan/warp 0.1.0 → 0.3.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 +45 -69
- package/dist/analysis/imports.d.ts +3 -1
- package/dist/analysis/imports.js +5 -1
- package/dist/analysis/typescript.js +2 -1
- package/dist/app/check.js +2 -1
- package/dist/app/checkModel.js +1 -1
- package/dist/app/load.js +12 -12
- package/dist/builtins/advice.d.ts +8 -0
- package/dist/builtins/advice.js +42 -0
- package/dist/builtins/dependency-direction/dependencyDirection.js +36 -16
- package/dist/builtins/index.js +2 -0
- package/dist/builtins/module-externals/moduleExternals.js +10 -9
- package/dist/builtins/no-cross-module-reexport/noCrossModuleReexport.js +16 -5
- package/dist/builtins/place.js +5 -3
- package/dist/builtins/unresolved-import/unresolvedImport.d.ts +2 -0
- package/dist/builtins/unresolved-import/unresolvedImport.js +15 -0
- package/dist/builtins/unused-declaration/declarations.js +1 -1
- package/dist/builtins/unused-declaration/empty.js +16 -9
- package/dist/builtins/unused-declaration/grants.js +8 -11
- package/dist/builtins/unused-declaration/surfaces.js +11 -19
- package/dist/cli.js +3 -3
- package/dist/git/repository.js +11 -16
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/model/archetype/builder.d.ts +11 -11
- package/dist/model/archetype/builder.js +14 -21
- package/dist/model/archetype/data.d.ts +19 -13
- package/dist/model/archetype/draft.d.ts +2 -9
- package/dist/model/archetype/draft.js +48 -59
- package/dist/model/archetype/fixes.d.ts +37 -0
- package/dist/model/archetype/fixes.js +234 -0
- package/dist/model/archetype/reach.js +34 -80
- package/dist/model/archetype/references.d.ts +1 -1
- package/dist/model/archetype/references.js +13 -28
- package/dist/model/archetype/requirements.js +3 -6
- package/dist/model/archetype/resolve.d.ts +2 -3
- package/dist/model/archetype/resolve.js +93 -71
- package/dist/model/archetype/rulesets.js +0 -7
- package/dist/model/archetype/settings.js +4 -19
- package/dist/model/facts.d.ts +6 -0
- package/dist/reporters/agent.d.ts +4 -0
- package/dist/reporters/agent.js +24 -0
- package/dist/reporters/claudeHook.js +3 -3
- package/dist/reporters/model.js +8 -9
- package/dist/reporters/omp.js +3 -5
- package/dist/reporters/reporter.d.ts +0 -4
- package/dist/reporters/reporter.js +0 -9
- package/dist/reporters/text.d.ts +2 -0
- package/dist/reporters/text.js +12 -8
- package/package.json +2 -3
- package/integrations/omp/warp.ts +0 -40
|
@@ -5,11 +5,11 @@ export const unusedGrants = (context) => {
|
|
|
5
5
|
const used = usedRefs(context);
|
|
6
6
|
return declared(context)
|
|
7
7
|
.filter(({ ref, holders }) => !used.has(ref) && holders.some((holder) => context.atModule(holder).on))
|
|
8
|
-
.map(({ ref, declaredIn, layer, holders }) => {
|
|
8
|
+
.map(({ ref, declaredIn, layer, holders, kit }) => {
|
|
9
9
|
const using = show(ref);
|
|
10
10
|
const modules = holders.map((holder) => holder.id);
|
|
11
11
|
const names = holders.map(named).join(', ');
|
|
12
|
-
const files =
|
|
12
|
+
const files = kit ? `the tests of ${names}` : names;
|
|
13
13
|
return unused(context.config, `${declaredIn}->${using}`, `${declaredIn} uses ${using}, but nothing in ${files} imports through it. Remove it from the using.`, { kind: 'grant', declaredIn, layer, using, modules });
|
|
14
14
|
});
|
|
15
15
|
};
|
|
@@ -17,20 +17,17 @@ const declared = (context) => Object.values(context.config.archetypes).flatMap((
|
|
|
17
17
|
const instances = instancesOf(context, archetype.name);
|
|
18
18
|
const modules = archetype.modules.flatMap((module) => {
|
|
19
19
|
const holders = childrenNamed(context, instances, module.name);
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
return [
|
|
23
|
-
...module.using.map((ref) => ({ ref, declaredIn, layer: 'production', holders })),
|
|
24
|
-
...tests.map((ref) => ({ ref, declaredIn: `${declaredIn}.tests`, layer: 'test', holders })),
|
|
25
|
-
];
|
|
20
|
+
const layer = module.kind === 'test' ? 'test' : 'production';
|
|
21
|
+
return module.using.map((ref) => ({ ref, declaredIn: `${archetype.name}.${module.name}`, layer, holders }));
|
|
26
22
|
});
|
|
27
|
-
const
|
|
23
|
+
const kit = (archetype.testUsing ?? []).map((ref) => ({
|
|
28
24
|
ref,
|
|
29
|
-
declaredIn: `${archetype.name}.
|
|
25
|
+
declaredIn: `${archetype.name}.testUsing`,
|
|
30
26
|
layer: 'test',
|
|
31
27
|
holders: instances,
|
|
28
|
+
kit: true,
|
|
32
29
|
}));
|
|
33
|
-
return [...modules, ...
|
|
30
|
+
return [...modules, ...kit];
|
|
34
31
|
});
|
|
35
32
|
const usedRefs = ({ project, verdicts }) => {
|
|
36
33
|
const used = new Set();
|
|
@@ -13,18 +13,22 @@ export const unusedSurfaces = (context) => {
|
|
|
13
13
|
const reached = (context, edges, holder, files) => edges.some(({ from, to }) => files.has(to) && !within(context.model.moduleOf(from), holder));
|
|
14
14
|
const declared = (context) => Object.values(context.config.archetypes).flatMap((archetype) => {
|
|
15
15
|
const instances = instancesOf(context, archetype.name).filter((instance) => instance !== context.model.root);
|
|
16
|
-
const
|
|
16
|
+
const judged = isEntry(archetype.exposes)
|
|
17
|
+
? instances.filter((instance) => !isTopLevel(context, instance))
|
|
18
|
+
: instances;
|
|
19
|
+
const own = archetype.exposes ? surfaces(context, archetype.name, archetype.exposes, judged, 'production') : [];
|
|
17
20
|
const modules = archetype.modules.flatMap((module) => {
|
|
18
21
|
const holders = childrenNamed(context, instances, module.name);
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
const layer = module.kind === 'test' ? 'test' : 'production';
|
|
23
|
+
return module.kind !== 'dir' && module.exposes
|
|
24
|
+
? surfaces(context, `${archetype.name}.${module.name}`, module.exposes, holders, layer)
|
|
21
25
|
: [];
|
|
22
26
|
});
|
|
23
|
-
|
|
24
|
-
return [...own, ...modules, ...tests];
|
|
27
|
+
return [...own, ...modules];
|
|
25
28
|
});
|
|
26
|
-
const
|
|
27
|
-
|
|
29
|
+
const isEntry = (exposes) => exposes?.kind === 'files' && exposes.entry === true;
|
|
30
|
+
const isTopLevel = (context, module) => module.parent === context.model.root;
|
|
31
|
+
const surfaces = (context, declaredIn, exposes, holders, layer) => {
|
|
28
32
|
if (exposes.kind !== 'surfaces')
|
|
29
33
|
return [
|
|
30
34
|
{ declaredIn, layer, exposes: whole(exposes), holders, files: (holder) => context.verdicts.surface(holder) },
|
|
@@ -37,18 +41,6 @@ const production = (context, declaredIn, exposes, holders) => {
|
|
|
37
41
|
files: (holder) => context.verdicts.surface(holder, name),
|
|
38
42
|
}));
|
|
39
43
|
};
|
|
40
|
-
const test = (declaredIn, exposes, holders) => {
|
|
41
|
-
const layer = 'test';
|
|
42
|
-
const filesOf = (holder, names) => new Set(holder.children
|
|
43
|
-
.filter((child) => child.test && (names === undefined || names.has(child.name)))
|
|
44
|
-
.flatMap((child) => child.files));
|
|
45
|
-
if (exposes.kind !== 'surfaces')
|
|
46
|
-
return [{ declaredIn, layer, exposes: whole(exposes), holders, files: (holder) => filesOf(holder) }];
|
|
47
|
-
return Object.entries(exposes.surfaces).map(([name, refs]) => {
|
|
48
|
-
const names = new Set(refs.flatMap((ref) => (ref.kind === 'module' ? [`tests.${ref.module}`] : [])));
|
|
49
|
-
return { declaredIn, layer, exposes: `exposes ${name}`, holders, files: (holder) => filesOf(holder, names) };
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
44
|
const whole = (exposes) => {
|
|
53
45
|
if (exposes.kind === 'all')
|
|
54
46
|
return 'exposes(all())';
|
package/dist/cli.js
CHANGED
|
@@ -27,15 +27,15 @@ check reports every finding in the working tree.
|
|
|
27
27
|
diff reports findings that are new or worse at <head> than at <base>. Without <head>, compares the working tree.
|
|
28
28
|
<base>...<head> compares from where <head> left <base>, as git does.
|
|
29
29
|
With --since-last-run, compares the working tree with the last such run, or with <base> if there is none.
|
|
30
|
-
model prints the modules the config finds, and which
|
|
30
|
+
model prints the modules the config finds, and which module each file is in.
|
|
31
31
|
|
|
32
32
|
--config path to the config file (default: the first of warp.config.ts, .mts, .js, .mjs)
|
|
33
33
|
--ruleset one of the config's rulesets (default: the one named default, if any)
|
|
34
34
|
--reporter ${[...reporters.keys()].join(', ')} (default: text)
|
|
35
35
|
--since-last-run with diff, compare with the last diff run that had this flag
|
|
36
36
|
--fail exit 1 when there are findings (check) or new or worse findings (diff)
|
|
37
|
-
--rules with model, list each module's
|
|
38
|
-
--json print the model as JSON, with every module's
|
|
37
|
+
--rules with model, list each module's rule settings that differ from the defaults
|
|
38
|
+
--json print the model as JSON, with every module's resolved rule settings`;
|
|
39
39
|
const adaptersAt = (root) => {
|
|
40
40
|
const adapters = { analyzer: typescriptAnalyzer, foldersAt: diskFolders };
|
|
41
41
|
try {
|
package/dist/git/repository.js
CHANGED
|
@@ -13,17 +13,11 @@ export const gitRepository = (projectRoot) => {
|
|
|
13
13
|
mergeBase: (a, b) => git('merge-base', a, b),
|
|
14
14
|
changedLines: (base, head) => changedLines(git, base, head),
|
|
15
15
|
checkout(commit, requiredFile) {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
git('worktree', 'remove', '--force', dir);
|
|
20
|
-
}
|
|
21
|
-
finally {
|
|
22
|
-
rmSync(dir, { recursive: true, force: true });
|
|
23
|
-
}
|
|
24
|
-
};
|
|
16
|
+
const scratch = mkdtempSync(join(tmpdir(), 'warp-'));
|
|
17
|
+
const dir = join(scratch, 'tree');
|
|
18
|
+
const dispose = () => rmSync(scratch, { recursive: true, force: true });
|
|
25
19
|
try {
|
|
26
|
-
|
|
20
|
+
exportTree(top, commit, scratch, dir);
|
|
27
21
|
const root = join(dir, projectPath);
|
|
28
22
|
if (!existsSync(join(root, requiredFile)))
|
|
29
23
|
return { dispose };
|
|
@@ -36,17 +30,18 @@ export const gitRepository = (projectRoot) => {
|
|
|
36
30
|
return { projectRoot: root, dispose };
|
|
37
31
|
}
|
|
38
32
|
catch (error) {
|
|
39
|
-
|
|
40
|
-
dispose();
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
throw error;
|
|
44
|
-
}
|
|
33
|
+
dispose();
|
|
45
34
|
throw error;
|
|
46
35
|
}
|
|
47
36
|
},
|
|
48
37
|
};
|
|
49
38
|
};
|
|
39
|
+
const exportTree = (cwd, commit, scratch, dir) => {
|
|
40
|
+
const env = { ...process.env, GIT_INDEX_FILE: join(scratch, 'index'), GIT_LFS_SKIP_SMUDGE: '1' };
|
|
41
|
+
const git = (...args) => execFileSync('git', args, { cwd, env, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
42
|
+
git('read-tree', commit);
|
|
43
|
+
git('checkout-index', '--all', `--prefix=${dir}${sep}`);
|
|
44
|
+
};
|
|
50
45
|
export const projectPathOf = (projectRoot) => {
|
|
51
46
|
try {
|
|
52
47
|
return gitRepository(projectRoot).projectPath();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { all, archetype, contains, defineConfig, dir, exposes, files, pkg, ruleset, using, type ModuleHandle, type Selector, type Ruleset, type RuleSettings, type WarpConfig, type All, type Archetype, type Exposed, type Using, type UsingContext, type Package, type Reference, type Shape, } from './model/archetype/builder.ts';
|
|
1
|
+
export { all, archetype, contains, defineConfig, dir, exposes, files, mirror, pkg, ruleset, using, type ModuleHandle, type Selector, type Ruleset, type RuleSettings, type WarpConfig, type All, type Archetype, type Exposed, type Using, type TestUsing, type UsingContext, type Package, type Reference, type Shape, } from './model/archetype/builder.ts';
|
|
2
2
|
export { loadConfigData, type LoadedConfigData } from './app/load.ts';
|
|
3
3
|
export type * from './model/archetype/data.ts';
|
|
4
4
|
export type { Complexity, FunctionFacts, ImportEdge, FileFacts, Member, MemberGraph, MemberKind, } from './model/facts.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { all, archetype, contains, defineConfig, dir, exposes, files, pkg, ruleset, using, } from './model/archetype/builder.js';
|
|
1
|
+
export { all, archetype, contains, defineConfig, dir, exposes, files, mirror, pkg, ruleset, using, } from './model/archetype/builder.js';
|
|
2
2
|
export { loadConfigData } from './app/load.js';
|
|
3
3
|
export { ConfigError } from './model/configError.js';
|
|
4
4
|
export { wholeNumberOptions, } from './rules/rule.js';
|
|
@@ -19,7 +19,7 @@ export interface Package {
|
|
|
19
19
|
export interface Shape {
|
|
20
20
|
readonly [shapeBrand]: 'dir' | 'files';
|
|
21
21
|
}
|
|
22
|
-
export interface Selector<K extends 'dir' | 'files' = 'dir' | 'files'> {
|
|
22
|
+
export interface Selector<K extends 'dir' | 'files' | 'mirror' = 'dir' | 'files'> {
|
|
23
23
|
readonly [selectorBrand]: K;
|
|
24
24
|
}
|
|
25
25
|
export interface Self {
|
|
@@ -52,7 +52,7 @@ export interface UsingContext {
|
|
|
52
52
|
export type Using<P> = readonly (Reference | Package)[] | ((m: P, context: UsingContext) => readonly (Reference | Package)[]);
|
|
53
53
|
type Surfaces = Record<string, Reference | readonly Reference[]>;
|
|
54
54
|
export type Exposed = All | Selector<'files'>;
|
|
55
|
-
type NewName<K extends string, C> = K extends
|
|
55
|
+
type NewName<K extends string, C> = K extends keyof C ? `module '${K}' is already declared` : K;
|
|
56
56
|
type With<C, K extends string, T> = C & {
|
|
57
57
|
readonly [k in K]: T;
|
|
58
58
|
};
|
|
@@ -63,7 +63,11 @@ export interface Modules<C, H> {
|
|
|
63
63
|
module<const K extends string>(name: NewName<K, C>, selector: Selector<'files'>, archetype?: Archetype<undefined, {}, C, {}>): Modules<With<C, K, Reference>, With<H, K, ModuleHandle>>;
|
|
64
64
|
module<const K extends string>(name: NewName<K, C>, selector: Selector<'dir'>, archetype: Self): Modules<With<C, K, AnySurface>, With<H, K, ModuleHandle>>;
|
|
65
65
|
module<const K extends string, N extends string | undefined = undefined, E = {}, H2 = {}>(name: NewName<K, C>, selector: Selector<'dir'>, archetype?: Archetype<N, E, C, H2>): Modules<With<C, K, SurfaceRefs<E>>, With<H, K, HandleOf<N, H2>>>;
|
|
66
|
+
testModule<const K extends string>(name: NewName<K, C>, selector: Selector<'files' | 'dir' | 'mirror'>, archetype?: Archetype<undefined, {}, C, {}>): Modules<With<C, K, Reference>, With<H, K, ModuleHandle>>;
|
|
66
67
|
}
|
|
68
|
+
export type TestUsing<C, R> = readonly (Reference | Package)[] | ((m: C, context: {
|
|
69
|
+
readonly required: R;
|
|
70
|
+
}) => readonly (Reference | Package)[]);
|
|
67
71
|
export interface ContainsContext<R> {
|
|
68
72
|
required: R;
|
|
69
73
|
self: Self;
|
|
@@ -83,8 +87,7 @@ export interface ArchetypeMethods<N extends string | undefined, C, H, R, E, P> e
|
|
|
83
87
|
entry(entry: Selector<'files'>): ArchetypeBuilder<N, C, H, R, {}, P>;
|
|
84
88
|
provides(provides: (s: C) => Record<string, Reference>): ArchetypeBuilder<N, C, H, R, E, P>;
|
|
85
89
|
description(description: string): ArchetypeBuilder<N, C, H, R, E, P>;
|
|
86
|
-
|
|
87
|
-
tests(locator: Selector, layer?: Archetype<undefined, any, C, any>): ArchetypeBuilder<N, C, With<H, 'tests', ModuleHandle>, R, E, P>;
|
|
90
|
+
testUsing(using: TestUsing<C, R>): ArchetypeBuilder<N, C, H, R, E, P>;
|
|
88
91
|
using<P2 = any>(using: Using<P2>): ArchetypeBuilder<N, C, H, R, E, P2>;
|
|
89
92
|
}
|
|
90
93
|
export interface Ruleset {
|
|
@@ -96,7 +99,6 @@ export interface Ruleset {
|
|
|
96
99
|
export interface WarpConfig {
|
|
97
100
|
root: Archetype<string, any, any, any>;
|
|
98
101
|
tsconfig?: string | readonly string[];
|
|
99
|
-
tests?: Selector<'files'>;
|
|
100
102
|
plugins?: Record<string, unknown>;
|
|
101
103
|
rulesets?: Record<string, Ruleset>;
|
|
102
104
|
}
|
|
@@ -113,7 +115,7 @@ export type RecordedRef = {
|
|
|
113
115
|
pattern: string;
|
|
114
116
|
};
|
|
115
117
|
export interface RecordedSelector {
|
|
116
|
-
kind: 'dir' | 'files';
|
|
118
|
+
kind: 'dir' | 'files' | 'mirror';
|
|
117
119
|
patterns: readonly unknown[];
|
|
118
120
|
}
|
|
119
121
|
export interface RecordedModule {
|
|
@@ -121,6 +123,7 @@ export interface RecordedModule {
|
|
|
121
123
|
selector: unknown;
|
|
122
124
|
archetype?: unknown;
|
|
123
125
|
extra: readonly unknown[];
|
|
126
|
+
test?: true;
|
|
124
127
|
}
|
|
125
128
|
export interface RecordedDefinition {
|
|
126
129
|
name: unknown;
|
|
@@ -131,11 +134,7 @@ export interface RecordedDefinition {
|
|
|
131
134
|
entry?: unknown;
|
|
132
135
|
provides?: unknown;
|
|
133
136
|
description?: unknown;
|
|
134
|
-
|
|
135
|
-
locator?: unknown;
|
|
136
|
-
layer?: unknown;
|
|
137
|
-
extra: readonly unknown[];
|
|
138
|
-
};
|
|
137
|
+
testUsing?: unknown;
|
|
139
138
|
}
|
|
140
139
|
export interface RecordedArchetype {
|
|
141
140
|
definition: RecordedDefinition;
|
|
@@ -177,6 +176,7 @@ export declare function dir(): Shape;
|
|
|
177
176
|
export declare function dir(...paths: [string, ...string[]]): Selector<'dir'>;
|
|
178
177
|
export declare function files(): Shape;
|
|
179
178
|
export declare function files(...patterns: [string, ...string[]]): Selector<'files'>;
|
|
179
|
+
export declare const mirror: (from: string, to: string) => Selector<'mirror'>;
|
|
180
180
|
export declare const pkg: (pattern: string) => Package;
|
|
181
181
|
export declare const defineConfig: <const C extends WarpConfig>(config: C) => C;
|
|
182
182
|
export declare const ruleset: () => Ruleset;
|
|
@@ -16,28 +16,24 @@ export const self = Object.freeze(record('self', true));
|
|
|
16
16
|
const modules = (entries) => ({
|
|
17
17
|
...record('modules', entries),
|
|
18
18
|
module: (name, selector, archetype, ...extra) => modules([...entries, { name, selector, archetype, extra }]),
|
|
19
|
+
testModule: (name, selector, archetype, ...extra) => modules([...entries, { name, selector, archetype, extra, test: true }]),
|
|
19
20
|
});
|
|
20
21
|
export const inlineName = (holder, module) => `${holder}.${module}`;
|
|
21
|
-
const handles = (holder, entries
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
: {};
|
|
32
|
-
return [entry.name, Object.freeze({ ...handle, ...nested })];
|
|
33
|
-
})),
|
|
34
|
-
...(tests === undefined ? {} : { tests: Object.freeze(record('handle', { archetype: holder, module: 'tests' })) }),
|
|
35
|
-
});
|
|
22
|
+
const handles = (holder, entries) => Object.fromEntries((Array.isArray(entries) ? entries : [])
|
|
23
|
+
.filter((entry) => typeof entry.name === 'string')
|
|
24
|
+
.map((entry) => {
|
|
25
|
+
const handle = record('handle', { archetype: holder, module: entry.name });
|
|
26
|
+
const anonymous = recordedAs(entry.archetype, 'archetype')?.definition;
|
|
27
|
+
const nested = anonymous && anonymous.name === undefined && !entry.test
|
|
28
|
+
? { modules: handles(inlineName(String(holder), entry.name), anonymous.modules) }
|
|
29
|
+
: {};
|
|
30
|
+
return [entry.name, Object.freeze({ ...handle, ...nested })];
|
|
31
|
+
}));
|
|
36
32
|
const builder = (state) => {
|
|
37
33
|
const { definition } = state;
|
|
38
34
|
const define = (field) => (value) => builder({ ...state, definition: { ...definition, [field]: value } });
|
|
39
35
|
return {
|
|
40
|
-
modules: handles(definition.name, definition.modules
|
|
36
|
+
modules: handles(definition.name, definition.modules),
|
|
41
37
|
name: definition.name,
|
|
42
38
|
...record('archetype', state),
|
|
43
39
|
identify: define('identify'),
|
|
@@ -47,11 +43,7 @@ const builder = (state) => {
|
|
|
47
43
|
entry: define('entry'),
|
|
48
44
|
provides: define('provides'),
|
|
49
45
|
description: define('description'),
|
|
50
|
-
|
|
51
|
-
const located = recordedAs(first, 'selector') !== undefined;
|
|
52
|
-
const [layer, ...extra] = located ? rest : [first, ...rest];
|
|
53
|
-
return define('tests')({ ...(located ? { locator: first } : {}), layer, extra });
|
|
54
|
-
},
|
|
46
|
+
testUsing: define('testUsing'),
|
|
55
47
|
using: (using) => builder({ ...state, using }),
|
|
56
48
|
};
|
|
57
49
|
};
|
|
@@ -70,6 +62,7 @@ export function dir(...paths) {
|
|
|
70
62
|
export function files(...patterns) {
|
|
71
63
|
return selector('files', patterns);
|
|
72
64
|
}
|
|
65
|
+
export const mirror = (from, to) => Object.freeze(record('selector', { kind: 'mirror', patterns: [from, to] }));
|
|
73
66
|
export const pkg = (pattern) => ref({ kind: 'package', pattern });
|
|
74
67
|
export const defineConfig = (config) => config;
|
|
75
68
|
const rulesetOf = (state) => ({
|
|
@@ -24,17 +24,14 @@ export type ExposesData = {
|
|
|
24
24
|
kind: 'surfaces';
|
|
25
25
|
surfaces: Record<string, RefData[]>;
|
|
26
26
|
};
|
|
27
|
-
export
|
|
27
|
+
export type LocatorData = {
|
|
28
28
|
kind: 'dir' | 'files';
|
|
29
29
|
patterns: string[];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
exposes?: ExposesData;
|
|
36
|
-
rules?: RuleSettingsData;
|
|
37
|
-
}
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'mirror';
|
|
32
|
+
from: string;
|
|
33
|
+
to: string;
|
|
34
|
+
};
|
|
38
35
|
export interface FilesModuleData {
|
|
39
36
|
kind: 'files';
|
|
40
37
|
name: string;
|
|
@@ -43,7 +40,6 @@ export interface FilesModuleData {
|
|
|
43
40
|
exposes?: Exclude<ExposesData, {
|
|
44
41
|
kind: 'surfaces';
|
|
45
42
|
}>;
|
|
46
|
-
tests?: TestLayerData;
|
|
47
43
|
rules?: RuleSettingsData;
|
|
48
44
|
description?: string;
|
|
49
45
|
}
|
|
@@ -56,7 +52,18 @@ export interface DirModuleData {
|
|
|
56
52
|
rules?: RuleSettingsData;
|
|
57
53
|
description?: string;
|
|
58
54
|
}
|
|
59
|
-
export
|
|
55
|
+
export interface TestModuleData {
|
|
56
|
+
kind: 'test';
|
|
57
|
+
name: string;
|
|
58
|
+
locator: LocatorData;
|
|
59
|
+
using: RefData[];
|
|
60
|
+
exposes?: Exclude<ExposesData, {
|
|
61
|
+
kind: 'surfaces';
|
|
62
|
+
}>;
|
|
63
|
+
rules?: RuleSettingsData;
|
|
64
|
+
description?: string;
|
|
65
|
+
}
|
|
66
|
+
export type ModuleData = FilesModuleData | DirModuleData | TestModuleData;
|
|
60
67
|
export type RequirementData = {
|
|
61
68
|
kind: 'archetype';
|
|
62
69
|
archetype: string;
|
|
@@ -79,7 +86,7 @@ export interface ArchetypeData {
|
|
|
79
86
|
modules: ModuleData[];
|
|
80
87
|
exposes?: ExposesData;
|
|
81
88
|
provides: Record<string, ModuleRefData>;
|
|
82
|
-
|
|
89
|
+
testUsing?: RefData[];
|
|
83
90
|
rules?: RuleSettingsData;
|
|
84
91
|
}
|
|
85
92
|
export interface ConfigData {
|
|
@@ -87,6 +94,5 @@ export interface ConfigData {
|
|
|
87
94
|
root: string;
|
|
88
95
|
archetypes: Record<string, ArchetypeData>;
|
|
89
96
|
tsconfig: string[];
|
|
90
|
-
tests?: string[];
|
|
91
97
|
rules?: RuleSettingsData;
|
|
92
98
|
}
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import { type RecordedDefinition } from './builder.ts';
|
|
2
|
-
import type { ArchetypeData,
|
|
2
|
+
import type { ArchetypeData, ModuleData } from './data.ts';
|
|
3
3
|
import { type Fail } from './shared.ts';
|
|
4
|
-
export interface DraftTests {
|
|
5
|
-
locator?: LocatorData;
|
|
6
|
-
modules: DraftModule[];
|
|
7
|
-
using: unknown[];
|
|
8
|
-
exposes?: DraftExposes;
|
|
9
|
-
}
|
|
10
4
|
export interface DraftModule {
|
|
11
5
|
data: ModuleData;
|
|
12
6
|
using: unknown[];
|
|
13
|
-
tests?: DraftTests;
|
|
14
7
|
}
|
|
15
8
|
export type DraftExposes = {
|
|
16
9
|
kind: 'all';
|
|
@@ -27,7 +20,7 @@ export interface Draft {
|
|
|
27
20
|
modules: DraftModule[];
|
|
28
21
|
exposes?: DraftExposes;
|
|
29
22
|
provides: Record<string, unknown>;
|
|
30
|
-
|
|
23
|
+
testUsing: unknown[];
|
|
31
24
|
}
|
|
32
25
|
export interface Collected extends RecordedDefinition {
|
|
33
26
|
inline?: true;
|
|
@@ -21,7 +21,7 @@ const named = (value) => {
|
|
|
21
21
|
return definition && definition.name !== undefined ? [definition] : [];
|
|
22
22
|
};
|
|
23
23
|
const reached = (definition) => [
|
|
24
|
-
...entriesOf(definition.modules).flatMap((entry) => named(entry.archetype)),
|
|
24
|
+
...entriesOf(definition.modules).flatMap((entry) => (entry.test ? [] : named(entry.archetype))),
|
|
25
25
|
...Object.values(isRecord(definition.requires) ? definition.requires : {}).flatMap(named),
|
|
26
26
|
...inlineArchetypes(definition),
|
|
27
27
|
];
|
|
@@ -43,7 +43,8 @@ const inlineArchetypes = (holder) => isName(holder.name)
|
|
|
43
43
|
]
|
|
44
44
|
: [])
|
|
45
45
|
: [];
|
|
46
|
-
const isInline = (entry) =>
|
|
46
|
+
const isInline = (entry) => !entry.test &&
|
|
47
|
+
(entry.archetype === undefined || anonymousOf(entry) !== undefined) &&
|
|
47
48
|
recordedAs(entry.selector, 'selector')?.kind === 'dir';
|
|
48
49
|
const entriesOf = (modules) => (Array.isArray(modules) ? modules : []);
|
|
49
50
|
const callback = (value) => (typeof value === 'function' ? value(moduleRefs()) : undefined);
|
|
@@ -56,7 +57,7 @@ export const draft = (name, state, fail) => {
|
|
|
56
57
|
const provides = state.provides === undefined ? {} : callback(state.provides);
|
|
57
58
|
if (!isRecord(provides))
|
|
58
59
|
fail(`${name}.provides: expected a callback returning modules by name, (m) => ({ strings: m.strings })`);
|
|
59
|
-
const
|
|
60
|
+
const testUsing = usingOf(`${name}.testUsing`, state.testUsing, fail);
|
|
60
61
|
return {
|
|
61
62
|
data: {
|
|
62
63
|
name,
|
|
@@ -70,52 +71,9 @@ export const draft = (name, state, fail) => {
|
|
|
70
71
|
modules,
|
|
71
72
|
...(exposes ? { exposes } : {}),
|
|
72
73
|
provides: isRecord(provides) ? provides : {},
|
|
73
|
-
|
|
74
|
+
testUsing,
|
|
74
75
|
};
|
|
75
76
|
};
|
|
76
|
-
const testsOf = (where, value, kind, fail) => {
|
|
77
|
-
if (value === undefined)
|
|
78
|
-
return undefined;
|
|
79
|
-
if (value.extra.length > 0)
|
|
80
|
-
fail(`${where}.tests: takes a locator and an archetype, .tests(dir('e2e'), using([...]))`);
|
|
81
|
-
const locator = value.locator === undefined ? undefined : selectorOf(`${where}.tests`, value.locator, fail);
|
|
82
|
-
const recorded = value.layer === undefined ? undefined : recordedAs(value.layer, 'archetype');
|
|
83
|
-
if (value.layer !== undefined && recorded?.definition.name !== undefined)
|
|
84
|
-
fail(`${where}.tests: a test layer is an archetype of its own: contains(...), using(...) or exposes(...)`);
|
|
85
|
-
const layer = recorded?.definition.name === undefined ? recorded?.definition : undefined;
|
|
86
|
-
if (layer)
|
|
87
|
-
checkLayer(`${where}.tests`, layer, fail);
|
|
88
|
-
const modules = layer
|
|
89
|
-
? draftModules(`${where}.tests`, layer.modules, fail).map((module) => testModule(where, module, fail))
|
|
90
|
-
: [];
|
|
91
|
-
if (kind === 'files' && modules.length > 0)
|
|
92
|
-
fail(`${where}.tests: a files module's tests hold no modules; give them to its folder's archetype`);
|
|
93
|
-
if (kind === 'files' && !locator)
|
|
94
|
-
fail(`${where}.tests: a files module names where its tests are, .tests(files('*.logic.test.ts'))`);
|
|
95
|
-
const exposes = exposesOf(`${where}.tests.exposes`, layer?.exposes, true, fail);
|
|
96
|
-
return {
|
|
97
|
-
...(locator ? { locator } : {}),
|
|
98
|
-
modules,
|
|
99
|
-
using: usingOf(`${where}.tests`, recorded?.using, fail),
|
|
100
|
-
...(exposes ? { exposes } : {}),
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
const checkLayer = (where, layer, fail) => {
|
|
104
|
-
for (const field of ['identify', 'provides', 'tests', 'entry'])
|
|
105
|
-
if (layer[field] !== undefined)
|
|
106
|
-
fail(`${where}.${field}: a test layer holds test modules, its using and what it exposes`);
|
|
107
|
-
if (isRecord(layer.requires) && Object.keys(layer.requires).length > 0)
|
|
108
|
-
fail(`${where}.requires: a test layer sees what its holder requires`);
|
|
109
|
-
};
|
|
110
|
-
const testModule = (where, module, fail) => {
|
|
111
|
-
const at = `${where}.tests.${module.data.name}`;
|
|
112
|
-
if (module.data.kind !== 'files')
|
|
113
|
-
fail(`${at}: a test module is a files module, files('*.dsl.ts')`);
|
|
114
|
-
if (module.using.length > 0)
|
|
115
|
-
fail(`${at}: a test module sees what its layer sees; give the layer .using()`);
|
|
116
|
-
const data = module.data;
|
|
117
|
-
return { ...module, data: { ...data, exposes: data.exposes ?? { kind: 'all' } } };
|
|
118
|
-
};
|
|
119
77
|
const surfaceOf = (name, state, fail) => {
|
|
120
78
|
if (state.entry === undefined)
|
|
121
79
|
return exposesOf(`${name}.exposes`, state.exposes, true, fail);
|
|
@@ -167,8 +125,8 @@ const draftModule = (archetype, entry, fail) => {
|
|
|
167
125
|
if (!isName(name) || name.includes('.'))
|
|
168
126
|
fail(`${archetype}: a module's name is a non-empty string without dots, not ${JSON.stringify(name)}`);
|
|
169
127
|
const where = `${archetype}.${String(name)}`;
|
|
170
|
-
if (
|
|
171
|
-
|
|
128
|
+
if (entry.test)
|
|
129
|
+
return draftTestModule(archetype, entry, where, fail);
|
|
172
130
|
const { kind, patterns } = selectorOf(where, entry.selector, fail);
|
|
173
131
|
if (entry.extra.length > 0)
|
|
174
132
|
fail(`${where}: .module() takes a name, a selector and an archetype`);
|
|
@@ -185,13 +143,41 @@ const draftModule = (archetype, entry, fail) => {
|
|
|
185
143
|
if (named !== undefined)
|
|
186
144
|
fail(`${where}: an archetype makes a folder module; use dir(...), not files(...)`);
|
|
187
145
|
const exposes = exposesOf(`${where}.exposes`, anonymous?.exposes, false, fail);
|
|
188
|
-
|
|
146
|
+
return { data: { kind, ...common, patterns, ...(exposes ? { exposes } : {}) }, using };
|
|
147
|
+
};
|
|
148
|
+
const draftTestModule = (holder, entry, where, fail) => {
|
|
149
|
+
const locator = locatorOf(where, entry.selector, fail);
|
|
150
|
+
if (entry.extra.length > 0)
|
|
151
|
+
fail(`${where}: .testModule() takes a name, a selector and an archetype`);
|
|
152
|
+
const { named, anonymous, using } = archetypeOf(where, holder, entry.archetype, fail);
|
|
153
|
+
if (named !== undefined)
|
|
154
|
+
fail(`${where}: a test module's archetype is its own: using(...), exposes(...) or description(...)`);
|
|
155
|
+
if (anonymous)
|
|
156
|
+
checkAnonymous(where, 'test', anonymous, fail);
|
|
157
|
+
const exposes = exposesOf(`${where}.exposes`, anonymous?.exposes, false, fail);
|
|
158
|
+
const description = anonymous?.description;
|
|
189
159
|
return {
|
|
190
|
-
data: {
|
|
160
|
+
data: {
|
|
161
|
+
kind: 'test',
|
|
162
|
+
name: entry.name,
|
|
163
|
+
locator,
|
|
164
|
+
using: [],
|
|
165
|
+
...(exposes ? { exposes } : {}),
|
|
166
|
+
...(description === undefined ? {} : { description }),
|
|
167
|
+
},
|
|
191
168
|
using,
|
|
192
|
-
...(tests ? { tests } : {}),
|
|
193
169
|
};
|
|
194
170
|
};
|
|
171
|
+
const locatorOf = (where, value, fail) => {
|
|
172
|
+
const selector = recordedAs(value, 'selector');
|
|
173
|
+
if (selector?.kind !== 'mirror')
|
|
174
|
+
return selectorOf(where, value, fail, 'test');
|
|
175
|
+
const [from, to] = selector.patterns;
|
|
176
|
+
if (!isMirrorPath(from) || !isMirrorPath(to))
|
|
177
|
+
fail(`${where}: mirror() takes two folder paths without placeholders, mirror('src', 'test')`);
|
|
178
|
+
return { kind: 'mirror', from: String(from), to: String(to) };
|
|
179
|
+
};
|
|
180
|
+
const isMirrorPath = (path) => isName(path) && !path.includes('{') && isDirPath(path);
|
|
195
181
|
const archetypeOf = (where, holder, value, fail) => {
|
|
196
182
|
if (value === undefined)
|
|
197
183
|
return { using: [] };
|
|
@@ -202,7 +188,7 @@ const archetypeOf = (where, holder, value, fail) => {
|
|
|
202
188
|
fail(`${where}: expected an archetype, such as component, using(...) or exposes(all())`);
|
|
203
189
|
return { using: [] };
|
|
204
190
|
}
|
|
205
|
-
const using = usingOf(where
|
|
191
|
+
const using = usingOf(`${where}.using`, recorded.using, fail);
|
|
206
192
|
const { definition } = recorded;
|
|
207
193
|
return definition.name === undefined ? { anonymous: definition, using } : { named: definition.name, using };
|
|
208
194
|
};
|
|
@@ -216,15 +202,18 @@ const checkAnonymous = (where, kind, definition, fail) => {
|
|
|
216
202
|
const hasModules = Array.isArray(definition.modules) && definition.modules.length > 0;
|
|
217
203
|
const folderOnly = [
|
|
218
204
|
...(hasModules ? ['contains'] : []),
|
|
219
|
-
...['identify', 'provides', 'entry'].filter((field) => definition[field] !== undefined),
|
|
205
|
+
...['identify', 'provides', 'entry', 'testUsing'].filter((field) => definition[field] !== undefined),
|
|
220
206
|
];
|
|
221
207
|
for (const field of folderOnly)
|
|
222
|
-
fail(
|
|
208
|
+
fail(kind === 'test'
|
|
209
|
+
? `${where}.${field}: a test module holds test code; its archetype takes using(...), exposes(...) and description(...)`
|
|
210
|
+
: `${where}.${field}: a files module has no modules; use dir(...) for ${field}`);
|
|
223
211
|
};
|
|
224
|
-
const selectorOf = (where, value, fail) => {
|
|
212
|
+
const selectorOf = (where, value, fail, of = 'module') => {
|
|
225
213
|
const selector = recordedAs(value, 'selector');
|
|
226
|
-
if (!selector) {
|
|
227
|
-
|
|
214
|
+
if (!selector || selector.kind === 'mirror') {
|
|
215
|
+
const shapes = of === 'test' ? "files('*.test.ts'), dir('e2e') or mirror('src', 'test')" : "files('*.ts') or dir('src/ui')";
|
|
216
|
+
fail(`${where}: expected a selector, ${shapes}`);
|
|
228
217
|
return { kind: 'files', patterns: [] };
|
|
229
218
|
}
|
|
230
219
|
const patterns = selector.patterns;
|
|
@@ -238,7 +227,7 @@ const usingOf = (where, value, fail) => {
|
|
|
238
227
|
const using = typeof value === 'function' ? value(moduleRefs(), { required: requiredRefs() }) : (value ?? []);
|
|
239
228
|
if (Array.isArray(using))
|
|
240
229
|
return using;
|
|
241
|
-
fail(`${where}
|
|
230
|
+
fail(`${where}: expected a list of references, or a callback returning one`);
|
|
242
231
|
return [];
|
|
243
232
|
};
|
|
244
233
|
const checkDirPaths = (where, paths, fail) => {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ConfigData, RefData } from './data.ts';
|
|
2
|
+
import type { Model, ModuleView } from './resolve.ts';
|
|
3
|
+
export interface Site {
|
|
4
|
+
label: string;
|
|
5
|
+
holder: ModuleView;
|
|
6
|
+
add(config: ConfigData, ref: RefData): ConfigData;
|
|
7
|
+
visible: ReadonlySet<string>;
|
|
8
|
+
self?: string;
|
|
9
|
+
tests: boolean;
|
|
10
|
+
}
|
|
11
|
+
export type Fix = {
|
|
12
|
+
kind: 'using';
|
|
13
|
+
site: string;
|
|
14
|
+
ref: RefData;
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'declare';
|
|
17
|
+
archetype: string;
|
|
18
|
+
module: string;
|
|
19
|
+
above: string;
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'require';
|
|
22
|
+
archetype: string;
|
|
23
|
+
name: string;
|
|
24
|
+
provider: string;
|
|
25
|
+
module: string;
|
|
26
|
+
} | {
|
|
27
|
+
kind: 'expose';
|
|
28
|
+
archetype: string;
|
|
29
|
+
ref: RefData;
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'expose-file';
|
|
32
|
+
archetype: string;
|
|
33
|
+
pattern: string;
|
|
34
|
+
};
|
|
35
|
+
export declare const namedArchetype: (config: ConfigData, name: string) => string;
|
|
36
|
+
export declare const sitesOf: (config: ConfigData, model: Model, file: string) => Site[];
|
|
37
|
+
export declare const fixesFor: (config: ConfigData, model: Model, from: string, to: string) => Fix[] | undefined;
|