Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

browserify-global-pack

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browserify-global-pack - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

29

index.js

@@ -85,21 +85,18 @@ 'use strict';

function writeDeps(verbose) {
return (deps) => _(deps)
.group('outfile')
return deps => _(deps)
.reduce({}, (files, dep) => {
const outfiles = Array.isArray(dep.outfile) ? dep.outfile : [dep.outfile];
outfiles.forEach(outfile => {
files[outfile] = (files[outfile] || '') + dep.content + '\n';
if (verbose) console.log(`${dep.sourceFile || dep.id} -> ${outfile}`);
});
return files;
})
.flatMap(_.pairs)
.flatMap(writeDepGroup(verbose));
.flatMap(([file, content]) => writeFile(file, content))
.map(() => deps)
.collect();
}
/**
* Write groups of deps
* @param {boolean} verbose Log writes
* @return {Stream}
*/
function writeDepGroup(verbose) {
return ([outfile, deps]) => {
return _(deps)
.reduce('', (prev, dep) => prev += dep.content + '\n')
.flatMap(allContent => writeFile(outfile, allContent))
.doto(() => verbose && deps.forEach(dep => console.log(`${dep.sourceFile || dep.id} -> ${outfile}`)));
};
}

@@ -106,0 +103,0 @@ module.exports = function browserifyGlobalPack(b, opts) {

{
"name": "browserify-global-pack",
"version": "1.2.1",
"version": "1.3.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -39,8 +39,9 @@ # browserify-global-pack

* `writeToDir`: Mandatory unless `getOutfile` is set. String describing the path to the directory where deps will be saved.
* `getOutfile`: Mandatory unless `writeToDir` is set. Function. The first argument is a module-dep object. Every dep in the bundle passes through this function, which should return the path (string) to which the dep should be saved. If this function returns the same path for multiple deps, those deps will be combined into one file. Examples:
* `getOutfile`: Mandatory unless `writeToDir` is set. Function. The first argument is a module-dep object. Every dep in the bundle passes through this function, which should return the path (string) to which the dep should be saved. If this function returns the same path for multiple deps, those deps will be combined into one file. If the function returns an array, the dep will be written to multiple files. Examples:
* `(dep) => path.join('bundle', 'dep-' + dep.id + '.js')` saves deps to the `bundle` folder and prefix their filenames with `dep-`.
* `(dep) => 'deps.js'` save all deps to a single file, `deps.js`.
* `(dep) => path.join('bundle', (dep.id === 'a' || dep.id === 'b') ? 'group1.js' : 'group2.js')` saves modules `a` and `b` to a `group1.js` file and all other deps to a `group2.js` file.
* `(dep) => ['a.js', 'b.js']` save all deps to two files, `a.js` and `b.js`.
* `cache`: Optional. Array. If set, this plugin will save all deps to this array before writing them out. If deps are already in this array when bundling, any deps in it that do not appear in the bundle will be added to the bundle.
* `scope`: Optional. String. [Global-pack](https://www.npmjs.com/package/global-pack) scope. Defaults to `window.modules`.
* `verbose`: Optional. Boolean. If `true`, log each time a dep is written.

@@ -127,2 +127,22 @@ const expect = require('chai').expect,

it ('writes a module to multiple files if getOutfile returns array for it', function (done) {
const bundler = browserify({fullPaths: true})
.require(path.join(__dirname, 'input', './a.js'))
.plugin(browserifyGlobalPack, {
getOutfile: () => [
path.join(__dirname, 'bundle', 'out-1.js'),
path.join(__dirname, 'bundle', 'out-2.js')
]
}),
bundlePromise = _(bundler.bundle()).toPromise(Promise);
bundlePromise
.then(() => {
assertOut('out-1.js', expectedOutput.join(''));
assertOut('out-2.js', expectedOutput.join(''));
done();
})
.catch(done);
});
it ('collects deps in cache array if provided', function (done) {

@@ -193,2 +213,3 @@ const cache = [],

});
});

@@ -195,0 +216,0 @@

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