diff --git a/.changeset/happy-carrots-carry.md b/.changeset/happy-carrots-carry.md new file mode 100644 index 000000000..82cae9fe5 --- /dev/null +++ b/.changeset/happy-carrots-carry.md @@ -0,0 +1,5 @@ +--- +'astro': minor +--- + +Implement [RFC0016](https://github.com/withastro/rfcs/blob/main/proposals/0016-style-script-defaults.md) which changes the default behavior of `script`, introduces `is:inline`, and changes ` +--- +import "${path}"; +--- `; } else if (isScriptRequest(path)) { extra = `It looks like you are resolving scripts. If you are adding a script tag, replace with this: @@ -134,7 +133,7 @@ export function createResult(args: CreateResultArgs): SSRResult { or consider make it a module like so: - `; diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 7cf56c35f..7e8bc2b50 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -535,16 +535,17 @@ function getHTMLElementName(constructor: typeof HTMLElement) { } function renderElement(name: string, { props: _props, children = '' }: SSRElement, shouldEscape = true) { - // Do not print `hoist`, `lang`, `global` + // Do not print `hoist`, `lang`, `is:global` const { lang: _, 'data-astro-id': astroId, 'define:vars': defineVars, ...props } = _props; if (defineVars) { if (name === 'style') { - if (props.global) { + if (props['is:global']) { children = defineStyleVars(`:root`, defineVars) + '\n' + children; } else { children = defineStyleVars(`.astro-${astroId}`, defineVars) + '\n' + children; } - delete props.global; + delete props['is:global']; + delete props['is:scoped']; } if (name === 'script') { delete props.hoist; diff --git a/packages/astro/src/vite-plugin-astro/index.ts b/packages/astro/src/vite-plugin-astro/index.ts index aded8f425..7d5839e48 100644 --- a/packages/astro/src/vite-plugin-astro/index.ts +++ b/packages/astro/src/vite-plugin-astro/index.ts @@ -63,7 +63,7 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu const { query: fromQuery, filename } = parseAstroRequest(from); if (fromQuery.astro && isRelativePath(id) && fromQuery.type === 'script') { const resolvedURL = new URL(id, `file://${filename}`); - const resolved = resolvedURL.pathname; + const resolved = resolvedURL.pathname if (isBrowserPath(resolved)) { return relativeToRoot(resolved + resolvedURL.search); } @@ -96,7 +96,7 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu let source = await fs.promises.readFile(fileUrl, 'utf-8'); const isPage = fileUrl.pathname.startsWith(config.pages.pathname); if (isPage && config._ctx.scripts.some((s) => s.stage === 'page')) { - source += `\n'); - expect(indexHtml).to.include(''); + expect(indexHtml).to.include(''); expect(indexHtml).to.include(''); }); }); diff --git a/packages/astro/test/fixtures/astro-css-bundling/src/components/Nav.astro b/packages/astro/test/fixtures/astro-css-bundling/src/components/Nav.astro index 159ef6719..37a2cecf1 100644 --- a/packages/astro/test/fixtures/astro-css-bundling/src/components/Nav.astro +++ b/packages/astro/test/fixtures/astro-css-bundling/src/components/Nav.astro @@ -19,7 +19,7 @@ } - \ No newline at end of file + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 814dbf0e8..b68e34713 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -442,7 +442,7 @@ importers: packages/astro: specifiers: - '@astrojs/compiler': ^0.13.2 + '@astrojs/compiler': ^0.14.1 '@astrojs/language-server': ^0.13.2 '@astrojs/markdown-remark': ^0.7.0 '@astrojs/prism': 0.4.1 @@ -528,7 +528,7 @@ importers: yargs-parser: ^21.0.1 zod: ^3.14.3 dependencies: - '@astrojs/compiler': 0.13.2 + '@astrojs/compiler': 0.14.1 '@astrojs/language-server': 0.13.2 '@astrojs/markdown-remark': link:../markdown/remark '@astrojs/prism': link:../astro-prism @@ -1713,8 +1713,8 @@ packages: leven: 3.1.0 dev: true - /@astrojs/compiler/0.13.2: - resolution: {integrity: sha512-0Un4CtLbhJljisFf9WaxK1TSV1oakR3Mh4x1Uyg1JHdyQ5te/1xcq+PWVaOyQc4lq4z8MYNFQb7hG66m0CeMtw==} + /@astrojs/compiler/0.14.1: + resolution: {integrity: sha512-dYgb52JvZE8jyDg84JkdJ/dTxRgHVbC47ou6Ymok/nZDh9kvlU7TJtEDCLlGfpfZTGvnkFTHMrz1kdbqCbFVCw==} dependencies: tsm: 2.2.1 uvu: 0.5.3