-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat(paths): Allow usage of TSConfig Paths #76
Conversation
@yoursunny It definitely isn't pretty, but it does work! If you don't mind taking a look at the code review for me. |
@@ -5,6 +5,7 @@ | |||
"moduleResolution": "Node", | |||
|
|||
"allowSyntheticDefaultImports": true, | |||
"declaration": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will make it easier for people to extend TS-ESNode in their own scripts. Recently realized that most of my modules don't have declaration enabled, oops.
src/index.ts
Outdated
let forceRelative = false; | ||
if (TSConfig && TSConfig.paths) { | ||
for (const tsPath of Object.keys(TSConfig.paths)) { | ||
const tsPathKey = tsPath.replace('/*', ''); | ||
if (specifier.startsWith(tsPathKey)) { | ||
const pathSpecifier = TSConfig.paths[tsPath][0].replace( | ||
'/*', | ||
specifier.split(tsPathKey)[1], | ||
); | ||
|
||
forceRelative = true; | ||
|
||
parentURL = `${ | ||
pathToFileURL(resolvePath(baseURL, TSConfig.baseUrl!)).href | ||
}/`; | ||
console.log(parentURL, pathSpecifier); | ||
|
||
specifier = pathSpecifier; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit of a hack, but I need to swap out the "/*" in the key and the path, and then force relative so that the fileFinder function runs since most people aren't using extension ESModule imports in Node.JS. And I need to resolve the path from the TSConfig path because of how the baseUrl and stuff is used in TypeScript. If I was the person writing the TypeScript side of the Paths feature I would have done it diferently.
@yoursunny To properly support Node.JS 13.9 I've set the target to ES2019 as you suggested. If you don't see anything horrific within the PR, I'll merge. Realized an old project I was porting used |
@@ -1,10 +1,11 @@ | |||
{ | |||
"compilerOptions": { | |||
"target": "ESNext", | |||
"target": "ES2019", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So as it turns out Node.JS 13.9 only has nullish coalescing and optional chaining working with an optional harmony V8 flags.
Let's hope this works, kinda expecting a bunch of issues introduced by this. |
# [1.5.0](v1.4.1...v1.5.0) (2020-05-26) ### Features * **paths:** Allow usage of TSConfig Paths ([#76](#76)) ([6e2f6af](6e2f6af))
🎉 This PR is included in version 1.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This PR introduces the ability to use the TSConfig Paths feature/options.