@ref0/workspace 0.0.0-stage → 0.2.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/LICENSE +201 -0
- package/README.md +169 -2
- package/dist/bin.d.mts +1 -0
- package/dist/bin.mjs +113 -0
- package/dist/docs-budget.mjs +122 -0
- package/dist/lint/anti-slop/LICENSE +21 -0
- package/dist/lint/anti-slop/UPSTREAM.md +11 -0
- package/dist/lint/anti-slop/effect/plugin.d.mts +3 -0
- package/dist/lint/anti-slop/effect/plugin.mjs +19 -0
- package/dist/lint/anti-slop/effect/rules/no-manual-effect-error-tag.mjs +33 -0
- package/dist/lint/anti-slop/effect/rules/no-manual-tag-comparison.mjs +32 -0
- package/dist/lint/anti-slop/effect/rules/no-manual-tagged-construction.mjs +22 -0
- package/dist/lint/anti-slop/effect/rules/no-service-constructor-imports.mjs +36 -0
- package/dist/lint/anti-slop/effect/rules/prefer-effect-match.mjs +40 -0
- package/dist/lint/anti-slop/effect/shared/tagged-values.mjs +40 -0
- package/dist/lint/anti-slop/plugin.d.mts +3 -0
- package/dist/lint/anti-slop/plugin.mjs +45 -0
- package/dist/lint/anti-slop/rules/no-array-filter-map.mjs +31 -0
- package/dist/lint/anti-slop/rules/no-chained-type-assertions.mjs +56 -0
- package/dist/lint/anti-slop/rules/no-conditional-empty-object-spread.mjs +32 -0
- package/dist/lint/anti-slop/rules/no-known-value-widening.mjs +236 -0
- package/dist/lint/anti-slop/rules/no-module-mocking.mjs +48 -0
- package/dist/lint/anti-slop/rules/no-object-parameters.mjs +48 -0
- package/dist/lint/anti-slop/rules/no-reduce-accumulator-copy.mjs +85 -0
- package/dist/lint/anti-slop/rules/no-reflect-apply.mjs +21 -0
- package/dist/lint/anti-slop/rules/no-reflect-get.mjs +21 -0
- package/dist/lint/anti-slop/rules/no-runtime-typeof.mjs +52 -0
- package/dist/lint/anti-slop/rules/no-shape-in-symbol-names.mjs +36 -0
- package/dist/lint/anti-slop/rules/no-unknown-parameters.mjs +44 -0
- package/dist/lint/anti-slop/rules/no-unknown-returns.mjs +47 -0
- package/dist/lint/anti-slop/rules/no-unknown-type-aliases.mjs +33 -0
- package/dist/lint/anti-slop/rules/no-unsafe-dictionary-type.mjs +121 -0
- package/dist/lint/anti-slop/rules/no-widen-then-assert.mjs +191 -0
- package/dist/lint/anti-slop/rules/require-readable-spacing.mjs +86 -0
- package/dist/lint/anti-slop/rules/require-safety-comment-for-type-assertion.mjs +82 -0
- package/dist/lint/anti-slop/shared/array-method.mjs +70 -0
- package/dist/lint/anti-slop/shared/child-nodes.mjs +24 -0
- package/dist/lint/anti-slop/shared/dictionary-types.mjs +248 -0
- package/dist/lint/anti-slop/shared/function-parameters.mjs +25 -0
- package/dist/lint/anti-slop/shared/lexical-type-parameters.mjs +21 -0
- package/dist/lint/anti-slop/shared/reflect-method.mjs +16 -0
- package/dist/lint/anti-slop/shared/scope.mjs +12 -0
- package/dist/lint/anti-slop/shared/string-literal.mjs +6 -0
- package/dist/lint/anti-slop/shared/type-alias-resolution.mjs +134 -0
- package/dist/lint/anti-slop/vendor/eslint-stylistic/LICENSE +22 -0
- package/dist/lint/anti-slop/vendor/eslint-stylistic/UPSTREAM.md +29 -0
- package/dist/lint/anti-slop/vendor/eslint-stylistic/padding-line-ast.mjs +32 -0
- package/dist/lint/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.mjs +608 -0
- package/dist/lint/config.d.mts +20 -0
- package/dist/lint/config.mjs +135 -0
- package/dist/lint/generic/effect-encoding.mjs +45 -0
- package/dist/lint/generic/entry-reexports.mjs +81 -0
- package/dist/lint/generic/env-at-entrypoints.mjs +65 -0
- package/dist/lint/generic/export-type-side-effects.mjs +22 -0
- package/dist/lint/generic/index-barrel.mjs +14 -0
- package/dist/lint/generic/log-messages.mjs +39 -0
- package/dist/lint/generic/plugin.d.mts +6 -0
- package/dist/lint/generic/plugin.mjs +26 -0
- package/dist/lint/generic/seeded-properties.mjs +78 -0
- package/dist/lint/plugins.d.mts +9 -0
- package/dist/lint/plugins.mjs +14 -0
- package/dist/lint/t3code/LICENSE +21 -0
- package/dist/lint/t3code/UPSTREAM.md +24 -0
- package/dist/lint/t3code/plugin.d.mts +2 -0
- package/dist/lint/t3code/plugin.mjs +20 -0
- package/dist/lint/t3code/rules/no-global-process-runtime.mjs +76 -0
- package/dist/lint/t3code/rules/no-inline-schema-compile.mjs +112 -0
- package/dist/lint/t3code/rules/no-manual-effect-runtime-in-tests.mjs +67 -0
- package/dist/lint/t3code/rules/no-native-title-tooltip.mjs +33 -0
- package/dist/lint/t3code/rules/no-test-in-loop.mjs +69 -0
- package/dist/lint/t3code/rules/no-unscoped-has.mjs +147 -0
- package/dist/lint/t3code/utils.mjs +21 -0
- package/dist/package-exports.mjs +157 -0
- package/dist/symbols/check.mjs +209 -0
- package/dist/symbols/find.mjs +63 -0
- package/dist/symbols/symbols.mjs +390 -0
- package/dist/type-coverage.mjs +68 -0
- package/dist/types/cache.mjs +157 -0
- package/dist/types/inputs.mjs +71 -0
- package/dist/types/projects.mjs +65 -0
- package/dist/types/types.mjs +175 -0
- package/package.json +68 -3
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
3
|
+
import { execPath } from "node:process";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { dirname, join, resolve } from "node:path";
|
|
6
|
+
import { Schema } from "effect";
|
|
7
|
+
// src/types/projects.ts
|
|
8
|
+
/**
|
|
9
|
+
* The TypeScript projects a config reaches through its references, each with the files it
|
|
10
|
+
* includes, as the repo's own TypeScript resolves its config. `type-coverage` names a file that
|
|
11
|
+
* none includes, and `types` reports each error in the project that includes its file.
|
|
12
|
+
*/
|
|
13
|
+
const run = promisify(execFile);
|
|
14
|
+
/**
|
|
15
|
+
* The file `specifier` names, resolved from the repo at `root`, as its own scripts would: the
|
|
16
|
+
* tools a check runs are the repo's, at the versions it pins, and this package's peers.
|
|
17
|
+
*/
|
|
18
|
+
const fromRoot = (root, specifier) => createRequire(join(root, "package.json")).resolve(specifier);
|
|
19
|
+
/** A project's config as TypeScript resolves it: the files it includes, and its references. */
|
|
20
|
+
const decodeConfig = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Struct({
|
|
21
|
+
files: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
22
|
+
references: Schema.optionalKey(Schema.Array(Schema.Struct({ path: Schema.String })))
|
|
23
|
+
})));
|
|
24
|
+
/** A reference's `path` names a project's directory or its config file. */
|
|
25
|
+
const configAt = (path) => path.endsWith(".json") ? path : join(path, "tsconfig.json");
|
|
26
|
+
/**
|
|
27
|
+
* The config at `config` and each project it reaches, through nested references, each once, as
|
|
28
|
+
* the TypeScript of the repo at `root` resolves them.
|
|
29
|
+
*/
|
|
30
|
+
const reachedProjects = async (root, config) => {
|
|
31
|
+
const tsc = join(dirname(fromRoot(root, "typescript/package.json")), "bin/tsc");
|
|
32
|
+
const projects = [];
|
|
33
|
+
const seen = /* @__PURE__ */ new Set([config]);
|
|
34
|
+
let next = [config];
|
|
35
|
+
while (next.length > 0) {
|
|
36
|
+
const configs = await Promise.all(next.map(async (path) => {
|
|
37
|
+
const { stdout } = await run(execPath, [
|
|
38
|
+
tsc,
|
|
39
|
+
"--project",
|
|
40
|
+
path,
|
|
41
|
+
"--showConfig"
|
|
42
|
+
], { maxBuffer: 67108864 });
|
|
43
|
+
return {
|
|
44
|
+
config: path,
|
|
45
|
+
...decodeConfig(stdout)
|
|
46
|
+
};
|
|
47
|
+
}));
|
|
48
|
+
next = [];
|
|
49
|
+
for (const { config, files = [], references = [] } of configs) {
|
|
50
|
+
const directory = dirname(config);
|
|
51
|
+
projects.push({
|
|
52
|
+
config,
|
|
53
|
+
files: new Set(files.map((file) => resolve(directory, file)))
|
|
54
|
+
});
|
|
55
|
+
for (const reference of references) {
|
|
56
|
+
const referenced = configAt(resolve(directory, reference.path));
|
|
57
|
+
if (seen.has(referenced)) continue;
|
|
58
|
+
seen.add(referenced);
|
|
59
|
+
next.push(referenced);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return projects;
|
|
64
|
+
};
|
|
65
|
+
export { fromRoot, reachedProjects };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { splitListed, typesCache } from "./cache.mjs";
|
|
2
|
+
import { fromRoot, reachedProjects } from "./projects.mjs";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { execPath } from "node:process";
|
|
5
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
6
|
+
// src/types/types.ts
|
|
7
|
+
/**
|
|
8
|
+
* Checks the types of every project the root `tsconfig.json` reaches, and Effect's rules, with
|
|
9
|
+
* tsrs, TypeScript 7's compiler ported to Rust, and fails on any error.
|
|
10
|
+
*
|
|
11
|
+
* ref0-workspace types
|
|
12
|
+
*
|
|
13
|
+
* It runs the tsrs that `@effect/tsgo` builds with Effect's language service, `effect-tsgo tsrs`,
|
|
14
|
+
* which reports the rules the repo's configs set as type errors. `@effect/tsgo`, `tsrs` and
|
|
15
|
+
* `typescript` are the repo's own, resolved from its root: they're this package's peers.
|
|
16
|
+
*
|
|
17
|
+
* Each file is checked with the options of the project that includes it. A project's program also
|
|
18
|
+
* holds the workspace sources it imports, since each package exports its source, and tsrs checks
|
|
19
|
+
* those under the importer's options too, such as `packages/ui`'s DOM code under `apps/web`'s
|
|
20
|
+
* Workers types. So this keeps only the errors in a project's own files, and in a file no project
|
|
21
|
+
* includes, and prints each error once. It turns off the declarations `composite` asks for:
|
|
22
|
+
* nothing here emits, and the projects are composite only so the root can reference them.
|
|
23
|
+
*
|
|
24
|
+
* Each project's results are kept for every worktree on the machine, and a project whose inputs
|
|
25
|
+
* match one, from this worktree or another, replays it, as `cache.ts` says, so every error still
|
|
26
|
+
* prints, kept or fresh.
|
|
27
|
+
*/
|
|
28
|
+
/** tsrs's options for every project. `--listFiles` names the files its program read, for the key. */
|
|
29
|
+
const options = [
|
|
30
|
+
"--noEmit",
|
|
31
|
+
"--composite",
|
|
32
|
+
"false",
|
|
33
|
+
"--declaration",
|
|
34
|
+
"false",
|
|
35
|
+
"--pretty",
|
|
36
|
+
"false",
|
|
37
|
+
"--listFiles"
|
|
38
|
+
];
|
|
39
|
+
/**
|
|
40
|
+
* Runs tsrs on `project` from `root`, so the paths it prints are from `root`, with the files its
|
|
41
|
+
* program read, and when it started.
|
|
42
|
+
*/
|
|
43
|
+
const check = (root, effectTsgo, project) => new Promise((done, fail) => {
|
|
44
|
+
const started = Date.now();
|
|
45
|
+
const child = spawn(execPath, [
|
|
46
|
+
effectTsgo,
|
|
47
|
+
"tsrs",
|
|
48
|
+
"--project",
|
|
49
|
+
project.config,
|
|
50
|
+
...options
|
|
51
|
+
], { cwd: root });
|
|
52
|
+
const stdout = [];
|
|
53
|
+
const stderr = [];
|
|
54
|
+
child.stdout.on("data", (chunk) => stdout.push(chunk));
|
|
55
|
+
child.stderr.on("data", (chunk) => stderr.push(chunk));
|
|
56
|
+
child.on("error", fail);
|
|
57
|
+
child.on("close", (status) => {
|
|
58
|
+
const { files, diagnostics } = splitListed(Buffer.concat(stdout).toString("utf8"));
|
|
59
|
+
done({
|
|
60
|
+
project,
|
|
61
|
+
status,
|
|
62
|
+
stdout: diagnostics,
|
|
63
|
+
stderr: Buffer.concat(stderr).toString("utf8"),
|
|
64
|
+
replayed: false,
|
|
65
|
+
listed: files,
|
|
66
|
+
started
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
/**
|
|
71
|
+
* The errors in tsrs's output, from `root`. Each starts a line, as `path(line,col): error TS…` or,
|
|
72
|
+
* when it's global, `error TS…`, and its indented lines below are its chain and related spans.
|
|
73
|
+
*/
|
|
74
|
+
const parseDiagnostics = (root, output) => {
|
|
75
|
+
const diagnostics = [];
|
|
76
|
+
for (const line of output.split("\n")) {
|
|
77
|
+
if (line.trim() === "") continue;
|
|
78
|
+
const last = diagnostics.at(-1);
|
|
79
|
+
if (/^\s/.test(line) && last !== void 0) {
|
|
80
|
+
last.lines.push(line);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const path = /^(.+?)\(\d+,\d+\): /.exec(line)?.[1];
|
|
84
|
+
diagnostics.push({
|
|
85
|
+
file: path === void 0 ? void 0 : resolve(root, path),
|
|
86
|
+
lines: [line]
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return diagnostics.map(({ file, lines }) => ({
|
|
90
|
+
file,
|
|
91
|
+
text: lines.join("\n")
|
|
92
|
+
}));
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* The errors to report from each project's: those in its own files, or global, or in a file no
|
|
96
|
+
* project includes, each once.
|
|
97
|
+
*/
|
|
98
|
+
const reportedErrors = (checked) => {
|
|
99
|
+
const owned = new Set(checked.flatMap(({ project }) => [...project.files]));
|
|
100
|
+
const reported = /* @__PURE__ */ new Map();
|
|
101
|
+
for (const { project, diagnostics } of checked) for (const diagnostic of diagnostics) {
|
|
102
|
+
const { file, text } = diagnostic;
|
|
103
|
+
if (file !== void 0 && owned.has(file) && !project.files.has(file)) continue;
|
|
104
|
+
reported.set(text, diagnostic);
|
|
105
|
+
}
|
|
106
|
+
return [...reported.values()];
|
|
107
|
+
};
|
|
108
|
+
/** tsrs exits 0 with no errors, and 1 or 2 with some. Anything else, or errors and none printed, is tsrs failing. */
|
|
109
|
+
const tsrsFailed = (root, { status, stdout }) => status === null || status > 2 || status !== 0 && parseDiagnostics(root, stdout).length === 0;
|
|
110
|
+
/** The errors in `run`'s own files, or global, or in a file no project of `projects` includes. */
|
|
111
|
+
const ownErrors = (root, projects, run) => reportedErrors([...projects.flatMap((project) => project === run.project ? [] : [{
|
|
112
|
+
project,
|
|
113
|
+
diagnostics: []
|
|
114
|
+
}]), {
|
|
115
|
+
project: run.project,
|
|
116
|
+
diagnostics: parseDiagnostics(root, run.stdout)
|
|
117
|
+
}]);
|
|
118
|
+
/**
|
|
119
|
+
* Replays each project's kept result whose key holds, and runs tsrs on the rest from `root`, four
|
|
120
|
+
* at a time, the most files first, so the largest starts at once. All at once took no less time on
|
|
121
|
+
* 16 cores, and held every project in memory. Each fresh result that tsrs didn't fail is kept.
|
|
122
|
+
*/
|
|
123
|
+
const checkAll = async (root, projects) => {
|
|
124
|
+
const effectTsgo = join(dirname(fromRoot(root, "@effect/tsgo/package.json")), "dist/effect-tsgo.cjs");
|
|
125
|
+
const cache = typesCache(root, projects, options);
|
|
126
|
+
const kept = await Promise.all(projects.map(async (project) => ({
|
|
127
|
+
project,
|
|
128
|
+
result: await cache.replay(project)
|
|
129
|
+
})));
|
|
130
|
+
const runs = kept.flatMap(({ project, result }) => result === void 0 ? [] : [{
|
|
131
|
+
project,
|
|
132
|
+
status: result.status,
|
|
133
|
+
stdout: result.diagnostics,
|
|
134
|
+
stderr: "",
|
|
135
|
+
replayed: true
|
|
136
|
+
}]);
|
|
137
|
+
const queue = kept.filter(({ result }) => result === void 0).map(({ project }) => project).sort((a, b) => b.files.size - a.files.size);
|
|
138
|
+
await Promise.all(Array.from({ length: 4 }, async () => {
|
|
139
|
+
for (let project = queue.shift(); project !== void 0; project = queue.shift()) {
|
|
140
|
+
const { listed, started, ...run } = await check(root, effectTsgo, project);
|
|
141
|
+
runs.push(run);
|
|
142
|
+
if (run.status !== null && !tsrsFailed(root, run) && ownErrors(root, projects, run).length === 0) await cache.keep(project, started, listed, {
|
|
143
|
+
status: run.status,
|
|
144
|
+
diagnostics: run.stdout
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}));
|
|
148
|
+
return runs.sort((a, b) => projects.indexOf(a.project) - projects.indexOf(b.project));
|
|
149
|
+
};
|
|
150
|
+
/** Checks the types of the repo at `root`, prints each error, and answers the exit code. */
|
|
151
|
+
const types = async (root) => {
|
|
152
|
+
const start = performance.now();
|
|
153
|
+
const projects = (await reachedProjects(root, resolve(root, "tsconfig.json"))).filter(({ files }) => files.size > 0);
|
|
154
|
+
const runs = (await checkAll(root, projects)).map((run) => ({
|
|
155
|
+
...run,
|
|
156
|
+
diagnostics: parseDiagnostics(root, run.stdout)
|
|
157
|
+
}));
|
|
158
|
+
const failed = runs.filter((run) => tsrsFailed(root, run));
|
|
159
|
+
for (const { project, status, stdout, stderr } of failed) {
|
|
160
|
+
console.error(`types: tsrs failed on ${relative(root, project.config)}, exit ${status}`);
|
|
161
|
+
console.error(stderr || stdout);
|
|
162
|
+
}
|
|
163
|
+
const errors = reportedErrors(runs);
|
|
164
|
+
for (const { text } of errors) console.log(text);
|
|
165
|
+
const seconds = ((performance.now() - start) / 1e3).toFixed(1);
|
|
166
|
+
const replayed = runs.filter((run) => run.replayed).length;
|
|
167
|
+
const checked = `${projects.length} projects, ${replayed} replayed, in ${seconds}s`;
|
|
168
|
+
if (failed.length > 0 || errors.length > 0) {
|
|
169
|
+
console.error(`types: ${errors.length} errors and ${failed.length} tsrs failures in ${checked}`);
|
|
170
|
+
return 1;
|
|
171
|
+
}
|
|
172
|
+
console.error(`types: no errors in ${checked}`);
|
|
173
|
+
return 0;
|
|
174
|
+
};
|
|
175
|
+
export { types };
|
package/package.json
CHANGED
|
@@ -1,6 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ref0/workspace",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "The lint and workspace checks every ref-0 repo shares",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/ref-0/home.git",
|
|
9
|
+
"directory": "packages/workspace"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"ref0-workspace": "./dist/bin.mjs"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"!dist/**/*.test.*",
|
|
17
|
+
"!dist/**/fixtures",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"exports": {
|
|
24
|
+
"./lint/config": {
|
|
25
|
+
"types": "./dist/lint/config.d.mts",
|
|
26
|
+
"import": "./dist/lint/config.mjs"
|
|
27
|
+
},
|
|
28
|
+
"./lint/plugins": {
|
|
29
|
+
"types": "./dist/lint/plugins.d.mts",
|
|
30
|
+
"import": "./dist/lint/plugins.mjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"effect": "4.1.2"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@effect/tsgo": "0.67.5",
|
|
41
|
+
"@types/node": "24.19.2",
|
|
42
|
+
"tsrs": "0.23.0-ts7.1.0-beta",
|
|
43
|
+
"typescript": "7.0.2",
|
|
44
|
+
"vite-plus": "1.5.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@effect/tsgo": "0.67.5",
|
|
48
|
+
"tsrs": "0.23.0-ts7.1.0-beta",
|
|
49
|
+
"typescript": "7.0.2",
|
|
50
|
+
"vite-plus": "1.5.0"
|
|
51
|
+
},
|
|
52
|
+
"peerDependenciesMeta": {
|
|
53
|
+
"@effect/tsgo": {
|
|
54
|
+
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"tsrs": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"typescript": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">=24"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "vp pack",
|
|
68
|
+
"test": "vp test run src",
|
|
69
|
+
"test:pack": "vp test run test/consumer.test.ts"
|
|
70
|
+
}
|
|
6
71
|
}
|