fix: compatibility of fs-extra with esm (#4017)
parent
bf8a5ffb5d
commit
27ffc9e71b
|
@ -1,14 +1,14 @@
|
|||
# default onwer
|
||||
* anncwb vince292007
|
||||
* anncwb@126.com vince292007@gmail.com
|
||||
|
||||
# vben core onwer
|
||||
/.github/ anncwb vince292007
|
||||
/.vscode/ anncwb vince292007
|
||||
/packages/ anncwb vince292007
|
||||
/packages/@core/ anncwb vince292007
|
||||
/internal/ anncwb vince292007
|
||||
/scripts/ anncwb vince292007
|
||||
/.github/ anncwb@126.com vince292007@gmail.com
|
||||
/.vscode/ anncwb@126.com vince292007@gmail.com
|
||||
/packages/ anncwb@126.com vince292007@gmail.com
|
||||
/packages/@core/ anncwb@126.com vince292007@gmail.com
|
||||
/internal/ anncwb@126.com vince292007@gmail.com
|
||||
/scripts/ anncwb@126.com vince292007@gmail.com
|
||||
|
||||
# vben team onwer
|
||||
apps/ @vbenjs/team-v5
|
||||
docs/ @vbenjs/team-v5
|
||||
apps/ anncwb@126.com vince292007@gmail.com @vbenjs/team-v5
|
||||
docs/ anncwb@126.com vince292007@gmail.com @vbenjs/team-v5
|
||||
|
|
|
@ -26,6 +26,12 @@ jobs:
|
|||
sed -i "s#VITE_COMPRESS\s*=.*#VITE_COMPRESS = gzip#g" ./apps/web-antd/.env.production
|
||||
sed -i "s#VITE_PWA\s*=.*#VITE_PWA = true#g" ./apps/web-antd/.env.production
|
||||
cat ./apps/web-antd/.env.production
|
||||
sed -i "s#VITE_COMPRESS\s*=.*#VITE_COMPRESS = gzip#g" ./apps/web-ele/.env.production
|
||||
sed -i "s#VITE_PWA\s*=.*#VITE_PWA = true#g" ./apps/web-ele/.env.production
|
||||
cat ./apps/web-ele/.env.production
|
||||
sed -i "s#VITE_COMPRESS\s*=.*#VITE_COMPRESS = gzip#g" ./apps/web-naive/.env.production
|
||||
sed -i "s#VITE_PWA\s*=.*#VITE_PWA = true#g" ./apps/web-naive/.env.production
|
||||
cat ./apps/web-naive/.env.production
|
||||
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@v4
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -491,9 +491,6 @@ importers:
|
|||
find-up:
|
||||
specifier: ^7.0.0
|
||||
version: 7.0.0
|
||||
fs-extra:
|
||||
specifier: ^11.2.0
|
||||
version: 11.2.0
|
||||
nanoid:
|
||||
specifier: ^5.0.7
|
||||
version: 5.0.7
|
||||
|
@ -513,9 +510,6 @@ importers:
|
|||
'@types/chalk':
|
||||
specifier: ^2.2.0
|
||||
version: 2.2.0
|
||||
'@types/fs-extra':
|
||||
specifier: ^11.0.4
|
||||
version: 11.0.4
|
||||
|
||||
internal/tailwind-config:
|
||||
dependencies:
|
||||
|
@ -3126,7 +3120,6 @@ packages:
|
|||
|
||||
'@ls-lint/ls-lint@2.2.3':
|
||||
resolution: {integrity: sha512-ekM12jNm/7O2I/hsRv9HvYkRdfrHpiV1epVuI2NP+eTIcEgdIdKkKCs9KgQydu/8R5YXTov9aHdOgplmCHLupw==}
|
||||
cpu: [x64, arm64, s390x]
|
||||
os: [darwin, linux, win32]
|
||||
hasBin: true
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@ import {
|
|||
colors,
|
||||
consola,
|
||||
findMonorepoRoot,
|
||||
fs,
|
||||
getPackages,
|
||||
gitAdd,
|
||||
outputJSON,
|
||||
prettierFormat,
|
||||
toPosixPath,
|
||||
} from '@vben/node-utils';
|
||||
|
@ -38,7 +38,7 @@ async function createCodeWorkspace({
|
|||
|
||||
const monorepoRoot = findMonorepoRoot();
|
||||
const outputPath = join(monorepoRoot, CODE_WORKSPACE_FILE);
|
||||
await fs.outputJSON(outputPath, { folders }, { encoding: 'utf8', spaces });
|
||||
await outputJSON(outputPath, { folders }, spaces);
|
||||
|
||||
await prettierFormat(outputPath);
|
||||
if (autoCommit) {
|
||||
|
|
|
@ -6,10 +6,12 @@ import { basename, dirname, join } from 'node:path';
|
|||
import {
|
||||
colors,
|
||||
consola,
|
||||
ensureFile,
|
||||
findMonorepoRoot,
|
||||
fs,
|
||||
generatorContentHash,
|
||||
getPackages,
|
||||
outputJSON,
|
||||
readJSON,
|
||||
UNICODE,
|
||||
} from '@vben/node-utils';
|
||||
|
||||
|
@ -56,8 +58,8 @@ function getCacheFile() {
|
|||
|
||||
async function readCache(cacheFile: string) {
|
||||
try {
|
||||
await fs.ensureFile(cacheFile);
|
||||
return await fs.readJSON(cacheFile, { encoding: 'utf8' });
|
||||
await ensureFile(cacheFile);
|
||||
return await readJSON(cacheFile);
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
|
@ -73,7 +75,7 @@ async function runPublint(files: string[], { check }: PubLintCommandOptions) {
|
|||
const results = await Promise.all(
|
||||
lintFiles.map(async (file) => {
|
||||
try {
|
||||
const pkgJson = await fs.readJSON(file);
|
||||
const pkgJson = await readJSON(file);
|
||||
|
||||
if (pkgJson.private) {
|
||||
return null;
|
||||
|
@ -106,7 +108,7 @@ async function runPublint(files: string[], { check }: PubLintCommandOptions) {
|
|||
}),
|
||||
);
|
||||
|
||||
await fs.outputJSON(cacheFile, cache);
|
||||
await outputJSON(cacheFile, cache);
|
||||
printResult(results, check);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue