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 — Allow export map entries to remap back to input files for a program by weswigham · Pull Request #47925 · microsoft/TypeScript

Conversation

@weswigham

@weswigham Wesley Wigham (weswigham) commented Feb 17, 2022

Copy link
Copy Markdown
Member

Fixes #46762

As the code may show, this is more of a mire than it appears at first blush. Because our output directory structure depends on the set of files we load (unless composite or rootDir is set), there's a circular dependency here - we need to resolve our set of input files to know what the output directory structure is, but we might need to know the output directory structure to know how to find our input files. Given that, I've employed a bit of a heuristic - in module resolution, we assume the common source directory is the top-most folder between the package file/config file and the directory we're resolving in that we can find that has a file matching the name we're looking for in it. Technically, this can never be wrong, since it'll cause us to load those top-level files, which'll, in turn, guarantee that the common source directory is at that top level. It might end up being surprising that adding an export map to your package.json and using a self-name import can change your output directory structure, but in some sense it makes sense, since adding an import changes that structure, too - this import just happens to (partially) be in your package.json.

AFAIK, this circular dependence issue was technically observable prior to export maps - imports like import("../../dist/other/file.js") don't resolve (to the input source) in TS today, we just see very little to no demand for fixing that issue, whereas once you couch it in terms of package exports and self names, such redirection gets a little more desirable.

Sorry, something went wrong.

Uh oh!

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

Offirmo and styfle reacted with thumbs up emoji benjie reacted with heart emoji
All reactions
  • 👍 2 reactions
  • ❤️ 1 reaction
@weswigham
Wesley Wigham (weswigham) requested review from Andrew Branch (andrewbranch) and Ron Buckton (rbuckton) February 17, 2022 00:00
@typescript-bot TypeScript Bot (typescript-bot) assigned Wesley Wigham (weswigham) Feb 17, 2022
@typescript-bot TypeScript Bot (typescript-bot) added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Feb 17, 2022
@weswigham
Allow export map entries to remap back to input files for a program
f6dc158
@weswigham
Wesley Wigham (weswigham) force-pushed the self-name-redirects branch from 8558033 to f6dc158 Compare February 17, 2022 00:07
Wesley Wigham (weswigham) added 2 commits March 2, 2022 10:07
@weswigham
Merge branch 'main' into self-name-redirects
7304ee6
@weswigham
Fix file casing issues on windows
6e44703
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) mentioned this pull request Mar 2, 2022
Design Meeting Notes, 3/2/2022 #48095
Closed
andrewbranch
Andrew Branch (andrewbranch) requested changes Mar 15, 2022
View reviewed changes

@andrewbranch Andrew Branch (andrewbranch) left a comment

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.

Conclusion from design meeting #48095 was to enforce rootDir.

Sorry, something went wrong.

Uh oh!

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

All reactions
@weswigham Wesley Wigham (weswigham) mentioned this pull request Apr 11, 2022
Unresolved TypeScript definition paths (when using node-esm with imports) #48639
Closed
Wesley Wigham (weswigham) added 3 commits April 18, 2022 10:56
@weswigham
Merge branch 'main' into self-name-redirects
cd02fd0
@weswigham
Implement abiguity error, doesnt quite work
9c8df0d
@weswigham
Refine selection logic in error case to use getCommonSourceDirectory,…
eb5a03e
… add more tests
@weswigham
Wesley Wigham (weswigham) requested a review from Andrew Branch (andrewbranch) April 18, 2022 20:55
@weswigham

Wesley Wigham (weswigham) commented Apr 28, 2022

Copy link
Copy Markdown
Member Author

Andrew Branch (@andrewbranch) Daniel Rosenwasser (@DanielRosenwasser) you wanna re-review this?

All reactions

Sorry, something went wrong.

Uh oh!

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

@andrewbranch

Andrew Branch (andrewbranch) commented Apr 28, 2022

Copy link
Copy Markdown
Member

So basically you kept the same guessing algorithm to use as a fallback when we issue the rootDir diagnostic?

All reactions

Sorry, something went wrong.

Uh oh!

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

@weswigham

Wesley Wigham (weswigham) commented Apr 28, 2022

Copy link
Copy Markdown
Member Author

Yep.

All reactions

Sorry, something went wrong.

Uh oh!

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

andrewbranch
Andrew Branch (andrewbranch) reviewed Apr 28, 2022
View reviewed changes
Comment thread src/compiler/moduleNameResolver.ts
fragment = ensureTrailingDirectorySeparator(commonDir);
}
}
if (commonSourceDirGuesses.length > 1) {

@andrewbranch Andrew Branch (andrewbranch) Apr 28, 2022

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.

If I’m reading this right, I find it troubling that if your project is sufficiently close to the disk root, the requirement of specifying rootDir is removed. It feels like where your fully-contained project directory is on disk should not affect program diagnostics—this seems like an easy way to get a compilation that succeeds in Docker because it was mounted at / but fails on the host machine, for example. I would lean toward a simple cause and effect: using X feature requires Y config, without any “weeeell technically” clauses. It also makes me wonder how much of this complexity can be removed. Why not use a simpler and more naive guess (config file path || current directory?) in the error case and save ~100 LOC?

Sorry, something went wrong.

Uh oh!

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

All reactions

@weswigham Wesley Wigham (weswigham) Apr 28, 2022

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.

If I’m reading this right, I find it troubling that if your project is sufficiently close to the disk root, the requirement of specifying rootDir is removed.

So... Sort-of. If the common path between the requesting file and the target file is the system root, then, yes. Every guess will be the system root, so there'll only be one unique guess. (Because it's the only possible root directory)

I don't think "mount location independence" is an aspect of our module resolver that it actually has - node_modules lookups trivially falsify that already. (Since you could mount somewhere that a parent node_modules that was used for resolution folder no longer exists.)

Sorry, something went wrong.

Uh oh!

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

All reactions

@weswigham Wesley Wigham (weswigham) Apr 28, 2022 •
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.

in the error case and save ~100 LOC?

Tbf, most of that is comments explaining why we don't actually know the final path and are making a guess. The actual guessing code is about 10 lines, changing the method wouldn't reduce it much, or even shrink the comment (just reduce how often it actually finds a file to pair with an error for better services behavior).

Sorry, something went wrong.

Uh oh!

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

All reactions
andrewbranch
Andrew Branch (andrewbranch) approved these changes May 5, 2022
View reviewed changes
@weswigham

Wesley Wigham (weswigham) commented May 5, 2022

Copy link
Copy Markdown
Member Author

Daniel Rosenwasser (@DanielRosenwasser) what/where/when do we want this merged?

All reactions

Sorry, something went wrong.

Uh oh!

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

@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented May 5, 2022

Copy link
Copy Markdown
Member

(There are conflicts now because some of these changes affect deleted baselines.)

It seems like this is part of the node16/nodenext story, so we should get it merged by today IMO.

All reactions

Sorry, something went wrong.

Uh oh!

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

@weswigham
Merge branch 'main' into self-name-redirects
c9cd511
@weswigham

Wesley Wigham (weswigham) commented May 5, 2022

Copy link
Copy Markdown
Member Author

Daniel Rosenwasser (@DanielRosenwasser) updated.

All reactions

Sorry, something went wrong.

Uh oh!

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

DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) approved these changes May 5, 2022
View reviewed changes
@weswigham
Wesley Wigham (weswigham) merged commit 8e433cd into microsoft:main May 5, 2022
@weswigham Wesley Wigham (weswigham) mentioned this pull request Jun 15, 2022
Allow exports map entries to point at .ts source files #48563
Merged
@sheetalkamat Sheetal Nandi (sheetalkamat) mentioned this pull request Jun 30, 2022
Pass module resolution cache from watch mode so that it is set and can be used by program to report error #49749
Closed
@andrewbranch Andrew Branch (andrewbranch) mentioned this pull request May 26, 2023
importing own package from test fails with error TS5055: Cannot write file #54299
Closed
Daniel Finke (danielfinke) added a commit to danielfinke/dynohot that referenced this pull request Feb 8, 2025
@danielfinke
Provide workaround for build in Node mod subtree
a8ce6d8
Build (including in `prepare` script) will fail if the repo is cloned
into a subtree of a `node_modules` directory other than the one
immediately containing dynohot, e.g.

`/a/node_modules/b/node_modules/dynohot`

Due to a TS bug in
https://github.com/microsoft/TypeScript/blob/48f2ada110a697668db7d2d1c11a382b0192d3f9/src/compiler/moduleNameResolver.ts#L2864-L2971

see microsoft/TypeScript#50762
see microsoft/TypeScript#47925
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) DanielRosenwasser approved these changes
@andrewbranch Andrew Branch (andrewbranch) andrewbranch approved these changes
@rbuckton Ron Buckton (rbuckton) Awaiting requested review from rbuckton

Uh oh!

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

Assignees

@weswigham Wesley Wigham (weswigham)

Labels

Author: Team For Milestone Bug PRs that fix a bug with a specific milestone

Projects

PR Backlog
Archived in project

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

--module nodenext self-name references don't work with an outDir from clean build

Uh oh!

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

4 participants

@weswigham @andrewbranch @DanielRosenwasser @typescript-bot
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.