[rush-resolver-cache] Fix projectFolder on Windows (#4931)

Co-authored-by: David Michon <dmichon-msft@users.noreply.github.com>
This commit is contained in:
David Michon 2024-09-19 17:30:02 -07:00 коммит произвёл GitHub
Родитель 9471818f13
Коммит 476c61e835
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 27 добавлений и 5 удалений

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Fix a bug that caused rush-resolver-cache-plugin to crash on Windows.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}

Просмотреть файл

@ -136,6 +136,15 @@ export interface IComputeResolverCacheFromLockfileOptions {
) => Promise<void>;
}
/**
* Copied from `@rushstack/node-core-library/src/Path.ts` to avoid expensive dependency
* @param path - Path using backslashes as path separators
* @returns The same string using forward slashes as path separators
*/
function convertToSlashes(path: string): string {
return path.replace(/\\/g, '/');
}
/**
* Given a lockfile and information about the workspace and platform, computes the resolver cache file.
* @param params - The options for computing the resolver cache
@ -146,9 +155,9 @@ export async function computeResolverCacheFromLockfileAsync(
): Promise<IResolverCacheFile> {
const { platformInfo, projectByImporterPath, lockfile, afterExternalPackagesAsync } = params;
// Needs to be normalized to `/` for path.posix.join to work correctly
const workspaceRoot: string = params.workspaceRoot.replace(/\\/g, '/');
const workspaceRoot: string = convertToSlashes(params.workspaceRoot);
// Needs to be normalized to `/` for path.posix.join to work correctly
const commonPrefixToTrim: string = params.commonPrefixToTrim.replace(/\\/g, '/');
const commonPrefixToTrim: string = convertToSlashes(params.commonPrefixToTrim);
const contexts: Map<string, IResolverContext> = new Map();
const missingOptionalDependencies: Set<string> = new Set();
@ -218,8 +227,10 @@ export async function computeResolverCacheFromLockfileAsync(
throw new Error(`Missing project for importer ${importerPath}`);
}
const descriptionFileRoot: string = convertToSlashes(project.projectFolder);
const context: IResolverContext = {
descriptionFileRoot: project.projectFolder,
descriptionFileRoot,
descriptionFileHash: undefined, // Not needed anymore
name: project.packageJson.name,
isProject: true,
@ -227,7 +238,7 @@ export async function computeResolverCacheFromLockfileAsync(
ordinal: -1
};
contexts.set(project.projectFolder, context);
contexts.set(descriptionFileRoot, context);
if (importer.dependencies) {
resolveDependencies(workspaceRoot, importer.dependencies, context);

Просмотреть файл

@ -107,7 +107,8 @@ describe(computeResolverCacheFromLockfileAsync.name, () => {
for (const importerPath of lockfile.importers.keys()) {
const remainder: string = importerPath.slice(importerPath.lastIndexOf('../') + 3);
projectByImporterPath.setItem(importerPath, {
projectFolder: `${commonPrefixToTrim.replace(/\\/g, '/')}${remainder}`,
// Normalization is the responsibility of the implementation
projectFolder: `${commonPrefixToTrim}${remainder}`,
packageJson: {
name: `@local/${remainder.replace(/\//g, '+')}`
}