Skip to content
New issue

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

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

Already on GitHub? # to your account

fix(install): Use npm-is to require Yarn before install. Fixes PWA-505. #2384

Merged
merged 10 commits into from
May 7, 2020

Conversation

zetlen
Copy link
Contributor

@zetlen zetlen commented May 6, 2020

Description

Add a preinstall script that prevents npm install, requiring yarn install instead.

The monorepo won't work right if installed with npm. Several users have reported that npm install at repo root causes somewhat mysterious errors. This is because the repo uses Yarn Workspaces, and Yarn automatically installs workspace dependencies along with root dependencies. NPM doesn't, so packages are missing deps when they run.

I, uh, found a utility called npm-is which detects and asserts package managers, and used it to add a preinstall script npx npm-is yarn. This command fails if the NPM script wasn't invoked with Yarn, thus preventing npm install.

Related Issue

Closes PWA-505.

Acceptance

Verification Stakeholders

@dpatil-magento

Verification Steps

  1. Run yarn run clean:all to remove all node_modules folders.
  2. Run npm install at package root.
  3. Observe that it fails before installing dependencies, throwing an informative error message.

Checklist

  • I have updated the documentation accordingly, if necessary.
  • I have added tests to cover my changes, if necessary.

@zetlen zetlen added tooling Related to the developer tooling, including buildpack, webpack plugins, and debug UIs. version: Patch This changeset includes backwards compatible bug fixes. labels May 6, 2020
@zetlen zetlen requested a review from dpatil-magento May 6, 2020 14:57
@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented May 6, 2020

Messages
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next nightly build run (assuming they are fixed).
📖

Associated JIRA tickets: PWA-505.

Generated by 🚫 dangerJS against d48497f

sirugh
sirugh previously approved these changes May 6, 2020
Copy link
Contributor

@sirugh sirugh left a comment

Choose a reason for hiding this comment

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

Look at that simple one line PR.

prod.dockerfile Outdated
@@ -23,6 +23,9 @@ COPY packages/venia-concept/package.json ./packages/venia-concept/package.json
COPY package.json yarn.lock babel.config.js magento-compatibility.js ./
COPY scripts/monorepo-introduction.js ./scripts/monorepo-introduction.js

# To handle "could not get uid/gid"
RUN npm config set unsafe-perm true

Copy link
Contributor

@dpatil-magento dpatil-magento May 6, 2020

Choose a reason for hiding this comment

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

@zetlen On CI yarn install was failing with error https://console.aws.amazon.com/codesuite/codebuild/projects/pwa-pull-request-build/build/pwa-pull-request-build%3A4b8d13c6-fd9e-42d3-83a3-287a61eea4bd/log?region=us-east-1 .
I tried updating to latest docker images but ended up in one or other error. You can check those errors in aws build logs for test pr #2385 commits.

I gave up on that and applied resolution from https://stackoverflow.com/questions/52196518/could-not-get-uid-gid-when-building-node-docker.

Also same image on local works fine bash docker/run-docker so I did not update dev.docker file.

dpatil-magento
dpatil-magento previously approved these changes May 7, 2020
@zetlen zetlen force-pushed the zetlen/require-yarn-at-preinstall branch from 163304b to 31247ba Compare May 7, 2020 15:43
package.json Outdated
@@ -30,6 +30,7 @@
"danger": "danger-ci",
"lint": "eslint '@(packages|scripts)/**/{*.js,package.json}' --ignore-pattern node_modules --ignore-pattern storybook-dist",
"postbuild": "rimraf \"./packages/*/dist/{,**/}__*__\"",
"preinstall": "node -e 'process.env.CI||process.exit(1)' || npx npm-is npm",
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense to me. Does npm-is not need to be added to the list of dependencies?

Copy link
Contributor

Choose a reason for hiding this comment

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

@zetlen I think you meant node -e 'process.env.CI||process.exit(1)' || npx npm-is yarn?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dpatil-magento I did, sorry. I was testing it and forgot to put it back.

@jimbo It does not! That’s why we use npx to run it, because it has to work before any dependencies are installed.

@@ -9,6 +9,9 @@ RUN apk --no-cache --virtual add \
g++ \
yarn

# set env variable for CI
ENV CI=true

Copy link
Contributor

Choose a reason for hiding this comment

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

AWS has CI env variable but dockerfile needs to have also.

@dpatil-magento dpatil-magento merged commit 9ad21c9 into develop May 7, 2020
@dpatil-magento dpatil-magento deleted the zetlen/require-yarn-at-preinstall branch May 7, 2020 18:56
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
tooling Related to the developer tooling, including buildpack, webpack plugins, and debug UIs. version: Patch This changeset includes backwards compatible bug fixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants