From 3662440908dbc5e0501eb5667e07b1431ebef917 Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Sat, 19 Sep 2020 20:40:31 +0300 Subject: [PATCH 1/3] Add TS types --- .eslintignore | 2 ++ package.json | 23 +++++++++++++++++++-- tsconfig.json | 13 ++++++++++++ types/index.d.ts | 48 +++++++++++++++++++++++++++++++++++++++++++ types/index.test-d.ts | 18 ++++++++++++++++ 5 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 .eslintignore create mode 100644 tsconfig.json create mode 100644 types/index.d.ts create mode 100644 types/index.test-d.ts diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..874fc1b --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +types/index.d.ts +types/index.test-d.ts diff --git a/package.json b/package.json index 8b59af4..dda3586 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,21 @@ "version": "1.1.0", "description": "Extremely fast utf8 only stream implementation", "main": "index.js", + "type": "commonjs", + "types": "types/index.d.ts", + "files": [ + "bench.js.js", + "check.js.js", + "example.js", + "index.js", + "types/index.d.ts", + "LICENSE", + "test.js", + "fixtures" + ], "scripts": { - "test": "standard && tap --no-ts --no-jsx --no-esm -t 120 test.js" + "test": "test:types && standard && tap --no-ts --no-jsx --no-esm -t 120 test.js", + "test:types": "tsc && tsd" }, "repository": { "type": "git", @@ -26,11 +39,14 @@ }, "homepage": "https://github.com/mcollina/sonic-boom#readme", "devDependencies": { + "@types/node": "^14.11.1", "fastbench": "^1.0.1", "husky": "^4.2.3", "proxyquire": "^2.1.0", "standard": "^14.0.0", - "tap": "^14.0.0" + "tap": "^14.0.0", + "tsd": "^0.13.1", + "typescript": "^4.0.3" }, "dependencies": { "atomic-sleep": "^1.0.0", @@ -40,5 +56,8 @@ "hooks": { "pre-commit": "npm test" } + }, + "tsd": { + "directory": "./types" } } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..19bebcc --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "es6", + "lib": [ "es2015" ], + "module": "commonjs", + "noEmit": true, + "strict": true + }, + "include": [ + "./types/index.test-d.ts", + "./types/index.d.ts" + ] +} diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..6402f9f --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,48 @@ +// Type definitions for sonic-boom 0.7 +// Definitions by: Alex Ferrando +// Igor Savin +/// + +import { EventEmitter } from 'events'; + +export default SonicBoom; + +declare class SonicBoom extends EventEmitter { + /** + * @param [fileDescriptor] File path or numerical file descriptor + * relative protocol is enabled. Default: process.stdout + * @returns a new sonic-boom instance + */ + constructor(fileDescriptor: string | number, minLength?: number, sync?: boolean) + + /** + * Writes the string to the file. It will return false to signal the producer to slow down. + */ + write(string: string): void; + + /** + * Writes the current buffer to the file if a write was not in progress. + * Do nothing if minLength is zero or if it is already writing. + */ + flush(): void; + + /** + * Reopen the file in place, useful for log rotation. + */ + reopen(fileDescriptor?: string | number): void; + + /** + * Flushes the buffered data synchronously. This is a costly operation. + */ + flushSync(): void; + + /** + * Closes the stream, the data will be flushed down asynchronously + */ + end(): void; + + /** + * Closes the stream immediately, the data is not flushed. + */ + destroy(): void; +} diff --git a/types/index.test-d.ts b/types/index.test-d.ts new file mode 100644 index 0000000..2984a04 --- /dev/null +++ b/types/index.test-d.ts @@ -0,0 +1,18 @@ +import SonicBoom from '../'; +const sonic = new SonicBoom(1); + +sonic.write('hello sonic\n'); + +sonic.flush(); + +sonic.flushSync(); + +sonic.reopen(); + +sonic.end(); + +sonic.destroy(); + +const extraSonic = new SonicBoom(1, 0, true); + +extraSonic.write('extra sonic\n'); From 3408ead91a1173ac4446ccc13a31195f8f329c3f Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Sat, 19 Sep 2020 20:42:55 +0300 Subject: [PATCH 2/3] Fix npm script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dda3586..1aa19f7 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "fixtures" ], "scripts": { - "test": "test:types && standard && tap --no-ts --no-jsx --no-esm -t 120 test.js", + "test": "npm run test:types && standard && tap --no-ts --no-jsx --no-esm -t 120 test.js", "test:types": "tsc && tsd" }, "repository": { From baf7c8ca90995780e109ad657ac5ca703158b6fb Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Sun, 20 Sep 2020 14:36:33 +0300 Subject: [PATCH 3/3] Replaces `files` with `.npmignore` --- .npmignore | 10 ++++++++++ package.json | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 .npmignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..abfef68 --- /dev/null +++ b/.npmignore @@ -0,0 +1,10 @@ +.editorconfig +.gitattributes +.git +.DS_Store +.gitignore +.github +.dependabot +.clinic +tsconfig.json +types/index.test-d.ts diff --git a/package.json b/package.json index 1aa19f7..9aefe7d 100644 --- a/package.json +++ b/package.json @@ -5,16 +5,6 @@ "main": "index.js", "type": "commonjs", "types": "types/index.d.ts", - "files": [ - "bench.js.js", - "check.js.js", - "example.js", - "index.js", - "types/index.d.ts", - "LICENSE", - "test.js", - "fixtures" - ], "scripts": { "test": "npm run test:types && standard && tap --no-ts --no-jsx --no-esm -t 120 test.js", "test:types": "tsc && tsd"