diff --git a/package.json b/package.json index 0b75da11..f604ba03 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "dependencies": { "@eggjs/koa": "^2.20.6", "@eggjs/router": "^3.0.5", - "@eggjs/utils": "^4.2.4", + "@eggjs/utils": "^4.3.0", "egg-logger": "^3.5.0", "egg-path-matching": "^2.0.0", "extend2": "^4.0.0", diff --git a/src/egg.ts b/src/egg.ts index 39af7c80..64fdec64 100644 --- a/src/egg.ts +++ b/src/egg.ts @@ -64,6 +64,35 @@ export class Context extends KoaContext { declare request: Request; declare response: Response; declare service: BaseContextClass; + + // #region router + + /** + * Returns map of URL parameters for given `path` and `paramNames`. + * @example + * ##### ctx.params.id {string} + * + * `GET /api/users/1` => `'1'` + * + * ##### ctx.params.per_page {string} + * + * The number of every page, `GET /api/users?per_page=20` => `20` + */ + params?: Record; + /** + * Returns array of router regexp url path captures. + */ + captures?: string[]; + /** + * Returns the name of the matched router. + */ + routerName?: string; + /** + * Returns the path of the matched router. + */ + routerPath?: string | RegExp; + + // #endregion } // export @eggjs/core types diff --git a/src/loader/file_loader.ts b/src/loader/file_loader.ts index 7d46f8f5..542b8b7b 100644 --- a/src/loader/file_loader.ts +++ b/src/loader/file_loader.ts @@ -4,6 +4,7 @@ import { debuglog } from 'node:util'; import path from 'node:path'; import globby from 'globby'; import { isClass, isGeneratorFunction, isAsyncFunction, isPrimitive } from 'is-type-of'; +import { isSupportTypeScript } from '@eggjs/utils'; import utils, { Fun } from '../utils/index.js'; const debug = debuglog('@eggjs/core/file_loader'); @@ -162,7 +163,7 @@ export class FileLoader { protected async parse(): Promise { let files = this.options.match; if (!files) { - files = (process.env.EGG_TYPESCRIPT === 'true' && utils.extensions['.ts']) + files = isSupportTypeScript() ? [ '**/*.(js|ts)', '!**/*.d.ts' ] : [ '**/*.js' ]; } else { diff --git a/test/egg-ts.test.ts b/test/egg-ts.test.ts index 2533a7f4..29dfa7f8 100644 --- a/test/egg-ts.test.ts +++ b/test/egg-ts.test.ts @@ -141,7 +141,7 @@ describe('test/egg-ts.test.ts', () => { assert(!app.serviceClasses.test); }); - it('should not load ts files while EGG_TYPESCRIPT was true but no extensions', async () => { + it.skip('should not load ts files while EGG_TYPESCRIPT was true but no extensions', async () => { mm(process.env, 'EGG_TYPESCRIPT', 'true'); mm(utils, 'extensions', [ '.js', '.json' ]); app = createApp('egg-ts-js');