Skip to content

Commit afb168a

Browse files
author
David Heinemeier Hansson
committed
Guard against npx without set-script
Fixes #35, #38
1 parent 016a561 commit afb168a

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

lib/install/esbuild/install.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22
run "yarn add esbuild"
33

44
say "Add build script"
5-
run %(npm set-script build "esbuild app/javascript/*.* --bundle --outdir=app/assets/builds")
5+
build_script = "esbuild app/javascript/*.* --bundle --outdir=app/assets/builds"
6+
7+
if (`npx -v`.to_f < 7.1 rescue "Missing")
8+
say %(Add "scripts": { "build": "#{build_script}" to your package.json), :green
9+
else
10+
run %(npm set-script build "#{build_script}")
11+
end

lib/install/rollup/install.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@
33
run "yarn add rollup @rollup/plugin-node-resolve"
44

55
say "Add build script"
6-
run %(npm set-script build "rollup -c rollup.config.js")
6+
build_script = "rollup -c rollup.config.js"
7+
8+
if (`npx -v`.to_f < 7.1 rescue "Missing")
9+
say %(Add "scripts": { "build": "#{build_script}" to your package.json), :green
10+
else
11+
run %(npm set-script build "#{build_script}")
12+
end

lib/install/webpack/install.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@
33
run "yarn add webpack webpack-cli"
44

55
say "Add build script"
6-
run %(npm set-script build "webpack --config webpack.config.js")
6+
build_script = "webpack --config webpack.config.js"
7+
8+
if (`npx -v`.to_f < 7.1 rescue "Missing")
9+
say %(Add "scripts": { "build": "#{build_script}" to your package.json), :green
10+
else
11+
run %(npm set-script build "#{build_script}")
12+
end

0 commit comments

Comments
 (0)