Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(paths): use TypeScript absolute paths #208

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from
11 changes: 11 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ parser: '@typescript-eslint/parser'
plugins:
- '@typescript-eslint'
- 'typescript-sort-keys'
- 'import'
- 'jest'
- 'prettier'
settings:
Expand All @@ -35,7 +36,17 @@ settings:
- .ts
import/cache:
lifetime: 'Infinity'
import/resolver:
- typescript:
- alwaysTryTypes: true
import/core-modules:
- lodash
- moment
- express
- app-root-path
rules:
import/no-unresolved:
- 'error'
jest/no-disabled-tests: 'off'
# Temporarily disabled due to code climate error (37259)
'@typescript-eslint/member-ordering':
Expand Down
12 changes: 8 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html
const { pathsToModuleNameMapper } = require(`ts-jest/utils`);
const { compilerOptions } = require(`./tsconfig`);

module.exports = {
// All imported modules in your tests should be mocked automatically
Expand Down Expand Up @@ -72,14 +74,16 @@ module.exports = {
// An array of directory names to be searched recursively up from the requiring module's location
moduleDirectories: [`./node_modules`],

// A map from regular expressions to module names that allow to stub out resources with a single module
// moduleNameMapper: {},
// An array of file extensions your modules use
moduleFileExtensions: [`js`, `json`, `ts`, `node`],

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],

// An array of file extensions your modules use
moduleFileExtensions: [`js`, `json`, `ts`, `node`],
// A map from regular expressions to module names that allow to stub out resources with a single module
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
prefix: `<rootDir>/`,
}),

// Activates notifications for test results
notify: true,
Expand Down
35 changes: 35 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"main": "./src/index.ts",
"scripts": {
"\n# BUILD SCRIPTS:": "",
"start": "ts-node-dev --respawn --transpileOnly .",
"start": "ts-node-dev -r tsconfig-paths/register --respawn --transpileOnly .",
"start:prod": "npm run build && npm run run:prod",
"build": "npm run clean:dist && concurrently \"parcel build ./src/index.ts --target node\" \"npm run build:environment:create\" && concurrently \"npm run build:environment:copy\" \"npm run build:environment:rewrite-path\" \"npm run build:update-app-initialization-date\"",
"build:environment:copy": "node scripts/build-environment-copy.js",
Expand Down Expand Up @@ -120,6 +120,7 @@
"eslint-config-google": "0.14.0",
"eslint-config-prettier": "6.10.1",
"eslint-config-recommended": "4.0.0",
"eslint-import-resolver-typescript": "2.0.0",
"eslint-plugin-import": "2.20.2",
"eslint-plugin-jest": "23.8.2",
"eslint-plugin-prettier": "3.1.2",
Expand Down
8 changes: 4 additions & 4 deletions src/classes/abstract-config-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ConfigService } from "../features/config/services/config-service";
import { ChalkService } from "../features/logger/services/chalk-service";
import { LoggerService } from "../features/logger/services/logger-service";
import { PartialNested } from "../types/partial-nested";
import { ConfigService } from "@app/features/config/services/config-service";
import { ChalkService } from "@app/features/logger/services/chalk-service";
import { LoggerService } from "@app/features/logger/services/logger-service";
import { PartialNested } from "@app/types/partial-nested";

export abstract class AbstractConfigService<C> {
protected abstract readonly _className: string;
Expand Down
4 changes: 2 additions & 2 deletions src/environment/constants/environment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LoggerConfigLevelEnum } from "../../features/logger/enums/logger-config-level.enum";
import { IEnvironment } from "../interfaces/environment";
import { IEnvironment } from "@app/environment/interfaces/environment";
import { LoggerConfigLevelEnum } from "@app/features/logger/enums/logger-config-level.enum";

export const ENVIRONMENT: IEnvironment = {
discord: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IEnvironmentDiscordMessageCommand } from "./environment-discord-message-command";
import { IEnvironmentDiscordMessageCommand } from "@app/environment/interfaces/environment-discord-message-command";

export interface IEnvironmentDiscordMessage {
command?: IEnvironmentDiscordMessageCommand;
Expand Down
4 changes: 2 additions & 2 deletions src/environment/interfaces/environment-discord.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IEnvironmentDiscordMessage } from "./environment-discord-message";
import { IEnvironmentDiscordSonia } from "./environment-discord-sonia";
import { IEnvironmentDiscordMessage } from "@app/environment/interfaces/environment-discord-message";
import { IEnvironmentDiscordSonia } from "@app/environment/interfaces/environment-discord-sonia";

export interface IEnvironmentDiscord {
message: IEnvironmentDiscordMessage;
Expand Down
4 changes: 2 additions & 2 deletions src/environment/interfaces/environment-logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LoggerConfigLevelEnum } from "../../features/logger/enums/logger-config-level.enum";
import { IEnvironmentProfile } from "./environment-profile";
import { IEnvironmentProfile } from "@app/environment/interfaces/environment-profile";
import { LoggerConfigLevelEnum } from "@app/features/logger/enums/logger-config-level.enum";

export interface IEnvironmentLogger {
isEnabled?: boolean;
Expand Down
10 changes: 5 additions & 5 deletions src/environment/interfaces/environment.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IEnvironmentApp } from "./environment-app";
import { IEnvironmentDiscord } from "./environment-discord";
import { IEnvironmentGithub } from "./environment-github";
import { IEnvironmentLogger } from "./environment-logger";
import { IEnvironmentProfile } from "./environment-profile";
import { IEnvironmentApp } from "@app/environment/interfaces/environment-app";
import { IEnvironmentDiscord } from "@app/environment/interfaces/environment-discord";
import { IEnvironmentGithub } from "@app/environment/interfaces/environment-github";
import { IEnvironmentLogger } from "@app/environment/interfaces/environment-logger";
import { IEnvironmentProfile } from "@app/environment/interfaces/environment-profile";

export interface IEnvironment {
app?: IEnvironmentApp;
Expand Down
2 changes: 1 addition & 1 deletion src/features/config/interfaces/config-update-boolean.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { IConfigUpdateValue } from "./config-update-value";
import { IConfigUpdateValue } from "@app/features/config/interfaces/config-update-value";

export type IConfigUpdateBoolean = IConfigUpdateValue<boolean>;
2 changes: 1 addition & 1 deletion src/features/config/interfaces/config-update-number.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { IConfigUpdateValue } from "./config-update-value";
import { IConfigUpdateValue } from "@app/features/config/interfaces/config-update-value";

export type IConfigUpdateNumber = IConfigUpdateValue<number>;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IConfigUpdateString } from "./config-update-string";
import { IConfigUpdateString } from "@app/features/config/interfaces/config-update-string";

export interface IConfigUpdateStringInternal<T = string>
extends IConfigUpdateString<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/features/config/interfaces/config-update-string.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IConfigUpdateValue } from "./config-update-value";
import { IConfigUpdateValue } from "@app/features/config/interfaces/config-update-value";

export interface IConfigUpdateString<T = string> extends IConfigUpdateValue<T> {
isValueDisplay?: boolean;
Expand Down
6 changes: 3 additions & 3 deletions src/features/init/services/init-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import appRootPath from "app-root-path";
import axios, { AxiosResponse } from "axios";
import fs from "fs-extra";
import { readJson } from "fs-extra";
import _ from "lodash";
import { ENVIRONMENT } from "../../../environment/constants/environment";
import { IEnvironment } from "../../../environment/interfaces/environment";
Expand Down Expand Up @@ -80,7 +80,7 @@ export class InitService {
}

private _configureAppFromPackage(): void {
fs.readJson(`${appRootPath}/package.json`)
readJson(`${appRootPath}/package.json`)
.then((data: Readonly<IPackage>): void => {
AppConfigMutatorService.getInstance().updateVersion(data.version);
})
Expand Down Expand Up @@ -131,7 +131,7 @@ export class InitService {
}

private _readEnvironment(): void {
fs.readJson(`${appRootPath}/src/environment/secret-environment.json`)
readJson(`${appRootPath}/src/environment/secret-environment.json`)
.then((environment: Readonly<IEnvironment>): void => {
this._startApp(this._mergeEnvironments(ENVIRONMENT, environment));
})
Expand Down
31 changes: 30 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,36 @@
"transform": "ts-auto-mock/transformer",
"cacheBetweenTests": false
}
]
],
"paths": {
"@app/classes/*": [
"src/classes/*"
],
"@app/environment/*": [
"src/environment/*"
],
"@app/features/*": [
"src/features/*"
],
"@app/functions/*": [
"src/functions/*"
],
"@app/interfaces/*": [
"src/interfaces/*"
],
"@app/types/*": [
"src/types/*"
],
"@app/views/*": [
"src/views/*"
],
"@app/index": [
"src/index.ts"
],
"@app/types": [
"src/types.d.ts"
]
}
},
"include": [
"./src/types.d.ts",
Expand Down