From d4cbec0cc2b77e9809e269b9c860bd9a2fc67656 Mon Sep 17 00:00:00 2001 From: kei-g Date: Tue, 31 Aug 2021 09:44:09 +0900 Subject: [PATCH 1/9] :arrow_up: Update packages for development - `@types/node` is upgraded from 16.7.1 to 16.7.8 - `@typescript-eslint/eslint-plugin` is upgraded from 4.29.2 to 4.30.0 - `@typescript-eslint/parser` is upgraded from 4.29.2 to 4.30.0 - `mocha` is upgraded from 9.1.0 to 9.1.1 - `terser` is upgraded from 5.7.1 to 5.7.2 - `typescript` is upgraded from 4.3.5 to 4.4.2 Signed-off-by: kei-g --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index bdc4ddf..fee36a7 100644 --- a/package.json +++ b/package.json @@ -45,17 +45,17 @@ "devDependencies": { "@types/chai": "^4.2.21", "@types/mocha": "^9.0.0", - "@types/node": "^16.7.1", - "@typescript-eslint/eslint-plugin": "^4.29.2", - "@typescript-eslint/parser": "^4.29.2", + "@types/node": "^16.7.8", + "@typescript-eslint/eslint-plugin": "^4.30.0", + "@typescript-eslint/parser": "^4.30.0", "chai": "^4.3.4", "eslint": "^7.32.0", - "mocha": "^9.1.0", + "mocha": "^9.1.1", "nyc": "^15.1.0", "rimraf": "^3.0.2", - "terser": "^5.7.1", + "terser": "^5.7.2", "ts-node": "^10.2.1", - "typescript": "^4.3.5", + "typescript": "^4.4.2", "uuid": "^8.3.2" }, "homepage": "https://github.com/kei-g/async-iterable-queue", From 381582b24071b400bd3dc267d1ede40a641dc14d Mon Sep 17 00:00:00 2001 From: kei-g Date: Tue, 31 Aug 2021 10:50:00 +0900 Subject: [PATCH 2/9] :hammer: Optimize build script Signed-off-by: kei-g --- .gitignore | 5 +++-- .npmignore | 2 +- lib/.npmignore | 1 - package.json | 20 +++++++++++-------- src/.gitignore | 1 + src/index.ts | 3 +++ .../lib/async-iterable-queue.ts | 0 test/async-iterable-queue.spec.ts | 2 +- tsconfig.json | 10 ++++------ 9 files changed, 25 insertions(+), 19 deletions(-) delete mode 100644 lib/.npmignore create mode 100644 src/.gitignore create mode 100644 src/index.ts rename async-iterable-queue.ts => src/lib/async-iterable-queue.ts (100%) diff --git a/.gitignore b/.gitignore index 706d5d1..ff3abd9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ +**/*.d.ts +**/*.js **/.nyc_output/ **/.vscode/ **/build/ **/coverage/ -**/lib/*.js -**/lib/*.ts +**/lib/ **/node_modules/ **/package-lock.json diff --git a/.npmignore b/.npmignore index 20889fd..41839aa 100644 --- a/.npmignore +++ b/.npmignore @@ -1,9 +1,9 @@ -**/*.ts **/.editorconfig **/.eslintrc.json **/.mocharc.json **/.travis.yml **/CODE_OF_CONDUCT.md **/build/ +**/src/ **/test/ **/tsconfig.json diff --git a/lib/.npmignore b/lib/.npmignore deleted file mode 100644 index 776a4d0..0000000 --- a/lib/.npmignore +++ /dev/null @@ -1 +0,0 @@ -!**/*.d.ts diff --git a/package.json b/package.json index fee36a7..c1cb230 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "chai": "^4.3.4", "eslint": "^7.32.0", "mocha": "^9.1.1", + "npm-run-all": "^4.1.5", "nyc": "^15.1.0", "rimraf": "^3.0.2", "terser": "^5.7.2", @@ -68,7 +69,7 @@ "queue" ], "license": "BSD-3-Clause", - "main": "lib/async-iterable-queue.js", + "main": "index.js", "name": "async-iterable-queue", "nyc": { "branches": 100, @@ -84,14 +85,17 @@ "url": "https://github.com/kei-g/async-iterable-queue.git" }, "scripts": { - "build": "npm run lint && tsc && terser build/async-iterable-queue.js -c -m -o lib/async-iterable-queue.js --toplevel", - "clean": "rimraf .nyc_output/ build/ coverage/ lib/*.d.ts lib/*.js", + "build": "npm-run-all -p clean lint -s build:tsc -p build:terse:*", + "build:terse:async-iterable-queue": "terser build/lib/async-iterable-queue.js -c -m -o lib/async-iteable-queue.js --toplevel", + "build:terse:index": "terser build/index.js -c -m -o index.js --toplevel", + "build:tsc": "tsc", + "clean": "rimraf .nyc_output/ build/ coverage/ index.d.ts index.js lib/", "cover": "nyc --check-coverage -r html -r text _mocha", - "lint": "eslint *.ts", - "prebuild": "rimraf build/ lib/*.d.ts lib/*.js", - "prepublishOnly": "npm run build", - "test": "npm run lint && npm run cover" + "lint": "eslint src/*.ts src/lib/*.ts", + "prebuild": "run-s clean", + "prepublishOnly": "run-s build", + "test": "run-p lint cover" }, - "types": "lib/async-iterable-queue.d.ts", + "types": "index.d.ts", "version": "1.0.0" } diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..1018baa --- /dev/null +++ b/src/.gitignore @@ -0,0 +1 @@ +!**/lib/ diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..73ffd26 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,3 @@ +export const name = 'async-iterable-queue' + +export * from './lib/async-iterable-queue' diff --git a/async-iterable-queue.ts b/src/lib/async-iterable-queue.ts similarity index 100% rename from async-iterable-queue.ts rename to src/lib/async-iterable-queue.ts diff --git a/test/async-iterable-queue.spec.ts b/test/async-iterable-queue.spec.ts index c4a3370..4619541 100644 --- a/test/async-iterable-queue.spec.ts +++ b/test/async-iterable-queue.spec.ts @@ -1,4 +1,4 @@ -import { AsyncIterableQueue } from '../async-iterable-queue' +import { AsyncIterableQueue } from '../src' import { describe, it } from 'mocha' import { expect } from 'chai' diff --git a/tsconfig.json b/tsconfig.json index fe13419..f3ab70c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "alwaysStrict": true, "charset": "utf8", "declaration": true, - "declarationDir": "lib", + "declarationDir": ".", "downlevelIteration": true, "emitBOM": false, "emitDeclarationOnly": false, @@ -26,9 +26,7 @@ ], }, "files": [ - "async-iterable-queue.ts", - ], - "include": [ - "async-iterable-queue.ts", - ], + "src/index.ts", + "src/lib/async-iterable-queue.ts", + ] } From 9e93b13539b1fcad421a35c6eda509dd4720148f Mon Sep 17 00:00:00 2001 From: kei-g Date: Tue, 31 Aug 2021 10:52:16 +0900 Subject: [PATCH 3/9] :green_heart: Test only 'main' branch Signed-off-by: kei-g --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index acb38c4..032908e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ branches: - except: - - /^v\d+\.\d+\.\d+$/ + only: + - main cache: directories: - ~/.npm From f96e3a90dd135c9cbbab2391e4f978fb94f21d0f Mon Sep 17 00:00:00 2001 From: kei-g Date: Tue, 31 Aug 2021 10:53:17 +0900 Subject: [PATCH 4/9] :green_heart: Except Node.js v15.x from test target Signed-off-by: kei-g --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 032908e..a53fbb7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ cache: language: node_js node_js: - 14 - - 15 - 16 notifications: email: false From 8cc7ce0bba1f08e7ad89e0acd071cfcee7c3c2c5 Mon Sep 17 00:00:00 2001 From: kei-g Date: Tue, 31 Aug 2021 10:56:19 +0900 Subject: [PATCH 5/9] :wrench: Add .nycrc.json Signed-off-by: kei-g --- .npmignore | 1 + .nycrc.json | 28 ++++++++++++++++++++++++++++ README.md | 4 +++- package.json | 6 ------ 4 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 .nycrc.json diff --git a/.npmignore b/.npmignore index 41839aa..d26ecd1 100644 --- a/.npmignore +++ b/.npmignore @@ -1,6 +1,7 @@ **/.editorconfig **/.eslintrc.json **/.mocharc.json +**/.nycrc.json **/.travis.yml **/CODE_OF_CONDUCT.md **/build/ diff --git a/.nycrc.json b/.nycrc.json new file mode 100644 index 0000000..ce1d23b --- /dev/null +++ b/.nycrc.json @@ -0,0 +1,28 @@ +{ + "all": true, + "branches": 100, + "check-coverage": true, + "exclude": [ + "**/*.spec.ts", + "**/index.ts" + ], + "extension": [ + ".ts" + ], + "functions": 100, + "include": [ + "**/*.ts" + ], + "lines": 100, + "reporter": [ + "html", + "text" + ], + "statements": 100, + "watermarks": { + "branches": [80, 95], + "functions": [80, 95], + "lines": [80, 95], + "statements": [80, 95] + } +} diff --git a/README.md b/README.md index acc3097..d36b4c8 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,19 @@ # async-iterable-queue [![License][license-image]][license-url] [![Dependency][depencency-image]][dependency-url] [![Travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] -[![maintenance][maintenance-image]][npmsio-url] [![quality][quality-image]][npmsio-url] +[![coverage][nyc-cov-image]][github-url] [![maintenance][maintenance-image]][npmsio-url] [![quality][quality-image]][npmsio-url] Async Iterable Queue [depencency-image]:https://img.shields.io/librariesio/release/npm/async-iterable-queue?logo=nodedotjs [dependency-url]:https://npmjs.com/package/async-iterable-queue?activeTab=dependencies +[github-url]:https://github.com/kei-g/async-iterable-queue [license-image]:https://img.shields.io/github/license/kei-g/async-iterable-queue [license-url]:https://opensource.org/licenses/BSD-3-Clause [maintenance-image]:https://img.shields.io/npms-io/maintenance-score/async-iterable-queue?logo=npm [npm-image]:https://img.shields.io/npm/v/async-iterable-queue.svg?logo=npm [npm-url]:https://npmjs.org/package/async-iterable-queue [npmsio-url]:https://npms.io/search?q=async-iterable-queue +[nyc-cov-image]:https://img.shields.io/nycrc/kei-g/async-iterable-queue?config=.nycrc.json&label=coverage [quality-image]:https://img.shields.io/npms-io/quality-score/async-iterable-queue?logo=npm [travis-image]:https://img.shields.io/travis/kei-g/async-iterable-queue/main.svg?logo=travis [travis-url]:https://travis-ci.org/kei-g/async-iterable-queue diff --git a/package.json b/package.json index c1cb230..59e1d49 100644 --- a/package.json +++ b/package.json @@ -71,12 +71,6 @@ "license": "BSD-3-Clause", "main": "index.js", "name": "async-iterable-queue", - "nyc": { - "branches": 100, - "functions": 100, - "lines": 100, - "statements": 100 - }, "publishConfig": { "access": "public" }, From 4d77c1dd8148f3ead42f24e0799536f9c9b0b4a1 Mon Sep 17 00:00:00 2001 From: kei-g Date: Tue, 31 Aug 2021 11:44:58 +0900 Subject: [PATCH 6/9] :green_heart: Setup Github Action for CI Signed-off-by: kei-g --- .github/.gitkeep | 0 .github/workflows/main.yml | 21 +++++++++++++++++++++ .npmignore | 1 + README.md | 3 ++- 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 .github/.gitkeep create mode 100644 .github/workflows/main.yml diff --git a/.github/.gitkeep b/.github/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..7610092 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,21 @@ +name: test +on: + push: + branches: [ main ] +jobs: + npm-test: + runs-on: ubuntu-latest + strategy: + matrix: + node: [ '14.17.5', '16.8.0' ] + name: Test on Node.js ${{ matrix.node }} + steps: + - uses: actions/checkout@v2 + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node }} + - name: Setup modules + run: npm i + - name: Test + run: npm test diff --git a/.npmignore b/.npmignore index d26ecd1..d50ceab 100644 --- a/.npmignore +++ b/.npmignore @@ -1,5 +1,6 @@ **/.editorconfig **/.eslintrc.json +**/.github/ **/.mocharc.json **/.nycrc.json **/.travis.yml diff --git a/README.md b/README.md index d36b4c8..e32c15f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# async-iterable-queue [![License][license-image]][license-url] [![Dependency][depencency-image]][dependency-url] [![Travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] +# async-iterable-queue [![License][license-image]][license-url] [![Dependency][depencency-image]][dependency-url] [![GitHub][github-test-image]][github-url] [![Travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![coverage][nyc-cov-image]][github-url] [![maintenance][maintenance-image]][npmsio-url] [![quality][quality-image]][npmsio-url] @@ -6,6 +6,7 @@ Async Iterable Queue [depencency-image]:https://img.shields.io/librariesio/release/npm/async-iterable-queue?logo=nodedotjs [dependency-url]:https://npmjs.com/package/async-iterable-queue?activeTab=dependencies +[github-test-image]:https://img.shields.io/github/workflow/status/kei-g/async-iterable-queue/test/main?label=build%20%26%20test&logo=github [github-url]:https://github.com/kei-g/async-iterable-queue [license-image]:https://img.shields.io/github/license/kei-g/async-iterable-queue [license-url]:https://opensource.org/licenses/BSD-3-Clause From 3ae481144a66bf0ce8c354226f1688e1f1b8ba78 Mon Sep 17 00:00:00 2001 From: kei-g Date: Tue, 31 Aug 2021 12:35:31 +0900 Subject: [PATCH 7/9] :memo: Add 'installation' and 'usage' and example Signed-off-by: kei-g --- .npmignore | 1 + README.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++- example.ts | 46 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 example.ts diff --git a/.npmignore b/.npmignore index d50ceab..5e047ef 100644 --- a/.npmignore +++ b/.npmignore @@ -6,6 +6,7 @@ **/.travis.yml **/CODE_OF_CONDUCT.md **/build/ +**/example.ts **/src/ **/test/ **/tsconfig.json diff --git a/README.md b/README.md index e32c15f..91b0bf0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,63 @@ [![coverage][nyc-cov-image]][github-url] [![maintenance][maintenance-image]][npmsio-url] [![quality][quality-image]][npmsio-url] -Async Iterable Queue +`async-iterable-queue` - A library for 'Queue' class which implements AsyncIterable\ works on [Node.js](https://nodejs.org/) + +## Installation + +```shell +npm i async-iterable-queue +``` + +## Usage + +```typescript +import { AsyncIterableQueue } from 'async-iterable-queue' + +type Foo = { + id: number + name: string +} + +async function example1(queue: AsyncIterableQueue): Promise { + console.debug('pushing 123') + await queue.push({ + id: 123, + name: 'foo', + }) + console.debug('123 has been pushed') + await queue.push({ + id: 456, + name: 'bar', + }) + console.debug('456 has been pushed') + await queue.push({ + id: 789, + name: 'baz', + }) + console.debug('789 has been pushed') + await queue.end() + console.debug('\'end\' has been pushed') +} + +async function example2(queue: AsyncIterableQueue): Promise { + for await (const value of queue) + console.debug(value) + console.debug('all elements have been popped from queue') +} + +async function example(): Promise { + console.debug('example for AsyncIterableQueue has begun') + const queue = new AsyncIterableQueue() + await Promise.all([ + example1(queue), + example2(queue), + ]) + console.debug('example for AsyncIterableQueue has finished') +} + +example() +``` [depencency-image]:https://img.shields.io/librariesio/release/npm/async-iterable-queue?logo=nodedotjs [dependency-url]:https://npmjs.com/package/async-iterable-queue?activeTab=dependencies diff --git a/example.ts b/example.ts new file mode 100644 index 0000000..ca9f8b0 --- /dev/null +++ b/example.ts @@ -0,0 +1,46 @@ + +import { AsyncIterableQueue } from './src' + +type Foo = { + id: number + name: string +} + +async function example1(queue: AsyncIterableQueue): Promise { + console.debug('pushing 123') + await queue.push({ + id: 123, + name: 'foo', + }) + console.debug('123 has been pushed') + await queue.push({ + id: 456, + name: 'bar', + }) + console.debug('456 has been pushed') + await queue.push({ + id: 789, + name: 'baz', + }) + console.debug('789 has been pushed') + await queue.end() + console.debug('\'end\' has been pushed') +} + +async function example2(queue: AsyncIterableQueue): Promise { + for await (const value of queue) + console.debug(value) + console.debug('all elements have been popped from queue') +} + +async function example(): Promise { + console.debug('example for AsyncIterableQueue has begun') + const queue = new AsyncIterableQueue() + await Promise.all([ + example1(queue), + example2(queue), + ]) + console.debug('example for AsyncIterableQueue has finished') +} + +example() From 9403e917c26925e3afe82bfe86f579a27183e266 Mon Sep 17 00:00:00 2001 From: kei-g Date: Tue, 31 Aug 2021 12:57:52 +0900 Subject: [PATCH 8/9] :memo: Correct badge for Travis CI Signed-off-by: kei-g --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 91b0bf0..09008b9 100644 --- a/README.md +++ b/README.md @@ -72,5 +72,5 @@ example() [npmsio-url]:https://npms.io/search?q=async-iterable-queue [nyc-cov-image]:https://img.shields.io/nycrc/kei-g/async-iterable-queue?config=.nycrc.json&label=coverage [quality-image]:https://img.shields.io/npms-io/quality-score/async-iterable-queue?logo=npm -[travis-image]:https://img.shields.io/travis/kei-g/async-iterable-queue/main.svg?logo=travis -[travis-url]:https://travis-ci.org/kei-g/async-iterable-queue +[travis-image]:https://img.shields.io/travis/com/kei-g/async-iterable-queue/main?label=build%20%26%20test&logo=travis +[travis-url]:https://app.travis-ci.com/kei-g/async-iterable-queue From 4dc5884384aa49adf4e007a03cf34286b78dd216 Mon Sep 17 00:00:00 2001 From: kei-g Date: Tue, 31 Aug 2021 13:05:11 +0900 Subject: [PATCH 9/9] :memo: Update the change log Signed-off-by: kei-g --- CHANGELOG.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b94fcd..16aa11f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,26 @@ # ChangeLogs +## Version 1.0.6 + +- :memo: Badge for Travis CI is corrected +- :hammer: Build script is optimized +- :children_crossing: Example code is added +- :green_heart: Github Action for CI +- :arrow_up: Packages for development are updated + - `@types/node` is upgraded from 16.7.1 to 16.7.8 + - `@typescript-eslint/eslint-plugin` is upgraded from 4.29.2 to 4.30.0 + - `@typescript-eslint/parser` is upgraded from 4.29.2 to 4.30.0 + - `mocha` is upgraded from 9.1.0 to 9.1.1 + - `terser` is upgraded from 5.7.1 to 5.7.2 + - `typescript` is upgraded from 4.3.5 to 4.4.2 +- :memo: README is updated + - Badges for both CI and coverage are added + - Installation section is added + - Usage section is added +- :green_heart: Travis CI + - Node.js v15.x is excepted from test target + - Only 'main' branch is made to be tested + ## Version 1.0.5 - :see_no_evil: .npmignore is added