Skip to content

Commit

Permalink
fix: mv single to @eggjs/core (#5387)
Browse files Browse the repository at this point in the history
eggjs/core#288

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

Based on the comprehensive summary, here are the release notes:

- **New Features**
- Added new CI workflows for different testing clusters and library
testing
  - Enhanced continuous integration configuration

- **Dependency Updates**
  - Updated `@eggjs/core` from version 6.2.13 to 6.3.0

- **Testing Improvements**
  - Added new test scripts for specific test clusters
  - Expanded error handling and logging test coverage
  - Restructured test file organization

- **Code Refactoring**
  - Removed singleton implementation from core library
  - Updated type assertions and import paths
  - Simplified error handling in test cases

- **Chores**
  - Updated GitHub Actions workflows
  - Reorganized test directory structure
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
fengmk2 authored Jan 21, 2025
1 parent 7c90c09 commit b223c7a
Show file tree
Hide file tree
Showing 24 changed files with 289 additions and 781 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/nodejs-cluster1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI cluster1

on:
push:
branches: [ master, next ]
pull_request:
branches: [ master, next ]

jobs:
Job:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, windows-latest'
version: '20'
test: 'npm run ci:cluster1'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
18 changes: 18 additions & 0 deletions .github/workflows/nodejs-cluster2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI cluster2

on:
push:
branches: [ master, next ]
pull_request:
branches: [ master, next ]

jobs:
Job:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, windows-latest'
version: '22'
test: 'npm run ci:cluster2'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
18 changes: 18 additions & 0 deletions .github/workflows/nodejs-lib-core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI lib/core

on:
push:
branches: [ master, next ]
pull_request:
branches: [ master, next ]

jobs:
Job:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, windows-latest'
version: '18, 20'
test: 'npm run ci:lib/core'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
18 changes: 18 additions & 0 deletions .github/workflows/nodejs-lib-plugins.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI lib/plugins

on:
push:
branches: [ master, next ]
pull_request:
branches: [ master, next ]

jobs:
Job:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, windows-latest'
version: '18, 20'
test: 'npm run ci:lib/plugins'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5 changes: 3 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: CI app

on:
push:
Expand All @@ -12,6 +12,7 @@ jobs:
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, macos-latest, windows-latest'
version: '18.19.0, 18, 20, 22'
version: '18, 20, 22'
test: 'npm run ci:app'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"@eggjs/cluster": "^3.0.0",
"@eggjs/cookies": "^3.0.0",
"@eggjs/core": "^6.2.13",
"@eggjs/core": "^6.3.0",
"@eggjs/development": "^4.0.0",
"@eggjs/i18n": "^3.0.1",
"@eggjs/jsonp": "^3.0.0",
Expand Down Expand Up @@ -94,10 +94,15 @@
"test": "egg-bin test",
"test-local": "egg-bin test",
"test:changed": "egg-bin test --changed",
"preci": "npm run clean && npm run lint",
"preci": "npm run clean && npm run lint",
"ci": "egg-bin cov",
"postci": "npm run prepublishOnly && npm run clean",
"prepublishOnly": "tshy && tshy-after && attw --pack --profile node16",
"ci:app": "npm run ci \"test/app/**/*.test.ts,test/*.test.ts\"",
"ci:cluster1": "npm run ci \"test/cluster1/**/*.test.ts\"",
"ci:cluster2": "npm run ci \"test/cluster2/**/*.test.ts\"",
"ci:lib/core": "npm run ci \"test/lib/core/**/*.test.ts\"",
"ci:lib/plugins": "npm run ci \"test/lib/plugins/**/*.test.ts\"",
"site:dev": "cross-env APP_ROOT=./site dumi dev",
"site:build": "cross-env APP_ROOT=./site dumi build",
"site:prettier": "prettier --config site/.prettierrc --ignore-path site/.prettierignore --write \"site/**/*.{js,jsx,tsx,ts,less,md,json}\"",
Expand Down
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ export type {
export * from './lib/egg.js';
export * from './lib/types.js';
export * from './lib/start.js';
export * from './lib/core/singleton.js';

// export singleton
export {
Singleton,
type SingletonCreateMethod,
type SingletonOptions,
} from '@eggjs/core';

// export errors
export * from './lib/error/index.js';
Expand Down
149 changes: 0 additions & 149 deletions src/lib/core/singleton.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/lib/egg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ import {
type HttpClientOptions,
} from './core/httpclient.js';
import { createLoggers } from './core/logger.js';
import {
Singleton, type SingletonCreateMethod, type SingletonOptions,
} from './core/singleton.js';
import { convertObject } from './core/utils.js';
import { BaseContextClass } from './core/base_context_class.js';
import { BaseHookClass } from './core/base_hook_class.js';
Expand Down Expand Up @@ -595,26 +592,6 @@ export class EggApplicationCore extends EggCore {
/* eslint no-empty-function: off */
set proxy(_) {}

/**
* create a singleton instance
* @param {String} name - unique name for singleton
* @param {Function|AsyncFunction} create - method will be invoked when singleton instance create
*/
addSingleton(name: string, create: SingletonCreateMethod) {
const options: SingletonOptions = {
name,
create,
app: this,
};
const singleton = new Singleton(options);
const initPromise = singleton.init();
if (initPromise) {
this.beforeStart(async () => {
await initPromise;
});
}
}

#patchClusterClient(client: any) {
const rawCreate = client.create;
client.create = (...args: any) => {
Expand Down Expand Up @@ -695,13 +672,10 @@ declare module '@eggjs/core' {
inspect(): any;
get currentContext(): EggContext | undefined;
ctxStorage: AsyncLocalStorage<EggContext>;
get logger(): EggLogger;
get coreLogger(): EggLogger;
getLogger(name: string): EggLogger;
createHttpClient(options?: HttpClientOptions): HttpClient;
HttpClient: typeof HttpClient;
get httpClient(): HttpClient;
curl<T = any>(url: HttpClientRequestURL, options?: HttpClientRequestOptions): Promise<HttpClientResponse<T>>;
addSingleton(name: string, create: SingletonCreateMethod): void;
}
}
Loading

0 comments on commit b223c7a

Please sign in to comment.