Skip to content

Commit

Permalink
feat: router v5 runtime plugin use meta path for runtime package (#5989)
Browse files Browse the repository at this point in the history
  • Loading branch information
caohuilin authored Jul 24, 2024
1 parent 88e3f9a commit dcbfa14
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .changeset/soft-oranges-fix.md
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions packages/runtime/plugin-garfish/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ const sharedConfig = require('@scripts/jest-config');
module.exports = {
...sharedConfig,
rootDir: __dirname,
moduleNameMapper: {
'^@meta/runtime$': '<rootDir>/node_modules/@modern-js/runtime/src',
},
};
1 change: 1 addition & 0 deletions packages/runtime/plugin-garfish/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down
4 changes: 4 additions & 0 deletions packages/runtime/plugin-garfish/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
3 changes: 1 addition & 2 deletions packages/runtime/plugin-garfish/src/runtime/utils/apps.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
5 changes: 5 additions & 0 deletions packages/runtime/plugin-router-v5/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ const sharedConfig = require('@scripts/jest-config');
module.exports = {
...sharedConfig,
rootDir: __dirname,
moduleNameMapper: {
'^@meta/runtime$': '<rootDir>/node_modules/@modern-js/runtime/src',
'^@meta/runtime/context$':
'<rootDir>/node_modules/@modern-js/runtime/src/core/context',
},
};
2 changes: 2 additions & 0 deletions packages/runtime/plugin-router-v5/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export const routerPlugin = (): CliPlugin<AppTools> => ({
source: {
alias: {
[`@${metaName}/runtime/router-v5`]: routerExportsUtils.getPath(),
'@meta/runtime': '@modern-js/runtime',
'@meta/runtime/context': '@modern-js/runtime/context',
},
},
};
Expand Down
8 changes: 8 additions & 0 deletions packages/runtime/plugin-router-v5/src/modern-app-env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
/// <reference types="@modern-js/types" />

declare module '@meta/runtime/context' {
export * from '@modern-js/runtime/context';
}

declare module '@meta/runtime' {
export * from '@modern-js/runtime';
}
7 changes: 2 additions & 5 deletions packages/runtime/plugin-router-v5/src/runtime/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
6 changes: 5 additions & 1 deletion tests/jest-ut.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ module.exports = {
},
],
},
moduleNameMapper: {},
moduleNameMapper: {
'^@meta/runtime$': '<rootDir>/packages/runtime/plugin-runtime/src',
'^@meta/runtime/context$':
'<rootDir>/packages/runtime/plugin-runtime/src/core/context',
},
globals: {},
resolver: '<rootDir>/tests/jest.resolver.js',
transformIgnorePatterns: [
Expand Down

0 comments on commit dcbfa14

Please sign in to comment.