Skip to content

Commit

Permalink
build: change tsc to babel for build
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Jun 10, 2020
1 parent a188c3b commit 96d58dd
Show file tree
Hide file tree
Showing 8 changed files with 667 additions and 162 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"@typescript-eslint/array-type": "off",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"@typescript-eslint/member-delimiter-style": "off"
"@typescript-eslint/member-delimiter-style": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/ban-types": "off"
}
}
33 changes: 33 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const BABEL_ENV = process.env.BABEL_ENV
const isCommonJS = BABEL_ENV !== undefined && BABEL_ENV === "cjs"
const isESM = BABEL_ENV !== undefined && BABEL_ENV === "esm"

module.exports = function (api) {
api.cache(true)

const presets = [
[
"@babel/env",
{
loose: true,
modules: isCommonJS ? "commonjs" : false,
targets: {
esmodules: isESM ? true : undefined,
},
},
],
"@babel/preset-typescript",
"@babel/preset-react",
]

return {
presets,
ignore: [
"**/*.test.tsx",
"**/*.test.ts",
"**/*.stories.tsx",
"**/*/tests/*",
"**/*/stories/*",
],
}
}
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@
"rimraf": "3.0.2",
"shelljs": "0.8.4",
"ts-jest": "26.1.0",
"typescript": "3.9.5"
"typescript": "3.9.5",
"@babel/cli": "7.10.1",
"@babel/core": "7.10.2",
"@babel/preset-env": "7.10.2",
"@babel/preset-react": "7.10.1",
"@babel/preset-typescript": "7.10.1",
"@babel/runtime": "7.10.2",
"microbundle": "0.12.0"
}
}
5 changes: 3 additions & 2 deletions packages/accordion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@
"prebuild": "rimraf dist",
"start": "nodemon --exec yarn build -e ts,tsx --ignore dist/ --ignore src/tests/ --ignore \"*.stories.tsx\"",
"build": "concurrently yarn:build:*",
"copy:types": "cp -r dist/types/* dist/esm",
"test": "jest --env=jsdom --passWithNoTests",
"lint": "concurrently yarn:lint:*",
"version": "yarn build",
"build:esm": "tsc --module esnext --outDir dist/esm --declaration false",
"build:cjs": "tsc --module commonjs --outDir dist/cjs --declaration false",
"build:esm": "BABEL_ENV=esm babel src --root-mode upward --extensions .ts,.tsx -d dist/esm --source-maps --delete-dir-on-start",
"build:cjs": "BABEL_ENV=esm babel src --root-mode upward --extensions .ts,.tsx -d dist/cjs --source-maps --delete-dir-on-start",
"build:types": "tsc --emitDeclarationOnly --declaration --declarationMap --declarationDir dist/types",
"test:cov": "yarn test --coverage",
"lint:src": "eslint src --ext .ts,.tsx --config ../../.eslintrc",
Expand Down
4 changes: 4 additions & 0 deletions packages/accordion/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"jsx": "react",
"jsxFactory": "React.createElement"
},
"include": ["src", "../../types"],
"exclude": ["src/tests", "**/*/*.stories.tsx"]
}
2 changes: 1 addition & 1 deletion packages/system/src/create-styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { ChakraComponent, Options } from "./system.types"
import { getDisplayName } from "./system.utils"

function createStyled<T extends As, P = {}>(
function createStyled<T extends As, P extends Dict>(
component: T,
options?: Options<T, P>,
) {
Expand Down
23 changes: 9 additions & 14 deletions packages/system/src/system.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SystemProps } from "@chakra-ui/parser"
import { ValidHTMLProps } from "./should-forward-prop"
import { ColorMode } from "@chakra-ui/color-mode"
import { Dict } from "@chakra-ui/utils"

export interface Options<T extends As, P> {
/**
Expand Down Expand Up @@ -160,8 +161,8 @@ export type WithChakra<P> = P extends { transition?: any }
* - Add the `as` prop. in this case, it doesn't do anything special.
* - Return a JSX Element
*/
type RegularComponent<T extends As, P, O extends string> = (
props: WithChakra<Omit<PropsOf<T>, keyof P | O>> & P & { as?: As },
type RegularComponent<T extends As, P> = (
props: WithChakra<Omit<PropsOf<T>, keyof P>> & P & { as?: As },
) => JSX.Element

/**
Expand All @@ -172,21 +173,15 @@ type RegularComponent<T extends As, P, O extends string> = (
* - Use the `WithAs` to merge the base component prop with `as` component prop
* - Add Chakra props to the resulting types.
*/
type ExtensibleComponent<T extends As, P, O extends string> = <
TT extends As = T
>(
props: WithChakra<WithAs<Omit<PropsOf<T>, O>, TT>> & P,
type ExtensibleComponent<T extends As, P> = <TT extends As = T>(
props: WithChakra<WithAs<PropsOf<T>, TT>> & P,
) => JSX.Element

type Component<T extends As, P, O extends string> =
| RegularComponent<T, P, O>
| ExtensibleComponent<T, P, O>
type Component<T extends As, P> =
| RegularComponent<T, P>
| ExtensibleComponent<T, P>

export type ChakraComponent<
T extends As,
P = {},
O extends string = ""
> = Component<T, P, O> & {
export type ChakraComponent<T extends As, P extends Dict> = Component<T, P> & {
displayName?: string
propTypes?: React.WeakValidationMap<PropsOf<T> & P>
defaultProps?: Partial<PropsOf<T> & P & ChakraProps>
Expand Down
Loading

0 comments on commit 96d58dd

Please sign in to comment.