Skip to content

Commit

Permalink
fix: mv single to @eggjs/core
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jan 20, 2025
1 parent 7c90c09 commit fb3b70f
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 579 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/nodejs-lib-cluster.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI lib/cluster

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, macos-latest, windows-latest'
version: '18.19.0, 18, 20, 22'
test: 'npm run ci:lib/cluster'
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, macos-latest, windows-latest'
version: '18.19.0, 18, 20, 22'
test: 'npm run ci:lib/core'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
18 changes: 18 additions & 0 deletions .github/workflows/nodejs-lib-other.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI lib/other

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, macos-latest, windows-latest'
version: '18.19.0, 18, 20, 22'
test: 'npm run ci:lib/other'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
18 changes: 18 additions & 0 deletions .github/workflows/nodejs-lib-plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI lib/plugin

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, macos-latest, windows-latest'
version: '18.19.0, 18, 20, 22'
test: 'npm run ci:lib/plugin'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
18 changes: 18 additions & 0 deletions .github/workflows/nodejs-other.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI other

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, macos-latest, windows-latest'
version: '18.19.0, 18, 20, 22'
test: 'npm run ci:lib/other'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3 changes: 2 additions & 1 deletion .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 @@ -13,5 +13,6 @@ jobs:
with:
os: 'ubuntu-latest, macos-latest, windows-latest'
version: '18.19.0, 18, 20, 22'
test: 'npm run ci:app'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
10 changes: 8 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,16 @@
"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",
"ci:lib/cluster": "npm run ci test/lib/cluster/**/*.test.ts",
"ci:lib/core": "npm run ci test/lib/core/**/*.test.ts",
"ci:lib/plugin": "npm run ci test/lib/plugin/**/*.test.ts",
"ci:lib/other": "npm run ci test/lib/*.test.ts",
"ci:other": "npm run ci test/*.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;
}
}
2 changes: 1 addition & 1 deletion test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ expectType<Redis>(redis);
expectType<string>(redis.get('foo'));
expectType<string>(redis.getSingletonInstance('client1').get('foo'));
expectType<Redis>(redis.getSingletonInstance('client1'));
// expectType<Redis>(redis.get('client1'));
expectType<Redis>(redis.get('client1') as unknown as Redis);
Loading

0 comments on commit fb3b70f

Please sign in to comment.