@decohere/flux 0.0.1-dev.20261105.99 → 0.0.1-dev.20261106.132

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decohere/flux",
3
- "version": "0.0.1-dev.20261105.99",
3
+ "version": "0.0.1-dev.20261106.132",
4
4
  "description": "Hot module reload server for Node.js ESM applications",
5
5
  "keywords": [
6
6
  "typescript",
@@ -26,20 +26,19 @@
26
26
  "exports": {
27
27
  ".": {
28
28
  "types": "./types/src/index.d.ts",
29
- "import": "./es6/src/index.js",
30
- "require": "./commonjs/src/index.js"
29
+ "import": "./es6/src/index.js"
31
30
  }
32
31
  },
33
32
  "scripts": {
34
33
  "test": "echo \"Error: no test specified\" && exit 1"
35
34
  },
36
35
  "dependencies": {
37
- "@decohere/core": "0.0.1-dev.20261105.99",
38
- "@decohere/crucible": "0.0.1-dev.20261105.99",
39
- "@decohere/devkit": "0.0.1-dev.20261105.99",
40
- "@decohere/forge": "0.0.1-dev.20261105.99",
41
- "@decohere/scribe": "0.0.1-dev.20261105.99",
42
- "@decohere/workspace": "0.0.1-dev.20261105.99",
36
+ "@decohere/core": "0.0.1-dev.20261106.132",
37
+ "@decohere/crucible": "0.0.1-dev.20261106.132",
38
+ "@decohere/devkit": "0.0.1-dev.20261106.132",
39
+ "@decohere/forge": "0.0.1-dev.20261106.132",
40
+ "@decohere/scribe": "0.0.1-dev.20261106.132",
41
+ "@decohere/workspace": "0.0.1-dev.20261106.132",
43
42
  "commander": "^13.1.0"
44
43
  },
45
44
  "devDependencies": {}
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "DeferredScriptRunner", {
6
- enumerable: true,
7
- get: function() {
8
- return DeferredScriptRunner;
9
- }
10
- });
11
- const _nodechild_process = require("node:child_process");
12
- const _decorators = require("@decohere/crucible/decorators");
13
- const _interop = require("@decohere/devkit/interop");
14
- const _scribe = require("@decohere/scribe");
15
- function _ts_decorate(decorators, target, key, desc) {
16
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
17
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
18
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
19
- return c > 3 && r && Object.defineProperty(target, key, r), r;
20
- }
21
- class DeferredScriptRunner {
22
- logger = _scribe.scribe.logger(DeferredScriptRunner.name);
23
- children = [];
24
- start(options) {
25
- const pm = (0, _interop.detectPackageManager)(options.workspaceRoot) ?? (0, _interop.packageManagerFromString)("pnpm");
26
- this.logger.info(`deferred ${options.label} — running ${pm.name} run ${options.script} in ${options.cwd}`);
27
- const child = (0, _nodechild_process.spawn)(pm.name, [
28
- "run",
29
- options.script
30
- ], {
31
- cwd: options.cwd,
32
- stdio: "inherit",
33
- env: process.env,
34
- shell: false
35
- });
36
- child.on("exit", (code, signal)=>{
37
- if (signal) return;
38
- if (code != null && code !== 0) {
39
- this.logger.warn(`deferred ${options.label} exited with ${code}`);
40
- }
41
- });
42
- this.children.push(child);
43
- return child;
44
- }
45
- async [Symbol.asyncDispose]() {
46
- for (const child of this.children){
47
- if (!child.killed) {
48
- child.kill("SIGTERM");
49
- }
50
- }
51
- this.children.length = 0;
52
- }
53
- }
54
- DeferredScriptRunner = _ts_decorate([
55
- (0, _decorators.injectable)()
56
- ], DeferredScriptRunner);
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "FluxCommand", {
6
- enumerable: true,
7
- get: function() {
8
- return FluxCommand;
9
- }
10
- });
11
- const _cli = require("@decohere/devkit/cli");
12
- const _runcommand = require("./run.command.js");
13
- const _servecommand = require("./serve.command.js");
14
- class FluxCommand extends _cli.DecohereCommand {
15
- constructor(commands, handler){
16
- super(FluxCommand);
17
- this.exitOverride();
18
- this.registerSubcommand({
19
- serve: _servecommand.ServeCommand,
20
- run: _runcommand.RunCommand,
21
- ...commands
22
- }, handler);
23
- }
24
- run(_actions, _options) {
25
- return this.help();
26
- }
27
- }
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "flux", {
6
- enumerable: true,
7
- get: function() {
8
- return flux;
9
- }
10
- });
11
- const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
12
- const _hotreloadserver = require("./hot-reload-server.js");
13
- const _sourcemoduleloader = require("./source-module-loader.js");
14
- function _interop_require_default(obj) {
15
- return obj && obj.__esModule ? obj : {
16
- default: obj
17
- };
18
- }
19
- /** Process-level one-shot loader so a second `run()` reconfigures instead of stacking hooks. */ const runLoader = new _sourcemoduleloader.SourceModuleLoader();
20
- async function run(entry, options = {}) {
21
- const trimmed = entry.trim();
22
- if (trimmed == null || trimmed === "") {
23
- throw new Error("flux.run requires an entry file path");
24
- }
25
- const absoluteEntry = _nodepath.default.resolve(trimmed);
26
- await runLoader.configure({
27
- workspace: options.workspace,
28
- buildConfig: options.configuration ?? "debug"
29
- });
30
- runLoader.registerHooks();
31
- process.argv = [
32
- process.execPath,
33
- absoluteEntry,
34
- ...options.args ?? []
35
- ];
36
- return runLoader.importEntry(absoluteEntry);
37
- }
38
- async function serve(options = {}) {
39
- const server = new _hotreloadserver.HotReloadServer();
40
- await server.start({
41
- buildConfig: options.configuration ?? "debug",
42
- project: options.project,
43
- projects: options.projects,
44
- workspace: options.workspace,
45
- rebootDebounceMs: options.rebootDebounceMs
46
- });
47
- return server;
48
- }
49
- function dispose() {
50
- runLoader.dispose();
51
- }
52
- const flux = {
53
- run,
54
- serve,
55
- dispose
56
- };
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "FluxModule", {
6
- enumerable: true,
7
- get: function() {
8
- return FluxModule;
9
- }
10
- });
11
- const _transpile = require("@decohere/forge/transpile");
12
- const _cli = require("@decohere/devkit/cli");
13
- const _deferredscriptrunner = require("./deferred-script-runner.js");
14
- const _fluxcommand = require("./flux.command.js");
15
- const _hotreloadserver = require("./hot-reload-server.js");
16
- const _runaction = require("./run.action.js");
17
- const _serveaction = require("./serve.action.js");
18
- class FluxModule extends _cli.ModuleManifest {
19
- id = "flux";
20
- command = _fluxcommand.FluxCommand;
21
- actions = {
22
- serve: _serveaction.ServeAction,
23
- run: _runaction.RunAction
24
- };
25
- registerServices(builder) {
26
- builder.registerSingleton(_hotreloadserver.HotReloadServer);
27
- builder.registerSingleton(_deferredscriptrunner.DeferredScriptRunner);
28
- }
29
- createWorkspace(options) {
30
- // Same workspace as `flux.run` / `flux.serve` and forge.
31
- return (0, _transpile.createWorkspace)(options);
32
- }
33
- }
@@ -1,467 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: Object.getOwnPropertyDescriptor(all, name).get
9
- });
10
- }
11
- _export(exports, {
12
- get DEFAULT_REBOOT_DEBOUNCE_MS () {
13
- return DEFAULT_REBOOT_DEBOUNCE_MS;
14
- },
15
- get HotReloadServer () {
16
- return HotReloadServer;
17
- },
18
- get formatFluxRebootReady () {
19
- return formatFluxRebootReady;
20
- },
21
- get formatFluxRebootStart () {
22
- return formatFluxRebootStart;
23
- },
24
- get resolveRebootDebounceMs () {
25
- return resolveRebootDebounceMs;
26
- }
27
- });
28
- const _nodeevents = require("node:events");
29
- const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
30
- const _io = require("@decohere/core/io");
31
- const _io1 = require("@decohere/devkit/io");
32
- const _system = require("@decohere/core/system");
33
- const _scribe = require("@decohere/scribe");
34
- const _sourcemoduleloader = require("./source-module-loader.js");
35
- function _interop_require_default(obj) {
36
- return obj && obj.__esModule ? obj : {
37
- default: obj
38
- };
39
- }
40
- const currentFilePath = _io.io.fileUrlToPath(require("url").pathToFileURL(__filename).toString());
41
- const VERSION_URL_PARAM = "version";
42
- const DEFAULT_REBOOT_DEBOUNCE_MS = 250;
43
- /** How many triggering paths to print on the info banner before `+N`. */ const MAX_REBOOT_TRIGGER_PATHS = 4;
44
- function resolveRebootDebounceMs(value) {
45
- const delay = value ?? DEFAULT_REBOOT_DEBOUNCE_MS;
46
- if (!Number.isFinite(delay) || delay < 0) {
47
- throw new Error(`rebootDebounceMs must be a non-negative number, got ${String(value)}`);
48
- }
49
- return delay;
50
- }
51
- function formatTriggerList(triggers) {
52
- if (triggers.length === 0) return undefined;
53
- if (triggers.length <= MAX_REBOOT_TRIGGER_PATHS) return triggers.join(", ");
54
- return `${triggers.slice(0, MAX_REBOOT_TRIGGER_PATHS).join(", ")}, +${triggers.length - MAX_REBOOT_TRIGGER_PATHS}`;
55
- }
56
- const BANNER_RULE = "═".repeat(56);
57
- function wrapFluxBanner(title, details) {
58
- const body = details.map((line)=>` ${line}`).join("\n");
59
- return `\n${BANNER_RULE}\n ${title}\n${body}\n${BANNER_RULE}\n`;
60
- }
61
- function formatFluxRebootStart(labels, triggers = []) {
62
- const who = labels.join(", ") || "entry";
63
- const files = formatTriggerList(triggers);
64
- const details = files == null ? [
65
- who
66
- ] : [
67
- who,
68
- files
69
- ];
70
- return wrapFluxBanner("FLUX REBOOT", details);
71
- }
72
- function formatFluxRebootReady(labels, elapsedMs) {
73
- const who = labels.join(", ") || "entry";
74
- return wrapFluxBanner("FLUX READY", [
75
- who,
76
- `${Math.max(0, Math.round(elapsedMs))}ms`
77
- ]);
78
- }
79
- /** Process-wide: Node's ESM cache is process-global, including across HotReloadServer instances. */ let moduleVersionSeq = 0;
80
- class HotReloadServer extends _nodeevents.EventEmitter {
81
- // ── State ────────────────────────────────────────────────────────────────
82
- logger = _scribe.scribe.logger(HotReloadServer.name);
83
- loader = new _sourcemoduleloader.SourceModuleLoader();
84
- disposed = false;
85
- /** Absolute entry paths currently served (one or more Flux apps). */ entries = new Map();
86
- pendingEntryReboots = new Set();
87
- /** Source paths that scheduled the next reboot (cleared when that reboot starts). */ pendingTriggers = new Set();
88
- watchSubscription;
89
- moduleCache = new Map();
90
- dependencies = new Map();
91
- rebootTail = Promise.resolve();
92
- rebootDebounceGen = 0;
93
- rebootInFlight = false;
94
- rebootFollowUp = false;
95
- rebootQueued = false;
96
- /** Modules whose reverse-graph edges are pruned at reboot, not on schedule. */ pendingGraphPrune = new Set();
97
- scheduleReboot = ()=>{};
98
- // ── Public API ───────────────────────────────────────────────────────────
99
- async start(options) {
100
- this.disposed = false;
101
- this.dependencies.clear();
102
- this.moduleCache.clear();
103
- this.entries.clear();
104
- this.pendingEntryReboots.clear();
105
- this.pendingTriggers.clear();
106
- this.pendingGraphPrune.clear();
107
- this.rebootTail = Promise.resolve();
108
- this.rebootInFlight = false;
109
- this.rebootFollowUp = false;
110
- this.rebootQueued = false;
111
- this.bindScheduleReboot(resolveRebootDebounceMs(options.rebootDebounceMs));
112
- const { buildConfig } = options;
113
- await this.loader.configure({
114
- buildConfig,
115
- workspace: options.workspace,
116
- versionFileUrl: (fileUrl)=>this.getCachedOrNew(fileUrl),
117
- onResolved: this.onPostResolve
118
- });
119
- const workspace = this.requireWorkspace();
120
- const selected = this.resolveProjects(buildConfig, options);
121
- for (const project of selected){
122
- const entryPath = _nodepath.default.resolve(project.getSourceEntryPath());
123
- this.entries.set(entryPath, {
124
- path: entryPath,
125
- label: project.name
126
- });
127
- }
128
- this.loader.registerHooks();
129
- this.invalidateAllSourceFiles();
130
- await workspace.watch(buildConfig);
131
- this.watchSubscription = workspace.projectFileChanged$.subscribe(this.onFileChange);
132
- for (const entry of this.entries.values()){
133
- this.logger.trace(`Serving ${entry.path}`);
134
- }
135
- await this.bootEntries([
136
- ...this.entries.keys()
137
- ]);
138
- this.emit("start");
139
- }
140
- async dispose() {
141
- if (this.disposed) return;
142
- this.disposed = true;
143
- this.rebootDebounceGen += 1;
144
- this.watchSubscription?.unsubscribe();
145
- await this.rebootTail;
146
- await this.disposeEntries([
147
- ...this.entries.keys()
148
- ]);
149
- this.loader.dispose();
150
- }
151
- async [Symbol.asyncDispose]() {
152
- await this.dispose();
153
- }
154
- // ── Lifecycle ────────────────────────────────────────────────────────────
155
- async bootEntries(entryPaths) {
156
- await Promise.all(entryPaths.map((entryPath)=>this.bootEntry(entryPath)));
157
- }
158
- async bootEntry(entryPath) {
159
- const state = this.entries.get(entryPath);
160
- if (state == null) return;
161
- try {
162
- const mod = await this.loader.importEntry(entryPath);
163
- state.module = mod?.default;
164
- state.failed = false;
165
- } catch (error) {
166
- state.module = undefined;
167
- state.failed = true;
168
- this.logger.error("There was an error booting the entry point. Your application may not function as expected", error);
169
- }
170
- }
171
- bindScheduleReboot(delayMs) {
172
- const gen = ++this.rebootDebounceGen;
173
- this.scheduleReboot = (0, _system.debounce)(async ()=>{
174
- if (this.disposed || gen !== this.rebootDebounceGen) return;
175
- this.requestReboot();
176
- }, delayMs);
177
- }
178
- requestReboot() {
179
- if (this.disposed) return;
180
- if (this.rebootInFlight) {
181
- this.rebootFollowUp = true;
182
- return;
183
- }
184
- if (this.rebootQueued) return;
185
- this.rebootQueued = true;
186
- this.rebootTail = this.rebootTail.then(()=>this.runReboot(), ()=>this.runReboot());
187
- }
188
- async runReboot() {
189
- this.rebootQueued = false;
190
- if (this.disposed) return;
191
- this.rebootInFlight = true;
192
- try {
193
- do {
194
- this.rebootFollowUp = false;
195
- if (this.disposed) return;
196
- const toReboot = this.pendingEntryReboots.size > 0 ? [
197
- ...this.pendingEntryReboots
198
- ] : [
199
- ...this.entries.keys()
200
- ];
201
- this.pendingEntryReboots.clear();
202
- // Drop reverse edges only when rebooting so later saves in the debounce
203
- // window can still walk the graph and reset the quiet timer.
204
- this.prunePendingDependencyEdges();
205
- const startedAt = Date.now();
206
- const labels = this.labelsFor(toReboot);
207
- const triggers = this.takeTriggers();
208
- this.logger.info(formatFluxRebootStart(labels, triggers));
209
- await this.disposeEntries(toReboot);
210
- await this.bootEntries(toReboot);
211
- this.logger.info(formatFluxRebootReady(labels, Date.now() - startedAt));
212
- this.emit("reboot");
213
- }while (this.rebootFollowUp && !this.disposed)
214
- } finally{
215
- const needsFollowUp = this.rebootFollowUp && !this.disposed;
216
- this.rebootFollowUp = false;
217
- this.rebootInFlight = false;
218
- if (needsFollowUp) this.requestReboot();
219
- }
220
- }
221
- async disposeEntries(entryPaths) {
222
- await Promise.all(entryPaths.map((entryPath)=>this.disposeEntry(entryPath)));
223
- }
224
- async disposeEntry(entryPath) {
225
- const paths = entryPath != null ? [
226
- entryPath
227
- ] : [
228
- ...this.entries.keys()
229
- ];
230
- for (const p of paths){
231
- const state = this.entries.get(p);
232
- if (state == null) continue;
233
- const entry = state.module;
234
- state.module = undefined;
235
- try {
236
- await entry?.[Symbol.asyncDispose]();
237
- } catch (error) {
238
- this.logger.error("Entry asyncDispose failed", error);
239
- }
240
- }
241
- }
242
- // ── Setup ────────────────────────────────────────────────────────────────
243
- requireWorkspace() {
244
- const workspace = this.loader.getWorkspace();
245
- if (workspace == null) {
246
- throw new Error("SourceModuleLoader has no workspace after configure");
247
- }
248
- return workspace;
249
- }
250
- resolveProjects(buildConfig, options) {
251
- const projects = this.loader.getWorkspace()?.getProjects(buildConfig) ?? [];
252
- const names = options.projects != null && options.projects.length > 0 ? options.projects : options.project != null ? [
253
- options.project
254
- ] : undefined;
255
- if (names == null) {
256
- const first = projects.at(0);
257
- if (first == null) {
258
- throw new Error(`No projects found for configuration: ${buildConfig}`);
259
- }
260
- return [
261
- first
262
- ];
263
- }
264
- const selected = [];
265
- for (const name of names){
266
- const found = projects.find((p)=>p.name === name);
267
- if (found == null) {
268
- throw new Error(`Project "${name}" not found in workspace`);
269
- }
270
- selected.push(found);
271
- }
272
- return selected;
273
- }
274
- /**
275
- * Post-next dependency tracker: records which source files import which
276
- * other source files so that reloadIfAffected can traverse the graph.
277
- */ onPostResolve = (result, parentUrl)=>{
278
- const { url } = result;
279
- const parentUrlClean = parentUrl.split("?")[0];
280
- let filePath;
281
- let parentPath;
282
- try {
283
- const urlObj = new URL(url);
284
- urlObj.search = "";
285
- filePath = _io.io.fileUrlToPath(urlObj.toString());
286
- } catch {
287
- return;
288
- }
289
- try {
290
- parentPath = _io.io.fileUrlToPath(parentUrlClean);
291
- } catch {
292
- parentPath = "";
293
- }
294
- const isSource = this.loader.hasSourceFile(filePath);
295
- const parentIsSource = this.loader.hasSourceFile(parentPath);
296
- if (isSource || parentIsSource) {
297
- this.trackDependency(filePath, parentPath);
298
- }
299
- };
300
- // ── File watching ────────────────────────────────────────────────────────
301
- onFileChange = (evt)=>{
302
- const { file, eventName, project } = evt;
303
- const fullPath = file.fullPath;
304
- this.logger.trace(`File ${eventName}: ${fullPath}`);
305
- if (eventName === _io1.WatchEvents.unlink) {
306
- this.loader.invalidateTranspile(fullPath);
307
- this.moduleCache.set(fullPath, null);
308
- return;
309
- }
310
- if (eventName === _io1.WatchEvents.add) {
311
- if (project.isSourceFile(file)) {
312
- this.loader.setSourceFile(fullPath, project);
313
- this.moduleCache.set(fullPath, null);
314
- this.reloadIfAffected(fullPath);
315
- this.retryFailedEntries(fullPath);
316
- }
317
- return;
318
- }
319
- // change
320
- if (!project.isSourceFile(file)) return;
321
- this.loader.invalidateTranspile(fullPath);
322
- this.reloadIfAffected(fullPath);
323
- this.retryFailedEntries(fullPath);
324
- };
325
- /**
326
- * A failed boot (e.g. importing a file that doesn't exist yet) may have recorded no
327
- * dependency edges, so the graph can't tell whether this save fixes it. Any source
328
- * add or change retries failed entries.
329
- */ retryFailedEntries(fullPath) {
330
- const failed = [
331
- ...this.entries.values()
332
- ].filter((entry)=>entry.failed);
333
- if (failed.length === 0) return;
334
- for (const entry of failed){
335
- // New URL version: Node caches the failed load and would replay the same error.
336
- this.invalidateModuleCaches(entry.path);
337
- this.pendingEntryReboots.add(entry.path);
338
- }
339
- this.pendingTriggers.add(fullPath);
340
- this.scheduleReboot();
341
- }
342
- reloadIfAffected(fullPath) {
343
- const deps = this.getDependencyGraph(fullPath);
344
- const modules = [
345
- ...new Set([
346
- ...deps,
347
- fullPath
348
- ])
349
- ];
350
- const affectedEntries = [
351
- ...this.entries.keys()
352
- ].filter((entryPath)=>modules.includes(entryPath));
353
- if (affectedEntries.length === 0) {
354
- this.logger.trace(`Change in ${fullPath} does not affect entry — skipping reload`);
355
- return false;
356
- }
357
- this.logger.trace(`Change in ${fullPath} affects ${modules.length} module(s) — scheduling reload`);
358
- this.invalidateModuleCaches(...modules);
359
- for (const module of modules){
360
- this.pendingGraphPrune.add(module);
361
- }
362
- for (const entryPath of affectedEntries){
363
- this.pendingEntryReboots.add(entryPath);
364
- }
365
- this.pendingTriggers.add(fullPath);
366
- this.scheduleReboot();
367
- return true;
368
- }
369
- // ── Dependency graph ─────────────────────────────────────────────────────
370
- /**
371
- * Every module that imports `moduleId`, directly or transitively. Visits each module
372
- * once: import graphs share modules (diamonds) and may legally contain cycles.
373
- */ getDependencyGraph(moduleId) {
374
- if (this.isSelf(moduleId)) return [];
375
- const found = new Set();
376
- const queue = [
377
- moduleId
378
- ];
379
- for(let next = queue.shift(); next != null; next = queue.shift()){
380
- for (const importer of this.dependencies.get(next) ?? []){
381
- if (found.has(importer)) continue;
382
- found.add(importer);
383
- if (this.loader.hasSourceFile(importer) && !this.isSelf(importer)) queue.push(importer);
384
- }
385
- }
386
- return [
387
- ...found
388
- ];
389
- }
390
- trackDependency(filePath, parentPath) {
391
- if (!parentPath) return;
392
- const deps = this.dependencies.get(filePath) ?? [];
393
- const updatedDeps = new Set([
394
- ...deps,
395
- parentPath
396
- ]);
397
- this.dependencies.set(filePath, [
398
- ...updatedDeps
399
- ]);
400
- }
401
- // ── Module cache ─────────────────────────────────────────────────────────
402
- getCachedOrNew(moduleUrl) {
403
- const filePath = _io.io.fileUrlToPath(moduleUrl);
404
- const cached = this.moduleCache.get(filePath);
405
- const versioned = cached ?? this.versionModule(moduleUrl);
406
- this.moduleCache.set(filePath, versioned);
407
- return versioned;
408
- }
409
- versionModule(moduleUrl) {
410
- const versionedUrl = new URL(moduleUrl);
411
- versionedUrl.searchParams.set(VERSION_URL_PARAM, String(++moduleVersionSeq));
412
- return versionedUrl.toString();
413
- }
414
- invalidateModuleCaches(...modules) {
415
- for (const module of modules){
416
- this.moduleCache.set(module, null);
417
- this.loader.invalidateTranspile(module);
418
- }
419
- }
420
- prunePendingDependencyEdges() {
421
- const modules = [
422
- ...this.pendingGraphPrune
423
- ];
424
- this.pendingGraphPrune.clear();
425
- this.pruneDependencyParents(...modules);
426
- }
427
- /** Remove these modules as parents so boot can rebuild edges without stale importers. */ pruneDependencyParents(...modules) {
428
- for (const module of modules){
429
- for (const [key, parents] of this.dependencies){
430
- const filtered = parents.filter((p)=>p !== module);
431
- if (filtered.length === 0) {
432
- this.dependencies.delete(key);
433
- } else {
434
- this.dependencies.set(key, filtered);
435
- }
436
- }
437
- }
438
- }
439
- invalidateAllSourceFiles() {
440
- for (const filePath of this.loader.sourceFilePaths()){
441
- this.moduleCache.set(filePath, null);
442
- }
443
- }
444
- isSelf(filePath) {
445
- return currentFilePath === _nodepath.default.resolve(filePath);
446
- }
447
- labelsFor(entryPaths) {
448
- return entryPaths.map((entryPath)=>this.entries.get(entryPath)?.label ?? _nodepath.default.basename(entryPath));
449
- }
450
- takeTriggers() {
451
- const triggers = [
452
- ...this.pendingTriggers
453
- ].map((fullPath)=>this.formatTrigger(fullPath));
454
- this.pendingTriggers.clear();
455
- return triggers;
456
- }
457
- formatTrigger(fullPath) {
458
- const root = this.loader.getWorkspace()?.rootDir;
459
- if (root != null) {
460
- const rel = _nodepath.default.relative(_nodepath.default.resolve(root), fullPath);
461
- if (rel !== "" && !rel.startsWith("..") && !_nodepath.default.isAbsolute(rel)) {
462
- return rel.replaceAll("\\", "/");
463
- }
464
- }
465
- return _nodepath.default.basename(fullPath);
466
- }
467
- }