wirejs-scripts 3.0.182 → 3.0.184
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/bin.js +95 -33
- package/package.json +3 -3
package/bin.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import process from 'process';
|
|
4
4
|
import { execSync, spawn } from 'child_process';
|
|
5
5
|
import fs from 'fs';
|
|
6
|
+
import { builtinModules } from 'module';
|
|
6
7
|
import os from 'os';
|
|
7
8
|
import path from 'path';
|
|
8
9
|
import { fileURLToPath } from 'url';
|
|
@@ -32,6 +33,14 @@ let networkIp = null;
|
|
|
32
33
|
let httpPort = 3000;
|
|
33
34
|
let wsPort = 3001;
|
|
34
35
|
|
|
36
|
+
const NODE_BUILTIN_EXTERNALS = Array.from(new Set(
|
|
37
|
+
builtinModules.flatMap(moduleName => {
|
|
38
|
+
if (moduleName.startsWith('_')) return [];
|
|
39
|
+
const bareName = moduleName.startsWith('node:') ? moduleName.slice(5) : moduleName;
|
|
40
|
+
return [bareName, `node:${bareName}`];
|
|
41
|
+
})
|
|
42
|
+
));
|
|
43
|
+
|
|
35
44
|
/** Tracks active node-cron tasks for CronJobs, keyed by absoluteId. */
|
|
36
45
|
const activeCronTasks = new Map();
|
|
37
46
|
|
|
@@ -50,6 +59,53 @@ const logger = {
|
|
|
50
59
|
}
|
|
51
60
|
};
|
|
52
61
|
|
|
62
|
+
function normalizeExternalList(value) {
|
|
63
|
+
if (!value) return [];
|
|
64
|
+
if (typeof value === 'string') return [value];
|
|
65
|
+
if (Array.isArray(value)) return value.filter(item => typeof item === 'string');
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let deploymentConfigPromise;
|
|
70
|
+
|
|
71
|
+
async function loadDeploymentConfig() {
|
|
72
|
+
if (deploymentConfigPromise) return deploymentConfigPromise;
|
|
73
|
+
|
|
74
|
+
deploymentConfigPromise = (async () => {
|
|
75
|
+
const configPath = path.join(CWD, 'deployment-config.ts');
|
|
76
|
+
if (!fs.existsSync(configPath)) return {};
|
|
77
|
+
|
|
78
|
+
const result = await esbuild.build({
|
|
79
|
+
entryPoints: [configPath],
|
|
80
|
+
bundle: true,
|
|
81
|
+
platform: 'node',
|
|
82
|
+
format: 'esm',
|
|
83
|
+
write: false,
|
|
84
|
+
logLevel: 'silent',
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const outputFile = result.outputFiles?.[0];
|
|
88
|
+
if (!outputFile) return {};
|
|
89
|
+
|
|
90
|
+
const compiledConfigPath = path.join(CWD, 'pre-dist', `.wirejs-deployment-config-${Date.now()}.mjs`);
|
|
91
|
+
await fs.promises.mkdir(path.dirname(compiledConfigPath), { recursive: true });
|
|
92
|
+
await fs.promises.writeFile(compiledConfigPath, outputFile.text, 'utf8');
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
return (await import(`${compiledConfigPath}?t=${Date.now()}`)).default ?? {};
|
|
96
|
+
} finally {
|
|
97
|
+
await fs.promises.rm(compiledConfigPath, { force: true });
|
|
98
|
+
}
|
|
99
|
+
})();
|
|
100
|
+
|
|
101
|
+
return deploymentConfigPromise;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function resolveSsgExternals() {
|
|
105
|
+
const config = await loadDeploymentConfig();
|
|
106
|
+
return normalizeExternalList(config?.ssgExternalModules);
|
|
107
|
+
}
|
|
108
|
+
|
|
53
109
|
const oldFetch = globalThis.fetch;
|
|
54
110
|
globalThis.fetch = (url, ...args) => {
|
|
55
111
|
if (typeof url === 'string') {
|
|
@@ -272,51 +328,57 @@ async function compile(watch = false) {
|
|
|
272
328
|
if (ssgFiles.length === 0) return;
|
|
273
329
|
|
|
274
330
|
const preSsgDir = path.join(CWD, 'pre-dist', 'ssg');
|
|
331
|
+
const preDist = path.join(CWD, 'pre-dist');
|
|
332
|
+
const configuredSsgExternals = await resolveSsgExternals();
|
|
275
333
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
platform: 'node',
|
|
283
|
-
format: 'esm',
|
|
284
|
-
conditions: ['wirejs:client'],
|
|
285
|
-
});
|
|
334
|
+
for (const ssgFile of ssgFiles) {
|
|
335
|
+
const external = configuredSsgExternals;
|
|
336
|
+
const browserExternal = Array.from(new Set([
|
|
337
|
+
...NODE_BUILTIN_EXTERNALS,
|
|
338
|
+
...configuredSsgExternals,
|
|
339
|
+
]));
|
|
286
340
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
});
|
|
341
|
+
// 1. Build server-side bundles (ESM, for ssg.js import()) into pre-dist/ssg/
|
|
342
|
+
await esbuild.build({
|
|
343
|
+
entryPoints: [ssgFile],
|
|
344
|
+
outdir: preSsgDir,
|
|
345
|
+
outbase: ssgDir,
|
|
346
|
+
bundle: true,
|
|
347
|
+
platform: 'node',
|
|
348
|
+
format: 'esm',
|
|
349
|
+
conditions: ['wirejs:client'],
|
|
350
|
+
external,
|
|
351
|
+
});
|
|
299
352
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
353
|
+
// 2. Build browser-side bundles (IIFE, for client hydration) into dist/
|
|
354
|
+
// These are referenced by <script src="..."> tags injected by ssg.js.
|
|
355
|
+
await esbuild.build({
|
|
356
|
+
entryPoints: [ssgFile],
|
|
357
|
+
outdir: distDir,
|
|
358
|
+
outbase: ssgDir,
|
|
359
|
+
bundle: true,
|
|
360
|
+
platform: 'browser',
|
|
361
|
+
format: 'iife',
|
|
362
|
+
conditions: ['wirejs:client'],
|
|
363
|
+
external: browserExternal,
|
|
364
|
+
sourcemap: true,
|
|
365
|
+
});
|
|
307
366
|
|
|
308
|
-
|
|
367
|
+
// 3. Run ssg.js on each server-side bundle to produce HTML.
|
|
368
|
+
// Pass CWD/pre-dist as SRC_DIR so ssg.js strips the correct prefix
|
|
369
|
+
// when building the hydration <script src="..."> path (e.g. /index.js).
|
|
370
|
+
const compiledSsgFile = path.join(preSsgDir, path.relative(ssgDir, ssgFile)).replace(/\.[^.]+$/, '.js');
|
|
309
371
|
try {
|
|
310
372
|
const html = execSync(
|
|
311
|
-
`node ${path.join(__dirname, 'ssg.js')} ${preDist} ${
|
|
373
|
+
`node ${path.join(__dirname, 'ssg.js')} ${preDist} ${compiledSsgFile}`,
|
|
312
374
|
{ stdio: ['pipe', 'pipe', 'pipe'] }
|
|
313
375
|
).toString();
|
|
314
|
-
const relative = path.relative(preSsgDir,
|
|
376
|
+
const relative = path.relative(preSsgDir, compiledSsgFile).replace(/\.js$/, '.html');
|
|
315
377
|
const htmlOut = path.join(distDir, relative);
|
|
316
378
|
await fs.promises.mkdir(path.dirname(htmlOut), { recursive: true });
|
|
317
379
|
await fs.promises.writeFile(htmlOut, html);
|
|
318
380
|
} catch (err) {
|
|
319
|
-
logger.error(`Could not generate SSG page ${
|
|
381
|
+
logger.error(`Could not generate SSG page ${compiledSsgFile}`, err);
|
|
320
382
|
}
|
|
321
383
|
}
|
|
322
384
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wirejs-scripts",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.184",
|
|
4
4
|
"description": "Basic build and start commands for wirejs apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"node-cron": "^4.2.1",
|
|
29
29
|
"rimraf": "^6.0.1",
|
|
30
30
|
"wirejs-dom": "^1.0.44",
|
|
31
|
-
"wirejs-hosting": "^0.1.
|
|
32
|
-
"wirejs-resources": "^0.1.
|
|
31
|
+
"wirejs-hosting": "^0.1.186",
|
|
32
|
+
"wirejs-resources": "^0.1.186"
|
|
33
33
|
}
|
|
34
34
|
}
|