mono-jsx-dom 0.1.5 → 0.1.6
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/build.mjs +9 -10
- package/bin/dev.mjs +1 -0
- package/bin/init.mjs +5 -4
- package/package.json +6 -2
- package/server/node-server-hooks.mjs +17 -0
package/bin/build.mjs
CHANGED
|
@@ -56,13 +56,6 @@ async function ensureDir(path) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// bin/build.ts
|
|
59
|
-
async function run() {
|
|
60
|
-
const flags = parseFlags();
|
|
61
|
-
const start = performance.now();
|
|
62
|
-
const runtime = flags.node ?? "fetch-server";
|
|
63
|
-
await build({ serverType: runtime });
|
|
64
|
-
console.log("\x1B[32m\u2728 Build completed.\x1B[0m", "\x1B[90m(%d ms)\x1B[0m", performance.now() - start);
|
|
65
|
-
}
|
|
66
59
|
async function build(options) {
|
|
67
60
|
const workDir = join(cwd(), options?.appName ?? ".");
|
|
68
61
|
const outdir = join(workDir, options?.outdir ?? "dist");
|
|
@@ -178,6 +171,13 @@ async function build(options) {
|
|
|
178
171
|
await buildServerJS(workDir, outdir, options?.serverType, extraJS);
|
|
179
172
|
await dispose();
|
|
180
173
|
}
|
|
174
|
+
async function run() {
|
|
175
|
+
const flags = parseFlags();
|
|
176
|
+
const start = performance.now();
|
|
177
|
+
const serverType = flags.node ? "node" : "fetch-server";
|
|
178
|
+
await build({ serverType });
|
|
179
|
+
console.log("\x1B[32m\u2728 Build completed.\x1B[0m", "\x1B[90m(" + Math.ceil(performance.now() - start) + " ms)\x1B[0m");
|
|
180
|
+
}
|
|
181
181
|
async function buildServerJS(workDir, outdir, serverType = "fetch-server", extraJS, watch) {
|
|
182
182
|
const stdin2 = {
|
|
183
183
|
sourcefile: join(workDir, "server.js"),
|
|
@@ -191,7 +191,7 @@ async function buildServerJS(workDir, outdir, serverType = "fetch-server", extra
|
|
|
191
191
|
stdin2.sourcefile = join(workDir, "server-node.mjs");
|
|
192
192
|
stdin2.resolveDir = workDir;
|
|
193
193
|
stdin2.contents = [
|
|
194
|
-
'import { serve$ } from "mono-jsx-dom/
|
|
194
|
+
'import { serve as serve$ } from "mono-jsx-dom/node-fetch-server";',
|
|
195
195
|
'import server$ from "./server.' + loader + '";',
|
|
196
196
|
"serve$(server$);"
|
|
197
197
|
].join("\n");
|
|
@@ -215,7 +215,7 @@ async function buildServerJS(workDir, outdir, serverType = "fetch-server", extra
|
|
|
215
215
|
platform: "node",
|
|
216
216
|
format: "esm",
|
|
217
217
|
target: "es2024",
|
|
218
|
-
external: ["mono-jsx-dom/server", "mono-jsx-dom/
|
|
218
|
+
external: ["mono-jsx-dom/server", "mono-jsx-dom/node-fetch-server"]
|
|
219
219
|
};
|
|
220
220
|
if (extraJS) {
|
|
221
221
|
esbOptions.banner = { js: extraJS };
|
|
@@ -335,6 +335,5 @@ function isUrl(url) {
|
|
|
335
335
|
}
|
|
336
336
|
export {
|
|
337
337
|
build,
|
|
338
|
-
buildServerJS,
|
|
339
338
|
run
|
|
340
339
|
};
|
package/bin/dev.mjs
CHANGED
|
@@ -167,6 +167,7 @@ async function dev(options) {
|
|
|
167
167
|
const serverScript = await resolveModule(join(workDir, "server"), [".ts", ".mjs", ".js"]) ?? join(workDir, "node_modules/mono-jsx-dom/server/index.mjs");
|
|
168
168
|
const args = ["--watch", serverScript];
|
|
169
169
|
if (runtime === "node") {
|
|
170
|
+
args.unshift("--import", "mono-jsx-dom/node-server-hooks");
|
|
170
171
|
args.push("--port", port.toString());
|
|
171
172
|
} else {
|
|
172
173
|
args.unshift("--port", port.toString());
|
package/bin/init.mjs
CHANGED
|
@@ -166,6 +166,7 @@ var template = {
|
|
|
166
166
|
name: "mono-app",
|
|
167
167
|
version: "0.0.0",
|
|
168
168
|
private: true,
|
|
169
|
+
type: "module",
|
|
169
170
|
scripts: {
|
|
170
171
|
dev: (bun ? "bun --bun " : "") + "mono-jsx-dom dev",
|
|
171
172
|
build: (bun ? "bun --bun " : "") + "mono-jsx-dom build",
|
|
@@ -246,12 +247,12 @@ async function run() {
|
|
|
246
247
|
console.log("You can now start or build the app with the following commands:");
|
|
247
248
|
console.log("");
|
|
248
249
|
console.log(`cd ${appName}`);
|
|
249
|
-
console.log(`${npmCmd} dev
|
|
250
|
+
console.log(`${npmCmd} run dev \x1B[90m# start the app in development mode.\x1B[0m`);
|
|
250
251
|
if (wrangler) {
|
|
251
|
-
console.log(`${npmCmd}
|
|
252
|
+
console.log(`${npmCmd} run deploy \x1B[90m# deploy the app to Cloudflare Workers.\x1B[0m`);
|
|
252
253
|
} else {
|
|
253
|
-
console.log(`${npmCmd}
|
|
254
|
-
console.log(`${npmCmd} start
|
|
254
|
+
console.log(`${npmCmd} run build \x1B[90m# build the app for production.\x1B[0m`);
|
|
255
|
+
console.log(`${npmCmd} run start \x1B[90m# build and start the app in production mode.\x1B[0m`);
|
|
255
256
|
}
|
|
256
257
|
console.log("");
|
|
257
258
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mono-jsx-dom",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "A JSX runtime for browsers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jsx",
|
|
@@ -35,9 +35,13 @@
|
|
|
35
35
|
"node": "./server/index.mjs",
|
|
36
36
|
"import": "./server/index.mjs"
|
|
37
37
|
},
|
|
38
|
-
"./
|
|
38
|
+
"./node-fetch-server": {
|
|
39
39
|
"node": "./server/node-fetch-server.mjs",
|
|
40
40
|
"import": "./server/node-fetch-server.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./node-server-hooks": {
|
|
43
|
+
"node": "./server/node-server-hooks.mjs",
|
|
44
|
+
"import": "./server/node-server-hooks.mjs"
|
|
41
45
|
}
|
|
42
46
|
},
|
|
43
47
|
"scripts": {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// server/node-server-hooks.ts
|
|
2
|
+
import { argv } from "node:process";
|
|
3
|
+
import { registerHooks } from "node:module";
|
|
4
|
+
var serverHook = `
|
|
5
|
+
import { serve as serve$ } from "mono-jsx-dom/node-fetch-server";
|
|
6
|
+
import(import.meta.url).then(m => serve$(m.default));
|
|
7
|
+
`;
|
|
8
|
+
registerHooks({
|
|
9
|
+
load(url, context, nextLoad) {
|
|
10
|
+
const result = nextLoad(url, context);
|
|
11
|
+
if (result.source && "file://" + argv[1] === url) {
|
|
12
|
+
const source = typeof result.source === "string" ? result.source : new TextDecoder().decode(result.source);
|
|
13
|
+
return { ...result, source: source + serverHook };
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
});
|