mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
Prevent scanning a user's deps (#1678)
* Prevent scanning a user's deps * Remove unused things * remove unused util
This commit is contained in:
parent
387bd1a48f
commit
77cd898dea
2 changed files with 2 additions and 17 deletions
|
@ -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<ViteConfigWithSSR> {
|
||||
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 }),
|
||||
|
|
|
@ -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<Record<string, any> | 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
|
||||
|
|
Loading…
Reference in a new issue