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(module-tools): add extension for matchPath when process dts alias #5142

Merged
merged 1 commit into from
Dec 25, 2023
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
6 changes: 6 additions & 0 deletions .changeset/mighty-fireants-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/module-tools': patch
---

fix(module-tools): When dealing with dts file alias, explicitly declare the extension when calling matchPath to avoid the problem of not being able to find the module.
fix(module-tools): 处理类型描述文件别名过程中,在调用 matchPath 时显式声明后缀名,避免无法找到模块的问题
8 changes: 7 additions & 1 deletion packages/solutions/module-tools/src/utils/dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ export const processDtsFilesAfterTsc = async (config: GeneratorDtsConfig) => {
return;
}
const { start, end, name } = module;
const absoluteImportPath = matchPath(name);
// same as https://github.com/web-infra-dev/modern.js/blob/main/packages/solutions/module-tools/src/builder/feature/redirect.ts#L52
const absoluteImportPath = matchPath(name, undefined, undefined, [
'.jsx',
'.tsx',
'.js',
'.ts',
]);
if (absoluteImportPath) {
const relativePath = relative(
dirname(originalFilePath),
Expand Down
13 changes: 6 additions & 7 deletions tests/integration/module/fixtures/build/dts/dts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,12 @@ describe('dts build', () => {
path.resolve(fixtureDir, 'src/index.ts'),
).toBeTruthy();

/// / fix jest bug
// const content = await fs.readFile(distPath, 'utf8');
// const distPath = path.join(
// fixtureDir,
// './dist/bundleless/types/index.d.ts',
// );
// expect(content.includes('./b')).toBeTruthy();
const distPath = path.join(
fixtureDir,
'./dist/bundleless/types/index.d.ts',
);
const content = await fs.readFile(distPath, 'utf8');
expect(content.includes('./b')).toBeTruthy();
});
});

Expand Down
2 changes: 1 addition & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"test:rspack": "pnpm test:builder:rspack && pnpm test:framework",
"test:framework": "jest",
"test:builder:rspack": "cd e2e/builder && pnpm test:rspack",
"test:module-tools": "cd integration && jest --testMatch **/module/**/*.test.ts",
"test:module-tools": "cd integration && jest --testMatch **/module/**/dts.test.ts",
"test": "pnpm test --filter api-service-koa & pnpm test:framework",
"test:ut": "node --conditions=jsnext:source -r tsm ./node_modules/jest/bin/jest.js -c jest-ut.config.js --maxWorkers=2",
"prepare": "node node_modules/puppeteer/install.js",
Expand Down