@ai-ecoverse/slicc-shared-web 1.15.0 → 1.16.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 CHANGED
@@ -8,9 +8,9 @@ Configuration shared by SLICC's web repos ([slicc-bios](https://github.com/ai-ec
8
8
  | `.github/workflows/node-ci.yml` | Reusable CI: `npm ci`, lint, Chromium's system libraries, integration tests, hotspots and the stack of every crash dump in the job summary, coverage/profiles/screenshots/crash dumps as artifacts. The browser itself comes from each repo's `pretest` | `jobs: { ci: { uses: ai-ecoverse/slicc-shared-web/.github/workflows/node-ci.yml@vX.Y.Z } }` |
9
9
  | `biome.json` | Formatter settings and slicc's strict linter: cognitive complexity ≤ 25, functions ≤ 150 lines, no unused variables or imports, no floating or misused promises, naming conventions, `import type`/`export type`. Test files under `test/` get slicc's test exemptions | `biome.json`: `{ "extends": ["@ai-ecoverse/slicc-shared-web/biome"] }` |
10
10
  | `tsconfig.json` | TypeScript base for Node's type stripping | `tsconfig.json`: `{ "extends": "@ai-ecoverse/slicc-shared-web/tsconfig.json", "include": ["src/**/*.ts"] }` |
11
- | `lefthook.yml` | Pre-commit hooks: Biome, typecheck, no comments, no unit tests in git, AGENTS.md, diff coverage | `lefthook.yml`: `extends: [node_modules/@ai-ecoverse/slicc-shared-web/lefthook.yml]` |
12
- | `mcr.config.mjs` | Unit-test coverage for JS and TS sources in `src/` (TS types are stripped first), written to `coverage/unit/lcov.info` | `test:unit`: `mcr -c node_modules/@ai-ecoverse/slicc-shared-web/mcr.config.mjs node --test 'test/unit/**/*.test.mjs'` |
13
- | `bin/` | `slicc-lint` runs every check below plus Biome and, if the repo has one, `typecheck`. `slicc-lint-comments` runs the [slicc no-comment checker](https://github.com/ai-ecoverse/slicc/tree/main/packages/dev-tools/no-comment) at a pinned commit, allowing AGENTS.md. `slicc-agents-md`, `slicc-no-unit-tests` and `slicc-diff-cover` complete the set. `slicc-minidump <file.dmp>...` prints a crash dump's stack, described [below](#crash-dumps) | `lint`: `slicc-lint`, and the hooks above |
11
+ | `lefthook.yml` | Pre-commit hooks: Biome, typecheck, no comments, no unit tests in git, AGENTS.md, and diff coverage over [only the unit tests the change reaches](#which-unit-tests-a-commit-runs) | `lefthook.yml`: `extends: [node_modules/@ai-ecoverse/slicc-shared-web/lefthook.yml]` |
12
+ | `mcr.config.mjs` | Unit-test coverage for JS and TS sources in `src/` (TS types are stripped first), written to `coverage/unit/lcov.info`. With `SLICC_UNIT_TESTS` set, `node --test` runs only those files ([below](#which-unit-tests-a-commit-runs)) | `test:unit`: `mcr -c node_modules/@ai-ecoverse/slicc-shared-web/mcr.config.mjs node --test 'test/unit/**/*.test.mjs'` |
13
+ | `bin/` | `slicc-lint` runs every check below plus Biome and, if the repo has one, `typecheck`. `slicc-lint-comments` runs the [slicc no-comment checker](https://github.com/ai-ecoverse/slicc/tree/main/packages/dev-tools/no-comment) at a pinned commit, allowing AGENTS.md. `slicc-agents-md`, `slicc-no-unit-tests` and `slicc-diff-cover` complete the set, and `slicc-unit-cover` is the diff-coverage hook. `slicc-minidump <file.dmp>...` prints a crash dump's stack, described [below](#crash-dumps) | `lint`: `slicc-lint`, and the hooks above |
14
14
  | `pnpmfile.mjs` | pnpm's counterpart to the Renovate preset: an `updateConfig` hook that adds `@ai-ecoverse/*` to `minimumReleaseAgeExclude`, so pnpm 12 doesn't hold back our own fresh releases (`ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION`) while third-party packages keep its age check | in a repo with a pnpm lockfile, as a [config dependency](https://pnpm.io/config-dependencies) in `pnpm-workspace.yaml`: `configDependencies: { '@ai-ecoverse/slicc-shared-web': X.Y.Z }` plus `pnpmfile: node_modules/.pnpm-config/@ai-ecoverse/slicc-shared-web/pnpmfile.mjs` |
15
15
  | `harness/` | The CDP integration-test harness, described [below](#integration-test-harness) | `import { launch } from '@ai-ecoverse/slicc-shared-web/harness'`, and `--test-global-setup=node_modules/@ai-ecoverse/slicc-shared-web/harness/global.mjs` |
16
16
 
@@ -27,6 +27,22 @@ The hooks expect two scripts in each repo: `test:unit`, which writes `coverage/u
27
27
  - No comments anywhere, and no `.md` files except README.md and AGENTS.md.
28
28
  - Agent guidance committed to a repo lives in AGENTS.md only, at most 1,000 characters per file. The repo has no CLAUDE.md, not even as a symlink, since Claude reads AGENTS.md. The check covers tracked and untracked files; gitignored local files are personal and stay out of it.
29
29
  - Unit tests stay out of git, in a gitignored `test/unit/`. The pre-commit hook requires them to execute every staged line in `src/`.
30
+
31
+ ## Which unit tests a commit runs
32
+
33
+ The diff-coverage hook, `slicc-unit-cover`, runs only the unit tests that cover the staged change, then `slicc-diff-cover` on their `coverage/unit/lcov.info`, so every staged line in `src/` still has to run:
34
+
35
+ - **What counts as changed:** the staged files (`git diff --cached --name-only`). Since `test/unit/` is gitignored, files in it count as changed when they were modified after HEAD last moved (the last commit, checkout or pull).
36
+ - **Which tests run:** every `*.test.*` file in `test/unit/` that is changed, or whose static imports reach a changed file. The import graph is parsed with [acorn](https://github.com/acornjs/acorn), TypeScript after Node's type stripping. It follows `import`, `export … from`, `import()`, `require()` and `new URL(…, import.meta.url)` with literal paths, relative or through the `paths` of `tsconfig.json` (and the files it extends). A path may leave out its extension or name `index`, and `.js` also finds `.ts`. Type-only imports don't count, and nothing is followed into `node_modules/`.
37
+ - **No code staged** (only docs, YAML, JSON or lockfiles): no unit tests and no diff coverage; the hook passes.
38
+ - **A staged file no unit test reaches:** no tests run, its lines show as uncovered, and diff coverage fails as before.
39
+ - **A file that won't parse:** one warning line, then every unit test.
40
+
41
+ The hook passes the list to the repo's own `test:unit` in `SLICC_UNIT_TESTS` (one path per line). A `--require` preload, which `slicc-unit-cover` and the shared `mcr.config.mjs` add to `NODE_OPTIONS`, makes the `node --test` process run the files on that list that its own patterns match, and none when the list is empty. Without the variable, `npm run test:unit` runs everything as before. To force a full run in the hook:
42
+
43
+ ```sh
44
+ SLICC_UNIT_ALL=1 git commit
45
+ ```
30
46
  - Integration tests are committed and run in CI.
31
47
 
32
48
  ## Integration-test harness
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from 'node:child_process';
3
+ import { existsSync } from 'node:fs';
4
+ import { join } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { code, ParseError, select } from '../unit/graph.mjs';
7
+ import { inject } from '../unit/inject.mjs';
8
+
9
+ const root = process.cwd();
10
+ const say = (line) => process.stderr.write(`slicc-unit-cover: ${line}\n`);
11
+
12
+ function git(...args) {
13
+ const run = spawnSync('git', args, { cwd: root, encoding: 'utf8' });
14
+ return run.status === 0 ? run.stdout : undefined;
15
+ }
16
+
17
+ function since() {
18
+ const moved = git('log', '-g', '-1', '--format=%gd', '--date=unix', 'HEAD')?.match(/\{(\d+)\}/);
19
+ const committed = git('log', '-1', '--format=%ct', 'HEAD')?.trim();
20
+ const seconds = Math.max(Number(moved?.[1] ?? 0), Number(committed || 0));
21
+ return seconds > 0 ? seconds * 1000 : undefined;
22
+ }
23
+
24
+ function run(command, args, env) {
25
+ const result = spawnSync(command, args, { cwd: root, env, stdio: 'inherit' });
26
+ if (result.error) throw result.error;
27
+ return result.status ?? 1;
28
+ }
29
+
30
+ function selection(staged) {
31
+ if (process.env.SLICC_UNIT_ALL === '1') return undefined;
32
+ try {
33
+ const { tests, total } = select({ root, changed: staged, since: since() });
34
+ say(`running ${tests.length} of ${total} unit test files`);
35
+ return tests;
36
+ } catch (error) {
37
+ if (!(error instanceof ParseError)) throw error;
38
+ say(
39
+ `could not build the import graph (${error.message.split('\n')[0]}), running every unit test`
40
+ );
41
+ return undefined;
42
+ }
43
+ }
44
+
45
+ const staged = (git('diff', '--cached', '--name-only', '--relative', '--no-renames', '-z') ?? '')
46
+ .split('\0')
47
+ .filter(Boolean);
48
+ if (process.env.SLICC_UNIT_ALL !== '1' && !staged.some((file) => code.test(file))) {
49
+ say('no code staged, skipping unit tests and diff coverage');
50
+ process.exit(0);
51
+ }
52
+
53
+ const env = { ...process.env };
54
+ const tests = selection(staged);
55
+ if (tests === undefined) delete env.SLICC_UNIT_TESTS;
56
+ else {
57
+ env.SLICC_UNIT_TESTS = tests.join('\n');
58
+ env.NODE_OPTIONS = inject(env.NODE_OPTIONS ?? '');
59
+ }
60
+ const status = run('npm', ['run', '--silent', 'test:unit'], env);
61
+ if (status !== 0) process.exit(status);
62
+ const local = join(root, 'node_modules', '.bin', 'slicc-diff-cover');
63
+ const cover = existsSync(local)
64
+ ? local
65
+ : fileURLToPath(new URL('slicc-diff-cover.sh', import.meta.url));
66
+ process.exit(run(cover, [], process.env));
package/lefthook.yml CHANGED
@@ -15,4 +15,4 @@ pre-commit:
15
15
  run: npx --no-install slicc-agents-md
16
16
  - name: diff coverage
17
17
  glob: "src/**.{js,mjs,ts}"
18
- run: npm run --silent test:unit && npx --no-install slicc-diff-cover
18
+ run: npx --no-install slicc-unit-cover
package/mcr.config.mjs CHANGED
@@ -1,4 +1,7 @@
1
1
  import { stripTypeScriptTypes } from 'node:module';
2
+ import { inject } from './unit/inject.mjs';
3
+
4
+ if (process.env.SLICC_UNIT_TESTS !== undefined) process.env.NODE_OPTIONS = inject();
2
5
 
3
6
  const strip = (entry) => {
4
7
  if (entry.url.endsWith('.ts')) entry.source = stripTypeScriptTypes(entry.source);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/slicc-shared-web",
3
- "version": "1.15.0",
3
+ "version": "1.16.0",
4
4
  "description": "Shared Renovate, Biome, TypeScript, lefthook and GitHub Actions configuration, plus the CDP integration-test harness, for SLICC's web repos",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -37,7 +37,8 @@
37
37
  "slicc-lint": "bin/slicc-lint.sh",
38
38
  "slicc-lint-comments": "bin/slicc-lint-comments.sh",
39
39
  "slicc-minidump": "bin/slicc-minidump.mjs",
40
- "slicc-no-unit-tests": "bin/slicc-no-unit-tests.sh"
40
+ "slicc-no-unit-tests": "bin/slicc-no-unit-tests.sh",
41
+ "slicc-unit-cover": "bin/slicc-unit-cover.mjs"
41
42
  },
42
43
  "files": [
43
44
  "bin",
@@ -47,7 +48,8 @@
47
48
  "lefthook.yml",
48
49
  "mcr.config.mjs",
49
50
  "tsconfig.json",
50
- "pnpmfile.mjs"
51
+ "pnpmfile.mjs",
52
+ "unit"
51
53
  ],
52
54
  "scripts": {
53
55
  "lint": "bin/slicc-lint.sh && shellcheck bin/*.sh",
@@ -66,7 +68,7 @@
66
68
  "semantic-release": "25.0.9"
67
69
  },
68
70
  "peerDependencies": {
69
- "@ai-ecoverse/slicc-cdp": ">=1.26.0",
71
+ "@ai-ecoverse/slicc-cdp": "*",
70
72
  "monocart-coverage-reports": ">=2.13.0",
71
73
  "playwright-core": ">=1.50.0"
72
74
  },
@@ -77,5 +79,8 @@
77
79
  "playwright-core": {
78
80
  "optional": true
79
81
  }
82
+ },
83
+ "dependencies": {
84
+ "acorn": "8.19.0"
80
85
  }
81
86
  }
package/unit/graph.mjs ADDED
@@ -0,0 +1,309 @@
1
+ import { readdirSync, readFileSync, statSync } from 'node:fs';
2
+ import { stripTypeScriptTypes } from 'node:module';
3
+ import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
4
+ import { parse } from 'acorn';
5
+
6
+ export const code = /\.(m|c)?(j|t)sx?$/;
7
+ const tests = /\.test\.(m|c)?(j|t)sx?$/;
8
+ const typed = /\.(m|c)?tsx?$/;
9
+ const swaps = { '.js': ['.ts', '.tsx'], '.mjs': ['.mts'], '.cjs': ['.cts'], '.jsx': ['.tsx'] };
10
+ const suffixes = ['.mjs', '.js', '.ts', '.tsx', '.mts', '.cjs', '.cts', '.jsx'];
11
+
12
+ export class ParseError extends Error {}
13
+
14
+ const isFile = (path) => {
15
+ try {
16
+ return statSync(path).isFile();
17
+ } catch {
18
+ return false;
19
+ }
20
+ };
21
+
22
+ function walk(dir, found = []) {
23
+ let entries;
24
+ try {
25
+ entries = readdirSync(dir, { withFileTypes: true });
26
+ } catch {
27
+ return found;
28
+ }
29
+ for (const entry of entries) {
30
+ if (entry.name === 'node_modules' || entry.name.startsWith('.')) continue;
31
+ const path = join(dir, entry.name);
32
+ if (entry.isDirectory()) walk(path, found);
33
+ else if (entry.isFile()) found.push(path);
34
+ }
35
+ return found;
36
+ }
37
+
38
+ function quiet(fn) {
39
+ const emit = process.emitWarning;
40
+ process.emitWarning = () => undefined;
41
+ try {
42
+ return fn();
43
+ } finally {
44
+ process.emitWarning = emit;
45
+ }
46
+ }
47
+
48
+ function strip(source) {
49
+ return quiet(() => {
50
+ try {
51
+ return stripTypeScriptTypes(source);
52
+ } catch {
53
+ return stripTypeScriptTypes(source, { mode: 'transform' });
54
+ }
55
+ });
56
+ }
57
+
58
+ function program(file) {
59
+ const raw = readFileSync(file, 'utf8');
60
+ const source = typed.test(file) ? strip(raw) : raw;
61
+ const options = { ecmaVersion: 'latest', allowHashBang: true, allowAwaitOutsideFunction: true };
62
+ try {
63
+ return parse(source, { ...options, sourceType: 'module' });
64
+ } catch (error) {
65
+ if (!/\.c(j|t)s$/.test(file)) throw error;
66
+ return parse(source, { ...options, sourceType: 'script', allowReturnOutsideFunction: true });
67
+ }
68
+ }
69
+
70
+ const literal = (node) => {
71
+ if (node?.type === 'Literal' && typeof node.value === 'string') return node.value;
72
+ if (node?.type === 'TemplateLiteral' && node.expressions.length === 0) {
73
+ return node.quasis[0].value.cooked;
74
+ }
75
+ return undefined;
76
+ };
77
+
78
+ const metaUrl = (node) =>
79
+ node?.type === 'MemberExpression' &&
80
+ node.object.type === 'MetaProperty' &&
81
+ node.property.name === 'url';
82
+
83
+ function specifier(node) {
84
+ switch (node.type) {
85
+ case 'ImportDeclaration':
86
+ case 'ExportAllDeclaration':
87
+ case 'ExportNamedDeclaration':
88
+ case 'ImportExpression':
89
+ return literal(node.source);
90
+ case 'CallExpression':
91
+ return node.callee.type === 'Identifier' && node.callee.name === 'require'
92
+ ? literal(node.arguments[0])
93
+ : undefined;
94
+ case 'NewExpression':
95
+ return node.callee.type === 'Identifier' &&
96
+ node.callee.name === 'URL' &&
97
+ metaUrl(node.arguments[1])
98
+ ? literal(node.arguments[0])
99
+ : undefined;
100
+ default:
101
+ return undefined;
102
+ }
103
+ }
104
+
105
+ function specifiers(ast) {
106
+ const found = [];
107
+ const stack = [ast];
108
+ while (stack.length > 0) {
109
+ const node = stack.pop();
110
+ const value = specifier(node);
111
+ if (value !== undefined) found.push(value);
112
+ for (const key of Object.keys(node)) {
113
+ const child = node[key];
114
+ if (Array.isArray(child)) {
115
+ for (const item of child) if (item && typeof item.type === 'string') stack.push(item);
116
+ } else if (child && typeof child.type === 'string') {
117
+ stack.push(child);
118
+ }
119
+ }
120
+ }
121
+ return found;
122
+ }
123
+
124
+ function candidates(target) {
125
+ const ext = extname(target);
126
+ const base = target.slice(0, target.length - ext.length);
127
+ return [
128
+ target,
129
+ ...(swaps[ext] ?? []).map((swap) => base + swap),
130
+ ...suffixes.map((suffix) => target + suffix),
131
+ ...suffixes.map((suffix) => join(target, `index${suffix}`)),
132
+ ];
133
+ }
134
+
135
+ function skip(text, at) {
136
+ if (text[at] !== '/') return at;
137
+ if (text[at + 1] === '/') {
138
+ const end = text.indexOf('\n', at);
139
+ return end === -1 ? text.length : end;
140
+ }
141
+ if (text[at + 1] === '*') {
142
+ const end = text.indexOf('*/', at + 2);
143
+ return end === -1 ? text.length : end + 2;
144
+ }
145
+ return at;
146
+ }
147
+
148
+ function quoted(text, at) {
149
+ let end = at + 1;
150
+ while (end < text.length && text[end] !== '"') end += text[end] === '\\' ? 2 : 1;
151
+ return end + 1;
152
+ }
153
+
154
+ export function jsonc(text) {
155
+ let out = '';
156
+ let comma = false;
157
+ let at = 0;
158
+ while (at < text.length) {
159
+ const next = skip(text, at);
160
+ if (next !== at) {
161
+ at = next;
162
+ continue;
163
+ }
164
+ const char = text[at];
165
+ if (/\s/.test(char)) {
166
+ at += 1;
167
+ continue;
168
+ }
169
+ if (comma && char !== '}' && char !== ']') out += ',';
170
+ comma = char === ',';
171
+ if (comma) {
172
+ at += 1;
173
+ continue;
174
+ }
175
+ const end = char === '"' ? quoted(text, at) : at + 1;
176
+ out += text.slice(at, end);
177
+ at = end;
178
+ }
179
+ return JSON.parse(comma ? `${out},` : out);
180
+ }
181
+
182
+ function readJson(path) {
183
+ try {
184
+ return jsonc(readFileSync(path, 'utf8'));
185
+ } catch {
186
+ return undefined;
187
+ }
188
+ }
189
+
190
+ function tsconfigPaths(root, file = join(root, 'tsconfig.json'), seen = new Set()) {
191
+ if (seen.has(file)) return [];
192
+ seen.add(file);
193
+ const config = readJson(file);
194
+ if (!config) return [];
195
+ const dir = dirname(file);
196
+ const parents = [config.extends ?? []].flat().flatMap((parent) => {
197
+ const path = parent.startsWith('.') ? resolve(dir, parent) : join(root, 'node_modules', parent);
198
+ const json = path.endsWith('.json') ? path : `${path}.json`;
199
+ return tsconfigPaths(root, json, seen);
200
+ });
201
+ const options = config.compilerOptions ?? {};
202
+ if (!options.paths) return parents;
203
+ const base = resolve(dir, options.baseUrl ?? '.');
204
+ const own = Object.entries(options.paths).map(([pattern, targets]) => ({
205
+ pattern,
206
+ targets: targets.map((target) => resolve(base, target)),
207
+ }));
208
+ return [...own, ...parents];
209
+ }
210
+
211
+ function aliased(spec, aliases) {
212
+ for (const { pattern, targets } of aliases) {
213
+ const star = pattern.indexOf('*');
214
+ if (star === -1) {
215
+ if (spec === pattern) return targets;
216
+ continue;
217
+ }
218
+ const head = pattern.slice(0, star);
219
+ const tail = pattern.slice(star + 1);
220
+ if (spec.length >= head.length + tail.length && spec.startsWith(head) && spec.endsWith(tail)) {
221
+ const middle = spec.slice(head.length, spec.length - tail.length);
222
+ return targets.map((target) => target.replace('*', middle));
223
+ }
224
+ }
225
+ return [];
226
+ }
227
+
228
+ function resolver(root) {
229
+ const aliases = tsconfigPaths(root);
230
+ return (from, spec) => {
231
+ let targets;
232
+ if (spec.startsWith('.')) targets = [resolve(dirname(from), spec)];
233
+ else if (isAbsolute(spec)) targets = [spec];
234
+ else targets = aliased(spec, aliases);
235
+ const missing = [];
236
+ for (const target of targets) {
237
+ const options = candidates(target.split(/[?#]/)[0]);
238
+ const hit = options.find(isFile);
239
+ if (hit) return hit.includes(`${sep}node_modules${sep}`) ? undefined : { hit };
240
+ missing.push(...options);
241
+ }
242
+ return { missing };
243
+ };
244
+ }
245
+
246
+ function graph(root, starts) {
247
+ const find = resolver(root);
248
+ const edges = new Map();
249
+ const queue = [...starts];
250
+ while (queue.length > 0) {
251
+ const file = queue.pop();
252
+ if (edges.has(file)) continue;
253
+ const out = [];
254
+ edges.set(file, out);
255
+ if (!code.test(file)) continue;
256
+ let ast;
257
+ try {
258
+ ast = program(file);
259
+ } catch (error) {
260
+ throw new ParseError(`${relative(root, file)}: ${error.message}`);
261
+ }
262
+ for (const spec of specifiers(ast)) {
263
+ const found = find(file, spec);
264
+ if (found?.hit) {
265
+ out.push(found.hit);
266
+ queue.push(found.hit);
267
+ } else if (found) {
268
+ out.push(...found.missing);
269
+ }
270
+ }
271
+ }
272
+ return edges;
273
+ }
274
+
275
+ function reaching(edges, changed) {
276
+ const back = new Map();
277
+ for (const [file, out] of edges) {
278
+ for (const target of out) {
279
+ if (!back.has(target)) back.set(target, []);
280
+ back.get(target).push(file);
281
+ }
282
+ }
283
+ const seen = new Set();
284
+ const queue = [...changed];
285
+ while (queue.length > 0) {
286
+ const file = queue.pop();
287
+ if (seen.has(file)) continue;
288
+ seen.add(file);
289
+ queue.push(...(back.get(file) ?? []));
290
+ }
291
+ return seen;
292
+ }
293
+
294
+ export function select({ root, changed, since }) {
295
+ const unit = join(root, 'test', 'unit');
296
+ const files = walk(unit);
297
+ const all = files.filter((file) => tests.test(file));
298
+ const fresh = files.filter((file) => since === undefined || statSync(file).mtimeMs > since);
299
+ const touched = new Set([...changed.map((file) => resolve(root, file)), ...fresh]);
300
+ const reached = reaching(graph(root, all), touched);
301
+ const posix = (file) => relative(root, file).split(sep).join('/');
302
+ return {
303
+ tests: all
304
+ .filter((file) => reached.has(file))
305
+ .map(posix)
306
+ .sort(),
307
+ total: all.length,
308
+ };
309
+ }
@@ -0,0 +1,9 @@
1
+ import { fileURLToPath } from 'node:url';
2
+
3
+ export const preload = fileURLToPath(new URL('select.cjs', import.meta.url));
4
+
5
+ export function inject(options = process.env.NODE_OPTIONS ?? '') {
6
+ if (options.includes(preload)) return options;
7
+ const flag = `--require ${/\s/.test(preload) ? `"${preload}"` : preload}`;
8
+ return options ? `${options} ${flag}` : flag;
9
+ }
package/unit/none.mjs ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+ const { isAbsolute, join, matchesGlob, normalize, relative } = require('node:path');
3
+
4
+ const key = Symbol.for('slicc.unit.select');
5
+ const list = process.env.SLICC_UNIT_TESTS;
6
+
7
+ const inside = (file, pattern) => {
8
+ const path = normalize(isAbsolute(pattern) ? relative(process.cwd(), pattern) : pattern);
9
+ const dir = path.replace(/\/+$/, '');
10
+ return file === path || file.startsWith(`${dir}/`) || matchesGlob(file, path);
11
+ };
12
+
13
+ if (
14
+ list !== undefined &&
15
+ !globalThis[key] &&
16
+ process.execArgv.includes('--test') &&
17
+ !process.env.NODE_TEST_CONTEXT
18
+ ) {
19
+ globalThis[key] = true;
20
+ const patterns = process.argv.slice(1);
21
+ const chosen = list
22
+ .split('\n')
23
+ .filter(Boolean)
24
+ .map((file) => normalize(file))
25
+ .filter((file) => patterns.length === 0 || patterns.some((pattern) => inside(file, pattern)));
26
+ process.argv.splice(
27
+ 1,
28
+ Number.POSITIVE_INFINITY,
29
+ ...(chosen.length > 0 ? chosen : [join(__dirname, 'none.mjs')])
30
+ );
31
+ }