diff --git a/package.json b/package.json index 980401453b..6ed50e7d89 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "esbuild": "^0.16.2", "escape-string-regexp": "^5.0.0", "etag": "^1.8.1", - "fs-extra": "^10.1.0", + "fs-extra": "^11.1.0", "globby": "^13.1.2", "gzip-size": "^7.0.0", "h3": "^1.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9b4578f154..ec9aaa53d3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -47,7 +47,7 @@ importers: etag: ^1.8.1 execa: ^6.1.0 expect-type: ^0.15.0 - fs-extra: ^10.1.0 + fs-extra: ^11.1.0 globby: ^13.1.2 gzip-size: ^7.0.0 h3: ^1.0.1 @@ -110,7 +110,7 @@ importers: esbuild: 0.16.2 escape-string-regexp: 5.0.0 etag: 1.8.1 - fs-extra: 10.1.0 + fs-extra: 11.1.0 globby: 13.1.2 gzip-size: 7.0.0 h3: 1.0.1 @@ -3076,6 +3076,16 @@ packages: graceful-fs: 4.2.10 jsonfile: 6.1.0 universalify: 2.0.0 + dev: true + + /fs-extra/11.1.0: + resolution: {integrity: sha512-0rcTq621PD5jM/e0a3EJoGC/1TC5ZBCERW82LQuwfGnCa1V8w7dpYH1yNu+SLb6E5dkeCBzKEyLGlFrnr+dUyw==} + engines: {node: '>=14.14'} + dependencies: + graceful-fs: 4.2.10 + jsonfile: 6.1.0 + universalify: 2.0.0 + dev: false /fs-memo/1.2.0: resolution: {integrity: sha512-YEexkCpL4j03jn5SxaMHqcO6IuWuqm8JFUYhyCep7Ao89JIYmB8xoKhK7zXXJ9cCaNXpyNH5L3QtAmoxjoHW2w==} diff --git a/src/presets/azure.ts b/src/presets/azure.ts index 042462aaad..bde4ba833c 100644 --- a/src/presets/azure.ts +++ b/src/presets/azure.ts @@ -1,4 +1,4 @@ -import fse from 'fs-extra' +import { readFile } from 'node:fs/promises' import { join, resolve } from 'pathe' import { writeFile } from '../utils' import { defineNitroPreset } from '../preset' @@ -26,7 +26,7 @@ async function writeRoutes (nitro: Nitro) { let nodeVersion = '16' try { - const currentNodeVersion = fse.readJSONSync(join(nitro.options.rootDir, 'package.json')).engines.node + const currentNodeVersion = JSON.parse(await readFile(join(nitro.options.rootDir, 'package.json'), 'utf8')).engines.node if (['16', '14'].includes(currentNodeVersion)) { nodeVersion = currentNodeVersion } diff --git a/src/presets/cloudflare.ts b/src/presets/cloudflare.ts index 9e12a3b7dd..6059d95e80 100644 --- a/src/presets/cloudflare.ts +++ b/src/presets/cloudflare.ts @@ -1,5 +1,5 @@ import { resolve } from 'pathe' -import { move } from 'fs-extra' +import fse from 'fs-extra' import { writeFile } from '../utils' import { defineNitroPreset } from '../preset' import type { Nitro } from '../types' @@ -37,8 +37,8 @@ export const cloudflarePages = defineNitroPreset({ }, hooks: { async 'compiled' (nitro: Nitro) { - await move(resolve(nitro.options.output.serverDir, 'path.js'), resolve(nitro.options.output.serverDir, '[[path]].js')) - await move(resolve(nitro.options.output.serverDir, 'path.js.map'), resolve(nitro.options.output.serverDir, '[[path]].js.map')) + await fse.move(resolve(nitro.options.output.serverDir, 'path.js'), resolve(nitro.options.output.serverDir, '[[path]].js')) + await fse.move(resolve(nitro.options.output.serverDir, 'path.js.map'), resolve(nitro.options.output.serverDir, '[[path]].js.map')) } } }) diff --git a/src/presets/firebase.ts b/src/presets/firebase.ts index 982df34fe2..293c4e7fca 100644 --- a/src/presets/firebase.ts +++ b/src/presets/firebase.ts @@ -1,6 +1,7 @@ import { createRequire } from 'module' +import { existsSync } from 'node:fs' +import { readFile } from 'node:fs/promises' import { join, relative, resolve } from 'pathe' -import fse from 'fs-extra' import { globby } from 'globby' import { readPackageJSON } from 'pkg-types' import { writeFile } from '../utils' @@ -20,7 +21,7 @@ export const firebase = defineNitroPreset({ }) async function writeRoutes (nitro: Nitro) { - if (!fse.existsSync(join(nitro.options.rootDir, 'firebase.json'))) { + if (!existsSync(join(nitro.options.rootDir, 'firebase.json'))) { const firebase = { functions: { source: relative(nitro.options.rootDir, nitro.options.output.serverDir) @@ -57,7 +58,7 @@ async function writeRoutes (nitro: Nitro) { let nodeVersion = '14' try { - const currentNodeVersion = fse.readJSONSync(join(nitro.options.rootDir, 'package.json')).engines.node + const currentNodeVersion = JSON.parse(await readFile(join(nitro.options.rootDir, 'package.json'), 'utf8')).engines.node if (['16', '14'].includes(currentNodeVersion)) { nodeVersion = currentNodeVersion } diff --git a/src/utils/index.ts b/src/utils/index.ts index f243fd82b7..cd3118f184 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,6 +1,7 @@ import { createRequire } from 'module' +import fsp from 'node:fs/promises' +import { existsSync, readFileSync } from 'node:fs' import { relative, dirname, resolve } from 'pathe' -import fse from 'fs-extra' import jiti from 'jiti' import consola from 'consola' import chalk from 'chalk' @@ -38,8 +39,8 @@ export function tryImport (dir: string, path: string) { } export async function writeFile (file: string, contents: Buffer | string, log = false) { - await fse.mkdirp(dirname(file)) - await fse.writeFile(file, contents, typeof contents === 'string' ? 'utf-8' : undefined) + await fsp.mkdir(dirname(file), { recursive: true }) + await fsp.writeFile(file, contents, typeof contents === 'string' ? 'utf-8' : undefined) if (log) { consola.info('Generated', prettyPath(file)) } @@ -80,7 +81,7 @@ export function detectTarget () { export async function isDirectory (path: string) { try { - return (await fse.stat(path)).isDirectory() + return (await fsp.stat(path)).isDirectory() } catch (_err) { return false } @@ -117,8 +118,8 @@ export function readPackageJson ( const pkgModulePaths = /^(.*\/node_modules\/).*$/.exec(_require.resolve(packageName)) for (const pkgModulePath of pkgModulePaths || []) { const path = resolve(pkgModulePath, packageName, 'package.json') - if (fse.existsSync(path)) { - return fse.readJSONSync(path) + if (existsSync(path)) { + return JSON.parse(readFileSync(path, 'utf8')) } continue }