Skip to content

Commit

Permalink
chore: add woker presets (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
jikkai authored Nov 23, 2024
1 parent 39135a0 commit bdc21c2
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 14 deletions.
10 changes: 10 additions & 0 deletions common/shared/prepare/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,23 @@ export function createLocalesFiles() {

export function createPresetsFiles() {
cleanupLibDir();

Object.keys(pkg.dependencies).forEach((key) => {
if (key.startsWith('@univerjs/preset')) {
const indexTs = `export * from '${key}';\n`;
const __indexTs = path.resolve(__dirname, 'src', `${key.replace('@univerjs/', '')}/index.ts`);
fs.ensureFileSync(__indexTs);
fs.writeFileSync(__indexTs, indexTs);

const __fromWorkerTs = path.resolve(__dirname, '../', `${key.replace('@univerjs/', '')}/src/worker.ts`);
if (fs.existsSync(__fromWorkerTs)) {
const workerTs = `export * from '${key}/worker';\n`;
const __toWorkerTs = path.resolve(__dirname, 'src', `${key.replace('@univerjs/', '')}/worker.ts`);

fs.ensureFileSync(__toWorkerTs);
fs.writeFileSync(__toWorkerTs, workerTs);
}

LOCLAES_MAP.forEach((localeKey) => {
const localeTs = `export { default } from '${key}/locales/${localeKey}';\n`;
const __localeTs = path.resolve(__dirname, 'src', `${key.replace('@univerjs/', '')}/locales/${localeKey}.ts`);
Expand Down
8 changes: 6 additions & 2 deletions common/shared/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ export async function build(options?: IBuildOptions) {
}
}

const hasWorker = fs.existsSync(path.resolve(__dirname, 'src/web-worker.ts'));
const hasWorker = fs.existsSync(path.resolve(__dirname, 'src/worker.ts'));
if (hasWorker) {
entry.webWorker = path.resolve(__dirname, 'src/web-worker.ts');
entry.worker = path.resolve(__dirname, 'src/worker.ts');
}

const sharedConfig: InlineConfig = {
Expand Down Expand Up @@ -190,6 +190,10 @@ export async function build(options?: IBuildOptions) {
entry[`${preset}/locales/${localeValue}`] = path.resolve(__presetDir, 'locales', file);
}

if (fs.existsSync(path.resolve(__presetDir, 'worker.ts'))) {
entry[`${preset}/worker`] = path.resolve(__presetDir, 'worker.ts');
}

const __cssFile = path.resolve(__dirname, 'node_modules', `@univerjs/${preset}`, 'lib/index.css');
const __cssOutputDir = path.resolve(__dirname, 'lib', 'styles');
fs.ensureDirSync(__cssOutputDir);
Expand Down
2 changes: 1 addition & 1 deletion examples-node/src/sheets-node-basic/worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createUniver, LocaleType } from '@univerjs/presets';
import { UniverSheetsNodeCoreWorkerPreset } from '@univerjs/presets/preset-sheets-node-core/web-worker';
import { UniverSheetsNodeCoreWorkerPreset } from '@univerjs/presets/preset-sheets-node-core/worker';

createUniver({
locale: LocaleType.ZH_CN,
Expand Down
4 changes: 2 additions & 2 deletions examples/src/sheets-collaboration-with-worker/worker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createUniver, LocaleType, Tools } from '@univerjs/presets';
import sheetsAdvancedZhCN from '@univerjs/presets/preset-sheets-advanced/locales/zh-CN';
import { UniverSheetsAdvancedWorkerPreset } from '@univerjs/presets/preset-sheets-advanced/web-worker';
import { UniverSheetsAdvancedWorkerPreset } from '@univerjs/presets/preset-sheets-advanced/worker';
import sheetsCoreZhCN from '@univerjs/presets/preset-sheets-core/locales/zh-CN';
import { UniverSheetsCoreWorkerPreset } from '@univerjs/presets/preset-sheets-core/web-worker';
import { UniverSheetsCoreWorkerPreset } from '@univerjs/presets/preset-sheets-core/worker';

createUniver({
locale: LocaleType.ZH_CN,
Expand Down
8 changes: 4 additions & 4 deletions packages/preset-sheets-advanced/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"exports": {
".": "./src/index.ts",
"./*": "./src/*",
"./web-worker": "./src/web-worker.ts",
"./worker": "./src/worker.ts",
"./locales/*": "./src/locales/*.ts"
},
"main": "./src/index.ts",
Expand All @@ -42,10 +42,10 @@
"require": "./lib/cjs/*",
"types": "./lib/types/index.d.ts"
},
"./web-worker": {
"import": "./lib/es/web-worker.js",
"./worker": {
"import": "./lib/es/worker.js",
"require": "./lib/cjs/locales/*.js",
"types": "./lib/types/web-worker.d.ts"
"types": "./lib/types/worker.d.ts"
},
"./locales/*": {
"import": "./lib/es/locales/*.js",
Expand Down
4 changes: 3 additions & 1 deletion packages/preset-sheets-advanced/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export function UniverSheetsAdvancedPreset(config: Partial<IUniverSheetsAdvanced
[UniverLicensePlugin, { license }],

// TODO: @wzhudev: if we use worker, we need to add different configurations to SheetsPivotTable
[UniverSheetsPivotTablePlugin, { notExecuteFormula: useWorker ?? undefined }],
useWorker
? [UniverSheetsPivotTablePlugin, { notExecuteFormula: true }]
: [UniverSheetsPivotTablePlugin],
UniverSheetsPivotTableUIPlugin,

UniverProFormulaEnginePlugin,
Expand Down
8 changes: 4 additions & 4 deletions packages/preset-sheets-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"exports": {
".": "./src/index.ts",
"./*": "./src/*",
"./web-worker": "./src/web-worker.ts",
"./worker": "./src/worker.ts",
"./locales/*": "./src/locales/*.ts"
},
"publishConfig": {
Expand All @@ -41,10 +41,10 @@
"require": "./lib/cjs/*",
"types": "./lib/types/index.d.ts"
},
"./web-worker": {
"import": "./lib/es/web-worker.js",
"./worker": {
"import": "./lib/es/worker.js",
"require": "./lib/cjs/locales/*.js",
"types": "./lib/types/web-worker.d.ts"
"types": "./lib/types/worker.d.ts"
},
"./locales/*": {
"import": "./lib/es/locales/*.js",
Expand Down
File renamed without changes.

0 comments on commit bdc21c2

Please sign in to comment.