зеркало из https://github.com/microsoft/rushstack.git
[rush-resolver-cache] Fix projectFolder on Windows (#4931)
Co-authored-by: David Michon <dmichon-msft@users.noreply.github.com>
This commit is contained in:
Родитель
9471818f13
Коммит
476c61e835
|
@ -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, '+')}`
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче