Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions tools/egg-bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@
"tsx": "catalog:"
},
"devDependencies": {
"@eggjs/controller-plugin": "workspace:*",
"@eggjs/mock": "workspace:*",
"@eggjs/static": "workspace:*",
"@eggjs/tegg": "workspace:*",
"@eggjs/tegg-config": "workspace:*",
"@eggjs/tegg-plugin": "workspace:*",
"@types/node": "catalog:",
"rimraf": "catalog:",
"typescript": "catalog:",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
interface TeggAppConfig {
keys: string;
security: { csrf: { enable: boolean } };
}

export default (): TeggAppConfig => {
return {
keys: 'tegg-app-keys',
security: {
csrf: {
enable: false,
},
},
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"path": "../modules/foo"
}
]
14 changes: 14 additions & 0 deletions tools/egg-bundler/test/fixtures/apps/tegg-app/config/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
teggConfig: {
package: '@eggjs/tegg-config',
enable: true,
},
tegg: {
package: '@eggjs/tegg-plugin',
enable: true,
},
teggController: {
package: '@eggjs/controller-plugin',
enable: true,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { HTTPController, HTTPMethod, HTTPMethodEnum, HTTPQuery, Inject } from '@eggjs/tegg';

import { FooService } from './FooService.js';

@HTTPController({
path: '/tegg',
})
export class FooController {
@Inject()
fooService: FooService;
Comment on lines +9 to +10
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In TypeScript, when using @Inject() without a constructor, the property should be marked with the definite assignment assertion operator (!) to avoid "Property has no initializer" errors when strictPropertyInitialization is enabled in the compiler options.

Suggested change
@Inject()
fooService: FooService;
@Inject()
fooService!: FooService;


@HTTPMethod({
method: HTTPMethodEnum.GET,
path: '/hello',
})
async hello(@HTTPQuery() name: string): Promise<{ message: string }> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The @httpquery() parameter name can be undefined if the query parameter is missing from the request. It should be marked as optional (name?: string) to be type-safe and avoid potential compilation errors in strict mode.

Suggested change
async hello(@HTTPQuery() name: string): Promise<{ message: string }> {
async hello(@HTTPQuery() name?: string): Promise<{ message: string }> {

return {
message: this.fooService.hello(name || 'world'),
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { AccessLevel, SingletonProto } from '@eggjs/tegg';

@SingletonProto({
accessLevel: AccessLevel.PUBLIC,
})
export class FooService {
hello(name: string): string {
return `hello, ${name}`;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "tegg-app-foo",
"type": "module",
"eggModule": {
"name": "foo"
}
}
13 changes: 13 additions & 0 deletions tools/egg-bundler/test/fixtures/apps/tegg-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "tegg-app",
"version": "1.0.0",
"private": true,
"type": "module",
"dependencies": {
"@eggjs/controller-plugin": "workspace:*",
"@eggjs/tegg": "workspace:*",
"@eggjs/tegg-config": "workspace:*",
"@eggjs/tegg-plugin": "workspace:*",
"egg": "workspace:*"
}
}
3 changes: 3 additions & 0 deletions tools/egg-bundler/test/fixtures/apps/tegg-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../../../../tsconfig.json"
}
23 changes: 23 additions & 0 deletions tools/egg-bundler/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,26 @@ describe('bundle() integration — minimal-app (Phase 2: real @utoo/pack)', () =
// parse tegg decorators reachable from egg's src entry).
});
});

describe('bundle() integration — tegg-app fixture structure', () => {
const TEGG_FIXTURE_BASE = path.join(__dirname, 'fixtures/apps/tegg-app');

it('tegg-app fixture exposes the expected @HTTPController + @SingletonProto module layout', async () => {
// This fixture exercises the tegg plugin path for future T14 coverage of
// real-@utoo/pack tegg bundling. For now we only pin the on-disk shape so
// refactors that rename files are caught here rather than in a live build.
const expected = [
'config/config.default.ts',
'config/module.json',
'config/plugin.ts',
'modules/foo/FooController.ts',
'modules/foo/FooService.ts',
'modules/foo/package.json',
'package.json',
'tsconfig.json',
];
for (const rel of expected) {
await expect(fs.stat(path.join(TEGG_FIXTURE_BASE, rel))).resolves.toBeTruthy();
}
});
});