Skip to content

Commit

Permalink
Merge pull request #23 from ice-lab/ice-scripts/release-2.1.6
Browse files Browse the repository at this point in the history
ice-scripts/release-2.1.6
  • Loading branch information
imsobear authored Aug 2, 2019
2 parents 06cd0c3 + 066f8c9 commit 930c337
Show file tree
Hide file tree
Showing 18 changed files with 118 additions and 36 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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] 支持非终端场景下构建日志的输出
Expand Down
9 changes: 9 additions & 0 deletions packages/ice-plugin-jsx-plus/CHANCELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

## 0.1.1

- [fix] 添加 babel-runtime-jsx-plus 查找目录

## 0.1.0

- [feat] 完成初始版本基础功能
1 change: 1 addition & 0 deletions packages/ice-plugin-jsx-plus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# ice-plugin-jsx-plus
41 changes: 41 additions & 0 deletions packages/ice-plugin-jsx-plus/index.js
Original file line number Diff line number Diff line change
@@ -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'));
});
};
24 changes: 24 additions & 0 deletions packages/ice-plugin-jsx-plus/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
2 changes: 2 additions & 0 deletions packages/ice-scripts/bin/ice-scripts-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const log = require('../lib/utils/log');

program
.option('--config <config>', 'use custom config')
.option('--analyzer', '开启构建分析')
.option('--analyzer-port', '设置分析端口号')
.parse(process.argv);

(async () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/ice-scripts/bin/ice-scripts.js
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion packages/ice-scripts/lib/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/ice-scripts/lib/commands/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/ice-scripts/lib/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 2 additions & 0 deletions packages/ice-scripts/lib/config/jest/shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import 'core-js/stable';
import 'regenerator-runtime/runtime';
5 changes: 0 additions & 5 deletions packages/ice-scripts/lib/config/processEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
1 change: 0 additions & 1 deletion packages/ice-scripts/lib/core/Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}) });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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'));
}
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = (content) => {
return `
import "core-js/stable";
import "regenerator-runtime/runtime";
${content}
`;
};
19 changes: 0 additions & 19 deletions packages/ice-scripts/lib/utils/checkUpdater.js

This file was deleted.

8 changes: 4 additions & 4 deletions packages/ice-scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ice-scripts",
"version": "2.1.5",
"version": "2.1.6",
"description": "ICE SDK",
"main": "index.js",
"bin": {
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -76,13 +76,13 @@
"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",
"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",
Expand Down
1 change: 0 additions & 1 deletion packages/ice-scripts/test/core/Context.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 930c337

Please sign in to comment.