Skip to content

Commit

Permalink
Export astro/compiler-runtime and cleanup exports (#8085)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Aug 15, 2023
1 parent 7b77b34 commit 68efd4a
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 6 deletions.
25 changes: 25 additions & 0 deletions .changeset/neat-owls-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
'astro': major
---

Remove exports for `astro/internal/*` and `astro/runtime/server/*` in favour of `astro/runtime/*`. Add new `astro/compiler-runtime` export for compiler-specific runtime code.

These are exports for Astro's internal API and should not affect your project, but if you do use these entrypoints, you can migrate like below:

```diff
- import 'astro/internal/index.js';
+ import 'astro/runtime/server/index.js';

- import 'astro/server/index.js';
+ import 'astro/runtime/server/index.js';
```

```diff
import { transform } from '@astrojs/compiler';

const result = await transform(source, {
- internalURL: 'astro/runtime/server/index.js',
+ internalURL: 'astro/compiler-runtime',
// ...
});
```
5 changes: 2 additions & 3 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"./tsconfigs/*": "./tsconfigs/*.json",
"./jsx/*": "./dist/jsx/*",
"./jsx-runtime": "./dist/jsx-runtime/index.js",
"./compiler-runtime": "./dist/runtime/compiler/index.js",
"./runtime/*": "./dist/runtime/*",
"./config": {
"types": "./config.d.ts",
"default": "./config.mjs"
Expand All @@ -60,10 +62,7 @@
"./content/runtime": "./dist/content/runtime.js",
"./content/runtime-assets": "./dist/content/runtime-assets.js",
"./debug": "./components/Debug.astro",
"./internal/*": "./dist/runtime/server/*",
"./package.json": "./package.json",
"./runtime/*": "./dist/runtime/*",
"./server/*": "./dist/runtime/server/*",
"./zod": {
"types": "./zod.d.ts",
"default": "./zod.mjs"
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/compile/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function compile({
filename,
normalizedFilename: normalizeFilename(filename, astroConfig.root),
sourcemap: 'both',
internalURL: 'astro/server/index.js',
internalURL: 'astro/compiler-runtime',
astroGlobalArgs: JSON.stringify(astroConfig.site),
scopedStyleStrategy: astroConfig.scopedStyleStrategy,
resultScopedSlot: true,
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ Code that executes within isolated contexts:

- `client/`: executes within the browser. Astro’s client-side partial hydration code lives here, and only browser-compatible code can be used.
- `server/`: executes inside Vite SSR. Though also a Node context, this is isolated from code in `core/`.
- `compiler/`: same as `server/`, but only used by the Astro compiler `internalURL` option.

[See CONTRIBUTING.md](../../../../CONTRIBUTING.md) for a code overview.
20 changes: 20 additions & 0 deletions packages/astro/src/runtime/compiler/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// NOTE: Although this entrypoint is exported, it is internal API and may change at any time.

export {
Fragment,
render,
createAstro,
createComponent,
renderComponent,
renderHead,
maybeRenderHead,
unescapeHTML,
renderSlot,
mergeSlots,
addAttribute,
renderTransition,
createTransitionScope,
spreadAttributes,
defineStyleVars,
defineScriptVars,
} from '../server/index.js';
2 changes: 2 additions & 0 deletions packages/astro/src/runtime/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// NOTE: Although this entrypoint is exported, it is internal API and may change at any time.

export { createComponent } from './astro-component.js';
export { createAstro } from './astro-global.js';
export { renderEndpoint } from './endpoint.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/vite-plugin-mdx/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default async function tagExportsWithRenderer({
return {
visitor: {
Program: {
// Inject `import { __astro_tag_component__ } from 'astro/server/index.js'`
// Inject `import { __astro_tag_component__ } from 'astro/runtime/server/index.js'`
enter(path) {
path.node.body.splice(
0,
Expand All @@ -30,7 +30,7 @@ export default async function tagExportsWithRenderer({
t.identifier('__astro_tag_component__')
),
],
t.stringLiteral('astro/server/index.js')
t.stringLiteral('astro/runtime/server/index.js')
)
);
},
Expand Down

0 comments on commit 68efd4a

Please sign in to comment.