mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Improved source map file name normalizer logic
Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/406
This commit is contained in:
@@ -4,6 +4,8 @@ import * as path from 'path';
|
||||
|
||||
import { TObject } from '../../types/TObject';
|
||||
|
||||
import { StringSeparator } from '../../enums/StringSeparator';
|
||||
|
||||
import { JavaScriptObfuscatorCLI } from '../JavaScriptObfuscatorCLI';
|
||||
|
||||
export class CLIUtils {
|
||||
@@ -14,11 +16,11 @@ export class CLIUtils {
|
||||
public static getOutputCodePath (inputPath: string): string {
|
||||
return path
|
||||
.normalize(inputPath)
|
||||
.split('.')
|
||||
.split(StringSeparator.Dot)
|
||||
.map((value: string, index: number) => {
|
||||
return index === 0 ? `${value}${JavaScriptObfuscatorCLI.obfuscatedFilePrefix}` : value;
|
||||
})
|
||||
.join('.');
|
||||
.join(StringSeparator.Dot);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,7 +36,7 @@ export class CLIUtils {
|
||||
}
|
||||
|
||||
if (!/\.js\.map$/.test(outputCodePath)) {
|
||||
outputCodePath = `${outputCodePath.split('.')[0]}.js.map`;
|
||||
outputCodePath = `${outputCodePath.split(StringSeparator.Dot)[0]}.js.map`;
|
||||
} else if (/\.js$/.test(outputCodePath)) {
|
||||
outputCodePath += '.map';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export enum StringSeparator {
|
||||
Dot = '.'
|
||||
}
|
||||
@@ -2,6 +2,8 @@ import { TOptionsNormalizerRule } from '../../types/options/TOptionsNormalizerRu
|
||||
|
||||
import { IOptions } from '../../interfaces/options/IOptions';
|
||||
|
||||
import { StringSeparator } from '../../enums/StringSeparator';
|
||||
|
||||
/**
|
||||
* @param {IOptions} options
|
||||
* @returns {IOptions}
|
||||
@@ -12,9 +14,9 @@ export const InputFileNameRule: TOptionsNormalizerRule = (options: IOptions): IO
|
||||
if (inputFileName) {
|
||||
inputFileName = inputFileName
|
||||
.replace(/^\/+/, '')
|
||||
.split('.')
|
||||
.split(StringSeparator.Dot)
|
||||
.slice(0, -1)
|
||||
.join('.') || inputFileName;
|
||||
.join(StringSeparator.Dot) || inputFileName;
|
||||
|
||||
options = {
|
||||
...options,
|
||||
|
||||
@@ -2,6 +2,8 @@ import { TOptionsNormalizerRule } from '../../types/options/TOptionsNormalizerRu
|
||||
|
||||
import { IOptions } from '../../interfaces/options/IOptions';
|
||||
|
||||
import { StringSeparator } from '../../enums/StringSeparator';
|
||||
|
||||
/**
|
||||
* @param {IOptions} options
|
||||
* @returns {IOptions}
|
||||
@@ -12,7 +14,18 @@ export const SourceMapFileNameRule: TOptionsNormalizerRule = (options: IOptions)
|
||||
if (sourceMapFileName) {
|
||||
sourceMapFileName = sourceMapFileName
|
||||
.replace(/^\/+/, '')
|
||||
.split('.')[0];
|
||||
.replace(/(?:\.js)?(?:\.map)?$/, '');
|
||||
|
||||
let sourceMapFileNameParts: string[] = sourceMapFileName.split(StringSeparator.Dot);
|
||||
const sourceMapFileNamePartsCount: number = sourceMapFileNameParts.length;
|
||||
const lastPart: string = sourceMapFileNameParts[sourceMapFileNamePartsCount - 1];
|
||||
|
||||
// try to predict if last part is extension or not
|
||||
if (sourceMapFileNamePartsCount > 1 && lastPart.length <= 3) {
|
||||
sourceMapFileNameParts = sourceMapFileNameParts.slice(0, -1);
|
||||
}
|
||||
|
||||
sourceMapFileName = sourceMapFileNameParts.join(StringSeparator.Dot);
|
||||
|
||||
options = {
|
||||
...options,
|
||||
|
||||
Reference in New Issue
Block a user