diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 48f9944f..00000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,24 +0,0 @@ - - -##### Checklist - - -- [ ] `npm test` passes -- [ ] tests and/or benchmarks are included -- [ ] documentation is changed or added -- [ ] commit message follows commit guidelines - -##### Affected core subsystem(s) - - - -##### Description of change - diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index eca8f7d6..be7dd715 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -3,7 +3,6 @@ name: CI on: push: branches: [ master ] - pull_request: branches: [ master ] @@ -12,6 +11,6 @@ jobs: name: Node.js uses: node-modules/github-actions/.github/workflows/node-test.yml@master with: - version: '16.13.0, 16, 18, 20, 22' + version: '18.7.0, 18, 20, 22' secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index 537c68f9..61400b17 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ test/fixtures/egg/node_modules/egg-core package-lock.json run test/fixtures/*/timing.json +lib/ diff --git a/README.md b/README.md index 7ddbda41..7e6b7f6a 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ [download-image]: https://img.shields.io/npm/dm/egg-core.svg?style=flat-square [download-url]: https://npmjs.org/package/egg-core -A core Pluggable framework based on [koa](https://github.com/koajs/koa). +A core plugin framework based on [koa](https://github.com/koajs/koa). **Don't use it directly, see [egg].** @@ -237,6 +237,7 @@ filter | `Function` | a function that filter the exports which can b ## Timing EggCore record boot progress with `Timing`, include: + - Process start time - Script start time(node don't implement an interface like `process.uptime` to record the script start running time, framework can implement a prestart file used with node `--require` options to set `process.scriptTime`) - Application start time diff --git a/package.json b/package.json index 4073e3f8..d3a56d19 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,9 @@ { "name": "@eggjs/core", "version": "5.3.1", + "engines": { + "node": ">= 18.7.0" + }, "description": "A core plugin framework based on koa", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -31,47 +34,44 @@ "url": "https://github.com/eggjs/egg/issues" }, "homepage": "https://github.com/eggjs/egg-core#readme", - "engines": { - "node": ">= 16.13.0" - }, "dependencies": { - "@eggjs/koa": "^2.15.1", + "@eggjs/koa": "^2.17.0", "@eggjs/router": "^2.0.1", "@types/depd": "^1.1.32", "co": "^4.6.0", "depd": "^2.0.0", - "egg-logger": "^3.3.1", - "egg-path-matching": "^1.0.1", - "extend2": "^1.0.0", - "gals": "^1.0.1", - "get-ready": "^3.0.0", + "egg-logger": "^3.5.0", + "egg-path-matching": "^1.1.0", + "extend2": "^1.0.1", + "get-ready": "^3.1.0", "globby": "^11.0.2", "is-type-of": "^1.2.1", "koa-convert": "^1.2.0", - "node-homedir": "^1.1.1", - "ready-callback": "^3.0.0", + "node-homedir": "^2.0.0", + "ready-callback": "^4.0.0", "tsconfig-paths": "^4.1.1", - "utility": "^1.16.1" + "utility": "^2.1.0" }, "devDependencies": { - "@eggjs/tsconfig": "^1.3.3", - "@types/mocha": "^10.0.1", - "@types/node": "^20.2.5", - "await-event": "^2.1.0", - "coffee": "^5.2.1", - "egg-bin": "^6.4.1", - "egg-utils": "^2.4.1", - "eslint": "^8.42.0", - "eslint-config-egg": "^12.2.1", + "@eggjs/tsconfig": "1", + "@types/mocha": "10", + "@types/node": "20", + "await-event": "2", + "coffee": "5", + "egg-bin": "6", + "egg-utils": "2", + "eslint": "8", + "eslint-config-egg": "13", + "gals": "^1.0.2", "git-contributor": "2", "js-yaml": "^3.13.1", - "mm": "^3.2.1", + "mm": "3", "pedding": "^1.1.0", "spy": "^1.0.0", "supertest": "^4.0.2", - "ts-node": "^10.9.1", - "typescript": "^5.1.3", - "urllib": "^3.10.0" + "ts-node": "10", + "typescript": "5", + "urllib": "3" }, "publishConfig": { "access": "public" diff --git a/src/egg.ts b/src/egg.ts index 7f1c360f..27459eea 100644 --- a/src/egg.ts +++ b/src/egg.ts @@ -7,7 +7,6 @@ import type { MiddlewareFunc } from '@eggjs/koa'; import { EggConsoleLogger } from 'egg-logger'; import { EggRouter as Router } from '@eggjs/router'; import type { ReadyFunctionArg } from 'get-ready'; -import { getAsyncLocalStorage } from 'gals'; import { BaseContextClass } from './utils/base_context_class'; import utils from './utils'; import { Timing } from './utils/timing'; @@ -56,10 +55,7 @@ export class EggCore extends KoaApplication { assert(fs.existsSync(options.baseDir), `Directory ${options.baseDir} not exists`); assert(fs.statSync(options.baseDir).isDirectory(), `Directory ${options.baseDir} is not a directory`); assert(options.type === 'application' || options.type === 'agent', 'options.type should be application or agent'); - // disable koa als and use egg logic - super({ asyncLocalStorage: false }); - // can access the AsyncLocalStorage instance in global - this.ctxStorage = getAsyncLocalStorage(); + super(); this.timing = new Timing(); diff --git a/src/loader/base_loader.ts b/src/loader/base_loader.ts index 9cd679fc..36dec67c 100644 --- a/src/loader/base_loader.ts +++ b/src/loader/base_loader.ts @@ -5,9 +5,9 @@ import { debuglog } from 'node:util'; import is from 'is-type-of'; import homedir from 'node-homedir'; import type { Logger } from 'egg-logger'; +import utility from 'utility'; import FileLoader from './file_loader'; import ContextLoader from './context_loader'; -import utility from 'utility'; import utils from '../utils'; import { Timing } from '../utils/timing'; import type { EggCore } from '../egg'; diff --git a/test/asyncLocalStorage.test.js b/test/asyncLocalStorage.test.js deleted file mode 100644 index 0f71c19a..00000000 --- a/test/asyncLocalStorage.test.js +++ /dev/null @@ -1,36 +0,0 @@ -const assert = require('assert'); -const path = require('path'); -const { AsyncLocalStorage } = require('async_hooks'); -const request = require('supertest'); -const { getAsyncLocalStorage, kGALS } = require('gals'); -const EggApplication = require('./fixtures/egg').Application; - -describe('test/asyncLocalStorage.test.js', () => { - let app; - before(() => { - app = new EggApplication({ - baseDir: path.join(__dirname, 'fixtures/session-cache-app'), - type: 'application', - }); - app.loader.loadAll(); - }); - - it('should start app with asyncLocalStorage = true by default', async () => { - assert(app.currentContext === undefined); - const res = await request(app.callback()) - .get('/'); - assert(res.status === 200); - console.log(res.body); - assert(res.body.sessionId === 'mock-session-id-123'); - assert(res.body.traceId); - assert(app.currentContext === undefined); - }); - - it('should access als on global', async () => { - assert(global[Symbol.for('gals#asyncLocalStorage')]); - assert(global[kGALS]); - assert(global[Symbol.for('gals#asyncLocalStorage')] instanceof AsyncLocalStorage); - assert.equal(app.ctxStorage, global[Symbol.for('gals#asyncLocalStorage')]); - assert.equal(app.ctxStorage, getAsyncLocalStorage()); - }); -}); diff --git a/test/asyncLocalStorage.test.ts b/test/asyncLocalStorage.test.ts index 31e6dc37..54298c2a 100644 --- a/test/asyncLocalStorage.test.ts +++ b/test/asyncLocalStorage.test.ts @@ -1,5 +1,6 @@ import { strict as assert } from 'node:assert'; import path from 'node:path'; +import { AsyncLocalStorage } from 'node:async_hooks'; import request from 'supertest'; import { getAsyncLocalStorage, kGALS } from 'gals'; import { Application } from './fixtures/egg'; diff --git a/test/fixtures/egg/index.js b/test/fixtures/egg/index.js index 44655ce4..78417bce 100644 --- a/test/fixtures/egg/index.js +++ b/test/fixtures/egg/index.js @@ -45,4 +45,4 @@ class EggApplication extends EggCore { } } -module.exports.Application = EggApplication; +exports.Application = EggApplication; diff --git a/test/utils.js b/test/utils.js deleted file mode 100644 index ae9250d9..00000000 --- a/test/utils.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict'; - -const path = require('path'); -const EggApplication = require('./fixtures/egg').Application; - -module.exports = { - - getFilepath(name) { - return path.join(__dirname, 'fixtures', name); - }, - - createApp(name, options) { - const baseDir = this.getFilepath(name); - options = options || {}; - options.baseDir = baseDir; - options.type = options.type || 'application'; - - let CustomApplication = EggApplication; - if (options.Application) { - CustomApplication = options.Application; - } - - return new CustomApplication(options); - }, - - symbol: { - view: Symbol('view'), - }, - - sleep(ms) { - return new Promise(resolve => { - setTimeout(resolve, ms); - }); - }, -}; diff --git a/test/utils.ts b/test/utils.ts new file mode 100644 index 00000000..6e77ac57 --- /dev/null +++ b/test/utils.ts @@ -0,0 +1,29 @@ +import path from 'node:path'; +import { setTimeout } from 'node:timers/promises'; +import { Application as EggApplication } from './fixtures/egg'; + +export function getFilepath(name: string) { + return path.join(__dirname, 'fixtures', name); +} + +export function createApp(name, options) { + const baseDir = this.getFilepath(name); + options = options || {}; + options.baseDir = baseDir; + options.type = options.type || 'application'; + + let CustomApplication = EggApplication; + if (options.Application) { + CustomApplication = options.Application; + } + + return new CustomApplication(options); +}; + +export async function sleep(ms: number) { + return await setTimeout(ms); +}; + +export const symbol = { + view: Symbol('view'), +};