@stati/core 1.24.0 → 1.24.1
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/dist/core/build.js
CHANGED
|
@@ -551,6 +551,19 @@ async function buildInternal(options = {}) {
|
|
|
551
551
|
outDir: config.outDir || DEFAULT_OUT_DIR,
|
|
552
552
|
mode: 'development',
|
|
553
553
|
});
|
|
554
|
+
// On initial dev startup, watcher output may not exist yet.
|
|
555
|
+
// Compile once so pages can auto-inject bundle scripts immediately.
|
|
556
|
+
if (compiledBundles.length === 0) {
|
|
557
|
+
const endTsSpan = recorder.startSpan('typescriptCompileMs');
|
|
558
|
+
compiledBundles = await compileTypeScript({
|
|
559
|
+
projectRoot: process.cwd(),
|
|
560
|
+
config: config.typescript,
|
|
561
|
+
outDir: config.outDir || DEFAULT_OUT_DIR,
|
|
562
|
+
mode: 'development',
|
|
563
|
+
logger,
|
|
564
|
+
});
|
|
565
|
+
endTsSpan();
|
|
566
|
+
}
|
|
554
567
|
}
|
|
555
568
|
else if (config.typescript?.enabled) {
|
|
556
569
|
const endTsSpan = recorder.startSpan('typescriptCompileMs');
|
package/dist/core/dev.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/core/dev.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAe,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAsC7D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;CACb;AAscD,wBAAsB,eAAe,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/core/dev.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAe,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAsC7D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;CACb;AAscD,wBAAsB,eAAe,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,SAAS,CAAC,CAihBxF"}
|
package/dist/core/dev.js
CHANGED
|
@@ -607,6 +607,45 @@ export async function createDevServer(options = {}) {
|
|
|
607
607
|
logger.error?.(`Failed to start dev server:\n${message}`);
|
|
608
608
|
throw error;
|
|
609
609
|
}
|
|
610
|
+
// TypeScript watcher setup
|
|
611
|
+
// Start this before the initial build so bundle outputs already exist for auto-injection.
|
|
612
|
+
if (config.typescript?.enabled) {
|
|
613
|
+
try {
|
|
614
|
+
// Start TypeScript watchers for hot reload (one per bundle)
|
|
615
|
+
tsWatchers = await createTypeScriptWatcher({
|
|
616
|
+
projectRoot: process.cwd(),
|
|
617
|
+
config: config.typescript,
|
|
618
|
+
outDir: config.outDir || DEFAULT_OUT_DIR,
|
|
619
|
+
logger,
|
|
620
|
+
awaitInitialBuild: true,
|
|
621
|
+
onRebuild: (_results, compileTimeMs) => {
|
|
622
|
+
logger.info?.(`▸ TypeScript recompiled in ${compileTimeMs}ms`);
|
|
623
|
+
// Broadcast reload to WebSocket clients
|
|
624
|
+
if (wsServer && !disableWsReload) {
|
|
625
|
+
wsServer.clients.forEach((client) => {
|
|
626
|
+
const ws = client;
|
|
627
|
+
if (ws.readyState === 1) {
|
|
628
|
+
// WebSocket.OPEN
|
|
629
|
+
ws.send(JSON.stringify({ type: 'reload' }));
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
},
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
catch (error) {
|
|
637
|
+
const tsError = error instanceof Error ? error : new Error(String(error));
|
|
638
|
+
// Prominent notification for TypeScript setup failure
|
|
639
|
+
console.log();
|
|
640
|
+
logger.error?.(`TypeScript setup failed: ${tsError.message}`);
|
|
641
|
+
logger.warning?.('──────────────────────────────────────────────────────────────');
|
|
642
|
+
logger.warning?.('! TypeScript hot reload is DISABLED for this session.');
|
|
643
|
+
logger.warning?.(" Dev server will continue, but TypeScript changes won't auto-reload.");
|
|
644
|
+
logger.warning?.(' Fix your TypeScript configuration and restart the dev server.');
|
|
645
|
+
logger.warning?.('──────────────────────────────────────────────────────────────');
|
|
646
|
+
console.log();
|
|
647
|
+
}
|
|
648
|
+
}
|
|
610
649
|
// Perform initial build
|
|
611
650
|
await performInitialBuild(configPath, logger, setLastBuildError);
|
|
612
651
|
// Create HTTP server
|
|
@@ -674,43 +713,6 @@ export async function createDevServer(options = {}) {
|
|
|
674
713
|
reject(error);
|
|
675
714
|
});
|
|
676
715
|
});
|
|
677
|
-
// TypeScript watcher setup (initial compilation is handled by performInitialBuild)
|
|
678
|
-
if (config.typescript?.enabled) {
|
|
679
|
-
try {
|
|
680
|
-
// Start TypeScript watchers for hot reload (one per bundle)
|
|
681
|
-
tsWatchers = await createTypeScriptWatcher({
|
|
682
|
-
projectRoot: process.cwd(),
|
|
683
|
-
config: config.typescript,
|
|
684
|
-
outDir: config.outDir || DEFAULT_OUT_DIR,
|
|
685
|
-
logger,
|
|
686
|
-
onRebuild: (_results, compileTimeMs) => {
|
|
687
|
-
logger.info?.(`▸ TypeScript recompiled in ${compileTimeMs}ms`);
|
|
688
|
-
// Broadcast reload to WebSocket clients
|
|
689
|
-
if (wsServer && !disableWsReload) {
|
|
690
|
-
wsServer.clients.forEach((client) => {
|
|
691
|
-
const ws = client;
|
|
692
|
-
if (ws.readyState === 1) {
|
|
693
|
-
// WebSocket.OPEN
|
|
694
|
-
ws.send(JSON.stringify({ type: 'reload' }));
|
|
695
|
-
}
|
|
696
|
-
});
|
|
697
|
-
}
|
|
698
|
-
},
|
|
699
|
-
});
|
|
700
|
-
}
|
|
701
|
-
catch (error) {
|
|
702
|
-
const tsError = error instanceof Error ? error : new Error(String(error));
|
|
703
|
-
// Prominent notification for TypeScript setup failure
|
|
704
|
-
console.log();
|
|
705
|
-
logger.error?.(`TypeScript setup failed: ${tsError.message}`);
|
|
706
|
-
logger.warning?.('──────────────────────────────────────────────────────────────');
|
|
707
|
-
logger.warning?.('! TypeScript hot reload is DISABLED for this session.');
|
|
708
|
-
logger.warning?.(" Dev server will continue, but TypeScript changes won't auto-reload.");
|
|
709
|
-
logger.warning?.(' Fix your TypeScript configuration and restart the dev server.');
|
|
710
|
-
logger.warning?.('──────────────────────────────────────────────────────────────');
|
|
711
|
-
console.log();
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
716
|
// Set up file watching
|
|
715
717
|
const watchPaths = [srcDir, staticDir].filter(Boolean);
|
|
716
718
|
watcher = chokidar.watch(watchPaths, {
|
|
@@ -42,6 +42,11 @@ export interface WatchOptions {
|
|
|
42
42
|
logger: Logger;
|
|
43
43
|
/** Callback invoked when files are recompiled, receives results and compile time in ms */
|
|
44
44
|
onRebuild: (results: CompiledBundleInfo[], compileTimeMs: number) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Whether to wait for the initial watch build to finish for all bundles.
|
|
47
|
+
* Useful during dev-server startup to ensure bundle files exist before page rendering.
|
|
48
|
+
*/
|
|
49
|
+
awaitInitialBuild?: boolean;
|
|
45
50
|
}
|
|
46
51
|
/**
|
|
47
52
|
* Detects existing TypeScript bundles in the output directory.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typescript.utils.d.ts","sourceRoot":"","sources":["../../../src/core/utils/typescript.utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAInC,OAAO,EAA6B,KAAK,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChG,OAAO,KAAK,EAAE,gBAAgB,EAAgB,MAAM,uBAAuB,CAAC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAQrD;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQjD;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,oCAAoC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,+BAA+B;IAC/B,MAAM,EAAE,gBAAgB,CAAC;IACzB,4CAA4C;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uBAAuB;IACvB,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC;IACnC,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,oCAAoC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,+BAA+B;IAC/B,MAAM,EAAE,gBAAgB,CAAC;IACzB,4CAA4C;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,0FAA0F;IAC1F,SAAS,EAAE,CAAC,OAAO,EAAE,kBAAkB,EAAE,EAAE,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"typescript.utils.d.ts","sourceRoot":"","sources":["../../../src/core/utils/typescript.utils.ts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E,cAAc,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAkD9F;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CAyHjC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAgB5E;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAM/E;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAqC7D;AAiBD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,MAAM,CA8B7E"}
|
|
@@ -217,12 +217,13 @@ export async function compileTypeScript(options) {
|
|
|
217
217
|
* ```
|
|
218
218
|
*/
|
|
219
219
|
export async function createTypeScriptWatcher(options) {
|
|
220
|
-
const { projectRoot, config, logger, onRebuild, outDir: globalOutDir } = options;
|
|
220
|
+
const { projectRoot, config, logger, onRebuild, outDir: globalOutDir, awaitInitialBuild = false, } = options;
|
|
221
221
|
const resolved = resolveConfig(config, 'development');
|
|
222
222
|
const outputDir = globalOutDir || DEFAULT_OUT_DIR;
|
|
223
223
|
const outDir = path.join(projectRoot, outputDir, resolved.outDir);
|
|
224
224
|
const contexts = [];
|
|
225
225
|
const latestResults = new Map();
|
|
226
|
+
const initialBuildPromises = [];
|
|
226
227
|
for (const bundleConfig of resolved.bundles) {
|
|
227
228
|
const entryPath = path.join(projectRoot, resolved.srcDir, bundleConfig.entryPoint);
|
|
228
229
|
// Validate entry point exists
|
|
@@ -230,10 +231,14 @@ export async function createTypeScriptWatcher(options) {
|
|
|
230
231
|
logger.warning(`TypeScript entry point not found: ${entryPath} (bundle: ${bundleConfig.bundleName})`);
|
|
231
232
|
continue;
|
|
232
233
|
}
|
|
233
|
-
// Track whether this is the initial build triggered by context.watch()
|
|
234
|
-
// We skip notifications for
|
|
235
|
-
// by compileTypeScript() during the initial build phase
|
|
234
|
+
// Track whether this is the initial build triggered by context.watch().
|
|
235
|
+
// We skip reload notifications for this build to avoid a reload storm during startup.
|
|
236
236
|
let isInitialBuild = true;
|
|
237
|
+
let resolveInitialBuild;
|
|
238
|
+
const initialBuildPromise = new Promise((resolve) => {
|
|
239
|
+
resolveInitialBuild = resolve;
|
|
240
|
+
});
|
|
241
|
+
initialBuildPromises.push(initialBuildPromise);
|
|
237
242
|
const context = await esbuild.context({
|
|
238
243
|
entryPoints: [entryPath],
|
|
239
244
|
bundle: true,
|
|
@@ -275,15 +280,21 @@ export async function createTypeScriptWatcher(options) {
|
|
|
275
280
|
path: bundlePath,
|
|
276
281
|
};
|
|
277
282
|
latestResults.set(bundleConfig.bundleName, bundleResult);
|
|
278
|
-
// Skip notifications for the initial build triggered by context.watch()
|
|
279
|
-
//
|
|
283
|
+
// Skip notifications for the initial build triggered by context.watch().
|
|
284
|
+
// This avoids triggering a reload while startup priming is still in progress.
|
|
280
285
|
if (isInitialBuild) {
|
|
281
286
|
isInitialBuild = false;
|
|
287
|
+
resolveInitialBuild();
|
|
282
288
|
return;
|
|
283
289
|
}
|
|
284
290
|
logger.info(`TypeScript '${bundleConfig.bundleName}' recompiled.`);
|
|
285
291
|
// Notify with all current results and compile time
|
|
286
292
|
onRebuild(Array.from(latestResults.values()), compileTime);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
if (isInitialBuild) {
|
|
296
|
+
isInitialBuild = false;
|
|
297
|
+
resolveInitialBuild();
|
|
287
298
|
}
|
|
288
299
|
});
|
|
289
300
|
},
|
|
@@ -294,6 +305,9 @@ export async function createTypeScriptWatcher(options) {
|
|
|
294
305
|
await context.watch();
|
|
295
306
|
contexts.push(context);
|
|
296
307
|
}
|
|
308
|
+
if (awaitInitialBuild && initialBuildPromises.length > 0) {
|
|
309
|
+
await Promise.all(initialBuildPromises);
|
|
310
|
+
}
|
|
297
311
|
if (contexts.length > 0) {
|
|
298
312
|
logger.info(`Watching TypeScript files in ${resolved.srcDir}/ (${contexts.length} bundle${contexts.length > 1 ? 's' : ''})`);
|
|
299
313
|
}
|