Skip to content

Commit 6bd872c

Browse files
committedApr 19, 2018
Added base web version
1 parent 2be1bf9 commit 6bd872c

22 files changed

+290
-85
lines changed
 

‎CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Change Log
22
===
3+
v0.17.0
4+
---
5+
* **Web version**: Added web version dist
6+
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/247
7+
38
v0.16.0
49
---
510
* Correct obfuscation of object rest and spread properties

‎README.md

+20-6
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
Author: Timofey Kachalov
55
-->
66

7-
# JavaScript obfuscator for Node.js
7+
# JavaScript obfuscator
88

99
![logo](https://raw.githubusercontent.com/javascript-obfuscator/javascript-obfuscator/master/images/logo.png)
1010

11-
JavaScript obfuscator is a powerful free obfuscator for JavaScript and Node.js with a wide number of features which provides protection for your source code.
11+
JavaScript obfuscator is a powerful free obfuscator for JavaScript with a wide number of features which provides protection for your source code.
1212

1313
Example of obfuscated code: [gist.github.com](https://gist.github.com/sanex3339/ffc2876123b52e6d11ce45369fd53acf)
1414

@@ -50,7 +50,9 @@ It is not recommended to obfuscate vendor scripts and polyfills, since the obfus
5050

5151
## Installation
5252

53-
Install the package with Yarn or NPM and add it to your `devDependencies`:
53+
#### Using Yarn or NPM
54+
55+
Install the package with Yarn or NPM and add it to your `dependencies` or `devDependencies`:
5456

5557
```sh
5658
$ yarn add --dev javascript-obfuscator
@@ -60,9 +62,21 @@ or
6062
$ npm install --save-dev javascript-obfuscator
6163
```
6264

63-
## Node.js usage
65+
#### In a Browser
66+
67+
Add `<script>` tag with package:
68+
69+
```html
70+
<script src="./node_modules/javascript-obfuscator/dist/index.web.js">
71+
```
72+
73+
or require package from CDN:
74+
75+
```html
76+
TODO
77+
```
6478
65-
Here's an example of how to use it:
79+
## Usage
6680
6781
```javascript
6882
var JavaScriptObfuscator = require('javascript-obfuscator');
@@ -866,7 +880,7 @@ Try to run `npm link javascript-obfuscator` command or install it globally with
866880
### Error `maximum call stack size exceeded`
867881
Likely this is `selfDefending` mechanism. Something is changing source code after obfuscation with `selfDefending` option.
868882
869-
### Web version?
883+
### Online version?
870884
871885
[obfuscator.io](https://obfuscator.io)
872886

‎bin/javascript-obfuscator

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env node
22

3-
require('../dist/index').runCLI(process.argv);
3+
require('../dist/index.cli').obfuscate(process.argv);

‎dist/index.cli.js

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/index.web.js

+54
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎index.cli.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
3+
import { JavaScriptObfuscatorCLI } from './src/JavaScriptObfuscatorCLIFacade';
4+
5+
module.exports = JavaScriptObfuscatorCLI;

‎package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"mkdirp": "0.5.1",
3434
"multimatch": "2.1.0",
3535
"opencollective": "1.0.3",
36-
"pjson": "1.0.9",
3736
"reflect-metadata": "0.1.12",
3837
"source-map-support": "0.5.4",
3938
"string-template": "1.0.0",
@@ -64,6 +63,7 @@
6463
"coveralls": "3.0.0",
6564
"istanbul": "1.1.0-alpha.1",
6665
"mocha": "5.1.0",
66+
"pjson": "1.0.9",
6767
"pre-commit": "1.2.2",
6868
"rimraf": "2.6.2",
6969
"sinon": "4.5.0",
@@ -85,7 +85,8 @@
8585
},
8686
"scripts": {
8787
"start": "scripts/start",
88-
"webpack": "scripts/webpack",
88+
"webpack:prod": "scripts/webpack-prod",
89+
"webpack:dev": "scripts/webpack-dev",
8990
"build": "scripts/build",
9091
"watch": "scripts/watch",
9192
"removeCacheDir": "scripts/remove-cache-dir",

‎scripts/build

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

33
yarn run removeCacheDir &&
4-
yarn run webpack &&
4+
yarn run webpack:prod &&
55
yarn run tslint &&
66
yarn test

‎scripts/watch

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
$(yarn bin)/webpack --mode development --watch
3+
$(yarn bin)/webpack --config webpack/webpack.config.js --mode development --watch

‎scripts/webpack

-3
This file was deleted.

‎scripts/webpack-dev

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
$(yarn bin)/webpack --config webpack/webpack.config.js --mode production

‎scripts/webpack-prod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
$(yarn bin)/webpack --config webpack/webpack.config.js --config webpack/webpack.web.config.js --mode production

‎src/JavaScriptObfuscator.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { ServiceIdentifiers } from './container/ServiceIdentifiers';
44
import * as escodegen from 'escodegen-wallaby';
55
import * as espree from 'espree';
66
import * as ESTree from 'estree';
7-
import * as packageJson from 'pjson';
87

98
import { IGeneratorOutput } from './interfaces/IGeneratorOutput';
109
import { IJavaScriptObfuscator } from './interfaces/IJavaScriptObfsucator';
@@ -127,7 +126,7 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
127126
*/
128127
public obfuscate (sourceCode: string): IObfuscationResult {
129128
const timeStart: number = Date.now();
130-
this.logger.info(LoggingMessage.Version, packageJson.version);
129+
this.logger.info(LoggingMessage.Version, '0.16.0');
131130
this.logger.info(LoggingMessage.ObfuscationStarted);
132131
this.logger.info(LoggingMessage.RandomGeneratorSeed, this.randomGenerator.getSeed());
133132

‎src/JavaScriptObfuscatorCLIFacade.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'reflect-metadata';
2+
3+
import { JavaScriptObfuscatorCLI } from './cli/JavaScriptObfuscatorCLI';
4+
5+
class JavaScriptObfuscatorCLIFacade {
6+
/**
7+
* @param {string[]} argv
8+
*/
9+
public static obfuscate (argv: string[]): void {
10+
const javaScriptObfuscatorCLI: JavaScriptObfuscatorCLI = new JavaScriptObfuscatorCLI(argv);
11+
12+
javaScriptObfuscatorCLI.initialize();
13+
javaScriptObfuscatorCLI.run();
14+
}
15+
}
16+
17+
export { JavaScriptObfuscatorCLIFacade as JavaScriptObfuscatorCLI };

‎src/JavaScriptObfuscatorFacade.ts

+5-11
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ import { IJavaScriptObfuscator } from './interfaces/IJavaScriptObfsucator';
99
import { IObfuscationResult } from './interfaces/IObfuscationResult';
1010

1111
import { InversifyContainerFacade } from './container/InversifyContainerFacade';
12-
import { JavaScriptObfuscatorCLI } from './cli/JavaScriptObfuscatorCLI';
1312

1413
class JavaScriptObfuscatorFacade {
14+
/**
15+
* @type {string | undefined}
16+
*/
17+
public static version: string = process.env.VERSION || 'unknown';
18+
1519
/**
1620
* @param {string} sourceCode
1721
* @param {TInputOptions} inputOptions
@@ -30,16 +34,6 @@ class JavaScriptObfuscatorFacade {
3034

3135
return obfuscationResult;
3236
}
33-
34-
/**
35-
* @param {string[]} argv
36-
*/
37-
public static runCLI (argv: string[]): void {
38-
const javaScriptObfuscatorCLI: JavaScriptObfuscatorCLI = new JavaScriptObfuscatorCLI(argv);
39-
40-
javaScriptObfuscatorCLI.initialize();
41-
javaScriptObfuscatorCLI.run();
42-
}
4337
}
4438

4539
export { JavaScriptObfuscatorFacade as JavaScriptObfuscator };

‎src/cli/JavaScriptObfuscatorCLI.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as commander from 'commander';
2-
import * as packageJson from 'pjson';
32
import * as path from 'path';
43

54
import { TInputCLIOptions } from '../types/options/TInputCLIOptions';
@@ -186,7 +185,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
186185
this.commands
187186
.usage('<inputPath> [options]')
188187
.version(
189-
packageJson.version,
188+
process.env.VERSION || 'unknown',
190189
'-v, --version'
191190
)
192191
.option(

‎test/functional-tests/cli/JavaScriptObfuscatorCLI.spec.ts

+20-20
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { assert } from 'chai';
77

88
import { StdoutWriteMock } from '../../mocks/StdoutWriteMock';
99

10-
import { JavaScriptObfuscator } from '../../../src/JavaScriptObfuscatorFacade';
10+
import { JavaScriptObfuscatorCLI } from '../../../src/JavaScriptObfuscatorCLIFacade';
1111

1212
describe('JavaScriptObfuscatorCLI', function (): void {
1313
this.timeout(100000);
@@ -35,7 +35,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
3535
let isFileExist: boolean;
3636

3737
before(() => {
38-
JavaScriptObfuscator.runCLI([
38+
JavaScriptObfuscatorCLI.obfuscate([
3939
'node',
4040
'javascript-obfuscator',
4141
fixtureFilePath,
@@ -67,7 +67,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
6767
before(() => {
6868
outputFixturesFilePath = `${fixturesDirName}/${outputFileName}`;
6969

70-
JavaScriptObfuscator.runCLI([
70+
JavaScriptObfuscatorCLI.obfuscate([
7171
'node',
7272
'javascript-obfuscator',
7373
fixtureFilePath
@@ -89,7 +89,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
8989
let testFunc: () => void;
9090

9191
before(() => {
92-
testFunc = () => JavaScriptObfuscator.runCLI([
92+
testFunc = () => JavaScriptObfuscatorCLI.obfuscate([
9393
'node',
9494
'javascript-obfuscator',
9595
'wrong/file/path'
@@ -111,7 +111,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
111111
before(() => {
112112
fs.writeFileSync(outputFilePath, 'data');
113113

114-
testFunc = () => JavaScriptObfuscator.runCLI([
114+
testFunc = () => JavaScriptObfuscatorCLI.obfuscate([
115115
'node',
116116
'javascript-obfuscator',
117117
outputFilePath
@@ -133,7 +133,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
133133
let isFileExist: boolean;
134134

135135
before(() => {
136-
JavaScriptObfuscator.runCLI([
136+
JavaScriptObfuscatorCLI.obfuscate([
137137
'node',
138138
'javascript-obfuscator',
139139
fixtureFilePath,
@@ -155,7 +155,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
155155
let testFunc: () => void;
156156

157157
before(() => {
158-
testFunc = () => JavaScriptObfuscator.runCLI([
158+
testFunc = () => JavaScriptObfuscatorCLI.obfuscate([
159159
'node',
160160
'javascript-obfuscator',
161161
fixtureFilePath,
@@ -201,7 +201,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
201201
outputFixturesFilePath2 = `${directoryPath}/${outputFileName2}`;
202202
outputFixturesFilePath3 = `${directoryPath}/${outputFileName3}`;
203203

204-
JavaScriptObfuscator.runCLI([
204+
JavaScriptObfuscatorCLI.obfuscate([
205205
'node',
206206
'javascript-obfuscator',
207207
directoryPath,
@@ -263,7 +263,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
263263
outputFixturesFilePath1 = `${directoryPath}/${outputFileName1}`;
264264
outputFixturesFilePath2 = `${directoryPath}/${outputFileName2}`;
265265

266-
JavaScriptObfuscator.runCLI([
266+
JavaScriptObfuscatorCLI.obfuscate([
267267
'node',
268268
'javascript-obfuscator',
269269
directoryPath,
@@ -322,7 +322,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
322322
outputFixturesFilePath2 = `${outputDirectoryPath}/${directoryPath}/${outputFileName2}`;
323323
outputFixturesFilePath3 = `${outputDirectoryPath}/${directoryPath}/${outputFileName3}`;
324324

325-
JavaScriptObfuscator.runCLI([
325+
JavaScriptObfuscatorCLI.obfuscate([
326326
'node',
327327
'javascript-obfuscator',
328328
directoryPath,
@@ -388,7 +388,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
388388
outputFixturesFilePath2 = `${directoryPath}/${outputFileName2}`;
389389
outputFixturesFilePath3 = `${directoryPath}/${outputFileName3}`;
390390

391-
JavaScriptObfuscator.runCLI([
391+
JavaScriptObfuscatorCLI.obfuscate([
392392
'node',
393393
'javascript-obfuscator',
394394
directoryPath,
@@ -453,7 +453,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
453453
outputFixturesFilePath2 = `${directoryPath}/${outputFileName2}`;
454454
outputFixturesFilePath3 = `${directoryPath}/${outputFileName3}`;
455455

456-
JavaScriptObfuscator.runCLI([
456+
JavaScriptObfuscatorCLI.obfuscate([
457457
'node',
458458
'javascript-obfuscator',
459459
directoryPath,
@@ -503,7 +503,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
503503
sourceMapObject: any;
504504

505505
before(() => {
506-
JavaScriptObfuscator.runCLI([
506+
JavaScriptObfuscatorCLI.obfuscate([
507507
'node',
508508
'javascript-obfuscator',
509509
fixtureFilePath,
@@ -554,7 +554,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
554554
sourceMapObject: any;
555555

556556
before(() => {
557-
JavaScriptObfuscator.runCLI([
557+
JavaScriptObfuscatorCLI.obfuscate([
558558
'node',
559559
'javascript-obfuscator',
560560
fixtureFilePath,
@@ -611,7 +611,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
611611
sourceMapObject: any;
612612

613613
before(() => {
614-
JavaScriptObfuscator.runCLI([
614+
JavaScriptObfuscatorCLI.obfuscate([
615615
'node',
616616
'javascript-obfuscator',
617617
fixtureFilePath,
@@ -664,7 +664,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
664664
let isFileExist: boolean;
665665

666666
before(() => {
667-
JavaScriptObfuscator.runCLI([
667+
JavaScriptObfuscatorCLI.obfuscate([
668668
'node',
669669
'javascript-obfuscator',
670670
fixtureFilePath,
@@ -708,7 +708,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
708708
beforeEach(() => {
709709
stdoutWriteMock.mute();
710710

711-
JavaScriptObfuscator.runCLI([
711+
JavaScriptObfuscatorCLI.obfuscate([
712712
'node',
713713
'javascript-obfuscator',
714714
fixtureFilePath,
@@ -730,7 +730,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
730730
beforeEach(() => {
731731
stdoutWriteMock.mute();
732732

733-
JavaScriptObfuscator.runCLI([
733+
JavaScriptObfuscatorCLI.obfuscate([
734734
'node',
735735
'javascript-obfuscator'
736736
]);
@@ -756,7 +756,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
756756
sourceMapObject: any;
757757

758758
before(() => {
759-
JavaScriptObfuscator.runCLI([
759+
JavaScriptObfuscatorCLI.obfuscate([
760760
'node',
761761
'javascript-obfuscator',
762762
fixtureFilePath,
@@ -804,7 +804,7 @@ describe('JavaScriptObfuscatorCLI', function (): void {
804804
let isFileExist: boolean;
805805

806806
before(() => {
807-
JavaScriptObfuscator.runCLI([
807+
JavaScriptObfuscatorCLI.obfuscate([
808808
'node',
809809
'javascript-obfuscator',
810810
fixtureFilePath,

‎tsconfig.web.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"compilerOptions": {
3+
"emitDecoratorMetadata": true,
4+
"experimentalDecorators": true,
5+
"lib": [
6+
"es2017",
7+
"dom"
8+
],
9+
"module": "commonjs",
10+
"esModuleInterop": true,
11+
"noImplicitThis": false,
12+
"noUnusedLocals": true,
13+
"removeComments": true,
14+
"sourceMap": true,
15+
"strict": true,
16+
"target": "es2017"
17+
},
18+
"exclude": [
19+
"node_modules",
20+
"test"
21+
],
22+
"compileOnSave": false,
23+
"buildOnSave": false
24+
}

‎webpack/utils/WebpackUtils.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const fs = require('fs');
2+
3+
const copyright = 'Copyright (C) 2016-2018 Timofey Kachalov <sanex3339@yandex.ru>';
4+
5+
class WebpackUtils {
6+
/**
7+
* @param entries
8+
* @returns {string[]}
9+
*/
10+
static getBannerText (...entries) {
11+
const lineSeparator = '\n\n';
12+
13+
return entries.reduce((bannerText, entry) => {
14+
return `${bannerText}${entry}${lineSeparator}`
15+
}, '');
16+
}
17+
18+
static getLicenseText () {
19+
return `/*!\n${copyright}\n\n` +
20+
fs.readFileSync('./LICENSE.BSD', 'utf8') + "\n*/";
21+
}
22+
23+
static getSourceMapSupportImport () {
24+
return `require("source-map-support").install();`;
25+
}
26+
}
27+
28+
module.exports.WebpackUtils = WebpackUtils;
+15-35
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,19 @@
11
'use strict';
22

3-
const fs = require("fs");
43
const nodeExternals = require('webpack-node-externals');
54
const webpack = require('webpack');
65
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
76
const TSLintPlugin = require('tslint-webpack-plugin');
7+
const packageJson = require('pjson');
88

9-
const copyright = 'Copyright (C) 2016-2018 Timofey Kachalov <sanex3339@yandex.ru>';
10-
11-
/**
12-
* @return {string}
13-
*/
14-
const getLicenseText = () => {
15-
return `/*!\n${copyright}\n\n` +
16-
fs.readFileSync('./LICENSE.BSD', 'utf8') + "\n*/";
17-
};
18-
19-
/**
20-
* @return {string}
21-
*/
22-
const getSourceMapSupportImport = () => {
23-
return `require("source-map-support").install();`;
24-
};
25-
26-
/**
27-
* @return {string}
28-
*/
29-
const getBannerText = () => {
30-
const lineSeparator = '\n\n';
31-
32-
return getLicenseText() +
33-
lineSeparator +
34-
getSourceMapSupportImport() +
35-
lineSeparator;
36-
};
9+
const WebpackUtils = require('./utils/WebpackUtils').WebpackUtils;
3710

3811
module.exports = {
12+
devtool: 'source-map',
3913
entry: {
40-
'index': './index.ts'
14+
'index': './index.ts',
15+
'index.cli': './index.cli.ts'
4116
},
42-
devtool: 'source-map',
4317
target: 'node',
4418
externals: [nodeExternals()],
4519
module: {
@@ -63,11 +37,17 @@ module.exports = {
6337
plugins: [
6438
new webpack.BannerPlugin(
6539
{
66-
banner: getBannerText(),
40+
banner: WebpackUtils.getBannerText(
41+
WebpackUtils.getLicenseText(),
42+
WebpackUtils.getSourceMapSupportImport()
43+
),
6744
raw: true,
6845
entryOnly: false
6946
}
7047
),
48+
new webpack.EnvironmentPlugin({
49+
VERSION: packageJson.version
50+
}),
7151
new CheckerPlugin(),
7252
new TSLintPlugin({
7353
files: ['./src/**/*.ts'],
@@ -76,10 +56,10 @@ module.exports = {
7656
})
7757
],
7858
output: {
79-
libraryTarget: "commonjs2",
80-
library: "JavaScriptObfuscator"
59+
libraryTarget: 'commonjs2',
60+
library: 'JavaScriptObfuscator'
8161
},
8262
stats: {
8363
maxModules: 0
8464
}
85-
};
65+
};

‎webpack/webpack.web.config.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
3+
const webpack = require('webpack');
4+
const packageJson = require('pjson');
5+
6+
const WebpackUtils = require('./utils/WebpackUtils').WebpackUtils;
7+
8+
module.exports = {
9+
devtool: 'source-map',
10+
entry: {
11+
'index': './index.ts'
12+
},
13+
target: 'web',
14+
module: {
15+
exprContextCritical: false,
16+
rules: [
17+
{
18+
test: /\.ts(x?)$/,
19+
loader: 'awesome-typescript-loader',
20+
query: {
21+
useBabel: true,
22+
babelCore: '@babel/core',
23+
useCache: true,
24+
forceIsolatedModules: true,
25+
configFileName: 'tsconfig.web.json'
26+
}
27+
}
28+
]
29+
},
30+
resolve: {
31+
extensions: ['.ts', '.js']
32+
},
33+
plugins: [
34+
new webpack.BannerPlugin(
35+
{
36+
banner: WebpackUtils.getBannerText(WebpackUtils.getLicenseText()),
37+
raw: true,
38+
entryOnly: false
39+
}
40+
),
41+
new webpack.EnvironmentPlugin({
42+
VERSION: packageJson.version
43+
})
44+
],
45+
output: {
46+
libraryTarget: 'var',
47+
library: 'JavaScriptObfuscator',
48+
filename: 'index.web.js'
49+
},
50+
performance: {
51+
hints: false
52+
},
53+
stats: {
54+
maxModules: 0,
55+
warnings: false
56+
}
57+
};

0 commit comments

Comments
 (0)
Please sign in to comment.