@ref0/workspace 0.11.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 +43 -15
- 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/plugin.d.mts +5 -2
- package/dist/lint/generic/plugin.mjs +15 -2
- 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/workspace-packages.d.mts +30 -1
- package/dist/lint/generic/workspace-packages.mjs +46 -5
- package/dist/lint/graph.d.mts +6 -2
- package/dist/lint/graph.mjs +2 -2
- package/dist/review-record/review-record.mjs +9 -6
- package/dist/review-record/settings.d.mts +3 -2
- package/dist/review-record/settings.mjs +4 -1
- package/dist/task-sources.d.mts +16 -0
- package/dist/task-sources.mjs +121 -0
- package/package.json +5 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { dependedOn, fromRoot, workspacePackages } from "./lint/generic/workspace-packages.mjs";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { env } from "node:process";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
// src/task-sources.ts
|
|
9
|
+
/**
|
|
10
|
+
* A cached task's command with its sources' contents in it, so that Vite Task's key holds them.
|
|
11
|
+
*
|
|
12
|
+
* Vite Task keys a task by its command, arguments, folder and named variables, and keeps the
|
|
13
|
+
* files it read, with their hashes, in the result. The remote tier keeps one result a key, so two
|
|
14
|
+
* branches that build one package from different sources replace each other's result, and the
|
|
15
|
+
* next run on either misses: on 8 Nov a new worktree, at the commit another had just built and
|
|
16
|
+
* uploaded, replayed 3 of 12 builds and no lint, every miss naming a file only another branch had.
|
|
17
|
+
* With the sources' hash in the command, each set of contents has a key of its own, and any
|
|
18
|
+
* checkout at those contents, CI's too, finds it. The files read are still checked on a replay.
|
|
19
|
+
*
|
|
20
|
+
* The hash is of each file's Git object ID, as the checkout holds it: from Git's index, or, for a
|
|
21
|
+
* file changed or added and not ignored, hashed as Git would. Ignored files, such as the
|
|
22
|
+
* compiler's generated bundles, are left out, so two checkouts that differ only there share a key,
|
|
23
|
+
* and the files read still tell them apart. A build's sources are its package's folder and each
|
|
24
|
+
* workspace package it depends on, but their test files, with the lockfile, the workspace file and
|
|
25
|
+
* `tsconfig.base.json`. Lint's are every file.
|
|
26
|
+
*
|
|
27
|
+
* A command that `&&` joins from several takes the hash on each, as web's and overlord's staging
|
|
28
|
+
* builds do, a build and then Wrangler's dry run of its deploy. Vite Task may keep a result for
|
|
29
|
+
* each joined command, as it did for those two before they had the hash, or one for them all, as
|
|
30
|
+
* it does with it, on 9 Nov 2026: either way, every key holds the hash.
|
|
31
|
+
*
|
|
32
|
+
* Only the run that plans the tasks adds it: a task's own processes, which Vite Task marks with
|
|
33
|
+
* `VP_RUN`, load the same config, where the command is never read. Outside Git, the command is
|
|
34
|
+
* left as it is.
|
|
35
|
+
*/
|
|
36
|
+
const git = (root, args, input = "") => execFileSync("git", args, {
|
|
37
|
+
cwd: root,
|
|
38
|
+
encoding: "utf8",
|
|
39
|
+
input,
|
|
40
|
+
maxBuffer: 268435456,
|
|
41
|
+
stdio: [
|
|
42
|
+
"pipe",
|
|
43
|
+
"pipe",
|
|
44
|
+
"ignore"
|
|
45
|
+
]
|
|
46
|
+
});
|
|
47
|
+
/** Each file's Git object ID, from the root, as the checkout holds it, or none outside Git. */
|
|
48
|
+
const listObjects = (root) => {
|
|
49
|
+
try {
|
|
50
|
+
const ids = /* @__PURE__ */ new Map();
|
|
51
|
+
for (const entry of git(root, [
|
|
52
|
+
"ls-files",
|
|
53
|
+
"--stage",
|
|
54
|
+
"-z"
|
|
55
|
+
]).split("\0")) {
|
|
56
|
+
const tab = entry.indexOf(" ");
|
|
57
|
+
if (tab === -1) continue;
|
|
58
|
+
ids.set(entry.slice(tab + 1), entry.slice(0, tab).split(" ")[1] ?? "");
|
|
59
|
+
}
|
|
60
|
+
const changed = git(root, [
|
|
61
|
+
"ls-files",
|
|
62
|
+
"--modified",
|
|
63
|
+
"--others",
|
|
64
|
+
"--exclude-standard",
|
|
65
|
+
"-z"
|
|
66
|
+
]).split("\0").filter((path) => path !== "" && !path.includes("\n"));
|
|
67
|
+
const present = changed.filter((path) => existsSync(join(root, path)));
|
|
68
|
+
for (const path of changed) ids.delete(path);
|
|
69
|
+
const hashed = present.length === 0 ? [] : git(root, ["hash-object", "--stdin-paths"], present.join("\n")).split("\n");
|
|
70
|
+
for (const [index, path] of present.entries()) ids.set(path, hashed[index] ?? "");
|
|
71
|
+
return ids;
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const objects = (root) => {
|
|
77
|
+
globalThis.ref0WorkspaceTaskSources ??= /* @__PURE__ */ new Map();
|
|
78
|
+
const known = globalThis.ref0WorkspaceTaskSources.get(root);
|
|
79
|
+
if (known !== void 0) return known;
|
|
80
|
+
const listed = listObjects(root);
|
|
81
|
+
globalThis.ref0WorkspaceTaskSources.set(root, listed);
|
|
82
|
+
return listed;
|
|
83
|
+
};
|
|
84
|
+
/** Every build reads these, as its inputs name them. */
|
|
85
|
+
const shared = /* @__PURE__ */ new Set([
|
|
86
|
+
"pnpm-lock.yaml",
|
|
87
|
+
"pnpm-workspace.yaml",
|
|
88
|
+
"tsconfig.base.json"
|
|
89
|
+
]);
|
|
90
|
+
const testFile = /\.test\.[cm]?[jt]sx?$/u;
|
|
91
|
+
/** A hash of the files under `folders`, from the root, `''` for all of them, but tests unless asked. */
|
|
92
|
+
const sourcesHash = (ids, folders, tests) => {
|
|
93
|
+
const within = (path) => shared.has(path) || folders.some((folder) => folder === "" || path.startsWith(`${folder}/`));
|
|
94
|
+
const entries = [...ids].flatMap(([path, id]) => within(path) && (tests || !testFile.test(path)) ? [`${path}\0${id}`] : []);
|
|
95
|
+
entries.sort();
|
|
96
|
+
return createHash("sha256").update(entries.join("\n")).digest("hex").slice(0, 16);
|
|
97
|
+
};
|
|
98
|
+
const keyed = (root, command, folders, tests) => {
|
|
99
|
+
if (env["VP_RUN"] !== void 0) return command;
|
|
100
|
+
const ids = objects(root);
|
|
101
|
+
if (ids === null) return command;
|
|
102
|
+
const sources = `env REF0_SOURCES=${sourcesHash(ids, folders, tests)}`;
|
|
103
|
+
return command.split(" && ").map((part) => `${sources} ${part}`).join(" && ");
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* The task commands of a workspace: `builtFrom`, a package's build command, from its
|
|
107
|
+
* `vite.config.ts`'s `import.meta.url`, keyed by its folder and the workspace packages it depends
|
|
108
|
+
* on, but their tests; and `readsAll`, a command that reads the whole workspace, such as lint's,
|
|
109
|
+
* keyed by every file.
|
|
110
|
+
*/
|
|
111
|
+
const taskSources = (workspace) => ({
|
|
112
|
+
builtFrom: (config, command) => {
|
|
113
|
+
const directory = fromRoot(workspace.root, dirname(fileURLToPath(config)));
|
|
114
|
+
const packages = workspacePackages(workspace);
|
|
115
|
+
const own = [...packages.values()].find((found) => found.directory === directory);
|
|
116
|
+
const dependencies = own === void 0 ? [] : [...dependedOn(own.name, packages).values()];
|
|
117
|
+
return keyed(workspace.root, command, [directory, ...dependencies.map((dependency) => dependency.directory)], false);
|
|
118
|
+
},
|
|
119
|
+
readsAll: (command) => keyed(workspace.root, command, [""], true)
|
|
120
|
+
});
|
|
121
|
+
export { sourcesHash, taskSources };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ref0/workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "The lint and workspace checks every ref-0 repo shares",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
"types": "./dist/lint/graph.d.mts",
|
|
34
34
|
"import": "./dist/lint/graph.mjs"
|
|
35
35
|
},
|
|
36
|
+
"./task-sources": {
|
|
37
|
+
"types": "./dist/task-sources.d.mts",
|
|
38
|
+
"import": "./dist/task-sources.mjs"
|
|
39
|
+
},
|
|
36
40
|
"./review-record": {
|
|
37
41
|
"types": "./dist/review-record/index.d.mts",
|
|
38
42
|
"import": "./dist/review-record/index.mjs"
|