Skip to content

Commit

Permalink
fix: dont import default value (#273)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Updated the dependency version for `@eggjs/koa` and added an
ECMAScript module field in `package.json`.

- **Bug Fixes**
	- Enhanced error handling in lifecycle management methods.
- Improved type safety in the error handling function of the
`Application` class.

- **Documentation**
	- Corrected minor typos in comments for clarity.

- **Chores**
	- Updated `.gitignore` to exclude `.package-lock.json`.
	- Modified import statements for clarity and consistency across files.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
fengmk2 authored Dec 13, 2024
1 parent 9ff7f76 commit 16274e7
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ test/fixtures/*/timing.json
lib/
.tshy*
dist
.package-lock.json
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"homepage": "https://github.com/eggjs/egg-core#readme",
"dependencies": {
"@eggjs/koa": "^2.18.2",
"@eggjs/koa": "^2.19.2",
"@eggjs/router": "^3.0.5",
"@eggjs/utils": "^4.0.2",
"egg-logger": "^3.5.0",
Expand Down Expand Up @@ -66,7 +66,7 @@
"mm": "3",
"supertest": "7",
"ts-node": "10",
"tshy": "1",
"tshy": "3",
"tshy-after": "1",
"typescript": "5",
"urllib": "4"
Expand All @@ -86,17 +86,16 @@
"./package.json": "./package.json",
".": {
"import": {
"source": "./src/index.ts",
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"source": "./src/index.ts",
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
},
"main": "./dist/commonjs/index.js",
"types": "./dist/commonjs/index.d.ts"
"types": "./dist/commonjs/index.d.ts",
"module": "./dist/esm/index.js"
}
9 changes: 3 additions & 6 deletions src/egg.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable prefer-spread */
import assert from 'node:assert';
import { debuglog } from 'node:util';
import is from 'is-type-of';
import KoaApplication from '@eggjs/koa';
import { Application as KoaApplication } from '@eggjs/koa';
import type { ContextDelegation, MiddlewareFunc } from '@eggjs/koa';
import { EggConsoleLogger } from 'egg-logger';
import { RegisterOptions, ResourcesController, EggRouter as Router } from '@eggjs/router';
Expand Down Expand Up @@ -157,10 +156,8 @@ export class EggCore extends KoaApplication {
* override koa's app.use, support generator function
* @since 1.0.0
*/
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
use(fn: MiddlewareFunc) {
assert(is.function(fn), 'app.use() requires a function');
assert(typeof fn === 'function', 'app.use() requires a function');
debug('[use] add middleware: %o', fn._name || fn.name || '-');
this.middleware.push(fn);
return this;
Expand Down Expand Up @@ -226,7 +223,7 @@ export class EggCore extends KoaApplication {
* Execute scope after loaded and before app start.
*
* Notice:
* This method is now NOT recommanded and reguarded as a deprecated one,
* This method is now NOT recommended and regarded as a deprecated one,
* For plugin development, we should use `didLoad` instead.
* For application development, we should use `willReady` instead.
*
Expand Down
6 changes: 3 additions & 3 deletions src/lifecycle.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import assert from 'node:assert';
import { EventEmitter } from 'node:events';
import { debuglog } from 'node:util';
import is, { isClass } from 'is-type-of';
import ReadyObject from 'get-ready';
import { isClass } from 'is-type-of';
import { Ready as ReadyObject } from 'get-ready';
import type { ReadyFunctionArg } from 'get-ready';
import { Ready } from 'ready-callback';
import { EggConsoleLogger } from 'egg-logger';
Expand Down Expand Up @@ -184,7 +184,7 @@ export class Lifecycle extends EventEmitter {
}

registerBeforeClose(fn: Fun) {
assert(is.function(fn), 'argument should be function');
assert(typeof fn === 'function', 'argument should be function');
assert(this.#isClosed === false, 'app has been closed');
this.#closeFunctionSet.add(fn);
}
Expand Down
2 changes: 1 addition & 1 deletion src/loader/egg_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'node:path';
import assert from 'node:assert';
import { debuglog, inspect } from 'node:util';
import { isAsyncFunction, isClass, isGeneratorFunction, isObject } from 'is-type-of';
import homedir from 'node-homedir';
import { homedir } from 'node-homedir';
import type { Logger } from 'egg-logger';
import { getParamNames, readJSONSync } from 'utility';
import { extend } from 'extend2';
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/egg-esm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class Application extends EggCore {

constructor(options: EggCoreInitOptions = {}) {
super(options);
this.on('error', err => {
this.on('error', (err: any) => {
console.error(err);
});
}
Expand Down

0 comments on commit 16274e7

Please sign in to comment.