Skip to content

Commit

Permalink
fix: ensure vite is not imported by runtime utils (#11847)
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic authored Aug 27, 2024
1 parent 2bb72c6 commit 45b599c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-papayas-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes a case where Vite would be imported by the SSR runtime, causing bundling errors and bloat.
3 changes: 2 additions & 1 deletion packages/astro/src/content/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
import { slug as githubSlug } from 'github-slugger';
import matter from 'gray-matter';
import type { PluginContext } from 'rollup';
import { type ViteDevServer, normalizePath } from 'vite';
import type { ViteDevServer } from 'vite';
import xxhash from 'xxhash-wasm';
import { z } from 'zod';
import type {
Expand All @@ -25,6 +25,7 @@ import {
PROPAGATED_ASSET_FLAG,
} from './consts.js';
import { createImage } from './runtime-assets.js';
import { normalizePath } from '../core/viteUtils.js';
/**
* Amap from a collection + slug to the local file path.
* This is used internally to resolve entry imports when using `getEntry()`.
Expand Down
12 changes: 10 additions & 2 deletions packages/astro/src/core/viteUtils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { normalizePath } from 'vite';
import { prependForwardSlash } from '../core/path.js';
import { prependForwardSlash, slash } from '../core/path.js';
import type { ModuleLoader } from './module-loader/index.js';
import { VALID_ID_PREFIX, resolveJsToTs, unwrapId, viteID } from './util.js';

const isWindows = typeof process !== 'undefined' && process.platform === 'win32';

/**
* Re-implementation of Vite's normalizePath that can be used without Vite
*/
export function normalizePath(id: string) {
return path.posix.normalize(isWindows ? slash(id) : id);
}

/**
* Resolve the hydration paths so that it can be imported in the client
*/
Expand Down

0 comments on commit 45b599c

Please sign in to comment.