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

feat(typescript): add types everywhere #611

Merged
merged 1 commit into from
Oct 31, 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
21 changes: 0 additions & 21 deletions .babelrc

This file was deleted.

4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
node_modules/
lib/
__fixtures__/
__fixtures_build__/
coverage/
examples/
svgr.now.sh/
/website/
/website/
dist/
38 changes: 19 additions & 19 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"root": true,
"parser": "babel-eslint",
"extends": ["airbnb", "prettier"],
"env": {
"jest": true
"node": true
},
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
"plugin:react/recommended"
],
"rules": {
"no-plusplus": "off",
"no-shadow": "off",
"class-methods-use-this": "off",
"no-param-reassign": "off",
"no-use-before-define": "off",
"import/prefer-default-export": "off",
"import/no-extraneous-dependencies": "off",
"import/extensions": "off",
"react/jsx-filename-extension": ["error", { "extensions": [".js"] }],
"react/jsx-wrap-multilines": "off",
"react/no-unused-state": "off",
"react/destructuring-assignment": "off",
"react/prop-types": "off",
"react/sort-comp": "off",
"react/jsx-props-no-spreading": "off",
"react/state-in-constructor": "off"
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": "warn",
"@typescript-eslint/ban-types": "warn",
"react/prop-types": "off"
},
"settings": {
"react": {
"version": "detect"
}
}
}
7 changes: 2 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Use npm v7
run: npm i -g npm@7 --registry=https://registry.npmjs.org
- name: Use latest npm
run: npm i -g npm@latest --registry=https://registry.npmjs.org
if: ${{ matrix.node-version == '12.x' || matrix.node-version == '14.x' }}

- name: Install dependencies
Expand All @@ -38,9 +38,6 @@ jobs:
- name: Lint
run: npm run lint

- name: Check DTS
run: npx check-dts

- name: Test
run: npm run test -- --ci --coverage

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules/
lib/
dist/
!svgr.now.sh/lib/
__fixtures_build__/
src/__fixtures__/dist/
Expand Down
23 changes: 0 additions & 23 deletions .gitpod.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ __fixtures__/
CHANGELOG.md
package.json
lerna.json
lib/
dist/
.next/
/website/.cache/
/website/public/
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ _Before_ submitting a pull request, please make sure the following is done…

Note: Replace `<your_username>` with your GitHub username

2. Run `npm install`.
2. Run `npm install` and `npm run build`.

3. If you've added code that should be tested, add tests. You can use watch mode that continuously transforms changed files to make your life easier.

Expand Down
5 changes: 2 additions & 3 deletions __fixtures__/custom-index.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const indexTemplate = require('./custom-index-template.js')

function template(
{ template },
opts,
{ imports, componentName, props, jsx, exports },
{ tpl }
) {
return template.ast`${imports}
return tpl`${imports}
export function ${componentName}(${props}) {
return ${jsx};
}
Expand Down
3 changes: 1 addition & 2 deletions api/api/svgr.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable import/no-unresolved */
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable @typescript-eslint/no-var-requires */
const { default: svgr } = require('@svgr/core')
const { default: jsx } = require('@svgr/plugin-jsx')
const { default: svgo } = require('@svgr/plugin-svgo')
Expand Down
14 changes: 9 additions & 5 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const path = require('path')
const fs = require('fs')
module.exports = (api) => {
api.cache(true)

const config = fs.readFileSync(path.join(__dirname, '.babelrc'))

module.exports = JSON.parse(config)
return {
presets: [
['@babel/preset-env', { targets: { node: '12' }, loose: true }],
'@babel/preset-typescript',
],
}
}
20 changes: 20 additions & 0 deletions build/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -e

npm run build --workspace @svgr/babel-plugin-add-jsx-attribute
npm run build --workspace @svgr/babel-plugin-remove-jsx-attribute
npm run build --workspace @svgr/babel-plugin-remove-jsx-empty-expression
npm run build --workspace @svgr/babel-plugin-replace-jsx-attribute-value
npm run build --workspace @svgr/babel-plugin-svg-dynamic-title
npm run build --workspace @svgr/babel-plugin-svg-em-dimensions
npm run build --workspace @svgr/babel-plugin-transform-react-native-svg
npm run build --workspace @svgr/babel-plugin-transform-svg-component
npm run build --workspace @svgr/babel-preset
npm run build --workspace @svgr/core
npm run build --workspace @svgr/hast-util-to-babel-ast
npm run build --workspace @svgr/plugin-jsx
npm run build --workspace @svgr/plugin-prettier
npm run build --workspace @svgr/plugin-svgo
npm run build --workspace @svgr/cli
npm run build --workspace @svgr/rollup
npm run build --workspace @svgr/webpack
39 changes: 39 additions & 0 deletions build/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import path from 'path'
import json from '@rollup/plugin-json'
import dts from 'rollup-plugin-dts'
import esbuild from 'rollup-plugin-esbuild'

// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require(path.resolve(process.cwd(), './package.json'))
const name = pkg.main ? pkg.main.replace(/\.js$/, '') : './dist/index'

const bundle = (config) => ({
...config,
input: 'src/index.ts',
external: (id) => !/^[./]/.test(id),
})

export default [
bundle({
plugins: [json(), esbuild()],
output: [
{
file: `${name}.js`,
format: 'cjs',
sourcemap: Boolean(pkg.main),
exports: 'auto',
},
],
}),
...(pkg.main
? [
bundle({
plugins: [dts()],
output: {
file: `${name}.d.ts`,
format: 'es',
},
}),
]
: []),
]
2 changes: 1 addition & 1 deletion deprecated-packages/svgr/message.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable no-console, import/no-unresolved */
/* eslint-disable @typescript-eslint/no-var-requires */
const githubCurrentUser = require('github-current-user')

githubCurrentUser.verify((err, verified, username) => {
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
watchPathIgnorePatterns: ['__fixtures__', '__fixtures__build__'],
rootDir: 'packages',
transform: {
'^.+\\.(j|t)sx?$': 'babel-jest',
},
}
Loading