Skip to content

Commit 968eec6

Browse files
authored
Merge pull request javascript-obfuscator#278 from javascript-obfuscator/input-file-name-option
`inputFileName` option
2 parents 6311cca + a003a6e commit 968eec6

15 files changed

Lines changed: 145 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Change Log
33
v0.17.0
44
---
55
* **Browser version**: Added browser version dist
6+
* **New Node API option:** `inputFileName` allows to set name of the input file with source code. This name will used internally, for example, for source map generation.
67
* [#274](https://github.com/javascript-obfuscator/javascript-obfuscator/pull/274)`domainLock` now will work in SVG.
78
<br/>
89
Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/273

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ Following options are available for the JS Obfuscator:
293293
domainLock: [],
294294
identifierNamesGenerator: 'hexadecimal',
295295
identifiersPrefix: '',
296+
inputFileName: '',
296297
log: false,
297298
renameGlobals: false,
298299
reservedNames: [],
@@ -600,6 +601,11 @@ Sets prefix for all global identifiers.
600601
601602
Use this option when you want to obfuscate multiple files. This option helps to avoid conflicts between global identifiers of these files. Prefix should be different for every file.
602603
604+
### `inputFileName`
605+
Type: `string` Default: `''`
606+
607+
Allows to set name of the input file with source code. This name will used internally for source map generation.
608+
603609
### `log`
604610
Type: `boolean` Default: `false`
605611

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.

src/JavaScriptObfuscator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
197197
};
198198

199199
if (this.options.sourceMap) {
200-
escodegenParams.sourceMap = 'sourceMap';
200+
escodegenParams.sourceMap = this.options.inputFileName || 'sourceMap';
201201
escodegenParams.sourceContent = sourceCode;
202202
}
203203

src/cli/JavaScriptObfuscatorCLI.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,13 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
173173
const configFilePath: string | undefined = this.inputCLIOptions.config;
174174
const configFileLocation: string = configFilePath ? path.resolve(configFilePath, '.') : '';
175175
const configFileOptions: TInputOptions = configFileLocation ? CLIUtils.getUserConfig(configFileLocation) : {};
176+
const inputFileName: string = path.basename(this.inputPath);
176177

177178
return {
178179
...DEFAULT_PRESET,
179180
...configFileOptions,
180-
...inputCLIOptions
181+
...inputCLIOptions,
182+
inputFileName
181183
};
182184
}
183185

src/interfaces/options/IOptions.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface IOptions {
1616
readonly domainLock: string[];
1717
readonly identifierNamesGenerator: IdentifierNamesGenerator;
1818
readonly identifiersPrefix: string;
19+
readonly inputFileName: string;
1920
readonly log: boolean;
2021
readonly renameGlobals: boolean;
2122
readonly reservedNames: string[];

src/options/Options.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ export class Options implements IOptions {
118118
@IsString()
119119
public readonly identifiersPrefix!: string;
120120

121+
/**
122+
* @type {string}
123+
*/
124+
@IsString()
125+
public readonly inputFileName!: string;
126+
121127
/**
122128
* @type {boolean}
123129
*/

src/options/OptionsNormalizer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ControlFlowFlatteningThresholdRule } from './normalizer-rules/ControlFl
99
import { DeadCodeInjectionRule } from './normalizer-rules/DeadCodeInjectionRule';
1010
import { DeadCodeInjectionThresholdRule } from './normalizer-rules/DeadCodeInjectionThresholdRule';
1111
import { DomainLockRule } from './normalizer-rules/DomainLockRule';
12+
import { InputFileNameRule } from './normalizer-rules/InputFileNameRule';
1213
import { SelfDefendingRule } from './normalizer-rules/SelfDefendingRule';
1314
import { SourceMapBaseUrlRule } from './normalizer-rules/SourceMapBaseUrlRule';
1415
import { SourceMapFileNameRule } from './normalizer-rules/SourceMapFileNameRule';
@@ -26,6 +27,7 @@ export class OptionsNormalizer implements IOptionsNormalizer {
2627
DeadCodeInjectionRule,
2728
DeadCodeInjectionThresholdRule,
2829
DomainLockRule,
30+
InputFileNameRule,
2931
SelfDefendingRule,
3032
SourceMapBaseUrlRule,
3133
SourceMapFileNameRule,

0 commit comments

Comments
 (0)