@yearofthedan/warp 0.4.0 → 0.5.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 +5 -7
- package/dist/{analysis → adapters/analysis}/complexity.d.ts +1 -1
- package/dist/adapters/analysis/folders.d.ts +2 -0
- package/dist/{app/facts.d.ts → adapters/analysis/freshFacts.d.ts} +1 -2
- package/dist/{app/facts.js → adapters/analysis/freshFacts.js} +0 -10
- package/dist/{analysis → adapters/analysis}/imports.d.ts +2 -1
- package/dist/{analysis → adapters/analysis}/imports.js +52 -18
- package/dist/{analysis → adapters/analysis}/members.d.ts +1 -1
- package/dist/adapters/analysis/specifiers.d.ts +10 -0
- package/dist/adapters/analysis/specifiers.js +39 -0
- package/dist/adapters/analysis/typescript.d.ts +2 -0
- package/dist/{analysis → adapters/analysis}/typescript.js +10 -4
- package/dist/adapters/config/loadConfig.d.ts +8 -0
- package/dist/{config → adapters/config}/loadConfig.js +44 -21
- package/dist/{git → adapters/git}/cache.d.ts +1 -1
- package/dist/{git → adapters/git}/cache.js +5 -1
- package/dist/adapters/git/factsStore.d.ts +2 -0
- package/dist/adapters/git/factsStore.js +10 -0
- package/dist/{git → adapters/git}/repository.d.ts +1 -1
- package/dist/{config → adapters/git}/toolDigest.js +1 -1
- package/dist/{reporters → adapters/reporters}/model.d.ts +2 -2
- package/dist/{reporters → adapters/reporters}/reporter.d.ts +2 -2
- package/dist/{reporters → adapters/reporters}/text.d.ts +2 -2
- package/dist/app/check.d.ts +5 -6
- package/dist/app/check.js +3 -3
- package/dist/app/checkModel.d.ts +5 -5
- package/dist/app/checkModel.js +4 -5
- package/dist/app/configLines.d.ts +1 -1
- package/dist/app/diff.d.ts +1 -1
- package/dist/app/diff.js +1 -1
- package/dist/app/failures.d.ts +6 -0
- package/dist/app/failures.js +15 -0
- package/dist/app/load.d.ts +11 -5
- package/dist/app/load.js +22 -59
- package/dist/app/ports.d.ts +13 -3
- package/dist/builtins/advice.d.ts +4 -4
- package/dist/builtins/advice.js +2 -2
- package/dist/builtins/cognitive-complexity/{cognitiveComplexity.d.ts → rule.d.ts} +1 -1
- package/dist/builtins/cognitive-complexity/{cognitiveComplexity.js → rule.js} +1 -1
- package/dist/builtins/components.d.ts +1 -1
- package/dist/builtins/dependency-direction/rule.d.ts +2 -0
- package/dist/builtins/dependency-direction/{dependencyDirection.js → rule.js} +9 -4
- package/dist/builtins/file-cohesion/{fileCohesion.d.ts → rule.d.ts} +1 -1
- package/dist/builtins/file-cohesion/{fileCohesion.js → rule.js} +1 -1
- package/dist/builtins/function-cohesion/{functionCohesion.d.ts → rule.d.ts} +1 -1
- package/dist/builtins/function-cohesion/{functionCohesion.js → rule.js} +1 -1
- package/dist/builtins/index.d.ts +2 -2
- package/dist/builtins/index.js +18 -13
- package/dist/builtins/loops.d.ts +1 -1
- package/dist/builtins/loops.js +1 -1
- package/dist/builtins/module-cycle/{moduleCycle.d.ts → rule.d.ts} +1 -1
- package/dist/builtins/module-externals/rule.d.ts +2 -0
- package/dist/builtins/module-externals/{moduleExternals.js → rule.js} +3 -3
- package/dist/builtins/no-cross-module-reexport/rule.d.ts +2 -0
- package/dist/builtins/no-cross-module-reexport/{noCrossModuleReexport.js → rule.js} +1 -1
- package/dist/builtins/no-cycle/{noCycle.d.ts → rule.d.ts} +1 -1
- package/dist/builtins/no-double-export/rule.d.ts +2 -0
- package/dist/builtins/no-double-export/{noDoubleExport.js → rule.js} +1 -1
- package/dist/builtins/packages.d.ts +1 -1
- package/dist/builtins/place.d.ts +1 -1
- package/dist/builtins/shared.d.ts +1 -1
- package/dist/builtins/unclassified/rule.d.ts +2 -0
- package/dist/builtins/unclassified/rule.js +15 -0
- package/dist/builtins/unresolved-import/rule.d.ts +2 -0
- package/dist/builtins/unresolved-import/{unresolvedImport.js → rule.js} +1 -1
- package/dist/builtins/unused-declaration/declarations.d.ts +3 -3
- package/dist/builtins/unused-declaration/empty.d.ts +1 -1
- package/dist/builtins/unused-declaration/empty.js +1 -1
- package/dist/builtins/unused-declaration/grants.d.ts +1 -1
- package/dist/builtins/unused-declaration/grants.js +64 -14
- package/dist/builtins/unused-declaration/rule.d.ts +2 -0
- package/dist/builtins/unused-declaration/{unusedDeclaration.js → rule.js} +1 -1
- package/dist/builtins/unused-declaration/surfaces.d.ts +1 -1
- package/dist/builtins/unused-declaration/surfaces.js +1 -1
- package/dist/cli.js +51 -54
- package/dist/{model/archetype → domain/fixes}/fixes.d.ts +2 -2
- package/dist/{model/archetype → domain/fixes}/fixes.js +36 -29
- package/dist/domain/language/compile.d.ts +11 -0
- package/dist/domain/language/compile.js +58 -0
- package/dist/{model/archetype → domain/language}/references.d.ts +3 -6
- package/dist/{model/archetype → domain/language}/references.js +16 -21
- package/dist/{model/archetype → domain/language}/requirements.d.ts +3 -3
- package/dist/{model/archetype → domain/language}/requirements.js +13 -2
- package/dist/domain/language/rulesets.d.ts +10 -0
- package/dist/domain/language/rulesets.js +60 -0
- package/dist/{model/archetype/language.d.ts → domain/language/structure.d.ts} +4 -3
- package/dist/{model/archetype/language.js → domain/language/structure.js} +50 -17
- package/dist/{model/archetype → domain/model}/data.d.ts +10 -6
- package/dist/{model/archetype → domain/model}/reach.d.ts +1 -0
- package/dist/{model/archetype → domain/model}/reach.js +3 -7
- package/dist/{model/archetype → domain/model}/resolve.d.ts +2 -0
- package/dist/{model/archetype → domain/model}/resolve.js +9 -3
- package/dist/{model/archetype → domain/model}/settings.d.ts +1 -1
- package/dist/domain/model/settings.js +82 -0
- package/dist/domain/model/text.d.ts +4 -0
- package/dist/domain/model/text.js +13 -0
- package/dist/{rules → domain/rules}/registry.d.ts +1 -0
- package/dist/{rules → domain/rules}/registry.js +11 -1
- package/dist/{rules → domain/rules}/rule.d.ts +10 -4
- package/dist/index.d.ts +6 -6
- package/dist/index.js +2 -2
- package/package.json +2 -1
- package/dist/analysis/folders.d.ts +0 -2
- package/dist/analysis/specifiers.d.ts +0 -2
- package/dist/analysis/specifiers.js +0 -6
- package/dist/analysis/typescript.d.ts +0 -2
- package/dist/app/unclassified.d.ts +0 -5
- package/dist/app/unclassified.js +0 -13
- package/dist/builtins/dependency-direction/dependencyDirection.d.ts +0 -2
- package/dist/builtins/module-externals/moduleExternals.d.ts +0 -2
- package/dist/builtins/no-cross-module-reexport/noCrossModuleReexport.d.ts +0 -2
- package/dist/builtins/no-double-export/noDoubleExport.d.ts +0 -2
- package/dist/builtins/unresolved-import/unresolvedImport.d.ts +0 -2
- package/dist/builtins/unused-declaration/unusedDeclaration.d.ts +0 -2
- package/dist/config/loadConfig.d.ts +0 -13
- package/dist/model/archetype/rulesets.d.ts +0 -5
- package/dist/model/archetype/rulesets.js +0 -138
- package/dist/model/archetype/settings.js +0 -49
- /package/dist/{analysis → adapters/analysis}/complexity.js +0 -0
- /package/dist/{analysis → adapters/analysis}/folders.js +0 -0
- /package/dist/{analysis → adapters/analysis}/members.js +0 -0
- /package/dist/{analysis → adapters/analysis}/source.d.ts +0 -0
- /package/dist/{analysis → adapters/analysis}/source.js +0 -0
- /package/dist/{git → adapters/git}/repository.js +0 -0
- /package/dist/{config → adapters/git}/toolDigest.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/agent.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/agent.js +0 -0
- /package/dist/{reporters → adapters/reporters}/claudeHook.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/claudeHook.js +0 -0
- /package/dist/{reporters → adapters/reporters}/index.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/index.js +0 -0
- /package/dist/{reporters → adapters/reporters}/json.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/json.js +0 -0
- /package/dist/{reporters → adapters/reporters}/model.js +0 -0
- /package/dist/{reporters → adapters/reporters}/omp.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/omp.js +0 -0
- /package/dist/{reporters → adapters/reporters}/reporter.js +0 -0
- /package/dist/{reporters → adapters/reporters}/sarif.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/sarif.js +0 -0
- /package/dist/{reporters → adapters/reporters}/text.js +0 -0
- /package/dist/builtins/module-cycle/{moduleCycle.js → rule.js} +0 -0
- /package/dist/builtins/no-cycle/{noCycle.js → rule.js} +0 -0
- /package/dist/{model → domain/facts}/facts.d.ts +0 -0
- /package/dist/{model → domain/facts}/facts.js +0 -0
- /package/dist/{model → domain/model}/configError.d.ts +0 -0
- /package/dist/{model → domain/model}/configError.js +0 -0
- /package/dist/{model/archetype → domain/model}/data.js +0 -0
- /package/dist/{model/archetype → domain/model}/shared.d.ts +0 -0
- /package/dist/{model/archetype → domain/model}/shared.js +0 -0
- /package/dist/{rules → domain/rules}/diff.d.ts +0 -0
- /package/dist/{rules → domain/rules}/diff.js +0 -0
- /package/dist/{rules → domain/rules}/rule.js +0 -0
package/dist/cli.js
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { readFileSync, realpathSync } from 'node:fs';
|
|
3
|
-
import {
|
|
2
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
4
|
import { parseArgs } from 'node:util';
|
|
5
|
-
import { diskFolders } from './analysis/folders.js';
|
|
6
|
-
import { typescriptAnalyzer } from './analysis/typescript.js';
|
|
5
|
+
import { diskFolders } from './adapters/analysis/folders.js';
|
|
6
|
+
import { typescriptAnalyzer } from './adapters/analysis/typescript.js';
|
|
7
7
|
import { modelProject, projectCheck } from './app/check.js';
|
|
8
8
|
import { placeProblems } from './app/configLines.js';
|
|
9
|
-
import { factsStore } from './
|
|
9
|
+
import { factsStore } from './adapters/git/factsStore.js';
|
|
10
|
+
import { failures } from './app/failures.js';
|
|
10
11
|
import { diffProject, parseRange } from './app/diff.js';
|
|
11
|
-
import {
|
|
12
|
-
import { findConfig,
|
|
13
|
-
import { toolDigest } from './
|
|
14
|
-
import { gitDirCache } from './git/cache.js';
|
|
15
|
-
import { gitRepository, projectPathOf } from './git/repository.js';
|
|
16
|
-
import { rulesOf } from './model/
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
12
|
+
import { warp } from './builtins/index.js';
|
|
13
|
+
import { findConfig, yamlConfig } from './adapters/config/loadConfig.js';
|
|
14
|
+
import { toolDigest } from './adapters/git/toolDigest.js';
|
|
15
|
+
import { gitDirCache } from './adapters/git/cache.js';
|
|
16
|
+
import { gitRepository, projectPathOf } from './adapters/git/repository.js';
|
|
17
|
+
import { anyRuleOn, rulesOf } from './domain/model/settings.js';
|
|
18
|
+
import { recommended } from './domain/language/compile.js';
|
|
19
|
+
import { loadConfig } from './app/load.js';
|
|
20
|
+
import { ConfigError } from './domain/model/configError.js';
|
|
21
|
+
import { reporters } from './adapters/reporters/index.js';
|
|
22
|
+
import { modelJson, modelText } from './adapters/reporters/model.js';
|
|
23
|
+
import { actionable } from './adapters/reporters/reporter.js';
|
|
22
24
|
const usage = `usage:
|
|
23
|
-
warp check [--config <file>] [--
|
|
24
|
-
warp diff <base>[..<head> | ...<head>] [--since-last-run] [--config <file>] [--
|
|
25
|
-
warp model [--config <file>] [--
|
|
25
|
+
warp check [--config <file>] [--reporter <name>] [--fail]
|
|
26
|
+
warp diff <base>[..<head> | ...<head>] [--since-last-run] [--config <file>] [--reporter <name>] [--fail]
|
|
27
|
+
warp model [--config <file>] [--rules] [--json]
|
|
26
28
|
|
|
27
29
|
check reports every finding in the working tree.
|
|
28
30
|
diff reports findings that are new or worse at <head> than at <base>. Without <head>, compares the working tree.
|
|
@@ -31,16 +33,17 @@ diff reports findings that are new or worse at <head> than at <base>. Without
|
|
|
31
33
|
model prints the modules the config finds, and which module each file is in.
|
|
32
34
|
|
|
33
35
|
--config path to the config file (default: warp.yaml)
|
|
34
|
-
--ruleset one of the config's rulesets (default: the one named default, if any)
|
|
35
36
|
--reporter ${[...reporters.keys()].join(', ')} (default: text)
|
|
36
37
|
--since-last-run with diff, compare with the last diff run that had this flag
|
|
37
38
|
--fail exit 1 when there are findings (check) or new or worse findings (diff)
|
|
38
39
|
--rules with model, list each module's rule settings that differ from the defaults
|
|
39
40
|
--json print the model as JSON, with every module's resolved rule settings`;
|
|
41
|
+
let toolHash;
|
|
42
|
+
const tool = () => (toolHash ??= toolDigest());
|
|
40
43
|
const adaptersAt = (root) => {
|
|
41
44
|
const adapters = { analyzer: typescriptAnalyzer, foldersAt: diskFolders };
|
|
42
45
|
try {
|
|
43
|
-
return { ...adapters, facts: factsStore(gitDirCache(root),
|
|
46
|
+
return { ...adapters, facts: factsStore(gitDirCache(root), tool(), gitRepository(root).projectPath()) };
|
|
44
47
|
}
|
|
45
48
|
catch {
|
|
46
49
|
return adapters;
|
|
@@ -52,7 +55,6 @@ const main = async (argv) => {
|
|
|
52
55
|
allowPositionals: true,
|
|
53
56
|
options: {
|
|
54
57
|
config: { type: 'string' },
|
|
55
|
-
ruleset: { type: 'string' },
|
|
56
58
|
rules: { type: 'boolean', default: false },
|
|
57
59
|
reporter: { type: 'string', default: 'text' },
|
|
58
60
|
fail: { type: 'boolean', default: false },
|
|
@@ -82,44 +84,49 @@ const help = (code) => {
|
|
|
82
84
|
const resolveConfig = async (options) => {
|
|
83
85
|
const configFile = realpathSync(options.config ? resolve(options.config) : findConfig(process.cwd()));
|
|
84
86
|
const root = dirname(configFile);
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
}
|
|
87
|
+
const source = yamlConfig(configFile);
|
|
88
|
+
const loaded = await loadConfig(source, { builtins: warp });
|
|
89
|
+
for (const tsconfig of loaded.config.tsconfig.filter((path) => !existsSync(join(root, path))))
|
|
90
|
+
throw new ConfigError(placeProblems(loaded.lines, source.file, `tsconfig: no ${tsconfig} beside ${source.file}; add it, or list the project's tsconfig files under tsconfig`));
|
|
91
|
+
return { root, ...loaded };
|
|
97
92
|
};
|
|
98
|
-
const checkOf = ({ root, config, rules, lines }) => projectCheck(adaptersAt(root), config, { rules,
|
|
93
|
+
const checkOf = ({ root, config, rules, lines }) => projectCheck(adaptersAt(root), config, { rules, lines });
|
|
99
94
|
const run = async (options, produce) => {
|
|
100
95
|
const reporter = reporters.get(options.reporter);
|
|
101
96
|
if (!reporter)
|
|
102
97
|
throw new Error(`no reporter called ${options.reporter}: use one of ${[...reporters.keys()].join(', ')}`);
|
|
103
98
|
try {
|
|
104
99
|
const resolved = await resolveConfig(options);
|
|
105
|
-
|
|
100
|
+
if (!anyRuleOn(resolved.config))
|
|
101
|
+
console.error(nothingOn(resolved.config.file));
|
|
102
|
+
const report = placed(resolved, () => produce(resolved.root, checkOf(resolved), resolved.digest));
|
|
106
103
|
const output = reporter.render(report, { toolVersion: version(), projectPath: projectPathOf(resolved.root) });
|
|
107
104
|
if (output)
|
|
108
105
|
console.log(output);
|
|
109
106
|
if (reporter.renderFailure)
|
|
110
|
-
|
|
107
|
+
lastFailure().forget();
|
|
111
108
|
return options.fail && actionable(report).length > 0 ? 1 : 0;
|
|
112
109
|
}
|
|
113
110
|
catch (error) {
|
|
114
111
|
const code = failed(error, reporter.failureExitCode);
|
|
115
112
|
const problem = describe(error);
|
|
116
|
-
if (!reporter.renderFailure || !
|
|
113
|
+
if (!reporter.renderFailure || !lastFailure().isNew(problem))
|
|
117
114
|
return code;
|
|
118
115
|
console.log(reporter.renderFailure(problem));
|
|
119
116
|
return 0;
|
|
120
117
|
}
|
|
121
118
|
};
|
|
122
|
-
const
|
|
119
|
+
const placed = ({ lines, config }, run) => {
|
|
120
|
+
try {
|
|
121
|
+
return run();
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (error instanceof ConfigError)
|
|
125
|
+
throw new ConfigError(placeProblems(lines, config.file, error.message));
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
const nothingOn = (file) => `No rules are on, so nothing was checked. Turn some on in ${file}: root: { ruleset: [${recommended}] }`;
|
|
123
130
|
const failureCache = () => {
|
|
124
131
|
try {
|
|
125
132
|
return gitDirCache(process.cwd());
|
|
@@ -128,22 +135,12 @@ const failureCache = () => {
|
|
|
128
135
|
return undefined;
|
|
129
136
|
}
|
|
130
137
|
};
|
|
131
|
-
const
|
|
132
|
-
const cache = failureCache();
|
|
133
|
-
if (cache?.get(failureKey()) === problem)
|
|
134
|
-
return false;
|
|
135
|
-
cache?.set(failureKey(), problem);
|
|
136
|
-
return true;
|
|
137
|
-
};
|
|
138
|
-
const forgetFailure = () => {
|
|
139
|
-
const cache = failureCache();
|
|
140
|
-
if (cache?.get(failureKey()) !== undefined)
|
|
141
|
-
cache.prune((key) => key !== failureKey());
|
|
142
|
-
};
|
|
138
|
+
const lastFailure = () => failures(failureCache(), tool());
|
|
143
139
|
const printModel = async (options) => {
|
|
144
140
|
try {
|
|
145
|
-
const
|
|
146
|
-
const {
|
|
141
|
+
const resolved = await resolveConfig(options);
|
|
142
|
+
const { root, config, rules } = resolved;
|
|
143
|
+
const { model } = placed(resolved, () => modelProject(adaptersAt(root), root, config));
|
|
147
144
|
const settings = rulesOf(config, model, rules);
|
|
148
145
|
console.log(options.json ? modelJson(model, settings) : modelText(model, options.rules ? settings : undefined));
|
|
149
146
|
return 0;
|
|
@@ -152,7 +149,7 @@ const printModel = async (options) => {
|
|
|
152
149
|
return failed(error);
|
|
153
150
|
}
|
|
154
151
|
};
|
|
155
|
-
const delta = (range, root, project, configDigest, sinceLastRun) => diffProject({ range: parseRange(range), root, project, configDigest, toolDigest:
|
|
152
|
+
const delta = (range, root, project, configDigest, sinceLastRun) => diffProject({ range: parseRange(range), root, project, configDigest, toolDigest: tool(), sinceLastRun }, { repository: gitRepository(root), cache: gitDirCache(root) });
|
|
156
153
|
const version = () => JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
157
154
|
const describe = (error) => error instanceof ConfigError
|
|
158
155
|
? `warp config: ${error.message}`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ConfigData, RefData } from '
|
|
2
|
-
import type
|
|
1
|
+
import type { ConfigData, RefData } from '../model/data.ts';
|
|
2
|
+
import { type Model, type ModuleView } from '../model/resolve.ts';
|
|
3
3
|
export interface Site {
|
|
4
4
|
label: string;
|
|
5
5
|
holder: ModuleView;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { instanceOf, verdicts } from '
|
|
2
|
-
|
|
3
|
-
for (let at = module.parent; at; at = at.parent)
|
|
4
|
-
yield at;
|
|
5
|
-
};
|
|
1
|
+
import { instanceOf, verdicts } from '../model/reach.js';
|
|
2
|
+
import { ancestors, subtree } from '../model/resolve.js';
|
|
6
3
|
const lineage = (module) => [module, ...ancestors(module)];
|
|
7
4
|
export const namedArchetype = (config, name) => config.archetypes[name].inline ? namedArchetype(config, name.slice(0, name.lastIndexOf('.'))) : name;
|
|
8
5
|
const withArchetype = (config, name, change) => ({
|
|
@@ -47,10 +44,10 @@ const surfacesOf = ({ exposes, testExposes }, tests) => [
|
|
|
47
44
|
...(tests ? Object.keys(testExposes ?? {}) : []),
|
|
48
45
|
]),
|
|
49
46
|
];
|
|
50
|
-
const moduleRefs = (config, module, tests, up = 0) => {
|
|
47
|
+
const moduleRefs = (config, module, tests, up = 0, top = false) => {
|
|
51
48
|
const surfaces = module.kind === 'dir' ? surfacesOf(config.archetypes[module.archetype], tests) : [];
|
|
52
49
|
const name = module.name;
|
|
53
|
-
const out = up > 0 ? { up } : {};
|
|
50
|
+
const out = { ...(up > 0 ? { up } : {}), ...(top ? { top: true } : {}) };
|
|
54
51
|
return [
|
|
55
52
|
...surfaces.map((surface) => ({ kind: 'module', module: name, surface, ...out })),
|
|
56
53
|
{ kind: 'module', module: name, ...out },
|
|
@@ -62,6 +59,7 @@ const levels = (config, holder) => {
|
|
|
62
59
|
found.push(at.parent);
|
|
63
60
|
return found;
|
|
64
61
|
};
|
|
62
|
+
const declares = (config, level, name) => config.archetypes[level.archetype].modules.some((module) => module.name === name);
|
|
65
63
|
const inputsOf = (config, site) => {
|
|
66
64
|
const named = config.archetypes[namedArchetype(config, site.holder.archetype)];
|
|
67
65
|
const names = [...named.requires, ...(site.tests ? (named.testRequires ?? []) : [])];
|
|
@@ -78,29 +76,39 @@ const nameable = (site, module) => !(module.parent === site.holder && module.nam
|
|
|
78
76
|
const usingChanges = function* (search, config) {
|
|
79
77
|
const targets = reachable(search);
|
|
80
78
|
for (const site of sitesOf(config, search.model, search.from)) {
|
|
81
|
-
const
|
|
79
|
+
const scopes = levels(config, site.holder);
|
|
80
|
+
const own = scopes.flatMap((level, up) => targets
|
|
82
81
|
.filter((module) => module.parent === level && nameable(site, module))
|
|
83
|
-
.flatMap((module) =>
|
|
82
|
+
.flatMap((module) => {
|
|
83
|
+
const shadowed = scopes.slice(0, up).some((nearer) => declares(config, nearer, module.name));
|
|
84
|
+
if (!shadowed)
|
|
85
|
+
return moduleRefs(config, module, site.tests, up);
|
|
86
|
+
return up === scopes.length - 1 ? moduleRefs(config, module, site.tests, up, true) : [];
|
|
87
|
+
}));
|
|
84
88
|
for (const ref of [...own, ...inputsOf(config, site)])
|
|
85
89
|
yield [{ fix: { kind: 'using', site: site.label, ref }, config: site.add(config, ref) }];
|
|
86
90
|
}
|
|
87
91
|
};
|
|
88
|
-
const bindingAt = (config, chain,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
const bindingAt = (config, chain, { holder }, name) => {
|
|
93
|
+
for (let key = holder, up = 0;; up += 1) {
|
|
94
|
+
if (config.archetypes[key].modules.some((module) => module.name === name))
|
|
95
|
+
return { kind: 'module', module: name, ...(up > 0 ? { up } : {}) };
|
|
96
|
+
if (!config.archetypes[key].inline)
|
|
97
|
+
break;
|
|
98
|
+
key = key.slice(0, key.lastIndexOf('.'));
|
|
99
|
+
}
|
|
100
|
+
return chain.has(namedArchetype(config, holder)) ? { kind: 'required', name } : undefined;
|
|
93
101
|
};
|
|
94
|
-
const
|
|
102
|
+
const usesOf = (config, archetype) => Object.entries(config.archetypes).flatMap(([holder, data]) => data.modules
|
|
103
|
+
.filter((module) => module.kind === 'dir' && module.archetype === archetype)
|
|
104
|
+
.map((module) => ({ holder, name: module.name })));
|
|
95
105
|
const chainTo = (config, holder, target) => {
|
|
106
|
+
const scope = instanceOf({ config }, target.parent);
|
|
96
107
|
const chain = [];
|
|
97
108
|
for (let instance = instanceOf({ config }, holder); instance.parent; instance = instanceOf({ config }, instance.parent)) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (!chain.includes(archetype))
|
|
102
|
-
chain.push(archetype);
|
|
103
|
-
if (instance.parent === target.parent)
|
|
109
|
+
if (!chain.includes(instance.archetype))
|
|
110
|
+
chain.push(instance.archetype);
|
|
111
|
+
if (instanceOf({ config }, instance.parent) === scope)
|
|
104
112
|
return chain;
|
|
105
113
|
}
|
|
106
114
|
return undefined;
|
|
@@ -110,12 +118,12 @@ const requireChanges = function* (search, config) {
|
|
|
110
118
|
for (const site of sitesOf(config, search.model, search.from))
|
|
111
119
|
for (const module of targets) {
|
|
112
120
|
const chain = chainTo(config, site.holder, module);
|
|
113
|
-
const changes = chain && requirement(config,
|
|
121
|
+
const changes = chain && requirement(config, site, chain, module);
|
|
114
122
|
if (changes)
|
|
115
123
|
yield changes;
|
|
116
124
|
}
|
|
117
125
|
};
|
|
118
|
-
const requirement = (config,
|
|
126
|
+
const requirement = (config, site, chain, module) => {
|
|
119
127
|
const name = module.name;
|
|
120
128
|
if (config.archetypes[chain[0]].requires.includes(name))
|
|
121
129
|
return undefined;
|
|
@@ -123,17 +131,17 @@ const requirement = (config, model, site, chain, module) => {
|
|
|
123
131
|
let required = config;
|
|
124
132
|
const fixes = [];
|
|
125
133
|
for (const archetype of chain.filter((at) => !config.archetypes[at].requires.includes(name))) {
|
|
126
|
-
const
|
|
127
|
-
const bindings =
|
|
134
|
+
const uses = usesOf(config, archetype);
|
|
135
|
+
const bindings = uses.map((use) => bindingAt(config, passing, use, name));
|
|
128
136
|
if (bindings.includes(undefined))
|
|
129
137
|
return undefined;
|
|
130
138
|
required = withArchetype(required, archetype, (data) => ({ ...data, requires: [...data.requires, name] }));
|
|
131
|
-
for (const [index,
|
|
132
|
-
required = withModule(required,
|
|
139
|
+
for (const [index, use] of uses.entries())
|
|
140
|
+
required = withModule(required, use.holder, use.name, (declared) => {
|
|
133
141
|
const dir = declared;
|
|
134
142
|
return { ...dir, inputs: { ...dir.inputs, [name]: bindings[index] } };
|
|
135
143
|
});
|
|
136
|
-
const sites =
|
|
144
|
+
const sites = uses.map((use) => `${use.holder}.${use.name}`);
|
|
137
145
|
fixes.push({ fix: { kind: 'require', archetype, name, sites, module: name }, config: required });
|
|
138
146
|
}
|
|
139
147
|
const ref = { kind: 'required', name };
|
|
@@ -197,7 +205,6 @@ const exposeFilesModule = (search, config, hiddenBy) => {
|
|
|
197
205
|
})),
|
|
198
206
|
};
|
|
199
207
|
};
|
|
200
|
-
const subtree = (module) => [module, ...module.children.flatMap(subtree)];
|
|
201
208
|
const uses = (config, model, from, under) => {
|
|
202
209
|
const judge = verdicts(config, model);
|
|
203
210
|
const reached = subtree(from).flatMap((module) => module.files.slice(0, 1).flatMap((file) => (judge.reach(file) ?? []).flatMap((grant) => [...grant.files])));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ConfigData } from '../model/data.ts';
|
|
2
|
+
import { type Check } from './references.ts';
|
|
3
|
+
export { recommended } from './rulesets.ts';
|
|
4
|
+
export interface CompileOptions {
|
|
5
|
+
file?: string;
|
|
6
|
+
plugins?: readonly string[];
|
|
7
|
+
rulesets?: Readonly<Record<string, unknown>>;
|
|
8
|
+
ruleIds?: ReadonlySet<string> | undefined;
|
|
9
|
+
options?: Check['options'];
|
|
10
|
+
}
|
|
11
|
+
export declare const compileConfig: (raw: unknown, { file, plugins, rulesets, ruleIds, options }?: CompileOptions) => ConfigData;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ConfigError } from '../model/configError.js';
|
|
2
|
+
import { defined, isName, isRecord } from '../model/shared.js';
|
|
3
|
+
import { checkReferences, toRules } from './references.js';
|
|
4
|
+
import { checkInputs, markTests } from './requirements.js';
|
|
5
|
+
import { rulesets as namedRulesets } from './rulesets.js';
|
|
6
|
+
import { parseStructure } from './structure.js';
|
|
7
|
+
export { recommended } from './rulesets.js';
|
|
8
|
+
const keys = ['root', 'archetypes', 'rulesets', 'plugins', 'tsconfig'];
|
|
9
|
+
export const compileConfig = (raw, { file = 'warp.yaml', plugins = [], rulesets = {}, ruleIds, options = {} } = {}) => {
|
|
10
|
+
const errors = [];
|
|
11
|
+
const fail = (message) => {
|
|
12
|
+
if (!errors.includes(message))
|
|
13
|
+
errors.push(message);
|
|
14
|
+
};
|
|
15
|
+
const failed = () => {
|
|
16
|
+
if (errors.length > 0)
|
|
17
|
+
throw new ConfigError(errors.join('\n'));
|
|
18
|
+
};
|
|
19
|
+
if (!isRecord(raw))
|
|
20
|
+
throw new ConfigError(`${file}: expected a mapping, root: { modules: ... }`);
|
|
21
|
+
const unknownKeys = Object.keys(raw).filter((key) => !keys.includes(key));
|
|
22
|
+
for (const key of unknownKeys)
|
|
23
|
+
fail(`${key}: unknown key; a config takes ${keys.join(', ')}`);
|
|
24
|
+
checkPlugins(raw.plugins, plugins, fail);
|
|
25
|
+
const check = { fail, ruleIds, options };
|
|
26
|
+
const named = namedRulesets(raw.rulesets, rulesets, (value, at) => toRules(check, value, at), fail);
|
|
27
|
+
const structure = parseStructure(raw.root, raw.archetypes, fail, named.parse);
|
|
28
|
+
named.checkUsed();
|
|
29
|
+
failed();
|
|
30
|
+
checkReferences(structure.archetypes, structure.pending, fail);
|
|
31
|
+
markTests(structure.archetypes, fail);
|
|
32
|
+
checkInputs(structure.archetypes, structure.pending, fail);
|
|
33
|
+
const config = {
|
|
34
|
+
file,
|
|
35
|
+
root: structure.root,
|
|
36
|
+
archetypes: Object.fromEntries(Object.entries(structure.archetypes).map(([name, archetype]) => [name, archetypeData(archetype)])),
|
|
37
|
+
tsconfig: tsconfigs(raw.tsconfig, fail),
|
|
38
|
+
};
|
|
39
|
+
failed();
|
|
40
|
+
return config;
|
|
41
|
+
};
|
|
42
|
+
const archetypeData = (archetype) => defined({ ...archetype, modules: archetype.modules.map(defined) });
|
|
43
|
+
const checkPlugins = (declared, loaded, fail) => {
|
|
44
|
+
if (declared === undefined)
|
|
45
|
+
return;
|
|
46
|
+
if (!isRecord(declared) || !Object.values(declared).every(isName)) {
|
|
47
|
+
fail('plugins: expected plugin paths by namespace, { wt: ./rules/wt.ts }');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
for (const namespace of Object.keys(declared).filter((namespace) => !loaded.includes(namespace)))
|
|
51
|
+
fail(`plugins.${namespace}: not loaded; warp loads each plugin from its path before reading the config`);
|
|
52
|
+
};
|
|
53
|
+
const tsconfigs = (value, fail) => {
|
|
54
|
+
const paths = [value ?? 'tsconfig.json'].flat();
|
|
55
|
+
if (paths.length === 0 || !paths.every(isName))
|
|
56
|
+
fail('tsconfig: expected a path or a list of paths');
|
|
57
|
+
return paths;
|
|
58
|
+
};
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import { type ArchetypeData, type ExposesData, type
|
|
2
|
-
import type { PendingRef } from './
|
|
3
|
-
import { type Fail } from '
|
|
1
|
+
import { type ArchetypeData, type ExposesData, type RuleSettingsData } from '../model/data.ts';
|
|
2
|
+
import type { PendingRef } from './structure.ts';
|
|
3
|
+
import { type Fail } from '../model/shared.ts';
|
|
4
4
|
export interface Check {
|
|
5
5
|
fail: Fail;
|
|
6
6
|
ruleIds?: ReadonlySet<string> | undefined;
|
|
7
7
|
options: Readonly<Record<string, (raw: Record<string, unknown>, at: string) => unknown>>;
|
|
8
8
|
}
|
|
9
|
-
export declare const packageText: (pattern: string) => string;
|
|
10
|
-
export declare const show: (ref: RefData) => string;
|
|
11
9
|
export declare const checkReferences: (archetypes: Record<string, ArchetypeData>, pending: readonly PendingRef[], fail: Fail) => void;
|
|
12
10
|
interface Surfaces {
|
|
13
11
|
exposes: ExposesData | undefined;
|
|
14
12
|
testExposes: readonly string[];
|
|
15
13
|
}
|
|
16
14
|
export declare const exposedProblem: (subject: string, { exposes, testExposes }: Surfaces, surface: string | undefined, tests: boolean) => string | undefined;
|
|
17
|
-
export declare const exposesText: (exposes: ExposesData | undefined) => string;
|
|
18
15
|
export declare const toRules: (check: Check, value: unknown, where: string) => RuleSettingsData | undefined;
|
|
19
16
|
export {};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { ConfigError } from '../configError.js';
|
|
2
|
-
import { isTestData } from '
|
|
3
|
-
import { isRecord, list } from '
|
|
4
|
-
|
|
5
|
-
export const show = (ref) => ref.kind === 'package'
|
|
6
|
-
? packageText(ref.pattern)
|
|
7
|
-
: `${ref.kind === 'required' ? ref.name : ref.module}${ref.surface === undefined ? '' : `.${ref.surface}`}`;
|
|
1
|
+
import { ConfigError } from '../model/configError.js';
|
|
2
|
+
import { isTestData } from '../model/data.js';
|
|
3
|
+
import { isRecord, list } from '../model/shared.js';
|
|
4
|
+
import { exposesText, show } from '../model/text.js';
|
|
8
5
|
export const checkReferences = (archetypes, pending, fail) => {
|
|
9
6
|
for (const entry of pending) {
|
|
10
7
|
const problem = refProblem(archetypes, entry);
|
|
@@ -48,35 +45,33 @@ export const exposedProblem = (subject, { exposes, testExposes }, surface, tests
|
|
|
48
45
|
return `${subject} exposes ${list(named, 'nothing')}`;
|
|
49
46
|
return `${subject} exposes ${exposesText(exposes)}, not named surfaces`;
|
|
50
47
|
};
|
|
51
|
-
export const exposesText = (exposes) => {
|
|
52
|
-
if (exposes === undefined)
|
|
53
|
-
return 'nothing';
|
|
54
|
-
if (exposes.kind === 'all')
|
|
55
|
-
return 'all its files';
|
|
56
|
-
if (exposes.kind === 'files')
|
|
57
|
-
return `{ files: [${exposes.patterns.join(', ')}] }`;
|
|
58
|
-
return Object.keys(exposes.surfaces).join(', ');
|
|
59
|
-
};
|
|
60
48
|
export const toRules = (check, value, where) => {
|
|
61
|
-
if (value === undefined
|
|
62
|
-
return
|
|
49
|
+
if (value === undefined)
|
|
50
|
+
return undefined;
|
|
51
|
+
if (value === 'off')
|
|
52
|
+
return { '*': false };
|
|
63
53
|
if (!isRecord(value)) {
|
|
64
54
|
check.fail(`${where}: expected off or rule settings by id`);
|
|
65
55
|
return undefined;
|
|
66
56
|
}
|
|
67
|
-
return Object.fromEntries(Object.entries(value).
|
|
57
|
+
return Object.fromEntries(Object.entries(value).flatMap(([id, setting]) => {
|
|
58
|
+
const parsed = toSetting(check, id, setting, where);
|
|
59
|
+
return parsed === undefined ? [] : [[id, parsed]];
|
|
60
|
+
}));
|
|
68
61
|
};
|
|
69
62
|
const toSetting = (check, id, setting, where) => {
|
|
70
63
|
if (id !== '*' && check.ruleIds && !check.ruleIds.has(id))
|
|
71
64
|
check.fail(`${where}: no rule called ${id}`);
|
|
65
|
+
else if (id === '*' && setting !== 'off' && setting !== false)
|
|
66
|
+
check.fail(`${where}.*: expected off; turn rules on by name, or extend a ruleset such as warp:recommended`);
|
|
72
67
|
else if (setting === 'on' || setting === 'off')
|
|
73
68
|
return setting === 'on';
|
|
74
69
|
else if (typeof setting === 'boolean')
|
|
75
70
|
return setting;
|
|
76
|
-
else if (
|
|
71
|
+
else if (isRecord(setting))
|
|
77
72
|
return checkOptions(check, id, setting, where);
|
|
78
73
|
else
|
|
79
|
-
check.fail(`${where}.${id}: expected on, off
|
|
74
|
+
check.fail(`${where}.${id}: expected on, off or options`);
|
|
80
75
|
return undefined;
|
|
81
76
|
};
|
|
82
77
|
const checkOptions = (check, id, options, where) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ArchetypeData } from '
|
|
2
|
-
import type { PendingRef } from './
|
|
3
|
-
import type { Fail } from '
|
|
1
|
+
import type { ArchetypeData } from '../model/data.ts';
|
|
2
|
+
import type { PendingRef } from './structure.ts';
|
|
3
|
+
import type { Fail } from '../model/shared.ts';
|
|
4
4
|
export declare const markTests: (archetypes: Record<string, ArchetypeData>, fail: Fail) => void;
|
|
5
5
|
export declare const checkInputs: (archetypes: Record<string, ArchetypeData>, pending: readonly PendingRef[], fail: Fail) => void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { exposedProblem
|
|
1
|
+
import { exposedProblem } from './references.js';
|
|
2
|
+
import { show } from '../model/text.js';
|
|
2
3
|
const namedOf = (archetype) => archetype.split('.')[0];
|
|
3
4
|
const sitesOf = (archetypes) => Object.values(archetypes).flatMap((holder) => holder.modules
|
|
4
5
|
.filter((module) => module.kind === 'dir' && !archetypes[module.archetype]?.inline)
|
|
@@ -23,8 +24,13 @@ export const checkInputs = (archetypes, pending, fail) => {
|
|
|
23
24
|
const uses = pending.filter((entry) => entry.ref.kind === 'required');
|
|
24
25
|
const usesOf = (archetype) => uses.filter((entry) => namedOf(entry.archetype) === archetype);
|
|
25
26
|
for (const archetype of Object.values(archetypes).filter((candidate) => !candidate.inline)) {
|
|
27
|
+
const inputs = [...archetype.requires, ...(archetype.testRequires ?? [])];
|
|
28
|
+
const shadowed = shadowsOf(archetypes, archetype.name, inputs);
|
|
29
|
+
for (const [module, name] of shadowed)
|
|
30
|
+
fail(`${module} shadows the input ${name}; rename one`);
|
|
26
31
|
const used = new Set(usesOf(archetype.name).map((entry) => entry.ref.name));
|
|
27
|
-
|
|
32
|
+
const names = new Set(shadowed.map(([, name]) => name));
|
|
33
|
+
for (const name of inputs.filter((input) => !used.has(input) && !names.has(input)))
|
|
28
34
|
fail(`${archetype.name} requires ${name}, which none of its modules names in dependencies`);
|
|
29
35
|
}
|
|
30
36
|
for (const site of sitesOf(archetypes)) {
|
|
@@ -33,6 +39,11 @@ export const checkInputs = (archetypes, pending, fail) => {
|
|
|
33
39
|
checkSite(archetypes, site, archetype, usesOf(archetype.name), fail);
|
|
34
40
|
}
|
|
35
41
|
};
|
|
42
|
+
const shadowsOf = (archetypes, named, inputs) => Object.values(archetypes)
|
|
43
|
+
.filter((archetype) => namedOf(archetype.name) === named)
|
|
44
|
+
.flatMap((archetype) => archetype.modules
|
|
45
|
+
.filter((module) => inputs.includes(module.name))
|
|
46
|
+
.map((module) => [`${archetype.name}.${module.name}`, module.name]));
|
|
36
47
|
const checkSite = (archetypes, { holder, module }, archetype, uses, fail) => {
|
|
37
48
|
const where = `${holder.name}.${module.name}`;
|
|
38
49
|
for (const name of archetype.requires.filter((input) => !module.inputs?.[input]))
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RuleSettingsData, RulesetData } from '../model/data.ts';
|
|
2
|
+
import { type Fail } from '../model/shared.ts';
|
|
3
|
+
export type ParseRules = (value: unknown, at: string) => RuleSettingsData | undefined;
|
|
4
|
+
export type ParseRuleset = (value: unknown, at: string) => RulesetData | undefined;
|
|
5
|
+
export interface Rulesets {
|
|
6
|
+
parse: ParseRuleset;
|
|
7
|
+
checkUsed(): void;
|
|
8
|
+
}
|
|
9
|
+
export declare const recommended = "warp:recommended";
|
|
10
|
+
export declare const rulesets: (named: unknown, shared: Readonly<Record<string, unknown>>, parseRules: ParseRules, fail: Fail) => Rulesets;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isRecord, list } from '../model/shared.js';
|
|
2
|
+
export const recommended = 'warp:recommended';
|
|
3
|
+
const rulesetKeys = ['extends', 'rules'];
|
|
4
|
+
export const rulesets = (named, shared, parseRules, fail) => {
|
|
5
|
+
const state = {
|
|
6
|
+
local: localRulesets(named, fail),
|
|
7
|
+
shared,
|
|
8
|
+
parseRules,
|
|
9
|
+
fail,
|
|
10
|
+
extended: new Set(),
|
|
11
|
+
};
|
|
12
|
+
return {
|
|
13
|
+
parse: (value, at) => (value === undefined ? undefined : flatten(state, value, at, [])),
|
|
14
|
+
checkUsed: () => {
|
|
15
|
+
for (const name of [...state.local.keys()].filter((name) => !state.extended.has(name)))
|
|
16
|
+
fail(`rulesets.${name}: nothing extends it; a named ruleset applies through a ruleset's extends`);
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const localRulesets = (value, fail) => {
|
|
21
|
+
if (value === undefined)
|
|
22
|
+
return new Map();
|
|
23
|
+
if (!isRecord(value)) {
|
|
24
|
+
fail('rulesets: expected rulesets by name, { strict: { rules: {...} } }');
|
|
25
|
+
return new Map();
|
|
26
|
+
}
|
|
27
|
+
for (const name of Object.keys(value).filter((name) => name.includes(':')))
|
|
28
|
+
fail(`rulesets.${name}: a name has no ':', which marks a plugin's ruleset`);
|
|
29
|
+
return new Map(Object.entries(value).filter(([name]) => !name.includes(':')));
|
|
30
|
+
};
|
|
31
|
+
const flatten = (state, value, at, seen) => {
|
|
32
|
+
const def = Array.isArray(value) ? { extends: value } : value === 'off' ? { rules: 'off' } : value;
|
|
33
|
+
if (!isRecord(def)) {
|
|
34
|
+
state.fail(`${at}: expected a ruleset, off, [${recommended}] or { extends: [${recommended}], rules: {...} }`);
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
for (const key of Object.keys(def).filter((key) => !rulesetKeys.includes(key)))
|
|
38
|
+
state.fail(`${at}: unknown key ${key}; a ruleset takes ${rulesetKeys.join(', ')}`);
|
|
39
|
+
const bases = [def.extends ?? []].flat().flatMap((base) => baseOf(state, base, `${at}.extends`, seen));
|
|
40
|
+
const own = state.parseRules(def.rules, `${at}.rules`);
|
|
41
|
+
return own ? [...bases, own] : bases;
|
|
42
|
+
};
|
|
43
|
+
const baseOf = (state, base, at, seen) => {
|
|
44
|
+
const local = typeof base === 'string' && state.local.has(base);
|
|
45
|
+
if (typeof base !== 'string' || !(local || Object.hasOwn(state.shared, base))) {
|
|
46
|
+
const known = [...Object.keys(state.shared), ...state.local.keys()];
|
|
47
|
+
state.fail(`${at}: '${String(base)}' is no ruleset; extend ${list(known, 'nothing')}`);
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
if (seen.includes(base)) {
|
|
51
|
+
state.fail(`${at}: ${[...seen, base].join(' extends ')}, a loop`);
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
state.extended.add(base);
|
|
55
|
+
return resolveNamed(state, base, local, seen);
|
|
56
|
+
};
|
|
57
|
+
const resolveNamed = (state, name, local, seen) => {
|
|
58
|
+
const def = local ? state.local.get(name) : state.shared[name];
|
|
59
|
+
return flatten(state, def, local ? `rulesets.${name}` : name, [...seen, name]);
|
|
60
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { ArchetypeData, RefData } from '
|
|
2
|
-
import { type Fail } from '
|
|
1
|
+
import type { ArchetypeData, RefData } from '../model/data.ts';
|
|
2
|
+
import { type Fail } from '../model/shared.ts';
|
|
3
|
+
import type { ParseRuleset } from './rulesets.ts';
|
|
3
4
|
export interface PendingRef {
|
|
4
5
|
ref: RefData;
|
|
5
6
|
where: string;
|
|
@@ -13,4 +14,4 @@ export interface Structure {
|
|
|
13
14
|
pending: PendingRef[];
|
|
14
15
|
}
|
|
15
16
|
export declare const rootName = "root";
|
|
16
|
-
export declare const parseStructure: (root: unknown, archetypes: unknown, fail: Fail) => Structure;
|
|
17
|
+
export declare const parseStructure: (root: unknown, archetypes: unknown, fail: Fail, ruleset: ParseRuleset) => Structure;
|