podlite 0.0.82 → 0.0.84
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/CHANGELOG.podlite +95 -0
- package/esm/assemble/async.d.ts +31 -0
- package/esm/assemble/async.js +113 -0
- package/esm/assemble/async.js.map +1 -0
- package/esm/assemble/files.d.ts +2 -0
- package/esm/assemble/files.js +77 -0
- package/esm/assemble/files.js.map +1 -0
- package/esm/assemble/index.d.ts +59 -0
- package/esm/assemble/index.js +1003 -0
- package/esm/assemble/index.js.map +1 -0
- package/esm/cli.js +160 -30
- package/esm/cli.js.map +1 -1
- package/esm/file-format.d.ts +3 -0
- package/esm/file-format.js +53 -0
- package/esm/file-format.js.map +1 -0
- package/esm/index.d.ts +4 -0
- package/esm/index.js +5 -2
- package/esm/index.js.map +1 -1
- package/esm/lint/config.js +6 -2
- package/esm/lint/config.js.map +1 -1
- package/esm/lint/engine.js +1 -1
- package/esm/lint/grammar/scan.d.ts +1 -1
- package/esm/lint/grammar/scan.js +7 -6
- package/esm/lint/grammar/scan.js.map +1 -1
- package/esm/lint/index.d.ts +1 -1
- package/esm/lint/index.js +14 -14
- package/esm/lint/index.js.map +1 -1
- package/esm/lint/loader.js +5 -4
- package/esm/lint/loader.js.map +1 -1
- package/esm/lint/mute.js +2 -1
- package/esm/lint/mute.js.map +1 -1
- package/esm/lint/parallel.js +1 -1
- package/esm/lint/rules/include-resolves.d.ts +6 -0
- package/esm/lint/rules/include-resolves.js +89 -0
- package/esm/lint/rules/include-resolves.js.map +1 -0
- package/esm/lint/rules/index.js +12 -10
- package/esm/lint/rules/index.js.map +1 -1
- package/esm/lint/rules/link-file-resolves.js +2 -2
- package/esm/lint/rules/link-not-empty.js +1 -1
- package/esm/lint/rules/link-target-resolves.js +1 -1
- package/esm/lint/rules/table-shape.js +7 -1
- package/esm/lint/rules/table-shape.js.map +1 -1
- package/esm/lint/types.d.ts +6 -1
- package/esm/lint/types.js.map +1 -1
- package/esm/lint/worker.js +1 -1
- package/esm/query-blocks.d.ts +6 -0
- package/esm/query-blocks.js +127 -0
- package/esm/query-blocks.js.map +1 -0
- package/esm/query.d.ts +2 -0
- package/esm/query.js +233 -26
- package/esm/query.js.map +1 -1
- package/esm/reader.d.ts +15 -0
- package/esm/reader.js +119 -0
- package/esm/reader.js.map +1 -0
- package/esm/refresh-tocs.d.ts +2 -0
- package/esm/refresh-tocs.js +52 -0
- package/esm/refresh-tocs.js.map +1 -0
- package/esm/resolve-includes.d.ts +27 -1
- package/esm/resolve-includes.js +80 -40
- package/esm/resolve-includes.js.map +1 -1
- package/esm/test/collect.d.ts +16 -0
- package/esm/test/collect.js +368 -0
- package/esm/test/collect.js.map +1 -0
- package/esm/test/documents.d.ts +47 -0
- package/esm/test/documents.js +211 -0
- package/esm/test/documents.js.map +1 -0
- package/esm/test/evaluate.d.ts +41 -0
- package/esm/test/evaluate.js +104 -0
- package/esm/test/evaluate.js.map +1 -0
- package/esm/test/formatters/json.d.ts +2 -0
- package/esm/test/formatters/json.js +11 -0
- package/esm/test/formatters/json.js.map +1 -0
- package/esm/test/formatters/text.d.ts +2 -0
- package/esm/test/formatters/text.js +104 -0
- package/esm/test/formatters/text.js.map +1 -0
- package/esm/test/index.d.ts +11 -0
- package/esm/test/index.js +19 -0
- package/esm/test/index.js.map +1 -0
- package/esm/test/resources.d.ts +5 -0
- package/esm/test/resources.js +45 -0
- package/esm/test/resources.js.map +1 -0
- package/esm/test/run.d.ts +52 -0
- package/esm/test/run.js +91 -0
- package/esm/test/run.js.map +1 -0
- package/esm/test/sources.d.ts +48 -0
- package/esm/test/sources.js +162 -0
- package/esm/test/sources.js.map +1 -0
- package/esm/test/types.d.ts +104 -0
- package/esm/test/types.js +3 -0
- package/esm/test/types.js.map +1 -0
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/assemble/async.d.ts +31 -0
- package/lib/assemble/async.js +118 -0
- package/lib/assemble/async.js.map +1 -0
- package/lib/assemble/files.d.ts +2 -0
- package/lib/assemble/files.js +81 -0
- package/lib/assemble/files.js.map +1 -0
- package/lib/assemble/index.d.ts +59 -0
- package/lib/assemble/index.js +1013 -0
- package/lib/assemble/index.js.map +1 -0
- package/lib/cli.js +154 -24
- package/lib/cli.js.map +1 -1
- package/lib/file-format.d.ts +3 -0
- package/lib/file-format.js +58 -0
- package/lib/file-format.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +22 -1
- package/lib/index.js.map +1 -1
- package/lib/lint/config.js +6 -2
- package/lib/lint/config.js.map +1 -1
- package/lib/lint/grammar/scan.d.ts +1 -1
- package/lib/lint/grammar/scan.js +7 -3
- package/lib/lint/grammar/scan.js.map +1 -1
- package/lib/lint/index.d.ts +1 -1
- package/lib/lint/index.js +3 -3
- package/lib/lint/index.js.map +1 -1
- package/lib/lint/loader.js +5 -4
- package/lib/lint/loader.js.map +1 -1
- package/lib/lint/mute.js +2 -1
- package/lib/lint/mute.js.map +1 -1
- package/lib/lint/rules/include-resolves.d.ts +6 -0
- package/lib/lint/rules/include-resolves.js +92 -0
- package/lib/lint/rules/include-resolves.js.map +1 -0
- package/lib/lint/rules/index.js +2 -0
- package/lib/lint/rules/index.js.map +1 -1
- package/lib/lint/rules/table-shape.js +7 -1
- package/lib/lint/rules/table-shape.js.map +1 -1
- package/lib/lint/types.d.ts +6 -1
- package/lib/lint/types.js.map +1 -1
- package/lib/query-blocks.d.ts +6 -0
- package/lib/query-blocks.js +136 -0
- package/lib/query-blocks.js.map +1 -0
- package/lib/query.d.ts +2 -0
- package/lib/query.js +232 -25
- package/lib/query.js.map +1 -1
- package/lib/reader.d.ts +15 -0
- package/lib/reader.js +124 -0
- package/lib/reader.js.map +1 -0
- package/lib/refresh-tocs.d.ts +2 -0
- package/lib/refresh-tocs.js +56 -0
- package/lib/refresh-tocs.js.map +1 -0
- package/lib/resolve-includes.d.ts +27 -1
- package/lib/resolve-includes.js +84 -40
- package/lib/resolve-includes.js.map +1 -1
- package/lib/test/collect.d.ts +16 -0
- package/lib/test/collect.js +374 -0
- package/lib/test/collect.js.map +1 -0
- package/lib/test/documents.d.ts +47 -0
- package/lib/test/documents.js +250 -0
- package/lib/test/documents.js.map +1 -0
- package/lib/test/evaluate.d.ts +41 -0
- package/lib/test/evaluate.js +142 -0
- package/lib/test/evaluate.js.map +1 -0
- package/lib/test/formatters/json.d.ts +2 -0
- package/lib/test/formatters/json.js +15 -0
- package/lib/test/formatters/json.js.map +1 -0
- package/lib/test/formatters/text.d.ts +2 -0
- package/lib/test/formatters/text.js +141 -0
- package/lib/test/formatters/text.js.map +1 -0
- package/lib/test/index.d.ts +11 -0
- package/lib/test/index.js +31 -0
- package/lib/test/index.js.map +1 -0
- package/lib/test/resources.d.ts +5 -0
- package/lib/test/resources.js +83 -0
- package/lib/test/resources.js.map +1 -0
- package/lib/test/run.d.ts +52 -0
- package/lib/test/run.js +95 -0
- package/lib/test/run.js.map +1 -0
- package/lib/test/sources.d.ts +48 -0
- package/lib/test/sources.js +200 -0
- package/lib/test/sources.js.map +1 -0
- package/lib/test/types.d.ts +104 -0
- package/lib/test/types.js +8 -0
- package/lib/test/types.js.map +1 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +28 -7
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { makeAttrs } from '@podlite/schema';
|
|
4
|
+
import { podlite } from '../index.js';
|
|
5
|
+
import { refreshTocs } from '../refresh-tocs.js';
|
|
6
|
+
import { readerFor, writtenTree } from '../reader.js';
|
|
7
|
+
import { formatOfFile } from '../file-format.js';
|
|
8
|
+
import { resolveIncludes } from '../resolve-includes.js';
|
|
9
|
+
import { err, ok } from './types.js';
|
|
10
|
+
const readerOf = (importPlugins) => () => {
|
|
11
|
+
const p = podlite({ importPlugins });
|
|
12
|
+
const read = readerFor(p);
|
|
13
|
+
return {
|
|
14
|
+
toTree: (text, recognition, diagnostics, config, file = '', format) => read(text, file, config, { recognition, diagnostics, format }),
|
|
15
|
+
written: (text, format) => writtenTree(p, text, format),
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/*
|
|
19
|
+
=begin pod :kind<export>
|
|
20
|
+
|
|
21
|
+
=head2 coreProfile
|
|
22
|
+
|
|
23
|
+
The profile the command uses: the plugins of this package, so a Markdown section is
|
|
24
|
+
read into blocks.
|
|
25
|
+
|
|
26
|
+
=end pod
|
|
27
|
+
*/
|
|
28
|
+
export const coreProfile = { name: 'core', reader: readerOf(true) };
|
|
29
|
+
// without the plugins of other packages: Markdown, diagrams, images
|
|
30
|
+
/*
|
|
31
|
+
=begin pod :kind<export>
|
|
32
|
+
|
|
33
|
+
=head2 schemaProfile
|
|
34
|
+
|
|
35
|
+
The parser alone, without plugins of other packages. A Markdown section stays one
|
|
36
|
+
block, so a test that reads into one does not hold under it.
|
|
37
|
+
|
|
38
|
+
=end pod
|
|
39
|
+
*/
|
|
40
|
+
export const schemaProfile = { name: 'schema', reader: readerOf(false) };
|
|
41
|
+
export const canonical = (file) => {
|
|
42
|
+
try {
|
|
43
|
+
return fs.realpathSync.native(file);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return path.resolve(file);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
// A problem that loses included content fails the input. An ambiguous address
|
|
50
|
+
// still brings a block, and so does a block placed as its file reads on its
|
|
51
|
+
// own; a =set with no target and a cycle reported for the assignments it lost
|
|
52
|
+
// leave the content as it was.
|
|
53
|
+
const isLosing = (problem) => problem.kind !== 'ambiguous' &&
|
|
54
|
+
problem.kind !== 'set-target' &&
|
|
55
|
+
problem.kind !== 'cycle' &&
|
|
56
|
+
problem.kind !== 'include-reading-differs' &&
|
|
57
|
+
problem.kind !== 'external';
|
|
58
|
+
const isObject = (value) => typeof value === 'object' && value !== null;
|
|
59
|
+
const isLocation = (value) => isObject(value) && isObject(value.start) && typeof value.start.offset === 'number';
|
|
60
|
+
// What in the assembled tree holds no data it should: a data table whose source
|
|
61
|
+
// the runner does not read, and a table whose data could not be had. A block an
|
|
62
|
+
// include left out does not count.
|
|
63
|
+
const unreadIn = (tree, place, lost, sections) => {
|
|
64
|
+
const found = [];
|
|
65
|
+
const visit = (node) => {
|
|
66
|
+
if (Array.isArray(node))
|
|
67
|
+
return node.forEach(visit);
|
|
68
|
+
if (!isObject(node))
|
|
69
|
+
return;
|
|
70
|
+
const location = isLocation(node.location) ? node.location : undefined;
|
|
71
|
+
// only a table reports lost data, and a block read out of a Markdown section
|
|
72
|
+
// counts its place from the section, so it matches nothing here
|
|
73
|
+
const table = node.type === 'block' && (node.name === 'table' || node.name === 'data-table') && !sections.has(node);
|
|
74
|
+
const message = table && location ? lost.get(node) : undefined;
|
|
75
|
+
if (message)
|
|
76
|
+
found.push({ source: place(node) ?? '', message, location });
|
|
77
|
+
if (node.type === 'block' && node.name === 'data-table') {
|
|
78
|
+
// the source is read the way the plugin reads it
|
|
79
|
+
const src = makeAttrs(node, {}).getFirstValue('src');
|
|
80
|
+
if (src !== undefined && src !== null && String(src) !== '') {
|
|
81
|
+
found.push({
|
|
82
|
+
source: String(src),
|
|
83
|
+
message: 'a data table reads a source the runner does not read',
|
|
84
|
+
location,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
visit(node.content);
|
|
89
|
+
};
|
|
90
|
+
visit(tree);
|
|
91
|
+
return found;
|
|
92
|
+
};
|
|
93
|
+
// The stages convert goes through: each file read and transformed on its own,
|
|
94
|
+
// then the includes, then the tables of contents of the document itself.
|
|
95
|
+
export const prepareDocument = (input, opts) => {
|
|
96
|
+
const { name, text, baseDir } = input;
|
|
97
|
+
const reader = opts.profile.reader();
|
|
98
|
+
const recognition = new Map();
|
|
99
|
+
const identify = (file) => (file === name ? name : canonical(file));
|
|
100
|
+
// Tables whose data could not be had. A file is read once for each place it
|
|
101
|
+
// is brought to, and the settings there decide whether its table is read, so
|
|
102
|
+
// the loss is kept with the table of that reading.
|
|
103
|
+
const lost = new WeakMap();
|
|
104
|
+
const markLost = (node, at) => {
|
|
105
|
+
if (Array.isArray(node))
|
|
106
|
+
return node.forEach(n => markLost(n, at));
|
|
107
|
+
if (!isObject(node))
|
|
108
|
+
return;
|
|
109
|
+
const message = isLocation(node.location) ? at.get(node.location.start.offset) : undefined;
|
|
110
|
+
if (message && node.type === 'block' && (node.name === 'table' || node.name === 'data-table')) {
|
|
111
|
+
lost.set(node, message);
|
|
112
|
+
}
|
|
113
|
+
markLost(node.content, at);
|
|
114
|
+
};
|
|
115
|
+
const sections = new WeakMap();
|
|
116
|
+
// marked per file before the includes: an address may bring in a block
|
|
117
|
+
// without the section around it
|
|
118
|
+
const markSections = (node, section) => {
|
|
119
|
+
if (Array.isArray(node))
|
|
120
|
+
return node.forEach(n => markSections(n, section));
|
|
121
|
+
if (!isObject(node))
|
|
122
|
+
return;
|
|
123
|
+
if (section)
|
|
124
|
+
sections.set(node, section);
|
|
125
|
+
const own = node.type === 'block' && (node.name === 'markdown' || node.name === 'Markdown') ? node : section;
|
|
126
|
+
markSections(node.content, own);
|
|
127
|
+
};
|
|
128
|
+
const toTree = (body, file, config, how) => {
|
|
129
|
+
const events = [];
|
|
130
|
+
const diagnostics = [];
|
|
131
|
+
const tree = reader.toTree(body, events, diagnostics, config, file, how?.format);
|
|
132
|
+
recognition.set(identify(file), events);
|
|
133
|
+
markSections(tree, undefined);
|
|
134
|
+
const at = new Map();
|
|
135
|
+
for (const d of diagnostics) {
|
|
136
|
+
if (d.code === 'table-source-unreadable' || d.code === 'table-source-deferred') {
|
|
137
|
+
at.set(d.location.start.offset, d.message);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (at.size)
|
|
141
|
+
markLost(tree, at);
|
|
142
|
+
return tree;
|
|
143
|
+
};
|
|
144
|
+
const carry = (from, to) => {
|
|
145
|
+
const section = sections.get(from);
|
|
146
|
+
if (section)
|
|
147
|
+
sections.set(to, section);
|
|
148
|
+
const message = lost.get(from);
|
|
149
|
+
if (message)
|
|
150
|
+
lost.set(to, message);
|
|
151
|
+
};
|
|
152
|
+
const origin = new WeakMap();
|
|
153
|
+
const errors = [];
|
|
154
|
+
const warnings = [];
|
|
155
|
+
const note = (problem) => {
|
|
156
|
+
;
|
|
157
|
+
(isLosing(problem) ? errors : warnings).push(problem);
|
|
158
|
+
};
|
|
159
|
+
try {
|
|
160
|
+
const resolved = resolveIncludes(toTree(text, name, undefined, { format: input.format }), {
|
|
161
|
+
baseDir,
|
|
162
|
+
parse: toTree,
|
|
163
|
+
file: name,
|
|
164
|
+
text,
|
|
165
|
+
self: input.self,
|
|
166
|
+
origin,
|
|
167
|
+
onCopy: carry,
|
|
168
|
+
provider: opts.provider,
|
|
169
|
+
onError: note,
|
|
170
|
+
onWarning: note,
|
|
171
|
+
});
|
|
172
|
+
const tree = refreshTocs(resolved, reader.written(text, input.format), name, origin, carry);
|
|
173
|
+
const place = (node) => {
|
|
174
|
+
const where = origin.get(node);
|
|
175
|
+
return where ? identify(where.file) : undefined;
|
|
176
|
+
};
|
|
177
|
+
return ok({
|
|
178
|
+
name,
|
|
179
|
+
text,
|
|
180
|
+
baseDir,
|
|
181
|
+
tree,
|
|
182
|
+
origin,
|
|
183
|
+
recognition,
|
|
184
|
+
identify,
|
|
185
|
+
errors,
|
|
186
|
+
warnings,
|
|
187
|
+
sections,
|
|
188
|
+
unread: unreadIn(tree, place, lost, sections),
|
|
189
|
+
profile: opts.profile.name,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
catch (e) {
|
|
193
|
+
return err(e instanceof Error ? e.message : String(e));
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
export const readDocument = (file) => {
|
|
197
|
+
try {
|
|
198
|
+
const text = fs.readFileSync(file, 'utf-8');
|
|
199
|
+
return ok({
|
|
200
|
+
name: canonical(file),
|
|
201
|
+
text,
|
|
202
|
+
baseDir: path.dirname(path.resolve(file)),
|
|
203
|
+
self: file,
|
|
204
|
+
format: formatOfFile(file),
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
catch (e) {
|
|
208
|
+
return err(e instanceof Error ? e.message : String(e));
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
//# sourceMappingURL=documents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.js","sourceRoot":"","sources":["../../src/test/documents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAS3C,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,OAAO,EAAE,eAAe,EAAiD,MAAM,qBAAqB,CAAA;AAEpG,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAkCjC,MAAM,QAAQ,GAAG,CAAC,aAAsB,EAAE,EAAE,CAAC,GAAW,EAAE;IACxD,MAAM,CAAC,GAAG,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC,CAAA;IACpC,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;IACzB,OAAO;QACL,MAAM,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,MAAM,EAAE,EAAE,CACpE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;QAChE,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,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,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC;YAC7C,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;SAC3B,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,GAAG,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;IACxD,CAAC;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAY,EAAgC,EAAE;IACzE,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAC3C,OAAO,EAAE,CAAC;YACR,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC;YACrB,IAAI;YACJ,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACzC,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,YAAY,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,GAAG,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;IACxD,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { SelectorError } from '@podlite/schema';
|
|
2
|
+
import type { Location } from '@podlite/schema';
|
|
3
|
+
import type { Profile } from './documents';
|
|
4
|
+
import type { AssertionInput, InputFailure, InputKind } from './sources';
|
|
5
|
+
import type { AssertDecl, Place, Result } from './types';
|
|
6
|
+
export type AssertionReason = {
|
|
7
|
+
kind: 'assertion-false';
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'unsupported-selector';
|
|
10
|
+
selector: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: 'operand-unresolved';
|
|
13
|
+
error: SelectorError['kind'];
|
|
14
|
+
message: string;
|
|
15
|
+
} | InputFailure;
|
|
16
|
+
export type Evidence = {
|
|
17
|
+
name: string;
|
|
18
|
+
file: string;
|
|
19
|
+
location?: Location;
|
|
20
|
+
precision?: 'section';
|
|
21
|
+
};
|
|
22
|
+
export type AssertionResult = {
|
|
23
|
+
index: number;
|
|
24
|
+
expression: string;
|
|
25
|
+
absent: boolean;
|
|
26
|
+
caption?: string;
|
|
27
|
+
place: Place;
|
|
28
|
+
held: boolean;
|
|
29
|
+
input?: {
|
|
30
|
+
kind: InputKind;
|
|
31
|
+
document: string;
|
|
32
|
+
source?: string;
|
|
33
|
+
base?: string;
|
|
34
|
+
fixture?: Place;
|
|
35
|
+
};
|
|
36
|
+
matches?: number;
|
|
37
|
+
evidence: Evidence[];
|
|
38
|
+
reason?: AssertionReason;
|
|
39
|
+
};
|
|
40
|
+
export declare const selectionOf: (expression: string) => string;
|
|
41
|
+
export declare const evaluateAssertion: (assert: AssertDecl, input: Result<AssertionInput, InputFailure>, profile: Profile) => AssertionResult;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import { parseSelector, runSelector, SelectorError } from '@podlite/schema';
|
|
3
|
+
import { splitSource } from './collect.js';
|
|
4
|
+
import { RESOURCE_ROOT } from './resources.js';
|
|
5
|
+
const isObject = (value) => typeof value === 'object' && value !== null;
|
|
6
|
+
const isLocation = (value) => isObject(value) && isObject(value.start) && typeof value.start.offset === 'number';
|
|
7
|
+
// A resource lives in no directory of the disk; it is shown by the name the
|
|
8
|
+
// test gave it.
|
|
9
|
+
const shownFile = (file) => {
|
|
10
|
+
const rel = path.relative(RESOURCE_ROOT, file);
|
|
11
|
+
return rel && !rel.startsWith('..') && !path.isAbsolute(rel) ? `resource:${rel.split(path.sep).join('/')}` : file;
|
|
12
|
+
};
|
|
13
|
+
export const selectionOf = (expression) => splitSource(expression).selection;
|
|
14
|
+
// A selection the implementation cannot read is not a selection of nothing:
|
|
15
|
+
// under :absent that would pass for a test that never looked.
|
|
16
|
+
const usable = (selection, profile) => selection === '' || (parseSelector(selection) !== undefined && (profile.supports?.(selection) ?? true));
|
|
17
|
+
const describeInput = (input) => ({
|
|
18
|
+
kind: input.kind,
|
|
19
|
+
document: input.document.name,
|
|
20
|
+
source: input.source,
|
|
21
|
+
base: input.base,
|
|
22
|
+
fixture: input.fixture?.place,
|
|
23
|
+
});
|
|
24
|
+
/*
|
|
25
|
+
=begin pod :kind<export>
|
|
26
|
+
|
|
27
|
+
=head2 evaluateAssertion
|
|
28
|
+
|
|
29
|
+
Runs one assertion over the input C<inputsFor> resolved for it. A selection the
|
|
30
|
+
profile cannot run and an input that could not be read both fail the assertion,
|
|
31
|
+
C<:absent> or not: neither is a document in which nothing matched.
|
|
32
|
+
|
|
33
|
+
=end pod
|
|
34
|
+
*/
|
|
35
|
+
export const evaluateAssertion = (assert, input, profile) => {
|
|
36
|
+
const base = {
|
|
37
|
+
index: assert.index,
|
|
38
|
+
expression: assert.expression,
|
|
39
|
+
absent: assert.absent,
|
|
40
|
+
caption: assert.caption,
|
|
41
|
+
place: assert.place,
|
|
42
|
+
};
|
|
43
|
+
const selection = selectionOf(assert.expression);
|
|
44
|
+
if (!usable(selection, profile)) {
|
|
45
|
+
return {
|
|
46
|
+
...base,
|
|
47
|
+
held: false,
|
|
48
|
+
input: input.ok === true ? describeInput(input.value) : undefined,
|
|
49
|
+
evidence: [],
|
|
50
|
+
reason: { kind: 'unsupported-selector', selector: selection },
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (input.ok === false)
|
|
54
|
+
return { ...base, held: false, evidence: [], reason: input.error };
|
|
55
|
+
const { document, target, readFile } = input.value;
|
|
56
|
+
let blocks;
|
|
57
|
+
try {
|
|
58
|
+
// the current document of the selection is the one the assertion is read against
|
|
59
|
+
const home = [{ file: document.name, node: document.tree }];
|
|
60
|
+
const found = selection === '' ? [target] : runSelector(selection, [{ file: document.name, node: target }], { home, readFile });
|
|
61
|
+
// a selection may hand back a document it was given; only blocks count
|
|
62
|
+
blocks = found.filter((item) => isObject(item) && !('file' in item));
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
if (e instanceof SelectorError) {
|
|
66
|
+
return {
|
|
67
|
+
...base,
|
|
68
|
+
held: false,
|
|
69
|
+
input: describeInput(input.value),
|
|
70
|
+
evidence: [],
|
|
71
|
+
reason: { kind: 'operand-unresolved', error: e.kind, message: e.message },
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
75
|
+
return {
|
|
76
|
+
...base,
|
|
77
|
+
held: false,
|
|
78
|
+
input: describeInput(input.value),
|
|
79
|
+
evidence: [],
|
|
80
|
+
reason: { kind: 'implementation-error', input: input.value.kind, message },
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const evidence = blocks.map((block) => {
|
|
84
|
+
const section = document.sections.get(block);
|
|
85
|
+
const placed = section ?? block;
|
|
86
|
+
const where = document.origin.get(placed);
|
|
87
|
+
return {
|
|
88
|
+
name: typeof block.name === 'string' ? block.name : String(block.type),
|
|
89
|
+
file: shownFile(where ? document.identify(where.file) : document.name),
|
|
90
|
+
location: isLocation(placed.location) ? placed.location : undefined,
|
|
91
|
+
...(section ? { precision: 'section' } : {}),
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
const held = assert.absent ? blocks.length === 0 : blocks.length > 0;
|
|
95
|
+
return {
|
|
96
|
+
...base,
|
|
97
|
+
held,
|
|
98
|
+
input: describeInput(input.value),
|
|
99
|
+
matches: blocks.length,
|
|
100
|
+
evidence,
|
|
101
|
+
reason: held ? undefined : { kind: 'assertion-false' },
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=evaluate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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AAC,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAA;IACpE,OAAO;QACL,GAAG,IAAI;QACP,IAAI;QACJ,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC;QACjC,OAAO,EAAE,MAAM,CAAC,MAAM;QACtB,QAAQ;QACR,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE;KACvD,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/test/formatters/json.ts"],"names":[],"mappings":"AAEA;;;;;;;;EAQE;AACF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAiB,EAAU,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAA"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
// a fixture is named after the file of its test and its place in it
|
|
3
|
+
const shown = (file, cwd) => {
|
|
4
|
+
const hash = file.indexOf('#');
|
|
5
|
+
const disk = hash === -1 ? file : file.slice(0, hash);
|
|
6
|
+
const rest = hash === -1 ? '' : file.slice(hash);
|
|
7
|
+
return path.isAbsolute(disk) ? `${path.relative(cwd, disk) || '.'}${rest}` : file;
|
|
8
|
+
};
|
|
9
|
+
const at = (place, cwd) => `${shown(place.file, cwd)}${place.location ? `:${place.location.start.line}` : ''}`;
|
|
10
|
+
const describeTestReason = (reason, cwd) => {
|
|
11
|
+
switch (reason.kind) {
|
|
12
|
+
case 'assertion':
|
|
13
|
+
return 'an assertion does not hold';
|
|
14
|
+
case 'no-assertions':
|
|
15
|
+
return 'the test has no assertion';
|
|
16
|
+
case 'malformed-test':
|
|
17
|
+
return `${reason.message} (${at(reason.place, cwd)})`;
|
|
18
|
+
case 'invalid-test':
|
|
19
|
+
return `${reason.message} (${at(reason.place, cwd)})`;
|
|
20
|
+
case 'unknown-child':
|
|
21
|
+
return `a block of an unknown name, ${reason.name}, is in the test (${at(reason.place, cwd)})`;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const describeAssertionReason = (reason, cwd) => {
|
|
25
|
+
switch (reason.kind) {
|
|
26
|
+
case 'assertion-false':
|
|
27
|
+
return 'does not hold';
|
|
28
|
+
case 'unsupported-selector':
|
|
29
|
+
return `the selection is not supported: ${reason.selector}`;
|
|
30
|
+
case 'operand-unresolved':
|
|
31
|
+
return `the operand of the selection does not resolve: ${reason.message}`;
|
|
32
|
+
case 'source-unavailable':
|
|
33
|
+
return `the source cannot be read: ${reason.source} (from ${shown(reason.base, cwd)})`;
|
|
34
|
+
case 'address-unresolved':
|
|
35
|
+
return `the address is not in the source: #${reason.address} in ${reason.source}`;
|
|
36
|
+
case 'source-unsupported':
|
|
37
|
+
return `the source is not supported: ${reason.source}, ${reason.message}`;
|
|
38
|
+
case 'input-error':
|
|
39
|
+
return `the ${reason.input} document lost content: ${reason.problems.map(p => p.message).join('; ')}`;
|
|
40
|
+
case 'implementation-error':
|
|
41
|
+
return `the implementation failed: ${reason.message}`;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const describeAssertion = (a, cwd) => {
|
|
45
|
+
const input = a.input ? `, against the ${a.input.kind} document ${shown(a.input.document, cwd)}` : '';
|
|
46
|
+
const count = a.matches === undefined ? '' : `, ${a.matches} ${a.matches === 1 ? 'match' : 'matches'}`;
|
|
47
|
+
const what = `${a.absent ? ':absent ' : ''}${a.expression}`;
|
|
48
|
+
const lines = [
|
|
49
|
+
` assertion ${a.index + 1} at ${at(a.place, cwd)}: ${what}`,
|
|
50
|
+
` ${a.held ? 'holds' : a.reason ? describeAssertionReason(a.reason, cwd) : 'does not hold'}${input}${count}`,
|
|
51
|
+
];
|
|
52
|
+
if (!a.held && a.absent) {
|
|
53
|
+
for (const e of a.evidence) {
|
|
54
|
+
const where = at({ file: e.file, location: e.location }, cwd);
|
|
55
|
+
lines.push(` found ${e.name} ${e.precision === 'section' ? `in the Markdown section at ${where}` : `at ${where}`}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return lines;
|
|
59
|
+
};
|
|
60
|
+
const describeTest = (t, cwd) => {
|
|
61
|
+
const name = t.id ?? t.caption ?? 'test';
|
|
62
|
+
const against = t.against ? ` against ${shown(t.against, cwd)}` : '';
|
|
63
|
+
const head = `${t.status.padEnd(7)} ${name} (${at(t.place, cwd)})${against}`;
|
|
64
|
+
if (t.status === 'passed')
|
|
65
|
+
return [head];
|
|
66
|
+
const reason = t.reason && t.reason.kind !== 'assertion' ? [` ${describeTestReason(t.reason, cwd)}`] : [];
|
|
67
|
+
return [head, ...reason, ...t.asserts.filter(a => !a.held).flatMap(a => describeAssertion(a, cwd))];
|
|
68
|
+
};
|
|
69
|
+
const describeProblem = (p, cwd) => {
|
|
70
|
+
switch (p.kind) {
|
|
71
|
+
case 'unreadable-source':
|
|
72
|
+
return `error: ${shown(p.source, cwd)}: cannot be read: ${p.message}`;
|
|
73
|
+
case 'implementation-error':
|
|
74
|
+
return `error: ${shown(p.source, cwd)}: the implementation failed: ${p.message}`;
|
|
75
|
+
case 'include': {
|
|
76
|
+
const step = p.problem.chain[p.problem.chain.length - 1];
|
|
77
|
+
const where = step ? at({ file: step.file, location: step.location }, cwd) : shown(p.source, cwd);
|
|
78
|
+
return `${p.severity}: ${where}: ${p.problem.message}`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
/*
|
|
83
|
+
=begin pod :kind<export>
|
|
84
|
+
|
|
85
|
+
=head2 formatText
|
|
86
|
+
|
|
87
|
+
The report as lines for a terminal: a line per test, the failed assertions of a
|
|
88
|
+
test that did not pass with the document each read, and a count. Paths are shown
|
|
89
|
+
relative to C<cwd>.
|
|
90
|
+
|
|
91
|
+
=end pod
|
|
92
|
+
*/
|
|
93
|
+
export const formatText = (report, cwd = process.cwd()) => {
|
|
94
|
+
const lines = [
|
|
95
|
+
...report.problems.map(p => describeProblem(p, cwd)),
|
|
96
|
+
...report.tests.flatMap(t => describeTest(t, cwd)),
|
|
97
|
+
];
|
|
98
|
+
const { tests, passed, failed, skipped } = report.counts;
|
|
99
|
+
const summary = tests === 0
|
|
100
|
+
? 'no tests were found: nothing was checked'
|
|
101
|
+
: `${tests} ${tests === 1 ? 'test' : 'tests'}: ${passed} passed, ${failed} failed, ${skipped} skipped`;
|
|
102
|
+
return `${[...lines, summary].join('\n')}\n`;
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/test/formatters/text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAK5B,oEAAoE;AACpE,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,GAAW,EAAU,EAAE;IAClD,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAC9B,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;IACrD,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAChD,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,GAAG,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;AACnF,CAAC,CAAA;AAED,MAAM,EAAE,GAAG,CAAC,K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,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;YACjG,OAAO,GAAG,CAAC,CAAC,QAAQ,KAAK,KAAK,KAAK,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;QACxD,CAAC;IACH,CAAC;AACH,CAAC,CAAA;AAED;;;;;;;;;;EAUE;AACF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAiB,EAAE,MAAc,OAAO,CAAC,GAAG,EAAE,EAAU,EAAE;IACnF,MAAM,KAAK,GAAG;QACZ,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QACpD,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;KACnD,CAAA;IACD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,CAAA;IACxD,MAAM,OAAO,GACX,KAAK,KAAK,CAAC;QACT,CAAC,CAAC,0CAA0C;QAC5C,CAAC,CAAC,GAAG,KAAK,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,KAAK,MAAM,YAAY,MAAM,YAAY,OAAO,UAAU,CAAA;IAC1G,OAAO,GAAG,CAAC,GAAG,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAA;AAC9C,CAAC,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { runTests } from './run';
|
|
2
|
+
export type { RunOptions, RunReport, TestResult, TestStatus } from './run';
|
|
3
|
+
export { collectTests, planRuns } from './collect';
|
|
4
|
+
export { inputsFor } from './sources';
|
|
5
|
+
export { evaluateAssertion } from './evaluate';
|
|
6
|
+
export type { AssertionResult } from './evaluate';
|
|
7
|
+
export { coreProfile, schemaProfile } from './documents';
|
|
8
|
+
export type { Profile } from './documents';
|
|
9
|
+
export { formatText } from './formatters/text';
|
|
10
|
+
export { formatJson } from './formatters/json';
|
|
11
|
+
export type { TestSource } from './types';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
=begin pod :kind<module>
|
|
3
|
+
|
|
4
|
+
=head1 podlite/test
|
|
5
|
+
|
|
6
|
+
Runs the tests written in Podlite files: C<=test> blocks with their C<=fixture>,
|
|
7
|
+
C<=assert> and C<=resource>. A run can also examine documents given from outside with
|
|
8
|
+
the same tests, which is how a set of assertions checks documents of a project.
|
|
9
|
+
|
|
10
|
+
=end pod
|
|
11
|
+
*/
|
|
12
|
+
export { runTests } from './run.js';
|
|
13
|
+
export { collectTests, planRuns } from './collect.js';
|
|
14
|
+
export { inputsFor } from './sources.js';
|
|
15
|
+
export { evaluateAssertion } from './evaluate.js';
|
|
16
|
+
export { coreProfile, schemaProfile } from './documents.js';
|
|
17
|
+
export { formatText } from './formatters/text.js';
|
|
18
|
+
export { formatJson } from './formatters/json.js';
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SourceProvider } from '../resolve-includes';
|
|
2
|
+
import type { ResourceDecl } from './types';
|
|
3
|
+
export declare const RESOURCE_ROOT: string;
|
|
4
|
+
export declare const resourceKey: (name: string) => string | undefined;
|
|
5
|
+
export declare const resourceProvider: (resources: ResourceDecl[]) => SourceProvider;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
// A directory no disk holds: a fixture reads its relative paths from here, and
|
|
3
|
+
// nothing outside the names a test declares is there to read.
|
|
4
|
+
export const RESOURCE_ROOT = path.resolve(path.sep, 'podlite-test-resources');
|
|
5
|
+
// The form a resource is looked up by; undefined for a name that would leave
|
|
6
|
+
// the directory of the test.
|
|
7
|
+
export const resourceKey = (name) => {
|
|
8
|
+
const slashed = name.replace(/\\/g, '/');
|
|
9
|
+
if (slashed.startsWith('/') || /^[a-zA-Z]:/.test(slashed))
|
|
10
|
+
return undefined;
|
|
11
|
+
const key = path.posix.normalize(slashed);
|
|
12
|
+
return key === '.' || key.startsWith('../') || key === '..' ? undefined : key;
|
|
13
|
+
};
|
|
14
|
+
const keyOfPath = (file) => {
|
|
15
|
+
const rel = path.relative(RESOURCE_ROOT, file);
|
|
16
|
+
if (!rel || path.isAbsolute(rel))
|
|
17
|
+
return undefined;
|
|
18
|
+
return resourceKey(rel.split(path.sep).join('/'));
|
|
19
|
+
};
|
|
20
|
+
export const resourceProvider = (resources) => {
|
|
21
|
+
const files = new Map();
|
|
22
|
+
for (const r of resources) {
|
|
23
|
+
const key = resourceKey(r.name);
|
|
24
|
+
if (key !== undefined && !files.has(key))
|
|
25
|
+
files.set(key, r.body);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
read: file => {
|
|
29
|
+
const key = keyOfPath(file);
|
|
30
|
+
return key === undefined ? null : files.get(key) ?? null;
|
|
31
|
+
},
|
|
32
|
+
list: (dir, deep) => {
|
|
33
|
+
const rel = path.relative(RESOURCE_ROOT, dir).split(path.sep).join('/');
|
|
34
|
+
if (rel.startsWith('..') || path.isAbsolute(rel))
|
|
35
|
+
return [];
|
|
36
|
+
const prefix = rel ? `${rel}/` : '';
|
|
37
|
+
return [...files.keys()]
|
|
38
|
+
.filter(key => key.startsWith(prefix))
|
|
39
|
+
.map(key => key.slice(prefix.length))
|
|
40
|
+
.filter(name => deep || !name.includes('/'))
|
|
41
|
+
.sort();
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/test/resources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAI5B,+EAA+E;AAC/E,8DAA8D;AAC9D,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,wBAAwB,CAAC,CAAA;AAE7E,6EAA6E;AAC7E,6BAA6B;AAC7B,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAsB,EAAE;IAC9D,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IACxC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,SAAS,CAAA;IAC3E,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IACzC,OAAO,GAAG,KAAK,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAA;AAC/E,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,CAAC,IAAY,EAAsB,EAAE;IACrD,MAAM,GAAG,GAAG,IAAI,CAA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