@camstack/server 1.2.183 → 1.2.185
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.
|
@@ -3243,13 +3243,23 @@ class AddonRegistryService {
|
|
|
3243
3243
|
// and the real-path match Node's cache keys demand.
|
|
3244
3244
|
//
|
|
3245
3245
|
// The purge mutates the PROCESS-GLOBAL require cache, so purge-then-import
|
|
3246
|
-
// must stay atomic per
|
|
3246
|
+
// must stay atomic per BUNDLE now that the boot plan overlaps (D171):
|
|
3247
3247
|
// `@camstack/addon-remote-storage` ships three addon ids whose entries all
|
|
3248
3248
|
// resolve into one `dist/`, and a sibling's purge landing mid-import would
|
|
3249
|
-
// evict a module graph while it is being evaluated. Different
|
|
3249
|
+
// evict a module graph while it is being evaluated. Different bundles
|
|
3250
3250
|
// still load concurrently.
|
|
3251
|
-
|
|
3252
|
-
|
|
3251
|
+
//
|
|
3252
|
+
// The scope is the BUNDLE (`<addonDir>/dist`), never `dirname(entryPath)`
|
|
3253
|
+
// — see `bundleGraphRootFor`. The narrow scope evicted the entry chunk and
|
|
3254
|
+
// kept the shared chunks, so the re-import re-ran the entry's module-scope
|
|
3255
|
+
// declarations against singletons that had survived, and took the broker
|
|
3256
|
+
// down on 2026-08-29 (D284). The serializer key MUST match the purge
|
|
3257
|
+
// scope: two addon ids of one package now purge the same graph, so
|
|
3258
|
+
// serializing them per entry-folder would let one evict the other's
|
|
3259
|
+
// modules mid-evaluation — the exact race the key exists to prevent.
|
|
3260
|
+
const graphRoot = (0, require_cache_js_1.bundleGraphRootFor)(addonDir, entryPath);
|
|
3261
|
+
const modUnknown = await this.moduleLoadSerializer.run(graphRoot, async () => {
|
|
3262
|
+
(0, require_cache_js_1.purgeRequireCacheUnder)(graphRoot);
|
|
3253
3263
|
// Kept for a genuinely ESM addon entry, where it IS the mechanism.
|
|
3254
3264
|
const cacheBustedUrl = `${(0, node_url_1.pathToFileURL)(entryPath).href}?t=${Date.now()}`;
|
|
3255
3265
|
// A plain `await import()` here is downleveled by tsc (the backend builds
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.purgeRequireCacheUnder = purgeRequireCacheUnder;
|
|
7
|
+
exports.bundleGraphRootFor = bundleGraphRootFor;
|
|
7
8
|
/**
|
|
8
9
|
* require-cache — evicting an addon's own modules so a hot-updated bundle
|
|
9
10
|
* is actually re-read.
|
|
@@ -36,6 +37,10 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
36
37
|
* hub's own modules and every other addon's, turning a catalog refresh into a
|
|
37
38
|
* process-wide reload. Best-effort — a cache that cannot be walked leaves the
|
|
38
39
|
* previous (stale) behaviour rather than failing the caller.
|
|
40
|
+
*
|
|
41
|
+
* **The directory must be the whole BUNDLE, never the entry's own folder** —
|
|
42
|
+
* see {@link bundleGraphRootFor}. A narrower scope purges half a module graph,
|
|
43
|
+
* which is worse than purging none of it.
|
|
39
44
|
*/
|
|
40
45
|
function purgeRequireCacheUnder(dir) {
|
|
41
46
|
try {
|
|
@@ -52,6 +57,39 @@ function purgeRequireCacheUnder(dir) {
|
|
|
52
57
|
// Non-CJS host, or a frozen cache. The caller's import still runs.
|
|
53
58
|
}
|
|
54
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* The directory that holds one addon bundle's WHOLE module graph.
|
|
62
|
+
*
|
|
63
|
+
* A multi-entry bundle does not live under its entry's folder. Every addon in
|
|
64
|
+
* this repo builds through `tools/build/vite-lib.preset.ts`, whose entries are
|
|
65
|
+
* `dist/<addon>/index.js` — and whose SHARED CHUNKS (`dist/dist-<hash>.js`,
|
|
66
|
+
* `dist/node-<hash>.js`, …) sit one level up, in `dist/`. Purging
|
|
67
|
+
* `dirname(entryPath)` therefore evicts the entry and leaves the chunks, so the
|
|
68
|
+
* re-import RE-EXECUTES the entry against module state that was never reset.
|
|
69
|
+
*
|
|
70
|
+
* That is not a stale-cache bug, it is a corrupted one, and it took the hub's
|
|
71
|
+
* `stream-broker` down on 2026-08-29: the entry chunk carries
|
|
72
|
+
* `log-channels.ts`'s module-scope `declareLogChannel` calls while the
|
|
73
|
+
* `LogChannelRegistry` singleton they write to is inlined into the shared
|
|
74
|
+
* chunk. Half the graph re-ran, the registry did not, and the second
|
|
75
|
+
* declaration threw `log channel "stream-broker.webrtc" is already declared in
|
|
76
|
+
* this process` — a message that is correct, and that named the loader rather
|
|
77
|
+
* than the addon. `dist/` is the unit the bundler emits, so `dist/` is the unit
|
|
78
|
+
* the cache is purged in.
|
|
79
|
+
*
|
|
80
|
+
* `node_modules/` under the addon is deliberately OUTSIDE this root: a package
|
|
81
|
+
* that declares `camstack.nativeDependencies` installs `.node` bindings there,
|
|
82
|
+
* and re-`dlopen`ing a native addon is not a refresh, it is a coin flip.
|
|
83
|
+
*
|
|
84
|
+
* Falls back to the entry's directory when there is no `dist/` above it (a
|
|
85
|
+
* loose `loadFromPath` module in a test or a dev tree) — the historical
|
|
86
|
+
* behaviour, for the shape that has no bundle.
|
|
87
|
+
*/
|
|
88
|
+
function bundleGraphRootFor(addonDir, entryPath) {
|
|
89
|
+
const distDir = node_path_1.default.resolve(addonDir, 'dist');
|
|
90
|
+
const withSep = distDir.endsWith(node_path_1.default.sep) ? distDir : `${distDir}${node_path_1.default.sep}`;
|
|
91
|
+
return entryPath.startsWith(withSep) ? distDir : node_path_1.default.dirname(entryPath);
|
|
92
|
+
}
|
|
55
93
|
/** The directory as given and as Node sees it, both as trailing-separator prefixes. */
|
|
56
94
|
function candidatePrefixes(dir) {
|
|
57
95
|
const withSep = (d) => (d.endsWith(node_path_1.default.sep) ? d : `${d}${node_path_1.default.sep}`);
|