pax_global_header00006660000000000000000000000064140620602670014515gustar00rootroot0000000000000052 comment=610074a72b79e534d14191ad93cc1a9d5c259521 gulp-changed-4.0.3/000077500000000000000000000000001406206026700140575ustar00rootroot00000000000000gulp-changed-4.0.3/.editorconfig000066400000000000000000000002571406206026700165400ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 gulp-changed-4.0.3/.gitattributes000066400000000000000000000000231406206026700167450ustar00rootroot00000000000000* text=auto eol=lf gulp-changed-4.0.3/.github/000077500000000000000000000000001406206026700154175ustar00rootroot00000000000000gulp-changed-4.0.3/.github/funding.yml000066400000000000000000000001611406206026700175720ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus patreon: sindresorhus custom: https://sindresorhus.com/donate gulp-changed-4.0.3/.github/workflows/000077500000000000000000000000001406206026700174545ustar00rootroot00000000000000gulp-changed-4.0.3/.github/workflows/main.yml000066400000000000000000000007021406206026700211220ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 14 - 12 - 10 - 8 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test gulp-changed-4.0.3/.gitignore000066400000000000000000000000271406206026700160460ustar00rootroot00000000000000node_modules yarn.lock gulp-changed-4.0.3/.npmrc000066400000000000000000000000231406206026700151720ustar00rootroot00000000000000package-lock=false gulp-changed-4.0.3/fixture/000077500000000000000000000000001406206026700155455ustar00rootroot00000000000000gulp-changed-4.0.3/fixture/different.ext/000077500000000000000000000000001406206026700203125ustar00rootroot00000000000000gulp-changed-4.0.3/fixture/different.ext/src/000077500000000000000000000000001406206026700211015ustar00rootroot00000000000000gulp-changed-4.0.3/fixture/different.ext/src/a.typescript000066400000000000000000000000011406206026700234400ustar00rootroot00000000000000agulp-changed-4.0.3/fixture/different.ext/src/b.typescript000066400000000000000000000000011406206026700234410ustar00rootroot00000000000000bgulp-changed-4.0.3/fixture/different.ext/trg/000077500000000000000000000000001406206026700211065ustar00rootroot00000000000000gulp-changed-4.0.3/fixture/different.ext/trg/a.coffee000066400000000000000000000000011406206026700224660ustar00rootroot00000000000000agulp-changed-4.0.3/fixture/different.ext/trg/b.coffee000066400000000000000000000000021406206026700224700ustar00rootroot00000000000000b!gulp-changed-4.0.3/fixture/different.transformPath/000077500000000000000000000000001406206026700223425ustar00rootroot00000000000000gulp-changed-4.0.3/fixture/different.transformPath/src/000077500000000000000000000000001406206026700231315ustar00rootroot00000000000000gulp-changed-4.0.3/fixture/different.transformPath/src/a000066400000000000000000000000021406206026700232640ustar00rootroot00000000000000a gulp-changed-4.0.3/fixture/different.transformPath/src/b000066400000000000000000000000021406206026700232650ustar00rootroot00000000000000b gulp-changed-4.0.3/fixture/different.transformPath/trg/000077500000000000000000000000001406206026700231365ustar00rootroot00000000000000gulp-changed-4.0.3/fixture/different.transformPath/trg/c/000077500000000000000000000000001406206026700233605ustar00rootroot00000000000000gulp-changed-4.0.3/fixture/different.transformPath/trg/c/a000066400000000000000000000000021406206026700235130ustar00rootroot00000000000000a gulp-changed-4.0.3/fixture/different.transformPath/trg/c/b000066400000000000000000000000031406206026700235150ustar00rootroot00000000000000b! gulp-changed-4.0.3/fixture/different/000077500000000000000000000000001406206026700175135ustar00rootroot00000000000000gulp-changed-4.0.3/fixture/different/src/000077500000000000000000000000001406206026700203025ustar00rootroot00000000000000gulp-changed-4.0.3/fixture/different/src/a000066400000000000000000000000011406206026700204340ustar00rootroot00000000000000agulp-changed-4.0.3/fixture/different/src/b000066400000000000000000000000011406206026700204350ustar00rootroot00000000000000bgulp-changed-4.0.3/fixture/different/trg/000077500000000000000000000000001406206026700203075ustar00rootroot00000000000000gulp-changed-4.0.3/fixture/different/trg/a000066400000000000000000000000011406206026700204410ustar00rootroot00000000000000agulp-changed-4.0.3/fixture/different/trg/b000066400000000000000000000000021406206026700204430ustar00rootroot00000000000000b!gulp-changed-4.0.3/fixture/identical/000077500000000000000000000000001406206026700175015ustar00rootroot00000000000000gulp-changed-4.0.3/fixture/identical/src/000077500000000000000000000000001406206026700202705ustar00rootroot00000000000000gulp-changed-4.0.3/fixture/identical/src/a000066400000000000000000000000011406206026700204220ustar00rootroot00000000000000agulp-changed-4.0.3/fixture/identical/src/b000066400000000000000000000000011406206026700204230ustar00rootroot00000000000000bgulp-changed-4.0.3/fixture/identical/trg/000077500000000000000000000000001406206026700202755ustar00rootroot00000000000000gulp-changed-4.0.3/fixture/identical/trg/a000066400000000000000000000000011406206026700204270ustar00rootroot00000000000000agulp-changed-4.0.3/fixture/identical/trg/b000066400000000000000000000000011406206026700204300ustar00rootroot00000000000000bgulp-changed-4.0.3/index.js000066400000000000000000000061431406206026700155300ustar00rootroot00000000000000'use strict'; const {promisify} = require('util'); const fs = require('fs'); const path = require('path'); const replaceExt = require('replace-ext'); const PluginError = require('plugin-error'); const through = require('through2'); const readFile = promisify(fs.readFile); const stat = promisify(fs.stat); // Ignore missing file error function fsOperationFailed(stream, sourceFile, error) { if (error.code !== 'ENOENT') { stream.emit('error', new PluginError('gulp-changed', error, { fileName: sourceFile.path })); } stream.push(sourceFile); } // Only push through files changed more recently than the destination files async function compareLastModifiedTime(stream, sourceFile, targetPath) { // TODO: Use the `stat` `bigint` option when targeting Node.js 10 and Gulp supports it const targetStat = await stat(targetPath); /* Precision is lost in the `mtime` when Gulp copies the file from source to target so we cannot compare the modified times directly. This has been the case since Gulp 4. Now, due to an issue in libuv affecting Node.js 14.17.0 and above (including 16.x: https://github.com/nodejs/node/issues/38981) when Gulp copies the file to the target, its `mtime` may be behind the source file by up to 1ms. For example, if the source file has a `mtime` like `1623259049896.314`, the target file `mtime` can end up as `1623259049895.999`. So to compare safely we use floor on the source and ceil on the target, which would give us `1623259049896` for both source and target in that example case. */ if (sourceFile.stat && Math.floor(sourceFile.stat.mtimeMs) > Math.ceil(targetStat.mtimeMs)) { stream.push(sourceFile); } } // Only push through files with different contents than the destination files async function compareContents(stream, sourceFile, targetPath) { const targetData = await readFile(targetPath); if (sourceFile.isNull() || !sourceFile.contents.equals(targetData)) { stream.push(sourceFile); } } module.exports = (destination, options) => { options = { cwd: process.cwd(), hasChanged: compareLastModifiedTime, ...options }; if (!destination) { throw new PluginError('gulp-changed', '`dest` required'); } if (options.transformPath !== undefined && typeof options.transformPath !== 'function') { throw new PluginError('gulp-changed', '`options.transformPath` needs to be a function'); } return through.obj(function (file, encoding, callback) { const dest2 = typeof destination === 'function' ? destination(file) : destination; let newPath = path.resolve(options.cwd, dest2, file.relative); if (options.extension) { newPath = replaceExt(newPath, options.extension); } if (options.transformPath) { newPath = options.transformPath(newPath); if (typeof newPath !== 'string') { throw new PluginError('gulp-changed', '`options.transformPath` needs to return a string'); } } (async () => { try { await options.hasChanged(this, file, newPath); } catch (error) { fsOperationFailed(this, file, error); } callback(); })(); }); }; module.exports.compareLastModifiedTime = compareLastModifiedTime; module.exports.compareContents = compareContents; gulp-changed-4.0.3/license000066400000000000000000000021251406206026700154240ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. gulp-changed-4.0.3/package.json000066400000000000000000000017731406206026700163550ustar00rootroot00000000000000{ "name": "gulp-changed", "version": "4.0.3", "description": "Only pass through changed files", "license": "MIT", "repository": "sindresorhus/gulp-changed", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js" ], "keywords": [ "gulpplugin", "file", "files", "changed", "newer", "modified", "modification", "updated", "time", "mtime", "stat", "cache", "cached", "passthrough" ], "dependencies": { "make-dir": "^3.0.0", "plugin-error": "^1.0.1", "replace-ext": "^1.0.0", "through2": "^3.0.1", "touch": "^3.1.0" }, "devDependencies": { "ava": "^2.3.0", "chalk": "^2.3.0", "del": "^5.0.0", "figures": "^3.0.0", "get-stream": "^5.1.0", "gulp": "^4.0.2", "vinyl": "^2.1.0", "xo": "^0.24.0" }, "peerDependencies": { "gulp": ">=4" }, "peerDependenciesMeta": { "gulp": { "optional": true } } } gulp-changed-4.0.3/readme.md000066400000000000000000000063621406206026700156450ustar00rootroot00000000000000# gulp-changed > Only pass through changed files No more wasting precious time on processing unchanged files. By default it's only able to detect whether files in the stream changed. If you require something more advanced like knowing if imports/dependencies changed, create a custom comparator, or use [another plugin](https://github.com/gulpjs/gulp#incremental-builds). ## Install ``` $ npm install --save-dev gulp-changed ``` ## Usage ```js const gulp = require('gulp'); const changed = require('gulp-changed'); const ngAnnotate = require('gulp-ng-annotate'); // Just as an example const SOURCE = 'src/*.js'; const DESTINATION = 'dist'; exports.default = () => ( gulp.src(SOURCE) .pipe(changed(DESTINATION)) // `ngAnnotate` will only get the files that // changed since the last time it was run .pipe(ngAnnotate()) .pipe(gulp.dest(DESTINATION)) ); ``` ## API ### changed(destination, options?) #### destination Type: `string | Function` Destination directory. Same as you put into `gulp.dest()`. This is needed to be able to compare the current files with the destination files. Can also be a function returning a destination directory path. #### options Type: `object` ##### cwd Type: `string`
Default: `process.cwd()` Working directory the folder is relative to. ##### extension Type: `string` Extension of the destination files. Useful if it differs from the original, like in the example below: ```js exports.jade = () => ( gulp.src('src/**/*.jade') .pipe(changed('app', {extension: '.html'})) .pipe(jade()) .pipe(gulp.dest('app')) ); ``` ##### hasChanged Type: `Function`
Default: `changed.compareLastModifiedTime` Function that determines whether the source file is different from the destination file. ###### Built-in comparators - `changed.compareLastModifiedTime` - `changed.compareContents` ###### Example ```js exports.jade = () => ( gulp.src('src/**/*.jade') .pipe(changed('app', {hasChanged: changed.compareContents})) .pipe(jade()) .pipe(gulp.dest('app')) ); ``` You can also supply a custom comparator function which will receive the following arguments and should return `Promise`. - `stream` *([transform object stream](https://github.com/rvagg/through2#transformfunction))* - Should be used to queue `sourceFile` if it passes some comparison - `sourceFile` *([Vinyl file object](https://github.com/wearefractal/vinyl#file))* - `destPath` *(string)* - Destination for `sourceFile` as an absolute path ##### transformPath Type: `Function` Function to transform the path to the destination file. Should return the absolute path to the (renamed) destination file. Useful if you rename your file later on, like in the below example: ```js exports.marked = () => ( gulp.src('src/content/about.md') .pipe(changed('dist', {transformPath: newPath => path.join(path.dirname(newPath), path.basename(newPath, '.md'), 'index.html')})) .pipe(marked()) .pipe(rename(newPath => path.join(path.dirname(newPath), path.basename(newPath, '.md'), 'index.html')))) .pipe(gulp.dest('dist')) ); ``` ## In-place change monitoring If you're looking to process source files in-place without any build output (formatting, linting, etc), have a look at [gulp-changed-in-place](https://github.com/alexgorbatchev/gulp-changed-in-place). gulp-changed-4.0.3/test.js000066400000000000000000000074451406206026700154060ustar00rootroot00000000000000import path from 'path'; import fs from 'fs'; import touch from 'touch'; import makeDir from 'make-dir'; import test from 'ava'; import gulp from 'gulp'; import Vinyl from 'vinyl'; import del from 'del'; import getStream from 'get-stream'; import figures from 'figures'; import chalk from 'chalk'; import changed from '.'; const pointer = chalk.gray.dim(figures.pointerSmall); const macro = async (t, options) => { // TODO: Use the `p-event` package here instead of the promise constructor // eslint-disable-next-line no-async-promise-executor return new Promise(async (resolve, reject) => { let {dest} = options; const extension = options.extension || '.js'; const stream = changed(dest, options); const files = []; if (typeof dest === 'function') { dest = dest(); } try { await makeDir(dest); await touch(path.join(dest, `foo${extension}`)); } catch (error) { reject(error); return; } stream.on('data', file => { files.push(file); fs.writeFileSync(path.join(dest, file.relative), file.contents); }); stream.on('end', () => { t.is(files.length, 1); t.is(files[0].relative, 'bar.js'); del.sync(dest); resolve(); }); stream.write(new Vinyl({ cwd: __dirname, base: __dirname, path: 'foo.js', contents: Buffer.from(''), stat: { mtime: fs.statSync(path.join(dest, 'foo' + extension)) } })); stream.write(new Vinyl({ base: __dirname, path: 'bar.js', contents: Buffer.from(''), stat: { mtime: new Date() } })); stream.end(); }); }; macro.title = (providedTitle, options) => { let desc = 'should only pass through changed files'; if (options && options.extension) { desc += ' using extension ' + options.extension; } else if (options.absolute) { desc += ' with a absolute path'; } else { desc += ' using file extension'; } return [providedTitle, desc].join(` ${pointer} `); }; test.serial(`compareLastModifiedTime ${pointer} using relative dest`, macro, {dest: 'tmp', absolute: true}); test.serial(`compareLastModifiedTime ${pointer} using relative dest`, macro, {dest: 'tmp', absolute: true, extension: '.coffee'}); test.serial(`compareLastModifiedTime ${pointer} dest can be a function`, macro, {dest: () => 'tmp'}); test(`compareContents ${pointer} should not pass any files through in identical directories`, async t => { const stream = gulp.src('fixture/identical/src/*') .pipe(changed('fixture/identical/trg', {hasChanged: changed.compareContents})); const files = await getStream.array(stream); t.is(files.length, 0); }); test(`compareContents ${pointer} should only pass through changed files using file extension`, async t => { const stream = gulp.src('fixture/different/src/*') .pipe(changed('fixture/different/trg', {hasChanged: changed.compareContents})); const files = await getStream.array(stream); t.is(files.length, 1); t.is(path.basename(files[0].path), 'b'); }); test(`compareContents ${pointer} should only pass through changed files using transformPath`, async t => { const stream = gulp.src('fixture/different.transformPath/src/*') .pipe(changed('fixture/different.transformPath/trg', { hasChanged: changed.compareContents, transformPath: newPath => { const pathParsed = path.parse(newPath); return path.join(pathParsed.dir, 'c', pathParsed.base); } })); const files = await getStream.array(stream); t.is(files.length, 1); t.is(path.basename(files[0].path), 'b'); }); test(`compareContents ${pointer} should only pass through changed files using extension .coffee`, async t => { const stream = gulp.src('fixture/different.ext/src/*') .pipe(changed('fixture/different.ext/trg', { hasChanged: changed.compareContents, extension: '.coffee' })); const files = await getStream.array(stream); t.is(files.length, 1); t.is(path.basename(files[0].path), 'b.typescript'); });