Skip to content

refactor(server): use nitropack/runtime in proxy handlers - #707

Merged
harlan-zw merged 5 commits into
mainfrom
refactor/proxy-nitropack-imports
Apr 14, 2026
Merged

refactor(server): use nitropack/runtime in proxy handlers#707
harlan-zw merged 5 commits into
mainfrom
refactor/proxy-nitropack-imports

Conversation

@harlan-zw

Copy link
Copy Markdown
Collaborator

🔗 Linked issue

N/A

❓ Type of change

  • 📖 Documentation
  • 🐞 Bug fix
  • 👌 Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking change

📚 Description

Swaps useRuntimeConfig / useNitroApp imports in the server-side proxy handlers (proxy-handler.ts, google-maps-geocode-proxy.ts, google-static-maps-proxy.ts, gravatar-proxy.ts, utils/withSigning.ts) from the Nuxt #imports virtual module to direct nitropack/runtime imports. This removes the lazy dynamic import('#imports') workaround in withSigning and lets unit tests import handler files (and their colocated utilities like rewriteUrl / scopeCss) without dragging in Nuxt's virtual module graph.

Adds a vitest alias on the unit project pointing nitropack/runtime to a tiny local mock so handler files resolve cleanly in Node tests. Also includes a routine catalog bump (@antfu/eslint-config, happy-dom, oxc-parser, posthog-js).

… handlers

Switches server-side proxy handlers from the Nuxt `#imports` virtual module
to direct `nitropack/runtime` imports. This lets unit tests import the
handler files (and their colocated utility exports like `rewriteUrl`,
`scopeCss`) without pulling Nuxt's virtual module graph. Adds a vitest
alias to a lightweight `nitropack/runtime` mock for the unit project.
@vercel

vercel Bot commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
scripts-playground Error Error Apr 14, 2026 3:07am

@pkg-pr-new

pkg-pr-new Bot commented Apr 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/scripts@707

commit: ea45349

@coderabbitai

coderabbitai Bot commented Apr 14, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR extracts Instagram embed utilities into a new module packages/script/src/runtime/server/utils/instagram-embed.ts and re-exports them from instagram-embed.ts. Five server handlers switch their useRuntimeConfig import source from #imports to nitropack/runtime (google-maps-geocode-proxy, google-static-maps-proxy, gravatar-proxy, proxy-handler, withSigning). Tests are updated to import the relocated utilities. The workspace catalog in pnpm-workspace.yaml bumps four dependency versions.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.08% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately describes the main change: refactoring server proxy handlers to use nitropack/runtime imports instead of Nuxt's #imports virtual module.
Description check ✅ Passed The description is directly related to the changeset, providing clear context about the import refactoring, the removal of dynamic imports, test improvements, and dependency updates.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/proxy-nitropack-imports

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@vitest.config.ts`:
- Around line 24-27: The alias currently uses new URL(...).pathname which yields
a POSIX-style path on Windows and breaks resolution; replace the pathname usage
by importing and calling fileURLToPath on the same URL and use that result for
the alias value (update the resolve.alias entry where 'nitropack/runtime' is
mapped and the URL is constructed to call fileURLToPath(new URL(...)) instead of
accessing .pathname).
🪄 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: e142d1a3-bab3-40b6-b566-fac11c861bf1

📥 Commits

Reviewing files that changed from the base of the PR and between 0bcb06d and a36d8e5.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (8)
  • packages/script/src/runtime/server/google-maps-geocode-proxy.ts
  • packages/script/src/runtime/server/google-static-maps-proxy.ts
  • packages/script/src/runtime/server/gravatar-proxy.ts
  • packages/script/src/runtime/server/proxy-handler.ts
  • packages/script/src/runtime/server/utils/withSigning.ts
  • pnpm-workspace.yaml
  • test/unit/__mocks__/nitropack-runtime.ts
  • vitest.config.ts

Comment thread vitest.config.ts Outdated
…e handler

Drop the nitropack/runtime vitest alias + stub by moving the pure URL
rewriting + CSS scoping helpers out of the handler file. The handler
now re-imports them; the unit test imports directly from the utils
module and no longer pulls the `withSigning` → `nitropack/runtime`
virtual chain at load time.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/script/src/runtime/server/utils/instagram-embed.ts`:
- Around line 93-110: The current use of selector.split(',') in scopeCss (around
the selector -> selectors mapping) incorrectly splits commas inside functional
pseudo-classes like :is(), :where(), :not(), and :has(), producing invalid
scoped CSS; replace that naive split with a nesting-aware selector splitter that
only splits on top-level commas (respecting parentheses, brackets, and quotes)
and use it where selectors is computed (instead of selector.split(',')) so
subsequent normalization (MULTI_SPACE_RE), filtering, mapping to scopedSelectors
(`scopeSelector ${s}`), and the output.push remain correct; ensure the new
splitter preserves whitespace and original selector fragments so
filteredSelectors and scopeSelector scoping logic works unchanged.
- Around line 65-69: The code assumes atRule.content always has a block by using
braceStart = atRule.content.indexOf('{') and slicing, which fails when
extractAtRule() returns a statement-form like "@layer foo;" (braceStart === -1)
and emits a stray "}". Fix in the branch handling atName === 'media' ||
'supports' || 'layer' by first checking if braceStart === -1 and, if so, push
the original atRule.content unchanged to output (preserving the statement-form);
otherwise proceed with extracting innerCss, calling processRules(innerCss,
scopeSelector), and pushing the reconstructed block as it currently does (using
atRule.content.slice(0, braceStart + 1) + scopedInner + '}').
🪄 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: 2cdebe19-7d5b-415d-8f14-82e4f8433f65

📥 Commits

Reviewing files that changed from the base of the PR and between 8bbd425 and c063d94.

📒 Files selected for processing (3)
  • packages/script/src/runtime/server/instagram-embed.ts
  • packages/script/src/runtime/server/utils/instagram-embed.ts
  • test/unit/instagram-embed.test.ts
✅ Files skipped from review due to trivial changes (1)
  • test/unit/instagram-embed.test.ts

Comment thread packages/script/src/runtime/server/utils/instagram-embed.ts Outdated
Comment thread packages/script/src/runtime/server/utils/instagram-embed.ts Outdated
…lector split

Addresses CodeRabbit findings:

- scopeCss now preserves statement-form `@layer foo;` rules instead of
  emitting a stray `}`.
- Top-level selector splitting respects parentheses, brackets, and
  quoted strings so commas inside `:is(...)`, `:not(...)`, and attribute
  selectors no longer fragment scoped rules.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
test/unit/instagram-embed.test.ts (1)

292-297: Test name mentions :where() but fixture doesn’t include it.

Optional: include a :where(...) selector in the same test so title and assertion coverage match exactly.

Suggested test tweak
-  it('does not split commas inside :is() / :where() / :not() selectors', () => {
-    const css = ':is(.Embed, .EmbedMedia) > :not(span, em) { color: red; }'
+  it('does not split commas inside :is() / :where() / :not() selectors', () => {
+    const css = ':is(.Embed, .EmbedMedia) > :not(span, em), :where(.EmbedCard, .EmbedFooter) { color: red; }'
     const result = scopeCss(css, scope)
     expect(result).toContain(`${scope} :is(.Embed, .EmbedMedia) > :not(span, em)`)
+    expect(result).toContain(`${scope} :where(.EmbedCard, .EmbedFooter)`)
     expect(result).not.toMatch(/\.EmbedMedia\) > :not\(span$/m)
   })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/unit/instagram-embed.test.ts` around lines 292 - 297, The test titled
"does not split commas inside :is() / :where() / :not() selectors" currently
only exercises :is() and :not(); update the fixture in the same test (the css
string passed to scopeCss) to also include a :where(...) selector (e.g., add
:where(.SomeClass, .OtherClass) alongside :is/.not) so the test name matches
coverage and verifies scopeCss handles :where() comma-containing lists
correctly; keep assertions using scopeCss and the same scope variable
(referencing scopeCss and the test case name) and assert the resulting string
contains the scoped :where(...) and does not incorrectly split its commas.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/unit/instagram-embed.test.ts`:
- Around line 292-297: The test titled "does not split commas inside :is() /
:where() / :not() selectors" currently only exercises :is() and :not(); update
the fixture in the same test (the css string passed to scopeCss) to also include
a :where(...) selector (e.g., add :where(.SomeClass, .OtherClass) alongside
:is/.not) so the test name matches coverage and verifies scopeCss handles
:where() comma-containing lists correctly; keep assertions using scopeCss and
the same scope variable (referencing scopeCss and the test case name) and assert
the resulting string contains the scoped :where(...) and does not incorrectly
split its commas.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 407491dc-5f2a-4b84-9eb3-b9a6984787b2

📥 Commits

Reviewing files that changed from the base of the PR and between c063d94 and ea45349.

📒 Files selected for processing (2)
  • packages/script/src/runtime/server/utils/instagram-embed.ts
  • test/unit/instagram-embed.test.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/script/src/runtime/server/utils/instagram-embed.ts

@harlan-zw
harlan-zw merged commit 2e8935f into main Apr 14, 2026
16 of 17 checks passed
@harlan-zw
harlan-zw deleted the refactor/proxy-nitropack-imports branch April 14, 2026 03:12
@harlan-zw
harlan-zw restored the refactor/proxy-nitropack-imports branch August 14, 2026 03: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.

1 participant