Skip to content

Commit

Permalink
fix(cjs): resolve directory import relative to parent (#42)
Browse files Browse the repository at this point in the history
fixes #583
  • Loading branch information
privatenumber committed Jun 8, 2024
1 parent 89621bf commit 02d3856
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/cjs/api/module-resolve-filename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export const createResolveFilename = (
*/
const resolved = (
tryExtensions(resolve, possiblePath)
|| tryExtensions(resolve, path.resolve(possiblePath, 'index'))
|| tryExtensions(resolve, `${request}${path.sep}index`)
);
if (resolved) {
return resolved + query;
Expand All @@ -187,7 +187,8 @@ export const createResolveFilename = (
} catch (error) {
const resolved = (
tryExtensions(resolve, request)
|| tryExtensions(resolve, path.resolve(request, 'index'))
// Default resolve handles resovling paths relative to the parent
|| tryExtensions(resolve, `${request}${path.sep}index`)
);
if (resolved) {
return resolved + query;
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ export const files = {
${syntaxLowering}
${preserveName}
export const cjsContext = ${cjsContextCheck};
// Implicit directory import works outside of immedaite CWD child
import '../ts/'
`,

'json/index.json': JSON.stringify({ loaded: 'json' }),
Expand Down

0 comments on commit 02d3856

Please sign in to comment.