From 3587f0daade76ec86646ab04614c3806f14fc473 Mon Sep 17 00:00:00 2001 From: Ming <527990618@163.com> Date: Tue, 19 Nov 2024 16:25:14 +0800 Subject: [PATCH 1/2] chore: add a server directory for universal server utils --- .changeset/smart-eyes-eat.md | 8 ++++++++ .../cli/plugin-data-loader/src/runtime/index.ts | 2 +- .../plugin-server/src/runtime/assets/assets.ts | 2 +- packages/toolkit/runtime-utils/package.json | 13 +++++++++++++ packages/toolkit/runtime-utils/src/node/index.ts | 1 - packages/toolkit/runtime-utils/src/server/index.ts | 1 + .../src/{node => server}/nestedRoutes.ts | 0 7 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 .changeset/smart-eyes-eat.md create mode 100644 packages/toolkit/runtime-utils/src/server/index.ts rename packages/toolkit/runtime-utils/src/{node => server}/nestedRoutes.ts (100%) diff --git a/.changeset/smart-eyes-eat.md b/.changeset/smart-eyes-eat.md new file mode 100644 index 000000000000..650a198f4a7a --- /dev/null +++ b/.changeset/smart-eyes-eat.md @@ -0,0 +1,8 @@ +--- +'@modern-js/plugin-data-loader': patch +'@modern-js/runtime-utils': patch +'@modern-js/plugin-server': patch +--- + +chore: add a server directory for universal server utils +chore: 添加一个 server 目录用于存放通用的服务端工具函数 diff --git a/packages/cli/plugin-data-loader/src/runtime/index.ts b/packages/cli/plugin-data-loader/src/runtime/index.ts index 812c8a30a144..9409ac1050f8 100644 --- a/packages/cli/plugin-data-loader/src/runtime/index.ts +++ b/packages/cli/plugin-data-loader/src/runtime/index.ts @@ -1,7 +1,6 @@ import { transformNestedRoutes } from '@modern-js/runtime-utils/browser'; import { createRequestContext, - matchEntry, reporterCtx, } from '@modern-js/runtime-utils/node'; import { @@ -11,6 +10,7 @@ import { isRouteErrorResponse, json, } from '@modern-js/runtime-utils/remix-router'; +import { matchEntry } from '@modern-js/runtime-utils/server'; import { time } from '@modern-js/runtime-utils/time'; import type { NestedRoute, Reporter, ServerRoute } from '@modern-js/types'; import { isPlainObject } from '@modern-js/utils/lodash'; diff --git a/packages/server/plugin-server/src/runtime/assets/assets.ts b/packages/server/plugin-server/src/runtime/assets/assets.ts index 1939c9cd4d15..1376574c01e5 100644 --- a/packages/server/plugin-server/src/runtime/assets/assets.ts +++ b/packages/server/plugin-server/src/runtime/assets/assets.ts @@ -1,5 +1,5 @@ -import { matchEntry } from '@modern-js/runtime-utils/node'; import { matchRoutes } from '@modern-js/runtime-utils/remix-router'; +import { matchEntry } from '@modern-js/runtime-utils/server'; const createScript = (href: string, nonce?: string) => ``; diff --git a/packages/toolkit/runtime-utils/package.json b/packages/toolkit/runtime-utils/package.json index 4a487f517fc7..9f681316ec1c 100644 --- a/packages/toolkit/runtime-utils/package.json +++ b/packages/toolkit/runtime-utils/package.json @@ -48,6 +48,11 @@ "require": "./dist/cjs/node/router.js", "default": "./dist/esm/node/router.js" }, + "./server": { + "types": "./dist/types/server/index.d.ts", + "require": "./dist/cjs/server/index.js", + "default": "./dist/esm/server/index.js" + }, "./time": { "types": "./dist/types/time.d.ts", "jsnext:source": "./src/time.ts", @@ -118,6 +123,11 @@ "require": "./dist/cjs/node/index.js", "default": "./dist/esm/node/index.js" }, + "./server": { + "types": "./dist/types/server/index.d.ts", + "require": "./dist/cjs/server/index.js", + "default": "./dist/esm/server/index.js" + }, "./node/router": { "types": "./dist/types/node/router.d.ts", "require": "./dist/cjs/node/router.js", @@ -174,6 +184,9 @@ "node": [ "./dist/types/node/index.d.ts" ], + "server": [ + "./dist/types/server/index.d.ts" + ], "node/router": [ "./dist/types/node/router.d.ts" ], diff --git a/packages/toolkit/runtime-utils/src/node/index.ts b/packages/toolkit/runtime-utils/src/node/index.ts index e2ef71003aa7..b0347be00b73 100644 --- a/packages/toolkit/runtime-utils/src/node/index.ts +++ b/packages/toolkit/runtime-utils/src/node/index.ts @@ -9,6 +9,5 @@ const { run, useContext: useHeaders } = createStorage(); export { run, useHeaders }; export { serializeJson } from './serialize'; -export * from './nestedRoutes'; export * from './loaderContext'; export * from './stream'; diff --git a/packages/toolkit/runtime-utils/src/server/index.ts b/packages/toolkit/runtime-utils/src/server/index.ts new file mode 100644 index 000000000000..041e41af0deb --- /dev/null +++ b/packages/toolkit/runtime-utils/src/server/index.ts @@ -0,0 +1 @@ +export * from './nestedRoutes'; diff --git a/packages/toolkit/runtime-utils/src/node/nestedRoutes.ts b/packages/toolkit/runtime-utils/src/server/nestedRoutes.ts similarity index 100% rename from packages/toolkit/runtime-utils/src/node/nestedRoutes.ts rename to packages/toolkit/runtime-utils/src/server/nestedRoutes.ts From f171d856a89bfe294598b27f896560a5b9617c9e Mon Sep 17 00:00:00 2001 From: Ming <527990618@163.com> Date: Wed, 20 Nov 2024 13:57:34 +0800 Subject: [PATCH 2/2] chore: add jsnext:source --- packages/toolkit/runtime-utils/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/toolkit/runtime-utils/package.json b/packages/toolkit/runtime-utils/package.json index 9f681316ec1c..c8668eb1e067 100644 --- a/packages/toolkit/runtime-utils/package.json +++ b/packages/toolkit/runtime-utils/package.json @@ -50,6 +50,7 @@ }, "./server": { "types": "./dist/types/server/index.d.ts", + "jsnext:source": "./src/server/index.ts", "require": "./dist/cjs/server/index.js", "default": "./dist/esm/server/index.js" },