Skip to content

Commit 3af2618

Browse files
committedNov 25, 2018
build: introduce a 'prepare' script in embark's package.json
** TL;DR ** These changes affect workflow with yarn. To prevent embark's 'prepare' script from running undesirably: - If node_modules is in place and you're reinstalling after switching branches: yarn run install_all - If node_modules is missing (fresh clone or deleted): EMBARK_NO_PREPARE=t yarn install && cd embark-ui && yarn install && cd .. It's not recommended to set EMBARK_NO_PREPARE in your environment (e.g. in '.bashrc') since that would interfere with embark's 'release' script if/when you run it. ----------------- 1. Specify embark's build-related steps in the 'prepare' script of package.json. When embark is installed directly from GitHub the 'prepare' script results in a "pre install" phase (handled automatically by npm/yarn) that fetches devDependencies, builds embark (including embark-ui), packs a tarball with the same steps (minus testing and tree-checking) as would happen during an embark release, and finally does a production install from that tarball. Important point: installs from GitHub must be performed with yarn; they're no longer possible with npm since during the "pre install" phase npm will honor embark's .npmrc and "engines" settings. The following will work correctly after this commit is merged: yarn add git+https://github.com/embark-framework/embark.git Use of "hosted git" shortcuts (e.g. 'embark-framework/embark#bracnh') won't work correctly because yarn doesn't fully support them: yarnpkg/yarn#5235 It's important to use 'git+https' urls. Following a succesful install with 'git+https' it is possible to use a "hosted git" shortcut or 'https' url, but that's owing to a subtle and unreliable interaction between yarn's cache and yarn's logic for installing from a url/shortcut. 2. Adjust the npm configs (.npmrc) for embark/-ui so that 'yarn run [cmd] [--opt]' can be used in place of 'npm run [cmd] -- [--opt]'. Either way is okay for running scripts, they're equivalent, but note the requirement to use '--' before specifying command options with 'npm run'. 3. Introduce yarn configs (.yarnrc) for embark/-ui and include the 'check-files' directive. H/t to @alaibe for the recommendation. 4. Ignore embark's 'dist/typings' and 'scripts' directories when packing a tarball. 5. Refactor embark/-ui's npm-scripts in relation to the 'prepare' script, and make other small improvements. Notably, if the environment variable EMBARK_NO_PREPARE is truthy (from JS perspective) then embark's 'prepare' script will exit early. This prevents 'install_all' and 'prepare' from getting stuck in a loop ('install:core' uses cross-env to set EMBARK_NO_PREPARE) and provides a mechanism for users to skip the 'prepare' script when doing a fresh install: EMBARK_NO_PREPARE=t yarn install 6. Give .js extensions to node scripts in embark's 'scripts/', remove the shebang lines, and have npm-scripts explicitly invoke them with node. This arrangement works for all platforms: Linux, macOS, and Windows. 7. Adjust travis and appveyor configs. Since at present there aren't any tests or other CI steps that make use of embark-ui's production build, set EMBARK_NO_PREPARE in the CI environments and invoke 'build:node' directly. Check the working tree after 'yarn install' for embark/-ui. This detects situations where changes should have been committed to yarn.lock but were not. Check the working tree again at the end to detect situations where ignore files should have been adjusted but were not. Both checks could also detect other surprising behavior that needs to be investigated. Any time the working tree is not clean (there are untracked files or changes) CI will fail. Drop CI runs for node 8.11.3 because that version uses an older npm that results in unstaged changes to the test apps' package-lock.json files, causing the working tree check to fail at the end of the CI run. A simple workaround isn't apparent, but the matter can be revisited. 8. Refactor embark's 'release' script in light of the 'prepare' script. Notably, do the push step only after 'npm publish' completes successfully. This allows embark's 'prepare' and 'prepublishOnly' scripts to detect problems before a commit and tag are pushed to GitHub, avoiding a need to rebase/revert the remote release branch; the local branch will still need to have a commit dropped and tag deleted before rerunning the 'release' script. Prompt the user if the 'release' script is not being run in '--dry-run' mode. Provide additional visual indicators of '--dry-run' mode. Force the user to supply '--repo-branch [branch]' if the intention is to release from a branch other than master.
1 parent 17cec1b commit 3af2618

14 files changed

+236
-105
lines changed
 

‎.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ CONTRIBUTING.md
99
appveyor.yml
1010
babel.config.js
1111
dist/test
12+
dist/typings
1213
header.png
1314
npm-debug.log*
1415
npm-shrinkwrap.json
1516
package-lock.json
17+
scripts
1618
src
1719
test_apps
1820
tsconfig.json

‎.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
engine-strict = true
22
package-lock = false
33
save-exact = true
4+
scripts-prepend-node-path = true

‎.travis.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@ os:
33
- linux
44
- osx
55
node_js:
6-
- "8.11.3"
76
- "8"
87
- "10"
98
before_install:
109
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.12.3
1110
- export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
1211
cache:
1312
yarn: true
13+
env:
14+
- EMBARK_NO_PREPARE=true
1415
install:
1516
- yarn install
1617
- cd embark-ui && yarn install && cd ..
17-
- git status && test -z "$(git status --porcelain)"
18+
- npm run check-working-tree
1819
script:
1920
- npm run build:node
2021
- npm test
22+
- npm run check-working-tree

‎.yarnrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--install.check-files true

‎appveyor.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
environment:
22
matrix:
3-
- nodejs_version: "8.11.3"
43
- nodejs_version: "8"
54
- nodejs_version: "10"
5+
EMBARK_NO_PREPARE: true
66
cache:
77
- "%LOCALAPPDATA%\\Yarn"
88
install:
@@ -11,11 +11,13 @@ install:
1111
- cmd /c start /wait msiexec.exe /i yarn-1.12.3.msi /quiet /qn /norestart
1212
- rm yarn-1.12.3.msi
1313
- node --version
14+
- npm --version
1415
- yarn --version
1516
- yarn install
1617
- cd embark-ui && yarn install && cd ..
17-
- git status && node -e "process.exit(require('child_process').execSync('git status --porcelain').toString().trim()===''?0:1)"
18+
- npm run check-working-tree
1819
test_script:
1920
- npm run build:node
2021
- npm test
22+
- npm run check-working-tree
2123
build: off

‎embark-ui/.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
engine-strict = true
22
package-lock = false
33
save-exact = true
4+
scripts-prepend-node-path = true

‎embark-ui/.yarnrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--install.check-files true

‎embark-ui/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"redux": "4.0.1",
7373
"redux-saga": "0.16.2",
7474
"resolve": "1.8.1",
75+
"rimraf": "2.6.2",
7576
"sass-loader": "7.1.0",
7677
"simple-line-icons": "2.4.1",
7778
"style-loader": "0.23.0",
@@ -85,6 +86,7 @@
8586
},
8687
"scripts": {
8788
"build": "node scripts/build.js",
89+
"clean": "rimraf build",
8890
"lint": "eslint src/",
8991
"start": "node scripts/start.js",
9092
"test": "node scripts/test.js"

‎embark-ui/yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -9364,7 +9364,7 @@ rgba-regex@^1.0.0:
93649364
resolved "https://registry.yarnpkg.com/rgba-regex/-/rgba-regex-1.0.0.tgz#43374e2e2ca0968b0ef1523460b7d730ff22eeb3"
93659365
integrity sha1-QzdOLiyglosO8VI0YLfXMP8i7rM=
93669366

9367-
rimraf@2, rimraf@^2.2.8, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2, rimraf@~2.6.2:
9367+
rimraf@2, rimraf@2.6.2, rimraf@^2.2.8, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2, rimraf@~2.6.2:
93689368
version "2.6.2"
93699369
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36"
93709370
integrity sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==

‎package.json

+15-10
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,33 @@
3232
"build": "npm-run-all build:*",
3333
"build:node": "npm run babel:node",
3434
"build:ui": "cd embark-ui && npm run build",
35-
"clean": "rimraf dist embark-*.tgz package embark-ui/build",
35+
"check-no-prepare": "node scripts/check-no-prepare.js",
36+
"check-working-tree": "node scripts/check-working-tree.js",
37+
"clean": "npm-run-all clean:*",
38+
"clean:core": "rimraf dist embark-*.tgz package",
39+
"clean:ui": "cd embark-ui && npm run clean",
3640
"eslint": "eslint",
37-
"install:core": "yarn install",
41+
"install:core": "cross-env EMBARK_NO_PREPARE=t yarn install",
3842
"install:ui": "cd embark-ui && yarn install",
3943
"install_all": "npm-run-all install:*",
4044
"lint": "npm-run-all lint:*",
4145
"lint:js": "npm-run-all lint:js:*",
42-
"lint:js:core": "eslint babel.config.js bin/embark src/bin/ src/lib/",
46+
"lint:js:core": "eslint babel.config.js bin/embark scripts/ src/bin/ src/lib/",
4347
"lint:js:ui": "cd embark-ui && npm run lint",
4448
"lint:ts": "tslint -c tslint.json 'src/**/*.ts'",
45-
"prepublishOnly": "npm-run-all clean build test",
46-
"test": "npm-run-all lint test:*",
47-
"test:core": "mocha dist/test/ --exit --no-timeouts --require source-map-support/register",
48-
"test:test_app": "cross-env DAPP=\"test_app\" npm run test_dapp",
49-
"test:contracts_app": "cross-env DAPP=\"contracts_app\" npm run test_dapp",
50-
"test_dapp": "cross-env-shell \"cd test_apps/$DAPP && npm install && npm test\"",
51-
"release": "./scripts/release",
49+
"prepare": "npm run --silent check-no-prepare && npm-run-all install_all clean build || exit 0",
50+
"prepublishOnly": "npm-run-all test check-working-tree",
51+
"release": "node scripts/release.js",
5252
"start": "run-p start:*",
5353
"start:embark": "run-p start:embark:*",
5454
"start:embark:babel": "npm run babel:watch",
5555
"start:embark:type-check": "npm run type-check:watch",
5656
"start:ui": "cd embark-ui && npm run start",
57+
"test": "npm-run-all lint test:*",
58+
"test:core": "mocha dist/test/ --exit --no-timeouts --require source-map-support/register",
59+
"test:test_app": "cross-env DAPP=test_app npm run test_dapp",
60+
"test:contracts_app": "cross-env DAPP=contracts_app npm run test_dapp",
61+
"test_dapp": "cross-env-shell \"cd test_apps/$DAPP && npm install && npm test\"",
5762
"tsc": "tsc",
5863
"tslint": "tslint",
5964
"type-check": "tsc",

‎scripts/check-no-prepare.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* global process */
2+
3+
process.exit(process.env.EMBARK_NO_PREPARE ? 1 : 0);

‎scripts/check-working-tree.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* global process require */
2+
3+
const {execSync} = require('child_process');
4+
5+
try {
6+
execSync('git status', {stdio: 'inherit'});
7+
process.exit(
8+
execSync('git status --porcelain').toString().trim() === '' ? 0 : 1
9+
);
10+
} catch (e) {
11+
process.exit(1);
12+
}

‎scripts/release

-90
This file was deleted.

0 commit comments

Comments
 (0)