Support pure ESM with TypeScript #66
Comments
I think Maybe we can add something right before the fallback: Lines 141 to 145 in b849105
// scratch / pseudo
try {
const extension = config.extension.find(extension => path.endsWith(extension));
if (extension) {
return {
type: 'source_file',
path: resolve.sync(path.slice(0, -extension.length), {
basedir: cwd,
extensions: [extension],
moduleDirectory: config.moduleDirectory,
}).replace(/\\/g, '/'),
}
}
} catch (e) {} |
Looks like we'll have to add that in a few places though if we want it to work with aliases and module-relative paths as well. |
I could see it being applied to all relative paths across the board, but enabled with config. Either in a very targeted way with |
I'm curious if it would "just work" if we were to add an empty extension to the array. Like |
When I tried that I received a "Failed parsing util" error message with exit code 1. |
I have it working for my project with an added |
A pull would be sweet! Thanks. |
This is useful for TypeScript projects outputing pure ESM. See https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-make-my-typescript-project-output-esm. Closes smeijer#66.
I created the PR. A couple notes about tests:
|
Here's a PR to fix the build/test failures I was seeing on the main branch: #69 |
I've also added a test for the pathTransforms config in my PR #67 |
This is useful for TypeScript projects outputing pure ESM. See https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-make-my-typescript-project-output-esm. Closes smeijer#66.
* feat: add regex path transformation This is useful for TypeScript projects outputing pure ESM. See https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-make-my-typescript-project-output-esm. Closes #66. * test: add assertion for new pathTransforms config * fix: use String.prototype.replace() Co-authored-by: Stephan Meijer <stephan.meijer@gmail.com>
🎉 This issue has been resolved in version 1.23.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Ran into an issue using this solution with |
I'm migrating a TypeScript project to output pure ESM. As part of that effort, I need to update every import which was previously extensionless, to specify a ".js" extension (even though the file in the source directory has a ".ts" extension). Like this:
It seems like unimported is unable to determine that
../a/module.js
should be resolved to../a/module.ts
and so it reports almost all files as being unimported.I've been referencing this guide for the migration to pure ESM.
The text was updated successfully, but these errors were encountered: