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: support Windows paths when importing tsdown configs (#7404)

梓拧d506d8827f55
diff --git a/common/shared/preset-build/index.ts b/common/shared/preset-build/index.ts
index 856d57aa70..67843ade2e 100644
--- a/common/shared/preset-build/index.ts
+++ b/common/shared/preset-build/index.ts
@@ -4,6 +4,7 @@ import type { IPresetBuildOptions, IPresetPackageJson } from './types.ts';
import { existsSync, readFileSync, rmSync } from 'node:fs';
import path from 'node:path';
import process from 'node:process';
+import { pathToFileURL } from 'node:url';
import { mergeConfig, build as tsdownBuild } from 'tsdown';
import { createModuleConfig } from '../tsdown/configs/module.ts';
import { BUILD_OUTPUT_DIRECTORIES, CLEANUP_DIRECTORIES } from '../tsdown/constants.ts';
@@ -37,7 +38,7 @@ async function loadUserConfig(options: IPresetBuildOptions, packageDir: string)
}
const configPath = path.resolve(packageDir, options.tsdownConfigPath);
- let userConfig = (await import(configPath)).default;
+ let userConfig = (await import(pathToFileURL(configPath).href)).default;
if (typeof userConfig === 'function') {
userConfig = await userConfig();
diff --git a/common/shared/tsdown/index.ts b/common/shared/tsdown/index.ts
index 71e05299c6..468a5f161c 100644
--- a/common/shared/tsdown/index.ts
+++ b/common/shared/tsdown/index.ts
@@ -3,6 +3,7 @@ import type { IBuildContext, IBuildOptions } from './types.ts';
import { existsSync, rmSync } from 'node:fs';
import path from 'node:path';
import process from 'node:process';
+import { pathToFileURL } from 'node:url';
import { mergeConfig, build as tsdownBuild } from 'tsdown';
import { createModuleConfig } from './configs/module.ts';
import { createUmdConfig } from './configs/umd.ts';
@@ -112,7 +113,7 @@ export async function build(options: IBuildOptions = {}) {
for (const ext of configExtensions) {
const defaultConfigPath = path.resolve(packageDir, `tsdown.config${ext}`);
if (existsSync(defaultConfigPath)) {
- const { default: userConfigModule } = await import(defaultConfigPath);
+ const { default: userConfigModule } = await import(pathToFileURL(defaultConfigPath).href);
if (userConfigModule.obfuscatorIgnorePatterns) {
options.obfuscatorIgnorePatterns = userConfigModule.obfuscatorIgnorePatterns;
}
@@ -126,7 +127,7 @@ export async function build(options: IBuildOptions = {}) {
if (options.tsdownConfigPath) {
const configPath = path.resolve(packageDir, options.tsdownConfigPath);
- let userConfig = (await import(configPath)).default;
+ let userConfig = (await import(pathToFileURL(configPath).href)).default;
if (typeof userConfig === 'function') {
userConfig = await userConfig();
}