From 31c9eaa2521f141f028fae5bf3ebe6c6a95d3558 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Mon, 31 Oct 2022 20:30:44 +0800 Subject: [PATCH 1/9] refactor: migrate typescript --- .gitignore | 1 + lib/console/{help.js => help.ts} | 10 +- lib/console/{index.js => index.ts} | 12 +- lib/console/{init.js => init.ts} | 20 +- lib/console/{version.js => version.ts} | 12 +- lib/{context.js => context.ts} | 22 +- lib/extend/{console.js => console.ts} | 19 +- lib/{find_pkg.js => find_pkg.ts} | 12 +- lib/{goodbye.js => goodbye.ts} | 2 +- lib/{hexo.js => hexo.ts} | 33 +- package-lock.json | 513 ++++++++++++++++++++----- package.json | 16 +- test/scripts/context.js | 2 +- test/scripts/find_pkg.js | 2 +- test/scripts/help.js | 6 +- test/scripts/hexo.js | 6 +- test/scripts/init.js | 4 +- test/scripts/version.js | 4 +- tsconfig.json | 19 + 19 files changed, 546 insertions(+), 169 deletions(-) rename lib/console/{help.js => help.ts} (93%) rename lib/console/{index.js => index.ts} (69%) rename lib/console/{init.js => init.ts} (86%) rename lib/console/{version.js => version.ts} (81%) rename lib/{context.js => context.ts} (73%) rename lib/extend/{console.js => console.ts} (84%) rename lib/{find_pkg.js => find_pkg.ts} (72%) rename lib/{goodbye.js => goodbye.ts} (65%) rename lib/{hexo.js => hexo.ts} (75%) create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index d99d1ad8..f411536f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ tmp/ .idea/ .nyc_output/ .vscode/ +dist/ \ No newline at end of file diff --git a/lib/console/help.js b/lib/console/help.ts similarity index 93% rename from lib/console/help.js rename to lib/console/help.ts index 5a57bf98..c0e12c95 100644 --- a/lib/console/help.js +++ b/lib/console/help.ts @@ -1,9 +1,9 @@ 'use strict'; -const { underline, bold } = require('picocolors'); -const { readFile } = require('hexo-fs'); -const { join } = require('path'); -const Promise = require('bluebird'); +import {underline, bold} from 'picocolors'; +import {readFile} from 'hexo-fs'; +import {join} from 'path'; +import Promise from 'bluebird'; const COMPLETION_DIR = join(__dirname, '../../completion'); @@ -115,4 +115,4 @@ function printCompletion(type) { }); } -module.exports = helpConsole; +export = helpConsole; diff --git a/lib/console/index.js b/lib/console/index.ts similarity index 69% rename from lib/console/index.js rename to lib/console/index.ts index 74b1f83f..e3f7f8ac 100644 --- a/lib/console/index.js +++ b/lib/console/index.ts @@ -1,9 +1,13 @@ 'use strict'; -module.exports = function(ctx) { +import helpConsole from './help'; +import initConsole from './init'; +import versionConsole from './version'; + +export = function(ctx) { const { console } = ctx.extend; - console.register('help', 'Get help on a command.', {}, require('./help')); + console.register('help', 'Get help on a command.', {}, helpConsole); console.register('init', 'Create a new Hexo folder.', { desc: 'Create a new Hexo folder at the specified path or the current directory.', @@ -15,7 +19,7 @@ module.exports = function(ctx) { {name: '--no-clone', desc: 'Copy files instead of cloning from GitHub'}, {name: '--no-install', desc: 'Skip npm install'} ] - }, require('./init')); + }, initConsole); - console.register('version', 'Display version information.', {}, require('./version')); + console.register('version', 'Display version information.', {}, versionConsole); }; diff --git a/lib/console/init.js b/lib/console/init.ts similarity index 86% rename from lib/console/init.js rename to lib/console/init.ts index 57e01790..67638db6 100644 --- a/lib/console/init.js +++ b/lib/console/init.ts @@ -1,12 +1,12 @@ 'use strict'; -const Promise = require('bluebird'); -const { join, resolve } = require('path'); -const { magenta } = require('picocolors'); -const { existsSync, readdirSync, rmdir, unlink, copyDir, readdir, stat } = require('hexo-fs'); -const tildify = require('tildify'); -const { spawn } = require('hexo-util'); -const commandExistsSync = require('command-exists').sync; +import BluebirdPromise from 'bluebird'; +import {join, resolve} from 'path'; +import {magenta} from 'picocolors'; +import {existsSync, readdirSync, rmdir, unlink, copyDir, readdir, stat} from 'hexo-fs'; +import tildify from 'tildify'; +import {spawn} from 'hexo-util'; +import {sync as commandExistsSync} from 'command-exists'; const ASSET_DIR = join(__dirname, '../../assets'); const GIT_REPO_URL = 'https://github.com/hexojs/hexo-starter.git'; @@ -20,7 +20,7 @@ async function initConsole(args) { if (existsSync(target) && readdirSync(target).length !== 0) { log.fatal(`${magenta(tildify(target))} not empty, please run \`hexo init\` on an empty folder and then copy your files into it`); - await Promise.reject(new Error('target not empty')); + await BluebirdPromise.reject(new Error('target not empty')); } log.info('Cloning hexo-starter', GIT_REPO_URL); @@ -38,7 +38,7 @@ async function initConsole(args) { await copyAsset(target); } - await Promise.all([ + await BluebirdPromise.all([ removeGitDir(target), removeGitModules(target) ]); @@ -111,4 +111,4 @@ async function removeGitModules(target) { } } -module.exports = initConsole; +export = initConsole; diff --git a/lib/console/version.js b/lib/console/version.ts similarity index 81% rename from lib/console/version.js rename to lib/console/version.ts index 842b4514..b0681271 100644 --- a/lib/console/version.js +++ b/lib/console/version.ts @@ -1,9 +1,9 @@ 'use strict'; -const os = require('os'); -const pkg = require('../../package.json'); -const Promise = require('bluebird'); -const { spawn } = require('hexo-util'); +import os from 'os'; +import pkg from '../../package.json'; +import BluebirdPromise from 'bluebird'; +import {spawn} from 'hexo-util'; async function versionConsole(args) { const { versions, platform } = process; @@ -33,7 +33,7 @@ async function versionConsole(args) { console.log('%s: %s', key, versions[key]); } - await Promise.resolve(); + await BluebirdPromise.resolve(); } -module.exports = versionConsole; +export = versionConsole; diff --git a/lib/context.js b/lib/context.ts similarity index 73% rename from lib/context.js rename to lib/context.ts index f169f5e0..470390bb 100644 --- a/lib/context.js +++ b/lib/context.ts @@ -1,15 +1,21 @@ 'use strict'; -const logger = require('hexo-log'); -const { underline } = require('picocolors'); -const { EventEmitter } = require('events'); -const Promise = require('bluebird'); -const ConsoleExtend = require('./extend/console'); +import logger from 'hexo-log'; +import {underline} from 'picocolors'; +import {EventEmitter} from 'events'; +import Promise from 'bluebird'; +import ConsoleExtend from './extend/console'; // a stub Hexo object // see `hexojs/hexo/lib/hexo/index.js` class Context extends EventEmitter { + base_dir: string; + log: any; + extend: { + console: ConsoleExtend; + } + constructor(base = process.cwd(), args = {}) { super(); this.base_dir = base; @@ -24,7 +30,7 @@ class Context extends EventEmitter { // Do nothing } - call(name, args, callback) { + call(name: string, args: object | Function, callback?: Function) { if (!callback && typeof args === 'function') { callback = args; args = {}; @@ -41,7 +47,7 @@ class Context extends EventEmitter { }).asCallback(callback); } - exit(err) { + exit(err?: Error) { if (err) { this.log.fatal( {err}, @@ -58,4 +64,4 @@ class Context extends EventEmitter { } } -module.exports = Context; +export = Context; diff --git a/lib/extend/console.js b/lib/extend/console.ts similarity index 84% rename from lib/extend/console.js rename to lib/extend/console.ts index fe1e6624..40b707a9 100644 --- a/lib/extend/console.js +++ b/lib/extend/console.ts @@ -1,15 +1,26 @@ 'use strict'; -const Promise = require('bluebird'); -const abbrev = require('abbrev'); +import Promise from 'bluebird'; +import abbrev from 'abbrev'; + +interface Store { + [key: string]: Function; +} + +interface Alias { + [key: string]: string; +} class Console { + store: Store; + alias: Alias; + constructor() { this.store = {}; this.alias = {}; } - get(name) { + get(name: string) { name = name.toLowerCase(); return this.store[this.alias[name]]; } @@ -62,4 +73,4 @@ class Console { } } -module.exports = Console; +export = Console; diff --git a/lib/find_pkg.js b/lib/find_pkg.ts similarity index 72% rename from lib/find_pkg.js rename to lib/find_pkg.ts index 79fd3904..97b8140c 100644 --- a/lib/find_pkg.js +++ b/lib/find_pkg.ts @@ -1,9 +1,13 @@ 'use strict'; -const { resolve, join, dirname } = require('path'); -const { readFile } = require('hexo-fs'); +import {resolve, join, dirname} from 'path'; +import {readFile} from 'hexo-fs'; -function findPkg(cwd, args = {}) { +interface findPkgArgs { + cwd?: string; +} + +function findPkg(cwd, args: findPkgArgs = {}) { if (args.cwd) { cwd = resolve(cwd, args.cwd); } @@ -29,4 +33,4 @@ function checkPkg(path) { }); } -module.exports = findPkg; +export = findPkg; diff --git a/lib/goodbye.js b/lib/goodbye.ts similarity index 65% rename from lib/goodbye.js rename to lib/goodbye.ts index a0ec92ad..382c1bd4 100644 --- a/lib/goodbye.js +++ b/lib/goodbye.ts @@ -9,4 +9,4 @@ const byeWords = [ 'Catch you later' ]; -module.exports = () => byeWords[(Math.random() * byeWords.length) | 0]; +export = () => byeWords[(Math.random() * byeWords.length) | 0]; diff --git a/lib/hexo.js b/lib/hexo.ts similarity index 75% rename from lib/hexo.js rename to lib/hexo.ts index 38dce4c9..bbf71bc2 100644 --- a/lib/hexo.js +++ b/lib/hexo.ts @@ -1,14 +1,19 @@ 'use strict'; -const { magenta } = require('picocolors'); -const tildify = require('tildify'); -const Promise = require('bluebird'); -const Context = require('./context'); -const findPkg = require('./find_pkg'); -const goodbye = require('./goodbye'); -const minimist = require('minimist'); -const resolve = require('resolve'); -const { camelCaseKeys } = require('hexo-util'); +import {magenta} from 'picocolors'; +import tildify from 'tildify'; +import Promise from 'bluebird'; +import Context from './context'; +import findPkg from './find_pkg'; +import goodbye from './goodbye'; +import minimist from 'minimist'; +import resolve from 'resolve'; +import { camelCaseKeys } from 'hexo-util'; + +import Console from './console'; +import helpConsole from './console/help'; +import initConsole from './console/init'; +import versionConsole from './console/version'; class HexoNotFoundError extends Error {} @@ -44,7 +49,7 @@ function entry(cwd = process.cwd(), args) { if (mod) hexo = mod; log = hexo.log; - require('./console')(hexo); + Console(hexo); return hexo.init(); }).then(() => { @@ -65,9 +70,9 @@ function entry(cwd = process.cwd(), args) { } entry.console = { - init: require('./console/init'), - help: require('./console/help'), - version: require('./console/version') + init: initConsole, + help: helpConsole, + version: versionConsole }; entry.version = require('../package.json').version; @@ -93,4 +98,4 @@ function watchSignal(hexo) { }); } -module.exports = entry; +export = entry; diff --git a/package-lock.json b/package-lock.json index 703b6080..a169d31b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,9 @@ "hexo": "bin/hexo" }, "devDependencies": { + "@types/node": "^18.11.8", + "@typescript-eslint/eslint-plugin": "^5.41.0", + "@typescript-eslint/parser": "^5.41.0", "chai": "^4.3.4", "eslint": "^8.2.0", "eslint-config-hexo": "^5.0.0", @@ -32,7 +35,9 @@ "nyc": "^15.1.0", "proxyquire": "^2.1.3", "rewire": "^6.0.0", - "sinon": "^14.0.0" + "sinon": "^14.0.0", + "ts-node": "^10.9.1", + "typescript": "^4.8.4" }, "engines": { "node": ">=14" @@ -318,6 +323,18 @@ "to-fast-properties": "^2.0.0" } }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/@eslint/eslintrc": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.0.tgz", @@ -459,6 +476,31 @@ "node": ">=8" } }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", + "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", + "dev": true, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.4.14", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", + "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", + "dev": true + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -538,23 +580,58 @@ "node": ">= 10" } }, + "node_modules/@tsconfig/node10": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", + "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==", + "dev": true + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.3.tgz", + "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==", + "dev": true + }, "node_modules/@types/json-schema": { "version": "7.0.11", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz", "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", "dev": true }, + "node_modules/@types/node": { + "version": "18.11.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.8.tgz", + "integrity": "sha512-uGwPWlE0Hj972KkHtCDVwZ8O39GmyjfMane1Z3GUBGGnkZ2USDq7SxLpVIiIHpweY9DS0QTDH0Nw7RNBsAAZ5A==", + "dev": true + }, + "node_modules/@types/semver": { + "version": "7.3.13", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.13.tgz", + "integrity": "sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==", + "dev": true + }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "5.33.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.33.1.tgz", - "integrity": "sha512-S1iZIxrTvKkU3+m63YUOxYPKaP+yWDQrdhxTglVDVEVBf+aCSw85+BmJnyUaQQsk5TXFG/LpBu9fa+LrAQ91fQ==", + "version": "5.41.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.41.0.tgz", + "integrity": "sha512-DXUS22Y57/LAFSg3x7Vi6RNAuLpTXwxB9S2nIA7msBb/Zt8p7XqMwdpdc1IU7CkOQUPgAqR5fWvxuKCbneKGmA==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "5.33.1", - "@typescript-eslint/type-utils": "5.33.1", - "@typescript-eslint/utils": "5.33.1", + "@typescript-eslint/scope-manager": "5.41.0", + "@typescript-eslint/type-utils": "5.41.0", + "@typescript-eslint/utils": "5.41.0", "debug": "^4.3.4", - "functional-red-black-tree": "^1.0.1", "ignore": "^5.2.0", "regexpp": "^3.2.0", "semver": "^7.3.7", @@ -593,14 +670,14 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "5.33.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.33.1.tgz", - "integrity": "sha512-IgLLtW7FOzoDlmaMoXdxG8HOCByTBXrB1V2ZQYSEV1ggMmJfAkMWTwUjjzagS6OkfpySyhKFkBw7A9jYmcHpZA==", + "version": "5.41.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.41.0.tgz", + "integrity": "sha512-HQVfix4+RL5YRWZboMD1pUfFN8MpRH4laziWkkAzyO1fvNOY/uinZcvo3QiFJVS/siNHupV8E5+xSwQZrl6PZA==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "5.33.1", - "@typescript-eslint/types": "5.33.1", - "@typescript-eslint/typescript-estree": "5.33.1", + "@typescript-eslint/scope-manager": "5.41.0", + "@typescript-eslint/types": "5.41.0", + "@typescript-eslint/typescript-estree": "5.41.0", "debug": "^4.3.4" }, "engines": { @@ -620,13 +697,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "5.33.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.33.1.tgz", - "integrity": "sha512-8ibcZSqy4c5m69QpzJn8XQq9NnqAToC8OdH/W6IXPXv83vRyEDPYLdjAlUx8h/rbusq6MkW4YdQzURGOqsn3CA==", + "version": "5.41.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.41.0.tgz", + "integrity": "sha512-xOxPJCnuktUkY2xoEZBKXO5DBCugFzjrVndKdUnyQr3+9aDWZReKq9MhaoVnbL+maVwWJu/N0SEtrtEUNb62QQ==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.33.1", - "@typescript-eslint/visitor-keys": "5.33.1" + "@typescript-eslint/types": "5.41.0", + "@typescript-eslint/visitor-keys": "5.41.0" }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -637,12 +714,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "5.33.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.33.1.tgz", - "integrity": "sha512-X3pGsJsD8OiqhNa5fim41YtlnyiWMF/eKsEZGsHID2HcDqeSC5yr/uLOeph8rNF2/utwuI0IQoAK3fpoxcLl2g==", + "version": "5.41.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.41.0.tgz", + "integrity": "sha512-L30HNvIG6A1Q0R58e4hu4h+fZqaO909UcnnPbwKiN6Rc3BUEx6ez2wgN7aC0cBfcAjZfwkzE+E2PQQ9nEuoqfA==", "dev": true, "dependencies": { - "@typescript-eslint/utils": "5.33.1", + "@typescript-eslint/typescript-estree": "5.41.0", + "@typescript-eslint/utils": "5.41.0", "debug": "^4.3.4", "tsutils": "^3.21.0" }, @@ -663,9 +741,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "5.33.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.33.1.tgz", - "integrity": "sha512-7K6MoQPQh6WVEkMrMW5QOA5FO+BOwzHSNd0j3+BlBwd6vtzfZceJ8xJ7Um2XDi/O3umS8/qDX6jdy2i7CijkwQ==", + "version": "5.41.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.41.0.tgz", + "integrity": "sha512-5BejraMXMC+2UjefDvrH0Fo/eLwZRV6859SXRg+FgbhA0R0l6lDqDGAQYhKbXhPN2ofk2kY5sgGyLNL907UXpA==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -676,13 +754,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "5.33.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.33.1.tgz", - "integrity": "sha512-JOAzJ4pJ+tHzA2pgsWQi4804XisPHOtbvwUyqsuuq8+y5B5GMZs7lI1xDWs6V2d7gE/Ez5bTGojSK12+IIPtXA==", + "version": "5.41.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.41.0.tgz", + "integrity": "sha512-SlzFYRwFSvswzDSQ/zPkIWcHv8O5y42YUskko9c4ki+fV6HATsTODUPbRbcGDFYP86gaJL5xohUEytvyNNcXWg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.33.1", - "@typescript-eslint/visitor-keys": "5.33.1", + "@typescript-eslint/types": "5.41.0", + "@typescript-eslint/visitor-keys": "5.41.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -703,9 +781,9 @@ } }, "node_modules/@typescript-eslint/typescript-estree/node_modules/semver": { - "version": "7.3.7", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", - "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", "dev": true, "dependencies": { "lru-cache": "^6.0.0" @@ -718,17 +796,19 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "5.33.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.33.1.tgz", - "integrity": "sha512-uphZjkMaZ4fE8CR4dU7BquOV6u0doeQAr8n6cQenl/poMaIyJtBu8eys5uk6u5HiDH01Mj5lzbJ5SfeDz7oqMQ==", + "version": "5.41.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.41.0.tgz", + "integrity": "sha512-QlvfwaN9jaMga9EBazQ+5DDx/4sAdqDkcs05AsQHMaopluVCUyu1bTRUVKzXbgjDlrRAQrYVoi/sXJ9fmG+KLQ==", "dev": true, "dependencies": { "@types/json-schema": "^7.0.9", - "@typescript-eslint/scope-manager": "5.33.1", - "@typescript-eslint/types": "5.33.1", - "@typescript-eslint/typescript-estree": "5.33.1", + "@types/semver": "^7.3.12", + "@typescript-eslint/scope-manager": "5.41.0", + "@typescript-eslint/types": "5.41.0", + "@typescript-eslint/typescript-estree": "5.41.0", "eslint-scope": "^5.1.1", - "eslint-utils": "^3.0.0" + "eslint-utils": "^3.0.0", + "semver": "^7.3.7" }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -741,13 +821,28 @@ "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/@typescript-eslint/utils/node_modules/semver": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "5.33.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.33.1.tgz", - "integrity": "sha512-nwIxOK8Z2MPWltLKMLOEZwmfBZReqUdbEoHQXeCpa+sRVARe5twpJGHCB4dk9903Yaf0nMAlGbQfaAH92F60eg==", + "version": "5.41.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.41.0.tgz", + "integrity": "sha512-vilqeHj267v8uzzakbm13HkPMl7cbYpKVjgFWZPIOHIJHZtinvypUhJ5xBXfWYg4eFKqztbMMpOgFpT9Gfx4fw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.33.1", + "@typescript-eslint/types": "5.41.0", "eslint-visitor-keys": "^3.3.0" }, "engines": { @@ -928,6 +1023,12 @@ "integrity": "sha1-+cjBN1fMHde8N5rHeyxipcKGjEA=", "dev": true }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, "node_modules/argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -1229,6 +1330,12 @@ "safe-buffer": "~5.1.1" } }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -3165,6 +3272,12 @@ "semver": "bin/semver.js" } }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, "node_modules/marked": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/marked/-/marked-4.1.1.tgz", @@ -4637,6 +4750,58 @@ "node": ">=12" } }, + "node_modules/ts-node": { + "version": "10.9.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", + "integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==", + "dev": true, + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, + "node_modules/ts-node/node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true, + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", @@ -4698,11 +4863,10 @@ } }, "node_modules/typescript": { - "version": "4.7.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", - "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", + "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==", "dev": true, - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -4755,6 +4919,12 @@ "integrity": "sha512-usZBT3PW+LOjM25wbqIlZwPeJV+3OSz3M1k1Ws8snlW39dZyYL9lOGC5FgPVHfk0jKmjiDV8Z0mIbVQPiwFs7g==", "dev": true }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true + }, "node_modules/w3c-xmlserializer": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-3.0.0.tgz", @@ -4985,6 +5155,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true, + "engines": { + "node": ">=6" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", @@ -5253,6 +5432,15 @@ "to-fast-properties": "^2.0.0" } }, + "@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "requires": { + "@jridgewell/trace-mapping": "0.3.9" + } + }, "@eslint/eslintrc": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.0.tgz", @@ -5361,6 +5549,28 @@ "integrity": "sha512-tsAQNx32a8CoFhjhijUIhI4kccIAgmGhy8LZMZgGfmXcpMbPRUqn5LWmgRttILi6yeGmBJd2xsPkFMs0PzgPCw==", "dev": true }, + "@jridgewell/resolve-uri": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", + "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", + "dev": true + }, + "@jridgewell/sourcemap-codec": { + "version": "1.4.14", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", + "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", + "dev": true + }, + "@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "requires": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -5428,23 +5638,58 @@ "integrity": "sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==", "dev": true }, + "@tsconfig/node10": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", + "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==", + "dev": true + }, + "@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true + }, + "@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true + }, + "@tsconfig/node16": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.3.tgz", + "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==", + "dev": true + }, "@types/json-schema": { "version": "7.0.11", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz", "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", "dev": true }, + "@types/node": { + "version": "18.11.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.8.tgz", + "integrity": "sha512-uGwPWlE0Hj972KkHtCDVwZ8O39GmyjfMane1Z3GUBGGnkZ2USDq7SxLpVIiIHpweY9DS0QTDH0Nw7RNBsAAZ5A==", + "dev": true + }, + "@types/semver": { + "version": "7.3.13", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.13.tgz", + "integrity": "sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==", + "dev": true + }, "@typescript-eslint/eslint-plugin": { - "version": "5.33.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.33.1.tgz", - "integrity": "sha512-S1iZIxrTvKkU3+m63YUOxYPKaP+yWDQrdhxTglVDVEVBf+aCSw85+BmJnyUaQQsk5TXFG/LpBu9fa+LrAQ91fQ==", + "version": "5.41.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.41.0.tgz", + "integrity": "sha512-DXUS22Y57/LAFSg3x7Vi6RNAuLpTXwxB9S2nIA7msBb/Zt8p7XqMwdpdc1IU7CkOQUPgAqR5fWvxuKCbneKGmA==", "dev": true, "requires": { - "@typescript-eslint/scope-manager": "5.33.1", - "@typescript-eslint/type-utils": "5.33.1", - "@typescript-eslint/utils": "5.33.1", + "@typescript-eslint/scope-manager": "5.41.0", + "@typescript-eslint/type-utils": "5.41.0", + "@typescript-eslint/utils": "5.41.0", "debug": "^4.3.4", - "functional-red-black-tree": "^1.0.1", "ignore": "^5.2.0", "regexpp": "^3.2.0", "semver": "^7.3.7", @@ -5463,52 +5708,53 @@ } }, "@typescript-eslint/parser": { - "version": "5.33.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.33.1.tgz", - "integrity": "sha512-IgLLtW7FOzoDlmaMoXdxG8HOCByTBXrB1V2ZQYSEV1ggMmJfAkMWTwUjjzagS6OkfpySyhKFkBw7A9jYmcHpZA==", + "version": "5.41.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.41.0.tgz", + "integrity": "sha512-HQVfix4+RL5YRWZboMD1pUfFN8MpRH4laziWkkAzyO1fvNOY/uinZcvo3QiFJVS/siNHupV8E5+xSwQZrl6PZA==", "dev": true, "requires": { - "@typescript-eslint/scope-manager": "5.33.1", - "@typescript-eslint/types": "5.33.1", - "@typescript-eslint/typescript-estree": "5.33.1", + "@typescript-eslint/scope-manager": "5.41.0", + "@typescript-eslint/types": "5.41.0", + "@typescript-eslint/typescript-estree": "5.41.0", "debug": "^4.3.4" } }, "@typescript-eslint/scope-manager": { - "version": "5.33.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.33.1.tgz", - "integrity": "sha512-8ibcZSqy4c5m69QpzJn8XQq9NnqAToC8OdH/W6IXPXv83vRyEDPYLdjAlUx8h/rbusq6MkW4YdQzURGOqsn3CA==", + "version": "5.41.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.41.0.tgz", + "integrity": "sha512-xOxPJCnuktUkY2xoEZBKXO5DBCugFzjrVndKdUnyQr3+9aDWZReKq9MhaoVnbL+maVwWJu/N0SEtrtEUNb62QQ==", "dev": true, "requires": { - "@typescript-eslint/types": "5.33.1", - "@typescript-eslint/visitor-keys": "5.33.1" + "@typescript-eslint/types": "5.41.0", + "@typescript-eslint/visitor-keys": "5.41.0" } }, "@typescript-eslint/type-utils": { - "version": "5.33.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.33.1.tgz", - "integrity": "sha512-X3pGsJsD8OiqhNa5fim41YtlnyiWMF/eKsEZGsHID2HcDqeSC5yr/uLOeph8rNF2/utwuI0IQoAK3fpoxcLl2g==", + "version": "5.41.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.41.0.tgz", + "integrity": "sha512-L30HNvIG6A1Q0R58e4hu4h+fZqaO909UcnnPbwKiN6Rc3BUEx6ez2wgN7aC0cBfcAjZfwkzE+E2PQQ9nEuoqfA==", "dev": true, "requires": { - "@typescript-eslint/utils": "5.33.1", + "@typescript-eslint/typescript-estree": "5.41.0", + "@typescript-eslint/utils": "5.41.0", "debug": "^4.3.4", "tsutils": "^3.21.0" } }, "@typescript-eslint/types": { - "version": "5.33.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.33.1.tgz", - "integrity": "sha512-7K6MoQPQh6WVEkMrMW5QOA5FO+BOwzHSNd0j3+BlBwd6vtzfZceJ8xJ7Um2XDi/O3umS8/qDX6jdy2i7CijkwQ==", + "version": "5.41.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.41.0.tgz", + "integrity": "sha512-5BejraMXMC+2UjefDvrH0Fo/eLwZRV6859SXRg+FgbhA0R0l6lDqDGAQYhKbXhPN2ofk2kY5sgGyLNL907UXpA==", "dev": true }, "@typescript-eslint/typescript-estree": { - "version": "5.33.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.33.1.tgz", - "integrity": "sha512-JOAzJ4pJ+tHzA2pgsWQi4804XisPHOtbvwUyqsuuq8+y5B5GMZs7lI1xDWs6V2d7gE/Ez5bTGojSK12+IIPtXA==", + "version": "5.41.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.41.0.tgz", + "integrity": "sha512-SlzFYRwFSvswzDSQ/zPkIWcHv8O5y42YUskko9c4ki+fV6HATsTODUPbRbcGDFYP86gaJL5xohUEytvyNNcXWg==", "dev": true, "requires": { - "@typescript-eslint/types": "5.33.1", - "@typescript-eslint/visitor-keys": "5.33.1", + "@typescript-eslint/types": "5.41.0", + "@typescript-eslint/visitor-keys": "5.41.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -5517,9 +5763,9 @@ }, "dependencies": { "semver": { - "version": "7.3.7", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", - "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", "dev": true, "requires": { "lru-cache": "^6.0.0" @@ -5528,26 +5774,39 @@ } }, "@typescript-eslint/utils": { - "version": "5.33.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.33.1.tgz", - "integrity": "sha512-uphZjkMaZ4fE8CR4dU7BquOV6u0doeQAr8n6cQenl/poMaIyJtBu8eys5uk6u5HiDH01Mj5lzbJ5SfeDz7oqMQ==", + "version": "5.41.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.41.0.tgz", + "integrity": "sha512-QlvfwaN9jaMga9EBazQ+5DDx/4sAdqDkcs05AsQHMaopluVCUyu1bTRUVKzXbgjDlrRAQrYVoi/sXJ9fmG+KLQ==", "dev": true, "requires": { "@types/json-schema": "^7.0.9", - "@typescript-eslint/scope-manager": "5.33.1", - "@typescript-eslint/types": "5.33.1", - "@typescript-eslint/typescript-estree": "5.33.1", + "@types/semver": "^7.3.12", + "@typescript-eslint/scope-manager": "5.41.0", + "@typescript-eslint/types": "5.41.0", + "@typescript-eslint/typescript-estree": "5.41.0", "eslint-scope": "^5.1.1", - "eslint-utils": "^3.0.0" + "eslint-utils": "^3.0.0", + "semver": "^7.3.7" + }, + "dependencies": { + "semver": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + } } }, "@typescript-eslint/visitor-keys": { - "version": "5.33.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.33.1.tgz", - "integrity": "sha512-nwIxOK8Z2MPWltLKMLOEZwmfBZReqUdbEoHQXeCpa+sRVARe5twpJGHCB4dk9903Yaf0nMAlGbQfaAH92F60eg==", + "version": "5.41.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.41.0.tgz", + "integrity": "sha512-vilqeHj267v8uzzakbm13HkPMl7cbYpKVjgFWZPIOHIJHZtinvypUhJ5xBXfWYg4eFKqztbMMpOgFpT9Gfx4fw==", "dev": true, "requires": { - "@typescript-eslint/types": "5.33.1", + "@typescript-eslint/types": "5.41.0", "eslint-visitor-keys": "^3.3.0" }, "dependencies": { @@ -5681,6 +5940,12 @@ "integrity": "sha1-+cjBN1fMHde8N5rHeyxipcKGjEA=", "dev": true }, + "arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -5924,6 +6189,12 @@ "safe-buffer": "~5.1.1" } }, + "create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true + }, "cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -7369,6 +7640,12 @@ } } }, + "make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, "marked": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/marked/-/marked-4.1.1.tgz", @@ -8477,6 +8754,35 @@ "punycode": "^2.1.1" } }, + "ts-node": { + "version": "10.9.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", + "integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==", + "dev": true, + "requires": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "dependencies": { + "diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true + } + } + }, "tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", @@ -8523,11 +8829,10 @@ } }, "typescript": { - "version": "4.7.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", - "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", - "dev": true, - "peer": true + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", + "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==", + "dev": true }, "universalify": { "version": "0.2.0", @@ -8566,6 +8871,12 @@ "integrity": "sha512-usZBT3PW+LOjM25wbqIlZwPeJV+3OSz3M1k1Ws8snlW39dZyYL9lOGC5FgPVHfk0jKmjiDV8Z0mIbVQPiwFs7g==", "dev": true }, + "v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true + }, "w3c-xmlserializer": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-3.0.0.tgz", @@ -8739,6 +9050,12 @@ } } }, + "yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true + }, "yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/package.json b/package.json index 0834bc8d..dd93f918 100644 --- a/package.json +++ b/package.json @@ -7,14 +7,19 @@ "hexo": "./bin/hexo" }, "files": [ - "lib", + "dist/**", "completion", "bin", "assets" ], + "types": "./dist/**/*.d.ts", "scripts": { + "prepublish ": "npm run clean && npm run build", + "build": "tsc -b", + "clean": "tsc -b --clean", "eslint": "eslint .", - "test": "mocha test/index.js", + "pretest": "npm run clean && npm run build", + "test": "mocha test/index.js --require ts-node/register", "test-cov": "nyc --reporter=lcovonly npm test", "prepare": "git submodule init && git submodule update && git submodule foreach git pull origin master" }, @@ -50,6 +55,9 @@ "tildify": "^2.0.0" }, "devDependencies": { + "@types/node": "^18.11.8", + "@typescript-eslint/eslint-plugin": "^5.41.0", + "@typescript-eslint/parser": "^5.41.0", "chai": "^4.3.4", "eslint": "^8.2.0", "eslint-config-hexo": "^5.0.0", @@ -58,7 +66,9 @@ "nyc": "^15.1.0", "proxyquire": "^2.1.3", "rewire": "^6.0.0", - "sinon": "^14.0.0" + "sinon": "^14.0.0", + "ts-node": "^10.9.1", + "typescript": "^4.8.4" }, "engines": { "node": ">=14" diff --git a/test/scripts/context.js b/test/scripts/context.js index 449110af..422e8fd2 100644 --- a/test/scripts/context.js +++ b/test/scripts/context.js @@ -5,7 +5,7 @@ const should = require('chai').should(); const sinon = require('sinon'); describe('context', () => { - const Context = require('../../lib/context'); + const Context = require('../../dist/context'); describe('call', () => { const hexo = new Context(); diff --git a/test/scripts/find_pkg.js b/test/scripts/find_pkg.js index 6d4f53a6..924f67a9 100644 --- a/test/scripts/find_pkg.js +++ b/test/scripts/find_pkg.js @@ -5,7 +5,7 @@ const { rmdir, writeFile, unlink } = require('hexo-fs'); const { dirname, join } = require('path'); describe('Find package', () => { - const findPkg = require('../../lib/find_pkg'); + const findPkg = require('../../dist/find_pkg'); const baseDir = join(__dirname, 'find_pkg_test'); after(async () => await rmdir(baseDir)); diff --git a/test/scripts/help.js b/test/scripts/help.js index 53835991..893eee55 100644 --- a/test/scripts/help.js +++ b/test/scripts/help.js @@ -1,7 +1,7 @@ 'use strict'; require('chai').should(); -const Context = require('../../lib/context'); +const Context = require('../../dist/context'); const sinon = require('sinon'); const { readFile } = require('hexo-fs'); const { join } = require('path'); @@ -13,10 +13,10 @@ function getConsoleLog({ args }) { } describe('help', () => { - const helpModule = rewire('../../lib/console/help'); + const helpModule = rewire('../../dist/console/help'); const hexo = new Context(); - require('../../lib/console')(hexo); + require('../../dist/console')(hexo); it('show global help', () => { const spy = sinon.spy(); diff --git a/test/scripts/hexo.js b/test/scripts/hexo.js index f454e979..8f299a7b 100644 --- a/test/scripts/hexo.js +++ b/test/scripts/hexo.js @@ -9,7 +9,7 @@ describe('hexo', () => { it('run help if no specified command', async () => { const spy = sinon.spy(); - const hexo = proxyquire('../../lib/hexo', { + const hexo = proxyquire('../../dist/hexo', { './console'(ctx) { ctx.extend.console.register('help', spy); } @@ -21,7 +21,7 @@ describe('hexo', () => { it('run specified command', async () => { const spy = sinon.spy(); - const hexo = proxyquire('../../lib/hexo', { + const hexo = proxyquire('../../dist/hexo', { './console'(ctx) { ctx.extend.console.register('test', spy); } @@ -33,7 +33,7 @@ describe('hexo', () => { it('run help if specified command not found', async () => { const spy = sinon.spy(); - const hexo = proxyquire('../../lib/hexo', { + const hexo = proxyquire('../../dist/hexo', { './console'(ctx) { ctx.extend.console.register('help', spy); } diff --git a/test/scripts/init.js b/test/scripts/init.js index 574cfb6d..923b6889 100644 --- a/test/scripts/init.js +++ b/test/scripts/init.js @@ -5,12 +5,12 @@ const { join } = require('path'); const { listDir, rmdir, createReadStream } = require('hexo-fs'); const { createSha1Hash } = require('hexo-util'); const rewire = require('rewire'); -const Context = require('../../lib/context'); +const Context = require('../../dist/context'); const assetDir = join(__dirname, '../../assets'); describe('init', () => { const baseDir = join(__dirname, 'init_test'); - const initModule = rewire('../../lib/console/init'); + const initModule = rewire('../../dist/console/init'); const hexo = new Context(baseDir, { silent: true }); const init = initModule.bind(hexo); let assets = []; diff --git a/test/scripts/version.js b/test/scripts/version.js index 2df42a26..4e9c0b3c 100644 --- a/test/scripts/version.js +++ b/test/scripts/version.js @@ -1,7 +1,7 @@ 'use strict'; require('chai').should(); -const Context = require('../../lib/context'); +const Context = require('../../dist/context'); const sinon = require('sinon'); const { platform, release } = require('os'); const { format } = require('util'); @@ -14,7 +14,7 @@ function getConsoleLog({ args }) { } describe('version', () => { - const versionModule = rewire('../../lib/console/version'); + const versionModule = rewire('../../dist/console/version'); const hexo = new Context(); it('show version info', () => { diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..cd227b8d --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "sourceMap": true, + "outDir": "dist", + "declaration": true, + "esModuleInterop": true, + "types": [ + "node" + ] + }, + "include": [ + "lib/hexo.ts" + ], + "exclude": [ + "node_modules" + ] +} \ No newline at end of file From 71cbf4e41623bd34cba7160c89ce4d8e7b94d120 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Tue, 1 Nov 2022 15:44:09 +0800 Subject: [PATCH 2/9] rename Bluebird --- .eslintignore | 3 ++- .eslintrc.json | 8 ++++++-- lib/console/init.ts | 6 +++--- lib/console/version.ts | 6 +++--- lib/context.ts | 4 +++- test/.eslintrc.json | 5 ++++- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.eslintignore b/.eslintignore index f3133c1e..383d0858 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,5 @@ node_modules/ coverage/ tmp/ -assets/ \ No newline at end of file +assets/ +dist/ \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index 91288aa9..6b545e66 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,4 +1,8 @@ { - "extends": "hexo", - "root": true + "root": true, + "extends": "hexo/ts.js", + "parserOptions": { + "sourceType": "module", + "ecmaVersion": 2020 + } } \ No newline at end of file diff --git a/lib/console/init.ts b/lib/console/init.ts index 67638db6..eecfb326 100644 --- a/lib/console/init.ts +++ b/lib/console/init.ts @@ -1,6 +1,6 @@ 'use strict'; -import BluebirdPromise from 'bluebird'; +import BlueBirdPromise from 'bluebird'; import {join, resolve} from 'path'; import {magenta} from 'picocolors'; import {existsSync, readdirSync, rmdir, unlink, copyDir, readdir, stat} from 'hexo-fs'; @@ -20,7 +20,7 @@ async function initConsole(args) { if (existsSync(target) && readdirSync(target).length !== 0) { log.fatal(`${magenta(tildify(target))} not empty, please run \`hexo init\` on an empty folder and then copy your files into it`); - await BluebirdPromise.reject(new Error('target not empty')); + await BlueBirdPromise.reject(new Error('target not empty')); } log.info('Cloning hexo-starter', GIT_REPO_URL); @@ -38,7 +38,7 @@ async function initConsole(args) { await copyAsset(target); } - await BluebirdPromise.all([ + await BlueBirdPromise.all([ removeGitDir(target), removeGitModules(target) ]); diff --git a/lib/console/version.ts b/lib/console/version.ts index b0681271..073e37d5 100644 --- a/lib/console/version.ts +++ b/lib/console/version.ts @@ -1,8 +1,8 @@ 'use strict'; import os from 'os'; -import pkg from '../../package.json'; -import BluebirdPromise from 'bluebird'; +const pkg =require('../../package.json'); +import BlueBirdPromise from 'bluebird'; import {spawn} from 'hexo-util'; async function versionConsole(args) { @@ -33,7 +33,7 @@ async function versionConsole(args) { console.log('%s: %s', key, versions[key]); } - await BluebirdPromise.resolve(); + await BlueBirdPromise.resolve(); } export = versionConsole; diff --git a/lib/context.ts b/lib/context.ts index 470390bb..6fad69f9 100644 --- a/lib/context.ts +++ b/lib/context.ts @@ -30,7 +30,9 @@ class Context extends EventEmitter { // Do nothing } - call(name: string, args: object | Function, callback?: Function) { + call(name: string, args: object, callback: Function); + call(name: string, args: Function); + call(name, args: object | Function, callback?: Function) { if (!callback && typeof args === 'function') { callback = args; args = {}; diff --git a/test/.eslintrc.json b/test/.eslintrc.json index 82825e53..852f0314 100644 --- a/test/.eslintrc.json +++ b/test/.eslintrc.json @@ -1,3 +1,6 @@ { - "extends": "hexo/test" + "extends": "hexo/test", + "rules": { + "@typescript-eslint/no-var-requires": 0 + } } \ No newline at end of file From adf2d819501e3cfb4ff52e28828ebd50af8b8f03 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Tue, 1 Nov 2022 15:48:57 +0800 Subject: [PATCH 3/9] eslint fix --- lib/console/help.ts | 2 -- lib/console/index.ts | 2 -- lib/console/init.ts | 2 -- lib/console/version.ts | 4 +--- lib/context.ts | 4 +--- lib/extend/console.ts | 2 -- lib/find_pkg.ts | 2 -- lib/goodbye.ts | 2 -- lib/hexo.ts | 3 --- 9 files changed, 2 insertions(+), 21 deletions(-) diff --git a/lib/console/help.ts b/lib/console/help.ts index c0e12c95..476b01fa 100644 --- a/lib/console/help.ts +++ b/lib/console/help.ts @@ -1,5 +1,3 @@ -'use strict'; - import {underline, bold} from 'picocolors'; import {readFile} from 'hexo-fs'; import {join} from 'path'; diff --git a/lib/console/index.ts b/lib/console/index.ts index e3f7f8ac..93262061 100644 --- a/lib/console/index.ts +++ b/lib/console/index.ts @@ -1,5 +1,3 @@ -'use strict'; - import helpConsole from './help'; import initConsole from './init'; import versionConsole from './version'; diff --git a/lib/console/init.ts b/lib/console/init.ts index eecfb326..97833c7f 100644 --- a/lib/console/init.ts +++ b/lib/console/init.ts @@ -1,5 +1,3 @@ -'use strict'; - import BlueBirdPromise from 'bluebird'; import {join, resolve} from 'path'; import {magenta} from 'picocolors'; diff --git a/lib/console/version.ts b/lib/console/version.ts index 073e37d5..ac1e8d7e 100644 --- a/lib/console/version.ts +++ b/lib/console/version.ts @@ -1,7 +1,5 @@ -'use strict'; - import os from 'os'; -const pkg =require('../../package.json'); +const pkg = require('../../package.json'); import BlueBirdPromise from 'bluebird'; import {spawn} from 'hexo-util'; diff --git a/lib/context.ts b/lib/context.ts index 6fad69f9..8167f95a 100644 --- a/lib/context.ts +++ b/lib/context.ts @@ -1,5 +1,3 @@ -'use strict'; - import logger from 'hexo-log'; import {underline} from 'picocolors'; import {EventEmitter} from 'events'; @@ -14,7 +12,7 @@ class Context extends EventEmitter { log: any; extend: { console: ConsoleExtend; - } + }; constructor(base = process.cwd(), args = {}) { super(); diff --git a/lib/extend/console.ts b/lib/extend/console.ts index 40b707a9..70b2c0f0 100644 --- a/lib/extend/console.ts +++ b/lib/extend/console.ts @@ -1,5 +1,3 @@ -'use strict'; - import Promise from 'bluebird'; import abbrev from 'abbrev'; diff --git a/lib/find_pkg.ts b/lib/find_pkg.ts index 97b8140c..d31f5b4c 100644 --- a/lib/find_pkg.ts +++ b/lib/find_pkg.ts @@ -1,5 +1,3 @@ -'use strict'; - import {resolve, join, dirname} from 'path'; import {readFile} from 'hexo-fs'; diff --git a/lib/goodbye.ts b/lib/goodbye.ts index 382c1bd4..f83a06fb 100644 --- a/lib/goodbye.ts +++ b/lib/goodbye.ts @@ -1,5 +1,3 @@ -'use strict'; - const byeWords = [ 'Good bye', 'See you again', diff --git a/lib/hexo.ts b/lib/hexo.ts index bbf71bc2..58485d52 100644 --- a/lib/hexo.ts +++ b/lib/hexo.ts @@ -1,5 +1,3 @@ -'use strict'; - import {magenta} from 'picocolors'; import tildify from 'tildify'; import Promise from 'bluebird'; @@ -9,7 +7,6 @@ import goodbye from './goodbye'; import minimist from 'minimist'; import resolve from 'resolve'; import { camelCaseKeys } from 'hexo-util'; - import Console from './console'; import helpConsole from './console/help'; import initConsole from './console/init'; From 38571ff58b2ae5f380c34141456da03bb18d8121 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Tue, 1 Nov 2022 19:00:53 +0800 Subject: [PATCH 4/9] update types --- .eslintrc.json | 3 ++ lib/console/version.ts | 2 +- lib/context.ts | 12 +++-- lib/extend/console.ts | 20 ++++++-- lib/find_pkg.ts | 2 +- lib/hexo.ts | 4 +- package-lock.json | 111 ++++++++++++++++++++++++++++++++--------- package.json | 1 + test/index.js | 2 +- test/scripts/init.js | 2 +- 10 files changed, 119 insertions(+), 40 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 6b545e66..7f9c5fa5 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,5 +4,8 @@ "parserOptions": { "sourceType": "module", "ecmaVersion": 2020 + }, + "rules": { + "@typescript-eslint/no-var-requires": 0 } } \ No newline at end of file diff --git a/lib/console/version.ts b/lib/console/version.ts index ac1e8d7e..16d993b7 100644 --- a/lib/console/version.ts +++ b/lib/console/version.ts @@ -3,7 +3,7 @@ const pkg = require('../../package.json'); import BlueBirdPromise from 'bluebird'; import {spawn} from 'hexo-util'; -async function versionConsole(args) { +async function versionConsole() { const { versions, platform } = process; const keys = Object.keys(versions); diff --git a/lib/context.ts b/lib/context.ts index 8167f95a..58597714 100644 --- a/lib/context.ts +++ b/lib/context.ts @@ -7,9 +7,11 @@ import ConsoleExtend from './extend/console'; // a stub Hexo object // see `hexojs/hexo/lib/hexo/index.js` +type Callback = (err?: any, value?: any) => void; + class Context extends EventEmitter { base_dir: string; - log: any; + log: logger; extend: { console: ConsoleExtend; }; @@ -28,11 +30,11 @@ class Context extends EventEmitter { // Do nothing } - call(name: string, args: object, callback: Function); - call(name: string, args: Function); - call(name, args: object | Function, callback?: Function) { + call(name: string, args: object, callback: Callback); + call(name: string, callback?: Callback); + call(name: string, args?: object | Callback, callback?: Callback) { if (!callback && typeof args === 'function') { - callback = args; + callback = args as Callback; args = {}; } diff --git a/lib/extend/console.ts b/lib/extend/console.ts index 70b2c0f0..45ad2bba 100644 --- a/lib/extend/console.ts +++ b/lib/extend/console.ts @@ -1,8 +1,14 @@ import Promise from 'bluebird'; import abbrev from 'abbrev'; +interface Callback { + (args?: object): any; + options?: object; + desc?: string; +} + interface Store { - [key: string]: Function; + [key: string]: Callback; } interface Alias { @@ -27,13 +33,17 @@ class Console { return this.store; } - register(name, desc, options, fn) { + register(name: string, desc: string, options: object, fn: Callback); + register(name: string, options: object, fn: Callback); + register(name: string, desc: string, fn: Callback); + register(name: string, fn: Callback); + register(name: string, desc: string | object | Callback, options?: object | Callback, fn?: Callback) { if (!name) throw new TypeError('name is required'); if (!fn) { if (options) { if (typeof options === 'function') { - fn = options; + fn = options as Callback; if (typeof desc === 'object') { // name, options, fn options = desc; @@ -47,7 +57,7 @@ class Console { } else { // name, fn if (typeof desc === 'function') { - fn = desc; + fn = desc as Callback; options = {}; desc = ''; } else { @@ -65,7 +75,7 @@ class Console { this.store[name.toLowerCase()] = fn; const c = fn; c.options = options; - c.desc = desc; + c.desc = desc as string; this.alias = abbrev(Object.keys(this.store)); } diff --git a/lib/find_pkg.ts b/lib/find_pkg.ts index d31f5b4c..5ffa8aa6 100644 --- a/lib/find_pkg.ts +++ b/lib/find_pkg.ts @@ -17,7 +17,7 @@ function checkPkg(path) { const pkgPath = join(path, 'package.json'); return readFile(pkgPath).then(content => { - const json = JSON.parse(content); + const json = JSON.parse(content as string); if (typeof json.hexo === 'object') return path; }).catch(err => { if (err && err.code === 'ENOENT') { diff --git a/lib/hexo.ts b/lib/hexo.ts index 58485d52..1acbfe0c 100644 --- a/lib/hexo.ts +++ b/lib/hexo.ts @@ -7,7 +7,7 @@ import goodbye from './goodbye'; import minimist from 'minimist'; import resolve from 'resolve'; import { camelCaseKeys } from 'hexo-util'; -import Console from './console'; +import registerConsole from './console'; import helpConsole from './console/help'; import initConsole from './console/init'; import versionConsole from './console/version'; @@ -46,7 +46,7 @@ function entry(cwd = process.cwd(), args) { if (mod) hexo = mod; log = hexo.log; - Console(hexo); + registerConsole(hexo); return hexo.init(); }).then(() => { diff --git a/package-lock.json b/package-lock.json index a169d31b..1a6757b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "hexo": "bin/hexo" }, "devDependencies": { + "@types/bluebird": "^3.5.37", "@types/node": "^18.11.8", "@typescript-eslint/eslint-plugin": "^5.41.0", "@typescript-eslint/parser": "^5.41.0", @@ -604,6 +605,12 @@ "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==", "dev": true }, + "node_modules/@types/bluebird": { + "version": "3.5.37", + "resolved": "https://registry.npmjs.org/@types/bluebird/-/bluebird-3.5.37.tgz", + "integrity": "sha512-g2qEd+zkfkTEudA2SrMAeAvY7CrFqtbsLILm2dT2VIeKTqMqVzcdfURlvu6FU3srRgbmXN1Srm94pg34EIehww==", + "dev": true + }, "node_modules/@types/json-schema": { "version": "7.0.11", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz", @@ -669,6 +676,21 @@ "node": ">=10" } }, + "node_modules/@typescript-eslint/eslint-plugin/node_modules/tsutils": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", + "dev": true, + "dependencies": { + "tslib": "^1.8.1" + }, + "engines": { + "node": ">= 6" + }, + "peerDependencies": { + "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" + } + }, "node_modules/@typescript-eslint/parser": { "version": "5.41.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.41.0.tgz", @@ -740,6 +762,21 @@ } } }, + "node_modules/@typescript-eslint/type-utils/node_modules/tsutils": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", + "dev": true, + "dependencies": { + "tslib": "^1.8.1" + }, + "engines": { + "node": ">= 6" + }, + "peerDependencies": { + "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" + } + }, "node_modules/@typescript-eslint/types": { "version": "5.41.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.41.0.tgz", @@ -795,6 +832,21 @@ "node": ">=10" } }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/tsutils": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", + "dev": true, + "dependencies": { + "tslib": "^1.8.1" + }, + "engines": { + "node": ">= 6" + }, + "peerDependencies": { + "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" + } + }, "node_modules/@typescript-eslint/utils": { "version": "5.41.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.41.0.tgz", @@ -4808,21 +4860,6 @@ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", "dev": true }, - "node_modules/tsutils": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", - "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", - "dev": true, - "dependencies": { - "tslib": "^1.8.1" - }, - "engines": { - "node": ">= 6" - }, - "peerDependencies": { - "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" - } - }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -5662,6 +5699,12 @@ "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==", "dev": true }, + "@types/bluebird": { + "version": "3.5.37", + "resolved": "https://registry.npmjs.org/@types/bluebird/-/bluebird-3.5.37.tgz", + "integrity": "sha512-g2qEd+zkfkTEudA2SrMAeAvY7CrFqtbsLILm2dT2VIeKTqMqVzcdfURlvu6FU3srRgbmXN1Srm94pg34EIehww==", + "dev": true + }, "@types/json-schema": { "version": "7.0.11", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz", @@ -5704,6 +5747,15 @@ "requires": { "lru-cache": "^6.0.0" } + }, + "tsutils": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } } } }, @@ -5739,6 +5791,17 @@ "@typescript-eslint/utils": "5.41.0", "debug": "^4.3.4", "tsutils": "^3.21.0" + }, + "dependencies": { + "tsutils": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } + } } }, "@typescript-eslint/types": { @@ -5770,6 +5833,15 @@ "requires": { "lru-cache": "^6.0.0" } + }, + "tsutils": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } } } }, @@ -8789,15 +8861,6 @@ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", "dev": true }, - "tsutils": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", - "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", - "dev": true, - "requires": { - "tslib": "^1.8.1" - } - }, "type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", diff --git a/package.json b/package.json index dd93f918..ccf3da2f 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "tildify": "^2.0.0" }, "devDependencies": { + "@types/bluebird": "^3.5.37", "@types/node": "^18.11.8", "@typescript-eslint/eslint-plugin": "^5.41.0", "@typescript-eslint/parser": "^5.41.0", diff --git a/test/index.js b/test/index.js index 675d4dd9..e658050c 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,6 @@ 'use strict'; -const chai = require('chai'); +require('chai'); describe('hexo-cli', () => { require('./scripts/find_pkg'); diff --git a/test/scripts/init.js b/test/scripts/init.js index 923b6889..f13c739d 100644 --- a/test/scripts/init.js +++ b/test/scripts/init.js @@ -57,7 +57,7 @@ describe('init', () => { } function withoutSpawn(fn) { - return initModule.__with__('spawn', () => Promise.reject(new Error('spawn is not available')))(fn); + return initModule.__with__('hexo_util_1.spawn', () => Promise.reject(new Error('spawn is not available')))(fn); } before(async () => { From bd3d467850953c4d071f2aed5c8ec67400240c7c Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Tue, 1 Nov 2022 19:12:30 +0800 Subject: [PATCH 5/9] prettify --- lib/console/help.ts | 6 +++--- lib/console/init.ts | 10 +++++----- lib/console/version.ts | 2 +- lib/context.ts | 4 ++-- lib/find_pkg.ts | 4 ++-- lib/hexo.ts | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/console/help.ts b/lib/console/help.ts index 476b01fa..1dd1ec3a 100644 --- a/lib/console/help.ts +++ b/lib/console/help.ts @@ -1,6 +1,6 @@ -import {underline, bold} from 'picocolors'; -import {readFile} from 'hexo-fs'; -import {join} from 'path'; +import { underline, bold } from 'picocolors'; +import { readFile } from 'hexo-fs'; +import { join } from 'path'; import Promise from 'bluebird'; const COMPLETION_DIR = join(__dirname, '../../completion'); diff --git a/lib/console/init.ts b/lib/console/init.ts index 97833c7f..1096094a 100644 --- a/lib/console/init.ts +++ b/lib/console/init.ts @@ -1,10 +1,10 @@ import BlueBirdPromise from 'bluebird'; -import {join, resolve} from 'path'; -import {magenta} from 'picocolors'; -import {existsSync, readdirSync, rmdir, unlink, copyDir, readdir, stat} from 'hexo-fs'; +import { join, resolve } from 'path'; +import { magenta } from 'picocolors'; +import { existsSync, readdirSync, rmdir, unlink, copyDir, readdir, stat } from 'hexo-fs'; import tildify from 'tildify'; -import {spawn} from 'hexo-util'; -import {sync as commandExistsSync} from 'command-exists'; +import { spawn } from 'hexo-util'; +import { sync as commandExistsSync } from 'command-exists'; const ASSET_DIR = join(__dirname, '../../assets'); const GIT_REPO_URL = 'https://github.com/hexojs/hexo-starter.git'; diff --git a/lib/console/version.ts b/lib/console/version.ts index 16d993b7..0a989da8 100644 --- a/lib/console/version.ts +++ b/lib/console/version.ts @@ -1,7 +1,7 @@ import os from 'os'; const pkg = require('../../package.json'); import BlueBirdPromise from 'bluebird'; -import {spawn} from 'hexo-util'; +import { spawn } from 'hexo-util'; async function versionConsole() { const { versions, platform } = process; diff --git a/lib/context.ts b/lib/context.ts index 58597714..f426553a 100644 --- a/lib/context.ts +++ b/lib/context.ts @@ -1,6 +1,6 @@ import logger from 'hexo-log'; -import {underline} from 'picocolors'; -import {EventEmitter} from 'events'; +import { underline } from 'picocolors'; +import { EventEmitter } from 'events'; import Promise from 'bluebird'; import ConsoleExtend from './extend/console'; diff --git a/lib/find_pkg.ts b/lib/find_pkg.ts index 5ffa8aa6..93b0559c 100644 --- a/lib/find_pkg.ts +++ b/lib/find_pkg.ts @@ -1,5 +1,5 @@ -import {resolve, join, dirname} from 'path'; -import {readFile} from 'hexo-fs'; +import { resolve, join, dirname } from 'path'; +import { readFile } from 'hexo-fs'; interface findPkgArgs { cwd?: string; diff --git a/lib/hexo.ts b/lib/hexo.ts index 1acbfe0c..7da97643 100644 --- a/lib/hexo.ts +++ b/lib/hexo.ts @@ -1,4 +1,4 @@ -import {magenta} from 'picocolors'; +import { magenta } from 'picocolors'; import tildify from 'tildify'; import Promise from 'bluebird'; import Context from './context'; From c4ea9989f3041995caac5f1d64625836185e614b Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Tue, 1 Nov 2022 19:46:29 +0800 Subject: [PATCH 6/9] feat: more type annotations --- lib/extend/console.ts | 8 ++++---- lib/find_pkg.ts | 4 ++-- lib/hexo.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/extend/console.ts b/lib/extend/console.ts index 45ad2bba..b5452dd8 100644 --- a/lib/extend/console.ts +++ b/lib/extend/console.ts @@ -33,10 +33,10 @@ class Console { return this.store; } - register(name: string, desc: string, options: object, fn: Callback); - register(name: string, options: object, fn: Callback); - register(name: string, desc: string, fn: Callback); - register(name: string, fn: Callback); + register(name: string, desc: string, options: object, fn: Callback): void; + register(name: string, options: object, fn: Callback): void; + register(name: string, desc: string, fn: Callback): void; + register(name: string, fn: Callback): void; register(name: string, desc: string | object | Callback, options?: object | Callback, fn?: Callback) { if (!name) throw new TypeError('name is required'); diff --git a/lib/find_pkg.ts b/lib/find_pkg.ts index 93b0559c..09740b72 100644 --- a/lib/find_pkg.ts +++ b/lib/find_pkg.ts @@ -5,7 +5,7 @@ interface findPkgArgs { cwd?: string; } -function findPkg(cwd, args: findPkgArgs = {}) { +function findPkg(cwd: string, args: findPkgArgs = {}) { if (args.cwd) { cwd = resolve(cwd, args.cwd); } @@ -13,7 +13,7 @@ function findPkg(cwd, args: findPkgArgs = {}) { return checkPkg(cwd); } -function checkPkg(path) { +function checkPkg(path: string) { const pkgPath = join(path, 'package.json'); return readFile(pkgPath).then(content => { diff --git a/lib/hexo.ts b/lib/hexo.ts index 7da97643..a88d33bf 100644 --- a/lib/hexo.ts +++ b/lib/hexo.ts @@ -72,7 +72,7 @@ entry.console = { version: versionConsole }; -entry.version = require('../package.json').version; +entry.version = require('../package.json').version as string; function loadModule(path, args) { return Promise.try(() => { From 3d3b67aa14b2994f42e80f7230b56de3650d8129 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Sat, 5 Nov 2022 23:31:40 +0800 Subject: [PATCH 7/9] bump hexo-fs --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1a6757b2..88dcc1da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "abbrev": "^1.1.1", "bluebird": "^3.7.2", "command-exists": "^1.2.9", - "hexo-fs": "^4.0.0", + "hexo-fs": "^4.1.1", "hexo-log": "^3.0.0", "hexo-util": "^2.5.0", "minimist": "^1.2.5", @@ -2627,9 +2627,9 @@ } }, "node_modules/hexo-fs": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/hexo-fs/-/hexo-fs-4.0.0.tgz", - "integrity": "sha512-nyFouUzoxabGraHzDGoF90sq+KDlZV94nUQarfVxwxBdI7x3LVeb9Y3r+HKYyxUyo2HtrJUILJh3UM0qzdBq9A==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/hexo-fs/-/hexo-fs-4.1.1.tgz", + "integrity": "sha512-aDysNTyv8ElcerbFVbPLRXnYt+QDY6gAOZZ5DLbCxudY0Ywppqd+uZ03gZ2BDypIBvmNB27WYWYz76M+Yv/YXw==", "dependencies": { "bluebird": "^3.7.2", "chokidar": "^3.5.3", @@ -7170,9 +7170,9 @@ "dev": true }, "hexo-fs": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/hexo-fs/-/hexo-fs-4.0.0.tgz", - "integrity": "sha512-nyFouUzoxabGraHzDGoF90sq+KDlZV94nUQarfVxwxBdI7x3LVeb9Y3r+HKYyxUyo2HtrJUILJh3UM0qzdBq9A==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/hexo-fs/-/hexo-fs-4.1.1.tgz", + "integrity": "sha512-aDysNTyv8ElcerbFVbPLRXnYt+QDY6gAOZZ5DLbCxudY0Ywppqd+uZ03gZ2BDypIBvmNB27WYWYz76M+Yv/YXw==", "requires": { "bluebird": "^3.7.2", "chokidar": "^3.5.3", diff --git a/package.json b/package.json index ccf3da2f..1bad2678 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "abbrev": "^1.1.1", "bluebird": "^3.7.2", "command-exists": "^1.2.9", - "hexo-fs": "^4.0.0", + "hexo-fs": "^4.1.1", "hexo-log": "^3.0.0", "hexo-util": "^2.5.0", "minimist": "^1.2.5", From e67418fd100b24d3cad325acd896757525d12d42 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Sat, 5 Nov 2022 23:54:23 +0800 Subject: [PATCH 8/9] set hexo.d.ts --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 98a6388c..1a16ad9d 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "bin", "assets" ], - "types": "./dist/**/*.d.ts", + "types": "./dist/hexo.d.ts", "scripts": { "prepublish ": "npm run clean && npm run build", "build": "tsc -b", From cff8ea6cbcf5694d9c13c6e482f78b2ae69fc4a0 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Wed, 9 Nov 2022 21:38:39 +0800 Subject: [PATCH 9/9] update package.json Co-authored-by: yoshinorin --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1a16ad9d..3a42708c 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ ], "types": "./dist/hexo.d.ts", "scripts": { - "prepublish ": "npm run clean && npm run build", + "prepublish ": "npm install && npm run clean && npm run build", "build": "tsc -b", "clean": "tsc -b --clean", "eslint": "eslint .",