underscore-template-loader
Advanced tools
Comparing version 0.1.0 to 0.2.0
42
index.js
var _ = require('underscore'); | ||
var loaderUtils = require('loader-utils'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
function resolveContent(content, root) { | ||
var includeRegex = /<!--include\s+([\/\w\.]*?[\w]+\.[\w]+)-->/g; | ||
var matches = includeRegex.exec(content); | ||
while (matches != null) { | ||
var file = loaderUtils.urlToRequest(matches[1]); | ||
var basename = path.basename(file); | ||
var dirname = path.join(root, path.dirname(file)); | ||
var rawContent = readFile(basename, dirname); | ||
content = content.replace(matches[0], rawContent); | ||
matches = includeRegex.exec(content); | ||
} | ||
return content; | ||
} | ||
function readFile(filepath, root) { | ||
var self = readFile; | ||
if (typeof(self.buffer) == "undefined") { | ||
self.buffer = {}; | ||
} | ||
if (filepath in self.buffer) { | ||
return self.buffer[filepath]; | ||
} | ||
var content = resolveContent(fs.readFileSync(path.join(root, filepath), 'utf8'), root); | ||
self.buffer[filepath] = content; | ||
return self.buffer[filepath]; | ||
} | ||
module.exports = function(content) { | ||
this.cacheable && this.cacheable(); | ||
var callback = this.async(); | ||
content = resolveContent(content, "./"); | ||
var fn = _.template(content); | ||
callback(null, "module.exports = " + fn.source + ";"); | ||
} | ||
callback(null, "module.exports = " + fn + ";"); | ||
}; | ||
module.exports._ = _; |
{ | ||
"name": "underscore-template-loader", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "A Underscore template loader for Webpack", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"bugs": { | ||
"url": "https://github.com/emaphp/underscore-template-loader/isuues" | ||
"url": "https://github.com/emaphp/underscore-template-loader/issues" | ||
}, | ||
@@ -15,4 +15,9 @@ "author": { | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/emaphp/underscore-template-loader.git" | ||
}, | ||
"dependencies": { | ||
"underscore": "^1.6.0" | ||
"underscore": "^1.6.0", | ||
"loader-utils": "^0.2.5" | ||
}, | ||
@@ -19,0 +24,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
4293
36
0
0
2
+ Addedloader-utils@^0.2.5
+ Addedbig.js@3.2.0(transitive)
+ Addedemojis-list@2.1.0(transitive)
+ Addedjson5@0.5.1(transitive)
+ Addedloader-utils@0.2.17(transitive)
+ Addedobject-assign@4.1.1(transitive)