Skip to content

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.

build(tsdown): include react from devDependencies in production deps (#6937)

白熱4b9a7809483d
diff --git a/common/shared/tsdown/types.ts b/common/shared/tsdown/types.ts
index a1fe10cd25..63a2fbf5d8 100644
--- a/common/shared/tsdown/types.ts
+++ b/common/shared/tsdown/types.ts
@@ -36,6 +36,7 @@ export interface IEntryConfig {
export interface IPackageJson {
[key: string]: unknown;
dependencies?: Record<string, string>;
+ devDependencies?: Record<string, string>;
name: string;
peerDependencies?: Record<string, string>;
}
diff --git a/common/shared/tsdown/utils/cleanup-pkg.ts b/common/shared/tsdown/utils/cleanup-pkg.ts
index f911e1d84b..af1b4056c9 100644
--- a/common/shared/tsdown/utils/cleanup-pkg.ts
+++ b/common/shared/tsdown/utils/cleanup-pkg.ts
@@ -356,6 +356,14 @@ function deriveDependencyGroups(packageDir: string, packageJson: IPackageJson):
}
}
+ const declaredDevDependencies: Record<string, string> = (packageJson as CleanupPackageJson).devDependencies ?? {};
+ if ('react' in declaredDevDependencies && !('react' in peerDeps)) {
+ const reactPeerDep = peerDepsMap.react;
+ if (reactPeerDep) {
+ peerDeps.react = reactPeerDep.version;
+ }
+ }
+
return {
dependencies: deps,
devDependencies: devDeps,
diff --git a/common/shared/tsdown/utils/package.ts b/common/shared/tsdown/utils/package.ts
index 132b4bc927..1dd347dae9 100644
--- a/common/shared/tsdown/utils/package.ts
+++ b/common/shared/tsdown/utils/package.ts
@@ -19,10 +19,17 @@ import { readFileSync } from 'node:fs';
import path from 'node:path';
function getProductionDependencyNames(packageJson: IPackageJson) {
- return [...new Set([
+ const names = new Set([
...Object.keys(packageJson.dependencies ?? {}),
...Object.keys(packageJson.peerDependencies ?? {}),
- ])].sort((left, right) => left.localeCompare(right));
+ ]);
+
+ const devDeps = packageJson.devDependencies ?? {};
+ if ('react' in devDeps) {
+ names.add('react');
+ }
+
+ return [...names].sort((left, right) => left.localeCompare(right));
}
function normalizeIgnoredPackages(ignorePackages: string[] = []) {