@resolid/dev 0.4.0 → 0.5.0
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/http.d.mts +2 -4
- package/dist/http.mjs +1 -1
- package/dist/index.mjs +2 -2
- package/dist/router.d.mts +22 -2
- package/dist/router.mjs +1 -1
- package/package.json +17 -11
package/dist/http.d.mts
CHANGED
|
@@ -5,8 +5,6 @@ import { RequestIdVariables } from "hono/request-id";
|
|
|
5
5
|
import { Context as Context$1 } from "@netlify/types";
|
|
6
6
|
import { HonoOptions } from "hono/hono-base";
|
|
7
7
|
import { BlankEnv } from "hono/types";
|
|
8
|
-
import { IncomingMessage, ServerResponse } from "http";
|
|
9
|
-
import { Http2ServerRequest, Http2ServerResponse } from "http2";
|
|
10
8
|
import { AddressInfo } from "node:net";
|
|
11
9
|
|
|
12
10
|
//#region src/http/utils/response.d.ts
|
|
@@ -71,8 +69,8 @@ declare function netlifyRequestOriginGetter(): RequestOriginGetter;
|
|
|
71
69
|
//#endregion
|
|
72
70
|
//#region src/http/platforms/vercel.d.ts
|
|
73
71
|
type HonoVercelServerOptions = HonoServerOptions<NodeEnv>;
|
|
74
|
-
type HonoVercelServer =
|
|
75
|
-
declare
|
|
72
|
+
type HonoVercelServer = Hono$1<NodeEnv>;
|
|
73
|
+
declare function createHonoVercelServer(options?: HonoVercelServerOptions): Promise<HonoVercelServer>;
|
|
76
74
|
declare function vercelClientIpGetter(): ClientIpGetter;
|
|
77
75
|
declare function vercelRequestIdGenerator(): RequestIdGenerator;
|
|
78
76
|
declare function vercelRequestOriginGetter(): RequestOriginGetter;
|
package/dist/http.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{RouterContextProvider as e,createRequestHandler as t,data as n}from"react-router";import{handle as r}from"hono/netlify";import{env as i}from"node:process";import{Hono as a}from"hono";import*as o from"virtual:react-router/server-build";import{
|
|
1
|
+
import{RouterContextProvider as e,createRequestHandler as t,data as n}from"react-router";import{handle as r}from"hono/netlify";import{env as i}from"node:process";import{Hono as a}from"hono";import*as o from"virtual:react-router/server-build";import{serve as s}from"@hono/node-server";import{serveStatic as c}from"@hono/node-server/serve-static";import{logger as l}from"hono/logger";import{networkInterfaces as u}from"node:os";import{requestId as d}from"hono/request-id";import{randomBytes as f}from"node:crypto";function p(e){return n({errors:e},422)}function m(e=`页面未找到`){throw new Response(e,{status:404})}function h(e,t=null,n=302){let r=new Headers;throw r.set(`Location`,e),t&&r.set(`Set-Cookie`,t),new Response(null,{status:n,headers:r})}async function g(n,r){let i=import.meta.env.RESOLID_BASENAME,s=new a(r.honoOptions);r.configure&&await r.configure(s);let c=new a({strict:!1});return c.use(async i=>(async i=>{let a=t(o,n),s=r.getLoadContext?.(i,{build:o,mode:n}),c=(s instanceof Promise?await s:s)??new e;return Object.assign(c,{hono:i}),a(i.req.raw,c)})(i)),s.route(i,c),i&&s.route(`${i}.data`,c),s}async function _(e={}){return r(await g(i.NODE_ENV==`test`?`development`:i.NODE_ENV,{...e}))}function v(){return e=>e.env.context.ip}function y(){return e=>e.env.context.requestId}function b(){return e=>e.env.context.site.url}async function x(e={}){return await g(i.NODE_ENV==`test`?`development`:i.NODE_ENV,{...e})}function S(){return e=>e.req.raw.headers.get(`x-real-ip`)??``}function C(){return e=>e.req.raw.headers.get(`x-vercel-id`)??``}function w(){return()=>`https://${i.VERCEL_PROJECT_PRODUCTION_URL}`}function T(e,t,n){let{proxy:r=!1,proxyCount:i=0,ipHeaders:a=`x-forwarded-for`}=n??{},o=e.headers.get(a),s=r&&o?o.split(/\s*,\s*/):[];return i>0&&(s=s.slice(-i)),s[0]??t.remoteAddress??``}function E(e,t,n=!1){return`${t.encrypted?`https`:(n?e.headers.get(`x-forwarded-proto`):null)?.split(/\s*,\s*/)[0]??`http`}://${(n?e.headers.get(`x-forwarded-host`):null)?.split(/\s*,\s*/)[0]??e.headers.get(`host`)}`}async function D(e={}){let t=i.NODE_ENV==`test`?`development`:i.NODE_ENV,n=t==`production`,r=import.meta.env.RESOLID_BASENAME,a={port:e.port??3e3,listeningListener:e=>{console.log(`🚀 Server started on port ${e.port}`);let t=Object.values(u()).flat().find(e=>String(e?.family).includes(`4`)&&!e?.internal)?.address;console.log(`[resolid] http://localhost:${e.port}${r}${i.SERVER_PATH??``}${t&&` (http://${t}:${e.port})`}`)},...e,defaultLogger:e.defaultLogger??!n},o=null,d=await g(t,{configure:async e=>{if(n){let t=`${import.meta.env.RESOLID_BUILD_DIR}/client`;e.use(`/${import.meta.env.RESOLID_ASSETS_DIR}/*`,O(3600*24*365,!0),c({root:t})),e.use(`*`,O(3600),c({root:t}))}else e.use(`*`,O(3600),c({root:`./public`}));a.defaultLogger&&e.use(`*`,l()),await a.configure?.(e)},honoOptions:a.honoOptions,getLoadContext:a.getLoadContext});n&&(o=s({fetch:d.fetch,port:a.port},a.listeningListener));async function f(){o?.close(),await a.onShutdown?.(),process.removeListener(`SIGINT`,f),process.removeListener(`SIGTERM`,f),console.log(`[resolid] Node server shutdown.`),process.exit(0)}return process.on(`SIGTERM`,f),process.on(`SIGINT`,f),import.meta.hot&&(process.removeListener(`SIGINT`,f),process.removeListener(`SIGTERM`,f)),d}function O(e,t=!1){return async(n,r)=>{if(!n.req.path.match(/\.[a-zA-Z0-9]+$/)||n.req.path.endsWith(`.data`))return r();await r(),n.res.ok&&n.header(`Cache-Control`,`public, max-age=${e}${t?`, immutable`:``}`)}}function k(e={}){return t=>T(t.req.raw,t.env.incoming.socket,e)}function A(e=!1){return t=>E(t.req.raw,t.env.incoming.socket,e)}function j(e=()=>f(16).toString(`hex`)){return d({generator:e})}function M(e){return async(t,n)=>{t.set(`requestOrigin`,e(t)),await n()}}function N(e){return async(t,n)=>{t.set(`clientIp`,e(t)),await n()}}export{O as cacheControl,N as clientIp,_ as createHonoNetlifyServer,D as createHonoNodeServer,x as createHonoVercelServer,m as httpNotFound,p as httpProblem,h as httpRedirect,v as netlifyClientIpGetter,y as netlifyRequestIdGenerator,b as netlifyRequestOriginGetter,k as nodeClientIpGetter,A as nodeRequestOriginGetter,j as requestId,M as requestOrigin,S as vercelClientIpGetter,C as vercelRequestIdGenerator,w as vercelRequestOriginGetter};
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{cp as e,mkdir as t,readFile as n,readdir as r,realpath as i,rm as a,stat as o,symlink as s,writeFile as c}from"node:fs/promises";import{basename as l,dirname as u,join as d,relative as f}from"node:path";import p from"fast-glob";import{existsSync as m}from"node:fs";import{build as h}from"rolldown";import{esmExternalRequirePlugin as g}from"rolldown/plugins";import{searchForWorkspaceRoot as _}from"vite";var v=`@resolid/dev`,y=`0.
|
|
1
|
+
import{cp as e,mkdir as t,readFile as n,readdir as r,realpath as i,rm as a,stat as o,symlink as s,writeFile as c}from"node:fs/promises";import{basename as l,dirname as u,join as d,relative as f}from"node:path";import p from"fast-glob";import{existsSync as m}from"node:fs";import{build as h}from"rolldown";import{esmExternalRequirePlugin as g}from"rolldown/plugins";import{searchForWorkspaceRoot as _}from"vite";var v=`@resolid/dev`,y=`0.5.0`;async function b({includeFiles:t=[],nodeVersion:r,buildManifest:i,reactRouterConfig:o,viteConfig:s,buildStart:c,buildBundleEnd:l}){let m=s.root,{assetsDir:_}=s.build,v=JSON.parse(await n(d(m,`package.json`),`utf8`)),y=x(v.dependencies??{},s.ssr.external),b=d(o.buildDirectory,`server`),C=i?.serverBundles??{site:{id:`site`,file:f(m,d(b,o.serverBuildFile))}},w=t.length>0?await p(t,{cwd:m}):[],T=await c();await Promise.all(Object.entries(C).map(async([,t])=>{let n=t.id,i=d(m,t.file),o=u(i);await S(d(o,`package.json`),v,y,r),console.log(`Bundle file for ${n}...`);let s=d(o,`server.mjs`);await h({input:i,output:{file:s,codeSplitting:!1,minify:`dce-only`,comments:{legal:!1}},platform:`node`,transform:{define:{"process.env.NODE_ENV":JSON.stringify(`production`),"import.meta.env.NODE_ENV":JSON.stringify(`production`)},target:`node${r}`},external:[`vite`,...Object.keys(y)],plugins:[g({external:[`vite`,...Object.keys(y)],skipDuplicateCheck:!0})]}),await a(d(o,_),{force:!0,recursive:!0}),await a(i,{force:!0}),await Promise.all(w.map(t=>e(t,d(b,t),{recursive:!0}))),await l?.(T,o,n,s,y)}))}function x(e,t){let n=Array.isArray(t)?t.filter(e=>![`react-router`,`react-router-dom`,`@react-router/architect`,`@react-router/cloudflare`,`@react-router/dev`,`@react-router/express`,`@react-router/node`,`@react-router/serve`].includes(e)):t;return Object.keys(e).filter(e=>n===void 0?!1:n===!0?!0:n.includes(e)).reduce((t,n)=>(t[n]=e[n]??``,t),{})}async function S(e,t,n,r){let i={name:t.name,type:t.type,version:t.version,scripts:{postinstall:t.scripts?.postinstall??``},dependencies:n,engines:{node:`${r}.x`}};await c(e,JSON.stringify(i,null,2),`utf8`)}async function C(e,n=!1){let r=d(...e);return n&&await a(r,{recursive:!0,force:!0}),await t(r,{recursive:!0}),r}function w(e){if(e?.routeIdToServerBundleId){let t=Object.values(e.routes).filter(e=>e.id!=`root`).map(t=>{let n=[...T(e.routes,t.parentId),t.path].join(`/`);return{id:t.id,path:`/${n}`}}),n={};for(let[r,i]of Object.entries(e.routeIdToServerBundleId)){n[i]??=[];for(let e of t)e.id==r&&n[i].push(e.path)}let r={};for(let[e,t]of Object.entries(n)){t.sort((e,t)=>e.length<t.length?-1:1);for(let n of t)!r[n]&&!Object.keys(r).find(t=>r[t].bundleId==e&&n.startsWith(r[t].path))&&(r[n]={path:n,bundleId:e})}let i=Object.values(r).map(e=>({path:e.path.endsWith(`/`)?e.path.slice(0,-1):e.path,bundleId:e.bundleId}));return i.sort((e,t)=>e.path.length>t.path.length?-1:1),i}return[{path:``,bundleId:`site`}]}function T(e,t){if(t==null)return[];let n=[],r=t=>{let i=e[t];i.parentId&&r(i.parentId),i.path&&n.push(i.path)};return r(t),n}async function E(n,a,c){let p=_(n),{nodeFileTrace:h}=await import(`@vercel/nft`),g=await h([n],{base:p,cache:c}),v=Array.from(g.fileList).map(e=>d(p,e)),y=u(v[0]);for(let e of v.slice(1))for(;!e.startsWith(y);)y=u(y);return await Promise.all(v.map(async c=>{let p=d(a,f(y,c)),h=await i(c),g=h!==c,_=(await o(c)).isDirectory();if(await t(u(p),{recursive:!0}),c==n){let t=u(n),i=u(p);await Promise.all((await r(t)).filter(e=>e!==l(n)).map(n=>e(d(t,n),d(i,n),{recursive:!0})))}g?m(p)||await s(f(u(p),d(a,f(y,h))),p,_?`dir`:`file`):_||await e(c,p)})),f(y,n)}function D({nodeVersion:e,includeFiles:t}){return{name:`@resolid/react-router-hono-netlify-preset`,reactRouterConfig(){return{async buildEnd({buildManifest:n,reactRouterConfig:r,viteConfig:i}){await b({includeFiles:t,nodeVersion:e,buildManifest:n,reactRouterConfig:r,viteConfig:i,async buildStart(){let e=await C([i.root,`.netlify`,`v1`],!0);return await O(i.build.assetsDir,d(e,`config.json`)),{netlifyRoot:e,netlifyFunctionDir:await C([e,`functions`]),serverRoutes:w(n),nftCache:{}}},async buildBundleEnd(t,n,r,i){console.log(`Coping Netlify function files for ${r}...`);let a=await E(i,await C([t.netlifyFunctionDir,r],!0),t.nftCache),o=t.serverRoutes.find(e=>e.bundleId==r)?.path,s=o?[o,`${o}/*`]:`/*`;await c(d(t.netlifyFunctionDir,`${r}.mjs`),`export { default } from "./${d(r,a)}";
|
|
2
2
|
|
|
3
3
|
export const config = {
|
|
4
4
|
path: ${Array.isArray(s)?JSON.stringify(s):`"${s}"`},
|
|
@@ -7,4 +7,4 @@ export const config = {
|
|
|
7
7
|
preferStatic: true,
|
|
8
8
|
nodeVersion: ${e}
|
|
9
9
|
};
|
|
10
|
-
`,`utf8`)}})}}
|
|
10
|
+
`,`utf8`)}})}}}}}async function O(e,t){console.log(`Writing Netlify config file...`);let n={headers:[]};n.headers.push({for:`^/${e}/.*`,values:{"Cache-Control":`public, max-age=31536000, immutable`}}),await c(t,JSON.stringify(n,null,2),`utf8`)}function k({nodeVersion:e,includeFiles:t}){return{name:`@resolid/react-router-hono-node-preset`,reactRouterConfig(){return{async buildEnd({buildManifest:n,reactRouterConfig:r,viteConfig:i}){await b({includeFiles:t,nodeVersion:e,buildManifest:n,reactRouterConfig:r,viteConfig:i,buildStart(){console.log(`Bundle Node Server for production...`)}})}}}}}function A({nodeVersion:e,includeFiles:t}){return{name:`@resolid/react-router-hono-vercel-preset`,reactRouterConfig(){return{buildEnd:async({buildManifest:n,reactRouterConfig:r,viteConfig:i})=>{await b({includeFiles:t,nodeVersion:e,buildManifest:n,reactRouterConfig:r,viteConfig:i,async buildStart(){let e=await C([i.root,`.vercel`,`output`],!0);return await j(d(r.buildDirectory,`client`),e),await M(i.build.assetsDir,n,d(e,`config.json`)),{vercelOutput:e,nftCache:{}}},async buildBundleEnd(t,n,r,i){console.log(`Coping Vercel function files for ${r}...`);let a=await C([t.vercelOutput,`functions`,`_${r}.func`],!0),o=await E(i,a,t.nftCache);await c(d(a,`.vc-config.json`),JSON.stringify({handler:o,runtime:`nodejs${e}.x`,launcherType:`Nodejs`,supportsResponseStreaming:!0},null,2),`utf8`)}})}}}}}async function j(t,n){console.log(`Copying assets...`);let r=await C([n,`static`]);await e(t,r,{recursive:!0,force:!0}),await a(d(r,`.vite`),{recursive:!0,force:!0})}async function M(e,t,n){console.log(`Writing Vercel config file...`);let r={version:3,routes:[],framework:{slug:`vite`}};r.routes.push({src:`^/${e}/.*`,headers:{"Cache-Control":`public, max-age=31536000, immutable`},continue:!0}),r.routes.push({handle:`filesystem`});let i=w(t);for(let e of i)e.path.length>0?r.routes.push({src:`^${e.path}(?:/.*)?$`,dest:`_${e.bundleId}`}):r.routes.push({src:`^/.*$`,dest:`_${e.bundleId}`});await c(n,JSON.stringify(r,null,2),`utf8`)}const N=({platform:e=`node`,nodeVersion:t=24,entryFile:n=`server.ts`,appDirectory:r=`src`,includeFiles:i=[],reactRouterConfig:a={},devExclude:o})=>{let s=(e==`netlify`?D:e==`vercel`?A:k)({nodeVersion:t,includeFiles:i}),{future:c,presets:l,...u}=a;return{vitePluginOptions:{platform:e,nodeVersion:t,entryFile:n,devExclude:o},reactRouterConfig:{...u,appDirectory:r,ssr:!0,serverModuleFormat:`esm`,presets:l?[...l,s]:[s],future:{...c,v8_middleware:!0,v8_splitRouteModules:!0,v8_viteEnvironmentApi:!0,v8_passThroughRequests:!0}}}};export{N as defineDevConfig};
|
package/dist/router.d.mts
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
|
-
import { MetaDescriptor } from "react-router";
|
|
1
|
+
import { LinkProps, MetaDescriptor, NavLinkProps, Path } from "react-router";
|
|
2
|
+
import { JSX } from "react/jsx-runtime";
|
|
3
|
+
import { RefObject } from "react";
|
|
2
4
|
|
|
3
5
|
//#region src/router/utils/merge-meta.d.ts
|
|
4
6
|
declare function mergeMeta<A extends {
|
|
5
7
|
matches: any[];
|
|
6
8
|
}>(metaFn: (args: A) => MetaDescriptor[], titleJoin?: string): (args: A) => MetaDescriptor[];
|
|
7
9
|
//#endregion
|
|
8
|
-
|
|
10
|
+
//#region src/router/components/history-link.d.ts
|
|
11
|
+
declare function HistoryLink(props: LinkProps): JSX.Element;
|
|
12
|
+
declare function HistoryNavLink(props: NavLinkProps): JSX.Element;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/router/hooks/use-history-back.d.ts
|
|
15
|
+
type UseHistoryBackOptions = {
|
|
16
|
+
backTo?: string | Partial<Path>;
|
|
17
|
+
};
|
|
18
|
+
declare function useHistoryBack(backTo?: string | Partial<Path>): () => Promise<void>;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/router/hooks/use-route-progress.d.ts
|
|
21
|
+
declare function useRouteProgress(): {
|
|
22
|
+
ref: RefObject<HTMLDivElement | null>;
|
|
23
|
+
active: boolean;
|
|
24
|
+
animating: boolean;
|
|
25
|
+
state: "idle" | "loading" | "submitting";
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
export { HistoryLink, HistoryNavLink, UseHistoryBackOptions, mergeMeta, useHistoryBack, useRouteProgress };
|
package/dist/router.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
import{Link as e,NavLink as t,useLocation as n,useNavigate as r,useNavigation as i}from"react-router";import{jsx as a}from"react/jsx-runtime";import{useEffect as o,useRef as s,useState as c}from"react";function l(e,t=` - `){return n=>{let r=e(n),i=n.matches.reduceRight((e,t)=>{for(let n of t.meta)e.findIndex(e=>`name`in e&&`name`in n?e.name===n.name:`property`in e&&`property`in n?e.property===n.property:`title`in e&&`title`in n?e.title===n.title:!1)==-1&&e.push(n);return e},r),a=[],o=[];for(let e of i)`title`in e?typeof e.title==`string`&&e.title.length>0&&a.push(...e.title.split(t)):o.push(e);return o.unshift({title:[...new Set(a)].join(t)}),o}}function u(t){let{state:n,to:r,...i}=t;return a(e,{to:r,state:{...n,previous:!0},...i})}function d(e){let{state:n,to:r,...i}=e;return a(t,{to:r,state:{...n,previous:!0},...i})}function f(e=`/`){let t=r(),{state:i}=n();return async()=>{i?.previous?await t(-1):await t(e)}}function p(){let e=i(),t=e.state!==`idle`,n=s(null),[r,a]=c(!1);return o(()=>{if(!n.current)return;Promise.allSettled(n.current.getAnimations().map(({finished:e})=>e)).then(()=>{t||a(!1)});let e=t?setTimeout(()=>a(!0),100):null;return()=>{e&&clearTimeout(e)}},[t]),{ref:n,active:t,animating:r,state:e.state}}export{u as HistoryLink,d as HistoryNavLink,l as mergeMeta,f as useHistoryBack,p as useRouteProgress};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@resolid/dev",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Development utils for Resolid applications",
|
|
6
6
|
"keywords": [
|
|
@@ -60,25 +60,31 @@
|
|
|
60
60
|
"provenance": true
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@hono/node-server": "^
|
|
63
|
+
"@hono/node-server": "^2.0.1",
|
|
64
64
|
"@resolid/utils": "^1.3.7",
|
|
65
65
|
"@vercel/nft": "^1.5.0",
|
|
66
66
|
"fast-glob": "^3.3.3",
|
|
67
|
-
"hono": "^4.12.
|
|
67
|
+
"hono": "^4.12.17",
|
|
68
68
|
"minimatch": "^10.2.5",
|
|
69
69
|
"rolldown": "latest"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@react-router/dev": "^7.
|
|
73
|
-
"
|
|
72
|
+
"@react-router/dev": "^7.15.0",
|
|
73
|
+
"@types/react": "^19.2.14",
|
|
74
|
+
"@types/react-dom": "^19.2.3",
|
|
75
|
+
"react": "^19.2.5",
|
|
76
|
+
"react-dom": "^19.2.5",
|
|
77
|
+
"tsdown": "^0.21.10"
|
|
74
78
|
},
|
|
75
79
|
"peerDependencies": {
|
|
76
|
-
"@netlify/types": "^2.
|
|
77
|
-
"@react-router/dev": "^7.
|
|
78
|
-
"@react-router/node": "^7.
|
|
79
|
-
"isbot": "^5.1.
|
|
80
|
-
"react
|
|
81
|
-
"
|
|
80
|
+
"@netlify/types": "^2.6.0",
|
|
81
|
+
"@react-router/dev": "^7.15.0",
|
|
82
|
+
"@react-router/node": "^7.15.0",
|
|
83
|
+
"isbot": "^5.1.40",
|
|
84
|
+
"react": "^19.2.5",
|
|
85
|
+
"react-dom": "^19.2.5",
|
|
86
|
+
"react-router": "^7.15.0",
|
|
87
|
+
"vite": "^8.0.10"
|
|
82
88
|
},
|
|
83
89
|
"engines": {
|
|
84
90
|
"node": "^22.13.0 || >=24"
|