Skip to content

Commit

Permalink
build: update build so that themes declarations are exported
Browse files Browse the repository at this point in the history
This replaces rollup-plugin-dts with the more traditional @rollup/plugin-typescript, as well as move
some types around so themes can be exported as a standalone with its own TypeScript config.

It also restores importing React and the ESLint rule react/react-in-jsx-scope to preserve React 16 compatibility.
  • Loading branch information
WesSouza committed Jul 29, 2022
1 parent 49ab26b commit b4eec70
Show file tree
Hide file tree
Showing 132 changed files with 334 additions and 231 deletions.
6 changes: 4 additions & 2 deletions .codesandbox/ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"installCommand": "install:codesandbox",
"buildCommand": "build:prod",
"sandboxes": ["react95-template-xkfj0"]
"node": "16",
"sandboxes": [
"react95-template-xkfj0"
]
}
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ module.exports = {
'react/jsx-props-no-spreading': 'off',
'react/no-array-index-key': 'off',
'react/prop-types': 'off',
'react/react-in-jsx-scope': 'off',
'react/require-default-props': 'off',
'react/static-property-placement': ['error', 'static public field']
},
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"lint": "eslint --ext .js,.ts,.tsx src",
"lint:fix": "yarn run lint --fix",
"semantic-release": "semantic-release",
"install:codesandbox": "yarn --ignore-engines",
"cz": "git-cz"
},
"peerDependencies": {
Expand All @@ -61,6 +60,7 @@
"@babel/plugin-transform-runtime": "^7.18.9",
"@babel/preset-env": "^7.18.9",
"@babel/preset-react": "^7.18.6",
"@rollup/plugin-typescript": "^8.3.4",
"@storybook/addon-docs": "^6.5.9",
"@storybook/addon-storysource": "^6.5.9",
"@storybook/react": "^6.5.9",
Expand Down Expand Up @@ -103,7 +103,6 @@
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^9.3.4",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-dts": "^4.2.2",
"rollup-plugin-esbuild": "^4.9.1",
"rollup-plugin-node-resolve": "^4.2.4",
"rollup-plugin-replace": "^2.2.0",
Expand Down
72 changes: 34 additions & 38 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,24 @@
import esbuild from 'rollup-plugin-esbuild';
import copy from 'rollup-plugin-copy';
import dts from 'rollup-plugin-dts';
import typescript from '@rollup/plugin-typescript';
import replace from 'rollup-plugin-replace';
import packageJson from './package.json';

const NODE_ENV = process.env.NODE_ENV || 'development';

const bundle = config => [
{
...config,
external: id => !/^[./]/.test(id),
plugins: [
...config.plugins,
replace({
'process.env.NODE_ENV': JSON.stringify(NODE_ENV)
}),
esbuild({ loaders: { '.js': 'jsx' } })
]
},
{
...config,
output: config.output.dir
? config.output
: {
file: packageJson.types,
format: 'es'
},
external: id => !/^[./]/.test(id),
plugins: [
...config.plugins,
replace({
'process.env.NODE_ENV': JSON.stringify(NODE_ENV)
}),
dts()
]
}
];
const baseBundle = {
external: id => !/^[./]/.test(id),
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify(NODE_ENV)
}),
esbuild({ loaders: { '.js': 'jsx' } })
]
};

export default [
...bundle({
{
...baseBundle,
input: './src/index.ts',
output: [
{
Expand All @@ -52,23 +32,39 @@ export default [
sourcemap: true
}
],
plugins: []
}),
...bundle({
plugins: [
...baseBundle.plugins,
typescript({
tsconfig: './tsconfig.build.index.json',
declaration: true,
declarationDir: 'dist'
})
]
},
{
...baseBundle,
input: './src/common/themes/index.ts',
output: {
dir: 'dist/themes',
exports: 'default',
format: 'cjs'
format: 'cjs',
preserveModules: true,
preserveModulesRoot: 'src/common/themes',
sourcemap: true
},
preserveModules: true,
plugins: [
...baseBundle.plugins,
copy({
targets: [
{ src: './src/assets/fonts/dist/*', dest: './dist/fonts' },
{ src: './src/assets/images/*', dest: './dist/images' }
]
}),
typescript({
tsconfig: './tsconfig.build.themes.json',
declaration: true,
declarationDir: 'dist/themes'
})
]
})
}
];
2 changes: 2 additions & 0 deletions src/Anchor/Anchor.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

import { render } from '@testing-library/react';

import { Anchor } from './Anchor';
Expand Down
1 change: 1 addition & 0 deletions src/Anchor/Anchor.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentMeta } from '@storybook/react';
import React from 'react';
import styled from 'styled-components';

import { Anchor } from './Anchor';
Expand Down
1 change: 1 addition & 0 deletions src/AppBar/AppBar.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { render } from '@testing-library/react';
import React from 'react';

import { AppBar } from './AppBar';

Expand Down
14 changes: 7 additions & 7 deletions src/AppBar/AppBar.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react';
import styled from 'styled-components';
import { ComponentMeta } from '@storybook/react';
import React, { useState } from 'react';
import {
AppBar,
Toolbar,
TextField,
Button,
Divider,
List,
ListItem,
Divider
TextField,
Toolbar
} from 'react95';
import { ComponentMeta } from '@storybook/react';
import styled from 'styled-components';
import logoIMG from '../assets/images/logo.png';

const Wrapper = styled.div`
Expand All @@ -24,7 +24,7 @@ export default {
} as ComponentMeta<typeof AppBar>;

export function Default() {
const [open, setOpen] = React.useState(false);
const [open, setOpen] = useState(false);

return (
<AppBar>
Expand Down
1 change: 1 addition & 0 deletions src/Avatar/Avatar.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { render } from '@testing-library/react';
import React from 'react';

import { renderWithTheme, theme } from '../../test/utils';

Expand Down
1 change: 1 addition & 0 deletions src/Avatar/Avatar.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentMeta } from '@storybook/react';
import React from 'react';
import { Avatar } from 'react95';
import styled from 'styled-components';

Expand Down
2 changes: 2 additions & 0 deletions src/Bar/Bar.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

import { renderWithTheme } from '../../test/utils';

import { Bar } from './Bar';
Expand Down
1 change: 1 addition & 0 deletions src/Bar/Bar.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentMeta } from '@storybook/react';
import React from 'react';
import { AppBar, Bar, Button, Toolbar } from 'react95';
import styled from 'styled-components';

Expand Down
3 changes: 2 additions & 1 deletion src/Button/Button.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { render, fireEvent } from '@testing-library/react';
import { fireEvent, render } from '@testing-library/react';
import React from 'react';

import { renderWithTheme, theme } from '../../test/utils';
import { blockSizes } from '../common/system';
Expand Down
2 changes: 1 addition & 1 deletion src/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentMeta } from '@storybook/react';
import { useState } from 'react';
import React, { useState } from 'react';
import {
Button,
Cutout,
Expand Down
2 changes: 2 additions & 0 deletions src/Checkbox/Checkbox.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

import { renderWithTheme } from '../../test/utils';
import { Checkbox } from './Checkbox';

Expand Down
1 change: 1 addition & 0 deletions src/ColorInput/ColorInput.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fireEvent } from '@testing-library/react';
import React from 'react';
import { renderWithTheme } from '../../test/utils';
import { ColorInput } from './ColorInput';

Expand Down
1 change: 1 addition & 0 deletions src/ColorInput/ColorInput.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentMeta } from '@storybook/react';
import React from 'react';
import styled from 'styled-components';

import { ColorInput, Cutout } from 'react95';
Expand Down
1 change: 1 addition & 0 deletions src/Counter/Counter.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';

import { renderWithTheme } from '../../test/utils';

import { Counter } from './Counter';
Expand Down
2 changes: 1 addition & 1 deletion src/Counter/Counter.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentMeta } from '@storybook/react';
import { useState } from 'react';
import React, { useState } from 'react';
import { Button, Counter, Panel } from 'react95';
import styled from 'styled-components';

Expand Down
1 change: 1 addition & 0 deletions src/Cutout/Cutout.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { render } from '@testing-library/react';
import React from 'react';

import { Cutout } from './Cutout';

Expand Down
1 change: 1 addition & 0 deletions src/Cutout/Cutout.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentMeta } from '@storybook/react';
import React from 'react';
import { Cutout, Window, WindowContent } from 'react95';
import styled from 'styled-components';

Expand Down
1 change: 1 addition & 0 deletions src/DatePicker/DatePicker.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable camelcase, react/jsx-pascal-case */
import { ComponentMeta } from '@storybook/react';
import React from 'react';
import { DatePicker__UNSTABLE } from 'react95';
import styled from 'styled-components';

Expand Down
2 changes: 1 addition & 1 deletion src/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { forwardRef, useCallback, useMemo, useState } from 'react';
import React, { forwardRef, useCallback, useMemo, useState } from 'react';
import styled from 'styled-components';

import { Button } from '../Button/Button';
Expand Down
1 change: 1 addition & 0 deletions src/Desktop/Desktop.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';

import { renderWithTheme } from '../../test/utils';

import { Desktop } from './Desktop';
Expand Down
6 changes: 3 additions & 3 deletions src/Desktop/Desktop.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from 'styled-components';

import { Desktop } from 'react95';
import { ComponentMeta } from '@storybook/react';
import React from 'react';
import { Desktop } from 'react95';
import styled from 'styled-components';

const Wrapper = styled.div`
padding: 5rem;
Expand Down
2 changes: 2 additions & 0 deletions src/Divider/Divider.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

import { renderWithTheme } from '../../test/utils';

import { Divider } from './Divider';
Expand Down
1 change: 1 addition & 0 deletions src/Divider/Divider.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentMeta } from '@storybook/react';
import React from 'react';
import styled from 'styled-components';

import { Divider, List, ListItem } from 'react95';
Expand Down
2 changes: 2 additions & 0 deletions src/Fieldset/Fieldset.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

import { renderWithTheme, theme } from '../../test/utils';

import { Fieldset } from './Fieldset';
Expand Down
2 changes: 1 addition & 1 deletion src/Fieldset/Fieldset.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentMeta } from '@storybook/react';
import { useState } from 'react';
import React, { useState } from 'react';
import { Checkbox, Cutout, Fieldset, Window, WindowContent } from 'react95';
import styled from 'styled-components';

Expand Down
6 changes: 3 additions & 3 deletions src/Hourglass/Hourglass.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from 'styled-components';

import { Hourglass } from 'react95';
import { ComponentMeta } from '@storybook/react';
import React from 'react';
import { Hourglass } from 'react95';
import styled from 'styled-components';

const Wrapper = styled.div`
padding: 5rem;
Expand Down
2 changes: 1 addition & 1 deletion src/Hourglass/Hourglass.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { forwardRef } from 'react';
import React, { forwardRef } from 'react';
import styled from 'styled-components';
import { getSize } from '../common/utils';
import base64hourglass from './base64hourglass';
Expand Down
2 changes: 2 additions & 0 deletions src/List/List.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

import { renderWithTheme } from '../../test/utils';

import { List } from './List';
Expand Down
3 changes: 2 additions & 1 deletion src/List/List.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ComponentMeta } from '@storybook/react';
import React from 'react';
import styled from 'styled-components';

import { List, ListItem, Bar, Divider } from 'react95';
import { Bar, Divider, List, ListItem } from 'react95';

const Wrapper = styled.div`
padding: 5rem;
Expand Down
2 changes: 2 additions & 0 deletions src/ListItem/ListItem.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

import { renderWithTheme, theme } from '../../test/utils';
import { blockSizes } from '../common/system';
import { ListItem } from './ListItem';
Expand Down
2 changes: 2 additions & 0 deletions src/LoadingIndicator/LoadingIndicator.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

import { renderWithTheme } from '../../test/utils';
import { LoadingIndicator } from './LoadingIndicator';

Expand Down
1 change: 1 addition & 0 deletions src/LoadingIndicator/LoadingIndicator.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentMeta } from '@storybook/react';
import React from 'react';
import styled from 'styled-components';

import { LoadingIndicator } from 'react95';
Expand Down
1 change: 1 addition & 0 deletions src/NumberField/NumberField.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fireEvent } from '@testing-library/react';
import React from 'react';

import { renderWithTheme } from '../../test/utils';
import { NumberField } from './NumberField';
Expand Down
1 change: 1 addition & 0 deletions src/NumberField/NumberField.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentMeta } from '@storybook/react';
import React from 'react';
import { Cutout, NumberField } from 'react95';
import styled from 'styled-components';

Expand Down
1 change: 1 addition & 0 deletions src/Panel/Panel.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { render } from '@testing-library/react';
import React from 'react';

import { Panel } from './Panel';

Expand Down
Loading

0 comments on commit b4eec70

Please sign in to comment.