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

Publish bundles instead of modules, use babel only for transpilation #2214

Merged
merged 9 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ const rules = {
'@typescript-eslint/consistent-indexed-object-style': 1,
'@typescript-eslint/consistent-type-assertions': [2, { assertionStyle: 'as', objectLiteralTypeAssertions: 'never' }],
'@typescript-eslint/consistent-type-definitions': [1, 'interface'],
'@typescript-eslint/consistent-type-imports': [1, { prefer: 'no-type-imports' }],
'@typescript-eslint/consistent-type-imports': 1,
Copy link
Contributor Author

@nstepien nstepien Nov 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tweaked this so we'll now use type imports, this is to help babel elide type imports, otherwise it cannot always know to remove some imports, especially in files like src/index.ts.

'@typescript-eslint/explicit-function-return-type': 0,
'@typescript-eslint/explicit-member-accessibility': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
run: npm run typecheck
- name: Test
run: npm t -- --coverage --colors
- name: Bundle
run: npm run build

storybook:
runs-on: ubuntu-latest
Expand Down
3 changes: 0 additions & 3 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ module.exports = function({ config, mode }) {
use: [{
loader: 'babel-loader',
options: { cacheDirectory: !isProd }
}, {
loader: 'ts-loader',
options: { onlyCompileBundledFiles: true }
}]
}, {
test: /\.less$/,
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ See [documentation](https://babeljs.io/docs/en/)
```
- Babel's `env` preset, if configured correctly, will transform this import so only the necessary polyfills are included in your bundle.
- Polyfilling the [`ResizeObserver`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver) API is required for older browsers.
- Optional: we also recommend using the [`babel-plugin-optimize-clsx` plugin](https://www.npmjs.com/package/babel-plugin-optimize-clsx).
</details>

<details>
Expand Down
11 changes: 9 additions & 2 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
{
"presets": [
["@babel/env", {
"loose": true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be using loose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original code:

ref.current?.focus({ preventScroll: true });

With loose enabled:

(_ref$current = ref.current) == null ? void 0 : _ref$current.focus({

With loose disabled:

(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus({

In non-loose mode, the value is explicitely checked for both null and undefined, as it needs to work with document.all, but we don't use document.all anywhere so it's safe.
image

It might matter in the future for new js syntax features, but loose will only break edge cases so I think it's fine.

"bugfixes": true,
"shippedProposals": true,
"corejs": 3,
"useBuiltIns": "entry"
}]
"useBuiltIns": "entry",
"include": [
"@babel/proposal-nullish-coalescing-operator",
"@babel/proposal-optional-chaining"
Comment on lines +10 to +11
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact: with our browserslist config, and our code, aside from these two transform plugins, @babel/preset-env does nothing.

]
}],
["@babel/react", { "useSpread": true }],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change this to use the new runtime in #2184

"@babel/typescript"
],
"plugins": [
["@babel/transform-runtime", { "useESModules": true }],
Copy link
Contributor Author

@nstepien nstepien Nov 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might have to add @babel/runtime in our dependencies in the future, but currently no helpers get imported in our bundles.
useESModules should also be set to false for the cjs bundle.

Expand Down
8 changes: 0 additions & 8 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
// https://jestjs.io/docs/en/configuration.html

export default {
preset: 'ts-jest',
globals: {
'ts-jest': {
tsconfig: {
esModuleInterop: true
}
}
},
coverageProvider: 'v8',
collectCoverageFrom: [
'src/**/*.{ts,tsx}'
Expand Down
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"import": "./lib/bundle.mjs",
"require": "./lib/bundle.cjs"
},
"default": "./lib/index.js"
"default": "./lib/bundle.mjs"
},
"./dist/": "./dist/"
},
"browser": "./lib/index.js",
"browser": "./lib/bundle.mjs",
"main": "./lib/bundle.cjs",
"module": "./lib/index.js",
"module": "./lib/bundle.mjs",
"types": "./lib/index.d.ts",
"files": [
"dist",
Expand All @@ -36,16 +36,15 @@
],
"scripts": {
"start": "start-storybook --quiet --no-dll -p 6006",
"build": "tsc",
"build": "rollup --config --no-stdin",
"postbuild": "node tools/buildStylesheets.mjs",
"rollup": "rollup --config --no-stdin",
"test": "jest",
"test:watch": "jest --watch",
"eslint": "eslint --ext mjs,ts,tsx --max-warnings 0 -f codeframe --cache --color src stories test tools",
"eslint:fix": "npm run eslint -- --fix",
"typecheck": "tsc -p tsconfig.all.json",
"build-storybook": "build-storybook --quiet --no-dll",
"prepublishOnly": "npm install && npm run build && npm run rollup",
"prepublishOnly": "npm install && npm run build && tsc",
"postpublish": "git push --follow-tags origin HEAD"
},
"dependencies": {
Expand All @@ -55,9 +54,12 @@
"@babel/core": "^7.12.3",
"@babel/plugin-transform-runtime": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"@babel/preset-react": "^7.12.5",
"@babel/preset-typescript": "^7.12.1",
"@babel/runtime": "^7.12.1",
"@juggle/resize-observer": "^3.2.0",
"@popperjs/core": "^2.5.3",
"@rollup/plugin-babel": "^5.2.1",
"@rollup/plugin-node-resolve": "^10.0.0",
"@storybook/react": "^6.0.27",
"@testing-library/jest-dom": "^5.11.5",
Expand Down Expand Up @@ -97,9 +99,6 @@
"react-select": "^3.1.0",
"react-sortable-hoc": "^1.11.0",
"rollup": "^2.32.1",
"rollup-plugin-sourcemaps": "^0.6.3",
"ts-jest": "^26.4.3",
"ts-loader": "^8.0.7",
"typescript": "~4.0.5"
},
"peerDependencies": {
Expand Down
24 changes: 15 additions & 9 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { isAbsolute } from 'path';
import { babel } from '@rollup/plugin-babel';
import nodeResolve from '@rollup/plugin-node-resolve';
import sourcemaps from 'rollup-plugin-sourcemaps';

const extensions = ['.ts', '.tsx'];

export default {
input: './lib/index.js',
input: './src/index.ts',
output: [{
file: './lib/bundle.mjs',
format: 'es',
Expand All @@ -15,13 +18,16 @@ export default {
sourcemap: true,
interop: false
}],
external: [
'clsx',
'react',
'react-dom'
],
external: id => !id.startsWith('.') && !isAbsolute(id),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will mark all non-relative imports as external, in other words all npm dependencies.

plugins: [
sourcemaps(),
nodeResolve()
babel({
babelHelpers: 'runtime',
extensions,
// remove all comments except terser annotations
// https://github.com/terser/terser#annotations
// https://babeljs.io/docs/en/options#shouldprintcomment
shouldPrintComment: comment => /^[@#]__.+__$/.test(comment)
}),
nodeResolve({ extensions })
]
};
2 changes: 1 addition & 1 deletion src/Cell.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { forwardRef, memo, useRef } from 'react';
import clsx from 'clsx';

import { CellRendererProps } from './types';
import type { CellRendererProps } from './types';
import { wrapEvent } from './utils';
import { useCombinedRefs } from './hooks';

Expand Down
2 changes: 1 addition & 1 deletion src/Columns.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { SelectCellFormatter } from './formatters';
import { Column } from './types';
import type { Column } from './types';
import { stopPropagation } from './utils/domUtils';

export const SELECT_COLUMN_KEY = 'select-row';
Expand Down
4 changes: 2 additions & 2 deletions src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
isDefaultCellInput
} from './utils';

import {
import type {
CalculatedColumn,
Column,
Filters,
Expand All @@ -39,7 +39,7 @@ import {
FillEvent,
PasteEvent
} from './types';
import { CellNavigationMode, SortDirection } from './enums';
import type { CellNavigationMode, SortDirection } from './enums';

interface SelectCellState extends Position {
mode: 'SELECT';
Expand Down
2 changes: 1 addition & 1 deletion src/EditCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState, useCallback } from 'react';
import clsx from 'clsx';

import EditorContainer from './editors/EditorContainer';
import { CellRendererProps, SharedEditorProps, Omit } from './types';
import type { CellRendererProps, SharedEditorProps, Omit } from './types';

type SharedCellRendererProps<R, SR> = Pick<CellRendererProps<R, SR>,
| 'rowIdx'
Expand Down
4 changes: 2 additions & 2 deletions src/FilterRow.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { createElement, memo } from 'react';
import clsx from 'clsx';

import { CalculatedColumn, Filters } from './types';
import { DataGridProps } from './DataGrid';
import type { CalculatedColumn, Filters } from './types';
import type { DataGridProps } from './DataGrid';

type SharedDataGridProps<R, SR> = Pick<DataGridProps<R, SR>,
| 'filters'
Expand Down
4 changes: 2 additions & 2 deletions src/GroupCell.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { memo } from 'react';
import clsx from 'clsx';

import { CalculatedColumn } from './types';
import { GroupRowRendererProps } from './GroupRow';
import type { CalculatedColumn } from './types';
import type { GroupRowRendererProps } from './GroupRow';

type SharedGroupRowRendererProps<R, SR> = Pick<GroupRowRendererProps<R, SR>,
| 'id'
Expand Down
2 changes: 1 addition & 1 deletion src/GroupRow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { memo } from 'react';
import clsx from 'clsx';

import { CalculatedColumn, Position, SelectRowEvent, Omit } from './types';
import type { CalculatedColumn, Position, SelectRowEvent, Omit } from './types';
import { SELECT_COLUMN_KEY } from './Columns';
import GroupCell from './GroupCell';

Expand Down
6 changes: 3 additions & 3 deletions src/HeaderCell.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { createElement } from 'react';
import clsx from 'clsx';

import { CalculatedColumn } from './types';
import { HeaderRowProps } from './HeaderRow';
import type { CalculatedColumn } from './types';
import type { HeaderRowProps } from './HeaderRow';
import SortableHeaderCell from './headerCells/SortableHeaderCell';
import ResizableHeaderCell from './headerCells/ResizableHeaderCell';
import { SortDirection } from './enums';
import type { SortDirection } from './enums';

function getAriaSort(sortDirection?: SortDirection) {
switch (sortDirection) {
Expand Down
4 changes: 2 additions & 2 deletions src/HeaderRow.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useCallback, memo } from 'react';

import HeaderCell from './HeaderCell';
import { CalculatedColumn } from './types';
import type { CalculatedColumn } from './types';
import { assertIsValidKeyGetter } from './utils';
import { DataGridProps } from './DataGrid';
import type { DataGridProps } from './DataGrid';

type SharedDataGridProps<R, SR> = Pick<DataGridProps<R, SR>,
| 'rows'
Expand Down
2 changes: 1 addition & 1 deletion src/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import clsx from 'clsx';

import Cell from './Cell';
import EditCell from './EditCell';
import { RowRendererProps, SelectedCellProps } from './types';
import type { RowRendererProps, SelectedCellProps } from './types';
import { wrapEvent } from './utils';

function Row<R, SR = unknown>({
Expand Down
2 changes: 1 addition & 1 deletion src/SummaryCell.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { memo } from 'react';
import clsx from 'clsx';

import { CellRendererProps } from './types';
import type { CellRendererProps } from './types';

type SharedCellRendererProps<R, SR> = Pick<CellRendererProps<R, SR>, 'column'>;

Expand Down
2 changes: 1 addition & 1 deletion src/SummaryRow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { memo } from 'react';

import SummaryCell from './SummaryCell';
import { RowRendererProps } from './types';
import type { RowRendererProps } from './types';

type SharedRowRendererProps<R, SR> = Pick<RowRendererProps<R, SR>,
| 'viewportColumns'
Expand Down
2 changes: 1 addition & 1 deletion src/editors/EditorContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { createPortal } from 'react-dom';

import { EditorProps } from '../types';
import type { EditorProps } from '../types';
import { useClickOutside } from '../hooks';

export default function EditorContainer<R, SR>({
Expand Down
2 changes: 1 addition & 1 deletion src/editors/TextEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { EditorProps } from '../types';
import type { EditorProps } from '../types';

function autoFocusAndSelect(input: HTMLInputElement | null) {
input?.focus();
Expand Down
2 changes: 1 addition & 1 deletion src/formatters/ToggleGroupFormatter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { GroupFormatterProps } from '../types';
import type { GroupFormatterProps } from '../types';
import { useFocusRef } from '../hooks/useFocusRef';

export function ToggleGroupFormatter<R, SR>({
Expand Down
2 changes: 1 addition & 1 deletion src/formatters/ValueFormatter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { FormatterProps } from '../types';
import type { FormatterProps } from '../types';

export function ValueFormatter<R, SR>(props: FormatterProps<R, SR>) {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/headerCells/ResizableHeaderCell.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { cloneElement } from 'react';
import { CalculatedColumn } from '../types';
import { cloneElement } from 'react';
import type { CalculatedColumn } from '../types';

interface ResizableHeaderCellProps<R, SR> {
children: React.ReactElement<React.ComponentProps<'div'>>;
Expand Down
4 changes: 2 additions & 2 deletions src/headerCells/SortableHeaderCell.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { HeaderCellProps } from '../HeaderCell';
import { SortDirection } from '../enums';
import type { HeaderCellProps } from '../HeaderCell';
import type { SortDirection } from '../enums';

const SORT_TEXT = {
ASC: '\u25B2',
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useViewportColumns.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMemo } from 'react';

import { CalculatedColumn, Column } from '../types';
import { DataGridProps } from '../DataGrid';
import type { CalculatedColumn, Column } from '../types';
import type { DataGridProps } from '../DataGrid';
import { ValueFormatter, ToggleGroupFormatter } from '../formatters';
import { SELECT_COLUMN_KEY } from '../Columns';

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useViewportRows.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo } from 'react';

import { GroupRow, GroupByDictionary, Dictionary } from '../types';
import type { GroupRow, GroupByDictionary, Dictionary } from '../types';
const RENDER_BACTCH_SIZE = 8;

interface ViewportRowsArgs<R> {
Expand Down
10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
export { default, DataGridProps, DataGridHandle } from './DataGrid';
export { default } from './DataGrid';
export type { DataGridProps, DataGridHandle } from './DataGrid';
export { default as Cell } from './Cell';
export { default as Row } from './Row';
export * from './Columns';
export * from './formatters';
export { default as TextEditor } from './editors/TextEditor';
export { default as SortableHeaderCell } from './headerCells/SortableHeaderCell';
export * from './enums';
export {
export type {
CellNavigationMode,
SortDirection
} from './enums';
export type {
Column,
CalculatedColumn,
FormatterProps,
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { ReactElement } from 'react';
import { SortDirection } from './enums';
import type { ReactElement } from 'react';
import type { SortDirection } from './enums';

export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/columnUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CalculatedColumn } from '../types';
import type { CalculatedColumn } from '../types';

export function getColumnScrollPosition<R, SR>(columns: readonly CalculatedColumn<R, SR>[], idx: number, currentScrollLeft: number, currentClientWidth: number): number {
let left = 0;
Expand Down
Loading