Skip to content

Commit

Permalink
fix: fix more typing
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Jun 20, 2024
1 parent c230cb1 commit 5c75ae3
Show file tree
Hide file tree
Showing 21 changed files with 287 additions and 288 deletions.
2 changes: 1 addition & 1 deletion packages/vite/src/node/__tests__/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import colors from 'picocolors'
import { describe, expect, test, vi } from 'vitest'
import type { OutputChunk, OutputOptions, RollupOutput } from 'rollup'
import type { OutputChunk, OutputOptions, RollupOutput } from '@rolldown/node'
import type { LibraryFormats, LibraryOptions } from '../build'
import { build, resolveBuildOutputs, resolveLibFilename } from '../build'
import type { Logger } from '../logger'
Expand Down
10 changes: 5 additions & 5 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { loadFallbackPlugin } from './plugins/loadFallback'
import { findNearestPackageData } from './packages'
import type { PackageCache } from './packages'
import { ESBUILD_MODULES_TARGET, VERSION } from './constants'
import { resolveChokidarOptions } from './watch'
// import { resolveChokidarOptions } from './watch'
import { completeSystemWrapPlugin } from './plugins/completeSystemWrap'
import { mergeConfig } from './publicUtils'
import { webWorkerPostPlugin } from './plugins/worker'
Expand Down Expand Up @@ -417,10 +417,10 @@ export async function resolveBuildPlugins(config: ResolvedConfig): Promise<{
post: Plugin[]
}> {
const options = config.build
const { commonjsOptions } = options
const usePluginCommonjs =
!Array.isArray(commonjsOptions?.include) ||
commonjsOptions?.include.length !== 0
// const { commonjsOptions } = options
// const usePluginCommonjs =
// !Array.isArray(commonjsOptions?.include) ||
// commonjsOptions?.include.length !== 0
const rollupOptionsPlugins = options.rollupOptions.plugins
return {
pre: [
Expand Down
42 changes: 21 additions & 21 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import colors from 'picocolors'
import type { Alias, AliasOptions } from 'dep-types/alias'
import aliasPlugin from '@rollup/plugin-alias'
import { build } from 'esbuild'
import type { RollupOptions } from 'rollup'
import type { RollupOptions } from '@rolldown/node'
import type { HookHandler, Plugin, PluginWithRequiredHook } from './plugin'
import type {
BuildOptions,
Expand Down Expand Up @@ -831,26 +831,26 @@ export async function resolveConfig(

// Check if all assetFileNames have the same reference.
// If not, display a warn for user.
const outputOption = config.build?.rollupOptions?.output ?? []
// Use isArray to narrow its type to array
if (Array.isArray(outputOption)) {
const assetFileNamesList = outputOption.map(
(output) => output.assetFileNames,
)
if (assetFileNamesList.length > 1) {
const firstAssetFileNames = assetFileNamesList[0]
const hasDifferentReference = assetFileNamesList.some(
(assetFileNames) => assetFileNames !== firstAssetFileNames,
)
if (hasDifferentReference) {
resolved.logger.warn(
colors.yellow(`
assetFileNames isn't equal for every build.rollupOptions.output. A single pattern across all outputs is supported by Vite.
`),
)
}
}
}
// const outputOption = config.build?.rollupOptions?.output ?? []
// // Use isArray to narrow its type to array
// if (Array.isArray(outputOption)) {
// const assetFileNamesList = outputOption.map(
// (output) => output.assetFileNames,
// )
// if (assetFileNamesList.length > 1) {
// const firstAssetFileNames = assetFileNamesList[0]
// const hasDifferentReference = assetFileNamesList.some(
// (assetFileNames) => assetFileNames !== firstAssetFileNames,
// )
// if (hasDifferentReference) {
// resolved.logger.warn(
// colors.yellow(`
// assetFileNames isn't equal for every build.rollupOptions.output. A single pattern across all outputs is supported by Vite.
// `),
// )
// }
// }
// }

// Warn about removal of experimental features
if (
Expand Down
14 changes: 7 additions & 7 deletions packages/vite/src/node/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,18 +241,18 @@ export function watchPackageDataPlugin(packageCache: PackageCache): Plugin {
return {
name: 'vite:watch-package-data',
buildStart() {
watchFile = this.addWatchFile.bind(this)
watchQueue.forEach(watchFile)
// watchFile = this.addWatchFile.bind(this)
// watchQueue.forEach(watchFile)
watchQueue.clear()
},
buildEnd() {
watchFile = watchFileStub
},
watchChange(id) {
if (id.endsWith('/package.json')) {
invalidatePackageData(packageCache, path.normalize(id))
}
},
// watchChange(id) {
// if (id.endsWith('/package.json')) {
// invalidatePackageData(packageCache, path.normalize(id))
// }
// },
handleHotUpdate({ file }) {
if (file.endsWith('/package.json')) {
invalidatePackageData(packageCache, path.normalize(file))
Expand Down
1 change: 0 additions & 1 deletion packages/vite/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
TransformPluginContext,
TransformResult,
} from '@rolldown/node'
export type { PluginContext } from 'rollup'
import type { ConfigEnv, ResolvedConfig, UserConfig } from './config'
import type { ServerHook } from './server'
import type { IndexHtmlTransform } from './plugins/html'
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
NormalizedOutputOptions,
PluginContext,
RenderedChunk,
} from 'rollup'
} from '@rolldown/node'
import MagicString from 'magic-string'
import colors from 'picocolors'
import {
Expand Down Expand Up @@ -188,7 +188,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
// raw requests, read from disk
if (rawRE.test(id)) {
const file = checkPublicFile(id, config) || cleanUrl(id)
this.addWatchFile(file)
// this.addWatchFile(file)
// raw query, read file and return as string
return `export default ${JSON.stringify(
await fsp.readFile(file, 'utf-8'),
Expand Down
16 changes: 8 additions & 8 deletions packages/vite/src/node/plugins/completeSystemWrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ export function completeSystemWrapPlugin(): Plugin {
name: 'vite:force-systemjs-wrap-complete',

renderChunk(code, chunk, opts) {
if (opts.format === 'system') {
return {
code: code.replace(SystemJSWrapRE, (s, s1) =>
s.replace(s1, '(exports, module)'),
),
map: null,
}
}
// if (opts.format === 'system') {
// return {
// code: code.replace(SystemJSWrapRE, (s, s1) =>
// s.replace(s1, '(exports, module)'),
// ),
// map: null,
// }
// }
},
}
}
14 changes: 7 additions & 7 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
RenderedChunk,
RollupError,
SourceMapInput,
} from 'rollup'
} from '@rolldown/node'
import { dataToEsm } from '@rollup/pluginutils'
import colors from 'picocolors'
import MagicString from 'magic-string'
Expand All @@ -26,7 +26,7 @@ import { formatMessages, transform } from 'esbuild'
import type { RawSourceMap } from '@ampproject/remapping'
import { getCodeWithSourcemap, injectSourcesContent } from '../server/sourcemap'
import type { ModuleNode } from '../server/moduleGraph'
import type { ResolveFn, ViteDevServer } from '../'
import type { ResolveFn, ViteDevServer } from '..'
import { resolveUserExternal, toOutputFilePathInCss } from '../build'
import {
CLIENT_PUBLIC_PATH,
Expand Down Expand Up @@ -304,11 +304,11 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
}

// track deps for build watch mode
if (config.command === 'build' && config.build.watch && deps) {
for (const file of deps) {
this.addWatchFile(file)
}
}
// if (config.command === 'build' && config.build.watch && deps) {
// for (const file of deps) {
// this.addWatchFile(file)
// }
// }

// dev
if (server) {
Expand Down
24 changes: 12 additions & 12 deletions packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,18 @@ export const buildEsbuildPlugin = (config: ResolvedConfig): Plugin => {
// We don't need to create a MagicString here because both the helpers and
// the headers don't modify the sourcemap
const esbuildCode = res.code
const contentIndex =
opts.format === 'iife'
? esbuildCode.match(IIFE_BEGIN_RE)?.index || 0
: opts.format === 'umd'
? esbuildCode.indexOf(`(function(`) // same for minified or not
: 0
if (contentIndex > 0) {
const esbuildHelpers = esbuildCode.slice(0, contentIndex)
res.code = esbuildCode
.slice(contentIndex)
.replace(`"use strict";`, `"use strict";` + esbuildHelpers)
}
// const contentIndex =
// opts.format === 'iife'
// ? esbuildCode.match(IIFE_BEGIN_RE)?.index || 0
// : opts.format === 'umd'
// ? esbuildCode.indexOf(`(function(`) // same for minified or not
// : 0
// if (contentIndex > 0) {
// const esbuildHelpers = esbuildCode.slice(0, contentIndex)
// res.code = esbuildCode
// .slice(contentIndex)
// .replace(`"use strict";`, `"use strict";` + esbuildHelpers)
// }
}

return res
Expand Down
124 changes: 62 additions & 62 deletions packages/vite/src/node/plugins/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import path from 'node:path'
import { gzip } from 'node:zlib'
import { promisify } from 'node:util'
import colors from 'picocolors'
import type { Plugin } from 'rollup'
import type { Plugin } from '@rolldown/node'
import type { ResolvedConfig } from '../config'
import {
isDefined,
isInNodeModules,
// isInNodeModules,
normalizePath,
withTrailingSlash,
} from '../utils'
Expand Down Expand Up @@ -47,7 +47,7 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
let transformedCount = 0
let chunkCount = 0
let compressedCount = 0
let startTime = Date.now()
// let startTime = Date.now()

async function getCompressedSize(
code: string | Uint8Array,
Expand Down Expand Up @@ -101,7 +101,7 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
},

options() {
startTime = Date.now()
// startTime = Date.now()
},

buildStart() {
Expand All @@ -124,50 +124,50 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
compressedCount = 0
},

renderChunk(code, chunk, options) {
if (!options.inlineDynamicImports) {
for (const id of chunk.moduleIds) {
const module = this.getModuleInfo(id)
if (!module) continue
// When a dynamic importer shares a chunk with the imported module,
// warn that the dynamic imported module will not be moved to another chunk (#12850).
if (module.importers.length && module.dynamicImporters.length) {
// Filter out the intersection of dynamic importers and sibling modules in
// the same chunk. The intersecting dynamic importers' dynamic import is not
// expected to work. Note we're only detecting the direct ineffective
// dynamic import here.
const detectedIneffectiveDynamicImport =
module.dynamicImporters.some(
(id) => !isInNodeModules(id) && chunk.moduleIds.includes(id),
)
if (detectedIneffectiveDynamicImport) {
this.warn(
`\n(!) ${
module.id
} is dynamically imported by ${module.dynamicImporters.join(
', ',
)} but also statically imported by ${module.importers.join(
', ',
)}, dynamic import will not move module into another chunk.\n`,
)
}
}
}
}
// renderChunk(code, chunk, options) {
// if (!options.inlineDynamicImports) {
// for (const id of chunk.moduleIds) {
// const module = this.getModuleInfo(id)
// if (!module) continue
// // When a dynamic importer shares a chunk with the imported module,
// // warn that the dynamic imported module will not be moved to another chunk (#12850).
// if (module.importers.length && module.dynamicImporters.length) {
// // Filter out the intersection of dynamic importers and sibling modules in
// // the same chunk. The intersecting dynamic importers' dynamic import is not
// // expected to work. Note we're only detecting the direct ineffective
// // dynamic import here.
// const detectedIneffectiveDynamicImport =
// module.dynamicImporters.some(
// (id) => !isInNodeModules(id) && chunk.moduleIds.includes(id),
// )
// if (detectedIneffectiveDynamicImport) {
// this.warn(
// `\n(!) ${
// module.id
// } is dynamically imported by ${module.dynamicImporters.join(
// ', ',
// )} but also statically imported by ${module.importers.join(
// ', ',
// )}, dynamic import will not move module into another chunk.\n`,
// )
// }
// }
// }
// }

chunkCount++
if (shouldLogInfo) {
if (!tty) {
if (!hasRenderedChunk) {
config.logger.info('rendering chunks...')
}
} else {
writeLine(`rendering chunks (${chunkCount})...`)
}
hasRenderedChunk = true
}
return null
},
// chunkCount++
// if (shouldLogInfo) {
// if (!tty) {
// if (!hasRenderedChunk) {
// config.logger.info('rendering chunks...')
// }
// } else {
// writeLine(`rendering chunks (${chunkCount})...`)
// }
// hasRenderedChunk = true
// }
// return null
// },

generateBundle() {
if (shouldLogInfo && tty) clearLine()
Expand Down Expand Up @@ -337,22 +337,22 @@ function throttle(fn: Function) {
}
}

function displayTime(time: number) {
// display: {X}ms
if (time < 1000) {
return `${time}ms`
}
// function displayTime(time: number) {
// // display: {X}ms
// if (time < 1000) {
// return `${time}ms`
// }

time = time / 1000
// time = time / 1000

// display: {X}s
if (time < 60) {
return `${time.toFixed(2)}s`
}
// // display: {X}s
// if (time < 60) {
// return `${time.toFixed(2)}s`
// }

const mins = parseInt((time / 60).toString())
const seconds = time % 60
// const mins = parseInt((time / 60).toString())
// const seconds = time % 60

// display: {X}m {Y}s
return `${mins}m${seconds < 1 ? '' : ` ${seconds.toFixed(0)}s`}`
}
// // display: {X}m {Y}s
// return `${mins}m${seconds < 1 ? '' : ` ${seconds.toFixed(0)}s`}`
// }
Loading

0 comments on commit 5c75ae3

Please sign in to comment.