From dcbfa1449381f42aefa36ab79fa097213c3d8b76 Mon Sep 17 00:00:00 2001 From: Belinda Cao Date: Wed, 24 Jul 2024 15:18:16 +0800 Subject: [PATCH] feat: router v5 runtime plugin use meta path for runtime package (#5989) --- .changeset/soft-oranges-fix.md | 8 ++++++++ packages/runtime/plugin-garfish/jest.config.js | 3 +++ packages/runtime/plugin-garfish/src/cli/index.ts | 1 + packages/runtime/plugin-garfish/src/global.d.ts | 4 ++++ .../runtime/plugin-garfish/src/runtime/utils/apps.tsx | 3 +-- packages/runtime/plugin-router-v5/jest.config.js | 5 +++++ packages/runtime/plugin-router-v5/src/cli/index.ts | 2 ++ packages/runtime/plugin-router-v5/src/modern-app-env.d.ts | 8 ++++++++ packages/runtime/plugin-router-v5/src/runtime/plugin.tsx | 7 ++----- tests/jest-ut.config.js | 6 +++++- 10 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 .changeset/soft-oranges-fix.md diff --git a/.changeset/soft-oranges-fix.md b/.changeset/soft-oranges-fix.md new file mode 100644 index 000000000000..343c5fb32803 --- /dev/null +++ b/.changeset/soft-oranges-fix.md @@ -0,0 +1,8 @@ +--- +'@modern-js/plugin-router-v5': patch +'@modern-js/plugin-garfish': patch +--- + +feat: router v5 and garfish runtime plugin use @meta/runtime path for @modern-js/runtime package + +feat: router v5 和 garfish runtime 插件使用 @meta/runtime 路径导入 @modern-js/runtime diff --git a/packages/runtime/plugin-garfish/jest.config.js b/packages/runtime/plugin-garfish/jest.config.js index 5fcd3e5b28bd..1f37fa70d3d3 100644 --- a/packages/runtime/plugin-garfish/jest.config.js +++ b/packages/runtime/plugin-garfish/jest.config.js @@ -4,4 +4,7 @@ const sharedConfig = require('@scripts/jest-config'); module.exports = { ...sharedConfig, rootDir: __dirname, + moduleNameMapper: { + '^@meta/runtime$': '/node_modules/@modern-js/runtime/src', + }, }; diff --git a/packages/runtime/plugin-garfish/src/cli/index.ts b/packages/runtime/plugin-garfish/src/cli/index.ts index 3e847db5bd51..38060572a056 100644 --- a/packages/runtime/plugin-garfish/src/cli/index.ts +++ b/packages/runtime/plugin-garfish/src/cli/index.ts @@ -137,6 +137,7 @@ export const garfishPlugin = (): CliPlugin< source: { alias: { [`@${metaName}/runtime/garfish`]: `@${metaName}/plugin-garfish/runtime`, + '@meta/runtime': '@modern-js/runtime', '@meta/runtime/browser': '@modern-js/runtime/browser', '@meta/runtime/react': '@modern-js/runtime/react', }, diff --git a/packages/runtime/plugin-garfish/src/global.d.ts b/packages/runtime/plugin-garfish/src/global.d.ts index a34ff5bcaed6..d3895d5cde10 100644 --- a/packages/runtime/plugin-garfish/src/global.d.ts +++ b/packages/runtime/plugin-garfish/src/global.d.ts @@ -7,3 +7,7 @@ declare module '@meta/runtime/react' { declare module '@meta/runtime/browser' { export * from '@modern-js/runtime/browser'; } + +declare module '@meta/runtime' { + export * from '@modern-js/runtime'; +} diff --git a/packages/runtime/plugin-garfish/src/runtime/utils/apps.tsx b/packages/runtime/plugin-garfish/src/runtime/utils/apps.tsx index 063df39eb9ec..d5fb0f31657c 100644 --- a/packages/runtime/plugin-garfish/src/runtime/utils/apps.tsx +++ b/packages/runtime/plugin-garfish/src/runtime/utils/apps.tsx @@ -1,7 +1,6 @@ // The loading logic of the current component refers to react-loadable https://github.com/jamiebuilds/react-loadable import React, { useContext, useState, useEffect, useRef } from 'react'; -// import { withRouter, useMatches } from '@modern-js/runtime/router'; -import { RuntimeReactContext } from '@modern-js/runtime'; +import { RuntimeReactContext } from '@meta/runtime'; // eslint-disable-next-line import/no-named-as-default import Garfish, { interfaces } from 'garfish'; // import Loadable from 'react-loadable'; diff --git a/packages/runtime/plugin-router-v5/jest.config.js b/packages/runtime/plugin-router-v5/jest.config.js index 5fcd3e5b28bd..124b0f9d55e1 100644 --- a/packages/runtime/plugin-router-v5/jest.config.js +++ b/packages/runtime/plugin-router-v5/jest.config.js @@ -4,4 +4,9 @@ const sharedConfig = require('@scripts/jest-config'); module.exports = { ...sharedConfig, rootDir: __dirname, + moduleNameMapper: { + '^@meta/runtime$': '/node_modules/@modern-js/runtime/src', + '^@meta/runtime/context$': + '/node_modules/@modern-js/runtime/src/core/context', + }, }; diff --git a/packages/runtime/plugin-router-v5/src/cli/index.ts b/packages/runtime/plugin-router-v5/src/cli/index.ts index a4ca9a6f514c..3891d0b80a0a 100644 --- a/packages/runtime/plugin-router-v5/src/cli/index.ts +++ b/packages/runtime/plugin-router-v5/src/cli/index.ts @@ -54,6 +54,8 @@ export const routerPlugin = (): CliPlugin => ({ source: { alias: { [`@${metaName}/runtime/router-v5`]: routerExportsUtils.getPath(), + '@meta/runtime': '@modern-js/runtime', + '@meta/runtime/context': '@modern-js/runtime/context', }, }, }; diff --git a/packages/runtime/plugin-router-v5/src/modern-app-env.d.ts b/packages/runtime/plugin-router-v5/src/modern-app-env.d.ts index 9392c84ca34c..4a5e076466ce 100644 --- a/packages/runtime/plugin-router-v5/src/modern-app-env.d.ts +++ b/packages/runtime/plugin-router-v5/src/modern-app-env.d.ts @@ -1 +1,9 @@ /// + +declare module '@meta/runtime/context' { + export * from '@modern-js/runtime/context'; +} + +declare module '@meta/runtime' { + export * from '@modern-js/runtime'; +} diff --git a/packages/runtime/plugin-router-v5/src/runtime/plugin.tsx b/packages/runtime/plugin-router-v5/src/runtime/plugin.tsx index 5b3f77c1c934..3f3fe536bf5b 100644 --- a/packages/runtime/plugin-router-v5/src/runtime/plugin.tsx +++ b/packages/runtime/plugin-router-v5/src/runtime/plugin.tsx @@ -15,13 +15,10 @@ import { useLocation, useHistory, } from 'react-router-dom'; -import { RuntimeReactContext, isBrowser } from '@modern-js/runtime'; +import { RuntimeReactContext, isBrowser } from '@meta/runtime'; import type { Plugin } from '@modern-js/runtime'; import { parsedJSONFromElement } from '@modern-js/runtime-utils/parsed'; -import { - getGlobalLayoutApp, - getGlobalRoutes, -} from '@modern-js/runtime/context'; +import { getGlobalLayoutApp, getGlobalRoutes } from '@meta/runtime/context'; import { renderRoutes, getLocation, urlJoin } from './utils'; import { modifyRoutesHook } from './hooks'; diff --git a/tests/jest-ut.config.js b/tests/jest-ut.config.js index 788c21658a7c..3ecb521e9327 100644 --- a/tests/jest-ut.config.js +++ b/tests/jest-ut.config.js @@ -24,7 +24,11 @@ module.exports = { }, ], }, - moduleNameMapper: {}, + moduleNameMapper: { + '^@meta/runtime$': '/packages/runtime/plugin-runtime/src', + '^@meta/runtime/context$': + '/packages/runtime/plugin-runtime/src/core/context', + }, globals: {}, resolver: '/tests/jest.resolver.js', transformIgnorePatterns: [