File tree 8 files changed +285
-73
lines changed
8 files changed +285
-73
lines changed Original file line number Diff line number Diff line change @@ -36,9 +36,6 @@ build/Release
36
36
node_modules /
37
37
jspm_packages /
38
38
39
- # Typescript v1 declaration files
40
- typings /
41
-
42
39
# Optional npm cache directory
43
40
.npm
44
41
@@ -57,4 +54,5 @@ typings/
57
54
# dotenv environment variables file
58
55
.env
59
56
60
- dist
57
+ dist
58
+ package
Original file line number Diff line number Diff line change
1
+ ** /*
2
+ ! dist /** /*
3
+ ! README.md
4
+ ! LICENSE
5
+ ! typings /** /*
6
+
Original file line number Diff line number Diff line change 11
11
"@types/node" : " ^9.3.0" ,
12
12
"@types/semver" : " ^5.4.0" ,
13
13
"app-root-path" : " ^2.0.1" ,
14
+ "javascript-obfuscator" : " ^0.13.0" ,
14
15
"jju" : " ^1.3.0" ,
15
16
"semver" : " ^5.4.1" ,
16
17
"source-map" : " ^0.6.1"
22
23
"precommit" : " tsc && lint-staged" ,
23
24
"test" : " jest"
24
25
},
26
+ "typings" : " dist/index.d.ts" ,
25
27
"lint-staged" : {
26
28
"*.ts" : [" prettier --no-semi --single-quote --trailing-comma es5" ]
27
29
},
Original file line number Diff line number Diff line change 1
- import * as crypto from "crypto"
2
- import * as fs from "fs"
3
-
4
- import { getCallerFile } from "./getCallerFile"
5
- import { MetroTransformer , getMetroTransformer } from "./getMetroTransformer"
6
-
7
- function getOwnCacheKey ( upstreamCacheKey : string , callerFilename : string ) {
8
- var key = crypto . createHash ( "md5" )
9
- key . update ( upstreamCacheKey )
10
- key . update ( fs . readFileSync ( __filename ) )
11
- key . update ( fs . readFileSync ( callerFilename ) )
12
- return key . digest ( "hex" )
13
- }
14
-
15
- interface ObfuscationOptions {
16
- match ?: RegExp
17
- upstreamTransformer ?: MetroTransformer
18
- }
19
-
20
- function obfuscatingTransformer ( {
21
- match = / .* .j s / ,
22
- upstreamTransformer = getMetroTransformer ( ) ,
23
- ..._options
24
- } : ObfuscationOptions ) : MetroTransformer {
25
- const callerFilename = getCallerFile ( )
26
-
27
- return {
28
- transform ( props ) {
29
- const result = upstreamTransformer . transform ( props )
30
- if ( props . filename . match ( match ) ) {
31
- console . log ( "obfuscating" , props . filename )
32
- }
33
- return result
34
- } ,
35
- getCacheKey ( ) {
36
- return getOwnCacheKey (
37
- upstreamTransformer . getCacheKey
38
- ? upstreamTransformer . getCacheKey ( )
39
- : "" ,
40
- callerFilename ,
41
- )
42
- } ,
43
- }
44
- }
1
+ import { obfuscatingTransformer } from "./obfuscatingTransformer"
45
2
46
3
export = obfuscatingTransformer
Original file line number Diff line number Diff line change
1
+ import * as crypto from "crypto"
2
+ import * as fs from "fs"
3
+ import * as JavaScriptObfuscator from "javascript-obfuscator"
4
+
5
+ import { getCallerFile } from "./getCallerFile"
6
+ import { MetroTransformer , getMetroTransformer } from "./getMetroTransformer"
7
+
8
+ function getOwnCacheKey ( upstreamCacheKey : string , callerFilename : string ) {
9
+ var key = crypto . createHash ( "md5" )
10
+ key . update ( upstreamCacheKey )
11
+ key . update ( fs . readFileSync ( __filename ) )
12
+ key . update ( fs . readFileSync ( callerFilename ) )
13
+ return key . digest ( "hex" )
14
+ }
15
+
16
+ export interface ObfuscatingTransformerOptions {
17
+ match ?: RegExp
18
+ upstreamTransformer ?: MetroTransformer
19
+ obfuscatorOptions ?: JavaScriptObfuscator . Options
20
+ }
21
+
22
+ export function obfuscatingTransformer ( {
23
+ match = / .* .j s / ,
24
+ upstreamTransformer = getMetroTransformer ( ) ,
25
+ ..._options
26
+ } : ObfuscatingTransformerOptions ) : MetroTransformer {
27
+ const callerFilename = getCallerFile ( )
28
+
29
+ return {
30
+ transform ( props ) {
31
+ const result = upstreamTransformer . transform ( props )
32
+ if ( props . filename . match ( match ) ) {
33
+ console . log ( "obfuscating" , props . filename )
34
+ }
35
+ return result
36
+ } ,
37
+ getCacheKey ( ) {
38
+ return getOwnCacheKey (
39
+ upstreamTransformer . getCacheKey
40
+ ? upstreamTransformer . getCacheKey ( )
41
+ : "" ,
42
+ callerFilename ,
43
+ )
44
+ } ,
45
+ }
46
+ }
Original file line number Diff line number Diff line change 7
7
],
8
8
"strict" : true ,
9
9
"outDir" : " dist" ,
10
+ "moduleResolution" : " node" ,
10
11
"noUnusedLocals" : true ,
11
12
"noUnusedParameters" : true ,
12
13
"inlineSourceMap" : true ,
13
- "allowJs" : true ,
14
+ "baseUrl" : " ." ,
15
+ "declaration" : true ,
16
+ "paths" : {
17
+ "javascript-obfuscator" : [
18
+ " typings/javascript-obfuscator.d.ts"
19
+ ]
20
+ },
21
+ "experimentalDecorators" : true ,
14
22
"inlineSources" : true
15
23
},
16
24
"include" : [
17
- " typings/**/*.d.ts" ,
18
- " src/**/*.ts"
25
+ " typings" ,
26
+ " src"
27
+ ],
28
+ "exclude" : [
29
+ " node_modules"
19
30
],
20
31
"compileOnSave" : true
21
32
}
Original file line number Diff line number Diff line change
1
+ declare module "javascript-obfuscator" {
2
+ namespace JavaScriptObfuscator {
3
+ interface Options {
4
+ compact ?: boolean
5
+ controlFlowFlattening ?: boolean
6
+ controlFlowFlatteningThreshold ?: 0.75
7
+ deadCodeInjection ?: boolean
8
+ deadCodeInjectionThreshold ?: 0.4
9
+ debugProtection ?: boolean
10
+ debugProtectionInterval ?: boolean
11
+ disableConsoleOutput ?: boolean
12
+ domainLock ?: string [ ]
13
+ identifierNamesGenerator ?: "hexadecimal" | "mangled"
14
+ log ?: boolean
15
+ renameGlobals ?: boolean
16
+ reservedNames ?: string [ ]
17
+ rotateStringArray ?: true
18
+ seed ?: 0
19
+ selfDefending ?: boolean
20
+ sourceMap ?: boolean
21
+ sourceMapBaseUrl ?: string
22
+ sourceMapFileName ?: string
23
+ sourceMapMode ?: "separate" | "inline"
24
+ stringArray ?: boolean
25
+ stringArrayEncoding ?: boolean
26
+ stringArrayThreshold ?: 0.75
27
+ target ?: "browser" | "extension" | "node"
28
+ unicodeEscapeSequence ?: boolean
29
+ }
30
+
31
+ function obfuscate (
32
+ sourceCode : string ,
33
+ options : Options ,
34
+ ) : {
35
+ getObfuscatedCode ( ) : string
36
+ getSourceMap ( ) : string | null
37
+ }
38
+ }
39
+
40
+ export = JavaScriptObfuscator
41
+ }
You can’t perform that action at this time.
0 commit comments