8000 Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/… · sec-js/javascript-obfuscator@e2d9784 · GitHub
[go: up one dir, main page]

Skip to content

Commit e2d9784

Browse files
author
sanex3339
committed
1 parent 173b2b8 commit e2d9784

File tree

10 files changed

+200
-144
lines changed

10 files changed

+200
-144
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Change Log
22

3+
v0.27.3
4+
---
5+
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/593
6+
37
v0.27.2
48
---
59
* Fixed identifiers prefix generation for `obfuscateMultiple` method

dist/index.browser.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.cli.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "javascript-obfuscator",
3-
"version": "0.27.2",
3+
"version": "0.27.3",
44
"description": "JavaScript obfuscator",
55
"keywords": [
66
"obfuscator",
@@ -25,7 +25,7 @@
2525
"@nuxtjs/opencollective": "0.2.2",
2626
"acorn": "7.1.1",
2727
"acorn-import-meta": "1.0.0",
28-
"chalk": "3.0.0",
28+
"chalk": "4.0.0",
2929
"chance": "1.1.4",
3030
"class-validator": "0.11.1",
3131
"commander": "5.0.0",
@@ -37,7 +37,7 @@
3737
"inversify": "5.0.1",
3838
"js-string-escape": "1.0.1",
3939
"md5": "2.2.1",
40-
"mkdirp": "1.0.3",
40+
"mkdirp": "1.0.4",
4141
"multimatch": "4.0.0",
4242
"reflect-metadata": "0.1.13",
4343
"source-map-support": "0.5.16",
@@ -46,7 +46,7 @@
4646
},
4747
"devDependencies": {
4848
"@types/chai": "4.2.11",
49-
"@types/chance": "1.0.9",
49+
"@types/chance": "1.0.10",
5050
"@types/escodegen": "0.0.6",
5151
"@types/eslint-scope": "3.7.0",
5252
"@types/estraverse": "0.0.6",
@@ -55,30 +55,30 @@
5555
"@types/mkdirp": "1.0.0",
5656
"@types/mocha": "7.0.2",
5757
"@types/multimatch": "4.0.0",
58-
"@types/node": "13.9.8",
58+
"@types/node": "13.11.1",
5959
"@types/rimraf": "3.0.0",
6060
"@types/sinon": "9.0.0",
6161
"@types/string-template": "1.0.2",
6262
"@types/webpack-env": "1.15.1",
63-
"@typescript-eslint/eslint-plugin": "2.26.0",
64-
"@typescript-eslint/parser": "2.26.0",
63+
"@typescript-eslint/eslint-plugin": "2.27.0",
64+
"@typescript-eslint/parser": "2.27.0",
6565
"chai": "4.2.0",
6666
"coveralls": "3.0.11",
6767
"eslint": "6.8.0",
6868
"eslint-plugin-import": "2.20.2",
6969
"eslint-plugin-jsdoc": "22.1.0",
7070
"eslint-plugin-no-null": "1.0.2",
71-
"eslint-plugin-prefer-arrow": "1.1.7",
71+
"eslint-plugin-prefer-arrow": "1.2.0",
7272
"eslint-plugin-unicorn": "18.0.1",
7373
"fork-ts-checker-notifier-webpack-plugin": "2.0.0",
74-
"fork-ts-checker-webpack-plugin": "4.1.2",
74+
"fork-ts-checker-webpack-plugin": "4.1.3",
7575
"mocha": "7.1.1",
76-
"nyc": "15.0.0",
76+
"nyc": "15.0.1",
7777
"pjson": "1.0.9",
7878
"pre-commit": "1.2.2",
7979
"rimraf": "3.0.2",
80-
"sinon": "9.0.1",
81-
"threads": "1.3.1",
80+
"sinon": "9.0.2",
81+
"threads": "1.4.0",
8282
"ts-loader": "6.2.2",
8383
"ts-node": "6.1.0",
8484
"typescript": "3.8.3",

src/cli/JavaScriptObfuscatorCLI.ts

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,18 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
9797

9898
/**
9999
* @param {TInputCLIOptions} inputOptions
100-
* @param {string} inputCodePath
101100
* @returns {TInputOptions}
102101
*/
103-
private static buildOptions (
104-
inputOptions: TInputCLIOptions,
105-
inputCodePath: string
106-
): TInputOptions {
102+
private static buildOptions (inputOptions: TInputCLIOptions): TInputOptions {
107103
const inputCLIOptions: TInputOptions = JavaScriptObfuscatorCLI.filterOptions(inputOptions);
108104
const configFilePath: string | undefined = inputOptions.config;
109105
const configFileLocation: string = configFilePath ? path.resolve(configFilePath, '.') : '';
110106
const configFileOptions: TInputOptions = configFileLocation ? CLIUtils.getUserConfig(configFileLocation) : {};
111-
const inputFileName: string = path.basename(inputCodePath);
112107

113108
return {
114109
...DEFAULT_PRESET,
115110
...configFileOptions,
116-
...inputCLIOptions,
117-
inputFileName
111+
...inputCLIOptions
118112
};
119113
}
120114

@@ -145,7 +139,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
145139
this.configureCommands();
146140
this.configureHelp();
147141

148-
this.inputCLIOptions = this.commands.opts();
142+
this.inputCLIOptions = JavaScriptObfuscatorCLI.buildOptions(this.commands.opts());
149143
this.sourceCodeReader = new SourceCodeReader(
150144
this.inputPath,
151145
this.inputCLIOptions
@@ -403,22 +397,16 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
403397
outputCodePath: string,
404398
sourceCodeIndex: number | null
405399
): void {
406-
let options: TInputOptions = JavaScriptObfuscatorCLI.buildOptions(
407-
this.inputCLIOptions,
408-
inputCodePath
409-
);
410-
411-
if (sourceCodeIndex !== null) {
412-
const identifiersPrefix: string = Utils.getIdentifiersPrefixForMultipleSources(
413-
this.inputCLIOptions.identifiersPrefix,
414-
sourceCodeIndex
415-
);
416-
417-
options = {
418-
...options,
419-
identifiersPrefix
420-
};
421-
}
400+
const options: TInputOptions = {
401+
...this.inputCLIOptions,
402+
inputFileName: path.basename(inputCodePath),
403+
...sourceCodeIndex !== null && {
404+
identifiersPrefix: Utils.getIdentifiersPrefixForMultipleSources(
405+
this.inputCLIOptions.identifiersPrefix,
406+
sourceCodeIndex
407+
)
408+
}
409+
};
422410

423411
if (options.sourceMap) {
424412
this.processSourceCodeWithSourceMap(sourceCode, outputCodePath, options);

test/fixtures/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
compact: true,
3+
exclude: ['**/foo.js'],
34
selfDefending: false,
45
sourceMap: true
56
};

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

Lines changed: 77 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -814,51 +814,93 @@ describe('JavaScriptObfuscatorCLI', function (): void {
814814
});
815815

816816
describe('`--config` option is set', () => {
817-
const outputSourceMapPath: string = `${outputFilePath}.map`;
817+
describe('Base options', () => {
818+
const outputSourceMapPath: string = `${outputFilePath}.map`;
818819

819-
let isFileExist: boolean,
820-
sourceMapObject: any;
820+
let isFileExist: boolean,
821+
sourceMapObject: any;
821822

822-
before(() => {
823-
JavaScriptObfuscatorCLI.obfuscate([
824-
'node',
825-
'javascript-obfuscator',
826-
fixtureFilePath,
827-
'--output',
828-
outputFilePath,
829-
'--config',
830-
configFilePath
831-
]);
823+
before(() => {
824+
JavaScriptObfuscatorCLI.obfuscate([
825+
'node',
826+
'javascript-obfuscator',
827+
fixtureFilePath,
828+
'--output',
829+
outputFilePath,
830+
'--config',
831+
configFilePath
832+
]);
832833

833-
try {
834-
const content: string = fs.readFileSync(outputSourceMapPath, {encoding: 'utf8'});
834+
try {
835+
const content: string = fs.readFileSync(outputSourceMapPath, {encoding: 'utf8'});
835836

836-
isFileExist = true;
837-
sourceMapObject = JSON.parse(content);
838-
} catch (e) {
839-
isFileExist = false;
840-
}
841-
});
837+
isFileExist = true;
838+
sourceMapObject = JSON.parse(content);
839+
} catch (e) {
840+
isFileExist = false;
841+
}
842+
});
842843

843-
it('should create file with source map in the same directory as output file', () => {
844-
assert.equal(isFileExist, true);
845-
});
844+
it('should create file with source map in the same directory as output file', () => {
845+
assert.equal(isFileExist, true);
846+
});
846847

847-
it('source map from created file should contains property `version`', () => {
848-
assert.property(sourceMapObject, 'version');
849-
});
848+
it('source map from created file should contains property `version`', () => {
849+
assert.property(sourceMapObject, 'version');
850+
});
850851

851-
it('source map from created file should contains property `sources`', () => {
852-
assert.property(sourceMapObject, 'sources');
853-
});
852+
it('source map from created file should contains property `sources`', () => {
853+
assert.property(sourceMapObject, 'sources');
854+
});
855+
856+
it('source map from created file should contains property `names`', () => {
857+
assert.property(sourceMapObject, 'names');
858+
});
854859

855-
it('source map from created file should contains property `names`', () => {
856-
assert.property(sourceMapObject, 'names');
860+
after(() => {
861+
fs.unlinkSync(outputFilePath);
862+
fs.unlinkSync(outputSourceMapPath);
863+
});
857864
});
858865

859-
after(() => {
860-
fs.unlinkSync(outputFilePath);
861-
fs.unlinkSync(outputSourceMapPath);
866+
describe('`--exclude` option', () => {
867+
const directoryPath: string = `${fixturesDirName}/directory-obfuscation`;
868+
const outputFileName1: string = 'foo-obfuscated.js';
869+
const outputFileName2: string = 'bar-obfuscated.js';
870+
871+
let outputFixturesFilePath1: string,
872+
outputFixturesFilePath2: string,
873+
isFileExist1: boolean,
874+
isFileExist2: boolean;
875+
876+
before(() => {
877+
outputFixturesFilePath1 = `${directoryPath}/${outputFileName1}`;
878+
outputFixturesFilePath2 = `${directoryPath}/${outputFileName2}`;
879+
880+
JavaScriptObfuscatorCLI.obfuscate([
881+
'node',
882+
'javascript-obfuscator',
883+
directoryPath,
884+
'--config',
885+
configFilePath
886+
]);
887+
888+
isFileExist1 = fs.existsSync(outputFixturesFilePath1);
889+
isFileExist2 = fs.existsSync(outputFixturesFilePath2);
890+
});
891+
892+
it(`shouldn't create file \`${outputFileName1}\` in \`${fixturesDirName}\` directory`, () => {
893+
assert.equal(isFileExist1, false);
894+
});
895+
896+
it(`should create file \`${outputFileName2}\` with obfuscated code in \`${fixturesDirName}\` directory`, () => {
897+
assert.equal(isFileExist2, true);
898+
});
899+
900+
after(() => {
901+
rimraf.sync(outputFixturesFilePath1);
902+
rimraf.sync(outputFixturesFilePath2);
903+
});
862904
});
863905
});
864906

test/unit-tests/cli/utils/CLIUtils.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('CLIUtils', () => {
1313
const configFilePath: string = `../../../${configDirName}/${configFileName}`;
1414
const expectedResult: TInputOptions = {
1515
compact: true,
16+
exclude: ['**/foo.js'],
1617
selfDefending: false,
1718
sourceMap: true
1819
};

0 commit comments

Comments
 (0)
0