-
Notifications
You must be signed in to change notification settings - Fork 3
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
Uncovered cases explored from a project migration #123
Comments
Hey @timofei-iatsenko, thanks a lot for putting in the effort to write such a detailed report! 🙏 Seeing others engage so deeply with projects I maintain gives me a real boost of motivation to keep working on them. 💪 Let's go through the topics... 1️⃣ Partial Support for
|
I started the script in each project in monorepo one by one eq:
I'm thinking might be utilizing real typescript resolver would help here? So the logic might be like that:
|
Thanks for your insights @timofei-iatsenko! I implemented support for dynamic imports (#130) and I created myself a test case for "2️⃣ Handling Package Exports and Subpath Imports": import omit from 'lodash/omit';
import {HttpsError} from 'firebase-functions/v1/https';
const object = {a: 1, b: '2', c: 3};
omit(object, ['a', 'c']);
export function logError() {
console.log(HttpsError);
} Using the current version of ts2esm it gets converted to this: import omit from 'lodash/omit.js';
import {HttpsError} from 'firebase-functions/v1/https';
const object = {a: 1, b: '2', c: 3};
omit(object, ['a', 'c']);
export function logError() {
console.log(HttpsError);
}
Isn't that exactly what you wanted? I also tried to use the built-in TypeScript resolver using this utility method: import { SourceFile, ts } from 'ts-morph';
export const ProjectUtil = {
getModule: (moduleName: string, sourceFile: SourceFile) => {
const compilerOptions = sourceFile.getProject().getCompilerOptions();
const host = ts.createCompilerHost(compilerOptions, true);
return ts.resolveModuleName(
moduleName,
sourceFile.getFilePath(),
sourceFile.getProject().getCompilerOptions(),
host
);
},
}; However, it returns a resolution to the
I am not yet sure how I can use this information to decide if I should add a |
Looks awesome!
That's a bummer, hoped it will free you from implementing this logic yourself. |
Hey there! First off, thanks for this awesome tool—it's been a huge time-saver! 🙌
I recently migrated a TypeScript project to ESM and used
ts2esm
to correctly add.js
extensions in imports. While it worked well overall, I ran into a few challenges that I think could improve the tool even further.1️⃣ Partial Support for
tsconfig
PathsI saw that tsconfig path support works to some extent, but I had issues in an Nx monorepo with
/apps/*
and/libs/*
. These are linked usingtsconfig
paths, andts2esm
only resolved the imports correctly after I movedlibs
inside anapps
folder. My workaround looked like this:libs/*
intoapps/myapp/libs/*
tsconfig.json
paths accordinglyts2esm
libs
back to their original locationIf
ts2esm
could resolve paths of aliases outside the current project dir, that would be amazing!2️⃣ Handling Package Exports and Subpath Imports
My project had a mix of modern packages (with
package.json
exports) and older ones using subpath imports. It would be great ifts2esm
could leverage TypeScript's built-in resolver to automatically handle these cases.Example 1: Legacy Package (
lodash
)lodash
doesn't have anexports
field, so it requires.js
in the import path:Currently,
ts2esm
doesn’t handle this, so I had to fix it manually.Example 2: Modern Package (
firebase-functions
)firebase-functions
has anexports
field, so no changes are needed:However, in cases where an import incorrectly targets a private subpath, it breaks in ESM:
Since TypeScript correctly flags these issues, maybe
ts2esm
could warn or ignore them?3️⃣ Dynamic Imports Are Not Converted
I also noticed that dynamic imports aren’t updated with
.js
extensions:Handling this would make
ts2esm
even more powerful!Would love to hear your thoughts! Let me know if I can help test anything. 😊
The text was updated successfully, but these errors were encountered: