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 — Watch mode watches for changes in package.json files used in resolution by weswigham · Pull Request #44935 · microsoft/TypeScript

Conversation

@weswigham

@weswigham Wesley Wigham (weswigham) commented Jul 7, 2021

Copy link
Copy Markdown
Member

This fixes an issue I noticed while writing tests for cts/mts (and type: module) support - when a package.json changed, we weren't noticing it in watch mode (and consequently weren't invaliding resolutions and rechecking programs) - the fix is somewhat substantial, so is now a separate PR, this. (In build mode, this fix is wholly non-incremental - we'll only pick up changes to package files after we've done a build involving them once, since we pull the data from the resolution cache - we could probably fix this by serializing the list of used package file resolutions for a file/project into the build info, but that seems involved).

cc Andrew Branch (@andrewbranch) since you said including package json files in the normal watched file set may affect/help package autoimports.

Sorry, something went wrong.

Uh oh!

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

All reactions
@weswigham
watch mode watches for changes in package.json files used in resolution
dbc38f5
@weswigham
Wesley Wigham (weswigham) requested review from Andrew Branch (andrewbranch) and Sheetal Nandi (sheetalkamat) July 7, 2021 22:50
@typescript-bot TypeScript Bot (typescript-bot) assigned Wesley Wigham (weswigham) Jul 7, 2021
@typescript-bot TypeScript Bot (typescript-bot) added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jul 7, 2021
@weswigham
Wesley Wigham (weswigham) requested a review from Ron Buckton (rbuckton) July 7, 2021 22:50
andrewbranch
Andrew Branch (andrewbranch) reviewed Jul 8, 2021
View reviewed changes
Comment thread src/compiler/tsbuildPublic.ts Resolved

Uh oh!

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

@weswigham
Pathify result of realpath
77465dc
@weswigham Wesley Wigham (weswigham) mentioned this pull request Jul 12, 2021
cts, mts, cjs, mjs, etc extension support weswigham/TypeScript#67
Closed
@weswigham
Actually accept pathified baselines
258f1f6
andrewbranch
Andrew Branch (andrewbranch) approved these changes Jul 12, 2021
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.

Looks good. Do you know if these same watches get used for editor services? I need to make a to-do for myself to remove the extra watch I added there if so.

Sorry, something went wrong.

Uh oh!

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

All reactions
@weswigham

Wesley Wigham (weswigham) commented Jul 13, 2021

Copy link
Copy Markdown
Member Author

I'm not sure, honestly. I think it depends on if services are constructed using a watch system or not.

All reactions

Sorry, something went wrong.

Uh oh!

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

@weswigham
Wesley Wigham (weswigham) merged commit 8e855d1 into microsoft:main Jul 13, 2021
@andrewbranch Andrew Branch (andrewbranch) mentioned this pull request Aug 30, 2021
Typescript 4.4 leaks watchers #45633
Closed
sheetalkamat
Sheetal Nandi (sheetalkamat) reviewed Mar 17, 2022
View reviewed changes
Comment thread src/compiler/tsbuildPublic.ts
getConfigFileParsingDiagnostics(config),
config.projectReferences
);
state.lastCachedPackageJsonLookups.set(projectPath, state.moduleResolutionCache && map(

@sheetalkamat Sheetal Nandi (sheetalkamat) Mar 17, 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.

Because these package json lookups are calculated when program is built.. If the program was already built and then you change package.json file and invoke tsbuild, the change wont be picked by ts build and it will be reported as upto date.

Also note that ts build uses the infomation from tsconfig to derive if things can be upto date. So we never watch module resolution etc. So this seems one off.
ts build also doesnt mean its incremental build so storing this info in tsbuildinfo is not enough.

Sorry, something went wrong.

Uh oh!

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

All reactions

@weswigham Wesley Wigham (weswigham) Mar 17, 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.

Yep - I said as much in the OP of this PR - node_modules lookups aren't part of the file set calculated by build mode (seems like an oversight, but also super nontrivial to calculate), so we have no idea what files to add to the watch set till we've built a program once and gotten the full file set. Still, this helps pick up changes that happen any time after the first build, which helps a lot in --watch , if not --incremental.

Sorry, something went wrong.

Uh oh!

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

All reactions
@sheetalkamat Sheetal Nandi (sheetalkamat) mentioned this pull request Mar 17, 2022
Tsbuild watching packagejson is dependent on whether program was built in the invocation #48314
Closed
sheetalkamat
Sheetal Nandi (sheetalkamat) reviewed Mar 17, 2022
View reviewed changes
Comment thread src/compiler/watchPublic.ts

// package.json changes invalidate module resolution and can change the set of loaded files
// so if we witness a change to one, we have to do a full reload
reloadLevel = ConfigFileProgramReloadLevel.Full;

@sheetalkamat Sheetal Nandi (sheetalkamat) Mar 17, 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.

This seems incorrect.. Full Reload means read config file again to calculate file names.. Why do we need to do that for package.json changes.
Also changesAffectResolution seems very unoptimized way of saying resolve all modules again. Need smarter way to invalidate resolutions.. Esp when someone is not using the node12+ stuff.. looks like every npm install will be problematic? (it many times spans across multiple updates if its many packages)

Sorry, something went wrong.

Uh oh!

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

All reactions

@weswigham Wesley Wigham (weswigham) Mar 17, 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.

A package.json change can change what arbitrary module specifiers in the program resolve to (when main, exports, or typesVersions change) and which imports are valid in arbitrary files (when type changes), so, yeah, a package.json change can invalidate the whole program.

Sorry, something went wrong.

Uh oh!

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

All reactions

@weswigham Wesley Wigham (weswigham) Mar 17, 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.

And do note, only the exports and type fields are new - we failed to pickup main and typesVersions changes and invalidations from package.json files entirely before. A fix for that actually landed before any of the node12 stuff.

Sorry, something went wrong.

Uh oh!

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

All reactions

@sheetalkamat Sheetal Nandi (sheetalkamat) Mar 17, 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.

But invalidating whole program is different from reading config file and getting initial set which is what ConfigFileProgramReloadLevel.Full means

Sorry, something went wrong.

Uh oh!

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

All reactions

@sheetalkamat Sheetal Nandi (sheetalkamat) Mar 17, 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.

Also package.json main and typeversion use to be rare and we use to watch failed lookups and in most cases that would cover it.. otherwise the npm install would need to re-do module resolutions for whole program.. Wouldnt it be still same that package.json affects certain files for module resolutions and not all.. eg. changing node's package.json shouldnt need to do module resolution in file that doesn't use node stuff..

Sorry, something went wrong.

Uh oh!

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

All reactions

@weswigham Wesley Wigham (weswigham) Mar 17, 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.

package.json main is about as far from "rare" as you can get - every package has one. :P

You would be right that we probably don't need to watch them if moduleResolution isn't node/node12/nodenext though. Not that many people use TS without one of those set, since module: commonjs (and thus moduleResolution: node) is the norm. Except I believe @types resolution unconditionally uses node-style resolution anyway; so I think we actually need to watch the package.json documents in those folders unconditionally...

Sorry, something went wrong.

Uh oh!

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

All reactions
@sheetalkamat Sheetal Nandi (sheetalkamat) mentioned this pull request Mar 17, 2022
Watch Mode: Do we really need full config file read and update on package json change #48315
Closed
sheetalkamat
Sheetal Nandi (sheetalkamat) reviewed Mar 17, 2022
View reviewed changes
Comment thread src/compiler/tsbuildPublic.ts
watchExtendedConfigFiles(state, projectPath, config);
watchWildCardDirectories(state, project, projectPath, config);
watchInputFiles(state, project, projectPath, config);
watchPackageJsonFiles(state, project, projectPath, config);

@sheetalkamat Sheetal Nandi (sheetalkamat) Mar 17, 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.

This is incorrect location for these? Because program is yet not created so this won't be correct list? And all the package.json watches will be deleted.

Sorry, something went wrong.

Uh oh!

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

All reactions

@weswigham Wesley Wigham (weswigham) Mar 17, 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.

How so? This is the only place we add tsbuild watchers, afaik. It's a known limitation that we don't have a full list on first build (or, more like, we have an empty list because we don't have a good way to calculate a list).

Sorry, something went wrong.

Uh oh!

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

All reactions

@sheetalkamat Sheetal Nandi (sheetalkamat) Mar 18, 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.

Because even though project config file was parsed to calculate the new filenames, options etc, the program was not created. that happens later during building of project so this cache is old cache and doing this has no effect?

Sorry, something went wrong.

Uh oh!

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

All reactions
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@sheetalkamat Sheetal Nandi (sheetalkamat) sheetalkamat left review comments
@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 Uncommitted Bug PR for untriaged, rejected, closed or missing bug

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.

4 participants

@weswigham @andrewbranch @sheetalkamat @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.