Skip to content

Commit

Permalink
feat(configs): configure TypeScript build system (#563)
Browse files Browse the repository at this point in the history
* chore(configs): set up TypeScript to compile code

* style(configs): configure Eslint to lint TypeScript

* feat(types): add basic types

* chore(configs): exclude spec and story files from build

* chore(configs): configure Jest for TypeScript

* chore(configs): configure Storybook for TypeScript

* chore(configs): configure static style script for TypeScript

* fix(theme): add missing colors to theme interface

* chore(deps): upgrade to Foundry v2.1

* chore(configs): configure Plop and lint-staged for TypeScript

Co-authored-by: Hugo <hleote@gmail.com>

BREAKING CHANGE: Compile code with TypeScript. The compiler targets ES2020 syntax, so users need to transpile the Circuit UI code themselves.
  • Loading branch information
connor-baer authored Apr 15, 2020
1 parent 42ae124 commit db9d865
Show file tree
Hide file tree
Showing 19 changed files with 1,398 additions and 503 deletions.
39 changes: 1 addition & 38 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,6 @@
]
],
"env": {
"cjs": {
"plugins": [
"@babel/plugin-proposal-class-properties",
"lodash",
"inline-react-svg",
"dev-expression"
],
"presets": [
["@babel/preset-env", { "loose": true }],
"@babel/preset-react",
[
"@emotion/babel-preset-css-prop",
{
"autoLabel": false,
"labelFormat": "[filename]--[local]"
}
]
]
},
"es": {
"plugins": [
"@babel/plugin-proposal-class-properties",
"lodash",
"inline-react-svg",
"dev-expression"
],
"presets": [
["@babel/preset-env", { "loose": true, "modules": false }],
"@babel/preset-react",
[
"@emotion/babel-preset-css-prop",
{
"autoLabel": false,
"labelFormat": "[filename]--[local]"
}
]
]
},
"static": {
"plugins": [
"@babel/plugin-proposal-class-properties",
Expand All @@ -59,6 +21,7 @@
"react-docgen"
],
"presets": [
"@babel/preset-typescript",
[
"@babel/preset-env",
{
Expand Down
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ static/
public/
coverage/
__coverage__/
__reports__/
/*.config.js
/*rc.js
/plopfile.js
/jest.*.js
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
module.exports = require('@sumup/foundry/eslint')(
{
language: 'JavaScript',
language: 'TypeScript',
environments: ['Browser'],
frameworks: ['React', 'Emotion', 'Jest'],
openSource: true
},
{
rules: {
'arrow-parens': 'off'
},
parserOptions: {
project: ['./tsconfig.eslint.json']
}
}
);
12 changes: 7 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: 10.x
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Cache dependencies
uses: actions/cache@v1
id: yarn-cache
with:
path: node_modules
key: ${{ runner.OS }}-node-${{ hashFiles('**/yarn.lock') }}
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.OS }}-node-${{ env.cache-name }}-
${{ runner.OS }}-node-
${{ runner.OS }}-
${{ runner.os }}-yarn-
- name: Install dependencies
run: |
npm install -g yarn
Expand Down
4 changes: 4 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ module.exports = {
'../docs/**/*.(stories|story).(js|ts|tsx|mdx)'
],
addons: [
{
name: '@storybook/preset-typescript',
options: { transpileManager: true }
},
'@storybook/addon-docs/',
'@storybook/addon-storysource',
'@storybook/addon-actions',
Expand Down
9 changes: 5 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
*/

module.exports = {
preset: 'ts-jest',
testURL: 'http://localhost',
coverageDirectory: './__coverage__',
rootDir: '.',
roots: ['src', 'scripts'],
moduleFileExtensions: ['js', 'jsx', 'json'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
collectCoverageFrom: [
'src/@(components|util|styles)/**/*.{js,jsx}',
'!src/@(components|util|styles)/**/index.{js,jsx}',
'!src/@(components|util|styles)/**/*.story.{js,jsx}',
'src/@(components|util|styles)/**/*.{ts,tsx,js,jsx}',
'!src/@(components|util|styles)/**/index.{ts,tsx,js,jsx}',
'!src/@(components|util|styles)/**/*.story.{jts,tsx,s,jsx}',
'!src/@(components|util|styles)/**/*.docs.mdx',
'!**/node_modules/**'
],
Expand Down
13 changes: 0 additions & 13 deletions jsconfig.json

This file was deleted.

2 changes: 1 addition & 1 deletion lint-staged.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
*/

module.exports = require('@sumup/foundry/lint-staged')({
language: 'JavaScript'
language: 'TypeScript'
});
40 changes: 23 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,26 @@
"sideEffects": false,
"version": "0.0.0-semantically-released",
"description": "SumUp's React UI component library",
"main": "build/index.js",
"module": "build/es/index.js",
"main": "dist/index.js",
"module": "dist/index.js",
"files": [
"build",
"dist",
"README.md"
],
"scripts": {
"commit": "git-cz",
"start": "start-storybook -p 6006 -s .storybook/public",
"dev": "tsc --watch",
"build": "tsc",
"create:component": "foundry run plop component",
"static-styles": "cross-env BABEL_ENV=static babel-node ./scripts/static-styles/cli.js",
"build": "rm -rf build && yarn build:cjs && yarn build:es",
"build:cjs": "cross-env BABEL_ENV=cjs babel src --out-dir build --ignore *.spec.js,*.story.js,*.docs.mdx",
"build:es": "cross-env BABEL_ENV=es babel src --out-dir build/es --ignore *.spec.js,*.story.js,*.docs.mdx",
"static-styles": "cross-env BABEL_ENV=static babel-node --extensions '.js,.ts,.tsx' ./scripts/static-styles/cli.js",
"build:docs": "yarn build:storybook && yarn build:stylesheets",
"prebuild:storybook": "yarn test:output",
"build:storybook": "build-storybook -c .storybook -o public -s .storybook/public",
"build:stylesheets": "mkdir -p public/static && yarn static-styles --global --filePath=./public/static/circuit-ui-v1.css",
"build:js": "yarn clean:js && yarn build:js:cjs && yarn build:js:es",
"build:js:cjs": "cross-env BABEL_ENV=cjs babel src --out-dir build --ignore *.spec.js,*.story.js,*.docs.mdx",
"build:js:es": "cross-env BABEL_ENV=es babel src --out-dir build/es --ignore *.spec.js,*.story.js,*.docs.mdx",
"clean:js": "rimraf build",
"lint": "foundry run eslint . --ext .js,.jsx",
"lint": "foundry run eslint . --ext .js,.jsx,.ts,.tsx",
"lint:fix": "yarn lint --fix",
"lint:watch": "onchange \"src/**/*.js\" -- yarn lint",
"lint:watch": "onchange \"src/**/*\" -- yarn lint",
"lint:ci": "yarn lint --format junit -o __reports__/eslint-results.xml",
"test": "jest --silent",
"test:watch": "yarn test --watch",
Expand Down Expand Up @@ -81,6 +76,7 @@
"@babel/node": "^7.6.2",
"@babel/plugin-proposal-class-properties": "^7.4.0",
"@babel/preset-env": "^7.4.2",
"@babel/preset-typescript": "^7.9.0",
"@emotion/babel-preset-css-prop": "^10.0.9",
"@emotion/cache": "^10.0.19",
"@emotion/core": "^10.0.21",
Expand All @@ -97,18 +93,24 @@
"@storybook/addon-storysource": "^5.2.0",
"@storybook/addon-viewport": "^5.2.4",
"@storybook/addons": "^5.2.0",
"@storybook/preset-typescript": "^3.0.0",
"@storybook/react": "^5.2.0",
"@storybook/source-loader": "^5.2.4",
"@sumup/foundry": "^2.0.0",
"@sumup/foundry": "^2.1.0",
"@svgr/webpack": "^4.3.3",
"@testing-library/dom": "^6.5.0",
"@testing-library/jest-dom": "^4.1.0",
"@testing-library/react": "^9.1.4",
"@testing-library/react-hooks": "^2.0.1",
"@testing-library/user-event": "^7.0.1",
"@types/jest": "^25.2.1",
"@types/lodash": "^4.14.149",
"@types/react": "^16.9.32",
"@types/react-dom": "^16.9.6",
"@types/recompose": "^0.30.7",
"audit-ci": "^2.1.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.5.0",
"babel-jest": "^25.0.0",
"babel-loader": "^8.0.5",
"babel-plugin-dev-expression": "^0.2.2",
"babel-plugin-dynamic-import-node": "^2.2.0",
Expand All @@ -125,9 +127,10 @@
"emotion-theming": "^10.0.19",
"eslint-plugin-prettier": "^3.1.0",
"expect": "^24.5.0",
"jest": "^24.5.0",
"fork-ts-checker-webpack-plugin": "^4.1.2",
"jest": "^25.0.0",
"jest-axe": "^3.1.1",
"jest-cli": "^24.5.0",
"jest-cli": "^25.0.0",
"jest-emotion": "^10.0.10",
"license-checker": "^25.0.1",
"onchange": "^6.1.0",
Expand All @@ -141,6 +144,9 @@
"react-swipeable": "^5.4.0",
"react-test-renderer": "^16.8.6",
"style-loader": "^1.0.0",
"ts-jest": "^25.3.1",
"ts-loader": "^6.2.2",
"typescript": "^3.8.3",
"webpack-merge": "^4.2.1"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion plopfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
* limitations under the License.
*/

module.exports = require('@sumup/foundry/plop')({ language: 'JavaScript' });
module.exports = require('@sumup/foundry/plop')({ language: 'TypeScript' });
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('Aggregator', () => {
expect(actual).toMatchSnapshot();
});

it('should render and match snapshot when open', async () => {
it('should render and match snapshot when open', () => {
const { container, getByTestId } = render(
<Aggregator {...props}>
<div data-testid="child">child</div>
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('Aggregator', () => {
expect(childEl).toBeVisible();
});

it('should not toggle when clicking again on the aggregator with a selected child', async () => {
it('should not toggle when clicking again on the aggregator with a selected child', () => {
const onClick = jest.fn();
const { getByTestId } = render(
<Aggregator {...props} onClick={onClick}>
Expand Down Expand Up @@ -161,7 +161,7 @@ describe('Aggregator', () => {
expect(childEl).toBeVisible();
});

it('should close when there are no selected children', async () => {
it('should close when there are no selected children', () => {
const onClick = jest.fn();
const { getByTestId } = render(<MockedNavigation onClick={onClick} />);
const aggregatorEl = getByTestId('aggregator');
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,6 @@ const theme = {
export { theme };

export { styleHelpers, constants as styleConstants } from './styles';

// Types
export { Theme } from './types/theme';
2 changes: 1 addition & 1 deletion src/styles/style-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const divide = (a, b) => a / b;

const transformUnit = (values, transform, allowMultipleUnits = true) => {
const getUnit = (value, otherUnit) => {
const [unit] = String(value).match(/[a-zA-Z]+/) || [];
const [unit] = /[a-zA-Z]+/.exec(value) || [];

const multipleValuesWithUnit = !allowMultipleUnits && unit && otherUnit;
if (multipleValuesWithUnit) {
Expand Down
4 changes: 0 additions & 4 deletions src/themes/circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,3 @@ export const zIndex = {
sidebar: 800,
modal: 1000
};

export const palette = {
divider: 'rgba(0, 0, 0, 0.12)'
};
Loading

0 comments on commit db9d865

Please sign in to comment.