fix(speedcurve): vendor LUX snippet and group schema options#805
fix(speedcurve): vendor LUX snippet and group schema options#805harlan-zw wants to merge 8 commits into
Conversation
- Inline the LUX 2.0.0 snippet as a string const in `runtime/utils/speedcurve-snippet.ts` so `@speedcurve/lux` is no longer required at user build time (still kept as an optional peer dep for types). - Drop `@speedcurve/lux` from `build.externals`; remove obsolete `?raw` mocks from the unit tests. - Split `SpeedCurveOptions` into composable-only options (`id`, `spaMode`, `autoTrackSpaNavigations`) and LUX `UserConfig` passthrough, with a note pointing to `LUX_USER_CONFIG_KEYS`. - Regenerate `registry-types.json`. Addresses unresolved review comments from #782.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
|
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:
📝 WalkthroughWalkthroughThis PR refactors SpeedCurve snippet resolution from a direct external package import to a build-time generated virtual module. The Nuxt module now conditionally generates a virtual module Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
…stration - Replace the vendored snippet with a virtual `#build/nuxt-scripts-speedcurve-snippet` template. - The module only emits the template when `scripts.registry.speedcurve` is set; missing registration produces a clear build error. - The template resolves the snippet from the user-installed `@speedcurve/lux` peer dep so users control the snippet version; missing dep throws at import with an install hint. - Adds a setup section to the docs documenting the opt-in registration + peer dep install.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/script/src/module.ts`:
- Around line 672-675: The fallback currently returns only a throwing expression
which causes ESM to fail before the install-hint can be read; change the
fallback returned by the module generator so it always exports luxSnippetSource
(e.g., an empty string or null) and then throws the install hint, so imports
that expect the luxSnippetSource export (from useScriptSpeedCurve / the
generated module using snippetPath and luxSnippetSource) won't fail during
instantiation; update the branch that checks snippetPath/existsSync to return a
module string that includes an export for luxSnippetSource plus the throw
message.
In `@packages/script/src/runtime/registry/speedcurve.ts`:
- Around line 7-12: Reorder the import statements so that the virtual/build
alias import "luxSnippetSource" from '`#build/nuxt-scripts-speedcurve-snippet`'
appears before the relative import from '../utils/after-next-paint' to satisfy
the linter's import ordering rule; locate the import of luxSnippetSource and
move it above the import of afterNextPaint (or any other ../utils/* imports) in
packages/script/src/runtime/registry/speedcurve.ts.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b9871179-1a35-4617-ac2b-0e687eda8770
📒 Files selected for processing (8)
docs/content/scripts/speedcurve.mdpackages/script/src/module.tspackages/script/src/runtime/registry/speedcurve.tstest/unit/__mocks__/empty.tstest/unit/speedcurve-auto-tracker.test.tstest/unit/speedcurve-config.test.tstest/unit/speedcurve-primer.test.tsvitest.config.ts
✅ Files skipped from review due to trivial changes (2)
- test/unit/mocks/empty.ts
- docs/content/scripts/speedcurve.md
🚧 Files skipped from review as they are similar to previous changes (2)
- test/unit/speedcurve-primer.test.ts
- test/unit/speedcurve-config.test.ts
A bare `throw` in the virtual template body produces an ESM module with no exports, so `import { luxSnippetSource }` fails at instantiation with "does not provide an export named 'luxSnippetSource'" before the install hint can surface. Wrap the throw inside the export initializer so the error fires only when the snippet is read.
Also reorders the virtual import in speedcurve.ts ahead of the relative imports to satisfy import-order lint.
…heck The Nuxt `#build/*` tsconfig path resolves to a real file on disk; without an emitted .d.ts the typecheck fails for any consumer of useScriptSpeedCurve regardless of registration. Always emit a tiny declaration template so types resolve, keep the runtime .mjs emission gated on `scripts.registry.speedcurve` so non-users carry no LUX primer code.
Drop the unconditional .d.ts template; the virtual is only emitted on registration, so just suppress the type error on the import line. Non-registered consumers still hit the unresolved-virtual build error at user build time.
…ual snippet The playground has speed-curve demo pages but speedcurve wasn't registered, so the gated `#build/nuxt-scripts-speedcurve-snippet` virtual didn't emit and the Vercel build failed at module resolution.
…l load
Make explicit that `scripts.registry.speedcurve` registration is what triggers the build-time primer resolution, not optional. Show the minimum `speedcurve: {}` shape for composable-only usage alongside the global-load variant, plus the two failure modes (missing registration vs missing peer dep) so users can diagnose without spelunking.
🔗 Linked issue
Follow-up to #782 — addresses unresolved review comments.
❓ Type of change
📚 Description
Resolves the two open review items left after #782 was merged.
Snippet sourcing — opt-in registration + user-installed peer dep. SpeedCurve LUX now requires the user to register the script in
scripts.registry.speedcurveand install@speedcurve/luxthemselves. The Nuxt module:#build/nuxt-scripts-speedcurve-snippetvirtual template whenscripts.registry.speedcurveis set. CallinguseScriptSpeedCurvewithout registering produces a clear build error from the missing virtual.@speedcurve/luxat build time viaresolvePath+readFileSync, then emits it as a string export. No?rawimport in runtime, no vendored snippet to keep in sync, users control the snippet version.npm i -D @speedcurve/lux).Docs gain a Setup section documenting the opt-in registration + peer dep install.
Schema clarity.
SpeedCurveOptionsis split with section comments —id,spaMode,autoTrackSpaNavigationsare composable-only; the rest match upstream LUXUserConfigcasing and are forwarded ontowindow.LUX. Comment points future editors to keep this in sync withLUX_USER_CONFIG_KEYSinspeedcurve.ts.Regenerated
registry-types.json. All 717 unit tests pass and@nuxt/scriptsbuilds clean.