diff --git a/.changeset/strange-terms-pull.md b/.changeset/strange-terms-pull.md new file mode 100644 index 000000000000..997c3cc13b65 --- /dev/null +++ b/.changeset/strange-terms-pull.md @@ -0,0 +1,7 @@ +--- +'@modern-js/runtime': patch +--- + +fix: fix router info error when use custom file system routes entry + +fix: 修复当使用自定义约定式路由入口时生成 router 信息问题 diff --git a/packages/runtime/plugin-runtime/src/router/cli/entry.ts b/packages/runtime/plugin-runtime/src/router/cli/entry.ts index b055e0f13ea2..e2388cc8dde4 100644 --- a/packages/runtime/plugin-runtime/src/router/cli/entry.ts +++ b/packages/runtime/plugin-runtime/src/router/cli/entry.ts @@ -38,7 +38,7 @@ export const modifyEntrypoints = ( } const isHasNestedRoutes = hasNestedRoutes(entrypoint.absoluteEntryDir!); const isHasPages = hasPages(entrypoint.absoluteEntryDir!); - if (!isHasNestedRoutes && !isHasPages) { + if (!isHasNestedRoutes && !isHasPages && !entrypoint.fileSystemRoutes) { return entrypoint; } // When the user configures a custom entry, and the entry path is a folder, fileSystemRoutes will be set to true during entry recognition. diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 62a7bd7b2504..4fadcc4e1a96 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5899,6 +5899,37 @@ importers: specifier: ^5 version: 5.3.3 + tests/integration/custom-file-system-entry: + dependencies: + '@modern-js/runtime': + specifier: workspace:* + version: link:../../../packages/runtime/plugin-runtime + react: + specifier: ^18 + version: 18.2.0 + react-dom: + specifier: ^18 + version: 18.2.0(react@18.2.0) + devDependencies: + '@modern-js/app-tools': + specifier: workspace:* + version: link:../../../packages/solutions/app-tools + '@types/jest': + specifier: ^29 + version: 29.2.6 + '@types/node': + specifier: ^14 + version: 14.18.35 + '@types/react': + specifier: ^18 + version: 18.0.21 + '@types/react-dom': + specifier: ^18 + version: 18.0.6 + typescript: + specifier: ^5 + version: 5.4.5 + tests/integration/custom-render: dependencies: '@modern-js/runtime': @@ -8261,6 +8292,7 @@ packages: engines: {node: '>=6.9.0'} dependencies: '@babel/types': 7.24.7 + dev: false /@babel/helper-builder-binary-assignment-operator-visitor@7.22.15: resolution: {integrity: sha512-QkBXwGgaoC2GtGZRoma6kv7Szfv06khvhFav67ZExau2RaXzy8MpHSMO2PNoP2XtmQphJQRHFfg77Bq731Yizw==} @@ -8417,40 +8449,40 @@ packages: regexpu-core: 5.3.2 semver: 6.3.1 - /@babel/helper-create-regexp-features-plugin@7.22.15(@babel/core@7.24.7): + /@babel/helper-create-regexp-features-plugin@7.22.15(@babel/core@7.24.6): resolution: {integrity: sha512-29FkPLFjn4TPEa3RE7GpW+qbE8tlsu3jntNYNfcGsc49LphF1PQIiD+vMZ1z1xVOKt+93khA9tc2JBs3kBjA7w==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0 dependencies: - '@babel/core': 7.24.7 + '@babel/core': 7.24.6 '@babel/helper-annotate-as-pure': 7.22.5 regexpu-core: 5.3.2 semver: 6.3.1 - dev: true + dev: false - /@babel/helper-create-regexp-features-plugin@7.24.6(@babel/core@7.24.6): - resolution: {integrity: sha512-C875lFBIWWwyv6MHZUG9HmRrlTDgOsLWZfYR0nW69gaKJNe0/Mpxx5r0EID2ZdHQkdUmQo2t0uNckTL08/1BgA==} + /@babel/helper-create-regexp-features-plugin@7.22.15(@babel/core@7.24.7): + resolution: {integrity: sha512-29FkPLFjn4TPEa3RE7GpW+qbE8tlsu3jntNYNfcGsc49LphF1PQIiD+vMZ1z1xVOKt+93khA9tc2JBs3kBjA7w==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0 dependencies: - '@babel/core': 7.24.6 - '@babel/helper-annotate-as-pure': 7.24.7 + '@babel/core': 7.24.7 + '@babel/helper-annotate-as-pure': 7.22.5 regexpu-core: 5.3.2 semver: 6.3.1 - dev: false - /@babel/helper-create-regexp-features-plugin@7.24.6(@babel/core@7.24.7): + /@babel/helper-create-regexp-features-plugin@7.24.6(@babel/core@7.24.6): resolution: {integrity: sha512-C875lFBIWWwyv6MHZUG9HmRrlTDgOsLWZfYR0nW69gaKJNe0/Mpxx5r0EID2ZdHQkdUmQo2t0uNckTL08/1BgA==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0 dependencies: - '@babel/core': 7.24.7 + '@babel/core': 7.24.6 '@babel/helper-annotate-as-pure': 7.24.7 regexpu-core: 5.3.2 semver: 6.3.1 + dev: false /@babel/helper-create-regexp-features-plugin@7.24.7(@babel/core@7.24.7): resolution: {integrity: sha512-03TCmXy2FtXJEZfbXDTSqq1fRJArk7lX9DOFC/47VthYcxyIOx+eXQmdo6DOQvrbpIix+KfXwvuXdFDZHxt+rA==} @@ -9038,7 +9070,7 @@ packages: resolution: {integrity: sha512-2YnuOp4HAk2BsBrJJvYCbItHx0zWscI1C3zgWkz+wDyD9I7GIVrfnLyrR4Y1VR+7p+chAEcrgRQYZAGIKMV7vQ==} engines: {node: '>=6.9.0'} dependencies: - '@babel/helper-validator-identifier': 7.24.6 + '@babel/helper-validator-identifier': 7.24.7 chalk: 2.4.2 js-tokens: 4.0.0 picocolors: 1.0.0 @@ -9948,8 +9980,8 @@ packages: '@babel/core': ^7.0.0 dependencies: '@babel/core': 7.24.6 - '@babel/helper-create-regexp-features-plugin': 7.24.6(@babel/core@7.24.6) - '@babel/helper-plugin-utils': 7.24.7 + '@babel/helper-create-regexp-features-plugin': 7.22.15(@babel/core@7.24.6) + '@babel/helper-plugin-utils': 7.22.5 dev: false /@babel/plugin-syntax-unicode-sets-regex@7.18.6(@babel/core@7.24.7): @@ -9959,8 +9991,8 @@ packages: '@babel/core': ^7.0.0 dependencies: '@babel/core': 7.24.7 - '@babel/helper-create-regexp-features-plugin': 7.24.6(@babel/core@7.24.7) - '@babel/helper-plugin-utils': 7.24.7 + '@babel/helper-create-regexp-features-plugin': 7.22.15(@babel/core@7.24.7) + '@babel/helper-plugin-utils': 7.22.5 /@babel/plugin-transform-arrow-functions@7.23.3(@babel/core@7.23.6): resolution: {integrity: sha512-NzQcQrzaQPkaEwoTm4Mhyl8jI1huEL/WWIEvudjTCMJ9aBZNpsJbMASx7EQECtQQPS/DcnFpo0FIh3LvEO9cxQ==} @@ -12815,7 +12847,7 @@ packages: resolution: {integrity: sha512-3vgazJlLwNXi9jhrR1ef8qiB65L1RK90+lEQwv4OxveHnqC3BfmnHdgySwRLzf6akhlOYenT+b7AfWq+a//AHw==} engines: {node: '>=6.9.0'} dependencies: - '@babel/code-frame': 7.24.6 + '@babel/code-frame': 7.24.7 '@babel/parser': 7.24.6 '@babel/types': 7.24.6 @@ -12882,7 +12914,7 @@ packages: resolution: {integrity: sha512-OsNjaJwT9Zn8ozxcfoBc+RaHdj3gFmCmYoQLUII1o6ZrUwku0BMg80FoOTPx+Gi6XhcQxAYE4xyjPTo4SxEQqw==} engines: {node: '>=6.9.0'} dependencies: - '@babel/code-frame': 7.24.6 + '@babel/code-frame': 7.24.7 '@babel/generator': 7.24.6 '@babel/helper-environment-visitor': 7.24.6 '@babel/helper-function-name': 7.24.6 @@ -12925,7 +12957,7 @@ packages: engines: {node: '>=6.9.0'} dependencies: '@babel/helper-string-parser': 7.23.4 - '@babel/helper-validator-identifier': 7.24.6 + '@babel/helper-validator-identifier': 7.24.7 to-fast-properties: 2.0.0 /@babel/types@7.24.5: @@ -20426,7 +20458,7 @@ packages: dependencies: magic-string: 0.30.5 pathe: 1.1.1 - pretty-format: 29.5.0 + pretty-format: 29.7.0 dev: true /@vitest/spy@0.33.0: @@ -20455,7 +20487,7 @@ packages: dependencies: diff-sequences: 29.4.3 loupe: 2.3.6 - pretty-format: 29.5.0 + pretty-format: 29.7.0 dev: true /@vue/babel-helper-vue-transform-on@1.1.5: @@ -23735,6 +23767,7 @@ packages: /diff-sequences@29.4.3: resolution: {integrity: sha512-ofrBgwpPhCD85kMKtE9RYFFq6OC1A89oW2vvgWZNCwxrUpRUILopY7lsYyMDSjc8g6U6aiO0Qubg6r4Wgt5ZnA==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + dev: true /diff-sequences@29.6.3: resolution: {integrity: sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q==} @@ -27697,9 +27730,10 @@ packages: engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: chalk: 4.1.2 - diff-sequences: 29.4.3 + diff-sequences: 29.6.3 jest-get-type: 29.6.3 pretty-format: 29.7.0 + dev: true /jest-diff@29.7.0: resolution: {integrity: sha512-LMIgiIrhigmPrs03JHpxUh2yISK3vLFPkAodPeo0+BuF7wA2FoQbkEg1u8gBYBThncu7e1oEDUfIXVuTqLRUjw==} @@ -27982,7 +28016,7 @@ packages: chalk: 4.1.2 expect: 29.5.0 graceful-fs: 4.2.11 - jest-diff: 29.5.0 + jest-diff: 29.7.0 jest-get-type: 29.6.3 jest-matcher-utils: 29.5.0 jest-message-util: 29.5.0 diff --git a/tests/integration/custom-file-system-entry/modern.config.ts b/tests/integration/custom-file-system-entry/modern.config.ts new file mode 100644 index 000000000000..b07d0aa461e4 --- /dev/null +++ b/tests/integration/custom-file-system-entry/modern.config.ts @@ -0,0 +1,20 @@ +import { appTools, defineConfig } from '@modern-js/app-tools'; + +const bundler = process.env.BUNDLER; + +export default defineConfig({ + source: { + entries: { + custom: 'src/custom', + }, + disableDefaultEntries: true, + }, + runtime: { + router: true, + }, + plugins: [ + appTools({ + bundler: bundler === 'rspack' ? 'experimental-rspack' : 'webpack', + }), + ], +}); diff --git a/tests/integration/custom-file-system-entry/package.json b/tests/integration/custom-file-system-entry/package.json new file mode 100644 index 000000000000..051f2ec7ffc7 --- /dev/null +++ b/tests/integration/custom-file-system-entry/package.json @@ -0,0 +1,32 @@ +{ + "private": true, + "name": "custom-file-system-entry", + "version": "2.9.0", + "scripts": { + "dev": "modern dev", + "build": "modern build", + "serve": "modern serve", + "new": "modern new", + "lint": "modern lint" + }, + "engines": { + "node": ">=14.17.6" + }, + "eslintIgnore": [ + "node_modules/", + "dist/" + ], + "dependencies": { + "@modern-js/runtime": "workspace:*", + "react": "^18", + "react-dom": "^18" + }, + "devDependencies": { + "@modern-js/app-tools": "workspace:*", + "@types/node": "^14", + "@types/react": "^18", + "@types/react-dom": "^18", + "typescript": "^5", + "@types/jest": "^29" + } +} diff --git a/tests/integration/custom-file-system-entry/src/custom/layout.tsx b/tests/integration/custom-file-system-entry/src/custom/layout.tsx new file mode 100644 index 000000000000..41ccb32b802b --- /dev/null +++ b/tests/integration/custom-file-system-entry/src/custom/layout.tsx @@ -0,0 +1,10 @@ +import { Outlet } from '@modern-js/runtime/router'; + +export default function Layout() { + return ( +