From 51c5ec5686e8ee2d685283a694cfeba7e96269bd Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 13 May 2018 14:04:42 -0700 Subject: [PATCH 01/13] Fix: Actually publish types --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 13c9e48..ee07f4b 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "types": "index.d.ts", "files": [ "index.js", + "index.d.ts", "LICENSE" ], "scripts": { From 82fde9e21d6b2336a7eeab5839aee86a5c191e3e Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 13 May 2018 14:05:04 -0700 Subject: [PATCH 02/13] Release: 1.3.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ee07f4b..62aeb02 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "async-done", - "version": "1.3.0", + "version": "1.3.1", "description": "Allows libraries to handle various caller provided asynchronous functions uniformly. Maps promises, observables, child processes and streams, and callbacks to callback style.", "author": "Gulp Team (http://gulpjs.com/)", "contributors": [ From 457ac2aa6fd04fc5620277a8095fa11e8ef61b65 Mon Sep 17 00:00:00 2001 From: Charles Samborski Date: Mon, 14 May 2018 22:04:35 +0200 Subject: [PATCH 03/13] Docs: Fix links to RxJS methods in README (#48) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ea86a0b..4e37054 100644 --- a/README.md +++ b/README.md @@ -68,8 +68,8 @@ Optionally takes a callback to call when async tasks are complete. - Completion: [onFulfilled][promise-onfulfilled] method called - Error: [onRejected][promise-onrejected] method called * `Observable` (e.g. from [RxJS v5][rxjs5-observable] or [RxJS v4][rxjs5-observable]) returned - - Completion: [complete][rxjs5-subscriber-complete] method called - - Error: [error][rxjs5-subscriber-error] method called + - Completion: [complete][rxjs5-observer-complete] method called + - Error: [error][rxjs5-observer-error] method called __Warning:__ Sync tasks are __not supported__ and your function will never complete if the one of the above strategies is not used to signal completion. However, thrown errors will be caught by the domain. From dce44f6867a6285dba5472f358d07e6c2b3cc7bc Mon Sep 17 00:00:00 2001 From: Pirate Praveen Arimbrathodiyil Date: Mon, 3 Jun 2019 12:53:20 +0530 Subject: [PATCH 04/13] Upgrade: Update process-nextick-args to 2.0.0 (closes #51) (#52) --- index.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 5af2eee..e5be989 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ var domain = require('domain'); var eos = require('end-of-stream'); -var tick = require('process-nextick-args'); +var p = require('process-nextick-args'); var once = require('once'); var exhaust = require('stream-exhaust'); @@ -82,7 +82,7 @@ function asyncDone(fn, cb) { } } - tick(asyncRunner); + p.nextTick(asyncRunner); } module.exports = asyncDone; diff --git a/package.json b/package.json index 62aeb02..e1d70e5 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "dependencies": { "end-of-stream": "^1.1.0", "once": "^1.3.2", - "process-nextick-args": "^1.0.7", + "process-nextick-args": "^2.0.0", "stream-exhaust": "^1.0.1" }, "devDependencies": { From 5e1b0b1618846ccfbeb24dc0cd182777e40acd5e Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 9 Jun 2019 14:47:00 +0900 Subject: [PATCH 05/13] Scaffold: Move custom links to bottom of README --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 4e37054..321e5a2 100644 --- a/README.md +++ b/README.md @@ -91,16 +91,6 @@ Errors can be caused by: MIT -[end-of-stream]: https://www.npmjs.com/package/end-of-stream -[domains]: http://nodejs.org/api/domain.html -[event-stream]: https://github.com/dominictarr/event-stream -[promise-onfulfilled]: http://promisesaplus.com/#point-26 -[promise-onrejected]: http://promisesaplus.com/#point-30 -[rx4-observable]: https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md -[rxjs5-observable]: http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html -[rxjs5-observer-complete]: http://reactivex.io/rxjs/class/es6/MiscJSDoc.js~ObserverDoc.html#instance-method-complete -[rxjs5-observer-error]: http://reactivex.io/rxjs/class/es6/MiscJSDoc.js~ObserverDoc.html#instance-method-error - [downloads-image]: http://img.shields.io/npm/dm/async-done.svg [npm-url]: https://www.npmjs.com/package/async-done [npm-image]: http://img.shields.io/npm/v/async-done.svg @@ -116,3 +106,13 @@ MIT [gitter-url]: https://gitter.im/gulpjs/gulp [gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg + +[end-of-stream]: https://www.npmjs.com/package/end-of-stream +[domains]: http://nodejs.org/api/domain.html +[event-stream]: https://github.com/dominictarr/event-stream +[promise-onfulfilled]: http://promisesaplus.com/#point-26 +[promise-onrejected]: http://promisesaplus.com/#point-30 +[rx4-observable]: https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md +[rxjs5-observable]: http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html +[rxjs5-observer-complete]: http://reactivex.io/rxjs/class/es6/MiscJSDoc.js~ObserverDoc.html#instance-method-complete +[rxjs5-observer-error]: http://reactivex.io/rxjs/class/es6/MiscJSDoc.js~ObserverDoc.html#instance-method-error From 7bb14730deecabc8625b8658db6260785bc8b522 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 9 Jun 2019 15:57:23 +0900 Subject: [PATCH 06/13] Scaffold: Update repository template --- .ci/.azure-pipelines-steps.yml | 38 ++++++++++++++ .ci/.azure-pipelines.yml | 90 ++++++++++++++++++++++++++++++++++ .gitignore | 46 +++++++++++++++-- .jscsrc | 3 -- .npmrc | 1 + .travis.yml | 2 +- README.md | 13 +++-- appveyor.yml | 9 +++- package.json | 24 +++++---- 9 files changed, 198 insertions(+), 28 deletions(-) create mode 100644 .ci/.azure-pipelines-steps.yml create mode 100644 .ci/.azure-pipelines.yml delete mode 100644 .jscsrc create mode 100644 .npmrc diff --git a/.ci/.azure-pipelines-steps.yml b/.ci/.azure-pipelines-steps.yml new file mode 100644 index 0000000..894c21e --- /dev/null +++ b/.ci/.azure-pipelines-steps.yml @@ -0,0 +1,38 @@ +steps: +- script: npm i -g npm@$(npm_version) + displayName: Use legacy npm version $(npm_version) + condition: ne(variables['npm_version'], '') + +- task: NodeTool@0 + inputs: + versionSpec: '$(node_version)' + displayName: Use Node $(node_version) + +- script: npm install + displayName: npm install + +- script: npm test + displayName: Run tests + +- script: npm run coveralls + displayName: Run coveralls + env: + # Pretend to be AppVeyor for now + APPVEYOR: true + APPVEYOR_BUILD_NUMBER: $(Build.BuildNumber) + APPVEYOR_BUILD_ID: $(Agent.OS)_$(node_version) + APPVEYOR_REPO_COMMIT: $(Build.SourceVersion) + APPVEYOR_REPO_BRANCH: $(Build.SourceBranchName) + # Overwrite the AppVeyor Service Name + COVERALLS_SERVICE_NAME: Azure Pipelines + COVERALLS_REPO_TOKEN: $(COVERALLS_REPO_TOKEN_SECRET) + COVERALLS_PARALLEL: true + CI_PULL_REQUEST: $(System.PullRequest.PullRequestNumber) + +- script: npm run azure-pipelines + displayName: Write tests to xml + +- task: PublishTestResults@2 + inputs: + testResultsFiles: '**/test.xunit' + condition: succeededOrFailed() diff --git a/.ci/.azure-pipelines.yml b/.ci/.azure-pipelines.yml new file mode 100644 index 0000000..2d717af --- /dev/null +++ b/.ci/.azure-pipelines.yml @@ -0,0 +1,90 @@ +trigger: +- master +- releases/* + +jobs: + - job: Test_Linux + displayName: Run Tests on Linux + pool: + vmImage: "Ubuntu 16.04" + strategy: + matrix: + Node_v12: + node_version: 12 + Node_v10: + node_version: 10 + Node_v8: + node_version: 8 + Node_v6: + node_version: 6 + Node_v4: + node_version: 4 + Node_v0_12: + node_version: 0.12 + Node_v0_10: + node_version: 0.10 + steps: + - template: .azure-pipelines-steps.yml + + - job: Test_Windows + displayName: Run Tests on Windows + pool: + vmImage: vs2017-win2016 + strategy: + matrix: + Node_v12: + node_version: 12 + Node_v10: + node_version: 10 + Node_v8: + node_version: 8 + Node_v6: + node_version: 6 + Node_v4: + node_version: 4 + npm_version: 2 + Node_v0_12: + node_version: 0.12 + npm_version: 2 + Node_v0_10: + node_version: 0.10 + npm_version: 2 + steps: + - template: .azure-pipelines-steps.yml + + - job: Test_MacOS + displayName: Run Tests on MacOS + pool: + vmImage: macos-10.13 + strategy: + matrix: + Node_v12: + node_version: 12 + Node_v10: + node_version: 10 + Node_v8: + node_version: 8 + Node_v6: + node_version: 6 + Node_v4: + node_version: 4 + Node_v0_12: + node_version: 0.12 + Node_v0_10: + node_version: 0.10 + steps: + - template: .azure-pipelines-steps.yml + + - job: Notify_Coveralls + displayName: Notify Coveralls that the parallel report is done + pool: + vmImage: "Ubuntu 16.04" + dependsOn: + - Test_Linux + - Test_Windows + - Test_MacOS + steps: + - script: curl -k https://coveralls.io/webhook?repo_token=$COVERALLS_REPO_TOKEN -d "payload[build_num]=$BUILD_NAME&payload[status]=done" + env: + COVERALLS_REPO_TOKEN: $(COVERALLS_REPO_TOKEN_SECRET) + BUILD_NAME: $(Build.BuildNumber) diff --git a/.gitignore b/.gitignore index bfb1212..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,17 +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 +# Bower dependency directory (https://bower.io/) +bower_components + # node-waf configuration .lock-wscript -# Compiled binary addons (http://nodejs.org/api/addons.html) +# Compiled binary addons (https://nodejs.org/api/addons.html) build/Release -# Dependency directory -# 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/ + +# 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/.travis.yml b/.travis.yml index 82d0f18..eda5b00 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ sudo: false language: node_js node_js: + - '12' - '10' - '8' - '6' - - '5' - '4' - '0.12' - '0.10' diff --git a/README.md b/README.md index 321e5a2..93545c2 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ # async-done -[![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] [![Azure Pipelines Build Status][azure-pipelines-image]][azure-pipelines-url] [![Travis 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] Allows libraries to handle various caller provided asynchronous functions uniformly. Maps promises, observables, child processes and streams, and callbacks to callback style. @@ -91,18 +91,21 @@ Errors can be caused by: MIT -[downloads-image]: http://img.shields.io/npm/dm/async-done.svg +[downloads-image]: https://img.shields.io/npm/dm/async-done.svg [npm-url]: https://www.npmjs.com/package/async-done -[npm-image]: http://img.shields.io/npm/v/async-done.svg +[npm-image]: https://img.shields.io/npm/v/async-done.svg + +[azure-pipelines-url]: https://dev.azure.com/gulpjs/gulp/_build/latest?definitionId=6&branchName=master +[azure-pipelines-image]: https://dev.azure.com/gulpjs/gulp/_apis/build/status/async-done?branchName=master [travis-url]: https://travis-ci.org/gulpjs/async-done -[travis-image]: http://img.shields.io/travis/gulpjs/async-done.svg?label=travis-ci +[travis-image]: https://img.shields.io/travis/gulpjs/async-done.svg?label=travis-ci [appveyor-url]: https://ci.appveyor.com/project/gulpjs/async-done [appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/async-done.svg?label=appveyor [coveralls-url]: https://coveralls.io/r/gulpjs/async-done -[coveralls-image]: http://img.shields.io/coveralls/gulpjs/async-done/master.svg +[coveralls-image]: https://img.shields.io/coveralls/gulpjs/async-done/master.svg [gitter-url]: https://gitter.im/gulpjs/gulp [gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg diff --git a/appveyor.yml b/appveyor.yml index e416994..47b3ca2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,13 +7,18 @@ environment: - nodejs_version: "0.10" - nodejs_version: "0.12" - nodejs_version: "4" - - nodejs_version: "5" - nodejs_version: "6" - nodejs_version: "8" - nodejs_version: "10" + - nodejs_version: "12" + +platform: + - x86 + - x64 install: - - ps: Install-Product node $env:nodejs_version + # https://www.appveyor.com/docs/lang/nodejs-iojs/#installing-any-version-of-nodejs-or-iojs + - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) $env:PLATFORM - npm install test_script: diff --git a/package.json b/package.json index e1d70e5..c12331f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "async-done", "version": "1.3.1", "description": "Allows libraries to handle various caller provided asynchronous functions uniformly. Maps promises, observables, child processes and streams, and callbacks to callback style.", - "author": "Gulp Team (http://gulpjs.com/)", + "author": "Gulp Team (https://gulpjs.com/)", "contributors": [ "Blaine Bublitz ", "Pawel Kozlowski ", @@ -22,12 +22,12 @@ "LICENSE" ], "scripts": { - "lint": "eslint . && jscs index.js test/", + "lint": "eslint .", "pretest": "npm run lint", - "test": "mocha --async-only && npm run test-types", + "test": "nyc mocha --async-only", "test-types": "tsc -p test/types", - "cover": "istanbul cover _mocha --report lcovonly", - "coveralls": "npm run cover && istanbul-coveralls" + "azure-pipelines": "nyc mocha --async-only --reporter xunit -O output=test.xunit", + "coveralls": "nyc report --reporter=text-lcov | coveralls" }, "dependencies": { "end-of-stream": "^1.1.0", @@ -37,14 +37,12 @@ }, "devDependencies": { "@types/node": "^9.3.0", - "eslint": "^1.7.3", - "eslint-config-gulp": "^2.0.0", - "expect": "^1.19.0", - "istanbul": "^0.4.3", - "istanbul-coveralls": "^1.0.3", - "jscs": "^2.3.5", - "jscs-preset-gulp": "^1.0.0", - "mocha": "^2.4.5", + "coveralls": "github:phated/node-coveralls#2.x", + "eslint": "^2.13.1", + "eslint-config-gulp": "^3.0.1", + "expect": "^1.20.2", + "mocha": "^3.0.0", + "nyc": "^10.3.2", "pumpify": "^1.3.6", "rxjs": "^5.5.6", "through2": "^2.0.0", From 35260ae27874e88e11f9a9e3942a3516534cc510 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 9 Jun 2019 16:45:03 +0900 Subject: [PATCH 07/13] Release: 1.3.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c12331f..774c733 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "async-done", - "version": "1.3.1", + "version": "1.3.2", "description": "Allows libraries to handle various caller provided asynchronous functions uniformly. Maps promises, observables, child processes and streams, and callbacks to callback style.", "author": "Gulp Team (https://gulpjs.com/)", "contributors": [ From 66f987f36d2cbd07d5b96f487ea327caa44acb10 Mon Sep 17 00:00:00 2001 From: Takayuki Sato Date: Tue, 23 Nov 2021 07:54:18 +0900 Subject: [PATCH 08/13] chore!: Normalize repository, dropping node <10.13 support (#54) chore: Remove process-nextick-args chore: Remove when Co-authored-by: Blaine Bublitz --- .ci/.azure-pipelines-steps.yml | 38 -------------- .ci/.azure-pipelines.yml | 90 ---------------------------------- .eslintignore | 1 + .github/workflows/dev.yml | 75 ++++++++++++++++++++++++++++ .github/workflows/release.yml | 17 +++++++ .gitignore | 2 +- .prettierignore | 3 ++ .travis.yml | 12 ----- LICENSE | 2 +- README.md | 29 +++++------ appveyor.yml | 32 ------------ index.d.ts | 2 +- index.js | 3 +- package.json | 45 +++++++++-------- test/.eslintrc | 3 -- test/callbacks.js | 4 +- test/child_processes.js | 8 +-- test/observables.js | 12 ++--- test/promises.js | 16 +++--- test/streams.js | 16 +++--- test/types/observables.ts | 8 +-- 21 files changed, 170 insertions(+), 248 deletions(-) delete mode 100644 .ci/.azure-pipelines-steps.yml delete mode 100644 .ci/.azure-pipelines.yml create mode 100644 .eslintignore create mode 100644 .github/workflows/dev.yml create mode 100644 .github/workflows/release.yml create mode 100644 .prettierignore delete mode 100644 .travis.yml delete mode 100644 appveyor.yml delete mode 100644 test/.eslintrc diff --git a/.ci/.azure-pipelines-steps.yml b/.ci/.azure-pipelines-steps.yml deleted file mode 100644 index 894c21e..0000000 --- a/.ci/.azure-pipelines-steps.yml +++ /dev/null @@ -1,38 +0,0 @@ -steps: -- script: npm i -g npm@$(npm_version) - displayName: Use legacy npm version $(npm_version) - condition: ne(variables['npm_version'], '') - -- task: NodeTool@0 - inputs: - versionSpec: '$(node_version)' - displayName: Use Node $(node_version) - -- script: npm install - displayName: npm install - -- script: npm test - displayName: Run tests - -- script: npm run coveralls - displayName: Run coveralls - env: - # Pretend to be AppVeyor for now - APPVEYOR: true - APPVEYOR_BUILD_NUMBER: $(Build.BuildNumber) - APPVEYOR_BUILD_ID: $(Agent.OS)_$(node_version) - APPVEYOR_REPO_COMMIT: $(Build.SourceVersion) - APPVEYOR_REPO_BRANCH: $(Build.SourceBranchName) - # Overwrite the AppVeyor Service Name - COVERALLS_SERVICE_NAME: Azure Pipelines - COVERALLS_REPO_TOKEN: $(COVERALLS_REPO_TOKEN_SECRET) - COVERALLS_PARALLEL: true - CI_PULL_REQUEST: $(System.PullRequest.PullRequestNumber) - -- script: npm run azure-pipelines - displayName: Write tests to xml - -- task: PublishTestResults@2 - inputs: - testResultsFiles: '**/test.xunit' - condition: succeededOrFailed() diff --git a/.ci/.azure-pipelines.yml b/.ci/.azure-pipelines.yml deleted file mode 100644 index 2d717af..0000000 --- a/.ci/.azure-pipelines.yml +++ /dev/null @@ -1,90 +0,0 @@ -trigger: -- master -- releases/* - -jobs: - - job: Test_Linux - displayName: Run Tests on Linux - pool: - vmImage: "Ubuntu 16.04" - strategy: - matrix: - Node_v12: - node_version: 12 - Node_v10: - node_version: 10 - Node_v8: - node_version: 8 - Node_v6: - node_version: 6 - Node_v4: - node_version: 4 - Node_v0_12: - node_version: 0.12 - Node_v0_10: - node_version: 0.10 - steps: - - template: .azure-pipelines-steps.yml - - - job: Test_Windows - displayName: Run Tests on Windows - pool: - vmImage: vs2017-win2016 - strategy: - matrix: - Node_v12: - node_version: 12 - Node_v10: - node_version: 10 - Node_v8: - node_version: 8 - Node_v6: - node_version: 6 - Node_v4: - node_version: 4 - npm_version: 2 - Node_v0_12: - node_version: 0.12 - npm_version: 2 - Node_v0_10: - node_version: 0.10 - npm_version: 2 - steps: - - template: .azure-pipelines-steps.yml - - - job: Test_MacOS - displayName: Run Tests on MacOS - pool: - vmImage: macos-10.13 - strategy: - matrix: - Node_v12: - node_version: 12 - Node_v10: - node_version: 10 - Node_v8: - node_version: 8 - Node_v6: - node_version: 6 - Node_v4: - node_version: 4 - Node_v0_12: - node_version: 0.12 - Node_v0_10: - node_version: 0.10 - steps: - - template: .azure-pipelines-steps.yml - - - job: Notify_Coveralls - displayName: Notify Coveralls that the parallel report is done - pool: - vmImage: "Ubuntu 16.04" - dependsOn: - - Test_Linux - - Test_Windows - - Test_MacOS - steps: - - script: curl -k https://coveralls.io/webhook?repo_token=$COVERALLS_REPO_TOKEN -d "payload[build_num]=$BUILD_NAME&payload[status]=done" - env: - COVERALLS_REPO_TOKEN: $(COVERALLS_REPO_TOKEN_SECRET) - BUILD_NAME: $(Build.BuildNumber) diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..404abb2 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +coverage/ diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 0000000..3b07263 --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,75 @@ +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 + + - 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..8a10ce3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,17 @@ +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 + bump-minor-pre-major: true diff --git a/.gitignore b/.gitignore index 58a757a..aa0c563 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,7 @@ coverage # nyc test coverage .nyc_output -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) .grunt # Bower dependency directory (https://bower.io/) 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 eda5b00..0000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -sudo: false -language: node_js -node_js: - - '12' - - '10' - - '8' - - '6' - - '4' - - '0.12' - - '0.10' -after_script: - - npm run coveralls diff --git a/LICENSE b/LICENSE index 9aedc0d..976e4a8 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-2019, 2021 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 93545c2..12c1f5f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ # async-done -[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Azure Pipelines Build Status][azure-pipelines-image]][azure-pipelines-url] [![Travis 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] Allows libraries to handle various caller provided asynchronous functions uniformly. Maps promises, observables, child processes and streams, and callbacks to callback style. @@ -67,7 +67,7 @@ Optionally takes a callback to call when async tasks are complete. * `Promise` returned - Completion: [onFulfilled][promise-onfulfilled] method called - Error: [onRejected][promise-onrejected] method called -* `Observable` (e.g. from [RxJS v5][rxjs5-observable] or [RxJS v4][rxjs5-observable]) returned +* `Observable` (e.g. from [RxJS v5][rxjs5-observable] or [RxJS v4][rxjs4-observable]) returned - Completion: [complete][rxjs5-observer-complete] method called - Error: [error][rxjs5-observer-error] method called @@ -91,31 +91,26 @@ Errors can be caused by: MIT -[downloads-image]: https://img.shields.io/npm/dm/async-done.svg + +[downloads-image]: https://img.shields.io/npm/dm/async-done.svg?style=flat-square [npm-url]: https://www.npmjs.com/package/async-done -[npm-image]: https://img.shields.io/npm/v/async-done.svg +[npm-image]: https://img.shields.io/npm/v/async-done.svg?style=flat-square -[azure-pipelines-url]: https://dev.azure.com/gulpjs/gulp/_build/latest?definitionId=6&branchName=master -[azure-pipelines-image]: https://dev.azure.com/gulpjs/gulp/_apis/build/status/async-done?branchName=master - -[travis-url]: https://travis-ci.org/gulpjs/async-done -[travis-image]: https://img.shields.io/travis/gulpjs/async-done.svg?label=travis-ci - -[appveyor-url]: https://ci.appveyor.com/project/gulpjs/async-done -[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/async-done.svg?label=appveyor +[ci-url]: https://github.com/gulpjs/async-done/actions?query=workflow:dev +[ci-image]: https://img.shields.io/github/workflow/status/gulpjs/async-done/dev?style=flat-square [coveralls-url]: https://coveralls.io/r/gulpjs/async-done -[coveralls-image]: https://img.shields.io/coveralls/gulpjs/async-done/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/async-done/master.svg?style=flat-square + + [end-of-stream]: https://www.npmjs.com/package/end-of-stream [domains]: http://nodejs.org/api/domain.html [event-stream]: https://github.com/dominictarr/event-stream [promise-onfulfilled]: http://promisesaplus.com/#point-26 [promise-onrejected]: http://promisesaplus.com/#point-30 -[rx4-observable]: https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md +[rxjs4-observable]: https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md [rxjs5-observable]: http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html [rxjs5-observer-complete]: http://reactivex.io/rxjs/class/es6/MiscJSDoc.js~ObserverDoc.html#instance-method-complete [rxjs5-observer-error]: http://reactivex.io/rxjs/class/es6/MiscJSDoc.js~ObserverDoc.html#instance-method-error + diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 47b3ca2..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,32 +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" - - nodejs_version: "10" - - nodejs_version: "12" - -platform: - - x86 - - x64 - -install: - # https://www.appveyor.com/docs/lang/nodejs-iojs/#installing-any-version-of-nodejs-or-iojs - - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) $env:PLATFORM - - npm install - -test_script: - - node --version - - npm --version - - cmd: npm test - -build: off - -# build version format -version: "{build}" diff --git a/index.d.ts b/index.d.ts index 2c4ab93..dfa8d23 100644 --- a/index.d.ts +++ b/index.d.ts @@ -58,7 +58,7 @@ declare namespace asyncDone { * Represents a callback function used to signal the completion of a * task without any result value. */ - type VoidCallback = (err: Error | null) => void; + type VoidCallback = (err: Error | null | void) => void; /** * Represents a callback function used to signal the completion of a diff --git a/index.js b/index.js index e5be989..5d0cd80 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,6 @@ var domain = require('domain'); var eos = require('end-of-stream'); -var p = require('process-nextick-args'); var once = require('once'); var exhaust = require('stream-exhaust'); @@ -82,7 +81,7 @@ function asyncDone(fn, cb) { } } - p.nextTick(asyncRunner); + process.nextTick(asyncRunner); } module.exports = asyncDone; diff --git a/package.json b/package.json index 774c733..e62c0f1 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "repository": "gulpjs/async-done", "license": "MIT", "engines": { - "node": ">= 0.10" + "node": ">= 10.13.0" }, "main": "index.js", "types": "index.d.ts", @@ -25,29 +25,34 @@ "lint": "eslint .", "pretest": "npm run lint", "test": "nyc mocha --async-only", - "test-types": "tsc -p test/types", - "azure-pipelines": "nyc mocha --async-only --reporter xunit -O output=test.xunit", - "coveralls": "nyc report --reporter=text-lcov | coveralls" + "test-types": "tsc -p test/types" }, "dependencies": { - "end-of-stream": "^1.1.0", - "once": "^1.3.2", - "process-nextick-args": "^2.0.0", - "stream-exhaust": "^1.0.1" + "end-of-stream": "^1.4.4", + "once": "^1.4.0", + "stream-exhaust": "^1.0.2" }, "devDependencies": { - "@types/node": "^9.3.0", - "coveralls": "github:phated/node-coveralls#2.x", - "eslint": "^2.13.1", - "eslint-config-gulp": "^3.0.1", - "expect": "^1.20.2", - "mocha": "^3.0.0", - "nyc": "^10.3.2", - "pumpify": "^1.3.6", - "rxjs": "^5.5.6", - "through2": "^2.0.0", - "typescript": "^2.6.2", - "when": "^3.7.3" + "@types/node": "^16.11.7", + "eslint": "^7.32.0", + "eslint-config-gulp": "^5.0.1", + "eslint-plugin-node": "^11.1.0", + "expect": "^27.3.1", + "mocha": "^8.4.0", + "nyc": "^15.1.0", + "pumpify": "^2.0.1", + "rxjs": "^7.4.0", + "through2": "^4.0.2", + "typescript": "^4.4.4" + }, + "nyc": { + "reporter": [ + "lcov", + "text-summary" + ] + }, + "prettier": { + "singleQuote": true }, "keywords": [ "promises", 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/callbacks.js b/test/callbacks.js index 150684f..e6dfa08 100644 --- a/test/callbacks.js +++ b/test/callbacks.js @@ -27,7 +27,7 @@ describe('callbacks', function() { it('should handle an errored callback', function(done) { asyncDone(failure, function(err) { - expect(err).toBeAn(Error); + expect(err).toBeInstanceOf(Error); done(); }); }); @@ -45,7 +45,7 @@ describe('callbacks', function() { it('should not handle error if something throws inside the callback', function(done) { var d = require('domain').create(); d.on('error', function(err) { - expect(err).toBeAn(Error); + expect(err).toBeInstanceOf(Error); done(); }); diff --git a/test/child_processes.js b/test/child_processes.js index ebf6ba4..86c4653 100644 --- a/test/child_processes.js +++ b/test/child_processes.js @@ -25,28 +25,28 @@ function spawnFail() { describe('child processes', function() { it('should handle successful exec', function(done) { asyncDone(execSuccess, function(err) { - expect(err).toNotBeAn(Error); + expect(err).not.toBeInstanceOf(Error); done(); }); }); it('should handle failing exec', function(done) { asyncDone(execFail, function(err) { - expect(err).toBeAn(Error); + expect(err).toBeInstanceOf(Error); done(); }); }); it('should handle successful spawn', function(done) { asyncDone(spawnSuccess, function(err) { - expect(err).toNotBeAn(Error); + expect(err).not.toBeInstanceOf(Error); done(); }); }); it('should handle failing spawn', function(done) { asyncDone(spawnFail, function(err) { - expect(err).toBeAn(Error); + expect(err).toBeInstanceOf(Error); done(); }); }); diff --git a/test/observables.js b/test/observables.js index 4956878..413b806 100644 --- a/test/observables.js +++ b/test/observables.js @@ -4,26 +4,26 @@ var expect = require('expect'); var asyncDone = require('../'); -var Observable = require('rxjs').Observable; +var rxjs = require('rxjs'); function success() { - return Observable.empty(); + return rxjs.empty(); } function successValue() { // This corresponds to `Observable.return(42);` in RxJS 4 - return Observable.of(42); + return rxjs.of(42); } function failure() { - return Observable.throw(new Error('Observable error')); + return rxjs.throw(new Error('Observable error')); } describe('observables', function() { it('should handle a finished observable', function(done) { asyncDone(success, function(err, result) { - expect(result).toEqual(undefined); + expect(result).toBeUndefined(); done(err); }); }); @@ -37,7 +37,7 @@ describe('observables', function() { it('should handle an errored observable', function(done) { asyncDone(failure, function(err) { - expect(err).toBeAn(Error); + expect(err).toBeInstanceOf(Error); done(); }); }); diff --git a/test/promises.js b/test/promises.js index edaa8e4..6ebda83 100644 --- a/test/promises.js +++ b/test/promises.js @@ -4,20 +4,18 @@ var domain = require('domain'); var expect = require('expect'); -var when = require('when'); - var asyncDone = require('../'); function success() { - return when.resolve(2); + return Promise.resolve(2); } function failure() { - return when.reject(new Error('Promise Error')); + return Promise.reject(new Error('Promise Error')); } function rejectNoError() { - return when.reject(); + return Promise.reject(); } describe('promises', function() { @@ -31,15 +29,15 @@ describe('promises', function() { it('should handle a rejected promise', function(done) { asyncDone(failure, function(err) { - expect(err).toBeAn(Error); + expect(err).toBeInstanceOf(Error); done(); }); }); it('properly errors when rejected without an error', function(done) { asyncDone(rejectNoError, function(err) { - expect(err).toExist(); - expect(err).toBeAn(Error); + expect(err).toBeTruthy(); + expect(err).toBeInstanceOf(Error); done(); }); }); @@ -47,7 +45,7 @@ describe('promises', function() { it('does not swallow thrown errors in callback', function(done) { var d = domain.create(); d.once('error', function(err) { - expect(err).toExist(); + expect(err).toBeTruthy(); expect(err.message).toContain('Boom'); done(); }); diff --git a/test/streams.js b/test/streams.js index a0eed97..f0a70c3 100644 --- a/test/streams.js +++ b/test/streams.js @@ -42,6 +42,10 @@ function pumpifyError() { through() ); + pipeline.on('error', function(err) { + throw err; + }); + return read.pipe(pipeline); } @@ -52,22 +56,22 @@ function unpiped() { describe('streams', function() { it('should handle a successful stream', function(done) { asyncDone(success, function(err) { - expect(err).toNotBeAn(Error); + expect(err).not.toBeInstanceOf(Error); done(); }); }); it('should handle an errored stream', function(done) { asyncDone(failure, function(err) { - expect(err).toBeAn(Error); + expect(err).toBeInstanceOf(Error); done(); }); }); it('should handle an errored pipeline', function(done) { asyncDone(pumpifyError, function(err) { - expect(err).toBeAn(Error); - expect(err.message).toNotBe('premature close'); + expect(err).toBeInstanceOf(Error); + expect(err.message).not.toEqual('premature close'); done(); }); }); @@ -78,7 +82,7 @@ describe('streams', function() { cb(null, 3); }); }, function(err, result) { - expect(err).toNotBeAn(Error); + expect(err).not.toBeInstanceOf(Error); expect(result).toEqual(3); // To know we called the callback done(); }); @@ -86,7 +90,7 @@ describe('streams', function() { it('consumes an unpiped readable stream', function(done) { asyncDone(unpiped, function(err) { - expect(err).toNotBeAn(Error); + expect(err).not.toBeInstanceOf(Error); done(); }); }); diff --git a/test/types/observables.ts b/test/types/observables.ts index 4f0dd53..f807584 100644 --- a/test/types/observables.ts +++ b/test/types/observables.ts @@ -1,18 +1,18 @@ import asyncDone from "async-done"; -import { Observable } from "rxjs/Observable"; +import { empty, of, throwError, Observable } from "rxjs"; import 'rxjs/add/observable/empty'; import 'rxjs/add/observable/of'; function success(): Observable { - return Observable.empty(); + return empty(); } function successValue(): Observable { - return Observable.of(42); + return of(42); } function failure(): Observable { - return Observable.throw(new Error("Observable error")); + return throwError(new Error("Observable error")); } // `success` callback From b6612f5315718fdb19fc14812b6e8db9ddcd6d0a Mon Sep 17 00:00:00 2001 From: phated Date: Mon, 22 Nov 2021 22:54:50 +0000 Subject: [PATCH 09/13] chore: Run prettier --- README.md | 60 +++++++++++++++++-------------- index.d.ts | 27 +++++++++----- test/arguments.js | 7 ++-- test/callbacks.js | 25 +++++++------ test/child_processes.js | 19 +++++----- test/observables.js | 15 ++++---- test/promises.js | 23 ++++++------ test/streams.js | 66 ++++++++++++++++++----------------- test/types/callback.ts | 12 +++---- test/types/child_processes.ts | 13 ++++--- test/types/observables.ts | 16 ++++----- test/types/promises.ts | 12 +++---- test/types/streams.ts | 8 ++--- test/types/tsconfig.json | 12 ++----- test/types/various.ts | 2 +- 15 files changed, 162 insertions(+), 155 deletions(-) diff --git a/README.md b/README.md index 12c1f5f..6ab8df8 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Allows libraries to handle various caller provided asynchronous functions uniformly. Maps promises, observables, child processes and streams, and callbacks to callback style. -As async conventions evolve, it is useful to be able to deal with several different *styles* of async completion uniformly. With this module you can handle completion using a node-style callback, regardless of a return value that's a promise, observable, child process or stream. +As async conventions evolve, it is useful to be able to deal with several different _styles_ of async completion uniformly. With this module you can handle completion using a node-style callback, regardless of a return value that's a promise, observable, child process or stream. ## Usage @@ -19,13 +19,16 @@ As async conventions evolve, it is useful to be able to deal with several differ ```js var asyncDone = require('async-done'); -asyncDone(function(done){ - // do async things - done(null, 2); -}, function(error, result){ - // `error` will be null on successful execution of the first function. - // `result` will be the result from the first function. -}); +asyncDone( + function (done) { + // do async things + done(null, 2); + }, + function (error, result) { + // `error` will be null on successful execution of the first function. + // `result` will be the result from the first function. + } +); ``` ### Failed completion @@ -33,13 +36,16 @@ asyncDone(function(done){ ```js var asyncDone = require('async-done'); -asyncDone(function(done){ - // do async things - done(new Error('Some Error Occurred')); -}, function(error, result){ - // `error` will be an error from the first function. - // `result` will be undefined on failed execution of the first function. -}); +asyncDone( + function (done) { + // do async things + done(new Error('Some Error Occurred')); + }, + function (error, result) { + // `error` will be an error from the first function. + // `result` will be undefined on failed execution of the first function. + } +); ``` ## API @@ -54,24 +60,24 @@ Optionally takes a callback to call when async tasks are complete. #### Completion and Error Resolution -* `Callback` (`done`) called +- `Callback` (`done`) called - Completion: called with null error - Error: called with non-null error -* `Stream` or `EventEmitter` returned +- `Stream` or `EventEmitter` returned - Completion: [end-of-stream][end-of-stream] module - Error: [domains][domains] - - __Note:__ Only actual streams are supported, not faux-streams; Therefore, modules like [`event-stream`][event-stream] are not supported. -* `Child Process` returned + - **Note:** Only actual streams are supported, not faux-streams; Therefore, modules like [`event-stream`][event-stream] are not supported. +- `Child Process` returned - Completion [end-of-stream][end-of-stream] module - Error: [domains][domains] -* `Promise` returned +- `Promise` returned - Completion: [onFulfilled][promise-onfulfilled] method called - Error: [onRejected][promise-onrejected] method called -* `Observable` (e.g. from [RxJS v5][rxjs5-observable] or [RxJS v4][rxjs4-observable]) returned +- `Observable` (e.g. from [RxJS v5][rxjs5-observable] or [RxJS v4][rxjs4-observable]) returned - Completion: [complete][rxjs5-observer-complete] method called - Error: [error][rxjs5-observer-error] method called -__Warning:__ Sync tasks are __not supported__ and your function will never complete if the one of the above strategies is not used to signal completion. However, thrown errors will be caught by the domain. +**Warning:** Sync tasks are **not supported** and your function will never complete if the one of the above strategies is not used to signal completion. However, thrown errors will be caught by the domain. #### `callback(error, result)` @@ -81,11 +87,11 @@ If an error occurred in the execution of the `fn` function, The `callback` metho Errors can be caused by: -* A thrown error -* An error passed to a `done` callback -* An `error` event emitted on a returned `Stream`, `EventEmitter` or `Child Process` -* A rejection of a returned `Promise` - If the `Promise` is not rejected with a value, we generate a new `Error` -* The `onError` handler being called on an `Observable` +- A thrown error +- An error passed to a `done` callback +- An `error` event emitted on a returned `Stream`, `EventEmitter` or `Child Process` +- A rejection of a returned `Promise` - If the `Promise` is not rejected with a value, we generate a new `Error` +- The `onError` handler being called on an `Observable` ## License diff --git a/index.d.ts b/index.d.ts index dfa8d23..195c97a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -48,12 +48,11 @@ * } * ``` */ -import { ChildProcess } from "child_process"; -import { EventEmitter } from "events"; -import { Stream } from "stream"; +import { ChildProcess } from 'child_process'; +import { EventEmitter } from 'events'; +import { Stream } from 'stream'; declare namespace asyncDone { - /** * Represents a callback function used to signal the completion of a * task without any result value. @@ -78,16 +77,25 @@ declare namespace asyncDone { * @see https://github.com/ReactiveX/rxjs/blob/c3c56867eaf93f302ac7cd588034c7d8712f2834/src/internal/Observable.ts#L77 */ interface Observable { - subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): any; + subscribe( + next?: (value: T) => void, + error?: (error: any) => void, + complete?: () => void + ): any; } /** * Represents an async operation. */ export type AsyncTask = - ((done: VoidCallback) => void) + | ((done: VoidCallback) => void) | ((done: Callback) => void) - | (() => ChildProcess | EventEmitter | Observable | PromiseLike | Stream); + | (() => + | ChildProcess + | EventEmitter + | Observable + | PromiseLike + | Stream); } /** @@ -96,6 +104,9 @@ declare namespace asyncDone { * @param fn Function to execute. * @param callback Function to call on completion. */ -declare function asyncDone(fn: asyncDone.AsyncTask, callback: asyncDone.Callback): void; +declare function asyncDone( + fn: asyncDone.AsyncTask, + callback: asyncDone.Callback +): void; export = asyncDone; diff --git a/test/arguments.js b/test/arguments.js index 108e585..cc60934 100644 --- a/test/arguments.js +++ b/test/arguments.js @@ -8,10 +8,9 @@ function twoArg(cb) { cb(null, 1, 2); } -describe('arguments', function() { - - it('passes all arguments to the completion callback', function(done) { - asyncDone(twoArg, function(err, arg1, arg2) { +describe('arguments', function () { + it('passes all arguments to the completion callback', function (done) { + asyncDone(twoArg, function (err, arg1, arg2) { expect(arg1).toEqual(1); expect(arg2).toEqual(2); done(err); diff --git a/test/callbacks.js b/test/callbacks.js index e6dfa08..841cb36 100644 --- a/test/callbacks.js +++ b/test/callbacks.js @@ -16,41 +16,40 @@ function neverDone() { return 2; } -describe('callbacks', function() { - - it('should handle a successful callback', function(done) { - asyncDone(success, function(err, result) { +describe('callbacks', function () { + it('should handle a successful callback', function (done) { + asyncDone(success, function (err, result) { expect(result).toEqual(2); done(err); }); }); - it('should handle an errored callback', function(done) { - asyncDone(failure, function(err) { + it('should handle an errored callback', function (done) { + asyncDone(failure, function (err) { expect(err).toBeInstanceOf(Error); done(); }); }); - it('a function that takes an argument but never calls callback', function(done) { - asyncDone(neverDone, function() { + it('a function that takes an argument but never calls callback', function (done) { + asyncDone(neverDone, function () { done(new Error('Callback called')); }); - setTimeout(function() { + setTimeout(function () { done(); }, 1000); }); - it('should not handle error if something throws inside the callback', function(done) { + it('should not handle error if something throws inside the callback', function (done) { var d = require('domain').create(); - d.on('error', function(err) { + d.on('error', function (err) { expect(err).toBeInstanceOf(Error); done(); }); - d.run(function() { - asyncDone(success, function() { + d.run(function () { + asyncDone(success, function () { throw new Error('Thrown Error'); }); }); diff --git a/test/child_processes.js b/test/child_processes.js index 86c4653..25fb0a5 100644 --- a/test/child_processes.js +++ b/test/child_processes.js @@ -5,7 +5,6 @@ var expect = require('expect'); var cp = require('child_process'); var asyncDone = require('../'); - function execSuccess() { return cp.exec('echo hello world'); } @@ -22,30 +21,30 @@ function spawnFail() { return cp.spawn('foo-bar-baz', ['hello world']); } -describe('child processes', function() { - it('should handle successful exec', function(done) { - asyncDone(execSuccess, function(err) { +describe('child processes', function () { + it('should handle successful exec', function (done) { + asyncDone(execSuccess, function (err) { expect(err).not.toBeInstanceOf(Error); done(); }); }); - it('should handle failing exec', function(done) { - asyncDone(execFail, function(err) { + it('should handle failing exec', function (done) { + asyncDone(execFail, function (err) { expect(err).toBeInstanceOf(Error); done(); }); }); - it('should handle successful spawn', function(done) { - asyncDone(spawnSuccess, function(err) { + it('should handle successful spawn', function (done) { + asyncDone(spawnSuccess, function (err) { expect(err).not.toBeInstanceOf(Error); done(); }); }); - it('should handle failing spawn', function(done) { - asyncDone(spawnFail, function(err) { + it('should handle failing spawn', function (done) { + asyncDone(spawnFail, function (err) { expect(err).toBeInstanceOf(Error); done(); }); diff --git a/test/observables.js b/test/observables.js index 413b806..18e2572 100644 --- a/test/observables.js +++ b/test/observables.js @@ -19,24 +19,23 @@ function failure() { return rxjs.throw(new Error('Observable error')); } -describe('observables', function() { - - it('should handle a finished observable', function(done) { - asyncDone(success, function(err, result) { +describe('observables', function () { + it('should handle a finished observable', function (done) { + asyncDone(success, function (err, result) { expect(result).toBeUndefined(); done(err); }); }); - it('should handle a finished observable with value', function(done) { - asyncDone(successValue, function(err, result) { + it('should handle a finished observable with value', function (done) { + asyncDone(successValue, function (err, result) { expect(result).toEqual(42); done(err); }); }); - it('should handle an errored observable', function(done) { - asyncDone(failure, function(err) { + it('should handle an errored observable', function (done) { + asyncDone(failure, function (err) { expect(err).toBeInstanceOf(Error); done(); }); diff --git a/test/promises.js b/test/promises.js index 6ebda83..3eb4d9e 100644 --- a/test/promises.js +++ b/test/promises.js @@ -18,39 +18,38 @@ function rejectNoError() { return Promise.reject(); } -describe('promises', function() { - - it('should handle a resolved promise', function(done) { - asyncDone(success, function(err, result) { +describe('promises', function () { + it('should handle a resolved promise', function (done) { + asyncDone(success, function (err, result) { expect(result).toEqual(2); done(err); }); }); - it('should handle a rejected promise', function(done) { - asyncDone(failure, function(err) { + it('should handle a rejected promise', function (done) { + asyncDone(failure, function (err) { expect(err).toBeInstanceOf(Error); done(); }); }); - it('properly errors when rejected without an error', function(done) { - asyncDone(rejectNoError, function(err) { + it('properly errors when rejected without an error', function (done) { + asyncDone(rejectNoError, function (err) { expect(err).toBeTruthy(); expect(err).toBeInstanceOf(Error); done(); }); }); - it('does not swallow thrown errors in callback', function(done) { + it('does not swallow thrown errors in callback', function (done) { var d = domain.create(); - d.once('error', function(err) { + d.once('error', function (err) { expect(err).toBeTruthy(); expect(err.message).toContain('Boom'); done(); }); - d.run(function() { - asyncDone(success, function() { + d.run(function () { + asyncDone(success, function () { throw new Error('Boom'); }); }); diff --git a/test/streams.js b/test/streams.js index f0a70c3..21ef6d7 100644 --- a/test/streams.js +++ b/test/streams.js @@ -12,13 +12,16 @@ var asyncDone = require('../'); var exists = path.join(__dirname, '../.gitignore'); var notExists = path.join(__dirname, '../not_exists'); -var EndStream = through.ctor(function(chunk, enc, cb) { - this.push(chunk); - cb(); -}, function(cb) { - this.emit('end', 2); - cb(); -}); +var EndStream = through.ctor( + function (chunk, enc, cb) { + this.push(chunk); + cb(); + }, + function (cb) { + this.emit('end', 2); + cb(); + } +); function success() { var read = fs.createReadStream(exists); @@ -36,13 +39,9 @@ function withErr(chunk, _, cb) { function pumpifyError() { var read = fs.createReadStream(exists); - var pipeline = pumpify( - through(), - through(withErr), - through() - ); + var pipeline = pumpify(through(), through(withErr), through()); - pipeline.on('error', function(err) { + pipeline.on('error', function (err) { throw err; }); @@ -53,43 +52,46 @@ function unpiped() { return fs.createReadStream(exists); } -describe('streams', function() { - it('should handle a successful stream', function(done) { - asyncDone(success, function(err) { +describe('streams', function () { + it('should handle a successful stream', function (done) { + asyncDone(success, function (err) { expect(err).not.toBeInstanceOf(Error); done(); }); }); - it('should handle an errored stream', function(done) { - asyncDone(failure, function(err) { + it('should handle an errored stream', function (done) { + asyncDone(failure, function (err) { expect(err).toBeInstanceOf(Error); done(); }); }); - it('should handle an errored pipeline', function(done) { - asyncDone(pumpifyError, function(err) { + it('should handle an errored pipeline', function (done) { + asyncDone(pumpifyError, function (err) { expect(err).toBeInstanceOf(Error); expect(err.message).not.toEqual('premature close'); done(); }); }); - it('handle a returned stream and cb by only calling callback once', function(done) { - asyncDone(function(cb) { - return success().on('end', function() { - cb(null, 3); - }); - }, function(err, result) { - expect(err).not.toBeInstanceOf(Error); - expect(result).toEqual(3); // To know we called the callback - done(); - }); + it('handle a returned stream and cb by only calling callback once', function (done) { + asyncDone( + function (cb) { + return success().on('end', function () { + cb(null, 3); + }); + }, + function (err, result) { + expect(err).not.toBeInstanceOf(Error); + expect(result).toEqual(3); // To know we called the callback + done(); + } + ); }); - it('consumes an unpiped readable stream', function(done) { - asyncDone(unpiped, function(err) { + it('consumes an unpiped readable stream', function (done) { + asyncDone(unpiped, function (err) { expect(err).not.toBeInstanceOf(Error); done(); }); diff --git a/test/types/callback.ts b/test/types/callback.ts index 17a0651..0f6bfe5 100644 --- a/test/types/callback.ts +++ b/test/types/callback.ts @@ -1,11 +1,11 @@ -import asyncDone, { Callback } from "async-done"; +import asyncDone, { Callback } from 'async-done'; function success(cb: Callback): void { cb(null, 2); } function failure(cb: Callback): void { - cb(new Error("Callback Error")); + cb(new Error('Callback Error')); } function neverDone(): number { @@ -14,7 +14,7 @@ function neverDone(): number { // `success` and stricter callback asyncDone(success, function (err: Error | null, result?: number): void { - console.log("Done"); + console.log('Done'); }); // The following code fails to compile as expected: @@ -24,17 +24,17 @@ asyncDone(success, function (err: Error | null, result?: number): void { // `success` and unsound callback asyncDone(success, function (err: Error | null, result: number): void { - console.log("Done"); + console.log('Done'); }); // `failure` and stricter callback asyncDone(failure, function (err: Error | null, result?: number): void { - console.log("Done"); + console.log('Done'); }); // `failure` and unsound callback asyncDone(failure, function (err: Error | null, result: number): void { - console.log("Done"); + console.log('Done'); }); // I don't think TS is currently able to prevent the current code from compiling diff --git a/test/types/child_processes.ts b/test/types/child_processes.ts index d0d431b..24e0059 100644 --- a/test/types/child_processes.ts +++ b/test/types/child_processes.ts @@ -1,19 +1,18 @@ -import asyncDone from "async-done"; -import cp from "child_process"; - +import asyncDone from 'async-done'; +import cp from 'child_process'; function success(): cp.ChildProcess { - return cp.exec("echo hello world"); + return cp.exec('echo hello world'); } function failure(): cp.ChildProcess { - return cp.exec("foo-bar-baz hello world"); + return cp.exec('foo-bar-baz hello world'); } asyncDone(success, function (err: Error | null): void { - console.log("Done"); + console.log('Done'); }); asyncDone(failure, function (err: Error | null): void { - console.log("Done"); + console.log('Done'); }); diff --git a/test/types/observables.ts b/test/types/observables.ts index f807584..9ee3576 100644 --- a/test/types/observables.ts +++ b/test/types/observables.ts @@ -1,5 +1,5 @@ -import asyncDone from "async-done"; -import { empty, of, throwError, Observable } from "rxjs"; +import asyncDone from 'async-done'; +import { empty, of, throwError, Observable } from 'rxjs'; import 'rxjs/add/observable/empty'; import 'rxjs/add/observable/of'; @@ -12,12 +12,12 @@ function successValue(): Observable { } function failure(): Observable { - return throwError(new Error("Observable error")); + return throwError(new Error('Observable error')); } // `success` callback asyncDone(success, function (err: Error | null): void { - console.log("Done"); + console.log('Done'); }); // The following code fails to compile as expected (`undefined` is not assignable to `number`): @@ -27,20 +27,20 @@ asyncDone(success, function (err: Error | null): void { // `successValue` and stricter callback asyncDone(successValue, function (err: Error | null, result?: number): void { - console.log("Done"); + console.log('Done'); }); // `successValue` and unsound callback asyncDone(successValue, function (err: Error | null, result: number): void { - console.log("Done"); + console.log('Done'); }); // `failure` and stricter callback asyncDone(failure, function (err: Error | null, result?: number): void { - console.log("Done"); + console.log('Done'); }); // `failure` and unsound callback asyncDone(failure, function (err: Error | null, result: number): void { - console.log("Done"); + console.log('Done'); }); diff --git a/test/types/promises.ts b/test/types/promises.ts index e7a7498..ab201ff 100644 --- a/test/types/promises.ts +++ b/test/types/promises.ts @@ -1,16 +1,16 @@ -import asyncDone from "async-done"; +import asyncDone from 'async-done'; function success(): Promise { return Promise.resolve(2); } function failure(): Promise { - return Promise.reject(new Error("Promise Error")); + return Promise.reject(new Error('Promise Error')); } // `successValue` and stricter callback asyncDone(success, function (err: Error | null, result?: number): void { - console.log("Done"); + console.log('Done'); }); // The following code fails to compile as expected: @@ -20,15 +20,15 @@ asyncDone(success, function (err: Error | null, result?: number): void { // `successValue` and unsound callback asyncDone(success, function (err: Error | null, result: number): void { - console.log("Done"); + console.log('Done'); }); // `failure` and stricter callback asyncDone(failure, function (err: Error | null, result?: number): void { - console.log("Done"); + console.log('Done'); }); // `failure` and unsound callback asyncDone(failure, function (err: Error | null, result: number): void { - console.log("Done"); + console.log('Done'); }); diff --git a/test/types/streams.ts b/test/types/streams.ts index cda238b..d6db15f 100644 --- a/test/types/streams.ts +++ b/test/types/streams.ts @@ -1,5 +1,5 @@ -import asyncDone from "async-done"; -import { Readable, Stream } from "stream"; +import asyncDone from 'async-done'; +import { Readable, Stream } from 'stream'; function streamSuccess(): Stream { return new Stream(); @@ -10,9 +10,9 @@ function streamFail(): Stream { } asyncDone(streamSuccess, function (err: Error | null): void { - console.log("Done"); + console.log('Done'); }); asyncDone(streamFail, function (err: Error | null): void { - console.log("Done"); + console.log('Done'); }); diff --git a/test/types/tsconfig.json b/test/types/tsconfig.json index 35ef644..2ed9fce 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": { - "async-done": [ - "index.d.ts" - ] + "async-done": ["index.d.ts"] }, "preserveConstEnums": true, "removeComments": false, @@ -56,8 +52,6 @@ "target": "es2017", "traceResolution": false }, - "include": [ - "./**/*.ts" - ], + "include": ["./**/*.ts"], "exclude": [] } diff --git a/test/types/various.ts b/test/types/various.ts index 73c6956..3427051 100644 --- a/test/types/various.ts +++ b/test/types/various.ts @@ -1,4 +1,4 @@ -import asyncDone, {AsyncTask, VoidCallback} from "async-done"; +import asyncDone, { AsyncTask, VoidCallback } from 'async-done'; // Do not error if the return value is not `void`. const fn: AsyncTask = (cb: VoidCallback): NodeJS.Timer => setTimeout(cb, 1000); From dfa4f0b30b1c4666dbf6c930aac62434cf6a0c1c Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 24 Jun 2022 17:03:41 -0700 Subject: [PATCH 10/13] fix: Ensure the Observable failure test works (#59) --- test/observables.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/observables.js b/test/observables.js index 18e2572..7aeaff0 100644 --- a/test/observables.js +++ b/test/observables.js @@ -16,7 +16,9 @@ function successValue() { } function failure() { - return rxjs.throw(new Error('Observable error')); + return rxjs.throwError(function () { + return new Error('Observable error'); + }); } describe('observables', function () { @@ -37,6 +39,7 @@ describe('observables', function () { it('should handle an errored observable', function (done) { asyncDone(failure, function (err) { expect(err).toBeInstanceOf(Error); + expect(err.message).toEqual('Observable error'); done(); }); }); From 7b37da45e8344e78a5d40a8c277cc57d796c1257 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 24 Jun 2022 17:12:17 -0700 Subject: [PATCH 11/13] chore: Add tests for streamx (#58) fix!: Allow end-of-stream to handle the stream error states --- index.js | 4 +-- package.json | 1 + test/streams.js | 4 --- test/streamx.js | 85 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 test/streamx.js diff --git a/index.js b/index.js index 5d0cd80..d835622 100644 --- a/index.js +++ b/index.js @@ -6,9 +6,7 @@ var eos = require('end-of-stream'); var once = require('once'); var exhaust = require('stream-exhaust'); -var eosConfig = { - error: false, -}; +var eosConfig = {}; function rethrowAsync(err) { process.nextTick(rethrow); diff --git a/package.json b/package.json index e62c0f1..6376413 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "nyc": "^15.1.0", "pumpify": "^2.0.1", "rxjs": "^7.4.0", + "streamx": "^2.12.0", "through2": "^4.0.2", "typescript": "^4.4.4" }, diff --git a/test/streams.js b/test/streams.js index 21ef6d7..d5119c6 100644 --- a/test/streams.js +++ b/test/streams.js @@ -41,10 +41,6 @@ function pumpifyError() { var read = fs.createReadStream(exists); var pipeline = pumpify(through(), through(withErr), through()); - pipeline.on('error', function (err) { - throw err; - }); - return read.pipe(pipeline); } diff --git a/test/streamx.js b/test/streamx.js new file mode 100644 index 0000000..71256b3 --- /dev/null +++ b/test/streamx.js @@ -0,0 +1,85 @@ +'use strict'; + +var expect = require('expect'); + +var streamx = require('streamx'); + +var asyncDone = require('../'); + +function success() { + return streamx.Readable.from('Foo Bar Baz').pipe(new streamx.Writable()); +} + +function failure() { + return streamx.Readable.from('Foo Bar Baz').pipe( + new streamx.Writable({ + write: function (data, cb) { + cb(new Error('Fail')); + }, + }) + ); +} + +function pipelineError() { + return streamx.pipeline( + streamx.Readable.from('Foo Bar Baz'), + new streamx.Transform(), + new streamx.Transform({ + transform: function (data, cb) { + cb(new Error('Fail')); + }, + }), + new streamx.Writable() + ); +} + +function unpiped() { + return streamx.Readable.from('Foo Bar Baz'); +} + +describe('streamx streams', function () { + it('should handle a successful stream', function (done) { + asyncDone(success, function (err) { + expect(err).not.toBeInstanceOf(Error); + done(); + }); + }); + + it('should handle an errored stream', function (done) { + asyncDone(failure, function (err) { + expect(err).toBeInstanceOf(Error); + expect(err.message).not.toEqual('premature close'); + done(); + }); + }); + + it('should handle an errored pipeline', function (done) { + asyncDone(pipelineError, function (err) { + expect(err).toBeInstanceOf(Error); + expect(err.message).not.toEqual('premature close'); + done(); + }); + }); + + it('handle a returned stream and cb by only calling callback once', function (done) { + asyncDone( + function (cb) { + return success().on('finish', function () { + cb(null, 3); + }); + }, + function (err, result) { + expect(err).not.toBeInstanceOf(Error); + expect(result).toEqual(3); // To know we called the callback + done(); + } + ); + }); + + it('consumes an unpiped readable stream', function (done) { + asyncDone(unpiped, function (err) { + expect(err).not.toBeInstanceOf(Error); + done(); + }); + }); +}); From 592afb00be2b836b99587d9a70650324db80cf99 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 24 Jun 2022 17:18:24 -0700 Subject: [PATCH 12/13] chore: Release 2.0.0 (#57) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 19 +++++++++++++++++++ package.json | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..951f773 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,19 @@ +# Changelog + +## [2.0.0](https://www.github.com/gulpjs/async-done/compare/v1.3.2...v2.0.0) (2022-06-25) + + +### ⚠ BREAKING CHANGES + +* Allow end-of-stream to handle the stream error states +* Normalize repository, dropping node <10.13 support (#54) + +### Bug Fixes + +* Allow end-of-stream to handle the stream error states ([7b37da4](https://www.github.com/gulpjs/async-done/commit/7b37da45e8344e78a5d40a8c277cc57d796c1257)) +* Ensure the Observable failure test works ([#59](https://www.github.com/gulpjs/async-done/issues/59)) ([dfa4f0b](https://www.github.com/gulpjs/async-done/commit/dfa4f0b30b1c4666dbf6c930aac62434cf6a0c1c)) + + +### Miscellaneous Chores + +* Normalize repository, dropping node <10.13 support ([#54](https://www.github.com/gulpjs/async-done/issues/54)) ([66f987f](https://www.github.com/gulpjs/async-done/commit/66f987f36d2cbd07d5b96f487ea327caa44acb10)) diff --git a/package.json b/package.json index 6376413..5f20a97 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "async-done", - "version": "1.3.2", + "version": "2.0.0", "description": "Allows libraries to handle various caller provided asynchronous functions uniformly. Maps promises, observables, child processes and streams, and callbacks to callback style.", "author": "Gulp Team (https://gulpjs.com/)", "contributors": [ From 4a7efae92c90ae6358412f2dc759561f0cb94ccc Mon Sep 17 00:00:00 2001 From: Takayuki Sato Date: Sun, 16 Apr 2023 07:05:06 +0900 Subject: [PATCH 13/13] chore: Normalize repository (#60) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ab8df8..cf5de9c 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ MIT [npm-image]: https://img.shields.io/npm/v/async-done.svg?style=flat-square [ci-url]: https://github.com/gulpjs/async-done/actions?query=workflow:dev -[ci-image]: https://img.shields.io/github/workflow/status/gulpjs/async-done/dev?style=flat-square +[ci-image]: https://img.shields.io/github/actions/workflow/status/gulpjs/async-done/dev.yml?branch=master&style=flat-square [coveralls-url]: https://coveralls.io/r/gulpjs/async-done [coveralls-image]: https://img.shields.io/coveralls/gulpjs/async-done/master.svg?style=flat-square