@ai-ecoverse/slicc-shared-web 1.16.0 → 1.18.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
@@ -4,13 +4,13 @@ Configuration shared by SLICC's web repos ([slicc-bios](https://github.com/ai-ec
4
4
 
5
5
  | File | What it is | How a repo uses it |
6
6
  |---|---|---|
7
- | `default.json` | Root Renovate preset: automerge on, one dependency per PR, exact pins, 7-day release age (14 for majors, 0 for vulnerability fixes and for our own `@ai-ecoverse` packages and `github.com/ai-ecoverse/*` Go modules, which also jump the PR queue), `<upstream>-slicc.<n>` prereleases (and only those, never past `latest`) for `@ai-ecoverse/fnox` and its `@ai-ecoverse/fnox-*` platform packages, including jumps to a new upstream fnox, one PR each, majors included, for the certified pairs `@ai-ecoverse/slicc-kernel` + `@ai-ecoverse/wasi-pnpm` ("kernel and pnpm") and `@ai-ecoverse/wasm-coreutils` + `@ai-ecoverse/wasm-procps` ("coreutils and procps"), `go mod tidy` after every Go module update (plus import-path rewrites on majors), and a manager for jsDelivr pins inside `src/` | `renovate.json`: `{ "extends": ["github>ai-ecoverse/slicc-shared-web"] }` |
7
+ | `default.json` | Root Renovate preset: automerge on, one dependency per PR, exact pins, 7-day release age (14 for majors, 0 for vulnerability fixes and for our own `@ai-ecoverse` packages and `github.com/ai-ecoverse/*` Go modules, which also jump the PR queue), `<upstream>-<build>` versions of our own `@ai-ecoverse` packages, such as `9.12.0-6`, which Renovate would otherwise skip as prereleases, never past the npm `latest` dist-tag (only `<upstream>-slicc.<n>` ones for `@ai-ecoverse/fnox` and its `@ai-ecoverse/fnox-*` platform packages), one PR each, majors included, for the certified pairs `@ai-ecoverse/slicc-kernel` + `@ai-ecoverse/wasi-pnpm` ("kernel and pnpm") and `@ai-ecoverse/wasm-coreutils` + `@ai-ecoverse/wasm-procps` ("coreutils and procps"), `go mod tidy` after every Go module update (plus import-path rewrites on majors), a manager for jsDelivr pins inside `src/`, and one for [`# renovate:` annotated pins in workflow files](#versions-pinned-in-workflow-files) | `renovate.json`: `{ "extends": ["github>ai-ecoverse/slicc-shared-web"] }` |
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
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
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 |
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 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) | `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
 
@@ -24,16 +24,53 @@ The hooks expect two scripts in each repo: `test:unit`, which writes `coverage/u
24
24
 
25
25
  ## Rules every repo follows
26
26
 
27
- - No comments anywhere, and no `.md` files except README.md and AGENTS.md.
27
+ - No comments anywhere, and no `.md` files except README.md and AGENTS.md. The one exception is the `# renovate:` line [above a pinned version in a workflow](#versions-pinned-in-workflow-files).
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
30
 
31
+ ## Versions pinned in workflow files
32
+
33
+ Renovate updates `uses:` actions and `package.json` on its own, but not a version written into a workflow's `env:`, a `with:` input or a `run:` line. The preset reads [Renovate's documented annotation](https://docs.renovatebot.com/modules/manager/regex/#advanced-capture) on the line above such a pin, in `.github/workflows/*.yml` and any `action.yml`:
34
+
35
+ ```yaml
36
+ # renovate: datasource=<npm|github-releases|github-tags|go|docker|…> depName=<name> [packageName=…] [versioning=…] [extractVersion=…] [registryUrl=…]
37
+ ```
38
+
39
+ The optional fields go in that order. The version is the first one on the next line after a `:`, an `=` or an `@`, starting with a digit or `v` and a digit. Without `versioning=` it is compared as `semver-coerced`, so `24` and `v2.12.2` work too. One example per shape:
40
+
41
+ ```yaml
42
+ env:
43
+ # renovate: datasource=github-releases depName=rhysd/actionlint extractVersion=^v(?<version>.+)$
44
+ ACTIONLINT: 1.7.7
45
+ ```
46
+
47
+ ```yaml
48
+ with:
49
+ # renovate: datasource=github-tags depName=nodejs/node versioning=node
50
+ node-version: 22.11.0
51
+ ```
52
+
53
+ ```yaml
54
+ # renovate: datasource=github-tags depName=owner/action
55
+ - uses: owner/action@v4.1.0
56
+ ```
57
+
58
+ ```yaml
59
+ # renovate: datasource=npm depName=playwright-core
60
+ - run: npm i -g playwright-core@1.63.0
61
+ ```
62
+
63
+ When a command needs the version more than once, as actionlint's download does, put it in `env:` once and use the variable, so a single annotated value moves. Renovate's `github-actions` manager already updates ordinary `uses:` refs, by tag or commit SHA, so annotate a `uses:` only when its ref should follow some other datasource.
64
+
65
+ Pin only where a fixed version is genuinely needed. When a workflow rolls forward to whatever is certified, as with `@ai-ecoverse/slicc-kernel` and its certified siblings, resolve "the newest certified" at run time instead (from the npm `latest` dist-tag, say) rather than pinning and annotating it.
66
+
31
67
  ## Which unit tests a commit runs
32
68
 
33
69
  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
70
 
35
71
  - **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
72
  - **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/`.
73
+ - **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.
37
74
  - **No code staged** (only docs, YAML, JSON or lockfiles): no unit tests and no diff coverage; the hook passes.
38
75
  - **A staged file no unit test reaches:** no tests run, its lines show as uncovered, and diff coverage fails as before.
39
76
  - **A file that won't parse:** one warning line, then every unit test.
@@ -13,9 +13,10 @@ if [ -z "$report" ]; then
13
13
  printf 'slicc-lint-comments: the no-comment checker produced no report\n' >&2
14
14
  exit 1
15
15
  fi
16
- rest=$(printf '%s\n' "$report" | grep -vE '^ok: |^(.+/)?AGENTS\.md: documentation file is not allowed' || true)
16
+ renovate='^(\.github/workflows/[^/:]+|(.+/)?action)\.ya?ml:[0-9]+: comment not allowed: # renovate: datasource=[a-z.-]+ depName=[^ ]+( packageName=[^ ]+)?( versioning=[^ ]+)?( extractVersion=[^ ]+)?( registryUrl=[^ ]+)?$'
17
+ rest=$(printf '%s\n' "$report" | grep -vE '^ok: |^(.+/)?AGENTS\.md: documentation file is not allowed' | grep -vE "$renovate" || true)
17
18
  if [ -n "$rest" ]; then
18
19
  printf '%s\n' "$rest" >&2
19
20
  exit 1
20
21
  fi
21
- printf 'ok: no comments, and no documentation besides README.md and AGENTS.md\n'
22
+ printf 'ok: no comments besides # renovate: annotations, and no documentation besides README.md and AGENTS.md\n'
package/default.json CHANGED
@@ -27,6 +27,19 @@
27
27
  "https://cdn\\.jsdelivr\\.net/npm/(?<depName>(?:@[^/@\\s'\"`]+/)?[^/@\\s'\"`]+)@(?<currentValue>\\d[^/\\s'\"`]*)"
28
28
  ],
29
29
  "datasourceTemplate": "npm"
30
+ },
31
+ {
32
+ "customType": "regex",
33
+ "description": "Versions pinned in workflow and action files, each annotated on the line above with # renovate: datasource=<datasource> depName=<name>, optionally followed by packageName=, versioning=, extractVersion= and registryUrl=. The version is the first one on the next line that follows a colon, an equals sign or an @, so it covers env: values, with: inputs, uses: refs and inline pkg@version installs.",
34
+ "managerFilePatterns": [
35
+ "/(^|/)\\.github/workflows/[^/]+\\.ya?ml$/",
36
+ "/(^|/)action\\.ya?ml$/"
37
+ ],
38
+ "matchStrings": [
39
+ "# renovate: datasource=(?<datasource>[a-z-.]+?) depName=(?<depName>[^\\s]+?)(?: packageName=(?<packageName>[^\\s]+?))?(?: versioning=(?<versioning>[^\\s]+?))?(?: extractVersion=(?<extractVersion>[^\\s]+?))?(?: registryUrl=(?<registryUrl>[^\\s]+?))?[ \\t]*\\r?\\n[^\\n]*?(?:[:=][ \\t]*[\"']?|@)(?<currentValue>v?\\d[^\\s\"'@,]*)"
40
+ ],
41
+ "versioningTemplate": "{{#if versioning}}{{{versioning}}}{{else}}semver-coerced{{/if}}",
42
+ "extractVersionTemplate": "{{#if extractVersion}}{{{extractVersion}}}{{/if}}"
30
43
  }
31
44
  ],
32
45
  "packageRules": [
@@ -58,10 +71,14 @@
58
71
  "prPriority": 10
59
72
  },
60
73
  {
61
- "description": "fnox-build publishes @ai-ecoverse/fnox and its platform packages only as <upstream fnox version>-slicc.<build> prereleases, with latest pointing at the newest. Renovate skips prereleases by default, and from 1.39.0-slicc.1 would only offer 1.39.0-slicc.2, never 1.40.0-slicc.1, so allow unstable versions, but only -slicc.N ones and never past latest.",
62
- "matchPackageNames": ["@ai-ecoverse/fnox", "@ai-ecoverse/fnox-*"],
74
+ "description": "Our own packages version their builds as <upstream version>-<build>, such as wasm-coreutils 9.12.0-6 or wasm-tls-engine 3.6.7-1, which Renovate reads as prereleases and by default never offers, so a pin like 3.6.5-1 never moves. Allow unstable versions, but never past the npm latest dist-tag, which homescoop moves only to certified builds, so a build that is only on stage or next is not offered.",
75
+ "matchPackageNames": ["@ai-ecoverse/{/,}**"],
63
76
  "ignoreUnstable": false,
64
- "respectLatest": true,
77
+ "respectLatest": true
78
+ },
79
+ {
80
+ "description": "fnox-build publishes @ai-ecoverse/fnox and its platform packages only as <upstream fnox version>-slicc.<build> prereleases, with latest pointing at the newest; take only the -slicc.N ones.",
81
+ "matchPackageNames": ["@ai-ecoverse/fnox", "@ai-ecoverse/fnox-*"],
65
82
  "allowedVersions": "/-slicc\\.\\d+$/"
66
83
  },
67
84
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/slicc-shared-web",
3
- "version": "1.16.0",
3
+ "version": "1.18.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",
@@ -0,0 +1,167 @@
1
+ export const ALL = '*';
2
+ export const BODY = '\0body';
3
+
4
+ const literal = (node) => {
5
+ if (node?.type === 'Literal' && typeof node.value === 'string') return node.value;
6
+ if (node?.type === 'TemplateLiteral' && node.expressions.length === 0) {
7
+ return node.quasis[0].value.cooked;
8
+ }
9
+ return undefined;
10
+ };
11
+
12
+ const named = (node) => (node.type === 'Literal' ? String(node.value) : node.name);
13
+
14
+ const metaUrl = (node) =>
15
+ node?.type === 'MemberExpression' &&
16
+ node.object.type === 'MetaProperty' &&
17
+ node.property.name === 'url';
18
+
19
+ function dynamic(node) {
20
+ switch (node.type) {
21
+ case 'ImportExpression':
22
+ return literal(node.source);
23
+ case 'CallExpression':
24
+ return node.callee.type === 'Identifier' && node.callee.name === 'require'
25
+ ? literal(node.arguments[0])
26
+ : undefined;
27
+ case 'NewExpression':
28
+ return node.callee.type === 'Identifier' &&
29
+ node.callee.name === 'URL' &&
30
+ metaUrl(node.arguments[1])
31
+ ? literal(node.arguments[0])
32
+ : undefined;
33
+ default:
34
+ return undefined;
35
+ }
36
+ }
37
+
38
+ function picked(node) {
39
+ if (node.type !== 'VariableDeclarator' || node.id.type !== 'ObjectPattern') return undefined;
40
+ const awaited = node.init?.type === 'AwaitExpression' ? node.init.argument : undefined;
41
+ if (awaited?.type !== 'ImportExpression') return undefined;
42
+ const spec = literal(awaited.source);
43
+ const props = node.id.properties;
44
+ if (spec === undefined || props.some((prop) => prop.type !== 'Property' || prop.computed)) {
45
+ return undefined;
46
+ }
47
+ return { spec, names: props.length > 0 ? props.map((prop) => named(prop.key)) : [BODY] };
48
+ }
49
+
50
+ function dynamics(ast) {
51
+ const found = [];
52
+ const stack = [ast];
53
+ while (stack.length > 0) {
54
+ const node = stack.pop();
55
+ const pick = picked(node);
56
+ if (pick) {
57
+ found.push(pick);
58
+ stack.push(node.id);
59
+ continue;
60
+ }
61
+ const value = dynamic(node);
62
+ if (value !== undefined) found.push({ spec: value, names: [ALL] });
63
+ for (const key of Object.keys(node)) {
64
+ const child = node[key];
65
+ if (Array.isArray(child)) {
66
+ for (const item of child) if (item && typeof item.type === 'string') stack.push(item);
67
+ } else if (child && typeof child.type === 'string') {
68
+ stack.push(child);
69
+ }
70
+ }
71
+ }
72
+ return found;
73
+ }
74
+
75
+ function bound(pattern, out = []) {
76
+ if (!pattern) return out;
77
+ switch (pattern.type) {
78
+ case 'Identifier':
79
+ out.push(pattern.name);
80
+ break;
81
+ case 'ObjectPattern':
82
+ for (const property of pattern.properties) bound(property.value ?? property.argument, out);
83
+ break;
84
+ case 'ArrayPattern':
85
+ for (const element of pattern.elements) bound(element, out);
86
+ break;
87
+ case 'RestElement':
88
+ bound(pattern.argument, out);
89
+ break;
90
+ case 'AssignmentPattern':
91
+ bound(pattern.left, out);
92
+ break;
93
+ default:
94
+ break;
95
+ }
96
+ return out;
97
+ }
98
+
99
+ function declared(declaration) {
100
+ if (declaration.type === 'VariableDeclaration') {
101
+ return declaration.declarations.flatMap((item) => bound(item.id));
102
+ }
103
+ return declaration.id ? [declaration.id.name] : [];
104
+ }
105
+
106
+ function imported(node, info) {
107
+ const names = new Set();
108
+ for (const item of node.specifiers) {
109
+ let name = ALL;
110
+ if (item.type === 'ImportDefaultSpecifier') name = 'default';
111
+ else if (item.type === 'ImportSpecifier') name = named(item.imported);
112
+ names.add(name);
113
+ info.bindings.set(item.local.name, { spec: node.source.value, name });
114
+ }
115
+ info.imports.push({ spec: node.source.value, names: names.size > 0 ? [...names] : [BODY] });
116
+ }
117
+
118
+ function exported(node, info) {
119
+ if (node.declaration) {
120
+ for (const name of declared(node.declaration)) info.locals.add(name);
121
+ return;
122
+ }
123
+ for (const item of node.specifiers) {
124
+ const local = named(item.local);
125
+ const name = named(item.exported);
126
+ if (node.source) info.reexports.set(name, { spec: node.source.value, name: local });
127
+ else info.aliases.set(name, local);
128
+ }
129
+ }
130
+
131
+ function exportedDefault(node, info) {
132
+ const { declaration } = node;
133
+ if (declaration.type === 'Identifier') info.aliases.set('default', declaration.name);
134
+ else info.locals.add('default');
135
+ }
136
+
137
+ const handlers = {
138
+ ImportDeclaration: imported,
139
+ ExportNamedDeclaration: exported,
140
+ ExportDefaultDeclaration: exportedDefault,
141
+ ExportAllDeclaration: (node, info) => {
142
+ if (node.exported) {
143
+ info.reexports.set(named(node.exported), { spec: node.source.value, name: ALL });
144
+ } else {
145
+ info.stars.push(node.source.value);
146
+ }
147
+ },
148
+ };
149
+
150
+ export function describe(ast, commonjs = false) {
151
+ const info = {
152
+ whole: commonjs || ast.sourceType !== 'module',
153
+ imports: [],
154
+ bindings: new Map(),
155
+ aliases: new Map(),
156
+ locals: new Set(),
157
+ reexports: new Map(),
158
+ stars: [],
159
+ dynamic: dynamics(ast),
160
+ };
161
+ for (const node of ast.body) handlers[node.type]?.(node, info);
162
+ for (const [name, local] of info.aliases) {
163
+ if (info.bindings.has(local)) info.reexports.set(name, info.bindings.get(local));
164
+ else info.locals.add(name);
165
+ }
166
+ return info;
167
+ }
package/unit/graph.mjs CHANGED
@@ -2,6 +2,7 @@ import { readdirSync, readFileSync, statSync } from 'node:fs';
2
2
  import { stripTypeScriptTypes } from 'node:module';
3
3
  import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
4
4
  import { parse } from 'acorn';
5
+ import { ALL, BODY, describe } from './exports.mjs';
5
6
 
6
7
  export const code = /\.(m|c)?(j|t)sx?$/;
7
8
  const tests = /\.test\.(m|c)?(j|t)sx?$/;
@@ -67,60 +68,6 @@ function program(file) {
67
68
  }
68
69
  }
69
70
 
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
71
  function candidates(target) {
125
72
  const ext = extname(target);
126
73
  const base = target.slice(0, target.length - ext.length);
@@ -243,52 +190,112 @@ function resolver(root) {
243
190
  };
244
191
  }
245
192
 
246
- function graph(root, starts) {
193
+ function modules(root) {
247
194
  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}`);
195
+ const cache = new Map();
196
+ const load = (file) => {
197
+ if (!cache.has(file)) {
198
+ let info;
199
+ if (code.test(file)) {
200
+ try {
201
+ info = describe(program(file), /\.c(j|t)s$/.test(file));
202
+ } catch (error) {
203
+ throw new ParseError(`${relative(root, file)}: ${error.message}`);
204
+ }
205
+ }
206
+ cache.set(file, info);
261
207
  }
262
- for (const spec of specifiers(ast)) {
208
+ return cache.get(file);
209
+ };
210
+ return { find, load };
211
+ }
212
+
213
+ function provider({ find, load }) {
214
+ const memo = new Map();
215
+ const provides = (file, name, stack = new Set()) => {
216
+ const key = `${file}\0${name}`;
217
+ if (memo.has(key)) return memo.get(key);
218
+ if (stack.has(key)) return false;
219
+ stack.add(key);
220
+ const info = load(file);
221
+ let answer;
222
+ if (!info || info.whole) answer = undefined;
223
+ else if (info.locals.has(name) || info.reexports.has(name)) answer = true;
224
+ else answer = starred(file, info, name, stack);
225
+ memo.set(key, answer);
226
+ return answer;
227
+ };
228
+ const starred = (file, info, name, stack) => {
229
+ let answer = false;
230
+ for (const spec of info.stars) {
231
+ const hit = find(file, spec)?.hit;
232
+ const own = hit ? provides(hit, name, stack) : undefined;
233
+ if (own === undefined) return undefined;
234
+ answer ||= own;
235
+ }
236
+ return answer;
237
+ };
238
+ return provides;
239
+ }
240
+
241
+ function reacher(graph) {
242
+ const { find } = graph;
243
+ const context = { find, provides: provider(graph) };
244
+ return (start) => {
245
+ const touched = new Set();
246
+ const seen = new Set();
247
+ const queue = [[start, BODY]];
248
+ const go = (file, spec, name) => {
263
249
  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);
250
+ if (found?.hit) queue.push([found.hit, name]);
251
+ else if (found) for (const path of found.missing) touched.add(path);
252
+ };
253
+ while (queue.length > 0) {
254
+ const [file, name] = queue.pop();
255
+ const key = `${file}\0${name}`;
256
+ if (seen.has(key)) continue;
257
+ seen.add(key);
258
+ touched.add(file);
259
+ const info = graph.load(file);
260
+ if (!info) continue;
261
+ for (const [next, wanted, spec] of step(info, name, file, context)) {
262
+ if (spec === undefined) queue.push([next, wanted]);
263
+ else go(next, spec, wanted);
269
264
  }
270
265
  }
271
- }
272
- return edges;
266
+ return touched;
267
+ };
273
268
  }
274
269
 
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
- }
270
+ function starred(file, info, name, { find, provides }) {
271
+ const targets = info.stars.map((spec) => find(file, spec)?.hit);
272
+ if (targets.some((target) => !target)) return [[file, ALL]];
273
+ const answers = targets.map((target) => provides(target, name));
274
+ if (answers.some((answer) => answer === undefined)) return [[file, ALL]];
275
+ const owners = targets.filter((_, index) => answers[index]);
276
+ return owners.length > 0 ? owners.map((target) => [target, name]) : [[file, ALL]];
277
+ }
278
+
279
+ function step(info, name, file, context) {
280
+ if (name === BODY) {
281
+ return [
282
+ ...info.imports.flatMap(({ spec, names }) => names.map((wanted) => [file, wanted, spec])),
283
+ ...info.dynamic.flatMap(({ spec, names }) => names.map((wanted) => [file, wanted, spec])),
284
+ ];
282
285
  }
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) ?? []));
286
+ if (info.whole) return [[file, BODY]];
287
+ if (name === ALL) {
288
+ return [
289
+ [file, BODY],
290
+ ...[...info.reexports.values()].map(({ spec, name: wanted }) => [file, wanted, spec]),
291
+ ...info.stars.map((spec) => [file, ALL, spec]),
292
+ ];
290
293
  }
291
- return seen;
294
+ if (info.locals.has(name)) return [[file, BODY]];
295
+ const again = info.reexports.get(name);
296
+ if (again) return [[file, again.name, again.spec]];
297
+ if (name === 'default' || info.stars.length === 0) return [[file, ALL]];
298
+ return starred(file, info, name, context);
292
299
  }
293
300
 
294
301
  export function select({ root, changed, since }) {
@@ -297,7 +304,8 @@ export function select({ root, changed, since }) {
297
304
  const all = files.filter((file) => tests.test(file));
298
305
  const fresh = files.filter((file) => since === undefined || statSync(file).mtimeMs > since);
299
306
  const touched = new Set([...changed.map((file) => resolve(root, file)), ...fresh]);
300
- const reached = reaching(graph(root, all), touched);
307
+ const reach = reacher(modules(root));
308
+ const reached = new Set(all.filter((test) => [...reach(test)].some((file) => touched.has(file))));
301
309
  const posix = (file) => relative(root, file).split(sep).join('/');
302
310
  return {
303
311
  tests: all