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

enhanced-require

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enhanced-require - npm Package Compare versions

Comparing version 0.4.0-beta12 to 0.4.0-beta13

49

lib/RequireContext.js

@@ -143,5 +143,7 @@ var fs = require("fs");

// check for resource cache
var content = this.root.contentCache[filename];
if(!content) {
content = this.root.contentCache[filename] = fs.readFileSync(filename);
if(filename) {
var content = this.root.contentCache[filename];
if(!content) {
content = this.root.contentCache[filename] = fs.readFileSync(filename);
}
}

@@ -157,6 +159,8 @@

request,
loaders, [filename],
[content],
loaders, filename ? [filename] : [],
filename ? [content] : [],
{
loaderType: "loader"
loaderType: "loader",
loaders: loaders,
resourceQuery: requestObj.resource && requestObj.resource.query
},

@@ -220,16 +224,16 @@ null,

if(err) return callback(err);
mapAsync(resolvedModules, function(resolvedModule, callback) {
if(typeof resolvedModule != "string") return callback();
if(existsNativeModule(resolvedModule)) return callback();
if(cache[resolvedModule]) return callback();
if(hasOwnProperty.call(options.substitutions, resolvedModule)) return callback();
if(hasOwnProperty.call(options.substitutionFactories, resolvedModule)) return callback();
if(sourceCache[resolvedModule]) return callback();
mapAsync(resolvedModules, function(request, callback) {
if(typeof request != "string") return callback();
if(existsNativeModule(request)) return callback();
if(cache[request]) return callback();
if(hasOwnProperty.call(options.substitutions, request)) return callback();
if(hasOwnProperty.call(options.substitutionFactories, request)) return callback();
if(sourceCache[request]) return callback();
// split loaders from resource
var request = resolvedModule;
var loaders = resolvedModule.split(/!/g);
var filename = loaders.pop();
var requestObj = resolve.parse(request);
var filename = requestObj.resource && requestObj.resource.path;
var loaders = requestObj.loaders || [];
if(contentCache[filename]) return makeSource(null, contentCache[filename]);
if(!filename || contentCache[filename]) return makeSource(null, contentCache[filename]);
return loadContent();

@@ -262,6 +266,11 @@

request,
loaders, [filename],
[content],
loaders,
filename ? [filename] : [],
filename ? [content] : [],
{
loaderType: "loader",
loaders: loaders,
resourceQuery: requestObj.resource && requestObj.resource.query
},
null,
null,
options,

@@ -268,0 +277,0 @@ function(err, sources) {

{
"name": "enhanced-require",
"version": "0.4.0-beta12",
"version": "0.4.0-beta13",
"author": "Tobias Koppers @sokra",

@@ -5,0 +5,0 @@ "description": "Enhance the require function in node.js with support for loaders which preprocess files and really async require (AMD). Enables Hot Code Replacement.",

@@ -7,3 +7,3 @@ var should = require("should");

var req = reqFactory(module);
beforeEach(function() {

@@ -18,3 +18,3 @@ function clean(obj) {

});
it("should execute a loader", function() {

@@ -32,3 +32,25 @@ var outer = req("./fixtures/outer");

});
it("should execute a loader without resource", function() {
var loaded = req("./fixtures/loader!");
should.exist(loaded);
loaded.should.have.property("loader").be.a("object");
loaded.should.have.property("async").be.eql(false);
loaded.loader.should.have.property("request").be.eql(req.resolve("./fixtures/loader!"));
loaded.loader.should.have.property("context").be.eql(__dirname);
loaded.loader.should.have.property("filenames").be.eql([]);
});
it("should execute a loader with only query", function() {
var loaded = req("./fixtures/loader?query2!?query1");
should.exist(loaded);
loaded.should.have.property("loader").be.a("object");
loaded.should.have.property("async").be.eql(false);
loaded.loader.should.have.property("request").be.eql(req.resolve("./fixtures/loader?query2!?query1"));
loaded.loader.should.have.property("resourceQuery").be.eql("?query1");
loaded.loader.should.have.property("query").be.eql("?query2");
loaded.loader.should.have.property("context").be.eql(__dirname);
loaded.loader.should.have.property("filenames").be.eql([]);
});
});

@@ -0,0 +0,0 @@ var should = require("should");

@@ -0,0 +0,0 @@ exports.filename = __filename;

@@ -0,0 +0,0 @@ module.exports = function(source) {

@@ -7,3 +7,3 @@ var should = require("should");

var req = reqFactory(module);
beforeEach(function() {

@@ -18,7 +18,7 @@ function clean(obj) {

});
it("should ensure the modules", function(done) {
var id = path.join(__dirname, "fixtures", "file.js");
req.ensure(["./fixtures/file", "./fixtures/inner"], function(req2) {

@@ -32,5 +32,23 @@ should.exist(req2);

});
});
it("should ensure the modules", function(done) {
var id = path.join(__dirname, "fixtures", "file.js");
req.ensure(["./fixtures/file", "./fixtures/file?1"], function(req2, err) {
should.exist(req2);
req2.should.be.a("function");
should.exist(req2.sourceCache[id]);
should.exist(req2.sourceCache[id+"?1"]);
var file = req2(id);
var file1 = req2(id+"?1");
file.should.be.eql({value: "file"});
file1.should.be.eql({value: "file"});
done();
});
});
it("should be executed synchron if empty list", function() {

@@ -45,3 +63,3 @@ var executed = false;

});
});
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