snapshot of https://github.com/dream-num/univer.git (dev, 2026-09-16; blobs > 131072B omitted)
Some checks failed
📦 Build / build (push) Has been cancelled
🧪 CI Test / test shard (1/4) (push) Has been cancelled
🧪 CI Test / test shard (2/4) (push) Has been cancelled
🧪 CI Test / test shard (3/4) (push) Has been cancelled
🧪 CI Test / test shard (4/4) (push) Has been cancelled
🧪 CI Test / test (push) Has been cancelled
🧪 CI Test / eslint (push) Has been cancelled
🧪 CI Test / typecheck (push) Has been cancelled
🔫 Sync to Pro / dispatch-sync (push) Has been cancelled
🔮 Sync Mirror / sync (push) Has been cancelled
Some checks failed
📦 Build / build (push) Has been cancelled
🧪 CI Test / test shard (1/4) (push) Has been cancelled
🧪 CI Test / test shard (2/4) (push) Has been cancelled
🧪 CI Test / test shard (3/4) (push) Has been cancelled
🧪 CI Test / test shard (4/4) (push) Has been cancelled
🧪 CI Test / test (push) Has been cancelled
🧪 CI Test / eslint (push) Has been cancelled
🧪 CI Test / typecheck (push) Has been cancelled
🔫 Sync to Pro / dispatch-sync (push) Has been cancelled
🔮 Sync Mirror / sync (push) Has been cancelled
This commit is contained in:
58
common/shared/tsdown/configs/module.ts
Normal file
58
common/shared/tsdown/configs/module.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import type { UserConfig } from 'tsdown';
|
||||
import type { IEntryConfig } from '../types.ts';
|
||||
import { defineConfig } from 'tsdown';
|
||||
import { createCssNoopInputOptions } from '../plugins/css-noop.ts';
|
||||
import { createOutputAliasPlugin } from '../plugins/output-alias.ts';
|
||||
import { createOutputObfuscatorPlugin } from '../plugins/output-obfuscator.ts';
|
||||
|
||||
export type TModuleFormat = 'cjs' | 'esm';
|
||||
|
||||
export interface ICreateModuleConfigOptions {
|
||||
baseConfig: Partial<UserConfig>;
|
||||
enableObfuscation: boolean;
|
||||
entries: IEntryConfig[];
|
||||
externalPackages: string[];
|
||||
facadeExternalPackages: string[];
|
||||
format: TModuleFormat;
|
||||
obfuscatorIgnorePatterns?: RegExp[];
|
||||
outDir: string;
|
||||
packageDir: string;
|
||||
plugins: any[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the common ESM/CJS bundle config for a single package entry.
|
||||
*/
|
||||
export function createModuleConfig(options: ICreateModuleConfigOptions): UserConfig {
|
||||
const { baseConfig, enableObfuscation, entries, externalPackages, facadeExternalPackages, format, obfuscatorIgnorePatterns, outDir, packageDir, plugins } = options;
|
||||
const hasFacadeEntry = entries.some((entry) => entry.type === 'facade');
|
||||
const hasIndexEntry = entries.some((entry) => entry.type === 'index');
|
||||
const neverBundle = hasFacadeEntry ? facadeExternalPackages : externalPackages;
|
||||
const copyToRoot = format === 'esm';
|
||||
const keepRootIndexCss = hasIndexEntry && format === 'esm';
|
||||
|
||||
return defineConfig({
|
||||
...baseConfig,
|
||||
deps: {
|
||||
neverBundle,
|
||||
},
|
||||
dts: false,
|
||||
entry: Object.fromEntries(entries.map((entry) => [entry.key, entry.path])),
|
||||
format,
|
||||
inputOptions: keepRootIndexCss ? baseConfig.inputOptions : createCssNoopInputOptions(baseConfig.inputOptions),
|
||||
outputOptions: {
|
||||
codeSplitting: true,
|
||||
minify: enableObfuscation,
|
||||
},
|
||||
outDir,
|
||||
plugins: [
|
||||
...plugins,
|
||||
...(enableObfuscation ? [createOutputObfuscatorPlugin(obfuscatorIgnorePatterns)] : []),
|
||||
createOutputAliasPlugin({
|
||||
copyToRoot,
|
||||
keepRootIndexCss,
|
||||
packageDir,
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
132
common/shared/tsdown/configs/umd.ts
Normal file
132
common/shared/tsdown/configs/umd.ts
Normal file
@@ -0,0 +1,132 @@
|
||||
import type { UserConfig } from 'tsdown';
|
||||
import type { IEntryConfig } from '../types.ts';
|
||||
import { defineConfig } from 'tsdown';
|
||||
import { peerDepsMap } from '../data/peer-deps.ts';
|
||||
import { createCssNoopInputOptions } from '../plugins/css-noop.ts';
|
||||
import { createOutputAliasPlugin } from '../plugins/output-alias.ts';
|
||||
import { createOutputObfuscatorPlugin } from '../plugins/output-obfuscator.ts';
|
||||
|
||||
export interface ICreateUmdConfigOptions {
|
||||
baseConfig: Partial<UserConfig>;
|
||||
enableObfuscation: boolean;
|
||||
entry: IEntryConfig;
|
||||
obfuscatorIgnorePatterns?: RegExp[];
|
||||
outDir: string;
|
||||
packageDir: string;
|
||||
packageName: string;
|
||||
plugins: any[];
|
||||
}
|
||||
|
||||
const UMD_GLOBALS: Record<string, string> = Object.fromEntries(
|
||||
Object.entries(peerDepsMap).map(([source, value]) => [source, value.global])
|
||||
);
|
||||
const CSS_UMD_GLOBAL = 'UniverCssNoop';
|
||||
|
||||
function convertLibNameFromPackageName(name: string) {
|
||||
return name
|
||||
.replace(/^@(univerjs(?:-pro)?)\//, (_, matchedPrefix) => {
|
||||
return matchedPrefix === 'univerjs-pro' ? 'univer-pro-' : 'univer-';
|
||||
})
|
||||
.replace('/facade', '-facade')
|
||||
.split('-')
|
||||
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
||||
.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps externals to their browser globals in UMD builds.
|
||||
*/
|
||||
function resolveUmdGlobal(source: string) {
|
||||
if (source.endsWith('.css')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (source in UMD_GLOBALS) {
|
||||
return UMD_GLOBALS[source];
|
||||
}
|
||||
|
||||
if (source.startsWith('@univerjs')) {
|
||||
if (source === '@univerjs/icons') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const localeMatch = source.match(/^(@univerjs(?:-pro)?\/[^/]+)\/(?:locale|locales)\/([^/]+)$/);
|
||||
|
||||
if (localeMatch) {
|
||||
return `${convertLibNameFromPackageName(localeMatch[1])}${convertLibNameFromPackageName(localeMatch[2])}`;
|
||||
}
|
||||
|
||||
return convertLibNameFromPackageName(source);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function resolveOutputGlobal(source: string) {
|
||||
const global = resolveUmdGlobal(source);
|
||||
|
||||
if (global !== null) {
|
||||
return global;
|
||||
}
|
||||
|
||||
if (source.endsWith('.css')) {
|
||||
return CSS_UMD_GLOBAL;
|
||||
}
|
||||
|
||||
return convertLibNameFromPackageName(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces a stable UMD global name for primary, facade and locale entries.
|
||||
*/
|
||||
function getGlobalName(packageName: string, entryKey: string) {
|
||||
const name = convertLibNameFromPackageName(packageName);
|
||||
|
||||
if (entryKey === 'facade') {
|
||||
return `${name}Facade`;
|
||||
}
|
||||
|
||||
if (entryKey.startsWith('locale/') || entryKey.startsWith('locales/')) {
|
||||
const localeKey = entryKey.split('/')[1];
|
||||
return `${name}${convertLibNameFromPackageName(localeKey)}`;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the browser-oriented UMD bundle config for a single package entry.
|
||||
*/
|
||||
export function createUmdConfig(options: ICreateUmdConfigOptions): UserConfig {
|
||||
const { baseConfig, enableObfuscation, entry, obfuscatorIgnorePatterns, outDir, packageDir, packageName, plugins } = options;
|
||||
|
||||
return defineConfig({
|
||||
...baseConfig,
|
||||
deps: {
|
||||
alwaysBundle: [/.*/],
|
||||
neverBundle: (source: string) => Boolean(resolveUmdGlobal(source)),
|
||||
onlyBundle: false,
|
||||
},
|
||||
dts: false,
|
||||
entry: { [entry.key]: entry.path },
|
||||
format: 'umd',
|
||||
globalName: getGlobalName(packageName, entry.key),
|
||||
inputOptions: createCssNoopInputOptions(baseConfig.inputOptions),
|
||||
outDir,
|
||||
outputOptions: {
|
||||
entryFileNames: '[name].js',
|
||||
globals: (source: string) => resolveOutputGlobal(source),
|
||||
minify: true,
|
||||
},
|
||||
platform: 'browser',
|
||||
plugins: [
|
||||
...plugins,
|
||||
...(enableObfuscation ? [createOutputObfuscatorPlugin(obfuscatorIgnorePatterns)] : []),
|
||||
createOutputAliasPlugin({
|
||||
copyToRoot: false,
|
||||
keepRootIndexCss: false,
|
||||
packageDir,
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user