Skip to content

fix: remove egg module#438

Merged
akitaSummer merged 1 commit intomasterfrom
fix/remove_service_worker_egg_module
Apr 18, 2026
Merged

fix: remove egg module#438
akitaSummer merged 1 commit intomasterfrom
fix/remove_service_worker_egg_module

Conversation

@akitaSummer
Copy link
Copy Markdown
Contributor

@akitaSummer akitaSummer commented Apr 18, 2026

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

Summary by CodeRabbit

  • Chores
    • Package version updated to 3.78.3; removed legacy module declaration from the package manifest.
    • Removed the package entry-point export for ServiceWorkerRunner (no longer accessible via the main package entry).
  • Refactor
    • Internal lifecycle and runtime behavior updated: added lifecycle registration, context-driven event handling, and a standalone object factory for improved runtime management.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 18, 2026

Warning

Rate limit exceeded

@akitaSummer has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 34 minutes and 53 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 34 minutes and 53 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: feccc50b-1691-4b8e-ade8-1d5905fade95

📥 Commits

Reviewing files that changed from the base of the PR and between 256ee3c and 190fe83.

📒 Files selected for processing (7)
  • core/standalone-decorator/src/event/EventHandler.ts
  • standalone/service-worker/index.ts
  • standalone/service-worker/package.json
  • standalone/service-worker/src/ServiceWorkerApp.ts
  • standalone/service-worker/src/ServiceWorkerRunner.ts
  • standalone/service-worker/src/StandaloneEggObjectFactory.ts
  • standalone/service-worker/src/hook/LoadUnitInnerClassHook.ts
📝 Walkthrough

Walkthrough

Removed ServiceWorkerRunner from the package entry exports, downgraded package version and removed eggModule from package.json, added LoadUnitInnerClassHook, StandaloneEggObjectFactory, and wired the hook into ServiceWorkerApp; ServiceWorkerRunner now reads fetch events from request context and injects StandaloneEggObjectFactory.

Changes

Cohort / File(s) Summary
Package manifest & entry
standalone/service-worker/package.json, standalone/service-worker/index.ts
Version changed 3.78.73.78.3; removed eggModule block; removed re-export of ./src/ServiceWorkerRunner from package entry.
Lifecycle hook
standalone/service-worker/src/hook/LoadUnitInnerClassHook.ts
Added LoadUnitInnerClassHook implementing LifecycleHook<LoadUnitLifecycleContext, LoadUnit> that on postCreate creates and registers configured inner-class prototypes for StandaloneLoadUnitType.
App wiring
standalone/service-worker/src/ServiceWorkerApp.ts
Registered new LoadUnitInnerClassHook (using StandaloneEggObjectFactory, ServiceWorkerRunner, FetchEventHandler) during construction and explicitly deletes it on destroy().
Runner behavior
standalone/service-worker/src/ServiceWorkerRunner.ts
main() now obtains fetch event from request-local context (ContextHandler.getContext() + ContextProtoProperty.Event.contextKey), adds runtime checks/errors, removes injected event field, and injects standaloneEggObjectFactory.
Factory class
standalone/service-worker/src/StandaloneEggObjectFactory.ts
Added StandaloneEggObjectFactory as a @SingletonProto class extending EggObjectFactory with configured protoImplType and accessLevel.
Types
core/standalone-decorator/src/event/EventHandler.ts
Added exported FetchEventLike interface describing type, request, respondWith(...), and optional waitUntil(...).

Sequence Diagram(s)

sequenceDiagram
  participant App as "ServiceWorkerApp"
  participant Loader as "LoadUnitLifecycle"
  participant Hook as "LoadUnitInnerClassHook"
  participant Creator as "EggPrototypeCreatorFactory"
  participant Registry as "EggPrototypeFactory"
  participant Runner as "ServiceWorkerRunner"
  participant Context as "Request Context"

  App->>Loader: register LoadUnitInnerClassHook
  Note over App,Hook: Hook configured with inner classes

  Loader->>Hook: postCreate(loadUnit)
  alt loadUnit.type == StandaloneLoadUnitType
    Hook->>Creator: createProto(clazz, loadUnit)
    Creator-->>Hook: proto (async)
    Hook->>Registry: registerPrototype(proto, loadUnit)
  end

  Runner->>Context: ContextHandler.getContext()
  Context-->>Runner: request-local context with FetchEvent
  Runner->>Runner: validate fetch event, lookup handler by event.type
  Runner->>FetchEventHandler: dispatch fetch handling
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • killagu
  • gxkl

Poem

🐰 A tiny hook hops into place,
Inner prototypes find their space,
Runner listens to context calls,
Eggs assemble in the halls,
Service starts with a gentle pace 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: remove egg module' directly relates to the main changes: removing eggModule from package.json and ServiceWorkerRunner re-export, while implementing lifecycle hook infrastructure.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/remove_service_worker_egg_module

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request removes the ServiceWorkerRunner class and its export, deletes the eggModule configuration, and downgrades the package version from 3.78.7 to 3.78.3. The removal of ServiceWorkerRunner is identified as a critical issue because ServiceWorkerApp relies on it to dispatch events. Furthermore, the version downgrade in package.json is flagged as a likely mistake that could cause dependency resolution issues.

I am having trouble creating individual review comments. Click here to see my feedback.

standalone/service-worker/src/ServiceWorkerRunner.ts (1-16)

high

Removing the ServiceWorkerRunner class will break the core functionality of ServiceWorkerApp. The Runner instance initialized in ServiceWorkerApp (line 76) and executed in handleEvent (line 91) relies on finding a class decorated with @Runner() within the load units to act as the entry point. Without this runner, there is no logic to dispatch incoming events to their respective handlers (such as FetchEventHandler).

standalone/service-worker/package.json (4)

medium

The version is being downgraded from 3.78.7 to 3.78.3. This is likely a mistake as package versions should typically be incremented to ensure proper dependency resolution and consistency with other packages in the repository (which are currently at 3.78.7).

@akitaSummer akitaSummer force-pushed the fix/remove_service_worker_egg_module branch from bc4b8f0 to bef6989 Compare April 18, 2026 10:28
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
standalone/service-worker/package.json (1)

1-78: ⚠️ Potential issue | 🔴 Critical

Add eggModule field to package.json — critical for module loading.

The package.json is missing the required eggModule field. When ServiceWorkerApp registers the framework dependency (baseDir: standalone/service-worker), ModuleLoadUnit.createModule() will attempt to load it as a module and assert that pkg.eggModule exists (core/metadata/src/impl/ModuleLoadUnit.ts:302). Without it, the loader will fail with "module config not found in package".

LoadUnitInnerClassHook([ServiceWorkerRunner]) does not replace module registration — it only registers inner classes within an already-loaded module. The ContextProtoLoadUnitHook('serviceWorker') depends on a LoadUnit with name 'serviceWorker' existing, which cannot be created without eggModule.

Add "eggModule": { "name": "serviceWorker" } to package.json.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@standalone/service-worker/package.json` around lines 1 - 78, The package.json
is missing the required eggModule entry which causes ModuleLoadUnit.createModule
to assert (see ModuleLoadUnit.createModule) when ServiceWorkerApp registers the
framework dependency; add an "eggModule" object to package.json with the module
name "serviceWorker" (e.g. "eggModule": { "name": "serviceWorker" }) so the
LoadUnit for 'serviceWorker' can be created and hooks like
LoadUnitInnerClassHook([ServiceWorkerRunner]) and
ContextProtoLoadUnitHook('serviceWorker') can register correctly.
🧹 Nitpick comments (2)
standalone/service-worker/src/hook/LoadUnitInnerClassHook.ts (2)

14-19: Consider parallelizing createProto calls.

The inner loop awaits each createProto sequentially. Since each call is independent per clazz, Promise.all would let them run concurrently. Minor, and only matters if innerClasses grows beyond [ServiceWorkerRunner].

♻️ Proposed refactor
-    for (const clazz of this.innerClasses) {
-      const protos = await EggPrototypeCreatorFactory.createProto(clazz, loadUnit);
-      for (const proto of protos) {
-        EggPrototypeFactory.instance.registerPrototype(proto, loadUnit);
-      }
-    }
+    const allProtos = await Promise.all(
+      this.innerClasses.map(clazz => EggPrototypeCreatorFactory.createProto(clazz, loadUnit)),
+    );
+    for (const protos of allProtos) {
+      for (const proto of protos) {
+        EggPrototypeFactory.instance.registerPrototype(proto, loadUnit);
+      }
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@standalone/service-worker/src/hook/LoadUnitInnerClassHook.ts` around lines 14
- 19, The loop in LoadUnitInnerClassHook is awaiting
EggPrototypeCreatorFactory.createProto(clazz, loadUnit) sequentially over
this.innerClasses; change it to launch all createProto calls concurrently (e.g.,
map this.innerClasses to an array of promises from
EggPrototypeCreatorFactory.createProto), await Promise.all to get the protos
results, then iterate the combined results and call
EggPrototypeFactory.instance.registerPrototype(proto, loadUnit) for each proto;
ensure you preserve the existing registerPrototype call and handle the nested
arrays of protos returned per clazz when flattening the Promise.all result.

1-3: Align imports with codebase conventions.

The factories EggPrototypeCreatorFactory and EggPrototypeFactory should be imported from @eggjs/tegg-metadata (not @eggjs/tegg/helper) for consistency with plugin/tegg/lib/AppLoadUnit.ts, standalone/standalone/src/StandaloneLoadUnit.ts, and other modules in the repository. Type-only imports like LoadUnit and LoadUnitLifecycleContext should use import type and come from @eggjs/tegg-types.

Suggested fix
import { EggProtoImplClass, LifecycleHook } from '@eggjs/tegg';
import { EggPrototypeCreatorFactory, EggPrototypeFactory } from '@eggjs/tegg-metadata';
import type { LoadUnit, LoadUnitLifecycleContext } from '@eggjs/tegg-types';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@standalone/service-worker/src/hook/LoadUnitInnerClassHook.ts` around lines 1
- 3, The imports are not aligned with project conventions: change the non-type
imports for EggPrototypeCreatorFactory and EggPrototypeFactory to come from
'@eggjs/tegg-metadata' (instead of '@eggjs/tegg/helper') and move LoadUnit and
LoadUnitLifecycleContext to be type-only imports from '@eggjs/tegg-types' using
`import type`; update the import statements at the top of
LoadUnitInnerClassHook.ts where EggProtoImplClass, LifecycleHook,
EggPrototypeCreatorFactory, EggPrototypeFactory, LoadUnit, and
LoadUnitLifecycleContext are declared so the factories use
'@eggjs/tegg-metadata' and the two lifecycle/type symbols use `import type` from
'@eggjs/tegg-types'.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@standalone/service-worker/package.json`:
- Line 4: The package.json "version" field in the standalone/service-worker
package is incorrectly set to "3.78.3" while its dependencies and sibling
packages use 3.78.7; update the "version" value to "3.78.7" (or a higher
compatible release) so it matches the monorepo and the dependency range (e.g.,
dependencies referencing ^3.78.7), ensuring the package can be published and
release consistency is preserved.

In `@standalone/service-worker/src/hook/LoadUnitInnerClassHook.ts`:
- Around line 12-20: Replace the hard-coded string comparison in
LoadUnitInnerClassHook.postCreate with the exported constant: import
StandaloneLoadUnitType from the package and change the guard from loadUnit.type
!== 'StandaloneLoadUnitType' to loadUnit.type !== StandaloneLoadUnitType; also
update the standalone package public exports by adding export * from
'./src/StandaloneLoadUnit'; to standalone/standalone/index.ts so
StandaloneLoadUnitType is available from '@eggjs/tegg-standalone'.

In `@standalone/service-worker/src/ServiceWorkerApp.ts`:
- Line 58: Registering a new LoadUnitInnerClassHook([ServiceWorkerRunner]) via
LoadUnitLifecycleUtil.registerLifecycle without keeping the instance leaks the
hook; retain the created hook instance in the ServiceWorkerApp (e.g., a private
field like lifecycleHook) when you call LoadUnitLifecycleUtil.registerLifecycle,
and then call LoadUnitLifecycleUtil.deleteLifecycle(this.lifecycleHook) from the
destroy() method to unregister it; ensure the field is initialized where
registerLifecycle is currently called and cleaned up (set to null) after
deleteLifecycle to avoid duplicate firings on re-instantiation.

---

Outside diff comments:
In `@standalone/service-worker/package.json`:
- Around line 1-78: The package.json is missing the required eggModule entry
which causes ModuleLoadUnit.createModule to assert (see
ModuleLoadUnit.createModule) when ServiceWorkerApp registers the framework
dependency; add an "eggModule" object to package.json with the module name
"serviceWorker" (e.g. "eggModule": { "name": "serviceWorker" }) so the LoadUnit
for 'serviceWorker' can be created and hooks like
LoadUnitInnerClassHook([ServiceWorkerRunner]) and
ContextProtoLoadUnitHook('serviceWorker') can register correctly.

---

Nitpick comments:
In `@standalone/service-worker/src/hook/LoadUnitInnerClassHook.ts`:
- Around line 14-19: The loop in LoadUnitInnerClassHook is awaiting
EggPrototypeCreatorFactory.createProto(clazz, loadUnit) sequentially over
this.innerClasses; change it to launch all createProto calls concurrently (e.g.,
map this.innerClasses to an array of promises from
EggPrototypeCreatorFactory.createProto), await Promise.all to get the protos
results, then iterate the combined results and call
EggPrototypeFactory.instance.registerPrototype(proto, loadUnit) for each proto;
ensure you preserve the existing registerPrototype call and handle the nested
arrays of protos returned per clazz when flattening the Promise.all result.
- Around line 1-3: The imports are not aligned with project conventions: change
the non-type imports for EggPrototypeCreatorFactory and EggPrototypeFactory to
come from '@eggjs/tegg-metadata' (instead of '@eggjs/tegg/helper') and move
LoadUnit and LoadUnitLifecycleContext to be type-only imports from
'@eggjs/tegg-types' using `import type`; update the import statements at the top
of LoadUnitInnerClassHook.ts where EggProtoImplClass, LifecycleHook,
EggPrototypeCreatorFactory, EggPrototypeFactory, LoadUnit, and
LoadUnitLifecycleContext are declared so the factories use
'@eggjs/tegg-metadata' and the two lifecycle/type symbols use `import type` from
'@eggjs/tegg-types'.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ecc4f753-9cf8-41c2-b4aa-0f0320e5de27

📥 Commits

Reviewing files that changed from the base of the PR and between edd12e9 and bef6989.

📒 Files selected for processing (4)
  • standalone/service-worker/index.ts
  • standalone/service-worker/package.json
  • standalone/service-worker/src/ServiceWorkerApp.ts
  • standalone/service-worker/src/hook/LoadUnitInnerClassHook.ts
💤 Files with no reviewable changes (1)
  • standalone/service-worker/index.ts

Comment thread standalone/service-worker/package.json
Comment thread standalone/service-worker/src/hook/LoadUnitInnerClassHook.ts
Comment thread standalone/service-worker/src/ServiceWorkerApp.ts Outdated
@akitaSummer akitaSummer force-pushed the fix/remove_service_worker_egg_module branch from 7f32797 to a1ec67c Compare April 18, 2026 10:55
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
standalone/service-worker/src/StandaloneEggObjectFactory.ts (1)

7-10: Set the singleton name explicitly to match the injection token.

ServiceWorkerRunner injects standaloneEggObjectFactory by name, but this prototype currently relies on derived naming. Make the DI contract explicit, mirroring the base EggObjectFactory pattern.

Proposed fix
 `@SingletonProto`({
   protoImplType: EGG_OBJECT_FACTORY_PROTO_IMPLE_TYPE,
+  name: 'standaloneEggObjectFactory',
   accessLevel: AccessLevel.PRIVATE,
 })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@standalone/service-worker/src/StandaloneEggObjectFactory.ts` around lines 7 -
10, The SingletonProto decorator on class StandaloneEggObjectFactory currently
relies on derived naming; explicitly set its singleton name to the injection
token used by ServiceWorkerRunner by adding the name property to the decorator
(match "standaloneEggObjectFactory"), following the same pattern as the base
EggObjectFactory; update the `@SingletonProto`(...) invocation to include name:
"standaloneEggObjectFactory" so DI resolves correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@standalone/service-worker/src/ServiceWorkerRunner.ts`:
- Around line 2-12: The ServiceWorkerRunner class must explicitly implement the
MainRunner<unknown> interface: update the class declaration for
ServiceWorkerRunner (the class annotated with `@Runner`()) to implement
MainRunner<unknown> so its signature matches the standalone runner contract and
aligns with the existing async main(): Promise<unknown> method; ensure imports
include MainRunner if missing and keep the `@Runner`() decorator and existing main
method intact.

In `@standalone/service-worker/src/StandaloneEggObjectFactory.ts`:
- Around line 1-5: The import uses a deep /src path and a non-public symbol
which will break in published builds; add a public export for
EGG_OBJECT_FACTORY_PROTO_IMPLE_TYPE in the package's root export (e.g.,
core/dynamic-inject-runtime/index.ts) and then update the import in
StandaloneEggObjectFactory.ts to import { EGG_OBJECT_FACTORY_PROTO_IMPLE_TYPE }
from '@eggjs/tegg-dynamic-inject-runtime' (instead of from
.../src/EggObjectFactoryPrototype), ensuring you reference the symbol name
EGG_OBJECT_FACTORY_PROTO_IMPLE_TYPE and keep the rest of the existing imports
(AccessLevel, SingletonProto, EggObjectFactory) unchanged.

---

Nitpick comments:
In `@standalone/service-worker/src/StandaloneEggObjectFactory.ts`:
- Around line 7-10: The SingletonProto decorator on class
StandaloneEggObjectFactory currently relies on derived naming; explicitly set
its singleton name to the injection token used by ServiceWorkerRunner by adding
the name property to the decorator (match "standaloneEggObjectFactory"),
following the same pattern as the base EggObjectFactory; update the
`@SingletonProto`(...) invocation to include name: "standaloneEggObjectFactory" so
DI resolves correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8438385a-9847-4334-b16b-2af9b3ddbe8f

📥 Commits

Reviewing files that changed from the base of the PR and between bef6989 and 256ee3c.

📒 Files selected for processing (7)
  • core/standalone-decorator/src/event/EventHandler.ts
  • standalone/service-worker/index.ts
  • standalone/service-worker/package.json
  • standalone/service-worker/src/ServiceWorkerApp.ts
  • standalone/service-worker/src/ServiceWorkerRunner.ts
  • standalone/service-worker/src/StandaloneEggObjectFactory.ts
  • standalone/service-worker/src/hook/LoadUnitInnerClassHook.ts
💤 Files with no reviewable changes (1)
  • standalone/service-worker/index.ts
✅ Files skipped from review due to trivial changes (2)
  • core/standalone-decorator/src/event/EventHandler.ts
  • standalone/service-worker/package.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • standalone/service-worker/src/hook/LoadUnitInnerClassHook.ts
  • standalone/service-worker/src/ServiceWorkerApp.ts

Comment thread standalone/service-worker/src/ServiceWorkerRunner.ts
Comment thread standalone/service-worker/src/StandaloneEggObjectFactory.ts
@akitaSummer akitaSummer force-pushed the fix/remove_service_worker_egg_module branch from 4c1a9d3 to 190fe83 Compare April 18, 2026 13:24
@akitaSummer akitaSummer merged commit c82c26e into master Apr 18, 2026
12 checks passed
@akitaSummer akitaSummer deleted the fix/remove_service_worker_egg_module branch April 18, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant