Skip to content

Commit b628e49

Browse files
author
sanex3339
committed
0.28.2 release
1 parent dc0d72f commit b628e49

File tree

6 files changed

+66
-46
lines changed

6 files changed

+66
-46
lines changed

dist/index.js

+19-11
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,32 @@ class WebpackObfuscator {
2121
const pluginName = this.constructor.name;
2222
compiler.hooks.emit.tap(pluginName, (compilation) => {
2323
let identifiersPrefixCounter = 0;
24+
const sourcemapOutput = {};
2425
compilation.chunks.forEach(chunk => {
2526
chunk.files.forEach((fileName) => {
27+
if (this.options.sourceMap && fileName.toLowerCase().endsWith('.map')) {
28+
let srcName = fileName.toLowerCase().substr(0, fileName.length - 4);
29+
if (!this.shouldExclude(srcName)) {
30+
const transferredSourceMap = transferSourceMap({
31+
fromSourceMap: sourcemapOutput[srcName],
32+
toSourceMap: compilation.assets[fileName].source()
33+
});
34+
const finalSourcemap = JSON.parse(transferredSourceMap);
35+
finalSourcemap['sourcesContent'] = JSON.parse(compilation.assets[fileName].source())['sourcesContent'];
36+
compilation.assets[fileName] = new webpack_sources_1.RawSource(JSON.stringify(finalSourcemap));
37+
}
38+
return;
39+
}
2640
if (!fileName.toLowerCase().endsWith('.js') || this.shouldExclude(fileName)) {
2741
return;
2842
}
2943
const asset = compilation.assets[fileName];
3044
const { inputSource, inputSourceMap } = this.extractSourceAndSourceMap(asset);
31-
const { obfuscatedSource, obfuscationSourceMap } = this.obfuscate(inputSource, identifiersPrefixCounter);
45+
const { obfuscatedSource, obfuscationSourceMap } = this.obfuscate(inputSource, fileName, identifiersPrefixCounter);
3246
if (this.options.sourceMap && inputSourceMap) {
33-
const transferredSourceMap = transferSourceMap({
34-
fromSourceMap: obfuscationSourceMap,
35-
toSourceMap: inputSourceMap
36-
});
37-
compilation.assets[fileName] = new webpack_sources_1.SourceMapSource(obfuscatedSource, fileName, transferredSourceMap, inputSource, inputSourceMap);
38-
}
39-
else {
40-
compilation.assets[fileName] = new webpack_sources_1.RawSource(obfuscatedSource);
47+
sourcemapOutput[fileName] = obfuscationSourceMap;
4148
}
49+
compilation.assets[fileName] = new webpack_sources_1.RawSource(obfuscatedSource);
4250
identifiersPrefixCounter++;
4351
});
4452
});
@@ -59,8 +67,8 @@ class WebpackObfuscator {
5967
};
6068
}
6169
}
62-
obfuscate(javascript, identifiersPrefixCounter) {
63-
const obfuscationResult = javascript_obfuscator_1.default.obfuscate(javascript, Object.assign({ identifiersPrefix: `${WebpackObfuscator.baseIdentifiersPrefix}${identifiersPrefixCounter}` }, this.options));
70+
obfuscate(javascript, fileName, identifiersPrefixCounter) {
71+
const obfuscationResult = javascript_obfuscator_1.default.obfuscate(javascript, Object.assign({ identifiersPrefix: `${WebpackObfuscator.baseIdentifiersPrefix}${identifiersPrefixCounter}`, sourceMapFileName: fileName + '.map' }, this.options));
6472
return {
6573
obfuscatedSource: obfuscationResult.getObfuscatedCode(),
6674
obfuscationSourceMap: obfuscationResult.getSourceMap()

index.ts

+17-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { Compiler, compilation } from 'webpack';
44
import JavaScriptObfuscator, { ObfuscatorOptions } from 'javascript-obfuscator';
5-
import { RawSource, SourceMapSource } from 'webpack-sources';
5+
import { RawSource } from 'webpack-sources';
66
import multimatch from 'multimatch';
77
import { RawSourceMap } from 'source-map';
88
const transferSourceMap = require("multi-stage-sourcemap").transfer;
@@ -24,6 +24,7 @@ class WebpackObfuscator {
2424

2525
public apply(compiler: Compiler): void {
2626
const isDevServer = process.argv.find(v => v.includes('webpack-dev-server'));
27+
2728
if (isDevServer) {
2829
console.info(
2930
'JavascriptObfuscator is disabled on webpack-dev-server as the reloading scripts ',
@@ -35,35 +36,40 @@ class WebpackObfuscator {
3536

3637
compiler.hooks.emit.tap(pluginName, (compilation: compilation.Compilation) => {
3738
let identifiersPrefixCounter: number = 0;
38-
let sourcemap_output: {[index:string]: string} = {};
39+
const sourcemapOutput: {[index:string]: string} = {};
40+
3941
compilation.chunks.forEach(chunk => {
4042
chunk.files.forEach((fileName: string) => {
4143
if (this.options.sourceMap && fileName.toLowerCase().endsWith('.map')) {
42-
let src_name = fileName.toLowerCase().substr(0, fileName.length-4);
43-
if (!this.shouldExclude(src_name)) {
44+
let srcName = fileName.toLowerCase().substr(0, fileName.length - 4);
45+
46+
if (!this.shouldExclude(srcName)) {
4447
const transferredSourceMap = transferSourceMap({
45-
fromSourceMap: sourcemap_output[src_name],
48+
fromSourceMap: sourcemapOutput[srcName],
4649
toSourceMap: compilation.assets[fileName].source()
4750
});
48-
let final_sourcemap = JSON.parse(transferredSourceMap);
49-
final_sourcemap['sourcesContent'] = JSON.parse(compilation.assets[fileName].source())['sourcesContent'];
50-
compilation.assets[fileName] = new RawSource(JSON.stringify(final_sourcemap));
51+
const finalSourcemap = JSON.parse(transferredSourceMap);
52+
53+
finalSourcemap['sourcesContent'] = JSON.parse(compilation.assets[fileName].source())['sourcesContent'];
54+
compilation.assets[fileName] = new RawSource(JSON.stringify(finalSourcemap));
5155
}
56+
5257
return;
5358
}
59+
5460
if (!fileName.toLowerCase().endsWith('.js') || this.shouldExclude(fileName)) {
5561
return;
5662
}
63+
5764
const asset = compilation.assets[fileName]
5865
const { inputSource, inputSourceMap } = this.extractSourceAndSourceMap(asset);
5966
const { obfuscatedSource, obfuscationSourceMap } = this.obfuscate(inputSource, fileName, identifiersPrefixCounter);
6067

6168
if (this.options.sourceMap && inputSourceMap) {
62-
sourcemap_output[fileName] = obfuscationSourceMap;
69+
sourcemapOutput[fileName] = obfuscationSourceMap;
6370
}
64-
compilation.assets[fileName] = new RawSource(obfuscatedSource);
65-
6671

72+
compilation.assets[fileName] = new RawSource(obfuscatedSource);
6773
identifiersPrefixCounter++;
6874
});
6975
});

package-lock.json

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

package.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack-obfuscator",
3-
"version": "0.28.1",
3+
"version": "0.28.2",
44
"description": "javascript-obfuscator plugin for Webpack",
55
"keywords": [
66
"obfuscator",
@@ -15,7 +15,7 @@
1515
"main": "./dist/index.js",
1616
"types": "./dist/index.d.ts",
1717
"dependencies": {
18-
"javascript-obfuscator": "^0.28.1",
18+
"javascript-obfuscator": "^0.28.2",
1919
"multi-stage-sourcemap": "^0.2.1",
2020
"multimatch": "^2.1.0",
2121
"webpack-sources": "^1.3.0"
@@ -46,5 +46,9 @@
4646
"author": {
4747
"name": "Timofey Kachalov"
4848
},
49-
"license": "BSD-2-Clause"
49+
"license": "BSD-2-Clause",
50+
"funding": {
51+
"type": "opencollective",
52+
"url": "https://opencollective.com/javascript-obfuscator"
53+
}
5054
}

readme.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ var JavaScriptObfuscator = require('webpack-obfuscator');
1818
// webpack plugins array
1919
plugins: [
2020
new JavaScriptObfuscator ({
21-
rotateUnicodeArray: true
21+
rotateStringArray: true
2222
}, ['excluded_bundle_name.js'])
23-
],
23+
]
2424
```
2525

2626
### obfuscatorOptions
@@ -58,7 +58,7 @@ module.exports = {
5858
},
5959
plugins: [
6060
new JavaScriptObfuscator({
61-
rotateUnicodeArray: true
61+
rotateStringArray: true
6262
}, ['abc.js'])
6363
]
6464
};
@@ -67,7 +67,7 @@ module.exports = {
6767
Can be used to bypass obfuscation of some files.
6868

6969
### License
70-
Copyright (C) 2017 [Timofey Kachalov](http://github.com/sanex3339).
70+
Copyright (C) 2020 [Timofey Kachalov](http://github.com/sanex3339).
7171

7272
Redistribution and use in source and binary forms, with or without
7373
modification, are permitted provided that the following conditions are met:

test/config/webpack.config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ module.exports = {
1414
},
1515
plugins: [
1616
new JavaScriptObfuscator({
17-
disableConsoleOutput: false
17+
disableConsoleOutput: false,
18+
sourceMap: true,
19+
sourceMapMode: 'separate'
1820
}, ['index-excluded*'])
1921
],
2022
output: {

0 commit comments

Comments
 (0)