From e3448fa0dac5f3ec7528e4819cc0e53250252e95 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 24 Jun 2024 23:50:37 +0200 Subject: [PATCH] chore(vite): restore utils required for `dev-bundler` --- packages/vite/src/dev-bundler.ts | 4 ++-- packages/vite/src/utils/index.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/dev-bundler.ts b/packages/vite/src/dev-bundler.ts index e2d970b524..9e4ec9d772 100644 --- a/packages/vite/src/dev-bundler.ts +++ b/packages/vite/src/dev-bundler.ts @@ -1,11 +1,11 @@ import { pathToFileURL } from 'node:url' import { existsSync } from 'node:fs' +import { writeFile } from 'node:fs/promises' import { builtinModules } from 'node:module' import { isAbsolute, normalize, resolve } from 'pathe' import type * as vite from 'vite' import type { isExternal } from 'externality' import { genDynamicImport, genObjectFromRawEntries } from 'knitwork' -import fse from 'fs-extra' import { debounce } from 'perfect-debounce' import { isIgnored, logger } from '@nuxt/kit' import { hashId, isCSS, uniq } from './utils' @@ -236,7 +236,7 @@ export async function initViteDevBundler (ctx: ViteBuildContext, onBuild: () => const _doBuild = async () => { const start = Date.now() const { code, ids } = await bundleRequest(options, ctx.entry) - await fse.writeFile(resolve(ctx.nuxt.options.buildDir, 'dist/server/server.mjs'), code, 'utf-8') + await writeFile(resolve(ctx.nuxt.options.buildDir, 'dist/server/server.mjs'), code, 'utf-8') // Have CSS in the manifest to prevent FOUC on dev SSR const manifestIds: string[] = [] for (const i of ids) { diff --git a/packages/vite/src/utils/index.ts b/packages/vite/src/utils/index.ts index 9221d70278..c667b96b20 100644 --- a/packages/vite/src/utils/index.ts +++ b/packages/vite/src/utils/index.ts @@ -1,5 +1,11 @@ +import { hash } from 'ohash' + export { isVue } from '../../../nuxt/src/core/utils/plugins' +export function uniq (arr: T[]): T[] { + return Array.from(new Set(arr)) +} + // Copied from vue-bundle-renderer utils const IS_CSS_RE = /\.(?:css|scss|sass|postcss|pcss|less|stylus|styl)(?:\?[^.]+)?$/ @@ -7,6 +13,10 @@ export function isCSS (file: string) { return IS_CSS_RE.test(file) } +export function hashId (id: string) { + return '$id_' + hash(id) +} + export function matchWithStringOrRegex (value: string, matcher: string | RegExp) { if (typeof matcher === 'string') { return value === matcher