Only pass through files once until changed
  • TypeScript 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Cornelius Ukena a5a3872f3d
Merge pull request #22 from corneliusio/release/v3.0.1
v3.0.1: restore multiline pipe formatting in README
2026-08-24 16:36:00 -05:00
.github/workflows test: cover persistence, gulp integration, error paths, types, and Windows 2026-08-24 16:19:19 -05:00
dist fix: address v3 review findings 2026-08-24 16:19:19 -05:00
src fix: address v3 review findings 2026-08-24 16:19:19 -05:00
test test: tighten pipeline, null-content, and write-failure assertions 2026-08-24 16:19:19 -05:00
.gitattributes ci: fix Node 20 lane and Windows line endings 2026-08-24 16:19:01 -05:00
.gitignore feat!: rewrite in TypeScript as ESM with zero runtime dependencies 2026-08-24 16:19:06 -05:00
LICENSE Initial commit 2016-04-29 11:10:15 -05:00
oxfmt.config.ts feat!: rewrite in TypeScript as ESM with zero runtime dependencies 2026-08-24 16:19:06 -05:00
oxlint.config.ts feat!: rewrite in TypeScript as ESM with zero runtime dependencies 2026-08-24 16:19:06 -05:00
package.json chore(release): v3.0.1 2026-08-24 16:34:27 -05:00
pnpm-lock.yaml test: cover persistence, gulp integration, error paths, types, and Windows 2026-08-24 16:19:19 -05:00
pnpm-workspace.yaml fix: address v3 review findings 2026-08-24 16:19:19 -05:00
README.md docs: keep fluent pipe example multiline via prettier-ignore 2026-08-24 16:34:27 -05:00
tsconfig.build.json feat!: rewrite in TypeScript as ESM with zero runtime dependencies 2026-08-24 16:19:06 -05:00
tsconfig.consumer.json test: tighten pipeline, null-content, and write-failure assertions 2026-08-24 16:19:19 -05:00
tsconfig.json test: cover persistence, gulp integration, error paths, types, and Windows 2026-08-24 16:19:19 -05:00

gulp-once

NPM Version Build Status

Only pass through files once unless changed

Similar to plugins such as gulp-cache, gulp-changed, and gulp-newer, except it doesn't care about your dest/build files and it will still persist your "cache" (unless you don't want it to) across Gulp runs. Also makes it easy to manage what files are filtered since data is stored in an easily readable JSON file.

Requirements

  • Node.js 22.18 or newer (applies to gulp-once >=3.0.0; gulp-once 2.x still supports Node 8+)
  • Works from both ESM and CommonJS gulpfiles

Install

$ npm install gulp-once --save-dev

Usage

import gulp from 'gulp'
import once from 'gulp-once'
import someExpensiveOperation from 'some-expensive-operation'

export default () =>
    gulp.src('src/**/*')
        .pipe(once())
        .pipe(someExpensiveOperation())
        .pipe(gulp.dest('dest'))

CommonJS gulpfiles work too:

const once = require('gulp-once')

Options

gulp.src('src/**/*')
    .pipe(
        once({
            context: process.cwd(),
            namespace: false,
            algorithm: 'sha256',
            file: '.checksums',
            fileIndent: 4,
        }),
    )
    .pipe(someExpensiveOperation())
    .pipe(gulp.dest('dest'))

options.context

[string|boolean]: Sets the path used for calculating all files' relative path, which is then used as the hash key in your checksums file. Keys always use forward slashes, so checksum files are portable across operating systems. If you only wish to store filenames without their path, you can set this option to false. Default: process.cwd()

options.namespace

[string|function|boolean]: If you want to separate pools/namespaces of hashes for different tasks within the same checksums file, you can assign a namespace for a specific stream. You can also provide a function that dynamically sets the namespace per file — this function is called for every file and receives a copy of the vinyl file object being checked. Default: false

If you do not pass an object as an option to once(), it will be passed to this setting.

gulp.src('src/img/*')
    .pipe(once('images'))
    .pipe(someExpensiveOperation())
    .pipe(gulp.dest('dest/img'))

options.algorithm

[string]: Whatever you would want passed to crypto.hash(). File contents are hashed as raw bytes, so binary files are handled correctly. Default: 'sha256'

options.file

[string|boolean]: Path to file to persist data as JSON between Gulp runs. Is useful for retaining file details if Gulp exits unexpectedly and you have to restart, if you run tasks manually (i.e. you don't gulp.watch() files), or to just not run unnecessary actions between work sessions. Also allows you to easily "cache bust" specific files if you are so inclined. Can be set to false to store data in memory; this effectively turns off persistence as a file will not be created/updated with any file changes. Default: '.checksums'

The file is written atomically (temp file + rename), and a malformed or unreadable checksum file is ignored with a warning rather than crashing the build.

Note: a file's checksum is recorded when it passes through this plugin, not when the rest of your pipeline finishes. If a later step fails, delete the file's entry from the checksum file (or the whole file) to force it through again.

options.fileIndent

[int]: If you're a stickler for spacing on your files, you can set the indentation for the checksum file. Has no effect if options.file is set to false. Default: 4

Migrating from v2

  • Node 22.18+ is required. The package is now ESM with TypeScript types included; require('gulp-once') continues to work on supported Node versions. The bundled type declarations require TypeScript 5.6 or newer.
  • The default hash algorithm changed from sha1 to sha256, so every file will pass through once more after upgrading while the checksum file regenerates. Set algorithm: 'sha1' to keep existing checksum files valid.
  • Errors are now instances of GulpOnceError (with a plugin: 'gulp-once' property) instead of plugin-error. The class is a named export and is also available as once.GulpOnceError from CommonJS. The plugin has no runtime dependencies.
  • Upgrading from v2.1.x or earlier? v2.2.0 already fixed dynamic namespace functions (now called for every file), binary file hashing, and cross-instance cache isolation - see its release notes.