Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for npm ci to lerna bootstrap #1324

Closed
casey-speer opened this issue Mar 14, 2018 · 21 comments
Closed

Add support for npm ci to lerna bootstrap #1324

casey-speer opened this issue Mar 14, 2018 · 21 comments

Comments

@casey-speer
Copy link

casey-speer commented Mar 14, 2018

Npm 5.7 includes a new install command, npm ci, that installs dependencies directly by scanning the package-lock.json and foregoes any additional dependency resolution. This can be much much faster than running the usual npm install, saving time on build. Lerna should have an option to use this command instead of npm install when running lerna bootstrap.

Expected Behavior

Able to use npm ci on request to install packages with lerna bootstrap.

Current Behavior

Currently bootstrap uses only the npm install command to install packages.

Possible Solution

Add a --npm-ci flag or similar to the bootstrap command that causes it to use npm ci instead of npm install when present.

Context

In a CI environment, we wish to have builds run as quickly as possible and npm ci is faster than npm install.

@evocateur
Copy link
Member

I would just skip lerna bootstrap completely. Use relative file: specifiers between your dependencies, npm i packages/* in the root, and call npm ci* directly. Lerna itself does exactly this.

* Caveat:
Until npm 5.8.0 becomes latest, there is a bug in npm ci that mangles local file: directory package.jsons. Installing either npm@next or cipm (and running it instead of npm ci) will workaround this problem for the time being.

@casey-speer
Copy link
Author

Hmmm maybe I'm missing something about file: specifiers, but wouldn't this mean that I have to always manually include the file: dependencies of a package X from my lerna repo in any host app that wants to use X?

@evocateur
Copy link
Member

Nope, the file: specifiers are overwritten with the current version range during lerna publish, so they're fully-functional npm packages that you treat like any other when consuming. (The versioned source code always preserves the file: specifiers)

Compare @lerna/cli's dependencies:

source:

  "dependencies": {
    "@lerna/add": "file:../../commands/add",
    "@lerna/bootstrap": "file:../../commands/bootstrap",
    "@lerna/changed": "file:../../commands/changed",
    "@lerna/clean": "file:../../commands/clean",
    "@lerna/diff": "file:../../commands/diff",
    "@lerna/exec": "file:../../commands/exec",
    "@lerna/global-options": "file:../global-options",
    "@lerna/import": "file:../../commands/import",
    "@lerna/init": "file:../../commands/init",
    "@lerna/link": "file:../../commands/link",
    "@lerna/list": "file:../../commands/list",
    "@lerna/publish": "file:../../commands/publish",
    "@lerna/run": "file:../../commands/run",
    "dedent": "^0.7.0",
    "is-ci": "^1.0.10",
    "npmlog": "^4.1.2",
    "yargs": "^11.0.0"
  }

npm v --json @lerna/cli dependencies:

{
  "@lerna/add": "^3.0.0-beta.3",
  "@lerna/bootstrap": "^3.0.0-beta.3",
  "@lerna/changed": "^3.0.0-beta.3",
  "@lerna/clean": "^3.0.0-beta.3",
  "@lerna/diff": "^3.0.0-beta.3",
  "@lerna/exec": "^3.0.0-beta.3",
  "@lerna/global-options": "^3.0.0-beta.3",
  "@lerna/import": "^3.0.0-beta.3",
  "@lerna/init": "^3.0.0-beta.3",
  "@lerna/link": "^3.0.0-beta.3",
  "@lerna/list": "^3.0.0-beta.3",
  "@lerna/publish": "^3.0.0-beta.3",
  "@lerna/run": "^3.0.0-beta.3",
  "dedent": "^0.7.0",
  "is-ci": "^1.0.10",
  "npmlog": "^4.1.2",
  "yargs": "^11.0.0"
}

@casey-speer
Copy link
Author

Perfect I'll give this a shot, thanks!

@reggi
Copy link

reggi commented Mar 16, 2018

When I use this method mainly switching to file and npm i packages/* the binaries are not located for each file, so scripts are failing :(

npm i packages/* && lerna bootstrap --hoist

This sorta fills in the cracks, but it's throwing a lot of errors.

@evocateur
Copy link
Member

evocateur commented Mar 16, 2018 via email

@reggi
Copy link

reggi commented Mar 16, 2018

@evocateur My issue with npm i packages/* is that it's not installing dev-deps, any idea how to fix that?

@evocateur
Copy link
Member

Move all the devDependencies to the root package.json.

@reggi
Copy link

reggi commented Mar 19, 2018

@evocateur when I run npm i packages/* then edit my package the packages that used the edited package still are referencing the version that was installed. How am I supposed to bypass this to allow the packages to be updated and have all the references to file: reflect the "live" copy of the module.

@evocateur
Copy link
Member

@reggi I need an actual example to debug, I have no (possible) answer other than "works on my repo". Local file: dependencies should show up as symlinks under the root node_modules, otherwise they're being clobbered by other dependencies.

You also need all of the leaf packages to specify their sibling dependencies as relative file: specifiers; if they are caret versions (like lerna bootstrap --hoist needs) they will fail because they're installing from npm.

@reggi
Copy link

reggi commented Mar 19, 2018

Is it possible that npm 3 does not symlink filemodules, while 5 does?

@evocateur
Copy link
Member

Correct, this pattern is npm5 only.

@jeremiahrhall
Copy link

For repos with a large number of entries in lerna.json's packages configuration, this approach is complicated. Is there really no desire to make it possible to use npm ci instead of install?

@evocateur
Copy link
Member

evocateur commented Mar 23, 2018 via email

vojtechsimetka added a commit to Giveth/giveth-dapp that referenced this issue Jul 2, 2018
vojtechsimetka added a commit to Giveth/giveth-dapp that referenced this issue Jul 8, 2018
* develop: (68 commits)
  Added support for absolute paths.
  update develop config
  Added Error boundary component which should catch all render errors and uncaught throws.
  Fixes #409 - Faucet link now opens in new window/tab
  Some style tweaks
  Commented out the warning header
  Fix issue where user profile showed all milestones and marked reviewer incorrectly
  Donations, campaign and DAC required transactions
  Campaign managers can now accept proposed milestones.
  Fix eslint issues.
  Fixed travis by switching back to npm. The install step should be changed to `npm ci` once this is fixed lerna/lerna#1324 .
  Added required confirmation count
  Update EditDAC.jsx
  update bridge addy
  add beta configuration
  Add validations for templates
  Initial changes to views for campaign, Donations
  Use default quill dropdown
  fix feathers endpoint in release config
  donations and roles on profile page
  ...

# Conflicts:
#	src/index.js
#	src/services/DonationService.js
@RobertWSaunders
Copy link
Contributor

I think this can be closed now that #1360 added it?

@evocateur
Copy link
Member

@RobertWSaunders Yes, thanks!

@RobertWSaunders
Copy link
Contributor

@evocateur Can you think of any reason why running lerna bootstrap --ci locally works fine but when running the same command in CircleCI it's failing. I get this error:

npm install --unsafe-perm || ((if [ -f npm-debug.log ]; then cat npm-debug.log; fi) && false) && lerna bootstrap --ci


> husky@1.0.0-rc.14 install /home/circleci/project/node_modules/husky
> node husky install

husky > setting up git hooks
CI detected, skipping Git hooks installation.
added 739 packages from 427 contributors and audited 37313 packages in 21.674s
found 0 vulnerabilities

lerna notice cli v3.4.0
lerna info Bootstrapping 2 packages
lerna info Installing external dependencies
lerna info hoist Installing hoisted dependencies into root
lerna info hoist Pruning hoisted dependencies
lerna info hoist Finished pruning hoisted dependencies
lerna ERR! npm ci exited 1 in 'qhacks-dashboard'
lerna ERR! npm ci stderr:
npm WARN prepare removing existing node_modules/ before installation
npm ERR! cipm can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
npm ERR! 
npm ERR! 
npm ERR! Missing: @sendgrid/mail@^6.3.1
npm ERR! Missing: axios@^0.18.0
npm ERR! Missing: babel-core@^6.26.0
npm ERR! Missing: babel-jest@^23.2.0
npm ERR! Missing: babel-loader@^7.1.2
npm ERR! Missing: babel-polyfill@^6.26.0
npm ERR! Missing: babel-preset-env@^1.6.1
npm ERR! Missing: babel-preset-react@^6.24.1
npm ERR! Missing: babel-preset-stage-2@^6.24.1
npm ERR! Missing: bcrypt@^3.0.0
npm ERR! Missing: body-parser@^1.18.3
npm ERR! Missing: camelcase@^5.0.0
npm ERR! Missing: compression@^1.7.3
npm ERR! Missing: compression-webpack-plugin@^1.1.3
npm ERR! Missing: connect-history-api-fallback@^1.5.0
npm ERR! Missing: css-loader@^0.28.9
npm ERR! Missing: dotenv@^6.0.0
npm ERR! Missing: enzyme@^3.3.0
npm ERR! Missing: enzyme-adapter-react-16@^1.1.1
npm ERR! Missing: enzyme-to-json@^3.3.4
npm ERR! Missing: express@^4.16.3
npm ERR! Missing: favicons-webpack-plugin@0.0.9
npm ERR! Missing: file-loader@^1.1.6
npm ERR! Missing: helmet@^3.13.0
npm ERR! Missing: html-webpack-plugin@^3.2.0
npm ERR! Missing: jest@^23.6.0
npm ERR! Missing: jest-environment-node@^23.4.0
npm ERR! Missing: jsonwebtoken@^8.3.0
npm ERR! Missing: less@2.7.3
npm ERR! Missing: less-loader@^4.0.5
npm ERR! Missing: mini-css-extract-plugin@^0.4.1
npm ERR! Missing: mjml@^4.1.2
npm ERR! Missing: moment@^2.22.2
npm ERR! Missing: mongodb-memory-server@^2.2.0
npm ERR! Missing: mongoose@^5.2.14
npm ERR! Missing: mustache@^2.3.2
npm ERR! Missing: nodemon@^1.18.4
npm ERR! Missing: querystring@^0.2.0
npm ERR! Missing: react@^16.2.0
npm ERR! Missing: react-dom@^16.2.0
npm ERR! Missing: react-emoji-render@^0.4.4
npm ERR! Missing: react-redux@^5.0.6
npm ERR! Missing: react-router-dom@^4.2.2
npm ERR! Missing: redux@^4.0.0
npm ERR! Missing: redux-form@^7.2.1
npm ERR! Missing: redux-form-validators@^2.3.2
npm ERR! Missing: redux-saga@^0.16.0
npm ERR! Missing: style-loader@^0.21.0
npm ERR! Missing: supertest@^3.3.0
npm ERR! Missing: url-loader@^1.0.1
npm ERR! Missing: validator@^10.7.1
npm ERR! Missing: webpack@^4.14.0
npm ERR! Missing: webpack-cli@^3.0.8
npm ERR! Missing: webpack-dev-server@^3.1.4
npm ERR! Missing: winston@^3.1.0
npm ERR! 

As you can see, the command being run is npm install --unsafe-perm || ((if [ -f npm-debug.log ]; then cat npm-debug.log; fi) && false) && lerna bootstrap --ci. Only reason I am calling npm install before lerna bootstrap is because lerna bootstrap requires lerna to be installed. Is that logic wrong?

@evocateur
Copy link
Member

No, but you can't --hoist if you're running npm ci, it's trying to install a bunch of hoisted dependencies in the root first. Not sure why you need the --unsafe-perm?

@RobertWSaunders
Copy link
Contributor

Thanks @evocateur! I had tried without hoisting but taking a second look I was able to get it. Yeah I got rid of --unsafe-perm, thanks for the tip, don't know how that got there.

@vidartf
Copy link

vidartf commented Oct 12, 2018

If you cannot use ci with --hoist, then shouldn't --hoist imply --no-ci ?

Ryuno-Ki added a commit to lobsangnet/lobsang.js that referenced this issue Nov 4, 2018
Ryuno-Ki added a commit to lobsangnet/lobsang.js that referenced this issue Nov 4, 2018
Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
@lock
Copy link

lock bot commented Dec 27, 2018

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 27, 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

No branches or pull requests

6 participants