postcss-hash
Advanced tools
Comparing version
45
index.js
@@ -1,22 +0,27 @@ | ||
'use strict'; | ||
"use strict"; | ||
const { readFile, writeFile } = require('fs'); | ||
const postcss = require('postcss'); | ||
const utils = require('./utils'); | ||
const readFileAsync = (file, enc) => new Promise((res, rej) => { | ||
readFile(file, enc, (err, val) => err ? rej(err) : res(val)); | ||
}); | ||
const writeFileAsync = (file, data, enc) => new Promise((res, rej) => { | ||
writeFile(file, data, enc, (err, val) => err ? rej(err) : res(val)); | ||
}); | ||
const { readFile, writeFile } = require("fs"); | ||
const postcss = require("postcss"); | ||
const utils = require("./utils"); | ||
const readFileAsync = (file, enc) => | ||
new Promise((res, rej) => { | ||
readFile(file, enc, (err, val) => (err ? rej(err) : res(val))); | ||
}); | ||
const writeFileAsync = (file, data, enc) => | ||
new Promise((res, rej) => { | ||
writeFile(file, data, enc, (err, val) => (err ? rej(err) : res(val))); | ||
}); | ||
module.exports = postcss.plugin('postcss-hash', (opts) => { | ||
opts = Object.assign({ | ||
algorithm: 'md5', | ||
trim: 10, | ||
manifest: './manifest.json', | ||
name: utils.defaultName | ||
}, opts); | ||
module.exports = postcss.plugin("postcss-hash", opts => { | ||
opts = Object.assign( | ||
{ | ||
algorithm: "md5", | ||
trim: 10, | ||
manifest: "./manifest.json", | ||
name: utils.defaultName | ||
}, | ||
opts | ||
); | ||
return function (root, result) { | ||
return function(root, result) { | ||
// replace filename | ||
@@ -28,8 +33,8 @@ const originalName = result.opts.to; | ||
const newData = utils.data(originalName, result.opts.to); | ||
return readFileAsync(opts.manifest, 'utf-8') | ||
return readFileAsync(opts.manifest, "utf-8") | ||
.then(JSON.parse, () => ({})) | ||
.then(oldData => Object.assign(oldData, newData)) | ||
.then(obj => JSON.stringify(obj, null, 2)) | ||
.then(data => writeFileAsync(opts.manifest, data, 'utf-8')); | ||
.then(data => writeFileAsync(opts.manifest, data, "utf-8")); | ||
}; | ||
}); |
{ | ||
"name": "postcss-hash", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "PostCSS plugin to replace output file names with HASH algorithms (md5, sha256, sha512, etc) and string length of your choice - for cache busting", | ||
@@ -42,3 +42,3 @@ "keywords": [ | ||
"jest": "^23.6.0", | ||
"mock-fs": "^4.7.0" | ||
"prettier": "^1.14.2" | ||
}, | ||
@@ -45,0 +45,0 @@ "scripts": { |
17
utils.js
@@ -1,3 +0,3 @@ | ||
const crypto = require('crypto'); | ||
const path = require('path'); | ||
const crypto = require("crypto"); | ||
const path = require("path"); | ||
@@ -10,11 +10,10 @@ /* | ||
return crypto | ||
.createHash(algorithm) | ||
.update(css) | ||
.digest('hex') | ||
.substr(0, trim); | ||
.createHash(algorithm) | ||
.update(css) | ||
.digest("hex") | ||
.substr(0, trim); | ||
} | ||
function defaultName(parts) { | ||
return path.join(parts.dir, parts.name + '.' + parts.hash + parts.ext); | ||
return path.join(parts.dir, parts.name + "." + parts.hash + parts.ext); | ||
} | ||
@@ -29,3 +28,3 @@ | ||
dir: path.dirname(file), | ||
name : path.basename(file, path.extname(file)), | ||
name: path.basename(file, path.extname(file)), | ||
ext: path.extname(file), | ||
@@ -32,0 +31,0 @@ hash: hash(css, opts.algorithm, opts.trim) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
1
-50%7966
-96.36%6
-14.29%78
-98.73%