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:
95
common/shared/tsdown/plugins/css-noop.ts
Normal file
95
common/shared/tsdown/plugins/css-noop.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
import type { UserConfig } from 'tsdown';
|
||||
|
||||
const CSS_NOOP_PLUGIN_NAME = 'univer-css-noop';
|
||||
const CSS_IMPORT_RE = /\.(?:css|less|sass|scss|styl|stylus)(?:$|\?)/;
|
||||
const CSS_NOOP_ID_PREFIX = '\0univer-css-noop:';
|
||||
const CSS_NOOP_ID_RE = /^\0univer-css-noop:/;
|
||||
|
||||
type TInputOptions = NonNullable<UserConfig['inputOptions']>;
|
||||
type TInputOptionsFunction = Extract<TInputOptions, (...args: any[]) => any>;
|
||||
type TInputOptionsObject = Exclude<TInputOptions, (...args: any[]) => any>;
|
||||
|
||||
function toPluginArray(plugins: unknown): any[] {
|
||||
return Array.isArray(plugins)
|
||||
? plugins
|
||||
: plugins
|
||||
? [plugins]
|
||||
: [];
|
||||
}
|
||||
|
||||
function withoutCssNoopPlugin(plugins: any[]) {
|
||||
return plugins.filter((plugin) => !plugin || plugin.name !== CSS_NOOP_PLUGIN_NAME);
|
||||
}
|
||||
|
||||
export function createCssNoopPlugin() {
|
||||
let nextId = 0;
|
||||
|
||||
return {
|
||||
name: CSS_NOOP_PLUGIN_NAME,
|
||||
resolveId: {
|
||||
filter: { id: CSS_IMPORT_RE },
|
||||
handler() {
|
||||
return `${CSS_NOOP_ID_PREFIX}${nextId++}`;
|
||||
},
|
||||
},
|
||||
load: {
|
||||
filter: { id: CSS_NOOP_ID_RE },
|
||||
handler() {
|
||||
return {
|
||||
code: 'export default {};',
|
||||
moduleSideEffects: false,
|
||||
moduleType: 'js',
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function prependCssNoopPlugin(plugins: any[]) {
|
||||
return [
|
||||
createCssNoopPlugin(),
|
||||
...withoutCssNoopPlugin(plugins),
|
||||
];
|
||||
}
|
||||
|
||||
export function createCssNoopInputOptions(inputOptions?: TInputOptions): TInputOptionsFunction {
|
||||
return (async (defaultOptions: { plugins?: unknown }, ...args: any[]) => {
|
||||
const defaultPlugins = toPluginArray(defaultOptions.plugins);
|
||||
|
||||
if (!inputOptions) {
|
||||
return {
|
||||
...defaultOptions,
|
||||
plugins: prependCssNoopPlugin(defaultPlugins),
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof inputOptions === 'function') {
|
||||
const defaultOptionsWithCssNoop = {
|
||||
...defaultOptions,
|
||||
plugins: prependCssNoopPlugin(defaultPlugins),
|
||||
};
|
||||
const resolvedOptions = await (inputOptions as any)(defaultOptionsWithCssNoop, ...args);
|
||||
|
||||
if (!resolvedOptions) {
|
||||
return defaultOptionsWithCssNoop;
|
||||
}
|
||||
|
||||
return {
|
||||
...defaultOptionsWithCssNoop,
|
||||
...resolvedOptions,
|
||||
plugins: prependCssNoopPlugin(toPluginArray(resolvedOptions.plugins ?? defaultOptionsWithCssNoop.plugins)),
|
||||
};
|
||||
}
|
||||
|
||||
const inputOptionsObject = inputOptions as TInputOptionsObject & { plugins?: unknown };
|
||||
|
||||
return {
|
||||
...defaultOptions,
|
||||
...inputOptionsObject,
|
||||
plugins: prependCssNoopPlugin([
|
||||
...toPluginArray(inputOptionsObject.plugins),
|
||||
...defaultPlugins,
|
||||
]),
|
||||
};
|
||||
}) as TInputOptionsFunction;
|
||||
}
|
||||
Reference in New Issue
Block a user