diff --git a/.gitattributes b/.gitattributes index 391f0a4..6313b56 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ -* text=auto -*.js text eol=lf +* text=auto eol=lf diff --git a/.github/funding.yml b/.github/funding.yml new file mode 100644 index 0000000..2c9ee28 --- /dev/null +++ b/.github/funding.yml @@ -0,0 +1,4 @@ +github: sindresorhus +open_collective: sindresorhus +tidelift: npm/gulp-debug +custom: https://sindresorhus.com/donate diff --git a/.github/security.md b/.github/security.md new file mode 100644 index 0000000..5358dc5 --- /dev/null +++ b/.github/security.md @@ -0,0 +1,3 @@ +# Security Policy + +To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..346585c --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,21 @@ +name: CI +on: + - push + - pull_request +jobs: + test: + name: Node.js ${{ matrix.node-version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-version: + - 20 + - 18 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2ae9d62..0000000 --- a/.travis.yml +++ /dev/null @@ -1,5 +0,0 @@ -language: node_js -node_js: - - '10' - - '8' - - '6' diff --git a/gulpfile.js b/gulpfile.js index 6f4932d..2ea0eb2 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,8 +1,7 @@ -'use strict'; -const gulp = require('gulp'); -const debug = require('.'); +import gulp from 'gulp'; +import debug from './index.js'; -gulp.task('default', () => - gulp.src('*') - .pipe(debug()) -); +export default function main() { + return gulp.src('*') + .pipe(debug()); +} diff --git a/index.js b/index.js index 08224f0..5346dc8 100644 --- a/index.js +++ b/index.js @@ -1,22 +1,22 @@ -'use strict'; -const path = require('path'); -const fancyLog = require('fancy-log'); -const through = require('through2'); -const tildify = require('tildify'); -const stringifyObject = require('stringify-object'); -const chalk = require('chalk'); -const plur = require('plur'); - -const prop = chalk.blue; - -module.exports = options => { - options = Object.assign({ - logger: fancyLog, +import process from 'node:process'; +import path from 'node:path'; +import tildify from 'tildify'; +import stringifyObject from 'stringify-object'; +import chalk from 'chalk'; +import plur from 'plur'; +import {gulpPlugin} from 'gulp-plugin-extras'; + +const styleProperty = chalk.blue; + +export default function gulpDebug(options) { + options = { + logger: console.log, title: 'gulp-debug:', minimal: true, showFiles: true, - showCount: true - }, options); + showCount: true, + ...options, + }; if (process.argv.includes('--verbose')) { options.verbose = true; @@ -27,28 +27,30 @@ module.exports = options => { let count = 0; - return through.obj((file, enc, cb) => { + return gulpPlugin('gulp-debug', file => { if (options.showFiles) { - const full = - '\n' + - (file.cwd ? 'cwd: ' + prop(tildify(file.cwd)) : '') + - (file.base ? '\nbase: ' + prop(tildify(file.base)) : '') + - (file.path ? '\npath: ' + prop(tildify(file.path)) : '') + - (file.stat && options.verbose ? '\nstat: ' + prop(stringifyObject(file.stat, {indent: ' '}).replace(/[{}]/g, '').trim()) : '') + - '\n'; + const full + = '\n' + + (file.cwd ? 'cwd: ' + styleProperty(tildify(file.cwd)) : '') + + (file.base ? '\nbase: ' + styleProperty(tildify(file.base)) : '') + + (file.path ? '\npath: ' + styleProperty(tildify(file.path)) : '') + + (file.stat && options.verbose ? '\nstat: ' + styleProperty(stringifyObject(file.stat, {indent: ' '}).replaceAll(/[{}]/g, '').trim()) : '') + + '\n'; - const output = options.minimal ? prop(path.relative(process.cwd(), file.path)) : full; + const output = options.minimal ? styleProperty(path.relative(process.cwd(), file.path)) : full; options.logger(options.title + ' ' + output); } count++; - cb(null, file); - }, cb => { - if (options.showCount) { - options.logger(options.title + ' ' + chalk.green(count + ' ' + plur('item', count))); - } - cb(); + return file; + }, { + supportsAnyType: true, + async * onFinish() { // eslint-disable-line require-yield + if (options.showCount) { + options.logger(options.title + ' ' + chalk.green(count + ' ' + plur('item', count))); + } + }, }); -}; +} diff --git a/license b/license index e7af2f7..fa7ceba 100644 --- a/license +++ b/license @@ -1,6 +1,6 @@ MIT License -Copyright (c) Sindre Sorhus (sindresorhus.com) +Copyright (c) Sindre Sorhus (https://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: diff --git a/package.json b/package.json index ed31437..b539cf8 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,19 @@ { "name": "gulp-debug", - "version": "4.0.0", + "version": "5.0.1", "description": "Debug Vinyl file streams to see what files are run through your Gulp pipeline", "license": "MIT", "repository": "sindresorhus/gulp-debug", + "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" + "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=6" + "node": ">=18" }, "scripts": { "test": "xo && ava" @@ -30,25 +33,28 @@ "fs" ], "dependencies": { - "chalk": "^2.3.0", - "fancy-log": "^1.3.2", - "plur": "^3.0.0", - "stringify-object": "^3.0.0", - "through2": "^2.0.0", - "tildify": "^1.1.2" + "chalk": "^5.3.0", + "gulp-plugin-extras": "^0.3.0", + "plur": "^5.1.0", + "stringify-object": "^5.0.0", + "tildify": "^3.0.0" }, "devDependencies": { - "ava": "*", - "gulp": "^4.0.0", - "p-event": "^1.0.0", - "sinon": "^4.1.3", - "strip-ansi": "^4.0.0", - "vinyl": "^2.1.0", - "xo": "*" + "ava": "^5.3.1", + "gulp": "^4.0.2", + "p-event": "^6.0.0", + "strip-ansi": "^7.1.0", + "vinyl": "^3.0.0", + "xo": "^0.56.0" }, "peerDependencies": { "gulp": ">=4" }, + "peerDependenciesMeta": { + "gulp": { + "optional": true + } + }, "ava": { "serial": true } diff --git a/readme.md b/readme.md index 0921840..427475c 100644 --- a/readme.md +++ b/readme.md @@ -1,77 +1,71 @@ -# gulp-debug [![Build Status](https://travis-ci.org/sindresorhus/gulp-debug.svg?branch=master)](https://travis-ci.org/sindresorhus/gulp-debug) +# gulp-debug > Debug [Vinyl](https://github.com/gulpjs/vinyl) file streams to see what files are run through your Gulp pipeline - ## Install +```sh +npm install --save-dev gulp-debug ``` -$ npm install --save-dev gulp-debug -``` - ## Usage ```js -const gulp = require('gulp'); -const debug = require('gulp-debug'); +import gulp from 'gulp'; +import debug from 'gulp-debug'; -gulp.task('default', () => +export default () => ( gulp.src('foo.js') .pipe(debug({title: 'unicorn:'})) .pipe(gulp.dest('dist')) ); ``` - ## API -### debug([options]) +### debug(options?) #### options -Type: `Object` +Type: `object` ##### title -Type: `string`
-Default: `gulp-debug:` +Type: `string`\ +Default: `'gulp-debug:'` Give it a custom title so it's possible to distinguish the output of multiple instances logging at once. ##### minimal -Type: `boolean`
+Type: `boolean`\ Default: `true` By default only relative paths are shown. Turn off minimal mode to also show `cwd`, `base`, `path`. -The [`stat` property](http://nodejs.org/api/fs.html#fs_class_fs_stats) will be shown when you run gulp in verbose mode: `gulp --verbose`. +The [`stat` property](https://nodejs.org/api/fs.html#fs_class_fs_stats) will be shown when you run gulp in verbose mode: `gulp --verbose`. ##### showFiles -Type: `boolean`
+Type: `boolean`\ Default: `true` Print filenames. ##### showCount -Type: `boolean`
+Type: `boolean`\ Default: `true` Print the file count. ##### logger(message) -Type: `Function`
-Default: [`fancy-log`](https://github.com/js-cli/fancy-log) - -Provide your own logging utility in place of [fancy-log](https://github.com/js-cli/fancy-log). The message is passed as a string in the first argument. Note that [ANSI colors](https://github.com/chalk/chalk) may be used in the message. - +Type: `Function`\ +Default: `console.log` -## License +Provide your own logging utility. -MIT © [Sindre Sorhus](https://sindresorhus.com) +The message is passed as a string in the first argument. Note that [ANSI colors](https://github.com/chalk/chalk) may be used in the message. diff --git a/test.js b/test.js index bd4dc28..e5ca813 100644 --- a/test.js +++ b/test.js @@ -1,15 +1,19 @@ -import fs from 'fs'; -import path from 'path'; +import {Buffer} from 'node:buffer'; +import fs from 'node:fs'; +import path from 'node:path'; +import {fileURLToPath} from 'node:url'; import test from 'ava'; import Vinyl from 'vinyl'; import stripAnsi from 'strip-ansi'; -import pEvent from 'p-event'; -import debug from '.'; +import {pEvent} from 'p-event'; +import debug from './index.js'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); const logInspect = { messages: [], - logger(msg) { - logInspect.messages.push(stripAnsi(msg)); + logger(message) { + logInspect.messages.push(stripAnsi(message)); }, get notCalled() { return this.messages.length === 0; @@ -18,8 +22,8 @@ const logInspect = { return this.messages[0]; }, get lastMessage() { - return this.messages[this.messages.length - 1]; - } + return this.messages.at(-1); + }, }; let file; @@ -32,14 +36,14 @@ test.beforeEach(() => { base: __dirname, path: path.join(__dirname, 'foo.js'), stat: fs.statSync('test.js'), - contents: Buffer.from('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') + contents: Buffer.from('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.'), }); }); test('output debug info', async t => { const stream = debug({ logger: logInspect.logger, - title: 'unicorn:' + title: 'unicorn:', }); const finish = pEvent(stream, 'finish'); stream.end(file); @@ -51,7 +55,7 @@ test('output debug info', async t => { test('output singular item count', async t => { const stream = debug({ logger: logInspect.logger, - title: 'unicorn:' + title: 'unicorn:', }); const finish = pEvent(stream, 'finish'); stream.end(file); @@ -63,7 +67,7 @@ test('output singular item count', async t => { test('output zero item count', async t => { const stream = debug({ logger: logInspect.logger, - title: 'unicorn:' + title: 'unicorn:', }); const finish = pEvent(stream, 'finish'); stream.end(); @@ -75,7 +79,7 @@ test('output zero item count', async t => { test('output plural item count', async t => { const stream = debug({ logger: logInspect.logger, - title: 'unicorn:' + title: 'unicorn:', }); const finish = pEvent(stream, 'finish'); @@ -92,7 +96,7 @@ test('do not output file names when `showFiles` is false', async t => { const stream = debug({ logger: logInspect.logger, title: 'unicorn:', - showFiles: false + showFiles: false, }); const finish = pEvent(stream, 'finish'); @@ -119,7 +123,7 @@ test('do not output count when `showCount` is false', async t => { const stream = debug({ logger: logInspect.logger, title: 'unicorn:', - showCount: false + showCount: false, }); const finish = pEvent(stream, 'finish');