From ea68846de7b437aff46f3d7ec381da93db728010 Mon Sep 17 00:00:00 2001 From: * <8> Date: Mon, 7 Mar 2022 17:13:00 +0800 Subject: [PATCH] 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" } }