|
1 | 1 | import * as yaml from 'js-yaml';
|
2 | 2 | import * as os from 'os';
|
3 | 3 | import * as semver from 'semver';
|
4 |
| -import { PackageName, FileSystem } from '@microsoft/node-core-library'; |
| 4 | +import { FileSystem } from '@microsoft/node-core-library'; |
5 | 5 |
|
6 | 6 | import { BaseShrinkwrapFile } from '../base/BaseShrinkwrapFile';
|
7 | 7 |
|
@@ -162,7 +162,14 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
|
162 | 162 |
|
163 | 163 | /**
|
164 | 164 | * Gets the version number from the list of top-level dependencies in the "dependencies" section
|
165 |
| - * of the shrinkwrap file |
| 165 | + * of the shrinkwrap file. Sample return values: |
| 166 | + * '2.1.113' |
| 167 | + |
| 168 | + * '5.0.0_25c559a5921686293a001a397be4dce0' |
| 169 | + * 'file:projects/empty-webpart-project.tgz' |
| 170 | + |
| 171 | + * 'file:projects/i18n-utilities.tgz_462eaf34881863298955eb323c130fc7' |
| 172 | + * undefined |
166 | 173 | */
|
167 | 174 | public getTopLevelDependencyVersion(dependencyName: string): string | undefined {
|
168 | 175 | return BaseShrinkwrapFile.tryGetValue(this._shrinkwrapJson.dependencies, dependencyName);
|
@@ -191,7 +198,13 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
|
191 | 198 | // Because of this, we actually need to check for a version that this package is directly
|
192 | 199 | // linked to.
|
193 | 200 |
|
194 |
| - const tempProjectDependencyKey: string = this._getTempProjectKey(tempProjectName); |
| 201 | + const tempProjectDependencyKey: string | undefined = this.getTopLevelDependencyVersion(tempProjectName); |
| 202 | + |
| 203 | + if (!tempProjectDependencyKey) { |
| 204 | + throw new Error(`Cannot get dependency key for temp project: ` |
| 205 | + + `${tempProjectName}`); |
| 206 | + } |
| 207 | + |
195 | 208 | const packageDescription: IPnpmShrinkwrapDependencyYaml | undefined =
|
196 | 209 | this._getPackageDescription(tempProjectDependencyKey);
|
197 | 210 | if (!packageDescription) {
|
@@ -259,7 +272,13 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
|
259 | 272 | * Returns the version of a dependency being used by a given project
|
260 | 273 | */
|
261 | 274 | private _getDependencyVersion(dependencyName: string, tempProjectName: string): string | undefined {
|
262 |
| - const tempProjectDependencyKey: string = this._getTempProjectKey(tempProjectName); |
| 275 | + const tempProjectDependencyKey: string | undefined = this.getTopLevelDependencyVersion(tempProjectName); |
| 276 | + |
| 277 | + if (!tempProjectDependencyKey) { |
| 278 | + throw new Error(`Cannot get dependency key for temp project: ` |
| 279 | + + `${tempProjectName}`); |
| 280 | + } |
| 281 | + |
263 | 282 | const packageDescription: IPnpmShrinkwrapDependencyYaml | undefined =
|
264 | 283 | this._getPackageDescription(tempProjectDependencyKey);
|
265 | 284 | if (!packageDescription) {
|
@@ -292,12 +311,6 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
|
292 | 311 | return semver.valid(validDependencyVersion) ? validDependencyVersion : dependencyVersion.split('_')[0]!;
|
293 | 312 | }
|
294 | 313 |
|
295 |
| - private _getTempProjectKey(tempProjectName: string): string { |
296 |
| - // Example: "project1" |
297 |
| - const unscopedTempProjectName: string = PackageName.getUnscopedName(tempProjectName); |
298 |
| - return `file:projects/${unscopedTempProjectName}.tgz`; |
299 |
| - } |
300 |
| - |
301 | 314 | private _normalizeDependencyVersion(dependencyName: string, version: string): string | undefined {
|
302 | 315 | if (version) {
|
303 | 316 | const extractedVersion: string | undefined = extractVersionFromPnpmVersionSpecifier(version);
|
|
0 commit comments