From 77cd898dead0413641cd614e28a44d5e5191cd24 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Wed, 27 Oct 2021 14:28:36 -0400 Subject: [PATCH] Prevent scanning a user's deps (#1678) * Prevent scanning a user's deps * Remove unused things * remove unused util --- packages/astro/src/core/create-vite.ts | 8 ++------ packages/astro/src/core/util.ts | 11 ----------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 0c9ddfa4d8..2692f3464d 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -9,7 +9,7 @@ import astroPostprocessVitePlugin from '../vite-plugin-astro-postprocess/index.j import markdownVitePlugin from '../vite-plugin-markdown/index.js'; import jsxVitePlugin from '../vite-plugin-jsx/index.js'; import fetchVitePlugin from '../vite-plugin-fetch/index.js'; -import { getPackageJSON, resolveDependency } from './util.js'; +import { resolveDependency } from './util.js'; // Some packages are just external, and that’s the way it goes. const ALWAYS_EXTERNAL = new Set([ @@ -37,17 +37,13 @@ interface CreateViteOptions { /** Return a common starting point for all Vite actions */ export async function createVite(inlineConfig: ViteConfigWithSSR, { astroConfig, logging, devServer }: CreateViteOptions): Promise { - const packageJSON = (await getPackageJSON(astroConfig.projectRoot)) || {}; - const userDeps = Object.keys(packageJSON?.dependencies || {}); - // First, start with the Vite configuration that Astro core needs let viteConfig: ViteConfigWithSSR = { cacheDir: fileURLToPath(new URL('./node_modules/.vite/', astroConfig.projectRoot)), // using local caches allows Astro to be used in monorepos, etc. clearScreen: false, // we want to control the output, not Vite logLevel: 'error', // log errors only optimizeDeps: { - entries: ['src/**/*'], // Try and scan a user’s project (won’t catch everything), - include: [...userDeps], // tell Vite to prebuild everything in a user’s package.json dependencies + entries: ['src/**/*'] // Try and scan a user’s project (won’t catch everything), }, plugins: [ astroVitePlugin({ config: astroConfig, devServer }), diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index 9dea3dba55..1abc6d1c63 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -14,17 +14,6 @@ export function canonicalURL(url: string, base?: string): URL { return new URL(pathname, base); } -/** get user dependency list for Vite */ -export async function getPackageJSON(projectRoot: URL): Promise | undefined> { - const possibleLocs = new Set(['./package.json']); - for (const possibleLoc of possibleLocs) { - const packageJSONLoc = new URL(possibleLoc, projectRoot); - if (fs.existsSync(packageJSONLoc)) { - return JSON.parse(await fs.promises.readFile(packageJSONLoc, 'utf8')); - } - } -} - /** is a specifier an npm package? */ export function parseNpmName(spec: string): { scope?: string; name: string; subpath?: string } | undefined { // not an npm package