Skip to content

Commit 7b3a521

Browse files
authored
fix: load zod json error under esm environment (#4433)
* fix: load zod json error under esm environment * fix: load zod json error under esm environment * fix: test * fix: test * fix: test * fix: test * chore: update * fix: test * fix: test * fix: test * fix: test * fix: test
1 parent e7ad8cd commit 7b3a521

File tree

33 files changed

+596
-649
lines changed

33 files changed

+596
-649
lines changed

.github/workflows/benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
strategy:
2121
matrix:
22-
node-version: ['lts/*']
22+
node-version: ['20.x']
2323

2424
steps:
2525
- uses: actions/checkout@v4

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"ts-jest": "29.2.5",
2020
"ts-node": "10.9.2",
2121
"typedoc": "^0.26.11",
22-
"typescript": "5.3.3",
22+
"typescript": "5.6.3",
2323
"why-is-node-running": "2.3.0",
2424
"zx": "8.2.4"
2525
},

packages/core/src/baseFramework.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,22 @@ export abstract class BaseFramework<
5959
private namespace: string;
6060

6161
@Inject()
62-
loggerService: MidwayLoggerService;
62+
protected loggerService: MidwayLoggerService;
6363

6464
@Inject()
65-
environmentService: MidwayEnvironmentService;
65+
protected environmentService: MidwayEnvironmentService;
6666

6767
@Inject()
68-
configService: MidwayConfigService;
68+
protected configService: MidwayConfigService;
6969

7070
@Inject()
71-
informationService: MidwayInformationService;
71+
protected informationService: MidwayInformationService;
7272

7373
@Inject()
74-
middlewareService: MidwayMiddlewareService<CTX, ResOrNext, Next>;
74+
protected middlewareService: MidwayMiddlewareService<CTX, ResOrNext, Next>;
7575

7676
@Inject()
77-
mockService: MidwayMockService;
77+
protected mockService: MidwayMockService;
7878

7979
constructor(readonly applicationContext: IMidwayGlobalContainer) {}
8080

packages/core/src/util/index.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ export const safeRequire = (p, enabledCache = true) => {
5555
}
5656
};
5757

58-
const innerLoadModuleCache = {};
59-
6058
/**
6159
* load module, and it can be chosen commonjs or esm mode
6260
* @param p
@@ -91,18 +89,9 @@ export const loadModule = async (
9189
} else {
9290
// if json file, import need add options
9391
if (p.endsWith('.json')) {
94-
/**
95-
* attention: import json not support under nodejs 16
96-
* use readFileSync instead
97-
*/
98-
if (!innerLoadModuleCache[p]) {
99-
// return (await import(p, { assert: { type: 'json' } })).default;
100-
const content = readFileSync(p, {
101-
encoding: 'utf-8',
102-
});
103-
innerLoadModuleCache[p] = JSON.parse(content);
104-
}
105-
return innerLoadModuleCache[p];
92+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
93+
// @ts-ignore
94+
return (await import(p, { with: { type: 'json' } })).default;
10695
} else {
10796
return await import(pathToFileURL(p).href);
10897
}

packages/core/test/common/applicationManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('test/common/applicationManager.test.ts', () => {
2020
}
2121

2222
const framework = new CustomFramework1({} as any);
23-
framework.mockService = mockService;
23+
framework['mockService'] = mockService;
2424
await framework.initialize();
2525

2626
manager.addFramework('test', framework);

packages/core/test/context/container.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe('/test/context/container.test.ts', () => {
137137
tt: any;
138138

139139
@App()
140-
a: any;
140+
declare a: any;
141141

142142
@Plugin()
143143
bb: any;

packages/core/test/decorator/metadataManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('MetadataManager.test.ts', () => {
143143
public method() {}
144144

145145
@TestProperty()
146-
public property: string;
146+
public declare property: string;
147147
}
148148

149149
new Child().method();

packages/core/test/fixtures/class_sample.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class SubCustom extends ParentCustom {
105105
tt: any;
106106

107107
@App()
108-
a: any;
108+
declare a: any;
109109

110110
@Plugin()
111111
bb: any;

packages/core/tsconfig.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
"compilerOptions": {
55
"rootDir": "src",
66
"outDir": "dist",
7-
"module": "Node16",
8-
"moduleResolution": "Node16"
97
},
108
"include": [
119
"./src/**/*.ts"

packages/faas/src/framework.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ import {
1313
ContextMiddlewareManager,
1414
FunctionMiddleware,
1515
IMidwayBootstrapOptions,
16-
MidwayEnvironmentService,
17-
MidwayMiddlewareService,
1816
MidwayServerlessFunctionService,
1917
RouterInfo,
2018
PathToRegexpUtil,
2119
Framework,
22-
Inject,
2320
WEB_RESPONSE_CONTENT_TYPE,
2421
WEB_RESPONSE_HEADER,
2522
WEB_RESPONSE_HTTP_CODE,
@@ -50,9 +47,9 @@ export class MidwayFaaSFramework extends BaseFramework<
5047
> {
5148
protected defaultHandlerMethod = 'handler';
5249
protected funMappingStore: Map<string, RouterInfo> = new Map();
53-
protected logger;
50+
protected declare logger;
5451
private lock = new SimpleLock();
55-
public app: Application;
52+
public declare app: Application;
5653
private isReplaceLogger =
5754
process.env['MIDWAY_SERVERLESS_REPLACE_LOGGER'] === 'true';
5855
private developmentRun = false;
@@ -65,12 +62,6 @@ export class MidwayFaaSFramework extends BaseFramework<
6562
private legacyVersion = false;
6663
private loadedFunction = false;
6764

68-
@Inject()
69-
environmentService: MidwayEnvironmentService;
70-
71-
@Inject()
72-
middlewareService: MidwayMiddlewareService<Context, any>;
73-
7465
configure(options: IFaaSConfigurationOptions) {
7566
const faasConfig = this.configService.getConfiguration('faas') ?? {};
7667
if (options || faasConfig['developmentRun']) {

0 commit comments

Comments
 (0)