feat: insert use client automatically at compilations instead of hardcode (#44608)

* feat: remove the hardcode of `use client`

* chore: update `@ant-design/tools`

* test: update

* fix: incorrect dictionary

* chore: update dep

* ci: check use client

* chore: update ci

* fix: should be LIB_DIR

* ci: should only run in dist

* chore: update check tsx files
This commit is contained in:
Dunqing 2023-09-04 19:27:20 +08:00 committed by GitHub
parent 54316f719c
commit f0c105d262
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
75 changed files with 43 additions and 145 deletions

View File

@ -188,6 +188,12 @@ jobs:
if: ${{ matrix.module == 'dist' }}
run: node ./tests/dekko/dist.test.js
- name: check use client
if: ${{ matrix.module == 'dist' }}
run: node ./tests/dekko/use-client.test.js
env:
LIB_DIR: dist
# dom test
- name: dom test
if: ${{ matrix.module == 'dom' }}
@ -286,6 +292,10 @@ jobs:
- name: check
run: node ./tests/dekko/lib.test.js
- name: check use client
run: node ./tests/dekko/use-client.test.js
needs: setup
compiled-module-test:

View File

@ -1,5 +1,3 @@
'use client';
import React, { createRef, forwardRef, useContext } from 'react';
import classNames from 'classnames';

View File

@ -1,5 +1,3 @@
'use client';
import type { AlertProps } from './Alert';
import InternalAlert from './Alert';
import ErrorBoundary from './ErrorBoundary';

View File

@ -1,5 +1,3 @@
'use client';
import InternalAnchor from './Anchor';
import AnchorLink from './AnchorLink';

View File

@ -1,5 +1,3 @@
'use client';
import classNames from 'classnames';
import type { ReactNode } from 'react';
import React, { useContext } from 'react';

View File

@ -1,5 +1,3 @@
'use client';
import classNames from 'classnames';
import type { BaseSelectRef } from 'rc-select';
import toArray from 'rc-util/lib/Children/toArray';

View File

@ -1,5 +1,3 @@
'use client';
import type { ForwardRefExoticComponent, RefAttributes } from 'react';
import type { AvatarProps } from './avatar';
import InternalAvatar from './avatar';

View File

@ -1,5 +1,3 @@
'use client';
import VerticalAlignTopOutlined from '@ant-design/icons/VerticalAlignTopOutlined';
import classNames from 'classnames';
import CSSMotion from 'rc-motion';

View File

@ -1,5 +1,3 @@
'use client';
import classnames from 'classnames';
import CSSMotion from 'rc-motion';
import * as React from 'react';

View File

@ -1,5 +1,3 @@
'use client';
import Breadcrumb from './Breadcrumb';
export type { BreadcrumbProps } from './Breadcrumb';

View File

@ -1,5 +1,3 @@
'use client';
import Button from './button';
export type { SizeType as ButtonSize } from '../config-provider/SizeContext';

View File

@ -1,5 +1,3 @@
'use client';
import type { Dayjs } from 'dayjs';
import dayjsGenerateConfig from 'rc-picker/lib/generate/dayjs';
import type { CalendarProps } from './generateCalendar';

View File

@ -1,5 +1,3 @@
'use client';
import InternalCard from './Card';
import Grid from './Grid';
import Meta from './Meta';

View File

@ -1,5 +1,3 @@
'use client';
import * as React from 'react';
import type { Settings } from '@ant-design/react-slick';
import SlickCarousel from '@ant-design/react-slick';

View File

@ -1,5 +1,3 @@
'use client';
import * as React from 'react';
import LeftOutlined from '@ant-design/icons/LeftOutlined';
import LoadingOutlined from '@ant-design/icons/LoadingOutlined';

View File

@ -1,5 +1,3 @@
'use client';
import type * as React from 'react';
import type { CheckboxProps } from './Checkbox';
import InternalCheckbox from './Checkbox';

View File

@ -1,5 +1,3 @@
'use client';
import { Col, type ColProps, type ColSize } from '../grid';
export type { ColProps, ColSize };

View File

@ -1,5 +1,3 @@
'use client';
import Collapse from './Collapse';
export type { CollapseProps } from './Collapse';

View File

@ -1,5 +1,3 @@
'use client';
import ColorPicker from './ColorPicker';
export type { ColorPickerProps } from './ColorPicker';

View File

@ -1,5 +1,3 @@
'use client';
import { createTheme } from '@ant-design/cssinjs';
import IconContext from '@ant-design/icons/lib/components/Context';
import type { ValidateMessages } from 'rc-field-form/lib/interface';

View File

@ -1,5 +1,3 @@
'use client';
import type { Dayjs } from 'dayjs';
import dayjsGenerateConfig from 'rc-picker/lib/generate/dayjs';
import genPurePanel from '../_util/PurePanel';

View File

@ -1,5 +1,3 @@
'use client';
/* eslint-disable react/no-array-index-key */
import classNames from 'classnames';
import * as React from 'react';

View File

@ -1,5 +1,3 @@
'use client';
import classNames from 'classnames';
import * as React from 'react';
import warning from '../_util/warning';

View File

@ -1,5 +1,3 @@
'use client';
import classNames from 'classnames';
import type { DrawerProps as RcDrawerProps } from 'rc-drawer';
import RcDrawer from 'rc-drawer';

View File

@ -1,5 +1,3 @@
'use client';
import InternalDropdown from './dropdown';
import DropdownButton from './dropdown-button';

View File

@ -1,5 +1,3 @@
'use client';
import classNames from 'classnames';
import * as React from 'react';
import { ConfigContext } from '../config-provider';

View File

@ -1,5 +1,3 @@
'use client';
import BackTop from './BackTop';
import FloatButton from './FloatButton';
import FloatButtonGroup from './FloatButtonGroup';

View File

@ -1,5 +1,3 @@
'use client';
import type { Rule, RuleObject, RuleRender } from 'rc-field-form/lib/interface';
import warning from '../_util/warning';
import ErrorList, { type ErrorListProps } from './ErrorList';

View File

@ -1,5 +1,3 @@
'use client';
import Col from './col';
import useInternalBreakpoint from './hooks/useBreakpoint';
import Row from './row';

View File

@ -1,5 +1,3 @@
'use client';
import * as React from 'react';
import EyeOutlined from '@ant-design/icons/EyeOutlined';
import classNames from 'classnames';

View File

@ -1,5 +1,3 @@
'use client';
export type { Breakpoint } from './_util/responsiveObserver';
export { default as Affix } from './affix';
export type { AffixProps } from './affix';

View File

@ -1,5 +1,3 @@
'use client';
import DownOutlined from '@ant-design/icons/DownOutlined';
import UpOutlined from '@ant-design/icons/UpOutlined';
import classNames from 'classnames';

View File

@ -1,5 +1,3 @@
'use client';
import type * as React from 'react';
import Group from './Group';
import type { InputProps, InputRef } from './Input';

View File

@ -1,5 +1,3 @@
'use client';
import InternalLayout, { Content, Footer, Header } from './layout';
import Sider from './Sider';

View File

@ -1,5 +1,3 @@
'use client';
import classNames from 'classnames';
// eslint-disable-next-line import/no-named-as-default
import * as React from 'react';

View File

@ -1,5 +1,3 @@
'use client';
import type { ValidateMessages } from 'rc-field-form/lib/interface';
import * as React from 'react';
import warning from '../_util/warning';

View File

@ -1,5 +1,3 @@
'use client';
import classNames from 'classnames';
import RcMentions from 'rc-mentions';
import type {

View File

@ -1,5 +1,3 @@
'use client';
import type { MenuRef as RcMenuRef } from 'rc-menu';
import { ItemGroup } from 'rc-menu';
import * as React from 'react';

View File

@ -1,5 +1,3 @@
'use client';
import * as React from 'react';
import { render } from 'rc-util/lib/React/render';

View File

@ -1,5 +1,3 @@
'use client';
import type { ModalStaticFunctions } from './confirm';
import confirm, {
modalGlobalConfig,

View File

@ -1,5 +1,3 @@
'use client';
import * as React from 'react';
import { render } from 'rc-util/lib/React/render';

View File

@ -1,5 +1,3 @@
'use client';
import Pagination from './Pagination';
export type { PaginationConfig, PaginationProps } from './Pagination';

View File

@ -1,5 +1,3 @@
'use client';
import ExclamationCircleFilled from '@ant-design/icons/ExclamationCircleFilled';
import classNames from 'classnames';
import KeyCode from 'rc-util/lib/KeyCode';

View File

@ -1,5 +1,3 @@
'use client';
import classNames from 'classnames';
import * as React from 'react';
import type { RenderFunction } from '../_util/getRenderPropValue';

View File

@ -1,5 +1,3 @@
'use client';
import Progress from './progress';
export type { ProgressAriaProps, ProgressProps } from './progress';

View File

@ -1,5 +1,3 @@
'use client';
import ReloadOutlined from '@ant-design/icons/ReloadOutlined';
import classNames from 'classnames';
import { QRCodeCanvas, QRCodeSVG } from 'qrcode.react';

View File

@ -1,5 +1,3 @@
'use client';
import type * as React from 'react';
import Group from './group';
import type { RadioProps } from './interface';

View File

@ -1,5 +1,3 @@
'use client';
import StarFilled from '@ant-design/icons/StarFilled';
import classNames from 'classnames';
import RcRate from 'rc-rate';

View File

@ -1,5 +1,3 @@
'use client';
import CheckCircleFilled from '@ant-design/icons/CheckCircleFilled';
import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled';
import ExclamationCircleFilled from '@ant-design/icons/ExclamationCircleFilled';

View File

@ -1,5 +1,3 @@
'use client';
import { Row, type RowProps } from '../grid';
export type { RowProps };

View File

@ -1,5 +1,3 @@
'use client';
import classNames from 'classnames';
import type {
SegmentedLabeledOption as RcSegmentedLabeledOption,

View File

@ -1,5 +1,3 @@
'use client';
// TODO: 4.0 - codemod should help to change `filterOption` to support node props.
import classNames from 'classnames';
import type { BaseSelectRef, SelectProps as RcSelectProps } from 'rc-select';

View File

@ -1,5 +1,3 @@
'use client';
import Skeleton from './Skeleton';
export type { SkeletonProps } from './Skeleton';

View File

@ -1,5 +1,3 @@
'use client';
import classNames from 'classnames';
import type { SliderProps as RcSliderProps } from 'rc-slider';
import RcSlider from 'rc-slider';

View File

@ -1,5 +1,3 @@
'use client';
import classNames from 'classnames';
import toArray from 'rc-util/lib/Children/toArray';
import * as React from 'react';

View File

@ -1,5 +1,3 @@
'use client';
import classNames from 'classnames';
import omit from 'rc-util/lib/omit';
import * as React from 'react';

View File

@ -1,5 +1,3 @@
'use client';
import type { CountdownProps } from './Countdown';
import Countdown from './Countdown';
import type { StatisticProps } from './Statistic';

View File

@ -1,5 +1,3 @@
'use client';
import CheckOutlined from '@ant-design/icons/CheckOutlined';
import CloseOutlined from '@ant-design/icons/CloseOutlined';
import classNames from 'classnames';

View File

@ -1,5 +1,3 @@
'use client';
/* eslint-disable import/prefer-default-export */
import type { CSSObject } from '@ant-design/cssinjs';
import type { AliasToken, DerivativeToken } from '../theme/internal';

View File

@ -1,5 +1,3 @@
'use client';
import LoadingOutlined from '@ant-design/icons/LoadingOutlined';
import classNames from 'classnames';
import RcSwitch from 'rc-switch';

View File

@ -1,5 +1,3 @@
'use client';
import { type TablePaginationConfig, type TableProps } from './InternalTable';
import Table from './Table';

View File

@ -1,5 +1,3 @@
'use client';
import CloseOutlined from '@ant-design/icons/CloseOutlined';
import EllipsisOutlined from '@ant-design/icons/EllipsisOutlined';
import PlusOutlined from '@ant-design/icons/PlusOutlined';

View File

@ -1,5 +1,3 @@
'use client';
import * as React from 'react';
import CloseOutlined from '@ant-design/icons/CloseOutlined';
import classNames from 'classnames';

View File

@ -1,5 +1,3 @@
'use client';
/* eslint-disable import/prefer-default-export */
import getDesignToken from './getDesignToken';
import type { GlobalToken, MappingAlgorithm } from './interface';

View File

@ -1,5 +1,3 @@
'use client';
import type { Dayjs } from 'dayjs';
import * as React from 'react';
import genPurePanel from '../_util/PurePanel';

View File

@ -1,5 +1,3 @@
'use client';
import Timeline from './Timeline';
export type { TimelineProps } from './Timeline';

View File

@ -1,5 +1,3 @@
'use client';
import type { BuildInPlacements } from '@rc-component/trigger';
import classNames from 'classnames';
import RcTooltip from 'rc-tooltip';

View File

@ -1,5 +1,3 @@
'use client';
import RCTour from '@rc-component/tour';
import classNames from 'classnames';
import React, { useContext } from 'react';

View File

@ -1,5 +1,3 @@
'use client';
import classNames from 'classnames';
import type { ChangeEvent, CSSProperties } from 'react';
import React, { useCallback, useContext } from 'react';

View File

@ -1,5 +1,3 @@
'use client';
import classNames from 'classnames';
import type { BaseSelectRef } from 'rc-select';
import type { Placement } from 'rc-select/lib/BaseSelect';

View File

@ -1,5 +1,3 @@
'use client';
import type RcTree from 'rc-tree';
import type { BasicDataNode } from 'rc-tree';
import { TreeNode } from 'rc-tree';

View File

@ -1,5 +1,3 @@
'use client';
import Link from './Link';
import Paragraph from './Paragraph';
import Text from './Text';

View File

@ -1,5 +1,3 @@
'use client';
import Dragger from './Dragger';
import type { UploadProps } from './Upload';
import InternalUpload, { LIST_IGNORE } from './Upload';

View File

@ -161,7 +161,7 @@
"devDependencies": {
"@ant-design/compatible": "^5.1.2",
"@ant-design/happy-work-theme": "^1.0.0",
"@ant-design/tools": "^17.0.0",
"@ant-design/tools": "^17.3.1",
"@antv/g6": "^4.8.13",
"@argos-ci/core": "^0.9.0",
"@babel/eslint-plugin": "^7.19.1",

View File

@ -0,0 +1,32 @@
const $ = require('dekko');
const chalk = require('chalk');
const fs = require('fs');
const includeUseClient = (filename) =>
fs.readFileSync(filename).toString().includes('"use client"');
if (process.env.LIB_DIR === 'dist') {
$('dist/*')
.isFile()
.assert("doesn't contain use client", (filename) => !includeUseClient(filename));
} else {
$('{es,lib}/index.js')
.isFile()
.assert('contain use client', (filename) => includeUseClient(filename));
$('{es,lib}/*/index.js')
.isFile()
.assert('contain use client', (filename) => includeUseClient(filename));
// check tsx files
$('{es,lib}/typography/*.js')
.isFile()
.assert('contain use client', (filename) => includeUseClient(filename));
$('{es,lib}/typography/Base/*.js')
.isFile()
.assert('contain use client', (filename) => includeUseClient(filename));
}
// eslint-disable-next-line no-console
console.log(chalk.green('✨ use client passed!'));