From 08ff4c3d21f4ced3e81fb4ac0138f29b6ddc8921 Mon Sep 17 00:00:00 2001 From: bluwy Date: Wed, 14 Sep 2022 22:00:22 +0800 Subject: [PATCH 1/3] Support Vite 3.1 --- .changeset/shaggy-books-give.md | 5 +++++ packages/astro/src/vite-plugin-astro/index.ts | 6 +++--- .../astro/src/vite-style-transform/style-transform.ts | 8 +------- .../astro/src/vite-style-transform/transform-with-vite.ts | 5 ++++- 4 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 .changeset/shaggy-books-give.md diff --git a/.changeset/shaggy-books-give.md b/.changeset/shaggy-books-give.md new file mode 100644 index 000000000000..1f5c26945aa9 --- /dev/null +++ b/.changeset/shaggy-books-give.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Support Vite 3.1 diff --git a/packages/astro/src/vite-plugin-astro/index.ts b/packages/astro/src/vite-plugin-astro/index.ts index d946dd2566aa..5d1bf2c181d9 100644 --- a/packages/astro/src/vite-plugin-astro/index.ts +++ b/packages/astro/src/vite-plugin-astro/index.ts @@ -340,17 +340,17 @@ ${source} throw err; } }, - async handleHotUpdate(this: PluginContext, context) { + async handleHotUpdate(context) { if (context.server.config.isProduction) return; const compileProps: CompileProps = { config, filename: context.file, moduleId: context.file, source: await context.read(), - transformStyle: createTransformStyles(styleTransformer, context.file, true, this), + transformStyle: createTransformStyles(styleTransformer, context.file, true), }; const compile = () => cachedCompilation(compileProps); - return handleHotUpdate.call(this, context, { + return handleHotUpdate(context, { config, logging, compile, diff --git a/packages/astro/src/vite-style-transform/style-transform.ts b/packages/astro/src/vite-style-transform/style-transform.ts index 276a52246fcd..6c63158af805 100644 --- a/packages/astro/src/vite-style-transform/style-transform.ts +++ b/packages/astro/src/vite-style-transform/style-transform.ts @@ -30,14 +30,8 @@ export function createTransformStyles( viteStyleTransformer: ViteStyleTransformer, filename: string, ssr: boolean, - pluginContext: PluginContext + pluginContext?: PluginContext ): TransformStyle { - // handleHotUpdate doesn't have `addWatchFile` used by transformStyleWithVite. - // TODO, refactor, why is this happening *here* ? - if (!pluginContext.addWatchFile) { - pluginContext.addWatchFile = () => {}; - } - const normalizedID = getNormalizedIDForPostCSS(filename); return async function (styleSource, lang) { diff --git a/packages/astro/src/vite-style-transform/transform-with-vite.ts b/packages/astro/src/vite-style-transform/transform-with-vite.ts index e473531fe455..71276dd0de38 100644 --- a/packages/astro/src/vite-style-transform/transform-with-vite.ts +++ b/packages/astro/src/vite-style-transform/transform-with-vite.ts @@ -46,7 +46,10 @@ export function createTransformStyleWithViteFn( viteDevServer?.moduleGraph.ensureEntryFromUrl(styleId, ssr, false); - const transformResult = await transformCss.call(this, source, styleId, ssr); + // This function could be called in a custom Vite hook like `handleHotUpdate` + // which doesn't have a context + const ctx = this ?? { addWatchFile: () => {} }; + const transformResult = await transformCss.call(ctx, source, styleId, ssr); // NOTE: only `code` and `map` are returned by vite:css const { code, map } = transformResult; From b8c56e7bd9dbe4d74d1f948370da3ed027316166 Mon Sep 17 00:00:00 2001 From: bluwy Date: Wed, 14 Sep 2022 22:28:06 +0800 Subject: [PATCH 2/3] Update ~3.1.0 --- packages/astro/package.json | 2 +- pnpm-lock.yaml | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/astro/package.json b/packages/astro/package.json index a99312e641ee..f5f54928e127 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -149,7 +149,7 @@ "tsconfig-resolver": "^3.0.1", "unist-util-visit": "^4.1.0", "vfile": "^5.3.2", - "vite": "3.0.9", + "vite": "~3.1.0", "yargs-parser": "^21.0.1", "zod": "^3.17.3" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index da16c7c16273..56fbc13f85e9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -417,7 +417,7 @@ importers: tsconfig-resolver: ^3.0.1 unist-util-visit: ^4.1.0 vfile: ^5.3.2 - vite: 3.0.9 + vite: ~3.1.0 yargs-parser: ^21.0.1 zod: ^3.17.3 dependencies: @@ -475,7 +475,7 @@ importers: tsconfig-resolver: 3.0.1 unist-util-visit: 4.1.1 vfile: 5.3.5 - vite: 3.0.9_sass@1.54.9 + vite: 3.1.0_sass@1.54.9 yargs-parser: 21.1.1 zod: 3.19.1 devDependencies: @@ -17328,8 +17328,8 @@ packages: - supports-color dev: false - /vite/3.0.9_sass@1.54.9: - resolution: {integrity: sha512-waYABTM+G6DBTCpYAxvevpG50UOlZuynR0ckTK5PawNVt7ebX6X7wNXHaGIO6wYYFXSM7/WcuFuO2QzhBB6aMw==} + /vite/3.1.0: + resolution: {integrity: sha512-YBg3dUicDpDWFCGttmvMbVyS9ydjntwEjwXRj2KBFwSB8SxmGcudo1yb8FW5+M/G86aS8x828ujnzUVdsLjs9g==} engines: {node: ^14.18.0 || >=16.0.0} hasBin: true peerDependencies: @@ -17347,16 +17347,15 @@ packages: terser: optional: true dependencies: - esbuild: 0.14.54 + esbuild: 0.15.7 postcss: 8.4.16 resolve: 1.22.1 - rollup: 2.77.3 - sass: 1.54.9 + rollup: 2.78.1 optionalDependencies: fsevents: 2.3.2 dev: false - /vite/3.1.0: + /vite/3.1.0_sass@1.54.9: resolution: {integrity: sha512-YBg3dUicDpDWFCGttmvMbVyS9ydjntwEjwXRj2KBFwSB8SxmGcudo1yb8FW5+M/G86aS8x828ujnzUVdsLjs9g==} engines: {node: ^14.18.0 || >=16.0.0} hasBin: true @@ -17379,6 +17378,7 @@ packages: postcss: 8.4.16 resolve: 1.22.1 rollup: 2.78.1 + sass: 1.54.9 optionalDependencies: fsevents: 2.3.2 dev: false From 60a1a5931107fc845c13279c78cf70ea8015eef4 Mon Sep 17 00:00:00 2001 From: bluwy Date: Wed, 14 Sep 2022 22:44:22 +0800 Subject: [PATCH 3/3] Revert Vite bump --- packages/astro/package.json | 2 +- pnpm-lock.yaml | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/astro/package.json b/packages/astro/package.json index f5f54928e127..a99312e641ee 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -149,7 +149,7 @@ "tsconfig-resolver": "^3.0.1", "unist-util-visit": "^4.1.0", "vfile": "^5.3.2", - "vite": "~3.1.0", + "vite": "3.0.9", "yargs-parser": "^21.0.1", "zod": "^3.17.3" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index af1cabae24a4..c8412144d61e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -417,7 +417,7 @@ importers: tsconfig-resolver: ^3.0.1 unist-util-visit: ^4.1.0 vfile: ^5.3.2 - vite: ~3.1.0 + vite: 3.0.9 yargs-parser: ^21.0.1 zod: ^3.17.3 dependencies: @@ -475,7 +475,7 @@ importers: tsconfig-resolver: 3.0.1 unist-util-visit: 4.1.1 vfile: 5.3.5 - vite: 3.1.0_sass@1.54.9 + vite: 3.0.9_sass@1.54.9 yargs-parser: 21.1.1 zod: 3.19.1 devDependencies: @@ -17328,8 +17328,8 @@ packages: - supports-color dev: false - /vite/3.1.0: - resolution: {integrity: sha512-YBg3dUicDpDWFCGttmvMbVyS9ydjntwEjwXRj2KBFwSB8SxmGcudo1yb8FW5+M/G86aS8x828ujnzUVdsLjs9g==} + /vite/3.0.9_sass@1.54.9: + resolution: {integrity: sha512-waYABTM+G6DBTCpYAxvevpG50UOlZuynR0ckTK5PawNVt7ebX6X7wNXHaGIO6wYYFXSM7/WcuFuO2QzhBB6aMw==} engines: {node: ^14.18.0 || >=16.0.0} hasBin: true peerDependencies: @@ -17347,15 +17347,16 @@ packages: terser: optional: true dependencies: - esbuild: 0.15.7 + esbuild: 0.14.54 postcss: 8.4.16 resolve: 1.22.1 - rollup: 2.78.1 + rollup: 2.77.3 + sass: 1.54.9 optionalDependencies: fsevents: 2.3.2 dev: false - /vite/3.1.0_sass@1.54.9: + /vite/3.1.0: resolution: {integrity: sha512-YBg3dUicDpDWFCGttmvMbVyS9ydjntwEjwXRj2KBFwSB8SxmGcudo1yb8FW5+M/G86aS8x828ujnzUVdsLjs9g==} engines: {node: ^14.18.0 || >=16.0.0} hasBin: true @@ -17378,7 +17379,6 @@ packages: postcss: 8.4.16 resolve: 1.22.1 rollup: 2.78.1 - sass: 1.54.9 optionalDependencies: fsevents: 2.3.2 dev: false