Skip to content

Use more nodelike paths for import types when possible - #24610

Merged
Wesley Wigham (weswigham) merged 3 commits into
microsoft:masterfrom
weswigham:basic-import-path-nodification
Jun 5, 2018
Merged

Use more nodelike paths for import types when possible#24610
Wesley Wigham (weswigham) merged 3 commits into
microsoft:masterfrom
weswigham:basic-import-path-nodification

Conversation

@weswigham

@weswighamWesley Wigham (weswigham) commented Jun 1, 2018

Copy link
Copy Markdown
Member

Partial fix for #24599

A complete fix (ie, one where /index is also removed and maybe where package.json's get walked backward) requires a much more complex reverse resolver to check there's no directory/file conflicts (in the case of /index) and for file contents (in the case of reversing a package.json). If we think that's worth doing, we can; but this simple change of stripping the leading relative part makes the output as portable as is usually expected.

@mhegazy

Copy link
Copy Markdown
Contributor

We have the code to this in the services. We use it to generate import quick fixes.

@weswigham
Wesley Wigham (weswigham)force-pushed the basic-import-path-nodification branch from 3543ffb to 052d1a2CompareJune 4, 2018 19:30
@weswigham

Copy link
Copy Markdown
MemberAuthor

Mohamed Hegazy (@mhegazy) Moved, patched tryGetModuleNameAsNodeModule to handle file/directory conflicts appropriately (previously it would always use module/foo for module/foo/index even if module/foo.ts existed), and used.

@weswigham
Wesley Wigham (weswigham) requested a review from a userJune 4, 2018 19:32
@weswigham
Wesley Wigham (weswigham)force-pushed the basic-import-path-nodification branch from 052d1a2 to d79d781CompareJune 4, 2018 19:33
@mhegazy

Copy link
Copy Markdown
Contributor

Sheetal Nandi (@sheetalkamat) and Andy (Andrewkraft) (@Andy-MS) can you please review this change.

Comment threadsrc/compiler/moduleSpecifiers.ts Outdated
const extensions = getSupportedExtensions({ allowJs: true }, [{ extension: "node", isMixedContent: false }, { extension: "json", isMixedContent: false, scriptKind: ScriptKind.JSON }]);
for (const e of extensions) {
const fullPath = path + e;
if (host.fileExists!(fullPath)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to mark this with #18217

@weswigham
Wesley Wigham (weswigham) merged commit d9b9390 into microsoft:masterJun 5, 2018
@weswigham
Wesley Wigham (weswigham) deleted the basic-import-path-nodification branch June 5, 2018 19:54
Wesley Wigham (weswigham) added a commit to weswigham/TypeScript that referenced this pull request Jun 12, 2018
* Use more nodelike paths for import types when possible
* move functionality from services into compiler, fix with propert file/directory conflict handling
* mark suspect cast
@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@weswigham@mhegazy@sheetalkamat