Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix router info error when use custom file system routes entry #5889

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/strange-terms-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/runtime': patch
---

fix: fix router info error when use custom file system routes entry

fix: 修复当使用自定义约定式路由入口时生成 router 信息问题
2 changes: 1 addition & 1 deletion packages/runtime/plugin-runtime/src/router/cli/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
78 changes: 56 additions & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions tests/integration/custom-file-system-entry/modern.config.ts
Original file line number Diff line number Diff line change
@@ -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',
}),
],
});
32 changes: 32 additions & 0 deletions tests/integration/custom-file-system-entry/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
10 changes: 10 additions & 0 deletions tests/integration/custom-file-system-entry/src/custom/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Outlet } from '@modern-js/runtime/router';

export default function Layout() {
return (
<div>
root layout
<Outlet />
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const App = () => {
return <div className="index">custom entry</div>;
};

export default App;
51 changes: 51 additions & 0 deletions tests/integration/custom-file-system-entry/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import path from 'path';
import puppeteer, { Browser } from 'puppeteer';

import type { Page } from 'puppeteer';
import {
launchApp,
killApp,
getPort,
launchOptions,
} from '../../../utils/modernTestUtils';

const appDir = path.resolve(__dirname, '../');

describe('dev', () => {
let app: unknown;
let appPort: number;
let page: Page;
let browser: Browser;
const errors: string[] = [];
beforeAll(async () => {
appPort = await getPort();
app = await launchApp(appDir, appPort, {}, {});
browser = await puppeteer.launch(launchOptions as any);
page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', interceptedRequest => {
interceptedRequest.continue();
});
page.on('pageerror', error => {
console.log(error.message);
errors.push(error.message);
});
});

test('should render correctly', async () => {
await page.goto(`http://localhost:${appPort}/custom`, {
waitUntil: ['networkidle0'],
});
const element = await page.$('.index');
const targetText = await page.evaluate(
el => el?.firstChild?.textContent,
element,
);
expect(targetText?.includes('custom entry'));
});
afterAll(async () => {
await killApp(app);
await page.close();
await browser.close();
});
});
12 changes: 12 additions & 0 deletions tests/integration/custom-file-system-entry/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@modern-js/tsconfig/base",
"compilerOptions": {
"declaration": true,
"jsx": "preserve",
"baseUrl": "./",
"emitDeclarationOnly": true,
"isolatedModules": true,
"paths": {},
"types": ["node", "jest"]
}
}
13 changes: 13 additions & 0 deletions tests/integration/custom-file-system-entry/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "@modern-js/tsconfig/base",
"compilerOptions": {
"declaration": false,
"jsx": "preserve",
"baseUrl": "./",
"paths": {
"@/*": ["./src/*"],
"@shared/*": ["./shared/*"]
}
},
"include": ["src", "shared", "config"]
}
Loading