Skip to content

Commit

Permalink
feat(node-resolve): Increase the support for .mjs/.cjs
Browse files Browse the repository at this point in the history
Import .mts or .cts files in TypeScript files requires passing through .mjs or .cjs flies.
  • Loading branch information
fierflame committed Mar 12, 2023
1 parent bc5cf91 commit 0e98f97
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/node-resolve/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ export function nodeResolve(opts = {}) {
}
}
}
// TypeScript files may import '.mjs' or '.cjs' to refer to either '.mts' or '.cts'
for (const [ext, tsExt] of [['.mjs', '.mts'], ['.cjs', '.cts']]) {
if (importee.endsWith(ext) && extensions.includes(tsExt)) {
importSpecifierList.push(importee.replace(/\.([mc])js$/, '.$1ts'));
}
}

const warn = (...args) => context.warn(...args);
const isRequire = custom && custom['node-resolve'] && custom['node-resolve'].isRequire;
Expand Down

0 comments on commit 0e98f97

Please sign in to comment.