Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion local-cli/cliEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function run() {

commander.parse(process.argv);

const isValidCommand = commands.find(cmd => cmd.name === process.argv[2]);
const isValidCommand = commands.find(cmd => cmd.name.split(" ")[0] === process.argv[2]);

@geof90 geof90 Aug 2, 2016

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is needed because the rnpm commands have additional positional arguments, e.g link <packageName> in their names, therefore a naive full string comparison wouldn't work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like this might be breaking all usages of link ABCD with the RC? If yes, that has to be cherry-picked into stable release.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep. Any chance you could take this whole change?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, actually @rozele submitted a PR fixing that particular thing, mind rebasing in like an hour once the merge finishes?

@geof90 geof90 Aug 3, 2016

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Which PR? I don't think #9173 is related, it only fixes showing the help. When you run the command react-native link react-native-plugin, you would still see the warning because isValidCommand fails to find a command with a name that matches. This fixes that.

I noticed you added "needs-revision", what exactly needs revision? Also, given that this is not the main point of this PR, I would appreciate it if you could comment on the addition of the pre/post unlink hooks :).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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


if (!isValidCommand) {
printUnknownCommand(process.argv[2]);
Expand Down
2 changes: 1 addition & 1 deletion local-cli/rnpm/link/link.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
func: require('./src/link'),
description: 'links all native dependencies',
name: 'link [packageName]',
name: 'link <packageName>',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the packageName argument should remain optional shouldn't it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

for link - yes, for unlink it's mandatory

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

};
1 change: 1 addition & 0 deletions local-cli/rnpm/link/src/commandStub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = (cb) => cb();
6 changes: 2 additions & 4 deletions local-cli/rnpm/link/src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ const copyAssetsIOS = require('./ios/copyAssets');
const getProjectDependencies = require('./getProjectDependencies');
const getDependencyConfig = require('./getDependencyConfig');
const pollParams = require('./pollParams');
const commandStub = require('./commandStub');
const promisify = require('./promisify');

log.heading = 'rnpm-link';

const commandStub = (cb) => cb();
const dedupeAssets = (assets) => uniq(assets, asset => path.basename(asset));

const promisify = (func) => new Promise((resolve, reject) =>
func((err, res) => err ? reject(err) : resolve(res))
);

const linkDependencyAndroid = (androidProject, dependency) => {
if (!androidProject || !dependency.config.android) {
Expand Down
3 changes: 3 additions & 0 deletions local-cli/rnpm/link/src/promisify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (func) => new Promise((resolve, reject) =>
func((err, res) => err ? reject(err) : resolve(res))
);
70 changes: 42 additions & 28 deletions local-cli/rnpm/link/src/unlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ const getDependencyConfig = require('./getDependencyConfig');
const compact = require('lodash').compact;
const difference = require('lodash').difference;
const filter = require('lodash').filter;
const isEmpty = require('lodash').isEmpty;
const find = require('lodash').find;
const flatten = require('lodash').flatten;
const isEmpty = require('lodash').isEmpty;
const promiseWaterfall = require('./promiseWaterfall');
const commandStub = require('./commandStub');
const promisify = require('./promisify');

log.heading = 'rnpm-link';

Expand Down Expand Up @@ -88,33 +92,43 @@ module.exports = function unlink(args, config) {

const allDependencies = getDependencyConfig(config, getProjectDependencies());
const otherDependencies = filter(allDependencies, d => d.name !== packageName);
const thisDependency = find(allDependencies, d => d.name === packageName);
const iOSDependencies = compact(otherDependencies.map(d => d.config.ios));

unlinkDependencyAndroid(project.android, dependency, packageName);
unlinkDependencyIOS(project.ios, dependency, packageName, iOSDependencies);

const assets = difference(
dependency.assets,
flatten(allDependencies, d => d.assets)
);

if (isEmpty(assets)) {
return Promise.resolve();
}

if (project.ios) {
log.info('Unlinking assets from ios project');
unlinkAssetsIOS(assets, project.ios);
}

if (project.android) {
log.info('Unlinking assets from android project');
unlinkAssetsAndroid(assets, project.android.assetsPath);
}

log.info(
`${packageName} assets has been successfully unlinked from your project`
);

return Promise.resolve();
const tasks = [
() => promisify(thisDependency.config.commands.preunlink || commandStub),
() => unlinkDependencyAndroid(project.android, dependency, packageName),
() => unlinkDependencyIOS(project.ios, dependency, packageName, iOSDependencies),
() => promisify(thisDependency.config.commands.postunlink || commandStub)
];

return promiseWaterfall(tasks)
.then(() => {
const assets = difference(
dependency.assets,
flatten(allDependencies, d => d.assets)
);

if (!isEmpty(assets)) {
if (project.ios) {
log.info('Unlinking assets from ios project');
unlinkAssetsIOS(assets, project.ios);
}

if (project.android) {
log.info('Unlinking assets from android project');
unlinkAssetsAndroid(assets, project.android.assetsPath);
}

log.info(
`${packageName} assets has been successfully unlinked from your project`
);
}
})
.catch(err => {
log.error(
`It seems something went wrong while linking. Error: ${err.message}`
);
throw err;
});
};