Skip to content

Commit

Permalink
feat: upgrade dependencies and devDependencies (#256)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: drop Node.js < 14.17.0 support
  • Loading branch information
fengmk2 authored Jan 1, 2023
1 parent c2debd5 commit 540f3fe
Show file tree
Hide file tree
Showing 61 changed files with 156 additions and 379 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
name: Node.js
uses: artusjs/github-actions/.github/workflows/node-test.yml@v1
with:
version: '8, 10, 12, 14.17.0, 14, 16, 18'
version: '14.17.0, 14, 16, 18'
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,16 @@ To load files from directory, and it will be bound the context.
// define service in app/service/query.js
module.exports = class Query {
constructor(ctx) {
super(ctx);
// get the ctx
}

get() {}
async get() {}
};

// use the service in app/controller/home.js
module.exports = function*() {
this.body = this.service.query.get();
module.exports = async ctx => {
ctx.body = await ctx.service.query.get();
};
```

Expand Down
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const EggCore = require('./lib/egg');
const EggLoader = require('./lib/loader/egg_loader');
const BaseContextClass = require('./lib/utils/base_context_class');
Expand Down
11 changes: 4 additions & 7 deletions lib/egg.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
'use strict';

const assert = require('assert');
const fs = require('fs');
const KoaApplication = require('koa');
const EggConsoleLogger = require('egg-logger').EggConsoleLogger;
const debug = require('debug')('egg-core');
const is = require('is-type-of');
const co = require('co');
const Router = require('@eggjs/router').EggRouter;
const BaseContextClass = require('./utils/base_context_class');
const utils = require('./utils');
const Router = require('@eggjs/router').EggRouter;
const Timing = require('./utils/timing');
const Lifecycle = require('./lifecycle');
const enableAsyncLocalStorage = !!require('async_hooks').AsyncLocalStorage;

const DEPRECATE = Symbol('EggCore#deprecate');
const ROUTER = Symbol('EggCore#router');
Expand Down Expand Up @@ -40,7 +37,7 @@ class EggCore extends KoaApplication {

// enable asyncLocalStorage by default
// https://github.com/koajs/koa/pull/1721
super({ asyncLocalStorage: enableAsyncLocalStorage });
super({ asyncLocalStorage: true });

this.timing = new Timing();

Expand Down Expand Up @@ -72,7 +69,7 @@ class EggCore extends KoaApplication {
/**
* Base controller to be extended by controller in `app.controller`
* @class Controller
* @extends BaseContextClass
* @augments BaseContextClass
* @example
* class UserController extends app.Controller {}
*/
Expand All @@ -88,7 +85,7 @@ class EggCore extends KoaApplication {
/**
* Base service to be extended by services in `app.service`
* @class Service
* @extends BaseContextClass
* @augments BaseContextClass
* @example
* class UserService extends app.Service {}
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/loader/context_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ClassLoader {

/**
* Same as {@link FileLoader}, but it will attach file to `inject[fieldClass]`. The exports will be lazy loaded, such as `ctx.group.repository`.
* @extends FileLoader
* @augments FileLoader
* @since 1.0.0
*/
class ContextLoader extends FileLoader {
Expand Down
3 changes: 1 addition & 2 deletions lib/loader/mixin/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const debug = require('debug')('egg-core:config');
const path = require('path');
const extend = require('extend2');
const assert = require('assert');
const { Console } = require('console');

module.exports = {

Expand Down Expand Up @@ -120,7 +119,7 @@ function setConfig(obj, filepath) {
for (const key of Object.keys(obj)) {
const val = obj[key];
// ignore console
if (key === 'console' && val && typeof val.Console === 'function' && val.Console === Console) {
if (key === 'console' && val && typeof val.Console === 'function' && val.Console === console.Console) {
obj[key] = filepath;
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/loader/mixin/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ module.exports = {
* // app/middleware/status.js
* module.exports = function(options, app) {
* // options == app.config.status
* return function*(next) {
* yield next;
* return async next => {
* await next();
* }
* }
* ```
Expand Down
26 changes: 12 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"scripts": {
"lint": "eslint .",
"test": "npm run lint -- --fix && npm run test-local",
"test-local": "egg-bin test",
"cov": "egg-bin cov",
"test-local": "egg-bin test -p",
"cov": "egg-bin cov -p",
"ci": "npm run lint && npm run cov",
"contributor": "git-contributor"
},
Expand All @@ -32,31 +32,29 @@
},
"homepage": "https://github.com/eggjs/egg-core#readme",
"engines": {
"node": ">= 8.9.0"
"node": ">= 14.17.0"
},
"devDependencies": {
"@types/depd": "^1.1.32",
"@types/koa": "^2.0.48",
"await-event": "^2.1.0",
"coffee": "^5.2.1",
"egg-bin": "^4.20.0",
"egg-bin": "^5.9.0",
"egg-utils": "^2.4.1",
"eslint": "^5.16.0",
"eslint-config-egg": "^7.4.1",
"eslint": "^8.31.0",
"eslint-config-egg": "^12.1.0",
"git-contributor": "^1.0.10",
"jest": "^24.8.0",
"js-yaml": "^3.13.1",
"mm": "^2.5.0",
"mz-modules": "^2.1.0",
"mm": "^3.2.1",
"pedding": "^1.1.0",
"rimraf": "^2.6.3",
"spy": "^1.0.0",
"supertest": "^4.0.2",
"ts-node": "^8.0.3",
"typescript": "^3.3.3333"
"ts-node": "^10.9.1",
"typescript": "^4.9.4",
"urllib": "^3.10.0"
},
"dependencies": {
"@eggjs/router": "^2.0.0",
"@types/depd": "^1.1.32",
"@types/koa": "^2.0.48",
"co": "^4.6.0",
"debug": "^4.1.1",
"depd": "^2.0.0",
Expand Down
7 changes: 1 addition & 6 deletions test/asyncLocalStorage.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

const assert = require('assert');
const path = require('path');
const request = require('supertest');
const enableAsyncLocalStorage = !!require('async_hooks').AsyncLocalStorage;
const EggApplication = require('./fixtures/egg').Application;

describe('test/asyncLocalStorage.test.js', () => {
Expand All @@ -23,9 +20,7 @@ describe('test/asyncLocalStorage.test.js', () => {
assert(res.status === 200);
console.log(res.body);
assert(res.body.sessionId === 'mock-session-id-123');
if (enableAsyncLocalStorage) {
assert(res.body.traceId);
}
assert(res.body.traceId);
assert(app.currentContext === undefined);
});
});
2 changes: 0 additions & 2 deletions test/egg-ts.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const mm = require('mm');
const request = require('supertest');
const assert = require('assert');
Expand Down
31 changes: 14 additions & 17 deletions test/egg.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
'use strict';

const mm = require('mm');
const is = require('is-type-of');
const util = require('util');
const path = require('path');
const assert = require('assert');
const spy = require('spy');
const sleep = require('mz-modules/sleep');
const request = require('supertest');
const coffee = require('coffee');
const utils = require('./utils');
const EggCore = require('..').EggCore;
const awaitEvent = require('await-event');
const fs = require('mz/fs');
const fs = require('fs/promises');

describe('test/egg.test.js', () => {
afterEach(mm.restore);
Expand Down Expand Up @@ -323,7 +320,7 @@ describe('test/egg.test.js', () => {
const first = spy();
const second = spy();
app = utils.createApp('close');
app.beforeClose(() => sleep(200));
app.beforeClose(() => utils.sleep(200));
app.close().then(first);
app.close().then(second);
setTimeout(() => {
Expand Down Expand Up @@ -503,7 +500,7 @@ describe('test/egg.test.js', () => {
// test/fixtures/egg/node_modules/session/app.js
assert(json[12].name.startsWith('Require(6) '));
assert(json[13].name === 'Require(7) app.js');
assert(json[14].name === 'Before Start in app.js:6:9');
assert.equal(json[14].name, 'Before Start in app.js:9:7');
assert(json[15].name === 'Before Start in mock Block');
assert(json[16].name === 'readyCallback in mockReadyCallbackWithoutFunction');

Expand All @@ -530,13 +527,13 @@ describe('test/egg.test.js', () => {
});

describe('agent', () => {
it('should get timing', function* () {
it('should get timing', async () => {
app = utils.createApp('timing');
app.loader.loadPlugin();
app.loader.loadConfig();
app.loader.loadApplicationExtend();
app.loader.loadCustomAgent();
yield app.ready();
await app.ready();

const json = app.timing.toJSON();
assert(json.length === 14);
Expand All @@ -560,7 +557,7 @@ describe('test/egg.test.js', () => {
// loadCustomAgent
assert(json[11].name === 'Load agent.js');
assert(json[12].name === 'Require(6) agent.js');
assert(json[13].name === 'Before Start in agent.js:5:11');
assert.equal(json[13].name, 'Before Start in agent.js:8:9');
});
});

Expand Down Expand Up @@ -607,7 +604,7 @@ describe('test/egg.test.js', () => {
'willReady',
'ready',
]);
await sleep(10);
await utils.sleep(10);
assert.deepStrictEqual(
app.bootLog,
[
Expand All @@ -621,7 +618,7 @@ describe('test/egg.test.js', () => {
'didReady',
]);
await app.lifecycle.triggerServerDidReady();
await sleep(10);
await utils.sleep(10);
assert.deepStrictEqual(
app.bootLog,
[
Expand Down Expand Up @@ -679,7 +676,7 @@ describe('test/egg.test.js', () => {
'willReady',
'ready',
]);
await sleep(10);
await utils.sleep(10);
assert.deepStrictEqual(
app.bootLog,
[
Expand All @@ -693,7 +690,7 @@ describe('test/egg.test.js', () => {
'didReady',
]);
await app.lifecycle.triggerServerDidReady();
await sleep(10);
await utils.sleep(10);
assert.deepStrictEqual(
app.bootLog,
[
Expand Down Expand Up @@ -753,7 +750,7 @@ describe('test/egg.test.js', () => {
}
assert.strictEqual(error.message, 'didLoad error');
assert.deepStrictEqual(app.bootLog, [ 'configDidLoad' ]);
await sleep(10);
await utils.sleep(10);
assert.deepStrictEqual(app.bootLog, [ 'configDidLoad', 'didReady' ]);
await app.close();
assert.deepStrictEqual(
Expand All @@ -778,7 +775,7 @@ describe('test/egg.test.js', () => {
}
assert.deepStrictEqual(app.bootLog, [ 'configDidLoad', 'didLoad' ]);
assert.strictEqual(error.message, 'willReady error');
await sleep(10);
await utils.sleep(10);
assert.deepStrictEqual(app.bootLog, [ 'configDidLoad', 'didLoad', 'didReady' ]);
await app.close();
assert.deepStrictEqual(
Expand Down Expand Up @@ -823,7 +820,7 @@ describe('test/egg.test.js', () => {
const app = utils.createApp('boot-serverDidLoad-error');
app.loader.loadAll();
await app.ready();
await sleep(10);
await utils.sleep(10);
assert.deepStrictEqual(app.bootLog, [
'configDidLoad',
'didLoad',
Expand Down Expand Up @@ -860,7 +857,7 @@ describe('test/egg.test.js', () => {
app.ready(() => {
app.bootLog.push('readyFunction');
});
await sleep(10);
await utils.sleep(10);
assert.deepStrictEqual(
app.bootLog,
[
Expand Down
4 changes: 1 addition & 3 deletions test/fixtures/beforestart-with-timeout-env/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

const sleep = require('ko-sleep');
const { sleep } = require('../../utils');
module.exports = function (app) {
app.beforeStart(function* () {
yield sleep(11000);
Expand Down
5 changes: 3 additions & 2 deletions test/fixtures/beforestart/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
Expand All @@ -7,7 +6,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments)).next());
});
};
const sleep = require('ko-sleep');

const { sleep } = require('../../utils');

module.exports = function (app) {
app.beforeStart(function() {
app.beforeStartFunction = true;
Expand Down
4 changes: 1 addition & 3 deletions test/fixtures/boot-configDidLoad-error/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

const sleep = require('mz-modules/sleep');
const { sleep } = require('../../utils');

module.exports = class {
constructor(app) {
Expand Down
4 changes: 1 addition & 3 deletions test/fixtures/boot-didLoad-error/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

const sleep = require('mz-modules/sleep');
const { sleep } = require('../../utils');

module.exports = class {
constructor(app) {
Expand Down
4 changes: 1 addition & 3 deletions test/fixtures/boot-didReady-error/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

const sleep = require('mz-modules/sleep');
const { sleep } = require('../../utils');

module.exports = class {
constructor(app) {
Expand Down
4 changes: 1 addition & 3 deletions test/fixtures/boot-serverDidLoad-error/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

const sleep = require('mz-modules/sleep');
const { sleep } = require('../../utils');

module.exports = class {
constructor(app) {
Expand Down
4 changes: 1 addition & 3 deletions test/fixtures/boot-timeout/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

const sleep = require('mz-modules/sleep');
const { sleep } = require('../../utils');

module.exports = class TimeoutHook {
async didLoad() {
Expand Down
Loading

0 comments on commit 540f3fe

Please sign in to comment.