Repository navigation
refactor(kit): inline c12 and untyped, make jiti/giget optional peers - #35936
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
42515f4 to
c242c51
Compare
c242c51 to
14eb45b
Compare
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThe change introduces Nuxt-specific layer and configuration types. It adds optional Giget and project-scoped Jiti resolution. Configuration loading supports native imports, cache busting, custom importers, Jiti fallback, and remote-layer dependency checks. Module loading tries native imports before Jiti and reports dedicated diagnostics. Tests cover dependency resolution and module formats. Documentation describes the remote-layer migration. Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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)
packages/kit/src/loader/config.ts (1)
257-306: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winPass the required Loader when loading aliased nested configs.
resolveOptions.importis not populated by c12’sresolvecontext, so the nestedloadConfigfor alias-prefixed sources uses c12’s own loader instead of this project’simportConfigFileloader. Pass the loader thatopts.import ?? importConfigFileresolves to into this nestedloadConfig.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/kit/src/loader/config.ts` around lines 257 - 306, Update the aliased-source branch in the resolve method to pass the configured loader, using the same opts.import ?? importConfigFile fallback used by the outer load. Do not rely on resolveOptions.import, since c12 does not populate it; ensure the nested loadConfig call uses this project loader.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/kit/src/internal/esm.ts`:
- Around line 89-101: Update requireJiti() so its fallback resolves jiti using
CommonJS-specific resolution conditions before passing the result to require().
Preserve the existing rootDir fallback and error propagation, but ensure the
resolved candidate targets jiti’s CJS entry rather than its ESM entry.
In `@packages/kit/src/internal/jiti.ts`:
- Around line 42-67: The loadJiti function does not guard concurrent
installation attempts, allowing multiple callers to invoke
ensureDependencyInstalled for jiti simultaneously. Add an in-flight installation
promise or equivalent per-root/package guard around the
ensureDependencyInstalled call, reuse it for concurrent requests, and preserve
the existing cached resolution and install-disabled behavior.
In `@packages/kit/src/module/install.ts`:
- Around line 374-391: Update describeNativeImportFailure() and the native
import catch in the module installation flow to return and enforce explicit
fallback eligibility, calling getSharedJiti() only for recognized runtime
incompatibilities such as non-erasable syntax, node_modules loading, or
unresolved specifiers. For module evaluation failures, rethrow the original
native error without resolving or installing Jiti, and add a regression test
covering a module that throws during evaluation.
---
Outside diff comments:
In `@packages/kit/src/loader/config.ts`:
- Around line 257-306: Update the aliased-source branch in the resolve method to
pass the configured loader, using the same opts.import ?? importConfigFile
fallback used by the outer load. Do not rely on resolveOptions.import, since c12
does not populate it; ensure the nested loadConfig call uses this project
loader.
🪄 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: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e5427801-ec4d-41d1-b519-33cca8c1afc5
⛔ Files ignored due to path filters (3)
packages/kit/package.jsonis excluded by!**/package.jsonpackages/schema/package.jsonis excluded by!**/package.jsonpnpm-lock.yamlis excluded by!**/pnpm-lock.yaml,!pnpm-lock.yaml
📒 Files selected for processing (16)
docs/1.getting-started/18.upgrade.mdknip.jsonpackages/kit/src/diagnostics/config.tspackages/kit/src/diagnostics/kit-api.tspackages/kit/src/internal/esm.tspackages/kit/src/internal/jiti.tspackages/kit/src/loader/config.tspackages/kit/src/module/install.tspackages/kit/test/jiti-resolution.spec.tspackages/kit/test/module.test.tspackages/kit/tsdown.config.tspackages/schema/src/index.tspackages/schema/src/types/config.tspackages/schema/src/types/layers.tspackages/schema/src/types/schema.tspnpm-workspace.yaml
Merging this PR will improve performance by 24.13%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | loadNuxtConfig in the basic test fixture (types) |
22.4 ms | 16.2 ms | +38.3% |
| ⚡ | loadNuxtConfig in the basic test fixture |
37 ms | 33.2 ms | +11.42% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing perf/kit-jiti (3b97dba) with main (8568cd2)2
Footnotes
-
3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
-
No successful run was found on
main(e6509fd) during the generation of this report, so 8568cd2 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/kit/src/internal/jiti.ts`:
- Line 23: Update the Jiti cache used by the initialization logic around cached
and the code at lines 43-52 to key promises by normalized rootDir, searchPaths,
and install policy instead of sharing one process-wide promise. Return the entry
matching each caller’s resolution context, and remove only that context’s cache
entry when initialization fails so other cached resolutions remain unaffected.
🪄 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: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c69365ad-cc25-4ee8-a4a4-38722dec6040
📒 Files selected for processing (2)
packages/kit/src/internal/jiti.tspackages/kit/src/module/define.ts
| install?: boolean | ||
| } | ||
|
|
||
| let cached: Promise<JitiModule | undefined> | undefined |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Key the Jiti cache by the resolution context.
Line 44 shares one process-wide promise, but rootDir, searchPaths, and install change the result. If one caller resolves Jiti from project A, a concurrent caller for project B receives project A’s module. If the first caller uses install: false, it can also prevent a concurrent install-enabled caller from installing Jiti.
Cache promises per normalised rootDir, searchPaths, and installation policy. Clear only the failed cache entry.
Also applies to: 43-52
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/kit/src/internal/jiti.ts` at line 23, Update the Jiti cache used by
the initialization logic around cached and the code at lines 43-52 to key
promises by normalized rootDir, searchPaths, and install policy instead of
sharing one process-wide promise. Return the entry matching each caller’s
resolution context, and remove only that context’s cache entry when
initialization fails so other cached resolutions remain unaffected.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/kit/src/internal/jiti.ts`:
- Around line 12-31: Update isLoaderError and its callers in the config and
module loading flows to accept the failed target/specifier and determine whether
native loading rejected that target before evaluation, rather than treating
SyntaxError instances or error codes alone as loader failures. Remove the
unconditional instanceof SyntaxError and code-only checks, preserve retries only
for pre-evaluation loader failures, and add regression coverage for runtime
SyntaxError and top-level dynamic-import rejection cases.
🪄 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: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 842ae44a-258f-4eee-820a-9c14aae13973
⛔ Files ignored due to path filters (26)
packages/kit/package.jsonis excluded by!**/package.jsontest/fixtures/basic-types/extends/node_modules/foo/nuxt.config.mjsis excluded by!**/node_modules/**test/fixtures/basic-types/package.jsonis excluded by!**/package.jsontest/fixtures/basic/extends/node_modules/foo/nuxt.config.mjsis excluded by!**/node_modules/**test/fixtures/basic/package.jsonis excluded by!**/package.jsontest/fixtures/build-assets-dir-collision/package.jsonis excluded by!**/package.jsontest/fixtures/chunk-error/package.jsonis excluded by!**/package.jsontest/fixtures/dynamic-paths/package.jsonis excluded by!**/package.jsontest/fixtures/external-vue-resolution/package.jsonis excluded by!**/package.jsontest/fixtures/hmr-sibling-layer/package.jsonis excluded by!**/package.jsontest/fixtures/hmr/package.jsonis excluded by!**/package.jsontest/fixtures/inline-styles/package.jsonis excluded by!**/package.jsontest/fixtures/minimal-pages/package.jsonis excluded by!**/package.jsontest/fixtures/minimal-types/package.jsonis excluded by!**/package.jsontest/fixtures/minimal/package.jsonis excluded by!**/package.jsontest/fixtures/nested-suspense/package.jsonis excluded by!**/package.jsontest/fixtures/nitro-vite-environment/package.jsonis excluded by!**/package.jsontest/fixtures/no-scripts/package.jsonis excluded by!**/package.jsontest/fixtures/runtime-compiler/package.jsonis excluded by!**/package.jsontest/fixtures/spa-loader/package.jsonis excluded by!**/package.jsontest/fixtures/spa/package.jsonis excluded by!**/package.jsontest/fixtures/ssr-streaming/package.jsonis excluded by!**/package.jsontest/fixtures/suspense-layout/package.jsonis excluded by!**/package.jsontest/fixtures/suspense/package.jsonis excluded by!**/package.jsontest/fixtures/ui-templates/package.jsonis excluded by!**/package.jsontest/fixtures/worker-assets/package.jsonis excluded by!**/package.json
📒 Files selected for processing (27)
packages/kit/src/diagnostics/kit-api.tspackages/kit/src/internal/esm.tspackages/kit/src/internal/jiti.tspackages/kit/src/loader/config.tspackages/kit/src/module/install.tspackages/kit/test/module.test.tstest/fixtures/basic-types/nuxt.config.tstest/fixtures/basic/nuxt.config.tstest/fixtures/build-assets-dir-collision/nuxt.config.tstest/fixtures/dynamic-paths/nuxt.config.tstest/fixtures/hmr/nuxt.config.tstest/fixtures/inline-styles/nuxt.config.tstest/fixtures/lazy-hydration/nuxt.config.tstest/fixtures/nested-suspense/nuxt.config.tstest/fixtures/nitro-vite-environment/nuxt.config.tstest/fixtures/nuxt-time/nuxt.config.tstest/fixtures/payload-cache-leak/nuxt.config.tstest/fixtures/preview/nuxt.config.tstest/fixtures/route-scroll/nuxt.config.tstest/fixtures/runtime-compiler/nuxt.config.tstest/fixtures/server-components/nuxt.config.tstest/fixtures/spa-loader/nuxt.config.tstest/fixtures/ssr-streaming/nuxt.config.tstest/fixtures/suspense-layout/nuxt.config.tstest/fixtures/suspense/nuxt.config.tstest/fixtures/ui-templates/nuxt.config.tstest/fixtures/worker-assets/nuxt.config.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- packages/kit/src/internal/esm.ts
- packages/kit/src/diagnostics/kit-api.ts
- packages/kit/src/module/install.ts
- packages/kit/src/loader/config.ts
`untyped` was the only package in a default Nuxt 5 install with a hard dependency on `jiti`, which it uses only in `untyped/loader`. Nuxt imports the main entry and lazily imports `untyped/babel-plugin`, so it is inlined into `nuxt` as `@nuxt/kit` already does (nuxt#35936). The babel plugin stays a separate chunk behind the existing dynamic import. `@nuxt/schema`'s declarations imported `untyped` types without depending on it, which only resolved because `nuxt` installed it. Those types are now bundled into the declarations, and `untyped` is no longer an allowed external type in the public API check. The no-jiti suite now also walks the installed `dependencies` of `nuxt`, since the existing check only looked at direct dependencies.
`untyped` was the only package in a default Nuxt 5 install with a hard dependency on `jiti`, which it uses only in `untyped/loader`. Nuxt imports the main entry and lazily imports `untyped/babel-plugin`, so it is inlined into `nuxt` as `@nuxt/kit` already does (nuxt#35936). The babel plugin stays a separate chunk behind the existing dynamic import. `@nuxt/schema`'s declarations imported `untyped` types without depending on it, which only resolved because `nuxt` installed it. Those types are now bundled into the declarations, and `untyped` is no longer an allowed external type in the public API check. The no-jiti suite now also walks the installed `dependencies` of `nuxt`, since the existing check only looked at direct dependencies.
`untyped` was the only package in a default Nuxt 5 install with a hard dependency on `jiti`, which it uses only in `untyped/loader`. Nuxt imports the main entry and lazily imports `untyped/babel-plugin`, so it is inlined into `nuxt` as `@nuxt/kit` already does (nuxt#35936). The babel plugin stays a separate chunk behind the existing dynamic import. `@nuxt/schema`'s declarations imported `untyped` types without depending on it, which only resolved because `nuxt` installed it. Those types are now bundled into the declarations, and `untyped` is no longer an allowed external type in the public API check. The no-jiti suite now also walks the installed `dependencies` of `nuxt`, since the existing check only looked at direct dependencies.
`untyped` was the only package in a default Nuxt 5 install with a hard dependency on `jiti`, which it uses only in `untyped/loader`. Nuxt uses only its core (`resolveSchema` and `generateTypes`), so it is inlined into `nuxt` as `@nuxt/kit` already does (nuxt#35936) and moves to `devDependencies`. `@nuxt/schema`'s declarations imported `untyped` types without depending on it, which only resolved because `nuxt` installed it. Those types are now bundled into the declarations, and `untyped` is no longer an allowed external type in the public API check. The no-jiti suite now also walks the installed `dependencies`, `optionalDependencies` and required peers of `nuxt`, since the existing check only looked at direct dependencies.
🔗 Linked issue
📚 Description
there are some unjs packages that have multiple purposes. for example, c12 supports watching a config file and brings in chokidar and other deps; untyped pulls in babel
this allows us to move jiti + giget to be optional peer dependencies. we are advising users to manage remote layers through their package manager; they can still add
gigetmanually if they want the previous behaviour.similarly, we will recommend users to write their
nuxt.config.tsand modules in a way that can be imported by node natively, without needing jiti to import it. now that typescript is natively supported, this is relatively straightforward. and for the few edge cases where it isn't, they can installjiti.this saves us install time (and processing time!) and makes the bare
nuxtinstall slimmer and better for most usersNote
nitro has already made exactly this move, for very similar reasons