@ai-ecoverse/slicc-shared-web 1.29.6 → 1.29.7
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/mcr.config.mjs +13 -4
- package/package.json +3 -2
- package/unit/graph.mjs +2 -22
- package/unit/inject.mjs +4 -2
- package/unit/transform.mjs +21 -0
- package/unit/typescript.mjs +47 -0
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`: `extends: [node_modules/@ai-ecoverse/slicc-shared-web/lefthook.yml]`, 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), 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), 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) | `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` |
|
|
@@ -227,7 +227,7 @@ The diff-coverage hook, `slicc-unit-cover`, runs only the unit tests that cover
|
|
|
227
227
|
- **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.
|
|
228
228
|
- **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.
|
|
229
229
|
- **A unit test for code this tree doesn't have:** a test whose imports reach a staged file but also a repo file that doesn't exist 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.
|
|
230
|
-
- **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/`.
|
|
230
|
+
- **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/`.
|
|
231
231
|
- **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.
|
|
232
232
|
- **No code staged** (only docs, YAML, JSON or lockfiles): no unit tests and no diff coverage; the hook passes.
|
|
233
233
|
- **A staged file no unit test reaches:** no tests run, its lines show as uncovered, and diff coverage fails as before.
|
package/mcr.config.mjs
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { relative, sep } from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { inject } from './unit/inject.mjs';
|
|
5
5
|
import { inSources, unitSources } from './unit/sources.mjs';
|
|
6
|
+
import { compile, inline, typed } from './unit/typescript.mjs';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
process.env.NODE_OPTIONS = inject();
|
|
8
9
|
|
|
9
10
|
const code = /\.(m|c)?(j|t)s$/;
|
|
10
|
-
const typed = /\.(m|c)?ts$/;
|
|
11
11
|
|
|
12
12
|
const strip = (entry) => {
|
|
13
|
-
if (typed.test(entry.url))
|
|
13
|
+
if (!typed.test(entry.url)) return;
|
|
14
|
+
const file = fileURLToPath(entry.url);
|
|
15
|
+
const output = compile(readFileSync(file, 'utf8'), file);
|
|
16
|
+
if (output.map === undefined) {
|
|
17
|
+
entry.source = output.code;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
entry.source = inline(output);
|
|
21
|
+
entry.sourceMap = output.map;
|
|
22
|
+
entry.fake = false;
|
|
14
23
|
};
|
|
15
24
|
|
|
16
25
|
const listed = unitSources();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-shared-web",
|
|
3
|
-
"version": "1.29.
|
|
3
|
+
"version": "1.29.7",
|
|
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",
|
|
@@ -86,6 +86,7 @@
|
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"acorn": "8.19.0"
|
|
89
|
+
"acorn": "8.19.0",
|
|
90
|
+
"amaro": "1.2.2"
|
|
90
91
|
}
|
|
91
92
|
}
|
package/unit/graph.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
-
import { stripTypeScriptTypes } from 'node:module';
|
|
3
2
|
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
4
3
|
import { parse } from 'acorn';
|
|
5
4
|
import { ALL, BODY, describe } from './exports.mjs';
|
|
5
|
+
import { compile } from './typescript.mjs';
|
|
6
6
|
|
|
7
7
|
export const code = /\.(m|c)?(j|t)sx?$/;
|
|
8
8
|
const tests = /\.test\.(m|c)?(j|t)sx?$/;
|
|
@@ -36,29 +36,9 @@ function walk(dir, found = []) {
|
|
|
36
36
|
return found;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
function quiet(fn) {
|
|
40
|
-
const emit = process.emitWarning;
|
|
41
|
-
process.emitWarning = () => undefined;
|
|
42
|
-
try {
|
|
43
|
-
return fn();
|
|
44
|
-
} finally {
|
|
45
|
-
process.emitWarning = emit;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function strip(source) {
|
|
50
|
-
return quiet(() => {
|
|
51
|
-
try {
|
|
52
|
-
return stripTypeScriptTypes(source);
|
|
53
|
-
} catch {
|
|
54
|
-
return stripTypeScriptTypes(source, { mode: 'transform' });
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
39
|
function program(file) {
|
|
60
40
|
const raw = readFileSync(file, 'utf8');
|
|
61
|
-
const source = typed.test(file) ?
|
|
41
|
+
const source = typed.test(file) ? compile(raw, file).code : raw;
|
|
62
42
|
const options = { ecmaVersion: 'latest', allowHashBang: true, allowAwaitOutsideFunction: true };
|
|
63
43
|
try {
|
|
64
44
|
return parse(source, { ...options, sourceType: 'module' });
|
package/unit/inject.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url';
|
|
2
2
|
|
|
3
3
|
export const preload = fileURLToPath(new URL('select.cjs', import.meta.url));
|
|
4
|
+
export const loader = new URL('transform.mjs', import.meta.url).href;
|
|
4
5
|
|
|
5
6
|
export function inject(options = process.env.NODE_OPTIONS ?? '') {
|
|
6
|
-
if (options.includes(preload)) return options;
|
|
7
7
|
const flag = `--require ${/\s/.test(preload) ? `"${preload}"` : preload}`;
|
|
8
|
-
|
|
8
|
+
const flags = [options.includes(preload) ? '' : flag];
|
|
9
|
+
if (!options.includes(loader)) flags.push(`--import ${loader}`);
|
|
10
|
+
return [options, ...flags].filter(Boolean).join(' ');
|
|
9
11
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { registerHooks } from 'node:module';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { compile, format, inline, typed } from './typescript.mjs';
|
|
5
|
+
|
|
6
|
+
registerHooks({
|
|
7
|
+
load(url, context, nextLoad) {
|
|
8
|
+
const { pathname } = new URL(url);
|
|
9
|
+
if (!url.startsWith('file:') || !typed.test(pathname) || pathname.includes('/node_modules/')) {
|
|
10
|
+
return nextLoad(url, context);
|
|
11
|
+
}
|
|
12
|
+
const file = fileURLToPath(url);
|
|
13
|
+
const output = compile(readFileSync(file, 'utf8'), file);
|
|
14
|
+
if (output.map === undefined) return nextLoad(url, context);
|
|
15
|
+
return {
|
|
16
|
+
format: format(file, context.format, output.code),
|
|
17
|
+
source: inline(output),
|
|
18
|
+
shortCircuit: true,
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createRequire, stripTypeScriptTypes } from 'node:module';
|
|
2
|
+
import { parse } from 'acorn';
|
|
3
|
+
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
|
|
6
|
+
export const typed = /\.(m|c)?ts$/;
|
|
7
|
+
|
|
8
|
+
function quiet(fn) {
|
|
9
|
+
const emit = process.emitWarning;
|
|
10
|
+
process.emitWarning = () => undefined;
|
|
11
|
+
try {
|
|
12
|
+
return fn();
|
|
13
|
+
} finally {
|
|
14
|
+
process.emitWarning = emit;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function compile(source, filename) {
|
|
19
|
+
try {
|
|
20
|
+
return { code: quiet(() => stripTypeScriptTypes(source)) };
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (error.code !== 'ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX') throw error;
|
|
23
|
+
}
|
|
24
|
+
const { transformSync } = require('amaro');
|
|
25
|
+
const { code, map } = transformSync(source, { mode: 'transform', sourceMap: true, filename });
|
|
26
|
+
return { code, map: { ...JSON.parse(map), sourcesContent: [source] } };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const inline = ({ code, map }) =>
|
|
30
|
+
`${code}\n//# sourceMappingURL=data:application/json;base64,${Buffer.from(JSON.stringify(map)).toString('base64')}\n`;
|
|
31
|
+
|
|
32
|
+
export function format(file, hint, code) {
|
|
33
|
+
if (/\.mts$/.test(file)) return 'module';
|
|
34
|
+
if (/\.cts$/.test(file)) return 'commonjs';
|
|
35
|
+
if (hint === 'module-typescript' || hint === 'commonjs-typescript') return hint.slice(0, -11);
|
|
36
|
+
try {
|
|
37
|
+
parse(code, {
|
|
38
|
+
ecmaVersion: 'latest',
|
|
39
|
+
sourceType: 'script',
|
|
40
|
+
allowHashBang: true,
|
|
41
|
+
allowReturnOutsideFunction: true,
|
|
42
|
+
});
|
|
43
|
+
return 'commonjs';
|
|
44
|
+
} catch {
|
|
45
|
+
return 'module';
|
|
46
|
+
}
|
|
47
|
+
}
|