Skip to content

Commit

Permalink
feat(typescript): add types everywhere
Browse files Browse the repository at this point in the history
The whole codebase has been rewritten to TypeScript.
  • Loading branch information
gregberge committed Oct 30, 2021
1 parent 5decc94 commit 9eac2d4
Show file tree
Hide file tree
Showing 174 changed files with 6,808 additions and 19,453 deletions.
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
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
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',
],
}
}
41 changes: 41 additions & 0 deletions build/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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 import/no-dynamic-require
const pkg = require(path.resolve(process.cwd(), './package.json'))

// eslint-disable-next-line import/no-dynamic-require
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',
},
}),
]
: []),
]
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

0 comments on commit 9eac2d4

Please sign in to comment.