From 8fe9c6451c4affa9a5c8b765194f4c0876587e00 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 1 Jul 2022 14:14:01 -0700 Subject: [PATCH 1/9] chore!: Normalize repository, dropping node <10.13 support (#22) chore: Run type tests in CI fix!: Allow to be constructed without new fix: Remove defaulting name since it is always set chore: Improve test coverage --- .github/workflows/dev.yml | 77 +++++++++++++++++++++ .github/workflows/release.yml | 16 +++++ .gitignore | 50 ++++++++++++-- .jscsrc | 3 - .npmrc | 1 + .prettierignore | 3 + .travis.yml | 10 --- LICENSE | 2 +- README.md | 20 +++--- appveyor.yml | 25 ------- index.js | 63 ++++++++++------- package.json | 42 ++++++------ test/.eslintrc | 3 - test/.gitkeep | 0 test/index.js | 124 ++++++++++++++++++++++------------ 15 files changed, 290 insertions(+), 149 deletions(-) create mode 100644 .github/workflows/dev.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .jscsrc create mode 100644 .npmrc create mode 100644 .prettierignore delete mode 100644 .travis.yml delete mode 100644 appveyor.yml delete mode 100644 test/.eslintrc create mode 100644 test/.gitkeep diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 0000000..7d21f8a --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,77 @@ +name: dev +on: + pull_request: + push: + branches: + - master + - main +env: + CI: true + +jobs: + prettier: + name: Format code + runs-on: ubuntu-latest + if: ${{ github.event_name == 'push' }} + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Prettier + uses: gulpjs/prettier_action@v3.0 + with: + commit_message: 'chore: Run prettier' + prettier_options: '--write .' + + test: + name: Tests for Node ${{ matrix.node }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + node: [10, 12, 14, 16] + os: [ubuntu-latest, windows-latest, macos-latest] + + steps: + - name: Clone repository + uses: actions/checkout@v2 + + - name: Set Node.js version + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node }} + + - run: node --version + - run: npm --version + + - name: Install npm dependencies + run: npm install + + - name: Run lint + run: npm run lint + + - name: Run tests + run: | + npm test + npm run test-types + + - name: Coveralls + uses: coverallsapp/github-action@v1.1.2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + flag-name: ${{matrix.os}}-node-${{ matrix.node }} + parallel: true + + coveralls: + needs: test + name: Finish up + + runs-on: ubuntu-latest + steps: + - name: Coveralls Finished + uses: coverallsapp/github-action@v1.1.2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + parallel-finished: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..87cd13c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,16 @@ +name: release +on: + push: + branches: + - master + - main + +jobs: + release-please: + runs-on: ubuntu-latest + steps: + - uses: GoogleCloudPlatform/release-please-action@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + release-type: node + package-name: release-please-action diff --git a/.gitignore b/.gitignore index 6f63646..58a757a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,15 @@ # Logs logs *.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* # Runtime data pids *.pid *.seed +*.pid.lock # Directory for instrumented libs generated by jscoverage/JSCover lib-cov @@ -13,19 +17,51 @@ lib-cov # Coverage directory used by tools like istanbul coverage +# nyc test coverage +.nyc_output + # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt -# Compiled binary addons (http://nodejs.org/api/addons.html) +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) build/Release -# Dependency directory -# Commenting this out is preferred by some people, see -# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- -node_modules +# Dependency directories +node_modules/ +jspm_packages/ -# Users Environment Variables -.lock-wscript +# TypeScript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +# next.js build output +.next # Garbage files .DS_Store + +# Test results +test.xunit diff --git a/.jscsrc b/.jscsrc deleted file mode 100644 index 703b33f..0000000 --- a/.jscsrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "preset": "gulp" -} diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..c96ebe0 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +coverage/ +.nyc_output/ +CHANGELOG.md diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f621cab..0000000 --- a/.travis.yml +++ /dev/null @@ -1,10 +0,0 @@ -sudo: false -language: node_js -node_js: - - '8' - - '6' - - '4' - - '0.12' - - '0.10' -after_script: - - npm run coveralls diff --git a/LICENSE b/LICENSE index e6755b6..182ee73 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Blaine Bublitz , Eric Schoffstall and other contributors +Copyright (c) 2015, 2017-2018, 2022 Blaine Bublitz and Eric Schoffstall Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index f5199c8..d07cf27 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ # plugin-error -[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url] +[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url] Error handling for Vinyl plugins. @@ -52,18 +52,14 @@ Error constructor that takes: MIT -[downloads-image]: http://img.shields.io/npm/dm/plugin-error.svg + +[downloads-image]: https://img.shields.io/npm/dm/plugin-error.svg?style=flat-square [npm-url]: https://www.npmjs.com/package/plugin-error -[npm-image]: http://img.shields.io/npm/v/plugin-error.svg +[npm-image]: https://img.shields.io/npm/v/plugin-error.svg?style=flat-square -[travis-url]: https://travis-ci.org/gulpjs/plugin-error -[travis-image]: http://img.shields.io/travis/gulpjs/plugin-error.svg?label=travis-ci - -[appveyor-url]: https://ci.appveyor.com/project/gulpjs/plugin-error -[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/plugin-error.svg?label=appveyor +[ci-url]: https://github.com/gulpjs/plugin-error/actions?query=workflow:dev +[ci-image]: https://img.shields.io/github/workflow/status/gulpjs/plugin-error/dev?style=flat-square [coveralls-url]: https://coveralls.io/r/gulpjs/plugin-error -[coveralls-image]: http://img.shields.io/coveralls/gulpjs/plugin-error/master.svg - -[gitter-url]: https://gitter.im/gulpjs/gulp -[gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg +[coveralls-image]: https://img.shields.io/coveralls/gulpjs/plugin-error/master.svg?style=flat-square + diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index e2d9fb3..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,25 +0,0 @@ -# http://www.appveyor.com/docs/appveyor-yml -# http://www.appveyor.com/docs/lang/nodejs-iojs - -environment: - matrix: - # node.js - - nodejs_version: "0.10" - - nodejs_version: "0.12" - - nodejs_version: "4" - - nodejs_version: "6" - - nodejs_version: "8" - -install: - - ps: Install-Product node $env:nodejs_version - - npm install - -test_script: - - node --version - - npm --version - - cmd: npm test - -build: off - -# build version format -version: "{build}" diff --git a/index.js b/index.js index a4d360d..5dbc8fc 100644 --- a/index.js +++ b/index.js @@ -1,16 +1,30 @@ var util = require('util'); var colors = require('ansi-colors'); -var extend = require('extend-shallow'); -var differ = require('arr-diff'); -var union = require('arr-union'); var nonEnum = ['message', 'name', 'stack']; -var ignored = union(nonEnum, ['__safety', '_stack', 'plugin', 'showProperties', 'showStack']); -var props = ['fileName', 'lineNumber', 'message', 'name', 'plugin', 'showProperties', 'showStack', 'stack']; +var ignored = new Set( + nonEnum.concat([ + '__safety', + '_stack', + 'plugin', + 'showProperties', + 'showStack', + ]) +); +var props = [ + 'fileName', + 'lineNumber', + 'message', + 'name', + 'plugin', + 'showProperties', + 'showStack', + 'stack', +]; function PluginError(plugin, message, options) { if (!(this instanceof PluginError)) { - throw new Error('Call PluginError using new'); + return new PluginError(plugin, message, options); } Error.call(this); @@ -19,27 +33,23 @@ function PluginError(plugin, message, options) { // If opts has an error, get details from it if (typeof opts.error === 'object') { - var keys = union(Object.keys(opts.error), nonEnum); + var keys = new Set(Object.keys(opts.error).concat(nonEnum)); // These properties are not enumerable, so we have to add them explicitly. - keys.forEach(function(prop) { + keys.forEach(function (prop) { self[prop] = opts.error[prop]; }); } // Opts object can override - props.forEach(function(prop) { + props.forEach(function (prop) { if (prop in opts) { this[prop] = opts[prop]; } }, this); // Defaults - if (!this.name) { - this.name = 'Error'; - } if (!this.stack) { - /** * `Error.captureStackTrace` appends a stack property which * relies on the toString method of the object it is applied to. @@ -50,7 +60,7 @@ function PluginError(plugin, message, options) { */ var safety = {}; - safety.toString = function() { + safety.toString = function () { return this._messageWithDetails() + '\nStack:'; }.bind(this); @@ -71,7 +81,7 @@ util.inherits(PluginError, Error); * Output a formatted message with details */ -PluginError.prototype._messageWithDetails = function() { +PluginError.prototype._messageWithDetails = function () { var msg = 'Message:\n ' + this.message; var details = this._messageDetails(); if (details !== '') { @@ -84,12 +94,14 @@ PluginError.prototype._messageWithDetails = function() { * Output actual message details */ -PluginError.prototype._messageDetails = function() { +PluginError.prototype._messageDetails = function () { if (!this.showProperties) { return ''; } - var props = differ(Object.keys(this), ignored); + var props = Object.keys(this).filter(function (key) { + return !ignored.has(key); + }); var len = props.length; if (len === 0) { @@ -111,8 +123,8 @@ PluginError.prototype._messageDetails = function() { * Override the `toString` method */ -PluginError.prototype.toString = function() { - var detailsWithStack = function(stack) { +PluginError.prototype.toString = function () { + var detailsWithStack = function (stack) { return this._messageWithDetails() + '\nStack:\n' + stack; }.bind(this); @@ -121,10 +133,8 @@ PluginError.prototype.toString = function() { // If there is no wrapped error, use the stack captured in the PluginError ctor if (this.__safety) { msg = this.__safety.stack; - } else if (this._stack) { msg = detailsWithStack(this._stack); - } else { // Stack from wrapped error msg = detailsWithStack(this.stack); @@ -177,10 +187,13 @@ function setDefaults(plugin, message, opts) { */ function defaults(opts) { - return extend({ - showStack: false, - showProperties: true, - }, opts); + return Object.assign( + { + showStack: false, + showProperties: true, + }, + opts + ); } /** diff --git a/package.json b/package.json index cd75f29..2c9f0d8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "plugin-error", "version": "1.0.1", "description": "Error handling for Vinyl plugins.", - "author": "Gulp Team (http://gulpjs.com/)", + "author": "Gulp Team (https://gulpjs.com/)", "contributors": [ "Jon Schlinkert ", "Blaine Bublitz " @@ -10,7 +10,7 @@ "repository": "gulpjs/plugin-error", "license": "MIT", "engines": { - "node": ">= 0.10" + "node": ">=10.13.0" }, "main": "index.js", "files": [ @@ -19,29 +19,31 @@ "index.js" ], "scripts": { - "lint": "eslint . && jscs index.js test/", + "lint": "eslint .", "pretest": "npm run lint", - "test": "mocha --async-only && npm run test-types", - "test-types": "tsc -p test/types", - "cover": "istanbul cover _mocha --report lcovonly", - "coveralls": "npm run cover && istanbul-coveralls" + "test": "nyc mocha --async-only", + "test-types": "tsc -p test/types" }, "dependencies": { - "ansi-colors": "^1.0.1", - "arr-diff": "^4.0.0", - "arr-union": "^3.1.0", - "extend-shallow": "^3.0.2" + "ansi-colors": "^1.0.1" }, "devDependencies": { - "eslint": "^1.7.3", - "eslint-config-gulp": "^2.0.0", - "expect": "^1.20.2", - "istanbul": "^0.4.3", - "istanbul-coveralls": "^1.0.3", - "jscs": "^2.3.5", - "jscs-preset-gulp": "^1.0.0", - "mocha": "^3.0.0", - "typescript": "^2.6.2" + "eslint": "^7.0.0", + "eslint-config-gulp": "^5.0.0", + "eslint-plugin-node": "^11.1.0", + "expect": "^27.0.0", + "mocha": "^8.0.0", + "nyc": "^15.0.0", + "typescript": "^4.7.4" + }, + "nyc": { + "reporter": [ + "lcov", + "text-summary" + ] + }, + "prettier": { + "singleQuote": true }, "keywords": [ "error", diff --git a/test/.eslintrc b/test/.eslintrc deleted file mode 100644 index 06b940f..0000000 --- a/test/.eslintrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "gulp/test" -} diff --git a/test/.gitkeep b/test/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/index.js b/test/index.js index b9c2da0..2b4466c 100644 --- a/test/index.js +++ b/test/index.js @@ -4,41 +4,64 @@ var expect = require('expect'); var PluginError = require('../'); -describe('PluginError()', function() { - it('should default name to Error', function(done) { +describe('PluginError()', function () { + it('should default name to Error', function (done) { var err = new PluginError('test', 'something broke'); expect(err.name).toEqual('Error'); done(); }); - it('should default name to Error, even when wrapped error has no name', function(done) { + it('can be constructed without new', function (done) { + var err = PluginError('test', 'something broke'); + expect(err).toBeInstanceOf(PluginError); + done(); + }); + + it('throws if plugin name not set', function (done) { + expect(function () { + new PluginError(undefined, 'something broke'); + }).toThrow(/Missing plugin name/); + done(); + }); + + it('throws if message not set', function (done) { + expect(function () { + new PluginError('test'); + }).toThrow(/Missing error message/); + done(); + }); + + it('should default name to Error, even when wrapped error has no name', function (done) { var realErr = { message: 'something broke' }; var err = new PluginError('test', realErr); expect(err.name).toEqual('Error'); done(); }); - it('should print the plugin name in toString', function(done) { + it('should print the plugin name in toString', function (done) { var err = new PluginError('test', 'something broke'); expect(err.toString()).toContain('test'); done(); }); - it('should not include the stack by default in toString', function(done) { + it('should not include the stack by default in toString', function (done) { var err = new PluginError('test', 'something broke'); // Just check that there are no 'at' lines - expect(err.toString()).toNotContain('at'); + expect(err.toString()).not.toContain('at'); done(); }); - it('should include the stack when specified in toString', function(done) { - var err = new PluginError('test', 'something broke', { stack: 'at huh', showStack: true }); + it('should include the stack when specified in toString', function (done) { + var err = new PluginError('test', 'something broke', { + stack: 'at huh', + showStack: true, + }); // Just check that there are 'at' lines expect(err.toString()).toContain('at'); done(); }); - it('should take arguments as one object', function(done) { + it('should take arguments as one object', function (done) { var err = new PluginError({ plugin: 'test', message: 'something broke', @@ -48,7 +71,7 @@ describe('PluginError()', function() { done(); }); - it('should take arguments as plugin name and one object', function(done) { + it('should take arguments as plugin name and one object', function (done) { var err = new PluginError('test', { message: 'something broke', }); @@ -57,14 +80,14 @@ describe('PluginError()', function() { done(); }); - it('should take arguments as plugin name and message', function(done) { + it('should take arguments as plugin name and message', function (done) { var err = new PluginError('test', 'something broke'); expect(err.plugin).toEqual('test'); expect(err.message).toEqual('something broke'); done(); }); - it('should take arguments as plugin name, message, and one object', function(done) { + it('should take arguments as plugin name, message, and one object', function (done) { var err = new PluginError('test', 'something broke', { showStack: true }); expect(err.plugin).toEqual('test'); expect(err.message).toEqual('something broke'); @@ -72,10 +95,13 @@ describe('PluginError()', function() { done(); }); - it('should take arguments as plugin name, error, and one object', function(done) { + it('should take arguments as plugin name, error, and one object', function (done) { var realErr = new Error('something broke'); realErr.fileName = 'original.js'; - var err = new PluginError('test', realErr, { showStack: true, fileName: 'override.js' }); + var err = new PluginError('test', realErr, { + showStack: true, + fileName: 'override.js', + }); expect(err.plugin).toEqual('test'); expect(err.message).toEqual('something broke'); expect(err.fileName).toEqual('override.js'); @@ -83,7 +109,7 @@ describe('PluginError()', function() { done(); }); - it('should take properties from error', function(done) { + it('should take properties from error', function (done) { var realErr = new Error('something broke'); realErr.abstractProperty = 'abstract'; var err = new PluginError('test', realErr); @@ -93,103 +119,115 @@ describe('PluginError()', function() { done(); }); - it('should be configured to show properties by default', function(done) { + it('should be configured to show properties by default', function (done) { var err = new PluginError('test', 'something broke'); expect(err.showProperties).toBe(true); done(); }); - it('should not be configured to take option to show properties', function(done) { - var err = new PluginError('test', 'something broke', { showProperties: false }); + it('should not be configured to take option to show properties', function (done) { + var err = new PluginError('test', 'something broke', { + showProperties: false, + }); expect(err.showProperties).toBe(false); done(); }); - it('should show properties', function(done) { + it('should show properties', function (done) { var err = new PluginError('test', 'it broke', { showProperties: true }); err.fileName = 'original.js'; err.lineNumber = 35; expect(err.toString()).toContain('it broke'); - expect(err.toString()).toNotContain('message:'); + expect(err.toString()).not.toContain('message:'); expect(err.toString()).toContain('fileName:'); done(); }); - it('should show properties', function(done) { + it('should show properties', function (done) { var realErr = new Error('something broke'); realErr.fileName = 'original.js'; realErr.lineNumber = 35; var err = new PluginError('test', realErr, { showProperties: true }); - expect(err.toString()).toNotContain('message:'); + expect(err.toString()).not.toContain('message:'); expect(err.toString()).toContain('fileName:'); done(); }); - it('should not show properties', function(done) { + it('should not show properties', function (done) { var realErr = new Error('something broke'); realErr.fileName = 'original.js'; realErr.lineNumber = 35; var err = new PluginError('test', realErr, { showProperties: false }); - expect(err.toString()).toNotContain('message:'); - expect(err.toString()).toNotContain('fileName:'); + expect(err.toString()).not.toContain('message:'); + expect(err.toString()).not.toContain('fileName:'); done(); }); - it('should not show properties, but should show stack', function(done) { - var err = new PluginError('test', 'it broke', { stack: 'test stack', showStack: true, showProperties: false }); + it('should not show properties, but should show stack', function (done) { + var err = new PluginError('test', 'it broke', { + stack: 'test stack', + showStack: true, + showProperties: false, + }); err.fileName = 'original.js'; err.lineNumber = 35; - expect(err.toString()).toNotContain('message:'); - expect(err.toString()).toNotContain('fileName:'); + expect(err.toString()).not.toContain('message:'); + expect(err.toString()).not.toContain('fileName:'); expect(err.toString()).toContain('test stack'); done(); }); - it('should not show properties, but should show stack for real error', function(done) { + it('should not show properties, but should show stack for real error', function (done) { var realErr = new Error('something broke'); realErr.fileName = 'original.js'; realErr.lineNumber = 35; realErr.stack = 'test stack'; - var err = new PluginError('test', realErr, { showStack: true, showProperties: false }); + var err = new PluginError('test', realErr, { + showStack: true, + showProperties: false, + }); expect(err.toString().indexOf('message:')).toEqual(-1); expect(err.toString().indexOf('fileName:')).toEqual(-1); - expect(err.toString().indexOf('test stack')).toNotEqual(-1); + expect(err.toString().indexOf('test stack')).not.toEqual(-1); done(); }); - it('should not show properties, but should show stack for _stack', function(done) { + it('should not show properties, but should show stack for _stack', function (done) { var realErr = new Error('something broke'); realErr.fileName = 'original.js'; realErr.lineNumber = 35; realErr._stack = 'test stack'; - var err = new PluginError('test', realErr, { showStack: true, showProperties: false }); + var err = new PluginError('test', realErr, { + showStack: true, + showProperties: false, + }); expect(err.toString().indexOf('message:')).toEqual(-1); expect(err.toString().indexOf('fileName:')).toEqual(-1); - expect(err.toString().indexOf('test stack')).toNotEqual(-1); + expect(err.toString().indexOf('test stack')).not.toEqual(-1); done(); }); - it('should show properties and stack', function(done) { + it('should show properties and stack', function (done) { var realErr = new Error('something broke'); realErr.fileName = 'original.js'; realErr.stack = 'test stack'; var err = new PluginError('test', realErr, { showStack: true }); expect(err.toString().indexOf('message:')).toEqual(-1); - expect(err.toString().indexOf('fileName:')).toNotEqual(-1); - expect(err.toString().indexOf('test stack')).toNotEqual(-1); + expect(err.toString().indexOf('fileName:')).not.toEqual(-1); + expect(err.toString().indexOf('test stack')).not.toEqual(-1); done(); }); - it('should show properties added after the error is created', function(done) { + it('should show properties added after the error is created', function (done) { var realErr = new Error('something broke'); var err = new PluginError('test', realErr); err.fileName = 'original.js'; expect(err.toString().indexOf('message:')).toEqual(-1); - expect(err.toString().indexOf('fileName:')).toNotEqual(-1); + expect(err.toString().indexOf('fileName:')).not.toEqual(-1); done(); }); - it('should toString quickly', function(done) { + it('should toString quickly', function (done) { this.timeout(100); var err = new PluginError('test', 'it broke', { showStack: true }); @@ -198,7 +236,7 @@ describe('PluginError()', function() { done(); }); - it('should toString quickly with original error', function(done) { + it('should toString quickly with original error', function (done) { this.timeout(100); var realErr = new Error('it broke'); @@ -208,7 +246,7 @@ describe('PluginError()', function() { done(); }); - it('should not show "Details:" if there are no properties to show', function(done) { + it('should not show "Details:" if there are no properties to show', function (done) { var err = new PluginError('plugin', 'message'); expect(err.toString().indexOf('Details:')).toEqual(-1); done(); From 334c165d0fd30d46df64101fcafba77362c5e3af Mon Sep 17 00:00:00 2001 From: phated Date: Fri, 1 Jul 2022 21:14:23 +0000 Subject: [PATCH 2/9] chore: Run prettier --- README.md | 19 ++++++++------- index.d.ts | 20 ++++++++++++---- test/types/test.ts | 51 ++++++++++++++++++++++++---------------- test/types/tsconfig.json | 12 +++------- 4 files changed, 59 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index d07cf27..1b261f0 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,12 @@ Error handling for Vinyl plugins. var PluginError = require('plugin-error'); var err = new PluginError('test', { - message: 'something broke' + message: 'something broke', }); var err = new PluginError({ plugin: 'test', - message: 'something broke' + message: 'something broke', }); var err = new PluginError('test', 'something broke'); @@ -37,16 +37,17 @@ var err = new PluginError('test', existingError, { showStack: true }); ### `new PluginError(pluginName, message[, options])` Error constructor that takes: -* `pluginName` - a `String` that should be the module name of your plugin -* `message` - a `String` message or an existing `Error` object -* `options` - an `Object` of your options + +- `pluginName` - a `String` that should be the module name of your plugin +- `message` - a `String` message or an existing `Error` object +- `options` - an `Object` of your options **Behavior:** -* By default the stack will not be shown. Set `options.showStack` to true if you think the stack is important for your error. -* If you pass an error object as the message the stack will be pulled from that, otherwise one will be created. -* If you pass in a custom stack string you need to include the message along with that. -* Error properties will be included in `err.toString()`, but may be omitted by including `{ showProperties: false }` in the options. +- By default the stack will not be shown. Set `options.showStack` to true if you think the stack is important for your error. +- If you pass an error object as the message the stack will be pulled from that, otherwise one will be created. +- If you pass in a custom stack string you need to include the message along with that. +- Error properties will be included in `err.toString()`, but may be omitted by including `{ showProperties: false }` in the options. ## License diff --git a/index.d.ts b/index.d.ts index 4ff8f54..07c6eb5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5,25 +5,36 @@ declare namespace PluginError { * @param error Base error * @param options Error options */ - new (plugin: string, error: E, options?: Options): PluginError; + new ( + plugin: string, + error: E, + options?: Options + ): PluginError; /** * @param plugin Plugin name * @param error Base error or error message * @param options Error options */ - new (plugin: string, error: E | string, options: Options): PluginError; + new ( + plugin: string, + error: E | string, + options: Options + ): PluginError; /** * @param plugin Plugin name * @param error Base error, error message, or options with message */ - new (plugin: string, error: E | string | (Options & {message: string})): PluginError; + new ( + plugin: string, + error: E | string | (Options & { message: string }) + ): PluginError; /** * @param options Options with plugin name and message */ - new(options: Options & {plugin: string, message: string}): PluginError; + new (options: Options & { plugin: string; message: string }): PluginError; } interface Options { @@ -42,7 +53,6 @@ declare namespace PluginError { */ fileName?: string; - /** * Line number where the error occurred */ diff --git a/test/types/test.ts b/test/types/test.ts index cc963ff..0c641d5 100644 --- a/test/types/test.ts +++ b/test/types/test.ts @@ -1,41 +1,46 @@ -import PluginError = require("plugin-error"); +import PluginError = require('plugin-error'); { // Check constructor signatures // See: https://github.com/gulpjs/gulp-util#new-pluginerrorpluginname-message-options { - const err = new PluginError("test", { - message: "something broke", + const err = new PluginError('test', { + message: 'something broke', }); } { const err = new PluginError({ - plugin: "test", - message: "something broke", + plugin: 'test', + message: 'something broke', }); } { - const err = new PluginError("test", "something broke"); + const err = new PluginError('test', 'something broke'); } { - const err = new PluginError("test", "something broke", {showStack: true}); + const err = new PluginError('test', 'something broke', { showStack: true }); } { - const existingError = new Error("OMG"); - const options: PluginError.Options = {showStack: true}; - const err = new PluginError("test", existingError, options); + const existingError = new Error('OMG'); + const options: PluginError.Options = { showStack: true }; + const err = new PluginError('test', existingError, options); } } { { // Check available properties - const realErr = Object.assign(new Error("something broke"), {fileName: "original.js"}); - const err = new PluginError("test", realErr, {showStack: true, fileName: "override.js"}); + const realErr = Object.assign(new Error('something broke'), { + fileName: 'original.js', + }); + const err = new PluginError('test', realErr, { + showStack: true, + fileName: 'override.js', + }); const plugin: string = err.plugin; const message: string = err.message; const fileName: string = err.fileName; @@ -44,8 +49,10 @@ import PluginError = require("plugin-error"); } { // Inference of custom properties from `error` argument, - const realErr = Object.assign(new Error("something broke"), {abstractProperty: "abstract"}); - const err = new PluginError("test", realErr, realErr); + const realErr = Object.assign(new Error('something broke'), { + abstractProperty: 'abstract', + }); + const err = new PluginError('test', realErr, realErr); const plugin: string = err.plugin; const message: string = err.message; const abstractProperty: string = err.abstractProperty; @@ -54,16 +61,18 @@ import PluginError = require("plugin-error"); { // Union types - const PLUGIN_NAME: string = "test"; + const PLUGIN_NAME: string = 'test'; interface FooError extends Error { foo: number; } - const ERROR: Error = new Error("something broke"); - const FOO_ERROR: FooError = Object.assign(new Error("something broke"), {foo: 1}); - const MESSAGE: string = "something broke"; - const OPTIONS: {message: string} = {message: "something broke"}; + const ERROR: Error = new Error('something broke'); + const FOO_ERROR: FooError = Object.assign(new Error('something broke'), { + foo: 1, + }); + const MESSAGE: string = 'something broke'; + const OPTIONS: { message: string } = { message: 'something broke' }; { function createError(error: Error | string) { @@ -116,7 +125,9 @@ import PluginError = require("plugin-error"); { // Check support for unions with option object - function createError(error: FooError | string | (PluginError.Options & {message: string})) { + function createError( + error: FooError | string | (PluginError.Options & { message: string }) + ) { return new PluginError(PLUGIN_NAME, error); } diff --git a/test/types/tsconfig.json b/test/types/tsconfig.json index 24ac961..f07fa4f 100644 --- a/test/types/tsconfig.json +++ b/test/types/tsconfig.json @@ -19,9 +19,7 @@ "inlineSourceMap": false, "inlineSources": false, "isolatedModules": false, - "lib": [ - "es2017" - ], + "lib": ["es2017"], "locale": "en-us", "module": "commonjs", "moduleResolution": "node", @@ -40,9 +38,7 @@ "noLib": false, "noResolve": false, "paths": { - "plugin-error": [ - "index.d.ts" - ] + "plugin-error": ["index.d.ts"] }, "preserveConstEnums": true, "removeComments": false, @@ -56,8 +52,6 @@ "target": "es2017", "traceResolution": false }, - "include": [ - "./**/*.ts" - ], + "include": ["./**/*.ts"], "exclude": [] } From 6c05aba3efef1a4dd94b3a5f33a501dd76c1b842 Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Fri, 1 Jul 2022 23:21:25 +0200 Subject: [PATCH 3/9] fix!: Avoid modifying arguments (#21) --- index.js | 7 +++---- test/index.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 5dbc8fc..15abdc6 100644 --- a/index.js +++ b/index.js @@ -164,13 +164,12 @@ function setDefaults(plugin, message, opts) { if (typeof plugin === 'object') { return defaults(plugin); } - opts = opts || {}; if (message instanceof Error) { - opts.error = message; + opts = Object.assign({}, opts, { error: message }); } else if (typeof message === 'object') { - opts = message; + opts = Object.assign({}, message); } else { - opts.message = message; + opts = Object.assign({}, opts, { message: message }); } opts.plugin = plugin; return defaults(opts); diff --git a/test/index.js b/test/index.js index 2b4466c..b927825 100644 --- a/test/index.js +++ b/test/index.js @@ -251,4 +251,18 @@ describe('PluginError()', function () { expect(err.toString().indexOf('Details:')).toEqual(-1); done(); }); + + it('should not modify error argument', function(done) { + var realErr = { message: 'something broke' }; + new PluginError('test', realErr); + expect(realErr).toEqual({ message: 'something broke' }); + done(); + }); + + it('should not modify options argument', function(done) { + var opts = { showStack: true }; + new PluginError('test', 'message', opts); + expect(opts).toEqual({ showStack: true }); + done(); + }); }); From 4e9522fd8f4b5120557f7e637789082e5d9ca97b Mon Sep 17 00:00:00 2001 From: phated Date: Fri, 1 Jul 2022 21:21:51 +0000 Subject: [PATCH 4/9] chore: Run prettier --- test/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/index.js b/test/index.js index b927825..ca7fc01 100644 --- a/test/index.js +++ b/test/index.js @@ -252,14 +252,14 @@ describe('PluginError()', function () { done(); }); - it('should not modify error argument', function(done) { + it('should not modify error argument', function (done) { var realErr = { message: 'something broke' }; new PluginError('test', realErr); expect(realErr).toEqual({ message: 'something broke' }); done(); }); - it('should not modify options argument', function(done) { + it('should not modify options argument', function (done) { var opts = { showStack: true }; new PluginError('test', 'message', opts); expect(opts).toEqual({ showStack: true }); From 932946a72ed8911aaa362ce09ef9d14931a97542 Mon Sep 17 00:00:00 2001 From: Brian Dukes Date: Fri, 1 Jul 2022 16:25:03 -0500 Subject: [PATCH 5/9] fix!: Don't include domain information in output (#19) --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 15abdc6..8fc412e 100644 --- a/index.js +++ b/index.js @@ -9,6 +9,8 @@ var ignored = new Set( 'plugin', 'showProperties', 'showStack', + 'domain', + 'domainThrown' ]) ); var props = [ From ca849db73b2c5391c3915a44f0ea7e88901ac83a Mon Sep 17 00:00:00 2001 From: phated Date: Fri, 1 Jul 2022 21:25:34 +0000 Subject: [PATCH 6/9] chore: Run prettier --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 8fc412e..1677dcb 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,7 @@ var ignored = new Set( 'showProperties', 'showStack', 'domain', - 'domainThrown' + 'domainThrown', ]) ); var props = [ From 65e5b6d583ec2591ba965a3c62016d73f5bf14fe Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 1 Jul 2022 14:29:16 -0700 Subject: [PATCH 7/9] chore: Release 2.0.0 (#23) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 23 +++++++++++++++++++++++ package.json | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..4582410 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,23 @@ +# Changelog + +## [2.0.0](https://www.github.com/gulpjs/plugin-error/compare/v1.0.1...v2.0.0) (2022-07-01) + + +### ⚠ BREAKING CHANGES + +* Don't include domain information in output (#19) +* Avoid modifying arguments (#21) +* Allow to be constructed without new +* Normalize repository, dropping node <10.13 support (#22) + +### Bug Fixes + +* Allow to be constructed without new ([8fe9c64](https://www.github.com/gulpjs/plugin-error/commit/8fe9c6451c4affa9a5c8b765194f4c0876587e00)) +* Avoid modifying arguments ([#21](https://www.github.com/gulpjs/plugin-error/issues/21)) ([6c05aba](https://www.github.com/gulpjs/plugin-error/commit/6c05aba3efef1a4dd94b3a5f33a501dd76c1b842)) +* Don't include domain information in output ([#19](https://www.github.com/gulpjs/plugin-error/issues/19)) ([932946a](https://www.github.com/gulpjs/plugin-error/commit/932946a72ed8911aaa362ce09ef9d14931a97542)) +* Remove defaulting name since it is always set ([8fe9c64](https://www.github.com/gulpjs/plugin-error/commit/8fe9c6451c4affa9a5c8b765194f4c0876587e00)) + + +### Miscellaneous Chores + +* Normalize repository, dropping node <10.13 support ([#22](https://www.github.com/gulpjs/plugin-error/issues/22)) ([8fe9c64](https://www.github.com/gulpjs/plugin-error/commit/8fe9c6451c4affa9a5c8b765194f4c0876587e00)) diff --git a/package.json b/package.json index 2c9f0d8..05c8584 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plugin-error", - "version": "1.0.1", + "version": "2.0.0", "description": "Error handling for Vinyl plugins.", "author": "Gulp Team (https://gulpjs.com/)", "contributors": [ From 2a89513886afb1aa449561e2f98f7ef409944226 Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Tue, 6 Dec 2022 20:21:47 +0100 Subject: [PATCH 8/9] fix: Exclude `domainEmitter` from output (#26) --- index.js | 1 + test/index.js | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/index.js b/index.js index 1677dcb..1f36b17 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,7 @@ var ignored = new Set( 'showProperties', 'showStack', 'domain', + 'domainEmitter', 'domainThrown', ]) ); diff --git a/test/index.js b/test/index.js index ca7fc01..d7abaed 100644 --- a/test/index.js +++ b/test/index.js @@ -252,6 +252,19 @@ describe('PluginError()', function () { done(); }); + it('should not show additional properties added by a domain', function (done) { + var Duplex = require('stream').Duplex; + var stream = new Duplex({ objectMode: true }); + var domain = require('domain').create(); + domain.add(stream); + domain.on('error', function (err) { + expect(err).toBeInstanceOf(PluginError); + expect(err.toString()).not.toContain('domain'); + done(); + }); + stream.emit('error', new PluginError('plugin', 'message')); + }); + it('should not modify error argument', function (done) { var realErr = { message: 'something broke' }; new PluginError('test', realErr); From 93926320fb69c37f6c90580ea5883924fe3cc625 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 6 Dec 2022 12:28:27 -0700 Subject: [PATCH 9/9] chore: Release 2.0.1 (#27) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4582410..6d0b36b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### [2.0.1](https://www.github.com/gulpjs/plugin-error/compare/v2.0.0...v2.0.1) (2022-12-06) + + +### Bug Fixes + +* Exclude `domainEmitter` from output ([#26](https://www.github.com/gulpjs/plugin-error/issues/26)) ([2a89513](https://www.github.com/gulpjs/plugin-error/commit/2a89513886afb1aa449561e2f98f7ef409944226)) + ## [2.0.0](https://www.github.com/gulpjs/plugin-error/compare/v1.0.1...v2.0.0) (2022-07-01) diff --git a/package.json b/package.json index 05c8584..dd325aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plugin-error", - "version": "2.0.0", + "version": "2.0.1", "description": "Error handling for Vinyl plugins.", "author": "Gulp Team (https://gulpjs.com/)", "contributors": [