From 68efd4a8b29f248397667801465b3152dc98e9a7 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Tue, 15 Aug 2023 16:21:28 +0800 Subject: [PATCH] Export astro/compiler-runtime and cleanup exports (#8085) --- .changeset/neat-owls-run.md | 25 ++++++++++++++++++++ packages/astro/package.json | 5 ++-- packages/astro/src/core/compile/compile.ts | 2 +- packages/astro/src/runtime/README.md | 1 + packages/astro/src/runtime/compiler/index.ts | 20 ++++++++++++++++ packages/astro/src/runtime/server/index.ts | 2 ++ packages/astro/src/vite-plugin-mdx/tag.ts | 4 ++-- 7 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 .changeset/neat-owls-run.md create mode 100644 packages/astro/src/runtime/compiler/index.ts diff --git a/.changeset/neat-owls-run.md b/.changeset/neat-owls-run.md new file mode 100644 index 000000000000..501b5319f5df --- /dev/null +++ b/.changeset/neat-owls-run.md @@ -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', + // ... +}); +``` diff --git a/packages/astro/package.json b/packages/astro/package.json index b21c4b334304..18918f934805 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -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" @@ -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" diff --git a/packages/astro/src/core/compile/compile.ts b/packages/astro/src/core/compile/compile.ts index f266c0b16cfd..bd069611df84 100644 --- a/packages/astro/src/core/compile/compile.ts +++ b/packages/astro/src/core/compile/compile.ts @@ -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, diff --git a/packages/astro/src/runtime/README.md b/packages/astro/src/runtime/README.md index a11a98d8c860..68225fed1098 100644 --- a/packages/astro/src/runtime/README.md +++ b/packages/astro/src/runtime/README.md @@ -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. diff --git a/packages/astro/src/runtime/compiler/index.ts b/packages/astro/src/runtime/compiler/index.ts new file mode 100644 index 000000000000..a5c238b68aca --- /dev/null +++ b/packages/astro/src/runtime/compiler/index.ts @@ -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'; diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 5d4697bc7927..81d05987adb8 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -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'; diff --git a/packages/astro/src/vite-plugin-mdx/tag.ts b/packages/astro/src/vite-plugin-mdx/tag.ts index 5efc4c41f6e7..b7ae1f2c44ed 100644 --- a/packages/astro/src/vite-plugin-mdx/tag.ts +++ b/packages/astro/src/vite-plugin-mdx/tag.ts @@ -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, @@ -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') ) ); },