Skip to content

Commit

Permalink
build(wireit): wireit for npm scripts
Browse files Browse the repository at this point in the history
Use google wireit to handle complex script runs, and some minor improvements
  • Loading branch information
asmyshlyaev177 committed Oct 31, 2023
1 parent b418147 commit 37ac2f5
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 35 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 14.x
node-version: 16.x
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
Expand All @@ -34,6 +34,7 @@ jobs:
- name: Install
run: |
yarn setup
- uses: google/wireit@setup-github-actions-caching/v1

- name: Unit tests
run: yarn test:unit --coverage --coverageReporters="lcov"
Expand All @@ -46,14 +47,14 @@ jobs:
coverage-reports: coverage/lcov.info

- name: E2E tests
uses: cypress-io/github-action@v2
uses: google/wireit@setup-github-actions-caching/v1
- uses: cypress-io/github-action@v2
timeout-minutes: 30
env:
NODE_OPTIONS: --max-old-space-size=4096
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
env: true
# install-command: yarn install --immutable
command: yarn test:e2e

- uses: actions/upload-artifact@v1
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ yarn-error.log
**/.pnp.*

cypress/videos
cypress/screenshots
cypress/screenshots

.wireit
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn test:unit && yarn test:e2e
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v14.19.3
v16
1 change: 1 addition & 0 deletions example-nextjs/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry = "https://registry.npmjs.com/"
1 change: 1 addition & 0 deletions example-nextjs/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
145 changes: 121 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,130 @@
}
},
"scripts": {
"test:unit": "jest",
"test:e2e": "run-p -r demo:test cypress:run-with-wait",
"cypress:run-with-wait": "run-s wait cypress:run",
"cypress:run": "cypress run",
"dev": "cross-env IS_DEVELOPMENT=true rollup -c rollup.config.js -w",
"test:unit": "wireit",
"test:e2e": "wireit",
"dev": "wireit",
"dev2": "webpack -w",
"kill-rollup": "sleep 3 && ps aux | grep rollup | awk '{print $2}' | xargs kill -9 &",
"postbuild": "wait-on dist/index.cjs dist/index.mjs dist/types && sleep 5 && yarn kill-rollup",
"build": "rm -rf dist && rollup -c rollup.config.js &",
"example": "cd example-nextjs && yarn dev",
"example-cra": "cd example-cra && yarn start",
"example:test": "cd example-nextjs && NEXT_PUBLIC_IS_TEST=true CHOKIDAR_USEPOLLING=1 yarn dev",
"wait": "wait-on http://localhost:3003 && sleep 10",
"demo": "run-p dev example",
"demo:test": "run-s build example:test",
"kill-rollup": "wireit",
"build": "wireit",
"demo": "wireit",
"commit": "cz",
"release": "yarn test:unit && yarn test:e2e && standard-version",
"publish": "yarn build && git push --follow-tags origin main && npm publish",
"release": "wireit",
"pub": "wireit",
"setup-yarn": "yarn cache clean && yarn set version 1.22.1",
"install-deps": "cd example-nextjs && yarn install && cd ../ && yarn install",
"setup-husky": "husky install",
"cz-install": "commitizen init cz-conventional-changelog --dev --exact --yarn",
"link-react": "rm -rf node_modules/react && rm -rf node_modules/react-dom && cd example-nextjs/node_modules/react && yarn link && cd ../react-dom && yarn link && cd ../../../ && yarn link react && yarn link react-dom && rm -rf node_modules/react && rm -rf node_modules/react-dom",
"prepare": "yarn link-react",
"setup": "yarn setup-yarn && yarn install-deps && yarn setup-husky && yarn cz-install",
"cz-husky-init": "husky add .husky/commit-msg 'npx --no-install commitlint --edit \"$1\"'",
"install-deps": "wireit",
"setup-husky": "wireit",
"cz-install": "wireit",
"link-react": "wireit",
"setup-tooling": "wireit",
"setup": "yarn setup-yarn && yarn install && yarn setup-tooling",
"cz-husky-init": "wireit",
"deploy-gp": "babel-node deploy-gp.js"
},
"wireit": {
"release": {
"command": "standard-version",
"dependencies": [
"test:unit",
"test:e2e"
]
},
"pub": {
"command": "yarn release && yarn push && npm publish",
"dependencies": [
"build"
]
},
"push": {
"command": "git push --follow-tags origin main"
},
"test:unit": {
"command": "jest",
"dependencies": ["setup-tooling"]
},
"kill-rollup": {
"command": "sleep 3 && ps aux | grep rollup | grep -v grep | awk '{print $2}' | xargs kill -9 && echo 'killed' || echo 'killed'"
},
"test:e2e": {
"command": "npx wait-on http://localhost:3003 && cypress run",
"dependencies": [
"setup-tooling",
"demo"
]
},
"dev": {
"command": "cross-env IS_DEVELOPMENT=true rollup -c rollup.config.js -w",
"service": true,
"dependencies": ["setup-tooling", "kill-rollup"]
},
"demo": {
"command": "cd example-nextjs && yarn dev",
"service": true,
"dependencies": [
"dev",
"kill-rollup"
]
},
"install-deps": {
"command": "yarn install",
"allowUsuallyExcludedPaths": true,
"files": ["package.json", "yarn.lock"]
},
"install-example-deps": {
"command": "cd example-nextjs && yarn install",
"dependencies": [
"install-deps"
],
"allowUsuallyExcludedPaths": true,
"files": ["example-nextjs/package.json", "example-nextjs/yarn.lock"]
},
"link-react": {
"command": "rm -rf node_modules/react && rm -rf node_modules/react-dom && cd example-nextjs/node_modules/react && yarn link && cd ../react-dom && yarn link && cd ../../../ && yarn link react && yarn link react-dom && rm -rf node_modules/react && rm -rf node_modules/react-dom",
"dependencies": [
"install-example-deps",
"install-deps"
]
},
"setup-tooling": {
"command": "echo 'setup tooling'",
"dependencies": [
"install-example-deps",
"setup-husky",
"cz-husky-init",
"cz-install",
"link-react"
]
},
"setup-husky": {
"command": "husky install && cat .husky/pre-commit | grep 'yarn test:unit && yarn test:e2e' ; [ $? -eq 1 ] && npx husky add .husky/pre-commit 'yarn test:unit && yarn test:e2e' || echo 'already installed' ",
"dependencies": [
"install-deps"
],
"allowUsuallyExcludedPaths": true,
"files": [".husky"]
},
"cz-husky-init": {
"command": "cat .husky/commit-msg | grep 'npx --no-install commitlint --edit \"$1\"' ; [ $? -eq 1 ] && husky add .husky/commit-msg 'npx --no-install commitlint --edit \"$1\"' || echo 'commit msg hook installed'",
"dependencies": [
"install-deps",
"setup-husky"
],
"allowUsuallyExcludedPaths": true,
"files": [".husky"]
},
"cz-install": {
"command": "commitizen init cz-conventional-changelog --dev --exact --yarn",
"dependencies": [
"install-deps"
]
},
"build": {
"command": "rollup -c rollup.config.js",
"clean": true,
"output": ["dist", "dist/index.cjs", "dist/index.mjs", "dist/types" ],
"dependencies": ["setup-tooling", "kill-rollup"]
}
},
"keywords": [
"react",
"react-component",
Expand Down Expand Up @@ -153,7 +249,8 @@
"wait-on": "^7.0.1",
"webpack": "^5.72.0",
"webpack-cli": "^4.7.2",
"webpack-merge": "^5.8.0"
"webpack-merge": "^5.8.0",
"wireit": "^0.14.1"
},
"peerDependencies": {
"react": ">=16.8"
Expand Down
82 changes: 76 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2560,7 +2560,7 @@ ansi-styles@^5.0.0:
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-5.2.0.tgz#07449690ad45777d1924ac2abb2fc8895dba836b"
integrity sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==

anymatch@^3.0.3:
anymatch@^3.0.3, anymatch@~3.1.2:
version "3.1.3"
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.3.tgz#790c58b19ba1720a84205b57c618d5ad8524973e"
integrity sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==
Expand Down Expand Up @@ -2921,6 +2921,11 @@ bcrypt-pbkdf@^1.0.0:
dependencies:
tweetnacl "^0.14.3"

binary-extensions@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d"
integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==

bl@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/bl/-/bl-4.1.0.tgz#451535264182bec2fbbc83a62ab98cf11d9f7b3a"
Expand Down Expand Up @@ -2974,7 +2979,7 @@ brace-expansion@^2.0.1:
dependencies:
balanced-match "^1.0.0"

braces@^3.0.2:
braces@^3.0.2, braces@~3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==
Expand Down Expand Up @@ -3190,6 +3195,21 @@ check-more-types@^2.24.0:
resolved "https://registry.yarnpkg.com/check-more-types/-/check-more-types-2.24.0.tgz#1420ffb10fd444dcfc79b43891bbfffd32a84600"
integrity sha512-Pj779qHxV2tuapviy1bSZNEL1maXr13bPYpsvSDB68HlYcYuhlDrmGd63i0JHMCLKzc7rUSNIrpdJlhVlNwrxA==

chokidar@^3.5.3:
version "3.5.3"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd"
integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==
dependencies:
anymatch "~3.1.2"
braces "~3.0.2"
glob-parent "~5.1.2"
is-binary-path "~2.1.0"
is-glob "~4.0.1"
normalize-path "~3.0.0"
readdirp "~3.6.0"
optionalDependencies:
fsevents "~2.3.2"

chownr@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/chownr/-/chownr-2.0.0.tgz#15bfbe53d2eab4cf70f18a8cd68ebe5b3cb1dece"
Expand Down Expand Up @@ -4816,6 +4836,17 @@ fast-diff@^1.1.2:
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==

fast-glob@^3.2.11:
version "3.3.1"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.3.1.tgz#784b4e897340f3dbbef17413b3f11acf03c874c4"
integrity sha512-kNFPyjhh5cKjrUltxs+wFx+ZkbRaxxmZ+X0ZU31SOsxCEtP9VPgtq2teZw1DebupL5GmDaNQ6yKMMVcM41iqDg==
dependencies:
"@nodelib/fs.stat" "^2.0.2"
"@nodelib/fs.walk" "^1.2.3"
glob-parent "^5.1.2"
merge2 "^1.3.0"
micromatch "^4.0.4"

fast-glob@^3.2.9:
version "3.2.12"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.12.tgz#7f39ec99c2e6ab030337142da9e0c18f37afae80"
Expand Down Expand Up @@ -5302,7 +5333,7 @@ gitconfiglocal@^1.0.0:
dependencies:
ini "^1.3.2"

glob-parent@^5.1.2:
glob-parent@^5.1.2, glob-parent@~5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4"
integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==
Expand Down Expand Up @@ -5849,6 +5880,13 @@ is-bigint@^1.0.1:
dependencies:
has-bigints "^1.0.1"

is-binary-path@~2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09"
integrity sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==
dependencies:
binary-extensions "^2.0.0"

is-boolean-object@^1.1.0:
version "1.1.2"
resolved "https://registry.yarnpkg.com/is-boolean-object/-/is-boolean-object-1.1.2.tgz#5c6dc200246dd9321ae4b885a114bb1f75f63719"
Expand Down Expand Up @@ -5912,7 +5950,7 @@ is-generator-fn@^2.0.0:
resolved "https://registry.yarnpkg.com/is-generator-fn/-/is-generator-fn-2.1.0.tgz#7d140adc389aaf3011a8f2a2a4cfa6faadffb118"
integrity sha512-cTIB4yPYL/Grw0EaSzASzg6bBy9gqCofvWN8okThAYIxKJZC+udlRAmGbM0XLeniEJSs8uEgHPGuHSe1XsOLSQ==

is-glob@^4.0.0, is-glob@^4.0.1:
is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1:
version "4.0.3"
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084"
integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==
Expand Down Expand Up @@ -6795,6 +6833,11 @@ [email protected], json5@^2.2.2:
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283"
integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==

jsonc-parser@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.2.0.tgz#31ff3f4c2b9793f89c67212627c51c6394f88e76"
integrity sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==

jsonfile@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
Expand Down Expand Up @@ -7584,7 +7627,7 @@ normalize-package-data@^3.0.0:
semver "^7.3.4"
validate-npm-package-license "^3.0.1"

normalize-path@^3.0.0:
normalize-path@^3.0.0, normalize-path@~3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==
Expand Down Expand Up @@ -8085,7 +8128,7 @@ picocolors@^1.0.0:
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"
integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==

picomatch@^2.0.4, picomatch@^2.2.2, picomatch@^2.2.3, picomatch@^2.3.1:
picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.2.2, picomatch@^2.2.3, picomatch@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
Expand Down Expand Up @@ -8527,6 +8570,15 @@ prop-types@^15.8.1:
object-assign "^4.1.1"
react-is "^16.13.1"

proper-lockfile@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/proper-lockfile/-/proper-lockfile-4.1.2.tgz#c8b9de2af6b2f1601067f98e01ac66baa223141f"
integrity sha512-TjNPblN4BwAWMXU8s9AEz4JmQxnD1NNL7bNOY/AKUzyamc379FWASUhc/K1pL2noVb+XmZKLL68cjzLsiOAMaA==
dependencies:
graceful-fs "^4.2.4"
retry "^0.12.0"
signal-exit "^3.0.2"

[email protected]:
version "1.0.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.0.0.tgz#33c50398f70ea7eb96d21f7b817630a55791c7ee"
Expand Down Expand Up @@ -8691,6 +8743,13 @@ readable-stream@^2.0.1, readable-stream@^2.0.6, readable-stream@~2.3.6:
string_decoder "~1.1.1"
util-deprecate "~1.0.1"

readdirp@~3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.6.0.tgz#74a370bd857116e245b29cc97340cd431a02a6c7"
integrity sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==
dependencies:
picomatch "^2.2.1"

rechoir@^0.7.0:
version "0.7.1"
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.7.1.tgz#9478a96a1ca135b5e88fc027f03ee92d6c645686"
Expand Down Expand Up @@ -10380,6 +10439,17 @@ wildcard@^2.0.0:
resolved "https://registry.yarnpkg.com/wildcard/-/wildcard-2.0.0.tgz#a77d20e5200c6faaac979e4b3aadc7b3dd7f8fec"
integrity sha512-JcKqAHLPxcdb9KM49dufGXn2x3ssnfjbcaQdLlfZsL9rH9wgDQjUtDxbo8NE0F6SFvydeu1VhZe7hZuHsB2/pw==

wireit@^0.14.1:
version "0.14.1"
resolved "https://registry.yarnpkg.com/wireit/-/wireit-0.14.1.tgz#83b63598503573db6722ad49b1fe15b57ee71890"
integrity sha512-q5sixPM/vKQEpyaub6J9QoHAFAF9g4zBdnjoYelH9/RLAekcUf3x1dmFLACGZ6nYjqehCsTlXC1irmzU7znPhA==
dependencies:
braces "^3.0.2"
chokidar "^3.5.3"
fast-glob "^3.2.11"
jsonc-parser "^3.0.0"
proper-lockfile "^4.1.2"

word-wrap@^1.0.3, word-wrap@^1.2.3, word-wrap@~1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"
Expand Down

0 comments on commit 37ac2f5

Please sign in to comment.