Skip to content

Tweak module resolution failed lookup watching #53591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 13, 2023
Merged

Conversation

sheetalkamat
Copy link
Member

This simplifies unnecessary extension watching from long ago when we had different resolutions based on .ts and .js files
Before we would never watch directories like c:/typescript/node_modules or /user/username/typescript/node_modules because we didnt watch folders like c:/typescript or /user/username/typescript. Now changed to watch node_modules in root folder. (We wont watch it at root unless tsconfig is at the root)

This should help with some of the npm ci issues in repo encountered if typescript repo was at root or in another folder .

@sheetalkamat sheetalkamat changed the title [WIP] Tweak module resolution failed lookup watching Tweak module resolution failed lookup watching Apr 10, 2023
@sheetalkamat sheetalkamat marked this pull request as ready for review April 10, 2023 21:46
@@ -205,6 +206,30 @@ export function removeIgnoredPath(path: Path): Path | undefined {
path;
}

function perceivedOsRootLengthForWatching(pathComponents: Readonly<PathPathComponents>, length: number) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This logic is same as before except it returns number of components that are roots for watching. Like c:\users\someUserName or in case of linux /anything/anything etc. So we would never watch anything in those directories.

if (length === undefined) length = pathComponents.length;
// Ignore "/", "c:/"
// ignore "/user", "c:/users" or "c:/folderAtRoot"
if (length <= 2) return false;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is just fast fail as root would alreast be 1

dir: failedLookupSplit.slice(0, rootSplitLength + 1).join(directorySeparator),
dirPath: failedLookupPathSplit.slice(0, rootSplitLength + 1).join(directorySeparator) as Path
};
return getDirectoryOfFailedLookupWatch(failedLookupComponents, failedLookupPathComponents, Math.max(rootPathComponents.length + 1, perceivedOsRootLength + 1));
Copy link
Member Author

@sheetalkamat sheetalkamat Apr 10, 2023

Choose a reason for hiding this comment

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

This helps with not watching "/users" when "/" is root directory (math.max part)

@jakebailey
Copy link
Member

Truthfully I'm a little out of my element in trying to review this; is this something I could just build locally and try the npm ci on our repo? Is that what this intends to fix?

@sheetalkamat
Copy link
Member Author

Yes . This should fix npm ci on our repo

@sheetalkamat
Copy link
Member Author

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 11, 2023

Heya @sheetalkamat, I've started to run the tarball bundle task on this PR at 5b0cbcc. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 11, 2023

Hey @sheetalkamat, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/152125/artifacts?artifactName=tgz&fileId=6CDA8996ADB377AF67813D7C28A2E301450030BA5B9818A3BE814629D6FA875702&fileName=/typescript-5.1.0-insiders.20230411.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/[email protected]".;

@jakebailey
Copy link
Member

It seems like it works, but, testing TS at nightly and stable, I can't actually get the bad behavior on npm ci anymore... I have somehow forgotten what my original repro was if it wasn't that...

@sandersn
Copy link
Member

If we don't have a repro for Typescript itself, is this still needed? From the description it sounds like the new way is strictly better even if it doesn't unblock us personally.

@jakebailey
Copy link
Member

Oh, I don't have a problem with taking this of course, I'm just annoyed that I seemingly forgot what it was I was doing that this fixed

@sheetalkamat
Copy link
Member Author

sheetalkamat commented Apr 13, 2023

@jakebailey i think it will repro if you host typescript at c:/typescript instead of something like c:/github/typescript and keep sys.ts open in editor when doing npm ci. This repro works from me on main but not with the branch

@jakebailey
Copy link
Member

Oh, huh. I've never checked out TS at that level before, so, would this not apply to the issue that I was having with npm ci? I mean, I can't make it happen anymore in my normal setup, so, maybe it's fixed? (Or just sporadic?)

But, trying it out at that level, and it definitely breaks before and works afterward. So, it's definitely an improvement!

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

Behavior wise this seems good to me; I gave the code a few looks over and didn't see anything particularly off but I'm also not an expert so I'm letting tests guide me 😄

Andrew may have a better idea about this bit.

@sheetalkamat
Copy link
Member Author

@andrewbranch do you mind taking a look at this so i can get this in.

@sheetalkamat
Copy link
Member Author

Merging for now and will fix feedback from @andrewbranch in another PR so its in nightly and can make it into beta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants