@antelopejs/tooling-configs 0.3.4 → 0.3.5

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.
@@ -0,0 +1,79 @@
1
+ import { join } from "node:path";
2
+ //#region src/lease/env.ts
3
+ /** The variable whose presence marks a command as running under `antelopejs-lease run`; `down --stop` finds a lease's processes by it. */
4
+ const LEASE_MARKER = "ANTELOPEJS_LEASE";
5
+ /**
6
+ * The `environ` entry that `run` hands its command and every descendant inherits, which marks a
7
+ * process as the work of lease `id`.
8
+ */
9
+ function leaseMarker(id) {
10
+ return `${LEASE_MARKER}=${id}`;
11
+ }
12
+ /**
13
+ * `env` without the lease marker, for a process that outlives the command that started it and
14
+ * belongs to no lease's `down --stop`, such as a lease's mongod started from inside another lease's
15
+ * `run`.
16
+ */
17
+ function unmarked(env) {
18
+ const { [LEASE_MARKER]: _marker, ...rest } = env;
19
+ return rest;
20
+ }
21
+ function isServerRole(value) {
22
+ return value === "api" || value === "web";
23
+ }
24
+ /** The variables `run` exports for a DMS dev stack, besides the `ANTELOPEJS_LEASE*` ones. */
25
+ const DEV_STACK_VARIABLES = [
26
+ "DMS_BACK_PORT",
27
+ "DMS_FRONT_PORT",
28
+ "DMS_INSPECT_PORT",
29
+ "DMS_SMTP_PORT",
30
+ "DMS_CLIENT_BASE_URL",
31
+ "MONGO_URL",
32
+ "MONGO_DATABASE",
33
+ "DMS_BACK_LOG",
34
+ "DMS_FRONT_LOG",
35
+ "TMPDIR",
36
+ "PORT"
37
+ ];
38
+ /** The variable that carries the lease's directory; a command is under a lease only when this and `LEASE_MARKER` are both non-empty. */
39
+ const LEASE_DIR = "ANTELOPEJS_LEASE_DIR";
40
+ /** The variable that carries the caller's own `TMPDIR` past the lease's override; empty when the caller had none, absent from a lease an older pack opened. */
41
+ const PARENT_TMPDIR = "ANTELOPEJS_LEASE_PARENT_TMPDIR";
42
+ /** The lease's own tmp folder, which `run` exports as `TMPDIR`. */
43
+ function leaseTmpDir(dir) {
44
+ return join(dir, "tmp");
45
+ }
46
+ /**
47
+ * The environment `run` hands its command: `parent` without `PORT`, plus the lease's variables.
48
+ * `PARENT_TMPDIR` keeps the caller's own `TMPDIR`, or the one an outer lease recorded.
49
+ * `PORT` comes back only for `as`, because one shell-wide `PORT` makes the backend and the
50
+ * dashboard bind the same port. `DMS_MONGO_URL` in `parent` replaces the lease's own mongod.
51
+ * `DMS_API_BASE_URL` stays unset. A backend whose config hard-codes its port falls back to a free
52
+ * one and records it in `.antelope/dev.json`, and `ajs dms dev` reads that file only without it.
53
+ */
54
+ function leaseEnv(lease, parent, as) {
55
+ const { record, dir } = lease;
56
+ const { ports } = record;
57
+ const { PORT: _inherited, ...env } = parent;
58
+ const devStack = {
59
+ DMS_BACK_PORT: String(ports.api),
60
+ DMS_FRONT_PORT: String(ports.web),
61
+ DMS_INSPECT_PORT: String(ports.inspect),
62
+ DMS_SMTP_PORT: String(ports.smtp),
63
+ DMS_CLIENT_BASE_URL: `http://localhost:${ports.web}`,
64
+ MONGO_URL: parent.DMS_MONGO_URL || `mongodb://127.0.0.1:${ports.mongo}`,
65
+ MONGO_DATABASE: `dms_${record.id}`,
66
+ DMS_BACK_LOG: join(dir, "logs", "back.log"),
67
+ DMS_FRONT_LOG: join(dir, "logs", "front.log"),
68
+ TMPDIR: leaseTmpDir(dir)
69
+ };
70
+ Object.assign(env, devStack, {
71
+ [LEASE_MARKER]: record.id,
72
+ [LEASE_DIR]: dir,
73
+ [PARENT_TMPDIR]: parent["ANTELOPEJS_LEASE_PARENT_TMPDIR"] ?? parent.TMPDIR ?? ""
74
+ });
75
+ if (as !== void 0) env.PORT = String(ports[as]);
76
+ return env;
77
+ }
78
+ //#endregion
79
+ export { isServerRole as a, leaseTmpDir as c, PARENT_TMPDIR as i, unmarked as l, LEASE_DIR as n, leaseEnv as o, LEASE_MARKER as r, leaseMarker as s, DEV_STACK_VARIABLES as t };
@@ -1,7 +1,8 @@
1
1
  import { l as skillFolder } from "./shared-igPpEDpS.mjs";
2
2
  import { f as parseJson, i as isObject } from "./json-CG2L7YFl.mjs";
3
- import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, rmSync, utimesSync, writeFileSync } from "node:fs";
4
- import { basename, join, matchesGlob, relative, resolve } from "node:path";
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, dirname, join, matchesGlob, relative, resolve } from "node:path";
5
6
  import { execFileSync } from "node:child_process";
6
7
  import { pathToFileURL } from "node:url";
7
8
  import { randomBytes } from "node:crypto";
@@ -12,8 +13,19 @@ import { homedir, tmpdir } from "node:os";
12
13
  * published packages. Nothing a journey asserts on lives here.
13
14
  */
14
15
  const CACHE_DIR = join(process.env.XDG_CACHE_HOME ?? join(homedir(), ".cache"), "antelopejs-verify");
16
+ /**
17
+ * The temp folder the operator would have outside a lease: the `TMPDIR` of
18
+ * `operatorEnv()`, else the platform default, so a lease's own tmp never
19
+ * holds a run.
20
+ */
21
+ function operatorTmpdir() {
22
+ const { TMPDIR: tmp, TMP, TEMP } = operatorEnv();
23
+ if (tmp) return tmp;
24
+ if (process.platform === "win32") return tmpdir();
25
+ return TMP || TEMP || "/tmp";
26
+ }
15
27
  /** The folder that holds every run, one subfolder per repository. */
16
- const RUNS_DIR = join(tmpdir(), "antelopejs-verify");
28
+ const RUNS_DIR = join(operatorTmpdir(), "antelopejs-verify");
17
29
  function makeWritable(folder) {
18
30
  chmodSync(folder, lstatSync(folder).mode | 448);
19
31
  for (const entry of readdirSync(folder, { withFileTypes: true })) if (entry.isDirectory()) makeWritable(join(folder, entry.name));
@@ -79,6 +91,7 @@ function loadRun(dir) {
79
91
  const stored = JSON.parse(readFileSync(file, "utf8"));
80
92
  return {
81
93
  ...stored,
94
+ timings: stored.timings ?? [],
82
95
  all: stored.all === true
83
96
  };
84
97
  }
@@ -108,7 +121,8 @@ function allocateRun(workspace, baseRef, title, all) {
108
121
  pack: "",
109
122
  manifestUrl: "",
110
123
  templateName: "",
111
- missingKeys: (workspace.config.saas?.env ?? []).filter((key) => !process.env[key])
124
+ missingKeys: (workspace.config.saas?.env ?? []).filter((key) => !process.env[key]),
125
+ timings: []
112
126
  };
113
127
  }
114
128
  const INHERITED_PREFIXES = [
@@ -117,13 +131,55 @@ const INHERITED_PREFIXES = [
117
131
  "PNPM_",
118
132
  "XDG_"
119
133
  ];
134
+ /** The real path of `path`, resolved through its nearest existing ancestor when the path itself is gone. */
135
+ function canonical(path) {
136
+ const full = resolve(path);
137
+ try {
138
+ return realpathSync(full);
139
+ } catch {
140
+ const parent = dirname(full);
141
+ return parent === full ? full : join(canonical(parent), basename(full));
142
+ }
143
+ }
144
+ function isLeaseTmp(tmp, leaseDir) {
145
+ return !!tmp && canonical(tmp) === canonical(leaseTmpDir(leaseDir));
146
+ }
147
+ /**
148
+ * The environment the operator would have outside `antelopejs-lease run`. A
149
+ * lease is active only when `ANTELOPEJS_LEASE` and `ANTELOPEJS_LEASE_DIR` are
150
+ * both non-empty. Under one, the lease's dev-stack variables and its own
151
+ * `ANTELOPEJS_LEASE*` variables are dropped. `TMPDIR` is replaced only when
152
+ * it is the lease's own tmp: by the value the lease recorded, or removed when
153
+ * the operator had none, and kept as it is when the lease recorded nothing
154
+ * (an older pack). A `TMPDIR` set for the command is honoured. Outside a
155
+ * lease it is `process.env` unchanged, so the operator's own `PORT` or
156
+ * `MONGO_URL` still counts.
157
+ */
158
+ function operatorEnv() {
159
+ const leaseDir = process.env[LEASE_DIR];
160
+ if (!process.env["ANTELOPEJS_LEASE"] || !leaseDir) return process.env;
161
+ const dropped = /* @__PURE__ */ new Set([
162
+ ...DEV_STACK_VARIABLES.filter((name) => name !== "TMPDIR"),
163
+ LEASE_MARKER,
164
+ LEASE_DIR,
165
+ PARENT_TMPDIR
166
+ ]);
167
+ const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !dropped.has(key)));
168
+ const recorded = process.env[PARENT_TMPDIR];
169
+ if (recorded !== void 0 && isLeaseTmp(env.TMPDIR, leaseDir)) {
170
+ if (recorded) env.TMPDIR = recorded;
171
+ else delete env.TMPDIR;
172
+ }
173
+ return env;
174
+ }
120
175
  /**
121
176
  * The environment every driven command gets: the journey's HOME, CI=1, no
122
177
  * update check, no colors and the shared caches. Variables that could leak
123
- * the operator's own settings into the run are dropped; npm and pnpm settings in any case, since both also read their upper and lowercase spellings. `NPM_TOKEN` and other uppercase variables a `.npmrc` interpolates are kept.
178
+ * the operator's own settings or the lease's dev stack into the run are
179
+ * dropped; npm and pnpm settings in any case, since both also read their upper and lowercase spellings. `NPM_TOKEN` and other uppercase variables a `.npmrc` interpolates are kept. The config `env` can set any of them back on purpose.
124
180
  */
125
181
  function isolatedEnv(workspace, home, extra = {}) {
126
- const kept = Object.entries(process.env).filter(([key]) => !INHERITED_PREFIXES.some((prefix) => key.startsWith(prefix)) && !/^p?npm_config_/i.test(key));
182
+ const kept = Object.entries(operatorEnv()).filter(([key]) => !INHERITED_PREFIXES.some((prefix) => key.startsWith(prefix)) && !/^p?npm_config_/i.test(key));
127
183
  return {
128
184
  ...Object.fromEntries(kept),
129
185
  HOME: home,
@@ -338,4 +394,4 @@ function planFor(workspace, baseRef, all = false) {
338
394
  };
339
395
  }
340
396
  //#endregion
341
- export { readFeatures as a, allocateRun as c, loadRun as d, openWorkspace as f, planFor as i, git as l, saveRun as m, SMOKE_FEATURE as n, CACHE_DIR as o, removeTree as p, checkMap as r, RUNS_DIR as s, DEFAULT_SHARED as t, isolatedEnv as u };
397
+ export { 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 };
@@ -174,7 +174,10 @@ interface JourneyContext {
174
174
  service(name: string): ServiceEndpoint;
175
175
  /** Runs a command inside a service's container: the read-back through the native client. */
176
176
  native(name: string, service: string, args: string[]): Promise<CommandResult>;
177
- /** Writes the fixture project of the interface or module kind and returns its folder. Each call writes a fresh project, so a journey can hold several. */
177
+ /**
178
+ * Writes the fixture project of the interface or module kind and returns its folder. Each call writes a fresh project, so a journey can hold several.
179
+ * The project's `.antelope/cache` starts as a copy of a cache of registry modules an earlier passing journey of the run left exactly as a fresh `ajs` install leaves it, none installed from a lock record, so `ajs` installs a registry module once per run.
180
+ */
178
181
  fixture(options?: {
179
182
  moduleConfig?: JsonObject;
180
183
  }): string;
@@ -183,8 +186,38 @@ interface JourneyContext {
183
186
  call(name: string, app: App, request: CallRequest): Promise<CallResult>;
184
187
  /** Stops an app with SIGINT by recorded PID. */
185
188
  stop(name: string, app: App): Promise<StopResult>;
186
- /** Creates a project from the template under verification with `ajs project init`. */
189
+ /**
190
+ * Creates a project from the template under verification with `ajs project init`.
191
+ * Once init succeeds, the project's `.antelope/cache` starts as a copy of a cache of registry modules an earlier passing journey of the run left exactly as a fresh `ajs` install leaves it, none installed from a lock record.
192
+ */
187
193
  scaffold(name: string, project: string, flags?: string[]): Promise<CommandResult>;
194
+ /**
195
+ * Builds a folder once per run and gives every journey its own copy, for
196
+ * the preparation many journeys repeat, such as a scaffolded and installed
197
+ * project. Returns `<work>/<key>`. The first journey of the run that asks
198
+ * for `key` runs `build` on that empty folder with its usual recorded
199
+ * steps, after a step `prepared <key>` that marks them as the build and says
200
+ * whether the run kept it. The run keeps a copy of the folder and of the
201
+ * build's step evidence only when `build` returns, recorded at least one
202
+ * check, passed every check, and left nothing in the folder but files,
203
+ * directories and symlinks. A later journey of the run, in this `journey`
204
+ * command or a later one, gets a fresh copy of the kept folder and one
205
+ * step, `prepared <key>`, that names the journey that built it and holds
206
+ * that build's evidence under `build/`. A build that is not kept is built
207
+ * again by the next journey. Rerunning the journey that built builds again.
208
+ * In a copy, an absolute symlink into the built folder points to the same
209
+ * path in the copy; every other symlink keeps its target. `build` writes
210
+ * only inside the folder it is given: what it writes elsewhere, such as a
211
+ * sibling in the journey's work folder or the repository, stays with the
212
+ * journey that built. Two journeys that ask for the same key at once, in
213
+ * concurrent `journey` commands, both build, and the first to finish is
214
+ * kept. The commands `build` runs get a HOME of their own, deleted when
215
+ * `build` ends, so what they write there (`ajs config set git`, caches) is
216
+ * never kept and every journey continues with its own HOME. Every journey
217
+ * passes the same `build` for a key. `key` is lowercase letters and digits
218
+ * joined by dashes. `clean` deletes what the run kept.
219
+ */
220
+ prepared(key: string, build: (folder: string) => Promise<void>): Promise<string>;
188
221
  }
189
222
  /** A repo-owned journey of `verify.config.ts`, named by id in a feature file. */
190
223
  interface Journey {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antelopejs/tooling-configs",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
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",