Skip to content

Commit ffdc191

Browse files
[infra] Remove dependency on fs-extra
1 parent cbecb44 commit ffdc191

File tree

14 files changed

+56
-89
lines changed

14 files changed

+56
-89
lines changed

apps/pigment-css-vite-app/src/pages/fixtures/index.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as path from 'path';
2-
import * as fse from 'fs-extra';
2+
import * as fs from 'node:fs/promises';
33
import { chromium } from '@playwright/test';
44

55
async function main() {
@@ -74,7 +74,7 @@ async function main() {
7474

7575
async function takeScreenshot({ testcase, route }) {
7676
const screenshotPath = path.resolve(screenshotDir, `.${route}.png`);
77-
await fse.ensureDir(path.dirname(screenshotPath));
77+
await fs.mkdir(path.dirname(screenshotPath), { recursive: true });
7878

7979
const explicitScreenshotTarget = await page.$('[data-testid="screenshot-target"]');
8080
const screenshotTarget = explicitScreenshotTarget || testcase;

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@
130130
"@playwright/test": "1.54.2",
131131
"@types/babel__core": "^7.20.5",
132132
"@types/babel__register": "^7.17.3",
133-
"@types/fs-extra": "^11.0.4",
134133
"@types/lodash": "^4.17.20",
135134
"@types/mocha": "^10.0.10",
136135
"@types/node": "^20.19.10",
@@ -154,7 +153,6 @@
154153
"eslint-plugin-consistent-default-export-name": "^0.0.15",
155154
"eslint-plugin-react": "^7.37.5",
156155
"fast-glob": "^3.3.3",
157-
"fs-extra": "^11.3.1",
158156
"git-url-parse": "^16.1.0",
159157
"globby": "^14.1.0",
160158
"jsonc-parser": "^3.3.1",

packages-internal/test-utils/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"chai-dom": "^1.12.1",
4747
"dom-accessibility-api": "^0.7.0",
4848
"format-util": "^1.0.5",
49-
"fs-extra": "^11.3.1",
5049
"jsdom": "^26.1.0",
5150
"lodash": "^4.17.21",
5251
"mocha": "^11.7.1",

packages-internal/test-utils/src/KarmaReporterReactProfiler.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// File is not transpiled.
22
const path = require('path');
3-
const fse = require('fs-extra');
3+
const fs = require('node:fs');
44

55
/**
66
* @typedef {object} Browser
@@ -25,7 +25,7 @@ function KarmaReporterReactProfiler(karmaConfig) {
2525
`Expected karma config to contain reactProfilerReporter.outputDir of type 'string' but got type '${typeof outputDir}'.`,
2626
);
2727
}
28-
fse.ensureDirSync(outputDir);
28+
fs.mkdirSync(outputDir, { recursive: true });
2929

3030
/**
3131
* @param {Browser} browser
@@ -44,7 +44,7 @@ function KarmaReporterReactProfiler(karmaConfig) {
4444
this.onBrowserStart = (browser) => {
4545
allRenders.set(browser.id, {});
4646
// Create it on start to signal to users where the files will appear
47-
fse.ensureDirSync(path.join(outputDir, browser.name));
47+
fs.mkdirSync(path.join(outputDir, browser.name), { recursive: true });
4848

4949
browser.emitter.addListener('browser_info', handleBrowserInfo);
5050
};
@@ -67,10 +67,11 @@ function KarmaReporterReactProfiler(karmaConfig) {
6767
return;
6868
}
6969

70-
fse.ensureDirSync(path.join(outputDir, browser.name));
71-
fse.writeJSONSync(path.join(outputDir, browser.name, `${Date.now()}.json`), browserRenders, {
72-
spaces: 2,
73-
});
70+
fs.mkdirSync(path.join(outputDir, browser.name), { recursive: true });
71+
fs.writeFileSync(
72+
path.join(outputDir, browser.name, `${Date.now()}.json`),
73+
JSON.stringify(browserRenders, null, 2),
74+
);
7475
};
7576
}
7677

packages/mui-material/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
"chai": "^4.5.0",
6363
"css-mediaquery": "^0.1.2",
6464
"fast-glob": "^3.3.3",
65-
"fs-extra": "^11.3.1",
6665
"lodash": "^4.17.21",
6766
"react": "^19.1.1",
6867
"react-dom": "^19.1.1",

pnpm-lock.yaml

Lines changed: 0 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/buildColorTypes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as path from 'path';
2-
import * as fse from 'fs-extra';
2+
import * as fs from 'node:fs/promises';
33
import * as colors from '@mui/material/colors';
44

55
// use netlify deploy preview if you want to test changes
@@ -38,7 +38,7 @@ ${Object.entries(variants)
3838
export default ${name};
3939
`;
4040

41-
return fse.writeFile(typesFilename, typescript, { encoding: 'utf8' });
41+
return fs.writeFile(typesFilename, typescript, { encoding: 'utf8' });
4242
}
4343

4444
function buildColorPreviews(name, variants) {
@@ -52,7 +52,7 @@ function buildColorPreviews(name, variants) {
5252
<rect width="100%" height="100%" fill="${color}"/>
5353
</svg>`;
5454
const filename = path.resolve(nextPublicPath, getColorHref(name, variant));
55-
await fse.writeFile(filename, svg, { encoding: 'utf8' });
55+
await fs.writeFile(filename, svg, { encoding: 'utf8' });
5656
}),
5757
);
5858
}

scripts/copyFilesUtils.mjs

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable no-console */
22
import path from 'path';
3-
import fse from 'fs-extra';
3+
import fs from 'node:fs/promises';
44
import glob from 'fast-glob';
55

66
const packagePath = process.cwd();
@@ -17,10 +17,17 @@ const buildPath = path.join(packagePath, './build');
1717
export async function includeFileInBuild(file, target = path.basename(file)) {
1818
const sourcePath = path.resolve(packagePath, file);
1919
const targetPath = path.resolve(buildPath, target);
20-
await fse.copy(sourcePath, targetPath);
20+
await fs.copyFile(sourcePath, targetPath);
2121
console.log(`Copied ${sourcePath} to ${targetPath}`);
2222
}
2323

24+
function pathExists(pathToTest) {
25+
return fs
26+
.stat(pathToTest)
27+
.then(() => true)
28+
.catch(() => false);
29+
}
30+
2431
/**
2532
* Puts a package.json into every immediate child directory of rootDir.
2633
* That package.json contains information about esm for bundlers so that imports
@@ -39,7 +46,7 @@ export async function createModulePackages({ from, to }) {
3946
await Promise.all(
4047
directoryPackages.map(async (directoryPackage) => {
4148
const packageJsonPath = path.join(to, directoryPackage, 'package.json');
42-
const topLevelPathImportsAreCommonJSModules = await fse.pathExists(
49+
const topLevelPathImportsAreCommonJSModules = await pathExists(
4350
path.resolve(path.dirname(packageJsonPath), '../esm'),
4451
);
4552

@@ -55,10 +62,10 @@ export async function createModulePackages({ from, to }) {
5562
};
5663

5764
const [typingsEntryExist, moduleEntryExists, mainEntryExists] = await Promise.all([
58-
fse.pathExists(path.resolve(path.dirname(packageJsonPath), packageJson.types)),
59-
fse.pathExists(path.resolve(path.dirname(packageJsonPath), packageJson.module)),
60-
fse.pathExists(path.resolve(path.dirname(packageJsonPath), packageJson.main)),
61-
fse.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2)),
65+
pathExists(path.resolve(path.dirname(packageJsonPath), packageJson.types)),
66+
pathExists(path.resolve(path.dirname(packageJsonPath), packageJson.module)),
67+
pathExists(path.resolve(path.dirname(packageJsonPath), packageJson.main)),
68+
fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2)),
6269
]);
6370

6471
const manifestErrorMessages = [];
@@ -81,25 +88,14 @@ export async function createModulePackages({ from, to }) {
8188
);
8289
}
8390

84-
export async function typescriptCopy({ from, to }) {
85-
if (!(await fse.pathExists(to))) {
86-
console.warn(`path ${to} does not exists`);
87-
return [];
88-
}
89-
90-
const files = await glob('**/*.d.ts', { cwd: from });
91-
const cmds = files.map((file) => fse.copy(path.resolve(from, file), path.resolve(to, file)));
92-
return Promise.all(cmds);
93-
}
94-
9591
export async function cjsCopy({ from, to }) {
96-
if (!(await fse.pathExists(to))) {
92+
if (!(await pathExists(to))) {
9793
console.warn(`path ${to} does not exists`);
9894
return [];
9995
}
10096

10197
const files = await glob('**/*.cjs', { cwd: from });
102-
const cmds = files.map((file) => fse.copy(path.resolve(from, file), path.resolve(to, file)));
98+
const cmds = files.map((file) => fs.copyFile(path.resolve(from, file), path.resolve(to, file)));
10399
return Promise.all(cmds);
104100
}
105101

@@ -139,7 +135,7 @@ function createExportFor(exportName, conditions) {
139135
}
140136

141137
export async function createPackageFile() {
142-
const packageData = await fse.readFile(path.resolve(packagePath, './package.json'), 'utf8');
138+
const packageData = await fs.readFile(path.resolve(packagePath, './package.json'), 'utf8');
143139
const { nyc, scripts, devDependencies, workspaces, ...packageDataOther } =
144140
JSON.parse(packageData);
145141

@@ -177,7 +173,7 @@ export async function createPackageFile() {
177173
};
178174

179175
const typeDefinitionsFilePath = path.resolve(buildPath, './index.d.ts');
180-
if (await fse.pathExists(typeDefinitionsFilePath)) {
176+
if (await pathExists(typeDefinitionsFilePath)) {
181177
newPackageData.types = './index.d.ts';
182178
}
183179

@@ -187,13 +183,13 @@ export async function createPackageFile() {
187183

188184
const targetPath = path.resolve(buildPath, './package.json');
189185

190-
await fse.writeFile(targetPath, JSON.stringify(newPackageData, null, 2), 'utf8');
186+
await fs.writeFile(targetPath, JSON.stringify(newPackageData, null, 2), 'utf8');
191187
console.log(`Created package.json in ${targetPath}`);
192188

193189
return newPackageData;
194190
}
195191

196192
export async function prepend(file, string) {
197-
const data = await fse.readFile(file, 'utf8');
198-
await fse.writeFile(file, string + data, 'utf8');
193+
const data = await fs.readFile(file, 'utf8');
194+
await fs.writeFile(file, string + data, 'utf8');
199195
}

scripts/generateProptypes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable no-console */
22
import * as path from 'path';
3-
import * as fse from 'fs-extra';
3+
import * as fs from 'node:fs/promises';
44
import * as prettier from 'prettier';
55
import glob from 'fast-glob';
66
import * as _ from 'lodash';
@@ -199,7 +199,7 @@ async function generateProptypes(
199199
});
200200
});
201201

202-
const sourceContent = await fse.readFile(sourceFile, 'utf8');
202+
const sourceContent = await fs.readFile(sourceFile, 'utf8');
203203
const isTsFile = /(\.(ts|tsx))/.test(sourceFile);
204204
// If the component inherits the props from some unstyled components
205205
// we don't want to add those propTypes again in the Material UI/Joy UI propTypes
@@ -296,7 +296,7 @@ async function generateProptypes(
296296
const formatted = fixBabelGeneratorIssues(prettified);
297297
const correctedLineEndings = fixLineEndings(sourceContent, formatted);
298298

299-
await fse.writeFile(sourceFile, correctedLineEndings);
299+
await fs.writeFile(sourceFile, correctedLineEndings);
300300
}
301301

302302
interface HandlerArgv {

scripts/pigmentcss-render-mui-demos.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'path';
2-
import fse from 'fs-extra';
2+
import fs from 'node:fs/promises';
33
import * as prettier from 'prettier';
44

55
function pascalCase(string) {
@@ -29,14 +29,14 @@ async function run() {
2929
});
3030

3131
// Find the demos of the component
32-
const docSource = await fse.readFile(
32+
const docSource = await fs.readFile(
3333
path.join(process.cwd(), `docs/pages/material-ui/${args[0]}.js`),
3434
'utf8',
3535
);
3636
const matches = docSource.match(/\/([a-z-]+)\.md\?/);
3737
const dataFolderName = matches[1];
3838

39-
const filenames = await fse.readdir(
39+
const filenames = await fs.readdir(
4040
path.join(process.cwd(), `docs/data/material/components/${dataFolderName}`),
4141
);
4242
const tsFiles = filenames.filter((filename) => filename.endsWith('.tsx'));
@@ -83,8 +83,8 @@ ${renders.join('\n')}
8383
...prettierConfig,
8484
filepath: nextFilepath,
8585
});
86-
await fse.mkdirp(`apps/pigment-css-next-app/src/app/material-ui/${args[0]}`);
87-
await fse.writeFile(nextFilepath, prettiedNextFileContent);
86+
await fs.mkdir(`apps/pigment-css-next-app/src/app/material-ui/${args[0]}`, { recursive: true });
87+
await fs.writeFile(nextFilepath, prettiedNextFileContent);
8888

8989
/**
9090
* Zero-Runtime Vite App
@@ -115,8 +115,8 @@ ${renders.join('\n')}
115115
...prettierConfig,
116116
filepath: viteFilepath,
117117
});
118-
await fse.mkdirp(`apps/pigment-css-vite-app/src/pages/material-ui`);
119-
await fse.writeFile(viteFilepath, prettiedViteFileContent);
118+
await fs.mkdir(`apps/pigment-css-vite-app/src/pages/material-ui`, { recursive: true });
119+
await fs.writeFile(viteFilepath, prettiedViteFileContent);
120120
}
121121

122122
run();

0 commit comments

Comments
 (0)