gulp-tpl-rev
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -1,7 +0,1 @@ | ||
/// <reference types="node" /> | ||
interface PluginOption { | ||
name: string; | ||
hash(pahtname?: string): string; | ||
} | ||
export default function (options?: PluginOption): import("stream").Transform; | ||
export {}; | ||
declare const plugin: any; |
51
index.js
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var through2_1 = __importDefault(require("through2")); | ||
var parse5_html_rewriting_stream_1 = __importDefault(require("parse5-html-rewriting-stream")); | ||
var url = __importStar(require("url")); | ||
var defaultOptions = { | ||
name: "_v", | ||
hash: function (pahtname) { return "" + Date.now(); } | ||
}; | ||
function default_1(options) { | ||
if (options === void 0) { options = defaultOptions; } | ||
return through2_1.default.obj(function (file, _, cb) { | ||
var tpl = ""; | ||
var rewriter = new parse5_html_rewriting_stream_1.default(); | ||
rewriter.on('startTag', function (token) { | ||
if (token.tagName === 'link') { | ||
var attr = token.attrs.filter(function (attr) { return attr.name === "href"; })[0]; | ||
if (attr) { | ||
var urlObject = url.parse(attr.value, true); | ||
var query = urlObject.query; | ||
query[options.name] = options.hash(urlObject.pathname); | ||
attr.value = url.format(urlObject); | ||
} | ||
} | ||
rewriter.emitStartTag(token); | ||
}); | ||
rewriter.on("text", function (token) { | ||
rewriter.emitText(token); | ||
}); | ||
rewriter.on("data", function (token) { | ||
tpl += token; | ||
}); | ||
rewriter.on("end", function () { | ||
file.contents = Buffer.from(tpl); | ||
cb(null, file); | ||
}); | ||
rewriter.end(file.contents.toString()); | ||
}); | ||
} | ||
exports.default = default_1; | ||
var plugin = require('./plugin').default; | ||
exports = module.exports = plugin; |
44
index.ts
@@ -1,43 +0,3 @@ | ||
import through2 from "through2"; | ||
import RewritingStream from "parse5-html-rewriting-stream" | ||
import * as url from "url"; | ||
const plugin = require('./plugin').default | ||
interface PluginOption { | ||
name: string, | ||
hash(pahtname?: string):string | ||
} | ||
const defaultOptions: PluginOption = { | ||
name: "_v", | ||
hash: function(pahtname: string) { return "" + Date.now() } | ||
} | ||
export default function(options: PluginOption = defaultOptions) { | ||
return through2.obj(function(file, _, cb) { | ||
let tpl = ""; | ||
const rewriter = new RewritingStream(); | ||
rewriter.on('startTag', token => { | ||
if (token.tagName === 'link') { | ||
const attr = token.attrs.filter(attr => attr.name === "href")[0]; | ||
if (attr) { | ||
const urlObject = url.parse(attr.value, true); | ||
const query = urlObject.query; | ||
query[options.name] = options.hash(urlObject.pathname); | ||
attr.value = url.format(urlObject); | ||
} | ||
} | ||
rewriter.emitStartTag(token); | ||
}); | ||
rewriter.on("text", function(token) { | ||
rewriter.emitText(token) | ||
}) | ||
rewriter.on("data", function(token) { | ||
tpl += token | ||
}) | ||
rewriter.on("end", function() { | ||
file.contents = Buffer.from(tpl) | ||
cb(null, file) | ||
}) | ||
rewriter.end(file.contents.toString()) | ||
}) | ||
} | ||
exports = module.exports = plugin |
{ | ||
"name": "gulp-tpl-rev", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "template resource url revisioning by appending content hash to filenames: unicorn.css => unicorn.css?_v=1", | ||
"main": "dist/index.js", | ||
"typings": "index.ts", | ||
"typings": "plugin.ts", | ||
"scripts": { | ||
@@ -8,0 +8,0 @@ "prepublishOnly": "npm run compile", |
@@ -52,4 +52,5 @@ { | ||
"files": [ | ||
"index.ts" | ||
"index.ts", | ||
"plugin.ts" | ||
] | ||
} |
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
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
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
11242
13
173
1