diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 67fede4..6fd02cd 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-types + test: name: Test runs-on: ${{ matrix.os }} diff --git a/lib/fs.js b/lib/fs.js index b682525..a63d9aa 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -6,6 +6,7 @@ function promisify(func) { return function(...args) { return new Promise((resolve, reject) => { args.push(wrap(resolve, reject)); + // @ts-ignore func.call(this, ...args); }); }; @@ -33,3 +34,4 @@ exports.rename = promisify(fs.rename); exports.readdir = promisify(fs.readdir); exports.stat = promisify(fs.stat); exports.unlink = promisify(fs.unlink); +exports.unsupported = false; diff --git a/lib/logger.js b/lib/logger.js index 3d37a4c..86e8909 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -11,6 +11,16 @@ const assert = require('bsert'); const format = require('./format'); const fs = require('./fs'); +/** + * @typedef {Object} LoggerOptions + * @property {String} [level=none] + * @property {Boolean} [colors] + * @property {Boolean} [console] + * @property {String} [filename] + * @property {Number} [maxFileSize] + * @property {Number} [maxFiles] + */ + /** * Logger */ @@ -19,9 +29,7 @@ class Logger { /** * Create a logger. * @constructor - * @param {(String|Object)?} options/level - * @param {String?} options.level - * @param {Boolean} [options.colors=true] + * @param {(String|LoggerOptions)} [options] */ constructor(options) { @@ -317,18 +325,17 @@ class Logger { /** * Set or reset the log level. - * @param {String} level + * @param {String} levelName */ - setLevel(name) { - const level = Logger.levels[name.toUpperCase()]; + setLevel(levelName) { + const level = Logger.levels[levelName.toUpperCase()]; assert(level != null, 'Invalid log level.'); this.level = level; } /** * Output a log to the `error` log level. - * @param {String|Object|Error} err * @param {...Object} args */ @@ -348,7 +355,6 @@ class Logger { /** * Output a log to the `warning` log level. - * @param {String|Object} obj * @param {...Object} args */ @@ -368,7 +374,6 @@ class Logger { /** * Output a log to the `info` log level. - * @param {String|Object} obj * @param {...Object} args */ @@ -388,7 +393,6 @@ class Logger { /** * Output a log to the `debug` log level. - * @param {String|Object} obj * @param {...Object} args */ @@ -408,7 +412,6 @@ class Logger { /** * Output a log to the `spam` log level. - * @param {String|Object} obj * @param {...Object} args */ @@ -429,7 +432,7 @@ class Logger { /** * Output a log to the desired log level. * Note that this bypasses the level check. - * @param {String} level + * @param {Number} level * @param {String|null} module * @param {Object[]} args */ @@ -464,7 +467,7 @@ class Logger { /** * Write log to the console. - * @param {String} level + * @param {Number} level * @param {String|null} module * @param {Object[]} args */ @@ -525,7 +528,7 @@ class Logger { /** * Write a string to the output stream (usually a file). - * @param {String} level + * @param {Number} level * @param {String|null} module * @param {Object[]} args */ @@ -564,7 +567,6 @@ class Logger { /** * Helper to parse an error into a nicer * format. Call's `log` internally. - * @private * @param {Number} level * @param {String|null} module * @param {Error} err @@ -689,7 +691,7 @@ class LoggerContext { /** * Set or reset the log level. - * @param {String} level + * @param {String} name */ setLevel(name) { @@ -698,7 +700,6 @@ class LoggerContext { /** * Output a log to the `error` log level. - * @param {String|Object|Error} err * @param {...Object} args */ @@ -718,7 +719,6 @@ class LoggerContext { /** * Output a log to the `warning` log level. - * @param {String|Object} obj * @param {...Object} args */ @@ -738,7 +738,6 @@ class LoggerContext { /** * Output a log to the `info` log level. - * @param {String|Object} obj * @param {...Object} args */ @@ -758,7 +757,6 @@ class LoggerContext { /** * Output a log to the `debug` log level. - * @param {String|Object} obj * @param {...Object} args */ @@ -778,7 +776,6 @@ class LoggerContext { /** * Output a log to the `spam` log level. - * @param {String|Object} obj * @param {...Object} args */ @@ -799,7 +796,7 @@ class LoggerContext { /** * Output a log to the desired log level. * Note that this bypasses the level check. - * @param {String} level + * @param {Number} level * @param {Object[]} args */ diff --git a/package-lock.json b/package-lock.json index 2329e00..209f64f 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 04ce61e..e953e4e 100644 --- a/package.json +++ b/package.json @@ -17,13 +17,15 @@ "main": "./lib/blgr.js", "scripts": { "lint": "eslint lib/", + "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..da7a94b --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,31 @@ +{ + "include": [ + "lib/**/*.js" + ], + "compilerOptions": { + "rootDir": ".", + "target": "ES2020", + "lib": [ + "ES2020" + ], + + "noEmit": true, + + "allowJs": true, + "checkJs": true, + "maxNodeModuleJsDepth": 10, + + "module": "commonjs", + "moduleResolution": "node", + "resolveJsonModule": true, + + "stripInternal": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": false, + + "typeRoots": [ + "node_modules/bts-type-deps/types" + ] + } +}