Skip to content

Commit

Permalink
feat(versions): support npm: alias protocol
Browse files Browse the repository at this point in the history
Closes #151
  • Loading branch information
JamieMason committed Jul 30, 2023
1 parent ce58e3a commit 2a7ef86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/instance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
} from 'npm-package-arg';
import type { Strategy } from '../config/get-custom-types';
import type { PackageJsonFile } from '../get-package-json-files/package-json-file';
import type { Delete } from '../get-version-groups/lib/delete';
import { DELETE, type Delete } from '../get-version-groups/lib/delete';
import { $R } from '../lib/$R';

/** Extends npm/npm-package-arg to support "workspace:*" */
Expand Down Expand Up @@ -88,7 +88,16 @@ export namespace Instance {

/** An `Instance` whose specifier is eg "npm:imageoptim-cli@3.1.7" */
export class AliasInstance extends Data.TaggedClass('AliasInstance')<BaseInstance<AliasResult>> {
setSpecifier = setSpecifier;
setSpecifier(version: string | Delete): void {
if (version === DELETE) {
setSpecifier.call(this, version);
} else {
const subSpec = this.parsedSpecifier.subSpec;
const name = subSpec.name || '';
const specifier = `npm:${name}@${version}`;
setSpecifier.call(this, specifier);
}
}

getSemverSpecifier(): Option.Option<string> {
const subSpec = this.parsedSpecifier.subSpec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('versionGroups', () => {
],
},
},
a: ['yarn@2.0.0', 'yarn@3.0.0'],
a: ['yarn@npm:yarn@2.0.0', 'yarn@npm:yarn@3.0.0'],
b: ['yarn@3.0.0', 'yarn@3.0.0'],
}).forEach((getScenario) => {
describe('versionGroup.inspect()', () => {
Expand Down

0 comments on commit 2a7ef86

Please sign in to comment.