From d6ac8319c0cadd217a5450762ec6b7b94b1c1c20 Mon Sep 17 00:00:00 2001 From: David Refoua Date: Sat, 30 Mar 2019 07:22:33 +0430 Subject: [PATCH 1/5] use gulp-sourcemaps instead --- README.md | 47 ++++++++++++++++++++++++++++++++++++++++++++--- index.js | 25 +++++++++++++++++++------ package.json | 4 ++-- 3 files changed, 65 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6f6a59c..a630320 100644 --- a/README.md +++ b/README.md @@ -28,10 +28,51 @@ gulp.src('file.js') ```javascript gulp.src('file.js') .pipe(javascriptObfuscator({ - compact:true, - sourceMap: true + compact: true })) .pipe(gulp.dest('dist')); ``` -Using **sourceMap** option with value set to **true** will also output a _.map_ file to Gulp stream. +The only exception is obfuscator's `sourceMap` option which will be handled automatically. + +## Source Maps + +With version `1.1.6` onwards, gulp-javascript-obfuscator can be used in tandem with [gulp-sourcemaps](https://github.com/floridoo/gulp-sourcemaps) in order to generate source maps for your javascript files. + +You will need to initialize gulp-sourcemaps prior to running gulp-javascript-obfuscator and write the source maps after, as such: + +```javascript +const sourcemaps = require('gulp-sourcemaps'); + +gulp.src('file.js') + .pipe(sourcemaps.init()) + .pipe(javascriptObfuscator({ + compact: true + })) + .pipe(sourcemaps.write()) + .pipe(gulp.dest('dist')); +``` + +This will output a `file.js.map` file to the **dist** directory. + +You can chain other gulp plugins as well: + +```javascript +const sourcemaps = require('gulp-sourcemaps'); + +gulp.src('file.js') + .pipe(sourcemaps.init()) + // use babel to pre-process javascript files + .pipe(babel({ + presets: ['@babel/preset-env'] + })) + .pipe(javascriptObfuscator({ + compact: true + })) + .pipe(sourcemaps.write()) + .pipe(gulp.dest('dist')); +``` + +### Alternative source maps method + +For backwards compatibility, using obfuscator's **sourceMap** option set to **true** will output a _.map_ file to Gulp stream. ([This is _deprecated_ and not recommended for future use.](https://github.com/javascript-obfuscator/gulp-javascript-obfuscator/pull/18)) diff --git a/index.js b/index.js index 78b0d12..2a7dd71 100644 --- a/index.js +++ b/index.js @@ -2,22 +2,35 @@ const through2 = require('through2'); const Vinyl = require('vinyl'); const JavaScriptObfuscator = require('javascript-obfuscator'); const PluginError = require('plugin-error'); +const applySourceMap = require('vinyl-sourcemaps-apply'); module.exports = function gulpJavaScriptObfuscator (options = {}) { return through2.obj(function (file, enc, cb) { if (file.isNull()) return cb(null, file); if (!file.isBuffer()) throw new PluginError('gulp-javascript-obfuscator', 'Only Buffers are supported!'); + if (file.sourceMap) { + options.sourceMap = true; + options.inputFileName = file.relative; + options.sourceMapMode = 'separate'; + } try { const obfuscationResult = JavaScriptObfuscator.obfuscate(String(file.contents), options); file.contents = new Buffer(obfuscationResult.getObfuscatedCode()); if (options.sourceMap && options.sourceMapMode !== 'inline') { - this.push(new Vinyl({ - cwd: file.cwd, - base: file.base, - path: file.path + '.map', - contents: new Buffer(obfuscationResult.getSourceMap()) - })) + if ( file.sourceMap ) { + const sourceMap = JSON.parse(obfuscationResult.getSourceMap()); + sourceMap.file = file.sourceMap.file; + applySourceMap(file, sourceMap); + } + else { + this.push(new Vinyl({ + cwd: file.cwd, + base: file.base, + path: file.path + '.map', + contents: new Buffer(obfuscationResult.getSourceMap()) + })) + } } return cb(null, file); } catch (err) { diff --git a/package.json b/package.json index 056f59d..fe270bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gulp-javascript-obfuscator", - "version": "1.1.5", + "version": "1.1.6", "description": "Gulp plugin for javascript-obfuscator Node.JS package", "homepage": "https://github.com/javascript-obfuscator/gulp-javascript-obfuscator", "repository": { @@ -27,7 +27,7 @@ ], "author": "Wain-PC", "contributors": [ - "adamxtokyo" + "adamxtokyo", "DRSDavidSoft" ], "license": "MIT", "dependencies": { From b575e02a31877dc871faaa842da77350a01bae84 Mon Sep 17 00:00:00 2001 From: David Refoua Date: Sat, 30 Mar 2019 07:34:16 +0430 Subject: [PATCH 2/5] update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a630320..f72de74 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ gulp.src('file.js') .pipe(gulp.dest('dist')); ``` -The only exception is obfuscator's `sourceMap` option which will be handled automatically. +The only exception is obfuscator's `sourceMap` option which must not be set, as it will be handled automatically when using `gulp-sourcemaps`. ## Source Maps @@ -75,4 +75,4 @@ gulp.src('file.js') ### Alternative source maps method -For backwards compatibility, using obfuscator's **sourceMap** option set to **true** will output a _.map_ file to Gulp stream. ([This is _deprecated_ and not recommended for future use.](https://github.com/javascript-obfuscator/gulp-javascript-obfuscator/pull/18)) +For backwards compatibility, if `gulp-sourcemaps` is not used and obfuscator's **sourceMap** option is set to **true**, a _.map_ file will be thrown to Gulp stream. ([This method is _deprecated_ and not recommended for future use.](https://github.com/javascript-obfuscator/gulp-javascript-obfuscator/pull/18#backwards-compatibility)) From 2ec3a457c9e4fa740bcd6a70f6be2c65c1513b28 Mon Sep 17 00:00:00 2001 From: David Refoua Date: Sat, 30 Mar 2019 07:37:33 +0430 Subject: [PATCH 3/5] remove deprecated method --- index.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 2a7dd71..7edb040 100644 --- a/index.js +++ b/index.js @@ -17,20 +17,10 @@ module.exports = function gulpJavaScriptObfuscator (options = {}) { try { const obfuscationResult = JavaScriptObfuscator.obfuscate(String(file.contents), options); file.contents = new Buffer(obfuscationResult.getObfuscatedCode()); - if (options.sourceMap && options.sourceMapMode !== 'inline') { - if ( file.sourceMap ) { - const sourceMap = JSON.parse(obfuscationResult.getSourceMap()); - sourceMap.file = file.sourceMap.file; - applySourceMap(file, sourceMap); - } - else { - this.push(new Vinyl({ - cwd: file.cwd, - base: file.base, - path: file.path + '.map', - contents: new Buffer(obfuscationResult.getSourceMap()) - })) - } + if (file.sourceMap) { + const sourceMap = JSON.parse(obfuscationResult.getSourceMap()); + sourceMap.file = file.sourceMap.file; + applySourceMap(file, sourceMap); } return cb(null, file); } catch (err) { From 53c84342f59805a6c51b8d109596688e783280b5 Mon Sep 17 00:00:00 2001 From: David Refoua Date: Sat, 30 Mar 2019 07:38:00 +0430 Subject: [PATCH 4/5] bump version to avoid breaking changes --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fe270bb..3b47950 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gulp-javascript-obfuscator", - "version": "1.1.6", + "version": "2.0.0", "description": "Gulp plugin for javascript-obfuscator Node.JS package", "homepage": "https://github.com/javascript-obfuscator/gulp-javascript-obfuscator", "repository": { From 6c63d4568c2b270a9ecde7dd05d3920df339be3b Mon Sep 17 00:00:00 2001 From: David Refoua Date: Sat, 30 Mar 2019 07:39:25 +0430 Subject: [PATCH 5/5] update docs --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index f72de74..a08c783 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ The only exception is obfuscator's `sourceMap` option which must not be set, as ## Source Maps -With version `1.1.6` onwards, gulp-javascript-obfuscator can be used in tandem with [gulp-sourcemaps](https://github.com/floridoo/gulp-sourcemaps) in order to generate source maps for your javascript files. +`gulp-javascript-obfuscator` can be used in tandem with [gulp-sourcemaps](https://github.com/floridoo/gulp-sourcemaps) in order to generate source maps for your javascript files. You will need to initialize gulp-sourcemaps prior to running gulp-javascript-obfuscator and write the source maps after, as such: @@ -73,6 +73,3 @@ gulp.src('file.js') .pipe(gulp.dest('dist')); ``` -### Alternative source maps method - -For backwards compatibility, if `gulp-sourcemaps` is not used and obfuscator's **sourceMap** option is set to **true**, a _.map_ file will be thrown to Gulp stream. ([This method is _deprecated_ and not recommended for future use.](https://github.com/javascript-obfuscator/gulp-javascript-obfuscator/pull/18#backwards-compatibility)) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy