Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/_data/acknowledgements.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function groupByAuthor(dependencies: Dependency[]): Author[] {
}
}

return Array.from(authorMap.entries())
return [...authorMap.entries()]
.map(([name, info]) => {
const sortedPackages = info.packages.sort((a, b) =>
a.name.localeCompare(b.name),
Expand Down
9 changes: 9 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-check
import e18e from '@e18e/eslint-plugin'
import eslint from '@eslint/js'
import pluginImportX from 'eslint-plugin-import-x'
import pluginN from 'eslint-plugin-n'
Expand Down Expand Up @@ -53,6 +54,7 @@ export default defineConfig(
plugins: {
n: pluginN,
'import-x': pluginImportX,
e18e,
},
rules: {
'n/no-exports-assign': 'error',
Expand Down Expand Up @@ -154,6 +156,13 @@ export default defineConfig(
'regexp/prefer-regexp-test': 'error',
// in some cases using explicit letter-casing is more performant than the `i` flag
'regexp/use-ignore-case': 'off',
'e18e/prefer-array-at': 'error',
'e18e/prefer-array-fill': 'error',
'e18e/prefer-includes': 'error',
'e18e/prefer-array-to-reversed': 'error',
'e18e/prefer-spread-syntax': 'error',
'e18e/prefer-object-has-own': 'error',
'e18e/prefer-nullish-coalescing': 'error',
},
},
{
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"merge-changelog": "tsx scripts/mergeChangelog.ts"
},
"devDependencies": {
"@e18e/eslint-plugin": "^0.8.0",
"@eslint/js": "^9.39.5",
"@type-challenges/utils": "^0.1.1",
"@types/babel__core": "^7.20.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ const FRAMEWORKS: Framework[] = [
]

const TEMPLATES = FRAMEWORKS.map((f) => f.variants.map((v) => v.name)).reduce(
(a, b) => a.concat(b),
(a, b) => [...a, ...b],
[],
)

Expand Down
7 changes: 4 additions & 3 deletions packages/vite/rolldown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@ function externalizeDepsInWatchPlugin(): Plugin {
options.external ||= []
if (!Array.isArray(options.external))
throw new Error('external must be an array')
options.external = options.external.concat(
Object.keys(pkg.devDependencies),
)
options.external = [
...options.external,
...Object.keys(pkg.devDependencies),
]
}
},
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/rolldown.dts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ function escapeRegex(str: string): string {
}

function unique<T>(arr: T[]): T[] {
return Array.from(new Set(arr))
return [...new Set(arr)]
}

const postcssLoadConfigDeepImport =
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/rollupLicensePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function getDependencyInformation(dep: Dependency): DependencyInfo {
}
}
if (names.size > 0) {
info.names = Array.from(names).join(', ')
info.names = [...names].join(', ')
}

if (repository) {
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/client/bundledDevHmrClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class BundledDevHMRClient extends HMRClient {
// Combined : [E, B, C, ACCEPTED, D, E]
const importChain = [
importer,
...[...currentChain].reverse(),
...currentChain.toReversed(),
...nodeChain.slice(importerIndex, -1).reverse(),
]
this.logger.debug(
Expand All @@ -223,7 +223,7 @@ export class BundledDevHMRClient extends HMRClient {
const result = this.isNodeWithinCircularImports(
importer,
nodeChain,
currentChain.concat(importer),
[...currentChain, importer],
traversedModules,
)
if (result) return result
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ async function handleMessage(payload: HotPayload) {
// can't use querySelector with `[href*=]` here since the link may be
// using relative paths so we need to use link.href to grab the full
// URL for the include check.
const el = Array.from(
document.querySelectorAll<HTMLLinkElement>('link'),
).find(
const el = [
...document.querySelectorAll<HTMLLinkElement>('link'),
].find(
(e) =>
!outdatedLinkTags.has(e) && cleanUrl(e.href).includes(searchUrl),
)
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/module-runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class ModuleRunner {
const meta = mod.meta!
const moduleId = meta.id

const importee = callstack[callstack.length - 1]
const importee = callstack.at(-1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#12539 (review) Follow the previous expectations


if (importee) mod.importers.add(importee)

Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/module-runner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function posixPathToFileHref(posixPath: string): string {
if (
(filePathLast === CHAR_FORWARD_SLASH ||
(isWindows && filePathLast === CHAR_BACKWARD_SLASH)) &&
resolved[resolved.length - 1] !== '/'
resolved.at(-1) !== '/'
)
resolved += '/'

Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const stopProfiler = (
const filterDuplicateOptions = <T extends object>(options: T) => {
for (const [key, value] of Object.entries(options)) {
if (Array.isArray(value)) {
options[key as keyof T] = value[value.length - 1]
options[key as keyof T] = value.at(-1)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin[] {
if (!url) {
const rawUrl = code.slice(start, end)
if (
(rawUrl[0] === `"` && rawUrl[rawUrl.length - 1] === `"`) ||
(rawUrl[0] === '`' && rawUrl[rawUrl.length - 1] === '`')
(rawUrl[0] === `"` && rawUrl.at(-1) === `"`) ||
(rawUrl[0] === '`' && rawUrl.at(-1) === '`')
)
url = rawUrl.slice(1, -1)
}
Expand Down Expand Up @@ -429,8 +429,8 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin[] {
if (!url) {
const rawUrl = code.slice(start, end)
if (
(rawUrl[0] === `"` && rawUrl[rawUrl.length - 1] === `"`) ||
(rawUrl[0] === '`' && rawUrl[rawUrl.length - 1] === '`')
(rawUrl[0] === `"` && rawUrl.at(-1) === `"`) ||
(rawUrl[0] === '`' && rawUrl.at(-1) === '`')
)
url = rawUrl.slice(1, -1)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/importMetaGlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export async function parseImportGlob(
// skip invalid js code
return []
}
const matches = Array.from(cleanCode.matchAll(importGlobRE))
const matches = [...cleanCode.matchAll(importGlobRE)]

const tasks = matches.map(async (match, index) => {
const start = match.index!
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export function oxcResolvePlugin(

mainFields: options.skipMainField
? options.mainFields
: options.mainFields.concat(['main']),
: [...options.mainFields, 'main'],
conditions: options.conditions,
externalConditions: options.externalConditions,
extensions: options.extensions,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/bundledDev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ class Clients {
}

getAll(): NormalizedHotChannelClient[] {
return Array.from(this.idToClient.values())
return [...this.idToClient.values()]
}

delete(client: NormalizedHotChannelClient): string | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ export function createRunnableDevEnvironment(
config: ResolvedConfig,
context: RunnableDevEnvironmentContext = {},
): RunnableDevEnvironment {
if (context.transport == null) {
context.transport = createServerHotChannel()
}
if (context.hot == null) {
context.hot = true
}

context.transport ??= createServerHotChannel()
context.hot ??= true
return new RunnableDevEnvironment(name, config, context)
}

Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/node/server/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ function propagateUpdate(
}

for (const importer of node.importers) {
const subChain = currentChain.concat(importer)
const subChain = [...currentChain, importer]

if (importer.acceptedHmrDeps.has(node)) {
// acceptedHmrDeps has value only for js and css
Expand Down Expand Up @@ -947,7 +947,7 @@ function isNodeWithinCircularImports(
// Combined : [E, B, C, ACCEPTED, D, E]
const importChain = [
importer,
...[...currentChain].reverse(),
...currentChain.toReversed(),
...nodeChain.slice(importerIndex, -1).reverse(),
]
debugHmr(
Expand All @@ -963,7 +963,7 @@ function isNodeWithinCircularImports(
const result = isNodeWithinCircularImports(
importer,
nodeChain,
currentChain.concat(importer),
[...currentChain, importer],
traversedModules,
)
if (result) return result
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/node/server/middlewares/indexHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,9 @@ const devHtmlHook: IndexHtmlTransformHook = async (
} else if (isModule && node.childNodes.length) {
addInlineModule(node, 'js')
} else if (node.childNodes.length) {
const scriptNode = node.childNodes[
node.childNodes.length - 1
] as DefaultTreeAdapterMap['textNode']
const scriptNode = node.childNodes.at(
-1,
) as DefaultTreeAdapterMap['textNode']
for (const {
url,
start,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/middlewares/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export function serveStaticMiddleware(

const resolvedPathname = redirectedPathname || pathname
let fileUrl = path.resolve(dir, removeLeadingSlash(resolvedPathname))
if (resolvedPathname.endsWith('/') && fileUrl[fileUrl.length - 1] !== '/') {
if (resolvedPathname.endsWith('/') && fileUrl.at(-1) !== '/') {
fileUrl = withTrailingSlash(fileUrl)
}
if (redirectedPathname) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/pluginContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ class EnvironmentPluginContainer<Env extends Environment = Environment> {
async close(): Promise<void> {
if (this._closed) return
this._closed = true
await Promise.allSettled(Array.from(this._processesing))
await Promise.allSettled([...this._processesing])
const config = this.environment.getTopLevelConfig()
let buildEndError: Error | undefined
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ export function createWebSocketServer(

[isWebSocketServer]: true,
get clients() {
return new Set(Array.from(wss.clients).map(getSocketClient))
return new Set([...wss.clients].map(getSocketClient))
},
}
}
9 changes: 4 additions & 5 deletions packages/vite/src/node/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ export function bindCLIShortcuts<Server extends ViteDevServer | PreviewServer>(
)
}

const shortcuts = customShortcuts.concat(
(isDev
? BASE_DEV_SHORTCUTS
: BASE_PREVIEW_SHORTCUTS) as CLIShortcut<Server>[],
)
const shortcuts = [
...customShortcuts,
isDev ? BASE_DEV_SHORTCUTS : BASE_PREVIEW_SHORTCUTS,
] as CLIShortcut<Server>[]

let actionRunning = false

Expand Down
9 changes: 6 additions & 3 deletions packages/vite/src/node/ssr/fetchModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,12 @@ function inlineSourceMap(
code = code.replace(OTHER_SOURCE_MAP_REGEXP, '')

const sourceMap = startOffset
? Object.assign({}, map, {
mappings: ';'.repeat(startOffset) + map.mappings,
})
? {
...map,
...{
mappings: ';'.repeat(startOffset) + map.mappings,
},
}
Comment thread
btea marked this conversation as resolved.
: map
result.code = `${code.trimEnd()}\n//# sourceURL=${
mod.id
Expand Down
7 changes: 4 additions & 3 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export const isJSRequest = (url: string): boolean => {
if (knownJsSrcRE.test(url)) {
return true
}
if (!path.extname(url) && url[url.length - 1] !== '/') {
if (!path.extname(url) && url.at(-1) !== '/') {
return true
}
return false
Expand Down Expand Up @@ -515,7 +515,7 @@ export function numberToPos(source: string, offset: number | Pos): Pos {
const lines = source.slice(0, offset).split(splitRE)
return {
line: lines.length,
column: lines[lines.length - 1].length,
column: lines.at(-1)!.length,
}
}

Expand Down Expand Up @@ -946,7 +946,7 @@ export function combineSourcemaps(
}

export function unique<T>(arr: T[]): T[] {
return Array.from(new Set(arr))
return [...new Set(arr)]
}

/**
Expand Down Expand Up @@ -1517,6 +1517,7 @@ function mergeConfigRecursively(
merged[key] = mergeAlias(existing, value)
continue
} else if (key === 'assetsInclude' && rootPath === '') {
// eslint-disable-next-line e18e/prefer-spread-syntax
merged[key] = [].concat(existing, value)
continue
} else if (
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/shared/ssrTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function analyzeImportedModDifference(
if (metadata?.importedNames?.length) {
const missingBindings = metadata.importedNames.filter((s) => !(s in mod))
if (missingBindings.length) {
const lastBinding = missingBindings[missingBindings.length - 1]
const lastBinding = missingBindings.at(-1)

// For invalid named exports only, similar to how Node.js errors for top-level imports.
// But since we transform as dynamic imports, we need to emulate the error manually.
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function isPrimitive(value: unknown): boolean {
}

export function withTrailingSlash(path: string): string {
if (path[path.length - 1] !== '/') {
if (path.at(-1) !== '/') {
return `${path}/`
}
return path
Expand Down
3 changes: 1 addition & 2 deletions playground/css/lightningcss-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ export function nestedLikePlugin() {
selector[0].type === 'nesting' &&
selector[1].type === 'type'
) {
const lastParentSelectorComponent =
parentSelector[parentSelector.length - 1]
const lastParentSelectorComponent = parentSelector.at(-1)
if ('name' in lastParentSelectorComponent) {
const newSelector = [
...parentSelector.slice(0, -1),
Expand Down
4 changes: 2 additions & 2 deletions playground/optimize-deps/dep-cjs-with-external-deps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (process.env.NODE_ENV === 'production') {
}
}
const external = require('@vitejs/test-dep-esm-external')
// eslint-disable-next-line no-prototype-builtins
const externalResult = external.hasOwnProperty('foo') ? 'ok' : 'error'

const externalResult = Object.hasOwn(external, 'foo') ? 'ok' : 'error'
const externalDummyNodeBuiltinResult = `${externalDummyNodeBuiltin()} ${externalDummyNodeBuiltin.bar}`
module.exports = { externalResult, externalDummyNodeBuiltinResult }
2 changes: 1 addition & 1 deletion playground/ssr/src/circular-dep-init/module-b.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { valueA } from './circular-dep-init'

export const valueB = 'circ-dep-init-b'
export const valueAB = valueA.concat(` ${valueB}`)
export const valueAB = `${valueA} ${valueB}`

export function getValueAB() {
return valueAB
Expand Down
2 changes: 1 addition & 1 deletion playground/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ export function extractSourcemap(
read?: (filename: string) => Promise<string>,
): any {
const lines = content.trim().split('\n')
const lastLine = lines[lines.length - 1]
const lastLine = lines.at(-1)
if (read) {
const result = fromMapFileComment(lastLine, async (url) => {
if (url.startsWith('data:')) {
Expand Down
Loading