mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-29 18:50:00 +08:00
chore: compile without lib (#36362)
* chore: compile es only * chore: update package.json * chore: code clean * chore: code clean * chore: update workflow * chore: update workflow * chore: update less src * chore: replace lib with es * chore: recover less * Revert "chore: replace lib with es" This reverts commit 41b8bf193873ca2d578fff6e6833c739d7f09f1d. * chore: update dist less * test: fix
This commit is contained in:
parent
bd2b80fb88
commit
469d0bc81c
@ -14,11 +14,11 @@ module.exports = {
|
|||||||
|
|
||||||
// We need compile additional content for antd user
|
// We need compile additional content for antd user
|
||||||
function finalizeCompile() {
|
function finalizeCompile() {
|
||||||
if (fs.existsSync(path.join(__dirname, './lib'))) {
|
if (fs.existsSync(path.join(__dirname, './es'))) {
|
||||||
// Build a entry less file to dist/antd.less
|
// Build a entry less file to dist/antd.less
|
||||||
const componentsPath = path.join(process.cwd(), 'components');
|
const componentsPath = path.join(process.cwd(), 'components');
|
||||||
let componentsLessContent = '';
|
let componentsLessContent = '';
|
||||||
// Build components in one file: lib/style/components.less
|
// Build components in one file: es/style/components.less
|
||||||
fs.readdir(componentsPath, (err, files) => {
|
fs.readdir(componentsPath, (err, files) => {
|
||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
if (fs.existsSync(path.join(componentsPath, file, 'style', 'index.less'))) {
|
if (fs.existsSync(path.join(componentsPath, file, 'style', 'index.less'))) {
|
||||||
@ -30,7 +30,7 @@ function finalizeCompile() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(process.cwd(), 'lib', 'style', 'components.less'),
|
path.join(process.cwd(), 'es', 'style', 'components.less'),
|
||||||
componentsLessContent,
|
componentsLessContent,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -42,7 +42,7 @@ function buildThemeFile(theme, vars) {
|
|||||||
if (theme !== 'default') {
|
if (theme !== 'default') {
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(process.cwd(), 'dist', `antd.${theme}.less`),
|
path.join(process.cwd(), 'dist', `antd.${theme}.less`),
|
||||||
`@import "../lib/style/${theme}.less";\n@import "../lib/style/components.less";`,
|
`@import "../es/style/${theme}.less";\n@import "../es/style/components.less";`,
|
||||||
);
|
);
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(`Built a entry less file to dist/antd.${theme}.less`);
|
console.log(`Built a entry less file to dist/antd.${theme}.less`);
|
||||||
@ -78,7 +78,7 @@ function finalizeDist() {
|
|||||||
// Build less entry file: dist/antd.less
|
// Build less entry file: dist/antd.less
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(process.cwd(), 'dist', 'antd.less'),
|
path.join(process.cwd(), 'dist', 'antd.less'),
|
||||||
'@import "../lib/style/default.less";\n@import "../lib/style/components.less";',
|
'@import "../es/style/default.less";\n@import "../es/style/components.less";',
|
||||||
);
|
);
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
@ -96,7 +96,7 @@ function finalizeDist() {
|
|||||||
`
|
`
|
||||||
function getThemeVariables(options = {}) {
|
function getThemeVariables(options = {}) {
|
||||||
let themeVar = {
|
let themeVar = {
|
||||||
'hack': \`true;@import "\${require.resolve('antd/lib/style/color/colorPalette.less')}";\`,
|
'hack': \`true;@import "\${require.resolve('antd/es/style/color/colorPalette.less')}";\`,
|
||||||
...defaultTheme
|
...defaultTheme
|
||||||
};
|
};
|
||||||
if(options.dark) {
|
if(options.dark) {
|
||||||
|
23
.github/workflows/test.yml
vendored
23
.github/workflows/test.yml
vendored
@ -163,12 +163,6 @@ jobs:
|
|||||||
path: node_modules
|
path: node_modules
|
||||||
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
|
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
|
||||||
|
|
||||||
- name: restore cache from lib
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: lib
|
|
||||||
key: lib-${{ github.sha }}
|
|
||||||
|
|
||||||
- name: restore cache from es
|
- name: restore cache from es
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
@ -198,12 +192,6 @@ jobs:
|
|||||||
path: node_modules
|
path: node_modules
|
||||||
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
|
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
|
||||||
|
|
||||||
- name: restore cache from lib
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: lib
|
|
||||||
key: lib-${{ github.sha }}
|
|
||||||
|
|
||||||
- name: restore cache from es
|
- name: restore cache from es
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
@ -324,12 +312,6 @@ jobs:
|
|||||||
path: node_modules
|
path: node_modules
|
||||||
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
|
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
|
||||||
|
|
||||||
- name: cache lib
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: lib
|
|
||||||
key: lib-${{ github.sha }}
|
|
||||||
|
|
||||||
- name: cache es
|
- name: cache es
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
@ -338,9 +320,6 @@ jobs:
|
|||||||
|
|
||||||
- name: compile
|
- name: compile
|
||||||
run: npm run compile
|
run: npm run compile
|
||||||
|
|
||||||
- name: check
|
|
||||||
run: node ./tests/dekko/lib.test.js
|
|
||||||
needs: setup
|
needs: setup
|
||||||
|
|
||||||
compiled-module-test:
|
compiled-module-test:
|
||||||
@ -349,7 +328,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
react: ['16', '17', '18']
|
react: ['16', '17', '18']
|
||||||
module: [lib, es]
|
module: [es]
|
||||||
shard: ['1/2', '2/2']
|
shard: ['1/2', '2/2']
|
||||||
env:
|
env:
|
||||||
REACT: ${{ matrix.react }}
|
REACT: ${{ matrix.react }}
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -60,6 +60,7 @@ site/theme/template/Resources/**/*.jsx
|
|||||||
site/theme/template/NotFound.jsx
|
site/theme/template/NotFound.jsx
|
||||||
scripts/previewEditor/index.html
|
scripts/previewEditor/index.html
|
||||||
components/version/version.tsx
|
components/version/version.tsx
|
||||||
|
components/version/token.tsx
|
||||||
|
|
||||||
# Image snapshot diff
|
# Image snapshot diff
|
||||||
__diff_output__/
|
__diff_output__/
|
||||||
|
14
package.json
14
package.json
@ -32,19 +32,17 @@
|
|||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"lib",
|
|
||||||
"es"
|
"es"
|
||||||
],
|
],
|
||||||
"sideEffects": [
|
"sideEffects": [
|
||||||
"dist/*",
|
"dist/*",
|
||||||
"es/**/style/*",
|
"es/**/style/*",
|
||||||
"lib/**/style/*",
|
|
||||||
"*.less"
|
"*.less"
|
||||||
],
|
],
|
||||||
"main": "lib/index.js",
|
"main": "es/index.js",
|
||||||
"module": "es/index.js",
|
"module": "es/index.js",
|
||||||
"unpkg": "dist/antd.min.js",
|
"unpkg": "dist/antd.min.js",
|
||||||
"typings": "lib/index.d.ts",
|
"typings": "es/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "husky install",
|
"prepare": "husky install",
|
||||||
"api-collection": "antd-tools run api-collection",
|
"api-collection": "antd-tools run api-collection",
|
||||||
@ -55,12 +53,13 @@
|
|||||||
"check-ts-demo": "node ./scripts/check-ts-demo",
|
"check-ts-demo": "node ./scripts/check-ts-demo",
|
||||||
"clean": "antd-tools run clean && rm -rf es lib coverage dist report.html",
|
"clean": "antd-tools run clean && rm -rf es lib coverage dist report.html",
|
||||||
"clean-lockfiles": "rm -rf package-lock.json yarn.lock",
|
"clean-lockfiles": "rm -rf package-lock.json yarn.lock",
|
||||||
|
"collect-token-statistic": "ts-node --project tsconfig.node.json scripts/collect-token-statistic.js",
|
||||||
"prestart": "npm run version",
|
"prestart": "npm run version",
|
||||||
"precompile": "npm run version",
|
"precompile": "npm run version",
|
||||||
"pretest": "npm run version",
|
"pretest": "npm run version",
|
||||||
"predist": "npm run version",
|
"predist": "npm run version",
|
||||||
"presite": "npm run version",
|
"presite": "npm run version",
|
||||||
"compile": "npm run clean && antd-tools run compile && node scripts/collect-token-statistic.js",
|
"compile": "npm run clean && antd-tools run compile-experimental",
|
||||||
"changelog": "node ./scripts/print-changelog",
|
"changelog": "node ./scripts/print-changelog",
|
||||||
"predeploy": "antd-tools run clean && npm run site && cp CNAME _site && npm run site:test",
|
"predeploy": "antd-tools run clean && npm run site && cp CNAME _site && npm run site:test",
|
||||||
"deploy": "bisheng gh-pages --push-only --dotfiles",
|
"deploy": "bisheng gh-pages --push-only --dotfiles",
|
||||||
@ -81,7 +80,7 @@
|
|||||||
"pre-publish": "npm run test-all -- --skip-build",
|
"pre-publish": "npm run test-all -- --skip-build",
|
||||||
"prettier": "prettier -c --write **/*",
|
"prettier": "prettier -c --write **/*",
|
||||||
"pretty-quick": "pretty-quick",
|
"pretty-quick": "pretty-quick",
|
||||||
"pub": "npm run version && antd-tools run pub",
|
"pub": "npm run version && antd-tools run pub-experimental",
|
||||||
"prepublishOnly": "node scripts/collect-token-statistic.js && antd-tools run guard",
|
"prepublishOnly": "node scripts/collect-token-statistic.js && antd-tools run guard",
|
||||||
"postpublish": "node ./scripts/post-script.js",
|
"postpublish": "node ./scripts/post-script.js",
|
||||||
"site:theme": "npm run site:theme-dark && npm run site:theme-compact",
|
"site:theme": "npm run site:theme-dark && npm run site:theme-compact",
|
||||||
@ -100,7 +99,7 @@
|
|||||||
"site:test": "jest --config .jest.site.js --cache=false --force-exit",
|
"site:test": "jest --config .jest.site.js --cache=false --force-exit",
|
||||||
"test-image": "npm run dist && docker-compose run tests",
|
"test-image": "npm run dist && docker-compose run tests",
|
||||||
"argos": "node ./scripts/argos-upload.js",
|
"argos": "node ./scripts/argos-upload.js",
|
||||||
"version": "node ./scripts/generate-version",
|
"version": "node ./scripts/generate-version && npm run collect-token-statistic",
|
||||||
"install-react-16": "npm i --no-save --legacy-peer-deps react@16 react-dom@16 enzyme-adapter-react-16",
|
"install-react-16": "npm i --no-save --legacy-peer-deps react@16 react-dom@16 enzyme-adapter-react-16",
|
||||||
"install-react-17": "npm i --no-save --legacy-peer-deps react@17 react-dom@17",
|
"install-react-17": "npm i --no-save --legacy-peer-deps react@17 react-dom@17",
|
||||||
"install-react-18": "npm i --no-save --legacy-peer-deps react@18 react-dom@18 @testing-library/react@13"
|
"install-react-18": "npm i --no-save --legacy-peer-deps react@18 react-dom@18 @testing-library/react@13"
|
||||||
@ -294,6 +293,7 @@
|
|||||||
"stylelint-declaration-block-no-ignored-properties": "^2.1.0",
|
"stylelint-declaration-block-no-ignored-properties": "^2.1.0",
|
||||||
"stylelint-order": "^5.0.0",
|
"stylelint-order": "^5.0.0",
|
||||||
"theme-switcher": "^1.0.2",
|
"theme-switcher": "^1.0.2",
|
||||||
|
"ts-node": "^10.8.2",
|
||||||
"typescript": "~4.7.2",
|
"typescript": "~4.7.2",
|
||||||
"webpack-bundle-analyzer": "^4.1.0",
|
"webpack-bundle-analyzer": "^4.1.0",
|
||||||
"xhr-mock": "^2.4.1",
|
"xhr-mock": "^2.4.1",
|
||||||
|
@ -1,62 +1,46 @@
|
|||||||
/* eslint-disable import/no-unresolved,no-console */
|
/* eslint-disable import/no-unresolved,no-console,global-require,import/no-dynamic-require */
|
||||||
|
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const ReactDOMServer = require('react-dom/server');
|
const ReactDOMServer = require('react-dom/server');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const antd = require('../lib');
|
const glob = require('glob');
|
||||||
const { statistic } = require('../lib/theme/util/statistic');
|
const path = require('path');
|
||||||
const useMessageStyle = require('../lib/message/style/index').default;
|
const { statistic } = require('../components/theme/util/statistic');
|
||||||
const useNotificationStyle = require('../lib/notification/style/index').default;
|
|
||||||
|
|
||||||
console.log(chalk.green(`🔥 Collecting token statistics...`));
|
console.log(chalk.green(`🔥 Collecting token statistics...`));
|
||||||
// Automatic rendering
|
|
||||||
Object.entries(antd).forEach(([key, component]) => {
|
|
||||||
if (
|
|
||||||
/[A-Z]/.test(key.charAt(0)) &&
|
|
||||||
key !== 'Form' &&
|
|
||||||
key !== 'Dropdown' &&
|
|
||||||
key !== 'Grid' &&
|
|
||||||
key !== 'ConfigProvider'
|
|
||||||
) {
|
|
||||||
ReactDOMServer.renderToString(React.createElement(component));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const EmptyElement = React.createElement('div');
|
const EmptyElement = React.createElement('div');
|
||||||
|
|
||||||
// Dropdown
|
const styleFiles = glob.sync(
|
||||||
ReactDOMServer.renderToString(
|
path.join(
|
||||||
React.createElement(antd.Dropdown, { overlay: EmptyElement }, EmptyElement),
|
process.cwd(),
|
||||||
|
'components/!(version|config-provider|icon|locale-provider|auto-complete|col|row|page-header|comment|time-picker|)/style/index.tsx',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
styleFiles.forEach(file => {
|
||||||
// Form
|
console.log(file);
|
||||||
ReactDOMServer.renderToString(React.createElement(antd.Form, undefined, EmptyElement));
|
let useStyle = () => {};
|
||||||
|
if (file.includes('grid')) {
|
||||||
// message
|
const { useColStyle, useRowStyle } = require(file);
|
||||||
const Message = () => {
|
useStyle = () => {
|
||||||
useMessageStyle('message');
|
useRowStyle();
|
||||||
|
useColStyle();
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
useStyle = require(file).default;
|
||||||
|
}
|
||||||
|
const Component = () => {
|
||||||
|
useStyle('file');
|
||||||
return EmptyElement;
|
return EmptyElement;
|
||||||
};
|
};
|
||||||
ReactDOMServer.renderToString(React.createElement(Message));
|
ReactDOMServer.renderToString(React.createElement(Component));
|
||||||
|
});
|
||||||
// Notification
|
|
||||||
const Notification = () => {
|
|
||||||
useNotificationStyle('notification');
|
|
||||||
return EmptyElement;
|
|
||||||
};
|
|
||||||
ReactDOMServer.renderToString(React.createElement(Notification));
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const libPath = `${process.cwd()}/lib/theme/util/statistic.js`;
|
const tokenPath = `${process.cwd()}/components/version/token.tsx`;
|
||||||
const libContent = await fs.readFile(libPath, 'utf8');
|
const content = `export default ${JSON.stringify(statistic, null, 2)}`;
|
||||||
const newLibContent = `${libContent}\nexports._statistic_build_ = ${JSON.stringify(statistic)}`;
|
await fs.writeFile(tokenPath, content, 'utf8');
|
||||||
await fs.writeFile(libPath, newLibContent, 'utf8');
|
|
||||||
|
|
||||||
const esPath = `${process.cwd()}/es/theme/util/statistic.js`;
|
|
||||||
const esContent = await fs.readFile(esPath, 'utf8');
|
|
||||||
const newEsContent = `${esContent}\n_statistic_build_ = ${JSON.stringify(statistic)}`;
|
|
||||||
await fs.writeFile(esPath, newEsContent, 'utf8');
|
|
||||||
|
|
||||||
console.log(chalk.green(`✅ Collecting token statistics done.`));
|
console.log(chalk.green(`✅ Collecting token statistics done.`));
|
||||||
})();
|
})();
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
const $ = require('dekko');
|
|
||||||
const chalk = require('chalk');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
function getFileName(filePath) {
|
|
||||||
return filePath.slice(filePath.lastIndexOf(path.sep) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$('lib').isDirectory().hasFile('index.js').hasFile('index.d.ts');
|
|
||||||
|
|
||||||
$('lib/style').isDirectory().hasFile('index.css').hasFile('default.css');
|
|
||||||
|
|
||||||
$('lib/*')
|
|
||||||
.filter(
|
|
||||||
filename =>
|
|
||||||
!filename.endsWith('index.js') &&
|
|
||||||
!filename.endsWith('index.d.ts') &&
|
|
||||||
!filename.endsWith('.map'),
|
|
||||||
)
|
|
||||||
.isDirectory()
|
|
||||||
.filter(
|
|
||||||
filename =>
|
|
||||||
!filename.endsWith('style') &&
|
|
||||||
!filename.endsWith('_util') &&
|
|
||||||
!filename.endsWith('theme') &&
|
|
||||||
!filename.endsWith('locale'),
|
|
||||||
)
|
|
||||||
.hasFile('index.js')
|
|
||||||
.hasFile('index.d.ts')
|
|
||||||
.hasDirectory('style');
|
|
||||||
|
|
||||||
$('lib/*/style').hasFile('css.js').hasFile('index.js');
|
|
||||||
|
|
||||||
// locale
|
|
||||||
const filterLocaleFile = filePath => {
|
|
||||||
const fileName = getFileName(filePath);
|
|
||||||
return (
|
|
||||||
!fileName.endsWith('index.js') &&
|
|
||||||
!fileName.endsWith('.d.ts') &&
|
|
||||||
!fileName.endsWith('.map') &&
|
|
||||||
!fileName.endsWith('style') &&
|
|
||||||
!fileName.includes('-') &&
|
|
||||||
!fileName.endsWith('LocaleReceiver.js') &&
|
|
||||||
!fileName.endsWith('context.js')
|
|
||||||
);
|
|
||||||
};
|
|
||||||
const localeFiles = $('lib/locale/*').filter(filterLocaleFile);
|
|
||||||
const localeProviderFiles = $('lib/locale-provider/*').filter(filterLocaleFile);
|
|
||||||
|
|
||||||
function compare(originFiles, targetFiles, targetPath) {
|
|
||||||
originFiles.assert(
|
|
||||||
`not exist in '${targetPath}'. Please use 'scripts/generateLegacyLocale.js' to refresh locale files.`,
|
|
||||||
filePath => {
|
|
||||||
const fileName = getFileName(filePath);
|
|
||||||
|
|
||||||
return targetFiles.filenames.some(targetFilePath => getFileName(targetFilePath) === fileName);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
compare(localeFiles, localeProviderFiles, '/locale-provider');
|
|
||||||
compare(localeProviderFiles, localeFiles, '/locale');
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log(chalk.green('✨ `lib` directory is valid.'));
|
|
7
tsconfig.node.json
Normal file
7
tsconfig.node.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "CommonJS",
|
||||||
|
"types": ["node"]
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user