@ref0/workspace 0.10.0 → 0.12.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 +171 -1
- package/dist/bin.mjs +19 -7
- package/dist/lint/generic/ast-fields.mjs +32 -0
- package/dist/lint/generic/build-cache-inputs.d.mts +9 -0
- package/dist/lint/generic/build-cache-inputs.mjs +147 -0
- package/dist/lint/generic/effect-gen-wrappers.d.mts +13 -0
- package/dist/lint/generic/effect-gen-wrappers.mjs +100 -0
- package/dist/lint/generic/folder-imports.mjs +84 -0
- package/dist/lint/generic/folder-layers.d.mts +40 -0
- package/dist/lint/generic/folder-layers.mjs +82 -0
- package/dist/lint/generic/imports.mjs +34 -0
- package/dist/lint/generic/package-graph.d.mts +36 -0
- package/dist/lint/generic/package-graph.mjs +111 -0
- package/dist/lint/generic/package-imports.mjs +85 -0
- package/dist/lint/generic/plugin.d.mts +7 -3
- package/dist/lint/generic/plugin.mjs +21 -3
- package/dist/lint/generic/public-docs.d.mts +12 -0
- package/dist/lint/generic/public-docs.mjs +345 -0
- package/dist/lint/generic/pure-effect-fn.mjs +107 -0
- package/dist/lint/generic/pure-top-level.d.mts +44 -0
- package/dist/lint/generic/pure-top-level.mjs +393 -0
- package/dist/lint/generic/rule-options.mjs +17 -0
- package/dist/lint/generic/workspace-packages.d.mts +58 -0
- package/dist/lint/generic/workspace-packages.mjs +119 -0
- package/dist/lint/graph.d.mts +8 -0
- package/dist/lint/graph.mjs +3 -0
- package/dist/review-record/command.mjs +107 -0
- package/dist/review-record/index.d.mts +3 -0
- package/dist/review-record/index.mjs +3 -0
- package/dist/review-record/review-record.d.mts +33 -0
- package/dist/review-record/review-record.mjs +1256 -0
- package/dist/review-record/settings.d.mts +40 -0
- package/dist/review-record/settings.mjs +103 -0
- package/dist/symbols/symbols.mjs +1 -1
- package/dist/task-sources.d.mts +16 -0
- package/dist/task-sources.mjs +121 -0
- package/package.json +13 -1
package/README.md
CHANGED
|
@@ -42,7 +42,9 @@ changes, beside its code, in the package too.
|
|
|
42
42
|
|
|
43
43
|
`ref0-generic`'s rules: `seeded-properties`, `index-barrel-only` and `export-type-side-effects`,
|
|
44
44
|
which `base.lint` turns on, and `effect-encoding`, `log-messages`, `env-at-entrypoints`,
|
|
45
|
-
`entry-reexports
|
|
45
|
+
`entry-reexports`, `no-comments`, `package-imports`, `folder-imports`, `public-docs`,
|
|
46
|
+
`build-cache-inputs`, `pure-effect-fn`, `pure-top-level` and `effect-gen-wrappers`, which a repo
|
|
47
|
+
turns on for its own files. `entry-reexports` takes the repo's root,
|
|
46
48
|
the folders of the packages whose entry files it checks, and the export condition that names an
|
|
47
49
|
entry point's source:
|
|
48
50
|
|
|
@@ -72,6 +74,63 @@ that leaves out what it doesn't own, such as vendored code:
|
|
|
72
74
|
|
|
73
75
|
and add `"comments": "ref0-workspace comment-budget"` to the root `package.json`'s scripts.
|
|
74
76
|
|
|
77
|
+
`package-imports` holds each package and app to a declared graph: what it imports of each other
|
|
78
|
+
package, by entry point, and how, as `values`, `types` (only `import type`) or `tests`. Nothing
|
|
79
|
+
imports an app, a relative path never leaves a package, and a package never imports itself by name
|
|
80
|
+
outside its tests. It takes the root, globs of the folders that hold packages and apps, the graph,
|
|
81
|
+
and `nodeFiles`, the files of a package that run only in Node and take values where it takes types.
|
|
82
|
+
`folder-imports` holds each layered source folder: a file imports its own place and places below
|
|
83
|
+
it, never beside or above. A source may name `exceptions`, by file and module, which fail once no
|
|
84
|
+
import needs them; `features`, places nothing outside them imports; and `entries`, when its top
|
|
85
|
+
files are entry points, `reexports` or `code`. `@ref0/workspace/lint/graph` exports the types to
|
|
86
|
+
declare both with, and `graphProblems`, which a repo's test expects to return none:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import type { FolderLayers, PackageGraph } from '@ref0/workspace/lint/graph';
|
|
90
|
+
|
|
91
|
+
export const packageGraph = {
|
|
92
|
+
'@acme/ui': {},
|
|
93
|
+
'@acme/site': { '@acme/ui': { values: ['.', 'cast'], tests: ['testing'] } },
|
|
94
|
+
} as const satisfies PackageGraph<'@acme/ui' | '@acme/site', '@acme/ui'>;
|
|
95
|
+
|
|
96
|
+
export const folderLayers = {
|
|
97
|
+
'packages/ui/src': { layers: [['tokens'], ['components'], ['blocks']], entries: 'reexports' },
|
|
98
|
+
} as const satisfies FolderLayers;
|
|
99
|
+
|
|
100
|
+
// In the config's overrides:
|
|
101
|
+
'ref0-generic/package-imports': [
|
|
102
|
+
'error',
|
|
103
|
+
{ root, packages: ['packages/*'], apps: ['apps/*'], graph: packageGraph },
|
|
104
|
+
],
|
|
105
|
+
'ref0-generic/folder-imports': ['error', { root, sources: folderLayers }],
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The rest take their options as below, with each options type in `@ref0/workspace/lint/graph`:
|
|
109
|
+
|
|
110
|
+
- `public-docs`: every name a public package publishes has a doc comment. It reads each published
|
|
111
|
+
entry's source through `condition`, or takes `entries`, files from the root.
|
|
112
|
+
- `build-cache-inputs`: each task `tasks` names lists, as cache input, the source, `package.json` and
|
|
113
|
+
`tsconfig.json` of each workspace package its package depends on, and each package's config
|
|
114
|
+
defines the first.
|
|
115
|
+
- `pure-effect-fn`: a top-level `Effect.fn` or `Effect.fnUntraced` carries `/* @__PURE__ */`. It
|
|
116
|
+
takes no options.
|
|
117
|
+
- `pure-top-level`: a top-level pure mark covers only a callee the repo lists in `callees`, each with
|
|
118
|
+
why it's pure, and with `requireMarks`, a listed call needs its mark, which `--fix` adds.
|
|
119
|
+
- `effect-gen-wrappers`: no function only returns `Effect.gen`. `allowed` names those that may, by
|
|
120
|
+
file and declaration, with why, and fails on one that no longer needs it.
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
'ref0-generic/public-docs': ['error', { root, packages: ['packages/*'], condition: '@ref0/source' }],
|
|
124
|
+
'ref0-generic/build-cache-inputs': ['error', { root, packages: ['packages/*'], tasks: ['build:cached'] }],
|
|
125
|
+
'ref0-generic/pure-top-level': ['error', { root, callees: pureCallees, requireMarks: true }],
|
|
126
|
+
'ref0-generic/effect-gen-wrappers': ['error', { root, allowed: {} }],
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`@ref0/workspace/task-sources` keys a cached task by the files it reads, which Vite+ can't track on
|
|
130
|
+
WSL2. `taskSources({ root, packages, apps })` gives `builtFrom(import.meta.url, command)`, keyed by
|
|
131
|
+
the config's package and every workspace package it depends on, and `readsAll(command)`, keyed by
|
|
132
|
+
every file. Each puts `env REF0_SOURCES=<hash>` before each command `&&` joins.
|
|
133
|
+
|
|
75
134
|
## Checks
|
|
76
135
|
|
|
77
136
|
`ref0-workspace <check>`, from anywhere in the repo's checkout:
|
|
@@ -91,6 +150,9 @@ and add `"comments": "ref0-workspace comment-budget"` to the root `package.json`
|
|
|
91
150
|
grows, so a review sees it.
|
|
92
151
|
- `symbols find <words...>` and `symbols check <base> [<head>]` or `symbols check --all`: what the
|
|
93
152
|
repo already has, and a change that copies it, as [Symbols](#symbols) says.
|
|
153
|
+
- `review-record [--count | --tier | --check <comment> [<body>] | --benched]`: whether a pull
|
|
154
|
+
request's review is on record for its merge risk, in CI, and a branch's floor before it opens, as
|
|
155
|
+
[The review gate](#the-review-gate) says.
|
|
94
156
|
- `types`: the types of every project the root `tsconfig.json` reaches, and Effect's rules, with
|
|
95
157
|
the repo's own `effect-tsgo tsrs`, each error once, in the project that includes its file. Each
|
|
96
158
|
project's result is kept for every checkout on the machine, in `REF0_WORKSPACE_TYPES_CACHE` or
|
|
@@ -161,6 +223,114 @@ that never installed the repo's hooks. A job that force-pushes a
|
|
|
161
223
|
`types` and `type-coverage` run the repo's own `@effect/tsgo`, `tsrs` and `typescript`, its
|
|
162
224
|
optional peers, resolved from its root, at the versions its catalog pins.
|
|
163
225
|
|
|
226
|
+
## The review gate
|
|
227
|
+
|
|
228
|
+
`ref0-workspace review-record` is the step of CI's result job that fails a pull request whose
|
|
229
|
+
review isn't on record for its merge risk, as the `review` skill's `references/merge-risk.md` and
|
|
230
|
+
the repo's `.agents/repo/review.md` say. Its body names a tier on a `Merge risk:` line, at or above
|
|
231
|
+
its floor, the highest tier its changed lines, the always-review list and its test code give it,
|
|
232
|
+
and the gate checks the session comment or `Break:` lines that tier needs.
|
|
233
|
+
|
|
234
|
+
- Bare, in CI: judges pull request `PR` of `GITHUB_REPOSITORY`, from `BASE` to `HEAD`, reading
|
|
235
|
+
GitHub with `gh` and `GH_TOKEN`, and the history from the Git checkout it runs in, which holds
|
|
236
|
+
both commits whole, blobs aside. It prints each reason it fails as an Actions `::error::`.
|
|
237
|
+
- `--count`: the branch's net lines of production source since its merge base with `origin/main`,
|
|
238
|
+
and on stderr whether that's a large change and its floor.
|
|
239
|
+
- `--tier`: the branch's floor, and what sets it, as a `Merge risk:` line.
|
|
240
|
+
- `--check <comment-file> [<body-file>]`: CI's checks on a session comment and a body, before you
|
|
241
|
+
post them.
|
|
242
|
+
- `--benched`: ci-bench's cases, one a line, that pull request `PR`'s files tie to, from the bench
|
|
243
|
+
list in the checkout it runs in.
|
|
244
|
+
|
|
245
|
+
Each reads the repo's settings, `.agents/repo/review.json`, and its always-review list,
|
|
246
|
+
`.agents/repo/review-paths.txt`, at the base: CI's from GitHub at `BASE`, and the branch
|
|
247
|
+
subcommands' at `origin/main`'s tip. A pull request's own copies count only once it merges.
|
|
248
|
+
Every key of `review.json` may be left out, for the value in brackets, which ref-0/git's gate
|
|
249
|
+
began with, and the file holds no other:
|
|
250
|
+
|
|
251
|
+
| Key | What it holds |
|
|
252
|
+
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
253
|
+
| `reviewTypes` | The review types a session may name, in lowercase, as the `review` skill's `references/types.md` lists them (its 14) |
|
|
254
|
+
| `consideredTypes` | The types each session names, as run or as not run with why, on a change a review covers: each one of `reviewTypes` (stress test, system design, red team, storage, program design, formal verification, fuzzing and fidelity) |
|
|
255
|
+
| `lowTierLines` | Changed lines, additions and deletions since the merge base, up to which a pull request may be low (150) |
|
|
256
|
+
| `highTierLines` | Changed lines up to which it may be medium, at least `lowTierLines` (500) |
|
|
257
|
+
| `productionSource` | Production source, as globs, whose net lines count toward a large change, each `!` entry taking files off, test code among them; fixtures never count (`packages/*/src/*.ts`, `packages/*/src/*.tsx`, `apps/*/src/*.ts`, `apps/*/src/*.tsx`, `!*.test.ts`, `!*.test-d.ts`, `!*/testing/*`) |
|
|
258
|
+
| `testCode` | Test code, as globs in `review-paths.txt`'s form (`*.test.ts`, `*.test-d.ts`, `*/testing/*`) |
|
|
259
|
+
| `testHelpers` | Shared test helpers, test code too whether `testCode` names them or not, whose change puts a pull request at medium (`*/testing/*`) |
|
|
260
|
+
| `benchedPaths` | The bench list's path, whose `<case> <glob>` lines tie source to the bench cases that time it (none: no bench) |
|
|
261
|
+
| `benchRuns` | Files under a `testing/` folder that a bench case runs all the same (none) |
|
|
262
|
+
|
|
263
|
+
```json
|
|
264
|
+
{ "benchedPaths": "bench/benched-paths.txt", "lowTierLines": 200 }
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
A file that doesn't read, a key it doesn't know, or a considered type the repo doesn't accept
|
|
268
|
+
stops the gate, which fails closed.
|
|
269
|
+
|
|
270
|
+
CI runs the command at the version the base's `pnpm-workspace.yaml` catalog names, from an npm
|
|
271
|
+
install of that version with no peers, which loads no peer, in a blobless clone of the base and
|
|
272
|
+
the head, so a pull request can't change the gate that judges it:
|
|
273
|
+
|
|
274
|
+
```yaml
|
|
275
|
+
- name: Fetch review-record history
|
|
276
|
+
id: fetch
|
|
277
|
+
if: always() && github.event_name == 'pull_request'
|
|
278
|
+
timeout-minutes: 2
|
|
279
|
+
env:
|
|
280
|
+
BASE: ${{ github.event.pull_request.base.sha }}
|
|
281
|
+
GH_TOKEN: ${{ github.token }}
|
|
282
|
+
GIT_TERMINAL_PROMPT: '0'
|
|
283
|
+
run: |
|
|
284
|
+
set -eu
|
|
285
|
+
rm -rf review-record
|
|
286
|
+
git init -q review-record
|
|
287
|
+
git -C review-record remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
|
288
|
+
git -C review-record \
|
|
289
|
+
-c credential.helper= \
|
|
290
|
+
-c 'credential.helper=!gh auth git-credential' \
|
|
291
|
+
-c credential.interactive=never \
|
|
292
|
+
fetch -q --no-tags --filter=blob:none origin "$GITHUB_SHA" "$BASE"
|
|
293
|
+
gate=$(git -C review-record ls-tree --name-only "$BASE" -- .agents/repo/review.json)
|
|
294
|
+
if [ -z "$gate" ]; then
|
|
295
|
+
echo "::notice::The base, $BASE, has no .agents/repo/review.json, so no review gate judges this pull request."
|
|
296
|
+
echo 'gate=none' >> "$GITHUB_OUTPUT"
|
|
297
|
+
exit 0
|
|
298
|
+
fi
|
|
299
|
+
git -C review-record \
|
|
300
|
+
-c credential.helper= \
|
|
301
|
+
-c 'credential.helper=!gh auth git-credential' \
|
|
302
|
+
-c credential.interactive=never \
|
|
303
|
+
checkout -q "$BASE" -- pnpm-workspace.yaml
|
|
304
|
+
version=$(sed -n "s/^ '@ref0\/workspace': \([0-9][0-9A-Za-z.+-]*\)$/\1/p" review-record/pnpm-workspace.yaml)
|
|
305
|
+
case "$version" in
|
|
306
|
+
'' | *[!0-9A-Za-z.+-]*) echo "::error::The base's catalog names no one @ref0/workspace version." >&2; exit 1 ;;
|
|
307
|
+
esac
|
|
308
|
+
npm install --prefix "$RUNNER_TEMP/review-record" --no-save --no-package-lock --omit=peer \
|
|
309
|
+
--omit=optional --ignore-scripts --no-audit --no-fund "@ref0/workspace@$version"
|
|
310
|
+
echo 'gate=base' >> "$GITHUB_OUTPUT"
|
|
311
|
+
- name: The review is on record
|
|
312
|
+
if: always() && github.event_name == 'pull_request' && steps.fetch.outcome == 'success' && steps.fetch.outputs.gate == 'base'
|
|
313
|
+
working-directory: review-record
|
|
314
|
+
env:
|
|
315
|
+
BASE: ${{ github.event.pull_request.base.sha }}
|
|
316
|
+
GH_TOKEN: ${{ github.token }}
|
|
317
|
+
HEAD: ${{ github.event.pull_request.head.sha }}
|
|
318
|
+
PR: ${{ github.event.pull_request.number }}
|
|
319
|
+
run: node "$RUNNER_TEMP/review-record/node_modules/@ref0/workspace/dist/bin.mjs" review-record
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
The job's token reads the pull request, its comments and the repo's contents. The fetch's
|
|
323
|
+
credential helper reads `GH_TOKEN` from the environment, so the token is never in `.git/config` or
|
|
324
|
+
on a command line, and a blob the gate reads later is fetched the same way, failing closed when the
|
|
325
|
+
fetch does. A base with no `review.json` holds no gate yet, and the job says so. A repo's
|
|
326
|
+
`review-paths.txt` lists `review.json` and `.github/workflows/ci.yml` at high, since each changes
|
|
327
|
+
the gate the next pull request meets, and `pnpm-workspace.yaml` at medium or above, since its
|
|
328
|
+
catalog picks the gate's version.
|
|
329
|
+
|
|
330
|
+
`@ref0/workspace/review-record` exports what a repo's own code reuses of the gate: `testsOnly` and
|
|
331
|
+
`benchedCases`, which a bench's seeds and its list's tests read, and `settingsFrom` and
|
|
332
|
+
`settingsPath`, to read the settings they take.
|
|
333
|
+
|
|
164
334
|
## Symbols
|
|
165
335
|
|
|
166
336
|
`symbols` keeps a repo from collecting copies of its own code. `find` shows what the repo already
|
package/dist/bin.mjs
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { changelog } from "./changelog.mjs";
|
|
3
|
-
import { commentBudget } from "./comment-budget.mjs";
|
|
4
3
|
import { commitMessage } from "./commit-message.mjs";
|
|
5
4
|
import { docsBudget } from "./docs-budget.mjs";
|
|
6
5
|
import { defaultCondition, packageExports } from "./package-exports.mjs";
|
|
7
6
|
import { preCommit } from "./pre-commit.mjs";
|
|
8
7
|
import { prePush } from "./pre-push.mjs";
|
|
9
|
-
import {
|
|
10
|
-
import { symbolsFind } from "./symbols/find.mjs";
|
|
8
|
+
import { reviewRecord } from "./review-record/command.mjs";
|
|
11
9
|
import { typeCoverage } from "./type-coverage.mjs";
|
|
12
10
|
import { types } from "./types/types.mjs";
|
|
13
11
|
import { execFileSync } from "node:child_process";
|
|
@@ -38,6 +36,12 @@ import { parseArgs } from "node:util";
|
|
|
38
36
|
* ref0-workspace pre-push <remote> <url> Git's pre-push hook: no force-push or delete
|
|
39
37
|
* of main, deploy/* or release/*, then the
|
|
40
38
|
* repo's checks
|
|
39
|
+
* ref0-workspace review-record [--count | --tier | --check <comment> [<body>] | --benched]
|
|
40
|
+
* a pull request's review is on record for its
|
|
41
|
+
* merge risk
|
|
42
|
+
*
|
|
43
|
+
* A check that needs a peer, Vite+ or a type checker, imports its module when it runs, so
|
|
44
|
+
* `review-record`, which CI runs from an install with no peers, loads none of them.
|
|
41
45
|
*/
|
|
42
46
|
/** The root of the Git checkout the command runs in, or where it runs outside one. */
|
|
43
47
|
const root = () => {
|
|
@@ -81,14 +85,17 @@ const checks = /* @__PURE__ */ new Map([
|
|
|
81
85
|
["comment-budget", {
|
|
82
86
|
args: "[--write | --grant <path>...]",
|
|
83
87
|
about: "each file's banned comments, within its budget for ref0-generic/no-comments; --write lowers each budget to what its file holds, and --grant sets the budgets of the files under the paths to what each holds",
|
|
84
|
-
run: (args) =>
|
|
88
|
+
run: async (args) => {
|
|
89
|
+
const { commentBudget } = await import("./comment-budget.mjs");
|
|
90
|
+
return commentBudget(args, root());
|
|
91
|
+
}
|
|
85
92
|
}],
|
|
86
93
|
["symbols", {
|
|
87
94
|
args: "find <words...> | check <base> [<head>] | check --all",
|
|
88
95
|
about: "what the repo has, before you write it again, and no change copying it",
|
|
89
|
-
run: ([command, ...rest]) => {
|
|
90
|
-
if (command === "find") return symbolsFind(rest, cwd());
|
|
91
|
-
if (command === "check") return symbolsCheck(rest, cwd());
|
|
96
|
+
run: async ([command, ...rest]) => {
|
|
97
|
+
if (command === "find") return (await import("./symbols/find.mjs")).symbolsFind(rest, cwd());
|
|
98
|
+
if (command === "check") return (await import("./symbols/check.mjs")).symbolsCheck(rest, cwd());
|
|
92
99
|
return usageError();
|
|
93
100
|
}
|
|
94
101
|
}],
|
|
@@ -140,6 +147,11 @@ const checks = /* @__PURE__ */ new Map([
|
|
|
140
147
|
if (remote === void 0 || url === void 0 || extra.length > 0) return usageError();
|
|
141
148
|
return prePush(root(), url, readFileSync(0, "utf8"), env);
|
|
142
149
|
}
|
|
150
|
+
}],
|
|
151
|
+
["review-record", {
|
|
152
|
+
args: "[--count | --tier | --check <comment> [<body>] | --benched]",
|
|
153
|
+
about: "CI: a pull request's review is on record for its merge risk; --count, --tier and --check ask it of this branch, and --benched lists ci-bench's cases",
|
|
154
|
+
run: (args) => reviewRecord(args, root(), env)
|
|
143
155
|
}]
|
|
144
156
|
]);
|
|
145
157
|
function usage() {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Predicate } from "effect";
|
|
2
|
+
// src/lint/generic/ast-fields.ts
|
|
3
|
+
/** Whether a field of oxc's tree is a node. */
|
|
4
|
+
const isNode = (value) => Predicate.isObject(value) && Predicate.hasProperty(value, "type") && Predicate.isString(value.type) && Predicate.hasProperty(value, "start") && Predicate.isNumber(value.start);
|
|
5
|
+
/** What `node` holds in its field `name`, which a node of another type may not have. */
|
|
6
|
+
const fieldOf = (node, name) => {
|
|
7
|
+
const fields = node;
|
|
8
|
+
return Object.hasOwn(fields, name) ? fields[name] : void 0;
|
|
9
|
+
};
|
|
10
|
+
/** Whether a field of oxc's tree is a node, a list or another object, so a walk goes into it. */
|
|
11
|
+
const isBranch = (value) => Predicate.isObjectOrArray(value);
|
|
12
|
+
/**
|
|
13
|
+
* Each item of a list, or each field of a plain value that isn't a node, such as a template's
|
|
14
|
+
* `{ raw, cooked }`, which holds no code.
|
|
15
|
+
*/
|
|
16
|
+
const itemsOf = (value) => isBranch(value) && !isNode(value) ? Object.values(value) : [];
|
|
17
|
+
/** The node `node` holds in its field `name`, if one. */
|
|
18
|
+
const nodeAt = (node, name) => {
|
|
19
|
+
const value = fieldOf(node, name);
|
|
20
|
+
return isNode(value) ? value : void 0;
|
|
21
|
+
};
|
|
22
|
+
/** The nodes `node` holds in its list `name`, its holes left out. */
|
|
23
|
+
const nodesAt = (node, name) => {
|
|
24
|
+
const value = fieldOf(node, name);
|
|
25
|
+
return itemsOf(value).filter(isNode);
|
|
26
|
+
};
|
|
27
|
+
/** An identifier's name, or `undefined` for any other node. */
|
|
28
|
+
const nameOf = (node) => {
|
|
29
|
+
const name = node?.type === "Identifier" ? fieldOf(node, "name") : void 0;
|
|
30
|
+
return Predicate.isString(name) ? name : void 0;
|
|
31
|
+
};
|
|
32
|
+
export { fieldOf, isNode, nameOf, nodeAt, nodesAt };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Workspace } from "./workspace-packages.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* What `ref0-generic/build-cache-inputs` takes: where the packages are, and `tasks`, the names of
|
|
4
|
+
* the tasks that build a package, such as `build:cached`, whose cache inputs it checks. Each
|
|
5
|
+
* package's config defines the first.
|
|
6
|
+
*/
|
|
7
|
+
export interface BuildCacheInputsOptions extends Workspace {
|
|
8
|
+
readonly tasks: readonly [string, ...ReadonlyArray<string>];
|
|
9
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { decodedOnce } from "./rule-options.mjs";
|
|
2
|
+
import { dependedOn, fromRoot, workspacePackages } from "./workspace-packages.mjs";
|
|
3
|
+
import { dirname, resolve } from "node:path";
|
|
4
|
+
import { Schema } from "effect";
|
|
5
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
6
|
+
// src/lint/generic/build-cache-inputs.ts
|
|
7
|
+
const decodeOptions = Schema.decodeUnknownSync(Schema.Tuple([Schema.Struct({
|
|
8
|
+
root: Schema.String,
|
|
9
|
+
packages: Schema.Array(Schema.String),
|
|
10
|
+
apps: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
11
|
+
tasks: Schema.NonEmptyArray(Schema.String)
|
|
12
|
+
})]));
|
|
13
|
+
const optionsOf = decodedOnce((options) => decodeOptions(options)[0]);
|
|
14
|
+
const isString = Schema.is(Schema.String);
|
|
15
|
+
/** Whether `node` is a `Literal` whose value is a string. */
|
|
16
|
+
const isStringLiteral = (node) => node?.type === "Literal" && isString(node.value);
|
|
17
|
+
/** A property's name, when it's written as a name or a string, not computed. */
|
|
18
|
+
const keyOf = (property) => {
|
|
19
|
+
if (property.computed) return void 0;
|
|
20
|
+
if (property.key.type === "Identifier") return property.key.name;
|
|
21
|
+
return isStringLiteral(property.key) ? property.key.value : void 0;
|
|
22
|
+
};
|
|
23
|
+
/** The value of an object literal's property named `key`, or nothing for any other node. */
|
|
24
|
+
const valueOf = (node, key) => node?.type === "ObjectExpression" ? node.properties.find((property) => property.type === "Property" && keyOf(property) === key)?.value : void 0;
|
|
25
|
+
/** The `pattern` of a `{ pattern, base: 'workspace' }` input, or nothing for any other. */
|
|
26
|
+
const workspacePattern = (input) => {
|
|
27
|
+
const base = valueOf(input, "base");
|
|
28
|
+
const pattern = valueOf(input, "pattern");
|
|
29
|
+
return isStringLiteral(base) && base.value === "workspace" && isStringLiteral(pattern) ? [pattern.value] : [];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* What a build reads of each workspace package it depends on: its source, its manifest, and its
|
|
33
|
+
* `tsconfig.json`, which esbuild and Vite read for each of its files, for such settings as
|
|
34
|
+
* `useDefineForClassFields`.
|
|
35
|
+
*/
|
|
36
|
+
const dependencyInputs = [
|
|
37
|
+
{
|
|
38
|
+
messageId: "missingSource",
|
|
39
|
+
path: "src/**"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
messageId: "missingManifest",
|
|
43
|
+
path: "package.json"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
messageId: "missingTsconfig",
|
|
47
|
+
path: "tsconfig.json"
|
|
48
|
+
}
|
|
49
|
+
];
|
|
50
|
+
/**
|
|
51
|
+
* Vite+'s automatic tracking fails on WSL2, which the shared machine runs: its file tracker can't
|
|
52
|
+
* install its seccomp filter there (voidzero-dev/vite-plus#1643, open as of Vite+ 1.8.0). Before
|
|
53
|
+
* 1.8.0 each process a build spawned, such as esbuild or tsgo, failed with `spawn EBUSY`; since, the
|
|
54
|
+
* task runs untracked and is never cached (vite-task#701). So each `build:cached` lists its inputs,
|
|
55
|
+
* and a package's build reads the source of every workspace package it depends on, through the
|
|
56
|
+
* `@ref0/source` condition in that package's `package.json`.
|
|
57
|
+
*/
|
|
58
|
+
const buildCacheInputsRule = defineRule({
|
|
59
|
+
meta: {
|
|
60
|
+
messages: {
|
|
61
|
+
missingSource: "{{task}} reads {{dependency}}'s source, which its cache input leaves out, so a change there would replay a stale build. Add { pattern: '{{pattern}}', base: 'workspace' }.",
|
|
62
|
+
missingManifest: "{{task}} resolves {{dependency}} through its package.json, which its cache input leaves out, so a change to its exports or dependencies would replay a stale build. Add { pattern: '{{pattern}}', base: 'workspace' }.",
|
|
63
|
+
missingTsconfig: "{{task}} compiles {{dependency}}'s source with its tsconfig.json, which its cache input leaves out, so a change to its compiler settings would replay a stale build. Add { pattern: '{{pattern}}', base: 'workspace' }.",
|
|
64
|
+
noTask: "A workspace package defines a {{task}} task, whose cache input lists the source and package.json of each workspace package it depends on."
|
|
65
|
+
},
|
|
66
|
+
schema: [{
|
|
67
|
+
type: "object",
|
|
68
|
+
properties: {
|
|
69
|
+
root: { type: "string" },
|
|
70
|
+
packages: {
|
|
71
|
+
type: "array",
|
|
72
|
+
items: { type: "string" }
|
|
73
|
+
},
|
|
74
|
+
apps: {
|
|
75
|
+
type: "array",
|
|
76
|
+
items: { type: "string" }
|
|
77
|
+
},
|
|
78
|
+
tasks: {
|
|
79
|
+
type: "array",
|
|
80
|
+
items: { type: "string" },
|
|
81
|
+
minItems: 1
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
required: [
|
|
85
|
+
"root",
|
|
86
|
+
"packages",
|
|
87
|
+
"tasks"
|
|
88
|
+
],
|
|
89
|
+
additionalProperties: false
|
|
90
|
+
}]
|
|
91
|
+
},
|
|
92
|
+
create(context) {
|
|
93
|
+
const options = optionsOf(context.options);
|
|
94
|
+
const packages = workspacePackages(options);
|
|
95
|
+
const directory = fromRoot(options.root, dirname(resolve(context.filename)));
|
|
96
|
+
const own = [...packages.values()].find((found) => found.directory === directory);
|
|
97
|
+
if (own === void 0) return {};
|
|
98
|
+
const { name } = own;
|
|
99
|
+
const [required] = options.tasks;
|
|
100
|
+
const buildTasks = new Set(options.tasks);
|
|
101
|
+
const arrays = /* @__PURE__ */ new Map();
|
|
102
|
+
const tasks = [];
|
|
103
|
+
/** A task's input list, written in place or as a `const` of this file holding the array. */
|
|
104
|
+
const inputOf = (task) => {
|
|
105
|
+
const input = valueOf(valueOf(task, "cache"), "input");
|
|
106
|
+
return input?.type === "Identifier" ? arrays.get(input.name) : input;
|
|
107
|
+
};
|
|
108
|
+
return {
|
|
109
|
+
VariableDeclarator(node) {
|
|
110
|
+
if (node.id.type === "Identifier" && node.init?.type === "ArrayExpression") arrays.set(node.id.name, node.init);
|
|
111
|
+
},
|
|
112
|
+
Property(node) {
|
|
113
|
+
const name = keyOf(node);
|
|
114
|
+
if (name !== void 0 && buildTasks.has(name)) tasks.push({
|
|
115
|
+
name,
|
|
116
|
+
node,
|
|
117
|
+
value: node.value
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
"Program:exit"(node) {
|
|
121
|
+
if (!tasks.some((task) => task.name === required)) context.report({
|
|
122
|
+
node,
|
|
123
|
+
messageId: "noTask",
|
|
124
|
+
data: { task: required }
|
|
125
|
+
});
|
|
126
|
+
for (const task of tasks) {
|
|
127
|
+
const input = inputOf(task.value);
|
|
128
|
+
const listed = new Set(input?.type === "ArrayExpression" ? input.elements.flatMap(workspacePattern) : []);
|
|
129
|
+
for (const [dependency, workspacePackage] of dependedOn(name, packages)) for (const { messageId, path } of dependencyInputs) {
|
|
130
|
+
const pattern = `${workspacePackage.directory}/${path}`;
|
|
131
|
+
if (listed.has(pattern)) continue;
|
|
132
|
+
context.report({
|
|
133
|
+
node: task.node,
|
|
134
|
+
messageId,
|
|
135
|
+
data: {
|
|
136
|
+
task: task.name,
|
|
137
|
+
dependency,
|
|
138
|
+
pattern
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
export { buildCacheInputsRule };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `ref0-generic/effect-gen-wrappers` takes, if anything: the repo's root, as an absolute path,
|
|
3
|
+
* and `allowed`, the functions that may stay ones returning `Effect.gen`, by file from the root,
|
|
4
|
+
* then by the top-level declaration each is in, with the reason each stays.
|
|
5
|
+
*/
|
|
6
|
+
export interface EffectGenWrappersOptions {
|
|
7
|
+
readonly root: string;
|
|
8
|
+
readonly allowed: {
|
|
9
|
+
readonly [file: string]: {
|
|
10
|
+
readonly [declaration: string]: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { decodedOnce } from "./rule-options.mjs";
|
|
2
|
+
import { fromRoot } from "./workspace-packages.mjs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { Schema } from "effect";
|
|
5
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
6
|
+
// src/lint/generic/effect-gen-wrappers.ts
|
|
7
|
+
const decodeOptions = Schema.decodeUnknownSync(Schema.Tuple([Schema.optionalKey(Schema.Struct({
|
|
8
|
+
root: Schema.String,
|
|
9
|
+
allowed: Schema.Record(Schema.String, Schema.Record(Schema.String, Schema.String))
|
|
10
|
+
}))]));
|
|
11
|
+
const optionsOf = decodedOnce((options) => decodeOptions(options)[0]);
|
|
12
|
+
/** `node` with its parentheses and TypeScript's wrappers that change no value taken off: `as`, `satisfies`, `!` and `<T>`. */
|
|
13
|
+
const unwrap = (node) => {
|
|
14
|
+
switch (node.type) {
|
|
15
|
+
case "ParenthesizedExpression":
|
|
16
|
+
case "TSAsExpression":
|
|
17
|
+
case "TSSatisfiesExpression":
|
|
18
|
+
case "TSNonNullExpression":
|
|
19
|
+
case "TSTypeAssertion": return unwrap(node.expression);
|
|
20
|
+
default: return node;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
/** `<object>.<property>`, or `<anything>.<property>` when `object` is `undefined`. */
|
|
24
|
+
const isMember = (node, object, property) => node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier" && node.property.name === property && (object === void 0 || node.object.type === "Identifier" && node.object.name === object);
|
|
25
|
+
/** Whether `expression` is `Effect.gen(...)`, with any `.pipe(...)` on it and type assertions around it. */
|
|
26
|
+
const isGenOf = (expression) => {
|
|
27
|
+
if (expression === null || expression === void 0) return false;
|
|
28
|
+
const node = unwrap(expression);
|
|
29
|
+
if (node.type !== "CallExpression") return false;
|
|
30
|
+
if (isMember(node.callee, "Effect", "gen")) return true;
|
|
31
|
+
return isMember(node.callee, void 0, "pipe") && node.callee.type === "MemberExpression" && isGenOf(node.callee.object);
|
|
32
|
+
};
|
|
33
|
+
/** Whether a function only returns `Effect.gen`: an arrow whose body is one, or a body whose only statement returns one. */
|
|
34
|
+
const returnsGen = (fn) => {
|
|
35
|
+
if (fn.body === null || fn.body === void 0) return false;
|
|
36
|
+
if (fn.body.type !== "BlockStatement") return isGenOf(fn.body);
|
|
37
|
+
const [only, ...rest] = fn.body.body;
|
|
38
|
+
return rest.length === 0 && only?.type === "ReturnStatement" && isGenOf(only.argument);
|
|
39
|
+
};
|
|
40
|
+
/** The name a top-level statement declares, `default` for a default export, or `(top)`. */
|
|
41
|
+
const declaredName = (statement) => {
|
|
42
|
+
const inner = statement.type === "ExportNamedDeclaration" && statement.declaration !== null ? statement.declaration : statement;
|
|
43
|
+
if (inner.type === "VariableDeclaration") {
|
|
44
|
+
const id = inner.declarations[0]?.id;
|
|
45
|
+
return id?.type === "Identifier" ? id.name : "(top)";
|
|
46
|
+
}
|
|
47
|
+
if ((inner.type === "FunctionDeclaration" || inner.type === "ClassDeclaration") && inner.id) return inner.id.name;
|
|
48
|
+
return statement.type === "ExportDefaultDeclaration" ? "default" : "(top)";
|
|
49
|
+
};
|
|
50
|
+
/** The top-level statement that holds `node`. */
|
|
51
|
+
const statementOf = (node) => node.parent === null || node.parent.type === "Program" ? node : statementOf(node.parent);
|
|
52
|
+
const effectGenWrappersRule = defineRule({
|
|
53
|
+
meta: {
|
|
54
|
+
messages: {
|
|
55
|
+
wrapper: "This function only returns Effect.gen, which makes a generator closure on each call. Write it as Effect.fnUntraced(function* (…) { … }), or Effect.fn(\"name\") where a span helps.",
|
|
56
|
+
stale: "The rule's allowed list names {{declaration}} in this file, and no function there returns Effect.gen. Delete it."
|
|
57
|
+
},
|
|
58
|
+
schema: [{
|
|
59
|
+
type: "object",
|
|
60
|
+
properties: {
|
|
61
|
+
root: { type: "string" },
|
|
62
|
+
allowed: { type: "object" }
|
|
63
|
+
},
|
|
64
|
+
required: ["root", "allowed"],
|
|
65
|
+
additionalProperties: false
|
|
66
|
+
}]
|
|
67
|
+
},
|
|
68
|
+
create(context) {
|
|
69
|
+
const options = optionsOf(context.options);
|
|
70
|
+
const allowed = options === void 0 ? {} : options.allowed[fromRoot(options.root, resolve(context.filename))] ?? {};
|
|
71
|
+
const used = /* @__PURE__ */ new Set();
|
|
72
|
+
const check = (fn) => {
|
|
73
|
+
if (!returnsGen(fn)) return;
|
|
74
|
+
const { parent } = fn;
|
|
75
|
+
if ((parent.type === "CallExpression" || parent.type === "NewExpression") && parent.arguments.some((argument) => argument === fn)) return;
|
|
76
|
+
const declaration = declaredName(statementOf(fn));
|
|
77
|
+
if (Object.hasOwn(allowed, declaration)) {
|
|
78
|
+
used.add(declaration);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
context.report({
|
|
82
|
+
node: fn,
|
|
83
|
+
messageId: "wrapper"
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
ArrowFunctionExpression: check,
|
|
88
|
+
FunctionExpression: check,
|
|
89
|
+
FunctionDeclaration: check,
|
|
90
|
+
"Program:exit"(program) {
|
|
91
|
+
for (const declaration of Object.keys(allowed)) if (!used.has(declaration)) context.report({
|
|
92
|
+
node: program,
|
|
93
|
+
messageId: "stale",
|
|
94
|
+
data: { declaration }
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
export { effectGenWrappersRule };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { folderImportsOf, layerProblem, moduleNamed } from "./folder-layers.mjs";
|
|
2
|
+
import { importsVisitor } from "./imports.mjs";
|
|
3
|
+
import { testFile } from "./package-graph.mjs";
|
|
4
|
+
import { decodedOnce } from "./rule-options.mjs";
|
|
5
|
+
import { fromRoot } from "./workspace-packages.mjs";
|
|
6
|
+
import { resolve } from "node:path";
|
|
7
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
8
|
+
// src/lint/generic/folder-imports.ts
|
|
9
|
+
const optionsOf = decodedOnce(folderImportsOf);
|
|
10
|
+
/** Whether a statement of an entry file re-exports: `export { … } from`, or `export *`. */
|
|
11
|
+
const reexports = (statement) => statement.type === "ExportNamedDeclaration" && statement.source !== null || statement.type === "ExportAllDeclaration";
|
|
12
|
+
const folderImportsRule = defineRule({
|
|
13
|
+
meta: {
|
|
14
|
+
messages: {
|
|
15
|
+
above: "{{from}} sits below {{to}} in the folder layers, so it imports nothing of it. Move what it needs down, to where both can import it.",
|
|
16
|
+
beside: "{{from}} and {{to}} sit in one layer of the folder layers, so neither imports the other. Move what it needs down, or join the two from a place above both.",
|
|
17
|
+
feature: "{{to}} is a feature a host can leave out, so {{from}} imports nothing of it. Read it through a seam {{from}} declares.",
|
|
18
|
+
entry: "{{to}} is an entry point, above every place of the folder layers, so {{from}} imports nothing of it. Import the module it re-exports.",
|
|
19
|
+
reexportOnly: "This file is an entry point at the top of its source, so it only re-exports: move this into a place of the folder layers, and re-export it here.",
|
|
20
|
+
unplaced: "{{place}} is in no layer of the folder layers. Add it to the layer it belongs in.",
|
|
21
|
+
stale: "The folder layers' exceptions let this file import {{module}}, and no import here needs that. Delete the exception."
|
|
22
|
+
},
|
|
23
|
+
schema: [{
|
|
24
|
+
type: "object",
|
|
25
|
+
properties: {
|
|
26
|
+
root: { type: "string" },
|
|
27
|
+
sources: { type: "object" }
|
|
28
|
+
},
|
|
29
|
+
required: ["root", "sources"],
|
|
30
|
+
additionalProperties: false
|
|
31
|
+
}]
|
|
32
|
+
},
|
|
33
|
+
create(context) {
|
|
34
|
+
const { root, sources } = optionsOf(context.options);
|
|
35
|
+
const path = fromRoot(root, resolve(context.filename));
|
|
36
|
+
const holding = sources.filter(({ folder }) => path.startsWith(`${folder}/`));
|
|
37
|
+
if (holding.length === 0 || testFile.test(path)) return {};
|
|
38
|
+
const used = /* @__PURE__ */ new Set();
|
|
39
|
+
const imports = importsVisitor((node, imported) => {
|
|
40
|
+
if (!imported.startsWith(".")) return;
|
|
41
|
+
const target = fromRoot(root, resolve(context.filename, "..", imported.replace(/\?.*$/, "")));
|
|
42
|
+
for (const source of holding) {
|
|
43
|
+
if (!target.startsWith(`${source.folder}/`)) continue;
|
|
44
|
+
const file = path.slice(source.folder.length + 1);
|
|
45
|
+
const module = moduleNamed(target.slice(source.folder.length + 1));
|
|
46
|
+
const problem = layerProblem(source, file, module);
|
|
47
|
+
if (problem === void 0) continue;
|
|
48
|
+
if (problem.messageId !== "unplaced" && source.exceptions?.[file]?.includes(module)) {
|
|
49
|
+
used.add(`${source.folder}\0${module}`);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
context.report({
|
|
53
|
+
node,
|
|
54
|
+
...problem
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const checkProgram = (program) => {
|
|
59
|
+
for (const source of holding) {
|
|
60
|
+
const file = path.slice(source.folder.length + 1);
|
|
61
|
+
if (source.entries !== "reexports" || moduleNamed(file).includes("/")) continue;
|
|
62
|
+
for (const statement of program.body) if (!reexports(statement)) context.report({
|
|
63
|
+
node: statement,
|
|
64
|
+
messageId: "reexportOnly"
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
...imports,
|
|
70
|
+
Program: checkProgram,
|
|
71
|
+
"Program:exit"(program) {
|
|
72
|
+
for (const source of holding) {
|
|
73
|
+
const file = path.slice(source.folder.length + 1);
|
|
74
|
+
for (const module of source.exceptions?.[file] ?? []) if (!used.has(`${source.folder}\0${module}`)) context.report({
|
|
75
|
+
node: program,
|
|
76
|
+
messageId: "stale",
|
|
77
|
+
data: { module }
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
export { folderImportsRule };
|