Skip to content

Commit

Permalink
refactor: extract '_metadata.json' string to a constant (#15541)
Browse files Browse the repository at this point in the history
  • Loading branch information
jh-leong authored Jan 10, 2024
1 parent 476e572 commit adda370
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/vite/src/node/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,5 @@ export const wildcardHosts = new Set([
export const DEFAULT_DEV_PORT = 5173

export const DEFAULT_PREVIEW_PORT = 4173

export const METADATA_FILENAME = '_metadata.json'
10 changes: 6 additions & 4 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
unique,
} from '../utils'
import { transformWithEsbuild } from '../plugins/esbuild'
import { ESBUILD_MODULES_TARGET } from '../constants'
import { ESBUILD_MODULES_TARGET, METADATA_FILENAME } from '../constants'
import { esbuildCjsExternalPlugin, esbuildDepPlugin } from './esbuildDepPlugin'
import { scanImports } from './scan'
import { createOptimizeDepsIncludeResolver, expandGlobIds } from './resolve'
Expand Down Expand Up @@ -369,7 +369,7 @@ export async function loadCachedDepOptimizationMetadata(
if (!force) {
let cachedMetadata: DepOptimizationMetadata | undefined
try {
const cachedMetadataPath = path.join(depsCacheDir, '_metadata.json')
const cachedMetadataPath = path.join(depsCacheDir, METADATA_FILENAME)
cachedMetadata = parseDepsOptimizerMetadata(
await fsp.readFile(cachedMetadataPath, 'utf-8'),
depsCacheDir,
Expand Down Expand Up @@ -541,8 +541,10 @@ export function runOptimizeDeps(

// Write metadata file, then commit the processing folder to the global deps cache
// Rewire the file paths from the temporary processing dir to the final deps cache dir
const dataPath = path.join(processingCacheDir, '_metadata.json')
debug?.(colors.green(`creating _metadata.json in ${processingCacheDir}`))
const dataPath = path.join(processingCacheDir, METADATA_FILENAME)
debug?.(
colors.green(`creating ${METADATA_FILENAME} in ${processingCacheDir}`),
)
fs.writeFileSync(
dataPath,
stringifyDepsOptimizerMetadata(metadata, depsCacheDir),
Expand Down

0 comments on commit adda370

Please sign in to comment.