diff --git a/.eslintrc.js b/.eslintrc.js index acce3a24..fc979176 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -40,19 +40,8 @@ module.exports = defineConfig({ }, }, ], - 'node/no-missing-import': [ - 'error', - { - allowModules: ['types', 'estree', 'testUtils', 'less', 'sass', 'stylus'], - tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts'], - }, - ], - 'node/no-missing-require': [ - 'error', - { - tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts'], - }, - ], + 'node/no-missing-import': 'off', + 'node/no-missing-require': 'off', 'node/no-deprecated-api': 'off', 'node/no-unpublished-import': 'off', 'node/no-unpublished-require': 'off', diff --git a/.npmignore b/.npmignore index ee1b8e5e..d560a8fc 100644 --- a/.npmignore +++ b/.npmignore @@ -2,5 +2,7 @@ examples benchmark .github tsconfig.json +tsconfig.build.json src -docs \ No newline at end of file +docs +yarn.lock \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/docs/CODE_OF_CONDUCT.md similarity index 100% rename from CODE_OF_CONDUCT.md rename to docs/CODE_OF_CONDUCT.md diff --git a/jest.config.js b/jest.config.js index efc38fab..c30d843d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,6 +3,10 @@ module.exports = { transform: { '^.+\\.(ts|tsx)$': 'ts-jest', }, + modulePaths: ['/src'], + moduleNameMapper: { + '^@/(.*)$': '/src/$1', + }, testPathIgnorePatterns: ['./examples'], testEnvironment: 'miniflare', testEnvironmentOptions: { diff --git a/package.json b/package.json index 676a3418..0ee3a743 100644 --- a/package.json +++ b/package.json @@ -10,63 +10,61 @@ "scripts": { "test": "jest", "lint": "eslint --ext js,ts src .eslintrc.js && prettier --check src", - "build": "rimraf dist && tsc", - "watch": "tsc -w", + "build": "rimraf dist && tsc --project tsconfig.build.json && tsc-alias -p tsconfig.build.json", + "watch": "tsc -w --project tsconfig.build.json & tsc-alias -w -p tsconfig.build.json", "prepublishOnly": "yarn build" }, "exports": { ".": "./dist/index.js", - "./basic-auth": "./dist/middleware/basic-auth/basic-auth.js", - "./body-parse": "./dist/middleware/body-parse/body-parse.js", - "./cookie": "./dist/middleware/cookie/cookie.js", - "./cors": "./dist/middleware/cors/cors.js", - "./etag": "./dist/middleware/etag/etag.js", - "./graphql-server": "./dist/middleware/graphql-server/graphql-server.js", - "./logger": "./dist/middleware/logger/logger.js", - "./mustache": "./dist/middleware/mustache/mustache.js", - "./powered-by": "./dist/middleware/powered-by/powered-by.js", - "./pretty-json": "./dist/middleware/pretty-json/pretty-json.js", - "./serve-static": "./dist/middleware/serve-static/serve-static.js", - "./router/trie-router": "./dist/router/trie-router/router.js", - "./router/reg-exp-router": "./dist/router/reg-exp-router/index.js", - "./utils/cloudflare": "./dist/utils/cloudflare.js", - "./utils/crypto": "./dist/utils/crypto.js", - "./utils/mime": "./dist/utils/mime.js" + "./basic-auth": "./dist/middleware/basic-auth", + "./body-parse": "./dist/middleware/body-parse", + "./cookie": "./dist/middleware/cookie", + "./cors": "./dist/middleware/cors", + "./etag": "./dist/middleware/etag", + "./graphql-server": "./dist/middleware/graphql-server", + "./logger": "./dist/middleware/logger", + "./mustache": "./dist/middleware/mustache", + "./powered-by": "./dist/middleware/powered-by", + "./pretty-json": "./dist/middleware/pretty-json", + "./serve-static": "./dist/middleware/serve-static", + "./router/trie-router": "./dist/router/trie-router", + "./router/reg-exp-router": "./dist/router/reg-exp-router", + "./utils/*": "./dist/utils/*.js" }, "typesVersions": { "*": { "basic-auth": [ - "./dist/middleware/basic-auth/basic-auth.d.ts" + "./dist/middleware/basic-auth" ], "body-parse": [ - "./dist/middleware/body-parse/body-parse.d.ts" + "./dist/middleware/body-parse" ], "cookie": [ - "./dist/middleware/cookie/cookie.d.ts" + "./dist/middleware/cookie" ], "cors": [ - "./dist/middleware/cors/cors.d.ts" + "./dist/middleware/cors" ], "etag": [ - "./dist/middleware/etag/etag.d.ts" + "./dist/middleware/etag" ], "graphql-server": [ - "./dist/middleware/graphql-server/graphql-server.d.ts" + "./dist/middleware/graphql-server" ], "logger": [ - "./dist/middleware/logger/logger.d.ts" + "./dist/middleware/logger" ], "mustache": [ - "./dist/middleware/mustache/mustache.d.ts" + "./dist/middleware/mustache" ], "powered-by": [ - "./dist/middleware/powered-by/powered-by.d.ts" + "./dist/middleware/powered-by" ], "pretty-json": [ - "./dist/middleware/pretty-json/pretty-json.d.ts" + "./dist/middleware/pretty-json" ], "serve-static": [ - "./dist/middleware/serve-static/serve-static.d.ts" + "./dist/middleware/serve-static" ], "router/trie-router": [ "./dist/router/trie-router/router.d.ts" @@ -74,14 +72,8 @@ "router/reg-exp-router": [ "./dist/router/reg-exp-router/router.d.ts" ], - "utils/cloudflare": [ - "./dist/utils/cloudflare.d.ts" - ], - "utils/crypto": [ - "./dist/utils/crypto.d.ts" - ], - "utils/mime": [ - "./dist/utils/mime.d.ts" + "utils/*": [ + "./dist/utils/*" ] } }, @@ -130,6 +122,7 @@ "prettier-plugin-md-nocjsp": "^1.2.0", "rimraf": "^3.0.2", "ts-jest": "^27.1.2", + "tsc-alias": "^1.6.6", "typescript": "^4.5.5" }, "engines": { diff --git a/src/compose.test.ts b/src/compose.test.ts index c2476cef..56c11df0 100644 --- a/src/compose.test.ts +++ b/src/compose.test.ts @@ -1,5 +1,5 @@ -import { compose } from './compose' -import { Context } from './context' +import { compose } from '@/compose' +import { Context } from '@/context' type C = { req: Record diff --git a/src/compose.ts b/src/compose.ts index 81f9a884..14f211f1 100644 --- a/src/compose.ts +++ b/src/compose.ts @@ -1,5 +1,5 @@ -import { Context } from './context' -import type { ErrorHandler } from './hono' +import { Context } from '@/context' +import type { ErrorHandler } from '@/hono' // Based on the code in the MIT licensed `koa-compose` package. export const compose = (middleware: Function[], onError?: ErrorHandler) => { diff --git a/src/context.test.ts b/src/context.test.ts index 99b6fc73..6daad6b2 100644 --- a/src/context.test.ts +++ b/src/context.test.ts @@ -1,4 +1,4 @@ -import { Context } from './context' +import { Context } from '@/context' describe('Context', () => { const req = new Request('http://localhost/') diff --git a/src/context.ts b/src/context.ts index bcd824bc..12117149 100644 --- a/src/context.ts +++ b/src/context.ts @@ -1,5 +1,5 @@ -import { isAbsoluteURL } from './utils/url' -import { getStatusText } from './utils/http-status' +import { isAbsoluteURL } from '@/utils/url' +import { getStatusText } from '@/utils/http-status' type Headers = Record type Data = string | ArrayBuffer | ReadableStream diff --git a/src/hono.test.ts b/src/hono.test.ts index 6177b4da..eacaf32a 100644 --- a/src/hono.test.ts +++ b/src/hono.test.ts @@ -1,4 +1,4 @@ -import { Hono } from './hono' +import { Hono } from '@/hono' describe('GET Request', () => { const app = new Hono() diff --git a/src/hono.ts b/src/hono.ts index 3b17cfbb..26b7f7b2 100644 --- a/src/hono.ts +++ b/src/hono.ts @@ -1,10 +1,10 @@ -import { compose } from './compose' -import { getPathFromURL, mergePath } from './utils/url' -import { Context } from './context' -import type { Env } from './context' -import type { Result, Router } from './router' -import { METHOD_NAME_OF_ALL } from './router' -import { TrieRouter } from './router/trie-router' // Default Router +import { compose } from '@/compose' +import { getPathFromURL, mergePath } from '@/utils/url' +import { Context } from '@/context' +import { METHOD_NAME_OF_ALL } from '@/router' +import { TrieRouter } from '@/router/trie-router' // Default Router +import type { Env } from '@/context' +import type { Result, Router } from '@/router' declare global { interface Request { diff --git a/src/index.ts b/src/index.ts index 311e6bd7..bb1fdba3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -export { Hono } from './hono' -export type { Handler, MiddlewareHandler } from './hono' -export { Context } from './context' -export type { Env } from './context' +export { Hono } from '@/hono' +export type { Handler, MiddlewareHandler } from '@/hono' +export { Context } from '@/context' +export type { Env } from '@/context' diff --git a/src/middleware/basic-auth/basic-auth.test.ts b/src/middleware/basic-auth/index.test.ts similarity index 97% rename from src/middleware/basic-auth/basic-auth.test.ts rename to src/middleware/basic-auth/index.test.ts index 1c0c8e08..3d20583b 100644 --- a/src/middleware/basic-auth/basic-auth.test.ts +++ b/src/middleware/basic-auth/index.test.ts @@ -1,5 +1,5 @@ -import { Hono } from '../../hono' -import { basicAuth } from './basic-auth' +import { Hono } from '@/hono' +import { basicAuth } from '@/middleware/basic-auth' import { SHA256 } from 'crypto-js' describe('Basic Auth by Middleware', () => { diff --git a/src/middleware/basic-auth/basic-auth.ts b/src/middleware/basic-auth/index.ts similarity index 93% rename from src/middleware/basic-auth/basic-auth.ts rename to src/middleware/basic-auth/index.ts index 1f5b935d..a7e4c1d1 100644 --- a/src/middleware/basic-auth/basic-auth.ts +++ b/src/middleware/basic-auth/index.ts @@ -1,6 +1,6 @@ -import type { Context } from '../../context' -import { timingSafeEqual } from '../../utils/buffer' -import { decodeBase64 } from '../../utils/crypto' +import type { Context } from '@/context' +import { timingSafeEqual } from '@/utils/buffer' +import { decodeBase64 } from '@/utils/crypto' const CREDENTIALS_REGEXP = /^ *(?:[Bb][Aa][Ss][Ii][Cc]) +([A-Za-z0-9._~+/-]+=*) *$/ const USER_PASS_REGEXP = /^([^:]*):(.*)$/ diff --git a/src/middleware/body-parse/body-parse.test.ts b/src/middleware/body-parse/index.test.ts similarity index 95% rename from src/middleware/body-parse/body-parse.test.ts rename to src/middleware/body-parse/index.test.ts index 941f449d..cbd4b2ce 100644 --- a/src/middleware/body-parse/body-parse.test.ts +++ b/src/middleware/body-parse/index.test.ts @@ -1,5 +1,5 @@ -import { Hono } from '../../hono' -import { bodyParse } from './body-parse' +import { Hono } from '@/hono' +import { bodyParse } from '@/middleware/body-parse' describe('Parse Body Middleware', () => { const app = new Hono() diff --git a/src/middleware/body-parse/body-parse.ts b/src/middleware/body-parse/index.ts similarity index 100% rename from src/middleware/body-parse/body-parse.ts rename to src/middleware/body-parse/index.ts diff --git a/src/middleware/cookie/cookie.test.ts b/src/middleware/cookie/index.test.ts similarity index 96% rename from src/middleware/cookie/cookie.test.ts rename to src/middleware/cookie/index.test.ts index e3b3e805..23a3a396 100644 --- a/src/middleware/cookie/cookie.test.ts +++ b/src/middleware/cookie/index.test.ts @@ -1,5 +1,5 @@ -import { Hono } from '../../hono' -import { cookie } from './cookie' +import { Hono } from '@/hono' +import { cookie } from '@/middleware/cookie' describe('Cookie Middleware', () => { const app = new Hono() diff --git a/src/middleware/cookie/cookie.ts b/src/middleware/cookie/index.ts similarity index 95% rename from src/middleware/cookie/cookie.ts rename to src/middleware/cookie/index.ts index 100f10ae..d3b92546 100644 --- a/src/middleware/cookie/cookie.ts +++ b/src/middleware/cookie/index.ts @@ -1,4 +1,4 @@ -import type { Context } from '../../context' +import type { Context } from '@/context' declare global { interface Request { @@ -6,7 +6,7 @@ declare global { } } -declare module '../../context' { +declare module '@/context' { interface Context { cookie: (name: string, value: string, options?: CookieOptions) => void } diff --git a/src/middleware/cors/cors.test.ts b/src/middleware/cors/index.test.ts similarity index 96% rename from src/middleware/cors/cors.test.ts rename to src/middleware/cors/index.test.ts index ae6e52df..50e4695e 100644 --- a/src/middleware/cors/cors.test.ts +++ b/src/middleware/cors/index.test.ts @@ -1,5 +1,5 @@ -import { Hono } from '../../hono' -import { cors } from './cors' +import { Hono } from '@/hono' +import { cors } from '@/middleware/cors' describe('CORS by Middleware', () => { const app = new Hono() diff --git a/src/middleware/cors/cors.ts b/src/middleware/cors/index.ts similarity index 100% rename from src/middleware/cors/cors.ts rename to src/middleware/cors/index.ts diff --git a/src/middleware/etag/etag.test.ts b/src/middleware/etag/index.test.ts similarity index 95% rename from src/middleware/etag/etag.test.ts rename to src/middleware/etag/index.test.ts index 8f263c2a..b4921a89 100644 --- a/src/middleware/etag/etag.test.ts +++ b/src/middleware/etag/index.test.ts @@ -1,5 +1,5 @@ -import { Hono } from '../../hono' -import { etag } from './etag' +import { Hono } from '@/hono' +import { etag } from '@/middleware/etag' describe('Etag Middleware', () => { const app = new Hono() diff --git a/src/middleware/etag/etag.ts b/src/middleware/etag/index.ts similarity index 85% rename from src/middleware/etag/etag.ts rename to src/middleware/etag/index.ts index f173102f..46982a50 100644 --- a/src/middleware/etag/etag.ts +++ b/src/middleware/etag/index.ts @@ -1,6 +1,6 @@ -import { sha1 } from '../../utils/crypto' -import { parseBody } from '../../utils/body' -import type { Context } from '../../context' +import { sha1 } from '@/utils/crypto' +import { parseBody } from '@/utils/body' +import type { Context } from '@/context' type ETagOptions = { weak: boolean diff --git a/src/middleware/graphql-server/graphql-server.test.ts b/src/middleware/graphql-server/index.test.ts similarity index 99% rename from src/middleware/graphql-server/graphql-server.test.ts rename to src/middleware/graphql-server/index.test.ts index dd10c519..af756ede 100644 --- a/src/middleware/graphql-server/graphql-server.test.ts +++ b/src/middleware/graphql-server/index.test.ts @@ -1,5 +1,5 @@ -import { Hono } from '../../hono' -import { errorMessages, graphqlServer } from './graphql-server' +import { Hono } from '@/hono' +import { errorMessages, graphqlServer } from '@/middleware/graphql-server' import { buildSchema, GraphQLSchema, diff --git a/src/middleware/graphql-server/graphql-server.ts b/src/middleware/graphql-server/index.ts similarity index 98% rename from src/middleware/graphql-server/graphql-server.ts rename to src/middleware/graphql-server/index.ts index cf3e8c5b..6a235b66 100644 --- a/src/middleware/graphql-server/graphql-server.ts +++ b/src/middleware/graphql-server/index.ts @@ -1,8 +1,8 @@ // Based on the code in the `express-graphql` package. // https://github.com/graphql/express-graphql/blob/main/src/index.ts -import { parseBody } from './parse-body' -import type { Context } from '../../context' +import { parseBody } from '@/middleware/graphql-server/parse-body' +import type { Context } from '@/context' import { Source, diff --git a/src/middleware/graphql-server/parse-body.test.ts b/src/middleware/graphql-server/parse-body.test.ts index a16c8671..114a29ca 100644 --- a/src/middleware/graphql-server/parse-body.test.ts +++ b/src/middleware/graphql-server/parse-body.test.ts @@ -1,4 +1,4 @@ -import { parseBody } from './parse-body' +import { parseBody } from '@/middleware/graphql-server/parse-body' describe('parseBody', () => { it('Should return a blank JSON object', async () => { diff --git a/src/middleware/logger/logger.test.ts b/src/middleware/logger/index.test.ts similarity index 96% rename from src/middleware/logger/logger.test.ts rename to src/middleware/logger/index.test.ts index 2e4c0b80..09aa446b 100644 --- a/src/middleware/logger/logger.test.ts +++ b/src/middleware/logger/index.test.ts @@ -1,5 +1,5 @@ -import { Hono } from '../../hono' -import { logger } from './logger' +import { Hono } from '@/hono' +import { logger } from '@/middleware/logger' describe('Logger by Middleware', () => { const app = new Hono() diff --git a/src/middleware/logger/logger.ts b/src/middleware/logger/index.ts similarity index 95% rename from src/middleware/logger/logger.ts rename to src/middleware/logger/index.ts index bc094952..717b2551 100644 --- a/src/middleware/logger/logger.ts +++ b/src/middleware/logger/index.ts @@ -1,5 +1,5 @@ -import { getPathFromURL } from '../../utils/url' -import type { Context } from '../../context' +import { getPathFromURL } from '@/utils/url' +import type { Context } from '@/context' const humanize = (n: string[], opts?: { delimiter?: string; separator?: string }) => { const options = opts || {} diff --git a/src/middleware/mustache/mustache.test.ts b/src/middleware/mustache/index.test.ts similarity index 95% rename from src/middleware/mustache/mustache.test.ts rename to src/middleware/mustache/index.test.ts index ac96b8cb..d6cd1fc1 100644 --- a/src/middleware/mustache/mustache.test.ts +++ b/src/middleware/mustache/index.test.ts @@ -1,5 +1,5 @@ -import { Hono } from '../../hono' -import { mustache } from './mustache' +import { Hono } from '@/hono' +import { mustache } from '@/middleware/mustache' // Mock const store: { [key: string]: string } = { diff --git a/src/middleware/mustache/mustache.ts b/src/middleware/mustache/index.ts similarity index 97% rename from src/middleware/mustache/mustache.ts rename to src/middleware/mustache/index.ts index 03dec1da..76761985 100644 --- a/src/middleware/mustache/mustache.ts +++ b/src/middleware/mustache/index.ts @@ -1,4 +1,4 @@ -import type { Context } from '../../context' +import type { Context } from '@/context' import { getContentFromKVAsset, getKVFilePath } from '../../utils/cloudflare' const EXTENSION = '.mustache' diff --git a/src/middleware/powered-by/powered-by.test.ts b/src/middleware/powered-by/index.test.ts similarity index 83% rename from src/middleware/powered-by/powered-by.test.ts rename to src/middleware/powered-by/index.test.ts index 0866786a..29529ae6 100644 --- a/src/middleware/powered-by/powered-by.test.ts +++ b/src/middleware/powered-by/index.test.ts @@ -1,5 +1,5 @@ -import { Hono } from '../../hono' -import { poweredBy } from './powered-by' +import { Hono } from '@/hono' +import { poweredBy } from '@/middleware/powered-by' describe('Powered by Middleware', () => { const app = new Hono() diff --git a/src/middleware/powered-by/powered-by.ts b/src/middleware/powered-by/index.ts similarity index 60% rename from src/middleware/powered-by/powered-by.ts rename to src/middleware/powered-by/index.ts index ad36aa1d..e4ed8272 100644 --- a/src/middleware/powered-by/powered-by.ts +++ b/src/middleware/powered-by/index.ts @@ -1,9 +1,8 @@ -import type { Context } from '../../context' +import type { Context } from '@/context' export const poweredBy = () => { return async (c: Context, next: Function) => { await next() - // await c.res.headers.append('X-Powered-By', 'Hono') c.res.headers.append('X-Powered-By', 'Hono') } } diff --git a/src/middleware/pretty-json/pretty-json.test.ts b/src/middleware/pretty-json/index.test.ts similarity index 90% rename from src/middleware/pretty-json/pretty-json.test.ts rename to src/middleware/pretty-json/index.test.ts index c7453c7e..1f279a91 100644 --- a/src/middleware/pretty-json/pretty-json.test.ts +++ b/src/middleware/pretty-json/index.test.ts @@ -1,5 +1,5 @@ -import { Hono } from '../../hono' -import { prettyJSON } from './pretty-json' +import { Hono } from '@/hono' +import { prettyJSON } from '@/middleware/pretty-json' describe('JSON pretty by Middleware', () => { const app = new Hono() diff --git a/src/middleware/pretty-json/pretty-json.ts b/src/middleware/pretty-json/index.ts similarity index 87% rename from src/middleware/pretty-json/pretty-json.ts rename to src/middleware/pretty-json/index.ts index 54392bfa..ece3535f 100644 --- a/src/middleware/pretty-json/pretty-json.ts +++ b/src/middleware/pretty-json/index.ts @@ -1,4 +1,4 @@ -import type { Context } from '../../context' +import type { Context } from '@/context' type prettyOptions = { space: number diff --git a/src/middleware/serve-static/serve-static.test.ts b/src/middleware/serve-static/index.test.ts similarity index 96% rename from src/middleware/serve-static/serve-static.test.ts rename to src/middleware/serve-static/index.test.ts index 4a4492a4..6ad3c441 100644 --- a/src/middleware/serve-static/serve-static.test.ts +++ b/src/middleware/serve-static/index.test.ts @@ -1,5 +1,5 @@ -import { Hono } from '../../hono' -import { serveStatic } from './serve-static' +import { Hono } from '@/hono' +import { serveStatic } from '@/middleware/serve-static' // Mock const store: { [key: string]: string } = { diff --git a/src/middleware/serve-static/serve-static.ts b/src/middleware/serve-static/index.ts similarity index 81% rename from src/middleware/serve-static/serve-static.ts rename to src/middleware/serve-static/index.ts index 927a685d..c1d1c88b 100644 --- a/src/middleware/serve-static/serve-static.ts +++ b/src/middleware/serve-static/index.ts @@ -1,6 +1,6 @@ -import type { Context } from '../../context' -import { getContentFromKVAsset, getKVFilePath } from '../../utils/cloudflare' -import { getMimeType } from '../../utils/mime' +import type { Context } from '@/context' +import { getContentFromKVAsset, getKVFilePath } from '@/utils/cloudflare' +import { getMimeType } from '@/utils/mime' type Options = { root: string diff --git a/src/router/reg-exp-router/index.ts b/src/router/reg-exp-router/index.ts index 45931b15..534400e6 100644 --- a/src/router/reg-exp-router/index.ts +++ b/src/router/reg-exp-router/index.ts @@ -1 +1 @@ -export { RegExpRouter } from './router' +export { RegExpRouter } from '@/router/reg-exp-router/router' diff --git a/src/router/reg-exp-router/router.test.ts b/src/router/reg-exp-router/router.test.ts index c5763477..3eafd289 100644 --- a/src/router/reg-exp-router/router.test.ts +++ b/src/router/reg-exp-router/router.test.ts @@ -1,5 +1,5 @@ -import { RegExpRouter } from './router' -import { METHOD_NAME_OF_ALL } from '../../router' +import { RegExpRouter } from '@/router/reg-exp-router/router' +import { METHOD_NAME_OF_ALL } from '@/router' describe('Basic Usage', () => { const router = new RegExpRouter() diff --git a/src/router/reg-exp-router/router.ts b/src/router/reg-exp-router/router.ts index c0f45581..f0ae6d4c 100644 --- a/src/router/reg-exp-router/router.ts +++ b/src/router/reg-exp-router/router.ts @@ -1,6 +1,6 @@ -import { Router, Result, METHOD_NAME_OF_ALL } from '../../router' -import type { ParamMap } from './trie' -import { Trie } from './trie' +import { Router, Result, METHOD_NAME_OF_ALL } from '@/router' +import type { ParamMap } from '@/router/reg-exp-router/trie' +import { Trie } from '@/router/reg-exp-router/trie' type Route = [string, T] type HandlerData = [T, ParamMap | null] diff --git a/src/router/reg-exp-router/trie.ts b/src/router/reg-exp-router/trie.ts index 0111a5fc..f0358895 100644 --- a/src/router/reg-exp-router/trie.ts +++ b/src/router/reg-exp-router/trie.ts @@ -1,7 +1,7 @@ -import type { ParamMap, Context } from './node' -import { Node } from './node' +import type { ParamMap, Context } from '@/router/reg-exp-router/node' +import { Node } from '@/router/reg-exp-router/node' -export type { ParamMap } from './node' +export type { ParamMap } from '@/router/reg-exp-router/node' export type ReplacementMap = number[] export class Trie { diff --git a/src/router/trie-router/index.ts b/src/router/trie-router/index.ts index c75ba247..b7a5bcb3 100644 --- a/src/router/trie-router/index.ts +++ b/src/router/trie-router/index.ts @@ -1 +1 @@ -export { TrieRouter } from './router' +export { TrieRouter } from '@/router/trie-router/router' diff --git a/src/router/trie-router/node.test.ts b/src/router/trie-router/node.test.ts index 9afb313e..4654a09d 100644 --- a/src/router/trie-router/node.test.ts +++ b/src/router/trie-router/node.test.ts @@ -1,4 +1,4 @@ -import { Node } from './node' +import { Node } from '@/router/trie-router/node' describe('Root Node', () => { const node = new Node() diff --git a/src/router/trie-router/node.ts b/src/router/trie-router/node.ts index f70a881e..c6659c53 100644 --- a/src/router/trie-router/node.ts +++ b/src/router/trie-router/node.ts @@ -1,6 +1,6 @@ -import type { Pattern } from '../../utils/url' -import { splitPath, getPattern } from '../../utils/url' -import { Result, METHOD_NAME_OF_ALL } from '../../router' +import type { Pattern } from '@/utils/url' +import { splitPath, getPattern } from '@/utils/url' +import { Result, METHOD_NAME_OF_ALL } from '@/router' const noRoute = (): null => { return null diff --git a/src/router/trie-router/router.test.ts b/src/router/trie-router/router.test.ts index e8a83057..2f710964 100644 --- a/src/router/trie-router/router.test.ts +++ b/src/router/trie-router/router.test.ts @@ -1,4 +1,4 @@ -import { TrieRouter } from './router' +import { TrieRouter } from '@/router/trie-router/router' describe('Basic Usage', () => { const router = new TrieRouter() diff --git a/src/router/trie-router/router.ts b/src/router/trie-router/router.ts index b3ebacf2..5b22d3c3 100644 --- a/src/router/trie-router/router.ts +++ b/src/router/trie-router/router.ts @@ -1,6 +1,6 @@ -import { Router } from '../../router' -import type { Result } from '../../router' -import { Node } from './node' +import { Router } from '@/router' +import type { Result } from '@/router' +import { Node } from '@/router/trie-router/node' export class TrieRouter extends Router { node: Node diff --git a/src/utils/body.test.ts b/src/utils/body.test.ts index 00e0f3ae..5665977f 100644 --- a/src/utils/body.test.ts +++ b/src/utils/body.test.ts @@ -1,4 +1,4 @@ -import { parseBody } from './body' +import { parseBody } from '@/utils/body' describe('Parse Body Middleware', () => { it('should parse JSON', async () => { diff --git a/src/utils/buffer.test.ts b/src/utils/buffer.test.ts index 42d46911..1afa7a39 100644 --- a/src/utils/buffer.test.ts +++ b/src/utils/buffer.test.ts @@ -1,4 +1,4 @@ -import { timingSafeEqual } from './buffer' +import { timingSafeEqual } from '@/utils/buffer' import { SHA256 as sha256CryptoJS } from 'crypto-js' describe('buffer', () => { diff --git a/src/utils/buffer.ts b/src/utils/buffer.ts index 183316cb..962285fa 100644 --- a/src/utils/buffer.ts +++ b/src/utils/buffer.ts @@ -1,4 +1,4 @@ -import { sha256 } from './crypto' +import { sha256 } from '@/utils/crypto' export const equal = (a: ArrayBuffer, b: ArrayBuffer) => { if (a === b) { diff --git a/src/utils/cloudflare.test.ts b/src/utils/cloudflare.test.ts index 25260e3d..ff59cbc8 100644 --- a/src/utils/cloudflare.test.ts +++ b/src/utils/cloudflare.test.ts @@ -1,4 +1,4 @@ -import { getContentFromKVAsset, getKVFilePath } from './cloudflare' +import { getContentFromKVAsset, getKVFilePath } from '@/utils/cloudflare' // Mock const store: { [key: string]: string } = { diff --git a/src/utils/crypto.test.ts b/src/utils/crypto.test.ts index 2e2fc136..edf27577 100644 --- a/src/utils/crypto.test.ts +++ b/src/utils/crypto.test.ts @@ -1,4 +1,4 @@ -import { sha256, sha1, decodeBase64, encodeBase64 } from './crypto' +import { sha256, sha1, decodeBase64, encodeBase64 } from '@/utils/crypto' describe('crypto', () => { it('sha256', async () => { diff --git a/src/utils/http-status.test.ts b/src/utils/http-status.test.ts index aae5dfe1..83431e20 100644 --- a/src/utils/http-status.test.ts +++ b/src/utils/http-status.test.ts @@ -1,4 +1,4 @@ -import { getStatusText } from './http-status' +import { getStatusText } from '@/utils/http-status' describe('http-status utility', () => { it('getStatusText', () => { diff --git a/src/utils/mime.test.ts b/src/utils/mime.test.ts index 9532d07f..9b864235 100644 --- a/src/utils/mime.test.ts +++ b/src/utils/mime.test.ts @@ -1,4 +1,4 @@ -import { getMimeType } from './mime' +import { getMimeType } from '@/utils/mime' describe('mime', () => { it('getMimeType', () => { diff --git a/src/utils/url.test.ts b/src/utils/url.test.ts index 57ea36fe..b5c79a1d 100644 --- a/src/utils/url.test.ts +++ b/src/utils/url.test.ts @@ -1,4 +1,4 @@ -import { splitPath, getPattern, getPathFromURL, isAbsoluteURL, mergePath } from './url' +import { splitPath, getPattern, getPathFromURL, isAbsoluteURL, mergePath } from '@/utils/url' describe('url', () => { it('splitPath', () => { diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 00000000..07d57331 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "include": [ + "src/**/*" + ], + "exclude": [ + "src/**/*.test.ts" + ] +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index c2552515..6266c90f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,12 +14,16 @@ "jest", "node", "@cloudflare/workers-types" - ] + ], + "baseUrl": ".", + "paths": { + "@/*": [ + "./src/*" + ] + }, }, "include": [ - "src/**/*" - ], - "exclude": [ + "src/**/*", "src/**/*.test.ts" - ] + ], } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 3bb94651..12d039a7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -990,7 +990,7 @@ ansi-styles@^5.0.0: resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-5.2.0.tgz#07449690ad45777d1924ac2abb2fc8895dba836b" integrity sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA== -anymatch@^3.0.3: +anymatch@^3.0.3, anymatch@~3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.2.tgz#c0557c096af32f106198f4f4e2a383537e378716" integrity sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg== @@ -1106,6 +1106,11 @@ balanced-match@^1.0.0: resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== +binary-extensions@^2.0.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" + integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== + brace-expansion@^1.1.7: version "1.1.11" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" @@ -1114,7 +1119,7 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" -braces@^3.0.1: +braces@^3.0.1, braces@~3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== @@ -1213,6 +1218,21 @@ char-regex@^1.0.2: resolved "https://registry.yarnpkg.com/char-regex/-/char-regex-1.0.2.tgz#d744358226217f981ed58f479b1d6bcc29545dcf" integrity sha512-kWWXztvZ5SBQV+eRgKFeh8q5sLuZY2+8WUIzlxWVTg+oGwY14qylx1KbKzHd8P6ZYkAg0xyIDU9JMHhyJMZ1jw== +chokidar@^3.5.3: + version "3.5.3" + resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" + integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw== + dependencies: + anymatch "~3.1.2" + braces "~3.0.2" + glob-parent "~5.1.2" + is-binary-path "~2.1.0" + is-glob "~4.0.1" + normalize-path "~3.0.0" + readdirp "~3.6.0" + optionalDependencies: + fsevents "~2.3.2" + ci-info@^3.2.0: version "3.3.0" resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.3.0.tgz#b4ed1fb6818dea4803a55c623041f9165d2066b2" @@ -1273,6 +1293,11 @@ combined-stream@^1.0.8: dependencies: delayed-stream "~1.0.0" +commander@^9.0.0: + version "9.2.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-9.2.0.tgz#6e21014b2ed90d8b7c9647230d8b7a94a4a419a9" + integrity sha512-e2i4wANQiSXgnrBlIatyHtP1odfUp0BbV5Y5nEGbxtIrStkEOAAzCUirvLBNXHLr7kwLvJl6V+4V3XV9x7Wd9w== + concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" @@ -1880,7 +1905,7 @@ fs.realpath@^1.0.0: resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= -fsevents@^2.3.2: +fsevents@^2.3.2, fsevents@~2.3.2: version "2.3.2" resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a" integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== @@ -1932,7 +1957,7 @@ get-symbol-description@^1.0.0: call-bind "^1.0.2" get-intrinsic "^1.1.1" -glob-parent@^5.1.2: +glob-parent@^5.1.2, glob-parent@~5.1.2: version "5.1.2" resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4" integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow== @@ -2130,6 +2155,13 @@ is-bigint@^1.0.1: dependencies: has-bigints "^1.0.1" +is-binary-path@~2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09" + integrity sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw== + dependencies: + binary-extensions "^2.0.0" + is-boolean-object@^1.1.0: version "1.1.2" resolved "https://registry.yarnpkg.com/is-boolean-object/-/is-boolean-object-1.1.2.tgz#5c6dc200246dd9321ae4b885a114bb1f75f63719" @@ -2172,7 +2204,7 @@ is-generator-fn@^2.0.0: resolved "https://registry.yarnpkg.com/is-generator-fn/-/is-generator-fn-2.1.0.tgz#7d140adc389aaf3011a8f2a2a4cfa6faadffb118" integrity sha512-cTIB4yPYL/Grw0EaSzASzg6bBy9gqCofvWN8okThAYIxKJZC+udlRAmGbM0XLeniEJSs8uEgHPGuHSe1XsOLSQ== -is-glob@^4.0.0, is-glob@^4.0.1, is-glob@^4.0.3: +is-glob@^4.0.0, is-glob@^4.0.1, is-glob@^4.0.3, is-glob@~4.0.1: version "4.0.3" resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084" integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg== @@ -2976,6 +3008,11 @@ mustache@^4.2.0: resolved "https://registry.yarnpkg.com/mustache/-/mustache-4.2.0.tgz#e5892324d60a12ec9c2a73359edca52972bf6f64" integrity sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ== +mylas@^2.1.9: + version "2.1.9" + resolved "https://registry.yarnpkg.com/mylas/-/mylas-2.1.9.tgz#8329626f95c0ce522ca7d3c192eca6221d172cdc" + integrity sha512-pa+cQvmhoM8zzgitPYZErmDt9EdTNVnXsH1XFjMeM4TyG4FFcgxrvK1+jwabVFwUOEDaSWuXBMjg43kqt/Ydlg== + natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" @@ -2996,7 +3033,7 @@ node-releases@^2.0.1: resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.1.tgz#3d1d395f204f1f2f29a54358b9fb678765ad2fc5" integrity sha512-CqyzN6z7Q6aMeF/ktcMVTzhAHCEpf8SOarwpzpf8pNBY2k5/oM34UHldUwp8VKI7uxct2HxSRdJjBaZeESzcxA== -normalize-path@^3.0.0: +normalize-path@^3.0.0, normalize-path@~3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== @@ -3165,7 +3202,7 @@ picocolors@^1.0.0: resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c" integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ== -picomatch@^2.0.4, picomatch@^2.2.3: +picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.2.3: version "2.3.1" resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42" integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA== @@ -3244,6 +3281,13 @@ react-is@^17.0.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== +readdirp@~3.6.0: + version "3.6.0" + resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.6.0.tgz#74a370bd857116e245b29cc97340cd431a02a6c7" + integrity sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA== + dependencies: + picomatch "^2.2.1" + regexpp@^3.0.0, regexpp@^3.1.0, regexpp@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.2.0.tgz#0425a2768d8f23bad70ca4b90461fa2f1213e1b2" @@ -3634,6 +3678,17 @@ ts-jest@^27.1.2: semver "7.x" yargs-parser "20.x" +tsc-alias@^1.6.6: + version "1.6.6" + resolved "https://registry.yarnpkg.com/tsc-alias/-/tsc-alias-1.6.6.tgz#1bdda705efa6251b9a62593e8ed4b0285c20803b" + integrity sha512-wQuIKleaPuQKpTwrzFb1gTOd3ZsB5GqIK+aPyh1okOLfYYNsMyxIypIYctQnSxiJ243iRxLdvNlboZOTEdK1MQ== + dependencies: + chokidar "^3.5.3" + commander "^9.0.0" + globby "^11.0.4" + mylas "^2.1.9" + normalize-path "^3.0.0" + tsconfig-paths@^3.12.0, tsconfig-paths@^3.9.0: version "3.12.0" resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.12.0.tgz#19769aca6ee8f6a1a341e38c8fa45dd9fb18899b"