mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
chore(vite): add missing types and move out utils (#710)
This commit is contained in:
parent
a4e903e55e
commit
2f5938c7b5
@ -1,6 +1,6 @@
|
|||||||
import { builtinModules } from 'module'
|
import { builtinModules } from 'module'
|
||||||
import { createHash } from 'crypto'
|
|
||||||
import * as vite from 'vite'
|
import * as vite from 'vite'
|
||||||
|
import { hashId, uniq } from './utils'
|
||||||
|
|
||||||
interface TransformChunk {
|
interface TransformChunk {
|
||||||
id: string,
|
id: string,
|
||||||
@ -68,10 +68,10 @@ async function transformRequestRecursive (viteServer: vite.ViteDevServer, id, pa
|
|||||||
return Object.values(chunks)
|
return Object.values(chunks)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function bundleRequest (viteServer: vite.ViteDevServer, entryURL) {
|
export async function bundleRequest (viteServer: vite.ViteDevServer, entryURL: string) {
|
||||||
const chunks = await transformRequestRecursive(viteServer, entryURL)
|
const chunks = await transformRequestRecursive(viteServer, entryURL)
|
||||||
|
|
||||||
const listIds = ids => ids.map(id => `// - ${id} (${hashId(id)})`).join('\n')
|
const listIds = (ids: string[]) => ids.map(id => `// - ${id} (${hashId(id)})`).join('\n')
|
||||||
const chunksCode = chunks.map(chunk => `
|
const chunksCode = chunks.map(chunk => `
|
||||||
// --------------------
|
// --------------------
|
||||||
// Request: ${chunk.id}
|
// Request: ${chunk.id}
|
||||||
@ -167,18 +167,3 @@ async function __instantiateModule__(url, urlStack) {
|
|||||||
|
|
||||||
return { code }
|
return { code }
|
||||||
}
|
}
|
||||||
|
|
||||||
function hashId (id: string) {
|
|
||||||
return '$id_' + hash(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
function hash (input: string, length = 8) {
|
|
||||||
return createHash('sha256')
|
|
||||||
.update(input)
|
|
||||||
.digest('hex')
|
|
||||||
.substr(0, length)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function uniq<T> (arr: T[]): T[] {
|
|
||||||
return Array.from(new Set(arr))
|
|
||||||
}
|
|
||||||
|
16
packages/vite/src/utils.ts
Normal file
16
packages/vite/src/utils.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { createHash } from 'crypto'
|
||||||
|
|
||||||
|
export function hashId (id: string) {
|
||||||
|
return '$id_' + hash(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hash (input: string, length = 8) {
|
||||||
|
return createHash('sha256')
|
||||||
|
.update(input)
|
||||||
|
.digest('hex')
|
||||||
|
.substr(0, length)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function uniq<T> (arr: T[]): T[] {
|
||||||
|
return Array.from(new Set(arr))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user