Skip to content

Handle packages with binaries - #192

Merged
gigabo merged 2 commits into
lerna:masterfrom
awakesecurity:handle-bins
Aug 10, 2016
Merged

gigabo merged 2 commits into
lerna:masterfrom
awakesecurity:handle-bins

Conversation

@rygine

@rygine rygine commented Jun 8, 2016

Copy link
Copy Markdown
Contributor

Minor refactor of some methods for easier to read code using async.series

@rygine

rygine commented Jun 8, 2016

Copy link
Copy Markdown
Contributor Author

At my company, we've written a few CLI tools that are accessed via NPM scripts in each package. Bootstrapping did not factor this in and they would fail to run.

Comment thread src/commands/BootstrapCommand.js Outdated

this.createLinkedDependency(linkSrc, linkDest, dependency.name, done);
this.createLinkedDependency(linkSrc, linkDest, dependency.name, (err) => {
const bin = dependency._package.bin;

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.

This should check err at the beginning and call done(err) if it exists and stop

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

@rygine

rygine commented Jun 10, 2016

Copy link
Copy Markdown
Contributor Author

i'm noticing that the unit tests are non-deterministic, both locally and travis

@paulyoung

Copy link
Copy Markdown

This is sorely needed! Anything I can do to help move this along?

@rygine

rygine commented Jun 22, 2016

Copy link
Copy Markdown
Contributor Author

@paulyoung, this functionality is actually covered in PR #237 as well.

Comment thread src/commands/BootstrapCommand.js Outdated
this.createLinkedDependency(linkSrc, linkDest, dependency.name, done);
this.createLinkedDependency(linkSrc, linkDest, dependency.name, (err) => {
if (!err && dependency._package.bin) {
const srcBinLocation = path.join(linkSrc, dependency._package.bin);

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.

Would be nice to add a bin getter in src/Package.js for consistency. Then this could be:

const srcBinLocation = path.join(linkSrc, dependency.bin);

@gigabo gigabo Jun 24, 2016 •

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.

Actually, dependency.bin isn't guaranteed to be a string.

Could normalize inside the getter to always return an object. Else the logic here will need to account for that.

@rygine

rygine commented Jun 27, 2016

Copy link
Copy Markdown
Contributor Author

@gigabo This should do it. I also uncovered a potential issue with the ignore flag during bootstrap. Fixed that as well.

  • Added symlink method to FileSystemUtilities
  • Added bin property to Package
  • Updated bootstrap to factor in dependencies with multiple binaries
  • Added test for package with multiple binaries
  • Refactored way ignored packages are determined (to be more like run command)
  • Updated unit test for ignored package

When a package is ignored while bootstrapping, it should be completely taken out of the equation. This update alters the previous behavior of not bootstrapping an ignored package, but still treating it as though it was part of the process. If a package is ignored, it should be treated as an external dependency. The updated unit test reflects this.

@gigabo

gigabo commented Jun 27, 2016

Copy link
Copy Markdown
Contributor

If a package is ignored, it should be treated as an external dependency.

Hmm... that's actually not what I'd naively expect. 😕

I'd expect "ignore package foo" to skip doing anything in packages/foo, but to do the normal things in package/bar, including linking foo as an in-repo dep. Am I just misunderstanding the --ignore flag?

@rygine

rygine commented Jun 27, 2016

Copy link
Copy Markdown
Contributor Author

@gigabo that's a good question. what exactly does ignore mean?

my initial thought was that it doesn't get any of its dependencies "linked" in the bootstrap, but i'm not sure that makes sense.

for example, check out this scenario:

  • packageA depends on packageB
  • packageC depends on packageA

i run bootstrap and ignore packageA, which means that packageA does not have a "linked" or installed version of packageB. meanwhile, i bootstrap packageC and "link" to packageA like normal. now, when i import packageA into packageC, packageB will not be imported as no form of it exists in packageA/node_modules/.

under the new scenario, packageA would be installed as an external dependency of packageC and all would be well. i don't see much use for the ignore flag during bootstrap except for some edge-cases when you simply want to disregard a module.

it is a bit confusing to think about. once i realized how things would be bootstrapped when you ignore a package, i'm not sure the original way of doing it would actually work.

@gigabo

gigabo commented Jun 27, 2016

Copy link
Copy Markdown
Contributor

@rygine - The behavior or --ignore is worth examining, but seems unrelated to handling packages with binaries. Can that part be pulled out into a separate issue or PR?

@rygine

rygine commented Jun 28, 2016

Copy link
Copy Markdown
Contributor Author

@gigabo makes sense. amended the commit.

Minor refactor of some methods for easier to read code using `async.series`
const todoPackages = PackageUtilities.filterPackages(this.packages, ignore, true);

// Get a trimmed down graph that includes only those packages.
const filteredGraph = PackageUtilities.getPackageGraph(todoPackages);

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 slightly unrelated to the PR, but i moved the package filtering to the initialize method to mimic the behavior of lerna run for consistency.

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.

unrelated to the PR

Generally speaking, smaller more targeted PRs are easier to review and therefore tend to get merged more quickly.

This PR adds much needed functionality, but it has gone through a number of iterations that each included a different set of unrelated changes. These other changes may also be valuable, but it would be easier to consider them on their own merit if they were showcased in dedicated PRs.

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.

point taken. amended.

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.

Thanks, that makes it easier to read. 👍

// if package has dependencies with binaries
if (depsWithBin.length) {
// symlink binaries
actions.push(cb => this.symlinkDependencyBinaries(pkg, depsWithBin, cb));

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.

I think the binaries should be linked before runPrepublishForPackage.

A package may have a prepublish script that uses a binary from a dependency.

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.

make sense.

* Added `symlink` method to FileSystemUtilities
* Added `bin` property to Package
* Updated bootstrap to factor in dependencies with multiple binaries
* Added test for package with multiple binaries
* Updated unit test for ignored package
@rygine

rygine commented Jul 6, 2016

Copy link
Copy Markdown
Contributor Author

@gigabo I addressed your comments with an amended commit. For future reference, should I continue to amend commits, or just make another one for things like this?

@rygine rygine mentioned this pull request Jul 12, 2016
@gigabo

gigabo commented Aug 1, 2016

Copy link
Copy Markdown
Contributor

should I continue to amend commits, or just make another one for things like this?

From my perspective it's nice to have a new commit so I can see clearly what changed. PRs are typically squashed during merge, so it won't clutter the commit history on master.

@gigabo

gigabo commented Aug 1, 2016

Copy link
Copy Markdown
Contributor

@hzoo, @thejameskyle - Anything else you'd like to see here? I want to use this!

@hzoo hzoo mentioned this pull request Aug 8, 2016
gigabo added a commit to gigabo/lerna that referenced this pull request Aug 8, 2016
This is an attempt to get lerna#192 merged by trimming extraneous changes to slim
down the diff.

None of the following changes reflect _disapproval_ of the code in the
original PR.  This is pure change-set minimization.

Changes:
- Revert incidental code reorganization in:
    - `createLinkDependency`
    - `linkDependencies`
    - `createLinkedDependencyFiles`
- Thin interface of `createBinaryLink`
- Eliminate unused optional argument to `FileSystemUtilities.symlink`
- Simplify `createBinaryLink`
- Remove jsdoc comments

The with this patch the diff against master is now pure addition.
gigabo added a commit to gigabo/lerna that referenced this pull request Aug 8, 2016
This is an attempt to get @rygine's lerna#192 merged by trimming extraneous changes
to slim down the diff.

None of the following changes reflect _disapproval_ of the code in the
original PR.  This is pure change-set minimization.

Changes:
- Revert incidental code reorganization in:
    - `createLinkDependency`
    - `linkDependencies`
    - `createLinkedDependencyFiles`
- Thin interface of `createBinaryLink`
- Eliminate unused optional argument to `FileSystemUtilities.symlink`
- Simplify `createBinaryLink`
- Remove jsdoc comments

The with this patch the diff against master is now pure addition.
gigabo added a commit to gigabo/lerna that referenced this pull request Aug 8, 2016
This is an attempt to get @rygine's lerna#192 merged by trimming extraneous changes
to slim down the diff and ease review.

None of the following changes reflect _disapproval_ of the code in the
original PR.  This is pure change-set minimization.

Changes:
- Revert incidental code reorganization in:
    - `createLinkDependency`
    - `linkDependencies`
    - `createLinkedDependencyFiles`
- Thin interface of `createBinaryLink`
- Eliminate unused optional argument to `FileSystemUtilities.symlink`
- Simplify `createBinaryLink`
- Remove jsdoc comments

With this patch the diff against master is now pure addition.
@gigabo

gigabo commented Aug 10, 2016

Copy link
Copy Markdown
Contributor

Taking #300 (comment) as a 👍 here.

Thanks for sticking with this @rygine. This is a big improvement!

@gigabo
gigabo merged commit 8ba4ae7 into lerna:master Aug 10, 2016
gigabo added a commit to gigabo/lerna that referenced this pull request Aug 10, 2016
This is an attempt to get @rygine's lerna#192 merged by trimming extraneous changes
to slim down the diff and ease review.

None of the following changes reflect _disapproval_ of the code in the
original PR.  This is pure change-set minimization.

Changes:
- Revert incidental code reorganization in:
    - `createLinkDependency`
    - `linkDependencies`
    - `createLinkedDependencyFiles`
- Thin interface of `createBinaryLink`
- Eliminate unused optional argument to `FileSystemUtilities.symlink`
- Simplify `createBinaryLink`
- Remove jsdoc comments

With this patch the diff against master is now pure addition.
gigabo added a commit that referenced this pull request Aug 10, 2016
This is an attempt to get @rygine's #192 merged by trimming extraneous changes
to slim down the diff and ease review.

None of the following changes reflect _disapproval_ of the code in the
original PR.  This is pure change-set minimization.

Changes:
- Revert incidental code reorganization in:
    - `createLinkDependency`
    - `linkDependencies`
    - `createLinkedDependencyFiles`
- Thin interface of `createBinaryLink`
- Eliminate unused optional argument to `FileSystemUtilities.symlink`
- Simplify `createBinaryLink`
- Remove jsdoc comments

With this patch the diff against master is now pure addition.
gigabo added a commit to gigabo/react-server that referenced this pull request Aug 11, 2016
This picks up lerna/lerna#192 which lets us simplify
our use of the CLI within the repo.
gigabo added a commit to redfin/react-server that referenced this pull request Aug 12, 2016
This picks up lerna/lerna#192 which lets us simplify
our use of the CLI within the repo.
@rygine
rygine deleted the handle-bins branch August 12, 2016 21:42
@lock

lock Bot commented Dec 28, 2018

Copy link
Copy Markdown

This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked as resolved and limited conversation to collaborators Dec 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants