From a1eb10285030153728a78f0f408624598682bbba Mon Sep 17 00:00:00 2001 From: Daryl Ronningen Date: Fri, 18 Jun 2021 03:08:11 -0700 Subject: [PATCH] chore: added import aliases --- .husky/pre-commit | 3 ++- package.json | 9 ++++++++- src/index.ts | 6 ++++-- src/lib/utils/logger.ts | 2 +- tests/utils/logger.test.ts | 4 ++-- tsconfig.json | 17 ++++++++++++++++- yarn.lock | 31 +++++++++++++++++++++++++++++++ 7 files changed, 64 insertions(+), 8 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index dc0378c..59d409c 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,5 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -yarn lint-staged \ No newline at end of file +yarn lint-staged +yarn test \ No newline at end of file diff --git a/package.json b/package.json index 6f98807..409848b 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "release:full": "standard-version -s", "run:dev": "node dist/src/index.js --dev", "run:prod": "node dist/index.js", - "test": "mocha -r ts-node/register tests/**/*.test.ts", + "test": "mocha -r ts-node/register -r tsconfig-paths/register tests/**/*.test.ts", "watch:bot": "nodemon dist/src/index.js --dev", "watch:rollup": "tsc --watch", "watch:tsc": "tsc --watch" @@ -91,6 +91,7 @@ "sinon": "^11.1.1", "standard-version": "^9.3.0", "ts-node": "^10.0.0", + "tsconfig-paths": "^3.9.0", "typescript": "^4.3.3", "typescript-eslint-language-service": "^4.1.4" }, @@ -181,5 +182,11 @@ "section": "Bug Fixes" } ] + }, + "_moduleAliases": { + "@": "dist", + "@src": "dist/src", + "@lib": "dist/src/lib", + "@utils": "dist/src/lib/utils/" } } diff --git a/src/index.ts b/src/index.ts index 8ebc103..4cfe1d8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,11 +14,13 @@ * You should have received a copy of the GNU General Public License * along with ArgonBot. If not, see . */ +require('module-alias/register'); + import { Client } from 'discord.js'; import figlet from 'figlet'; import gradient from 'gradient-string'; -import { debug, error, info } from './lib/utils/logger'; -import { ELoggingScope } from './lib/utils/types'; +import { debug, error, info } from '@utils/logger'; +import { ELoggingScope } from '@utils/types'; //import { token } from '../config.json'; debug('Starting bot... Please wait!', ELoggingScope.Startup); diff --git a/src/lib/utils/logger.ts b/src/lib/utils/logger.ts index 213dd99..4da98a6 100644 --- a/src/lib/utils/logger.ts +++ b/src/lib/utils/logger.ts @@ -16,7 +16,7 @@ */ import chalk from 'chalk'; import { DateTime } from 'luxon'; -import { loglevel } from '../../../config.json'; +import { loglevel } from '@/config.json'; import type { ELoggingScope } from './types'; diff --git a/tests/utils/logger.test.ts b/tests/utils/logger.test.ts index eb93b2b..0ef0693 100644 --- a/tests/utils/logger.test.ts +++ b/tests/utils/logger.test.ts @@ -17,8 +17,8 @@ import { describe, it, beforeEach, afterEach } from 'mocha'; import { expect } from 'chai'; import * as sinon from 'sinon'; -import { verbose, debug, info, warn, error, fatal } from '../../src/lib/utils/logger'; -import { ELoggingScope } from '../../src/lib/utils/types'; +import { verbose, debug, info, warn, error, fatal } from '@utils/logger'; +import { ELoggingScope } from '@utils/types'; describe('verbose()', () => { let spy: sinon.SinonStub<[message?: any, ...optionalParams: any[]], void>; diff --git a/tsconfig.json b/tsconfig.json index 377dc43..2079a21 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -47,11 +47,26 @@ "preserveConstEnums": true, "resolveJsonModule": true, "traceResolution": false, + "baseUrl": ".", "plugins": [ { "name": "typescript-eslint-language-service" } - ] + ], + "paths": { + "@/*": [ + "*" + ], + "@/src": [ + "src/*" + ], + "@lib/*": [ + "src/lib/*" + ], + "@utils/*": [ + "src/lib/utils/*" + ] + } }, "watchOptions": { "watchFile": "useFsEvents", diff --git a/yarn.lock b/yarn.lock index 9ae62ed..2e2006b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -866,6 +866,13 @@ __metadata: languageName: node linkType: hard +"@types/json5@npm:^0.0.29": + version: 0.0.29 + resolution: "@types/json5@npm:0.0.29" + checksum: e60b153664572116dfea673c5bda7778dbff150498f44f998e34b5886d8afc47f16799280e4b6e241c0472aef1bc36add771c569c68fc5125fc2ae519a3eb9ac + languageName: node + linkType: hard + "@types/keyv@npm:*, @types/keyv@npm:^3.1.1": version: 3.1.1 resolution: "@types/keyv@npm:3.1.1" @@ -1577,6 +1584,7 @@ __metadata: standard-version: ^9.3.0 terminal-link: ^3.0.0 ts-node: ^10.0.0 + tsconfig-paths: ^3.9.0 tslib: ^2.3.0 typescript: ^4.3.3 typescript-eslint-language-service: ^4.1.4 @@ -4595,6 +4603,17 @@ __metadata: languageName: node linkType: hard +"json5@npm:^1.0.1": + version: 1.0.1 + resolution: "json5@npm:1.0.1" + dependencies: + minimist: ^1.2.0 + bin: + json5: lib/cli.js + checksum: e76ea23dbb8fc1348c143da628134a98adf4c5a4e8ea2adaa74a80c455fc2cdf0e2e13e6398ef819bfe92306b610ebb2002668ed9fc1af386d593691ef346fc3 + languageName: node + linkType: hard + "json5@npm:^2.1.1, json5@npm:^2.1.2": version: 2.2.0 resolution: "json5@npm:2.2.0" @@ -7463,6 +7482,18 @@ __metadata: languageName: node linkType: hard +"tsconfig-paths@npm:^3.9.0": + version: 3.9.0 + resolution: "tsconfig-paths@npm:3.9.0" + dependencies: + "@types/json5": ^0.0.29 + json5: ^1.0.1 + minimist: ^1.2.0 + strip-bom: ^3.0.0 + checksum: 243b3b098c76a4ca90ea0431683f3755a4ff175c6123bcba5f7b4bd80fe2ef8fa9bdc8f4d525148a1e71ade7f3e037e7c0313ae177fd12398ab68f05c2c7f25d + languageName: node + linkType: hard + "tslib@npm:^1.13.0, tslib@npm:^1.8.1, tslib@npm:^1.9.0": version: 1.14.1 resolution: "tslib@npm:1.14.1"