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

use the new JSX transform #2102

Merged
merged 25 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
92031b8
bump swc
mayank99 Jun 11, 2024
527bb82
Merge branch 'main' into mayank/bump-swc
mayank99 Jun 11, 2024
ef39341
Merge branch 'main' into mayank/bump-swc
mayank99 Jun 12, 2024
ae41079
add `--strip-leading-paths`
mayank99 Jun 12, 2024
e9d0f32
replace `tsc` with `swc` for compiling TSX files
mayank99 Jun 12, 2024
9457ad4
fix tsconfig
mayank99 Jun 12, 2024
3cc128e
fix prettier
mayank99 Jun 12, 2024
db07617
prettier changeset
mayank99 Jun 12, 2024
6beafb9
minimize diff
mayank99 Jun 12, 2024
b2b2e5d
use new JSX transform
mayank99 Jun 12, 2024
e7cd1a7
remove unnecessary react import
mayank99 Jun 12, 2024
78431fb
fix tsconfig and eslint config
mayank99 Jun 12, 2024
fbee216
use automatic runtime for dev server too
mayank99 Jun 12, 2024
cdbbf04
Merge branch 'origin/main' into mayank/swc-build
mayank99 Jun 12, 2024
95e92d8
Merge branch 'mayank/swc-build' into mayank/jsx-runtime
mayank99 Jun 12, 2024
b3686cb
use new url
mayank99 Jun 13, 2024
a281781
Merge branch 'main' into mayank/swc-build
mayank99 Jun 13, 2024
1e93a6e
Merge branch 'mayank/swc-build' into mayank/jsx-runtime
mayank99 Jun 13, 2024
172351a
fix inputflexcontainer import
mayank99 Jun 13, 2024
e3ec1a5
disable using eslint plugin
mayank99 Jun 13, 2024
ce12597
make the same change in stories
mayank99 Jun 13, 2024
f0531e4
manually fix imports for failed codemods
mayank99 Jun 13, 2024
34d6394
remove `noInterop`
mayank99 Jun 13, 2024
557f86c
Merge branch 'mayank/swc-build' into mayank/jsx-runtime
mayank99 Jun 13, 2024
ab819c3
Merge branch 'main' into mayank/jsx-runtime
mayank99 Jun 14, 2024
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
5 changes: 5 additions & 0 deletions .changeset/fresh-hats-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': minor
---

The build output now uses the [new JSX transform](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) instead of `React.createElement`.
5 changes: 5 additions & 0 deletions .changeset/lemon-kings-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': minor
---

Replaced dependency on `tslib` with `@swc/helpers`. This is used mainly by the CommonJS build.
5 changes: 5 additions & 0 deletions .changeset/strange-spiders-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': patch
---

The build output is now (again) formatted using `prettier` for easier debugging.
5 changes: 5 additions & 0 deletions .changeset/witty-ties-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': patch
---

Removed all code comments from the build output.
2 changes: 2 additions & 0 deletions internal/configs/eslint-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ module.exports = {
curly: 'error',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'no-restricted-imports': ['error', '..'],
'react/react-in-jsx-scope': 'off',
'react/jsx-uses-react': 'off',
r100-stack marked this conversation as resolved.
Show resolved Hide resolved
},
};
2 changes: 1 addition & 1 deletion packages/itwinui-react/.swcrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": { "syntax": "typescript" },
"transform": { "react": { "useBuiltins": true } },
"transform": { "react": { "useBuiltins": true, "runtime": "automatic" } },
"target": "es2022"
},
"module": {
Expand Down
9 changes: 5 additions & 4 deletions packages/itwinui-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@
"ux"
],
"scripts": {
"build": "pnpm clean:build && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && tsc -p tsconfig.react-table.json && pnpm build:styles && pnpm build:post",
"build": "pnpm clean:build && pnpm build:js && pnpm build:styles && pnpm build:types && pnpm build:post",
"build:js": "node ./scripts/build.mjs",
"build:types": "tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && tsc -p tsconfig.react-table.json",
"build:styles": "vite build src/styles.js",
"build:watch": "concurrently \"tsc -p tsconfig.cjs.json --watch\" \"tsc -p tsconfig.esm.json --watch\"",
"build:post": "node ./scripts/postBuild.mjs",
"clean:build": "rimraf esm && rimraf cjs && rimraf react-table.d.ts",
"clean:coverage": "rimraf coverage",
Expand All @@ -85,11 +86,11 @@
"dependencies": {
"@floating-ui/react": "^0.26.10",
"@itwin/itwinui-illustrations-react": "^2.1.0",
"@swc/helpers": "^0.5.11",
"classnames": "^2.3.2",
"jotai": "^2.8.0",
"react-table": "^7.8.0",
"react-transition-group": "^4.4.5",
"tslib": "^2.6.0"
"react-transition-group": "^4.4.5"
},
"devDependencies": {
"@swc/cli": "^0.3.12",
Expand Down
43 changes: 43 additions & 0 deletions packages/itwinui-react/scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { execSync } from 'node:child_process';

// https://swc.rs/docs/usage/cli
const swcOptions = {
shared: [
'--strip-leading-paths',
'--no-swcrc',
'--ignore **/*.test.*,**/styles.js/*,**/styles*',
].join(' '),

// https://swc.rs/docs/configuration/compilation
compilerOptions: [
'',
'jsc.parser.syntax=typescript',
'jsc.parser.tsx=true',
'jsc.transform.react.useBuiltins=true',
'jsc.transform.react.runtime=automatic',
'jsc.target=es2020',
'jsc.minify.format.comments=false',
'jsc.externalHelpers=true',
'module.noInterop=true',
].join(' -C '),

get esm() {
return [this.shared, this.compilerOptions, '-C module.type=es6'].join(' ');
},

get cjs() {
return [this.shared, this.compilerOptions, '-C module.type=commonjs'].join(
' ',
);
},
};

execSync(`pnpm swc src -d esm ${swcOptions.esm}`);
console.log('✓ Built esm.');

execSync(`pnpm swc src -d cjs ${swcOptions.cjs}`);
console.log('✓ Built cjs.');
18 changes: 10 additions & 8 deletions packages/itwinui-react/scripts/postBuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import fs from 'node:fs';
import { exec } from 'node:child_process';
import { execSync } from 'node:child_process';

// This creates a dummy package.json file in the cjs folder.
// Without this, all cjs files would need the .cjs extension
Expand All @@ -15,10 +15,12 @@ try {
}

// Run prettier on all compiled output because it gets jumbled by tsc.
exec('pnpm exec prettier --write "{esm,cjs}/**/*.js"', (error) => {
if (error) {
console.error('Error when running prettier', error);
} else {
console.log('✓ Finished compiling @itwin/itwinui-react');
}
});
try {
execSync(
'npx prettier --write --ignore-path="../../.gitignore" "{esm,cjs}/**/*.js"',
);
} catch (error) {
console.error('Error when running prettier', error);
}

console.log('\x1b[32m✓ Finished building @itwin/itwinui-react');
1 change: 0 additions & 1 deletion packages/itwinui-react/src/core/Alert/Alert.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { fireEvent, render, screen } from '@testing-library/react';
import * as React from 'react';
import { userEvent } from '@testing-library/user-event';

import { Alert } from './Alert.js';
Expand Down
1 change: 0 additions & 1 deletion packages/itwinui-react/src/core/Avatar/Avatar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { render, screen } from '@testing-library/react';
import { SvgUser } from '@itwin/itwinui-icons-react';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { render } from '@testing-library/react';

import { Avatar } from '../Avatar/Avatar.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { render } from '@testing-library/react';
import { Backdrop } from './Backdrop.js';

Expand Down
1 change: 0 additions & 1 deletion packages/itwinui-react/src/core/Badge/Badge.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { render } from '@testing-library/react';

import { Badge } from './Badge.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import { SvgMore, SvgClose as SvgPlaceholder } from '../../utils/index.js';
import { fireEvent, render } from '@testing-library/react';
import * as React from 'react';
import * as UseOverflow from '../../utils/hooks/useOverflow.js';

import { ButtonGroup } from './ButtonGroup.js';
Expand Down
1 change: 0 additions & 1 deletion packages/itwinui-react/src/core/Buttons/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { render } from '@testing-library/react';
import * as React from 'react';
import { SvgClose as SvgPlaceholder } from '../../utils/index.js';
import { Button } from './Button.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { render, screen } from '@testing-library/react';
import * as React from 'react';
import { SvgMore } from '../../utils/index.js';

import { IconButton } from './IconButton.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { render } from '@testing-library/react';
import * as React from 'react';

import { IdeasButton } from './IdeasButton.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { render } from '@testing-library/react';

import { Carousel } from './Carousel.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { render, screen, act } from '@testing-library/react';
import * as React from 'react';
import { CarouselDotsList } from './CarouselDotsList.js';
import * as UseResizeObserver from '../../utils/hooks/useResizeObserver.js';
import { userEvent } from '@testing-library/user-event';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { render, screen } from '@testing-library/react';
import * as React from 'react';

import { Checkbox } from './Checkbox.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { act, fireEvent, render } from '@testing-library/react';
import { ColorPicker } from './ColorPicker.js';
import { ColorInputPanel } from './ColorInputPanel.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { render } from '@testing-library/react';
import { ColorPalette } from './ColorPalette.js';
import { ColorPicker } from './ColorPicker.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { fireEvent, render } from '@testing-library/react';
import { getColorValue, ColorPicker } from './ColorPicker.js';
import { ColorPalette } from './ColorPalette.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { fireEvent, render } from '@testing-library/react';
import { ColorSwatch } from './ColorSwatch.js';
import { ColorValue } from '../../utils/index.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* (e.g. react-workshop, unit tests, etc.)
*/

import React, { useRef } from 'react';
import { useRef } from 'react';
import { ComboBox } from './ComboBox.js';

() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import { fireEvent, render, screen } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';
import * as React from 'react';
import { DatePicker } from './DatePicker.js';

const selectedDaySelector = '.iui-calendar-day-selected';
Expand Down
1 change: 0 additions & 1 deletion packages/itwinui-react/src/core/Dialog/Dialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { render, act } from '@testing-library/react';
import { Dialog } from './Dialog.js';
import { Button } from '../Buttons/Button.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { render } from '@testing-library/react';
import { DialogBackdrop } from './DialogBackdrop.js';
import { userEvent } from '@testing-library/user-event';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { render, screen } from '@testing-library/react';
import * as React from 'react';
import { Button } from '../Buttons/Button.js';

import { DialogButtonBar } from './DialogButtonBar.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { render, screen } from '@testing-library/react';
import * as React from 'react';
import { DialogContent } from './DialogContent.js';

it('should render in its most basic state', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { DialogMain } from './DialogMain.js';
import { DialogTitleBar } from './DialogTitleBar.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { render } from '@testing-library/react';
import * as React from 'react';

import { DialogTitleBar } from './DialogTitleBar.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { render } from '@testing-library/react';
import * as React from 'react';

import { DialogTitleBarTitle } from './DialogTitleBarTitle.js';

Expand Down
1 change: 0 additions & 1 deletion packages/itwinui-react/src/core/Divider/Divider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { render } from '@testing-library/react';

import { Divider } from './Divider.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import { DropdownMenu, type DropdownMenuProps } from './DropdownMenu.js';
import { Button } from '../Buttons/Button.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import { fireEvent, render, screen } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';
import * as React from 'react';
import { StatusIconMap, SvgMore as SvgPlaceholder } from '../../utils/index.js';
import * as UseId from '../../utils/hooks/useId.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { fireEvent, render } from '@testing-library/react';
import { Fieldset } from './Fieldset.js';
import { InputGroup } from '../InputGroup/InputGroup.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { fireEvent, render } from '@testing-library/react';

import { FileUpload } from './FileUpload.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { fireEvent, render } from '@testing-library/react';
import { FileUploadTemplate } from './FileUploadTemplate.js';
import { SvgUpload } from '../../utils/index.js';
Expand Down
1 change: 0 additions & 1 deletion packages/itwinui-react/src/core/Flex/Flex.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { render } from '@testing-library/react';

import { Flex } from './Flex.js';
Expand Down
Loading
Loading