From 2f528a71714cb9a95bccbe179bdb7cee7a932ac8 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Thu, 25 Jul 2019 09:58:27 +0800 Subject: [PATCH 1/6] chore: version --- packages/ice-scripts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ice-scripts/package.json b/packages/ice-scripts/package.json index cb6fa91..8e7a64e 100644 --- a/packages/ice-scripts/package.json +++ b/packages/ice-scripts/package.json @@ -1,6 +1,6 @@ { "name": "ice-scripts", - "version": "2.1.5", + "version": "2.1.6", "description": "ICE SDK", "main": "index.js", "bin": { From be3d5f9fe6f480b6a2aed0006547ada6f550f38e Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Thu, 1 Aug 2019 16:22:36 +0800 Subject: [PATCH 2/6] fix: modify cmd type when run scripts in non-tty (#26) * fix: modify cmdType when run scripts without tty * chore: typo --- packages/ice-scripts/lib/commands/build.js | 2 +- packages/ice-scripts/lib/commands/dev.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ice-scripts/lib/commands/build.js b/packages/ice-scripts/lib/commands/build.js index 64ae37d..31a105b 100644 --- a/packages/ice-scripts/lib/commands/build.js +++ b/packages/ice-scripts/lib/commands/build.js @@ -36,7 +36,7 @@ module.exports = async function (context) { rootDir, kit: 'ice-scripts', kitVersion: iceScriptsPkgData.version, - cmd_type: 'build', + cmdType: process.stderr.isTTY ? 'build' : 'nontty-build', }); } catch (err) { log.warn('collectDetail error', err); diff --git a/packages/ice-scripts/lib/commands/dev.js b/packages/ice-scripts/lib/commands/dev.js index d36ca96..867b4e7 100644 --- a/packages/ice-scripts/lib/commands/dev.js +++ b/packages/ice-scripts/lib/commands/dev.js @@ -50,7 +50,7 @@ module.exports = async function (context, subprocess) { rootDir, kit: 'ice-scripts', kitVersion: pkgData.version, - cmd_type: 'dev', + cmdType: process.stderr.isTTY ? 'dev' : 'nontty-dev', }); } catch (err) { log.warn('collectDetail error', err); From 3092a17b4b6c48a7d08064a23b45a792bdda50aa Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Thu, 1 Aug 2019 16:26:00 +0800 Subject: [PATCH 3/6] feat: add plugin for jsx plus (#25) * feat: add plugin for jsx plus * fix: add resolve modules of babel-runtime-jsx-plus * chore: version * chore: remove space --- packages/ice-plugin-jsx-plus/CHANCELOG.md | 9 +++++ packages/ice-plugin-jsx-plus/README.md | 1 + packages/ice-plugin-jsx-plus/index.js | 41 +++++++++++++++++++++++ packages/ice-plugin-jsx-plus/package.json | 24 +++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 packages/ice-plugin-jsx-plus/CHANCELOG.md create mode 100644 packages/ice-plugin-jsx-plus/README.md create mode 100644 packages/ice-plugin-jsx-plus/index.js create mode 100644 packages/ice-plugin-jsx-plus/package.json diff --git a/packages/ice-plugin-jsx-plus/CHANCELOG.md b/packages/ice-plugin-jsx-plus/CHANCELOG.md new file mode 100644 index 0000000..f33e70a --- /dev/null +++ b/packages/ice-plugin-jsx-plus/CHANCELOG.md @@ -0,0 +1,9 @@ +# Changelog + +## 0.1.1 + +- [fix] 添加 babel-runtime-jsx-plus 查找目录 + +## 0.1.0 + +- [feat] 完成初始版本基础功能 \ No newline at end of file diff --git a/packages/ice-plugin-jsx-plus/README.md b/packages/ice-plugin-jsx-plus/README.md new file mode 100644 index 0000000..c54fce4 --- /dev/null +++ b/packages/ice-plugin-jsx-plus/README.md @@ -0,0 +1 @@ +# ice-plugin-jsx-plus \ No newline at end of file diff --git a/packages/ice-plugin-jsx-plus/index.js b/packages/ice-plugin-jsx-plus/index.js new file mode 100644 index 0000000..eb09b92 --- /dev/null +++ b/packages/ice-plugin-jsx-plus/index.js @@ -0,0 +1,41 @@ +const path = require('path'); + +module.exports = ({ chainWebpack }) => { + // Babel plugins for JSX+ + const plugins = [ + 'babel-plugin-transform-jsx-list', + 'babel-plugin-transform-jsx-condition', + 'babel-plugin-transform-jsx-memo', + 'babel-plugin-transform-jsx-slot', + ['babel-plugin-transform-jsx-fragment', { moduleName: 'react' }], + 'babel-plugin-transform-jsx-class', + ]; + chainWebpack((config) => { + // modify babel config + ['jsx', 'tsx'].forEach((rule) => { + config.module + .rule(rule) + .use('babel-loader') + .tap((options) => { + plugins.forEach(plugin => { + if (typeof plugin === 'string') { + options.plugins.push(require.resolve(plugin)); + } else if (Array.isArray(plugin)) { + const [pluginName, pluginOption] = plugin; + options.plugins.push([ + require.resolve(pluginName), + pluginOption, + ]); + } + }); + return options; + }); + }); + + // add resolve modules for babel-runtime-jsx-plus + const runtimePath = require.resolve('babel-runtime-jsx-plus'); + const pathArr = runtimePath.split('node_modules'); + pathArr.pop(); // pop file path + config.resolve.modules.add(path.join(pathArr.join('node_modules'), 'node_modules')); + }); +}; diff --git a/packages/ice-plugin-jsx-plus/package.json b/packages/ice-plugin-jsx-plus/package.json new file mode 100644 index 0000000..4055440 --- /dev/null +++ b/packages/ice-plugin-jsx-plus/package.json @@ -0,0 +1,24 @@ +{ + "name": "ice-plugin-jsx-plus", + "version": "0.1.1", + "description": "ice plugin for jsx plus", + "main": "index.js", + "scripts": { + "test": "echo \"test\"" + }, + "keywords": [ + "ice", + "ice-plugin" + ], + "author": "", + "license": "ISC", + "dependencies": { + "babel-plugin-transform-jsx-class": "^0.1.2", + "babel-plugin-transform-jsx-condition": "^0.1.1", + "babel-plugin-transform-jsx-fragment": "^0.1.1", + "babel-plugin-transform-jsx-list": "^0.1.0", + "babel-plugin-transform-jsx-memo": "^0.1.2", + "babel-plugin-transform-jsx-slot": "^0.1.1", + "babel-runtime-jsx-plus": "^0.1.3" + } +} From 678dff54b063c8eb4dc831bc1f275fb94aee72ef Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Thu, 1 Aug 2019 16:26:36 +0800 Subject: [PATCH 4/6] fix: remove check update of ice-scripts (#24) * fix: rework check update of ice-scripts * chore: lint * fix: remove nodate-notifier --- packages/ice-scripts/bin/ice-scripts.js | 2 -- .../ice-scripts/lib/utils/checkUpdater.js | 19 ------------------- packages/ice-scripts/package.json | 3 +-- 3 files changed, 1 insertion(+), 23 deletions(-) delete mode 100644 packages/ice-scripts/lib/utils/checkUpdater.js diff --git a/packages/ice-scripts/bin/ice-scripts.js b/packages/ice-scripts/bin/ice-scripts.js index 961b813..4bca185 100755 --- a/packages/ice-scripts/bin/ice-scripts.js +++ b/packages/ice-scripts/bin/ice-scripts.js @@ -1,7 +1,6 @@ #!/usr/bin/env node const program = require('commander'); const packageInfo = require('../package.json'); -const checkUpdater = require('../lib/utils/checkUpdater'); const checkNodeVersion = require('../lib/utils/checkNodeVersion'); const validationSassAvailable = require('../lib/utils/validationSassAvailable'); @@ -10,7 +9,6 @@ const validationSassAvailable = require('../lib/utils/validationSassAvailable'); // finish check before run command checkNodeVersion(packageInfo.engines.node); validationSassAvailable(); - await checkUpdater(); program .version(packageInfo.version) diff --git a/packages/ice-scripts/lib/utils/checkUpdater.js b/packages/ice-scripts/lib/utils/checkUpdater.js deleted file mode 100644 index 89fdc16..0000000 --- a/packages/ice-scripts/lib/utils/checkUpdater.js +++ /dev/null @@ -1,19 +0,0 @@ -const updater = require('npm-updater'); -const packageJson = require('../../package.json'); -const log = require('./log'); - -module.exports = function () { - const tag = 'latest'; - const updateMessage = `你可以执行 npm install ice-scripts@${tag} --save-dev 来安装此版本\n`; - - // 提醒用户安装最新版本 - return updater({ - package: packageJson, - abort: false, - tag, - updateMessage, - interval: '1d', - }).catch((err) => { - log.verbose('check updater error', err); - }); -}; diff --git a/packages/ice-scripts/package.json b/packages/ice-scripts/package.json index 8e7a64e..73f9911 100644 --- a/packages/ice-scripts/package.json +++ b/packages/ice-scripts/package.json @@ -66,8 +66,8 @@ "fs-extra": "^7.0.1", "html-webpack-plugin": "^3.2.0", "identity-obj-proxy": "^3.0.0", - "jest": "^24.8.0", "inquirer": "^6.4.1", + "jest": "^24.8.0", "less": "^3.8.1", "less-loader": "^4.1.0", "lodash": "^4.17.11", @@ -76,7 +76,6 @@ "mkcert": "^1.2.0", "node-ipc": "^9.1.1", "node-sass": "^4.9.0", - "npm-updater": "^3.0.3", "npmlog": "^4.1.2", "optimize-css-assets-webpack-plugin": "^5.0.1", "path-exists": "^3.0.0", From 49c83bc81d474c5fcbf95c2ae63479db4df4bf4e Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Fri, 2 Aug 2019 10:00:25 +0800 Subject: [PATCH 5/6] fix: use core-js and regenerator-runtime instead of @babel/polyfill (#27) * fix: use core-js and regenerator-runtime instead of @babel/polyfill * feat: support analyzer after build * fix: modify setupFiles of command test * fix: add rule polyfill at the end of rules --- packages/ice-scripts/bin/ice-scripts-build.js | 2 ++ packages/ice-scripts/lib/commands/test.js | 2 +- packages/ice-scripts/lib/config/jest/shim.js | 2 ++ .../ice-scripts/lib/config/processEntry.js | 5 ----- packages/ice-scripts/lib/core/Context.js | 1 - .../plugins/userConfig/configs/injectBabel.js | 19 ++++++++++++++++++- .../userConfig/utils/polyfillLoader.js | 7 +++++++ packages/ice-scripts/package.json | 3 ++- .../ice-scripts/test/core/Context.test.js | 1 - 9 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 packages/ice-scripts/lib/config/jest/shim.js create mode 100644 packages/ice-scripts/lib/plugins/userConfig/utils/polyfillLoader.js diff --git a/packages/ice-scripts/bin/ice-scripts-build.js b/packages/ice-scripts/bin/ice-scripts-build.js index 76f5c48..c886f8b 100755 --- a/packages/ice-scripts/bin/ice-scripts-build.js +++ b/packages/ice-scripts/bin/ice-scripts-build.js @@ -6,6 +6,8 @@ const log = require('../lib/utils/log'); program .option('--config ', 'use custom config') + .option('--analyzer', '开启构建分析') + .option('--analyzer-port', '设置分析端口号') .parse(process.argv); (async () => { diff --git a/packages/ice-scripts/lib/commands/test.js b/packages/ice-scripts/lib/commands/test.js index 06d7294..8ef58e9 100644 --- a/packages/ice-scripts/lib/commands/test.js +++ b/packages/ice-scripts/lib/commands/test.js @@ -29,7 +29,7 @@ module.exports = (context) => { // generate default jest config const jestConfig = { rootDir, - setupFiles: [require.resolve('@babel/polyfill')], + setupFiles: [require.resolve('../config/jest/shim.js')], testMatch: ['**/?*.(spec|test).(j|t)s?(x)'], transform: { '^.+\\.(js|jsx|ts|tsx)$': require.resolve('../config/jest/babelTransform.js'), diff --git a/packages/ice-scripts/lib/config/jest/shim.js b/packages/ice-scripts/lib/config/jest/shim.js new file mode 100644 index 0000000..7629ad5 --- /dev/null +++ b/packages/ice-scripts/lib/config/jest/shim.js @@ -0,0 +1,2 @@ +import 'core-js/stable'; +import 'regenerator-runtime/runtime'; \ No newline at end of file diff --git a/packages/ice-scripts/lib/config/processEntry.js b/packages/ice-scripts/lib/config/processEntry.js index 92ac360..04d4787 100644 --- a/packages/ice-scripts/lib/config/processEntry.js +++ b/packages/ice-scripts/lib/config/processEntry.js @@ -51,10 +51,5 @@ module.exports = (entry, options = {}) => { entries = enhanceEntries(entries, hotDevClientPath); } - // Note:https://github.com/alibaba/ice/pull/834 - if (options.polyfill) { - entries = enhanceEntries(entries, require.resolve('@babel/polyfill')); - } - return entries; }; diff --git a/packages/ice-scripts/lib/core/Context.js b/packages/ice-scripts/lib/core/Context.js index a086739..dca2b95 100644 --- a/packages/ice-scripts/lib/core/Context.js +++ b/packages/ice-scripts/lib/core/Context.js @@ -97,7 +97,6 @@ module.exports = class Context { config.entryPoints.clear(); // merge new entry config.merge({ entry: processEntry(entry, { - polyfill: this.userConfig.injectBabel !== 'runtime', hotDev: this.command === 'dev' && !this.commandArgs.disabledReload, }) }); } diff --git a/packages/ice-scripts/lib/plugins/userConfig/configs/injectBabel.js b/packages/ice-scripts/lib/plugins/userConfig/configs/injectBabel.js index e0dae4b..8e88521 100644 --- a/packages/ice-scripts/lib/plugins/userConfig/configs/injectBabel.js +++ b/packages/ice-scripts/lib/plugins/userConfig/configs/injectBabel.js @@ -1,4 +1,6 @@ -module.exports = ({ chainWebpack }, injectBabel) => { +const path = require('path'); + +module.exports = ({ chainWebpack, context }, injectBabel) => { chainWebpack((config) => { if (injectBabel === 'runtime') { ['jsx', 'tsx'].forEach((rule) => { @@ -24,6 +26,21 @@ module.exports = ({ chainWebpack }, injectBabel) => { return Object.assign(options, { plugins }); }); }); + } else if (injectBabel === 'polyfill') { + const { rootDir } = context; + const entries = config.toConfig().entry; + const rule = config.module.rule('polyfill').test(/\.jsx?|\.tsx?$/); + Object.keys(entries).forEach((key) => { + // only include entry path + rule.include.add(path.resolve(rootDir, entries[key][0])); + }); + rule.use('polyfill-loader').loader(require.resolve('../utils/polyfillLoader')).options({}); + + // add resolve modules for get core-js and regenerator-runtime + const modulePath = require.resolve('core-js'); + const pathArr = modulePath.split('node_modules'); + pathArr.pop(); // pop file path + config.resolve.modules.add(path.join(pathArr.join('node_modules'), 'node_modules')); } }); }; diff --git a/packages/ice-scripts/lib/plugins/userConfig/utils/polyfillLoader.js b/packages/ice-scripts/lib/plugins/userConfig/utils/polyfillLoader.js new file mode 100644 index 0000000..16b6370 --- /dev/null +++ b/packages/ice-scripts/lib/plugins/userConfig/utils/polyfillLoader.js @@ -0,0 +1,7 @@ +module.exports = (content) => { + return ` +import "core-js/stable"; +import "regenerator-runtime/runtime"; +${content} + `; +}; diff --git a/packages/ice-scripts/package.json b/packages/ice-scripts/package.json index 73f9911..63d04e4 100644 --- a/packages/ice-scripts/package.json +++ b/packages/ice-scripts/package.json @@ -42,7 +42,6 @@ "@babel/plugin-syntax-dynamic-import": "^7.0.0", "@babel/plugin-syntax-import-meta": "^7.0.0", "@babel/plugin-transform-runtime": "^7.1.0", - "@babel/polyfill": "^7.0.0", "@babel/preset-env": "^7.4.0", "@babel/preset-react": "^7.0.0", "@babel/preset-typescript": "^7.3.3", @@ -57,6 +56,7 @@ "chokidar": "^3.0.0", "commander": "^2.18.0", "copy-webpack-plugin": "^5.0.2", + "core-js": "^3.1.4", "css-hot-loader": "^1.4.2", "css-loader": "^1.0.1", "deepmerge": "^2.1.1", @@ -82,6 +82,7 @@ "postcss-loader": "^3.0.0", "postcss-safe-parser": "^4.0.1", "react-dev-utils": "^5.0.2", + "regenerator-runtime": "^0.13.3", "sass-loader": "^7.1.0", "semver": "^6.1.1", "ts-loader": "^5.3.3", diff --git a/packages/ice-scripts/test/core/Context.test.js b/packages/ice-scripts/test/core/Context.test.js index 296e146..f1cf96e 100644 --- a/packages/ice-scripts/test/core/Context.test.js +++ b/packages/ice-scripts/test/core/Context.test.js @@ -42,7 +42,6 @@ describe('init context', () => { const webpackConfig = context.getWebpackConfig(); expect(webpackConfig.resolve.extensions).toEqual(['.js', '.jsx', '.json', '.html', '.ts', '.tsx']); expect(webpackConfig.entry.index).toEqual([ - require.resolve('@babel/polyfill'), path.resolve(process.cwd(), 'src/index.js'), ]); done(); From 066f8c916378803b0dd38c03a1873b5529a24187 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Fri, 2 Aug 2019 10:29:29 +0800 Subject: [PATCH 6/6] chore: changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c84b011..993f544 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 2.1.6 + +- [fix] remove check latest version of ice-scripts alibaba/ice#2517 +- [fix] modify collect params +- [fix] use core-js and regenerator-runtime instead of @babel/polyfill +- [feat] ice-plugin-jsx-plus for support jsx+ + ## 2.1.5 - [feat] 支持非终端场景下构建日志的输出