Socket
Socket
Sign inDemoInstall

obfuscator

Package Overview
Dependencies
11
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.0 to 0.4.0

.jshintignore

28

History.md
# Release History
0.4.0 / 2014-02-26
==================
## 0.3.0
* Add test for GH-12
* Fix mocked require tests
* Cleanup makefile
* Refactor JSON file support
* Obfuscate all strings
* Remove component-builder example
0.3.0 / 2013-12-20
==================
- removed grunt support; use [grunt-obfuscator](https://github.com/stephenmathieson/grunt-obfuscator) instead.
## 0.2.2
0.2.2 / 2013-10-22
==================
- update uglify-js to ~2.4.0
## 0.2.1
0.2.1 / 2013-09-12
==================
- fixed grunt task ([#9](https://github.com/stephenmathieson/node-obfuscator/pull/9))
## 0.2.0
0.2.0 / 2013-08-13
==================

@@ -23,3 +35,4 @@ - fixed windows pathing bug ([#8](https://github.com/stephenmathieson/node-obfuscator/pull/8))

## 0.1.0
0.1.0 / 2013-05-17
==================

@@ -29,4 +42,5 @@ - added `string` option, optionally obfuscating strings contained in your package

## 0.0.2
0.0.2 / 2013-02-10
==================
- initial release
'use strict';
var fs = require('fs'),
path = require('path'),
uglify = require('uglify-js'),
utils = require('./utils');
var fs = require('fs');
var path = require('path');
var uglify = require('uglify-js');
var utils = require('./utils');
var rJSON = /\.json$/,
__require = fs.readFileSync(path.join(__dirname, './require.js'), 'utf-8');
var rJSON = /\.json$/;
var __require = fs.readFileSync(path.join(__dirname, './require.js'), 'utf-8');

@@ -144,4 +144,3 @@

obfuscator.register = function (root, file, cb) {
var code,
filename = dotslash(path.relative(root, file));
var filename = dotslash(path.relative(root, file));

@@ -153,5 +152,6 @@ fs.readFile(file, 'utf-8', function (err, data) {

code = 'require.register("' + filename + '",'
+ 'function (module, exports, require) {'
+ (rJSON.test(file)
var code =
'require.register("' + filename + '",'
+ 'function (module, exports, require) {'
+ (rJSON.test(file)
// just export json

@@ -161,3 +161,3 @@ ? 'module.exports = ' + data + ';'

: data)
+ '});';
+ '});';
return cb(null, code);

@@ -176,7 +176,5 @@ });

obfuscator.concatenate = function (options, cb) {
var root = options.root,
entry = dotslash(path.relative(root, options.entry)),
files = options.files,
index = -1,
built = [];
var entry = dotslash(path.relative(options.root, options.entry));
var index = -1;
var built = [];

@@ -200,3 +198,3 @@ function complete() {

index++;
var file = files[index];
var file = options.files[index];

@@ -209,3 +207,3 @@ // no remaining files?

// register the file
obfuscator.register(root, file, function (err, data) {
obfuscator.register(options.root, file, function (err, data) {
if (err) {

@@ -212,0 +210,0 @@ return cb(err);

@@ -0,38 +1,32 @@

// based on TJ Holowaychuk's commonjs require binding
/*global native_require*/
function require(p, root) {
// third-party module? use native require
if ('.' != p[0] && '/' != p[0])
return native_require(p);
// jshint maxcomplexity: 5, maxstatements: 15
root = root || 'root';
function require(p) {
var path, module;
var path = require.resolve(p);
// third-party module? use native require
if (p[0] !== '.') {
return native_require(p);
}
// if it's a non-registered json file, it
// must be at the root of the project
if (!path && /\.json$/i.test(p))
return native_require('./' + require.basename(p));
if (require.json.test(p)) {
// TODO hack: all json must be contained in project root
return native_require('./' + require.basename(p));
}
var module = require.cache[path];
path = require.resolve(p);
module = require.cache[path];
if (!module)
throw new Error('failed to require "' + p + '" from ' + root);
if (!module) {
throw new Error('failed to require "' + p + '"');
}
if (!module.exports) {
module.exports = {};
module.call(module.exports, module, module.exports,
require.relative(path));
}
if (!module.exports) {
module.exports = {};
module.call(module.exports, module, module.exports,
require.relative(path));
}
return module.exports;
return module.exports;
}
require.json = /\.json$/i;
// same as node's `require`

@@ -45,47 +39,45 @@ require.cache = {};

require.resolve = function (path) {
var orig = path,
reg = path + '.js',
index = path + '/index.js';
// GH-12
if ('.' != path[0]) return native_require.resolve(path);
return (require.cache[reg] && reg) ||
(require.cache[index] && index) || orig;
var paths = [
path,
path + '.js',
path + '/index.js',
path + '.json',
path + '/index.json'
];
for (var i = 0, p; p = paths[i]; i++) {
if (require.cache[p]) return p;
}
};
require.register = function (path, fn) {
require.cache[path] = fn;
require.cache[path] = fn;
};
require.relative = function (parent) {
function _relative(p) {
var path, segs, i, len, seg;
function relative(p) {
if ('.' != p[0]) return require(p);
if ('.' !== p[0]) {
return require(p);
}
var path = parent.split('/');
var segs = p.split('/');
path.pop();
path = parent.split('/');
segs = p.split('/');
path.pop();
for (var i = 0, len = segs.length; i < len; i += 1) {
var seg = segs[i];
if ('..' == seg) {
path.pop();
} else if ('.' != seg) {
path.push(seg);
}
}
for (i = 0, len = segs.length; i < len; i += 1) {
seg = segs[i];
if (seg === '..') {
path.pop();
} else if (seg !== '.') {
path.push(seg);
}
}
return require(path.join('/'), parent);
}
return require(path.join('/'));
}
_relative.resolve = function (p) {
// TODO hack: all json must be contained in project root
return require.json.test(p)
? './' + require.basename(p)
: require.resolve(p);
};
_relative.cache = require.cache;
return _relative;
relative.resolve = require.resolve;
relative.cache = require.cache;
return relative;
};

@@ -146,7 +146,2 @@

*
* Strings which contain non-alphanumeric characters
* other than `.-_/` will be ignored.
*
* Strings not wrapped in double quotes will be ignored.
*
* Example:

@@ -165,3 +160,3 @@ *

exports.strings = function (js) {
var expression = /("[a-z\d\/\.\_\-]+")/gi;
var expression = /("(?:(?!")[^\\\n]|\\.)*"|'(?:(?!')[^\\\n]|\\.)*')/g;

@@ -168,0 +163,0 @@ function replacer(match, str) {

{
"name": "obfuscator",
"version": "0.3.0",
"version": "0.4.0",
"scripts": {
"test": "make validate"
"test": "make all"
},

@@ -28,3 +28,3 @@ "description": "Code protection / obfuscation for node",

"better-assert": "~1.0.0",
"glob": "~3.2.6"
"glob": "~3.2.7"
},

@@ -31,0 +31,0 @@ "bin": "bin/obfuscator",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc