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

chroe: use yalc for local development #1508

Merged
merged 3 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
dist/
node_modules
node_modules
scripts
examples
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ dist
examples/**/yarn.lock
package-lock.json
tsconfig.tsbuildinfo
**/*.yalc
yalc.lock
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ To run SWR locally, you can start it with any example in `examples` folder. You
First of all, build SWR assets

```sh
# or `yarn watch`
yarn build
yarn watch
```

Install dependency of the target example, for instance `examples/basic`:

```sh
cd examples/basic && yarn
cd examples/basic && yarn && npx yalc link swr
huozhi marked this conversation as resolved.
Show resolved Hide resolved
```

After setup, back to the root directory and run:
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
"scripts": {
"clean": "rimraf dist infinite/dist immutable/dist",
"build": "yarn build:core && yarn build:infinite && yarn build:immutable",
"watch": "yarn run-p watch:core watch:infinite watch:immutable",
"watch:core": "bunchee src/index.ts --watch",
"watch:infinite": "bunchee index.ts --cwd infinite --watch",
"watch:immutable": "bunchee index.ts --cwd immutable --watch",
"watch": "yalc publish && node scripts/watch.js",
"watch:core": "node scripts/watch.js core",
"watch:infinite": "node scripts/watch.js infinite",
"watch:immutable": "node scripts/watch.js immutable",
"build:core": "bunchee src/index.ts -m --no-sourcemap",
"build:infinite": "bunchee index.ts --cwd infinite -m --no-sourcemap",
"build:immutable": "bunchee index.ts --cwd immutable -m --no-sourcemap",
Expand All @@ -51,7 +51,6 @@
"lint": "eslint . --ext .ts,.tsx --cache",
"lint:fix": "yarn lint --fix",
"test": "jest",
"register": "yarn link && cd node_modules/react && yarn link",
"dev-next": "node scripts/dev-next.js"
},
"husky": {
Expand Down Expand Up @@ -94,7 +93,8 @@
"react-experimental": "npm:react@alpha",
"rimraf": "3.0.2",
"ts-jest": "27.0.3",
"typescript": "4.4.3"
"typescript": "4.4.3",
"yalc": "1.0.0-pre.53"
},
"peerDependencies": {
"react": "^16.11.0 || ^17.0.0 || ^18.0.0"
Expand Down
11 changes: 2 additions & 9 deletions scripts/dev-next.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,10 @@ const exampleDir = resolve(examplesDir, target)

const nextBin = resolve(exampleDir, 'node_modules/.bin/next')
if (!fs.existsSync(nextBin)) {
error(`Please run "yarn install" inside ${target} example directory\n`)
error(`Please run "yarn install && npx yalc link swr" inside ${target} example directory\n`)
}

const requireHookPath = resolve(__dirname, 'require-hook.js')
const nextConfigPath = resolve(exampleDir, 'next.config.js')
const devCmd = `node -r ${requireHookPath} ${nextBin} ${nextCmd}`.split(' ')

if (!fs.existsSync(nextConfigPath)) {
fs.symlinkSync(resolve(__dirname, 'next-config.js'), nextConfigPath, 'file')
}
const devCmd = `node ${nextBin} ${nextCmd}`.split(' ')

const sub = childProcess.spawn(devCmd.shift(), devCmd, { cwd: exampleDir })

Expand All @@ -47,7 +41,6 @@ sub.stderr.on('close', () => {

const teardown = () => {
if (sub.killed) sub.kill('SIGINT')
if (fs.existsSync(nextConfigPath)) fs.unlinkSync(nextConfigPath)
}

process.on('exit', teardown)
Expand Down
21 changes: 0 additions & 21 deletions scripts/next-config.js

This file was deleted.

20 changes: 0 additions & 20 deletions scripts/require-hook.js

This file was deleted.

81 changes: 81 additions & 0 deletions scripts/watch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* @type {import('bunchee/dist/src/bundle').default}
*/
const bundle = require('bunchee').bundle
const childProcess = require('child_process')

const args = process.argv
const target = args[2]

const entryMap = {
core: {
entry: 'src/index.ts',
cwd: ''
},
infinite: {
entry: 'index.ts',
cwd: 'infinite'
},
immutable: {
entry: 'index.ts',
cwd: 'immutable'
}
}

function error(message) {
console.log(message)
process.exit(1)
}

function start() {
const option = entryMap[target]
if (option) {
bundle(option.entry, {
watch: true,
cwd: option.cwd,
sourcemap: true
})
.then(watch)
.catch(e => {
console.log(e)
})
} else {
error(`package ${target} not found`)
}
}
/**
*
* @param {import('rollup').RollupWatcher} rollupWatcher
*/
function watch(rollupWatcher) {
rollupWatcher.on('event', event => {
if (event.code === 'BUNDLE_END') {
event.result.close()
push()
}
if (event.code === 'ERROR') {
error(event.error)
event.result.close()
}
})
teardown(rollupWatcher.close)
}

function push() {
const sub = childProcess.spawn('yalc', ['push'])
sub.stdout.on('data', logStdout)
sub.stderr.on('data', logStderr)
sub.stderr.on('close', () => {
sub.stdout.off('data', logStdout)
sub.stderr.off('data', logStderr)
})
}

function teardown(cb) {
process.on('exit', cb)
process.on('SIGINT', cb)
}

const logStdout = data => process.stdout.write(data.toString())
const logStderr = data => process.stderr.write(data.toString())
start()
77 changes: 73 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2476,6 +2476,11 @@ delayed-stream@~1.0.0:
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk=

detect-indent@^6.0.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-6.1.0.tgz#592485ebbbf6b3b1ab2be175c8393d04ca0d57e6"
integrity sha512-reYkTUJAZb9gUuZ2RvVCNhVHdg62RHnJ7WJl8ftMi4diZ6NWlciOzQN88pUhSELEwflJht4oQDv0F0BMlwaYtA==

detect-newline@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-3.1.0.tgz#576f5dfc63ae1a192ff192d8ad3af6308991b651"
Expand Down Expand Up @@ -3021,6 +3026,15 @@ fragment-cache@^0.2.1:
dependencies:
map-cache "^0.2.2"

fs-extra@^8.0.1:
version "8.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^4.0.0"
universalify "^0.1.0"

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
Expand Down Expand Up @@ -3168,7 +3182,7 @@ globby@^6.1.0:
pify "^2.0.0"
pinkie-promise "^2.0.0"

graceful-fs@^4.1.2, graceful-fs@^4.2.4:
graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4:
version "4.2.8"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a"
integrity sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==
Expand Down Expand Up @@ -3307,12 +3321,19 @@ iconv-lite@0.4.24:
dependencies:
safer-buffer ">= 2.1.2 < 3"

ignore-walk@^3.0.3:
version "3.0.4"
resolved "https://registry.yarnpkg.com/ignore-walk/-/ignore-walk-3.0.4.tgz#c9a09f69b7c7b479a5d74ac1a3c0d4236d2a6335"
integrity sha512-PY6Ii8o1jMRA1z4F2hRkH/xN59ox43DavKvD3oDpfurRlOJyAHpifIwpbdv1n4jt4ov0jSpw3kQ4GhJnpBL6WQ==
dependencies:
minimatch "^3.0.4"

ignore@^4.0.6:
version "4.0.6"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc"
integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==

ignore@^5.1.4:
ignore@^5.0.4, ignore@^5.1.4:
version "5.1.8"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.8.tgz#f150a8b50a34289b33e22f5889abd4d8016f0e57"
integrity sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==
Expand Down Expand Up @@ -3369,6 +3390,11 @@ inherits@2, inherits@^2.0.4:
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==

ini@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ini/-/ini-2.0.0.tgz#e5fd556ecdd5726be978fa1001862eacb0a94bc5"
integrity sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA==

internal-slot@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/internal-slot/-/internal-slot-1.0.3.tgz#7347e307deeea2faac2ac6205d4bc7d34967f59c"
Expand Down Expand Up @@ -4235,6 +4261,13 @@ json5@2.x, json5@^2.1.2:
dependencies:
minimist "^1.2.5"

jsonfile@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
integrity sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=
optionalDependencies:
graceful-fs "^4.1.6"

jsx-ast-utils@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-2.4.1.tgz#1114a4c1209481db06c690c2b4f488cc665f657e"
Expand Down Expand Up @@ -4675,6 +4708,28 @@ normalize-path@^3.0.0:
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==

npm-bundled@^1.1.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/npm-bundled/-/npm-bundled-1.1.2.tgz#944c78789bd739035b70baa2ca5cc32b8d860bc1"
integrity sha512-x5DHup0SuyQcmL3s7Rx/YQ8sbw/Hzg0rj48eN0dV7hf5cmQq5PXIeioroH3raV1QC1yh3uTYuMThvEQF3iKgGQ==
dependencies:
npm-normalize-package-bin "^1.0.1"

npm-normalize-package-bin@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/npm-normalize-package-bin/-/npm-normalize-package-bin-1.0.1.tgz#6e79a41f23fd235c0623218228da7d9c23b8f6e2"
integrity sha512-EPfafl6JL5/rU+ot6P3gRSCpPDW5VmIzX959Ob1+ySFUuuYHWHekXpwdUZcKP5C+DS4GEtdJluwBjnsNDl+fSA==

npm-packlist@^2.1.5:
version "2.2.2"
resolved "https://registry.yarnpkg.com/npm-packlist/-/npm-packlist-2.2.2.tgz#076b97293fa620f632833186a7a8f65aaa6148c8"
integrity sha512-Jt01acDvJRhJGthnUJVF/w6gumWOZxO7IkpY/lsX9//zqQgnF7OJaxgQXcerd4uQOLu7W5bkb4mChL9mdfm+Zg==
dependencies:
glob "^7.1.6"
ignore-walk "^3.0.3"
npm-bundled "^1.1.1"
npm-normalize-package-bin "^1.0.1"

npm-path@^2.0.2:
version "2.0.4"
resolved "https://registry.yarnpkg.com/npm-path/-/npm-path-2.0.4.tgz#c641347a5ff9d6a09e4d9bce5580c4f505278e64"
Expand Down Expand Up @@ -6124,7 +6179,7 @@ union-value@^1.0.0:
is-extendable "^0.1.1"
set-value "^2.0.1"

universalify@^0.1.2:
universalify@^0.1.0, universalify@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"
integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==
Expand Down Expand Up @@ -6310,6 +6365,20 @@ y18n@^5.0.5:
resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"
integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==

yalc@1.0.0-pre.53:
version "1.0.0-pre.53"
resolved "https://registry.yarnpkg.com/yalc/-/yalc-1.0.0-pre.53.tgz#c51db2bb924a6908f4cb7e82af78f7e5606810bc"
integrity sha512-tpNqBCpTXplnduzw5XC+FF8zNJ9L/UXmvQyyQj7NKrDNavbJtHvzmZplL5ES/RCnjX7JR7W9wz5GVDXVP3dHUQ==
dependencies:
chalk "^4.1.0"
detect-indent "^6.0.0"
fs-extra "^8.0.1"
glob "^7.1.4"
ignore "^5.0.4"
ini "^2.0.0"
npm-packlist "^2.1.5"
yargs "^16.1.1"

yallist@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
Expand All @@ -6320,7 +6389,7 @@ yargs-parser@20.x, yargs-parser@^20.2.2:
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee"
integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==

yargs@^16.0.3:
yargs@^16.0.3, yargs@^16.1.1:
version "16.2.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66"
integrity sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==
Expand Down