Skip to content

Commit

Permalink
Remove bundledDependencies (facebook#1068)
Browse files Browse the repository at this point in the history
* Remove bundledDependencies
* Change the e2e scripts to use local file dependencies instead of
  bundledDependencies to test the packages
  • Loading branch information
fson authored and randycoulman committed May 8, 2017
1 parent 3b3d8a4 commit 1f0bb7f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ and then run `npm start` or `npm run build`.
6. Make sure to include “Migrating from ...” instructions for the previous release. Often you can copy and paste them.
7. After merging the changelog update, create a GitHub Release with the same text. See previous Releases for inspiration.
8. **Do not run `npm publish`. Instead, run `npm run publish`.**
9. Wait for a long time, and it will get published. Don’t worry that it’s stuck. It will bundle dependencies into a single tarball before publishing for faster installs. In the end the publish script will prompt for versions before publishing the packages.
9. Wait for a long time, and it will get published. Don’t worry that it’s stuck. In the end the publish script will prompt for versions before publishing the packages.

Make sure to test the released version! If you want to be extra careful, you can publish a prerelease by running `npm run publish -- --tag next` instead of `npm run publish`.

Expand Down
11 changes: 6 additions & 5 deletions tasks/cra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ cd packages/react-scripts
# Save package.json because we're going to touch it
cp package.json package.json.orig

# Like bundle-deps, this script modifies packages/react-scripts/package.json,
# copying own dependencies (those in the `packages` dir) to bundledDependencies
# ZEAL: Disabled because https://github.com/npm/npm/issues/12834, it will be
# removed soon: https://github.com/facebookincubator/create-react-app/pull/1068
# node $root_path/tasks/bundle-own-deps.js
# Replace own dependencies (those in the `packages` dir) with the local paths
# of those packages.
node $root_path/tasks/replace-own-deps.js

# Finally, pack react-scripts
scripts_path=$root_path/packages/react-scripts/`npm pack`
Expand All @@ -77,6 +75,9 @@ mv package.json.orig package.json
# Now that we have packed them, call the global CLI.
# ******************************************************************************

# If Yarn is installed, clean its cache because it may have cached react-scripts
yarn cache clean || true

# Go back to the root directory and run the command from here
cd $root_path
node packages/create-react-app/index.js --scripts-version=$scripts_path "$@"
Expand Down
14 changes: 11 additions & 3 deletions tasks/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ if [ "$USE_YARN" = "yes" ]
then
# Install Yarn so that the test can use it to install packages.
npm install -g yarn
yarn cache clean
fi

npm install
Expand Down Expand Up @@ -96,13 +97,20 @@ cli_path=$PWD/`npm pack`
# Go to react-scripts
cd $root_path/packages/react-scripts

# Like bundle-deps, this script modifies packages/react-scripts/package.json,
# copying own dependencies (those in the `packages` dir) to bundledDependencies
node $root_path/tasks/bundle-own-deps.js
# Save package.json because we're going to touch it
cp package.json package.json.orig

# Replace own dependencies (those in the `packages` dir) with the local paths
# of those packages.
node $root_path/tasks/replace-own-deps.js

# Finally, pack react-scripts
scripts_path=$root_path/packages/react-scripts/`npm pack`

# Restore package.json
rm package.json
mv package.json.orig package.json

# ******************************************************************************
# Now that we have packed them, create a clean app folder and install them.
# ******************************************************************************
Expand Down
19 changes: 0 additions & 19 deletions tasks/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,6 @@ if [ -n "$(git status --porcelain)" ]; then
exit 1;
fi

# Update deps
rm -rf node_modules
rm -rf ~/.npm
npm cache clear
npm install

cd packages/react-scripts
# Force dedupe
npm dedupe

# Don't bundle fsevents because it is optional and OS X-only
# Since it's in optionalDependencies, it will attempt install outside bundle
rm -rf node_modules/fsevents

# This modifies package.json to copy all dependencies to bundledDependencies
# ZEAL: Disabled because https://github.com/npm/npm/issues/12834, it will be
# removed soon: https://github.com/facebookincubator/create-react-app/pull/1068
# node ./node_modules/.bin/bundle-deps

cd $root_path
# Go!
./node_modules/.bin/lerna publish --independent "$@"
12 changes: 7 additions & 5 deletions tasks/bundle-own-deps.js → tasks/replace-own-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
*/
'use strict';

// Like bundle-deps, this script modifies packages/react-scripts/package.json,
// copying own dependencies (those in the `packages` dir) to bundledDependencies
// Replaces internal dependencies in package.json with local package paths.

const fs = require('fs');
const path = require('path');
Expand All @@ -19,10 +18,13 @@ const packagesDir = path.join(__dirname, '../packages');
const pkgFilename = path.join(packagesDir, 'react-scripts/package.json');
const data = require(pkgFilename);

data.bundledDependencies = fs.readdirSync(packagesDir)
.filter((name) => data.dependencies[name]);
fs.readdirSync(packagesDir).forEach((name) => {
if (data.dependencies[name]) {
data.dependencies[name] = 'file:' + path.join(packagesDir, name);
}
})

fs.writeFile(pkgFilename, JSON.stringify(data, null, 2), 'utf8', (err) => {
if (err) throw err;
console.log('bundled ' + data.bundledDependencies.length + ' dependencies.');
console.log('Replaced local dependencies.');
});

0 comments on commit 1f0bb7f

Please sign in to comment.