Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mv single to @eggjs/core #5387

Merged
merged 8 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
fengmk2 marked this conversation as resolved.
Show resolved Hide resolved

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-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, macos-latest, windows-latest'
version: '18.19.0, 18, 20, 22'
test: 'npm run ci:lib/plugins'
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
fengmk2 marked this conversation as resolved.
Show resolved Hide resolved
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/plugins": "npm run ci \"test/lib/plugins/**/*.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;
}
}
7 changes: 2 additions & 5 deletions test/app/extend/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ describe('test/app/extend/agent.test.ts', () => {
assert(config.foo === 'bar');
assert(config.foo2 === 'bar2');

try {
assert.throws(() => {
app.agent.dataServiceAsync.createInstance({ foo: 'bar2' });
throw new Error('should not execute');
} catch (err: any) {
assert(err.message === 'egg:singleton dataServiceAsync only support create asynchronous, please use createInstanceAsync');
}
}, /dataServiceAsync only support synchronous creation, please use createInstanceAsync/);

const ds4 = await app.agent.dataServiceAsync.createInstanceAsync({ foo: 'bar2' });
config = await ds4.getConfig();
Expand Down
Loading
Loading