-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Upgrade Vite to latest #2424
Upgrade Vite to latest #2424
Changes from all commits
484b309
f8c50e7
473ce43
7558ba5
2c4d345
b73a3b2
bc4be8a
e2685d2
fa8fe77
9d1d23a
69805ec
3096ded
2fda826
d7f2141
c9ab133
cc199b9
d76e9f0
9ffc343
ccfc10e
c0894c9
9552a32
9e3859b
2511328
e2f4ba4
7d1479b
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 | ||
--- | ||
|
||
Fixes HMR of CSS that is imported from astro, when using the static build flag |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': minor | ||
--- | ||
|
||
Upgrade `vite` to `2.8.x`, unvendoring `vite` and bringing Astro up-to-date with the ecosystem |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@astrojs/renderer-svelte': minor | ||
'@astrojs/renderer-vue': minor | ||
'@astrojs/renderer-solid': minor | ||
--- | ||
|
||
Upgrade to [email protected] |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,18 +66,16 @@ | |
"@astropub/webapi": "^0.10.1", | ||
"@babel/core": "^7.15.8", | ||
"@babel/traverse": "^7.15.4", | ||
"@proload/core": "^0.2.1", | ||
"@proload/core": "^0.2.2", | ||
"@proload/plugin-tsm": "^0.1.0", | ||
"@types/babel__core": "^7.1.15", | ||
"@types/debug": "^4.1.7", | ||
"@web/parse5-utils": "^1.3.0", | ||
"astring": "^1.7.5", | ||
"ci-info": "^3.2.0", | ||
"common-ancestor-path": "^1.0.1", | ||
"eol": "^0.9.1", | ||
"es-module-lexer": "^0.9.3", | ||
"esbuild": "0.13.7", | ||
"estree-util-value-to-estree": "^1.2.0", | ||
"estree-walker": "^3.0.0", | ||
"fast-glob": "^3.2.7", | ||
"fast-xml-parser": "^4.0.0-beta.3", | ||
|
@@ -93,10 +91,11 @@ | |
"prismjs": "^1.25.0", | ||
"rehype-slug": "^5.0.0", | ||
"resolve": "^1.20.0", | ||
"rollup": "^2.57.0", | ||
"sass": "^1.43.4", | ||
"rollup": "^2.64.0", | ||
"sass": "^1.49.0", | ||
"semver": "^7.3.5", | ||
"send": "^0.17.1", | ||
"serialize-javascript": "^6.0.0", | ||
"shiki": "^0.10.0", | ||
"shorthash": "^0.0.2", | ||
"slash": "^4.0.0", | ||
|
@@ -106,7 +105,7 @@ | |
"strip-ansi": "^7.0.1", | ||
"supports-esm": "^1.0.0", | ||
"tsconfig-resolver": "^3.0.1", | ||
"vite": "~2.6.10", | ||
"vite": "^2.8.0-beta.7", | ||
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. No more vendored |
||
"yargs-parser": "^21.0.0", | ||
"zod": "^3.8.1" | ||
}, | ||
|
@@ -125,9 +124,8 @@ | |
"@types/yargs-parser": "^20.2.1", | ||
"chai": "^4.3.4", | ||
"cheerio": "^1.0.0-rc.10", | ||
"hast-util-select": "^5.0.1", | ||
"mocha": "^9.1.3", | ||
"vite": "~2.6.10" | ||
"execa": "^6.0.0", | ||
"mocha": "^9.1.3" | ||
}, | ||
"engines": { | ||
"node": "^14.15.0 || >=16.0.0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare module 'serialize-javascript' { | ||
export default function serialize(value: any): string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,18 +16,15 @@ import { resolveDependency } from './util.js'; | |
const ALWAYS_EXTERNAL = new Set([ | ||
...builtinModules.map((name) => `node:${name}`), | ||
'@sveltejs/vite-plugin-svelte', | ||
'estree-util-value-to-estree', | ||
'micromark-util-events-to-acorn', | ||
'serialize-javascript', | ||
'node-fetch', | ||
'prismjs', | ||
'shiki', | ||
'shorthash', | ||
'unified', | ||
'whatwg-url', | ||
]); | ||
const ALWAYS_NOEXTERNAL = new Set([ | ||
'astro', // This is only because Vite's native ESM doesn't resolve "exports" correctly. | ||
]); | ||
Comment on lines
-28
to
-30
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 comment is no longer true, so |
||
|
||
// note: ssr is still an experimental API hence the type omission | ||
export type ViteConfigWithSSR = vite.InlineConfig & { ssr?: { external?: string[]; noExternal?: string[] } }; | ||
|
@@ -72,7 +69,7 @@ export async function createVite(inlineConfig: ViteConfigWithSSR, { astroConfig, | |
// Note: SSR API is in beta (https://vitejs.dev/guide/ssr.html) | ||
ssr: { | ||
external: [...ALWAYS_EXTERNAL], | ||
noExternal: [...ALWAYS_NOEXTERNAL], | ||
noExternal: [], | ||
}, | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from '../../vendor/vite/dist/node/index.js'; | ||
export { default } from '../../vendor/vite/dist/node/index.js'; | ||
export * from 'vite'; | ||
export { default } from 'vite'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,12 @@ | ||
import type { AstroComponentMetadata } from '../../@types/astro'; | ||
import type { SSRElement, SSRResult } from '../../@types/astro'; | ||
import { valueToEstree } from 'estree-util-value-to-estree'; | ||
import * as astring from 'astring'; | ||
Comment on lines
-3
to
-4
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. These packages we needlessly complex and weren't being handled well by Vite. |
||
import { hydrationSpecifier, serializeListValue } from './util.js'; | ||
|
||
const { generate, GENERATOR } = astring; | ||
|
||
// INVESTIGATE: What features are we getting from this that we need? | ||
// JSON.stringify has a "replacer" argument. | ||
// A more robust version alternative to `JSON.stringify` that can handle most values | ||
// see https://github.com/remcohaszing/estree-util-value-to-estree#readme | ||
const customGenerator: astring.Generator = { | ||
...GENERATOR, | ||
Literal(node, state) { | ||
if (node.raw != null) { | ||
// escape closing script tags in strings so browsers wouldn't interpret them as | ||
// closing the actual end tag in HTML | ||
state.write(node.raw.replace('</script>', '<\\/script>')); | ||
} else { | ||
GENERATOR.Literal(node, state); | ||
} | ||
}, | ||
}; | ||
import serializeJavaScript from 'serialize-javascript'; | ||
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 was replaced by |
||
|
||
// Serializes props passed into a component so that they can be reused during hydration. | ||
// The value is any | ||
export function serializeProps(value: any) { | ||
return generate(valueToEstree(value), { | ||
generator: customGenerator, | ||
}); | ||
return serializeJavaScript(value); | ||
} | ||
|
||
const HydrationDirectives = ['load', 'idle', 'media', 'visible', 'only']; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,15 +64,20 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu | |
let { filename, query } = parseAstroRequest(id); | ||
if (query.astro) { | ||
if (query.type === 'style') { | ||
if (filename.startsWith('/@fs')) { | ||
filename = filename.slice('/@fs'.length); | ||
} else if (filename.startsWith('/') && !ancestor(filename, config.projectRoot.pathname)) { | ||
filename = new URL('.' + filename, config.projectRoot).pathname; | ||
} | ||
|
||
Comment on lines
+67
to
+72
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. @matthewp any idea if this was old code that snuck back in via a rebase? |
||
if (typeof query.index === 'undefined') { | ||
throw new Error(`Requests for Astro CSS must include an index.`); | ||
} | ||
|
||
const transformResult = await cachedCompilation(config, normalizeFilename(filename), null, viteTransform, opts); | ||
const transformResult = await cachedCompilation(config, normalizeFilename(filename), null, viteTransform, { ssr: Boolean(opts?.ssr) }); | ||
|
||
// Track any CSS dependencies so that HMR is triggered when they change. | ||
await trackCSSDependencies.call(this, { viteDevServer, id, filename, deps: transformResult.rawCSSDeps }); | ||
|
||
const csses = transformResult.css; | ||
const code = csses[query.index]; | ||
|
||
|
@@ -84,7 +89,7 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu | |
throw new Error(`Requests for hoisted scripts must include an index`); | ||
} | ||
|
||
const transformResult = await cachedCompilation(config, normalizeFilename(filename), null, viteTransform, opts); | ||
const transformResult = await cachedCompilation(config, normalizeFilename(filename), null, viteTransform, { ssr: Boolean(opts?.ssr) }); | ||
const scripts = transformResult.scripts; | ||
const hoistedScript = scripts[query.index]; | ||
|
||
|
@@ -106,7 +111,7 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu | |
} | ||
|
||
try { | ||
const transformResult = await cachedCompilation(config, id, source, viteTransform, opts); | ||
const transformResult = await cachedCompilation(config, id, source, viteTransform, { ssr: Boolean(opts?.ssr) }); | ||
|
||
// Compile all TypeScript to JavaScript. | ||
// Also, catches invalid JS/TS in the compiled output before returning. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
{ | ||
"name": "@astrojs/test-static-build-pkg", | ||
"main": "./oops.js", | ||
"version": "0.0.2", | ||
"main": "./oops.cjs", | ||
"version": "0.0.3", | ||
"exports": { | ||
".": { | ||
"import": "./pkg.js", | ||
"require": "./oops.js" | ||
"import": "./pkg.mjs", | ||
"require": "./oops.cjs" | ||
} | ||
} | ||
} |
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 is a change worth calling out... Had to drop the
@nanostores/preact
usage from this example to get everything passing. I think there's some issue with deduping going on, but I'm hoping it's just in our monorepo. Will be sure to check this once we cut a release.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.
Thanks for the callout. If you're worried about not being able to resolve this before end of week, I'd suggest creating an issue to track adding
@nanostores/preact
back.