Skip to content

Commit

Permalink
Add support for linking scoped packages (#18766) (#19828)
Browse files Browse the repository at this point in the history
Summary:
Currently, when the cli tries to determine the package name, it accidentally trims out the entire package name.  This makes it appear to the rest of the program as if `react-native link The controller you requested could not be found./my-package` was just `react-native link`.  This adds a little regex to prevent that from happening, so that scopes can be passed as parts of packages.

Fixes #18766
Pull Request resolved: #19828

Differential Revision: D8704742

Pulled By: hramos

fbshipit-source-id: d8183f9b55e8656b8a0acae842e1361a1f428102
  • Loading branch information
Tvrqvoise authored and facebook-github-bot committed Aug 6, 2018
1 parent 5219585 commit 6d65e8b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 1 addition & 3 deletions local-cli/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ const defaultRNConfig = {
getDependencyConfig(packageName: string) {
const platforms = this.getPlatformConfig();
const folder = path.join(process.cwd(), 'node_modules', packageName);
const rnpm = getRNPMConfig(
path.join(process.cwd(), 'node_modules', packageName),
);
const rnpm = getRNPMConfig(folder);

let config = Object.assign({}, rnpm, {
assets: findAssets(folder, rnpm.assets),
Expand Down
14 changes: 14 additions & 0 deletions local-cli/link/__tests__/link.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ describe('link', () => {
});
});

it('should accept the name of a dependency with a scope / tag', async () => {
const config = {
getPlatformConfig: () => ({ios: {}, android: {}}),
getProjectConfig: () => ({assets: []}),
getDependencyConfig: sinon.stub().returns({assets: [], commands: {}}),
};

const link = require('../link').func;
await link(['@scope/something@latest'], config);
expect(
config.getDependencyConfig.calledWith('@scope/something'),
).toBeTruthy();
});

it('should register native module when android/ios projects are present', done => {
const registerNativeModule = sinon.stub();
const dependencyConfig = {android: {}, ios: {}, assets: [], commands: {}};
Expand Down
4 changes: 2 additions & 2 deletions local-cli/link/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ function link(args: Array<string>, config: RNConfig) {
}

let packageName = args[0];
// Check if install package by specific version (eg. package@latest)
// Trim the version / tag out of the package name (eg. package@latest)
if (packageName !== undefined) {
packageName = packageName.split('@')[0];
packageName = packageName.replace(/^(.+?)(@.+?)$/gi, '$1');
}

const dependencies = getDependencyConfig(
Expand Down

0 comments on commit 6d65e8b

Please sign in to comment.