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.
In order to avoid misuse again in the future, I rename this function and add comment
| let { pathname, query } = resolveRelativeRequest(importer, id) | ||
|
|
||
| // 2. resolve extensions. | ||
| const ext = resolver.resolveExt(pathname) |
There was a problem hiding this comment.
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.
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.