From b22ab1a83c8b3f65b5cffad755680313c00b8813 Mon Sep 17 00:00:00 2001 From: Chuns Chen Date: Tue, 22 Nov 2022 16:21:37 +0800 Subject: [PATCH] chore: revert compile with lib (#38832) * chore: revert compile with lib * chore: lib dekko test * fix: filename has spaces * chore: bump @ant-design/tools --- .antd-tools.config.js | 18 +++++------- .github/workflows/test.yml | 11 ++++++- package.json | 9 +++--- tests/dekko/lib.test.js | 60 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 15 deletions(-) create mode 100644 tests/dekko/lib.test.js diff --git a/.antd-tools.config.js b/.antd-tools.config.js index 5c139e9d30..deb1c04063 100644 --- a/.antd-tools.config.js +++ b/.antd-tools.config.js @@ -1,23 +1,21 @@ const fs = require('fs'); const path = require('path'); +const restCssPath = path.join(process.cwd(), 'components', 'style', 'reset.css'); + function finalizeCompile() { if (fs.existsSync(path.join(__dirname, './es'))) { - // Build less entry file: dist/antd.less - fs.copyFileSync( - path.join(process.cwd(), 'components', 'style', 'reset.css'), - path.join(process.cwd(), 'es', 'style', 'reset.css'), - ); + fs.copyFileSync(restCssPath, path.join(process.cwd(), 'es', 'style', 'reset.css')); + } + + if (fs.existsSync(path.join(__dirname, './lib'))) { + fs.copyFileSync(restCssPath, path.join(process.cwd(), 'lib', 'style', 'reset.css')); } } function finalizeDist() { if (fs.existsSync(path.join(__dirname, './dist'))) { - // Build less entry file: dist/antd.less - fs.copyFileSync( - path.join(process.cwd(), 'components', 'style', 'reset.css'), - path.join(process.cwd(), 'dist', 'reset.css'), - ); + fs.copyFileSync(restCssPath, path.join(process.cwd(), 'dist', 'reset.css')); } } diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d522526689..53d87f61fd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -250,6 +250,12 @@ jobs: path: node_modules 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 uses: actions/cache@v3 with: @@ -258,6 +264,9 @@ jobs: - name: compile run: npm run compile + + - name: check + run: node ./tests/dekko/lib.test.js needs: setup compiled-module-test: @@ -266,7 +275,7 @@ jobs: strategy: matrix: react: ['16', '17', '18'] - module: [es] + module: [lib, es] shard: ['1/2', '2/2'] env: REACT: ${{ matrix.react }} diff --git a/package.json b/package.json index 3310ddec3f..b57abb003d 100644 --- a/package.json +++ b/package.json @@ -33,12 +33,13 @@ "files": [ "dist", "es", + "lib", "locale" ], "sideEffects": [ "*.less" ], - "main": "dist/antd.js", + "main": "lib/index.js", "module": "es/index.js", "unpkg": "dist/antd.min.js", "typings": "es/index.d.ts", @@ -59,7 +60,7 @@ "pretest": "npm run version", "predist": "npm run version", "presite": "npm run version && npm run collect-token-statistic", - "compile": "npm run clean && antd-tools run compile-experimental", + "compile": "npm run clean && antd-tools run compile", "changelog": "node ./scripts/print-changelog", "predeploy": "antd-tools run clean && npm run site && cp CNAME _site && npm run site:test", "deploy": "gh-pages -d _site -b gh-pages -f", @@ -77,7 +78,7 @@ "lint:script": "eslint . --ext .js,.jsx,.ts,.tsx", "pre-publish": "npm run test-all -- --skip-build", "prettier": "prettier -c --write **/*", - "pub": "npm run version && npm run collect-token-statistic && antd-tools run pub-experimental", + "pub": "npm run version && npm run collect-token-statistic && antd-tools run pub", "rome:format": "rome format --write .", "prepublishOnly": "antd-tools run guard", "postpublish": "node ./scripts/post-script.js", @@ -157,7 +158,7 @@ "devDependencies": { "@ant-design/bisheng-plugin": "^3.3.0-alpha.4", "@ant-design/hitu": "^0.0.0-alpha.13", - "@ant-design/tools": "^16.0.0-alpha.3", + "@ant-design/tools": "^16.1.0-alpha.2", "@docsearch/css": "^3.0.0", "@emotion/babel-preset-css-prop": "^11.10.0", "@emotion/css": "^11.10.5", diff --git a/tests/dekko/lib.test.js b/tests/dekko/lib.test.js new file mode 100644 index 0000000000..73c626f124 --- /dev/null +++ b/tests/dekko/lib.test.js @@ -0,0 +1,60 @@ +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/*') + .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('locale'), + ) + .hasFile('index.js') + .hasFile('index.d.ts'); + +// 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.'));