-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup dependencies #5773
Cleanup dependencies #5773
Changes from 5 commits
4e37e82
66032ca
47971c3
9ca1f9c
9c7f48a
63d2f29
f74260e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Cleanup dependencies |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ import markdownVitePlugin from '../vite-plugin-markdown/index.js'; | |
import astroScannerPlugin from '../vite-plugin-scanner/index.js'; | ||
import astroScriptsPlugin from '../vite-plugin-scripts/index.js'; | ||
import astroScriptsPageSSRPlugin from '../vite-plugin-scripts/page-ssr.js'; | ||
import { resolveDependency } from './util.js'; | ||
|
||
interface CreateViteOptions { | ||
settings: AstroSettings; | ||
|
@@ -33,7 +32,7 @@ interface CreateViteOptions { | |
fs?: typeof nodeFs; | ||
} | ||
|
||
const ALWAYS_NOEXTERNAL = new Set([ | ||
const ALWAYS_NOEXTERNAL = [ | ||
// This is only because Vite's native ESM doesn't resolve "exports" correctly. | ||
'astro', | ||
// Vite fails on nested `.astro` imports without bundling | ||
|
@@ -43,21 +42,7 @@ const ALWAYS_NOEXTERNAL = new Set([ | |
'@nanostores/preact', | ||
// fontsource packages are CSS that need to be processed | ||
'@fontsource/*', | ||
]); | ||
|
||
function getSsrNoExternalDeps(projectRoot: URL): string[] { | ||
let noExternalDeps = []; | ||
for (const dep of ALWAYS_NOEXTERNAL) { | ||
try { | ||
resolveDependency(dep, projectRoot); | ||
noExternalDeps.push(dep); | ||
} catch { | ||
// ignore dependency if *not* installed / present in your project | ||
// prevents hard error from Vite! | ||
} | ||
} | ||
return noExternalDeps; | ||
} | ||
Comment on lines
-48
to
-60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vite doesn't have an issue now if the deps are not installed. This enables removing |
||
]; | ||
|
||
/** Return a common starting point for all Vite actions */ | ||
export async function createVite( | ||
|
@@ -166,10 +151,7 @@ export async function createVite( | |
dedupe: ['astro'], | ||
}, | ||
ssr: { | ||
noExternal: [ | ||
...getSsrNoExternalDeps(settings.config.root), | ||
...astroPkgsConfig.ssr.noExternal, | ||
], | ||
noExternal: [...ALWAYS_NOEXTERNAL, ...astroPkgsConfig.ssr.noExternal], | ||
// shiki is imported by Code.astro, which is no-externalized (processed by Vite). | ||
// However, shiki's deps are in CJS and trips up Vite's dev SSR transform, externalize | ||
// shiki to load it with node instead. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import slashify from 'slash'; | ||
import type { SSRElement } from '../../@types/astro'; | ||
|
||
import npath from 'path-browserify'; | ||
import { appendForwardSlash } from '../../core/path.js'; | ||
import { appendForwardSlash, removeLeadingForwardSlash } from '../../core/path.js'; | ||
|
||
function getRootPath(base?: string): string { | ||
return appendForwardSlash(new URL(base || '/', 'http://localhost/').pathname); | ||
} | ||
|
||
function joinToRoot(href: string, base?: string): string { | ||
return npath.posix.join(getRootPath(base), href); | ||
const rootPath = getRootPath(base); | ||
const normalizedHref = slashify(href); | ||
return appendForwardSlash(rootPath) + removeLeadingForwardSlash(normalizedHref); | ||
Comment on lines
-11
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only place we use the For reference, here's it's implementation: https://github.com/browserify/path-browserify/blob/872fec31a8bac7b9b43be0e54ef3037e0202c5fb/index.js#L180-L197 |
||
} | ||
|
||
export function createLinkStylesheetElement(href: string, base?: string): SSRElement { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { encode } from 'html-entities'; | ||
import { escape } from 'html-escaper'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
import { baseCSS } from './css.js'; | ||
|
||
interface ErrorTemplateOptions { | ||
|
@@ -58,7 +58,7 @@ export default function template({ | |
${ | ||
body || | ||
` | ||
<pre>Path: ${encode(pathname)}</pre> | ||
<pre>Path: ${escape(pathname)}</pre> | ||
` | ||
} | ||
</main> | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,7 +1,5 @@ | ||||
import type { PluginObj } from '@babel/core'; | ||||
import * as t from '@babel/types'; | ||||
import { resolve as importMetaResolve } from 'import-meta-resolve'; | ||||
import { fileURLToPath } from 'url'; | ||||
|
||||
/** | ||||
* This plugin handles every file that runs through our JSX plugin. | ||||
|
@@ -18,9 +16,6 @@ export default async function tagExportsWithRenderer({ | |||
rendererName: string; | ||||
root: URL; | ||||
}): Promise<PluginObj> { | ||||
const astroServerPath = fileURLToPath( | ||||
await importMetaResolve('astro/server/index.js', root.toString()) | ||||
); | ||||
Comment on lines
-21
to
-23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not needed anymore as I made a change to dedupe
|
||||
return { | ||||
visitor: { | ||||
Program: { | ||||
|
@@ -36,7 +31,7 @@ export default async function tagExportsWithRenderer({ | |||
t.identifier('__astro_tag_component__') | ||||
), | ||||
], | ||||
t.stringLiteral(astroServerPath) | ||||
t.stringLiteral('astro/server/index.js') | ||||
) | ||||
); | ||||
}, | ||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is unused. The
postcss
andpostcss-load-config
deps can be removed along.