@astroscope/boot 0.2.0 → 0.2.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/index.cjs +2 -1
- package/dist/index.js +2 -1
- package/dist/warmup.cjs +24 -8
- package/dist/warmup.d.cts +11 -0
- package/dist/warmup.d.ts +11 -0
- package/dist/warmup.js +27 -11
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -227,7 +227,8 @@ function boot(options = {}) {
|
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
const { host, port } = getServerDefaults(astroConfig);
|
|
230
|
-
const bootImport = `
|
|
230
|
+
const bootImport = `globalThis.__astroscope_server_url = import.meta.url;
|
|
231
|
+
import * as __boot from './${bootChunkName}';
|
|
231
232
|
const __bootContext = { dev: false, host: process.env.HOST ?? '${host}', port: process.env.PORT ? Number(process.env.PORT) : ${port} };
|
|
232
233
|
await __boot.onStartup?.(__bootContext);
|
|
233
234
|
if (__boot.onShutdown) process.on('SIGTERM', async () => { await __boot.onShutdown(__bootContext); process.exit(0); });
|
package/dist/index.js
CHANGED
|
@@ -190,7 +190,8 @@ function boot(options = {}) {
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
const { host, port } = getServerDefaults(astroConfig);
|
|
193
|
-
const bootImport = `
|
|
193
|
+
const bootImport = `globalThis.__astroscope_server_url = import.meta.url;
|
|
194
|
+
import * as __boot from './${bootChunkName}';
|
|
194
195
|
const __bootContext = { dev: false, host: process.env.HOST ?? '${host}', port: process.env.PORT ? Number(process.env.PORT) : ${port} };
|
|
195
196
|
await __boot.onStartup?.(__bootContext);
|
|
196
197
|
if (__boot.onShutdown) process.on('SIGTERM', async () => { await __boot.onShutdown(__bootContext); process.exit(0); });
|
package/dist/warmup.cjs
CHANGED
|
@@ -31,21 +31,37 @@ var WARMUP_MANIFEST_FILE = "warmup-manifest.json";
|
|
|
31
31
|
function isDevMode() {
|
|
32
32
|
return Boolean(import_meta.env?.["DEV"]);
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function loadManifest() {
|
|
35
35
|
if (isDevMode()) {
|
|
36
|
-
return
|
|
36
|
+
return null;
|
|
37
37
|
}
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
const serverUrl = globalThis.__astroscope_server_url;
|
|
39
|
+
if (!serverUrl) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const serverDir = (0, import_node_path.dirname)((0, import_node_url.fileURLToPath)(serverUrl));
|
|
43
|
+
const manifestPath = (0, import_node_path.join)(serverDir, "chunks", WARMUP_MANIFEST_FILE);
|
|
44
|
+
if (!(0, import_node_fs.existsSync)(manifestPath)) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const manifest = JSON.parse((0, import_node_fs.readFileSync)(manifestPath, "utf-8"));
|
|
48
|
+
return {
|
|
49
|
+
modules: manifest.modules ?? [],
|
|
50
|
+
serverDir
|
|
51
|
+
};
|
|
41
52
|
}
|
|
42
53
|
async function warmup() {
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
54
|
+
const manifest = loadManifest();
|
|
55
|
+
if (!manifest || manifest.modules.length === 0) {
|
|
45
56
|
return { success: [], failed: [], duration: 0 };
|
|
46
57
|
}
|
|
58
|
+
const { modules, serverDir } = manifest;
|
|
47
59
|
const start = Date.now();
|
|
48
|
-
const
|
|
60
|
+
const resolvedModules = modules.map((mod) => {
|
|
61
|
+
const absolutePath = (0, import_node_path.resolve)(serverDir, mod);
|
|
62
|
+
return (0, import_node_url.pathToFileURL)(absolutePath).href;
|
|
63
|
+
});
|
|
64
|
+
const results = await Promise.allSettled(resolvedModules.map((mod) => import(mod)));
|
|
49
65
|
const success = [];
|
|
50
66
|
const failed = [];
|
|
51
67
|
for (let i = 0; i < results.length; i++) {
|
package/dist/warmup.d.cts
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { W as WarmupResult } from './types-CxpusND2.cjs';
|
|
2
2
|
|
|
3
|
+
declare global {
|
|
4
|
+
var __astroscope_server_url: string | undefined;
|
|
5
|
+
}
|
|
3
6
|
/**
|
|
4
7
|
* Warms up V8 by importing all page modules and middleware.
|
|
5
8
|
*
|
|
6
9
|
* In development mode, this is a no-op that returns empty results.
|
|
7
10
|
* In production, reads the warmup manifest and imports all discovered modules.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { warmup } from '@astroscope/boot/warmup';
|
|
15
|
+
*
|
|
16
|
+
* const result = await warmup();
|
|
17
|
+
* console.log(`warmed up ${result.success.length} modules`);
|
|
18
|
+
* ```
|
|
8
19
|
*/
|
|
9
20
|
declare function warmup(): Promise<WarmupResult>;
|
|
10
21
|
|
package/dist/warmup.d.ts
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { W as WarmupResult } from './types-CxpusND2.js';
|
|
2
2
|
|
|
3
|
+
declare global {
|
|
4
|
+
var __astroscope_server_url: string | undefined;
|
|
5
|
+
}
|
|
3
6
|
/**
|
|
4
7
|
* Warms up V8 by importing all page modules and middleware.
|
|
5
8
|
*
|
|
6
9
|
* In development mode, this is a no-op that returns empty results.
|
|
7
10
|
* In production, reads the warmup manifest and imports all discovered modules.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { warmup } from '@astroscope/boot/warmup';
|
|
15
|
+
*
|
|
16
|
+
* const result = await warmup();
|
|
17
|
+
* console.log(`warmed up ${result.success.length} modules`);
|
|
18
|
+
* ```
|
|
8
19
|
*/
|
|
9
20
|
declare function warmup(): Promise<WarmupResult>;
|
|
10
21
|
|
package/dist/warmup.js
CHANGED
|
@@ -1,26 +1,42 @@
|
|
|
1
1
|
// src/warmup.ts
|
|
2
|
-
import { readFileSync } from "fs";
|
|
3
|
-
import { dirname, join } from "path";
|
|
4
|
-
import { fileURLToPath } from "url";
|
|
2
|
+
import { existsSync, readFileSync } from "fs";
|
|
3
|
+
import { dirname, join, resolve } from "path";
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from "url";
|
|
5
5
|
var WARMUP_MANIFEST_FILE = "warmup-manifest.json";
|
|
6
6
|
function isDevMode() {
|
|
7
7
|
return Boolean(import.meta.env?.["DEV"]);
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function loadManifest() {
|
|
10
10
|
if (isDevMode()) {
|
|
11
|
-
return
|
|
11
|
+
return null;
|
|
12
12
|
}
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
};
|
|
16
27
|
}
|
|
17
28
|
async function warmup() {
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
29
|
+
const manifest = loadManifest();
|
|
30
|
+
if (!manifest || manifest.modules.length === 0) {
|
|
20
31
|
return { success: [], failed: [], duration: 0 };
|
|
21
32
|
}
|
|
33
|
+
const { modules, serverDir } = manifest;
|
|
22
34
|
const start = Date.now();
|
|
23
|
-
const
|
|
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(mod)));
|
|
24
40
|
const success = [];
|
|
25
41
|
const failed = [];
|
|
26
42
|
for (let i = 0; i < results.length; i++) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astroscope/boot",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Startup and graceful shutdown hooks for Astro SSR",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"lint:fix": "eslint 'src/**/*.{ts,tsx}' --fix"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"astro": "^5.
|
|
50
|
+
"astro": "^5.17.1",
|
|
51
51
|
"tsup": "^8.5.1",
|
|
52
52
|
"typescript": "^5.9.3"
|
|
53
53
|
},
|