Skip to content

Fix @astrojs/cloudflare dependency scan incorrectly matching import.meta and import() as static imports - #18145

Merged
matthewp merged 2 commits into
mainfrom
factory/fix-18144
Sep 28, 2026
Merged

matthewp merged 2 commits into
mainfrom
factory/fix-18144

Conversation

@astro-factory

@astro-factory astro-factory Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Changes

  • Adds a negative lookahead (?!\s*[.(]) after \b in IMPORT_STMT_RE in rolldown-plugin-astro-frontmatter.ts. Previously, the word boundary \b matched between import and . or ( (both non-word characters), causing Prettier-wrapped expressions like import.meta.env.BASE_URL… at the start of a line to be incorrectly hoisted out of the __astro__() wrapper. This left the preceding assignment incomplete, producing a parse error that silently failed the entire dependency pre-bundling scan project-wide.
  • The lookahead leaves all valid static import declaration forms unaffected while excluding import.meta and dynamic import() expressions.

Testing

  • Added two new cases to packages/integrations/cloudflare/test/units/wrap-frontmatter.test.ts: one covering a line-leading import.meta expression (the Prettier-wrapped pattern), and one covering a dynamic import() call — both verifying the expressions remain inside the __astro__() body rather than being hoisted.

Docs

  • No docs update needed; this is a bug fix in an internal transform with no user-facing API change.

Closes #18144

@astro-factory astro-factory Bot added the fix verified Reporter confirmed the triage bot fix works label Sep 26, 2026
@changeset-bot

changeset-bot Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c1e7a92

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/cloudflare Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the pkg: integration Related to any renderer integration (scope) label Sep 26, 2026
@astro-factory
astro-factory Bot removed the request for review from astro-reviewer September 26, 2026 17:45

@astro-factory astro-factory Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Merge Requirement Assessment

Status: satisfied

  • Fix @astrojs/cloudflare dependency scan incorrectly matching import.meta and import() as static imports - isImportExpression returns true for import.meta / import(...) lines (allowing whitespace and both /* *//// comments between the import token and . or (), so the wrapFrontmatter replace callback leaves those expressions inside the __astro__() body instead of hoisting them. The added unit tests cover the Prettier-wrapped, line-leading import.meta pattern, dynamic import() calls, and both comment-separated variants described in the issue.

Review Status

Verdict: ready to merge based on static review
Context: PR #18145 (closes #18144)
Scope: Full PR diff (base 3f3d580b83b0cb9f14d451b86dab547ccffe4eab → head c1e7a92f0444b26b70c38339ce092a4bcffec259) — packages/integrations/cloudflare/src/rolldown-plugin-astro-frontmatter.ts, packages/integrations/cloudflare/test/units/wrap-frontmatter.test.ts, .changeset/hot-places-ask.md.
Changeset: present and covers @astrojs/cloudflare.
Limitations: none.
Validation: Static review only; no project code, tests, builds, or checks were run.
GitHub context: collected.
Git scope: PR base/head verified via GitHub read-only tools.

This review was made by an LLM. The analysis may be wrong, and reports might be incorrect.

@astro-factory

astro-factory Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

Factory Adversary

Purple selected red, not Blue. Confidence: medium.

This is a bug fix in `@astrojs/cloudflare`'s frontmatter wrapping transform used during dependency scanning. The contract is to stop treating `import.meta` property access and dynamic `import()` calls as static import declarations (so they are not hoisted out of the `__astro__()` wrapper), while continuing to hoist real static imports and including focused regression tests plus a patch changeset. Red and blue differ in implementation: red uses a post-match `isImportExpression` helper that skips whitespace/comments before checking for `.` or `(`, while blue adds a negative lookahead `(?!\s*[.(])` to the same regex. Both pass their own new unit tests for line-leading `import.meta` and `import()`, but blue fails on comment-separated variants (e.g., `import /* c */ .meta.url` and `import // c\n ("./mod")`), leaving the wrapper invalid. Red also covers those cases in tests and implementation. Because correctness is the first Astro comparison criterion, red is the better solution.

No alternative pull request was created.

Disclosure: The alternative and assessment were generated by AI agents.

@matthewp
matthewp merged commit 02246c9 into main Sep 28, 2026
27 checks passed
@matthewp
matthewp deleted the factory/fix-18144 branch September 28, 2026 12:55
@astrobot-houston astrobot-houston mentioned this pull request Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix verified Reporter confirmed the triage bot fix works pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@astrojs/cloudflare: dev dependency scan fails when a frontmatter line opens with import.meta

1 participant