@antelopejs/tooling-configs 0.3.6 → 0.3.8

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.
@@ -1,12 +1,25 @@
1
1
  import { l as skillFolder } from "./shared-igPpEDpS.mjs";
2
- import { f as parseJson, i as isObject } from "./json-CG2L7YFl.mjs";
2
+ import { c as object, f as parseJson, i as isObject, o as list, p as str, s as num } from "./json-CG2L7YFl.mjs";
3
3
  import { c as leaseTmpDir, i as PARENT_TMPDIR, n as LEASE_DIR, r as LEASE_MARKER, t as DEV_STACK_VARIABLES } from "./env-DT0UJNeL.mjs";
4
- import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, utimesSync, writeFileSync } from "node:fs";
5
- import { basename, delimiter, dirname, join, matchesGlob, relative, resolve } from "node:path";
4
+ import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, utimesSync, writeFileSync } from "node:fs";
5
+ import { basename, delimiter, dirname, join, relative, resolve } from "node:path";
6
6
  import { execFileSync } from "node:child_process";
7
7
  import { pathToFileURL } from "node:url";
8
8
  import { randomBytes } from "node:crypto";
9
9
  import { homedir, tmpdir } from "node:os";
10
+ import { minimatch } from "minimatch";
11
+ //#region src/verify/glob.ts
12
+ /**
13
+ * Whether `file` matches `glob`, dotfiles and dot folders included: `src/**`
14
+ * matches `src/.env` and `**` matches `.prettierrc`, while braces, classes,
15
+ * extglobs and negations keep their meaning (`{.env,.npmrc}` matches `.env`,
16
+ * `[!.]*` does not). `path.matchesGlob` never lets a wildcard match a
17
+ * leading dot, so a diff touching only a dotfile would map to no feature.
18
+ */
19
+ function matchesPath(file, glob) {
20
+ return minimatch(file, glob, { dot: true });
21
+ }
22
+ //#endregion
10
23
  //#region src/verify/workspace.ts
11
24
  /**
12
25
  * Caches shared by every run: the warm pnpm store, the npm cache and the
@@ -82,7 +95,7 @@ async function openWorkspace(root, kind) {
82
95
  function stateFile(dir) {
83
96
  return join(dir, "run.json");
84
97
  }
85
- /** Reads a run created by `new`, failing with the reason when it is missing, and marks it active by touching run.json. */
98
+ /** Reads a run created by `new`, failing with the reason when it is missing, and marks it active by touching run.json. Its processes are those run.json records and those of every command's records file. */
86
99
  function loadRun(dir) {
87
100
  const file = stateFile(resolve(dir));
88
101
  if (!existsSync(file)) throw new Error(`No run at ${dir}: run.json is missing. Create one with \`new\`.`);
@@ -91,13 +104,82 @@ function loadRun(dir) {
91
104
  const stored = JSON.parse(readFileSync(file, "utf8"));
92
105
  return {
93
106
  ...stored,
107
+ processes: [...stored.processes, ...commandRecords(stored.dir)],
94
108
  timings: stored.timings ?? [],
95
109
  all: stored.all === true
96
110
  };
97
111
  }
98
- /** Persists the run state. */
112
+ /** Writes `text` to `file` through a sibling temporary file and one rename, so a reader in another process sees the old content or the new, never part of it. */
113
+ function writeWhole(file, text) {
114
+ const staging = `${file}.${randomBytes(6).toString("hex")}.tmp`;
115
+ try {
116
+ writeFileSync(staging, text);
117
+ renameSync(staging, file);
118
+ } finally {
119
+ rmSync(staging, { force: true });
120
+ }
121
+ }
122
+ /** Persists the run state; the processes a command's records file holds stay in that file only. */
99
123
  function saveRun(state) {
100
- writeFileSync(stateFile(state.dir), `${JSON.stringify(state, null, 2)}\n`);
124
+ const commands = new Set(commandRecords(state.dir).map((record) => record.pid));
125
+ writeWhole(stateFile(state.dir), `${JSON.stringify({
126
+ ...state,
127
+ processes: state.processes.filter((record) => !commands.has(record.pid))
128
+ }, null, 2)}\n`);
129
+ }
130
+ /** A command's records file in the run folder: the command's PID, a random suffix that keeps a later command with a reused PID from overwriting it, and `.json`. */
131
+ const RECORDS_FILE = /^processes-(\d+)-[0-9a-f]+\.json$/;
132
+ /** This command's records file in each run it started processes in, and the records it holds. */
133
+ const ownRecords = /* @__PURE__ */ new Map();
134
+ /**
135
+ * The processes the commands of the run in `dir` recorded in their own
136
+ * files: every command's, or only those of the command whose PID is
137
+ * `command`. A file that does not hold a list of records records nothing,
138
+ * and a temporary file a crashed command left is not read.
139
+ */
140
+ function commandRecords(dir, command) {
141
+ let names;
142
+ try {
143
+ names = readdirSync(dir);
144
+ } catch {
145
+ return [];
146
+ }
147
+ return names.flatMap((name) => {
148
+ const match = RECORDS_FILE.exec(name);
149
+ if (match === null || command !== void 0 && Number(match[1]) !== command) return [];
150
+ try {
151
+ return list(parseJson(readFileSync(join(dir, name), "utf8")), name).map((entry) => {
152
+ const record = object(entry, name);
153
+ return {
154
+ name: str(record, "name"),
155
+ pid: num(record, "pid")
156
+ };
157
+ });
158
+ } catch {
159
+ return [];
160
+ }
161
+ });
162
+ }
163
+ /**
164
+ * Adds `add` to the processes the run records and drops the records of the
165
+ * PIDs in `drop`, in `state` and in this command's records file, which
166
+ * {@link loadRun} reads with run.json and every other command's file.
167
+ * Several `journey` commands of one run may start and stop processes at
168
+ * once; each writes only its own file, whole, so none can lose a record
169
+ * another made, and none waits for another. The file goes once it records
170
+ * nothing.
171
+ */
172
+ function recordProcesses(state, change) {
173
+ const apply = (records) => [...records.filter((record) => !change.drop?.includes(record.pid)), ...change.add ?? []];
174
+ state.processes = apply(state.processes);
175
+ const own = ownRecords.get(state.dir) ?? {
176
+ file: join(state.dir, `processes-${process.pid}-${randomBytes(6).toString("hex")}.json`),
177
+ records: []
178
+ };
179
+ own.records = apply(own.records);
180
+ ownRecords.set(state.dir, own);
181
+ if (own.records.length === 0) rmSync(own.file, { force: true });
182
+ else writeWhole(own.file, `${JSON.stringify(own.records)}\n`);
101
183
  }
102
184
  /** Allocates the folders of a new run under the system temp folder. */
103
185
  function allocateRun(workspace, baseRef, title, all) {
@@ -296,7 +378,7 @@ function readFeatures(workspace) {
296
378
  });
297
379
  }
298
380
  function matches(file, globs) {
299
- return globs.some((glob) => matchesGlob(file, glob));
381
+ return globs.some((glob) => matchesPath(file, glob));
300
382
  }
301
383
  /** Whether a user can observe a change to `file`. */
302
384
  function userFacing(workspace, file) {
@@ -322,7 +404,7 @@ function featureProblems(workspace, feature, known, tracked) {
322
404
  if (!feature.body.includes(`\`${journey}\``)) problems.push(`${feature.file}: journey \`${journey}\` is not described`);
323
405
  }
324
406
  if (feature.name !== "smoke" && feature.covers.length === 0) problems.push(`${feature.file}: lists no covers globs`);
325
- for (const glob of feature.covers) if (!tracked.some((file) => matchesGlob(file, glob))) problems.push(`${feature.file}: glob ${glob} matches no tracked file`);
407
+ for (const glob of feature.covers) if (!tracked.some((file) => matchesPath(file, glob))) problems.push(`${feature.file}: glob ${glob} matches no tracked file`);
326
408
  if (feature.docs.length === 0) problems.push(`${feature.file}: lists no docs pages`);
327
409
  for (const doc of feature.docs) if (!existsSync(join(workspace.root, doc))) problems.push(`${feature.file}: docs path ${doc} does not exist`);
328
410
  return problems;
@@ -412,4 +494,4 @@ function planFor(workspace, baseRef, all = false) {
412
494
  };
413
495
  }
414
496
  //#endregion
415
- export { withLocalBins as _, readFeatures as a, allocateRun as c, loadRun as d, openWorkspace as f, saveRun as g, removeTree as h, planFor as i, git as l, operatorTmpdir as m, SMOKE_FEATURE as n, CACHE_DIR as o, operatorEnv as p, checkMap as r, RUNS_DIR as s, DEFAULT_SHARED as t, isolatedEnv as u };
497
+ export { removeTree as _, readFeatures as a, writeWhole as b, allocateRun as c, isolatedEnv as d, loadRun as f, recordProcesses as g, operatorTmpdir as h, planFor as i, commandRecords as l, operatorEnv as m, SMOKE_FEATURE as n, CACHE_DIR as o, openWorkspace as p, checkMap as r, RUNS_DIR as s, DEFAULT_SHARED as t, git as u, saveRun as v, matchesPath as x, withLocalBins as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antelopejs/tooling-configs",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "description": "Shared tooling presets for AntelopeJS repositories: oxlint (with the vendored anti-slop rules), oxfmt, ESLint for Nuxt layers, Knip, and an interface range check",
5
5
  "keywords": [
6
6
  "antelopejs",
@@ -80,6 +80,7 @@
80
80
  "dependencies": {
81
81
  "@oxlint/plugins": "1.81.0",
82
82
  "dts-bundle-generator": "^9.5.1",
83
+ "minimatch": "^10.2.6",
83
84
  "typescript": "^5.9.3",
84
85
  "yaml": "^2.9.1"
85
86
  },