@astroscope/boot 0.6.2 → 0.6.4

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/index.cjs CHANGED
@@ -142,7 +142,7 @@ async function ssrImport(server, moduleId) {
142
142
  }
143
143
 
144
144
  // src/hmr.ts
145
- function setupBootHmr(server, entry, logger, getBootContext2) {
145
+ function setupBootHmr(server, entry, logger, getBootContext2, initialModule) {
146
146
  const bootModuleId = `/${entry}`;
147
147
  const bootFilePath = import_node_path.default.resolve(server.config.root, entry);
148
148
  const getBootDependencies = () => {
@@ -165,15 +165,21 @@ function setupBootHmr(server, entry, logger, getBootContext2) {
165
165
  const p = filePath.toLowerCase();
166
166
  return ignoredSuffixes.some((suffix) => p.endsWith(suffix));
167
167
  };
168
- server.watcher.on("change", async (changedPath) => {
169
- if (shouldIgnore(changedPath)) return;
170
- const bootDeps = getBootDependencies();
171
- if (bootDeps.has(changedPath)) {
172
- logger.info(`boot dependency changed: ${changedPath}, rerunning hooks...`);
168
+ let currentBootModule = initialModule;
169
+ let running = false;
170
+ let pendingReason;
171
+ let rerunPromise = null;
172
+ const rerunBoot = async (reason) => {
173
+ if (running) {
174
+ pendingReason = reason;
175
+ return;
176
+ }
177
+ running = true;
178
+ try {
179
+ logger.info(`${reason}, rerunning hooks...`);
173
180
  const bootContext = getBootContext2();
174
181
  try {
175
- const oldModule = await ssrImport(server, bootModuleId);
176
- await runShutdown(oldModule, bootContext);
182
+ await runShutdown(currentBootModule, bootContext);
177
183
  } catch (error) {
178
184
  logger.error(`Error during boot HMR shutdown: ${serializeError(error)}`);
179
185
  }
@@ -181,10 +187,55 @@ function setupBootHmr(server, entry, logger, getBootContext2) {
181
187
  try {
182
188
  const newModule = await ssrImport(server, bootModuleId);
183
189
  await runStartup(newModule, bootContext);
190
+ currentBootModule = newModule;
184
191
  } catch (error) {
185
192
  logger.error(`Error during boot HMR startup: ${serializeError(error)}`);
186
193
  }
194
+ } finally {
195
+ running = false;
196
+ }
197
+ if (pendingReason) {
198
+ const nextReason = pendingReason;
199
+ pendingReason = void 0;
200
+ await rerunBoot(nextReason);
201
+ }
202
+ };
203
+ server.watcher.on("change", async (changedPath) => {
204
+ if (shouldIgnore(changedPath)) return;
205
+ const bootDeps = getBootDependencies();
206
+ if (bootDeps.has(changedPath)) {
207
+ rerunPromise = rerunBoot(`boot dependency changed: ${changedPath}`);
208
+ await rerunPromise;
209
+ rerunPromise = null;
210
+ }
211
+ });
212
+ let handleFullReloads = false;
213
+ if (server.httpServer) {
214
+ server.httpServer.once("listening", () => {
215
+ handleFullReloads = true;
216
+ });
217
+ } else {
218
+ handleFullReloads = true;
219
+ }
220
+ const scheduleFullReloadRerun = (payload) => {
221
+ if (!handleFullReloads) return;
222
+ if (payload.type !== "full-reload") return;
223
+ const triggeredBy = "triggeredBy" in payload ? payload.triggeredBy : void 0;
224
+ if (triggeredBy && getBootDependencies().has(triggeredBy)) return;
225
+ rerunPromise = rerunBoot("full reload detected");
226
+ void rerunPromise.then(() => {
227
+ rerunPromise = null;
228
+ });
229
+ };
230
+ const ssrOutsideEmitter = server.environments["ssr"]?.hot?.api?.outsideEmitter;
231
+ if (ssrOutsideEmitter) {
232
+ ssrOutsideEmitter.on("send", scheduleFullReloadRerun);
233
+ }
234
+ server.middlewares.use(async (_req, _res, next) => {
235
+ if (rerunPromise) {
236
+ await rerunPromise;
187
237
  }
238
+ next();
188
239
  });
189
240
  }
190
241
 
@@ -350,24 +401,25 @@ ${warmupEnd}`;
350
401
  enforce: "post",
351
402
  async configureServer(server) {
352
403
  if (command !== "dev") return;
404
+ let bootModule;
353
405
  try {
354
406
  const bootContext = getBootContext(server, astroConfig);
355
- const module2 = await ssrImport(server, `/${entry}`);
356
- await runStartup(module2, bootContext);
407
+ bootModule = await ssrImport(server, `/${entry}`);
408
+ await runStartup(bootModule, bootContext);
357
409
  } catch (error) {
358
410
  logger.error(`Error running startup script: ${serializeError(error)}`);
359
411
  }
360
412
  server.httpServer?.once("close", async () => {
361
413
  try {
362
414
  const bootContext = getBootContext(server, astroConfig);
363
- const module2 = await ssrImport(server, `/${entry}`);
364
- await runShutdown(module2, bootContext);
415
+ const mod = await ssrImport(server, `/${entry}`);
416
+ await runShutdown(mod, bootContext);
365
417
  } catch (error) {
366
418
  logger.error(`Error running shutdown script: ${serializeError(error)}`);
367
419
  }
368
420
  });
369
- if (hmr) {
370
- setupBootHmr(server, entry, logger, () => getBootContext(server, astroConfig));
421
+ if (hmr && bootModule) {
422
+ setupBootHmr(server, entry, logger, () => getBootContext(server, astroConfig), bootModule);
371
423
  }
372
424
  }
373
425
  }
package/dist/index.js CHANGED
@@ -79,7 +79,7 @@ async function ssrImport(server, moduleId) {
79
79
  }
80
80
 
81
81
  // src/hmr.ts
82
- function setupBootHmr(server, entry, logger, getBootContext2) {
82
+ function setupBootHmr(server, entry, logger, getBootContext2, initialModule) {
83
83
  const bootModuleId = `/${entry}`;
84
84
  const bootFilePath = path.resolve(server.config.root, entry);
85
85
  const getBootDependencies = () => {
@@ -102,15 +102,21 @@ function setupBootHmr(server, entry, logger, getBootContext2) {
102
102
  const p = filePath.toLowerCase();
103
103
  return ignoredSuffixes.some((suffix) => p.endsWith(suffix));
104
104
  };
105
- server.watcher.on("change", async (changedPath) => {
106
- if (shouldIgnore(changedPath)) return;
107
- const bootDeps = getBootDependencies();
108
- if (bootDeps.has(changedPath)) {
109
- logger.info(`boot dependency changed: ${changedPath}, rerunning hooks...`);
105
+ let currentBootModule = initialModule;
106
+ let running = false;
107
+ let pendingReason;
108
+ let rerunPromise = null;
109
+ const rerunBoot = async (reason) => {
110
+ if (running) {
111
+ pendingReason = reason;
112
+ return;
113
+ }
114
+ running = true;
115
+ try {
116
+ logger.info(`${reason}, rerunning hooks...`);
110
117
  const bootContext = getBootContext2();
111
118
  try {
112
- const oldModule = await ssrImport(server, bootModuleId);
113
- await runShutdown(oldModule, bootContext);
119
+ await runShutdown(currentBootModule, bootContext);
114
120
  } catch (error) {
115
121
  logger.error(`Error during boot HMR shutdown: ${serializeError(error)}`);
116
122
  }
@@ -118,10 +124,55 @@ function setupBootHmr(server, entry, logger, getBootContext2) {
118
124
  try {
119
125
  const newModule = await ssrImport(server, bootModuleId);
120
126
  await runStartup(newModule, bootContext);
127
+ currentBootModule = newModule;
121
128
  } catch (error) {
122
129
  logger.error(`Error during boot HMR startup: ${serializeError(error)}`);
123
130
  }
131
+ } finally {
132
+ running = false;
133
+ }
134
+ if (pendingReason) {
135
+ const nextReason = pendingReason;
136
+ pendingReason = void 0;
137
+ await rerunBoot(nextReason);
138
+ }
139
+ };
140
+ server.watcher.on("change", async (changedPath) => {
141
+ if (shouldIgnore(changedPath)) return;
142
+ const bootDeps = getBootDependencies();
143
+ if (bootDeps.has(changedPath)) {
144
+ rerunPromise = rerunBoot(`boot dependency changed: ${changedPath}`);
145
+ await rerunPromise;
146
+ rerunPromise = null;
147
+ }
148
+ });
149
+ let handleFullReloads = false;
150
+ if (server.httpServer) {
151
+ server.httpServer.once("listening", () => {
152
+ handleFullReloads = true;
153
+ });
154
+ } else {
155
+ handleFullReloads = true;
156
+ }
157
+ const scheduleFullReloadRerun = (payload) => {
158
+ if (!handleFullReloads) return;
159
+ if (payload.type !== "full-reload") return;
160
+ const triggeredBy = "triggeredBy" in payload ? payload.triggeredBy : void 0;
161
+ if (triggeredBy && getBootDependencies().has(triggeredBy)) return;
162
+ rerunPromise = rerunBoot("full reload detected");
163
+ void rerunPromise.then(() => {
164
+ rerunPromise = null;
165
+ });
166
+ };
167
+ const ssrOutsideEmitter = server.environments["ssr"]?.hot?.api?.outsideEmitter;
168
+ if (ssrOutsideEmitter) {
169
+ ssrOutsideEmitter.on("send", scheduleFullReloadRerun);
170
+ }
171
+ server.middlewares.use(async (_req, _res, next) => {
172
+ if (rerunPromise) {
173
+ await rerunPromise;
124
174
  }
175
+ next();
125
176
  });
126
177
  }
127
178
 
@@ -278,24 +329,25 @@ ${warmupEnd}`;
278
329
  enforce: "post",
279
330
  async configureServer(server) {
280
331
  if (command !== "dev") return;
332
+ let bootModule;
281
333
  try {
282
334
  const bootContext = getBootContext(server, astroConfig);
283
- const module = await ssrImport(server, `/${entry}`);
284
- await runStartup(module, bootContext);
335
+ bootModule = await ssrImport(server, `/${entry}`);
336
+ await runStartup(bootModule, bootContext);
285
337
  } catch (error) {
286
338
  logger.error(`Error running startup script: ${serializeError(error)}`);
287
339
  }
288
340
  server.httpServer?.once("close", async () => {
289
341
  try {
290
342
  const bootContext = getBootContext(server, astroConfig);
291
- const module = await ssrImport(server, `/${entry}`);
292
- await runShutdown(module, bootContext);
343
+ const mod = await ssrImport(server, `/${entry}`);
344
+ await runShutdown(mod, bootContext);
293
345
  } catch (error) {
294
346
  logger.error(`Error running shutdown script: ${serializeError(error)}`);
295
347
  }
296
348
  });
297
- if (hmr) {
298
- setupBootHmr(server, entry, logger, () => getBootContext(server, astroConfig));
349
+ if (hmr && bootModule) {
350
+ setupBootHmr(server, entry, logger, () => getBootContext(server, astroConfig), bootModule);
299
351
  }
300
352
  }
301
353
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astroscope/boot",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "Startup and graceful shutdown hooks for Astro SSR",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,57 +0,0 @@
1
- // src/warmup.ts
2
- import { readdirSync } from "fs";
3
- import { join, resolve } from "path";
4
- import { pathToFileURL } from "url";
5
- var SKIP_PATTERNS = [/^noop-/, /server-island/, /session-driver/];
6
- function setServerDir(dir) {
7
- globalThis.__astroscope_boot_server_dir = dir;
8
- }
9
- function isDevMode() {
10
- return Boolean(import.meta.env?.["DEV"]);
11
- }
12
- function discoverChunks(chunksDir) {
13
- let entries;
14
- try {
15
- entries = readdirSync(chunksDir);
16
- } catch {
17
- return [];
18
- }
19
- return entries.filter((name) => {
20
- if (!name.endsWith(".mjs")) return false;
21
- return !SKIP_PATTERNS.some((pattern) => pattern.test(name));
22
- });
23
- }
24
- async function warmup() {
25
- const dir = globalThis.__astroscope_boot_server_dir;
26
- if (isDevMode() || !dir) {
27
- return { success: [], failed: [], duration: 0 };
28
- }
29
- const chunksDir = join(dir, "chunks");
30
- const chunks = discoverChunks(chunksDir);
31
- if (chunks.length === 0) {
32
- return { success: [], failed: [], duration: 0 };
33
- }
34
- const start = Date.now();
35
- const resolvedModules = chunks.map((name) => pathToFileURL(resolve(chunksDir, name)).href);
36
- const results = await Promise.allSettled(resolvedModules.map((mod) => import(
37
- /* @vite-ignore */
38
- mod
39
- )));
40
- const success = [];
41
- const failed = [];
42
- for (let i = 0; i < results.length; i++) {
43
- const result = results[i];
44
- if (result.status === "fulfilled") {
45
- success.push(chunks[i]);
46
- } else {
47
- const reason = result.reason instanceof Error ? result.reason.message : String(result.reason);
48
- failed.push(`${chunks[i]} (${reason})`);
49
- }
50
- }
51
- return { success, failed, duration: Date.now() - start };
52
- }
53
-
54
- export {
55
- setServerDir,
56
- warmup
57
- };
@@ -1,38 +0,0 @@
1
- // src/events.ts
2
- var STORE_KEY = /* @__PURE__ */ Symbol.for("@astroscope/boot/events");
3
- function getStore() {
4
- const existing = globalThis[STORE_KEY];
5
- if (existing) return existing;
6
- const store = {
7
- listeners: /* @__PURE__ */ new Map()
8
- };
9
- globalThis[STORE_KEY] = store;
10
- return store;
11
- }
12
- function on(event, handler) {
13
- const store = getStore();
14
- let handlers = store.listeners.get(event);
15
- if (!handlers) {
16
- handlers = /* @__PURE__ */ new Set();
17
- store.listeners.set(event, handlers);
18
- }
19
- handlers.add(handler);
20
- }
21
- function off(event, handler) {
22
- const store = getStore();
23
- store.listeners.get(event)?.delete(handler);
24
- }
25
- async function emit(event, context) {
26
- const store = getStore();
27
- const handlers = store.listeners.get(event);
28
- if (!handlers) return;
29
- for (const handler of handlers) {
30
- await handler(context);
31
- }
32
- }
33
-
34
- export {
35
- on,
36
- off,
37
- emit
38
- };
@@ -1,57 +0,0 @@
1
- // src/warmup.ts
2
- import { readdirSync } from "fs";
3
- import { join, resolve } from "path";
4
- import { pathToFileURL } from "url";
5
- var SKIP_PATTERNS = [/^noop-/, /server-island/, /session-driver/];
6
- var serverDir;
7
- function setServerDir(dir) {
8
- serverDir = dir;
9
- }
10
- function isDevMode() {
11
- return Boolean(import.meta.env?.["DEV"]);
12
- }
13
- function discoverChunks(chunksDir) {
14
- let entries;
15
- try {
16
- entries = readdirSync(chunksDir);
17
- } catch {
18
- return [];
19
- }
20
- return entries.filter((name) => {
21
- if (!name.endsWith(".mjs")) return false;
22
- return !SKIP_PATTERNS.some((pattern) => pattern.test(name));
23
- });
24
- }
25
- async function warmup() {
26
- if (isDevMode() || !serverDir) {
27
- return { success: [], failed: [], duration: 0 };
28
- }
29
- const chunksDir = join(serverDir, "chunks");
30
- const chunks = discoverChunks(chunksDir);
31
- if (chunks.length === 0) {
32
- return { success: [], failed: [], duration: 0 };
33
- }
34
- const start = Date.now();
35
- const resolvedModules = chunks.map((name) => pathToFileURL(resolve(chunksDir, name)).href);
36
- const results = await Promise.allSettled(resolvedModules.map((mod) => import(
37
- /* @vite-ignore */
38
- mod
39
- )));
40
- const success = [];
41
- const failed = [];
42
- for (let i = 0; i < results.length; i++) {
43
- const result = results[i];
44
- if (result.status === "fulfilled") {
45
- success.push(chunks[i]);
46
- } else {
47
- const reason = result.reason instanceof Error ? result.reason.message : String(result.reason);
48
- failed.push(`${chunks[i]} (${reason})`);
49
- }
50
- }
51
- return { success, failed, duration: Date.now() - start };
52
- }
53
-
54
- export {
55
- setServerDir,
56
- warmup
57
- };
@@ -1,57 +0,0 @@
1
- // src/warmup.ts
2
- import { existsSync, readFileSync } from "fs";
3
- import { dirname, join, resolve } from "path";
4
- import { fileURLToPath, pathToFileURL } from "url";
5
- var WARMUP_MANIFEST_FILE = "warmup-manifest.json";
6
- function isDevMode() {
7
- return Boolean(import.meta.env?.["DEV"]);
8
- }
9
- function loadManifest() {
10
- if (isDevMode()) {
11
- return null;
12
- }
13
- const serverUrl = globalThis.__astroscope_server_url;
14
- if (!serverUrl) {
15
- return null;
16
- }
17
- const serverDir = dirname(fileURLToPath(serverUrl));
18
- const manifestPath = join(serverDir, "chunks", WARMUP_MANIFEST_FILE);
19
- if (!existsSync(manifestPath)) {
20
- return null;
21
- }
22
- const manifest = JSON.parse(readFileSync(manifestPath, "utf-8"));
23
- return {
24
- modules: manifest.modules ?? [],
25
- serverDir
26
- };
27
- }
28
- async function warmup() {
29
- const manifest = loadManifest();
30
- if (!manifest || manifest.modules.length === 0) {
31
- return { success: [], failed: [], duration: 0 };
32
- }
33
- const { modules, serverDir } = manifest;
34
- const start = Date.now();
35
- const resolvedModules = modules.map((mod) => {
36
- const absolutePath = resolve(serverDir, mod);
37
- return pathToFileURL(absolutePath).href;
38
- });
39
- const results = await Promise.allSettled(resolvedModules.map((mod) => import(
40
- /* @vite-ignore */
41
- mod
42
- )));
43
- const success = [];
44
- const failed = [];
45
- for (let i = 0; i < results.length; i++) {
46
- if (results[i].status === "fulfilled") {
47
- success.push(modules[i]);
48
- } else {
49
- failed.push(modules[i]);
50
- }
51
- }
52
- return { success, failed, duration: Date.now() - start };
53
- }
54
-
55
- export {
56
- warmup
57
- };
@@ -1,45 +0,0 @@
1
- // src/lifecycle.ts
2
- var STATE_KEY = /* @__PURE__ */ Symbol.for("@astroscope/boot/lifecycle");
3
- function getState() {
4
- const existing = globalThis[STATE_KEY];
5
- if (existing) {
6
- return existing;
7
- }
8
- const state = {
9
- listeners: /* @__PURE__ */ new Map()
10
- };
11
- globalThis[STATE_KEY] = state;
12
- return state;
13
- }
14
- function onLifecycle(event, listener) {
15
- const state = getState();
16
- let listeners = state.listeners.get(event);
17
- if (!listeners) {
18
- listeners = /* @__PURE__ */ new Set();
19
- state.listeners.set(event, listeners);
20
- }
21
- listeners.add(listener);
22
- return () => {
23
- listeners.delete(listener);
24
- };
25
- }
26
- async function emitLifecycle(event) {
27
- const state = getState();
28
- const listeners = state.listeners.get(event);
29
- if (!listeners || listeners.size === 0) {
30
- return;
31
- }
32
- const promises = [];
33
- for (const listener of listeners) {
34
- const result = listener();
35
- if (result instanceof Promise) {
36
- promises.push(result);
37
- }
38
- }
39
- await Promise.all(promises);
40
- }
41
-
42
- export {
43
- onLifecycle,
44
- emitLifecycle
45
- };
@@ -1,16 +0,0 @@
1
- interface BootContext {
2
- /** Whether running in development mode (vite dev server) */
3
- dev: boolean;
4
- /** Server host from Astro config */
5
- host: string;
6
- /** Server port from Astro config */
7
- port: number;
8
- }
9
- interface WarmupResult {
10
- /** Modules that were loaded (page paths + middleware) */
11
- modules: string[];
12
- /** Time taken in milliseconds */
13
- duration: number;
14
- }
15
-
16
- export type { BootContext as B, WarmupResult as W };
@@ -1,16 +0,0 @@
1
- interface BootContext {
2
- /** Whether running in development mode (vite dev server) */
3
- dev: boolean;
4
- /** Server host from Astro config */
5
- host: string;
6
- /** Server port from Astro config */
7
- port: number;
8
- }
9
- interface WarmupResult {
10
- /** Modules that were loaded (page paths + middleware) */
11
- modules: string[];
12
- /** Time taken in milliseconds */
13
- duration: number;
14
- }
15
-
16
- export type { BootContext as B, WarmupResult as W };
@@ -1,18 +0,0 @@
1
- interface BootContext {
2
- /** Whether running in development mode (vite dev server) */
3
- dev: boolean;
4
- /** Server host from Astro config */
5
- host: string;
6
- /** Server port from Astro config */
7
- port: number;
8
- }
9
- interface WarmupResult {
10
- /** Modules that were successfully loaded */
11
- success: string[];
12
- /** Modules that failed to load */
13
- failed: string[];
14
- /** Time taken in milliseconds */
15
- duration: number;
16
- }
17
-
18
- export type { BootContext as B, WarmupResult as W };
@@ -1,18 +0,0 @@
1
- interface BootContext {
2
- /** Whether running in development mode (vite dev server) */
3
- dev: boolean;
4
- /** Server host from Astro config */
5
- host: string;
6
- /** Server port from Astro config */
7
- port: number;
8
- }
9
- interface WarmupResult {
10
- /** Modules that were successfully loaded */
11
- success: string[];
12
- /** Modules that failed to load */
13
- failed: string[];
14
- /** Time taken in milliseconds */
15
- duration: number;
16
- }
17
-
18
- export type { BootContext as B, WarmupResult as W };
package/dist/warmup.cjs DELETED
@@ -1,83 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/warmup.ts
21
- var warmup_exports = {};
22
- __export(warmup_exports, {
23
- setServerDir: () => setServerDir,
24
- warmup: () => warmup
25
- });
26
- module.exports = __toCommonJS(warmup_exports);
27
- var import_node_fs = require("fs");
28
- var import_node_path = require("path");
29
- var import_node_url = require("url");
30
- var import_meta = {};
31
- var SKIP_PATTERNS = [/^noop-/, /server-island/, /session-driver/];
32
- function setServerDir(dir) {
33
- globalThis.__astroscope_boot_server_dir = dir;
34
- }
35
- function isDevMode() {
36
- return Boolean(import_meta.env?.["DEV"]);
37
- }
38
- function discoverChunks(chunksDir) {
39
- let entries;
40
- try {
41
- entries = (0, import_node_fs.readdirSync)(chunksDir);
42
- } catch {
43
- return [];
44
- }
45
- return entries.filter((name) => {
46
- if (!name.endsWith(".mjs")) return false;
47
- return !SKIP_PATTERNS.some((pattern) => pattern.test(name));
48
- });
49
- }
50
- async function warmup() {
51
- const dir = globalThis.__astroscope_boot_server_dir;
52
- if (isDevMode() || !dir) {
53
- return { success: [], failed: [], duration: 0 };
54
- }
55
- const chunksDir = (0, import_node_path.join)(dir, "chunks");
56
- const chunks = discoverChunks(chunksDir);
57
- if (chunks.length === 0) {
58
- return { success: [], failed: [], duration: 0 };
59
- }
60
- const start = Date.now();
61
- const resolvedModules = chunks.map((name) => (0, import_node_url.pathToFileURL)((0, import_node_path.resolve)(chunksDir, name)).href);
62
- const results = await Promise.allSettled(resolvedModules.map((mod) => import(
63
- /* @vite-ignore */
64
- mod
65
- )));
66
- const success = [];
67
- const failed = [];
68
- for (let i = 0; i < results.length; i++) {
69
- const result = results[i];
70
- if (result.status === "fulfilled") {
71
- success.push(chunks[i]);
72
- } else {
73
- const reason = result.reason instanceof Error ? result.reason.message : String(result.reason);
74
- failed.push(`${chunks[i]} (${reason})`);
75
- }
76
- }
77
- return { success, failed, duration: Date.now() - start };
78
- }
79
- // Annotate the CommonJS export names for ESM import in node:
80
- 0 && (module.exports = {
81
- setServerDir,
82
- warmup
83
- });
package/dist/warmup.d.cts DELETED
@@ -1,28 +0,0 @@
1
- import { W as WarmupResult } from './types-CxpusND2.cjs';
2
-
3
- declare global {
4
- var __astroscope_boot_server_dir: string | undefined;
5
- }
6
- /**
7
- * Set the server directory for warmup module discovery.
8
- * Called internally by `setup()` — users do not need to call this.
9
- */
10
- declare function setServerDir(dir: string): void;
11
- /**
12
- * Warms up V8 by importing all server chunks.
13
- *
14
- * In development mode, this is a no-op that returns empty results.
15
- * In production, discovers all `.mjs` chunks in the server output directory
16
- * and imports them to eliminate cold-start latency on first request.
17
- *
18
- * @example
19
- * ```ts
20
- * import { warmup } from '@astroscope/boot/warmup';
21
- *
22
- * const result = await warmup();
23
- * console.log(`warmed up ${result.success.length} modules`);
24
- * ```
25
- */
26
- declare function warmup(): Promise<WarmupResult>;
27
-
28
- export { WarmupResult, setServerDir, warmup };
package/dist/warmup.d.ts DELETED
@@ -1,28 +0,0 @@
1
- import { W as WarmupResult } from './types-CxpusND2.js';
2
-
3
- declare global {
4
- var __astroscope_boot_server_dir: string | undefined;
5
- }
6
- /**
7
- * Set the server directory for warmup module discovery.
8
- * Called internally by `setup()` — users do not need to call this.
9
- */
10
- declare function setServerDir(dir: string): void;
11
- /**
12
- * Warms up V8 by importing all server chunks.
13
- *
14
- * In development mode, this is a no-op that returns empty results.
15
- * In production, discovers all `.mjs` chunks in the server output directory
16
- * and imports them to eliminate cold-start latency on first request.
17
- *
18
- * @example
19
- * ```ts
20
- * import { warmup } from '@astroscope/boot/warmup';
21
- *
22
- * const result = await warmup();
23
- * console.log(`warmed up ${result.success.length} modules`);
24
- * ```
25
- */
26
- declare function warmup(): Promise<WarmupResult>;
27
-
28
- export { WarmupResult, setServerDir, warmup };
package/dist/warmup.js DELETED
@@ -1,8 +0,0 @@
1
- import {
2
- setServerDir,
3
- warmup
4
- } from "./chunk-AL4QFQEW.js";
5
- export {
6
- setServerDir,
7
- warmup
8
- };