From bb5a9fd392506d8f57085a7e3974dae0dddb6bfd Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Fri, 2 Jul 2021 22:55:14 +0800 Subject: [PATCH] refactor: add @ path alias --- packages/core/package.json | 4 ++++ packages/core/src/database/pool.ts | 2 +- packages/core/src/index.ts | 2 ++ packages/core/src/init/oidc.ts | 8 ++++---- packages/core/src/init/router.ts | 4 ++-- packages/core/src/oidc/adapter.ts | 6 +++--- packages/core/src/queries/user.ts | 4 ++-- packages/core/tsconfig.json | 6 +++++- packages/core/yarn.lock | 5 +++++ 9 files changed, 28 insertions(+), 13 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 85b930bbf..4c5721ac5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -21,6 +21,7 @@ "koa-logger": "^3.2.1", "koa-mount": "^4.0.0", "koa-router": "^10.0.0", + "module-alias": "^2.2.2", "oidc-provider": "^7.4.1", "slonik": "^23.8.1", "slonik-interceptor-preset": "^1.2.10" @@ -42,5 +43,8 @@ "node": "14", "yarn": "1" }, + "_moduleAliases": { + "@": "./build" + }, "prettier": "@logto/essentials/.prettierrc.json" } diff --git a/packages/core/src/database/pool.ts b/packages/core/src/database/pool.ts index c89bb3b76..09d3f3e82 100644 --- a/packages/core/src/database/pool.ts +++ b/packages/core/src/database/pool.ts @@ -1,6 +1,6 @@ import { createPool } from 'slonik'; import { createInterceptors } from 'slonik-interceptor-preset'; -import { getEnv } from '../utils'; +import { getEnv } from '@/utils'; const interceptors = [...createInterceptors()]; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 49834774a..304e09120 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,3 +1,5 @@ +import 'module-alias/register'; + import dotenv from 'dotenv'; dotenv.config(); diff --git a/packages/core/src/init/oidc.ts b/packages/core/src/init/oidc.ts index 17d28f570..a8195aacc 100644 --- a/packages/core/src/init/oidc.ts +++ b/packages/core/src/init/oidc.ts @@ -2,12 +2,12 @@ import crypto from 'crypto'; import Koa from 'koa'; import mount from 'koa-mount'; import { Provider } from 'oidc-provider'; -import postgresAdapter from '../oidc/adapter'; +import postgresAdapter from '@/oidc/adapter'; import { fromKeyLike } from 'jose/jwk/from_key_like'; -import { getEnv } from '../utils'; -import { findUserById } from '../queries/user'; -import { signInRoute } from '../consts'; +import { getEnv } from '@/utils'; +import { findUserById } from '@/queries/user'; +import { signInRoute } from '@/consts'; export default async function initOidc(app: Koa, port: number): Promise { const privateKey = crypto.createPrivateKey( diff --git a/packages/core/src/init/router.ts b/packages/core/src/init/router.ts index f8d722d6e..fbe8a995d 100644 --- a/packages/core/src/init/router.ts +++ b/packages/core/src/init/router.ts @@ -3,8 +3,8 @@ import Koa from 'koa'; import Router from 'koa-router'; import { promisify } from 'util'; import stream from 'stream'; -import { signInRoute } from '../consts'; -import { getEnv } from '../utils'; +import { signInRoute } from '@/consts'; +import { getEnv } from '@/utils'; const pipeline = promisify(stream.pipeline); const router = new Router(); diff --git a/packages/core/src/oidc/adapter.ts b/packages/core/src/oidc/adapter.ts index c9987d267..f41d439fd 100644 --- a/packages/core/src/oidc/adapter.ts +++ b/packages/core/src/oidc/adapter.ts @@ -2,9 +2,9 @@ import dayjs from 'dayjs'; import { AdapterFactory } from 'oidc-provider'; import { IdentifierSqlTokenType, sql, ValueExpressionType } from 'slonik'; import { OidcModelInstances, OidcModelInstanceDBEntry } from '@logto/schemas'; -import pool from '../database/pool'; -import { convertToIdentifiers } from '../database/utils'; -import { conditional } from '../utils'; +import pool from '@/database/pool'; +import { convertToIdentifiers } from '@/database/utils'; +import { conditional } from '@/utils'; export default function postgresAdapter(modelName: string) { const { table, fields } = convertToIdentifiers(OidcModelInstances); diff --git a/packages/core/src/queries/user.ts b/packages/core/src/queries/user.ts index 19a9b8eed..61e3f5cb1 100644 --- a/packages/core/src/queries/user.ts +++ b/packages/core/src/queries/user.ts @@ -1,7 +1,7 @@ import { UserDBEntry, Users } from '@logto/schemas'; import { sql } from 'slonik'; -import pool from '../database/pool'; -import { convertToIdentifiers } from '../database/utils'; +import pool from '@/database/pool'; +import { convertToIdentifiers } from '@/database/utils'; const { table, fields } = convertToIdentifiers(Users); diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index 5d40dd9b3..4e6bcd963 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -1,7 +1,11 @@ { "extends": "@logto/essentials/tsconfig.base", "compilerOptions": { - "outDir": "build" + "outDir": "build", + "baseUrl": ".", + "paths": { + "@/*": ["src/*"] + } }, "include": ["src"] } diff --git a/packages/core/yarn.lock b/packages/core/yarn.lock index f6cd55cd8..97ed8d583 100644 --- a/packages/core/yarn.lock +++ b/packages/core/yarn.lock @@ -3759,6 +3759,11 @@ mixin-deep@^1.2.0: for-in "^1.0.2" is-extendable "^1.0.1" +module-alias@^2.2.2: + version "2.2.2" + resolved "https://registry.yarnpkg.com/module-alias/-/module-alias-2.2.2.tgz#151cdcecc24e25739ff0aa6e51e1c5716974c0e0" + integrity sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q== + ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"