Skip to content

Commit

Permalink
simplify example development (#1787)
Browse files Browse the repository at this point in the history
* simplify example development

* move setup to test folder
  • Loading branch information
huozhi authored Jan 14, 2022
1 parent d45b05d commit 1cd8b7b
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 162 deletions.
7 changes: 1 addition & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,10 @@ yarn watch

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

```sh
cd examples/basic && yarn && npx yalc link swr
```

After setup, back to the root directory and run:

```sh
# by default it will run next dev for the example
yarn dev-next basic
yarn next dev examples/basic
```

All examples are built with Next.js, so Next.js commands are all supported:
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
testEnvironment: 'jsdom',
testRegex: '/test/.*\\.test\\.tsx?$',
modulePathIgnorePatterns: ['<rootDir>/examples/'],
setupFilesAfterEnv: ['<rootDir>/scripts/jest-setup.ts'],
setupFilesAfterEnv: ['<rootDir>/test/jest-setup.ts'],
moduleNameMapper: {
'^swr$': '<rootDir>/src',
'^swr/infinite$': '<rootDir>/infinite/index.ts',
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"scripts": {
"clean": "rimraf dist infinite/dist immutable/dist",
"build": "yarn build:core && yarn build:infinite && yarn build:immutable",
"watch": "yalc publish && node scripts/watch.js",
"watch": "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",
Expand All @@ -52,9 +52,7 @@
"format": "prettier --write ./**/*.{ts,tsx}",
"lint": "eslint . --ext .ts,.tsx --cache",
"lint:fix": "yarn lint --fix",
"test": "jest --coverage",
"register": "yarn link && cd node_modules/react && yarn link",
"dev-next": "node scripts/dev-next.js"
"test": "jest --coverage"
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -90,6 +88,7 @@
"husky": "2.4.1",
"jest": "27.0.6",
"lint-staged": "8.2.1",
"next": "12.0.8",
"npm-run-all": "4.1.5",
"prettier": "2.5.0",
"react": "17.0.1",
Expand All @@ -98,7 +97,7 @@
"react-experimental": "npm:react@alpha",
"rimraf": "3.0.2",
"typescript": "4.4.3",
"yalc": "1.0.0-pre.53"
"swr": "link:./"
},
"peerDependencies": {
"react": "^16.11.0 || ^17.0.0 || ^18.0.0"
Expand Down
50 changes: 0 additions & 50 deletions scripts/dev-next.js

This file was deleted.

12 changes: 0 additions & 12 deletions scripts/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ function watch(rollupWatcher) {
rollupWatcher.on('event', event => {
if (event.code === 'BUNDLE_END') {
event.result.close()
push()
}
if (event.code === 'ERROR') {
error(event.error)
Expand All @@ -61,21 +60,10 @@ function watch(rollupWatcher) {
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()
File renamed without changes.
2 changes: 1 addition & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"rootDir": "..",
"strict": false
},
"include": [".", "../scripts/jest-setup.ts"],
"include": [".", "./jest-setup.ts"],
// This file need "strict": true
"exclude": ["./type/mutator.ts"]
}
Loading

0 comments on commit 1cd8b7b

Please sign in to comment.