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:
42
common/shared/tsdown/plugins/output-obfuscator.ts
Normal file
42
common/shared/tsdown/plugins/output-obfuscator.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import type { ObfuscatorOptions } from 'javascript-obfuscator';
|
||||
import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import JavaScriptObfuscator from 'javascript-obfuscator';
|
||||
|
||||
interface IBundleOutput {
|
||||
fileName?: string;
|
||||
}
|
||||
|
||||
export function createOutputObfuscatorPlugin(ignorePatterns?: RegExp[]) {
|
||||
const obfuscationOptions: ObfuscatorOptions = {
|
||||
ignoreImports: true,
|
||||
};
|
||||
|
||||
return {
|
||||
name: 'create-output-obfuscator',
|
||||
writeBundle(outputOptions: { dir?: string }, bundle: Record<string, IBundleOutput>) {
|
||||
if (!outputOptions.dir) {
|
||||
return;
|
||||
}
|
||||
|
||||
const outDir = outputOptions.dir;
|
||||
|
||||
for (const output of Object.values(bundle)) {
|
||||
const fileName = output.fileName;
|
||||
if (!fileName || !fileName.endsWith('.js') || fileName.endsWith('.map')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ignorePatterns?.some((pattern) => pattern.test(fileName))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const targetPath = path.resolve(outDir, fileName);
|
||||
const sourceCode = readFileSync(targetPath, 'utf8');
|
||||
const obfuscatedCode = JavaScriptObfuscator.obfuscate(sourceCode, obfuscationOptions).getObfuscatedCode();
|
||||
|
||||
writeFileSync(targetPath, obfuscatedCode, 'utf8');
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user