javascript-obfuscator / javascript-obfuscator/webpack-obfuscator

How to make webpack obfuscator config type safe?

Open
#180 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
928
Forks
92
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with webpack.config.ts and the referenced javascript-obfuscator typings paths; inspect how WebpackObfuscatorPlugin declares its options and how those enum imports are emitted at runtime. Done means invalid optionsPreset values are rejected by TypeScript while the supported configuration can be imported without the reported runtime error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, webpack
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.