From 236b826e4ee465bfec9d04988a4bb6ce7323bced Mon Sep 17 00:00:00 2001 From: softworkz Date: Fri, 30 Jun 2023 00:29:19 +0200 Subject: [PATCH 1/2] Bump to javascript-obfuscator 4.0.0 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5bc6523..633f91a 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ }, "dependencies": { "chalk": "^1.0.0", - "javascript-obfuscator": "^2.0.0" + "javascript-obfuscator": "^4.0.0" }, "devDependencies": { "grunt": "^1.0.0", @@ -28,7 +28,7 @@ "grunt-contrib-nodeunit": "^1.0.0" }, "peerDependencies": { - "javascript-obfuscator": "^2.0.0" + "javascript-obfuscator": "^4.0.0" }, "keywords": [ "gruntplugin", From e81024c7fea22474cf21ee852d2abbe3e5084eea Mon Sep 17 00:00:00 2001 From: softworkz Date: Fri, 30 Jun 2023 00:30:11 +0200 Subject: [PATCH 2/2] Automatically generate identifiersPrefix --- README.md | 7 +++++++ tasks/obfuscator.js | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index da9f1b3..1037486 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,13 @@ _Note that at this time the `sourceMap` isn't implemented in this plugin._ In addition to the obfuscator options, you can also use: +#### baseIdentifiersPrefix +Type: `String` +Default: `'_'` + +This string will be used as a prefix for the identifiersPrefix values. It must not be numeric. The identifiersPrefix will be set to `'baseIdentifiersPrefix' + n` where 'n' is an auto-incrementing number. + + #### banner Type: `String` Default: `''` diff --git a/tasks/obfuscator.js b/tasks/obfuscator.js index df29c43..6d5dfe6 100644 --- a/tasks/obfuscator.js +++ b/tasks/obfuscator.js @@ -53,13 +53,17 @@ module.exports = function (grunt) { var filenameDest = getFilename(file.dest); + var execOptions = Object.assign({ + identifiersPrefix: (options.baseIdentifiersPrefix || '_') + created.files + }, options); + if (filenameDest) { try { var totalCode = availableFiles.map(function (file) { return grunt.file.read(file); }).join(''); - obfuscated = obfuscate(totalCode, options); + obfuscated = obfuscate(totalCode, execOptions); } catch (err) { grunt.log.error(err); @@ -76,7 +80,7 @@ module.exports = function (grunt) { try { var code = grunt.file.read(fileSrc); - obfuscated = obfuscate(code, options); + obfuscated = obfuscate(code, execOptions); } catch (err) { grunt.log.error(err);