chore: merge main

This commit is contained in:
patak-dev 2024-10-23 10:54:33 +02:00
commit 16e4cb4206
16 changed files with 207 additions and 86 deletions

View File

@ -244,19 +244,6 @@ const numFrameworksPerRow = computed(
() => numBlocksPerRow.value - paddedBlocksPerSide.value * 2,
)
/**
* The indexes of the blocks on each row that support framework cards.
*/
const centerIndexes: ComputedRef<{ start: number; end: number }> = computed(
() => {
const startIndex = paddedBlocksPerSide.value
return {
start: startIndex,
end: numBlocksPerRow.value - paddedBlocksPerSide.value,
}
},
)
/**
* How many rows do we need to display all the frameworks?
*/
@ -264,6 +251,41 @@ const numRows: ComputedRef<number> = computed(() => {
return Math.ceil(frameworks.length / numFrameworksPerRow.value)
})
/**
* The indexes of the blocks on each row that support framework cards.
*
* Note that the index of the returned array is 1-based.
*/
const centerIndexes: ComputedRef<{ start: number; end: number }[]> = computed(
() => {
const firstRowsStartIndex = paddedBlocksPerSide.value
const frameworksPerFirstRows =
numBlocksPerRow.value - 2 * paddedBlocksPerSide.value
const lastRowStartIndex =
paddedBlocksPerSide.value +
Math.floor(
(frameworksPerFirstRows -
(frameworks.length % frameworksPerFirstRows)) /
2,
)
return new Array(numRows.value + 1).fill(0).map((_, i) => {
return i < numRows.value ||
frameworks.length % frameworksPerFirstRows === 0
? {
start: firstRowsStartIndex,
end: numBlocksPerRow.value - paddedBlocksPerSide.value,
}
: {
start: lastRowStartIndex,
end:
lastRowStartIndex +
(frameworks.length % frameworksPerFirstRows) +
1,
}
})
},
)
/**
* Generate CSS transformations for each row, to gracefully slide between horizontal positions.
*/
@ -289,8 +311,8 @@ const rowStyle: ComputedRef<{ transform: string }> = computed(() => {
<template v-for="columnIndex in numBlocksPerRow + 2">
<template
v-if="
columnIndex - 1 >= centerIndexes.start &&
columnIndex - 1 < centerIndexes.end
columnIndex - 1 >= centerIndexes[rowIndex].start &&
columnIndex - 1 < centerIndexes[rowIndex].end
"
>
<FrameworkCard
@ -298,7 +320,7 @@ const rowStyle: ComputedRef<{ transform: string }> = computed(() => {
frameworks[
(rowIndex - 1) * numFrameworksPerRow +
(columnIndex - 1) -
centerIndexes.start
centerIndexes[rowIndex].start
]
"
/>

View File

@ -1,3 +1,23 @@
## <small>5.5.4 (2024-10-23)</small>
* chore: change Angular customCommand (#18425) ([b53db53](https://github.com/vitejs/vite/commit/b53db53df17c43602d61a24e9bf579267ee8eb6b)), closes [#18425](https://github.com/vitejs/vite/issues/18425)
* chore: combine deps license with same text (#18356) ([b5d1a05](https://github.com/vitejs/vite/commit/b5d1a058f9dab6a6b1243c2a0b11d2c421dd3291)), closes [#18356](https://github.com/vitejs/vite/issues/18356)
* chore: specify TypeScript version with `~` (#18406) ([70bb8de](https://github.com/vitejs/vite/commit/70bb8ded1d5d2f1323d0350a8ad9cb3954c0bd61)), closes [#18406](https://github.com/vitejs/vite/issues/18406)
* chore: update all url references of vitejs.dev to vite.dev (#18276) ([7052c8f](https://github.com/vitejs/vite/commit/7052c8f6fc253f0a88ff04a4c18c108f3bfdaa78)), closes [#18276](https://github.com/vitejs/vite/issues/18276)
* chore: update license copyright (#18278) ([56eb869](https://github.com/vitejs/vite/commit/56eb869a67551a257d20cba00016ea59b1e1a2c4)), closes [#18278](https://github.com/vitejs/vite/issues/18278)
* chore: update moduleResolution value casing (#18409) ([ff018dc](https://github.com/vitejs/vite/commit/ff018dca959c73481ae5f8328cd77d3b02f02134)), closes [#18409](https://github.com/vitejs/vite/issues/18409)
* chore(create-vite): mark template files as CC0 (#18366) ([f6b9074](https://github.com/vitejs/vite/commit/f6b90747eb2b1ad863e5f147a80c75b15e38a51b)), closes [#18366](https://github.com/vitejs/vite/issues/18366)
* chore(deps): bump TypeScript to 5.6 (#18254) ([57a0e85](https://github.com/vitejs/vite/commit/57a0e85186b88118bf5f79dd53391676fb91afec)), closes [#18254](https://github.com/vitejs/vite/issues/18254)
* chore(deps): update all non-major dependencies (#18404) ([802839d](https://github.com/vitejs/vite/commit/802839d48335a69eb15f71f2cd816d0b6e4d3556)), closes [#18404](https://github.com/vitejs/vite/issues/18404)
* chore(deps): update eslint-plugin-react-hooks to stable v5 (#18335) ([0ddfb9f](https://github.com/vitejs/vite/commit/0ddfb9f31a74eea6d61bbedbda2a5c280c9bcc77)), closes [#18335](https://github.com/vitejs/vite/issues/18335)
* feat: add custom Angular variants (#18410) ([ac1fd41](https://github.com/vitejs/vite/commit/ac1fd41059f5549922b9f1a93c2bc00fbfcca3e8)), closes [#18410](https://github.com/vitejs/vite/issues/18410)
* feat(create-vite): update to svelte 5 (#18407) ([291830f](https://github.com/vitejs/vite/commit/291830fa632c756b2a0311142d1f25ca7b56a637)), closes [#18407](https://github.com/vitejs/vite/issues/18407)
* fix(create-vite): update qwik URL (#18285) ([45c9b5c](https://github.com/vitejs/vite/commit/45c9b5cca160346b41dbddacf6f9000ab1b638bc)), closes [#18285](https://github.com/vitejs/vite/issues/18285)
* fix(deps): update all non-major dependencies (#18292) ([5cac054](https://github.com/vitejs/vite/commit/5cac0544dca2764f0114aac38e9922a0c13d7ef4)), closes [#18292](https://github.com/vitejs/vite/issues/18292)
* fix(deps): update all non-major dependencies (#18345) ([5552583](https://github.com/vitejs/vite/commit/5552583a2272cd4208b30ad60e99d984e34645f0)), closes [#18345](https://github.com/vitejs/vite/issues/18345)
## <small>5.5.3 (2024-10-04)</small>
* chore: enable some eslint rules (#18084) ([e9a2746](https://github.com/vitejs/vite/commit/e9a2746ca77473b1814fd05db3d299c074135fe5)), closes [#18084](https://github.com/vitejs/vite/issues/18084)

View File

@ -1,6 +1,6 @@
{
"name": "create-vite",
"version": "5.5.3",
"version": "5.5.4",
"type": "module",
"license": "MIT",
"author": "Evan You",

View File

@ -258,7 +258,7 @@ const FRAMEWORKS: Framework[] = [
name: 'custom-angular',
display: 'Angular ↗',
color: red,
customCommand: 'npx -p @angular/cli@latest ng new TARGET_DIR',
customCommand: 'npm exec @angular/cli@latest new TARGET_DIR',
},
{
name: 'custom-analog',

View File

@ -87,7 +87,6 @@ export function createIsConfiguredAsExternal(
config.command === 'build' ? undefined : importer,
resolveOptions,
undefined,
true,
// try to externalize, will return undefined or an object without
// a external flag if it isn't externalizable
true,

View File

@ -253,13 +253,25 @@ async function computeEntries(environment: ScanEnvironment) {
if (explicitEntryPatterns) {
entries = await globEntries(explicitEntryPatterns, environment)
} else if (buildInput) {
const resolvePath = (p: string) => path.resolve(environment.config.root, p)
const resolvePath = async (p: string) => {
const id = (
await environment.pluginContainer.resolveId(p, undefined, {
scan: true,
})
)?.id
if (id === undefined) {
throw new Error(
`failed to resolve rollupOptions.input value: ${JSON.stringify(p)}.`,
)
}
return id
}
if (typeof buildInput === 'string') {
entries = [resolvePath(buildInput)]
entries = [await resolvePath(buildInput)]
} else if (Array.isArray(buildInput)) {
entries = buildInput.map(resolvePath)
entries = await Promise.all(buildInput.map(resolvePath))
} else if (isObject(buildInput)) {
entries = Object.values(buildInput).map(resolvePath)
entries = await Promise.all(Object.values(buildInput).map(resolvePath))
} else {
throw new Error('invalid rollupOptions.input value.')
}

View File

@ -512,7 +512,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
if (isExternalUrl(specifier) || isDataUrl(specifier)) {
return
}
// skip ssr external
// skip ssr externals and builtins
if (ssr && !matchAlias(specifier)) {
if (shouldExternalize(environment, specifier, importer)) {
return

View File

@ -23,7 +23,6 @@ import {
isBuiltin,
isDataUrl,
isExternalUrl,
isFilePathESM,
isInNodeModules,
isNonDriveRelativeAbsolutePath,
isObject,
@ -445,7 +444,6 @@ export function resolvePlugin(
importer,
options,
depsOptimizer,
ssr,
external,
undefined,
depsOptimizerOptions,
@ -747,7 +745,6 @@ export function tryNodeResolve(
importer: string | null | undefined,
options: InternalResolveOptionsWithOverrideConditions,
depsOptimizer?: DepsOptimizer,
ssr: boolean = false,
externalize?: boolean,
allowLinkedExternal: boolean = true,
depsOptimizerOptions?: DepOptimizationOptions,
@ -881,11 +878,9 @@ export function tryNodeResolve(
: OPTIMIZABLE_ENTRY_RE.test(resolved)
let exclude = depsOptimizer?.options.exclude
let include = depsOptimizer?.options.include
if (options.ssrOptimizeCheck) {
// we don't have the depsOptimizer
exclude = depsOptimizerOptions?.exclude
include = depsOptimizerOptions?.include
}
const skipOptimization =
@ -894,15 +889,7 @@ export function tryNodeResolve(
(importer && isInNodeModules(importer)) ||
exclude?.includes(pkgId) ||
exclude?.includes(id) ||
SPECIAL_QUERY_RE.test(resolved) ||
// During dev SSR, we don't have a way to reload the module graph if
// a non-optimized dep is found. So we need to skip optimization here.
// The only optimized deps are the ones explicitly listed in the config.
(!options.ssrOptimizeCheck && !isBuild && ssr) ||
// Only optimize non-external CJS deps during SSR by default
(ssr &&
isFilePathESM(resolved, options.packageCache) &&
!(include?.includes(pkgId) || include?.includes(id)))
SPECIAL_QUERY_RE.test(resolved)
if (options.ssrOptimizeCheck) {
return {
@ -1223,7 +1210,6 @@ function tryResolveBrowserMapping(
undefined,
undefined,
undefined,
undefined,
depsOptimizerOptions,
)?.id
: tryFsResolve(path.join(pkg.dir, browserMappedPath), options))

View File

@ -136,14 +136,8 @@ export class DevEnvironment extends BaseEnvironment {
} else if (isDepOptimizationDisabled(optimizeDeps)) {
this.depsOptimizer = undefined
} else {
// We only support auto-discovery for the client environment, for all other
// environments `noDiscovery` has no effect and a simpler explicit deps
// optimizer is used that only optimizes explicitly included dependencies
// so it doesn't need to reload the environment. Now that we have proper HMR
// and full reload for general environments, we can enable auto-discovery for
// them in the future
this.depsOptimizer = (
optimizeDeps.noDiscovery || options.consumer !== 'client'
optimizeDeps.noDiscovery
? createExplicitDepsOptimizer
: createDepsOptimizer
)(this)

View File

@ -44,20 +44,13 @@ export async function fetchModule(
const { externalConditions, dedupe, preserveSymlinks } =
environment.config.resolve
const resolved = tryNodeResolve(
url,
importer,
{
const resolved = tryNodeResolve(url, importer, {
mainFields: ['main'],
conditions: [],
externalConditions,
external: [],
noExternal: [],
overrideConditions: [
...externalConditions,
'production',
'development',
],
overrideConditions: [...externalConditions, 'production', 'development'],
extensions: ['.js', '.cjs', '.json'],
dedupe,
preserveSymlinks,
@ -66,10 +59,7 @@ export async function fetchModule(
root,
packageCache: environment.config.packageCache,
webCompatible: environment.config.webCompatible,
},
undefined,
true,
)
})
if (!resolved) {
const err: any = new Error(
`Cannot find module '${url}' imported from '${importer}'`,

View File

@ -62,7 +62,6 @@ export function resolveSSROptions(
...ssr,
optimizeDeps: {
...optimizeDeps,
noDiscovery: true, // always true for ssr
esbuildOptions: {
preserveSymlinks,
...optimizeDeps.esbuildOptions,

View File

@ -1,9 +0,0 @@
import { test } from 'vitest'
import { page } from '~utils'
test('basic', async () => {
await page.getByText('hydrated: true').isVisible()
await page.getByText('Count: 0').isVisible()
await page.getByRole('button', { name: '+' }).click()
await page.getByText('Count: 1').isVisible()
})

View File

@ -0,0 +1,92 @@
import fs from 'node:fs'
import path from 'node:path'
import { describe, expect, onTestFinished, test } from 'vitest'
import type { DepOptimizationMetadata } from 'vite'
import {
isBuild,
page,
readFile,
serverLogs,
testDir,
untilUpdated,
} from '~utils'
test('basic', async () => {
await page.getByText('hydrated: true').isVisible()
await page.getByText('Count: 0').isVisible()
await page.getByRole('button', { name: '+' }).click()
await page.getByText('Count: 1').isVisible()
})
describe.runIf(!isBuild)('pre-bundling', () => {
test('client', async () => {
const meta = await readFile('node_modules/.vite/deps/_metadata.json')
const metaJson: DepOptimizationMetadata = JSON.parse(meta)
expect(metaJson.optimized['react']).toBeTruthy()
expect(metaJson.optimized['react-dom/client']).toBeTruthy()
expect(metaJson.optimized['react/jsx-dev-runtime']).toBeTruthy()
expect(metaJson.optimized['react-dom/server']).toBeFalsy()
})
test('ssr', async () => {
const meta = await readFile('node_modules/.vite/deps_$ssr/_metadata.json')
const metaJson: DepOptimizationMetadata = JSON.parse(meta)
expect(metaJson.optimized['react']).toBeTruthy()
expect(metaJson.optimized['react-dom/server']).toBeTruthy()
expect(metaJson.optimized['react/jsx-dev-runtime']).toBeTruthy()
expect(metaJson.optimized['react-dom/client']).toBeFalsy()
})
test('deps reload', async () => {
const envs = ['client', 'server'] as const
const getMeta = (env: (typeof envs)[number]): DepOptimizationMetadata => {
const meta = readFile(
`node_modules/.vite/deps${env === 'client' ? '' : '_$ssr'}/_metadata.json`,
)
return JSON.parse(meta)
}
expect(getMeta('client').optimized['react-fake-client']).toBeFalsy()
expect(getMeta('client').optimized['react-fake-server']).toBeFalsy()
expect(getMeta('server').optimized['react-fake-server']).toBeFalsy()
expect(getMeta('server').optimized['react-fake-client']).toBeFalsy()
envs.forEach((env) => {
const filePath = path.resolve(testDir, `src/entry-${env}.tsx`)
const originalContent = readFile(filePath)
fs.writeFileSync(
filePath,
`import 'react-fake-${env}'\n${originalContent}`,
'utf-8',
)
onTestFinished(() => {
fs.writeFileSync(filePath, originalContent, 'utf-8')
})
})
await untilUpdated(
() =>
serverLogs
.map(
(log) =>
log
// eslint-disable-next-line no-control-regex
.replace(/\x1B\[\d+m/g, '')
.match(/new dependencies optimized: (react-fake-.*)/)?.[1],
)
.filter(Boolean)
.join(', '),
'react-fake-server, react-fake-client',
)
expect(getMeta('client').optimized['react-fake-client']).toBeTruthy()
expect(getMeta('client').optimized['react-fake-server']).toBeFalsy()
expect(getMeta('server').optimized['react-fake-server']).toBeTruthy()
expect(getMeta('server').optimized['react-fake-client']).toBeFalsy()
})
})

View File

@ -12,6 +12,8 @@
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
"react": "^18.3.1",
"react-fake-client": "npm:react@^18.3.1",
"react-fake-server": "npm:react@^18.3.1",
"react-dom": "^18.3.1"
}
}

View File

@ -21,6 +21,9 @@ export default defineConfig((env) => ({
},
},
],
resolve: {
noExternal: true,
},
$client: {
build: {
minify: false,
@ -29,6 +32,11 @@ export default defineConfig((env) => ({
},
},
$ssr: {
dev: {
optimizeDeps: {
noDiscovery: false,
},
},
build: {
outDir: 'dist/server',
// [feedback]

View File

@ -698,6 +698,12 @@ importers:
react-dom:
specifier: ^18.3.1
version: 18.3.1(react@18.3.1)
react-fake-client:
specifier: npm:react@^18.3.1
version: react@18.3.1
react-fake-server:
specifier: npm:react@^18.3.1
version: react@18.3.1
playground/extensions:
dependencies:
@ -7123,8 +7129,8 @@ packages:
zimmerframe@1.0.0:
resolution: {integrity: sha512-H6qQ6LtjP+kDQwDgol18fPi4OCo7F+73ZBYt2U9c1D3V74bIMKxXvyrN0x+1I7/RYh5YsausflQxQR/qwDLHPQ==}
zod@3.22.4:
resolution: {integrity: sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==}
zod@3.23.8:
resolution: {integrity: sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==}
zwitch@2.0.4:
resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==}
@ -11301,7 +11307,7 @@ snapshots:
workerd: 1.20241011.1
ws: 8.18.0
youch: 3.2.3
zod: 3.22.4
zod: 3.23.8
transitivePeerDependencies:
- bufferutil
- supports-color
@ -12908,6 +12914,6 @@ snapshots:
zimmerframe@1.0.0: {}
zod@3.22.4: {}
zod@3.23.8: {}
zwitch@2.0.4: {}