@astroscope/boot 0.3.0 → 0.3.2
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 +14 -16
- package/dist/index.js +14 -16
- package/dist/setup.cjs +3 -4
- package/dist/setup.d.cts +4 -1
- package/dist/setup.d.ts +4 -1
- package/dist/setup.js +1 -2
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -118,6 +118,14 @@ async function runShutdown(boot2, context) {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
// src/utils.ts
|
|
122
|
+
function serializeError(error) {
|
|
123
|
+
if (error instanceof Error) {
|
|
124
|
+
return error.stack ?? error.message;
|
|
125
|
+
}
|
|
126
|
+
return JSON.stringify(error);
|
|
127
|
+
}
|
|
128
|
+
|
|
121
129
|
// src/hmr.ts
|
|
122
130
|
function setupBootHmr(server, entry, logger, getBootContext) {
|
|
123
131
|
const bootModuleId = `/${entry}`;
|
|
@@ -152,14 +160,14 @@ function setupBootHmr(server, entry, logger, getBootContext) {
|
|
|
152
160
|
const oldModule = await server.ssrLoadModule(bootModuleId);
|
|
153
161
|
await runShutdown(oldModule, bootContext);
|
|
154
162
|
} catch (error) {
|
|
155
|
-
logger.error(`Error during boot HMR shutdown: ${error}`);
|
|
163
|
+
logger.error(`Error during boot HMR shutdown: ${serializeError(error)}`);
|
|
156
164
|
}
|
|
157
165
|
server.moduleGraph.invalidateAll();
|
|
158
166
|
try {
|
|
159
167
|
const newModule = await server.ssrLoadModule(bootModuleId);
|
|
160
168
|
await runStartup(newModule, bootContext);
|
|
161
169
|
} catch (error) {
|
|
162
|
-
logger.error(`Error during boot HMR startup: ${error}`);
|
|
170
|
+
logger.error(`Error during boot HMR startup: ${serializeError(error)}`);
|
|
163
171
|
}
|
|
164
172
|
}
|
|
165
173
|
});
|
|
@@ -202,8 +210,6 @@ function resolveEntry(entry) {
|
|
|
202
210
|
if (import_node_fs2.default.existsSync("src/boot/index.ts")) return "src/boot/index.ts";
|
|
203
211
|
return "src/boot.ts";
|
|
204
212
|
}
|
|
205
|
-
var VIRTUAL_MODULE_ID = "virtual:@astroscope/boot/config";
|
|
206
|
-
var RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID}`;
|
|
207
213
|
function getServerDefaults(config) {
|
|
208
214
|
return {
|
|
209
215
|
host: typeof config?.server?.host === "string" ? config.server.host : config?.server?.host === true ? "0.0.0.0" : "localhost",
|
|
@@ -230,15 +236,6 @@ function boot(options = {}) {
|
|
|
230
236
|
{
|
|
231
237
|
name: "@astroscope/boot",
|
|
232
238
|
enforce: "pre",
|
|
233
|
-
resolveId(id) {
|
|
234
|
-
if (id === VIRTUAL_MODULE_ID) return RESOLVED_VIRTUAL_MODULE_ID;
|
|
235
|
-
},
|
|
236
|
-
load(id) {
|
|
237
|
-
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
238
|
-
const { host, port } = getServerDefaults(astroConfig);
|
|
239
|
-
return `export const config = ${JSON.stringify({ host, port })};`;
|
|
240
|
-
}
|
|
241
|
-
},
|
|
242
239
|
async configureServer(server) {
|
|
243
240
|
if (isBuild) return;
|
|
244
241
|
const getBootContext = () => {
|
|
@@ -255,7 +252,7 @@ function boot(options = {}) {
|
|
|
255
252
|
const module2 = await server.ssrLoadModule(`/${entry}`);
|
|
256
253
|
await runStartup(module2, bootContext);
|
|
257
254
|
} catch (error) {
|
|
258
|
-
logger.error(`Error running startup script: ${error}`);
|
|
255
|
+
logger.error(`Error running startup script: ${serializeError(error)}`);
|
|
259
256
|
}
|
|
260
257
|
server.httpServer?.once("close", async () => {
|
|
261
258
|
try {
|
|
@@ -263,7 +260,7 @@ function boot(options = {}) {
|
|
|
263
260
|
const module2 = await server.ssrLoadModule(`/${entry}`);
|
|
264
261
|
await runShutdown(module2, bootContext);
|
|
265
262
|
} catch (error) {
|
|
266
|
-
logger.error(`Error running shutdown script: ${error}`);
|
|
263
|
+
logger.error(`Error running shutdown script: ${serializeError(error)}`);
|
|
267
264
|
}
|
|
268
265
|
});
|
|
269
266
|
if (hmr) {
|
|
@@ -293,10 +290,11 @@ function boot(options = {}) {
|
|
|
293
290
|
return;
|
|
294
291
|
}
|
|
295
292
|
warmupModules = collectWarmupModules(bundle);
|
|
293
|
+
const { host, port } = getServerDefaults(astroConfig);
|
|
296
294
|
const bootImport = `globalThis.__astroscope_server_url = import.meta.url;
|
|
297
295
|
import * as __astroscope_boot from './${bootChunkName}';
|
|
298
296
|
import { setup as __astroscope_bootSetup } from '@astroscope/boot/setup';
|
|
299
|
-
await __astroscope_bootSetup(__astroscope_boot);
|
|
297
|
+
await __astroscope_bootSetup(__astroscope_boot, ${JSON.stringify({ host, port })});
|
|
300
298
|
`;
|
|
301
299
|
const s = new import_magic_string.default(entryChunk.code);
|
|
302
300
|
s.prepend(bootImport);
|
package/dist/index.js
CHANGED
|
@@ -54,6 +54,14 @@ var ignoredSuffixes = [
|
|
|
54
54
|
".less"
|
|
55
55
|
];
|
|
56
56
|
|
|
57
|
+
// src/utils.ts
|
|
58
|
+
function serializeError(error) {
|
|
59
|
+
if (error instanceof Error) {
|
|
60
|
+
return error.stack ?? error.message;
|
|
61
|
+
}
|
|
62
|
+
return JSON.stringify(error);
|
|
63
|
+
}
|
|
64
|
+
|
|
57
65
|
// src/hmr.ts
|
|
58
66
|
function setupBootHmr(server, entry, logger, getBootContext) {
|
|
59
67
|
const bootModuleId = `/${entry}`;
|
|
@@ -88,14 +96,14 @@ function setupBootHmr(server, entry, logger, getBootContext) {
|
|
|
88
96
|
const oldModule = await server.ssrLoadModule(bootModuleId);
|
|
89
97
|
await runShutdown(oldModule, bootContext);
|
|
90
98
|
} catch (error) {
|
|
91
|
-
logger.error(`Error during boot HMR shutdown: ${error}`);
|
|
99
|
+
logger.error(`Error during boot HMR shutdown: ${serializeError(error)}`);
|
|
92
100
|
}
|
|
93
101
|
server.moduleGraph.invalidateAll();
|
|
94
102
|
try {
|
|
95
103
|
const newModule = await server.ssrLoadModule(bootModuleId);
|
|
96
104
|
await runStartup(newModule, bootContext);
|
|
97
105
|
} catch (error) {
|
|
98
|
-
logger.error(`Error during boot HMR startup: ${error}`);
|
|
106
|
+
logger.error(`Error during boot HMR startup: ${serializeError(error)}`);
|
|
99
107
|
}
|
|
100
108
|
}
|
|
101
109
|
});
|
|
@@ -138,8 +146,6 @@ function resolveEntry(entry) {
|
|
|
138
146
|
if (fs2.existsSync("src/boot/index.ts")) return "src/boot/index.ts";
|
|
139
147
|
return "src/boot.ts";
|
|
140
148
|
}
|
|
141
|
-
var VIRTUAL_MODULE_ID = "virtual:@astroscope/boot/config";
|
|
142
|
-
var RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID}`;
|
|
143
149
|
function getServerDefaults(config) {
|
|
144
150
|
return {
|
|
145
151
|
host: typeof config?.server?.host === "string" ? config.server.host : config?.server?.host === true ? "0.0.0.0" : "localhost",
|
|
@@ -166,15 +172,6 @@ function boot(options = {}) {
|
|
|
166
172
|
{
|
|
167
173
|
name: "@astroscope/boot",
|
|
168
174
|
enforce: "pre",
|
|
169
|
-
resolveId(id) {
|
|
170
|
-
if (id === VIRTUAL_MODULE_ID) return RESOLVED_VIRTUAL_MODULE_ID;
|
|
171
|
-
},
|
|
172
|
-
load(id) {
|
|
173
|
-
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
174
|
-
const { host, port } = getServerDefaults(astroConfig);
|
|
175
|
-
return `export const config = ${JSON.stringify({ host, port })};`;
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
175
|
async configureServer(server) {
|
|
179
176
|
if (isBuild) return;
|
|
180
177
|
const getBootContext = () => {
|
|
@@ -191,7 +188,7 @@ function boot(options = {}) {
|
|
|
191
188
|
const module = await server.ssrLoadModule(`/${entry}`);
|
|
192
189
|
await runStartup(module, bootContext);
|
|
193
190
|
} catch (error) {
|
|
194
|
-
logger.error(`Error running startup script: ${error}`);
|
|
191
|
+
logger.error(`Error running startup script: ${serializeError(error)}`);
|
|
195
192
|
}
|
|
196
193
|
server.httpServer?.once("close", async () => {
|
|
197
194
|
try {
|
|
@@ -199,7 +196,7 @@ function boot(options = {}) {
|
|
|
199
196
|
const module = await server.ssrLoadModule(`/${entry}`);
|
|
200
197
|
await runShutdown(module, bootContext);
|
|
201
198
|
} catch (error) {
|
|
202
|
-
logger.error(`Error running shutdown script: ${error}`);
|
|
199
|
+
logger.error(`Error running shutdown script: ${serializeError(error)}`);
|
|
203
200
|
}
|
|
204
201
|
});
|
|
205
202
|
if (hmr) {
|
|
@@ -229,10 +226,11 @@ function boot(options = {}) {
|
|
|
229
226
|
return;
|
|
230
227
|
}
|
|
231
228
|
warmupModules = collectWarmupModules(bundle);
|
|
229
|
+
const { host, port } = getServerDefaults(astroConfig);
|
|
232
230
|
const bootImport = `globalThis.__astroscope_server_url = import.meta.url;
|
|
233
231
|
import * as __astroscope_boot from './${bootChunkName}';
|
|
234
232
|
import { setup as __astroscope_bootSetup } from '@astroscope/boot/setup';
|
|
235
|
-
await __astroscope_bootSetup(__astroscope_boot);
|
|
233
|
+
await __astroscope_bootSetup(__astroscope_boot, ${JSON.stringify({ host, port })});
|
|
236
234
|
`;
|
|
237
235
|
const s = new MagicString(entryChunk.code);
|
|
238
236
|
s.prepend(bootImport);
|
package/dist/setup.cjs
CHANGED
|
@@ -23,7 +23,6 @@ __export(setup_exports, {
|
|
|
23
23
|
setup: () => setup
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(setup_exports);
|
|
26
|
-
var import_config = require("virtual:@astroscope/boot/config");
|
|
27
26
|
|
|
28
27
|
// src/events.ts
|
|
29
28
|
var STORE_KEY = /* @__PURE__ */ Symbol.for("@astroscope/boot/events");
|
|
@@ -59,11 +58,11 @@ async function runShutdown(boot, context) {
|
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
// src/setup.ts
|
|
62
|
-
async function setup(boot) {
|
|
61
|
+
async function setup(boot, config) {
|
|
63
62
|
const context = {
|
|
64
63
|
dev: false,
|
|
65
|
-
host: process.env["HOST"] ??
|
|
66
|
-
port: process.env["PORT"] ? Number(process.env["PORT"]) :
|
|
64
|
+
host: process.env["HOST"] ?? config.host,
|
|
65
|
+
port: process.env["PORT"] ? Number(process.env["PORT"]) : config.port
|
|
67
66
|
};
|
|
68
67
|
try {
|
|
69
68
|
await runStartup(boot, context);
|
package/dist/setup.d.cts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { BootModule } from './lifecycle.cjs';
|
|
2
2
|
import './types-CxpusND2.cjs';
|
|
3
3
|
|
|
4
|
-
declare function setup(boot: BootModule
|
|
4
|
+
declare function setup(boot: BootModule, config: {
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
7
|
+
}): Promise<void>;
|
|
5
8
|
|
|
6
9
|
export { setup };
|
package/dist/setup.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { BootModule } from './lifecycle.js';
|
|
2
2
|
import './types-CxpusND2.js';
|
|
3
3
|
|
|
4
|
-
declare function setup(boot: BootModule
|
|
4
|
+
declare function setup(boot: BootModule, config: {
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
7
|
+
}): Promise<void>;
|
|
5
8
|
|
|
6
9
|
export { setup };
|
package/dist/setup.js
CHANGED
|
@@ -5,8 +5,7 @@ import {
|
|
|
5
5
|
import "./chunk-I62ZQYTP.js";
|
|
6
6
|
|
|
7
7
|
// src/setup.ts
|
|
8
|
-
|
|
9
|
-
async function setup(boot) {
|
|
8
|
+
async function setup(boot, config) {
|
|
10
9
|
const context = {
|
|
11
10
|
dev: false,
|
|
12
11
|
host: process.env["HOST"] ?? config.host,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astroscope/boot",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Startup and graceful shutdown hooks for Astro SSR",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"homepage": "https://github.com/smnbbrv/astroscope/tree/main/packages/boot#readme",
|
|
51
51
|
"scripts": {
|
|
52
|
-
"build": "tsup src/index.ts src/warmup.ts src/events.ts src/lifecycle.ts src/setup.ts --format esm,cjs --dts
|
|
52
|
+
"build": "tsup src/index.ts src/warmup.ts src/events.ts src/lifecycle.ts src/setup.ts --format esm,cjs --dts",
|
|
53
53
|
"typecheck": "tsc --noEmit",
|
|
54
54
|
"lint": "eslint 'src/**/*.{ts,tsx}'",
|
|
55
55
|
"lint:fix": "eslint 'src/**/*.{ts,tsx}' --fix"
|