GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Refactor module resolution logic to have configurable goal extensions by weswigham · Pull Request #9430 · microsoft/TypeScript

Conversation

@weswigham

@weswigham Wesley Wigham (weswigham) commented Jun 29, 2016

Copy link
Copy Markdown
Member

Fixes #9427

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Wesley Wigham (weswigham) added 2 commits June 29, 2016 14:05
@weswigham
Alter lookup logic to look for js after exhausting @types
ed46d89
@weswigham
Add projects test with an @types and real module
5a3c695
@msftclas Microsoft Contribution License Agreements (msftclas) added the cla-already-signed label Jun 29, 2016
@weswigham

Wesley Wigham (weswigham) commented Jun 29, 2016

Copy link
Copy Markdown
Member Author

Bill Ticehurst (@billti) You should probably take a quick look at this.
Ron Buckton (@rbuckton) I've used your suggestion for this area of code from my other PR, so you should probably take a look, too.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

DanielRosenwasser
DanielRosenwasser reviewed Jun 29, 2016
View reviewed changes
Comment thread tests/baselines/reference/project/realisticNpmTypes/amd/realisticNpmTypes.json
"moduleResolution": "node",
"resolvedInputFiles": [
"lib.d.ts",
"node_modules/@types/m1/index.d.ts",

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Jun 29, 2016

Copy link
Copy Markdown
Member

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 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

@weswigham Wesley Wigham (weswigham) Jun 29, 2016 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

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.

Hah. It didn't get committed because it's in a node_modules folder. That's funny. And annoying. Let me fix that.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@billti Bill Ticehurst (billti) Jun 29, 2016

Copy link
Copy Markdown
Member

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.

Yeah, see the last line I added to the gitignore file on my prior merge to master. That nearly got me too.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@weswigham
Add missing files from node_modules folder
5e40c8e
mhegazy
mhegazy reviewed Jun 29, 2016
View reviewed changes
Comment thread src/compiler/program.ts
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) {

@mhegazy Mohamed Hegazy (mhegazy) Jun 29, 2016

Copy link
Copy Markdown
Contributor

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.

when do we need something that is not a string?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@weswigham Wesley Wigham (weswigham) Jun 29, 2016

Copy link
Copy Markdown
Member Author

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.

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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@rbuckton Ron Buckton (rbuckton) Jun 30, 2016

Copy link
Copy Markdown
Contributor

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.

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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Wesley Wigham (weswigham) added 3 commits June 29, 2016 15:01
@weswigham
Add another test
7894136
@weswigham
Pass through a resolution goal enum rather than extensions
fa9bfc8
@weswigham
Accept new baselines
6a257a4
@billti

Bill Ticehurst (billti) commented Jun 29, 2016

Copy link
Copy Markdown
Member

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;
                    }
                }
            }
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@billti

Bill Ticehurst (billti) commented Jun 29, 2016

Copy link
Copy Markdown
Member

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rbuckton
rbuckton reviewed Jun 30, 2016
View reviewed changes
Comment thread src/compiler/core.ts Outdated
export const supportedJavascriptExtensions = [".js", ".jsx"];
const allSupportedExtensions = supportedTypeScriptExtensions.concat(supportedJavascriptExtensions);

export function getExtensionsForGoal(goal: ResolutionGoal): string[] {

@rbuckton Ron Buckton (rbuckton) Jun 30, 2016

Copy link
Copy Markdown
Contributor

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.

ResolutionGoal seems to have some similarities to the ExtensionPriority enum used as part of glob resolution.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@weswigham Wesley Wigham (weswigham) Jun 30, 2016

Copy link
Copy Markdown
Member Author

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.

Merged! ExtensionPriority overlays nicely onto what I used to call ResolutionGoal (now since renamed).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Wesley Wigham (weswigham) added 2 commits June 29, 2016 18:59
@weswigham
Add trace baselines to project tests
ef102da
@weswigham
Rename ResolutionGoal and merge with ExtensionPriority
903ad65
@weswigham

Wesley Wigham (weswigham) commented Jun 30, 2016 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

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 ExtensionPriority enum used by globbing.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@billti

Bill Ticehurst (billti) commented Jun 30, 2016

Copy link
Copy Markdown
Member

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@weswigham

Wesley Wigham (weswigham) commented Jun 30, 2016

Copy link
Copy Markdown
Member Author

On a related note, Travis finally finished testing this PR and it's now lit up green. :D

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy

Mohamed Hegazy (mhegazy) commented Jun 30, 2016

Copy link
Copy Markdown
Contributor

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@weswigham Wesley Wigham (weswigham) changed the title Look for js files after @types files Refactor module resolution logic to have configurable goal extensions Jul 5, 2016
@weswigham
Merge branch 'master' into fix-lookup-priority
b1b31d2
@weswigham

Wesley Wigham (weswigham) commented Jul 12, 2016

Copy link
Copy Markdown
Member Author

Mohamed Hegazy (@mhegazy) Now that we've cut a 2.0 beta and have a PR out to bump the version tag in master to 2.1, can we look into merging this refactoring again?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@weswigham

Wesley Wigham (weswigham) commented Jul 15, 2016

Copy link
Copy Markdown
Member Author

Vladimir Matveev (@vladima) Could you look at this PR?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy

Mohamed Hegazy (mhegazy) commented Dec 30, 2016

Copy link
Copy Markdown
Contributor

This is stale by now. sorry for the delay. closing.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy Mohamed Hegazy (mhegazy) closed this Dec 30, 2016
@mhegazy
Mohamed Hegazy (mhegazy) deleted the fix-lookup-priority branch November 2, 2017 21:02
@microsoft Microsoft (microsoft) locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@weswigham @billti @mhegazy @DanielRosenwasser @rbuckton @msftclas
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.