diff --git a/.eslintrc b/.eslintrc index 7e43db39c..1c0ef1df9 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,10 +5,9 @@ }, "overrides": [ { - "files": "*.ts", + "files": ["*.ts", "*.mts"], "extends": ["plugin:prettier/recommended"], "rules": { - "sort-imports": ["error", { "ignoreCase": true }], "@typescript-eslint/ban-ts-comment": "warn", "@typescript-eslint/explicit-function-return-type": "off", "@typescript-eslint/no-explicit-any": "warn", diff --git a/bin/tsconfig.json b/bin/tsconfig.json deleted file mode 100644 index cf3f0c853..000000000 --- a/bin/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "compilerOptions": { - "module": "NodeNext", - "rootDir": ".", - "target": "ESNext", - "strict": true, - "noUncheckedIndexedAccess": true, - "noErrorTruncation": true - }, - "include": ["telegraf.mts"] -} diff --git a/package-lock.json b/package-lock.json index 49f00458c..2aaaf3c16 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,19 +1,17 @@ { "name": "telegraf", - "version": "4.8.5", + "version": "4.9.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "telegraf", - "version": "4.8.5", + "version": "4.9.0", "license": "MIT", "dependencies": { "abort-controller": "^3.0.0", "debug": "^4.3.3", - "es-main": "^1.2.0", - "minimist": "^1.2.6", - "module-alias": "^2.2.2", + "mri": "^1.2.0", "node-fetch": "^2.6.7", "p-timeout": "^4.1.0", "safe-compare": "^1.1.4", @@ -21,12 +19,10 @@ "typegram": "github:MKRhere/typegram#e2ba9f01f14b96c6dbb1c617e66692a3cc776cf6" }, "bin": { - "telegraf": "bin/telegraf.mjs" + "telegraf": "lib/cli.mjs" }, "devDependencies": { "@types/debug": "^4.1.7", - "@types/minimist": "^1.2.2", - "@types/module-alias": "^2.0.1", "@types/node": "^17.0.14", "@types/node-fetch": "^2.5.12", "@types/safe-compare": "^1.1.0", @@ -40,7 +36,6 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^4.0.0", "eslint-plugin-promise": "^6.0.0", - "eslint-plugin-standard": "^5.0.0", "prettier": "^2.5.1", "typedoc": "^0.23.10", "typescript": "^4.7.4" @@ -172,18 +167,6 @@ "integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=", "dev": true }, - "node_modules/@types/minimist": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.2.tgz", - "integrity": "sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==", - "dev": true - }, - "node_modules/@types/module-alias": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@types/module-alias/-/module-alias-2.0.1.tgz", - "integrity": "sha512-DN/CCT1HQG6HquBNJdLkvV+4v5l/oEuwOHUPLxI+Eub0NED+lk0YUfba04WGH90EINiUrNgClkNnwGmbICeWMQ==", - "dev": true - }, "node_modules/@types/ms": { "version": "0.7.31", "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz", @@ -1380,11 +1363,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/es-main": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/es-main/-/es-main-1.2.0.tgz", - "integrity": "sha512-A4tCSY43O/mH4rHjG1n0mI4DhK2BmKDr8Lk8PXK/GBB6zxGFGmIW4bbkbTQ2Gi9iNamMZ9vbGrwjZOIeiM7vMw==" - }, "node_modules/es-to-primitive": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", @@ -1779,30 +1757,6 @@ "eslint": "^7.0.0 || ^8.0.0" } }, - "node_modules/eslint-plugin-standard": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-standard/-/eslint-plugin-standard-5.0.0.tgz", - "integrity": "sha512-eSIXPc9wBM4BrniMzJRBm2uoVuXz2EPa+NXPk2+itrVt+r5SbKFERx/IgrK/HmfjddyKVz2f+j+7gBRvu19xLg==", - "deprecated": "standard 16.0.0 and eslint-config-standard 16.0.0 no longer require the eslint-plugin-standard package. You can remove it from your dependencies with 'npm rm eslint-plugin-standard'. More info here: https://github.com/standard/standard/issues/1316", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "peerDependencies": { - "eslint": ">=5.0.0" - } - }, "node_modules/eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -3041,12 +2995,16 @@ "node_modules/minimist": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", - "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", + "dev": true }, - "node_modules/module-alias": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/module-alias/-/module-alias-2.2.2.tgz", - "integrity": "sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q==" + "node_modules/mri": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz", + "integrity": "sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==", + "engines": { + "node": ">=4" + } }, "node_modules/ms": { "version": "2.1.2", @@ -4371,18 +4329,6 @@ "integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=", "dev": true }, - "@types/minimist": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.2.tgz", - "integrity": "sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==", - "dev": true - }, - "@types/module-alias": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@types/module-alias/-/module-alias-2.0.1.tgz", - "integrity": "sha512-DN/CCT1HQG6HquBNJdLkvV+4v5l/oEuwOHUPLxI+Eub0NED+lk0YUfba04WGH90EINiUrNgClkNnwGmbICeWMQ==", - "dev": true - }, "@types/ms": { "version": "0.7.31", "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz", @@ -5226,11 +5172,6 @@ "unbox-primitive": "^1.0.1" } }, - "es-main": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/es-main/-/es-main-1.2.0.tgz", - "integrity": "sha512-A4tCSY43O/mH4rHjG1n0mI4DhK2BmKDr8Lk8PXK/GBB6zxGFGmIW4bbkbTQ2Gi9iNamMZ9vbGrwjZOIeiM7vMw==" - }, "es-to-primitive": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", @@ -5580,13 +5521,6 @@ "dev": true, "requires": {} }, - "eslint-plugin-standard": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-standard/-/eslint-plugin-standard-5.0.0.tgz", - "integrity": "sha512-eSIXPc9wBM4BrniMzJRBm2uoVuXz2EPa+NXPk2+itrVt+r5SbKFERx/IgrK/HmfjddyKVz2f+j+7gBRvu19xLg==", - "dev": true, - "requires": {} - }, "eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -6420,12 +6354,13 @@ "minimist": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", - "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", + "dev": true }, - "module-alias": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/module-alias/-/module-alias-2.2.2.tgz", - "integrity": "sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q==" + "mri": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz", + "integrity": "sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==" }, "ms": { "version": "2.1.2", diff --git a/package.json b/package.json index 802ffac9f..b66980462 100644 --- a/package.json +++ b/package.json @@ -40,11 +40,11 @@ "future.*" ], "bin": { - "telegraf": "bin/telegraf.mjs" + "telegraf": "lib/cli.mjs" }, "scripts": { "prepare": "npm run --silent build", - "build": "tsc && tsc -p bin/tsconfig.json", + "build": "tsc", "build:docs": "typedoc src/index.ts", "pretest": "npm run build", "test": "ava test/*", @@ -61,9 +61,7 @@ "dependencies": { "abort-controller": "^3.0.0", "debug": "^4.3.3", - "es-main": "^1.2.0", - "minimist": "^1.2.6", - "module-alias": "^2.2.2", + "mri": "^1.2.0", "node-fetch": "^2.6.7", "p-timeout": "^4.1.0", "safe-compare": "^1.1.4", @@ -72,8 +70,6 @@ }, "devDependencies": { "@types/debug": "^4.1.7", - "@types/minimist": "^1.2.2", - "@types/module-alias": "^2.0.1", "@types/node": "^17.0.14", "@types/node-fetch": "^2.5.12", "@types/safe-compare": "^1.1.0", @@ -87,7 +83,6 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^4.0.0", "eslint-plugin-promise": "^6.0.0", - "eslint-plugin-standard": "^5.0.0", "prettier": "^2.5.1", "typedoc": "^0.23.10", "typescript": "^4.7.4" diff --git a/bin/telegraf.mts b/src/cli.mts similarity index 83% rename from bin/telegraf.mts rename to src/cli.mts index 45a974b50..8960c9eaa 100755 --- a/bin/telegraf.mts +++ b/src/cli.mts @@ -1,20 +1,13 @@ #!/usr/bin/env node +/* global console, process */ import debug from 'debug' +import parse from 'mri' import path from 'path' -import parse from 'minimist' -import { addAlias } from 'module-alias' -// @ts-expect-error Telegraf doesn't build JS and d.ts in the same place, that needs to be fixed -import { Telegraf as _Telegraf } from '../lib/index.js' -import type { Telegraf as Tf, Context, Middleware } from '../typings/index.js' import type { RequestListener } from 'http' import type { TlsOptions } from 'tls' - -import esMain from 'es-main' - -// hack to type Telegraf correctly -const Telegraf: typeof Tf = _Telegraf +import { Telegraf, type Context, type Middleware } from './index.js' const log = debug('telegraf:cli') @@ -121,6 +114,7 @@ export async function main(argv: string[], env: Env = {}) { path.resolve(process.cwd(), 'package.json') )) as { main?: string } file = packageJson.main || 'index.js' + // eslint-disable-next-line no-empty } catch (err) {} } @@ -149,13 +143,12 @@ export async function main(argv: string[], env: Env = {}) { try { if (args.logs) debug.enable('telegraf:*') - addAlias('telegraf', path.join(import.meta.url, '../')) const mod: Mod = await import(file) const botHandler = mod.botHandler || mod.default const httpHandler = mod.httpHandler const tlsOptions = mod.tlsOptions - const config: Tf.LaunchOptions = {} + const config: Telegraf.LaunchOptions = {} if (domain) { config.webhook = { domain, @@ -182,6 +175,4 @@ export async function main(argv: string[], env: Env = {}) { return 0 } -// run main if called from command line and not imported from another file -if (esMain(import.meta)) - process.exitCode = await main(process.argv, process.env as Env) +process.exitCode = await main(process.argv, process.env as Env) diff --git a/tsconfig.json b/tsconfig.json index 9ad6728a9..01fd5116d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,10 @@ { "compilerOptions": { - "module": "commonjs", + "module": "Node16", "declaration": true, "declarationMap": true, "declarationDir": "typings/", + "esModuleInterop": true, "outDir": "lib/", "rootDir": "src/", "target": "ES2019", @@ -24,5 +25,5 @@ "out": "docs/build/", "readme": "README.md" }, - "include": ["src/**/*.ts"] + "include": ["src/"] }