-
Notifications
You must be signed in to change notification settings - Fork 146
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
Change source code to TypeScript #133
Conversation
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.
Great work on this! Are the AST Node types coming through at all?
src/resolve-dependency.ts
Outdated
if (typeof exports === 'string' || | ||
typeof exports === 'object' && !Array.isArray(exports) && Object.keys(exports).length && Object.keys(exports)[0][0] !== '.') | ||
exports = { '.' : exports }; | ||
function resolveExportsTarget (pkgPath: string, exp: string | { [key: string]: string }, subpath: string, job: Job, cjsResolve: boolean): string | undefined { |
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.
I noticed that getExportsTarget()
handles the exports: null
case however this resolveExportsTarget()
function does not. Should we also handle exports: null
here?
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.
Yes on 117 we should probably have a null check too for consistency.
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.
What should happen for null
on line 117?
return null
?- assign
exports = { '.' : null }
? - assign
exports = null
? - something else?
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.
Actually exports
can never be null
or undefined
here as it is guarded in all calls.
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.
Good point, I added a PkgCfg
and Exports
type so we can confirm all cases are covered, thanks!
src/resolve-dependency.ts
Outdated
@@ -183,5 +200,5 @@ function resolvePackage (name, parent, job, cjsResolve) { | |||
return resolveFile(pathTarget, parent, job) || resolveDir(pathTarget, parent, job); |
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 path should have || throwNotFound
on the fallback.
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.
Ah ha, this is the missing piece! I pushed a change which makes sure resolveDependency(): string | string[]
so we never return undefined anymore
I found a few bugs when changing the source code to TypeScript.
I'll need some feedback from @guybedford to decide how to proceed in some cases, see comments below.