Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wl-gulp-rev

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wl-gulp-rev - npm Package Compare versions

Comparing version 1.0.1 to 1.0.3

readme.md

224

index.js

@@ -7,3 +7,3 @@ 'use strict';

const revHash = require('rev-hash');
const revPath = require('wl-rev-path');
const revPath = require('@stl/wl-rev-path');
const sortKeys = require('sort-keys');

@@ -13,156 +13,156 @@ const modifyFilename = require('modify-filename');

function relPath(base, filePath) {
filePath = filePath.replace(/\\/g, '/');
base = base.replace(/\\/g, '/');
filePath = filePath.replace(/\\/g, '/');
base = base.replace(/\\/g, '/');
if (filePath.indexOf(base) !== 0) {
return filePath;
}
if (filePath.indexOf(base) !== 0) {
return filePath;
}
const newPath = filePath.slice(base.length);
const newPath = filePath.slice(base.length);
if (newPath[0] === '/') {
return newPath.slice(1);
}
if (newPath[0] === '/') {
return newPath.slice(1);
}
return newPath;
return newPath;
}
function transformFilename(file, ishash) {
// Save the old path for later
file.revOrigPath = file.path;
// Save the old path for later
file.revOrigPath = file.path;
file.revOrigBase = file.base;
if (ishash === false) {
file.revHash = "8888888888";
}else{
file.revHash = revHash(file.contents);
}
file.path = modifyFilename(file.path, (filename, extension) => {
const extIndex = filename.indexOf('.');
file.revHash = "8888888888";
} else {
file.revHash = revHash(file.contents);
}
file.path = modifyFilename(file.path, (filename, extension) => {
const extIndex = filename.indexOf('.');
filename = extIndex === -1 ?
revPath(filename, file.revHash) :
revPath(filename.slice(0, extIndex), file.revHash) + filename.slice(extIndex);
return filename + extension;
});
filename = extIndex === -1 ?
revPath(filename, file.revHash) :
revPath(filename.slice(0, extIndex), file.revHash) + filename.slice(extIndex);
return filename + extension;
});
}
const getManifestFile = opts => vinylFile.read(opts.path, opts).catch(err => {
if (err.code === 'ENOENT') {
return new gutil.File(opts);
}
if (err.code === 'ENOENT') {
return new gutil.File(opts);
}
throw err;
throw err;
});
const plugin = (ishash) => {
const sourcemaps = [];
const pathMap = {};
const sourcemaps = [];
const pathMap = {};
return through.obj((file, enc, cb) => {
if (file.isNull()) {
cb(null, file);
return;
}
return through.obj((file, enc, cb) => {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new gutil.PluginError('gulp-rev', 'Streaming not supported'));
return;
}
if (file.isStream()) {
cb(new gutil.PluginError('gulp-rev', 'Streaming not supported'));
return;
}
// This is a sourcemap, hold until the end
if (path.extname(file.path) === '.map') {
sourcemaps.push(file);
cb();
return;
}
// This is a sourcemap, hold until the end
if (path.extname(file.path) === '.map') {
sourcemaps.push(file);
cb();
return;
}
const oldPath = file.path;
const oldPath = file.path;
transformFilename(file, ishash);
pathMap[oldPath] = file.revHash;
pathMap[oldPath] = file.revHash;
cb(null, file);
}, function (cb) {
sourcemaps.forEach(file => {
let reverseFilename;
cb(null, file);
}, function(cb) {
sourcemaps.forEach(file => {
let reverseFilename;
// Attempt to parse the sourcemap's JSON to get the reverse filename
try {
reverseFilename = JSON.parse(file.contents.toString()).file;
} catch (err) {}
// Attempt to parse the sourcemap's JSON to get the reverse filename
try {
reverseFilename = JSON.parse(file.contents.toString()).file;
} catch (err) {}
if (!reverseFilename) {
reverseFilename = path.relative(path.dirname(file.path), path.basename(file.path, '.map'));
}
if (!reverseFilename) {
reverseFilename = path.relative(path.dirname(file.path), path.basename(file.path, '.map'));
}
if (pathMap[reverseFilename]) {
// Save the old path for later
file.revOrigPath = file.path;
file.revOrigBase = file.base;
if (pathMap[reverseFilename]) {
// Save the old path for later
file.revOrigPath = file.path;
file.revOrigBase = file.base;
const hash = pathMap[reverseFilename];
file.path = revPath(file.path.replace(/\.map$/, ''), hash) + '.map';
} else {
const hash = pathMap[reverseFilename];
file.path = revPath(file.path.replace(/\.map$/, ''), hash) + '.map';
} else {
transformFilename(file, ishash);
}
}
this.push(file);
});
this.push(file);
});
cb();
});
cb();
});
};
plugin.manifest = (pth, opts) => {
if (typeof pth === 'string') {
pth = {path: pth};
}
if (typeof pth === 'string') {
pth = { path: pth };
}
opts = Object.assign({
path: 'rev-manifest.json',
merge: false,
transformer: JSON
}, opts, pth);
opts = Object.assign({
path: 'rev-manifest.json',
merge: false,
transformer: JSON
}, opts, pth);
let manifest = {};
let manifest = {};
return through.obj((file, enc, cb) => {
// Ignore all non-rev'd files
if (!file.path || !file.revOrigPath) {
cb();
return;
}
return through.obj((file, enc, cb) => {
// Ignore all non-rev'd files
if (!file.path || !file.revOrigPath) {
cb();
return;
}
const revisionedFile = relPath(file.base, file.path);
const originalFile = path.join(path.dirname(revisionedFile), path.basename(file.revOrigPath)).replace(/\\/g, '/');
manifest[originalFile] = revisionedFile + '?v=' + file.revHash;
cb();
}, function (cb) {
// No need to write a manifest file if there's nothing to manifest
if (Object.keys(manifest).length === 0) {
cb();
return;
}
const revisionedFile = relPath(file.base, file.path);
const originalFile = path.join(path.dirname(revisionedFile), path.basename(file.revOrigPath)).replace(/\\/g, '/');
manifest[originalFile] = revisionedFile + '?v=' + file.revHash;
getManifestFile(opts).then(manifestFile => {
if (opts.merge && !manifestFile.isNull()) {
let oldManifest = {};
cb();
}, function(cb) {
try {
oldManifest = opts.transformer.parse(manifestFile.contents.toString());
} catch (err) {}
// No need to write a manifest file if there's nothing to manifest
if (Object.keys(manifest).length === 0) {
cb();
return;
}
manifest = Object.assign(oldManifest, manifest);
}
getManifestFile(opts).then(manifestFile => {
if (opts.merge && !manifestFile.isNull()) {
let oldManifest = {};
manifestFile.contents = Buffer.from(opts.transformer.stringify(sortKeys(manifest), null, ' '));
this.push(manifestFile);
cb();
}).catch(cb);
});
try {
oldManifest = opts.transformer.parse(manifestFile.contents.toString());
} catch (err) {}
manifest = Object.assign(oldManifest, manifest);
}
manifestFile.contents = Buffer.from(opts.transformer.stringify(sortKeys(manifest), null, ' '));
this.push(manifestFile);
cb();
}).catch(cb);
});
};
module.exports = plugin;
module.exports = plugin;
{
"name": "wl-gulp-rev",
"version": "1.0.1",
"description": "wl-gulp-rev",
"keywords": [
"wl-gulp-rev"
],
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "slothman",
"license": "ISC",
"devDependencies": {
"gulp-util": "^3.0.8",
"modify-filename": "^1.1.0",
"path": "^0.12.7",
"rev-hash": "^2.0.0",
"sort-keys": "^2.0.0",
"through2": "^2.0.3",
"vinyl-file": "^3.0.0",
"wl-rev-path": "^1.0.0"
}
}
"name": "wl-gulp-rev",
"version": "1.0.3",
"description": "wl-gulp-rev",
"keywords": [
"wl-gulp-rev"
],
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "slothman",
"license": "ISC",
"devDependencies": {
"gulp-rev": "^8.1.1",
"gulp-util": "^3.0.8",
"inquirer": "^7.2.0",
"modify-filename": "^1.1.0",
"path": "^0.12.7",
"rev-hash": "^2.0.0",
"sort-keys": "^2.0.0",
"through2": "^2.0.3",
"vinyl-file": "^3.0.0",
"wl-rev-path": "^1.0.2"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc