diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 67fede4..a1a2cae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ jobs: node-version: 20.x - name: Install tools - run: npm install --location=global bslint + run: npm install --location=global bslint typescript - name: Install dependencies run: npm install @@ -24,6 +24,9 @@ jobs: - name: Lint run: npm run lint + - name: Lint types + run: npm run lint + test: name: Test runs-on: ${{ matrix.os }} diff --git a/lib/brq.js b/lib/brq.js index e14282e..783a692 100644 --- a/lib/brq.js +++ b/lib/brq.js @@ -6,4 +6,6 @@ 'use strict'; -module.exports = require('./request'); +const {request} = require('./request'); + +module.exports = request; diff --git a/lib/request-browser.js b/lib/request-browser.js index a6ebc5e..2d9a24b 100644 --- a/lib/request-browser.js +++ b/lib/request-browser.js @@ -313,7 +313,6 @@ class Response { /** * Response * @constructor - * @ignore */ constructor() { @@ -430,6 +429,7 @@ request.stream = function stream(options) { const s = new EventEmitter(); const body = []; + // @ts-ignore s.write = (data, enc) => { if (!Buffer.isBuffer(data)) { assert(typeof data === 'string'); @@ -439,6 +439,7 @@ request.stream = function stream(options) { return true; }; + // @ts-ignore s.end = () => { options.extra = Buffer.concat(body); _request(options, false).then((res) => { @@ -461,4 +462,4 @@ request.stream = function stream(options) { * Expose */ -module.exports = request; +exports.request = request; diff --git a/lib/request.js b/lib/request.js index 02c7aca..804c467 100644 --- a/lib/request.js +++ b/lib/request.js @@ -341,7 +341,6 @@ class Request extends Stream { /** * Request * @constructor - * @private * @param {Object} options */ @@ -641,4 +640,4 @@ function ensureRequires(ssl) { * Expose */ -module.exports = request; +exports.request = request; diff --git a/package-lock.json b/package-lock.json index 32b7133..99dd7e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,8 @@ "bsert": "~0.0.12" }, "devDependencies": { - "bmocha": "^2.1.8" + "bmocha": "^2.1.8", + "bts-type-deps": "^0.0.3" }, "engines": { "node": ">=8.0.0" @@ -38,6 +39,12 @@ "engines": { "node": ">=8.0.0" } + }, + "node_modules/bts-type-deps": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/bts-type-deps/-/bts-type-deps-0.0.3.tgz", + "integrity": "sha512-OQHGWhX5amae6Vj6ShlGaQu0sNCICgJ5YspNZPRzfR5RobrD+wjm5vkZK/J3EH5b/ymxqSWo9VkiFNpCxjaG2Q==", + "dev": true } } } diff --git a/package.json b/package.json index b95378c..81b2e0d 100644 --- a/package.json +++ b/package.json @@ -16,13 +16,15 @@ "main": "./lib/brq.js", "scripts": { "lint": "eslint lib/ test/", + "lint-types": "tsc -p .", "test": "bmocha --reporter spec test/*-test.js" }, "dependencies": { "bsert": "~0.0.12" }, "devDependencies": { - "bmocha": "^2.1.8" + "bmocha": "^2.1.8", + "bts-type-deps": "^0.0.3" }, "engines": { "node": ">=8.0.0" diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..56c78ac --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,31 @@ +{ + "include": [ + "lib/**/*.js" + ], + "compilerOptions": { + "rootDir": ".", + "target": "ES2016", + "lib": [ + "ES2016" + ], + + "noEmit": true, + + "allowJs": true, + "checkJs": true, + "maxNodeModuleJsDepth": 2, + + "module": "commonjs", + "moduleResolution": "node", + "resolveJsonModule": true, + + "stripInternal": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": false, + + "typeRoots": [ + "node_modules/bts-type-deps/types" + ] + } +}