@decohere/flux 0.0.1-dev.20261123.408 → 0.0.1-dev.20261125.414
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/es6/src/deferred-script-runner.js +12 -4
- package/es6/src/hot-reload-server.js +51 -17
- package/es6/src/rewrite-serve-specifier.js +12 -4
- package/es6/src/serve.action.js +3 -1
- package/es6/src/slice-serve.js +7 -3
- package/es6/src/source-module-loader.js +72 -26
- package/es6/src/static-imports.js +3 -1
- package/es6/src/transpile-disk-cache.js +41 -15
- package/package.json +7 -7
|
@@ -18,11 +18,15 @@ import { scribe } from "@decohere/scribe";
|
|
|
18
18
|
process.kill(-child.pid, name);
|
|
19
19
|
} catch (error) {
|
|
20
20
|
// The whole group has already gone, which is what we wanted.
|
|
21
|
-
if (error.code !== "ESRCH")
|
|
21
|
+
if (error.code !== "ESRCH") {
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
/** Resolves true once the package manager has exited, or false if it hasn't within `ms`. */ function waitForExit(child, ms) {
|
|
25
|
-
if (child.exitCode != null || child.signalCode != null)
|
|
27
|
+
if (child.exitCode != null || child.signalCode != null) {
|
|
28
|
+
return Promise.resolve(true);
|
|
29
|
+
}
|
|
26
30
|
return new Promise((resolve)=>{
|
|
27
31
|
const timer = setTimeout(()=>resolve(false), ms);
|
|
28
32
|
child.once("exit", ()=>{
|
|
@@ -48,7 +52,9 @@ export class DeferredScriptRunner {
|
|
|
48
52
|
detached: USE_PROCESS_GROUP
|
|
49
53
|
});
|
|
50
54
|
child.on("exit", (code, signal)=>{
|
|
51
|
-
if (signal)
|
|
55
|
+
if (signal) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
52
58
|
if (code != null && code !== 0) {
|
|
53
59
|
this.logger.warn(`deferred ${options.label} exited with ${code}`);
|
|
54
60
|
}
|
|
@@ -60,7 +66,9 @@ export class DeferredScriptRunner {
|
|
|
60
66
|
const children = this.children.splice(0);
|
|
61
67
|
await Promise.all(children.map(async (child)=>{
|
|
62
68
|
signal(child, "SIGTERM");
|
|
63
|
-
if (!await waitForExit(child, STOP_TIMEOUT_MS))
|
|
69
|
+
if (!await waitForExit(child, STOP_TIMEOUT_MS)) {
|
|
70
|
+
signal(child, "SIGKILL");
|
|
71
|
+
}
|
|
64
72
|
}));
|
|
65
73
|
}
|
|
66
74
|
}
|
|
@@ -17,8 +17,12 @@ export function resolveRebootDebounceMs(value) {
|
|
|
17
17
|
return delay;
|
|
18
18
|
}
|
|
19
19
|
function formatTriggerList(triggers) {
|
|
20
|
-
if (triggers.length === 0)
|
|
21
|
-
|
|
20
|
+
if (triggers.length === 0) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
if (triggers.length <= MAX_REBOOT_TRIGGER_PATHS) {
|
|
24
|
+
return triggers.join(", ");
|
|
25
|
+
}
|
|
22
26
|
return `${triggers.slice(0, MAX_REBOOT_TRIGGER_PATHS).join(", ")}, +${triggers.length - MAX_REBOOT_TRIGGER_PATHS}`;
|
|
23
27
|
}
|
|
24
28
|
const BANNER_RULE = "═".repeat(56);
|
|
@@ -106,7 +110,9 @@ export class HotReloadServer extends EventEmitter {
|
|
|
106
110
|
this.emit("start");
|
|
107
111
|
}
|
|
108
112
|
async dispose() {
|
|
109
|
-
if (this.disposed)
|
|
113
|
+
if (this.disposed) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
110
116
|
this.disposed = true;
|
|
111
117
|
this.rebootDebounceGen += 1;
|
|
112
118
|
this.watchSubscription?.unsubscribe();
|
|
@@ -125,7 +131,9 @@ export class HotReloadServer extends EventEmitter {
|
|
|
125
131
|
}
|
|
126
132
|
async bootEntry(entryPath) {
|
|
127
133
|
const state = this.entries.get(entryPath);
|
|
128
|
-
if (state == null)
|
|
134
|
+
if (state == null) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
129
137
|
try {
|
|
130
138
|
const mod = await this.loader.importEntry(entryPath);
|
|
131
139
|
state.module = mod?.default;
|
|
@@ -139,28 +147,38 @@ export class HotReloadServer extends EventEmitter {
|
|
|
139
147
|
bindScheduleReboot(delayMs) {
|
|
140
148
|
const gen = ++this.rebootDebounceGen;
|
|
141
149
|
this.scheduleReboot = debounce(async ()=>{
|
|
142
|
-
if (this.disposed || gen !== this.rebootDebounceGen)
|
|
150
|
+
if (this.disposed || gen !== this.rebootDebounceGen) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
143
153
|
this.requestReboot();
|
|
144
154
|
}, delayMs);
|
|
145
155
|
}
|
|
146
156
|
requestReboot() {
|
|
147
|
-
if (this.disposed)
|
|
157
|
+
if (this.disposed) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
148
160
|
if (this.rebootInFlight) {
|
|
149
161
|
this.rebootFollowUp = true;
|
|
150
162
|
return;
|
|
151
163
|
}
|
|
152
|
-
if (this.rebootQueued)
|
|
164
|
+
if (this.rebootQueued) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
153
167
|
this.rebootQueued = true;
|
|
154
168
|
this.rebootTail = this.rebootTail.then(()=>this.runReboot(), ()=>this.runReboot());
|
|
155
169
|
}
|
|
156
170
|
async runReboot() {
|
|
157
171
|
this.rebootQueued = false;
|
|
158
|
-
if (this.disposed)
|
|
172
|
+
if (this.disposed) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
159
175
|
this.rebootInFlight = true;
|
|
160
176
|
try {
|
|
161
177
|
do {
|
|
162
178
|
this.rebootFollowUp = false;
|
|
163
|
-
if (this.disposed)
|
|
179
|
+
if (this.disposed) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
164
182
|
const toReboot = this.pendingEntryReboots.size > 0 ? [
|
|
165
183
|
...this.pendingEntryReboots
|
|
166
184
|
] : [
|
|
@@ -183,7 +201,9 @@ export class HotReloadServer extends EventEmitter {
|
|
|
183
201
|
const needsFollowUp = this.rebootFollowUp && !this.disposed;
|
|
184
202
|
this.rebootFollowUp = false;
|
|
185
203
|
this.rebootInFlight = false;
|
|
186
|
-
if (needsFollowUp)
|
|
204
|
+
if (needsFollowUp) {
|
|
205
|
+
this.requestReboot();
|
|
206
|
+
}
|
|
187
207
|
}
|
|
188
208
|
}
|
|
189
209
|
async disposeEntries(entryPaths) {
|
|
@@ -197,7 +217,9 @@ export class HotReloadServer extends EventEmitter {
|
|
|
197
217
|
];
|
|
198
218
|
for (const p of paths){
|
|
199
219
|
const state = this.entries.get(p);
|
|
200
|
-
if (state == null)
|
|
220
|
+
if (state == null) {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
201
223
|
const entry = state.module;
|
|
202
224
|
state.module = undefined;
|
|
203
225
|
try {
|
|
@@ -285,7 +307,9 @@ export class HotReloadServer extends EventEmitter {
|
|
|
285
307
|
return;
|
|
286
308
|
}
|
|
287
309
|
// change
|
|
288
|
-
if (!project.isSourceFile(file))
|
|
310
|
+
if (!project.isSourceFile(file)) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
289
313
|
this.loader.invalidateTranspile(fullPath);
|
|
290
314
|
this.reloadIfAffected(fullPath);
|
|
291
315
|
this.retryFailedEntries(fullPath);
|
|
@@ -298,7 +322,9 @@ export class HotReloadServer extends EventEmitter {
|
|
|
298
322
|
const failed = [
|
|
299
323
|
...this.entries.values()
|
|
300
324
|
].filter((entry)=>entry.failed);
|
|
301
|
-
if (failed.length === 0)
|
|
325
|
+
if (failed.length === 0) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
302
328
|
for (const entry of failed){
|
|
303
329
|
// New URL version: Node caches the failed load and would replay the same error.
|
|
304
330
|
this.invalidateModuleCaches(entry.path);
|
|
@@ -339,16 +365,22 @@ export class HotReloadServer extends EventEmitter {
|
|
|
339
365
|
* Every module that imports `moduleId`, directly or transitively. Visits each module
|
|
340
366
|
* once: import graphs share modules (diamonds) and may legally contain cycles.
|
|
341
367
|
*/ getDependencyGraph(moduleId) {
|
|
342
|
-
if (this.isSelf(moduleId))
|
|
368
|
+
if (this.isSelf(moduleId)) {
|
|
369
|
+
return [];
|
|
370
|
+
}
|
|
343
371
|
const found = new Set();
|
|
344
372
|
const queue = [
|
|
345
373
|
moduleId
|
|
346
374
|
];
|
|
347
375
|
for(let next = queue.shift(); next != null; next = queue.shift()){
|
|
348
376
|
for (const importer of this.dependencies.get(next) ?? []){
|
|
349
|
-
if (found.has(importer))
|
|
377
|
+
if (found.has(importer)) {
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
350
380
|
found.add(importer);
|
|
351
|
-
if (this.loader.hasSourceFile(importer) && !this.isSelf(importer))
|
|
381
|
+
if (this.loader.hasSourceFile(importer) && !this.isSelf(importer)) {
|
|
382
|
+
queue.push(importer);
|
|
383
|
+
}
|
|
352
384
|
}
|
|
353
385
|
}
|
|
354
386
|
return [
|
|
@@ -356,7 +388,9 @@ export class HotReloadServer extends EventEmitter {
|
|
|
356
388
|
];
|
|
357
389
|
}
|
|
358
390
|
trackDependency(filePath, parentPath) {
|
|
359
|
-
if (!parentPath)
|
|
391
|
+
if (!parentPath) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
360
394
|
const deps = this.dependencies.get(filePath) ?? [];
|
|
361
395
|
const updatedDeps = new Set([
|
|
362
396
|
...deps,
|
|
@@ -36,16 +36,24 @@ import { packageAliases, sourceExtensions } from "@decohere/workspace";
|
|
|
36
36
|
return candidates.find((candidate)=>isWatchedTs(candidate)) ?? null;
|
|
37
37
|
}
|
|
38
38
|
function resolveRelativeWatchedTs(specifier, parentUrl, isWatchedTs) {
|
|
39
|
-
if (packageAliases.isBareSpecifier(specifier))
|
|
40
|
-
|
|
39
|
+
if (packageAliases.isBareSpecifier(specifier)) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
if (!(specifier.startsWith(".") || specifier.startsWith("/"))) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
41
45
|
const parentClean = parentUrl.split("?")[0];
|
|
42
|
-
if (parentClean == null || parentClean === "")
|
|
46
|
+
if (parentClean == null || parentClean === "") {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
43
49
|
let resolved;
|
|
44
50
|
try {
|
|
45
51
|
resolved = new URL(specifier, parentClean);
|
|
46
52
|
} catch {
|
|
47
53
|
return null;
|
|
48
54
|
}
|
|
49
|
-
if (resolved.protocol !== "file:")
|
|
55
|
+
if (resolved.protocol !== "file:") {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
50
58
|
return watchedTs(fileURLToPath(resolved), isWatchedTs);
|
|
51
59
|
}
|
package/es6/src/serve.action.js
CHANGED
|
@@ -54,7 +54,9 @@ export class ServeAction {
|
|
|
54
54
|
const workspaceRoot = path.resolve(this.workspace.rootDir ?? process.cwd());
|
|
55
55
|
for (const deferred of classified.defer){
|
|
56
56
|
const script = resolveDeferScript(deferred.scripts);
|
|
57
|
-
if (script == null)
|
|
57
|
+
if (script == null) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
58
60
|
const project = this.findProject(options.configuration, deferred.name);
|
|
59
61
|
this.deferredScripts.start({
|
|
60
62
|
label: deferred.projectDirectory,
|
package/es6/src/slice-serve.js
CHANGED
|
@@ -85,9 +85,13 @@ export function classifySliceProjects(projects, slices) {
|
|
|
85
85
|
const skip = [];
|
|
86
86
|
for (const project of inSlice){
|
|
87
87
|
const kind = classifySliceProject(project);
|
|
88
|
-
if (kind === "flux")
|
|
89
|
-
|
|
90
|
-
else
|
|
88
|
+
if (kind === "flux") {
|
|
89
|
+
flux.push(project);
|
|
90
|
+
} else if (kind === "defer") {
|
|
91
|
+
defer.push(project);
|
|
92
|
+
} else {
|
|
93
|
+
skip.push(project);
|
|
94
|
+
}
|
|
91
95
|
}
|
|
92
96
|
return {
|
|
93
97
|
flux,
|
|
@@ -69,14 +69,18 @@ export class SourceModuleLoader {
|
|
|
69
69
|
this.aliasPaths = aliases.paths;
|
|
70
70
|
}
|
|
71
71
|
registerHooks() {
|
|
72
|
-
if (this.hooksRegistered)
|
|
72
|
+
if (this.hooksRegistered) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
73
75
|
this.hooksRegistered = true;
|
|
74
76
|
// Compiled code carries inline source maps; Node only applies them to stack traces when
|
|
75
77
|
// this is on. Without it, errors point at compiled line numbers.
|
|
76
78
|
process.setSourceMapsEnabled(true);
|
|
77
79
|
registerHooks({
|
|
78
80
|
resolve: (specifier, context, next)=>{
|
|
79
|
-
if (this.disposed)
|
|
81
|
+
if (this.disposed) {
|
|
82
|
+
return next(specifier, context);
|
|
83
|
+
}
|
|
80
84
|
const parentUrl = context.parentURL ?? "";
|
|
81
85
|
const rewritten = rewriteServeSpecifier({
|
|
82
86
|
specifier,
|
|
@@ -90,7 +94,9 @@ export class SourceModuleLoader {
|
|
|
90
94
|
return result;
|
|
91
95
|
},
|
|
92
96
|
load: (url, context, next)=>{
|
|
93
|
-
if (this.disposed)
|
|
97
|
+
if (this.disposed) {
|
|
98
|
+
return next(url, context);
|
|
99
|
+
}
|
|
94
100
|
const result = this.loadTs(url);
|
|
95
101
|
if (result != null) {
|
|
96
102
|
return {
|
|
@@ -130,7 +136,9 @@ export class SourceModuleLoader {
|
|
|
130
136
|
* on enums, decorators and parameter properties. Null for everything else.
|
|
131
137
|
*/ sourceInfo(fullPath) {
|
|
132
138
|
const fileInfo = this.fileInfoMap.get(fullPath);
|
|
133
|
-
if (fileInfo != null)
|
|
139
|
+
if (fileInfo != null) {
|
|
140
|
+
return fileInfo;
|
|
141
|
+
}
|
|
134
142
|
const outsidePackages = sourceExtensions.isSource(fullPath) && !fullPath.split(/[/\\]/).includes("node_modules") && existsSync(fullPath);
|
|
135
143
|
return outsidePackages ? {} : null;
|
|
136
144
|
}
|
|
@@ -166,12 +174,18 @@ export class SourceModuleLoader {
|
|
|
166
174
|
...reached
|
|
167
175
|
].filter((fullPath)=>!this.transpileCache.has(fullPath));
|
|
168
176
|
const seen = new Set(reached);
|
|
169
|
-
for (const start of starts)
|
|
177
|
+
for (const start of starts){
|
|
178
|
+
seen.delete(start);
|
|
179
|
+
}
|
|
170
180
|
const visit = async (fullPath)=>{
|
|
171
|
-
if (seen.has(fullPath))
|
|
181
|
+
if (seen.has(fullPath)) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
172
184
|
seen.add(fullPath);
|
|
173
185
|
const code = await this.compiledAhead(fullPath);
|
|
174
|
-
if (code == null)
|
|
186
|
+
if (code == null) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
175
189
|
const parentUrl = pathToFileURL(fullPath).toString();
|
|
176
190
|
await Promise.all(staticImports.scan(code).map((specifier)=>{
|
|
177
191
|
const target = this.sourcePathOf(specifier, parentUrl);
|
|
@@ -183,18 +197,28 @@ export class SourceModuleLoader {
|
|
|
183
197
|
}
|
|
184
198
|
/** The file's compiled code, from the cache or compiled now; undefined if it isn't a source. */ compiledAhead(fullPath) {
|
|
185
199
|
const fileInfo = this.sourceInfo(fullPath);
|
|
186
|
-
if (fileInfo == null)
|
|
200
|
+
if (fileInfo == null) {
|
|
201
|
+
return Promise.resolve(undefined);
|
|
202
|
+
}
|
|
187
203
|
const cached = this.transpileCache.get(fullPath);
|
|
188
|
-
if (cached != null)
|
|
204
|
+
if (cached != null) {
|
|
205
|
+
return Promise.resolve(cached);
|
|
206
|
+
}
|
|
189
207
|
const inFlight = this.compilingAhead.get(fullPath);
|
|
190
|
-
if (inFlight != null)
|
|
208
|
+
if (inFlight != null) {
|
|
209
|
+
return inFlight;
|
|
210
|
+
}
|
|
191
211
|
const version = this.transpileVersions.get(fullPath);
|
|
192
212
|
const cache = this.transpileCache;
|
|
193
213
|
const compiling = this.compileAsync(fullPath, fileInfo.project).then((code)=>{
|
|
194
|
-
if (code == null)
|
|
214
|
+
if (code == null) {
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
195
217
|
// Saved, reconfigured or disposed while compiling: don't cache stale code.
|
|
196
218
|
const current = !this.disposed && cache === this.transpileCache && version === this.transpileVersions.get(fullPath);
|
|
197
|
-
if (current)
|
|
219
|
+
if (current) {
|
|
220
|
+
cache.set(fullPath, code);
|
|
221
|
+
}
|
|
198
222
|
return code;
|
|
199
223
|
}).finally(()=>this.compilingAhead.delete(fullPath));
|
|
200
224
|
this.compilingAhead.set(fullPath, compiling);
|
|
@@ -211,18 +235,24 @@ export class SourceModuleLoader {
|
|
|
211
235
|
return url == null ? null : fileURLToPath(url);
|
|
212
236
|
}
|
|
213
237
|
loadTs(url) {
|
|
214
|
-
if (!url.startsWith("file:"))
|
|
238
|
+
if (!url.startsWith("file:")) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
215
241
|
// fileURLToPath, not URL.pathname: decodes %20 and gives Windows paths, so files
|
|
216
242
|
// whose path has a space still match the workspace's package list.
|
|
217
243
|
const cleanPath = fileURLToPath(url);
|
|
218
244
|
const fileInfo = this.sourceInfo(cleanPath);
|
|
219
|
-
if (fileInfo == null)
|
|
245
|
+
if (fileInfo == null) {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
220
248
|
const format = sourceExtensions.isCommonJs(cleanPath) ? "commonjs" : "module";
|
|
221
249
|
const cached = this.transpileCache.get(cleanPath);
|
|
222
|
-
if (cached != null)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
250
|
+
if (cached != null) {
|
|
251
|
+
return {
|
|
252
|
+
source: cached,
|
|
253
|
+
format
|
|
254
|
+
};
|
|
255
|
+
}
|
|
226
256
|
const code = this.compileSync(cleanPath, fileInfo.project);
|
|
227
257
|
this.transpileCache.set(cleanPath, code);
|
|
228
258
|
return {
|
|
@@ -249,13 +279,17 @@ export class SourceModuleLoader {
|
|
|
249
279
|
}
|
|
250
280
|
const key = this.diskCache?.keyFor(fullPath, source, baseConfig);
|
|
251
281
|
const hit = key == null ? undefined : this.diskCache?.readSync(key);
|
|
252
|
-
if (hit != null)
|
|
282
|
+
if (hit != null) {
|
|
283
|
+
return hit;
|
|
284
|
+
}
|
|
253
285
|
const response = this.transpiler.transformCodeSync(source, file, BuildTargets.es6, baseConfig);
|
|
254
286
|
if (response.outcome !== "success") {
|
|
255
287
|
this.logger.error(`Failed to transpile ${fullPath}`, response);
|
|
256
288
|
throw new Error(`Failed to transpile ${fullPath}`);
|
|
257
289
|
}
|
|
258
|
-
if (key != null)
|
|
290
|
+
if (key != null) {
|
|
291
|
+
this.diskCache?.writeSync(key, response.code);
|
|
292
|
+
}
|
|
259
293
|
return response.code;
|
|
260
294
|
}
|
|
261
295
|
/**
|
|
@@ -278,10 +312,16 @@ export class SourceModuleLoader {
|
|
|
278
312
|
}
|
|
279
313
|
const key = this.diskCache?.keyFor(fullPath, source, baseConfig);
|
|
280
314
|
const hit = key == null ? undefined : this.diskCache?.readSync(key);
|
|
281
|
-
if (hit != null)
|
|
315
|
+
if (hit != null) {
|
|
316
|
+
return hit;
|
|
317
|
+
}
|
|
282
318
|
const response = await this.transpiler.transformCode(source, file, BuildTargets.es6, baseConfig);
|
|
283
|
-
if (response.outcome !== "success")
|
|
284
|
-
|
|
319
|
+
if (response.outcome !== "success") {
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
if (key != null) {
|
|
323
|
+
await this.diskCache?.write(key, response.code);
|
|
324
|
+
}
|
|
285
325
|
return response.code;
|
|
286
326
|
}
|
|
287
327
|
/**
|
|
@@ -291,11 +331,15 @@ export class SourceModuleLoader {
|
|
|
291
331
|
* directory indexes), so SWC does not resolve them a second time against the disk.
|
|
292
332
|
*/ swcConfigFor(project, fullPath) {
|
|
293
333
|
const config = this.esModuleConfigFor(project);
|
|
294
|
-
if (!sourceExtensions.isCommonJs(fullPath))
|
|
334
|
+
if (!sourceExtensions.isCommonJs(fullPath)) {
|
|
335
|
+
return config;
|
|
336
|
+
}
|
|
295
337
|
// `.cts` is CommonJS: Node loads it with `require` semantics, so SWC emits CommonJS.
|
|
296
338
|
// Kept per project, like the ES module options, so the disk cache hashes them once.
|
|
297
339
|
const cached = this.commonJsConfigs.get(project);
|
|
298
|
-
if (cached != null)
|
|
340
|
+
if (cached != null) {
|
|
341
|
+
return cached;
|
|
342
|
+
}
|
|
299
343
|
const commonJs = {
|
|
300
344
|
...config,
|
|
301
345
|
module: {
|
|
@@ -307,7 +351,9 @@ export class SourceModuleLoader {
|
|
|
307
351
|
}
|
|
308
352
|
/** Forge's defaults when there is no project: decorators and their metadata on. */ esModuleConfigFor(project) {
|
|
309
353
|
const cached = this.swcConfigs.get(project);
|
|
310
|
-
if (cached != null)
|
|
354
|
+
if (cached != null) {
|
|
355
|
+
return cached;
|
|
356
|
+
}
|
|
311
357
|
const base = this.transpiler.createBaseConfig(BuildTargets.es6, {
|
|
312
358
|
tsConfig: project?.getTsConfigSync(),
|
|
313
359
|
userConfig: project?.getSwcConfigSync(),
|
|
@@ -40,13 +40,17 @@ const PRUNE_MARKER = ".last-prune";
|
|
|
40
40
|
optionsHashes = new WeakMap();
|
|
41
41
|
optionsHash(options) {
|
|
42
42
|
const cached = this.optionsHashes.get(options);
|
|
43
|
-
if (cached != null)
|
|
43
|
+
if (cached != null) {
|
|
44
|
+
return cached;
|
|
45
|
+
}
|
|
44
46
|
const hash = createHash("sha256").update(JSON.stringify(options)).digest("hex");
|
|
45
47
|
this.optionsHashes.set(options, hash);
|
|
46
48
|
return hash;
|
|
47
49
|
}
|
|
48
50
|
readSync(key) {
|
|
49
|
-
if (this.disabled)
|
|
51
|
+
if (this.disabled) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
50
54
|
try {
|
|
51
55
|
return fs.readFileSync(this.entryPath(key), "utf8");
|
|
52
56
|
} catch (error) {
|
|
@@ -54,7 +58,9 @@ const PRUNE_MARKER = ".last-prune";
|
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
60
|
async read(key) {
|
|
57
|
-
if (this.disabled)
|
|
61
|
+
if (this.disabled) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
58
64
|
try {
|
|
59
65
|
return await fs.promises.readFile(this.entryPath(key), "utf8");
|
|
60
66
|
} catch (error) {
|
|
@@ -62,7 +68,9 @@ const PRUNE_MARKER = ".last-prune";
|
|
|
62
68
|
}
|
|
63
69
|
}
|
|
64
70
|
writeSync(key, code) {
|
|
65
|
-
if (this.disabled)
|
|
71
|
+
if (this.disabled) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
66
74
|
const file = this.entryPath(key);
|
|
67
75
|
const temp = this.tempPath(file);
|
|
68
76
|
try {
|
|
@@ -76,7 +84,9 @@ const PRUNE_MARKER = ".last-prune";
|
|
|
76
84
|
}
|
|
77
85
|
}
|
|
78
86
|
async write(key, code) {
|
|
79
|
-
if (this.disabled)
|
|
87
|
+
if (this.disabled) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
80
90
|
const file = this.entryPath(key);
|
|
81
91
|
const temp = this.tempPath(file);
|
|
82
92
|
try {
|
|
@@ -90,14 +100,20 @@ const PRUNE_MARKER = ".last-prune";
|
|
|
90
100
|
}
|
|
91
101
|
}
|
|
92
102
|
/** Deletes entries older than 30 days, if it hasn't done so in the last day. */ async pruneIfDue(now = Date.now()) {
|
|
93
|
-
if (this.disabled)
|
|
103
|
+
if (this.disabled) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
94
106
|
const marker = path.join(this.dir, PRUNE_MARKER);
|
|
95
107
|
try {
|
|
96
108
|
const last = await fs.promises.stat(marker).then((stat)=>stat.mtimeMs, (error)=>{
|
|
97
|
-
if (error.code === "ENOENT")
|
|
109
|
+
if (error.code === "ENOENT") {
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
98
112
|
throw error;
|
|
99
113
|
});
|
|
100
|
-
if (now - last < PRUNE_EVERY_MS)
|
|
114
|
+
if (now - last < PRUNE_EVERY_MS) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
101
117
|
await fs.promises.mkdir(this.dir, {
|
|
102
118
|
recursive: true
|
|
103
119
|
});
|
|
@@ -105,19 +121,25 @@ const PRUNE_MARKER = ".last-prune";
|
|
|
105
121
|
for (const shard of (await fs.promises.readdir(this.dir, {
|
|
106
122
|
withFileTypes: true
|
|
107
123
|
}))){
|
|
108
|
-
if (!shard.isDirectory())
|
|
124
|
+
if (!shard.isDirectory()) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
109
127
|
const shardDir = path.join(this.dir, shard.name);
|
|
110
128
|
for (const entry of (await fs.promises.readdir(shardDir))){
|
|
111
129
|
// Old entries, and temp files a crashed process left mid-write.
|
|
112
130
|
const file = path.join(shardDir, entry);
|
|
113
131
|
const mtime = await fs.promises.stat(file).then((stat)=>stat.mtimeMs, (error)=>{
|
|
114
132
|
// Renamed or removed by another process since the listing: nothing to prune.
|
|
115
|
-
if (error.code === "ENOENT")
|
|
133
|
+
if (error.code === "ENOENT") {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
116
136
|
throw error;
|
|
117
137
|
});
|
|
118
|
-
if (mtime != null && now - mtime > MAX_AGE_MS)
|
|
119
|
-
|
|
120
|
-
|
|
138
|
+
if (mtime != null && now - mtime > MAX_AGE_MS) {
|
|
139
|
+
await fs.promises.rm(file, {
|
|
140
|
+
force: true
|
|
141
|
+
});
|
|
142
|
+
}
|
|
121
143
|
}
|
|
122
144
|
}
|
|
123
145
|
} catch (error) {
|
|
@@ -131,11 +153,15 @@ const PRUNE_MARKER = ".last-prune";
|
|
|
131
153
|
return `${file}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
|
|
132
154
|
}
|
|
133
155
|
/** A missing entry is a miss; any other read error turns the cache off. */ missOrDisable(error) {
|
|
134
|
-
if (error.code !== "ENOENT")
|
|
156
|
+
if (error.code !== "ENOENT") {
|
|
157
|
+
this.disable("read", error);
|
|
158
|
+
}
|
|
135
159
|
return undefined;
|
|
136
160
|
}
|
|
137
161
|
disable(operation, error) {
|
|
138
|
-
if (this.disabled)
|
|
162
|
+
if (this.disabled) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
139
165
|
this.disabled = true;
|
|
140
166
|
this.logger.warn(`Transpile cache turned off for this run: could not ${operation} ${this.dir} (${String(error)}). ` + "Flux compiles without it. Set DECOHERE_CACHE_DIR to a writable directory, or DECOHERE_CACHE=0 to silence this.");
|
|
141
167
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decohere/flux",
|
|
3
|
-
"version": "0.0.1-dev.
|
|
3
|
+
"version": "0.0.1-dev.20261125.414",
|
|
4
4
|
"description": "Hot module reload server for Node.js ESM applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@decohere/core": "0.0.1-dev.
|
|
37
|
-
"@decohere/crucible": "0.0.1-dev.
|
|
38
|
-
"@decohere/devkit": "0.0.1-dev.
|
|
39
|
-
"@decohere/forge": "0.0.1-dev.
|
|
40
|
-
"@decohere/scribe": "0.0.1-dev.
|
|
41
|
-
"@decohere/workspace": "0.0.1-dev.
|
|
36
|
+
"@decohere/core": "0.0.1-dev.20261125.414",
|
|
37
|
+
"@decohere/crucible": "0.0.1-dev.20261125.414",
|
|
38
|
+
"@decohere/devkit": "0.0.1-dev.20261125.414",
|
|
39
|
+
"@decohere/forge": "0.0.1-dev.20261125.414",
|
|
40
|
+
"@decohere/scribe": "0.0.1-dev.20261125.414",
|
|
41
|
+
"@decohere/workspace": "0.0.1-dev.20261125.414",
|
|
42
42
|
"commander": "^13.1.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {}
|