From c2a7ada1bff2f04cf5a7b3d17ce26aec066d9861 Mon Sep 17 00:00:00 2001 From: bluwy Date: Mon, 9 Jan 2023 15:42:29 +0800 Subject: [PATCH 1/9] Update createAstro breaking change --- packages/astro/src/core/compile/compile.ts | 5 +---- packages/astro/src/runtime/server/astro-global.ts | 9 ++------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/astro/src/core/compile/compile.ts b/packages/astro/src/core/compile/compile.ts index e431f1bb36d4..f5e157ba0e41 100644 --- a/packages/astro/src/core/compile/compile.ts +++ b/packages/astro/src/core/compile/compile.ts @@ -39,13 +39,10 @@ export async function compile({ transformResult = await transform(source, { moduleId, pathname: filename, - projectRoot: astroConfig.root.toString(), - site: astroConfig.site?.toString(), sourcefile: filename, sourcemap: 'both', internalURL: 'astro/server/index.js', - // TODO: baseline flag - experimentalStaticExtraction: true, + injectGlobals: JSON.stringify(astroConfig.site), preprocessStyle: createStylePreprocessor({ filename, viteConfig, diff --git a/packages/astro/src/runtime/server/astro-global.ts b/packages/astro/src/runtime/server/astro-global.ts index 3182026bf35b..d175bc2e9acb 100644 --- a/packages/astro/src/runtime/server/astro-global.ts +++ b/packages/astro/src/runtime/server/astro-global.ts @@ -17,13 +17,8 @@ function createAstroGlobFn() { } // This is used to create the top-level Astro global; the one that you can use -// Inside of getStaticPaths. -// TODO: remove `_filePathname` and `_projectRootStr` from the compiler -export function createAstro( - _filePathname: string, - site: string | undefined, - _projectRootStr: string -): AstroGlobalPartial { +// inside of getStaticPaths. See the `injectGlobals` option for parameter type. +export function createAstro(site: string | undefined): AstroGlobalPartial { return { site: site ? new URL(site) : undefined, generator: `Astro v${ASTRO_VERSION}`, From 82e855baa9887c9f6d829bca50144331ec781e2c Mon Sep 17 00:00:00 2001 From: bluwy Date: Thu, 12 Jan 2023 13:09:17 +0800 Subject: [PATCH 2/9] Use new options --- packages/astro/package.json | 2 +- packages/astro/src/core/compile/compile.ts | 19 +++++++++++++++---- pnpm-lock.yaml | 8 ++++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/packages/astro/package.json b/packages/astro/package.json index b73779f8c608..90f9aa0c1d2a 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -109,7 +109,7 @@ "test:e2e:match": "playwright test -g" }, "dependencies": { - "@astrojs/compiler": "^0.31.4", + "@astrojs/compiler": "^0.32.0", "@astrojs/language-server": "^0.28.3", "@astrojs/markdown-remark": "^2.0.0-beta.1", "@astrojs/telemetry": "^1.0.1", diff --git a/packages/astro/src/core/compile/compile.ts b/packages/astro/src/core/compile/compile.ts index 95eb192db12b..4c8beaa32629 100644 --- a/packages/astro/src/core/compile/compile.ts +++ b/packages/astro/src/core/compile/compile.ts @@ -3,6 +3,8 @@ import type { ResolvedConfig } from 'vite'; import type { AstroConfig } from '../../@types/astro'; import { transform } from '@astrojs/compiler'; +import { normalizePath } from 'vite'; +import { fileURLToPath } from 'url'; import { AggregateError, AstroError, CompilerError } from '../errors/errors.js'; import { AstroErrorData } from '../errors/index.js'; import { resolvePath } from '../util.js'; @@ -35,12 +37,11 @@ export async function compile({ // use `sourcemap: "both"` so that sourcemap is included in the code // result passed to esbuild, but also available in the catch handler. transformResult = await transform(source, { - moduleId: filename, - pathname: filename, - sourcefile: filename, + filename, + normalizedFilename: normalizeFilename(filename, astroConfig.root), sourcemap: 'both', internalURL: 'astro/server/index.js', - injectGlobals: JSON.stringify(astroConfig.site), + astroGlobalArgs: JSON.stringify(astroConfig.site), preprocessStyle: createStylePreprocessor({ filename, viteConfig, @@ -108,3 +109,13 @@ function handleCompileResultErrors(result: TransformResult, cssTransformErrors: } } } + +function normalizeFilename(filename: string, root: URL) { + const normalizedFilename = normalizePath(filename); + const normalizedRoot = normalizePath(fileURLToPath(root)); + if (normalizedFilename.startsWith(normalizedRoot + '/')) { + return normalizedFilename.slice(normalizedRoot.length); + } else { + return normalizedFilename; + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0cf1e85b97c2..9a67142bd011 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -385,7 +385,7 @@ importers: packages/astro: specifiers: - '@astrojs/compiler': ^0.31.4 + '@astrojs/compiler': ^0.32.0 '@astrojs/language-server': ^0.28.3 '@astrojs/markdown-remark': ^2.0.0-beta.1 '@astrojs/telemetry': ^1.0.1 @@ -475,7 +475,7 @@ importers: yargs-parser: ^21.0.1 zod: ^3.17.3 dependencies: - '@astrojs/compiler': 0.31.4 + '@astrojs/compiler': 0.32.0 '@astrojs/language-server': 0.28.3 '@astrojs/markdown-remark': link:../markdown/remark '@astrojs/telemetry': link:../telemetry @@ -3828,6 +3828,10 @@ packages: /@astrojs/compiler/0.31.4: resolution: {integrity: sha512-6bBFeDTtPOn4jZaiD3p0f05MEGQL9pw2Zbfj546oFETNmjJFWO3nzHz6/m+P53calknCvyVzZ5YhoBLIvzn5iw==} + /@astrojs/compiler/0.32.0: + resolution: {integrity: sha512-QL5qMGkfsC1/kDjJF4RRagz8/hACBUb19cHWrQ8AROphS42qXM6JhoO1Og5FohV3p2VfT5CdEJspn4uNsgZvmw==} + dev: false + /@astrojs/language-server/0.28.3: resolution: {integrity: sha512-fPovAX/X46eE2w03jNRMpQ7W9m2mAvNt4Ay65lD9wl1Z5vIQYxlg7Enp9qP225muTr4jSVB5QiLumFJmZMAaVA==} hasBin: true From bb4594eb42559ad56ac13176ea043f1984b50c8f Mon Sep 17 00:00:00 2001 From: bluwy Date: Thu, 12 Jan 2023 13:09:21 +0800 Subject: [PATCH 3/9] Fix tests --- packages/astro/test/units/compile/invalid-css.test.js | 7 ++++--- .../astro/test/units/vite-plugin-astro/compile.test.js | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/astro/test/units/compile/invalid-css.test.js b/packages/astro/test/units/compile/invalid-css.test.js index 1aa50107097d..6be17620a580 100644 --- a/packages/astro/test/units/compile/invalid-css.test.js +++ b/packages/astro/test/units/compile/invalid-css.test.js @@ -2,6 +2,7 @@ import { resolveConfig } from 'vite'; import { expect } from 'chai'; import { cachedCompilation } from '../../../dist/core/compile/index.js'; import { AggregateError } from '../../../dist/core/errors/index.js'; +import { pathToFileURL } from 'url'; describe('astro/src/core/compile', () => { describe('Invalid CSS', () => { @@ -9,9 +10,9 @@ describe('astro/src/core/compile', () => { let error; try { let r = await cachedCompilation({ - astroConfig: /** @type {any} */ ({ - root: '/', - }), + astroConfig: { + root: pathToFileURL('/'), + }, viteConfig: await resolveConfig({ configFile: false }, 'serve'), filename: '/src/pages/index.astro', source: ` diff --git a/packages/astro/test/units/vite-plugin-astro/compile.test.js b/packages/astro/test/units/vite-plugin-astro/compile.test.js index 7f3eb20d7edb..1c1d53baca23 100644 --- a/packages/astro/test/units/vite-plugin-astro/compile.test.js +++ b/packages/astro/test/units/vite-plugin-astro/compile.test.js @@ -2,6 +2,7 @@ import { expect } from 'chai'; import { resolveConfig } from 'vite'; import { cachedFullCompilation } from '../../../dist/vite-plugin-astro/compile.js'; import { init, parse } from 'es-module-lexer'; +import { pathToFileURL } from 'url'; const viteConfig = await resolveConfig({ configFile: false }, 'serve'); @@ -12,7 +13,7 @@ const viteConfig = await resolveConfig({ configFile: false }, 'serve'); async function compile(source, id) { return await cachedFullCompilation({ compileProps: { - astroConfig: { root: '/', base: '/' }, + astroConfig: { root: pathToFileURL('/'), base: '/' }, viteConfig, filename: id, source, From 425bb576d1483a6a0c68b8e741e8cf9c9e7e554f Mon Sep 17 00:00:00 2001 From: bluwy Date: Thu, 12 Jan 2023 13:34:21 +0800 Subject: [PATCH 4/9] Fix test install --- .npmrc | 2 - package.json | 3 + packages/astro/src/core/compile/compile.ts | 4 +- .../fixtures/third-party-astro/package.json | 2 +- pnpm-lock.yaml | 316 ++---------------- 5 files changed, 33 insertions(+), 294 deletions(-) diff --git a/.npmrc b/.npmrc index 28128c1daa06..f44bad2825c8 100644 --- a/.npmrc +++ b/.npmrc @@ -10,7 +10,5 @@ public-hoist-pattern[]=github-slugger # Vite's esbuild optimizer has trouble optimizing `@astrojs/lit/client-shim.js` # which imports this dependency. public-hoist-pattern[]=@webcomponents/template-shadowroot -# On Windows, `svelte-preprocess` can't import `svelte/compiler`. Might be a pnpm bug. -public-hoist-pattern[]=svelte # There's a lit dependency duplication somewhere causing multiple Lit versions error. public-hoist-pattern[]=*lit* diff --git a/package.json b/package.json index 03e71b8c9457..f119d34d0598 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,9 @@ "react", "react-dom", "@types/react" + ], + "allowAny": [ + "astro" ] }, "patchedDependencies": { diff --git a/packages/astro/src/core/compile/compile.ts b/packages/astro/src/core/compile/compile.ts index 4c8beaa32629..89f226e93ea9 100644 --- a/packages/astro/src/core/compile/compile.ts +++ b/packages/astro/src/core/compile/compile.ts @@ -113,8 +113,8 @@ function handleCompileResultErrors(result: TransformResult, cssTransformErrors: function normalizeFilename(filename: string, root: URL) { const normalizedFilename = normalizePath(filename); const normalizedRoot = normalizePath(fileURLToPath(root)); - if (normalizedFilename.startsWith(normalizedRoot + '/')) { - return normalizedFilename.slice(normalizedRoot.length); + if (normalizedFilename.startsWith(normalizedRoot)) { + return normalizedFilename.slice(normalizedRoot.length - 1); } else { return normalizedFilename; } diff --git a/packages/astro/test/fixtures/third-party-astro/package.json b/packages/astro/test/fixtures/third-party-astro/package.json index f5bfdb768a87..26e11aefdd6f 100644 --- a/packages/astro/test/fixtures/third-party-astro/package.json +++ b/packages/astro/test/fixtures/third-party-astro/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "private": true, "dependencies": { - "astro": "^1.0.0", + "astro": "workspace:*", "astro-embed": "^0.1.1" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9a67142bd011..1f05719e1e33 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2471,11 +2471,11 @@ importers: packages/astro/test/fixtures/third-party-astro: specifiers: - astro: ^1.0.0 + astro: workspace:* astro-embed: ^0.1.1 dependencies: - astro: 1.9.1 - astro-embed: 0.1.3_astro@1.9.1 + astro: link:../../.. + astro-embed: 0.1.3_astro@packages+astro packages/astro/test/fixtures/type-imports: specifiers: @@ -3774,46 +3774,46 @@ packages: leven: 3.1.0 dev: false - /@astro-community/astro-embed-integration/0.1.2_astro@1.9.1: + /@astro-community/astro-embed-integration/0.1.2_astro@packages+astro: resolution: {integrity: sha512-ONBDHkOUZ7ssQNzRc5XRZtBBJR0zC68Gm2FCm5w6fxxciDkRkU9Zn9BSssgaNrLPfsXycxFLtQZT3dX9ZPsAxw==} peerDependencies: - astro: ^1.0.0-beta.10 + astro: '*' dependencies: - '@astro-community/astro-embed-twitter': 0.1.3_astro@1.9.1 - '@astro-community/astro-embed-vimeo': 0.1.1_astro@1.9.1 - '@astro-community/astro-embed-youtube': 0.2.1_astro@1.9.1 - astro: 1.9.1 + '@astro-community/astro-embed-twitter': 0.1.3_astro@packages+astro + '@astro-community/astro-embed-vimeo': 0.1.1_astro@packages+astro + '@astro-community/astro-embed-youtube': 0.2.1_astro@packages+astro + astro: link:packages/astro unist-util-select: 4.0.2 dev: false - /@astro-community/astro-embed-twitter/0.1.3_astro@1.9.1: + /@astro-community/astro-embed-twitter/0.1.3_astro@packages+astro: resolution: {integrity: sha512-lcOBnzhczNrngkafzD+8BGKiK8oJvahg3/QUuWgueNwHRU8C+18brdxKc1i4ttZWgAt1A5u+jx21Tc4bquMUzg==} peerDependencies: - astro: ^1.0.0-beta.10 + astro: '*' dependencies: '@astro-community/astro-embed-utils': 0.0.3 - astro: 1.9.1 + astro: link:packages/astro dev: false /@astro-community/astro-embed-utils/0.0.3: resolution: {integrity: sha512-hXwSMtSAL3V9fnFHps+/CoDIJst26U/qSdI7srIQ8GPmFqdbcqJd/qOqYzGezAR/qTM8gmTjDCGOuVI0Z+xT3Q==} dev: false - /@astro-community/astro-embed-vimeo/0.1.1_astro@1.9.1: + /@astro-community/astro-embed-vimeo/0.1.1_astro@packages+astro: resolution: {integrity: sha512-M7ALKJkH8NDJFY+onsKvlxq7Lpj6FQm90W/+0cGilrdWkKBAYPVLApnkAcUf2strg/4cQ2otZekXI6uvU4ruzg==} peerDependencies: - astro: ^1.0.0-beta.10 + astro: '*' dependencies: - astro: 1.9.1 + astro: link:packages/astro lite-vimeo-embed: 0.1.0 dev: false - /@astro-community/astro-embed-youtube/0.2.1_astro@1.9.1: + /@astro-community/astro-embed-youtube/0.2.1_astro@packages+astro: resolution: {integrity: sha512-yO2u9MCDQwxRYnZixYcRbBU/QrrBI+69GLDh9W+M/dsgmSZxtZY4kG00ewmC+Lr0JCLteaxz2iSY1U61+WNfEw==} peerDependencies: - astro: ^1.0.0-beta.10 + astro: '*' dependencies: - astro: 1.9.1 + astro: link:packages/astro lite-youtube-embed: 0.2.0 dev: false @@ -3850,80 +3850,12 @@ packages: vscode-uri: 3.0.7 dev: false - /@astrojs/markdown-remark/1.2.0: - resolution: {integrity: sha512-Cb+uhSuukyfERknfJ8K4iJLeKJaiZWi1BTwPS4fzw0bc9kGKe5VeTRzd2E25+vaMnRTk0tN/y6QfYEMMN3Q97g==} - dependencies: - '@astrojs/micromark-extension-mdx-jsx': 1.0.3 - '@astrojs/prism': 1.0.2 - acorn: 8.8.1 - acorn-jsx: 5.3.2_acorn@8.8.1 - github-slugger: 1.5.0 - hast-util-to-html: 8.0.4 - import-meta-resolve: 2.2.1 - mdast-util-from-markdown: 1.2.0 - mdast-util-mdx-expression: 1.3.1 - mdast-util-mdx-jsx: 1.2.0 - micromark-extension-mdx-expression: 1.0.3 - micromark-extension-mdx-md: 1.0.0 - micromark-util-combine-extensions: 1.0.0 - rehype-raw: 6.1.1 - rehype-stringify: 9.0.3 - remark-gfm: 3.0.1 - remark-parse: 10.0.1 - remark-rehype: 10.1.0 - remark-smartypants: 2.0.0 - shiki: 0.11.1 - unified: 10.1.2 - unist-util-map: 3.1.2 - unist-util-visit: 4.1.1 - vfile: 5.3.6 - transitivePeerDependencies: - - supports-color - dev: false - - /@astrojs/micromark-extension-mdx-jsx/1.0.3: - resolution: {integrity: sha512-O15+i2DGG0qb1R/1SYbFXgOKDGbYdV8iJMtuboVb1S9YFQfMOJxaCMco0bhXQI7PmZcQ4pZWIjT5oZ64dXUtRA==} - dependencies: - '@types/acorn': 4.0.6 - estree-util-is-identifier-name: 2.0.1 - micromark-factory-mdx-expression: 1.0.6 - micromark-factory-space: 1.0.0 - micromark-util-character: 1.1.0 - micromark-util-symbol: 1.0.1 - micromark-util-types: 1.0.2 - uvu: 0.5.6 - vfile-message: 3.1.3 - dev: false - /@astrojs/node/1.1.0: resolution: {integrity: sha512-4KkCEFYtmTUSvU49UZSJD/VQfD/oKzf0ld8COjFW1pxfquBgvevLxRVpYLRanZB20L3c8/xyyQpDq7zMSMqQrg==} dependencies: '@astrojs/webapi': 1.1.1 dev: false - /@astrojs/prism/1.0.2: - resolution: {integrity: sha512-o3cUVoAuALDqdN5puNlsN2eO4Yi1kDh68YO8V7o6U4Ts+J/mMayzlJ7JsgYAmob0xrf/XnADVgu8khfMv/w3uA==} - engines: {node: ^14.18.0 || >=16.12.0} - dependencies: - prismjs: 1.29.0 - dev: false - - /@astrojs/telemetry/1.0.1: - resolution: {integrity: sha512-SJVfZHp00f8VZsT1fsx1+6acJGUNt/84xZytV5znPzzNE8RXjlE0rv03llgTsEeUHYZc6uJah91jNojS7RldFg==} - engines: {node: ^14.18.0 || >=16.12.0} - dependencies: - ci-info: 3.7.1 - debug: 4.3.4 - dlv: 1.1.3 - dset: 3.1.2 - is-docker: 3.0.0 - is-wsl: 2.2.0 - node-fetch: 3.3.0 - which-pm-runs: 1.1.0 - transitivePeerDependencies: - - supports-color - dev: false - /@astrojs/webapi/1.1.1: resolution: {integrity: sha512-yeUvP27PoiBK/WCxyQzC4HLYZo4Hg6dzRd/dTsL50WGlAQVCwWcqzVJrIZKvzNDNaW/fIXutZTmdj6nec0PIGg==} dependencies: @@ -6613,15 +6545,6 @@ packages: escalade: 3.1.1 dev: false - /@proload/plugin-tsm/0.2.1_@proload+core@0.3.3: - resolution: {integrity: sha512-Ex1sL2BxU+g8MHdAdq9SZKz+pU34o8Zcl9PHWo2WaG9hrnlZme607PU6gnpoAYsDBpHX327+eu60wWUk+d/b+A==} - peerDependencies: - '@proload/core': ^0.3.2 - dependencies: - '@proload/core': 0.3.3 - tsm: 2.3.0 - dev: false - /@rollup/plugin-alias/3.1.9_rollup@2.79.1: resolution: {integrity: sha512-QI5fsEvm9bDzt32k39wpOwZhVzRcL5ydcffUHMyLVaVaLeC70I8TJZ17F1z1eMoLu4E/UOcH9BWVkKpIKdrfiw==} engines: {node: '>=8.0.0'} @@ -6923,12 +6846,6 @@ packages: resolution: {integrity: sha512-OyiZ3jEKu7RtGO1yp9oOdK0cTwZ/10oE9PDJ6fyN3r9T5wkyOcvr6awdugjYdqF6KVO5eUvt7jx7rk2Eylufow==} dev: true - /@types/estree-jsx/0.0.1: - resolution: {integrity: sha512-gcLAYiMfQklDCPjQegGn0TBAn9it05ISEsEhlKQUddIk7o2XDokOcTN7HBO8tznM0D9dGezvHEfRZBfZf6me0A==} - dependencies: - '@types/estree': 1.0.0 - dev: false - /@types/estree-jsx/1.0.0: resolution: {integrity: sha512-3qvGd0z8F2ENTGr/GG1yViqfiKmRfrXVx5sJyHGFu3z7m5g5utCQtGp/g29JnjflhtQJBv1WDQukHiT58xPcYQ==} dependencies: @@ -6979,6 +6896,7 @@ packages: /@types/html-escaper/3.0.0: resolution: {integrity: sha512-OcJcvP3Yk8mjYwf/IdXZtTE1tb/u0WF0qa29ER07ZHCYUBZXSN29Z1mBS+/96+kNMGTFUAbSz9X+pHmHpZrTCw==} + dev: true /@types/http-cache-semantics/4.0.1: resolution: {integrity: sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ==} @@ -7869,107 +7787,21 @@ packages: tslib: 2.4.1 dev: true - /ast-types/0.14.2: - resolution: {integrity: sha512-O0yuUDnZeQDL+ncNGlJ78BiO4jnYI3bvMsD5prT0/nsgijG/LpNBIr63gTjVTNsiGkgQhiyCShTgxt8oXOrklA==} - engines: {node: '>=4'} - dependencies: - tslib: 2.4.1 - dev: false - /astring/1.8.4: resolution: {integrity: sha512-97a+l2LBU3Op3bBQEff79i/E4jMD2ZLFD8rHx9B6mXyB2uQwhJQYfiDqUwtfjF4QA1F2qs//N6Cw8LetMbQjcw==} hasBin: true dev: false - /astro-embed/0.1.3_astro@1.9.1: + /astro-embed/0.1.3_astro@packages+astro: resolution: {integrity: sha512-ztKlhFdUqlSlE5frybHLHQILsgBLnlcN2PejtkYEaIZHvysteiniT6Rg1o08z7+0FIt/KVE+8L/Y5g3ufFWdPg==} peerDependencies: - astro: ^1.0.0-beta.10 - dependencies: - '@astro-community/astro-embed-integration': 0.1.2_astro@1.9.1 - '@astro-community/astro-embed-twitter': 0.1.3_astro@1.9.1 - '@astro-community/astro-embed-vimeo': 0.1.1_astro@1.9.1 - '@astro-community/astro-embed-youtube': 0.2.1_astro@1.9.1 - astro: 1.9.1 - dev: false - - /astro/1.9.1: - resolution: {integrity: sha512-aQ6rvAP4w4VCgipVYA/zPmnkuTbFrMZ/+x/sAv2W1uJHWU2iQmrVRrrjUFJl+i1TuYYlHAuC2vKK7aRyXCjD4A==} - engines: {node: ^14.18.0 || >=16.12.0, npm: '>=6.14.0'} - hasBin: true + astro: '*' dependencies: - '@astrojs/compiler': 0.31.4 - '@astrojs/language-server': 0.28.3 - '@astrojs/markdown-remark': 1.2.0 - '@astrojs/telemetry': 1.0.1 - '@astrojs/webapi': 1.1.1 - '@babel/core': 7.20.12 - '@babel/generator': 7.20.7 - '@babel/parser': 7.20.7 - '@babel/plugin-transform-react-jsx': 7.20.7_@babel+core@7.20.12 - '@babel/traverse': 7.20.12 - '@babel/types': 7.20.7 - '@proload/core': 0.3.3 - '@proload/plugin-tsm': 0.2.1_@proload+core@0.3.3 - '@types/babel__core': 7.1.20 - '@types/html-escaper': 3.0.0 - '@types/yargs-parser': 21.0.0 - acorn: 8.8.1 - boxen: 6.2.1 - ci-info: 3.7.1 - common-ancestor-path: 1.0.1 - cookie: 0.5.0 - debug: 4.3.4 - deepmerge-ts: 4.2.2 - devalue: 4.2.1 - diff: 5.1.0 - es-module-lexer: 1.1.0 - estree-walker: 3.0.2 - execa: 6.1.0 - fast-glob: 3.2.12 - github-slugger: 2.0.0 - gray-matter: 4.0.3 - html-entities: 2.3.3 - html-escaper: 3.0.3 - import-meta-resolve: 2.2.1 - kleur: 4.1.5 - magic-string: 0.27.0 - mime: 3.0.0 - ora: 6.1.2 - path-browserify: 1.0.1 - path-to-regexp: 6.2.1 - postcss: 8.4.21 - postcss-load-config: 3.1.4_postcss@8.4.21 - preferred-pm: 3.0.3 - prompts: 2.4.2 - recast: 0.20.5 - rehype: 12.0.1 - resolve: 1.22.1 - rollup: 2.79.1 - semver: 7.3.8 - shiki: 0.11.1 - sirv: 2.0.2 - slash: 4.0.0 - string-width: 5.1.2 - strip-ansi: 7.0.1 - supports-esm: 1.0.0 - tsconfig-resolver: 3.0.1 - typescript: 4.9.4 - unist-util-visit: 4.1.1 - vfile: 5.3.6 - vite: 3.2.5 - vitefu: 0.2.4_vite@3.2.5 - yargs-parser: 21.1.1 - zod: 3.20.2 - transitivePeerDependencies: - - '@types/node' - - less - - sass - - stylus - - sugarss - - supports-color - - terser - - ts-node + '@astro-community/astro-embed-integration': 0.1.2_astro@packages+astro + '@astro-community/astro-embed-twitter': 0.1.3_astro@packages+astro + '@astro-community/astro-embed-vimeo': 0.1.1_astro@packages+astro + '@astro-community/astro-embed-youtube': 0.2.1_astro@packages+astro + astro: link:packages/astro dev: false /async-sema/3.1.1: @@ -11537,19 +11369,6 @@ packages: transitivePeerDependencies: - supports-color - /mdast-util-mdx-jsx/1.2.0: - resolution: {integrity: sha512-5+ot/kfxYd3ChgEMwsMUO71oAfYjyRI3pADEK4I7xTmWLGQ8Y7ghm1CG36zUoUvDPxMlIYwQV/9DYHAUWdG4dA==} - dependencies: - '@types/estree-jsx': 0.0.1 - '@types/mdast': 3.0.10 - mdast-util-to-markdown: 1.5.0 - parse-entities: 4.0.0 - stringify-entities: 4.0.3 - unist-util-remove-position: 4.0.1 - unist-util-stringify-position: 3.0.2 - vfile-message: 3.1.3 - dev: false - /mdast-util-mdx-jsx/2.1.0: resolution: {integrity: sha512-KzgzfWMhdteDkrY4mQtyvTU5bc/W4ppxhe9SzelO6QUUiwLAM+Et2Dnjjprik74a336kHdo0zKm7Tp+n6FFeRg==} dependencies: @@ -12664,6 +12483,7 @@ packages: /path-browserify/1.0.1: resolution: {integrity: sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==} + dev: true /path-exists/3.0.0: resolution: {integrity: sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==} @@ -13414,16 +13234,6 @@ packages: /reading-time/1.5.0: resolution: {integrity: sha512-onYyVhBNr4CmAxFsKS7bz+uTLRakypIe4R+5A824vBSkQy/hB3fZepoVEf8OVAxzLvK+H/jm9TzpI3ETSm64Kg==} - /recast/0.20.5: - resolution: {integrity: sha512-E5qICoPoNL4yU0H0NoBDntNB0Q5oMSNh9usFctYniLBluTthi3RsQVBXIJNbApOlvSwW/RGxIuokPcAc59J5fQ==} - engines: {node: '>= 4'} - dependencies: - ast-types: 0.14.2 - esprima: 4.0.1 - source-map: 0.6.1 - tslib: 2.4.1 - dev: false - /redent/3.0.0: resolution: {integrity: sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg==} engines: {node: '>=8'} @@ -14065,15 +13875,6 @@ packages: totalist: 1.1.0 dev: false - /sirv/2.0.2: - resolution: {integrity: sha512-4Qog6aE29nIjAOKe/wowFTxOdmbEZKb+3tsLljaBRzJwtqto0BChD2zzH0LhgCSXiI+V7X+Y45v14wBZQ1TK3w==} - engines: {node: '>= 10'} - dependencies: - '@polka/url': 1.0.0-next.21 - mrmime: 1.0.1 - totalist: 3.0.0 - dev: false - /sisteransi/1.0.5: resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} dev: false @@ -14598,11 +14399,6 @@ packages: engines: {node: '>=6'} dev: false - /totalist/3.0.0: - resolution: {integrity: sha512-eM+pCBxXO/njtF7vdFsHuqb+ElbxqtI4r5EAvk6grfAFyJ6IvWlSkfZ5T9ozC6xWw3Fj1fGoSmrl0gUs46JVIw==} - engines: {node: '>=6'} - dev: false - /tr46/0.0.3: resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} @@ -14665,14 +14461,6 @@ packages: /tslib/2.4.1: resolution: {integrity: sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==} - /tsm/2.3.0: - resolution: {integrity: sha512-++0HFnmmR+gMpDtKTnW3XJ4yv9kVGi20n+NfyQWB9qwJvTaIWY9kBmzek2YUQK5APTQ/1DTrXmm4QtFPmW9Rzw==} - engines: {node: '>=12'} - hasBin: true - dependencies: - esbuild: 0.15.18 - dev: false - /tsutils/3.21.0_typescript@4.7.4: resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} engines: {node: '>= 6'} @@ -14997,12 +14785,6 @@ packages: /unist-util-is/5.1.1: resolution: {integrity: sha512-F5CZ68eYzuSvJjGhCLPL3cYx45IxkqXSetCcRgUXtbcm50X2L9oOWQlfUfDdAf+6Pd27YDblBfdtmsThXmwpbQ==} - /unist-util-map/3.1.2: - resolution: {integrity: sha512-WLA2R6x/UaopedG2poaWLShf5LCi+BNa6mMkACdjft23PHou4v85PvZItjbO2XgXvukMP365PlL/DrbuMgr3eg==} - dependencies: - '@types/unist': 2.0.6 - dev: false - /unist-util-modify-children/3.1.0: resolution: {integrity: sha512-L0UizdncPZ1NIwpmkwFdLo2NaK2Eb5LU/vaQ7lZGkAaOBZfsHp+8T/gVWPVmmMO1hj6gc+XeMoytut8jr7fdyA==} dependencies: @@ -15244,39 +15026,6 @@ packages: - supports-color dev: false - /vite/3.2.5: - resolution: {integrity: sha512-4mVEpXpSOgrssFZAOmGIr85wPHKvaDAcXqxVxVRZhljkJOMZi1ibLibzjLHzJvcok8BMguLc7g1W6W/GqZbLdQ==} - engines: {node: ^14.18.0 || >=16.0.0} - hasBin: true - peerDependencies: - '@types/node': '>= 14' - less: '*' - sass: '*' - stylus: '*' - sugarss: '*' - terser: ^5.4.0 - peerDependenciesMeta: - '@types/node': - optional: true - less: - optional: true - sass: - optional: true - stylus: - optional: true - sugarss: - optional: true - terser: - optional: true - dependencies: - esbuild: 0.15.18 - postcss: 8.4.21 - resolve: 1.22.1 - rollup: 2.79.1 - optionalDependencies: - fsevents: 2.3.2 - dev: false - /vite/3.2.5_@types+node@18.11.18: resolution: {integrity: sha512-4mVEpXpSOgrssFZAOmGIr85wPHKvaDAcXqxVxVRZhljkJOMZi1ibLibzjLHzJvcok8BMguLc7g1W6W/GqZbLdQ==} engines: {node: ^14.18.0 || >=16.0.0} @@ -15420,17 +15169,6 @@ packages: optional: true dev: false - /vitefu/0.2.4_vite@3.2.5: - resolution: {integrity: sha512-fanAXjSaf9xXtOOeno8wZXIhgia+CZury481LsDaV++lSvcU2R9Ch2bPh3PYFyoHW+w9LqAeYRISVQjUIew14g==} - peerDependencies: - vite: ^3.0.0 || ^4.0.0 - peerDependenciesMeta: - vite: - optional: true - dependencies: - vite: 3.2.5 - dev: false - /vitefu/0.2.4_vite@4.0.4: resolution: {integrity: sha512-fanAXjSaf9xXtOOeno8wZXIhgia+CZury481LsDaV++lSvcU2R9Ch2bPh3PYFyoHW+w9LqAeYRISVQjUIew14g==} peerDependencies: From 3292c13509660e469a7f1e2425d686e8ba2d0c5b Mon Sep 17 00:00:00 2001 From: bluwy Date: Thu, 12 Jan 2023 16:42:13 +0800 Subject: [PATCH 5/9] Handle stable hash HMR --- packages/astro/src/vite-plugin-astro/hmr.ts | 34 +++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/packages/astro/src/vite-plugin-astro/hmr.ts b/packages/astro/src/vite-plugin-astro/hmr.ts index dbee93b495fd..d0e8f51c4b24 100644 --- a/packages/astro/src/vite-plugin-astro/hmr.ts +++ b/packages/astro/src/vite-plugin-astro/hmr.ts @@ -1,7 +1,12 @@ import { fileURLToPath } from 'node:url'; import type { HmrContext, ModuleNode } from 'vite'; import type { AstroConfig } from '../@types/astro'; -import { cachedCompilation, invalidateCompilation, isCached } from '../core/compile/index.js'; +import { + cachedCompilation, + CompileResult, + invalidateCompilation, + isCached, +} from '../core/compile/index.js'; import type { LogOptions } from '../core/logger/core.js'; import { info } from '../core/logger/core.js'; import * as msg from '../core/messages.js'; @@ -30,8 +35,7 @@ export async function handleHotUpdate( // But we also need a fresh, uncached result to compare it to invalidateCompilation(config, ctx.file); const newResult = await compile(); - // If the hashes are identical, we assume only styles have changed - if (oldResult.scope === newResult.scope) { + if (isStyleOnlyChanged(oldResult, newResult)) { isStyleOnlyChange = true; // All styles are the same, we can skip an HMR update const styles = new Set(newResult.css); @@ -134,3 +138,27 @@ export async function handleHotUpdate( return mods; } + +const astroStyleImportRE = /import\s*"[^"]+astro&type=style[^"]+"/g; + +function isStyleOnlyChanged(oldResult: CompileResult, newResult: CompileResult) { + // When a style tag is added/removed, it adds/removes the import. + // Normalized it here to verify if non-style code has changed. + const oldCode = oldResult.code.replace(astroStyleImportRE, ''); + const newCode = newResult.code.replace(astroStyleImportRE, ''); + if (oldCode !== newCode) return false; + // If non-style code is the same, check if styles are different + return !isArrayEqual(oldResult.css, newResult.css); +} + +function isArrayEqual(a: any[], b: any[]) { + if (a.length !== b.length) { + return false; + } + for (let i = 0; i < a.length; i++) { + if (a[i] !== b[i]) { + return false; + } + } + return true; +} From 892345dcef1dea5e50faf4546d20790421a12ae0 Mon Sep 17 00:00:00 2001 From: bluwy Date: Thu, 12 Jan 2023 19:11:08 +0800 Subject: [PATCH 6/9] Fix style reload --- packages/astro/src/core/compile/compile.ts | 2 +- packages/astro/src/vite-plugin-astro/hmr.ts | 34 +++++++++------------ 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/packages/astro/src/core/compile/compile.ts b/packages/astro/src/core/compile/compile.ts index 89f226e93ea9..7e8dc8a31927 100644 --- a/packages/astro/src/core/compile/compile.ts +++ b/packages/astro/src/core/compile/compile.ts @@ -3,8 +3,8 @@ import type { ResolvedConfig } from 'vite'; import type { AstroConfig } from '../../@types/astro'; import { transform } from '@astrojs/compiler'; -import { normalizePath } from 'vite'; import { fileURLToPath } from 'url'; +import { normalizePath } from 'vite'; import { AggregateError, AstroError, CompilerError } from '../errors/errors.js'; import { AstroErrorData } from '../errors/index.js'; import { resolvePath } from '../util.js'; diff --git a/packages/astro/src/vite-plugin-astro/hmr.ts b/packages/astro/src/vite-plugin-astro/hmr.ts index d0e8f51c4b24..93631a2f9975 100644 --- a/packages/astro/src/vite-plugin-astro/hmr.ts +++ b/packages/astro/src/vite-plugin-astro/hmr.ts @@ -37,16 +37,6 @@ export async function handleHotUpdate( const newResult = await compile(); if (isStyleOnlyChanged(oldResult, newResult)) { isStyleOnlyChange = true; - // All styles are the same, we can skip an HMR update - const styles = new Set(newResult.css); - for (const style of oldResult.css) { - if (styles.has(style)) { - styles.delete(style); - } - } - if (styles.size === 0) { - return []; - } } } else { invalidateCompilation(config, ctx.file); @@ -139,16 +129,22 @@ export async function handleHotUpdate( return mods; } -const astroStyleImportRE = /import\s*"[^"]+astro&type=style[^"]+"/g; - function isStyleOnlyChanged(oldResult: CompileResult, newResult: CompileResult) { - // When a style tag is added/removed, it adds/removes the import. - // Normalized it here to verify if non-style code has changed. - const oldCode = oldResult.code.replace(astroStyleImportRE, ''); - const newCode = newResult.code.replace(astroStyleImportRE, ''); - if (oldCode !== newCode) return false; - // If non-style code is the same, check if styles are different - return !isArrayEqual(oldResult.css, newResult.css); + return ( + normalizeCode(oldResult.code) === normalizeCode(newResult.code) && + !isArrayEqual(oldResult.css, newResult.css) + ); +} + +const astroStyleImportRE = /import\s*"[^"]+astro&type=style[^"]+";/g; +const sourceMappingUrlRE = /\/\/# sourceMappingURL=[^ ]+$/gm; + +/** + * Remove style-related code and sourcemap from the final astro output so they + * can be compared between non-style code + */ +function normalizeCode(code: string) { + return code.replace(astroStyleImportRE, '').replace(sourceMappingUrlRE, '').trim(); } function isArrayEqual(a: any[], b: any[]) { From 72a8db8b512aa8e1a6434ad2136c1e246eaa98f9 Mon Sep 17 00:00:00 2001 From: bluwy Date: Thu, 12 Jan 2023 19:29:54 +0800 Subject: [PATCH 7/9] Skip HMR if source same --- packages/astro/src/vite-plugin-astro/hmr.ts | 7 +++++-- packages/astro/src/vite-plugin-astro/index.ts | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/vite-plugin-astro/hmr.ts b/packages/astro/src/vite-plugin-astro/hmr.ts index 93631a2f9975..ff972d660e99 100644 --- a/packages/astro/src/vite-plugin-astro/hmr.ts +++ b/packages/astro/src/vite-plugin-astro/hmr.ts @@ -22,17 +22,20 @@ export interface HandleHotUpdateOptions { config: AstroConfig; logging: LogOptions; compile: () => ReturnType; + source: string; } export async function handleHotUpdate( ctx: HmrContext, - { config, logging, compile }: HandleHotUpdateOptions + { config, logging, compile, source }: HandleHotUpdateOptions ) { let isStyleOnlyChange = false; if (ctx.file.endsWith('.astro') && isCached(config, ctx.file)) { // Get the compiled result from the cache const oldResult = await compile(); - // But we also need a fresh, uncached result to compare it to + // Skip HMR if source isn't changed + if (oldResult.source === source) return []; + // Invalidate to get fresh, uncached result to compare it to invalidateCompilation(config, ctx.file); const newResult = await compile(); if (isStyleOnlyChanged(oldResult, newResult)) { diff --git a/packages/astro/src/vite-plugin-astro/index.ts b/packages/astro/src/vite-plugin-astro/index.ts index 62f6a1627b81..765c7a3515ad 100644 --- a/packages/astro/src/vite-plugin-astro/index.ts +++ b/packages/astro/src/vite-plugin-astro/index.ts @@ -179,6 +179,7 @@ export default function astro({ settings, logging }: AstroPluginOptions): vite.P config, logging, compile, + source: compileProps.source, }); }, }; From 3432dd79521a9d84ee6c02eeee15bbd636759e1f Mon Sep 17 00:00:00 2001 From: bluwy Date: Thu, 12 Jan 2023 19:51:32 +0800 Subject: [PATCH 8/9] Add changeset [skip ci] --- .changeset/dull-rabbits-relax.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/dull-rabbits-relax.md diff --git a/.changeset/dull-rabbits-relax.md b/.changeset/dull-rabbits-relax.md new file mode 100644 index 000000000000..03bf99dac03f --- /dev/null +++ b/.changeset/dull-rabbits-relax.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Upgrade compiler and handle breaking changes From 5f1c619b48c9512d861ff01a629bbb858bab31fa Mon Sep 17 00:00:00 2001 From: bluwy Date: Thu, 12 Jan 2023 19:53:34 +0800 Subject: [PATCH 9/9] Fix comment typo [skip ci] --- packages/astro/src/runtime/server/astro-global.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro/src/runtime/server/astro-global.ts b/packages/astro/src/runtime/server/astro-global.ts index d175bc2e9acb..7ed51132239d 100644 --- a/packages/astro/src/runtime/server/astro-global.ts +++ b/packages/astro/src/runtime/server/astro-global.ts @@ -17,7 +17,7 @@ function createAstroGlobFn() { } // This is used to create the top-level Astro global; the one that you can use -// inside of getStaticPaths. See the `injectGlobals` option for parameter type. +// inside of getStaticPaths. See the `astroGlobalArgs` option for parameter type. export function createAstro(site: string | undefined): AstroGlobalPartial { return { site: site ? new URL(site) : undefined,