cache-hash
Advanced tools
Comparing version 1.0.0-beta.0 to 1.0.0-beta.1
@@ -27,7 +27,7 @@ /** | ||
html: true, | ||
css: true, | ||
style: true, | ||
queryString: { | ||
js: true, | ||
css: true, | ||
html: { | ||
style: true, | ||
script: true | ||
@@ -40,3 +40,3 @@ } | ||
module.exports = function (options) { | ||
module.exports = async function (options) { | ||
try { | ||
@@ -59,5 +59,6 @@ options.target = isAbsolute(options.target) ? options.target : join(CWD, options.target, '/') | ||
const params = { options, files, mappings, caches } | ||
handlerJs(params) | ||
handlerCss(params) | ||
handlerHtml(params) | ||
await handlerCss(params) | ||
await handlerHtml(params) | ||
@@ -64,0 +65,0 @@ const interval = prettyHrtime(process.hrtime(start)) |
const { readFileSync, writeFileSync } = require('fs') | ||
const { extname } = require('path') | ||
const injectHash = require('./queryString') | ||
const cssUrl = require('../utils/cssUrl') | ||
module.exports = (params) => { | ||
module.exports = async (params) => { | ||
const { options, files } = params | ||
if (!options.queryString.css) return | ||
if (!options.css) return | ||
const styles = files.filter((file) => extname(file) === '.css') | ||
@@ -12,4 +12,5 @@ | ||
const content = readFileSync(style).toString() | ||
writeFileSync(style, injectHash(params, content, options.relative)) | ||
const css = await cssUrl(options, content, style) | ||
writeFileSync(style, css) | ||
} | ||
} |
@@ -5,3 +5,5 @@ const { readFileSync, writeFileSync } = require('fs') | ||
const { JSDOM } = jsdom | ||
const cssUrl = require('../utils/cssUrl') | ||
const injectHash = require('./queryString') | ||
const searchParams = require('../utils/searchParams') | ||
@@ -39,3 +41,3 @@ const DOCTYPE = '<!DOCTYPE html>' | ||
url.searchParams.set(versionKey, version) | ||
const value = relativePath + url.search + url.hash | ||
const value = searchParams(relativePath, versionKey, version) | ||
source.setAttribute(obj[source.tagName], value) | ||
@@ -46,3 +48,3 @@ } | ||
function handlerInline(params, inlines) { | ||
async function handlerInline(params, inlines, file) { | ||
const { dom, options } = params | ||
@@ -56,8 +58,12 @@ | ||
content = injectHash(params, content, options.relative) | ||
Array.from(inline.attributes).forEach((attr) => newTag.setAttribute(attr.name, attr.value)) | ||
newTag.text = content | ||
newTag.textContent = content | ||
inline.parentNode.replaceChild(newTag, inline) | ||
if (inline.tagName === 'SCRIPT') { | ||
content = injectHash(params, content, options.relative) | ||
inline.parentNode.replaceChild(newTag, inline) | ||
} else { | ||
const css = await cssUrl(options, content, file) | ||
newTag.textContent = css | ||
inline.parentNode.replaceChild(newTag, inline) | ||
} | ||
} | ||
@@ -67,3 +73,3 @@ } | ||
/* eslint-disable max-statements*/ | ||
module.exports = (params) => { | ||
module.exports = async (params) => { | ||
const { options, files } = params | ||
@@ -83,4 +89,4 @@ const { queryString } = options | ||
handlerSource(params) | ||
queryString.html.script && handlerInline(params, scripts) | ||
queryString.html.style && handlerInline(params, styles) | ||
queryString.html.script && (await handlerInline(params, scripts, html)) | ||
options.style && (await handlerInline(params, styles, html)) | ||
@@ -87,0 +93,0 @@ let outerHTML = dom.window.document.documentElement.outerHTML |
{ | ||
"name": "cache-hash", | ||
"version": "1.0.0-beta.0", | ||
"version": "1.0.0-beta.1", | ||
"description": "Create hash for static resources to break http cache", | ||
@@ -40,2 +40,3 @@ "main": "cache-hash.js", | ||
"jsdom": "^20.0.0", | ||
"postcss": "^8.4.14", | ||
"pretty-hrtime": "^1.0.3" | ||
@@ -42,0 +43,0 @@ }, |
@@ -46,5 +46,5 @@ # Cache-hash | ||
--html <html> Generate hash for html referenced resources (default: true) | ||
--css <css> Generate hash for css referenced resources (default: true) | ||
--style <style> Generating hashes for resources referenced by style tags (<style>) (default: true) | ||
--queryJS <queryJS> String lookup and replacement of js file content (default: true) | ||
--queryCSS <queryCSS> String lookup and replacement of css file content (default: true) | ||
--queryStyle <queryStyle> String query replacement for inline "style" tags in html file content (default: true) | ||
--queryScript <queryScript> String query replacement for inline "script" tags in html file content (default: true) | ||
@@ -51,0 +51,0 @@ -h, --help display help for command |
console.log('Successfully') | ||
const abc = 'index.js?v=9f4c797654' | ||
const abc = 'index.js?v=6abdea5749' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
23836
27
387
4
9
+ Addedpostcss@^8.4.14
+ Addednanoid@3.3.8(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpostcss@8.4.49(transitive)
+ Addedsource-map-js@1.2.1(transitive)