Skip to content

jesstelford/npm-scripts-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

npm vs yarn script execution order

Based on discussion in yarnpkg/yarn#2853

yarn --version
> 0.21.3
npm --version
> 4.3.0

tl;dr npm scripts !== yarn scripts (they sometimes execute different sets of scripts depending on if it's a dep of a dep, or if it's a local file, etc)

Local modules

From root of project (no deps)

Click to expand

See package.json@v2.0.0

npm

git clone --branch v2.0.0 https://github.com/jesstelford/npm-scripts-test.git
cd npm-scripts-test
npm install

yarn

git clone --branch v2.0.0 https://github.com/jesstelford/npm-scripts-test.git
cd npm-scripts-test
yarn

Output

cat node_modules/npm-scripts-test/scripts
npm
npm-scripts-test.preinstall
npm-scripts-test.install
npm-scripts-test.postinstall
npm-scripts-test.prepublish
npm-scripts-test.prepare
yarn
npm-scripts-test.preinstall
npm-scripts-test.install
npm-scripts-test.postinstall
npm-scripts-test.prepublish
The diff
--- a/yarn-scripts
+++ b/npm-scripts
@@ -2,4 +2,3 @@ npm-scripts-test.preinstall
 npm-scripts-test.install
 npm-scripts-test.postinstall
 npm-scripts-test.prepublish
+npm-scripts-test.prepare

Single level dep

Click to expand

See package.json@v2.0.0

npm

git clone --branch v2.0.0 https://github.com/jesstelford/npm-scripts-test.git
mkdir test-single-level-npm
cd test-single-level-npm
npm init -y .
npm install --save ../npm-scripts-test

yarn

git clone --branch v2.0.0 https://github.com/jesstelford/npm-scripts-test.git
mkdir test-single-level-yarn
cd test-single-level-yarn
yarn init -y .
yarn add file:../npm-scripts-test

Output

cat node_modules/npm-scripts-test/scripts
npm
npm-scripts-test.preinstall
npm-scripts-test.install
npm-scripts-test.postinstall
yarn
npm-scripts-test.preinstall
npm-scripts-test.install
npm-scripts-test.postinstall
npm-scripts-test.prepublish
npm-scripts-test.prepublish
npm-scripts-test.prepare
npm-scripts-test.preinstall
npm-scripts-test.install
npm-scripts-test.postinstall
The diff
--- a/npm-scripts
+++ b/yarn-scripts
@@ -1,9 +1,3 @@
 npm-scripts-test.preinstall
 npm-scripts-test.install
 npm-scripts-test.postinstall
-npm-scripts-test.prepublish
-npm-scripts-test.prepublish
-npm-scripts-test.prepare
-npm-scripts-test.preinstall
-npm-scripts-test.install
-npm-scripts-test.postinstall

Dep local, but dep of a dep from registry

Click to expand

See npm-scripts-test-parent/package.json@v1.0.0

npm

git clone --branch v1.0.0 https://github.com/jesstelford/npm-scripts-test-parent.git
mkdir test-dep-of-dep-npm
cd test-dep-of-dep-npm
npm init -y .
npm install --save ../npm-scripts-test-parent

yarn

git clone --branch v1.0.0 https://github.com/jesstelford/npm-scripts-test-parent.git
mkdir test-dep-of-dep-yarn
cd test-dep-of-dep-yarn
yarn init -y .
yarn add file:../npm-scripts-test-parent

Output

(output is the same for both npm & yarn)

cat node_modules/npm-scripts-test/scripts
npm-scripts-test.preinstall
npm-scripts-test.install
npm-scripts-test.postinstall
npm-scripts-test.prepublish
npm-scripts-test.prepare
npm-scripts-test.prepublish
npm-scripts-test.prepare
npm-scripts-test.preinstall
npm-scripts-test.install
npm-scripts-test.postinstall

Non-linear Dep local, but dep of a dep from registry

Click to expand

See npm-scripts-test-parent/package.json@v1.0.0

npm

git clone --branch v1.0.0 https://github.com/jesstelford/npm-scripts-test-parent.git
mkdir test-dep-of-dep-npm
cd test-dep-of-dep-npm
npm init -y .
npm install --save ../npm-scripts-test-parent
npm install --save ../npm-scripts-test
rm -rf node_modules
npm install

yarn

git clone --branch v1.0.0 https://github.com/jesstelford/npm-scripts-test-parent.git
mkdir test-dep-of-dep-yarn
cd test-dep-of-dep-yarn
yarn init -y .
yarn add file:../npm-scripts-test-parent
yarn add file:../npm-scripts-test
rm -rf node_modules yarn.lock
yarn

Output

cat node_modules/npm-scripts-test/scripts
npm
npm-scripts-test.preinstall
npm-scripts-test.install
npm-scripts-test.postinstall
yarn
npm-scripts-test.preinstall
npm-scripts-test.install
npm-scripts-test.postinstall
npm-scripts-test.prepublish
npm-scripts-test.prepublish
npm-scripts-test.prepare
npm-scripts-test.preinstall
npm-scripts-test.install
npm-scripts-test.postinstall
The diff
--- a/npm-scripts
+++ b/yarn-scripts
@@ -1,9 +1,3 @@
 npm-scripts-test.preinstall
 npm-scripts-test.install
 npm-scripts-test.postinstall
-npm-scripts-test.prepublish
-npm-scripts-test.prepublish
-npm-scripts-test.prepare
-npm-scripts-test.preinstall
-npm-scripts-test.install
-npm-scripts-test.postinstall

From registry

As a dependency

Click to expand

See package.json@v2.0.0

npm

npm init -y .
npm install --save npm-scripts-test@2.0.0

yarn

yarn init -y .
yarn add npm-scripts-test@2.0.0

Output

(output is the same for both npm & yarn)

cat node_modules/npm-scripts-test/scripts
npm-scripts-test.preinstall
npm-scripts-test.install
npm-scripts-test.postinstall
npm-scripts-test.prepublish
npm-scripts-test.prepare
npm-scripts-test.prepublish
npm-scripts-test.prepare
npm-scripts-test.preinstall
npm-scripts-test.install
npm-scripts-test.postinstall

As a dependency of a dependency

Click to expand

See npm-scripts-test-parent/package.json@v1.0.0

npm

npm init -y .
npm install --save npm-scripts-test-parent@1.0.0

yarn

yarn init -y .
yarn add npm-scripts-test-parent@1.0.0

Output

(output is the same for both npm & yarn)

cat node_modules/npm-scripts-test/scripts
npm-scripts-test.preinstall
npm-scripts-test.install
npm-scripts-test.postinstall
npm-scripts-test.prepublish
npm-scripts-test.prepare
npm-scripts-test.prepublish
npm-scripts-test.prepare
npm-scripts-test.preinstall
npm-scripts-test.install
npm-scripts-test.postinstall

Non-linear dep of dep

Click to expand

See npm-scripts-test-parent/package.json@v1.0.0

npm

npm init -y .
npm install --save npm-scripts-test-parent@1.0.0
npm install --save npm-scripts-test@2.0.0
rm -rf node_modules
npm install

yarn

yarn init -y .
yarn add npm-scripts-test-parent@1.0.0
yarn add npm-scripts-test@2.0.0
rm -rf node_modules yarn.lock
yarn

Output

(output is the same for both npm & yarn)

cat node_modules/npm-scripts-test/scripts
npm-scripts-test.preinstall
npm-scripts-test.install
npm-scripts-test.postinstall
npm-scripts-test.prepublish
npm-scripts-test.prepare
npm-scripts-test.prepublish
npm-scripts-test.prepare
npm-scripts-test.preinstall
npm-scripts-test.install
npm-scripts-test.postinstall

About

Demoing the execution order of npm / yarn scripts

Resources

Stars

Watchers

Forks

Packages

No packages published