rev-replace-loader
Advanced tools
Comparing version 0.1.4 to 0.2.0
38
index.js
@@ -1,18 +0,28 @@ | ||
var path = require('path') | ||
var loaderUtils = require('loader-utils') | ||
var path = require('path'); | ||
var glob = require('glob'); | ||
var loaderUtils = require('loader-utils'); | ||
module.exports = function(source) { | ||
module.exports = function (source) { | ||
var query = loaderUtils.parseQuery(this.query); | ||
var manifest = query.manifest || (query.manifestPath ? requireManifests(query.manifestPath) : false); | ||
var query = loaderUtils.parseQuery(this.query) | ||
var manifest = query.manifest || (query.manifestPath ? requireManifest(query.manifestPath) : false) | ||
if (manifest) { | ||
for ( var key in manifest ) { | ||
var value = manifest[key] | ||
var pattern = new RegExp(key, 'gm') | ||
source = source.replace(pattern, value) | ||
for (var key in manifest) { | ||
var value = manifest[key]; | ||
var pattern = new RegExp(key, 'gm'); | ||
source = source.replace(pattern, value); | ||
} | ||
} | ||
return source | ||
return source; | ||
}; | ||
function requireManifests(manifestGlob) { | ||
return glob.sync(manifestGlob).map(function (path) { | ||
return requireManifest(path); | ||
}).filter(function (manifest) { | ||
return manifest !== false; | ||
}).reduce(function (manifest, current) { | ||
return Object.assign(manifest, current); | ||
}, {}); | ||
} | ||
@@ -22,6 +32,6 @@ | ||
try { | ||
return require(manifestPath) | ||
} catch(error) { | ||
return false | ||
return require(path.resolve(process.cwd(), manifestPath)); | ||
} catch (error) { | ||
return false; | ||
} | ||
} |
{ | ||
"name": "rev-replace-loader", | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"description": "Webpack loader to replace asset paths with hashed ones from a rev-manifest.json file", | ||
@@ -18,7 +18,7 @@ "main": "index.js", | ||
], | ||
"author": "Dan Tello", | ||
"license": "MIT", | ||
"dependencies": { | ||
"glob": "7.1.2", | ||
"loader-utils": "0.2.16" | ||
} | ||
} |
@@ -23,2 +23,3 @@ Replace rev'd asset references in your production JS compiled with Webpack! | ||
You can either pass a `manifest` object directly, or pass a `manfiestPath` for the loader to try. The latter will not error if no manifest file is found. Filenames will simply remain the same. | ||
The `manifestPath` parameter also supports `glob` queries. | ||
@@ -25,0 +26,0 @@ ```js |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
3458
6
31
40
2
3
+ Addedglob@7.1.2
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.1.2(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedwrappy@1.0.2(transitive)