When installing unrelated package inside scoped packages dont invalidate resolutions from everything in the scoped package (#53873)

This commit is contained in:
Sheetal Nandi
2023-04-17 12:37:32 -07:00
committed by GitHub
parent 020ce0c08c
commit 53d378720a
4 changed files with 548 additions and 6 deletions

View File

@@ -1889,7 +1889,7 @@ export function pathContainsNodeModules(path: string): boolean {
*
* @internal
*/
export function parseNodeModuleFromPath(resolved: string): string | undefined {
export function parseNodeModuleFromPath(resolved: string, isFolder?: boolean): string | undefined {
const path = normalizePath(resolved);
const idx = path.lastIndexOf(nodeModulesPathPart);
if (idx === -1) {
@@ -1897,16 +1897,16 @@ export function parseNodeModuleFromPath(resolved: string): string | undefined {
}
const indexAfterNodeModules = idx + nodeModulesPathPart.length;
let indexAfterPackageName = moveToNextDirectorySeparatorIfAvailable(path, indexAfterNodeModules);
let indexAfterPackageName = moveToNextDirectorySeparatorIfAvailable(path, indexAfterNodeModules, isFolder);
if (path.charCodeAt(indexAfterNodeModules) === CharacterCodes.at) {
indexAfterPackageName = moveToNextDirectorySeparatorIfAvailable(path, indexAfterPackageName);
indexAfterPackageName = moveToNextDirectorySeparatorIfAvailable(path, indexAfterPackageName, isFolder);
}
return path.slice(0, indexAfterPackageName);
}
function moveToNextDirectorySeparatorIfAvailable(path: string, prevSeparatorIndex: number): number {
function moveToNextDirectorySeparatorIfAvailable(path: string, prevSeparatorIndex: number, isFolder: boolean | undefined): number {
const nextSeparatorIndex = path.indexOf(directorySeparator, prevSeparatorIndex + 1);
return nextSeparatorIndex === -1 ? prevSeparatorIndex : nextSeparatorIndex;
return nextSeparatorIndex === -1 ? isFolder ? path.length : prevSeparatorIndex : nextSeparatorIndex;
}
function loadModuleFromFileNoPackageId(extensions: Extensions, candidate: string, onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {