Skip to content

simplify example development #1787

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

Merged
merged 2 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
File renamed without changes.
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>/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()
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