MCPcopy
hub / github.com/nuxt/nuxt / getVueHash

Function getVueHash

packages/nuxt/src/core/cache.ts:13–67  ·  view source on GitHub ↗
(nuxt: Nuxt)

Source from the content-addressed store, hash-verified

11import type { TarFileInput } from 'nanotar'
12
13export async function getVueHash (nuxt: Nuxt) {
14 const id = 'vue'
15
16 const { hash } = await getHashes(nuxt, {
17 id,
18 cwd: layer => layer.config.srcDir || layer.cwd,
19 patterns: (layer) => {
20 const srcDir = layer.config.srcDir || layer.cwd
21 return [
22 '**',
23 `!${relative(srcDir, layer.config.serverDir || join(layer.cwd, 'server'))}/**`,
24 `!${relative(srcDir, resolve(layer.cwd, layer.config.dir?.public || 'public'))}/**`,
25 '!node_modules/**',
26 '!nuxt.config.*',
27 ]
28 },
29 configOverrides: {
30 buildId: undefined,
31 serverDir: undefined,
32 nitro: undefined,
33 devServer: undefined,
34 runtimeConfig: undefined,
35 logLevel: undefined,
36 devServerHandlers: undefined,
37 devtools: undefined,
38 },
39 })
40
41 const cacheFile = join(getCacheDir(nuxt), id, hash + '.tar')
42 const buildIdCacheFile = cacheFile.replace('.tar', '.buildid')
43
44 return {
45 hash,
46 async collectCache () {
47 const start = Date.now()
48 await writeCache(nuxt.options.buildDir, nuxt.options.buildDir, cacheFile)
49
50 // Cache buildId so it can be restored before modules are initialised on the next build
51 await mkdir(dirname(buildIdCacheFile), { recursive: true })
52 await writeFile(buildIdCacheFile, nuxt.options.buildId)
53
54 const elapsed = Date.now() - start
55 consola.success(`Cached Vue client and server builds in \`${elapsed}ms\`.`)
56 },
57 async restoreCache () {
58 const start = Date.now()
59 const res = await restoreCacheFromFile(nuxt.options.buildDir, cacheFile)
60 const elapsed = Date.now() - start
61 if (res) {
62 consola.success(`Restored Vue client and server builds from cache in \`${elapsed}ms\`.`)
63 }
64 return res
65 },
66 }
67}
68
69/**
70 * Restore cached buildId before modules are initialised.

Callers 2

buildFunction · 0.90
restoreCachedBuildIdFunction · 0.85

Calls 2

getHashesFunction · 0.85
getCacheDirFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…