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

Install devDependencies by default #519

Merged
merged 10 commits into from
Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@ cache_build() {
header "Caching build"
Copy link
Contributor Author

@jmorrell jmorrell Feb 22, 2018

Choose a reason for hiding this comment

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

This changes a lot of the fixture files for tests which can be mostly ignored. The important changes are found in:

bin/compile
lib/dependencies.sh
lib/environment.sh
lib/failure.sh

With tests changes in:
test/run

cache_build | output "$LOG_FILE"

prune_devdependencies() {
if $YARN; then
yarn_prune_devdependencies "$BUILD_DIR"
else
npm_prune_devdependencies "$BUILD_DIR"
fi
}

header "Pruning devDependencies"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the terminology that npm uses, but I don't love it.

Is there a clearer way to get across "we're removing the modules defined in devDepenencies from node_modules"?

Copy link
Member

@hone hone Feb 27, 2018

Choose a reason for hiding this comment

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

If it's the command in both yarn and npm, it's probably fine since that's what people will be familiar with.

prune_devdependencies | output "$LOG_FILE"

summarize_build() {
if $NODE_VERBOSE; then
list_dependencies "$BUILD_DIR"
Expand Down
51 changes: 48 additions & 3 deletions lib/dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,34 @@ log_build_scripts() {

yarn_node_modules() {
local build_dir=${1:-}
local production=${YARN_PRODUCTION:-false}

echo "Installing node modules (yarn.lock)"
cd "$build_dir"
yarn install --frozen-lockfile --ignore-engines 2>&1
yarn install --production=$production --frozen-lockfile --ignore-engines 2>&1
}

yarn_prune_devdependencies() {
local build_dir=${1:-}

if [ $NODE_ENV == "test" ]; then
Copy link
Member

@hone hone Feb 27, 2018

Choose a reason for hiding this comment

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

This will be caught by the elif clause below. Do we want the explicit messaging here?

echo "Skipping because NODE_ENV is 'test'"
return 0
elif [ $NODE_ENV != "production" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

It might be worth quoting the $NODE_ENV and the various other variables in conditionals, since otherwise spurious spaces can cause a too many arguments bash error and the wrong result.

eg:

$ NODE_ENV="foo bar"; if [ $NODE_ENV != "production" ]; then echo "not production"; else echo "production"; fi
bash: [: too many arguments
production

Fwiw shellcheck is able to find issues like this (the Python buildpack runs it on Travis):

In lib/dependencies.sh line 103:
  elif [ $NODE_ENV != "production" ]; then
         ^-- SC2086: Double quote to prevent globbing and word splitting.

(https://github.com/koalaman/shellcheck/wiki/SC2086)

Choose a reason for hiding this comment

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

cough shellcheck is the best

echo "Skipping because NODE_ENV is not 'production'"
return 0
elif [ -n "$YARN_PRODUCTION" ] && [ "$YARN_PRODUCTION" != "true" ]; then
echo "Skipping because YARN_PRODUCTION is not 'true'"
return 0
else
cd "$build_dir"
yarn install --frozen-lockfile --ignore-engines --ignore-scripts --prefer-offline 2>&1
fi
}

npm_node_modules() {
local build_dir=${1:-}
local production=${NPM_CONFIG_PRODUCTION:-false}

if [ -e $build_dir/package.json ]; then
cd $build_dir
Expand All @@ -106,14 +126,15 @@ npm_node_modules() {
else
echo "Installing node modules (package.json)"
fi
npm install --unsafe-perm --userconfig $build_dir/.npmrc 2>&1
npm install --production=$production --unsafe-perm --userconfig $build_dir/.npmrc 2>&1
else
echo "Skipping (no package.json)"
fi
}

npm_rebuild() {
local build_dir=${1:-}
local production=${NPM_CONFIG_PRODUCTION:-false}

if [ -e $build_dir/package.json ]; then
cd $build_dir
Expand All @@ -124,8 +145,32 @@ npm_rebuild() {
else
echo "Installing any new modules (package.json)"
fi
npm install --unsafe-perm --userconfig $build_dir/.npmrc 2>&1
npm install --production=$production --unsafe-perm --userconfig $build_dir/.npmrc 2>&1
else
echo "Skipping (no package.json)"
fi
}

npm_prune_devdependencies() {
local build_dir=${1:-}
local npm_version=$(npm --version)

if [ $NODE_ENV == "test" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

Same as the yarn comment above, but wanted to point it out for completeness sake.

echo "Skipping because NODE_ENV is 'test'"
return 0
elif [ $NODE_ENV != "production" ]; then
echo "Skipping because NODE_ENV is not 'production'"
return 0
elif [ -n "$NPM_CONFIG_PRODUCTION" ] && [ "$NPM_CONFIG_PRODUCTION" != "true" ]; then
echo "Skipping because NPM_CONFIG_PRODUCTION is not 'true'"
return 0
elif [ $npm_version == "5.3.0" ]; then
mcount "skip-prune-issue-npm-5.3.0"
echo "Skipping because npm 5.3.0 fails when running 'npm prune' due to a known issue"
echo "https://github.com/npm/npm/issues/17781"
return 0
else
cd "$build_dir"
npm prune --userconfig $build_dir/.npmrc 2>&1
fi
}
3 changes: 1 addition & 2 deletions lib/environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ platform="$os-$cpu"
export JQ="$BP_DIR/vendor/jq-$os"

create_default_env() {
export NPM_CONFIG_PRODUCTION=${NPM_CONFIG_PRODUCTION:-true}
export NPM_CONFIG_LOGLEVEL=${NPM_CONFIG_LOGLEVEL:-error}
export NODE_MODULES_CACHE=${NODE_MODULES_CACHE:-true}
export NODE_ENV=${NODE_ENV:-production}
Expand Down Expand Up @@ -68,7 +67,7 @@ write_ci_profile() {
local bp_dir="$1"
local build_dir="$2"
write_profile "$1" "$2"
cp $bp_dir/ci-profile/* $build_dir/.profile.d/
cp $bp_dir/ci-profile/* $build_dir/.profile.d/
}

write_export() {
Expand Down
3 changes: 1 addition & 2 deletions lib/failure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ fail_yarn_outdated() {
local log_file="$1"
local yarn_engine=$(read_json "$BUILD_DIR/package.json" ".engines.yarn")

if grep -qi 'error: unknown option .--frozen-lockfile' "$log_file"; then
echo "ran"
if grep -qi 'error .install. has been replaced with .add. to add new dependencies' "$log_file"; then
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is changed because in these earlier versions adding the --production flag changes the error message that is displayed

mcount "failures.outdated-yarn"
echo ""
warn "Outdated Yarn version: $yarn_engine
Expand Down
22 changes: 22 additions & 0 deletions test/fixtures/ci-dependencies-yarn/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "node-buildpack-test-app",
"version": "0.0.1",
"description": "node buildpack integration test app",
"repository": {
"type": "git",
"url": "http://github.com/example/example.git"
},
"dependencies": {
"hashish": "*"
},
"license": "MIT",
"engines": {
"yarn": "1.4.0"
},
"devDependencies": {
"lodash": "^2.4.1"
},
"scripts": {
"test": "ls node_modules"
}
}
17 changes: 17 additions & 0 deletions test/fixtures/ci-dependencies-yarn/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


hashish@*:
version "0.0.4"
resolved "https://registry.yarnpkg.com/hashish/-/hashish-0.0.4.tgz#6d60bc6ffaf711b6afd60e426d077988014e6554"
dependencies:
traverse ">=0.2.4"

lodash@^2.4.1:
version "2.4.2"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-2.4.2.tgz#fadd834b9683073da179b3eae6d9c0d15053f73e"

traverse@>=0.2.4:
version "0.6.6"
resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.6.6.tgz#cbdf560fd7b9af632502fed40f918c157ea97137"
1 change: 1 addition & 0 deletions test/fixtures/ci-dependencies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A fake README, to keep npm from polluting stderr.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
"hashish": "*"
},
"engines": {
"node": "~0.10.0"
"node": "8.x"
},
"devDependencies": {
"lodash": "^2.4.1"
},
"scripts": {
"test": "ls node_modules"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A fake README, to keep npm from polluting stderr.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading