-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Conversation
* 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 => { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
60cf615
to
9bc5c2b
Compare
const ext = resolveExt(resolved) | ||
const result = { | ||
filePath: ext ? resolved + ext : resolved, | ||
ext: ext || path.extname(resolved) |
There was a problem hiding this comment.
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.
I don't know why test is failling, it seems like jest issue with esModule? |
The implementation seems to have a lot of problems in Windows due to not distinguishing between request paths vs. file paths. |
This is a regression of #228
You can see the reproduction in the playground.