/usr/lib/nodejs/gulp-changed/index.js is in node-gulp-changed 3.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | 'use strict';
const fs = require('fs');
const path = require('path');
const gutil = require('gulp-util');
const through = require('through2');
const pify = require('pify');
const readFile = pify(fs.readFile);
const stat = pify(fs.stat);
// Ignore missing file error
function fsOperationFailed(stream, sourceFile, err) {
if (err.code !== 'ENOENT') {
stream.emit('error', new gutil.PluginError('gulp-changed', err, {
fileName: sourceFile.path
}));
}
stream.push(sourceFile);
}
// Only push through files changed more recently than the destination files
function compareLastModifiedTime(stream, sourceFile, targetPath) {
return stat(targetPath)
.then(targetStat => {
if (sourceFile.stat && sourceFile.stat.mtime > targetStat.mtime) {
stream.push(sourceFile);
}
});
}
// Only push through files with different contents than the destination files
function compareContents(stream, sourceFile, targetPath) {
return readFile(targetPath)
.then(targetData => {
if (sourceFile.isNull() || !sourceFile.contents.equals(targetData)) {
stream.push(sourceFile);
}
});
}
module.exports = (dest, opts) => {
opts = Object.assign({
cwd: process.cwd(),
hasChanged: compareLastModifiedTime
}, opts);
if (!dest) {
throw new gutil.PluginError('gulp-changed', '`dest` required');
}
if (opts.transformPath !== undefined && typeof opts.transformPath !== 'function') {
throw new gutil.PluginError('gulp-changed', '`opts.transformPath` needs to be a function');
}
return through.obj(function (file, enc, cb) {
const dest2 = typeof dest === 'function' ? dest(file) : dest;
let newPath = path.resolve(opts.cwd, dest2, file.relative);
if (opts.extension) {
newPath = gutil.replaceExtension(newPath, opts.extension);
}
if (opts.transformPath) {
newPath = opts.transformPath(newPath);
if (typeof newPath !== 'string') {
throw new gutil.PluginError('gulp-changed', '`opts.transformPath` needs to return a string');
}
}
opts
.hasChanged(this, file, newPath)
.catch(err => fsOperationFailed(this, file, err))
.then(() => cb());
});
};
module.exports.compareLastModifiedTime = compareLastModifiedTime;
module.exports.compareContents = compareContents;
module.exports.compareSha1Digest = compareContents;
|