Skip to content
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": "[rush-resolver-cache] Ensure that the correct version of rush-lib is loaded when the global version doesn't match the repository version.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function getPlatformInfo(): IPlatformInfo {
}

const END_TOKEN: string = '/package.json":';
const RESOLVER_CACHE_FILE_VERSION: 1 = 1;
const RESOLVER_CACHE_FILE_VERSION: 2 = 2;

interface IExtendedResolverCacheFile extends IResolverCacheFile {
/**
Expand Down Expand Up @@ -94,6 +94,12 @@ export async function afterInstallAsync(
throw new Error(`Failed to load shrinkwrap file: ${lockFilePath}`);
}

if (!lockFile.hash) {
throw new Error(
`Shrinkwrap file does not have a hash. This indicates linking to an old version of Rush.`
);
}

try {
const oldCacheFileContent: string = await FileSystem.readFileAsync(cacheFilePath);
const oldCache: IExtendedResolverCacheFile = JSON.parse(oldCacheFileContent);
Expand Down
19 changes: 10 additions & 9 deletions rush-plugins/rush-resolver-cache-plugin/src/externals.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.

import type Module from 'node:module';

import type { Operation as OperationType, OperationStatus as OperationStatusType } from '@rushstack/rush-sdk';
import type { PnpmShrinkwrapFile as PnpmShrinkwrapFileType } from '@rushstack/rush-sdk/lib/logic/pnpm/PnpmShrinkwrapFile';
import type * as rushSdkType from '@rushstack/rush-sdk';
Expand All @@ -22,27 +20,30 @@ export { Operation, OperationStatus };
// Support this plugin being webpacked.
const req: typeof require = typeof __non_webpack_require__ === 'function' ? __non_webpack_require__ : require;

const entryModule: Module | undefined = req.main;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function getExternal<TResult = any>(name: string): TResult {
const rushLibPath: string | undefined = process.env._RUSH_LIB_PATH;

function importDependency<TResult>(name: string): TResult {
if (!rushLibPath) {
throw new Error(`_RUSH_LIB_PATH variable is not set, cannot resolve rush-lib.`);
}
const externalPath: string = req.resolve(name, {
paths: entryModule?.paths
paths: [rushLibPath]
});

return req(externalPath);
}

// Private Rush APIs
export const { PnpmShrinkwrapFile } = getExternal<
export const { PnpmShrinkwrapFile } = importDependency<
typeof import('@rushstack/rush-sdk/lib/logic/pnpm/PnpmShrinkwrapFile')
>('@microsoft/rush-lib/lib/logic/pnpm/PnpmShrinkwrapFile');
// eslint-disable-next-line @typescript-eslint/no-redeclare
export type PnpmShrinkwrapFile = PnpmShrinkwrapFileType;

// Avoid bundling expensive stuff that's already part of Rush.
export const { Async } = getExternal<typeof import('@rushstack/node-core-library/lib/Async')>(
export const { Async } = importDependency<typeof import('@rushstack/node-core-library/lib/Async')>(
`@rushstack/node-core-library/lib/Async`
);
export const { FileSystem } = getExternal<typeof import('@rushstack/node-core-library/lib/FileSystem')>(
export const { FileSystem } = importDependency<typeof import('@rushstack/node-core-library/lib/FileSystem')>(
`@rushstack/node-core-library/lib/FileSystem`
);
Loading