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 rewrite in unoptimized dep #344

Merged
merged 9 commits into from
Jun 4, 2020

Conversation

csr632
Copy link
Member

@csr632 csr632 commented Jun 3, 2020

This is a regression of #228

You can see the reproduction in the playground.

* returning undefined indicates the filePath is not fuzzy:
* it is already an exact file path, or it can't match any file
*/
const resolveFilePathPostfix = (filePath: string): string | undefined => {
Copy link
Member Author

@csr632 csr632 Jun 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to avoid misuse again in the future, I rename this function and add comment

@@ -254,11 +252,8 @@ export const resolveImport = (
// ./foo -> /some/path/foo
let { pathname, query } = resolveRelativeRequest(importer, id)

// 2. resolve extensions.
const ext = resolver.resolveExt(pathname)
Copy link
Member Author

@csr632 csr632 Jun 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the cause of bug. resolveExt is misused.
For pathname /test-package/lib/dir, resolveExt returned .js instead of /index.js here.
So it is rewritten into /test-package/lib/dir.js instead of /test-package/lib/dir/index.js

const ext = resolveExt(resolved)
const result = {
filePath: ext ? resolved + ext : resolved,
ext: ext || path.extname(resolved)
Copy link
Member Author

@csr632 csr632 Jun 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous code can't guarantee ext is the actual missing postfix of publicPath, because defaultRequestToFile would add /index.js to resolved silently, and ext only return .js here.

@csr632
Copy link
Member Author

csr632 commented Jun 4, 2020

I don't know why test is failling, it seems like jest issue with esModule?

@yyx990803
Copy link
Member

The implementation seems to have a lot of problems in Windows due to not distinguishing between request paths vs. file paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants