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

Stop using npm link in tests #3345

Merged
merged 28 commits into from
Oct 30, 2017
Merged

Stop using npm link in tests #3345

merged 28 commits into from
Oct 30, 2017

Conversation

Timer
Copy link
Contributor

@Timer Timer commented Oct 28, 2017

npm link is super unreliable and causes our tests to fail; this replaces npm link with a much more predictable behavior.

This doesn't work on AppVeyor yet because the version of rsync is complaining about a local copy; any ideas?

@gaearon
Copy link
Contributor

gaearon commented Oct 29, 2017

Can we just use cp -r? Why do we need rsync?

@Timer
Copy link
Contributor Author

Timer commented Oct 29, 2017

We want to skip node_modules; we could cp -r & rm -r, then install because only want dependencies and not dev ones.

@gaearon
Copy link
Contributor

gaearon commented Oct 29, 2017

Sounds reasonable

This reverts commit eebf1dbc19aeb6e1f66d5ec27bda2d076bea0956.
@Timer Timer added this to the 1.0.15 milestone Oct 29, 2017
@Timer
Copy link
Contributor Author

Timer commented Oct 29, 2017

This should be good to land.

@gaearon
Copy link
Contributor

gaearon commented Oct 29, 2017

Can you explain what this does and why?

@Timer
Copy link
Contributor Author

Timer commented Oct 29, 2017

Usages of npm link were swapped out with install_package, which behaves like so:

  1. Clear existing instances of the package (rm -rf **/pkg/)
    • why: The package may exist at arbitrarily nested levels in the package tree, so we want to ensure it's removed everywhere. We should be testing our source controlled version of the package, not one grabbed from npm. This will ensure any request for our package drops into node module resolution and searches up the tree for the copy of the package we're about to create.
  2. The package is copied into the root-most level node_modules to ensure it can be resolved by all packages which require it (cp -R ${1%/} node_modules/).
    • This matches behavior that would be seen in npm >= 3 & Yarn (package hoisting).
  3. Remove all node_modules which were copied over with the package (rm -rf node_modules/$pkg/node_modules/).
    • why: These packages may include development dependencies, which we do not want to include while testing (we want to be as close to a real install as possible).
  4. Production dependencies are installed in the package we are simulating a link for (cd node_modules/$pkg/ && npm install --only=production).
    • why: We need them 😄
    • Sure, these packages aren't hoisted but we're testing our functionality, not the correctness of the package manager -- we're sort of reverting to npm 2 behavior [which was better for testing anyways].
  5. We remove any installed dependencies of the linked package which are in our monorepo -- this ensures Node module resolution kicks in and we search up a level where the package should also of been linked (rm -rf node_modules/{babel-preset-react-app,eslint-config-react-app,react-dev-utils,react-error-overlay,react-scripts}).

@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

Why do we need to run Yarn after ejecting?

@Timer
Copy link
Contributor Author

Timer commented Oct 30, 2017

The dependency tree is invalid after ejecting since we don't run Yarn, so the installation is broken.
This happens in existing applications and now in our CI since we use a more "real life" install_package instead of npm link, which was masking this failure.

Note babel-loader is installed under react-scripts and not top level.

$ npx create-react-app testing # installs via Yarn
$ npm ls babel-loader
testing@0.1.0 /Users/joe/Desktop/testing
└─┬ react-scripts@1.0.14
  └── babel-loader@7.1.1 
$ echo y | yarn eject
$ npm ls babel-loader
testing@0.1.0 /Users/joe/Desktop/testing
└── UNMET DEPENDENCY babel-loader@7.1.1
$ yarn build
yarn run v1.2.1
$ node scripts/build.js
module.js:529
    throw err;
    ^

Error: Cannot find module 'babel-loader'
...
$ yarn
yarn install v1.2.1
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 📃  Building fresh packages...
success Saved lockfile.
✨  Done in 3.43s.
$ yarn build
yarn run v1.2.1
$ node scripts/build.js
Creating an optimized production build...
Compiled successfully.
...

See #3347

@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

Should we just fix our eject code to do npm uninstall --save react-scripts and then npm install --save <its dependencies>, and do the same for Yarn (yarn remove react-scripts and yarn add <its dependencies>)? Then we won't need to do CI-specific hacks and will solve the problem of incorrect lockfile.

@Timer
Copy link
Contributor Author

Timer commented Oct 30, 2017

We could make that adjustment, but I'm not sure it's necessary -- Yarn fixes the invalid lockfile as of July (the react-scripts entry is removed).
I'm not sure about npm's package-lock.json.

The CI-specific hack isn't so IMO, because our end-users have to do this. The project is broken otherwise.

@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

It might not be necessary but it feels more consistent and bringing less surprises in the future.

@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

... assuming we figure out how to run npm in the right folder 😉

@Timer
Copy link
Contributor Author

Timer commented Oct 30, 2017

Want to land this as-is and make the eject changes in a separate PR? I can do it in this PR if you'd like.

@gaearon gaearon merged commit de1beec into facebook:master Oct 30, 2017
@gaearon
Copy link
Contributor

gaearon commented Oct 30, 2017

Yep, sounds good. Thanks.

@Timer Timer deleted the stop-using-npm branch October 30, 2017 14:27
@gaearon gaearon mentioned this pull request Oct 30, 2017
kellyrmilligan added a commit to kellyrmilligan/create-react-app that referenced this pull request Oct 31, 2017
* master: (32 commits)
  Publish
  Reorder publishing instructions
  Changelog for 1.0.16 (facebook#3376)
  Update favicon description (facebook#3374)
  Changelog for 1.0.15 (facebook#3357)
  Replace template literal; fixes facebook#3367 (facebook#3368)
  CLI@1.4.2
  Publish
  Add preflight CWD check for npm (facebook#3355)
  Stop using `npm link` in tests (facebook#3345)
  Fix for add .gitattributes file facebook#3080 (facebook#3122)
  Mention that start_url needs to be "." for client side routing
  start using npm-run-all to build scss and js (facebook#2957)
  Updating the Service Worker opt-out documentation (facebook#3108)
  Remove an useless negation in registerServiceWorker.js (facebook#3150)
  Remove output.path from dev webpack config (facebook#3158)
  Add `.mjs` support (facebook#3239)
  Add documentation for Enzyme 3 integration (facebook#3286)
  Make uglify work in Safari 10.0 - fixes facebook#3280 (facebook#3281)
  Fix favicon sizes value in manifest (facebook#3287)
  ...
suutari-ai referenced this pull request in andersinno/create-react-app-ai Jan 25, 2018
…pescript

* 'master' of https://github.com/wmonk/create-react-app-typescript: (265 commits)
  fix typo in changelog
  Update README For 2.13.0
  v2.13.0
  Remove tslint-loader from prod build (again)
  Include TypeScript as devDependency in boilerplate output
  Documented how to define custom module formats for the TypeScript compiler so that you can import images and other files (references wmonk#172)
  v2.12.0
  Update README For 2.12.0
  Update typescript to 2.6.2
  v2.11.0
  Update changelog for 2.11.0
  Fixed problem with tsconfig.json baseUrl and paths
  Update createJestConfig.js
  Update changelog for 2.10.0
  v2.10.0
  Readd transformIgnorePatterns
  Update react-dev-utils
  Update package.json dependencies
  Readd Missing raf Package
  Update JestConfig Creation
  Fix
  Fix Missing Variable
  Fix package.json
  Merge pull request wmonk#204 from StefanSchoof/patch-1
  Merge pull request wmonk#201 from StefanSchoof/patch-1
  Merge pull request wmonk#199 from DorianGrey/master
  Merge pull request wmonk#165 from johnnyreilly/master
  Publish
  Add 1.0.17 changelog (#3402)
  Use new WebpackDevServer option (#3401)
  Fix grammar in README (#3394)
  Add link to VS Code troubleshooting guide (#3399)
  Update VS Code debug configuration (#3400)
  Update README.md (#3392)
  Publish
  Reorder publishing instructions
  Changelog for 1.0.16 (#3376)
  Update favicon description (#3374)
  Changelog for 1.0.15 (#3357)
  Replace template literal; fixes #3367 (#3368)
  CLI@1.4.2
  Publish
  Add preflight CWD check for npm (#3355)
  Stop using `npm link` in tests (#3345)
  Fix for add .gitattributes file #3080 (#3122)
  Mention that start_url needs to be "." for client side routing
  start using npm-run-all to build scss and js (#2957)
  Updating the Service Worker opt-out documentation (#3108)
  Remove an useless negation in registerServiceWorker.js (#3150)
  Remove output.path from dev webpack config (#3158)
  Add `.mjs` support (#3239)
  Add documentation for Enzyme 3 integration (#3286)
  Make uglify work in Safari 10.0 - fixes #3280 (#3281)
  Fix favicon sizes value in manifest (#3287)
  Bump dependencies (#3342)
  recommend react-snap; react-snapshot isn't upgraded for React 16 (#3328)
  Update appveyor.cleanup-cache.txt
  Polyfill rAF in test environment (#3340)
  Use React 16 in development
  Use a simpler string replacement for the overlay
  Clarify the npm precompilation advice
  --no-edit
  Update `eslint-plugin-react` (#3146)
  Add jest coverage configuration docs (#3279)
  Update link to Jest Expect docs (#3303)
  Update README.md
  Fix dead link to Jest "expect" docs (#3289)
  v2.8.0
  Use production React version for bundled overlay (#3267)
  Add warning when using `react-error-overlay` in production (#3264)
  Add external links to deployment services (#3265)
  `react-error-overlay` has no dependencies now (#3263)
  Add click-to-open support for build errors (#3100)
  Update style-loader and disable inclusion of its HMR code in builds (#3236)
  Update url-loader to 0.6.2 for mime ReDoS vuln (#3246)
  Make error overlay to run in the context of the iframe (#3142)
  Upgrade to typescript 2.5.3
  Fix Windows compatibility (#3232)
  Fix package management link in README (#3227)
  Watch for changes in `src/**/node_modules` (#3230)
  More spec compliant HTML template (#2914)
  Minor change to highlight dev proxy behaviour (#3075)
  Correct manual proxy documentation (#3185)
  Improve grammar in README (#3211)
  Publish
  Fix license comments
  Changelog for 1.0.14
  BSD+Patents -> MIT (#3189)
  Add link to active CSS modules discussion (#3163)
  Update webpack-dev-server to 2.8.2 (#3157)
  Part of class fields to stage 3 (#2908)
  Update unclear wording in webpack config docs (#3160)
  Display pid in already running message (#3131)
  Link local react-error-overlay package in kitchensink test
  Resolved issue #2971 (#2989)
  Revert "run npm 5.4.0 in CI (#3026)" (#3107)
  Updated react-error-overlay to latest Flow (0.54.0) (#3065)
  Auto-detect running editor on Linux for error overlay (#3077)
  Clean target directory before compiling overlay (#3102)
  Rerun prettier and pin version (#3058)
  ...
@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants