From 8750f5b7dea6cd6a3cab143a3415df42c05e920d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E7=86=B1?= Date: Mon, 15 Apr 2024 19:22:01 +0800 Subject: [PATCH 1/2] feat: add support for opening .xlsx files --- eslint.config.js | 1 + package.json | 20 +++- pnpm-lock.yaml | 211 ++++++++++++++++++++++----------------- src/main.ts | 5 +- src/mock/exchange.wasm | 0 src/mock/wasm_exec.js | 0 src/modals/chooseType.ts | 4 +- src/univer/docs.ts | 4 +- src/univer/sheets.ts | 6 +- src/utils/createFile.ts | 4 +- src/utils/snapshot.ts | 118 ++++++++++++++++++++++ src/views/udoc.ts | 6 +- src/views/usheet.ts | 4 +- src/views/xlsx.ts | 119 ++++++++++++++++++++++ tsconfig.json | 9 -- vite.config.ts | 5 +- 16 files changed, 391 insertions(+), 125 deletions(-) create mode 100644 src/mock/exchange.wasm create mode 100644 src/mock/wasm_exec.js create mode 100644 src/utils/snapshot.ts create mode 100644 src/views/xlsx.ts diff --git a/eslint.config.js b/eslint.config.js index 1e0ada5..e9015b0 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -5,5 +5,6 @@ export default antfu({ }, { rules: { 'no-new': 'off', + 'ts/ban-ts-comment': 'off', }, }) diff --git a/package.json b/package.json index d95cc58..9178b9c 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "@univerjs/engine-render": "^0.1.7", "@univerjs/facade": "^0.1.7", "@univerjs/find-replace": "^0.1.7", + "@univerjs/protocol": "^0.1.17", "@univerjs/rpc": "^0.1.7", "@univerjs/sheets": "^0.1.7", "@univerjs/sheets-conditional-formatting-ui": "^0.1.7", @@ -42,19 +43,28 @@ "@univerjs/ui": "^0.1.7", "defu": "^6.1.4" }, + "optionalDependencies": { + "@univerjs-pro/exchange-wasm": "^1.0.3" + }, "devDependencies": { - "@antfu/eslint-config": "^2.8.3", + "@antfu/eslint-config": "^2.13.3", "@release-it/conventional-changelog": "^8.0.1", - "@types/node": "^20.11.28", + "@types/node": "^20.12.7", "@univerjs/vite-plugin": "^0.3.2", "builtin-modules": "^3.3.0", "dotenv": "^16.4.5", "eslint": "^8.57.0", "lint-staged": "^15.2.2", "obsidian": "1.5.7-1", - "release-it": "^17.1.1", + "release-it": "^17.2.0", "simple-git-hooks": "^2.11.1", - "typescript": "^5.4.2", - "vite": "^5.1.6" + "typescript": "^5.4.5", + "vite": "^5.2.8" + }, + "simple-git-hooks": { + "pre-commit": "pnpm lint-staged" + }, + "lint-staged": { + "*": "eslint --fix" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 24403b1..92dadd0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,6 +32,9 @@ dependencies: '@univerjs/find-replace': specifier: ^0.1.7 version: 0.1.7(@univerjs/core@0.1.7)(@univerjs/design@0.1.7)(@univerjs/engine-render@0.1.7)(@univerjs/ui@0.1.7)(@wendellhu/redi@0.13.0)(react-dom@18.2.0)(react@18.2.0)(rxjs@7.8.1) + '@univerjs/protocol': + specifier: ^0.1.17 + version: 0.1.17(@grpc/grpc-js@1.10.6)(rxjs@7.8.1) '@univerjs/rpc': specifier: ^0.1.7 version: 0.1.7(@univerjs/core@0.1.7)(@wendellhu/redi@0.13.0)(rxjs@7.8.1) @@ -66,15 +69,20 @@ dependencies: specifier: ^6.1.4 version: 6.1.4 +optionalDependencies: + '@univerjs-pro/exchange-wasm': + specifier: ^1.0.3 + version: 1.0.3 + devDependencies: '@antfu/eslint-config': - specifier: ^2.8.3 + specifier: ^2.13.3 version: 2.13.3(@vue/compiler-sfc@3.4.21)(eslint@8.57.0)(typescript@5.4.5) '@release-it/conventional-changelog': specifier: ^8.0.1 - version: 8.0.1(release-it@17.1.1) + version: 8.0.1(release-it@17.2.0) '@types/node': - specifier: ^20.11.28 + specifier: ^20.12.7 version: 20.12.7 '@univerjs/vite-plugin': specifier: ^0.3.2 @@ -95,16 +103,16 @@ devDependencies: specifier: 1.5.7-1 version: 1.5.7-1(@codemirror/state@6.4.1)(@codemirror/view@6.26.3) release-it: - specifier: ^17.1.1 - version: 17.1.1(typescript@5.4.5) + specifier: ^17.2.0 + version: 17.2.0(typescript@5.4.5) simple-git-hooks: specifier: ^2.11.1 version: 2.11.1 typescript: - specifier: ^5.4.2 + specifier: ^5.4.5 version: 5.4.5 vite: - specifier: ^5.1.6 + specifier: ^5.2.8 version: 5.2.8(@types/node@20.12.7) packages: @@ -172,14 +180,14 @@ packages: eslint-plugin-jsdoc: 48.2.3(eslint@8.57.0) eslint-plugin-jsonc: 2.15.1(eslint@8.57.0) eslint-plugin-markdown: 4.0.1(eslint@8.57.0) - eslint-plugin-n: 17.2.0(eslint@8.57.0) + eslint-plugin-n: 17.2.1(eslint@8.57.0) eslint-plugin-no-only-tests: 3.1.0 - eslint-plugin-perfectionist: 2.8.0(eslint@8.57.0)(typescript@5.4.5)(vue-eslint-parser@9.4.2) + eslint-plugin-perfectionist: 2.9.0(eslint@8.57.0)(typescript@5.4.5)(vue-eslint-parser@9.4.2) eslint-plugin-toml: 0.11.0(eslint@8.57.0) eslint-plugin-unicorn: 52.0.0(eslint@8.57.0) eslint-plugin-unused-imports: 3.1.0(@typescript-eslint/eslint-plugin@7.6.0)(eslint@8.57.0) - eslint-plugin-vitest: 0.5.1(@typescript-eslint/eslint-plugin@7.6.0)(eslint@8.57.0)(typescript@5.4.5) - eslint-plugin-vue: 9.24.1(eslint@8.57.0) + eslint-plugin-vitest: 0.5.3(@typescript-eslint/eslint-plugin@7.6.0)(eslint@8.57.0)(typescript@5.4.5) + eslint-plugin-vue: 9.25.0(eslint@8.57.0) eslint-plugin-yml: 1.14.0(eslint@8.57.0) eslint-processor-vue-blocks: 0.1.1(@vue/compiler-sfc@3.4.21)(eslint@8.57.0) globals: 15.0.0 @@ -718,8 +726,8 @@ packages: universal-user-agent: 6.0.1 dev: true - /@octokit/rest@20.0.2: - resolution: {integrity: sha512-Ux8NDgEraQ/DMAU1PlAohyfBBXDwhnX2j33Z1nJNziqAfHi70PuxkFYIcIt8aIAxtRE7KVuKp8lSR8pA0J5iOQ==} + /@octokit/rest@20.1.0: + resolution: {integrity: sha512-STVO3itHQLrp80lvcYB2UIKoeil5Ctsgd2s1AM+du3HqZIR35ZH7WE9HLwUOLXH0myA0y3AGNPo8gZtcgIbw0g==} engines: {node: '>= 18'} dependencies: '@octokit/core': 5.2.0 @@ -873,7 +881,7 @@ packages: react-dom: 18.2.0(react@18.2.0) dev: false - /@release-it/conventional-changelog@8.0.1(release-it@17.1.1): + /@release-it/conventional-changelog@8.0.1(release-it@17.2.0): resolution: {integrity: sha512-pwc9jaBYDaSX5TXw6rEnPfqDkKJN2sFBhYpON1kBi9T3sA9EOBncC4ed0Bv3L1ciNb6eqEJXPfp+tQMqVlv/eg==} engines: {node: '>=18'} peerDependencies: @@ -882,124 +890,132 @@ packages: concat-stream: 2.0.0 conventional-changelog: 5.1.0 conventional-recommended-bump: 9.0.0 - release-it: 17.1.1(typescript@5.4.5) + release-it: 17.2.0(typescript@5.4.5) semver: 7.6.0 dev: true - /@rollup/rollup-android-arm-eabi@4.14.2: - resolution: {integrity: sha512-ahxSgCkAEk+P/AVO0vYr7DxOD3CwAQrT0Go9BJyGQ9Ef0QxVOfjDZMiF4Y2s3mLyPrjonchIMH/tbWHucJMykQ==} + /@rollup/rollup-android-arm-eabi@4.14.3: + resolution: {integrity: sha512-X9alQ3XM6I9IlSlmC8ddAvMSyG1WuHk5oUnXGw+yUBs3BFoTizmG1La/Gr8fVJvDWAq+zlYTZ9DBgrlKRVY06g==} cpu: [arm] os: [android] requiresBuild: true dev: true optional: true - /@rollup/rollup-android-arm64@4.14.2: - resolution: {integrity: sha512-lAarIdxZWbFSHFSDao9+I/F5jDaKyCqAPMq5HqnfpBw8dKDiCaaqM0lq5h1pQTLeIqueeay4PieGR5jGZMWprw==} + /@rollup/rollup-android-arm64@4.14.3: + resolution: {integrity: sha512-eQK5JIi+POhFpzk+LnjKIy4Ks+pwJ+NXmPxOCSvOKSNRPONzKuUvWE+P9JxGZVxrtzm6BAYMaL50FFuPe0oWMQ==} cpu: [arm64] os: [android] requiresBuild: true dev: true optional: true - /@rollup/rollup-darwin-arm64@4.14.2: - resolution: {integrity: sha512-SWsr8zEUk82KSqquIMgZEg2GE5mCSfr9sE/thDROkX6pb3QQWPp8Vw8zOq2GyxZ2t0XoSIUlvHDkrf5Gmf7x3Q==} + /@rollup/rollup-darwin-arm64@4.14.3: + resolution: {integrity: sha512-Od4vE6f6CTT53yM1jgcLqNfItTsLt5zE46fdPaEmeFHvPs5SjZYlLpHrSiHEKR1+HdRfxuzXHjDOIxQyC3ptBA==} cpu: [arm64] os: [darwin] requiresBuild: true dev: true optional: true - /@rollup/rollup-darwin-x64@4.14.2: - resolution: {integrity: sha512-o/HAIrQq0jIxJAhgtIvV5FWviYK4WB0WwV91SLUnsliw1lSAoLsmgEEgRWzDguAFeUEUUoIWXiJrPqU7vGiVkA==} + /@rollup/rollup-darwin-x64@4.14.3: + resolution: {integrity: sha512-0IMAO21axJeNIrvS9lSe/PGthc8ZUS+zC53O0VhF5gMxfmcKAP4ESkKOCwEi6u2asUrt4mQv2rjY8QseIEb1aw==} cpu: [x64] os: [darwin] requiresBuild: true dev: true optional: true - /@rollup/rollup-linux-arm-gnueabihf@4.14.2: - resolution: {integrity: sha512-nwlJ65UY9eGq91cBi6VyDfArUJSKOYt5dJQBq8xyLhvS23qO+4Nr/RreibFHjP6t+5ap2ohZrUJcHv5zk5ju/g==} + /@rollup/rollup-linux-arm-gnueabihf@4.14.3: + resolution: {integrity: sha512-ge2DC7tHRHa3caVEoSbPRJpq7azhG+xYsd6u2MEnJ6XzPSzQsTKyXvh6iWjXRf7Rt9ykIUWHtl0Uz3T6yXPpKw==} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-arm-musleabihf@4.14.3: + resolution: {integrity: sha512-ljcuiDI4V3ySuc7eSk4lQ9wU8J8r8KrOUvB2U+TtK0TiW6OFDmJ+DdIjjwZHIw9CNxzbmXY39wwpzYuFDwNXuw==} cpu: [arm] os: [linux] requiresBuild: true dev: true optional: true - /@rollup/rollup-linux-arm64-gnu@4.14.2: - resolution: {integrity: sha512-Pg5TxxO2IVlMj79+c/9G0LREC9SY3HM+pfAwX7zj5/cAuwrbfj2Wv9JbMHIdPCfQpYsI4g9mE+2Bw/3aeSs2rQ==} + /@rollup/rollup-linux-arm64-gnu@4.14.3: + resolution: {integrity: sha512-Eci2us9VTHm1eSyn5/eEpaC7eP/mp5n46gTRB3Aar3BgSvDQGJZuicyq6TsH4HngNBgVqC5sDYxOzTExSU+NjA==} cpu: [arm64] os: [linux] requiresBuild: true dev: true optional: true - /@rollup/rollup-linux-arm64-musl@4.14.2: - resolution: {integrity: sha512-cAOTjGNm84gc6tS02D1EXtG7tDRsVSDTBVXOLbj31DkwfZwgTPYZ6aafSU7rD/4R2a34JOwlF9fQayuTSkoclA==} + /@rollup/rollup-linux-arm64-musl@4.14.3: + resolution: {integrity: sha512-UrBoMLCq4E92/LCqlh+blpqMz5h1tJttPIniwUgOFJyjWI1qrtrDhhpHPuFxULlUmjFHfloWdixtDhSxJt5iKw==} cpu: [arm64] os: [linux] requiresBuild: true dev: true optional: true - /@rollup/rollup-linux-powerpc64le-gnu@4.14.2: - resolution: {integrity: sha512-4RyT6v1kXb7C0fn6zV33rvaX05P0zHoNzaXI/5oFHklfKm602j+N4mn2YvoezQViRLPnxP8M1NaY4s/5kXO5cw==} + /@rollup/rollup-linux-powerpc64le-gnu@4.14.3: + resolution: {integrity: sha512-5aRjvsS8q1nWN8AoRfrq5+9IflC3P1leMoy4r2WjXyFqf3qcqsxRCfxtZIV58tCxd+Yv7WELPcO9mY9aeQyAmw==} cpu: [ppc64] os: [linux] requiresBuild: true dev: true optional: true - /@rollup/rollup-linux-riscv64-gnu@4.14.2: - resolution: {integrity: sha512-KNUH6jC/vRGAKSorySTyc/yRYlCwN/5pnMjXylfBniwtJx5O7X17KG/0efj8XM3TZU7raYRXJFFReOzNmL1n1w==} + /@rollup/rollup-linux-riscv64-gnu@4.14.3: + resolution: {integrity: sha512-sk/Qh1j2/RJSX7FhEpJn8n0ndxy/uf0kI/9Zc4b1ELhqULVdTfN6HL31CDaTChiBAOgLcsJ1sgVZjWv8XNEsAQ==} cpu: [riscv64] os: [linux] requiresBuild: true dev: true optional: true - /@rollup/rollup-linux-s390x-gnu@4.14.2: - resolution: {integrity: sha512-xPV4y73IBEXToNPa3h5lbgXOi/v0NcvKxU0xejiFw6DtIYQqOTMhZ2DN18/HrrP0PmiL3rGtRG9gz1QE8vFKXQ==} + /@rollup/rollup-linux-s390x-gnu@4.14.3: + resolution: {integrity: sha512-jOO/PEaDitOmY9TgkxF/TQIjXySQe5KVYB57H/8LRP/ux0ZoO8cSHCX17asMSv3ruwslXW/TLBcxyaUzGRHcqg==} cpu: [s390x] os: [linux] requiresBuild: true dev: true optional: true - /@rollup/rollup-linux-x64-gnu@4.14.2: - resolution: {integrity: sha512-QBhtr07iFGmF9egrPOWyO5wciwgtzKkYPNLVCFZTmr4TWmY0oY2Dm/bmhHjKRwZoGiaKdNcKhFtUMBKvlchH+Q==} + /@rollup/rollup-linux-x64-gnu@4.14.3: + resolution: {integrity: sha512-8ybV4Xjy59xLMyWo3GCfEGqtKV5M5gCSrZlxkPGvEPCGDLNla7v48S662HSGwRd6/2cSneMQWiv+QzcttLrrOA==} cpu: [x64] os: [linux] requiresBuild: true dev: true optional: true - /@rollup/rollup-linux-x64-musl@4.14.2: - resolution: {integrity: sha512-8zfsQRQGH23O6qazZSFY5jP5gt4cFvRuKTpuBsC1ZnSWxV8ZKQpPqOZIUtdfMOugCcBvFGRa1pDC/tkf19EgBw==} + /@rollup/rollup-linux-x64-musl@4.14.3: + resolution: {integrity: sha512-s+xf1I46trOY10OqAtZ5Rm6lzHre/UiLA1J2uOhCFXWkbZrJRkYBPO6FhvGfHmdtQ3Bx793MNa7LvoWFAm93bg==} cpu: [x64] os: [linux] requiresBuild: true dev: true optional: true - /@rollup/rollup-win32-arm64-msvc@4.14.2: - resolution: {integrity: sha512-H4s8UjgkPnlChl6JF5empNvFHp77Jx+Wfy2EtmYPe9G22XV+PMuCinZVHurNe8ggtwoaohxARJZbaH/3xjB/FA==} + /@rollup/rollup-win32-arm64-msvc@4.14.3: + resolution: {integrity: sha512-+4h2WrGOYsOumDQ5S2sYNyhVfrue+9tc9XcLWLh+Kw3UOxAvrfOrSMFon60KspcDdytkNDh7K2Vs6eMaYImAZg==} cpu: [arm64] os: [win32] requiresBuild: true dev: true optional: true - /@rollup/rollup-win32-ia32-msvc@4.14.2: - resolution: {integrity: sha512-djqpAjm/i8erWYF0K6UY4kRO3X5+T4TypIqw60Q8MTqSBaQNpNXDhxdjpZ3ikgb+wn99svA7jxcXpiyg9MUsdw==} + /@rollup/rollup-win32-ia32-msvc@4.14.3: + resolution: {integrity: sha512-T1l7y/bCeL/kUwh9OD4PQT4aM7Bq43vX05htPJJ46RTI4r5KNt6qJRzAfNfM+OYMNEVBWQzR2Gyk+FXLZfogGw==} cpu: [ia32] os: [win32] requiresBuild: true dev: true optional: true - /@rollup/rollup-win32-x64-msvc@4.14.2: - resolution: {integrity: sha512-teAqzLT0yTYZa8ZP7zhFKEx4cotS8Tkk5XiqNMJhD4CpaWB1BHARE4Qy+RzwnXvSAYv+Q3jAqCVBS+PS+Yee8Q==} + /@rollup/rollup-win32-x64-msvc@4.14.3: + resolution: {integrity: sha512-/BypzV0H1y1HzgYpxqRaXGBRqfodgoBBCcsrujT6QRcakDQdfU+Lq9PENPh5jB4I44YWq+0C2eHsHya+nZY1sA==} cpu: [x64] os: [win32] requiresBuild: true @@ -1351,6 +1367,12 @@ packages: resolution: {integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==} dev: true + /@univerjs-pro/exchange-wasm@1.0.3: + resolution: {integrity: sha512-qpchL9g6lVmFBNbac4CqxLK3cZ9DaPkGODD+TU8IIPA7i22gksudBn/Jn7Si719fLE/R7xTjP0bEjXKpYyv/uA==} + requiresBuild: true + dev: false + optional: true + /@univerjs/core@0.1.7(@grpc/grpc-js@1.10.6)(@wendellhu/redi@0.13.0)(rxjs@7.8.1): resolution: {integrity: sha512-5JBGCN7WtrB5XwBYLL1x3oIZXkdYqpN9r1hs3Fm3LXdTZ+K2kN0Nk2710IaYVKaA5rafHBeOINiWwK1eLMc1rg==} engines: {node: '>=16.0.0', npm: '>=8.0.0'} @@ -2211,8 +2233,8 @@ packages: engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} hasBin: true dependencies: - caniuse-lite: 1.0.30001609 - electron-to-chromium: 1.4.735 + caniuse-lite: 1.0.30001610 + electron-to-chromium: 1.4.736 node-releases: 2.0.14 update-browserslist-db: 1.0.13(browserslist@4.23.0) dev: true @@ -2279,8 +2301,8 @@ packages: engines: {node: '>=14.16'} dev: true - /caniuse-lite@1.0.30001609: - resolution: {integrity: sha512-JFPQs34lHKx1B5t1EpQpWH4c+29zIyn/haGsbpfq3suuV9v56enjFt23zqijxGTMwy1p/4H2tjnQMY+p1WoAyA==} + /caniuse-lite@1.0.30001610: + resolution: {integrity: sha512-QFutAY4NgaelojVMjY63o6XlZyORPaLfyMnsl3HgnWdJUcX6K0oaJymHjH8PT5Gk7sTm8rvC/c5COUQKXqmOMA==} dev: true /chalk@2.4.2: @@ -2854,8 +2876,8 @@ packages: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} dev: true - /electron-to-chromium@1.4.735: - resolution: {integrity: sha512-pkYpvwg8VyOTQAeBqZ7jsmpCjko1Qc6We1ZtZCjRyYbT5v4AIUKDy5cQTRotQlSSZmMr8jqpEt6JtOj5k7lR7A==} + /electron-to-chromium@1.4.736: + resolution: {integrity: sha512-Rer6wc3ynLelKNM4lOCg7/zPQj8tPOCB2hzD32PX9wd3hgRRi9MxEbmkFCokzcEhRVMiOVLjnL9ig9cefJ+6+Q==} dev: true /emoji-regex@10.3.0: @@ -3203,8 +3225,8 @@ packages: - supports-color dev: true - /eslint-plugin-n@17.2.0(eslint@8.57.0): - resolution: {integrity: sha512-XBkFQxjTFKy9oc925ezHcDoZ8VLdGfxRkdZf0poR4TjC+zvm28pG2Tc7ZZpD1/UxSAzbw6Zz0WpnpUX3KruAAA==} + /eslint-plugin-n@17.2.1(eslint@8.57.0): + resolution: {integrity: sha512-uW1+df2bo06kR7ix6nB614RUlvjRPrYxlaX832O6e1MCJp4V7YozEdvMgCYuvn4ltnjPu1FVYhQ2KRrmTNoJfg==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} peerDependencies: eslint: '>=8.23.0' @@ -3225,8 +3247,8 @@ packages: engines: {node: '>=5.0.0'} dev: true - /eslint-plugin-perfectionist@2.8.0(eslint@8.57.0)(typescript@5.4.5)(vue-eslint-parser@9.4.2): - resolution: {integrity: sha512-XBjQ4ctU1rOzQ4bFJoUowe8XdsIIz42JqNrouFlae1TO78HjoyYBaRP8+gAHDDQCSdHY10pbChyzlJeBA6D51w==} + /eslint-plugin-perfectionist@2.9.0(eslint@8.57.0)(typescript@5.4.5)(vue-eslint-parser@9.4.2): + resolution: {integrity: sha512-ipFtDrqtF99qVVo+FE1fo6aHyLLp7hg6PNGfzY5KxQjcl0XCbyEFvjtR1NfkHDTN9rdFeEDxg59LLOv3VOAHAw==} peerDependencies: astro-eslint-parser: ^0.16.0 eslint: '>=8.0.0' @@ -3310,8 +3332,8 @@ packages: eslint-rule-composer: 0.3.0 dev: true - /eslint-plugin-vitest@0.5.1(@typescript-eslint/eslint-plugin@7.6.0)(eslint@8.57.0)(typescript@5.4.5): - resolution: {integrity: sha512-g137wC+LCq2N+tfqK39Nl6Rs2N9u+zu6lWxaVgpN3wX+Kq6zSyxjPSI/ZBXUjP+qandT3z1DM5wK5IjD4XrAIw==} + /eslint-plugin-vitest@0.5.3(@typescript-eslint/eslint-plugin@7.6.0)(eslint@8.57.0)(typescript@5.4.5): + resolution: {integrity: sha512-D0iu6ppP6FmNSZP4cdhEXqyI+fuW6JwwWdECRrNymd1jiVgUmDgSvtryytonNxHQQWhGNmZM3V/qvpXttH1rRQ==} engines: {node: ^18.0.0 || >= 20.0.0} peerDependencies: '@typescript-eslint/eslint-plugin': '*' @@ -3331,8 +3353,8 @@ packages: - typescript dev: true - /eslint-plugin-vue@9.24.1(eslint@8.57.0): - resolution: {integrity: sha512-wk3SuwmS1pZdcuJlokGYEi/buDOwD6KltvhIZyOnpJ/378dcQ4zchu9PAMbbLAaydCz1iYc5AozszcOOgZIIOg==} + /eslint-plugin-vue@9.25.0(eslint@8.57.0): + resolution: {integrity: sha512-tDWlx14bVe6Bs+Nnh3IGrD+hb11kf2nukfm6jLsmJIhmiRQ1SUaksvwY9U5MvPB0pcrg0QK0xapQkfITs3RKOA==} engines: {node: ^14.17.0 || >=16.0.0} peerDependencies: eslint: ^6.2.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 @@ -4086,8 +4108,8 @@ packages: engines: {node: '>=10'} dev: true - /inquirer@9.2.14: - resolution: {integrity: sha512-4ByIMt677Iz5AvjyKrDpzaepIyMewNvDcvwpVVRZNmy9dLakVoVgdCHZXbK1SlVJra1db0JZ6XkJyHsanpdrdQ==} + /inquirer@9.2.17: + resolution: {integrity: sha512-Vr3Ia2ud5sGnioURkE69endl4SkeJcMzTF6SosKcX5GALJfId7C+JvO5ZZb6y1LOXnEofCPbwzoQ1q0e8Gaduw==} engines: {node: '>=18'} dependencies: '@ljharb/through': 2.3.13 @@ -4428,9 +4450,9 @@ packages: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} dev: true - /issue-parser@6.0.0: - resolution: {integrity: sha512-zKa/Dxq2lGsBIXQ7CUZWTHfvxPC2ej0KfO7fIPqLlHB9J2hJ7rGhZ5rilhuufylr4RXYPzJUeFjKxz305OsNlA==} - engines: {node: '>=10.13'} + /issue-parser@7.0.0: + resolution: {integrity: sha512-jgAw78HO3gs9UrKqJNQvfDj9Ouy8Mhu40fbEJ8yXff4MW8+/Fcn9iFjyWUQ6SKbX8ipPk3X5A3AyfYHRu6uVLw==} + engines: {node: ^18.17 || >=20.6.1} dependencies: lodash.capitalize: 4.2.1 lodash.escaperegexp: 4.1.2 @@ -5053,8 +5075,8 @@ packages: mimic-fn: 4.0.0 dev: true - /open@10.0.3: - resolution: {integrity: sha512-dtbI5oW7987hwC9qjJTyABldTaa19SuyJse1QboWv3b0qCcrrLNVDqBx1XgELAjh9QTVQaP/C5b1nhQebd1H2A==} + /open@10.1.0: + resolution: {integrity: sha512-mnkeQ1qP5Ue2wd+aivTD3NHd/lZ96Lu0jgf0pwktLPtx6cTZiH7tyeGRRHs0zX0rbrahXPnXlUnbeXyaBBuIaw==} engines: {node: '>=18'} dependencies: default-browser: 5.2.1 @@ -5890,13 +5912,13 @@ packages: jsesc: 0.5.0 dev: true - /release-it@17.1.1(typescript@5.4.5): - resolution: {integrity: sha512-b+4Tu2eb5f2wIdIe5E9hre0evbMQrXp/kRq0natHsHYJVqu1Bd4/h2a+swFi0faGmC3cJdB16uYR6LscG9SchQ==} - engines: {node: '>=18'} + /release-it@17.2.0(typescript@5.4.5): + resolution: {integrity: sha512-Cidaq5W4apZSpdEDQd2TJhH7GZAwfaG+ewe60p7B7+txyCHYR/T6lGvkKinJmePpdHsM0fzA05yGGXKCiHJHmA==} + engines: {node: ^18.18.0 || ^20.8.0 || ^21.0.0} hasBin: true dependencies: '@iarna/toml': 2.2.5 - '@octokit/rest': 20.0.2 + '@octokit/rest': 20.1.0 async-retry: 1.3.3 chalk: 5.3.0 cosmiconfig: 9.0.0(typescript@5.4.5) @@ -5904,14 +5926,14 @@ packages: git-url-parse: 14.0.0 globby: 14.0.1 got: 13.0.0 - inquirer: 9.2.14 + inquirer: 9.2.17 is-ci: 3.0.1 - issue-parser: 6.0.0 + issue-parser: 7.0.0 lodash: 4.17.21 mime-types: 2.1.35 new-github-release-url: 2.0.0 node-fetch: 3.3.2 - open: 10.0.3 + open: 10.1.0 ora: 8.0.1 os-name: 5.1.0 promise.allsettled: 1.0.7 @@ -5920,7 +5942,7 @@ packages: shelljs: 0.8.5 update-notifier: 7.0.0 url-join: 5.0.0 - wildcard-match: 5.1.2 + wildcard-match: 5.1.3 yargs-parser: 21.1.1 transitivePeerDependencies: - supports-color @@ -6001,28 +6023,29 @@ packages: glob: 7.2.3 dev: true - /rollup@4.14.2: - resolution: {integrity: sha512-WkeoTWvuBoFjFAhsEOHKRoZ3r9GfTyhh7Vff1zwebEFLEFjT1lG3784xEgKiTa7E+e70vsC81roVL2MP4tgEEQ==} + /rollup@4.14.3: + resolution: {integrity: sha512-ag5tTQKYsj1bhrFC9+OEWqb5O6VYgtQDO9hPDBMmIbePwhfSr+ExlcU741t8Dhw5DkPCQf6noz0jb36D6W9/hw==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} hasBin: true dependencies: '@types/estree': 1.0.5 optionalDependencies: - '@rollup/rollup-android-arm-eabi': 4.14.2 - '@rollup/rollup-android-arm64': 4.14.2 - '@rollup/rollup-darwin-arm64': 4.14.2 - '@rollup/rollup-darwin-x64': 4.14.2 - '@rollup/rollup-linux-arm-gnueabihf': 4.14.2 - '@rollup/rollup-linux-arm64-gnu': 4.14.2 - '@rollup/rollup-linux-arm64-musl': 4.14.2 - '@rollup/rollup-linux-powerpc64le-gnu': 4.14.2 - '@rollup/rollup-linux-riscv64-gnu': 4.14.2 - '@rollup/rollup-linux-s390x-gnu': 4.14.2 - '@rollup/rollup-linux-x64-gnu': 4.14.2 - '@rollup/rollup-linux-x64-musl': 4.14.2 - '@rollup/rollup-win32-arm64-msvc': 4.14.2 - '@rollup/rollup-win32-ia32-msvc': 4.14.2 - '@rollup/rollup-win32-x64-msvc': 4.14.2 + '@rollup/rollup-android-arm-eabi': 4.14.3 + '@rollup/rollup-android-arm64': 4.14.3 + '@rollup/rollup-darwin-arm64': 4.14.3 + '@rollup/rollup-darwin-x64': 4.14.3 + '@rollup/rollup-linux-arm-gnueabihf': 4.14.3 + '@rollup/rollup-linux-arm-musleabihf': 4.14.3 + '@rollup/rollup-linux-arm64-gnu': 4.14.3 + '@rollup/rollup-linux-arm64-musl': 4.14.3 + '@rollup/rollup-linux-powerpc64le-gnu': 4.14.3 + '@rollup/rollup-linux-riscv64-gnu': 4.14.3 + '@rollup/rollup-linux-s390x-gnu': 4.14.3 + '@rollup/rollup-linux-x64-gnu': 4.14.3 + '@rollup/rollup-linux-x64-musl': 4.14.3 + '@rollup/rollup-win32-arm64-msvc': 4.14.3 + '@rollup/rollup-win32-ia32-msvc': 4.14.3 + '@rollup/rollup-win32-x64-msvc': 4.14.3 fsevents: 2.3.3 dev: true @@ -6729,7 +6752,7 @@ packages: '@types/node': 20.12.7 esbuild: 0.20.2 postcss: 8.4.38 - rollup: 4.14.2 + rollup: 4.14.3 optionalDependencies: fsevents: 2.3.3 dev: true @@ -6821,8 +6844,8 @@ packages: string-width: 5.1.2 dev: true - /wildcard-match@5.1.2: - resolution: {integrity: sha512-qNXwI591Z88c8bWxp+yjV60Ch4F8Riawe3iGxbzquhy8Xs9m+0+SLFBGb/0yCTIDElawtaImC37fYZ+dr32KqQ==} + /wildcard-match@5.1.3: + resolution: {integrity: sha512-a95hPUk+BNzSGLntNXYxsjz2Hooi5oL7xOfJR6CKwSsSALh7vUNuTlzsrZowtYy38JNduYFRVhFv19ocqNOZlg==} dev: true /windows-release@5.1.1: diff --git a/src/main.ts b/src/main.ts index 79c2e4f..edcf420 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,11 +2,12 @@ import './style/univer.css' import { defu } from 'defu' import { Plugin, addIcon } from 'obsidian' import { Type as USheetType, USheetView } from './views/usheet' +import { Type as XlsxType, XlsxTypeView } from './views/xlsx' import { Type as UDocType, UDocView } from './views/udoc' import { ChooseTypeModal } from './modals/chooseType' import { SettingTab } from './modals/settingTab' import { univerIconSvg } from './utils/common' -import type { UniverPluginSettings } from '~/types/setting' +import type { UniverPluginSettings } from '@/types/setting' export type ViewType = typeof USheetType | typeof UDocType @@ -29,11 +30,13 @@ export default class UniverPlugin extends Plugin { // register view this.registerView(USheetType, leaf => new USheetView(leaf, this.settings)) + this.registerView(XlsxType, leaf => new XlsxTypeView(leaf, this.settings)) this.registerView(UDocType, leaf => new UDocView(leaf, this.settings)) this.registerExtensions(['usheet'], USheetType) this.registerExtensions(['udoc'], UDocType) + this.registerExtensions(['xlsx'], XlsxType) } async loadSettings() { diff --git a/src/mock/exchange.wasm b/src/mock/exchange.wasm new file mode 100644 index 0000000..e69de29 diff --git a/src/mock/wasm_exec.js b/src/mock/wasm_exec.js new file mode 100644 index 0000000..e69de29 diff --git a/src/modals/chooseType.ts b/src/modals/chooseType.ts index 49d7eb3..2ccd607 100644 --- a/src/modals/chooseType.ts +++ b/src/modals/chooseType.ts @@ -1,7 +1,7 @@ import type { App } from 'obsidian' import { Modal } from 'obsidian' -import type { UniverPluginSettings } from '~/types/setting' -import { createNewFile } from '~/utils/createFile' +import type { UniverPluginSettings } from '@/types/setting' +import { createNewFile } from '@/utils/createFile' interface ModalText { title: string diff --git a/src/univer/docs.ts b/src/univer/docs.ts index 498fe3f..221f5bc 100644 --- a/src/univer/docs.ts +++ b/src/univer/docs.ts @@ -6,8 +6,8 @@ import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula' import { UniverRenderEnginePlugin } from '@univerjs/engine-render' import { UniverUIPlugin } from '@univerjs/ui' import type { IUniverUIConfig } from '@univerjs/ui/lib/types/ui-plugin' -import { legacyLocales } from '~/utils/common' -import type { UniverPluginSettings } from '~/types/setting' +import { legacyLocales } from '@/utils/common' +import type { UniverPluginSettings } from '@/types/setting' export function docInit( option: IUniverUIConfig, diff --git a/src/univer/sheets.ts b/src/univer/sheets.ts index effaa33..1a71cf8 100644 --- a/src/univer/sheets.ts +++ b/src/univer/sheets.ts @@ -17,10 +17,8 @@ import { UniverUIPlugin } from '@univerjs/ui' import { UniverDataValidationPlugin } from '@univerjs/data-validation' import { UniverSheetsDataValidationPlugin } from '@univerjs/sheets-data-validation' import type { IUniverUIConfig } from '@univerjs/ui/lib/types/ui-plugin' -import { legacyLocales } from '~/utils/common' -import type { UniverPluginSettings } from '~/types/setting' - -// const workerScriptURL = new URL('./worker.ts', import.meta.url) +import { legacyLocales } from '@/utils/common' +import type { UniverPluginSettings } from '@/types/setting' export function sheetInit( option: IUniverUIConfig, diff --git a/src/utils/createFile.ts b/src/utils/createFile.ts index a35655c..9fbc28e 100644 --- a/src/utils/createFile.ts +++ b/src/utils/createFile.ts @@ -1,6 +1,6 @@ import { type App, Notice } from 'obsidian' -import { Type as DocType } from '~/views/udoc' -import { Type as SheetType } from '~/views/usheet' +import { Type as DocType } from '@/views/udoc' +import { Type as SheetType } from '@/views/usheet' export async function createNewFile(app: App, suffix: string, folderPath?: string, fileNum?: number): Promise { if (folderPath) { diff --git a/src/utils/snapshot.ts b/src/utils/snapshot.ts new file mode 100644 index 0000000..b0c9d35 --- /dev/null +++ b/src/utils/snapshot.ts @@ -0,0 +1,118 @@ +import type { IWorkbookData, Nullable } from '@univerjs/core' +import { b64DecodeUnicode, textEncoder, transformSnapshotToWorkbookData } from '@univerjs/core' + +import type { ISheetBlock, ISnapshot, IWorkbookMeta, IWorksheetMeta } from '@univerjs/protocol' + +export interface WorksheetMetaJson extends Omit { + originalMeta: string +} + +export interface WorkbookMetaJson extends Omit { + originalMeta: string + sheets: { + [key: string]: Partial + } +} + +export interface ISnapshotJson extends Omit { + workbook: Partial +} + +export interface ISheetBlockData extends Omit { + data: string +} + +export interface ISheetBlockJson { + [key: string]: Partial +} + +/** + * The originalMeta value in the JSON data transmitted from the backend is in string format and needs to be converted to Uint8Array first to fully comply with the ISnapshot format. + * @param snapshot + * @returns + */ +export function transformSnapshotMetaToBuffer(snapshot: ISnapshotJson): Nullable { + const workbook = snapshot.workbook + if (!workbook) + return null + + const sheets: { + [key: string]: IWorksheetMeta + } = {} + + if (workbook.sheets) { + // Loop through sheets and convert originalMeta + Object.keys(workbook.sheets).forEach((sheetKey) => { + const sheet = workbook.sheets && workbook.sheets[sheetKey] + + if (!sheet) + return + + // Set the converted Uint8Array to originalMeta + sheets[sheetKey] = { + ...sheet, + type: sheet.type || 0, + id: sheet.id || '', + name: sheet.name || '', + rowCount: sheet.rowCount || 0, + columnCount: sheet.columnCount || 0, + originalMeta: textEncoder.encode(b64DecodeUnicode(sheet.originalMeta || '')), + } + }) + } + + // Set the converted Uint8Array to originalMeta + const workbookOriginalMeta = textEncoder.encode(b64DecodeUnicode(workbook.originalMeta || '')) + + return { + ...snapshot, + workbook: { + ...workbook, + unitID: workbook.unitID || '', + rev: workbook.rev || 0, + creator: workbook.creator || '', + name: workbook.name || '', + sheetOrder: workbook.sheetOrder || [], + resources: workbook.resources || [], + blockMeta: workbook.blockMeta || {}, + originalMeta: workbookOriginalMeta, + sheets, + }, + } +} + +/** + * The data in the sheet block is in string format and needs to be converted to Uint8Array first to fully comply with the ISheetBlock format. + * @param sheetBlocks + * @returns + */ +export function transformSheetBlockMetaToBuffer(sheetBlocks: ISheetBlockJson): ISheetBlock[] { + const sheetBlockArray: ISheetBlock[] = [] + Object.keys(sheetBlocks).forEach((blockKey) => { + const block = sheetBlocks[blockKey] + sheetBlockArray.push({ + ...block, + id: block.id || '', + startRow: block.startRow || 0, + endRow: block.endRow || 0, + data: textEncoder.encode(b64DecodeUnicode(block.data || '')), + }) + }) + return sheetBlockArray +} + +/** + * Convert snapshot data to workbook data + * @param snapshot + * @param sheetBlocks + * @returns + */ +export function transformSnapshotJsonToWorkbookData(snapshot: ISnapshotJson, sheetBlocks: ISheetBlockJson): Nullable { + const snapshotData = transformSnapshotMetaToBuffer(snapshot) + if (!snapshotData) + return null + + const blocks = transformSheetBlockMetaToBuffer(sheetBlocks) + + return transformSnapshotToWorkbookData(snapshotData, blocks) +} diff --git a/src/views/udoc.ts b/src/views/udoc.ts index 6220c9f..05e5fcd 100644 --- a/src/views/udoc.ts +++ b/src/views/udoc.ts @@ -4,9 +4,9 @@ import { FUniver } from '@univerjs/facade' import type { WorkspaceLeaf } from 'obsidian' import { TextFileView } from 'obsidian' import { DEFAULT_DOCUMENT_DATA_EN } from '../data/default-document-data-en' -import type { UniverPluginSettings } from '~/types/setting' -import { docInit } from '~/univer/docs' -import { DEFAULT_DOCUMENT_DATA_CN } from '~/data/default-document-data-cn' +import type { UniverPluginSettings } from '@/types/setting' +import { docInit } from '@/univer/docs' +import { DEFAULT_DOCUMENT_DATA_CN } from '@/data/default-document-data-cn' export const Type = 'univer-doc' diff --git a/src/views/usheet.ts b/src/views/usheet.ts index cb1bb22..cb55de5 100644 --- a/src/views/usheet.ts +++ b/src/views/usheet.ts @@ -5,8 +5,8 @@ import { FUniver } from '@univerjs/facade' import { UniverSheetsConditionalFormattingUIPlugin } from '@univerjs/sheets-conditional-formatting-ui' import { DEFAULT_WORKBOOK_DATA_DEMO as SHEET_EN } from '../data/default-workbook-data-demo-EN' import { DEFAULT_WORKBOOK_DATA_DEMO as SHEET_CN } from '../data/default-workbook-data-demo-CN' -import type { UniverPluginSettings } from '~/types/setting' -import { sheetInit } from '~/univer/sheets' +import type { UniverPluginSettings } from '@/types/setting' +import { sheetInit } from '@/univer/sheets' export const Type = 'univer-sheet' diff --git a/src/views/xlsx.ts b/src/views/xlsx.ts new file mode 100644 index 0000000..e9ef9f5 --- /dev/null +++ b/src/views/xlsx.ts @@ -0,0 +1,119 @@ +import type { IWorkbookData, Univer, Workbook } from '@univerjs/core' +import type { WorkspaceLeaf } from 'obsidian' +import { TextFileView } from 'obsidian' +import { FUniver } from '@univerjs/facade' +import { UniverSheetsConditionalFormattingUIPlugin } from '@univerjs/sheets-conditional-formatting-ui' +import exec from '@univerjs-pro/exchange-wasm/wasm_exec?raw' +import init from '@univerjs-pro/exchange-wasm/exchange.wasm?init' +import type { UniverPluginSettings } from '@/types/setting' +import { sheetInit } from '@/univer/sheets' +import { transformSnapshotJsonToWorkbookData } from '@/utils/snapshot' + +async function injectWasm() { + try { + // eslint-disable-next-line no-new-func + new Function(exec)() + + // @ts-expect-error + const go = new window.Go() + + init(go.importObject).then((instance) => { + go.run(instance) + }).catch((err) => { + console.error(err) + }) + } + catch (err) { + console.error(err) + } +} + +function readFile(file: ArrayBuffer): Promise { + return new Promise((resolve) => { + const reader = new FileReader() + reader.onload = function () { + // @ts-expect-error + const result = window.univerProExchangeImport(reader.result) + resolve(result) + } + + reader.readAsArrayBuffer(new Blob([file])) + }) +} + +export const Type = 'univer-xlsx' + +export class XlsxTypeView extends TextFileView { + rootContainer: HTMLDivElement + univer: Univer + workbook: Workbook + FUniver: FUniver + sheetData: IWorkbookData | object + settings: UniverPluginSettings + + constructor(leaf: WorkspaceLeaf, settings: UniverPluginSettings) { + super(leaf) + this.settings = settings + } + + getViewData(): string { + return JSON.stringify(this.workbook.save()) + } + + async setViewData(_data: string, _: boolean) { + await injectWasm() + + this.domInit() + this.univer?.dispose() + this.workbook?.dispose() + + if (!this.file) + return + + const options = { + container: this.rootContainer, + header: true, + footer: true, + } + this.univer = sheetInit(options, this.settings) + + this.FUniver = FUniver.newAPI(this.univer) + + this.univer.registerPlugin(UniverSheetsConditionalFormattingUIPlugin) + + const raw = await this.app.vault.readBinary(this.file) + const result = await readFile(raw) + + const json = JSON.parse(result) + const workbookData = transformSnapshotJsonToWorkbookData(json.snapshot, json.sheetBlocks) + + if (workbookData) + this.workbook = this.univer.createUniverSheet(workbookData) + + // this.FUniver.onCommandExecuted(() => { + // this.requestSave() + // }) + } + + getViewType() { + return Type + } + + clear(): void {} + + async onOpen() {} + + domInit() { + this.contentEl.empty() + this.rootContainer = this.contentEl.createDiv() + this.rootContainer.id = 'Xlsx-app' + this.rootContainer.classList.add('uproduct-container') + } + + async onClose() { + // this.requestSave() + this.univer?.dispose() + this.workbook?.dispose() + this.contentEl.empty() + } +} diff --git a/tsconfig.json b/tsconfig.json index 91e4d16..d8fd9c0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,15 +15,6 @@ "module": "ESNext", "moduleResolution": "node", "paths": { - "~": [ - "src" - ], - "~/*": [ - "src/*" - ], - "@": [ - "src" - ], "@/*": [ "src/*" ] diff --git a/vite.config.ts b/vite.config.ts index 630b7fe..4b2a5ec 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,6 +1,7 @@ import { copyFile, rename, writeFile } from 'node:fs/promises' import { join, resolve } from 'node:path' import process from 'node:process' +import { existsSync } from 'node:fs' import { defineConfig } from 'vite' import { univerPlugin } from '@univerjs/vite-plugin' import builtins from 'builtin-modules' @@ -36,6 +37,8 @@ function generate(isDev?: boolean) { } } +const exchangeWasm = resolve(__dirname, './node_modules/@univerjs-pro/exchange-wasm/package.json') + export default defineConfig((_) => { const dev = process.argv.includes('--watch') @@ -47,7 +50,7 @@ export default defineConfig((_) => { resolve: { alias: { '@': resolve(__dirname, './src'), - '~': resolve(__dirname, './src'), + '@univerjs-pro/exchange-wasm': existsSync(exchangeWasm) ? resolve(__dirname, './node_modules/@univerjs-pro/exchange-wasm') : resolve(__dirname, './src/mock'), }, }, build: { From 40f73e470c100d53c87e2e9b8f83b922283df706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E7=86=B1?= Date: Mon, 15 Apr 2024 19:53:44 +0800 Subject: [PATCH 2/2] ci: update release.yml --- .github/workflows/release.yml | 23 ++++++++++++----- .github/workflows/test.yml | 48 +++++++++++++++++++++++++++++++++++ vite.config.ts | 7 ++++- 3 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4fe4ff6..c5871e7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,17 +13,28 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Use Node.js - uses: actions/setup-node@v1 + - uses: actions/checkout@v3 + + - name: Setup pnpm + uses: pnpm/action-setup@v2 + with: + version: 8 + + - name: Setup Node.js + uses: actions/setup-node@v4 with: - node-version: 16 + node-version: 20 + cache: pnpm + registry-url: ${{ secrets.VERDACCIO_URL }} + scope: '@univerjs-pro' + env: + NODE_AUTH_TOKEN: ${{ secrets.VERDACCIO_TOKEN }} - name: Build id: build run: | - npm install - npm run build + pnpm i + pnpm build mkdir ${{ env.PLUGIN_NAME }} echo "Waiting for build files..." while [ ! -f dist/main.js ] || [ ! -f dist/manifest.json ] || [ ! -f dist/styles.css ]; do diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..24c72b7 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,48 @@ +name: 🩺 Test + +on: + push: + branches: [master] + pull_request: + branches: [master] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 15 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup pnpm + uses: pnpm/action-setup@v2 + with: + version: 8 + + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: 18 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: pnpm + registry-url: ${{ secrets.VERDACCIO_URL }} + scope: '@univerjs-pro' + env: + NODE_AUTH_TOKEN: ${{ secrets.VERDACCIO_TOKEN }} + + - name: 📦 Build + run: | + pnpm i + pnpm run build diff --git a/vite.config.ts b/vite.config.ts index 4b2a5ec..0bc6580 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,7 +1,7 @@ import { copyFile, rename, writeFile } from 'node:fs/promises' import { join, resolve } from 'node:path' import process from 'node:process' -import { existsSync } from 'node:fs' +import { existsSync, readdirSync } from 'node:fs' import { defineConfig } from 'vite' import { univerPlugin } from '@univerjs/vite-plugin' import builtins from 'builtin-modules' @@ -39,6 +39,11 @@ function generate(isDev?: boolean) { const exchangeWasm = resolve(__dirname, './node_modules/@univerjs-pro/exchange-wasm/package.json') +if (!existsSync(exchangeWasm)) { + // eslint-disable-next-line no-console + console.log('exchange-wasm not found, using mock exchange-wasm') +} + export default defineConfig((_) => { const dev = process.argv.includes('--watch')