From d272576087d4b1de67a6768747e168b664642c5a Mon Sep 17 00:00:00 2001 From: Bowen Tan Date: Mon, 15 Aug 2022 17:12:17 +0800 Subject: [PATCH] build(chakra): split chakra widgets and lib --- .gitignore | 4 +- packages/arco-lib/package.json | 5 +- packages/arco-lib/tsconfig.json | 1 - packages/chakra-ui-lib/package.json | 16 +++--- packages/chakra-ui-lib/src/index.ts | 64 +-------------------- packages/chakra-ui-lib/src/lib.ts | 62 ++++++++++++++++++++ packages/chakra-ui-lib/tsconfig.json | 1 - packages/chakra-ui-lib/tsup.config.ts | 11 ++++ packages/core/src/index.ts | 1 + packages/editor/src/services/EditorStore.ts | 2 +- packages/runtime/index.html | 2 +- yarn.lock | 37 ++++-------- 12 files changed, 99 insertions(+), 107 deletions(-) create mode 100644 packages/chakra-ui-lib/src/lib.ts create mode 100644 packages/chakra-ui-lib/tsup.config.ts diff --git a/.gitignore b/.gitignore index b31c4644..d600a5e1 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,6 @@ tsconfig.tsbuildinfo typings # jest test coverage -coverage \ No newline at end of file +coverage + +stats.html diff --git a/packages/arco-lib/package.json b/packages/arco-lib/package.json index a155b6de..3a255966 100644 --- a/packages/arco-lib/package.json +++ b/packages/arco-lib/package.json @@ -10,13 +10,12 @@ "type": "git", "url": "git+https://github.com/smartxworks/sunmao-ui-arco-lib.git" }, - "main": "dist/index.cjs", + "main": "dist/index.js", "module": "dist/index.mjs", "unpkg": "dist/index.global.js", "types": "dist/index.d.ts", "files": [ - "dist", - "lib" + "dist" ], "scripts": { "dev": "vite", diff --git a/packages/arco-lib/tsconfig.json b/packages/arco-lib/tsconfig.json index 3d9c1f5d..98307100 100644 --- a/packages/arco-lib/tsconfig.json +++ b/packages/arco-lib/tsconfig.json @@ -14,7 +14,6 @@ "resolveJsonModule": true, "isolatedModules": true, "noEmit": false, - "emitDeclarationOnly": true, "jsx": "react-jsx", "outDir": "./lib", "baseUrl": "./", diff --git a/packages/chakra-ui-lib/package.json b/packages/chakra-ui-lib/package.json index 0ec2cfdb..85cd25e9 100644 --- a/packages/chakra-ui-lib/package.json +++ b/packages/chakra-ui-lib/package.json @@ -13,20 +13,18 @@ "url": "git+https://github.com/smartxworks/sunmao-ui.git" }, "main": "dist/index.js", - "module": "dist/esm/index.js", - "unpkg": "dist/iife/index.js", - "types": "lib/index.d.ts", + "module": "dist/index.mjs", + "unpkg": "dist/index.global.js", + "types": "dist/index.d.ts", "files": [ - "dist", - "lib" + "dist" ], "scripts": { "dev": "vite", "test": "jest", - "build": "tsup src/index.ts src/widgets/index.ts --format cjs,esm,iife --legacy-output --inject ./react-import.js --clean --no-splitting --sourcemap", - "typings": "tsc --emitDeclarationOnly", + "build": "tsup", "lint": "eslint src --ext .ts", - "prepublish": "npm run build && npm run typings" + "prepublish": "npm run build" }, "dependencies": { "@chakra-ui/icons": "^1.0.15", @@ -49,7 +47,7 @@ "@vitejs/plugin-react": "^1.0.1", "babel-jest": "^27.1.0", "jest": "^27.1.0", - "tsup": "^5.5.0", + "tsup": "^5.11.11", "typescript": "^4.5.0", "vite": "^2.6.13" }, diff --git a/packages/chakra-ui-lib/src/index.ts b/packages/chakra-ui-lib/src/index.ts index bfdce0eb..7d4258ca 100644 --- a/packages/chakra-ui-lib/src/index.ts +++ b/packages/chakra-ui-lib/src/index.ts @@ -1,64 +1,2 @@ -import { SunmaoLib } from '@sunmao-ui/runtime'; -import ChakraUIRoot from './components/Root'; -import ChakraUIButton from './components/Button'; -import ChakraUITabs from './components/Tabs'; -import ChakraUITable from './components/Table'; -import ChakraUIInput from './components/Input'; -import ChakraUIBox from './components/Box'; -import ChakraUIDivider from './components/Divider'; -import ChakraUIFormControl from './components/Form/FormControl'; -import ChakraUIForm from './components/Form/Form'; -import ChakraUIKbd from './components/Kbd'; -import ChakraUIList from './components/List'; -import ChakraUILink from './components/Link'; -import ChakraUINumberInput from './components/NumberInput'; -import ChakraUIMultiSelect from './components/MultiSelect'; -import ChakraUICheckboxGroup from './components/CheckboxGroup'; -import ChakraUICheckbox from './components/Checkbox'; -import ChakraUIStack from './components/Stack'; -import ChakraUISwitch from './components/Switch'; -import ChakraUITooltip from './components/Tooltip'; -import ChakraUIHStack from './components/HStack'; -import ChakraUIVStack from './components/VStack'; -import ChakraUIImage from './components/Image'; -import ChakraUIDialog from './components/Dialog'; -import ChakraUISelect from './components/Select'; -import ChakraUIRadioGroup from './components/RadioGroup'; -import ChakraUIRadio from './components/Radio'; -import ChakraUIToastUtilMethodFactory from './components/Types/Toast'; - -export const sunmaoChakraUILib: SunmaoLib = { - components: [ - ChakraUIRoot, - ChakraUIButton, - ChakraUITabs, - ChakraUITable, - ChakraUIInput, - ChakraUIBox, - ChakraUIDivider, - ChakraUIFormControl, - ChakraUIForm, - ChakraUIKbd, - ChakraUIList, - ChakraUILink, - ChakraUIMultiSelect, - ChakraUINumberInput, - ChakraUICheckbox, - ChakraUICheckboxGroup, - ChakraUIStack, - ChakraUISwitch, - ChakraUITooltip, - ChakraUIHStack, - ChakraUIVStack, - ChakraUIImage, - ChakraUIDialog, - ChakraUISelect, - ChakraUIRadioGroup, - ChakraUIRadio, - ], - traits: [], - modules: [], - utilMethods: [ChakraUIToastUtilMethodFactory], -}; - +export { sunmaoChakraUILib } from './lib'; export { widgets } from './widgets'; diff --git a/packages/chakra-ui-lib/src/lib.ts b/packages/chakra-ui-lib/src/lib.ts new file mode 100644 index 00000000..bd59cd7e --- /dev/null +++ b/packages/chakra-ui-lib/src/lib.ts @@ -0,0 +1,62 @@ +import { SunmaoLib } from '@sunmao-ui/runtime'; +import ChakraUIRoot from './components/Root'; +import ChakraUIButton from './components/Button'; +import ChakraUITabs from './components/Tabs'; +import ChakraUITable from './components/Table'; +import ChakraUIInput from './components/Input'; +import ChakraUIBox from './components/Box'; +import ChakraUIDivider from './components/Divider'; +import ChakraUIFormControl from './components/Form/FormControl'; +import ChakraUIForm from './components/Form/Form'; +import ChakraUIKbd from './components/Kbd'; +import ChakraUIList from './components/List'; +import ChakraUILink from './components/Link'; +import ChakraUINumberInput from './components/NumberInput'; +import ChakraUIMultiSelect from './components/MultiSelect'; +import ChakraUICheckboxGroup from './components/CheckboxGroup'; +import ChakraUICheckbox from './components/Checkbox'; +import ChakraUIStack from './components/Stack'; +import ChakraUISwitch from './components/Switch'; +import ChakraUITooltip from './components/Tooltip'; +import ChakraUIHStack from './components/HStack'; +import ChakraUIVStack from './components/VStack'; +import ChakraUIImage from './components/Image'; +import ChakraUIDialog from './components/Dialog'; +import ChakraUISelect from './components/Select'; +import ChakraUIRadioGroup from './components/RadioGroup'; +import ChakraUIRadio from './components/Radio'; +import ChakraUIToastUtilMethodFactory from './components/Types/Toast'; + +export const sunmaoChakraUILib: SunmaoLib = { + components: [ + ChakraUIRoot, + ChakraUIButton, + ChakraUITabs, + ChakraUITable, + ChakraUIInput, + ChakraUIBox, + ChakraUIDivider, + ChakraUIFormControl, + ChakraUIForm, + ChakraUIKbd, + ChakraUIList, + ChakraUILink, + ChakraUIMultiSelect, + ChakraUINumberInput, + ChakraUICheckbox, + ChakraUICheckboxGroup, + ChakraUIStack, + ChakraUISwitch, + ChakraUITooltip, + ChakraUIHStack, + ChakraUIVStack, + ChakraUIImage, + ChakraUIDialog, + ChakraUISelect, + ChakraUIRadioGroup, + ChakraUIRadio, + ], + traits: [], + modules: [], + utilMethods: [ChakraUIToastUtilMethodFactory], +}; diff --git a/packages/chakra-ui-lib/tsconfig.json b/packages/chakra-ui-lib/tsconfig.json index 1a373082..8947ba96 100644 --- a/packages/chakra-ui-lib/tsconfig.json +++ b/packages/chakra-ui-lib/tsconfig.json @@ -1,7 +1,6 @@ { "extends": "../../config/tsconfig.base.json", "compilerOptions": { - "composite": true, "target": "ES6", "lib": ["DOM", "DOM.Iterable", "ESNext"], "outDir": "./lib", diff --git a/packages/chakra-ui-lib/tsup.config.ts b/packages/chakra-ui-lib/tsup.config.ts new file mode 100644 index 00000000..b2532064 --- /dev/null +++ b/packages/chakra-ui-lib/tsup.config.ts @@ -0,0 +1,11 @@ +import { defineConfig } from 'tsup'; + +export default defineConfig({ + entry: ['src/lib.ts', 'src/index.ts', 'src/widgets/index.ts'], + format: ['cjs', 'esm', 'iife'], + inject: ['./react-import.js'], + splitting: false, + sourcemap: true, + clean: true, + dts: true, +}); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index efa3b6e8..e00a5676 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -8,3 +8,4 @@ export * from './version'; export * from './slot'; export * from './utilMethod'; export * from './schema'; +export * from './metadata'; diff --git a/packages/editor/src/services/EditorStore.ts b/packages/editor/src/services/EditorStore.ts index d80dc0ee..c4f0d79d 100644 --- a/packages/editor/src/services/EditorStore.ts +++ b/packages/editor/src/services/EditorStore.ts @@ -17,7 +17,7 @@ import { CORE_VERSION, CoreComponentName } from '@sunmao-ui/shared'; import { isEqual } from 'lodash'; import { resolveApplicationComponents } from '../utils/resolveApplicationComponents'; import { AppModelManager } from '../operations/AppModelManager'; -import type { Metadata } from '@sunmao-ui/core/lib/metadata'; +import type { Metadata } from '@sunmao-ui/core'; type EditingTarget = { kind: 'app' | 'module'; diff --git a/packages/runtime/index.html b/packages/runtime/index.html index 4341016c..ac400e1c 100644 --- a/packages/runtime/index.html +++ b/packages/runtime/index.html @@ -14,7 +14,7 @@ import { initSunmaoUI } from './src'; import { ChakraProvider } from '@chakra-ui/react'; import { sunmaoChakraUILib } from '@sunmao-ui/chakra-ui-lib'; - import { ArcoDesignLib } from '@sunmao-ui/arco-lib'; + import { ArcoDesignLib } from '@sunmao-ui/arco-lib/lib'; import examples from '@example.json'; import '@arco-design/web-react/dist/css/arco.css'; diff --git a/yarn.lock b/yarn.lock index df104809..14fc9df2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4220,6 +4220,13 @@ use-debounce "^6.0.1" web-vitals "^0.2.2" +"@originjs/vite-plugin-commonjs@^1.0.3": + version "1.0.3" + resolved "https://registry.yarnpkg.com/@originjs/vite-plugin-commonjs/-/vite-plugin-commonjs-1.0.3.tgz#2e3fb11ec78847da9422b79c103953f94d667f09" + integrity sha512-KuEXeGPptM2lyxdIEJ4R11+5ztipHoE7hy8ClZt3PYaOVQ/pyngd2alaSrPnwyFeOW1UagRBaQ752aA1dTMdOQ== + dependencies: + esbuild "^0.14.14" + "@popperjs/core@2.4.4": version "2.4.4" resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.4.4.tgz#11d5db19bd178936ec89cd84519c4de439574398" @@ -5571,11 +5578,6 @@ cac@^6.7.12: resolved "https://registry.npmjs.org/cac/-/cac-6.7.12.tgz" integrity sha512-rM7E2ygtMkJqD9c7WnFU6fruFcN3xe4FM5yUmgxhZzIKJk4uHl9U/fhwdajGFQbQuv43FAUo1Fe8gX/oIKDeSA== -cac@^6.7.2: - version "6.7.11" - resolved "https://registry.npmjs.org/cac/-/cac-6.7.11.tgz" - integrity sha512-m4xrA2MKfid6uDV2j2+0mXrtPGxlvAW0y+7Gnn2P8WVMSG+4e4tcoYX++94ZPblPfpBccJ5e7HvKdghlX5yiDA== - cacache@^15.0.5, cacache@^15.2.0: version "15.3.0" resolved "https://registry.npmjs.org/cacache/-/cacache-15.3.0.tgz" @@ -7112,7 +7114,7 @@ esbuild-windows-arm64@0.14.7: resolved "https://registry.yarnpkg.com/esbuild-windows-arm64/-/esbuild-windows-arm64-0.14.7.tgz#ecfd9ac289606f26760c4f737caaeeadfff3cfe3" integrity sha512-eOs1eSivOqN7cFiRIukEruWhaCf75V0N8P0zP7dh44LIhLl8y6/z++vv9qQVbkBm5/D7M7LfCfCTmt1f1wHOCw== -esbuild@^0.13.2, esbuild@^0.13.4: +esbuild@^0.13.2: version "0.13.12" resolved "https://registry.npmjs.org/esbuild/-/esbuild-0.13.12.tgz" integrity sha512-vTKKUt+yoz61U/BbrnmlG9XIjwpdIxmHB8DlPR0AAW6OdS+nBQBci6LUHU2q9WbBobMEIQxxDpKbkmOGYvxsow== @@ -11792,7 +11794,7 @@ rollup@^2.42.3: optionalDependencies: fsevents "~2.3.2" -rollup@^2.56.1, rollup@^2.57.0: +rollup@^2.57.0: version "2.59.0" resolved "https://registry.npmjs.org/rollup/-/rollup-2.59.0.tgz" integrity sha512-l7s90JQhCQ6JyZjKgo7Lq1dKh2RxatOM+Jr6a9F7WbS9WgKbocyUSeLmZl8evAse7y96Ae98L2k1cBOwWD8nHw== @@ -12369,7 +12371,7 @@ stylis@^4.0.10: resolved "https://registry.npmjs.org/stylis/-/stylis-4.0.10.tgz" integrity sha512-m3k+dk7QeJw660eIKRRn3xPF6uuvHs/FFzjX3HQ5ove0qYsiygoAhwn5a3IYKaZPo5LrYD0rfVmtv1gNY1uYwg== -sucrase@^3.20.1, sucrase@^3.20.3: +sucrase@^3.20.3: version "3.20.3" resolved "https://registry.npmjs.org/sucrase/-/sucrase-3.20.3.tgz" integrity sha512-azqwq0/Bs6RzLAdb4dXxsCgMtAaD2hzmUr4UhSfsxO46JFPAwMnnb441B/qsudZiS6Ylea3JXZe3Q497lsgXzQ== @@ -12742,25 +12744,6 @@ tsup@^5.11.11: sucrase "^3.20.3" tree-kill "^1.2.2" -tsup@^5.5.0: - version "5.5.0" - resolved "https://registry.npmjs.org/tsup/-/tsup-5.5.0.tgz" - integrity sha512-khx/80b15RxK00UWqWlaizvrwO8kDZFBM0AbORKfjwKxxmzLuu35ceubzLg3wJgZ21E0BCLrCainh4zzJYImoA== - dependencies: - cac "^6.7.2" - chalk "^4.1.0" - chokidar "^3.5.1" - debug "^4.3.1" - esbuild "^0.13.4" - execa "^5.0.0" - globby "^11.0.3" - joycon "^3.0.1" - postcss-load-config "^3.0.1" - resolve-from "^5.0.0" - rollup "^2.56.1" - sucrase "^3.20.1" - tree-kill "^1.2.2" - tsutils@^3.21.0: version "3.21.0" resolved "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz"