From ea68846de7b437aff46f3d7ec381da93db728010 Mon Sep 17 00:00:00 2001 From: * <8> Date: Mon, 7 Mar 2022 17:13:00 +0800 Subject: [PATCH 1/4] Match-id-a8b5250aac298f4a0a53722836c75ea1aa46c377 --- .gitignore | 1 + README.md | 50 ++++++++++++++++--- .../.babelrc | 25 ++++++++++ .../README.md | 1 + .../babel.config.js | 10 ++++ .../jest.config.js | 10 ++++ .../package.json | 37 ++++++++++++++ .../src/index.ts | 25 ++++++++++ .../test/index.spec.ts | 10 ++++ libs/{ => horizon}/README.md | 0 libs/{ => horizon}/index.d.ts | 0 libs/{ => horizon}/index.js | 0 libs/{ => horizon}/index.ts | 4 +- libs/{ => horizon}/package.json | 0 package.json | 41 ++++----------- 15 files changed, 175 insertions(+), 39 deletions(-) create mode 100644 libs/horizon-jsx-transform-babel-plugin/.babelrc create mode 100644 libs/horizon-jsx-transform-babel-plugin/README.md create mode 100644 libs/horizon-jsx-transform-babel-plugin/babel.config.js create mode 100644 libs/horizon-jsx-transform-babel-plugin/jest.config.js create mode 100644 libs/horizon-jsx-transform-babel-plugin/package.json create mode 100644 libs/horizon-jsx-transform-babel-plugin/src/index.ts create mode 100644 libs/horizon-jsx-transform-babel-plugin/test/index.spec.ts rename libs/{ => horizon}/README.md (100%) rename libs/{ => horizon}/index.d.ts (100%) rename libs/{ => horizon}/index.js (100%) rename libs/{ => horizon}/index.ts (94%) rename libs/{ => horizon}/package.json (100%) diff --git a/.gitignore b/.gitignore index 7c699172..070f36c2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build/ .idea .vscode package-lock.json +libs/**/dist diff --git a/README.md b/README.md index da653b2d..8706f7f9 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,52 @@ # horizon - ## 工程编译: -1、npm install -2、npm run build +Horizon采用monorepo方式管理项目,意思是在版本控制系统的单个代码库里包含了许多项目的代码 -全局单元测试 npm run test +monorepo工具采用yarn +### yarn配置 +1. yarn1(推荐) +``` shell +// 先安装yarn +npm i yarn -g +``` +在 `C:\Users\[工号]\.yarnrc`无相应文件需要新建 -发布包: +加入yarn配置: +```shell +registry "http://szxy1.artifactory.cd-cloud-artifact.tools.huawei.com/artifactory/api/npm/sz-npm-public" +no-proxy .huawei.com +lastUpdateCheck 1646381423295 +strict-ssl false +``` +2. yarn2 + +由于yarn2+有不兼容更新,安装方式依赖node 16+的corepack功能,安装参考 [yarn官网](https://yarnpkg.com/getting-started/install) +在 `C:\Users\[工号]\.yarnrc.yml`加入yarn配置,无相应文件需要新建 + +加入yarn配置: +```shell +npmRegistryServer "http://szxy1.artifactory.cd-cloud-artifact.tools.huawei.com/artifactory/api/npm/sz-npm-public" +``` +注意:yarn2配置文件和字段都存在大量不兼容,参考[详细配置](https://yarnpkg.com/configuration/yarnrc#npmRegistryServer) +### 工程命令 +#### 安装 +```shell +yarn +``` +> 需要使用yarn安装,monorepo的依赖才能正确安装到node_modules +#### 打包 +```shell +yarn run build +``` +#### 全局单元测试 +```shell +yarn run test +``` + +#### 发布包: +```shell npm publish build/horizon --_auth=XXX - +``` XXX是base64编码后的密码值,CMO保管。 ## 不兼容: diff --git a/libs/horizon-jsx-transform-babel-plugin/.babelrc b/libs/horizon-jsx-transform-babel-plugin/.babelrc new file mode 100644 index 00000000..da678c47 --- /dev/null +++ b/libs/horizon-jsx-transform-babel-plugin/.babelrc @@ -0,0 +1,25 @@ +{ + "plugins": [ + "@babel/plugin-syntax-dynamic-import", + "@babel/plugin-syntax-import-meta", + "@babel/plugin-proposal-class-properties", + "@babel/plugin-proposal-json-strings", + [ + "@babel/plugin-proposal-decorators", + { + "legacy": true + } + ], + "@babel/plugin-proposal-function-sent", + "@babel/plugin-proposal-export-namespace-from", + "@babel/plugin-proposal-numeric-separator", + "@babel/plugin-proposal-throw-expressions" + ], + "env": { + "test": { + "plugins": [ + "@babel/plugin-transform-modules-commonjs" + ] + } + } +} diff --git a/libs/horizon-jsx-transform-babel-plugin/README.md b/libs/horizon-jsx-transform-babel-plugin/README.md new file mode 100644 index 00000000..d61ed313 --- /dev/null +++ b/libs/horizon-jsx-transform-babel-plugin/README.md @@ -0,0 +1 @@ +# horizon jsx babel plugin diff --git a/libs/horizon-jsx-transform-babel-plugin/babel.config.js b/libs/horizon-jsx-transform-babel-plugin/babel.config.js new file mode 100644 index 00000000..0e88e2a3 --- /dev/null +++ b/libs/horizon-jsx-transform-babel-plugin/babel.config.js @@ -0,0 +1,10 @@ +/* istanbul ignore next */ +module.exports = { + presets: [ + '@babel/preset-env', + ], + plugins: [ + /* eslint-disable-next-line global-require */ + [require('./dist/index.js')], + ], +}; diff --git a/libs/horizon-jsx-transform-babel-plugin/jest.config.js b/libs/horizon-jsx-transform-babel-plugin/jest.config.js new file mode 100644 index 00000000..a8851a34 --- /dev/null +++ b/libs/horizon-jsx-transform-babel-plugin/jest.config.js @@ -0,0 +1,10 @@ +module.exports = { + transform: { + '\\.(ts|tsx)$': 'ts-jest', + }, + globals: { + 'ts-jest': { + babelConfig: true, + }, + }, +}; diff --git a/libs/horizon-jsx-transform-babel-plugin/package.json b/libs/horizon-jsx-transform-babel-plugin/package.json new file mode 100644 index 00000000..41b6f7b8 --- /dev/null +++ b/libs/horizon-jsx-transform-babel-plugin/package.json @@ -0,0 +1,37 @@ +{ + "name": "@cloudsop/horizon-jsx-transform-babel-plugin", + "version": "0.2.0", + "description": "transform jsx for horizon", + "main": "./dist/index.js", + "scripts": { + "build": "rimraf dist && tsc", + "test": "rimraf dist && tsc && jest", + "jest": "jest", + "prepublish": "npm run build" + }, + "files": [ + "../dist" + ], + "dependencies": { + "@babel/generator": "^7.2.2", + "@babel/parser": "^7.2.3" + }, + "devDependencies": { + "@babel/core": "^7.2.2", + "@babel/plugin-proposal-class-properties": "^7.2.1", + "@babel/plugin-proposal-decorators": "^7.2.0", + "@babel/plugin-proposal-export-namespace-from": "^7.2.0", + "@babel/plugin-proposal-function-sent": "^7.2.0", + "@babel/plugin-proposal-json-strings": "^7.2.0", + "@babel/plugin-proposal-numeric-separator": "^7.2.0", + "@babel/plugin-proposal-throw-expressions": "^7.2.0", + "@babel/plugin-syntax-dynamic-import": "^7.2.0", + "@babel/plugin-syntax-import-meta": "^7.2.0", + "@babel/plugin-syntax-jsx": "^7.2.0", + "@babel/plugin-transform-modules-commonjs": "^7.2.0", + "@babel/preset-env": "^7.16.11", + "@babel/types": "^7.0.0", + "babel-plugin-tester": "^10.1.0", + "ts-jest": "^26.1.3" + } +} diff --git a/libs/horizon-jsx-transform-babel-plugin/src/index.ts b/libs/horizon-jsx-transform-babel-plugin/src/index.ts new file mode 100644 index 00000000..0b0f7818 --- /dev/null +++ b/libs/horizon-jsx-transform-babel-plugin/src/index.ts @@ -0,0 +1,25 @@ +import SyntaxJSX from '@babel/plugin-syntax-jsx'; +import * as BabelCore from '@babel/core'; +import * as t from '@babel/types'; +import {NodePath} from '@babel/traverse'; + +export default ({types}: typeof BabelCore) => { + return { + name: 'horizon-jsx-babel-plugin', + inherits: SyntaxJSX, + + visitor: { + Program(path: NodePath) { + // program = path + }, + + JSXElement: { + exit(path) { + + }, + }, + + } + }; +}; + diff --git a/libs/horizon-jsx-transform-babel-plugin/test/index.spec.ts b/libs/horizon-jsx-transform-babel-plugin/test/index.spec.ts new file mode 100644 index 00000000..b7496e5e --- /dev/null +++ b/libs/horizon-jsx-transform-babel-plugin/test/index.spec.ts @@ -0,0 +1,10 @@ +const path = require('path'); +const pluginTester = require('babel-plugin-tester').default; +import plugin from '../src'; + +pluginTester({ + plugin, + title: 'horizon jsx plugin', + fixtures: path.join(__dirname, '__fixtures__'), + snapshot: true +}); diff --git a/libs/README.md b/libs/horizon/README.md similarity index 100% rename from libs/README.md rename to libs/horizon/README.md diff --git a/libs/index.d.ts b/libs/horizon/index.d.ts similarity index 100% rename from libs/index.d.ts rename to libs/horizon/index.d.ts diff --git a/libs/index.js b/libs/horizon/index.js similarity index 100% rename from libs/index.js rename to libs/horizon/index.js diff --git a/libs/index.ts b/libs/horizon/index.ts similarity index 94% rename from libs/index.ts rename to libs/horizon/index.ts index 57f83b0b..64762f9e 100644 --- a/libs/index.ts +++ b/libs/horizon/index.ts @@ -23,7 +23,7 @@ import { createElement, cloneElement, isValidElement, -} from './horizon/src/external/Horizon'; +} from './src/external/Horizon'; import { render, @@ -31,7 +31,7 @@ import { unstable_batchedUpdates, findDOMNode, unmountComponentAtNode, -} from './horizon/src/dom/DOMExternal'; +} from './src/dom/DOMExternal'; const Horizon = { Children, diff --git a/libs/package.json b/libs/horizon/package.json similarity index 100% rename from libs/package.json rename to libs/horizon/package.json diff --git a/package.json b/package.json index 2091aad8..a6bae649 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,14 @@ "workspaces": [ "libs/*" ], + "scripts": { + "build": " webpack --config ./scripts/webpack/webpack.config.js", + "build-3rdLib": "node ./scripts/gen3rdLib.js", + "build-3rdLib-dev": "node ./scripts/gen3rdLib.js --dev", + "debug-test": "yarn test --debug", + "test": "jest --config=jest.config.js", + "watch-test": "yarn test --watch --dev" + }, "devDependencies": { "@babel/cli": "^7.10.5", "@babel/code-frame": "^7.10.4", @@ -40,9 +48,9 @@ "@babel/preset-typescript": "^7.16.7", "@babel/register": "^7.14.5", "@babel/traverse": "^7.11.0", - "@cloudsop/eview-ui": "^0.1.65", "@mattiasbuelens/web-streams-polyfill": "^0.3.2", - "art": "0.10.1", + "@types/jest": "^26.0.24", + "@types/node": "^17.0.18", "babel-core": "^6.26.3", "babel-eslint": "^10.0.3", "babel-jest": "^27.5.1", @@ -52,14 +60,11 @@ "babel-preset-react": "^6.24.1", "chalk": "^3.0.0", "clean-webpack-plugin": "^4.0.0-alpha.0", - "cli-table": "^0.3.1", - "coffee-script": "^1.12.7", "concurrently": "^6.2.0", "confusing-browser-globals": "^1.0.9", "copy-webpack-plugin": "5.0.4", "core-js": "^3.6.4", "coveralls": "^3.0.9", - "create-react-class": "^15.6.3", "cross-env": "^7.0.3", "css-loader": "3.4.2", "danger": "^9.2.10", @@ -76,15 +81,11 @@ "eslint-plugin-react": "^6.7.1", "eslint-webpack-plugin": "^3.0.1", "express": "^4.17.1", - "fbjs-scripts": "1.2.0", "filesize": "^6.0.1", - "flow-bin": "0.97", "glob": "^7.1.6", "glob-stream": "^6.1.0", - "google-closure-compiler": "^20200517.0.0", "gzip-size": "^5.1.1", "html-webpack-plugin": "4.4.1", - "jasmine-check": "^1.0.0-rc.0", "jest": "^25.5.4", "jest-cli": "^25.2.7", "jest-diff": "^25.2.6", @@ -94,18 +95,14 @@ "minimatch": "^3.0.4", "minimist": "^1.2.3", "mkdirp": "^0.5.1", - "mocha": "^9.0.1", "ncp": "^2.0.0", "object-assign": "^4.1.1", "pacote": "^10.3.0", "power-assert": "^1.6.1", "prettier": "1.19.1", "prop-types": "^15.6.2", - "puppeteer-core": "^10.1.0", "random-seed": "^0.3.0", - "react-is": "^17.0.2", "react-lifecycles-compat": "^3.0.4", - "react-router-dom": "^5.2.0", "regenerator-runtime": "^0.13.9", "resemblejs": "^4.0.0", "rimraf": "^3.0.0", @@ -124,23 +121,5 @@ }, "devEngines": { "node": "8.x || 9.x || 10.x || 11.x || 12.x || 13.x || 14.x" - }, - "scripts": { - "build": " webpack --config ./scripts/webpack/webpack.config.js", - "build-3rdLib": "node ./scripts/gen3rdLib.js", - "build-3rdLib-dev": "node ./scripts/gen3rdLib.js --dev", - "debug-test": "yarn test --debug", - "test": "jest --config=jest.config.js", - "watch-test": "yarn test --watch --release-channel=horizon --dev" - }, - "dependencies": { - "@elg/speedscope": "^1.9.0-a6f84db", - "@types/node": "^17.0.18", - "babel-code-frame": "^6.26.0", - "grunt-cli": "^1.4.3", - "react-dom": "^17.0.2", - "react-shallow-renderer": "^16.14.1", - "rxjs": "^7.1.0", - "symlink-dir": "^4.2.0" } } From 885af8cb7948e719251ddba21b1e7a96329d58f7 Mon Sep 17 00:00:00 2001 From: * <8> Date: Tue, 8 Mar 2022 11:44:48 +0800 Subject: [PATCH 2/4] Match-id-bb74986eff163d2fe265b8aac9796fe992faf803 --- README.md | 35 ++++--------------------- libs/horizon/src/external/JSXElement.ts | 8 +++--- package.json | 34 +++--------------------- scripts/webpack/webpack.base.js | 5 ++-- 4 files changed, 15 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 8706f7f9..d8d63078 100644 --- a/README.md +++ b/README.md @@ -2,45 +2,20 @@ ## 工程编译: Horizon采用monorepo方式管理项目,意思是在版本控制系统的单个代码库里包含了许多项目的代码 -monorepo工具采用yarn -### yarn配置 -1. yarn1(推荐) -``` shell -// 先安装yarn -npm i yarn -g -``` -在 `C:\Users\[工号]\.yarnrc`无相应文件需要新建 - -加入yarn配置: -```shell -registry "http://szxy1.artifactory.cd-cloud-artifact.tools.huawei.com/artifactory/api/npm/sz-npm-public" -no-proxy .huawei.com -lastUpdateCheck 1646381423295 -strict-ssl false -``` -2. yarn2 - -由于yarn2+有不兼容更新,安装方式依赖node 16+的corepack功能,安装参考 [yarn官网](https://yarnpkg.com/getting-started/install) -在 `C:\Users\[工号]\.yarnrc.yml`加入yarn配置,无相应文件需要新建 - -加入yarn配置: -```shell -npmRegistryServer "http://szxy1.artifactory.cd-cloud-artifact.tools.huawei.com/artifactory/api/npm/sz-npm-public" -``` -注意:yarn2配置文件和字段都存在大量不兼容,参考[详细配置](https://yarnpkg.com/configuration/yarnrc#npmRegistryServer) +monorepo工具采用npm workspaces **(npm版本需要大于7.x)** ### 工程命令 #### 安装 ```shell -yarn +npm install ``` -> 需要使用yarn安装,monorepo的依赖才能正确安装到node_modules +> 需要使用npm7.x以后版本安装,monorepo的依赖才能正确安装到node_modules #### 打包 ```shell -yarn run build +npm run build ``` #### 全局单元测试 ```shell -yarn run test +npm run test ``` #### 发布包: diff --git a/libs/horizon/src/external/JSXElement.ts b/libs/horizon/src/external/JSXElement.ts index 2a138387..1829bbd3 100644 --- a/libs/horizon/src/external/JSXElement.ts +++ b/libs/horizon/src/external/JSXElement.ts @@ -30,7 +30,7 @@ function isValidKey(key) { } function mergeDefault(sourceObj, defaultObj) { - Object.keys(defaultObj).forEach((key) => { + Object.keys(defaultObj).forEach(key => { if (sourceObj[key] === undefined) { sourceObj[key] = defaultObj[key]; } @@ -44,10 +44,10 @@ function buildElement(isClone, type, setting, children) { const props = isClone ? { ...type.props } : {}; let vNode = isClone ? type.belongClassVNode : getProcessingClassVNode(); - if (setting != null) { + if (setting !== null) { const keys = Object.keys(setting); const keyLength = keys.length; - for(let i = 0; i < keyLength; i++) { + for (let i = 0; i < keyLength; i++) { const k = keys[i]; if (isValidKey(k)) { props[k] = setting[k]; @@ -81,5 +81,5 @@ export function cloneElement(element, setting, ...children) { // 检测结构体是否为合法的Element export function isValidElement(element) { - return !!(element && element.vtype === TYPE_COMMON_ELEMENT); + return (element && element.vtype === TYPE_COMMON_ELEMENT); } diff --git a/package.json b/package.json index a6bae649..7b933fc4 100644 --- a/package.json +++ b/package.json @@ -59,14 +59,9 @@ "babel-preset-env": "^1.7.0", "babel-preset-react": "^6.24.1", "chalk": "^3.0.0", - "clean-webpack-plugin": "^4.0.0-alpha.0", - "concurrently": "^6.2.0", "confusing-browser-globals": "^1.0.9", "copy-webpack-plugin": "5.0.4", "core-js": "^3.6.4", - "coveralls": "^3.0.9", - "cross-env": "^7.0.3", - "css-loader": "3.4.2", "danger": "^9.2.10", "ejs": "^3.1.6", "error-stack-parser": "^2.0.6", @@ -80,46 +75,25 @@ "eslint-plugin-no-function-declare-after-return": "^1.0.0", "eslint-plugin-react": "^6.7.1", "eslint-webpack-plugin": "^3.0.1", - "express": "^4.17.1", - "filesize": "^6.0.1", - "glob": "^7.1.6", - "glob-stream": "^6.1.0", - "gzip-size": "^5.1.1", - "html-webpack-plugin": "4.4.1", "jest": "^25.5.4", "jest-cli": "^25.2.7", "jest-diff": "^25.2.6", "jest-environment-jsdom-sixteen": "^1.0.3", "jest-react": "^0.12.0", "jest-snapshot-serializer-raw": "^1.1.0", - "minimatch": "^3.0.4", "minimist": "^1.2.3", - "mkdirp": "^0.5.1", - "ncp": "^2.0.0", "object-assign": "^4.1.1", - "pacote": "^10.3.0", - "power-assert": "^1.6.1", "prettier": "1.19.1", - "prop-types": "^15.6.2", - "random-seed": "^0.3.0", "react-lifecycles-compat": "^3.0.4", "regenerator-runtime": "^0.13.9", - "resemblejs": "^4.0.0", "rimraf": "^3.0.0", - "semver": "^7.1.1", - "style-loader": "1.0.0", - "targz": "^1.0.1", - "through2": "^3.0.1", - "tmp": "^0.1.0", "tslint": "^6.0.0", "typescript": "^3.9.7", - "url-loader": "^4.1.1", - "wait-on": "^6.0.0", "webpack": "^4.46.0", - "webpack-cli": "^4.7.2", - "yargs": "^15.3.1" + "webpack-cli": "^4.7.2" }, - "devEngines": { - "node": "8.x || 9.x || 10.x || 11.x || 12.x || 13.x || 14.x" + "engines": { + "node": ">=10.x", + "npm": ">=7.x" } } diff --git a/scripts/webpack/webpack.base.js b/scripts/webpack/webpack.base.js index ed5ed92d..8bae9049 100644 --- a/scripts/webpack/webpack.base.js +++ b/scripts/webpack/webpack.base.js @@ -1,7 +1,6 @@ -'use strict'; const path = require('path'); -const libPath = path.join(__dirname, '../../libs'); +const libPath = path.join(__dirname, '../../libs/horizon'); const baseConfig = { entry: path.resolve(libPath, 'index.ts'), module: { @@ -10,7 +9,7 @@ const baseConfig = { test: /\.(js)|ts$/, exclude: /node_modules/, use: [ - { + { loader: 'babel-loader' } ] From 6fa1fdb46df200c61987684ee844911d3f304c51 Mon Sep 17 00:00:00 2001 From: * <8> Date: Thu, 10 Mar 2022 16:54:28 +0800 Subject: [PATCH 3/4] Match-id-977b8ef12a4b099ecca12564c3063b508f3e3b82 --- libs/horizon/src/event/customEvents/EventFactory.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/horizon/src/event/customEvents/EventFactory.ts b/libs/horizon/src/event/customEvents/EventFactory.ts index db6bfc17..3bad01d4 100644 --- a/libs/horizon/src/event/customEvents/EventFactory.ts +++ b/libs/horizon/src/event/customEvents/EventFactory.ts @@ -10,11 +10,14 @@ const uniqueKeyMap = new Map([ ['Del', 'Delete'], ]); +const noop = () => {}; // 创建普通自定义事件对象实例,和原生事件对应 export function decorateNativeEvent(customEventName, nativeEvtName, nativeEvent) { nativeEvent.isDefaultPrevented = () => nativeEvent.defaultPrevented; nativeEvent.isPropagationStopped = () => nativeEvent.cancelBubble; + // 适配React16事件api + nativeEvent.persist = noop; // custom事件自定义属性 nativeEvent.customEventName = customEventName; From bec923e83dfcaf3c01047d0dda2db9afb45707cc Mon Sep 17 00:00:00 2001 From: * <8> Date: Thu, 10 Mar 2022 17:37:08 +0800 Subject: [PATCH 4/4] Match-id-a965dbe9849e2f595a38731982d03499bc2ef956 --- libs/horizon/src/event/customEvents/EventFactory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/horizon/src/event/customEvents/EventFactory.ts b/libs/horizon/src/event/customEvents/EventFactory.ts index 3bad01d4..8ca28579 100644 --- a/libs/horizon/src/event/customEvents/EventFactory.ts +++ b/libs/horizon/src/event/customEvents/EventFactory.ts @@ -16,7 +16,7 @@ export function decorateNativeEvent(customEventName, nativeEvtName, nativeEvent) nativeEvent.isDefaultPrevented = () => nativeEvent.defaultPrevented; nativeEvent.isPropagationStopped = () => nativeEvent.cancelBubble; - // 适配React16事件api + // 适配老版本事件api nativeEvent.persist = noop; // custom事件自定义属性