[rush-resolver-cache] Fix Windows compatibility (#4909)

Co-authored-by: David Michon <dmichon-msft@users.noreply.github.com>
This commit is contained in:
David Michon 2024-08-29 11:22:15 -07:00 коммит произвёл GitHub
Родитель c4ed903c2b
Коммит 6cf823c14a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 21 добавлений и 11 удалений

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

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Fix Windows compatibility for `@rushstack/rush-resolver-cache-plugin`.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}

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

@ -144,14 +144,12 @@ export interface IComputeResolverCacheFromLockfileOptions {
export async function computeResolverCacheFromLockfileAsync(
params: IComputeResolverCacheFromLockfileOptions
): Promise<IResolverCacheFile> {
const {
workspaceRoot,
commonPrefixToTrim,
platformInfo,
projectByImporterPath,
lockfile,
afterExternalPackagesAsync
} = params;
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, '/');
// Needs to be normalized to `/` for path.posix.join to work correctly
const commonPrefixToTrim: string = params.commonPrefixToTrim.replace(/\\/g, '/');
const contexts: Map<string, IResolverContext> = new Map();
const missingOptionalDependencies: Set<string> = new Set();

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

@ -23,13 +23,15 @@ interface ITestCase {
const TEST_CASES: readonly ITestCase[] = [
{
// Validate with POSIX-style path inputs
workspaceRoot: '/$root/common/temp/build-tests',
commonPrefixToTrim: '/$root/',
lockfileName: 'build-tests-subspace.yaml'
},
{
workspaceRoot: '/$root/common/temp/default',
commonPrefixToTrim: '/$root/',
// Validate that it works with Windows-style path inputs
workspaceRoot: '\\$root\\common\\temp\\default',
commonPrefixToTrim: '\\$root\\',
lockfileName: 'default-subspace.yaml'
},
{
@ -105,7 +107,7 @@ describe(computeResolverCacheFromLockfileAsync.name, () => {
for (const importerPath of lockfile.importers.keys()) {
const remainder: string = importerPath.slice(importerPath.lastIndexOf('../') + 3);
projectByImporterPath.setItem(importerPath, {
projectFolder: `${commonPrefixToTrim}${remainder}`,
projectFolder: `${commonPrefixToTrim.replace(/\\/g, '/')}${remainder}`,
packageJson: {
name: `@local/${remainder.replace(/\//g, '+')}`
}