weifuwu 0.19.7 → 0.19.8
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/cli/template/ui/components/Greeting.tsx +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +47 -20
- package/dist/react.js +1 -1
- package/dist/ssr-entries.d.ts +4 -0
- package/package.json +3 -1
package/dist/index.d.ts
CHANGED
|
@@ -73,3 +73,5 @@ export { layout } from './layout.ts';
|
|
|
73
73
|
export { notFound } from './not-found.ts';
|
|
74
74
|
export { errorBoundary } from './error-boundary.ts';
|
|
75
75
|
export { clearCompileCache } from './compile.ts';
|
|
76
|
+
export { ssrEntries } from './ssr-entries.ts';
|
|
77
|
+
export type { SsrEntry } from './ssr-entries.ts';
|
package/dist/index.js
CHANGED
|
@@ -5192,7 +5192,7 @@ async function compileHotComponent(path2) {
|
|
|
5192
5192
|
});
|
|
5193
5193
|
let code = new TextDecoder().decode(result.outputFiles[0].contents);
|
|
5194
5194
|
if (code.includes("__require") && (code.includes('"react"') || code.includes("'react'"))) {
|
|
5195
|
-
code = `import __r from '
|
|
5195
|
+
code = `import * as __r from 'react';
|
|
5196
5196
|
` + code.replace(/__require\(["']react["']\)/g, "__r");
|
|
5197
5197
|
}
|
|
5198
5198
|
return { hash: h, code };
|
|
@@ -5233,8 +5233,8 @@ function buildHeadPayload(opts) {
|
|
|
5233
5233
|
`;
|
|
5234
5234
|
}
|
|
5235
5235
|
if (compiledTailwindCss) {
|
|
5236
|
-
const cssUrl = ctx.tailwindCssUrl
|
|
5237
|
-
result += `<link rel="stylesheet" href="${cssUrl}" />
|
|
5236
|
+
const cssUrl = ctx.tailwindCssUrl;
|
|
5237
|
+
if (cssUrl) result += `<link rel="stylesheet" href="${cssUrl}" />
|
|
5238
5238
|
`;
|
|
5239
5239
|
}
|
|
5240
5240
|
const localeData = ctx.parsed?.__localeData ?? globalThis.__LOCALE_DATA__;
|
|
@@ -5337,6 +5337,9 @@ function streamResponse(reactStream, opts) {
|
|
|
5337
5337
|
});
|
|
5338
5338
|
}
|
|
5339
5339
|
|
|
5340
|
+
// ssr-entries.ts
|
|
5341
|
+
var ssrEntries = /* @__PURE__ */ new Map();
|
|
5342
|
+
|
|
5340
5343
|
// ssr.ts
|
|
5341
5344
|
var als = new AsyncLocalStorage();
|
|
5342
5345
|
__registerAls(() => als.getStore());
|
|
@@ -5413,7 +5416,9 @@ async function buildClientBundle(entryPath, layoutPaths) {
|
|
|
5413
5416
|
}
|
|
5414
5417
|
}
|
|
5415
5418
|
function ssr(path2) {
|
|
5416
|
-
const
|
|
5419
|
+
const absPath = resolve4(path2);
|
|
5420
|
+
const entryId = id2(absPath);
|
|
5421
|
+
ssrEntries.set(entryId, { path: absPath });
|
|
5417
5422
|
const bundleKey = `/__ssr/${entryId}.js`;
|
|
5418
5423
|
const r = new Router();
|
|
5419
5424
|
r.get("/__ssr/:path", (req, ctx) => {
|
|
@@ -5562,7 +5567,7 @@ ${src}`;
|
|
|
5562
5567
|
// live.ts
|
|
5563
5568
|
import chokidar from "chokidar";
|
|
5564
5569
|
import { existsSync as existsSync4 } from "node:fs";
|
|
5565
|
-
import { join as join4, resolve as resolve6 } from "node:path";
|
|
5570
|
+
import { dirname as dirname3, join as join4, resolve as resolve6 } from "node:path";
|
|
5566
5571
|
var clients = /* @__PURE__ */ new Set();
|
|
5567
5572
|
var hotBundleCache = /* @__PURE__ */ new Map();
|
|
5568
5573
|
var hotKeys = [];
|
|
@@ -5625,6 +5630,24 @@ function liveReload(dir) {
|
|
|
5625
5630
|
ignored: /(^|[/\\])\.|node_modules|[/\\]\.weifuwu[/\\]/,
|
|
5626
5631
|
ignoreInitial: true
|
|
5627
5632
|
});
|
|
5633
|
+
function findEntries(changedPath) {
|
|
5634
|
+
const matched = [];
|
|
5635
|
+
for (const [, entry] of ssrEntries) {
|
|
5636
|
+
if (!entry.path.startsWith(resolved)) continue;
|
|
5637
|
+
if (entry.path === changedPath) {
|
|
5638
|
+
matched.push(entry.path);
|
|
5639
|
+
} else {
|
|
5640
|
+
const ed = dirname3(entry.path);
|
|
5641
|
+
if (changedPath.startsWith(ed)) matched.push(entry.path);
|
|
5642
|
+
}
|
|
5643
|
+
}
|
|
5644
|
+
if (matched.length === 0) {
|
|
5645
|
+
for (const [, entry] of ssrEntries) {
|
|
5646
|
+
if (entry.path.startsWith(resolved)) matched.push(entry.path);
|
|
5647
|
+
}
|
|
5648
|
+
}
|
|
5649
|
+
return matched;
|
|
5650
|
+
}
|
|
5628
5651
|
watcher.on("change", async (filePath) => {
|
|
5629
5652
|
if (/\.tsx?$/i.test(filePath)) {
|
|
5630
5653
|
if (filePath.endsWith("layout.tsx")) {
|
|
@@ -5632,25 +5655,28 @@ function liveReload(dir) {
|
|
|
5632
5655
|
}
|
|
5633
5656
|
clearCompileCache();
|
|
5634
5657
|
markClientBundleDirty();
|
|
5658
|
+
const targets = existsSync4(entryPath) ? [entryPath] : findEntries(resolve6(filePath));
|
|
5659
|
+
if (targets.length === 0) return broadcastReload();
|
|
5635
5660
|
try {
|
|
5636
|
-
const target = existsSync4(entryPath) ? entryPath : filePath;
|
|
5637
|
-
await compileTsxDev(target);
|
|
5638
|
-
const { hash, code } = await compileHotComponent(target);
|
|
5639
|
-
setHot(hash, code);
|
|
5640
5661
|
let css;
|
|
5641
5662
|
const cssPath = join4(resolved, "app.css");
|
|
5642
5663
|
if (existsSync4(cssPath)) {
|
|
5643
5664
|
css = await compileTailwindCss(cssPath, resolved);
|
|
5644
5665
|
}
|
|
5645
|
-
const
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5666
|
+
for (const target of targets) {
|
|
5667
|
+
await compileTsxDev(target);
|
|
5668
|
+
const { hash, code } = await compileHotComponent(target);
|
|
5669
|
+
setHot(hash, code);
|
|
5670
|
+
const entry = id(target);
|
|
5671
|
+
const msg = { type: "component", hash, entry };
|
|
5672
|
+
if (css) msg.css = css;
|
|
5673
|
+
const str = JSON.stringify(msg);
|
|
5674
|
+
for (const ws of clients) {
|
|
5675
|
+
try {
|
|
5676
|
+
ws.send(str);
|
|
5677
|
+
} catch {
|
|
5678
|
+
clients.delete(ws);
|
|
5679
|
+
}
|
|
5654
5680
|
}
|
|
5655
5681
|
}
|
|
5656
5682
|
} catch (e) {
|
|
@@ -5993,7 +6019,7 @@ function createReadTool(ctx) {
|
|
|
5993
6019
|
import { tool as tool5 } from "ai";
|
|
5994
6020
|
import { z as z7 } from "zod";
|
|
5995
6021
|
import { writeFileSync as writeFileSync2, mkdirSync as mkdirSync3 } from "node:fs";
|
|
5996
|
-
import { resolve as resolve9, dirname as
|
|
6022
|
+
import { resolve as resolve9, dirname as dirname4 } from "node:path";
|
|
5997
6023
|
function createWriteTool(ctx) {
|
|
5998
6024
|
return tool5({
|
|
5999
6025
|
description: "Create or overwrite a file. Parent directories are created automatically.",
|
|
@@ -6006,7 +6032,7 @@ function createWriteTool(ctx) {
|
|
|
6006
6032
|
if (!isPathAllowed(resolved, ctx.workspace, ctx.permissions)) {
|
|
6007
6033
|
return { error: "Path not allowed" };
|
|
6008
6034
|
}
|
|
6009
|
-
mkdirSync3(
|
|
6035
|
+
mkdirSync3(dirname4(resolved), { recursive: true });
|
|
6010
6036
|
writeFileSync2(resolved, content, "utf-8");
|
|
6011
6037
|
return { path: path2, size: content.length };
|
|
6012
6038
|
}
|
|
@@ -8498,6 +8524,7 @@ export {
|
|
|
8498
8524
|
setCookie,
|
|
8499
8525
|
smoothStream,
|
|
8500
8526
|
ssr,
|
|
8527
|
+
ssrEntries,
|
|
8501
8528
|
streamObject,
|
|
8502
8529
|
streamText,
|
|
8503
8530
|
tenant,
|
package/dist/react.js
CHANGED
|
@@ -192,7 +192,7 @@ async function navigate(href) {
|
|
|
192
192
|
location.href = href;
|
|
193
193
|
return;
|
|
194
194
|
}
|
|
195
|
-
const bundleMatch = html.match(/src="(\/
|
|
195
|
+
const bundleMatch = html.match(/src="(\/__ssr\/[^"]+\.js)"/);
|
|
196
196
|
const bundleUrl = bundleMatch ? bundleMatch[1] : null;
|
|
197
197
|
applyHead(html);
|
|
198
198
|
const currentRoot = document.getElementById("__weifuwu_root");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weifuwu",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.8",
|
|
4
4
|
"description": "Web-standard HTTP framework for Node.js — (req, ctx) => Response",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
"LICENSE"
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
|
+
"dev": "node --watch ./cli/template/index.ts",
|
|
24
|
+
"start": "NODE_ENV=production node ./cli/template/index.ts",
|
|
23
25
|
"build": "esbuild index.ts --bundle --format=esm --platform=node --outfile=dist/index.js --packages=external && esbuild cli.ts --bundle --format=esm --platform=node --outfile=dist/cli.js --packages=external && esbuild react.ts --bundle --format=esm --outfile=dist/react.js --external:react --external:react-dom",
|
|
24
26
|
"prepublishOnly": "npm run build && tsc --emitDeclarationOnly --outdir dist",
|
|
25
27
|
"test": "node --test 'test/**/*.test.ts'"
|