fix: compatibility of fs-extra with esm (#4017)
This commit is contained in:
@@ -35,7 +35,6 @@
|
||||
"dayjs": "^1.11.12",
|
||||
"execa": "^9.3.0",
|
||||
"find-up": "^7.0.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"nanoid": "^5.0.7",
|
||||
"ora": "^8.0.1",
|
||||
"pkg-types": "^1.1.3",
|
||||
@@ -43,7 +42,6 @@
|
||||
"rimraf": "^6.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chalk": "^2.2.0",
|
||||
"@types/fs-extra": "^11.0.4"
|
||||
"@types/chalk": "^2.2.0"
|
||||
}
|
||||
}
|
||||
|
41
internal/node-utils/src/fs.ts
Normal file
41
internal/node-utils/src/fs.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { promises as fs } from 'node:fs';
|
||||
import { dirname } from 'node:path';
|
||||
|
||||
export async function outputJSON(
|
||||
filePath: string,
|
||||
data: any,
|
||||
spaces: number = 2,
|
||||
) {
|
||||
try {
|
||||
const dir = dirname(filePath);
|
||||
await fs.mkdir(dir, { recursive: true });
|
||||
const jsonData = JSON.stringify(data, null, spaces);
|
||||
await fs.writeFile(filePath, jsonData, 'utf8');
|
||||
console.log(`JSON data written to ${filePath}`);
|
||||
} catch (error) {
|
||||
console.error('Error writing JSON file:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function ensureFile(filePath: string) {
|
||||
try {
|
||||
const dir = dirname(filePath);
|
||||
await fs.mkdir(dir, { recursive: true });
|
||||
await fs.writeFile(filePath, '', { flag: 'a' }); // 'a' flag to append if file exists, otherwise create
|
||||
console.log(`File ensured: ${filePath}`);
|
||||
} catch (error) {
|
||||
console.error('Error ensuring file:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function readJSON(filePath: string) {
|
||||
try {
|
||||
const data = await fs.readFile(filePath, 'utf8');
|
||||
return JSON.parse(data);
|
||||
} catch (error) {
|
||||
console.error('Error reading JSON file:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
export * from './constants';
|
||||
export * from './date';
|
||||
export * from './fs';
|
||||
export * from './git';
|
||||
export { add as gitAdd, getStagedFiles } from './git';
|
||||
export { generatorContentHash } from './hash';
|
||||
@@ -12,8 +13,9 @@ export { default as colors } from 'chalk';
|
||||
export { consola } from 'consola';
|
||||
export * from 'execa';
|
||||
|
||||
export * as fs from 'fs-extra';
|
||||
export { nanoid } from 'nanoid';
|
||||
export { type PackageJson, readPackageJSON } from 'pkg-types';
|
||||
|
||||
export { default as fs } from 'node:fs/promises';
|
||||
|
||||
export { type PackageJson, readPackageJSON } from 'pkg-types';
|
||||
export { rimraf } from 'rimraf';
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import fs from 'fs-extra';
|
||||
import fs from 'node:fs/promises';
|
||||
|
||||
import { format, getFileInfo, resolveConfig } from 'prettier';
|
||||
|
||||
async function prettierFormat(filepath: string) {
|
||||
@@ -12,7 +13,7 @@ async function prettierFormat(filepath: string) {
|
||||
parser: fileInfo.inferredParser as any,
|
||||
});
|
||||
if (output !== input) {
|
||||
fs.writeFileSync(filepath, output, 'utf8');
|
||||
await fs.writeFile(filepath, output, 'utf8');
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
@@ -1,8 +1,9 @@
|
||||
import type { Config } from 'tailwindcss';
|
||||
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
import { fs, getPackagesSync } from '@vben/node-utils';
|
||||
import { getPackagesSync } from '@vben/node-utils';
|
||||
|
||||
import { addDynamicIconSelectors } from '@iconify/tailwind';
|
||||
import typographyPlugin from '@tailwindcss/typography';
|
||||
|
@@ -1,7 +1,8 @@
|
||||
import fs from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import { fs, readPackageJSON } from '@vben/node-utils';
|
||||
import { readPackageJSON } from '@vben/node-utils';
|
||||
|
||||
import { type PluginOption } from 'vite';
|
||||
|
||||
@@ -61,7 +62,7 @@ async function getLoadingRawByHtmlTemplate(loadingTemplate: string) {
|
||||
return;
|
||||
}
|
||||
|
||||
const htmlRaw = await fs.readFile(loadingPath, 'utf8');
|
||||
const htmlRaw = fs.readFileSync(loadingPath, 'utf8');
|
||||
return htmlRaw;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user