@yearofthedan/warp 0.2.0 → 0.4.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 +24 -25
- 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.d.ts +3 -1
- package/dist/app/check.js +5 -3
- package/dist/app/checkModel.js +1 -1
- package/dist/app/configLines.d.ts +5 -0
- package/dist/app/configLines.js +24 -0
- package/dist/app/load.d.ts +2 -2
- package/dist/app/load.js +31 -43
- package/dist/builtins/advice.d.ts +8 -0
- package/dist/builtins/advice.js +42 -0
- package/dist/builtins/dependency-direction/dependencyDirection.js +33 -16
- package/dist/builtins/index.js +2 -0
- package/dist/builtins/module-externals/moduleExternals.js +11 -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 +19 -11
- package/dist/builtins/unused-declaration/grants.js +22 -15
- package/dist/builtins/unused-declaration/surfaces.js +24 -22
- package/dist/cli.js +14 -11
- package/dist/config/loadConfig.d.ts +7 -1
- package/dist/config/loadConfig.js +83 -12
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/model/archetype/data.d.ts +25 -29
- package/dist/model/archetype/data.js +1 -1
- package/dist/model/archetype/fixes.d.ts +35 -0
- package/dist/model/archetype/fixes.js +265 -0
- package/dist/model/archetype/language.d.ts +16 -0
- package/dist/model/archetype/language.js +419 -0
- package/dist/model/archetype/reach.d.ts +8 -3
- package/dist/model/archetype/reach.js +142 -122
- package/dist/model/archetype/references.d.ts +11 -5
- package/dist/model/archetype/references.js +58 -132
- package/dist/model/archetype/requirements.d.ts +3 -3
- package/dist/model/archetype/requirements.js +65 -61
- package/dist/model/archetype/resolve.d.ts +3 -3
- package/dist/model/archetype/resolve.js +64 -77
- package/dist/model/archetype/rulesets.d.ts +2 -1
- package/dist/model/archetype/rulesets.js +72 -49
- package/dist/model/archetype/settings.js +4 -19
- package/dist/model/facts.d.ts +6 -0
- package/dist/reporters/model.js +9 -9
- package/dist/rules/registry.js +1 -1
- package/package.json +3 -2
- package/dist/model/archetype/builder.d.ts +0 -183
- package/dist/model/archetype/builder.js +0 -85
- package/dist/model/archetype/draft.d.ts +0 -37
- package/dist/model/archetype/draft.js +0 -275
|
@@ -1,22 +1,30 @@
|
|
|
1
|
+
import { isTestData } from '../../model/archetype/data.js';
|
|
1
2
|
import { childrenNamed, instancesOf, named, unused } from './declarations.js';
|
|
2
3
|
export const emptyModules = (context) => Object.values(context.config.archetypes).flatMap((archetype) => {
|
|
3
4
|
const instances = instancesOf(context, archetype.name);
|
|
4
5
|
const on = instances.some((instance) => context.atModule(instance).on);
|
|
5
|
-
const declared =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
layer: 'test',
|
|
11
|
-
})),
|
|
12
|
-
];
|
|
6
|
+
const declared = archetype.modules.map((module) => ({
|
|
7
|
+
module,
|
|
8
|
+
name: module.name,
|
|
9
|
+
layer: isTestData(module) ? 'test' : 'production',
|
|
10
|
+
}));
|
|
13
11
|
return declared
|
|
14
12
|
.filter(({ name }) => on && childrenNamed(context, instances, name).length === 0)
|
|
15
13
|
.map(({ module, name, layer }) => empty(context, `${archetype.name}.${name}`, module, layer, instances));
|
|
16
14
|
});
|
|
17
15
|
const empty = (context, declaredIn, module, layer, instances) => {
|
|
18
|
-
const selector =
|
|
16
|
+
const selector = selectorText(module);
|
|
19
17
|
const where = instances.map(named).join(', ');
|
|
20
|
-
return unused(context.config, declaredIn, `${declaredIn} matches no files: ${selector} finds nothing in ${where}. Fix the
|
|
18
|
+
return unused(context.config, declaredIn, `${declaredIn} matches no files: ${selector} finds nothing in ${where}. Fix the pattern, or remove the module.`, { kind: 'empty', declaredIn, layer, selector });
|
|
19
|
+
};
|
|
20
|
+
const shown = (patterns) => {
|
|
21
|
+
const items = patterns
|
|
22
|
+
.map((pattern) => pattern.replaceAll('{name}', '*'))
|
|
23
|
+
.map((pattern) => (/^[\w./-]+$/.test(pattern) ? pattern : `'${pattern}'`));
|
|
24
|
+
return items.length === 1 ? items[0] : `[${items.join(', ')}]`;
|
|
25
|
+
};
|
|
26
|
+
const selectorText = (module) => {
|
|
27
|
+
if (module.kind === 'dir')
|
|
28
|
+
return `dir: ${shown(module.paths)}`;
|
|
29
|
+
return `files: ${shown(module.patterns)}`;
|
|
21
30
|
};
|
|
22
|
-
const quoted = (patterns) => patterns.map((pattern) => `'${pattern}'`).join(', ');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isTestData } from '../../model/archetype/data.js';
|
|
1
2
|
import { show } from '../../model/archetype/references.js';
|
|
2
3
|
import { listsPackage } from '../packages.js';
|
|
3
4
|
import { childrenNamed, instancesOf, named, unused } from './declarations.js';
|
|
@@ -5,41 +6,47 @@ export const unusedGrants = (context) => {
|
|
|
5
6
|
const used = usedRefs(context);
|
|
6
7
|
return declared(context)
|
|
7
8
|
.filter(({ ref, holders }) => !used.has(ref) && holders.some((holder) => context.atModule(holder).on))
|
|
8
|
-
.map(({ ref, declaredIn, layer, holders }) => {
|
|
9
|
+
.map(({ ref, declaredIn, layer, holders, kit }) => {
|
|
9
10
|
const using = show(ref);
|
|
10
11
|
const modules = holders.map((holder) => holder.id);
|
|
11
12
|
const names = holders.map(named).join(', ');
|
|
12
|
-
const files =
|
|
13
|
-
return unused(context.config, `${declaredIn}->${using}`, `${declaredIn}
|
|
13
|
+
const files = kit ? `the tests of ${names}` : names;
|
|
14
|
+
return unused(context.config, `${declaredIn}->${using}`, `${declaredIn} names ${using}, but nothing in ${files} imports through it. Remove it.`, { kind: 'grant', declaredIn, layer, using, modules });
|
|
14
15
|
});
|
|
15
16
|
};
|
|
16
17
|
const declared = (context) => Object.values(context.config.archetypes).flatMap((archetype) => {
|
|
17
18
|
const instances = instancesOf(context, archetype.name);
|
|
18
19
|
const modules = archetype.modules.flatMap((module) => {
|
|
19
20
|
const holders = childrenNamed(context, instances, module.name);
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
const layer = isTestData(module) ? 'test' : 'production';
|
|
22
|
+
return module.using.map((ref) => ({
|
|
23
|
+
ref,
|
|
24
|
+
declaredIn: `${archetype.name}.${module.name}.dependencies`,
|
|
25
|
+
layer,
|
|
26
|
+
holders,
|
|
27
|
+
}));
|
|
26
28
|
});
|
|
27
|
-
const
|
|
29
|
+
const kit = (archetype.testUsing ?? []).map((ref) => ({
|
|
28
30
|
ref,
|
|
29
|
-
declaredIn: `${archetype.name}.
|
|
31
|
+
declaredIn: `${archetype.name}.test.provides`,
|
|
30
32
|
layer: 'test',
|
|
31
33
|
holders: instances,
|
|
34
|
+
kit: true,
|
|
32
35
|
}));
|
|
33
|
-
return [...modules, ...
|
|
36
|
+
return [...modules, ...kit];
|
|
34
37
|
});
|
|
35
38
|
const usedRefs = ({ project, verdicts }) => {
|
|
36
39
|
const used = new Set();
|
|
37
40
|
for (const file of project.files) {
|
|
38
41
|
const reach = verdicts.reach(file.path) ?? [];
|
|
39
42
|
const targets = file.imports.map((edge) => edge.via ?? edge.to);
|
|
40
|
-
for (const grant of reach)
|
|
41
|
-
if (grant.declared
|
|
42
|
-
|
|
43
|
+
for (const grant of reach) {
|
|
44
|
+
if (!grant.declared || !permits(grant, targets, file.externals))
|
|
45
|
+
continue;
|
|
46
|
+
used.add(grant.declared);
|
|
47
|
+
for (const bound of grant.via ?? [])
|
|
48
|
+
used.add(bound);
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
51
|
return used;
|
|
45
52
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isTestData } from '../../model/archetype/data.js';
|
|
1
2
|
import { childrenNamed, instancesOf, named, unused, within } from './declarations.js';
|
|
2
3
|
export const unusedSurfaces = (context) => {
|
|
3
4
|
const edges = context.project.files.flatMap((file) => file.imports.map((edge) => ({ from: file.path, to: edge.via ?? edge.to })));
|
|
@@ -13,18 +14,31 @@ export const unusedSurfaces = (context) => {
|
|
|
13
14
|
const reached = (context, edges, holder, files) => edges.some(({ from, to }) => files.has(to) && !within(context.model.moduleOf(from), holder));
|
|
14
15
|
const declared = (context) => Object.values(context.config.archetypes).flatMap((archetype) => {
|
|
15
16
|
const instances = instancesOf(context, archetype.name).filter((instance) => instance !== context.model.root);
|
|
16
|
-
const
|
|
17
|
+
const judged = isEntry(archetype.exposes)
|
|
18
|
+
? instances.filter((instance) => !isTopLevel(context, instance))
|
|
19
|
+
: instances;
|
|
20
|
+
const own = archetype.exposes
|
|
21
|
+
? surfaces(context, archetype.name, archetype.exposes, judged, archetype.test ? 'test' : 'production')
|
|
22
|
+
: [];
|
|
23
|
+
const tests = Object.entries(archetype.testExposes ?? {}).map(([name, refs]) => ({
|
|
24
|
+
declaredIn: archetype.name,
|
|
25
|
+
layer: 'test',
|
|
26
|
+
exposes: `test.exposes ${name}`,
|
|
27
|
+
holders: instances,
|
|
28
|
+
files: (holder) => new Set(refs.flatMap((ref) => [...context.verdicts.files(holder, ref, 'test')])),
|
|
29
|
+
}));
|
|
17
30
|
const modules = archetype.modules.flatMap((module) => {
|
|
18
31
|
const holders = childrenNamed(context, instances, module.name);
|
|
19
|
-
|
|
20
|
-
|
|
32
|
+
const layer = isTestData(module) ? 'test' : 'production';
|
|
33
|
+
return module.kind !== 'dir' && module.exposes
|
|
34
|
+
? surfaces(context, `${archetype.name}.${module.name}`, module.exposes, holders, layer)
|
|
21
35
|
: [];
|
|
22
36
|
});
|
|
23
|
-
|
|
24
|
-
return [...own, ...modules, ...tests];
|
|
37
|
+
return [...own, ...tests, ...modules];
|
|
25
38
|
});
|
|
26
|
-
const
|
|
27
|
-
|
|
39
|
+
const isEntry = (exposes) => exposes?.kind === 'files' && exposes.entry === true;
|
|
40
|
+
const isTopLevel = (context, module) => module.parent === context.model.root;
|
|
41
|
+
const surfaces = (context, declaredIn, exposes, holders, layer) => {
|
|
28
42
|
if (exposes.kind !== 'surfaces')
|
|
29
43
|
return [
|
|
30
44
|
{ declaredIn, layer, exposes: whole(exposes), holders, files: (holder) => context.verdicts.surface(holder) },
|
|
@@ -37,21 +51,9 @@ const production = (context, declaredIn, exposes, holders) => {
|
|
|
37
51
|
files: (holder) => context.verdicts.surface(holder, name),
|
|
38
52
|
}));
|
|
39
53
|
};
|
|
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
54
|
const whole = (exposes) => {
|
|
53
55
|
if (exposes.kind === 'all')
|
|
54
|
-
return 'exposes
|
|
55
|
-
const
|
|
56
|
-
return exposes.entry ?
|
|
56
|
+
return 'exposes: all';
|
|
57
|
+
const patterns = exposes.patterns.join(', ');
|
|
58
|
+
return exposes.entry ? `entry: ${patterns}` : `exposes: { files: [${patterns}] }`;
|
|
57
59
|
};
|
package/dist/cli.js
CHANGED
|
@@ -5,6 +5,7 @@ import { parseArgs } from 'node:util';
|
|
|
5
5
|
import { diskFolders } from './analysis/folders.js';
|
|
6
6
|
import { typescriptAnalyzer } from './analysis/typescript.js';
|
|
7
7
|
import { modelProject, projectCheck } from './app/check.js';
|
|
8
|
+
import { placeProblems } from './app/configLines.js';
|
|
8
9
|
import { factsStore } from './app/facts.js';
|
|
9
10
|
import { diffProject, parseRange } from './app/diff.js';
|
|
10
11
|
import { builtinRegistry, unclassifiedDocs } from './builtins/index.js';
|
|
@@ -29,7 +30,7 @@ diff reports findings that are new or worse at <head> than at <base>. Without
|
|
|
29
30
|
With --since-last-run, compares the working tree with the last such run, or with <base> if there is none.
|
|
30
31
|
model prints the modules the config finds, and which module each file is in.
|
|
31
32
|
|
|
32
|
-
--config path to the config file (default:
|
|
33
|
+
--config path to the config file (default: warp.yaml)
|
|
33
34
|
--ruleset one of the config's rulesets (default: the one named default, if any)
|
|
34
35
|
--reporter ${[...reporters.keys()].join(', ')} (default: text)
|
|
35
36
|
--since-last-run with diff, compare with the last diff run that had this flag
|
|
@@ -81,18 +82,20 @@ const help = (code) => {
|
|
|
81
82
|
const resolveConfig = async (options) => {
|
|
82
83
|
const configFile = realpathSync(options.config ? resolve(options.config) : findConfig(process.cwd()));
|
|
83
84
|
const root = dirname(configFile);
|
|
84
|
-
const { raw, digest } = await loadConfig(configFile);
|
|
85
|
+
const { raw, plugins, lines, digest } = await loadConfig(configFile);
|
|
85
86
|
const builtins = [...builtinRegistry.values()];
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
ruleset: options.ruleset,
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
const file = basename(configFile);
|
|
88
|
+
try {
|
|
89
|
+
const { config, rules } = loadConfigData(raw, { builtins, plugins, ruleset: options.ruleset, file });
|
|
90
|
+
return { root, config, rules, lines, digest };
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (error instanceof ConfigError)
|
|
94
|
+
throw new ConfigError(placeProblems(lines, file, error.message));
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
94
97
|
};
|
|
95
|
-
const checkOf = ({ root, config, rules }) => projectCheck(adaptersAt(root), config, { rules, unclassifiedDocs });
|
|
98
|
+
const checkOf = ({ root, config, rules, lines }) => projectCheck(adaptersAt(root), config, { rules, unclassifiedDocs, lines });
|
|
96
99
|
const run = async (options, produce) => {
|
|
97
100
|
const reporter = reporters.get(options.reporter);
|
|
98
101
|
if (!reporter)
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const configName = "warp.yaml";
|
|
2
2
|
export declare const findConfig: (dir: string) => string;
|
|
3
3
|
export interface LoadedConfig {
|
|
4
4
|
raw: unknown;
|
|
5
|
+
plugins: Record<string, unknown>;
|
|
6
|
+
lines: ReadonlyMap<string, number>;
|
|
5
7
|
digest: string;
|
|
6
8
|
}
|
|
9
|
+
export declare const parseConfig: (text: string, file: string) => {
|
|
10
|
+
raw: unknown;
|
|
11
|
+
lines: Map<string, number>;
|
|
12
|
+
};
|
|
7
13
|
export declare const loadConfig: (file: string) => Promise<LoadedConfig>;
|
|
@@ -16,22 +16,80 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
16
16
|
return path;
|
|
17
17
|
};
|
|
18
18
|
import { createHash } from 'node:crypto';
|
|
19
|
-
import { existsSync } from 'node:fs';
|
|
20
|
-
import { registerHooks } from 'node:module';
|
|
21
|
-
import { join } from 'node:path';
|
|
19
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
20
|
+
import { createRequire, registerHooks } from 'node:module';
|
|
21
|
+
import { dirname, join, resolve } from 'node:path';
|
|
22
22
|
import { pathToFileURL } from 'node:url';
|
|
23
|
+
import { isAlias, isMap, isNode, isPair, isScalar, parseDocument, visit } from 'yaml';
|
|
23
24
|
import { ConfigError } from '../model/configError.js';
|
|
24
|
-
export const
|
|
25
|
+
export const configName = 'warp.yaml';
|
|
25
26
|
export const findConfig = (dir) => {
|
|
26
|
-
const found =
|
|
27
|
-
if (!found)
|
|
28
|
-
throw new ConfigError(`no config in ${dir}: add
|
|
27
|
+
const found = join(dir, configName);
|
|
28
|
+
if (!existsSync(found))
|
|
29
|
+
throw new ConfigError(`no config in ${dir}: add a ${configName}`);
|
|
29
30
|
return found;
|
|
30
31
|
};
|
|
32
|
+
export const parseConfig = (text, file) => {
|
|
33
|
+
const doc = parseDocument(text, { version: '1.2', merge: false, uniqueKeys: true });
|
|
34
|
+
const lineOf = (offset) => text.slice(0, offset).split('\n').length;
|
|
35
|
+
const problems = [
|
|
36
|
+
...doc.errors.map((error) => `${file}:${lineOf(error.pos[0])}: ${firstLine(error.message)}`),
|
|
37
|
+
...anchors(doc).map((offset) => `${file}:${lineOf(offset)}: anchors and aliases are not part of warp.yaml; write it out`),
|
|
38
|
+
];
|
|
39
|
+
if (problems.length > 0)
|
|
40
|
+
throw new ConfigError(problems.join('\n'));
|
|
41
|
+
const lines = new Map();
|
|
42
|
+
const walk = (node, at) => {
|
|
43
|
+
if (!isMap(node))
|
|
44
|
+
return;
|
|
45
|
+
for (const pair of node.items.filter(isPair)) {
|
|
46
|
+
if (!isScalar(pair.key))
|
|
47
|
+
continue;
|
|
48
|
+
const place = at(String(pair.key.value));
|
|
49
|
+
if (place.path !== undefined)
|
|
50
|
+
lines.set(place.path, lineOf(pair.key.range?.[0] ?? 0));
|
|
51
|
+
walk(pair.value, place.inside);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
walk(doc.contents, top);
|
|
55
|
+
return { raw: doc.toJS() ?? {}, lines };
|
|
56
|
+
};
|
|
57
|
+
const firstLine = (message) => message.split('\n')[0].replace(/ at line \d+, column \d+:?$/, '');
|
|
58
|
+
const anchors = (doc) => {
|
|
59
|
+
const offsets = [];
|
|
60
|
+
visit(doc, {
|
|
61
|
+
Node: (_, node) => {
|
|
62
|
+
if (isAlias(node) || (isNode(node) && node.anchor))
|
|
63
|
+
offsets.push(node.range?.[0] ?? 0);
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
return offsets;
|
|
67
|
+
};
|
|
68
|
+
const plain = (path) => (key) => ({ path: `${path}.${key}`, inside: plain(`${path}.${key}`) });
|
|
69
|
+
const moduleAt = (path) => ({ path, inside: moduleKey(path) });
|
|
70
|
+
const moduleKey = (path) => (key) => {
|
|
71
|
+
if (key === 'modules')
|
|
72
|
+
return { inside: (child) => moduleAt(`${path}.${child}`) };
|
|
73
|
+
if (key === 'test')
|
|
74
|
+
return { path: `${path}.test`, inside: testKey(path) };
|
|
75
|
+
return plain(path)(key);
|
|
76
|
+
};
|
|
77
|
+
const testKey = (path) => (key) => key === 'modules' ? { inside: (child) => moduleAt(`${path}.${child}`) } : plain(`${path}.test`)(key);
|
|
78
|
+
const top = (key) => {
|
|
79
|
+
if (key === 'root')
|
|
80
|
+
return moduleAt('root');
|
|
81
|
+
if (key === 'archetypes')
|
|
82
|
+
return { inside: moduleAt };
|
|
83
|
+
return { path: key, inside: plain(key) };
|
|
84
|
+
};
|
|
31
85
|
const entry = new URL(import.meta.url.endsWith('.ts') ? '../index.ts' : '../index.js', import.meta.url).href;
|
|
32
86
|
const ownFiles = new URL('../../', import.meta.url).href;
|
|
33
87
|
export const loadConfig = async (file) => {
|
|
34
|
-
const
|
|
88
|
+
const text = readFileSync(file, 'utf8');
|
|
89
|
+
const digest = createHash('sha256').update(text);
|
|
90
|
+
const { raw, lines } = parseConfig(text, file);
|
|
91
|
+
const declared = raw.plugins;
|
|
92
|
+
const specs = declared && typeof declared === 'object' && !Array.isArray(declared) ? Object.entries(declared) : [];
|
|
35
93
|
const hooks = registerHooks({
|
|
36
94
|
resolve: (specifier, context, nextResolve) => specifier === '@yearofthedan/warp' ? { url: entry, shortCircuit: true } : nextResolve(specifier, context),
|
|
37
95
|
load: (url, context, nextLoad) => {
|
|
@@ -42,12 +100,25 @@ export const loadConfig = async (file) => {
|
|
|
42
100
|
},
|
|
43
101
|
});
|
|
44
102
|
try {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
103
|
+
const plugins = {};
|
|
104
|
+
for (const [namespace, spec] of specs) {
|
|
105
|
+
if (typeof spec !== 'string')
|
|
106
|
+
continue;
|
|
107
|
+
const module = await import(__rewriteRelativeImportExtension(pathToFileURL(pluginPath(file, spec)).href));
|
|
108
|
+
if (module.default === undefined)
|
|
109
|
+
throw new ConfigError(`${file}:${lines.get(`plugins.${namespace}`) ?? 1}: plugins.${namespace}: ${spec} has no default export; export the plugin as default`);
|
|
110
|
+
plugins[namespace] = module.default;
|
|
111
|
+
}
|
|
112
|
+
return { raw, plugins, lines, digest: digest.digest('hex') };
|
|
49
113
|
}
|
|
50
114
|
finally {
|
|
51
115
|
hooks.deregister();
|
|
52
116
|
}
|
|
53
117
|
};
|
|
118
|
+
const pluginPath = (file, spec) => {
|
|
119
|
+
if (spec.startsWith('npm:'))
|
|
120
|
+
return createRequire(file).resolve(spec.slice(4));
|
|
121
|
+
if (spec.startsWith('./') || spec.startsWith('../'))
|
|
122
|
+
return resolve(dirname(file), spec);
|
|
123
|
+
throw new ConfigError(`${file}: plugin '${spec}': name a path, ./rules/x.ts, or a package, npm:x`);
|
|
124
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
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';
|
|
2
1
|
export { loadConfigData, type LoadedConfigData } from './app/load.ts';
|
|
3
2
|
export type * from './model/archetype/data.ts';
|
|
4
3
|
export type { Complexity, FunctionFacts, ImportEdge, FileFacts, Member, MemberGraph, MemberKind, } from './model/facts.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { all, archetype, contains, defineConfig, dir, exposes, files, pkg, ruleset, using, } from './model/archetype/builder.js';
|
|
2
1
|
export { loadConfigData } from './app/load.js';
|
|
3
2
|
export { ConfigError } from './model/configError.js';
|
|
4
3
|
export { wholeNumberOptions, } from './rules/rule.js';
|
|
@@ -2,6 +2,7 @@ export interface ModuleRefData {
|
|
|
2
2
|
kind: 'module';
|
|
3
3
|
module: string;
|
|
4
4
|
surface?: string;
|
|
5
|
+
up?: number;
|
|
5
6
|
}
|
|
6
7
|
export interface RequiredRefData {
|
|
7
8
|
kind: 'required';
|
|
@@ -24,17 +25,6 @@ export type ExposesData = {
|
|
|
24
25
|
kind: 'surfaces';
|
|
25
26
|
surfaces: Record<string, RefData[]>;
|
|
26
27
|
};
|
|
27
|
-
export interface LocatorData {
|
|
28
|
-
kind: 'dir' | 'files';
|
|
29
|
-
patterns: string[];
|
|
30
|
-
}
|
|
31
|
-
export interface TestLayerData {
|
|
32
|
-
locator?: LocatorData;
|
|
33
|
-
modules: FilesModuleData[];
|
|
34
|
-
using: RefData[];
|
|
35
|
-
exposes?: ExposesData;
|
|
36
|
-
rules?: RuleSettingsData;
|
|
37
|
-
}
|
|
38
28
|
export interface FilesModuleData {
|
|
39
29
|
kind: 'files';
|
|
40
30
|
name: string;
|
|
@@ -43,7 +33,6 @@ export interface FilesModuleData {
|
|
|
43
33
|
exposes?: Exclude<ExposesData, {
|
|
44
34
|
kind: 'surfaces';
|
|
45
35
|
}>;
|
|
46
|
-
tests?: TestLayerData;
|
|
47
36
|
rules?: RuleSettingsData;
|
|
48
37
|
description?: string;
|
|
49
38
|
}
|
|
@@ -52,34 +41,42 @@ export interface DirModuleData {
|
|
|
52
41
|
name: string;
|
|
53
42
|
paths: string[];
|
|
54
43
|
archetype: string;
|
|
44
|
+
test?: true;
|
|
55
45
|
using: RefData[];
|
|
46
|
+
inputs?: Record<string, RefData>;
|
|
47
|
+
testInputs?: Record<string, RefData>;
|
|
56
48
|
rules?: RuleSettingsData;
|
|
57
49
|
description?: string;
|
|
58
50
|
}
|
|
59
|
-
export
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
51
|
+
export interface TestModuleData {
|
|
52
|
+
kind: 'test';
|
|
53
|
+
name: string;
|
|
54
|
+
patterns: string[];
|
|
55
|
+
of?: string;
|
|
56
|
+
using: RefData[];
|
|
57
|
+
exposes?: Exclude<ExposesData, {
|
|
58
|
+
kind: 'surfaces';
|
|
59
|
+
}>;
|
|
60
|
+
rules?: RuleSettingsData;
|
|
61
|
+
description?: string;
|
|
62
|
+
}
|
|
63
|
+
export type ModuleData = FilesModuleData | DirModuleData | TestModuleData;
|
|
64
|
+
export declare const isTestData: (module: ModuleData) => boolean;
|
|
65
|
+
export interface IdentifyData {
|
|
69
66
|
marker: string;
|
|
70
|
-
}
|
|
71
|
-
match: (dir: string, chain: readonly unknown[]) => false | Record<string, string>;
|
|
72
|
-
};
|
|
67
|
+
}
|
|
73
68
|
export interface ArchetypeData {
|
|
74
69
|
name: string;
|
|
75
70
|
inline?: true;
|
|
71
|
+
test?: true;
|
|
76
72
|
description?: string;
|
|
77
73
|
identify?: IdentifyData;
|
|
78
|
-
requires:
|
|
74
|
+
requires: string[];
|
|
75
|
+
testRequires?: string[];
|
|
79
76
|
modules: ModuleData[];
|
|
80
77
|
exposes?: ExposesData;
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
testExposes?: Record<string, RefData[]>;
|
|
79
|
+
testUsing?: RefData[];
|
|
83
80
|
rules?: RuleSettingsData;
|
|
84
81
|
}
|
|
85
82
|
export interface ConfigData {
|
|
@@ -87,6 +84,5 @@ export interface ConfigData {
|
|
|
87
84
|
root: string;
|
|
88
85
|
archetypes: Record<string, ArchetypeData>;
|
|
89
86
|
tsconfig: string[];
|
|
90
|
-
tests?: string[];
|
|
91
87
|
rules?: RuleSettingsData;
|
|
92
88
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const isTestData = (module) => module.kind === 'test' || (module.kind === 'dir' && module.test === true);
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
self?: string;
|
|
8
|
+
tests: boolean;
|
|
9
|
+
}
|
|
10
|
+
export type Fix = {
|
|
11
|
+
kind: 'using';
|
|
12
|
+
site: string;
|
|
13
|
+
ref: RefData;
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'require';
|
|
16
|
+
archetype: string;
|
|
17
|
+
name: string;
|
|
18
|
+
sites: string[];
|
|
19
|
+
module: string;
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'expose';
|
|
22
|
+
archetype: string;
|
|
23
|
+
ref: RefData;
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'test-expose';
|
|
26
|
+
archetype: string;
|
|
27
|
+
ref: RefData;
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'expose-file';
|
|
30
|
+
archetype: string;
|
|
31
|
+
pattern: string;
|
|
32
|
+
};
|
|
33
|
+
export declare const namedArchetype: (config: ConfigData, name: string) => string;
|
|
34
|
+
export declare const sitesOf: (config: ConfigData, model: Model, file: string) => Site[];
|
|
35
|
+
export declare const fixesFor: (config: ConfigData, model: Model, from: string, to: string) => Fix[] | undefined;
|