@ai-ecoverse/slicc-shared-web 2.3.4 → 2.3.6
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 +2 -2
- package/package.json +2 -2
- package/unit/exports.mjs +3 -1
- package/unit/graph.mjs +25 -7
- package/unit/transform.mjs +27 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Configuration shared by SLICC's web repos ([slicc-bios](https://github.com/ai-ec
|
|
|
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
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`: the [fail-closed snippet below](#hooks-that-fail-closed), and `prepare`: `slicc-install-hooks` plus the committed `.githooks/` it writes ([one hooks directory per worktree](#one-hooks-directory-per-worktree)) |
|
|
12
|
-
| `mcr.config.mjs` | Unit-test coverage for JS and TS sources (`.js`, `.mjs`, `.cjs`, `.ts`, `.mts`, `.cts`) in `src/` or the `slicc.unitSources` directories (TS types are stripped first; TS that strip-only mode rejects, such as enums and parameter properties, is transformed with [amaro](https://github.com/nodejs/amaro) under the tests too, through an `--import` loader the config adds to `NODE_OPTIONS`, and its coverage is mapped back to the `.ts` lines), written to `coverage/unit/lcov.info`. Every source file is in it, tested or not, and paths are matched relative to the repo root, so a checkout under a dot-directory such as `~/.bb/` still reports untested files to diff coverage. 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'` |
|
|
12
|
+
| `mcr.config.mjs` | Unit-test coverage for JS and TS sources (`.js`, `.mjs`, `.cjs`, `.ts`, `.mts`, `.cts`) in `src/` or the `slicc.unitSources` directories (TS types are stripped first; TS that strip-only mode rejects, such as enums and parameter properties, is transformed with [amaro](https://github.com/nodejs/amaro) under the tests too, through an `--import` loader the config adds to `NODE_OPTIONS`, and its coverage is mapped back to the `.ts` lines; the same loader resolves a relative `./x.js`, `.mjs` or `.cjs` that isn't on disk to its `.ts`, `.mts` or `.cts` sibling, and imports a `.json` module, such as a package whose `main` is JSON, without `with { type: 'json' }`), written to `coverage/unit/lcov.info`. Every source file is in it, tested or not, and paths are matched relative to the repo root, so a checkout under a dot-directory such as `~/.bb/` still reports untested files to diff coverage. 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
13
|
| `bin/` | `slicc-lint` runs every check below plus Biome and, if the repo has one, `typecheck`. Every step prints its own `<step>: PASS …` line, and slicc-lint checks for it: a step that exits 0 without one fails the run with exit 70 (`slicc-lint: FAIL <step> (no PASS line from it)`), so a check that silently stops early can't pass. The last line, `slicc-lint: PASS`, comes only after every step has printed its PASS, and a gate can require it. `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 and [`# renovate:` annotations](#versions-pinned-in-workflow-files) in workflow and action files. `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). `slicc-memory-peak` prints the job's [memory peak](#memory-peak). `slicc-install-hooks` installs the hooks into [this worktree's own directory](#one-hooks-directory-per-worktree), and on Windows does nothing and exits 0, so `npm ci` works there | `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` |
|
|
@@ -236,7 +236,7 @@ The diff-coverage hook, `slicc-unit-cover`, runs only the unit tests that cover
|
|
|
236
236
|
|
|
237
237
|
- **Which directories are source:** `src/` by default, anywhere in the path, as before. A repo whose code lives elsewhere lists its directories in `package.json`: `"slicc": { "unitSources": ["extension", "six", "scripts"] }`, repo-relative, without `.` or `..` segments. `mcr.config.mjs` then collects coverage only from those directories, and the hook treats a staged file outside them as no code. A malformed list fails the hook.
|
|
238
238
|
- **What counts as changed:** the staged files (`git diff --cached --name-only`), and nothing else. `test/unit/` is gitignored, and repos that keep their unit tests in a store outside git sync the whole store into it before a commit, which brings in tests for code that is on other branches; so a unit test that is new or edited runs only when its imports reach a staged file, like any other. One that reaches nothing staged adds no coverage to the staged lines.
|
|
239
|
-
- **A unit test for code this tree doesn't have:** a test whose imports reach a staged file but also a
|
|
239
|
+
- **A unit test for code this tree doesn't have:** a test whose imports reach a staged file but also a code module under the sources that doesn't exist, isn't gitignored and isn't a staged deletion (a store test for a module on another branch) is skipped, and the hook names it in one line before the count. A missing `new URL(…, import.meta.url)` target, a missing non-code file such as `.wasm` or `.json`, and a missing file outside the sources or gitignored (a build output such as `dist/` or a bundled worker) don't skip the test.
|
|
240
240
|
- **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, or amaro's transform where stripping isn't enough. 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/`.
|
|
241
241
|
- **Barrels are followed by name:** a test that imports `{ a, b }` from a module follows only what provides `a` and `b`: `export { a } from`, `export { default as a } from`, an imported binding exported again, and `export * from`, by the target's own exports. `const { a, b } = await import('…')` with a literal path is followed by name too. A name the module declares itself follows all of that module's imports. A namespace import (`import * as`), any other `import()` (bound to a namespace, with `.then`, or destructured with a computed key or a rest element), a `require()`, and an `export *` that leads outside the repo or into CommonJS (any `.cjs` or `.cts` file) all count as the whole module.
|
|
242
242
|
- **No code staged** (only docs, YAML, JSON or lockfiles): no unit tests and no diff coverage; the hook passes.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-shared-web",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.6",
|
|
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",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"release": "semantic-release"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@ai-ecoverse/slicc-browsers": "1.
|
|
67
|
+
"@ai-ecoverse/slicc-browsers": "1.14.0",
|
|
68
68
|
"@ai-ecoverse/slicc-cdp": "1.30.20",
|
|
69
69
|
"@biomejs/biome": "2.5.15",
|
|
70
70
|
"lefthook": "2.2.2",
|
package/unit/exports.mjs
CHANGED
|
@@ -59,7 +59,9 @@ function dynamics(ast) {
|
|
|
59
59
|
continue;
|
|
60
60
|
}
|
|
61
61
|
const value = dynamic(node);
|
|
62
|
-
if (value !== undefined)
|
|
62
|
+
if (value !== undefined) {
|
|
63
|
+
found.push({ spec: value, names: [ALL], asset: node.type === 'NewExpression' });
|
|
64
|
+
}
|
|
63
65
|
for (const key of Object.keys(node)) {
|
|
64
66
|
const child = node[key];
|
|
65
67
|
if (Array.isArray(child)) {
|
package/unit/graph.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
1
2
|
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
2
3
|
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
3
4
|
import { parse } from 'acorn';
|
|
4
5
|
import { ALL, BODY, describe } from './exports.mjs';
|
|
6
|
+
import { inSources, unitSources } from './sources.mjs';
|
|
5
7
|
import { compile } from './typescript.mjs';
|
|
6
8
|
|
|
7
9
|
export const code = /\.(m|c)?(j|t)sx?$/;
|
|
@@ -226,12 +228,12 @@ function reacher(graph) {
|
|
|
226
228
|
const absent = [];
|
|
227
229
|
const seen = new Set();
|
|
228
230
|
const queue = [[start, BODY]];
|
|
229
|
-
const go = (file, spec, name) => {
|
|
231
|
+
const go = (file, spec, name, asset) => {
|
|
230
232
|
const found = find(file, spec);
|
|
231
233
|
if (found?.hit) queue.push([found.hit, name]);
|
|
232
234
|
else if (found) {
|
|
233
235
|
for (const path of found.missing) touched.add(path);
|
|
234
|
-
if (found.missing.length > 0) absent.push(found.missing);
|
|
236
|
+
if (found.missing.length > 0 && !asset) absent.push(found.missing);
|
|
235
237
|
}
|
|
236
238
|
};
|
|
237
239
|
while (queue.length > 0) {
|
|
@@ -242,9 +244,9 @@ function reacher(graph) {
|
|
|
242
244
|
touched.add(file);
|
|
243
245
|
const info = graph.load(file);
|
|
244
246
|
if (!info) continue;
|
|
245
|
-
for (const [next, wanted, spec] of step(info, name, file, context)) {
|
|
247
|
+
for (const [next, wanted, spec, asset] of step(info, name, file, context)) {
|
|
246
248
|
if (spec === undefined) queue.push([next, wanted]);
|
|
247
|
-
else go(next, spec, wanted);
|
|
249
|
+
else go(next, spec, wanted, asset);
|
|
248
250
|
}
|
|
249
251
|
}
|
|
250
252
|
return { touched, absent };
|
|
@@ -264,7 +266,9 @@ function step(info, name, file, context) {
|
|
|
264
266
|
if (name === BODY) {
|
|
265
267
|
return [
|
|
266
268
|
...info.imports.flatMap(({ spec, names }) => names.map((wanted) => [file, wanted, spec])),
|
|
267
|
-
...info.dynamic.flatMap(({ spec, names }) =>
|
|
269
|
+
...info.dynamic.flatMap(({ spec, names, asset }) =>
|
|
270
|
+
names.map((wanted) => [file, wanted, spec, asset])
|
|
271
|
+
),
|
|
268
272
|
];
|
|
269
273
|
}
|
|
270
274
|
if (info.whole) return [[file, BODY]];
|
|
@@ -282,15 +286,29 @@ function step(info, name, file, context) {
|
|
|
282
286
|
return starred(file, info, name, context);
|
|
283
287
|
}
|
|
284
288
|
|
|
289
|
+
function ignored(root) {
|
|
290
|
+
const memo = new Map();
|
|
291
|
+
return (path) => {
|
|
292
|
+
if (!memo.has(path)) {
|
|
293
|
+
const run = spawnSync('git', ['check-ignore', '-q', '--', path], { cwd: root });
|
|
294
|
+
memo.set(path, run.status === 0);
|
|
295
|
+
}
|
|
296
|
+
return memo.get(path);
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
285
300
|
export function select({ root, changed }) {
|
|
286
301
|
const all = walk(join(root, 'test', 'unit')).filter((file) => tests.test(file));
|
|
287
302
|
const staged = new Set(changed.map((file) => resolve(root, file)));
|
|
288
303
|
const reach = reacher(modules(root));
|
|
289
304
|
const posix = (file) => relative(root, file).split(sep).join('/');
|
|
305
|
+
const sources = unitSources(root);
|
|
306
|
+
const built = ignored(root);
|
|
290
307
|
const lacks = ([target, ...rest]) =>
|
|
291
|
-
|
|
292
|
-
|
|
308
|
+
(code.test(target) || extname(target) === '') &&
|
|
309
|
+
inSources(relative(root, target), root, sources) &&
|
|
293
310
|
!existsSync(target) &&
|
|
311
|
+
!built(target) &&
|
|
294
312
|
![target, ...rest].some((path) => staged.has(path));
|
|
295
313
|
const reached = [];
|
|
296
314
|
const elsewhere = [];
|
package/unit/transform.mjs
CHANGED
|
@@ -1,11 +1,37 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { registerHooks } from 'node:module';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { compile, format, inline, typed } from './typescript.mjs';
|
|
5
5
|
|
|
6
|
+
const swaps = { '.js': '.ts', '.mjs': '.mts', '.cjs': '.cts' };
|
|
7
|
+
const missing = new Set(['ERR_MODULE_NOT_FOUND', 'MODULE_NOT_FOUND']);
|
|
8
|
+
|
|
9
|
+
const sibling = (specifier, parentURL) => {
|
|
10
|
+
const ext = /^\.\.?\/.*(\.(m|c)?js)$/.exec(specifier)?.[1];
|
|
11
|
+
if (!ext || !parentURL?.startsWith('file:')) return undefined;
|
|
12
|
+
const swapped = specifier.slice(0, -ext.length) + swaps[ext];
|
|
13
|
+
return existsSync(fileURLToPath(new URL(swapped, parentURL))) ? swapped : undefined;
|
|
14
|
+
};
|
|
15
|
+
|
|
6
16
|
registerHooks({
|
|
17
|
+
resolve(specifier, context, nextResolve) {
|
|
18
|
+
try {
|
|
19
|
+
return nextResolve(specifier, context);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
const swapped = missing.has(error?.code) && sibling(specifier, context.parentURL);
|
|
22
|
+
if (!swapped) throw error;
|
|
23
|
+
return nextResolve(swapped, context);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
7
26
|
load(url, context, nextLoad) {
|
|
8
27
|
const { pathname } = new URL(url);
|
|
28
|
+
if (pathname.endsWith('.json') && context.importAttributes?.type === undefined) {
|
|
29
|
+
return nextLoad(url, {
|
|
30
|
+
...context,
|
|
31
|
+
format: 'json',
|
|
32
|
+
importAttributes: { ...context.importAttributes, type: 'json' },
|
|
33
|
+
});
|
|
34
|
+
}
|
|
9
35
|
if (!url.startsWith('file:') || !typed.test(pathname) || pathname.includes('/node_modules/')) {
|
|
10
36
|
return nextLoad(url, context);
|
|
11
37
|
}
|