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..d8d63078 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,27 @@ # horizon - ## 工程编译: -1、npm install -2、npm run build +Horizon采用monorepo方式管理项目,意思是在版本控制系统的单个代码库里包含了许多项目的代码 -全局单元测试 npm run test +monorepo工具采用npm workspaces **(npm版本需要大于7.x)** +### 工程命令 +#### 安装 +```shell +npm install +``` +> 需要使用npm7.x以后版本安装,monorepo的依赖才能正确安装到node_modules +#### 打包 +```shell +npm run build +``` +#### 全局单元测试 +```shell +npm 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/libs/horizon/src/event/customEvents/EventFactory.ts b/libs/horizon/src/event/customEvents/EventFactory.ts index db6bfc17..8ca28579 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; + // 适配老版本事件api + nativeEvent.persist = noop; // custom事件自定义属性 nativeEvent.customEventName = customEventName; 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 2091aad8..7b933fc4 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", @@ -51,17 +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", - "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", "ejs": "^3.1.6", "error-stack-parser": "^2.0.6", @@ -75,72 +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", - "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", "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", - "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", - "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" - }, - "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" + "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' } ]