@ai-ecoverse/slicc-shared-web 2.3.3 → 2.3.5
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 +5 -2
- package/bin/slicc-install-hooks.mjs +9 -0
- package/package.json +4 -4
- package/unit/transform.mjs +27 -1
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`: 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'` |
|
|
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; 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
|
+
| `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
|
|
|
@@ -224,6 +224,9 @@ and the PR commits the `.githooks/` directory that the first `npm install` write
|
|
|
224
224
|
- **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.
|
|
225
225
|
- **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.
|
|
226
226
|
- **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`.
|
|
227
|
+
- **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.
|
|
228
|
+
- **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.
|
|
229
|
+
- **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/`.
|
|
227
230
|
- **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.
|
|
228
231
|
- **Outside a git checkout** (a packed tarball, say) it does nothing and exits 0.
|
|
229
232
|
|
|
@@ -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/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.5",
|
|
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.
|
|
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.
|
|
57
|
+
"prepare": "node bin/slicc-install-hooks.mjs",
|
|
58
58
|
"lint": "bin/slicc-lint.sh && shellcheck bin/*.sh",
|
|
59
59
|
"pretest": "slicc-cdp install-browser",
|
|
60
60
|
"test": "SLICC_PROFILE=1 node --test --test-global-setup=harness/global.mjs test/integration/*.test.mjs && node test/integration/verify.mjs",
|
|
@@ -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/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
|
}
|