From 3a1394b7611249c3dc4a996a19411d576e76b694 Mon Sep 17 00:00:00 2001 From: caohuilin Date: Wed, 24 Jul 2024 13:39:20 +0800 Subject: [PATCH 1/5] feat: router v5 runtime plugin use @meta/runtime path for @modern-js/runtime package --- .changeset/soft-oranges-fix.md | 8 ++++++++ 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/src/cli/index.ts | 2 ++ packages/runtime/plugin-router-v5/src/global.d.ts | 7 +++++++ packages/runtime/plugin-router-v5/src/runtime/plugin.tsx | 7 ++----- 7 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 .changeset/soft-oranges-fix.md create mode 100644 packages/runtime/plugin-router-v5/src/global.d.ts 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/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/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/global.d.ts b/packages/runtime/plugin-router-v5/src/global.d.ts new file mode 100644 index 000000000000..2bec23a1006c --- /dev/null +++ b/packages/runtime/plugin-router-v5/src/global.d.ts @@ -0,0 +1,7 @@ +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'; From dea662d3ce0d4bcae369e3345b05b68d2ca7e7ed Mon Sep 17 00:00:00 2001 From: caohuilin Date: Wed, 24 Jul 2024 13:59:48 +0800 Subject: [PATCH 2/5] fix: unit test --- packages/runtime/plugin-garfish/jest.config.js | 3 +++ packages/runtime/plugin-router-v5/jest.config.js | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/packages/runtime/plugin-garfish/jest.config.js b/packages/runtime/plugin-garfish/jest.config.js index 5fcd3e5b28bd..0c8fc73a1a59 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', + }, }; diff --git a/packages/runtime/plugin-router-v5/jest.config.js b/packages/runtime/plugin-router-v5/jest.config.js index 5fcd3e5b28bd..af95b744578c 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', + '^@meta/runtime/context$': + '/node_modules/@modern-js/runtime/dist/esm/core/context', + }, }; From 4b97402c359419b4e87e90426ed54244dd315bc4 Mon Sep 17 00:00:00 2001 From: caohuilin Date: Wed, 24 Jul 2024 14:03:38 +0800 Subject: [PATCH 3/5] fix: build type error --- packages/runtime/plugin-router-v5/src/global.d.ts | 7 ------- packages/runtime/plugin-router-v5/src/modern-app-env.d.ts | 8 ++++++++ 2 files changed, 8 insertions(+), 7 deletions(-) delete mode 100644 packages/runtime/plugin-router-v5/src/global.d.ts diff --git a/packages/runtime/plugin-router-v5/src/global.d.ts b/packages/runtime/plugin-router-v5/src/global.d.ts deleted file mode 100644 index 2bec23a1006c..000000000000 --- a/packages/runtime/plugin-router-v5/src/global.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -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/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'; +} From 4badcf97cc173c0104f4867fd350911aae0ca928 Mon Sep 17 00:00:00 2001 From: caohuilin Date: Wed, 24 Jul 2024 14:22:45 +0800 Subject: [PATCH 4/5] fix: root ut test --- tests/jest-ut.config.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/jest-ut.config.js b/tests/jest-ut.config.js index 788c21658a7c..c1e045bf924b 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', + '^@meta/runtime/context$': + '/packages/runtime/plugin-runtime/dist/esm/core/context', + }, globals: {}, resolver: '/tests/jest.resolver.js', transformIgnorePatterns: [ From 8be6acf339a917fd60e1467af836997e96f21b74 Mon Sep 17 00:00:00 2001 From: caohuilin Date: Wed, 24 Jul 2024 14:32:05 +0800 Subject: [PATCH 5/5] fix: jest alias runtime path --- packages/runtime/plugin-garfish/jest.config.js | 2 +- packages/runtime/plugin-router-v5/jest.config.js | 4 ++-- tests/jest-ut.config.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/runtime/plugin-garfish/jest.config.js b/packages/runtime/plugin-garfish/jest.config.js index 0c8fc73a1a59..1f37fa70d3d3 100644 --- a/packages/runtime/plugin-garfish/jest.config.js +++ b/packages/runtime/plugin-garfish/jest.config.js @@ -5,6 +5,6 @@ module.exports = { ...sharedConfig, rootDir: __dirname, moduleNameMapper: { - '^@meta/runtime$': '/node_modules/@modern-js/runtime', + '^@meta/runtime$': '/node_modules/@modern-js/runtime/src', }, }; diff --git a/packages/runtime/plugin-router-v5/jest.config.js b/packages/runtime/plugin-router-v5/jest.config.js index af95b744578c..124b0f9d55e1 100644 --- a/packages/runtime/plugin-router-v5/jest.config.js +++ b/packages/runtime/plugin-router-v5/jest.config.js @@ -5,8 +5,8 @@ module.exports = { ...sharedConfig, rootDir: __dirname, moduleNameMapper: { - '^@meta/runtime$': '/node_modules/@modern-js/runtime', + '^@meta/runtime$': '/node_modules/@modern-js/runtime/src', '^@meta/runtime/context$': - '/node_modules/@modern-js/runtime/dist/esm/core/context', + '/node_modules/@modern-js/runtime/src/core/context', }, }; diff --git a/tests/jest-ut.config.js b/tests/jest-ut.config.js index c1e045bf924b..3ecb521e9327 100644 --- a/tests/jest-ut.config.js +++ b/tests/jest-ut.config.js @@ -25,9 +25,9 @@ module.exports = { ], }, moduleNameMapper: { - '^@meta/runtime$': '/packages/runtime/plugin-runtime', + '^@meta/runtime$': '/packages/runtime/plugin-runtime/src', '^@meta/runtime/context$': - '/packages/runtime/plugin-runtime/dist/esm/core/context', + '/packages/runtime/plugin-runtime/src/core/context', }, globals: {}, resolver: '/tests/jest.resolver.js',