@ai-ecoverse/slicc-shared-web 1.29.6 → 1.29.8

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
@@ -9,8 +9,8 @@ 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'` |
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 |
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
+ | `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` |
16
16
 
@@ -217,6 +217,9 @@ and the PR commits the `.githooks/` directory that the first `npm install` write
217
217
  - **What it does:** sets one shared, relative `core.hooksPath` of `.githooks` (`<dir>/.githooks` for a package in a subdirectory of the repo), runs `lefthook install --force` with its output pointed at this worktree's gitignored `node_modules/.git-hooks/`, and writes a shim into `.githooks/` for every hook lefthook installed that has none yet. It never overwrites an existing shim. Git resolves a relative `core.hooksPath` against the top of the worktree a commit runs in, so each worktree runs its own committed shim, and the shim runs that worktree's own `node_modules/.git-hooks/<hook>`. No `extensions.worktreeConfig`, no per-worktree config, and `core.bare` stays where it is, so worktrees of a bare repo work too. Running it again changes nothing.
218
218
  - **Hooks are never shared:** whatever another worktree installs later, removing a worktree removes only its own hooks, and a moved checkout keeps working. Lefthook's own `postinstall` refuses the custom `core.hooksPath`, writes nothing and doesn't fail the install, and git never reads `.git/hooks/` once `core.hooksPath` is set, so `allowScripts` needs no entry for lefthook.
219
219
  - **A worktree that never ran `npm install`** fails every commit with `pre-commit: run npm install`, since its shim finds no `node_modules/.git-hooks/pre-commit`.
220
+ - **A checkout without the committed `.githooks/`** (a branch cut before the rollout PR) has no shim, so its commits run no hooks until it merges or rebases onto the rollout.
221
+ - **A hook type added to `lefthook.yml` later** needs `npm install` again in each worktree, and its new shim committed: lefthook skips its own hook sync while `core.hooksPath` is set.
222
+ - **Lefthook's `core.hooksPath is set locally` notice** on commits is expected. Don't follow its advice to unset `core.hooksPath`: that sends every worktree back to the shared `.git/hooks/`.
220
223
  - **Clones set up by the previous version** (2.1.1, 1.29.3), which set an absolute per-worktree `core.hooksPath` into a `worktree-hooks/` directory: it unsets that in the current worktree's `config.worktree`. It leaves `extensions.worktreeConfig` and the moved `core.bare` alone.
221
224
  - **Outside a git checkout** (a packed tarball, say) it does nothing and exits 0.
222
225
 
@@ -227,7 +230,7 @@ The diff-coverage hook, `slicc-unit-cover`, runs only the unit tests that cover
227
230
  - **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
231
  - **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
232
  - **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/`.
233
+ - **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
234
  - **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
235
  - **No code staged** (only docs, YAML, JSON or lockfiles): no unit tests and no diff coverage; the hook passes.
233
236
  - **A staged file no unit test reaches:** no tests run, its lines show as uncovered, and diff coverage fails as before.
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from 'node:child_process';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ if (process.platform === 'win32') process.exit(0);
6
+ const script = fileURLToPath(new URL('slicc-install-hooks.sh', import.meta.url));
7
+ const run = spawnSync('sh', [script, ...process.argv.slice(2)], { stdio: 'inherit' });
8
+ if (run.error) throw run.error;
9
+ process.exit(run.status ?? 1);
package/mcr.config.mjs CHANGED
@@ -1,16 +1,25 @@
1
- import { stripTypeScriptTypes } from 'node:module';
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
- if (process.env.SLICC_UNIT_TESTS !== undefined) process.env.NODE_OPTIONS = inject();
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)) entry.source = stripTypeScriptTypes(entry.source);
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.6",
3
+ "version": "1.29.8",
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",
@@ -34,7 +34,7 @@
34
34
  "bin": {
35
35
  "slicc-agents-md": "bin/slicc-agents-md.sh",
36
36
  "slicc-diff-cover": "bin/slicc-diff-cover.sh",
37
- "slicc-install-hooks": "bin/slicc-install-hooks.sh",
37
+ "slicc-install-hooks": "bin/slicc-install-hooks.mjs",
38
38
  "slicc-lint": "bin/slicc-lint.sh",
39
39
  "slicc-lint-comments": "bin/slicc-lint-comments.sh",
40
40
  "slicc-memory-peak": "bin/slicc-memory-peak.sh",
@@ -54,7 +54,7 @@
54
54
  "unit"
55
55
  ],
56
56
  "scripts": {
57
- "prepare": "bin/slicc-install-hooks.sh",
57
+ "prepare": "node bin/slicc-install-hooks.mjs",
58
58
  "lint": "bin/slicc-lint.sh && shellcheck bin/*.sh",
59
59
  "pretest": "playwright-core install --no-shell chromium",
60
60
  "test": "SLICC_PROFILE=1 node --test --test-global-setup=harness/global.mjs test/integration/*.test.mjs && node test/integration/verify.mjs",
@@ -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) ? strip(raw) : raw;
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
- return options ? `${options} ${flag}` : flag;
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
+ }