Skip to content

feat: add @eggjs/typings package#5896

Merged
killagu merged 1 commit intoeggjs:nextfrom
killagu:egg-15-typings
Apr 26, 2026
Merged

feat: add @eggjs/typings package#5896
killagu merged 1 commit intoeggjs:nextfrom
killagu:egg-15-typings

Conversation

@killagu
Copy link
Copy Markdown
Contributor

@killagu killagu commented Apr 26, 2026

关联 EGG-15。

Summary:

  • Add @eggjs/typings as a shared workspace package for BundleModuleLoader and global augmentation.
  • Make @eggjs/core load the shared global augmentation entry so the global bundle loader type is available without depending on core internals from other packages.
  • Document the shared typings package and global type conventions in AGENTS.md, CLAUDE.md, and wiki pages.
  • Keep the PR scoped to type ownership and documentation; runtime import behavior and bundle import tests are intentionally left out of this PR.

Local checks:

  • pnpm --filter @eggjs/typings run typecheck
  • pnpm --filter @eggjs/core run typecheck
  • pnpm --filter @eggjs/utils run typecheck
  • pnpm -r --if-present run typecheck
  • pnpm exec oxfmt --check AGENTS.md CLAUDE.md packages/typings/package.json packages/typings/src/index.ts packages/typings/src/global.ts packages/typings/tsconfig.json packages/typings/tsdown.config.ts packages/core/package.json packages/core/src/index.ts tsconfig.json wiki/index.md wiki/log.md wiki/packages/typings.md
  • pnpm exec oxlint --type-aware --type-check --quiet packages/typings/src packages/core/src/index.ts
  • pnpm --filter @eggjs/typings exec tsdown
  • pnpm --filter @eggjs/core exec tsdown
  • pnpm --filter @eggjs/typings exec publint

Note: pnpm run typecheck still exits before workspace checks because ut run clean-dist calls clean and reports ERROR Script 'clean' not found in package.json, so the direct workspace typecheck command above was used for workspace verification.

Summary by CodeRabbit

  • New Features

    • Added a shared TypeScript typings package exposing a BundleModuleLoader type and a global type augmentation for cross-package consumption
    • Core package now includes the shared typings augmentation so consumers receive the global types automatically
  • Documentation

    • Added contributor guidance and wiki updates describing the typings package, global type conventions, and import usage

Copilot AI review requested due to automatic review settings April 26, 2026 12:34
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 26, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a new @eggjs/typings package with exported type and a global augmentation, wires packages/core to import the augmentation, updates TypeScript project references, and adds documentation and wiki entries describing the new typings and guidance for global augmentations.

Changes

Cohort / File(s) Summary
Typings Package Manifest & Config
packages/typings/package.json, packages/typings/tsconfig.json, packages/typings/tsdown.config.ts
Adds new package manifest (ESM, exports for . and ./global, publish config), project tsconfig, and tsdown config for building/type output.
Typings Sources
packages/typings/src/index.ts, packages/typings/src/global.ts
Introduces exported BundleModuleLoader type and a declare global augmentation for globalThis.__EGG_BUNDLE_MODULE_LOADER__.
Core Package Integration
packages/core/package.json, packages/core/src/index.ts
Adds @eggjs/typings as a workspace dependency and a side-effect import @eggjs/typings/global in core entrypoint.
TypeScript Build Graph
tsconfig.json
Adds ./packages/typings to composite project references.
Documentation & Wiki
AGENTS.md, CLAUDE.md, wiki/index.md, wiki/log.md, wiki/packages/typings.md
Adds contributor guidance for TypeScript global augmentations, links the typings package in docs, and records the change in wiki/log.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • jerryliang64
  • fengmk2
  • gxkl

Poem

🐰 I hop through code with a tiny type bag,

I plant a global where no runtimes lag,
Bundle loader named, a gentle little sign,
Shared typings placed where many projects dine,
Hooray — nibble, bundle, and ship with a carrot wine! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add @eggjs/typings package' directly and accurately describes the main change in the PR: introducing a new shared typings package.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.52%. Comparing base (0b6c9fb) to head (8501dec).
⚠️ Report is 1 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #5896   +/-   ##
=======================================
  Coverage   85.52%   85.52%           
=======================================
  Files         662      662           
  Lines       18863    18863           
  Branches     3658     3658           
=======================================
  Hits        16132    16132           
  Misses       2360     2360           
  Partials      371      371           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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 introduces a new @eggjs/typings package and implements a bundle module loader in @eggjs/utils to allow intercepting module imports via a global loader. The importModule function was updated to support this loader, including logic for path normalization and handling transpiled module shapes. Review feedback suggests refining the module unwrapping logic to include function types and ensure safer property access when handling 'double default' exports.

Comment thread packages/utils/src/import.ts Outdated
Comment thread packages/utils/src/import.ts Outdated
Copy link
Copy Markdown
Contributor

@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.

🧹 Nitpick comments (2)
packages/utils/src/import.ts (2)

414-423: Optional: factor the export-unwrap logic into a helper.

The unwrap pattern here is the third copy in this file — almost identical to the snapshot-loader branch (lines 428-436) and the ESM branch (lines 453-485), differing only in defensive typeof obj === 'object' checks. A small private helper, e.g. unwrapModule(obj, importDefaultOnly), would keep all three branches in lockstep so a future fix to the interop heuristic doesn't have to be made in three places.

Not blocking — current behavior is consistent with the test matrix.

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

In `@packages/utils/src/import.ts` around lines 414 - 423, Extract the repeated
export-unwrapping logic into a small private helper function (e.g.
unwrapModule(obj, importDefaultOnly)) and replace the three in-place copies (the
one inside the _bundleModuleLoader branch that calls
normalizeBundleModulePath(filepath) and checks options?.importDefaultOnly, the
snapshot-loader branch, and the ESM branch) with calls to that helper; the
helper should perform the same checks currently present (detect
obj?.default?.__esModule === true && 'default' in obj, and when
importDefaultOnly and obj is an object return obj.default) so behavior remains
identical while centralizing the heuristic for future fixes.

409-411: Minor: setBundleModuleLoader(undefined) leaves the property defined on globalThis.

Assigning undefined keeps __EGG_BUNDLE_MODULE_LOADER__ as an own property of globalThis (with value undefined). The runtime check on line 415 still treats it as falsy, so behavior is correct. Consider delete globalThis.__EGG_BUNDLE_MODULE_LOADER__ when loader === undefined if you want a clean tear-down (e.g. for tests, snapshot inspectors). Purely cosmetic.

♻️ Optional cleanup
 export function setBundleModuleLoader(loader: BundleModuleLoader | undefined): void {
-  globalThis.__EGG_BUNDLE_MODULE_LOADER__ = loader;
+  if (loader === undefined) {
+    delete globalThis.__EGG_BUNDLE_MODULE_LOADER__;
+  } else {
+    globalThis.__EGG_BUNDLE_MODULE_LOADER__ = loader;
+  }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/utils/src/import.ts` around lines 409 - 411, The setter
setBundleModuleLoader currently assigns undefined to
globalThis.__EGG_BUNDLE_MODULE_LOADER__, leaving the property present; change
setBundleModuleLoader to delete globalThis.__EGG_BUNDLE_MODULE_LOADER__ when
loader === undefined and only assign the loader value when it's not undefined so
tests/snapshots see a clean teardown; reference function name
setBundleModuleLoader and property __EGG_BUNDLE_MODULE_LOADER__.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/utils/src/import.ts`:
- Around line 414-423: Extract the repeated export-unwrapping logic into a small
private helper function (e.g. unwrapModule(obj, importDefaultOnly)) and replace
the three in-place copies (the one inside the _bundleModuleLoader branch that
calls normalizeBundleModulePath(filepath) and checks options?.importDefaultOnly,
the snapshot-loader branch, and the ESM branch) with calls to that helper; the
helper should perform the same checks currently present (detect
obj?.default?.__esModule === true && 'default' in obj, and when
importDefaultOnly and obj is an object return obj.default) so behavior remains
identical while centralizing the heuristic for future fixes.
- Around line 409-411: The setter setBundleModuleLoader currently assigns
undefined to globalThis.__EGG_BUNDLE_MODULE_LOADER__, leaving the property
present; change setBundleModuleLoader to delete
globalThis.__EGG_BUNDLE_MODULE_LOADER__ when loader === undefined and only
assign the loader value when it's not undefined so tests/snapshots see a clean
teardown; reference function name setBundleModuleLoader and property
__EGG_BUNDLE_MODULE_LOADER__.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: af43da8f-b4c4-4d8f-9d0b-c8ad88f37c1b

📥 Commits

Reviewing files that changed from the base of the PR and between 0b6c9fb and 75cedaf.

⛔ Files ignored due to path filters (1)
  • packages/utils/test/__snapshots__/index.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (11)
  • packages/core/package.json
  • packages/core/src/index.ts
  • packages/typings/package.json
  • packages/typings/src/global.ts
  • packages/typings/src/index.ts
  • packages/typings/tsconfig.json
  • packages/typings/tsdown.config.ts
  • packages/utils/package.json
  • packages/utils/src/import.ts
  • packages/utils/test/bundle-import.test.ts
  • tsconfig.json

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new shared workspace package @eggjs/typings to centralize cross-package types and a global augmentation entry, then wires it into @eggjs/utils and @eggjs/core to support a global bundle module loader hook.

Changes:

  • Add new @eggjs/typings package with BundleModuleLoader type + global augmentation entry (@eggjs/typings/global).
  • Update @eggjs/utils import utilities to use the shared typings and add setBundleModuleLoader() + bundle-loader interception logic in importModule().
  • Ensure @eggjs/core loads the shared global augmentation and add test coverage + snapshot updates for the new utils export.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tsconfig.json Adds packages/typings as a TS project reference.
packages/utils/src/import.ts Introduces bundle loader global hook, consumes @eggjs/typings, and intercepts importModule().
packages/utils/package.json Adds @eggjs/typings workspace dependency.
packages/utils/test/bundle-import.test.ts Adds coverage for bundle loader behavior (fallback, default-only, virtual specifiers, Windows path normalization).
packages/utils/test/snapshots/index.test.ts.snap Updates export snapshot to include setBundleModuleLoader.
packages/typings/package.json New package metadata/exports (including ./global subpath).
packages/typings/src/index.ts Defines BundleModuleLoader type.
packages/typings/src/global.ts Declares globalThis.__EGG_BUNDLE_MODULE_LOADER__ augmentation.
packages/typings/tsconfig.json TS config extending repo root.
packages/typings/tsdown.config.ts Build entries for index and global.
packages/core/src/index.ts Loads @eggjs/typings/global to ensure augmentation is applied.
packages/core/package.json Adds @eggjs/typings workspace dependency.

Comment thread packages/utils/src/import.ts Outdated
Copy link
Copy Markdown
Contributor

@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.

🧹 Nitpick comments (1)
packages/utils/src/import.ts (1)

7-9: Optional: collapse into a single re-export.

import type { BundleModuleLoader } is only used as a parameter type annotation on setBundleModuleLoader (Line 438), which under TypeScript's isolatedModules/erasable-syntax rules does not require a separate import — a single export type re-export is enough since you can reference re-exported types within the same file when using --isolatedModules. If you'd rather keep both for clarity, leave as-is.

♻️ Proposed simplification
 import '@eggjs/typings/global';
-import type { BundleModuleLoader } from '@eggjs/typings';
-export type { BundleModuleLoader } from '@eggjs/typings';
+import type { BundleModuleLoader } from '@eggjs/typings';
+export type { BundleModuleLoader };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/utils/src/import.ts` around lines 7 - 9, Collapse the two separate
imports into a single type re-export: keep the side-effect import "import
'@eggjs/typings/global';" but remove the separate "import type {
BundleModuleLoader }" and rely on "export type { BundleModuleLoader }" only;
this lets references like the parameter type on setBundleModuleLoader use the
re-exported BundleModuleLoader under isolatedModules/erasable-syntax rules while
preserving the global typings import.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/utils/src/import.ts`:
- Around line 7-9: Collapse the two separate imports into a single type
re-export: keep the side-effect import "import '@eggjs/typings/global';" but
remove the separate "import type { BundleModuleLoader }" and rely on "export
type { BundleModuleLoader }" only; this lets references like the parameter type
on setBundleModuleLoader use the re-exported BundleModuleLoader under
isolatedModules/erasable-syntax rules while preserving the global typings
import.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b4f4f25c-9082-4fd0-bc7b-a5621384de2b

📥 Commits

Reviewing files that changed from the base of the PR and between 75cedaf and 3594c02.

⛔ Files ignored due to path filters (1)
  • packages/utils/test/__snapshots__/index.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (11)
  • packages/core/package.json
  • packages/core/src/index.ts
  • packages/typings/package.json
  • packages/typings/src/global.ts
  • packages/typings/src/index.ts
  • packages/typings/tsconfig.json
  • packages/typings/tsdown.config.ts
  • packages/utils/package.json
  • packages/utils/src/import.ts
  • packages/utils/test/bundle-import.test.ts
  • tsconfig.json
✅ Files skipped from review due to trivial changes (9)
  • packages/core/src/index.ts
  • packages/typings/src/index.ts
  • tsconfig.json
  • packages/core/package.json
  • packages/typings/tsconfig.json
  • packages/typings/tsdown.config.ts
  • packages/typings/src/global.ts
  • packages/utils/package.json
  • packages/typings/package.json

Copilot AI review requested due to automatic review settings April 26, 2026 13:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Comment thread packages/typings/src/global.ts
Copilot AI review requested due to automatic review settings April 26, 2026 14:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Comment thread packages/core/src/index.ts
@killagu killagu merged commit 965f62c into eggjs:next Apr 26, 2026
23 of 24 checks passed
@killagu killagu deleted the egg-15-typings branch April 26, 2026 14:40
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.

2 participants