Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
CI: add CI and other dev tools (#19)
Wenzhao Hu886fdaa6f053
diff --git a/.circleci/config.yml b/.circleci/config.ymlnew file mode 100644index 0000000000..f446812fc2--- /dev/null+++ b/.circleci/config.yml@@ -0,0 +1,34 @@+version: 2++defaults: &defaults+ working_directory: ~/repo+ docker:+ - image: cimg/node:16.20.0++jobs:+ build:+ <<: *defaults+ working_directory: ~/repo++ steps:+ - checkout++ - run:+ name: Install pnpm+ command: npm install -g pnpm++ # dependencies+ # we do not use caches here because monorepos have their own package.json files+ # it is fast to install dependencies on CI+ - run:+ name: Install dependencies+ command: pnpm install++ # tests+ - run:+ name: Run tests+ command: pnpm run test++ # TODO: type check++ # TODO: build\ No newline at end of filediff --git a/.editorconfig b/.editorconfignew file mode 100644index 0000000000..516f5ba597--- /dev/null+++ b/.editorconfig@@ -0,0 +1,7 @@+[*]+charset=utf-8+end_of_line=lf+indent_size=4+indent_style=space+insert_final_newline=false+trim_trailing_whitespace=truediff --git a/.eslintignore b/.eslintignoreindex 0cebdb60f1..edc627e497 100644--- a/.eslintignore+++ b/.eslintignore@@ -1,10 +1,3 @@-.eslintrc.js-.eslintrc-vite.config.ts-**/*.test.jsdistlibnode_modules-package.json-tsconfig.json-jest.config.jsdiff --git a/.eslintrc.back.js b/.eslintrc.back.jsdeleted file mode 100644index 08c49d792c..0000000000--- a/.eslintrc.back.js+++ /dev/null@@ -1,125 +0,0 @@-module.exports = {- // env: {- // browser: true,- // es2021: true,- // node: true,- // jest: true,- // },- globals: {- page: true,- browser: true,- context: true,- jestPuppeteer: true,- },- // parser: '@typescript-eslint/parser',- // extends: ['airbnb-typescript', 'prettier', 'eslint:recommended', 'plugin:import/recommended', 'plugin:import/typescript'],- extends: ['airbnb-base', 'airbnb-typescript/base', 'prettier'],- env: {- browser: true,- es2021: true,- },- parser: '@typescript-eslint/parser',- parserOptions: {- warnOnUnsupportedTypeScriptVersion: false,- ecmaVersion: 12,- sourceType: 'module',- tsconfigRootDir: __dirname,- project: ['./packages/*/tsconfig.json'],- },- plugins: ['@typescript-eslint', 'prettier', 'import', 'import-newlines', 'unused-imports'],- rules: {- 'no-cond-assign': 'off',- 'no-restricted-globals': 'off',- 'prettier/prettier': [- 'error',- {- endOfLine: 'auto',- },- ],- 'import/prefer-default-export': 'off',- 'import/no-extraneous-dependencies': ['error', { devDependencies: true }],- // turn on errors for missing imports- 'import/no-unresolved': [2, { ignore: ['\\.less$', '^@'] }],- '@typescript-eslint/naming-convention': 'off',- '@typescript-eslint/no-use-before-define': 'off',- '@typescript-eslint/no-shadow': 'off',- 'import/no-cycle': 'off',- 'no-param-reassign': 'off',- 'no-bitwise': 'off',- 'default-case': 'off',- 'class-methods-use-this': 'off',- 'consistent-return': 'off',- 'no-underscore-dangle': 'off',- 'no-restricted-syntax': 'off',- 'max-classes-per-file': 'off',- 'prefer-destructuring': 'off',- 'no-plusplus': 'off',- 'no-return-assign': 'off',- 'no-continue': 'off',- 'no-loop-func': 'off',- '@typescript-eslint/no-loop-func': 'off',- 'guard-for-in': 'off',- 'no-prototype-builtins': 'off',- 'no-lonely-if': 'off',- 'prefer-const': 'off',- radix: 'off',- 'no-nested-ternary': 'off',- 'no-new': 'off',- 'no-unused-expressions': 'off',- '@typescript-eslint/no-unused-expressions': 'off',- 'no-console': 'off',- 'no-multi-assign': 'off',- 'no-restricted-properties': 'off',- 'no-control-regex': 'off',- '@typescript-eslint/array-type': ['error', { default: 'array-simple' }],- 'no-await-in-loop': 'off',- '@typescript-eslint/explicit-member-accessibility': [- 'error',- {- accessibility: 'no-public',- },- ],- '@typescript-eslint/consistent-type-assertions': [- 'error',- {- assertionStyle: 'as',- objectLiteralTypeAssertions: 'allow-as-parameter',- },- ],- 'spaced-comment': 'off',- eqeqeq: ['error', 'always', { null: 'ignore' }],-- // eslint-plugin-unused-imports- '@typescript-eslint/no-unused-vars': 'off',- 'unused-imports/no-unused-imports': 'error',-- 'prefer-regex-literals': 'off',- '@typescript-eslint/default-param-last': 'off',- 'grouped-accessor-pairs': 'off',- '@typescript-eslint/member-ordering': 'error',- // '@typescript-eslint/member-ordering': [- // 'error',- // { default: ['private-field', 'protected-field', 'public-field', 'constructor', 'private-method', 'protected-method', 'public-method'] },- // ],- },- settings: {- 'import/parsers': {- '@typescript-eslint/parser': ['.ts', '.tsx'],- },- 'import/resolver': {- typescript: {- // always try to resolve config under `<root>@config`- // directory even it doesn't contain any source code,- // like `@config/unist`- alwaysTryTypes: true,- // Choose from one of the "project" configs below or omit- // to use <root>/tsconfig.json by default- // use <root>/path/to/folder/tsconfig.json- project: './tsconfig.json',- },- node: {- extensions: ['.ts', '.tsx'],- },- },- },-};diff --git a/.eslintrc.js b/.eslintrc.jsindex c6a3974e8c..1e52bea21d 100644--- a/.eslintrc.js+++ b/.eslintrc.js@@ -1,129 +1,131 @@-module.exports = {- "root": true,- env: {- browser: true,- es2021: true,- },- "parser": "@typescript-eslint/parser",- "plugins": [- "@typescript-eslint", "prettier", 'import', 'import-newlines', 'unused-imports'- ],- "extends": [- "airbnb-base", // https://www.npmjs.com/package/eslint-config-airbnb-base- "airbnb-typescript/base", // https://www.npmjs.com/package/eslint-config-airbnb-typescript- // "plugin:@typescript-eslint/recommended",// no need https://typescript-eslint.io/- "prettier"- ],- "parserOptions": {- "ecmaVersion": 12,- "sourceType": "module",- "project": "./tsconfig.json"- },- rules: {- 'no-cond-assign': 'off',- 'no-restricted-globals': 'off',- 'prettier/prettier': [- 'error',- {- endOfLine: 'auto',- },- ],- 'import/prefer-default-export': 'off',- 'import/no-extraneous-dependencies': ['error',- {- devDependencies: true- }- ],- // turn on errors for missing imports- 'import/no-unresolved': [- 2,- {- ignore: ['\\.less$', '^@'- ]- }- ],- '@typescript-eslint/naming-convention': 'off',- '@typescript-eslint/no-use-before-define': 'off',- '@typescript-eslint/no-shadow': 'off',- 'import/no-cycle': 'off',- 'no-param-reassign': 'off',- 'no-bitwise': 'off',- 'default-case': 'off',- 'class-methods-use-this': 'off',- 'consistent-return': 'off',- 'no-underscore-dangle': 'off',- 'no-restricted-syntax': 'off',- 'max-classes-per-file': 'off',- 'prefer-destructuring': 'off',- 'no-plusplus': 'off',- 'no-return-assign': 'off',- 'no-continue': 'off',- 'no-loop-func': 'off',- '@typescript-eslint/no-loop-func': 'off',- 'guard-for-in': 'off',- 'no-prototype-builtins': 'off',- 'no-lonely-if': 'off',- 'prefer-const': 'off',- radix: 'off',- 'no-nested-ternary': 'off',- 'no-new': 'off',- 'no-unused-expressions': 'off',- '@typescript-eslint/no-unused-expressions': 'off',- 'no-console': 'off',- 'no-multi-assign': 'off',- 'no-restricted-properties': 'off',- 'no-control-regex': 'off',- '@typescript-eslint/array-type': ['error',- {- default: 'array-simple'- }- ],- 'no-await-in-loop': 'off',- '@typescript-eslint/explicit-member-accessibility': [- 'error',- {- accessibility: 'no-public',- },- ],- '@typescript-eslint/consistent-type-assertions': [- 'error',- {- assertionStyle: 'as',- objectLiteralTypeAssertions: 'allow-as-parameter',- },- ],- 'spaced-comment': 'off',- eqeqeq: ['error', 'always',- {- null: 'ignore'- }- ],- // eslint-plugin-unused-imports- '@typescript-eslint/no-unused-vars': 'off',- 'unused-imports/no-unused-imports': 'error',-- 'prefer-regex-literals': 'off',- '@typescript-eslint/default-param-last': 'off',- 'grouped-accessor-pairs': 'off',- '@typescript-eslint/member-ordering': 'error',- // '@typescript-eslint/member-ordering': [- // 'error',- // { default: ['private-field', 'protected-field', 'public-field', 'constructor', 'private-method', 'protected-method', 'public-method'] },- // ],- },- // https://www.npmjs.com/package/eslint-import-resolver-typescript- settings: {- 'import/parsers': {- '@typescript-eslint/parser': ['.ts', '.tsx'],- },- 'import/resolver': {- typescript: {- alwaysTryTypes: true,- project: './tsconfig.json',- },- node: {- extensions: ['.ts', '.tsx'],- },- },- },-}\ No newline at end of file+module.exports = {+ root: true,+ env: {+ browser: true,+ es2021: true,+ },+ parser: '@typescript-eslint/parser',+ plugins: ['@typescript-eslint', 'prettier', 'import', 'import-newlines', 'unused-imports'],+ extends: [+ 'airbnb-base', // https://www.npmjs.com/package/eslint-config-airbnb-base+ 'airbnb-typescript/base', // https://www.npmjs.com/package/eslint-config-airbnb-typescript+ // "plugin:@typescript-eslint/recommended",// no need https://typescript-eslint.io/+ 'prettier',+ ],+ parserOptions: {+ ecmaVersion: 12,+ sourceType: 'module',+ // https://typescript-eslint.io/linting/troubleshooting/#i-get-errors-telling-me-eslint-was-configured-to-run--however-that-tsconfig-does-not--none-of-those-tsconfigs-include-this-file+ project: './tsconfig.eslint.json',+ },+ rules: {+ 'no-cond-assign': 'off',+ 'no-restricted-globals': 'off',+ 'prettier/prettier': [+ 'error',+ {+ endOfLine: 'auto',+ },+ ],+ 'import/prefer-default-export': 'off',+ 'import/no-extraneous-dependencies': [+ 'error',+ {+ devDependencies: true,+ },+ ],+ // turn on errors for missing imports+ 'import/no-unresolved': [+ 2,+ {+ ignore: ['\\.less$', '^@'],+ },+ ],+ '@typescript-eslint/naming-convention': 'off',+ '@typescript-eslint/no-use-before-define': 'off',+ '@typescript-eslint/no-shadow': 'off',+ 'import/no-cycle': 'off',+ 'no-param-reassign': 'off',+ 'no-bitwise': 'off',+ 'default-case': 'off',+ 'class-methods-use-this': 'off',+ 'consistent-return': 'off',+ 'no-underscore-dangle': 'off',+ 'no-restricted-syntax': 'off',+ 'max-classes-per-file': 'off',+ 'prefer-destructuring': 'off',+ 'no-plusplus': 'off',+ 'no-return-assign': 'off',+ 'no-continue': 'off',+ 'no-loop-func': 'off',+ '@typescript-eslint/no-loop-func': 'off',+ 'guard-for-in': 'off',+ 'no-prototype-builtins': 'off',+ 'no-lonely-if': 'off',+ 'prefer-const': 'off',+ radix: 'off',+ 'no-nested-ternary': 'off',+ 'no-new': 'off',+ 'no-unused-expressions': 'off',+ '@typescript-eslint/no-unused-expressions': 'off',+ 'no-console': 'off',+ 'no-multi-assign': 'off',+ 'no-restricted-properties': 'off',+ 'no-control-regex': 'off',+ '@typescript-eslint/array-type': [+ 'error',+ {+ default: 'array-simple',+ },+ ],+ 'no-await-in-loop': 'off',+ '@typescript-eslint/explicit-member-accessibility': [+ 'error',+ {+ accessibility: 'no-public',+ },+ ],+ '@typescript-eslint/consistent-type-assertions': [+ 'error',+ {+ assertionStyle: 'as',+ objectLiteralTypeAssertions: 'allow-as-parameter',+ },+ ],+ 'spaced-comment': 'off',+ eqeqeq: [+ 'error',+ 'always',+ {+ null: 'ignore',+ },+ ],+ // eslint-plugin-unused-imports+ '@typescript-eslint/no-unused-vars': 'off',+ 'unused-imports/no-unused-imports': 'error',++ 'prefer-regex-literals': 'off',+ '@typescript-eslint/default-param-last': 'off',+ 'grouped-accessor-pairs': 'off',+ '@typescript-eslint/member-ordering': 'error',+ // '@typescript-eslint/member-ordering': [+ // 'error',+ // { default: ['private-field', 'protected-field', 'public-field', 'constructor', 'private-method', 'protected-method', 'public-method'] },+ // ],+ },+ // https://www.npmjs.com/package/eslint-import-resolver-typescript+ settings: {+ 'import/parsers': {+ '@typescript-eslint/parser': ['.ts', '.tsx'],+ },+ 'import/resolver': {+ typescript: {+ alwaysTryTypes: true,+ project: './tsconfig.json',+ },+ node: {+ extensions: ['.ts', '.tsx'],+ },+ },+ },+};diff --git a/.husky/commit-msg b/.husky/commit-msgnew file mode 100755index 0000000000..c160a77123--- /dev/null+++ b/.husky/commit-msg@@ -0,0 +1,4 @@+#!/usr/bin/env sh+. "$(dirname -- "$0")/_/husky.sh"++npx --no -- commitlint --edit ${1}diff --git a/.husky/pre-commit b/.husky/pre-commitold mode 100644new mode 100755index 75040296fd..5acce99ecb--- a/.husky/pre-commit+++ b/.husky/pre-commit@@ -1,4 +1,5 @@#!/usr/bin/env sh. "$(dirname -- "$0")/_/husky.sh"-# npm run pre-lint+# lint all changed files+npm run pre-commitdiff --git a/.nvmrc b/.nvmrcnew file mode 100644index 0000000000..3b3a53bf3c--- /dev/null+++ b/.nvmrc@@ -0,0 +1 @@+16.20.0\ No newline at end of filediff --git a/.prettierrc.cjs b/.prettierrc.jssimilarity index 100%rename from .prettierrc.cjsrename to .prettierrc.jsindex 6604107223..3494bb5894 100644--- a/.prettierrc.cjs+++ b/.prettierrc.js@@ -1,7 +1,7 @@module.exports = {+ printWidth: 180,+ semi: true,singleQuote: true,- trailingComma: 'es5',tabWidth: 4,- semi: true,- printWidth: 180,+ trailingComma: 'es5',};diff --git a/.vscode/extensions.json b/.vscode/extensions.jsonindex a256fb9d30..9d734fb796 100644--- a/.vscode/extensions.json+++ b/.vscode/extensions.json@@ -1,9 +1,10 @@{"recommendations": ["dbaeumer.vscode-eslint",+ "editorconfig.editorconfig","esbenp.prettier-vscode",- "streetsidesoftware.code-spell-checker",+ "gruntfuggly.todo-tree","intellsmi.comment-translate",- "Gruntfuggly.todo-tree"+ "streetsidesoftware.code-spell-checker"]}\ No newline at end of filediff --git a/commitlint.config.js b/commitlint.config.jsnew file mode 100644index 0000000000..3d88028984--- /dev/null+++ b/commitlint.config.js@@ -0,0 +1 @@+module.exports = { extends: ['@commitlint/config-conventional'] };\ No newline at end of filediff --git a/package.json b/package.jsonindex 78cec76875..4c7b5c4202 100644--- a/package.json+++ b/package.json@@ -13,7 +13,7 @@"dev:preact": "pnpm run --filter univer-sheet-preact dev","dev:doc": "pnpm run --filter univer-doc-ts dev","dev:slide": "pnpm run --filter univer-slide-ts dev",- "d": "pnpm run --filter univer-vanilla-ts dev",+ "d": "pnpm run dev:all","api": "node scripts/api","lighthouse-dev": "start /B node scripts/dev && lighthouse http://127.0.0.1:3103 --output html --output-path ./report.html","build": "node scripts/build.js",@@ -27,14 +27,20 @@"univer-cli": "cd cli && npm run cli","postinstall": "node scripts/postinstall.js","prepare": "husky install",- "pre-lint": "lint-staged",+ "pre-commit": "lint-staged","lint": "eslint --cache --ext .ts,.tsx packages/{core,base-render,base-ui,base-sheets,ui-plugin-sheets}/src/*/**.ts{x,}","lint-and-fix": "eslint --ext .ts,.tsx packages/{core,base-render,base-ui,base-sheets,ui-plugin-sheets}/src/*/**.ts{x,} --fix"},+ "engines": {+ "node": "^16.20.0",+ "pnpm": "^8.6.1"+ },"author": "DreamNum <[email protected]>","license": "MIT","devDependencies": {"@changesets/cli": "^2.22.0",+ "@commitlint/cli": "^17.6.5",+ "@commitlint/config-conventional": "^17.6.5","@microsoft/api-documenter": "^7.18.1","@microsoft/api-extractor": "7.25.0","@playwright/test": "^1.18.1",@@ -67,7 +73,8 @@"typescript": "^4.4.1-rc"},"lint-staged": {- "./packages/{core,base-render,base-ui,base-sheets,ui-plugin-sheets}/src/**/*.ts?(x)": ["eslint --fix"]-+ "packages/**/src/**/*.ts?(x)": [+ "eslint --fix"+ ]}}diff --git a/packages/core/src/Basics/UniverSheet.ts b/packages/core/src/Basics/UniverSheet.tsindex 8d23fb4172..d117433f96 100644--- a/packages/core/src/Basics/UniverSheet.ts+++ b/packages/core/src/Basics/UniverSheet.ts@@ -5,6 +5,12 @@ import { IOHttp, IOHttpConfig, Logger } from '../Shared';import { SheetContext } from './SheetContext';import { VersionCode, VersionEnv } from './Version';+interface IComposedConfig {+ [key: string]: any;++ workbookConfig: IWorkbookConfig;+}+/*** Externally provided UniverSheet root instance*/@@ -60,10 +66,7 @@ export class UniverSheet {* @param sheet* @param data*/- static load<T extends { workbookConfig: IWorkbookConfig }>(- sheet: UniverSheet,- data: T- ) {+ static load<T extends IComposedConfig>(sheet: UniverSheet, data: T) {sheet.getWorkBook().load(data.workbookConfig);sheet.context.getPluginManager()@@ -85,9 +88,9 @@ export class UniverSheet {** @param univerSheet*/- static toJson(univerSheet: UniverSheet) {+ static toJson(univerSheet: UniverSheet): IComposedConfig {const workbookConfig = univerSheet.getWorkBook().save();- const pluginConfig = {};+ const pluginConfig: Partial<IComposedConfig> = {};univerSheet.context.getPluginManager().getPlugins()diff --git a/scripts/api.js b/scripts/api.jsindex d64256a113..5ad8a8cfa7 100644--- a/scripts/api.js+++ b/scripts/api.js@@ -1,8 +1,10 @@const execa = require('execa');const childProcess = require('child_process');+const exec = childProcess.exec;+const devTarget = '@univerjs/core';-const { execFile } = require('child_process');+run();async function run() {diff --git a/scripts/build.js b/scripts/build.jsindex 52486376cf..52b0f7af6a 100644--- a/scripts/build.js+++ b/scripts/build.js@@ -1,4 +1,5 @@const execa = require('execa');+const os = require('os');// const { targets: allTargets } = require('./util');const buildTargets = [@@ -39,7 +40,7 @@ async function run() {}// Reference https://github.com/vuejs/vue-next/blob/master/scripts/build.jsasync function buildAll(targets) {- await runParallel(require('os').cpus().length, targets, build);+ await runParallel(os.cpus().length, targets, build);}async function runParallel(maxConcurrency, source, iteratorFn) {diff --git a/scripts/dev.js b/scripts/dev.jsindex d974116e83..b438a34bec 100644--- a/scripts/dev.js+++ b/scripts/dev.js@@ -1,8 +1,8 @@const execa = require('execa');const childProcess = require('child_process');-const exec = childProcess.exec;+const devTarget = '@univerjs/base-sheets';-const { execFile } = require('child_process');+run();// esbuildasync function run() {diff --git a/scripts/link.js b/scripts/link.jsindex b3c9e00c02..928a8154e1 100644--- a/scripts/link.js+++ b/scripts/link.js@@ -1,4 +1,5 @@const execa = require('execa');+const os = require('os');// const { targets: allTargets } = require('./util');const linkTargets = [@@ -41,7 +42,7 @@ async function run() {}// Reference https://github.com/vuejs/vue-next/blob/master/scripts/build.jsasync function linkAll(targets) {- await runParallel(require('os').cpus().length, targets, link);+ await runParallel(os.cpus().length, targets, link);}async function runParallel(maxConcurrency, source, iteratorFn) {diff --git a/scripts/postinstall.js b/scripts/postinstall.jsindex 4baf9c04af..9bf1bcac51 100644--- a/scripts/postinstall.js+++ b/scripts/postinstall.js@@ -1,4 +1,4 @@-const { copyFileSync } = require('./utils.js');+const { copyFileSync } = require('./utils');// The names of modules such as Selection and Range conflict with lib.dom.d.ts. api-extractor will parse to get Selection_2 and Range_2. This problem has not been fixed in api-extractor in version 7.25.0. Refer to https://github.com/microsoft/rushstack/pull/2608 for local patching to fix this issue. In addition, pnpm is not compatible with patch-package, so use node script to solvecopyFileSync('./patches/ApiModelGenerator.js', './node_modules/@microsoft/api-extractor/lib/generators/ApiModelGenerator.js');diff --git a/scripts/server.js b/scripts/server.jsindex 0939766057..c05205fab2 100644--- a/scripts/server.js+++ b/scripts/server.js@@ -1,7 +1,7 @@const http = require('http');const server = http.createServer();-server.on('request', function (req, res) {+server.on('request', (req, res) => {res.setHeader('Access-Control-Allow-Origin', '*');res.setHeader('Access-Control-Allow-Headers', 'Content-Type,Content-Length, Authorization, Accept,X-Requested-With');res.setHeader('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS');@@ -34,35 +34,28 @@ server.on('request', function (req, res) {}});-server.listen(3998, function () {+server.listen(3998, () => {console.log('Node server running on port 3998...');});-const JSONize = (str) => {+const JSONize = (str) =>// https://stackoverflow.com/questions/14432165/uncaught-syntaxerror-unexpected-token-with-json-parse/50730876- return (- str- .replace(/\\n/g, '\\n')- .replace(/\\'/g, "\\'")- .replace(/\\"/g, '\\"')- .replace(/\\&/g, '\\&')- .replace(/\\r/g, '\\r')- .replace(/\\t/g, '\\t')- .replace(/\\b/g, '\\b')- .replace(/\\f/g, '\\f')- // remove non-printable and other non-valid JSON chars- .replace(/[\u0000-\u0019]+/g, '')+ str+ .replace(/\\n/g, '\\n')+ .replace(/\\'/g, "\\'")+ .replace(/\\"/g, '\\"')+ .replace(/\\&/g, '\\&')+ .replace(/\\r/g, '\\r')+ .replace(/\\t/g, '\\t')+ .replace(/\\b/g, '\\b')+ .replace(/\\f/g, '\\f')+ // remove non-printable and other non-valid JSON chars+ .replace(/[\u0000-\u0019]+/g, '')- // https://stackoverflow.com/questions/9036429/convert-object-string-to-json- // wrap keys without quote with valid double quote- .replace(/([\$\w]+)\s*:/g, function (_, $1) {- return '"' + $1 + '":';- })- // replacing single quote wrapped ones to double quote- .replace(/'([^']+)'/g, function (_, $1) {- return '"' + $1 + '"';- })- // '{ "value": "red", }' to '{ "value": "red" }'- .replace(/,(?=\s*})/g, '')- );-};+ // https://stackoverflow.com/questions/9036429/convert-object-string-to-json+ // wrap keys without quote with valid double quote+ .replace(/([$\w]+)\s*:/g, (_, $1) => `"${$1}":`)+ // replacing single quote wrapped ones to double quote+ .replace(/'([^']+)'/g, (_, $1) => `"${$1}"`)+ // '{ "value": "red", }' to '{ "value": "red" }'+ .replace(/,(?=\s*})/g, '');diff --git a/scripts/test.js b/scripts/test.jsindex 1373b0c863..7310d11a7f 100644--- a/scripts/test.js+++ b/scripts/test.js@@ -1,17 +1,24 @@const execa = require('execa');-const { osType } = require('./utils');const child_process = require('child_process');+const { osType } = require('./utils');++const isCI = process.env.CI === 'true';const devTarget = '@univerjs/core';-// node scripts/server && pnpm run --filter @univerjs/core test+run();async function run() {await testAll(devTarget);}+async function testAll(target) {- // start http server,/B will starts application without creating a new window.- // kill in IOHttp test script+ if (isCI) {+ // https://jestjs.io/docs/troubleshooting#tests-are-extremely-slow-on-docker-andor-continuous-integration-ci-server+ await execa('pnpm', ['run', '--filter', target, 'test', '--runInBand'], { stdio: 'inherit' });+ return;+ }+if (osType() === 'windows') {child_process.exec('start /B node scripts/server.js');} else if (osType() === 'mac') {diff --git a/scripts/utils.js b/scripts/utils.jsindex f8a314156a..8a8433dd3e 100644--- a/scripts/utils.js+++ b/scripts/utils.js@@ -1,44 +1,46 @@// Reference https://github.com/vuejs/vue-next/blob/master/scripts/utils.jsconst fs = require('fs');-const kill = require('tree-kill');-const find = require('find-process');+const path = require('path');const os = require('os');-const child_process = require('child_process');const targets = (exports.targets = fs.readdirSync('packages').filter((f) => {try {if (!fs.statSync(`packages/${f}`).isDirectory()) {return false;}+ // eslint-disable-next-line import/no-dynamic-require, global-requireconst pkg = require(`../packages/${f}/package.json`);if (pkg.private && !pkg.buildOptions) {return false;}return true;- } catch (error) {}+ } catch (error) {+ return false;+ }}));function osType() {- if (os.type() == 'Windows_NT') {+ if (os.type() === 'Windows_NT') {//windowsreturn 'windows';- } else if (os.type() == 'Darwin') {+ }+ if (os.type() === 'Darwin') {//macreturn 'mac';- } else if (os.type() == 'Linux') {+ }+ if (os.type() === 'Linux') {//Linuxreturn 'linux';- } else {- //Prompt not supported- return '';}+ //Prompt not supported+ return '';}exports.osType = osType;-exports.copyFileSync = function (source, target) {- var targetFile = target;+exports.copyFileSync = function copyFileSync(source, target) {+ let targetFile = target;// If target is a directory, a new file with the same name will be createdif (fs.existsSync(target)) {diff --git a/tsconfig.eslint.json b/tsconfig.eslint.jsonnew file mode 100644index 0000000000..e23d9c4f2c--- /dev/null+++ b/tsconfig.eslint.json@@ -0,0 +1,11 @@+{+ "extends": "./tsconfig.json",+ "compilerOptions": {+ "allowJs": true,+ },+ "include": [+ "packages/**/*",+ "examples/**/*",+ "scripts/**/*",+ ],+}\ No newline at end of file