GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Refactor module resolution logic to have configurable goal extensions by weswigham · Pull Request #9430 · microsoft/TypeScript Conversation
Member
Fixes #9427
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this file doesn't exist, but it's referenced?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
| jsonContent = jsonText ? <{ typings?: string, types?: string, main?: string }>JSON.parse(jsonText) : {}; | ||
| function getPackageEntry(packageJson: any, key: string, tag: string, state: ModuleResolutionState) { | ||
| const value = packageJson[key]; | ||
| if (typeof value === tag) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
when do we need something that is not a string?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
At this point, never. This was mostly Ron Buckton (@rbuckton)'s suggestion. I can specialize the function, if you'd prefer it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We discussed the possibility of augmenting the package.json for extensions, which could leverage this if we decided to lean in that direction.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This seems like a lot more code change than we need. I was thinking just something like the below in program.ts @ 781 would be sufficient, which is a minor change to existing logic. Anywhere this has issues? if (baseName !== "node_modules") { // Try to load source from the package const packageResult = loadModuleFromNodeModulesFolder(moduleName, directory, failedLookupLocations, state); if (packageResult && hasTypeScriptFileExtension(packageResult)) { // Always prefer TypeScript source (.ts, .tsx, .d.ts) shipped with the package return packageResult; } else { // Else prefer a types package over non-TypeScript results (e.g. JavaScript files) const typesResult = loadModuleFromNodeModulesFolder(combinePaths("@types", moduleName), directory, failedLookupLocations, state); if (typesResult || packageResult) { return typesResult || packageResult; } } } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I just tested the above simple change and that seems to work fine too. I'll push some commits to the (slightly) related change at #9421 for review. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| export const supportedJavascriptExtensions = [".js", ".jsx"]; | ||
| const allSupportedExtensions = supportedTypeScriptExtensions.concat(supportedJavascriptExtensions); | ||
|
|
||
| export function getExtensionsForGoal(goal: ResolutionGoal): string[] { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
ResolutionGoal seems to have some similarities to the ExtensionPriority enum used as part of glob resolution.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Merged! ExtensionPriority overlays nicely onto what I used to call ResolutionGoal (now since renamed).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Bill Ticehurst (@billti) I have ulterior motives for making this a little more complicated: I need to make it easy (in the near future) to specify that I want to load js files only for resolving modules in the extension PR (which is where the first draft of this code came from). Additionally, we were passing a handful of flags around to control the loading of js and jsx/tsx - this now unifies them. And, thanks to a little bit more effort, is now merged with the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Right, I was figuring as much. But we need this fix for 2.0, which has already snapped for stabilization. I'd rather keep it as simple as possible, especially as the extensibility stuff is very early on at this point and may go through more changes. That said, I'll let Mohamed Hegazy (@mhegazy) make the call on which pull request to take. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
On a related note, Travis finally finished testing this PR and it's now lit up green. :D |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I do agree with Bill Ticehurst (@billti) for 2.0 i think #9421 is sufficient. we ca take these other changes separately, and no need to lump them here. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Mohamed Hegazy (@mhegazy) Now that we've cut a |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Vladimir Matveev (@vladima) Could you look at this PR? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This is stale by now. sorry for the delay. closing. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.