File tree Expand file tree Collapse file tree 8 files changed +285
-73
lines changed Expand file tree Collapse file tree 8 files changed +285
-73
lines changed Original file line number Diff line number Diff line change @@ -36,9 +36,6 @@ build/Release
3636node_modules /
3737jspm_packages /
3838
39- # Typescript v1 declaration files
40- typings /
41-
4239# Optional npm cache directory
4340.npm
4441
@@ -57,4 +54,5 @@ typings/
5754# dotenv environment variables file
5855.env
5956
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 1111 "@types/node" : " ^9.3.0" ,
1212 "@types/semver" : " ^5.4.0" ,
1313 "app-root-path" : " ^2.0.1" ,
14+ "javascript-obfuscator" : " ^0.13.0" ,
1415 "jju" : " ^1.3.0" ,
1516 "semver" : " ^5.4.1" ,
1617 "source-map" : " ^0.6.1"
2223 "precommit" : " tsc && lint-staged" ,
2324 "test" : " jest"
2425 },
26+ "typings" : " dist/index.d.ts" ,
2527 "lint-staged" : {
2628 "*.ts" : [" prettier --no-semi --single-quote --trailing-comma es5" ]
2729 },
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"
452
463export = 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 77 ],
88 "strict" : true ,
99 "outDir" : " dist" ,
10+ "moduleResolution" : " node" ,
1011 "noUnusedLocals" : true ,
1112 "noUnusedParameters" : true ,
1213 "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 ,
1422 "inlineSources" : true
1523 },
1624 "include" : [
17- " typings/**/*.d.ts" ,
18- " src/**/*.ts"
25+ " typings" ,
26+ " src"
27+ ],
28+ "exclude" : [
29+ " node_modules"
1930 ],
2031 "compileOnSave" : true
2132}
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