withastro / compiler

The Astro compiler. Written in Go. Distributed as WASM.
Other
503 stars 59 forks source link

Add renderScript option #969

Closed bluwy closed 9 months ago

bluwy commented 9 months ago

Changes

This PR allows rendering non-inline script tags using a runtime API from internalURL, e.g.

<script>console.log("a")</script>

becomes:

`${$$renderScript($$metadata, "/src/pages/index.astro?astro&type=script&index=0&lang.ts")}`

Personally I'm not a fan of the hardcoded script URL default, but the styles were also hardcoded this way, and it was easier to implement.

Testing

Added go tests

Docs

Only added jsdoc to the types explaining this feature. Options added in the past didn't have public docs either (?)

changeset-bot[bot] commented 9 months ago

🦋 Changeset detected

Latest commit: e8c2170aa127075e05edfca326f40bd106b0b4be

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

This PR includes changesets to release 1 package | Name | Type | | ----------------- | ----- | | @astrojs/compiler | Minor |

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

bluwy commented 9 months ago

!preview render-script

github-actions[bot] commented 9 months ago
 > root@0.0.0 release /home/runner/work/compiler/compiler > changeset publish "--tag" "next--render-script" 🦋 warn ===============================IMPORTANT!=============================== 🦋 warn Packages will be released under the next--render-script tag 🦋 warn ---------------------------------------------------------------------- 🦋 info npm info @astrojs/compiler 🦋 info @astrojs/compiler is being published because our local version (0.0.0-render-script-20240214150051) has not been published on npm 🦋 info Publishing "@astrojs/compiler" at "0.0.0-render-script-20240214150051" 🦋 success packages published successfully: 🦋 @astrojs/compiler@0.0.0-render-script-20240214150051 🦋 Creating git tag... 🦋 New tag: @astrojs/compiler@0.0.0-render-script-20240214150051
ematipico commented 9 months ago

What's internalURL? I lack some context

bluwy commented 9 months ago

internalURL is one of the compiler option names. We pass something like astro/compiler-runtime.

ematipico commented 9 months ago

Let's 🚢 it

bluwy commented 9 months ago

Thanks for the reviews! I'll merge this in for now then and we could get the other PRs in to cut a new minor together.