Skip to content

Commit a57e291

Browse files
authored
feat: js -> ts (#47)
* refactor: js -> ts refactoring (incl. tests, linter, and bundling) * ci: optimise travis config * improvement: make withCatalog more failure robust * build: optimise webpack build (eg. with externals setting and TerserPlugin) * feat: add CatalogProvider.defaultProps * build: build package with babel, export declarations with tsc * refactor(example): js -> ts(x) example app * chore(ts): fix issue with multiple @types/* packages w/ different version installed
1 parent a748726 commit a57e291

42 files changed

Lines changed: 3025 additions & 3222 deletions

Some content is hidden

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

.eslintrc.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
const path = require('path')
22

33
module.exports = {
4-
extends: 'eslint-config-ns',
4+
extends: [
5+
'eslint-config-ns',
6+
// add typescript specific linting rules and add prettier typescript support
7+
'plugin:@typescript-eslint/recommended',
8+
'prettier/@typescript-eslint',
9+
],
10+
parser: '@typescript-eslint/parser',
511
plugins: ['react-hooks'],
612
globals: {
713
__DEV__: true,
@@ -14,14 +20,24 @@ module.exports = {
1420
'react/prop-types': 0,
1521
'react-hooks/rules-of-hooks': 'error',
1622
'react-hooks/exhaustive-deps': 'error',
23+
'@typescript-eslint/interface-name-prefix': [
24+
2,
25+
{
26+
prefixWithI: 'always',
27+
allowUnderscorePrefix: true,
28+
},
29+
],
1730
},
1831
overrides: [
1932
{
20-
files: ['*.test.js'],
33+
files: ['*.test.ts', '*.test.tsx'],
2134
rules: {
2235
'import/no-extraneous-dependencies': 0,
2336
'max-classes-per-file': 0,
2437
'no-console': 0,
38+
// lets loosen the typescript rules in test files a little
39+
'@typescript-eslint/explicit-function-return-type': 0,
40+
'@typescript-eslint/no-explicit-any': 0,
2541
},
2642
},
2743
],
@@ -34,6 +50,12 @@ module.exports = {
3450
['Base', path.resolve(__dirname, 'example/client/base')],
3551
],
3652
},
53+
node: {
54+
extensions: ['.js', '.jsx', '.ts', '.tsx'],
55+
},
56+
},
57+
react: {
58+
version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
3759
},
3860
},
3961
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ node_modules
1111
tmp
1212

1313
# build
14+
.awcache
15+
build
1416
dist
1517
es
1618
esm

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ language: node_js
33
node_js:
44
- "node"
55

6+
install:
7+
- npm install
8+
69
script:
7-
- npm run test
10+
- npm test --silent
811
- npm run build
912
- npm run size
1013

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ class App extends React.Component {
254254
## How to build and test this package
255255

256256
```sh
257-
# -- build the package--
257+
# -- build the package --
258258
npm i
259-
npm build
259+
npm watch # or build it once with npm run build
260260
```
261261

262262
```sh
@@ -300,6 +300,7 @@ When you're ready to release, execute the following commands in the given order:
300300
- [semantic-release](https://github.com/semantic-release/semantic-release)
301301
(standard-version alternative, with extended CI support)
302302
- [commitlint](https://github.com/conventional-changelog/commitlint)
303+
- [npm-dedupe when eg. multiple @types/\* versions are installed](https://docs.npmjs.com/cli/dedupe.html)
303304

304305
## Credits
305306

babel.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ if (environment === 'es') {
2222

2323
module.exports = {
2424
comments: false,
25-
presets: [...defaultPresets, '@babel/preset-react'],
25+
presets: [
26+
// use babel to create *.js files from *ts(x) ones
27+
'@babel/preset-typescript',
28+
...defaultPresets,
29+
'@babel/preset-react',
30+
],
2631
plugins: [
2732
'@babel/plugin-transform-modules-commonjs',
2833
'@babel/plugin-proposal-class-properties',

example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ For the purpose of this demo this should be enough.
2525
## Setup new clients
2626

2727
In order to serve new clients (eg `hello`) in this demo, one has to extend the
28-
folowing:
28+
following:
2929

3030
1. add new bundle to the [webpack.config.js](./webpack.config.js)
3131
2. allow another client pattern in [server/render.js](./server/render.js))
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)