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
revert(tsdown): stop bundling third-party deps (#6742)
白熱f57e7dfbaa94
diff --git a/common/shared/tsdown/configs/module.ts b/common/shared/tsdown/configs/module.tsindex 44e2e11530..e2a681669d 100644--- a/common/shared/tsdown/configs/module.ts+++ b/common/shared/tsdown/configs/module.ts@@ -22,13 +22,8 @@ import { createOutputObfuscatorPlugin } from '../plugins/output-obfuscator';export type TModuleFormat = 'cjs' | 'esm';-function matchesPackage(source: string, packageNames: string[]) {- return packageNames.some((packageName) => source === packageName || source.startsWith(`${packageName}/`));-}-export interface ICreateModuleConfigOptions {baseConfig: Partial<UserConfig>;- bundledPackages: string[];enableObfuscation: boolean;entry: IEntryConfig;externalPackages: string[];@@ -43,17 +38,15 @@ export interface ICreateModuleConfigOptions {* Creates the common ESM/CJS bundle config for a single package entry.*/export function createModuleConfig(options: ICreateModuleConfigOptions): UserConfig {- const { baseConfig, bundledPackages, enableObfuscation, entry, externalPackages, facadeExternalPackages, format, outDir, packageDir, plugins } = options;- const neverBundlePackages = entry.type === 'facade' ? facadeExternalPackages : externalPackages;+ const { baseConfig, enableObfuscation, entry, externalPackages, facadeExternalPackages, format, outDir, packageDir, plugins } = options;+ const neverBundle = entry.type === 'facade' ? facadeExternalPackages : externalPackages;const copyToRoot = format === 'esm';const keepRootIndexCss = entry.type === 'index' && format === 'esm';return defineConfig({...baseConfig,deps: {- alwaysBundle: (source) => matchesPackage(source, bundledPackages),- neverBundle: (source) => matchesPackage(source, neverBundlePackages),- onlyBundle: false,+ neverBundle,},dts: false,entry: { [entry.key]: entry.path },diff --git a/common/shared/tsdown/index.ts b/common/shared/tsdown/index.tsindex eb6c7f9c95..a26e84c671 100644--- a/common/shared/tsdown/index.ts+++ b/common/shared/tsdown/index.ts@@ -27,7 +27,7 @@ import { createBaseConfig, createInputOptions, createInputPlugins } from './utilimport { cleanupPackageJson } from './utils/cleanup-pkg';import { getEntries } from './utils/entries';import { removeCssArtifacts } from './utils/files';-import { createBundledPackages, createExternalPackages, readPackageJson } from './utils/package';+import { createExternalPackages, readPackageJson } from './utils/package';import { emitPublishPackageJson } from './utils/publish-manifest';/**@@ -35,14 +35,12 @@ import { emitPublishPackageJson } from './utils/publish-manifest';*/function createBuildContext(packageDir: string, options: IBuildOptions): IBuildContext {const packageJson = readPackageJson(packageDir);- const bundledPackages = createBundledPackages(packageJson, options.ignorePackages);const externalPackages = createExternalPackages(packageJson, options.ignorePackages);return {- bundledPackages,entries: getEntries(packageDir),externalPackages,- facadeExternalPackages: [...externalPackages, packageJson.name],+ facadeExternalPackages: [...externalPackages, packageJson.name, `${packageJson.name}/*`],inputOptions: createInputOptions(options),packageDir,packageJson,@@ -61,7 +59,6 @@ function createConfigs(context: IBuildContext, options: IBuildOptions) {const moduleConfigs = context.entries.flatMap((entry) => {return moduleFormats.map((format) => createModuleConfig({baseConfig,- bundledPackages: context.bundledPackages,enableObfuscation,entry,externalPackages: context.externalPackages,diff --git a/common/shared/tsdown/types.ts b/common/shared/tsdown/types.tsindex a646a6aab0..c31250f8c5 100644--- a/common/shared/tsdown/types.ts+++ b/common/shared/tsdown/types.ts@@ -39,7 +39,6 @@ export interface IPackageJson {}export interface IBuildContext {- bundledPackages: string[];entries: IEntryConfig[];externalPackages: string[];facadeExternalPackages: string[];diff --git a/common/shared/tsdown/utils/package.spec.ts b/common/shared/tsdown/utils/package.spec.tsdeleted file mode 100644index 9fc83ed06e..0000000000--- a/common/shared/tsdown/utils/package.spec.ts+++ /dev/null@@ -1,52 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import { describe, expect, it } from 'vitest';-import { createBundledPackages, createExternalPackages } from './package';--const packageJson = {- name: '@univerjs/core',- dependencies: {- '@univerjs/design': 'workspace:*',- '@univerjs-pro/example': 'workspace:*',- canvas: '^3.2.2',- '@wendellhu/redi': '1.1.1',- dayjs: '^1.11.20',- },- peerDependencies: {- react: '^19.0.0',- rxjs: '>=7.0.0',- },-};--describe('package dependency helpers', () => {- it('should keep @univerjs packages and ignored packages as external', () => {- expect(createExternalPackages(packageJson, ['canvas'])).toEqual([- '@univerjs-pro/example',- '@univerjs/design',- 'canvas',- ]);- });-- it('should bundle third-party production dependencies and peer dependencies except ignored packages', () => {- expect(createBundledPackages(packageJson, ['canvas'])).toEqual([- '@wendellhu/redi',- 'dayjs',- 'react',- 'rxjs',- ]);- });-});diff --git a/common/shared/tsdown/utils/package.ts b/common/shared/tsdown/utils/package.tsindex e65eb7919b..132b4bc927 100644--- a/common/shared/tsdown/utils/package.ts+++ b/common/shared/tsdown/utils/package.ts@@ -18,10 +18,6 @@ import type { IPackageJson } from '../types';import { readFileSync } from 'node:fs';import path from 'node:path';-function isUniverPackage(packageName: string) {- return packageName.startsWith('@univerjs/') || packageName.startsWith('@univerjs-pro/');-}-function getProductionDependencyNames(packageJson: IPackageJson) {return [...new Set([...Object.keys(packageJson.dependencies ?? {}),@@ -41,25 +37,15 @@ export function readPackageJson(packageDir: string): IPackageJson {}/**- * Produces the external package allowlist.+ * Produces the external package allowlist including subpath imports.*/export function createExternalPackages(packageJson: IPackageJson, ignorePackages: string[] = []) {const ignoredPackages = normalizeIgnoredPackages(ignorePackages);return [...new Set([- ...getProductionDependencyNames(packageJson)- .filter((packageName) => isUniverPackage(packageName)),+ ...getProductionDependencyNames(packageJson),...ignoredPackages,- ])].sort((left, right) => left.localeCompare(right));-}--/**- * Produces the package allowlist that should be bundled into ESM/CJS outputs.- */-export function createBundledPackages(packageJson: IPackageJson, ignorePackages: string[] = []) {- const ignoredPackages = normalizeIgnoredPackages(ignorePackages);-- return getProductionDependencyNames(packageJson)- .filter((packageName) => !isUniverPackage(packageName))- .filter((packageName) => !ignoredPackages.includes(packageName));+ ])]+ .sort((left, right) => left.localeCompare(right))+ .flatMap((packageName) => [packageName, `${packageName}/*`]);}