Skip to content

Commit 36ba75f

Browse files
authored
Merge pull request #59 from tkrotoff/react18
Use React 18 in examples + update most npm packages when possible
2 parents e723888 + 5b9692c commit 36ba75f

File tree

187 files changed

+45989
-18031
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+45989
-18031
lines changed

.eslintignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
node_modules/
22
build/
33
dist/
4-
lib/
5-
lib-es5/
64
coverage/

.eslintrc.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,22 @@ const config = {
66
parserOptions: {},
77
extends: [
88
// /!\ Order matters: the next one overrides rules from the previous one
9-
'plugin:unicorn/recommended',
109
'plugin:jest/recommended',
10+
'plugin:unicorn/recommended',
1111
'airbnb',
1212
// Already done by Airbnb
1313
//'plugin:react/recommended'
1414
'plugin:@typescript-eslint/recommended',
15-
'plugin:prettier/recommended',
16-
'prettier/@typescript-eslint',
17-
'prettier/react'
15+
'plugin:prettier/recommended'
1816
],
1917
plugins: ['simple-import-sort', 'react-hooks'],
2018
env: {
2119
browser: true
2220
},
23-
globals: {
24-
// Jest Puppeteer, see https://github.com/smooth-code/jest-puppeteer/blob/v4.0.0/README.md#configure-eslint
25-
page: true
26-
},
21+
globals: {},
2722

2823
rules: {
29-
'no-console': 'off',
24+
'no-console': ['error', { allow: ['error', 'info'] }],
3025
'no-alert': 'off',
3126
'no-underscore-dangle': 'off',
3227
'no-plusplus': 'off',
@@ -46,10 +41,10 @@ const config = {
4641
'import/prefer-default-export': 'off',
4742
'import/extensions': 'off',
4843

49-
'simple-import-sort/sort': [
44+
'simple-import-sort/imports': [
5045
'error',
5146
{
52-
// https://github.com/lydell/eslint-plugin-simple-import-sort/blob/v5.0.2/src/sort.js#L3-L15
47+
// https://github.com/lydell/eslint-plugin-simple-import-sort/blob/v7.0.0/src/imports.js#L5
5348
groups: [
5449
// Side effect imports
5550
['^\\u0000'],
@@ -63,8 +58,8 @@ const config = {
6358
],
6459

6560
// Absolute imports and other imports such as Vue-style `@/foo`
66-
// Anything that does not start with a dot
67-
['^[^.]'],
61+
// Anything not matched in another group
62+
['^'],
6863

6964
// Relative imports
7065
[
@@ -86,6 +81,7 @@ const config = {
8681
]
8782
}
8883
],
84+
'simple-import-sort/exports': 'error',
8985

9086
// https://github.com/typescript-eslint/typescript-eslint/blob/v4.1.0/packages/eslint-plugin/docs/rules/no-use-before-define.md
9187
'no-use-before-define': 'off',
@@ -119,21 +115,38 @@ const config = {
119115
// [IE does not support for...of](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of#Browser_compatibility)
120116
'unicorn/no-for-loop': 'off',
121117
'unicorn/no-null': 'off',
118+
// https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v27.0.0/docs/rules/no-array-for-each.md
119+
// https://github.com/github/eslint-plugin-github/blob/v4.1.1/docs/rules/array-foreach.md
120+
// conflicts with
121+
// https://github.com/airbnb/javascript/issues/1271
122+
'unicorn/no-array-for-each': 'off',
123+
// FIXME Activate when ES modules are well supported
124+
'unicorn/prefer-module': 'off',
122125
'unicorn/prefer-query-selector': 'off',
126+
'unicorn/numeric-separators-style': 'off',
127+
'unicorn/no-await-expression-member': 'off',
123128

124129
'jsx-a11y/label-has-associated-control': 'off',
125130

126131
'react/no-unescaped-entities': 'off',
127132
'react/jsx-filename-extension': ['error', { extensions: ['.tsx', '.jsx'] }],
133+
'react/jsx-uses-react': 'off',
134+
'react/react-in-jsx-scope': 'off',
135+
// FIXME https://github.com/yannickcr/eslint-plugin-react/issues/3114#issuecomment-951725512
136+
'react/jsx-no-bind': 'off',
128137
'react/jsx-pascal-case': 'off',
129138
'react/jsx-props-no-spreading': 'off',
130139
'react/static-property-placement': 'off',
131140
'react/state-in-constructor': 'off',
141+
'react/no-unused-class-component-methods': 'off',
142+
'react/no-unstable-nested-components': 'off',
143+
'react/require-default-props': 'off',
144+
'react/default-props-match-prop-types': 'off',
145+
'react/no-unused-prop-types': 'off',
132146

133147
'react-hooks/rules-of-hooks': 'error',
134148
'react-hooks/exhaustive-deps': 'error',
135149

136-
'jest/no-expect-resolves': 'error',
137150
'jest/expect-expect': 'off'
138151
},
139152

@@ -154,8 +167,10 @@ const config = {
154167
}
155168
},
156169
{
157-
files: ['*.test.tsx'],
170+
files: ['*.test.ts', '*.test.tsx'],
158171
rules: {
172+
'unicorn/consistent-function-scoping': 'off',
173+
159174
'jsx-a11y/iframe-has-title': 'off'
160175
}
161176
}

.github/workflows/node.js.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# https://github.com/actions/starter-workflows/blob/c934669ce246e6d64e54006b714b04199cbe445b/ci/node.js.yml
1+
# https://github.com/actions/starter-workflows/blob/692c4c52607f67dd3ee34ad0b7c26066ae85bbae/ci/node.js.yml
22

33
name: Node.js CI
44

@@ -11,19 +11,18 @@ jobs:
1111

1212
strategy:
1313
matrix:
14-
node-version: [12.x, 14.x]
14+
node-version: [16.x, 18.x]
1515

1616
steps:
17-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v3
1818
- name: Use Node.js ${{matrix.node-version}}
19-
uses: actions/setup-node@v1
19+
uses: actions/setup-node@v3
2020
with:
2121
node-version: ${{matrix.node-version}}
22-
- run: yarn install
23-
- run: yarn prepublishOnly
24-
- run: yarn build
25-
- run: yarn lint
26-
- run: yarn test:coverage
27-
- run: yarn test:e2e
28-
env:
29-
CI: true
22+
cache: 'npm'
23+
- run: npm install
24+
- run: npx playwright install --with-deps
25+
- run: npm run build
26+
- run: npm run lint
27+
- run: npm run test:coverage
28+
- run: npm run test:e2e

.github/workflows/npm-publish.yml

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# https://github.com/actions/starter-workflows/blob/c934669ce246e6d64e54006b714b04199cbe445b/ci/npm-publish.yml
1+
# https://github.com/actions/starter-workflows/blob/692c4c52607f67dd3ee34ad0b7c26066ae85bbae/ci/npm-publish.yml
22

33
name: Node.js Package
44

@@ -10,28 +10,27 @@ jobs:
1010
build:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
14-
- uses: actions/setup-node@v1
13+
- uses: actions/checkout@v3
14+
- uses: actions/setup-node@v3
1515
with:
16-
node-version: 12
17-
- run: yarn install
18-
- run: yarn prepublishOnly
19-
- run: yarn build
20-
- run: yarn lint
21-
- run: yarn test:coverage
22-
- run: yarn test:e2e
16+
node-version: 16
17+
- run: npm install
18+
- run: npm run prepublishOnly
19+
- run: npm run build
20+
- run: npm run lint
21+
- run: npm run test:coverage
22+
- run: npm run test:e2e
2323

2424
publish-npm:
2525
needs: build
2626
runs-on: ubuntu-latest
2727
steps:
28-
- uses: actions/checkout@v2
29-
- uses: actions/setup-node@v1
28+
- uses: actions/checkout@v3
29+
- uses: actions/setup-node@v3
3030
with:
31-
node-version: 12
31+
node-version: 16
3232
registry-url: https://registry.npmjs.org/
33-
- run: yarn install
34-
- run: yarn prepublishOnly
35-
- run: yarn lerna publish from-git --yes
33+
- run: npm install
34+
- run: npm run publish
3635
env:
3736
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

.gitignore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ node_modules/
44
# Generated files
55
build/
66
dist/
7-
lib/
8-
lib-es5/
97
coverage/
108

11-
# rollup-plugin-typescript2
12-
# [.rpt2_cache should be in /tmp](https://github.com/ezolenko/rollup-plugin-typescript2/issues/34)
13-
.rpt2_cache/
9+
# React Native example
10+
examples/ReactNative/package-lock.json
11+
examples/ReactNative/.expo/
12+
examples/ReactNative/ios/
13+
examples/ReactNative/android/

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npm run precommit

.husky/pre-push

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npm run prepush

.huskyrc.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

.prettierignore

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
.git/
2+
.husky/
23
node_modules/
34
build/
45
dist/
5-
lib/
6-
lib-es5/
76
coverage/
87
.gitignore
98
.prettierignore
109
.eslintignore
1110
.editorconfig
1211
.browserslistrc
1312
*.png
14-
yarn.lock
15-
yarn-error.log
13+
package-lock.json
1614
LICENSE
15+
16+
# React Native example
17+
examples/ReactNative/.expo/
18+
examples/ReactNative/ios/
19+
examples/ReactNative/android/

.stylelintrc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @ts-check
22

3-
/** @type {Partial<import('stylelint').Configuration>} */
3+
/** @type {Partial<import('stylelint').Config>} */
44
const config = {
55
extends: [
66
// /!\ Order matters: the next one overrides rules from the previous one
77

8-
// Includes stylelint-config-recommended-scss and stylelint-config-standard
9-
'stylelint-config-twbs-bootstrap/scss',
8+
// Extends stylelint-config-standard-scss which extends stylelint-config-recommended-scss
9+
'stylelint-config-twbs-bootstrap',
1010

1111
'stylelint-prettier/recommended'
1212
],

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## v0.19.0 (2022/07/21)
2+
3+
- Fix React 18 types (#58)
4+
- Use React 18 in examples
5+
- Update most npm packages when possible
6+
- Switch from Puppeteer to Playwright
7+
- Remove Yarn, use npm workspaces instead
8+
- Use Lerna only for `npm run version`
9+
110
## v0.18.0 (2021/05/20)
211

312
### Breaking Changes

README.md

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -335,67 +335,6 @@ You can use HTML5 attributes like `type="email"`, `required`, [`minlength`](http
335335

336336
In the last case you will have to manage translations yourself (see SignUp example).
337337

338-
## How to consume the npm packages?
339-
340-
### ESNext (currently ES2018) + ES modules
341-
342-
Files inside [`lib/`](https://unpkg.com/react-form-with-constraints@latest/lib/) (package.json `"module": "lib/index.js"`).
343-
344-
A recent browser or Node.js is required or you will need to transpile the react-form-with-constraints source code using Babel (or TypeScript tsc).
345-
346-
Several advantages:
347-
348-
- The combine use of `"sideEffects": false` with `"module": ...` generates a smaller bundle thanks to [tree shaking](https://webpack.js.org/guides/tree-shaking/)
349-
- You can transpile react-form-with-constraints source code with your Babel's [preset-env](https://babeljs.io/docs/en/babel-preset-env) and [Browserslist](https://github.com/browserslist/browserslist) configuration
350-
351-
For this to work, do not exclude `node_modules` from your webpack configuration, example:
352-
353-
```JS
354-
// webpack.config.js
355-
module: {
356-
rules: [
357-
{
358-
test: /\.jsx?$/,
359-
360-
//exclude: /node_modules/,
361-
// [Babel should not transpile core-js](https://github.com/zloirock/core-js/issues/514#issuecomment-476533317)
362-
exclude: /\/core-js/,
363-
364-
loader: 'babel-loader'
365-
}
366-
]
367-
}
368-
```
369-
370-
```JS
371-
// babel.config.js
372-
module.exports = {
373-
presets: [
374-
[
375-
'@babel/preset-env',
376-
{
377-
useBuiltIns: 'entry',
378-
corejs: 3
379-
}
380-
],
381-
'@babel/preset-react'
382-
],
383-
plugins: []
384-
};
385-
```
386-
387-
### ES5 + CommonJS
388-
389-
Classic ES5 transpilation, files inside [`lib-es5/`](https://unpkg.com/react-form-with-constraints@latest/lib-es5/) (package.json `"main": "lib-es5/index.js"`).
390-
No tree shaking.
391-
392-
### UMD (Universal Module Definition) + ES5
393-
394-
Files inside [`dist/`](https://unpkg.com/react-form-with-constraints@latest/dist/).
395-
Typical use is with `<script src="react-form-with-constraints.production.min.js">` inside your index.html.
396-
397-
A good use case is [CodePen](https://codepen.io/tkrotoff/pen/BRGdqL), files are generated by [Rollup](packages/react-form-with-constraints/rollup.config.js).
398-
399338
## Notes
400339

401340
- A [`type="hidden"`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/hidden#Validation), [`readonly`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-readonly) or [`disabled`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-disabled) input won't trigger any HTML5 form constraint validation like [`required`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-required), see https://codepen.io/tkrotoff/pen/gdjVNv

examples/Bootstrap/App.jsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import 'core-js';
44
import 'regenerator-runtime/runtime';
55
import 'raf/polyfill';
66

7-
import React, { useRef, useState } from 'react';
7+
import { useRef, useState } from 'react';
88
import { isEqual } from 'lodash-es';
9-
import ReactDOM from 'react-dom';
9+
import { createRoot } from 'react-dom/client';
1010
import {
1111
Async,
1212
FieldFeedback,
@@ -20,11 +20,13 @@ import './index.html';
2020
import './App.scss';
2121

2222
function wait(ms) {
23-
return new Promise(resolve => setTimeout(resolve, ms));
23+
return new Promise(resolve => {
24+
setTimeout(resolve, ms);
25+
});
2426
}
2527

2628
async function checkUsernameAvailability(value) {
27-
console.log('checkUsernameAvailability');
29+
console.info('checkUsernameAvailability');
2830
await wait(1000);
2931
return !['john', 'paul', 'george', 'ringo'].includes(value.toLowerCase());
3032
}
@@ -214,4 +216,5 @@ function App() {
214216
);
215217
}
216218

217-
ReactDOM.render(<App />, document.getElementById('app'));
219+
const root = createRoot(document.getElementById('app'));
220+
root.render(<App />);

0 commit comments

Comments
 (0)