@entifix/swap 0.0.0-bootstrap.0 → 0.23.23
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 +21 -0
- package/README.md +79 -1
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +6 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli.d.ts +5 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +37 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands.d.ts +57 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +204 -0
- package/dist/commands.js.map +1 -0
- package/dist/consumers.d.ts +52 -0
- package/dist/consumers.d.ts.map +1 -0
- package/dist/consumers.js +122 -0
- package/dist/consumers.js.map +1 -0
- package/dist/context.d.ts +27 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +51 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/markers.d.ts +50 -0
- package/dist/markers.d.ts.map +1 -0
- package/dist/markers.js +116 -0
- package/dist/markers.js.map +1 -0
- package/dist/reload.d.ts +12 -0
- package/dist/reload.d.ts.map +1 -0
- package/dist/reload.js +44 -0
- package/dist/reload.js.map +1 -0
- package/package.json +45 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 r10c Technologies
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,81 @@
|
|
|
1
1
|
# @entifix/swap
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Run a consumer of `@entifix/*` against a local entifix checkout before it is
|
|
4
|
+
released, and put the release back. One command, `entifix-swap`:
|
|
5
|
+
|
|
6
|
+
| Command | Does |
|
|
7
|
+
| -------------------------- | --------------------------------------------------------------------------------------------------- |
|
|
8
|
+
| `entifix-swap checkout` | clones entifix into `.entifix/` if it is missing, then `pnpm install` inside it |
|
|
9
|
+
| `entifix-swap local` | runs entifix's `dev-sync` from that clone: build, copy over the release, rebuild on every save |
|
|
10
|
+
| `entifix-swap registry` | deletes the synced copies and relinks the release, in a few seconds |
|
|
11
|
+
| `entifix-swap status` | the release, or which packages are synced and from which entifix commit |
|
|
12
|
+
| `entifix-swap guard` | refuses a commit while a synced copy is installed; `ENTIFIX_DEV_SYNC_OK=1` lets one through |
|
|
13
|
+
| `entifix-swap fingerprint` | the Nx runtime input that keeps a synced build out of the task cache; prints nothing on the release |
|
|
14
|
+
|
|
15
|
+
It is how an entifix change is proven in an application **before** it is
|
|
16
|
+
released: sync the branch, run the consumer's whole suite against it, and cut
|
|
17
|
+
one release for everything the run turned up
|
|
18
|
+
([ADR 0036](../../../docs/adr/0036-a-consumer-proves-an-entifix-change-before-it-is-released.md)).
|
|
19
|
+
|
|
20
|
+
## Setting a consumer up
|
|
21
|
+
|
|
22
|
+
```jsonc
|
|
23
|
+
// package.json
|
|
24
|
+
{
|
|
25
|
+
"scripts": {
|
|
26
|
+
"entifix:checkout": "entifix-swap checkout",
|
|
27
|
+
"entifix:local": "entifix-swap local",
|
|
28
|
+
"entifix:registry": "entifix-swap registry",
|
|
29
|
+
"entifix:status": "entifix-swap status",
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": { "@entifix/swap": "<the release every other @entifix/* is on>" },
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- **Every `@entifix/*` at one version from the registry.** A `link:` or `file:`
|
|
36
|
+
specifier resolves `effect` and `react` from entifix's own `node_modules`, and
|
|
37
|
+
two copies of either break identity without an error. The sync copies files
|
|
38
|
+
into the consumer's own store instead, where they resolve the consumer's.
|
|
39
|
+
- **`/.entifix/` in `.gitignore`**, and in any tool that walks the tree without
|
|
40
|
+
reading `.gitignore` (ESLint's flat config does not). `checkout` refuses to
|
|
41
|
+
clone into a path the repository would commit.
|
|
42
|
+
- **`entifix-swap guard` in the pre-commit hook.** CI installs the pinned
|
|
43
|
+
release, so a commit that works only against a synced copy fails there.
|
|
44
|
+
- **`{ "runtime": "node_modules/.bin/entifix-swap fingerprint" }` in the task
|
|
45
|
+
inputs** every cacheable target reads (`sharedGlobals` in Nx). Nx keys an
|
|
46
|
+
installed package on its lockfile version, and a synced copy keeps it; without
|
|
47
|
+
this input a build against the local entifix and a build against the release
|
|
48
|
+
share a cache entry.
|
|
49
|
+
|
|
50
|
+
`ENTIFIX_DIR` (default `.entifix`), `ENTIFIX_REPO` and `ENTIFIX_REF` configure
|
|
51
|
+
`checkout` and `local`. Every consumer checkout — each repository, and each
|
|
52
|
+
worktree of one — keeps its **own** clone, so two of them can change entifix on
|
|
53
|
+
two branches at once. An entifix branch one consumer needs from another has to
|
|
54
|
+
be pushed and fetched like any other branch.
|
|
55
|
+
|
|
56
|
+
## Restarting services
|
|
57
|
+
|
|
58
|
+
A Next dev server serves a synced change by itself. A service started by
|
|
59
|
+
`@nx/js:node` restarts only on the Nx daemon's file events, and the daemon
|
|
60
|
+
ignores `node_modules` — so while `local` runs it polls the synced versions and
|
|
61
|
+
touches the `package.json` of every service that runs a changed package. A touch
|
|
62
|
+
moves the mtime and no content, so it fires the restart and leaves `git status`
|
|
63
|
+
clean. `registry` restarts them too, putting the release back.
|
|
64
|
+
|
|
65
|
+
- **Which services.** A tracked `package.json` whose `nx.targets.dev.executor`
|
|
66
|
+
is `@nx/js:node` and whose dependencies name a changed package **or any
|
|
67
|
+
entifix package that depends on one**. The dependency graph is read from the
|
|
68
|
+
installed entifix manifests, not from the consumer.
|
|
69
|
+
- **When.** Once the synced versions have held still for 1.5s, so a sync of
|
|
70
|
+
every package restarts each service once. Tune with `ENTIFIX_RELOAD_POLL_MS` /
|
|
71
|
+
`ENTIFIX_RELOAD_SETTLE_MS`.
|
|
72
|
+
- A consumer with no such service — a static site — restarts nothing.
|
|
73
|
+
|
|
74
|
+
## Why a copy and not pnpm's own mechanisms
|
|
75
|
+
|
|
76
|
+
`pnpm install --force` does not undo a sync — pnpm 11's optimistic repeat
|
|
77
|
+
install answers "Already up to date" and leaves every copy in place; `registry`
|
|
78
|
+
deletes the synced store entries and installs without that shortcut. A git
|
|
79
|
+
submodule would record an entifix commit in the consumer's history, and a
|
|
80
|
+
workspace glob over the clone would rewrite the lockfile whenever the clone is
|
|
81
|
+
present, so CI and a laptop would resolve differently.
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
|
package/dist/bin.js
ADDED
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { main } from './cli.js';\nimport { processContext } from './context.js';\n\nprocess.exitCode = await main(\n process.argv.slice(2),\n processContext(process.cwd()),\n);\n"],"names":["main","processContext","process","exitCode","argv","slice","cwd"],"mappings":";AACA,SAASA,IAAI,QAAQ,WAAW;AAChC,SAASC,cAAc,QAAQ,eAAe;AAE9CC,QAAQC,QAAQ,GAAG,MAAMH,KACvBE,QAAQE,IAAI,CAACC,KAAK,CAAC,IACnBJ,eAAeC,QAAQI,GAAG"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAYhD,eAAO,MAAM,KAAK,QASN,CAAC;AAEb,+CAA+C;AAC/C,wBAAsB,IAAI,CACxB,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,GAAG,EAAE,WAAW,GACf,OAAO,CAAC,MAAM,CAAC,CAYjB"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `entifix-swap <command>`: run a consumer of `@entifix/*` against a local
|
|
3
|
+
* entifix checkout, and put the release back.
|
|
4
|
+
*/ import { checkout, fingerprint, guard, local, registry, status } from './commands.js';
|
|
5
|
+
const COMMANDS = {
|
|
6
|
+
checkout,
|
|
7
|
+
local: (ctx)=>local(ctx),
|
|
8
|
+
registry,
|
|
9
|
+
status,
|
|
10
|
+
guard,
|
|
11
|
+
fingerprint
|
|
12
|
+
};
|
|
13
|
+
export const USAGE = [
|
|
14
|
+
'Usage: entifix-swap <command>',
|
|
15
|
+
'',
|
|
16
|
+
' checkout clone entifix into $ENTIFIX_DIR (.entifix) and install it',
|
|
17
|
+
' local sync that clone over the installed release, rebuilding on save',
|
|
18
|
+
' registry put the release back',
|
|
19
|
+
' status the release, or what is synced and from which commit',
|
|
20
|
+
' guard refuse a commit while a synced copy is installed (pre-commit)',
|
|
21
|
+
' fingerprint the Nx runtime input that keeps a sync out of the cache'
|
|
22
|
+
].join('\n');
|
|
23
|
+
/** Runs one command; answers its exit code. */ export async function main(argv, ctx) {
|
|
24
|
+
const [name] = argv;
|
|
25
|
+
if (name === undefined || name === '--help' || name === '-h') {
|
|
26
|
+
ctx.out(USAGE);
|
|
27
|
+
return name === undefined ? 2 : 0;
|
|
28
|
+
}
|
|
29
|
+
const command = COMMANDS[name];
|
|
30
|
+
if (command === undefined) {
|
|
31
|
+
ctx.err(`entifix-swap: unknown command "${name}"\n\n${USAGE}`);
|
|
32
|
+
return 2;
|
|
33
|
+
}
|
|
34
|
+
return command(ctx);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts"],"sourcesContent":["/**\n * `entifix-swap <command>`: run a consumer of `@entifix/*` against a local\n * entifix checkout, and put the release back.\n */\nimport {\n checkout,\n fingerprint,\n guard,\n local,\n registry,\n status,\n} from './commands.js';\nimport type { SwapContext } from './context.js';\n\nconst COMMANDS: Record<string, (ctx: SwapContext) => number | Promise<number>> =\n {\n checkout,\n local: ctx => local(ctx),\n registry,\n status,\n guard,\n fingerprint,\n };\n\nexport const USAGE = [\n 'Usage: entifix-swap <command>',\n '',\n ' checkout clone entifix into $ENTIFIX_DIR (.entifix) and install it',\n ' local sync that clone over the installed release, rebuilding on save',\n ' registry put the release back',\n ' status the release, or what is synced and from which commit',\n ' guard refuse a commit while a synced copy is installed (pre-commit)',\n ' fingerprint the Nx runtime input that keeps a sync out of the cache',\n].join('\\n');\n\n/** Runs one command; answers its exit code. */\nexport async function main(\n argv: readonly string[],\n ctx: SwapContext,\n): Promise<number> {\n const [name] = argv;\n if (name === undefined || name === '--help' || name === '-h') {\n ctx.out(USAGE);\n return name === undefined ? 2 : 0;\n }\n const command = COMMANDS[name];\n if (command === undefined) {\n ctx.err(`entifix-swap: unknown command \"${name}\"\\n\\n${USAGE}`);\n return 2;\n }\n return command(ctx);\n}\n"],"names":["checkout","fingerprint","guard","local","registry","status","COMMANDS","ctx","USAGE","join","main","argv","name","undefined","out","command","err"],"mappings":"AAAA;;;CAGC,GACD,SACEA,QAAQ,EACRC,WAAW,EACXC,KAAK,EACLC,KAAK,EACLC,QAAQ,EACRC,MAAM,QACD,gBAAgB;AAGvB,MAAMC,WACJ;IACEN;IACAG,OAAOI,CAAAA,MAAOJ,MAAMI;IACpBH;IACAC;IACAH;IACAD;AACF;AAEF,OAAO,MAAMO,QAAQ;IACnB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAACC,IAAI,CAAC,MAAM;AAEb,6CAA6C,GAC7C,OAAO,eAAeC,KACpBC,IAAuB,EACvBJ,GAAgB;IAEhB,MAAM,CAACK,KAAK,GAAGD;IACf,IAAIC,SAASC,aAAaD,SAAS,YAAYA,SAAS,MAAM;QAC5DL,IAAIO,GAAG,CAACN;QACR,OAAOI,SAASC,YAAY,IAAI;IAClC;IACA,MAAME,UAAUT,QAAQ,CAACM,KAAK;IAC9B,IAAIG,YAAYF,WAAW;QACzBN,IAAIS,GAAG,CAAC,CAAC,+BAA+B,EAAEJ,KAAK,KAAK,EAAEJ,OAAO;QAC7D,OAAO;IACT;IACA,OAAOO,QAAQR;AACjB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { SwapContext } from './context.js';
|
|
2
|
+
export declare const DEFAULT_DIR = ".entifix";
|
|
3
|
+
export declare const DEFAULT_REPO = "git@github.com:r10c-technologies/entifix.git";
|
|
4
|
+
/**
|
|
5
|
+
* Gives this checkout its own entifix clone, gitignored, at `$ENTIFIX_DIR`.
|
|
6
|
+
*
|
|
7
|
+
* Clones only when the directory is missing, and never touches an existing
|
|
8
|
+
* clone beyond `pnpm install`: its branch and uncommitted work are yours.
|
|
9
|
+
* Refuses a directory the repository would commit, because a clone that is not
|
|
10
|
+
* ignored is 100 MB of someone else's history one `git add .` away from a pull
|
|
11
|
+
* request. `ENTIFIX_REPO` and `ENTIFIX_REF` pick what to clone.
|
|
12
|
+
*/
|
|
13
|
+
export declare function checkout(ctx: SwapContext): Promise<number>;
|
|
14
|
+
export interface LocalOptions {
|
|
15
|
+
readonly pollMs?: number;
|
|
16
|
+
readonly settleMs?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Runs this checkout against its own local entifix instead of the release.
|
|
20
|
+
*
|
|
21
|
+
* Starts entifix's `dev-sync` in the clone `checkout` made: it builds every
|
|
22
|
+
* entifix package once, copies each over the release installed here, then
|
|
23
|
+
* rebuilds and re-copies whatever you save. Runs until it is stopped; the
|
|
24
|
+
* copies stay until `registry` puts the release back. Beside it, the services
|
|
25
|
+
* each sync changes are restarted (see `reload.ts`).
|
|
26
|
+
*
|
|
27
|
+
* ⚠️ Every inherited `NX_*` variable is dropped first. Started through the
|
|
28
|
+
* consumer's Nx, the environment carries its workspace root, its task id and
|
|
29
|
+
* its `NX_INVOCATION_ROOT_PID` — and entifix's Nx reading those believes it is
|
|
30
|
+
* a nested task of the consumer, which is how a shared root pid produces
|
|
31
|
+
* `Recursive task invocation detected`. `nx watch` also needs the daemon, so an
|
|
32
|
+
* inherited `NX_DAEMON=false` would stop it cold.
|
|
33
|
+
*/
|
|
34
|
+
export declare function local(ctx: SwapContext, options?: LocalOptions): Promise<number>;
|
|
35
|
+
/** Puts the release back, and restarts the services that ran a synced copy. */
|
|
36
|
+
export declare function registry(ctx: SwapContext): Promise<number>;
|
|
37
|
+
export declare function status(ctx: SwapContext): number;
|
|
38
|
+
/**
|
|
39
|
+
* Refuses a commit made while `node_modules` carries an unreleased entifix.
|
|
40
|
+
*
|
|
41
|
+
* A synced copy lives only in `node_modules`, and CI installs the version the
|
|
42
|
+
* lockfile pins. A commit that works locally because of synced code is therefore
|
|
43
|
+
* a commit that fails in CI, or worse passes there against a release that does
|
|
44
|
+
* not have the behaviour it was written for. `ENTIFIX_DEV_SYNC_OK=1` lets one
|
|
45
|
+
* through deliberately — an environment variable rather than `--no-verify`, so
|
|
46
|
+
* the rest of the hook still runs.
|
|
47
|
+
*/
|
|
48
|
+
export declare function guard(ctx: SwapContext): number;
|
|
49
|
+
/**
|
|
50
|
+
* Prints the cache-key fragment (see `fingerprintOf` in `markers.ts`).
|
|
51
|
+
*
|
|
52
|
+
* ⚠️ It must never fail: Nx computes it for every task hash, so a failure here
|
|
53
|
+
* breaks every command in the workspace. An unreadable store prints a fixed
|
|
54
|
+
* marker instead, which misses the cache rather than trusting it.
|
|
55
|
+
*/
|
|
56
|
+
export declare function fingerprint(ctx: SwapContext): number;
|
|
57
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAUhD,eAAO,MAAM,WAAW,aAAa,CAAC;AACtC,eAAO,MAAM,YAAY,iDAAiD,CAAC;AAM3E;;;;;;;;GAQG;AACH,wBAAsB,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAiDhE;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,KAAK,CACzB,GAAG,EAAE,WAAW,EAChB,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,MAAM,CAAC,CAwCjB;AAED,+EAA+E;AAC/E,wBAAsB,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CA0BhE;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,CAG/C;AAED;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,CAO9C;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,CASpD"}
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The kit's commands, one function each, every one answering an exit code.
|
|
3
|
+
*
|
|
4
|
+
* | Command | Does |
|
|
5
|
+
* | ------------- | ------------------------------------------------------------------------ |
|
|
6
|
+
* | `checkout` | clones entifix into `$ENTIFIX_DIR` (`.entifix`), then `pnpm install`s it |
|
|
7
|
+
* | `local` | runs entifix's `dev-sync` from that clone, restarting services it changes |
|
|
8
|
+
* | `registry` | deletes the synced copies and relinks the release |
|
|
9
|
+
* | `status` | the release, or which packages are synced and from which commit |
|
|
10
|
+
* | `guard` | refuses a commit while a synced copy is installed |
|
|
11
|
+
* | `fingerprint` | the Nx runtime input that keeps a synced build out of the task cache |
|
|
12
|
+
*
|
|
13
|
+
* Every consumer checkout — each repository, and each worktree of one — keeps
|
|
14
|
+
* its own clone, so two of them can change entifix on two branches at once.
|
|
15
|
+
*/ import { existsSync } from 'node:fs';
|
|
16
|
+
import { join, resolve } from 'node:path';
|
|
17
|
+
import { affectedPackages, entifixDependencies, formatRestart, servicesToRestart, touch, workspaceManifests } from './consumers.js';
|
|
18
|
+
import { fingerprintOf, formatStatus, formatSyncedFindings, restoreRelease, syncedEntifixPackages } from './markers.js';
|
|
19
|
+
import { makeReloader } from './reload.js';
|
|
20
|
+
export const DEFAULT_DIR = '.entifix';
|
|
21
|
+
export const DEFAULT_REPO = 'git@github.com:r10c-technologies/entifix.git';
|
|
22
|
+
const cloneDir = (ctx)=>ctx.env['ENTIFIX_DIR'] || DEFAULT_DIR;
|
|
23
|
+
const isCheckout = (dir)=>existsSync(join(dir, 'nx.json'));
|
|
24
|
+
/**
|
|
25
|
+
* Gives this checkout its own entifix clone, gitignored, at `$ENTIFIX_DIR`.
|
|
26
|
+
*
|
|
27
|
+
* Clones only when the directory is missing, and never touches an existing
|
|
28
|
+
* clone beyond `pnpm install`: its branch and uncommitted work are yours.
|
|
29
|
+
* Refuses a directory the repository would commit, because a clone that is not
|
|
30
|
+
* ignored is 100 MB of someone else's history one `git add .` away from a pull
|
|
31
|
+
* request. `ENTIFIX_REPO` and `ENTIFIX_REF` pick what to clone.
|
|
32
|
+
*/ export async function checkout(ctx) {
|
|
33
|
+
const dir = cloneDir(ctx);
|
|
34
|
+
const path = resolve(ctx.root, dir);
|
|
35
|
+
// Asked with a trailing slash: a directory pattern such as `/.entifix/` does
|
|
36
|
+
// not match the bare path of a directory that does not exist yet.
|
|
37
|
+
const ignored = ctx.read('git', [
|
|
38
|
+
'check-ignore',
|
|
39
|
+
'-q',
|
|
40
|
+
`${dir.replace(/\/$/, '')}/`
|
|
41
|
+
], {
|
|
42
|
+
cwd: ctx.root
|
|
43
|
+
});
|
|
44
|
+
if (ignored === undefined) {
|
|
45
|
+
ctx.err(`entifix-swap checkout: ${dir} is not gitignored here — add it to .gitignore first`);
|
|
46
|
+
return 1;
|
|
47
|
+
}
|
|
48
|
+
if (existsSync(path)) {
|
|
49
|
+
if (!isCheckout(path)) {
|
|
50
|
+
ctx.err(`entifix-swap checkout: ${dir} exists but is not an entifix checkout — move it aside`);
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
const branch = ctx.read('git', [
|
|
54
|
+
'rev-parse',
|
|
55
|
+
'--abbrev-ref',
|
|
56
|
+
'HEAD'
|
|
57
|
+
], {
|
|
58
|
+
cwd: path
|
|
59
|
+
});
|
|
60
|
+
const commit = ctx.read('git', [
|
|
61
|
+
'rev-parse',
|
|
62
|
+
'--short',
|
|
63
|
+
'HEAD'
|
|
64
|
+
], {
|
|
65
|
+
cwd: path
|
|
66
|
+
});
|
|
67
|
+
ctx.out(`entifix-swap checkout: ${dir} already present, on ${String(branch)} @ ${String(commit)}`);
|
|
68
|
+
} else {
|
|
69
|
+
const ref = ctx.env['ENTIFIX_REF'];
|
|
70
|
+
const cloned = await ctx.run('git', [
|
|
71
|
+
'clone',
|
|
72
|
+
...ref ? [
|
|
73
|
+
'--branch',
|
|
74
|
+
ref
|
|
75
|
+
] : [],
|
|
76
|
+
ctx.env['ENTIFIX_REPO'] || DEFAULT_REPO,
|
|
77
|
+
path
|
|
78
|
+
], {
|
|
79
|
+
cwd: ctx.root
|
|
80
|
+
});
|
|
81
|
+
if (cloned !== 0) return cloned;
|
|
82
|
+
}
|
|
83
|
+
return ctx.run('pnpm', [
|
|
84
|
+
'--dir',
|
|
85
|
+
path,
|
|
86
|
+
'install'
|
|
87
|
+
], {
|
|
88
|
+
cwd: ctx.root
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Runs this checkout against its own local entifix instead of the release.
|
|
93
|
+
*
|
|
94
|
+
* Starts entifix's `dev-sync` in the clone `checkout` made: it builds every
|
|
95
|
+
* entifix package once, copies each over the release installed here, then
|
|
96
|
+
* rebuilds and re-copies whatever you save. Runs until it is stopped; the
|
|
97
|
+
* copies stay until `registry` puts the release back. Beside it, the services
|
|
98
|
+
* each sync changes are restarted (see `reload.ts`).
|
|
99
|
+
*
|
|
100
|
+
* ⚠️ Every inherited `NX_*` variable is dropped first. Started through the
|
|
101
|
+
* consumer's Nx, the environment carries its workspace root, its task id and
|
|
102
|
+
* its `NX_INVOCATION_ROOT_PID` — and entifix's Nx reading those believes it is
|
|
103
|
+
* a nested task of the consumer, which is how a shared root pid produces
|
|
104
|
+
* `Recursive task invocation detected`. `nx watch` also needs the daemon, so an
|
|
105
|
+
* inherited `NX_DAEMON=false` would stop it cold.
|
|
106
|
+
*/ export async function local(ctx, options = {}) {
|
|
107
|
+
const dir = cloneDir(ctx);
|
|
108
|
+
const path = resolve(ctx.root, dir);
|
|
109
|
+
if (!isCheckout(path)) {
|
|
110
|
+
ctx.err(`entifix-swap local: no entifix checkout at ${dir} — run \`entifix-swap checkout\` first`);
|
|
111
|
+
return 1;
|
|
112
|
+
}
|
|
113
|
+
const env = {
|
|
114
|
+
ENTIFIX_CONSUMERS: ctx.root
|
|
115
|
+
};
|
|
116
|
+
for (const [name, value] of Object.entries(ctx.env)){
|
|
117
|
+
if (!name.startsWith('NX_') && name !== 'ENTIFIX_CONSUMERS') {
|
|
118
|
+
env[name] = value;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const reloader = makeReloader({
|
|
122
|
+
root: ctx.root,
|
|
123
|
+
settleMs: options.settleMs ?? Number(ctx.env['ENTIFIX_RELOAD_SETTLE_MS'] ?? 1500),
|
|
124
|
+
now: Date.now,
|
|
125
|
+
log: ctx.out
|
|
126
|
+
});
|
|
127
|
+
const poll = setInterval(reloader.tick, options.pollMs ?? Number(ctx.env['ENTIFIX_RELOAD_POLL_MS'] ?? 1000));
|
|
128
|
+
ctx.out('entifix-swap: watching synced versions — a sync restarts the services that run it.');
|
|
129
|
+
try {
|
|
130
|
+
return await ctx.run('pnpm', [
|
|
131
|
+
'exec',
|
|
132
|
+
'nx',
|
|
133
|
+
'run',
|
|
134
|
+
'@entifix/source:dev-sync'
|
|
135
|
+
], {
|
|
136
|
+
cwd: path,
|
|
137
|
+
env
|
|
138
|
+
});
|
|
139
|
+
} finally{
|
|
140
|
+
clearInterval(poll);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** Puts the release back, and restarts the services that ran a synced copy. */ export async function registry(ctx) {
|
|
144
|
+
// Read before the restore deletes them: a running service still holds the
|
|
145
|
+
// synced code.
|
|
146
|
+
const wasSynced = syncedEntifixPackages(ctx.root).map((pkg)=>pkg.name);
|
|
147
|
+
const dependencies = entifixDependencies(ctx.root);
|
|
148
|
+
let failed = 0;
|
|
149
|
+
const restored = await restoreRelease(ctx.root, async (dir)=>{
|
|
150
|
+
failed = await ctx.run('pnpm', [
|
|
151
|
+
'install',
|
|
152
|
+
'--config.optimistic-repeat-install=false'
|
|
153
|
+
], {
|
|
154
|
+
cwd: dir
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
if (failed !== 0) return failed;
|
|
158
|
+
ctx.out(`Restored ${String(restored)} synced entifix entries to the release.`);
|
|
159
|
+
if (wasSynced.length > 0) {
|
|
160
|
+
const services = servicesToRestart(workspaceManifests(ctx.root), affectedPackages(wasSynced, dependencies));
|
|
161
|
+
touch(ctx.root, services, new Date());
|
|
162
|
+
ctx.out(formatRestart(wasSynced, services, 'put back'));
|
|
163
|
+
}
|
|
164
|
+
return 0;
|
|
165
|
+
}
|
|
166
|
+
export function status(ctx) {
|
|
167
|
+
ctx.out(formatStatus(syncedEntifixPackages(ctx.root)));
|
|
168
|
+
return 0;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Refuses a commit made while `node_modules` carries an unreleased entifix.
|
|
172
|
+
*
|
|
173
|
+
* A synced copy lives only in `node_modules`, and CI installs the version the
|
|
174
|
+
* lockfile pins. A commit that works locally because of synced code is therefore
|
|
175
|
+
* a commit that fails in CI, or worse passes there against a release that does
|
|
176
|
+
* not have the behaviour it was written for. `ENTIFIX_DEV_SYNC_OK=1` lets one
|
|
177
|
+
* through deliberately — an environment variable rather than `--no-verify`, so
|
|
178
|
+
* the rest of the hook still runs.
|
|
179
|
+
*/ export function guard(ctx) {
|
|
180
|
+
const synced = syncedEntifixPackages(ctx.root);
|
|
181
|
+
if (synced.length > 0 && ctx.env['ENTIFIX_DEV_SYNC_OK'] !== '1') {
|
|
182
|
+
ctx.err(formatSyncedFindings(synced));
|
|
183
|
+
return 1;
|
|
184
|
+
}
|
|
185
|
+
return 0;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Prints the cache-key fragment (see `fingerprintOf` in `markers.ts`).
|
|
189
|
+
*
|
|
190
|
+
* ⚠️ It must never fail: Nx computes it for every task hash, so a failure here
|
|
191
|
+
* breaks every command in the workspace. An unreadable store prints a fixed
|
|
192
|
+
* marker instead, which misses the cache rather than trusting it.
|
|
193
|
+
*/ export function fingerprint(ctx) {
|
|
194
|
+
let value;
|
|
195
|
+
try {
|
|
196
|
+
value = fingerprintOf(syncedEntifixPackages(ctx.root));
|
|
197
|
+
} catch {
|
|
198
|
+
value = 'unreadable';
|
|
199
|
+
}
|
|
200
|
+
ctx.write(value);
|
|
201
|
+
return 0;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands.ts"],"sourcesContent":["/**\n * The kit's commands, one function each, every one answering an exit code.\n *\n * | Command | Does |\n * | ------------- | ------------------------------------------------------------------------ |\n * | `checkout` | clones entifix into `$ENTIFIX_DIR` (`.entifix`), then `pnpm install`s it |\n * | `local` | runs entifix's `dev-sync` from that clone, restarting services it changes |\n * | `registry` | deletes the synced copies and relinks the release |\n * | `status` | the release, or which packages are synced and from which commit |\n * | `guard` | refuses a commit while a synced copy is installed |\n * | `fingerprint` | the Nx runtime input that keeps a synced build out of the task cache |\n *\n * Every consumer checkout — each repository, and each worktree of one — keeps\n * its own clone, so two of them can change entifix on two branches at once.\n */\nimport { existsSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\n\nimport {\n affectedPackages,\n entifixDependencies,\n formatRestart,\n servicesToRestart,\n touch,\n workspaceManifests,\n} from './consumers.js';\nimport type { SwapContext } from './context.js';\nimport {\n fingerprintOf,\n formatStatus,\n formatSyncedFindings,\n restoreRelease,\n syncedEntifixPackages,\n} from './markers.js';\nimport { makeReloader } from './reload.js';\n\nexport const DEFAULT_DIR = '.entifix';\nexport const DEFAULT_REPO = 'git@github.com:r10c-technologies/entifix.git';\n\nconst cloneDir = (ctx: SwapContext) => ctx.env['ENTIFIX_DIR'] || DEFAULT_DIR;\n\nconst isCheckout = (dir: string) => existsSync(join(dir, 'nx.json'));\n\n/**\n * Gives this checkout its own entifix clone, gitignored, at `$ENTIFIX_DIR`.\n *\n * Clones only when the directory is missing, and never touches an existing\n * clone beyond `pnpm install`: its branch and uncommitted work are yours.\n * Refuses a directory the repository would commit, because a clone that is not\n * ignored is 100 MB of someone else's history one `git add .` away from a pull\n * request. `ENTIFIX_REPO` and `ENTIFIX_REF` pick what to clone.\n */\nexport async function checkout(ctx: SwapContext): Promise<number> {\n const dir = cloneDir(ctx);\n const path = resolve(ctx.root, dir);\n // Asked with a trailing slash: a directory pattern such as `/.entifix/` does\n // not match the bare path of a directory that does not exist yet.\n const ignored = ctx.read(\n 'git',\n ['check-ignore', '-q', `${dir.replace(/\\/$/, '')}/`],\n { cwd: ctx.root },\n );\n if (ignored === undefined) {\n ctx.err(\n `entifix-swap checkout: ${dir} is not gitignored here — add it to .gitignore first`,\n );\n return 1;\n }\n\n if (existsSync(path)) {\n if (!isCheckout(path)) {\n ctx.err(\n `entifix-swap checkout: ${dir} exists but is not an entifix checkout — move it aside`,\n );\n return 1;\n }\n const branch = ctx.read('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {\n cwd: path,\n });\n const commit = ctx.read('git', ['rev-parse', '--short', 'HEAD'], {\n cwd: path,\n });\n ctx.out(\n `entifix-swap checkout: ${dir} already present, on ${String(branch)} @ ${String(commit)}`,\n );\n } else {\n const ref = ctx.env['ENTIFIX_REF'];\n const cloned = await ctx.run(\n 'git',\n [\n 'clone',\n ...(ref ? ['--branch', ref] : []),\n ctx.env['ENTIFIX_REPO'] || DEFAULT_REPO,\n path,\n ],\n { cwd: ctx.root },\n );\n if (cloned !== 0) return cloned;\n }\n\n return ctx.run('pnpm', ['--dir', path, 'install'], { cwd: ctx.root });\n}\n\nexport interface LocalOptions {\n readonly pollMs?: number;\n readonly settleMs?: number;\n}\n\n/**\n * Runs this checkout against its own local entifix instead of the release.\n *\n * Starts entifix's `dev-sync` in the clone `checkout` made: it builds every\n * entifix package once, copies each over the release installed here, then\n * rebuilds and re-copies whatever you save. Runs until it is stopped; the\n * copies stay until `registry` puts the release back. Beside it, the services\n * each sync changes are restarted (see `reload.ts`).\n *\n * ⚠️ Every inherited `NX_*` variable is dropped first. Started through the\n * consumer's Nx, the environment carries its workspace root, its task id and\n * its `NX_INVOCATION_ROOT_PID` — and entifix's Nx reading those believes it is\n * a nested task of the consumer, which is how a shared root pid produces\n * `Recursive task invocation detected`. `nx watch` also needs the daemon, so an\n * inherited `NX_DAEMON=false` would stop it cold.\n */\nexport async function local(\n ctx: SwapContext,\n options: LocalOptions = {},\n): Promise<number> {\n const dir = cloneDir(ctx);\n const path = resolve(ctx.root, dir);\n if (!isCheckout(path)) {\n ctx.err(\n `entifix-swap local: no entifix checkout at ${dir} — run \\`entifix-swap checkout\\` first`,\n );\n return 1;\n }\n\n const env: NodeJS.ProcessEnv = { ENTIFIX_CONSUMERS: ctx.root };\n for (const [name, value] of Object.entries(ctx.env)) {\n if (!name.startsWith('NX_') && name !== 'ENTIFIX_CONSUMERS') {\n env[name] = value;\n }\n }\n\n const reloader = makeReloader({\n root: ctx.root,\n settleMs:\n options.settleMs ?? Number(ctx.env['ENTIFIX_RELOAD_SETTLE_MS'] ?? 1500),\n now: Date.now,\n log: ctx.out,\n });\n const poll = setInterval(\n reloader.tick,\n options.pollMs ?? Number(ctx.env['ENTIFIX_RELOAD_POLL_MS'] ?? 1000),\n );\n ctx.out(\n 'entifix-swap: watching synced versions — a sync restarts the services that run it.',\n );\n try {\n return await ctx.run(\n 'pnpm',\n ['exec', 'nx', 'run', '@entifix/source:dev-sync'],\n { cwd: path, env },\n );\n } finally {\n clearInterval(poll);\n }\n}\n\n/** Puts the release back, and restarts the services that ran a synced copy. */\nexport async function registry(ctx: SwapContext): Promise<number> {\n // Read before the restore deletes them: a running service still holds the\n // synced code.\n const wasSynced = syncedEntifixPackages(ctx.root).map(pkg => pkg.name);\n const dependencies = entifixDependencies(ctx.root);\n let failed = 0;\n const restored = await restoreRelease(ctx.root, async dir => {\n failed = await ctx.run(\n 'pnpm',\n ['install', '--config.optimistic-repeat-install=false'],\n { cwd: dir },\n );\n });\n if (failed !== 0) return failed;\n ctx.out(\n `Restored ${String(restored)} synced entifix entries to the release.`,\n );\n if (wasSynced.length > 0) {\n const services = servicesToRestart(\n workspaceManifests(ctx.root),\n affectedPackages(wasSynced, dependencies),\n );\n touch(ctx.root, services, new Date());\n ctx.out(formatRestart(wasSynced, services, 'put back'));\n }\n return 0;\n}\n\nexport function status(ctx: SwapContext): number {\n ctx.out(formatStatus(syncedEntifixPackages(ctx.root)));\n return 0;\n}\n\n/**\n * Refuses a commit made while `node_modules` carries an unreleased entifix.\n *\n * A synced copy lives only in `node_modules`, and CI installs the version the\n * lockfile pins. A commit that works locally because of synced code is therefore\n * a commit that fails in CI, or worse passes there against a release that does\n * not have the behaviour it was written for. `ENTIFIX_DEV_SYNC_OK=1` lets one\n * through deliberately — an environment variable rather than `--no-verify`, so\n * the rest of the hook still runs.\n */\nexport function guard(ctx: SwapContext): number {\n const synced = syncedEntifixPackages(ctx.root);\n if (synced.length > 0 && ctx.env['ENTIFIX_DEV_SYNC_OK'] !== '1') {\n ctx.err(formatSyncedFindings(synced));\n return 1;\n }\n return 0;\n}\n\n/**\n * Prints the cache-key fragment (see `fingerprintOf` in `markers.ts`).\n *\n * ⚠️ It must never fail: Nx computes it for every task hash, so a failure here\n * breaks every command in the workspace. An unreadable store prints a fixed\n * marker instead, which misses the cache rather than trusting it.\n */\nexport function fingerprint(ctx: SwapContext): number {\n let value: string;\n try {\n value = fingerprintOf(syncedEntifixPackages(ctx.root));\n } catch {\n value = 'unreadable';\n }\n ctx.write(value);\n return 0;\n}\n"],"names":["existsSync","join","resolve","affectedPackages","entifixDependencies","formatRestart","servicesToRestart","touch","workspaceManifests","fingerprintOf","formatStatus","formatSyncedFindings","restoreRelease","syncedEntifixPackages","makeReloader","DEFAULT_DIR","DEFAULT_REPO","cloneDir","ctx","env","isCheckout","dir","checkout","path","root","ignored","read","replace","cwd","undefined","err","branch","commit","out","String","ref","cloned","run","local","options","ENTIFIX_CONSUMERS","name","value","Object","entries","startsWith","reloader","settleMs","Number","now","Date","log","poll","setInterval","tick","pollMs","clearInterval","registry","wasSynced","map","pkg","dependencies","failed","restored","length","services","status","guard","synced","fingerprint","write"],"mappings":"AAAA;;;;;;;;;;;;;;CAcC,GACD,SAASA,UAAU,QAAQ,UAAU;AACrC,SAASC,IAAI,EAAEC,OAAO,QAAQ,YAAY;AAE1C,SACEC,gBAAgB,EAChBC,mBAAmB,EACnBC,aAAa,EACbC,iBAAiB,EACjBC,KAAK,EACLC,kBAAkB,QACb,iBAAiB;AAExB,SACEC,aAAa,EACbC,YAAY,EACZC,oBAAoB,EACpBC,cAAc,EACdC,qBAAqB,QAChB,eAAe;AACtB,SAASC,YAAY,QAAQ,cAAc;AAE3C,OAAO,MAAMC,cAAc,WAAW;AACtC,OAAO,MAAMC,eAAe,+CAA+C;AAE3E,MAAMC,WAAW,CAACC,MAAqBA,IAAIC,GAAG,CAAC,cAAc,IAAIJ;AAEjE,MAAMK,aAAa,CAACC,MAAgBrB,WAAWC,KAAKoB,KAAK;AAEzD;;;;;;;;CAQC,GACD,OAAO,eAAeC,SAASJ,GAAgB;IAC7C,MAAMG,MAAMJ,SAASC;IACrB,MAAMK,OAAOrB,QAAQgB,IAAIM,IAAI,EAAEH;IAC/B,6EAA6E;IAC7E,kEAAkE;IAClE,MAAMI,UAAUP,IAAIQ,IAAI,CACtB,OACA;QAAC;QAAgB;QAAM,GAAGL,IAAIM,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC;KAAC,EACpD;QAAEC,KAAKV,IAAIM,IAAI;IAAC;IAElB,IAAIC,YAAYI,WAAW;QACzBX,IAAIY,GAAG,CACL,CAAC,uBAAuB,EAAET,IAAI,oDAAoD,CAAC;QAErF,OAAO;IACT;IAEA,IAAIrB,WAAWuB,OAAO;QACpB,IAAI,CAACH,WAAWG,OAAO;YACrBL,IAAIY,GAAG,CACL,CAAC,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hC,IAAIe,GAAG,CAAC5B,cAAcqD,WAAWO,UAAU;IAC7C;IACA,OAAO;AACT;AAEA,OAAO,SAASC,OAAOhD,GAAgB;IACrCA,IAAIe,GAAG,CAACvB,aAAaG,sBAAsBK,IAAIM,IAAI;IACnD,OAAO;AACT;AAEA;;;;;;;;;CASC,GACD,OAAO,SAAS2C,MAAMjD,GAAgB;IACpC,MAAMkD,SAASvD,sBAAsBK,IAAIM,IAAI;IAC7C,IAAI4C,OAAOJ,MAAM,GAAG,KAAK9C,IAAIC,GAAG,CAAC,sBAAsB,KAAK,KAAK;QAC/DD,IAAIY,GAAG,CAACnB,qBAAqByD;QAC7B,OAAO;IACT;IACA,OAAO;AACT;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,YAAYnD,GAAgB;IAC1C,IAAIwB;IACJ,IAAI;QACFA,QAAQjC,cAAcI,sBAAsBK,IAAIM,IAAI;IACtD,EAAE,OAAM;QACNkB,QAAQ;IACV;IACAxB,IAAIoD,KAAK,CAAC5B;IACV,OAAO;AACT"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** The executor whose restart is driven by the daemon's file events. */
|
|
2
|
+
export declare const RESTARTING_EXECUTOR = "@nx/js:node";
|
|
3
|
+
/** A tracked `package.json` of the consumer, parsed. */
|
|
4
|
+
export interface WorkspaceManifest {
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly manifest: PackageManifest;
|
|
7
|
+
}
|
|
8
|
+
export interface PackageManifest {
|
|
9
|
+
readonly name?: string;
|
|
10
|
+
readonly dependencies?: Record<string, string>;
|
|
11
|
+
readonly devDependencies?: Record<string, string>;
|
|
12
|
+
readonly peerDependencies?: Record<string, string>;
|
|
13
|
+
readonly optionalDependencies?: Record<string, string>;
|
|
14
|
+
readonly nx?: {
|
|
15
|
+
readonly targets?: Record<string, {
|
|
16
|
+
readonly executor?: string;
|
|
17
|
+
}>;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** A service to restart: its project name and its manifest's path. */
|
|
21
|
+
export interface Service {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly path: string;
|
|
24
|
+
}
|
|
25
|
+
/** `name → version` for every synced copy; empty on the release. */
|
|
26
|
+
export declare function syncedVersions(root: string): Map<string, string>;
|
|
27
|
+
/**
|
|
28
|
+
* Package names whose synced version differs between two readings — changed,
|
|
29
|
+
* newly synced, or put back to the release.
|
|
30
|
+
*/
|
|
31
|
+
export declare function changedPackages(before: ReadonlyMap<string, string>, after: ReadonlyMap<string, string>): string[];
|
|
32
|
+
/**
|
|
33
|
+
* `name → Set<@entifix/* it depends on>` for every entifix package installed
|
|
34
|
+
* under the virtual store, synced or not.
|
|
35
|
+
*
|
|
36
|
+
* Only an entry's own package is read: `@entifix+amqp@…` also links the
|
|
37
|
+
* packages amqp depends on beside it, and those are read from their own entries.
|
|
38
|
+
*/
|
|
39
|
+
export declare function entifixDependencies(root: string): Map<string, Set<string>>;
|
|
40
|
+
/** The changed packages plus every entifix package that reaches one of them. */
|
|
41
|
+
export declare function affectedPackages(changed: readonly string[], dependencies: ReadonlyMap<string, ReadonlySet<string>>): Set<string>;
|
|
42
|
+
/** Every tracked `package.json` in the consumer, parsed, with its path. */
|
|
43
|
+
export declare function workspaceManifests(root: string): WorkspaceManifest[];
|
|
44
|
+
/**
|
|
45
|
+
* The manifests of the projects whose `dev` restarts on file events and whose
|
|
46
|
+
* own dependencies name an affected package, sorted by project name.
|
|
47
|
+
*/
|
|
48
|
+
export declare function servicesToRestart(manifests: readonly WorkspaceManifest[], affected: ReadonlySet<string>): Service[];
|
|
49
|
+
/** Fires each service's restart by bumping its manifest's mtime. */
|
|
50
|
+
export declare function touch(root: string, services: readonly Service[], now: Date): void;
|
|
51
|
+
export declare function formatRestart(changed: readonly string[], services: readonly Service[], event?: string): string;
|
|
52
|
+
//# sourceMappingURL=consumers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumers.d.ts","sourceRoot":"","sources":["../src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mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAyB1E;AAED,gFAAgF;AAChF,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,YAAY,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,GACrD,GAAG,CAAC,MAAM,CAAC,CAcb;AAED,2EAA2E;AAC3E,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAgBpE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,SAAS,iBAAiB,EAAE,EACvC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,GAC5B,OAAO,EAAE,CASX;AAED,oEAAoE;AACpE,wBAAgB,KAAK,CACnB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,GAAG,EAAE,IAAI,GACR,IAAI,CAIN;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,KAAK,SAAW,GACf,MAAM,CAQR"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which running services a sync has to restart.
|
|
3
|
+
*
|
|
4
|
+
* A Next dev server serves a synced entifix change by itself. A service started
|
|
5
|
+
* by `@nx/js:node` does not: it restarts on the Nx daemon's file events, and the
|
|
6
|
+
* daemon ignores `node_modules`, so the process keeps the code it booted with.
|
|
7
|
+
* The restart path itself works — touching a file the daemon does watch fires it,
|
|
8
|
+
* and a touch changes no content, so `git status` stays clean.
|
|
9
|
+
*
|
|
10
|
+
* So after a sync the kit touches the manifest of every service that runs a
|
|
11
|
+
* changed package. "Runs" follows entifix's own dependencies as well: a change to
|
|
12
|
+
* `@entifix/core` restarts a service that names only `@entifix/service-shell`.
|
|
13
|
+
* A consumer with no such service — a static site — restarts nothing.
|
|
14
|
+
*/ import { execFileSync } from 'node:child_process';
|
|
15
|
+
import { existsSync, readdirSync, readFileSync, utimesSync } from 'node:fs';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
import { ownPackage, syncedEntifixPackages } from './markers.js';
|
|
18
|
+
/** The executor whose restart is driven by the daemon's file events. */ export const RESTARTING_EXECUTOR = '@nx/js:node';
|
|
19
|
+
/** `name → version` for every synced copy; empty on the release. */ export function syncedVersions(root) {
|
|
20
|
+
return new Map(syncedEntifixPackages(root).map((pkg)=>[
|
|
21
|
+
pkg.name,
|
|
22
|
+
pkg.version
|
|
23
|
+
]));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Package names whose synced version differs between two readings — changed,
|
|
27
|
+
* newly synced, or put back to the release.
|
|
28
|
+
*/ export function changedPackages(before, after) {
|
|
29
|
+
const names = new Set([
|
|
30
|
+
...before.keys(),
|
|
31
|
+
...after.keys()
|
|
32
|
+
]);
|
|
33
|
+
return [
|
|
34
|
+
...names
|
|
35
|
+
].filter((name)=>before.get(name) !== after.get(name)).sort();
|
|
36
|
+
}
|
|
37
|
+
const manifestDependencies = (manifest)=>Object.keys({
|
|
38
|
+
...manifest.dependencies,
|
|
39
|
+
...manifest.devDependencies,
|
|
40
|
+
...manifest.peerDependencies,
|
|
41
|
+
...manifest.optionalDependencies
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* `name → Set<@entifix/* it depends on>` for every entifix package installed
|
|
45
|
+
* under the virtual store, synced or not.
|
|
46
|
+
*
|
|
47
|
+
* Only an entry's own package is read: `@entifix+amqp@…` also links the
|
|
48
|
+
* packages amqp depends on beside it, and those are read from their own entries.
|
|
49
|
+
*/ export function entifixDependencies(root) {
|
|
50
|
+
const store = join(root, 'node_modules', '.pnpm');
|
|
51
|
+
const graph = new Map();
|
|
52
|
+
if (!existsSync(store)) return graph;
|
|
53
|
+
for (const entry of readdirSync(store)){
|
|
54
|
+
if (!entry.startsWith('@entifix+')) continue;
|
|
55
|
+
const manifestPath = join(store, entry, 'node_modules', '@entifix', ownPackage(entry), 'package.json');
|
|
56
|
+
if (!existsSync(manifestPath)) continue;
|
|
57
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
58
|
+
const deps = graph.get(manifest.name) ?? new Set();
|
|
59
|
+
for (const dep of manifestDependencies(manifest)){
|
|
60
|
+
if (dep.startsWith('@entifix/')) deps.add(dep);
|
|
61
|
+
}
|
|
62
|
+
graph.set(manifest.name, deps);
|
|
63
|
+
}
|
|
64
|
+
return graph;
|
|
65
|
+
}
|
|
66
|
+
/** The changed packages plus every entifix package that reaches one of them. */ export function affectedPackages(changed, dependencies) {
|
|
67
|
+
const affected = new Set(changed);
|
|
68
|
+
let grew = true;
|
|
69
|
+
while(grew){
|
|
70
|
+
grew = false;
|
|
71
|
+
for (const [name, deps] of dependencies){
|
|
72
|
+
if (affected.has(name)) continue;
|
|
73
|
+
if ([
|
|
74
|
+
...deps
|
|
75
|
+
].some((dep)=>affected.has(dep))) {
|
|
76
|
+
affected.add(name);
|
|
77
|
+
grew = true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return affected;
|
|
82
|
+
}
|
|
83
|
+
/** Every tracked `package.json` in the consumer, parsed, with its path. */ export function workspaceManifests(root) {
|
|
84
|
+
const output = execFileSync('git', [
|
|
85
|
+
'ls-files',
|
|
86
|
+
'-z',
|
|
87
|
+
'--',
|
|
88
|
+
'package.json',
|
|
89
|
+
':(glob)**/package.json'
|
|
90
|
+
], {
|
|
91
|
+
cwd: root,
|
|
92
|
+
encoding: 'utf8',
|
|
93
|
+
maxBuffer: 32 * 1024 * 1024
|
|
94
|
+
});
|
|
95
|
+
return output.split('\0').filter(Boolean).filter((path)=>existsSync(join(root, path))).map((path)=>({
|
|
96
|
+
path,
|
|
97
|
+
manifest: JSON.parse(readFileSync(join(root, path), 'utf8'))
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The manifests of the projects whose `dev` restarts on file events and whose
|
|
102
|
+
* own dependencies name an affected package, sorted by project name.
|
|
103
|
+
*/ export function servicesToRestart(manifests, affected) {
|
|
104
|
+
return manifests.filter(({ manifest })=>manifest.nx?.targets?.['dev']?.executor === RESTARTING_EXECUTOR && manifestDependencies(manifest).some((dep)=>affected.has(dep))).map(({ path, manifest })=>({
|
|
105
|
+
name: manifest.name ?? path,
|
|
106
|
+
path
|
|
107
|
+
})).sort((a, b)=>a.name.localeCompare(b.name));
|
|
108
|
+
}
|
|
109
|
+
/** Fires each service's restart by bumping its manifest's mtime. */ export function touch(root, services, now) {
|
|
110
|
+
for (const service of services){
|
|
111
|
+
utimesSync(join(root, service.path), now, now);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export function formatRestart(changed, services, event = 'synced') {
|
|
115
|
+
const what = changed.join(', ');
|
|
116
|
+
if (services.length === 0) {
|
|
117
|
+
return `entifix-swap: ${what} ${event} — no running service depends on it.`;
|
|
118
|
+
}
|
|
119
|
+
return `entifix-swap: ${what} ${event} — restarting ${services.map((service)=>service.name).join(', ')}.`;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//# sourceMappingURL=consumers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/consumers.ts"],"sourcesContent":["/**\n * Which running services a sync has to restart.\n *\n * A Next dev server serves a synced entifix change by itself. A service started\n * by `@nx/js:node` does not: it restarts on the Nx daemon's file events, and the\n * daemon ignores `node_modules`, so the process keeps the code it booted with.\n * The restart path itself works — touching a file the daemon does watch fires it,\n * and a touch changes no content, so `git status` stays clean.\n *\n * So after a sync the kit touches the manifest of every service that runs a\n * changed package. \"Runs\" follows entifix's own dependencies as well: a change to\n * `@entifix/core` restarts a service that names only `@entifix/service-shell`.\n * A consumer with no such service — a static site — restarts nothing.\n */\nimport { execFileSync } from 'node:child_process';\nimport { existsSync, readdirSync, readFileSync, utimesSync } from 'node:fs';\nimport { join } from 'node:path';\n\nimport { ownPackage, syncedEntifixPackages } from './markers.js';\n\n/** The executor whose restart is driven by the daemon's file events. */\nexport const RESTARTING_EXECUTOR = '@nx/js:node';\n\n/** A tracked `package.json` of the consumer, parsed. */\nexport interface WorkspaceManifest {\n readonly path: string;\n readonly manifest: PackageManifest;\n}\n\nexport interface PackageManifest {\n readonly name?: string;\n readonly dependencies?: Record<string, string>;\n readonly devDependencies?: Record<string, string>;\n readonly peerDependencies?: Record<string, string>;\n readonly optionalDependencies?: Record<string, string>;\n readonly nx?: {\n readonly targets?: Record<string, { readonly executor?: string }>;\n };\n}\n\n/** A service to restart: its project name and its manifest's path. */\nexport interface Service {\n readonly name: string;\n readonly path: string;\n}\n\n/** `name → version` for every synced copy; empty on the release. */\nexport function syncedVersions(root: string): Map<string, string> {\n return new Map(\n syncedEntifixPackages(root).map(pkg => [pkg.name, pkg.version]),\n );\n}\n\n/**\n * Package names whose synced version differs between two readings — changed,\n * newly synced, or put back to the release.\n */\nexport function changedPackages(\n before: ReadonlyMap<string, string>,\n after: ReadonlyMap<string, string>,\n): string[] {\n const names = new Set([...before.keys(), ...after.keys()]);\n return [...names].filter(name => before.get(name) !== after.get(name)).sort();\n}\n\nconst manifestDependencies = (manifest: PackageManifest) =>\n Object.keys({\n ...manifest.dependencies,\n ...manifest.devDependencies,\n ...manifest.peerDependencies,\n ...manifest.optionalDependencies,\n });\n\n/**\n * `name → Set<@entifix/* it depends on>` for every entifix package installed\n * under the virtual store, synced or not.\n *\n * Only an entry's own package is read: `@entifix+amqp@…` also links the\n * packages amqp depends on beside it, and those are read from their own entries.\n */\nexport function entifixDependencies(root: string): Map<string, Set<string>> {\n const store = join(root, 'node_modules', '.pnpm');\n const graph = new Map<string, Set<string>>();\n if (!existsSync(store)) return graph;\n for (const entry of readdirSync(store)) {\n if (!entry.startsWith('@entifix+')) continue;\n const manifestPath = join(\n store,\n entry,\n 'node_modules',\n '@entifix',\n ownPackage(entry),\n 'package.json',\n );\n if (!existsSync(manifestPath)) continue;\n const manifest = JSON.parse(readFileSync(manifestPath, 'utf8')) as {\n name: string;\n } & PackageManifest;\n const deps = graph.get(manifest.name) ?? new Set<string>();\n for (const dep of manifestDependencies(manifest)) {\n if (dep.startsWith('@entifix/')) deps.add(dep);\n }\n graph.set(manifest.name, deps);\n }\n return graph;\n}\n\n/** The changed packages plus every entifix package that reaches one of them. */\nexport function affectedPackages(\n changed: readonly string[],\n dependencies: ReadonlyMap<string, ReadonlySet<string>>,\n): Set<string> {\n const affected = new Set(changed);\n let grew = true;\n while (grew) {\n grew = false;\n for (const [name, deps] of dependencies) {\n if (affected.has(name)) continue;\n if ([...deps].some(dep => affected.has(dep))) {\n affected.add(name);\n grew = true;\n }\n }\n }\n return affected;\n}\n\n/** Every tracked `package.json` in the consumer, parsed, with its path. */\nexport function workspaceManifests(root: string): WorkspaceManifest[] {\n const output = execFileSync(\n 'git',\n ['ls-files', '-z', '--', 'package.json', ':(glob)**/package.json'],\n { cwd: root, encoding: 'utf8', maxBuffer: 32 * 1024 * 1024 },\n );\n return output\n .split('\\0')\n .filter(Boolean)\n .filter(path => existsSync(join(root, path)))\n .map(path => ({\n path,\n manifest: JSON.parse(\n readFileSync(join(root, path), 'utf8'),\n ) as PackageManifest,\n }));\n}\n\n/**\n * The manifests of the projects whose `dev` restarts on file events and whose\n * own dependencies name an affected package, sorted by project name.\n */\nexport function servicesToRestart(\n manifests: readonly WorkspaceManifest[],\n affected: ReadonlySet<string>,\n): Service[] {\n return manifests\n .filter(\n ({ manifest }) =>\n manifest.nx?.targets?.['dev']?.executor === RESTARTING_EXECUTOR &&\n manifestDependencies(manifest).some(dep => affected.has(dep)),\n )\n .map(({ path, manifest }) => ({ name: manifest.name ?? path, path }))\n .sort((a, b) => a.name.localeCompare(b.name));\n}\n\n/** Fires each service's restart by bumping its manifest's mtime. */\nexport function touch(\n root: string,\n services: readonly Service[],\n now: Date,\n): void {\n for (const service of services) {\n utimesSync(join(root, service.path), now, now);\n }\n}\n\nexport function formatRestart(\n changed: readonly string[],\n services: readonly Service[],\n event = 'synced',\n): string {\n const what = changed.join(', ');\n if (services.length === 0) {\n return `entifix-swap: ${what} ${event} — no running service depends on it.`;\n }\n return `entifix-swap: ${what} ${event} — restarting ${services\n .map(service => service.name)\n .join(', ')}.`;\n}\n"],"names":["execFileSync","existsSync","readdirSync","readFileSync","utimesSync","join","ownPackage","syncedEntifixPackages","RESTARTING_EXECUTOR","syncedVersions","root","Map","map","pkg","name","version","changedPackages","before","after","names","Set","keys","filter","get","sort","manifestDependencies","manifest","Object","dependencies","devDependencies","peerDependencies","optionalDependencies","entifixDependencies","store","graph","entry","startsWith","manifestPath","JSON","parse","deps","dep","add","set","affectedPackages","changed","affected","grew","has","some","workspaceManifests","output","cwd","encoding","maxBuffer","split","Boolean","path","servicesToRestart","manifests","nx","targets","executor","a","b","localeCompare","touch","services","now","service","formatRestart","event","what","length"],"mappings":"AAAA;;;;;;;;;;;;;CAaC,GACD,SAASA,YAAY,QAAQ,qBAAqB;AAClD,SAASC,UAAU,EAAEC,WAAW,EAAEC,YAAY,EAAEC,UAAU,QAAQ,UAAU;AAC5E,SAASC,IAAI,QAAQ,YAAY;AAEjC,SAASC,UAAU,EAAEC,qBAAqB,QAAQ,eAAe;AAEjE,sEAAsE,GACtE,OAAO,MAAMC,sBAAsB,cAAc;AAyBjD,kEAAkE,GAClE,OAAO,SAASC,eAAeC,IAAY;IACzC,OAAO,IAAIC,IACTJ,sBAAsBG,MAAME,GAAG,CAACC,CAAAA,MAAO;YAACA,IAAIC,IAAI;YAAED,IAAIE,OAAO;SAAC;AAElE;AAEA;;;CAGC,GACD,OAAO,SAASC,gBACdC,MAAmC,EACnCC,KAAkC;IAElC,MAAMC,QAAQ,IAAIC,IAAI;WAAIH,OAAOI,IAAI;WAAOH,MAAMG,IAAI;KAAG;IACzD,OAAO;WAAIF;KAAM,CAACG,MAAM,CAACR,C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I,QAAQ,QAAQ;IAEhB,MAAMC,OAAO3B,QAAQxC,IAAI,CAAC;IAC1B,IAAI8D,SAASM,MAAM,KAAK,GAAG;QACzB,OAAO,CAAC,cAAc,EAAED,KAAK,CAAC,EAAED,MAAM,oCAAoC,CAAC;IAC7E;IACA,OAAO,CAAC,cAAc,EAAEC,KAAK,CAAC,EAAED,MAAM,cAAc,EAAEJ,SACnDvD,GAAG,CAACyD,CAAAA,UAAWA,QAAQvD,IAAI,EAC3BT,IAAI,CAAC,MAAM,CAAC,CAAC;AAClB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface RunOptions {
|
|
2
|
+
readonly cwd: string;
|
|
3
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
4
|
+
}
|
|
5
|
+
export interface SwapContext {
|
|
6
|
+
/** The consumer's repository root. */
|
|
7
|
+
readonly root: string;
|
|
8
|
+
readonly env: NodeJS.ProcessEnv;
|
|
9
|
+
readonly out: (line: string) => void;
|
|
10
|
+
readonly err: (line: string) => void;
|
|
11
|
+
/** Writes to standard output as is, with no line ending added. */
|
|
12
|
+
readonly write: (text: string) => void;
|
|
13
|
+
/** Runs a command with the terminal attached; resolves its exit code. */
|
|
14
|
+
readonly run: (command: string, args: readonly string[], options: RunOptions) => Promise<number>;
|
|
15
|
+
/** Runs a command and returns its trimmed output, or `undefined` on failure. */
|
|
16
|
+
readonly read: (command: string, args: readonly string[], options: RunOptions) => string | undefined;
|
|
17
|
+
}
|
|
18
|
+
export declare const readCommand: SwapContext['read'];
|
|
19
|
+
export declare const runCommand: SwapContext['run'];
|
|
20
|
+
/**
|
|
21
|
+
* The repository the command was started in: git's top level, so a command run
|
|
22
|
+
* from a subdirectory still finds the consumer's `node_modules`, or the
|
|
23
|
+
* directory itself outside git.
|
|
24
|
+
*/
|
|
25
|
+
export declare const repositoryRoot: (cwd: string) => string;
|
|
26
|
+
export declare const processContext: (cwd: string) => SwapContext;
|
|
27
|
+
//# sourceMappingURL=context.d.ts.map
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
|
|
|
1
|
+
/**
|
|
2
|
+
* What a command needs from the machine: where the consumer is, its
|
|
3
|
+
* environment, two output streams and a way to run a child process. The real
|
|
4
|
+
* one is built here; specs build their own.
|
|
5
|
+
*/ import { execFileSync, spawn } from 'node:child_process';
|
|
6
|
+
export const readCommand = (command, args, options)=>{
|
|
7
|
+
try {
|
|
8
|
+
return execFileSync(command, args, {
|
|
9
|
+
cwd: options.cwd,
|
|
10
|
+
env: options.env,
|
|
11
|
+
encoding: 'utf8',
|
|
12
|
+
stdio: [
|
|
13
|
+
'ignore',
|
|
14
|
+
'pipe',
|
|
15
|
+
'ignore'
|
|
16
|
+
]
|
|
17
|
+
}).trim();
|
|
18
|
+
} catch {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export const runCommand = (command, args, options)=>new Promise((resolve)=>{
|
|
23
|
+
const child = spawn(command, args, {
|
|
24
|
+
cwd: options.cwd,
|
|
25
|
+
env: options.env,
|
|
26
|
+
stdio: 'inherit'
|
|
27
|
+
});
|
|
28
|
+
child.on('error', ()=>resolve(127));
|
|
29
|
+
child.on('close', (code)=>resolve(code ?? 1));
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* The repository the command was started in: git's top level, so a command run
|
|
33
|
+
* from a subdirectory still finds the consumer's `node_modules`, or the
|
|
34
|
+
* directory itself outside git.
|
|
35
|
+
*/ export const repositoryRoot = (cwd)=>readCommand('git', [
|
|
36
|
+
'rev-parse',
|
|
37
|
+
'--show-toplevel'
|
|
38
|
+
], {
|
|
39
|
+
cwd
|
|
40
|
+
}) || cwd;
|
|
41
|
+
export const processContext = (cwd)=>({
|
|
42
|
+
root: repositoryRoot(cwd),
|
|
43
|
+
env: process.env,
|
|
44
|
+
out: (line)=>console.log(line),
|
|
45
|
+
err: (line)=>console.error(line),
|
|
46
|
+
write: (text)=>process.stdout.write(text),
|
|
47
|
+
run: runCommand,
|
|
48
|
+
read: readCommand
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/context.ts"],"sourcesContent":["/**\n * What a command needs from the machine: where the consumer is, its\n * environment, two output streams and a way to run a child process. The real\n * one is built here; specs build their own.\n */\nimport { execFileSync, spawn } from 'node:child_process';\n\nexport interface RunOptions {\n readonly cwd: string;\n readonly env?: NodeJS.ProcessEnv;\n}\n\nexport interface SwapContext {\n /** The consumer's repository root. */\n readonly root: string;\n readonly env: NodeJS.ProcessEnv;\n readonly out: (line: string) => void;\n readonly err: (line: string) => void;\n /** Writes to standard output as is, with no line ending added. */\n readonly write: (text: string) => void;\n /** Runs a command with the terminal attached; resolves its exit code. */\n readonly run: (\n command: string,\n args: readonly string[],\n options: RunOptions,\n ) => Promise<number>;\n /** Runs a command and returns its trimmed output, or `undefined` on failure. */\n readonly read: (\n command: string,\n args: readonly string[],\n options: RunOptions,\n ) => string | undefined;\n}\n\nexport const readCommand: SwapContext['read'] = (command, args, options) => {\n try {\n return execFileSync(command, args, {\n cwd: options.cwd,\n env: options.env,\n encoding: 'utf8',\n stdio: ['ignore', 'pipe', 'ignore'],\n }).trim();\n } catch {\n return undefined;\n }\n};\n\nexport const runCommand: SwapContext['run'] = (command, args, options) =>\n new Promise(resolve => {\n const child = spawn(command, args, {\n cwd: options.cwd,\n env: options.env,\n stdio: 'inherit',\n });\n child.on('error', () => resolve(127));\n child.on('close', code => resolve(code ?? 1));\n });\n\n/**\n * The repository the command was started in: git's top level, so a command run\n * from a subdirectory still finds the consumer's `node_modules`, or the\n * directory itself outside git.\n */\nexport const repositoryRoot = (cwd: string): string =>\n readCommand('git', ['rev-parse', '--show-toplevel'], { cwd }) || cwd;\n\nexport const processContext = (cwd: string): SwapContext => ({\n root: repositoryRoot(cwd),\n env: process.env,\n out: line => console.log(line),\n err: line => console.error(line),\n write: text => process.stdout.write(text),\n run: runCommand,\n read: readCommand,\n});\n"],"names":["execFileSync","spawn","readCommand","command","args","options","cwd","env","encoding","stdio","trim","undefined","runCommand","Promise","resolve","child","on","code","repositoryRoot","processContext","root","process","out","line","console","log","err","error","write","text","stdout","run","read"],"mappings":"AAAA;;;;CAIC,GACD,SAASA,YAAY,EAAEC,KAAK,QAAQ,qBAAqB;AA6BzD,OAAO,MAAMC,cAAmC,CAACC,SAASC,MAAMC;IAC9D,IAAI;QACF,OAAOL,aAAaG,SAASC,MAAM;YACjCE,KAAKD,QAAQC,GAAG;YAChBC,KAAKF,QAAQE,GAAG;YAChBC,UAAU;YACVC,OAAO;gBAAC;gBAAU;gBAAQ;aAAS;QACrC,GAAGC,IAAI;IACT,EAAE,OAAM;QACN,OAAOC;IACT;AACF,EAAE;AAEF,OAAO,MAAMC,aAAiC,CAACT,SAASC,MAAMC,UAC5D,IAAIQ,QAAQC,CAAAA;QACV,MAAMC,QAAQd,MAAME,SAASC,MAAM;YACjCE,KAAKD,QAAQC,GAAG;YAChBC,KAAKF,QAAQE,GAAG;YAChBE,OAAO;QACT;QACAM,MAAMC,EAAE,CAAC,SAAS,IAAMF,QAAQ;QAChCC,MAAMC,EAAE,CAAC,SAASC,CAAAA,OAAQH,QAAQG,QAAQ;IAC5C,GAAG;AAEL;;;;CAIC,GACD,OAAO,MAAMC,iBAAiB,CAACZ,MAC7BJ,YAAY,OAAO;QAAC;QAAa;KAAkB,EAAE;QAAEI;IAAI,MAAMA,IAAI;AAEvE,OAAO,MAAMa,iBAAiB,CAACb,MAA8B,CAAA;QAC3Dc,MAAMF,eAAeZ;QACrBC,KAAKc,QAAQd,GAAG;QAChBe,KAAKC,CAAAA,OAAQC,QAAQC,GAAG,CAACF;QACzBG,KAAKH,CAAAA,OAAQC,QAAQG,KAAK,CAACJ;QAC3BK,OAAOC,CAAAA,OAAQR,QAAQS,MAAM,CAACF,KAAK,CAACC;QACpCE,KAAKnB;QACLoB,MAAM9B;IACR,CAAA,EAAG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './cli.js';\nexport * from './commands.js';\nexport * from './consumers.js';\nexport * from './context.js';\nexport * from './markers.js';\nexport * from './reload.js';\n"],"names":[],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,gBAAgB;AAC9B,cAAc,iBAAiB;AAC/B,cAAc,eAAe;AAC7B,cAAc,eAAe;AAC7B,cAAc,cAAc"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** One synced copy, named once whatever its peer-set duplicates. */
|
|
2
|
+
export interface SyncedPackage {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly version: string;
|
|
5
|
+
/** The entifix commit the copy was built from. */
|
|
6
|
+
readonly source: string;
|
|
7
|
+
}
|
|
8
|
+
/** The package an entry such as `@entifix+core@0.1.1_effect@3` was made for. */
|
|
9
|
+
export declare const ownPackage: (entry: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Every synced copy under a checkout's virtual store, sorted and de-duplicated
|
|
12
|
+
* by name.
|
|
13
|
+
*
|
|
14
|
+
* pnpm keeps one directory per resolved peer set, so one package can have
|
|
15
|
+
* several copies; the report names the package once.
|
|
16
|
+
*/
|
|
17
|
+
export declare function syncedEntifixPackages(root: string): SyncedPackage[];
|
|
18
|
+
/**
|
|
19
|
+
* The virtual-store entries whose own package is a synced copy.
|
|
20
|
+
*
|
|
21
|
+
* An entry such as `@entifix+amqp@0.1.1_…` also links the entifix packages amqp
|
|
22
|
+
* depends on beside it, so only the entry's own package decides — otherwise
|
|
23
|
+
* one synced `core` would mark every entry that depends on it.
|
|
24
|
+
*/
|
|
25
|
+
export declare function syncedEntifixEntries(root: string): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Deletes every synced entry and re-links the release in their place.
|
|
28
|
+
*
|
|
29
|
+
* ⚠️ Not `pnpm install --force`. With manifests and lockfile unchanged, pnpm 11's
|
|
30
|
+
* optimistic repeat install answers "Already up to date" and leaves every synced
|
|
31
|
+
* copy where it is. Deleting the entries and installing non-optimistically takes
|
|
32
|
+
* about a second and a half; a forced refetch of the whole tree took four
|
|
33
|
+
* minutes.
|
|
34
|
+
*/
|
|
35
|
+
export declare function restoreRelease(root: string, install: (root: string) => Promise<void> | void): Promise<number>;
|
|
36
|
+
/**
|
|
37
|
+
* A cache-key fragment for the task hasher: empty while the release is
|
|
38
|
+
* installed, a digest of every synced `name@version` otherwise.
|
|
39
|
+
*
|
|
40
|
+
* Nx keys an installed package on the version its lockfile resolves, and a
|
|
41
|
+
* synced copy leaves the lockfile untouched — so without this, a build against a
|
|
42
|
+
* local entifix and a build against the release share one cache entry, and
|
|
43
|
+
* whichever ran first is served to the other. Empty on the release keeps every
|
|
44
|
+
* hash exactly what it was before this input existed; each sync writes a new dev
|
|
45
|
+
* version, so each sync is a miss; and a restore brings the old hits back.
|
|
46
|
+
*/
|
|
47
|
+
export declare function fingerprintOf(packages: readonly SyncedPackage[]): string;
|
|
48
|
+
export declare function formatStatus(packages: readonly SyncedPackage[]): string;
|
|
49
|
+
export declare function formatSyncedFindings(packages: readonly SyncedPackage[]): string;
|
|
50
|
+
//# sourceMappingURL=markers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markers.d.ts","sourceRoot":"","sources":["../src/markers.ts"],"names":[],"mappings":"AAeA,oEAAoE;AACpE,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,kDAAkD;IAClD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAaD,gFAAgF;AAChF,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,WACO,CAAC;AAEhD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAsBnE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAqB3D;AAED;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAC9C,OAAO,CAAC,MAAM,CAAC,CAKjB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,GAAG,MAAM,CAMxE;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,GAAG,MAAM,CAUvE;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,SAAS,aAAa,EAAE,GACjC,MAAM,CAUR"}
|
package/dist/markers.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a consumer's `node_modules` holds of entifix: the release its lockfile
|
|
3
|
+
* pins, or copies synced from a local entifix checkout.
|
|
4
|
+
*
|
|
5
|
+
* entifix's `dev-sync` copies a local build over the installed release, file by
|
|
6
|
+
* file, under `node_modules/.pnpm`. Every copy's manifest carries an
|
|
7
|
+
* `entifixDevSync` marker and a `<release>-dev.<timestamp>` version, both written
|
|
8
|
+
* by the sync. Every command of the kit — the commit guard, the status report,
|
|
9
|
+
* the cache fingerprint and the restore — reads those markers through this one
|
|
10
|
+
* module, so they cannot disagree about what "synced" means.
|
|
11
|
+
*/ import { createHash } from 'node:crypto';
|
|
12
|
+
import { existsSync, readdirSync, readFileSync, rmSync } from 'node:fs';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
const readManifest = (path)=>JSON.parse(readFileSync(path, 'utf8'));
|
|
15
|
+
const storeOf = (root)=>join(root, 'node_modules', '.pnpm');
|
|
16
|
+
/** The package an entry such as `@entifix+core@0.1.1_effect@3` was made for. */ export const ownPackage = (entry)=>entry.slice('@entifix+'.length).split('@')[0];
|
|
17
|
+
/**
|
|
18
|
+
* Every synced copy under a checkout's virtual store, sorted and de-duplicated
|
|
19
|
+
* by name.
|
|
20
|
+
*
|
|
21
|
+
* pnpm keeps one directory per resolved peer set, so one package can have
|
|
22
|
+
* several copies; the report names the package once.
|
|
23
|
+
*/ export function syncedEntifixPackages(root) {
|
|
24
|
+
const store = storeOf(root);
|
|
25
|
+
if (!existsSync(store)) return [];
|
|
26
|
+
const found = new Map();
|
|
27
|
+
for (const entry of readdirSync(store)){
|
|
28
|
+
if (!entry.startsWith('@entifix+')) continue;
|
|
29
|
+
const scope = join(store, entry, 'node_modules', '@entifix');
|
|
30
|
+
if (!existsSync(scope)) continue;
|
|
31
|
+
for (const name of readdirSync(scope)){
|
|
32
|
+
const manifestPath = join(scope, name, 'package.json');
|
|
33
|
+
if (!existsSync(manifestPath)) continue;
|
|
34
|
+
const manifest = readManifest(manifestPath);
|
|
35
|
+
if (manifest.entifixDevSync && !found.has(manifest.name)) {
|
|
36
|
+
found.set(manifest.name, {
|
|
37
|
+
name: manifest.name,
|
|
38
|
+
version: manifest.version,
|
|
39
|
+
source: manifest.entifixDevSync.source
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return [
|
|
45
|
+
...found.values()
|
|
46
|
+
].sort((a, b)=>a.name.localeCompare(b.name));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The virtual-store entries whose own package is a synced copy.
|
|
50
|
+
*
|
|
51
|
+
* An entry such as `@entifix+amqp@0.1.1_…` also links the entifix packages amqp
|
|
52
|
+
* depends on beside it, so only the entry's own package decides — otherwise
|
|
53
|
+
* one synced `core` would mark every entry that depends on it.
|
|
54
|
+
*/ export function syncedEntifixEntries(root) {
|
|
55
|
+
const store = storeOf(root);
|
|
56
|
+
if (!existsSync(store)) return [];
|
|
57
|
+
return readdirSync(store).filter((entry)=>entry.startsWith('@entifix+')).filter((entry)=>{
|
|
58
|
+
const manifest = join(store, entry, 'node_modules', '@entifix', ownPackage(entry), 'package.json');
|
|
59
|
+
return existsSync(manifest) && readManifest(manifest).entifixDevSync !== undefined;
|
|
60
|
+
}).map((entry)=>join(store, entry)).sort();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Deletes every synced entry and re-links the release in their place.
|
|
64
|
+
*
|
|
65
|
+
* ⚠️ Not `pnpm install --force`. With manifests and lockfile unchanged, pnpm 11's
|
|
66
|
+
* optimistic repeat install answers "Already up to date" and leaves every synced
|
|
67
|
+
* copy where it is. Deleting the entries and installing non-optimistically takes
|
|
68
|
+
* about a second and a half; a forced refetch of the whole tree took four
|
|
69
|
+
* minutes.
|
|
70
|
+
*/ export async function restoreRelease(root, install) {
|
|
71
|
+
const entries = syncedEntifixEntries(root);
|
|
72
|
+
for (const entry of entries)rmSync(entry, {
|
|
73
|
+
recursive: true,
|
|
74
|
+
force: true
|
|
75
|
+
});
|
|
76
|
+
if (entries.length > 0) await install(root);
|
|
77
|
+
return entries.length;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A cache-key fragment for the task hasher: empty while the release is
|
|
81
|
+
* installed, a digest of every synced `name@version` otherwise.
|
|
82
|
+
*
|
|
83
|
+
* Nx keys an installed package on the version its lockfile resolves, and a
|
|
84
|
+
* synced copy leaves the lockfile untouched — so without this, a build against a
|
|
85
|
+
* local entifix and a build against the release share one cache entry, and
|
|
86
|
+
* whichever ran first is served to the other. Empty on the release keeps every
|
|
87
|
+
* hash exactly what it was before this input existed; each sync writes a new dev
|
|
88
|
+
* version, so each sync is a miss; and a restore brings the old hits back.
|
|
89
|
+
*/ export function fingerprintOf(packages) {
|
|
90
|
+
if (packages.length === 0) return '';
|
|
91
|
+
return createHash('sha256').update(packages.map((pkg)=>`${pkg.name}@${pkg.version}`).join('\n')).digest('hex').slice(0, 16);
|
|
92
|
+
}
|
|
93
|
+
export function formatStatus(packages) {
|
|
94
|
+
if (packages.length === 0) {
|
|
95
|
+
return 'entifix: the release — every @entifix/* is what the lockfile pins.';
|
|
96
|
+
}
|
|
97
|
+
return [
|
|
98
|
+
`entifix: ${String(packages.length)} package(s) synced from a local checkout:`,
|
|
99
|
+
...packages.map((pkg)=>` ${pkg.name}@${pkg.version} (from ${pkg.source})`)
|
|
100
|
+
].join('\n');
|
|
101
|
+
}
|
|
102
|
+
export function formatSyncedFindings(packages) {
|
|
103
|
+
const sources = [
|
|
104
|
+
...new Set(packages.map((pkg)=>pkg.source))
|
|
105
|
+
].join(', ');
|
|
106
|
+
return [
|
|
107
|
+
`node_modules carries unreleased entifix, synced from ${sources}:`,
|
|
108
|
+
...packages.map((pkg)=>` ${pkg.name}@${pkg.version}`),
|
|
109
|
+
'',
|
|
110
|
+
'CI installs the version the lockfile pins, not this.',
|
|
111
|
+
'Put the release back with `entifix-swap registry`, or commit with',
|
|
112
|
+
'ENTIFIX_DEV_SYNC_OK=1 if this change deliberately waits on an entifix release.'
|
|
113
|
+
].join('\n');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=markers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/markers.ts"],"sourcesContent":["/**\n * What a consumer's `node_modules` holds of entifix: the release its lockfile\n * pins, or copies synced from a local entifix checkout.\n *\n * entifix's `dev-sync` copies a local build over the installed release, file by\n * file, under `node_modules/.pnpm`. Every copy's manifest carries an\n * `entifixDevSync` marker and a `<release>-dev.<timestamp>` version, both written\n * by the sync. Every command of the kit — the commit guard, the status report,\n * the cache fingerprint and the restore — reads those markers through this one\n * module, so they cannot disagree about what \"synced\" means.\n */\nimport { createHash } from 'node:crypto';\nimport { existsSync, readdirSync, readFileSync, rmSync } from 'node:fs';\nimport { join } from 'node:path';\n\n/** One synced copy, named once whatever its peer-set duplicates. */\nexport interface SyncedPackage {\n readonly name: string;\n readonly version: string;\n /** The entifix commit the copy was built from. */\n readonly source: string;\n}\n\ninterface Manifest {\n readonly name: string;\n readonly version: string;\n readonly entifixDevSync?: { readonly source: string };\n}\n\nconst readManifest = (path: string): Manifest =>\n JSON.parse(readFileSync(path, 'utf8')) as Manifest;\n\nconst storeOf = (root: string) => join(root, 'node_modules', '.pnpm');\n\n/** The package an entry such as `@entifix+core@0.1.1_effect@3` was made for. */\nexport const ownPackage = (entry: string) =>\n entry.slice('@entifix+'.length).split('@')[0];\n\n/**\n * Every synced copy under a checkout's virtual store, sorted and de-duplicated\n * by name.\n *\n * pnpm keeps one directory per resolved peer set, so one package can have\n * several copies; the report names the package once.\n */\nexport function syncedEntifixPackages(root: string): SyncedPackage[] {\n const store = storeOf(root);\n if (!existsSync(store)) return [];\n const found = new Map<string, SyncedPackage>();\n for (const entry of readdirSync(store)) {\n if (!entry.startsWith('@entifix+')) continue;\n const scope = join(store, entry, 'node_modules', '@entifix');\n if (!existsSync(scope)) continue;\n for (const name of readdirSync(scope)) {\n const manifestPath = join(scope, name, 'package.json');\n if (!existsSync(manifestPath)) continue;\n const manifest = readManifest(manifestPath);\n if (manifest.entifixDevSync && !found.has(manifest.name)) {\n found.set(manifest.name, {\n name: manifest.name,\n version: manifest.version,\n source: manifest.entifixDevSync.source,\n });\n }\n }\n }\n return [...found.values()].sort((a, b) => a.name.localeCompare(b.name));\n}\n\n/**\n * The virtual-store entries whose own package is a synced copy.\n *\n * An entry such as `@entifix+amqp@0.1.1_…` also links the entifix packages amqp\n * depends on beside it, so only the entry's own package decides — otherwise\n * one synced `core` would mark every entry that depends on it.\n */\nexport function syncedEntifixEntries(root: string): string[] {\n const store = storeOf(root);\n if (!existsSync(store)) return [];\n return readdirSync(store)\n .filter(entry => entry.startsWith('@entifix+'))\n .filter(entry => {\n const manifest = join(\n store,\n entry,\n 'node_modules',\n '@entifix',\n ownPackage(entry),\n 'package.json',\n );\n return (\n existsSync(manifest) &&\n readManifest(manifest).entifixDevSync !== undefined\n );\n })\n .map(entry => join(store, entry))\n .sort();\n}\n\n/**\n * Deletes every synced entry and re-links the release in their place.\n *\n * ⚠️ Not `pnpm install --force`. With manifests and lockfile unchanged, pnpm 11's\n * optimistic repeat install answers \"Already up to date\" and leaves every synced\n * copy where it is. Deleting the entries and installing non-optimistically takes\n * about a second and a half; a forced refetch of the whole tree took four\n * minutes.\n */\nexport async function restoreRelease(\n root: string,\n install: (root: string) => Promise<void> | void,\n): Promise<number> {\n const entries = syncedEntifixEntries(root);\n for (const entry of entries) rmSync(entry, { recursive: true, force: true });\n if (entries.length > 0) await install(root);\n return entries.length;\n}\n\n/**\n * A cache-key fragment for the task hasher: empty while the release is\n * installed, a digest of every synced `name@version` otherwise.\n *\n * Nx keys an installed package on the version its lockfile resolves, and a\n * synced copy leaves the lockfile untouched — so without this, a build against a\n * local entifix and a build against the release share one cache entry, and\n * whichever ran first is served to the other. Empty on the release keeps every\n * hash exactly what it was before this input existed; each sync writes a new dev\n * version, so each sync is a miss; and a restore brings the old hits back.\n */\nexport function fingerprintOf(packages: readonly SyncedPackage[]): string {\n if (packages.length === 0) return '';\n return createHash('sha256')\n .update(packages.map(pkg => `${pkg.name}@${pkg.version}`).join('\\n'))\n .digest('hex')\n .slice(0, 16);\n}\n\nexport function formatStatus(packages: readonly SyncedPackage[]): string {\n if (packages.length === 0) {\n return 'entifix: the release — every @entifix/* is what the lockfile pins.';\n }\n return [\n `entifix: ${String(packages.length)} package(s) synced from a local checkout:`,\n ...packages.map(\n pkg => ` ${pkg.name}@${pkg.version} (from ${pkg.source})`,\n ),\n ].join('\\n');\n}\n\nexport function formatSyncedFindings(\n packages: readonly SyncedPackage[],\n): string {\n const sources = [...new Set(packages.map(pkg => pkg.source))].join(', ');\n return [\n `node_modules carries unreleased entifix, synced from ${sources}:`,\n ...packages.map(pkg => ` ${pkg.name}@${pkg.version}`),\n '',\n 'CI installs the version the lockfile pins, not this.',\n 'Put the release back with `entifix-swap registry`, or commit with',\n 'ENTIFIX_DEV_SYNC_OK=1 if this change deliberately waits on an entifix release.',\n ].join('\\n');\n}\n"],"names":["createHash","existsSync","readdirSync","readFileSync","rmSync","join","readManifest","path","JSON","parse","storeOf","root","ownPackage","entry","slice","length","split","syncedEntifixPackages","store","found","Map","startsWith","scope","name","manifestPath","manifest","entifixDevSync","has","set","version","source","values","sort","a","b","localeCompare","syncedEntifixEntries","filter","undefined","map","restoreRelease","install","entries","recursive","force","fingerprintOf","packages","update","pkg","digest","formatStatus","String","formatSyncedFindings","sources","Set"],"mappings":"AAAA;;;;;;;;;;CAUC,GACD,SAASA,UAAU,QAAQ,cAAc;AACzC,SAASC,UAAU,EAAEC,WAAW,EAAEC,YAAY,EAAEC,MAAM,QAAQ,UAAU;AACxE,SAASC,IAAI,QAAQ,YAAY;AAgBjC,MAAMC,eAAe,CAACC,OACpBC,KAAKC,KAAK,CAACN,aAAaI,MAAM;AAEhC,MAAMG,UAAU,CAACC,OAAiBN,KAAKM,MAAM,gBAAgB;AAE7D,8EAA8E,GAC9E,OAAO,MAAMC,aAAa,CAACC,QACzBA,MAAMC,KAAK,CAAC,YAAYC,MAAM,EAAEC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;AAEhD;;;;;;CAMC,GACD,OAAO,SAASC,sBAAsBN,IAAY;IAChD,MAAMO,QAAQR,QAAQC;IACtB,IAAI,CAACV,WAAWiB,QAAQ,OAAO,EAAE;IACjC,MAAMC,QAAQ,IAAIC;IAClB,KAAK,MAAMP,SAASX,YAAYgB,OAAQ;QACtC,IAAI,CAACL,MAAMQ,UAAU,CAAC,cAAc;QACpC,MAAMC,QAAQjB,KAAKa,OAAOL,OAAO,gBAAgB;QACjD,IAAI,CAACZ,WAAWqB,QAAQ;QACxB,KAAK,MAAMC,QAAQrB,YA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AAcC,QAAkC;IAC9D,IAAIA,SAAS/B,MAAM,KAAK,GAAG,OAAO;IAClC,OAAOf,WAAW,UACf+C,MAAM,CAACD,SAASP,GAAG,CAACS,CAAAA,MAAO,GAAGA,IAAIzB,IAAI,CAAC,CAAC,EAAEyB,IAAInB,OAAO,EAAE,EAAExB,IAAI,CAAC,OAC9D4C,MAAM,CAAC,OACPnC,KAAK,CAAC,GAAG;AACd;AAEA,OAAO,SAASoC,aAAaJ,QAAkC;IAC7D,IAAIA,SAAS/B,MAAM,KAAK,GAAG;QACzB,OAAO;IACT;IACA,OAAO;QACL,CAAC,SAAS,EAAEoC,OAAOL,SAAS/B,MAAM,EAAE,yCAAyC,CAAC;WAC3E+B,SAASP,GAAG,CACbS,CAAAA,MAAO,CAAC,EAAE,EAAEA,IAAIzB,IAAI,CAAC,CAAC,EAAEyB,IAAInB,OAAO,CAAC,QAAQ,EAAEmB,IAAIlB,MAAM,CAAC,CAAC,CAAC;KAE9D,CAACzB,IAAI,CAAC;AACT;AAEA,OAAO,SAAS+C,qBACdN,QAAkC;IAElC,MAAMO,UAAU;WAAI,IAAIC,IAAIR,SAASP,GAAG,CAACS,CAAAA,MAAOA,IAAIlB,MAAM;KAAG,CAACzB,IAAI,CAAC;IACnE,OAAO;QACL,CAAC,qDAAqD,EAAEgD,QAAQ,CAAC,CAAC;WAC/DP,SAASP,GAAG,CAACS,CAAAA,MAAO,CAAC,EAAE,EAAEA,IAAIzB,IAAI,CAAC,CAAC,EAAEyB,IAAInB,OAAO,EAAE;QACrD;QACA;QACA;QACA;KACD,CAACxB,IAAI,CAAC;AACT"}
|
package/dist/reload.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface ReloaderOptions {
|
|
2
|
+
readonly root: string;
|
|
3
|
+
/** How long the synced versions must hold still before a restart, in ms. */
|
|
4
|
+
readonly settleMs: number;
|
|
5
|
+
readonly now: () => number;
|
|
6
|
+
readonly log: (line: string) => void;
|
|
7
|
+
}
|
|
8
|
+
/** One poll: call `tick` on an interval. */
|
|
9
|
+
export declare function makeReloader({ root, settleMs, now, log }: ReloaderOptions): {
|
|
10
|
+
readonly tick: () => void;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=reload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reload.d.ts","sourceRoot":"","sources":["../src/reload.ts"],"names":[],"mappings":"AAwBA,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4EAA4E;IAC5E,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,MAAM,CAAC;IAC3B,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACtC;AAED,4CAA4C;AAC5C,wBAAgB,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,eAAe,GAAG;IAC3E,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC;CAC3B,CA6BA"}
|
package/dist/reload.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Restarts the running services a sync changed, for as long as `local` runs.
|
|
3
|
+
*
|
|
4
|
+
* It polls the synced versions rather than watching files: the sync writes each
|
|
5
|
+
* copy file by file into a store with thousands of entries, and what marks a
|
|
6
|
+
* finished copy is the `<release>-dev.<timestamp>` version it stamps. A change
|
|
7
|
+
* is acted on only once the versions have held still for one settle interval,
|
|
8
|
+
* so a sync still in progress restarts nothing, and one burst of saves restarts
|
|
9
|
+
* each service once.
|
|
10
|
+
*
|
|
11
|
+
* The reloader reads the current versions as its baseline when it is made, so a
|
|
12
|
+
* checkout that is already synced is not restarted on launch.
|
|
13
|
+
*/ import { affectedPackages, changedPackages, entifixDependencies, formatRestart, servicesToRestart, syncedVersions, touch, workspaceManifests } from './consumers.js';
|
|
14
|
+
/** One poll: call `tick` on an interval. */ export function makeReloader({ root, settleMs, now, log }) {
|
|
15
|
+
let applied = syncedVersions(root);
|
|
16
|
+
let pending = applied;
|
|
17
|
+
let pendingSince = 0;
|
|
18
|
+
const tick = ()=>{
|
|
19
|
+
let current;
|
|
20
|
+
try {
|
|
21
|
+
current = syncedVersions(root);
|
|
22
|
+
} catch {
|
|
23
|
+
// A manifest caught mid-write reads as invalid JSON; the next poll sees it whole.
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (changedPackages(pending, current).length > 0) {
|
|
27
|
+
pending = current;
|
|
28
|
+
pendingSince = now();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const changed = changedPackages(applied, pending);
|
|
32
|
+
if (changed.length === 0 || now() - pendingSince < settleMs) return;
|
|
33
|
+
const affected = affectedPackages(changed, entifixDependencies(root));
|
|
34
|
+
const services = servicesToRestart(workspaceManifests(root), affected);
|
|
35
|
+
touch(root, services, new Date(now()));
|
|
36
|
+
applied = pending;
|
|
37
|
+
log(formatRestart(changed, services));
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
tick
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=reload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/reload.ts"],"sourcesContent":["/**\n * Restarts the running services a sync changed, for as long as `local` runs.\n *\n * It polls the synced versions rather than watching files: the sync writes each\n * copy file by file into a store with thousands of entries, and what marks a\n * finished copy is the `<release>-dev.<timestamp>` version it stamps. A change\n * is acted on only once the versions have held still for one settle interval,\n * so a sync still in progress restarts nothing, and one burst of saves restarts\n * each service once.\n *\n * The reloader reads the current versions as its baseline when it is made, so a\n * checkout that is already synced is not restarted on launch.\n */\nimport {\n affectedPackages,\n changedPackages,\n entifixDependencies,\n formatRestart,\n servicesToRestart,\n syncedVersions,\n touch,\n workspaceManifests,\n} from './consumers.js';\n\nexport interface ReloaderOptions {\n readonly root: string;\n /** How long the synced versions must hold still before a restart, in ms. */\n readonly settleMs: number;\n readonly now: () => number;\n readonly log: (line: string) => void;\n}\n\n/** One poll: call `tick` on an interval. */\nexport function makeReloader({ root, settleMs, now, log }: ReloaderOptions): {\n readonly tick: () => void;\n} {\n let applied = syncedVersions(root);\n let pending = applied;\n let pendingSince = 0;\n\n const tick = () => {\n let current: Map<string, string>;\n try {\n current = syncedVersions(root);\n } catch {\n // A manifest caught mid-write reads as invalid JSON; the next poll sees it whole.\n return;\n }\n if (changedPackages(pending, current).length > 0) {\n pending = current;\n pendingSince = now();\n return;\n }\n const changed = changedPackages(applied, pending);\n if (changed.length === 0 || now() - pendingSince < settleMs) return;\n\n const affected = affectedPackages(changed, entifixDependencies(root));\n const services = servicesToRestart(workspaceManifests(root), affected);\n touch(root, services, new Date(now()));\n applied = pending;\n log(formatRestart(changed, services));\n };\n\n return { tick };\n}\n"],"names":["affectedPackages","changedPackages","entifixDependencies","formatRestart","servicesToRestart","syncedVersions","touch","workspaceManifests","makeReloader","root","settleMs","now","log","applied","pending","pendingSince","tick","current","length","changed","affected","services","Date"],"mappings":"AAAA;;;;;;;;;;;;CAYC,GACD,SACEA,gBAAgB,EAChBC,eAAe,EACfC,mBAAmB,EACnBC,aAAa,EACbC,iBAAiB,EACjBC,cAAc,EACdC,KAAK,EACLC,kBAAkB,QACb,iBAAiB;AAUxB,0CAA0C,GAC1C,OAAO,SAASC,aAAa,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,GAAG,EAAmB;IAGxE,IAAIC,UAAUR,eAAeI;IAC7B,IAAIK,UAAUD;IACd,IAAIE,eAAe;IAEnB,MAAMC,OAAO;QACX,IAAIC;QACJ,IAAI;YACFA,UAAUZ,eAAeI;QAC3B,EAAE,OAAM;YACN,kFAAkF;YAClF;QACF;QACA,IAAIR,gBAAgBa,SAASG,SAASC,MAAM,GAAG,GAAG;YAChDJ,UAAUG;YACVF,eAAeJ;YACf;QACF;QACA,MAAMQ,UAAUlB,gBAAgBY,SAASC;QACzC,IAAIK,QAAQD,MAAM,KAAK,KAAKP,QAAQI,eAAeL,UAAU;QAE7D,MAAMU,WAAWpB,iBAAiBmB,SAASjB,oBAAoBO;QAC/D,MAAMY,WAAWjB,kBAAkBG,mBAAmBE,OAAOW;QAC7Dd,MAAMG,MAAMY,UAAU,IAAIC,KAAKX;QAC/BE,UAAUC;QACVF,IAAIT,cAAcgB,SAASE;IAC7B;IAEA,OAAO;QAAEL;IAAK;AAChB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entifix/swap",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.23.23",
|
|
4
|
+
"description": "Run a consumer of @entifix/* against a local entifix checkout before it is released, refuse a commit made on top of one, keep it out of the Nx cache, and put the release back.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -10,5 +10,47 @@
|
|
|
10
10
|
},
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"module": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"bin": {
|
|
19
|
+
"entifix-swap": "./dist/bin.js"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
"./package.json": "./package.json",
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"!**/*.tsbuildinfo",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"nx": {
|
|
36
|
+
"tags": [
|
|
37
|
+
"tier:0"
|
|
38
|
+
],
|
|
39
|
+
"sourceRoot": "packages/ts/swap/src",
|
|
40
|
+
"targets": {
|
|
41
|
+
"build": {
|
|
42
|
+
"executor": "@nx/js:swc",
|
|
43
|
+
"outputs": [
|
|
44
|
+
"{options.outputPath}"
|
|
45
|
+
],
|
|
46
|
+
"options": {
|
|
47
|
+
"outputPath": "packages/ts/swap/dist",
|
|
48
|
+
"main": "packages/ts/swap/src/index.ts",
|
|
49
|
+
"tsConfig": "packages/ts/swap/tsconfig.lib.json",
|
|
50
|
+
"skipTypeCheck": true,
|
|
51
|
+
"stripLeadingPaths": true
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
13
55
|
}
|
|
14
|
-
}
|
|
56
|
+
}
|