Skip to content

Commit f547a89

Browse files
author
David Sheldrick
committed
add enableInDevelopment flag
1 parent 9b012c0 commit f547a89

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,20 @@ interface ObfuscatorOptions {
100100

101101
Iff true, prints a list of files being obfuscated
102102

103+
#### Default value: `false`
104+
103105
### `emitObfuscatedFiles: boolean`
104106

105107
Iff true, emits the obfuscated versions of files alongside their originals, for comparison.
106108

109+
#### Default value: `false`
110+
111+
### `enableInDevelopment: boolean`
112+
113+
Iff true, enables obfuscation in development mode. This is true by default.
114+
115+
#### Default value: `false`
116+
107117
## License
108118

109119
MIT

src/getMetroTransformer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export interface MetroTransformer {
1818
transform(props: {
1919
filename: string
2020
src: string
21-
options: object
21+
options: {
22+
dev?: boolean
23+
retainLines?: boolean
24+
// others unused
25+
}
2226
}): MetroTransformerResult
2327
getCacheKey?(): string
2428
}

src/obfuscatingTransformer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface ObfuscatingTransformerOptions {
3333
obfuscatorOptions?: JavaScriptObfuscator.Options
3434
trace?: boolean
3535
emitObfuscatedFiles?: boolean
36+
enableInDevelopment?: boolean
3637
}
3738

3839
const sourceDir = path.join(appRootPath, "src")
@@ -55,6 +56,11 @@ export function obfuscatingTransformer({
5556
return {
5657
transform(props) {
5758
const result = upstreamTransformer.transform(props)
59+
60+
if (props.options.dev && !otherOptions.enableInDevelopment) {
61+
return result
62+
}
63+
5864
const resultCanBeObfuscated = result.code || result.ast
5965

6066
if (resultCanBeObfuscated && filter(props.filename, props.src)) {

0 commit comments

Comments
 (0)