Skip to content

Commit

Permalink
Use tarball path instead of id for determining the path in .local, ad…
Browse files Browse the repository at this point in the history
…d more comments
  • Loading branch information
sachinjoseph committed Jul 10, 2019
1 parent b545a6b commit b3900a9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
48 changes: 33 additions & 15 deletions apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export class PnpmLinkManager extends BaseLinkManager {
rushLinkJson: IRushLinkJson,
pnpmShrinkwrapFile: PnpmShrinkwrapFile | undefined): Promise<void> {

if (!pnpmShrinkwrapFile) {
throw new InternalError(`Shrinkwrap is undefined."`);
}

// first, read the temp package.json information

// Example: "project1"
Expand Down Expand Up @@ -158,44 +162,58 @@ export class PnpmLinkManager extends BaseLinkManager {
// file:projects/build-tools.tgz_dc21d88642e18a947127a751e00b020a
// file:projects/imodel-from-geojson.tgz_request@2.88.0
const topLevelDependencyVersion: string | undefined =
pnpmShrinkwrapFile!.getTopLevelDependencyVersion(project.tempProjectName);
pnpmShrinkwrapFile.getTopLevelDependencyVersion(project.tempProjectName);

if (!topLevelDependencyVersion) {
throw new InternalError(`Cannot find top level dependency for "${project.tempProjectName}"` +
` in shrinkwrap.`);
}

const packageId: string | undefined = pnpmShrinkwrapFile!.getPackageId(topLevelDependencyVersion);
// e.g.: file:projects/project-name.tgz
const tarballEntry: string | undefined = pnpmShrinkwrapFile.getTarballPath(topLevelDependencyVersion);

// e.g.: projects\api-documenter.tgz
const relativePathToTgzFile: string = packageId
? packageId.slice('file:'.length)
: topLevelDependencyVersion.slice('file:'.length);

if (packageId) {
relativePathToTgzFile = packageId.slice('file:'.length);
} else {
relativePathToTgzFile = topLevelDependencyVersion.slice('file:'.length);
if (!tarballEntry) {
throw new InternalError(`Cannot find tarball path for "${topLevelDependencyVersion}"` +
` in shrinkwrap.`);
}

// e.g.: projects\api-documenter.tgz
const relativePathToTgzFile: string | undefined = tarballEntry.slice(`file:`.length);

// e.g.: C:\wbt\common\temp\projects\api-documenter.tgz
const absolutePathToTgzFile: string = path.resolve(this._rushConfiguration.commonTempFolder, relativePathToTgzFile);

// The folder name in `.local` is constructed as:
// UriEncode(absolutePathToTgzFile) + _suffix
//
// Note that _suffix is not encoded. The tarball attribute of the package 'file:projects/project-name.tgz_suffix'
// holds the tarball path 'file:projects/project-name.tgz', which can be used for the constructing the folder name.
//
// '_suffix' is extracted by stripping the tarball path from top level dependency value.
// tarball path = 'file:projects/project-name.tgz'
// top level dependency = 'file:projects/project-name.tgz_suffix'

// e.g.:
// '' [empty string]
// _jsdom@11.12.0
// _2a665c89609864b4e75bc5365d7f8f56
const folderNameSuffix: string = (tarballEntry && tarballEntry.length < topLevelDependencyVersion.length ?
topLevelDependencyVersion.slice(tarballEntry.length) : '');

// e.g.:
// C%3A%2Fwbt%2Fcommon%2Ftemp%2Fprojects%2Fapi-documenter.tgz
// C%3A%2Fdev%2Fimodeljs%2Fimodeljs%2Fcommon%2Ftemp%2Fprojects%2Fpresentation-integration-tests.tgz_jsdom@11.12.0
// C%3A%2Fdev%2Fimodeljs%2Fimodeljs%2Fcommon%2Ftemp%2Fprojects%2Fbuild-tools.tgz_2a665c89609864b4e75bc5365d7f8f56
const dirNameInLocal: string = uriEncode(Text.replaceAll(absolutePathToTgzFile, path.sep, '/')) +
(packageId && packageId.length < topLevelDependencyVersion.length ?
topLevelDependencyVersion.slice(packageId.length) : '');
const folderNameInLocalInstallationRoot: string = uriEncode(Text.replaceAll(absolutePathToTgzFile, path.sep, '/')) +
folderNameSuffix;

// tslint:disable-next-line:max-line-length
// e.g.: C:\wbt\common\temp\node_modules\.local\C%3A%2Fwbt%2Fcommon%2Ftemp%2Fprojects%2Fapi-documenter.tgz\node_modules
const pathToLocalInstallation: string = path.join(
this._rushConfiguration.commonTempFolder,
RushConstants.nodeModulesFolderName,
'.local',
dirNameInLocal,
folderNameInLocalInstallationRoot,
RushConstants.nodeModulesFolderName);

for (const dependencyName of Object.keys(commonPackage.packageJson!.dependencies || {})) {
Expand Down
16 changes: 8 additions & 8 deletions apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ interface IPnpmShrinkwrapDependencyYaml {
};
/** The list of dependencies and the resolved version */
dependencies: { [dependency: string]: string };
id: string;
}

/**
Expand Down Expand Up @@ -147,18 +146,19 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
}

/**
* Gets the version number from the list of top-level dependencies in the "dependencies" section
* of the shrinkwrap file
* Gets the path to the tarball file if the package is a tarball,
* otherwise returns undefined. Example: file:projects/build-tools.tgz
*/
public getTopLevelDependencyVersion(dependencyName: string): string | undefined {
return BaseShrinkwrapFile.tryGetValue(this._shrinkwrapJson.dependencies, dependencyName);
public getTarballPath(packageName: string): string | undefined {
return this._shrinkwrapJson.packages[packageName].resolution.tarball;
}

/**
* Gets the id of the specified package
* Gets the version number from the list of top-level dependencies in the "dependencies" section
* of the shrinkwrap file
*/
public getPackageId(packageName: string): string | undefined {
return this._shrinkwrapJson.packages[packageName].id;
public getTopLevelDependencyVersion(dependencyName: string): string | undefined {
return BaseShrinkwrapFile.tryGetValue(this._shrinkwrapJson.dependencies, dependencyName);
}

/**
Expand Down

0 comments on commit b3900a9

Please sign in to comment.