Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Handle packages from organizations on link #1138

Merged
merged 1 commit into from
Jul 22, 2019
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
13 changes: 11 additions & 2 deletions packages/cli/src/models/dependency/Dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class Dependency {
private _projectFile: ProjectFile;

public static fromNameWithVersion(nameAndVersion: string): Dependency {
const [name, version] = nameAndVersion.split('@');
const [name, version] = this.splitNameAndVersion(nameAndVersion);
return new this(name, version);
}

Expand All @@ -55,7 +55,7 @@ export default class Dependency {
const networkDependencies = new NetworkFile(null, network, networkFileName).dependencies;
const hasDependenciesForDeploy = dependencies.find(
(depNameAndVersion): any => {
const [name, version] = depNameAndVersion.split('@');
const [name, version] = this.splitNameAndVersion(depNameAndVersion);
const dependency = new Dependency(name);
const networkFilePath = dependency.getExistingNetworkFilePath(network);
const projectDependency = networkDependencies[name];
Expand All @@ -74,6 +74,15 @@ export default class Dependency {
return this.fromNameWithVersion(nameAndVersion);
}

public static splitNameAndVersion(nameAndVersion: string): [string, string] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static splitNameAndVersion(nameAndVersion: string): [string, string] {
public static splitNameAndVersion(nameAndVersion: string): [string, string] {
const isOrg = nameAndVersion.startsWith('@');
const [name, version] = (isOrg ? nameAndVersion.slice(1) : nameAndVersion).split('@');
return [isOrg ? `@${name}` : name, version];
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm why the extra indentation? Looks odd.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A glitch during copy-paste. Github actually doesn't allow to make multiple line suggestions yet.

const parts = nameAndVersion.split('@');
if (parts[0].length === 0) {
parts.shift();
parts[0] = `@${parts[0]}`;
}
return [parts[0], parts[1]];
}

public constructor(name: string, requirement?: string | semver.Range) {
this.name = name;
this._networkFiles = {};
Expand Down
22 changes: 22 additions & 0 deletions packages/cli/test/models/Dependency.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ contract('Dependency', function([_, from]) {
});
});

describe('#splitNameAndVersion', function () {
it('parses package name', function () {
Dependency.splitNameAndVersion('foo').should.deep.eq(['foo', undefined]);
});

it('parses package name and version', function () {
Dependency.splitNameAndVersion('[email protected]').should.deep.eq(['foo', '1.2.3']);
});

it('parses organization package', function () {
Dependency.splitNameAndVersion('@org/foo').should.deep.eq(['@org/foo', undefined]);
});

it('parses organization package with version', function () {
Dependency.splitNameAndVersion('@org/[email protected]').should.deep.eq(['@org/foo', '1.2.3']);
});

it('parses organization package with version and prerelease tag', function () {
Dependency.splitNameAndVersion('@org/[email protected]').should.deep.eq(['@org/foo', '1.2.3-rc.1']);
});
});

describe('#install', function() {
it('calls npm install', async function() {
const npmInstallStub = sinon.stub(npm, 'install');
Expand Down