gobem-proc-sqwish
Advanced tools
Comparing version 0.0.6 to 0.0.7
38
index.js
'use strict'; | ||
var sqwish = require('sqwish'), | ||
redis = require('redis'); | ||
var path = require('path'), | ||
fs = require('fs'), | ||
sqwish = require('sqwish'), | ||
xxhash = require('xxhash'); | ||
@@ -9,35 +11,25 @@ module.exports = function (options) { | ||
let client = options.redisClient, | ||
key = options.redisKey || 'gobem-proc-sqwish'; | ||
return { | ||
before: function (next) { | ||
client = client || redis.createClient(options.redisOptions); | ||
client.expire(key, 86400); | ||
next(); | ||
}, | ||
process: function (next, input, output, config, rawContent, rawPath) { | ||
if (!rawContent) return next(); | ||
process: function (next, input, output, config, content, path) { | ||
if (!content) return next(); | ||
client.hget(key, content, function (error, reply) { | ||
if (reply === null) { | ||
let key = xxhash.hash(new Buffer(rawContent), 0xCAFEBABE) + '', | ||
filePath = path.join(options.cacheDir + '', 'gobem-proc-sqwish^' + key); | ||
fs.readFile(filePath, 'utf8', (error, fileContent) => { | ||
if (error) { | ||
try { | ||
output.set(path, sqwish.minify(content)); | ||
client.hset(key, content, output.get(path), next); | ||
output.set(rawPath, sqwish.minify(rawContent)); | ||
fs.writeFile(filePath, output.get(rawPath), next); | ||
} catch (error) { | ||
output.set(path, content); | ||
output.set(rawPath, rawContent); | ||
next(options.ignoreErrors ? null : error); | ||
} | ||
} else { | ||
output.set(path, reply); | ||
output.set(rawPath, fileContent); | ||
next(); | ||
} | ||
}); | ||
}, | ||
clear: function (next) { | ||
!options.redisClient && client.end(); | ||
next(); | ||
} | ||
}; | ||
}; |
{ | ||
"name": "gobem-proc-sqwish", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Processor to minify CSS files for gobem builder.", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"sqwish": "*", | ||
"redis": "*" | ||
"xxhash": "*" | ||
}, | ||
@@ -11,0 +11,0 @@ "peerDependencies": { |
# gobem-proc-sqwish | ||
This processor for [gobem](https://github.com/Enet/gobem) minifies CSS files using **sqwish**. All options are passed as a single object. **gobem-proc-sqwish** requires redis database to cache results of the work. | ||
This processor for [gobem](https://github.com/Enet/gobem) minifies CSS files using **sqwish**. All options are passed as a single object. **gobem-proc-sqwish** requires directory to cache results of the work. | ||
The following options are supported: | ||
* `ignoreErrors`<br> | ||
* `ignoreErrors`\ | ||
If this flag is `true` and error occured, raw file's content will be written instead minified one. | ||
* `redisKey`<br> | ||
The key in the redis database to store cache. Default value is `gobem-proc-sqwish`. | ||
* `redisClient`<br> | ||
Already created redis-client. [This](https://github.com/NodeRedis/node_redis) module is used. | ||
* `redisOptions`<br> | ||
Options for a new redis-client. This field is ignored, if `redisClient` is passed. | ||
* `cacheDir`\ | ||
Full path to a readable and writable directory to cache files. | ||
@@ -21,5 +17,3 @@ ### Example for **build.js** | ||
ignoreErrors: true, | ||
redisOptions: { | ||
port: 6370 | ||
} | ||
cacheDir: '/var/www/gobem/cache' | ||
}], | ||
@@ -26,0 +20,0 @@ ['write', 1] |
Floating dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
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
Floating dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
37881
29
23
2
+ Addedxxhash@*
+ Addednan@2.19.0(transitive)
+ Addedxxhash@0.3.0(transitive)
- Removedredis@*
- Removed@redis/bloom@1.2.0(transitive)
- Removed@redis/client@1.5.16(transitive)
- Removed@redis/graph@1.1.1(transitive)
- Removed@redis/json@1.0.6(transitive)
- Removed@redis/search@1.1.6(transitive)
- Removed@redis/time-series@1.0.5(transitive)
- Removedcluster-key-slot@1.1.2(transitive)
- Removedgeneric-pool@3.9.0(transitive)
- Removedredis@4.6.14(transitive)
- Removedyallist@4.0.0(transitive)