javascript-obfuscator / javascript-obfuscator/webpack-obfuscator
How to make webpack obfuscator config type safe?
- 主要语言
- TypeScript
- 星标
- 928
- 派生
- 92
- PR 合并指标
- 30 天内没有已合并 PR
描述
I want to ensure the values I use in my webpack obfuscator config are type safe. But for some reason the TypeScript compiler gives me no error if, for example, I use incorrect values like `high-obfuscation123` for `optionsPreset`:
webpack.config.ts
```typescript
export const mainConfig: Configuration = {
// ...
plugins: [
// ...
new WebpackObfuscatorPlugin({
optionsPreset: "high-obfuscation123", // No compile time errors. Only runtime ones (during webpack running).
// ...
})
],
// ...
}
```
I also tried to access configuration types directly but it causes an another runtime error although VSCode successfully recognize imports:
webpack.config.ts
```typescript
// ...
import WebpackObfuscatorPlugin from 'webpack-obfuscator';
import { OptionsPreset } from 'javascript-obfuscator/typings/src/enums/options/presets/OptionsPreset';
import { SourceMapMode } from 'javascript-obfuscator/typings/src/enums/source-map/SourceMapMode';
import { SourceMapSourcesMode } from 'javascript-obfuscator/typings/src/enums/source-map/SourceMapSourcesMode';
export const mainConfig: Configuration = {
// ...
plugins: [
// ...
new WebpackObfuscatorPlugin({
// ...
optionsPreset: OptionsPreset.LowObfuscation,
sourceMapMode: SourceMapMode.Separate,
sourceMapSourcesMode: SourceMapSourcesMode.Sources,
stringArrayIndexesType: [StringArrayIndexesType.HexadecimalNumericString],
target: ObfuscationTarget.Node
})
],
// ...
}
```
How can I make my webpack obfuscator config type safe?
贡献指南
这个仓库没有索引到贡献指南
调研方向
从 webpack.config.ts 和所引用的 javascript-obfuscator typings 路径开始;检查 WebpackObfuscatorPlugin 如何声明其选项,以及这些 enum import 如何在运行时输出。完成标准是:无效的 optionsPreset 值会被 TypeScript 拒绝,同时支持的配置可以导入且不会出现所报告的运行时错误。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript, webpack
- 领域
- build-system, tooling
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100