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

requirejs-memfiles

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

requirejs-memfiles - npm Package Compare versions

Comparing version 2.1.15-1 to 2.1.15-2

73

index.js

@@ -1,2 +0,2 @@

var fileApi, files, prim,
var fileApi, files, mutexLock, prim, queue,
path = require( "path" ),

@@ -119,4 +119,46 @@ requirejs = require( "requirejs" );

queue = [];
function enqueue() {
queue.push( arguments );
if ( queue.length === 1 ) {
run();
}
}
function dequeue() {
queue.shift();
run();
}
function run() {
var args = queue[ 0 ];
if ( args !== undefined ) {
setFiles.apply( {}, args );
}
}
function setFiles( _files, callback ) {
if ( mutexLock ) {
return callback( new Error( "Internal bug: concurrent calls not supported" ) );
}
mutexLock = true;
requirejs.define( "node/file", [ "prim" ], function( _prim ) {
prim = _prim;
return fileApi;
});
files = _files;
callback(function() {
files = {};
mutexLock = false;
dequeue();
});
}
/**
* requirejs.setFiles( files )
* requirejs.setFiles( files, callback )
*

@@ -130,13 +172,24 @@ * @files [Object] containing (path, data) key-value pairs, e.g.:

*
* @callback [Function] called with one argument: a callback function that must be called when
* use is complete.
*
* Example:
* ```javascript
* requirejs.setFiles( files, function( done ) {
* requirejs.optmize( config, function() {
* doSomething();
* done();
* }, function( error ) {
* doSomething( error );
* done();
* });
* });
*
* ```
*
*/
requirejs.setFiles = function( _files ) {
requirejs.define( "node/file", [ "prim" ], function( _prim ) {
prim = _prim;
return fileApi;
});
files = _files;
requirejs.setFiles = function( files, callback ) {
enqueue( files, callback );
};
module.exports = requirejs;

3

package.json
{
"name": "requirejs-memfiles",
"version": "2.1.15-1",
"version": "2.1.15-2",
"main": "index.js",

@@ -25,2 +25,3 @@ "repository": {

"devDependencies": {
"async": "0.9.0",
"chai": "1.10.x",

@@ -27,0 +28,0 @@ "jshint": "2.6.x",

@@ -0,1 +1,2 @@

var async = require( "async" );
var expect = require( "chai" ).expect;

@@ -5,27 +6,106 @@ var requirejs = require( "../index.js" );

describe( "requirejs.optimize", function() {
var files = {
"a.js": "define([\"./b\"], function( b ) { return b; });",
"b.js": "define(function() { return \"B\"; });"
};
it( "should build dist/output.js", function( done ) {
var files = {
"a.js": "define([\"./b\"], function( b ) { return b; });",
"b.js": "define(function() { return \"B\"; });"
};
requirejs.setFiles( files );
requirejs.optimize({
appDir: ".",
baseUrl: ".",
dir: "dist",
modules: [{
name: "output",
include: "a",
create: true
}]
}, function() {
expect( files ).to.include.keys( "dist/output.js" );
expect( files[ "dist/output.js" ] ).to.be.equal( "define(\"b\",[],function(){return\"B\"}),define(\"a\",[\"./b\"],function(e){return e}),define(\"output\",function(){});" );
done();
}, function( error ) {
expect( error ).to.be.null;
before(function( doneSetup ) {
requirejs.setFiles( files, function( doneRequirejsMemfiles ) {
requirejs.optimize({
appDir: ".",
baseUrl: ".",
dir: "dist",
modules: [{
name: "output",
include: "a",
create: true
}]
}, function() {
doneSetup();
doneRequirejsMemfiles();
}, function( error ) {
doneSetup( error );
doneRequirejsMemfiles();
});
});
});
it( "should build dist/output.js", function() {
expect( files ).to.include.keys( "dist/output.js" );
expect( files[ "dist/output.js" ] ).to.be.equal( "define(\"b\",[],function(){return\"B\"}),define(\"a\",[\"./b\"],function(e){return e}),define(\"output\",function(){});" );
});
});
describe( "concurrent requirejs.optimize calls", function() {
var filesA, filesB;
filesA = {
"a.js": "define([\"./b\"], function( b ) { return b; });",
"b.js": "define(function() { return \"B\"; });"
};
filesB = {
"a.js": "define([\"./b\"], function( b ) { return b; });",
"b.js": "define(function() { return \"B\"; });"
};
before(function( doneSetup ) {
async.parallel([
function( callback ) {
requirejs.setFiles( filesA, function( doneRequirejsMemfiles ) {
requirejs.optimize({
appDir: ".",
baseUrl: ".",
dir: "dist",
modules: [{
name: "outputA",
include: "a",
create: true
}]
}, function() {
callback();
doneRequirejsMemfiles();
}, function( error ) {
callback( error );
doneRequirejsMemfiles();
});
});
},
function( callback ) {
requirejs.setFiles( filesB, function( doneRequirejsMemfiles ) {
requirejs.optimize({
appDir: ".",
baseUrl: ".",
dir: "dist",
modules: [{
name: "outputB",
include: "a",
create: true
}]
}, function() {
callback();
doneRequirejsMemfiles();
}, function( error ) {
callback( error );
doneRequirejsMemfiles();
});
});
}
], function( error ) {
doneSetup( error );
});
});
it( "should build dist/outputA.js", function() {
expect( filesA ).to.include.keys( "dist/outputA.js" );
expect( filesA ).to.not.include.keys( "dist/outputB.js" );
expect( filesA[ "dist/outputA.js" ] ).to.be.equal( "define(\"b\",[],function(){return\"B\"}),define(\"a\",[\"./b\"],function(e){return e}),define(\"outputA\",function(){});" );
});
it( "should build dist/outputB.js", function() {
expect( filesB ).to.include.keys( "dist/outputB.js" );
expect( filesB ).to.not.include.keys( "dist/outputA.js" );
expect( filesB[ "dist/outputB.js" ] ).to.be.equal( "define(\"b\",[],function(){return\"B\"}),define(\"a\",[\"./b\"],function(e){return e}),define(\"outputB\",function(){});" );
});
});
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