New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bant-normalize

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bant-normalize - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

test/locals.js

104

index.js
var through = require('through2');
var path = require('path');
var defined = require('defined');
var toposort = require('toposort');
var debug = require('debug')('bant:normalize');
var compact = require('bant-compact');
var extend = require('util')._extend;
var inherits = require('util').inherits;
var Transform = require('readable-stream/transform');
module.exports = function (opts) {
module.exports = normalize;
inherits(normalize, Transform);
function normalize (opts) {
if (!(this instanceof normalize)) return new normalize(opts);
if (!opts) opts = {};
var rows = [];
this._opts = opts;
this._raw = [];
return through.obj(write, end);
Transform.call(this, { objectMode: true });
}
function write (row, enc, cb) {
if (isVinylBuffer(row) && row.isBuffer()) {
var basedir = path.dirname(row.path);
normalize.prototype._transform = function (row, enc, cb) {
var basedir, opts = this._opts;
if (isVinyl(row)) {
if (row.isStream()) throw 'not implemented';
else if (row.isBuffer()) {
basedir = path.dirname(row.path);
var vinyl = row.clone();
row = JSON.parse(row.contents);
row.vinyl = vinyl;
row.basedir = basedir;
}
rows.push(row);
cb();
}
function end () { normalize.bind(this, rows, opts)(); }
row.name = defined(row.name, row.expose);
if ('string' === typeof row.name) {
row.expose = defined(row.expose, row.name);
row.basedir = path.resolve(defined(row.basedir, opts.basedir, process.cwd()));
this._raw.push(row);
}
cb();
};
function normalize (rows, opts) {
normalize.prototype._flush = function (cb) {
var self = this,
nodes = [], edges = [], index = {};
rows.forEach(function (row, i) {
var files = [],
basedir = path.resolve(defined(row.basedir, opts.basedir, process.cwd())),
scripts = [];
row.basedir = basedir;
row.name = defined(row.name, 'module_' + i);
row.locals = defined(row.locals, []);
if (has(row, 'main')) {
var obj = {
file: row.main,
expose: defined(row.expose, row.name)
};
if (!isStream(row.main))
obj.file = path.resolve(basedir, row.main);
else
obj.basedir = basedir;
row.main = obj;
scripts.push(obj);
}
row.scripts = scripts.concat(defined(row.scripts, []).filter(Boolean)
.map(function (file) {
var obj = { file: row.main };
if (!isStream(file))
obj.file = path.resolve(basedir, file);
else
obj.basedir = basedir;
return obj;
}));
nodes.push(row.name);
row.locals.forEach(function (name) {
edges.push([row.name, name]);
});
index[row.name] = row;
tree = compact(this._raw);
tree.forEach(function (branch) {
self.push(branch);
});
rows = toposort.array(nodes, edges).reverse().map(function (name) {
return index[name];
});
rows.forEach(function (row) { self.push(row); });
self.push(null);
}
};
function isVinylBuffer (row) { return row && typeof row.isBuffer === 'function'; }
function isVinyl (row) { return row && typeof row.isBuffer === 'function'; }
function has (row, key) { return row && row.hasOwnProperty(key); }
function isStream (s) { return s && typeof s.pipe === 'function'; }
{
"name": "bant-normalize",
"version": "0.1.2",
"version": "0.1.3",
"description": "",

@@ -10,10 +10,12 @@ "main": "index.js",

"dependencies": {
"bant-compact": "^0.1.1",
"debug": "^2.1.1",
"defined": "0.0.0",
"readable-stream": "^1.0.33",
"through2": "^0.6.3",
"toposort": "^0.2.10"
"vinyl-fs": "^0.3.13"
},
"devDependencies": {
"tape": "^3.5.0",
"vinyl-fs": "^0.3.13"
"vinyl": "^0.4.6"
},

@@ -20,0 +22,0 @@ "scripts": {

@@ -5,17 +5,15 @@ var normalize = require('..');

var fs = require('vinyl-fs');
var File = require('vinyl');
var test = require('tape');
test('vinyl', function (t) {
var rows = {};
t.plan(2);
fs.src([__dirname + '/vinyl/*.json'])
.pipe(normalize())
.pipe(through.obj(function (row, enc, cb) {
rows[row.name] = row;
t.equal(row.basedir, __dirname + '/vinyl');
t.ok(row.vinyl instanceof File);
cb();
}, function () {
t.equal(rows.x.basedir, __dirname + '/vinyl');
t.equal(rows.y.basedir, __dirname + '/vinyl');
t.end();
}));
});
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc