Skip to content

Commit f90057d

Browse files
committed
Version update to 2.6.0
1 parent 390b5ae commit f90057d

File tree

10 files changed

+1774
-4714
lines changed

10 files changed

+1774
-4714
lines changed

.travis.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
language: node_js
22
node_js:
3-
- "10"
4-
- "12"
5-
- "stable"
3+
- "8"
64

75
before_script:
86
- npm run setup

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# javascript-obfuscator plugin and loader for Webpack@5
1+
# javascript-obfuscator plugin and loader for Webpack
22

33
[![npm version](https://badge.fury.io/js/webpack-obfuscator.svg)](https://badge.fury.io/js/webpack-obfuscator)
44

55
### Installation
66

77
Install the package with NPM and add it to your devDependencies:
88

9-
`npm install --save-dev javascript-obfuscator webpack-obfuscator`
9+
`npm install --save-dev webpack-obfuscator`
1010

1111
### Plugin usage:
1212

declarations/loaderUtils.d.ts

-3
This file was deleted.

loader/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
import JavaScriptObfuscator, {ObfuscatorOptions} from 'javascript-obfuscator';
3+
import JavaScriptObfuscator from 'javascript-obfuscator';
44
import estraverse from 'estraverse';
55
import * as ESTree from 'estree';
66
import loaderUtils from 'loader-utils';
@@ -110,7 +110,7 @@ class WebpackObfuscatorLoaderHelper {
110110
function Loader (sourceCode: string) {
111111
// Obfuscates commented source code
112112
// @ts-ignore
113-
const options = loaderUtils.getOptions<ObfuscatorOptions>(this) || {};
113+
const options = loaderUtils.getOptions(this) || {};
114114
const commentedSourceCode: string = WebpackObfuscatorLoaderHelper.getCommentedSource(sourceCode);
115115
const obfuscationResult = JavaScriptObfuscator.obfuscate(commentedSourceCode, options);
116116

package-lock.json

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

package.json

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "webpack-obfuscator",
3-
"version": "3.0.0-beta.0",
4-
"description": "javascript-obfuscator plugin for Webpack@5",
3+
"version": "2.6.0",
4+
"description": "javascript-obfuscator plugin for Webpack",
55
"keywords": [
66
"obfuscator",
77
"obfuscation",
@@ -15,27 +15,29 @@
1515
"main": "./dist/index.js",
1616
"types": "./dist/index.d.ts",
1717
"dependencies": {
18-
"acorn": "^8.0.4",
18+
"acorn": "^8.0.1",
1919
"estraverse": "^5.2.0",
2020
"loader-utils": "^2.0.0",
2121
"multi-stage-sourcemap": "^0.3.1",
22-
"multimatch": "^5.0.0",
23-
"webpack-sources": "^2.0.1"
22+
"multimatch": "^4.0.0",
23+
"webpack-sources": "^1.4.3"
2424
},
2525
"peerDependencies": {
2626
"javascript-obfuscator": "^2.6.0",
27-
"webpack": "^5.1.0"
27+
"webpack": "^4.44.1"
2828
},
2929
"devDependencies": {
3030
"@types/estraverse": "^5.1.0",
3131
"@types/estree": "0.0.45",
32-
"@types/node": "^14.11.8",
33-
"@types/webpack-sources": "^2.0.0",
32+
"@types/loader-utils": "^2.0.1",
33+
"@types/node": "^14.6.4",
34+
"@types/webpack": "^4.41.22",
35+
"@types/webpack-sources": "^1.4.2",
3436
"javascript-obfuscator": "^2.6.0",
3537
"source-map": "^0.7.3",
36-
"typescript": "^4.0.3",
37-
"webpack": "^5.1.0",
38-
"webpack-cli": "^4.0.0"
38+
"typescript": "^4.0.2",
39+
"webpack": "^4.42.0",
40+
"webpack-cli": "^3.3.12"
3941
},
4042
"repository": {
4143
"type": "git",
@@ -45,8 +47,8 @@
4547
"setup": "npm install",
4648
"build": "npx tsc",
4749
"watch": "npx tsc -w",
48-
"test:plugin": "npm run build && npx webpack --config test/config/javascript-obfuscator-plugin.config.js",
49-
"test:loader": "npm run build && npx webpack --config test/config/javascript-obfuscator-loader.config.js"
50+
"test:plugin": "npx webpack --config test/config/javascript-obfuscator-plugin.config.js",
51+
"test:loader": "npx webpack --config test/config/javascript-obfuscator-loader.config.js"
5052
},
5153
"author": {
5254
"name": "Timofey Kachalov"

plugin/index.ts

+41-50
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"use strict";
22

3-
import { Compiler, Compilation, sources } from 'webpack';
3+
import { Compiler, compilation } from 'webpack';
44
import JavaScriptObfuscator, { ObfuscatorOptions } from 'javascript-obfuscator';
5+
import { RawSource } from 'webpack-sources';
56
import multimatch from 'multimatch';
67
import { RawSourceMap } from 'source-map';
78
const transferSourceMap = require("multi-stage-sourcemap").transfer;
@@ -41,55 +42,45 @@ export class WebpackObfuscatorPlugin {
4142

4243
const pluginName = this.constructor.name;
4344

44-
compiler.hooks.compilation.tap(pluginName, (compilation: Compilation) => {
45-
compilation.hooks.processAssets.tap(
46-
{
47-
name: 'WebpackObfuscator',
48-
stage: Compilation.PROCESS_ASSETS_STAGE_DERIVED
49-
},
50-
(assets) => {
51-
let identifiersPrefixCounter: number = 0;
52-
const sourcemapOutput: {[index:string]: string} = {};
53-
54-
compilation.chunks.forEach(chunk => {
55-
chunk.files.forEach((fileName: string) => {
56-
if (this.options.sourceMap && fileName.toLowerCase().endsWith('.map')) {
57-
let srcName = fileName.toLowerCase().substr(0, fileName.length - 4);
58-
59-
if (!this.shouldExclude(srcName)) {
60-
const transferredSourceMap = transferSourceMap({
61-
fromSourceMap: sourcemapOutput[srcName],
62-
toSourceMap: compilation.assets[fileName].source()
63-
});
64-
const finalSourcemap = JSON.parse(transferredSourceMap);
65-
66-
finalSourcemap['sourcesContent'] = JSON.parse(
67-
assets[fileName].source().toString()
68-
)['sourcesContent'];
69-
assets[fileName] = new sources.RawSource(JSON.stringify(finalSourcemap), false);
70-
}
71-
72-
return;
73-
}
74-
75-
if (!fileName.toLowerCase().endsWith('.js') || this.shouldExclude(fileName)) {
76-
return;
77-
}
78-
79-
const asset = compilation.assets[fileName]
80-
const { inputSource, inputSourceMap } = this.extractSourceAndSourceMap(asset);
81-
const { obfuscatedSource, obfuscationSourceMap } = this.obfuscate(inputSource, fileName, identifiersPrefixCounter);
82-
83-
if (this.options.sourceMap && inputSourceMap) {
84-
sourcemapOutput[fileName] = obfuscationSourceMap;
85-
}
86-
87-
assets[fileName] = new sources.RawSource(obfuscatedSource, false);
88-
identifiersPrefixCounter++;
89-
});
90-
});
91-
}
92-
);
45+
compiler.hooks.emit.tap(pluginName, (compilation: compilation.Compilation) => {
46+
let identifiersPrefixCounter: number = 0;
47+
const sourcemapOutput: {[index:string]: string} = {};
48+
49+
compilation.chunks.forEach(chunk => {
50+
chunk.files.forEach((fileName: string) => {
51+
if (this.options.sourceMap && fileName.toLowerCase().endsWith('.map')) {
52+
let srcName = fileName.toLowerCase().substr(0, fileName.length - 4);
53+
54+
if (!this.shouldExclude(srcName)) {
55+
const transferredSourceMap = transferSourceMap({
56+
fromSourceMap: sourcemapOutput[srcName],
57+
toSourceMap: compilation.assets[fileName].source()
58+
});
59+
const finalSourcemap = JSON.parse(transferredSourceMap);
60+
61+
finalSourcemap['sourcesContent'] = JSON.parse(compilation.assets[fileName].source())['sourcesContent'];
62+
compilation.assets[fileName] = new RawSource(JSON.stringify(finalSourcemap));
63+
}
64+
65+
return;
66+
}
67+
68+
if (!fileName.toLowerCase().endsWith('.js') || this.shouldExclude(fileName)) {
69+
return;
70+
}
71+
72+
const asset = compilation.assets[fileName]
73+
const { inputSource, inputSourceMap } = this.extractSourceAndSourceMap(asset);
74+
const { obfuscatedSource, obfuscationSourceMap } = this.obfuscate(inputSource, fileName, identifiersPrefixCounter);
75+
76+
if (this.options.sourceMap && inputSourceMap) {
77+
sourcemapOutput[fileName] = obfuscationSourceMap;
78+
}
79+
80+
compilation.assets[fileName] = new RawSource(obfuscatedSource);
81+
identifiersPrefixCounter++;
82+
});
83+
});
9384
});
9485
}
9586

test/input/index-excluded.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require('./nested');
2-
31
(function () {
42
var test = 1;
53

test/input/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require('./nested');
2-
31
(function () {
42
var test = 1;
53

test/input/nested.js

-1
This file was deleted.

0 commit comments

Comments
 (0)