Skip to content

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

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Fix Windows compatibility for `@rushstack/rush-resolver-cache-plugin`.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
{
Expand Down Expand Up @@ -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, '+')}`
}
Expand Down
Loading