Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace mkdirp with mkdir fs #46388

Closed
18 changes: 0 additions & 18 deletions flow-typed/npm/mkdirp_v0.5.x.js

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
"metro-babel-register": "^0.80.10",
"metro-memory-fs": "^0.80.10",
"micromatch": "^4.0.4",
"mkdirp": "^0.5.1",
"node-fetch": "^2.2.0",
"nullthrows": "^1.1.1",
"prettier": "2.8.8",
Expand Down
1 change: 0 additions & 1 deletion packages/react-native-codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"hermes-parser": "0.23.1",
"invariant": "^2.2.4",
"jscodeshift": "^0.14.0",
"mkdirp": "^0.5.1",
"nullthrows": "^1.1.1",
"yargs": "^17.6.2"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native-codegen/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const chalk = require('chalk');
const fs = require('fs');
const glob = require('glob');
const micromatch = require('micromatch');
const mkdirp = require('mkdirp');
const path = require('path');
const prettier = require('prettier');
const prettierConfig = JSON.parse(
Expand Down Expand Up @@ -60,7 +59,8 @@ function getBuildPath(file, buildFolder) {
function buildFile(file, silent) {
const destPath = getBuildPath(file, BUILD_DIR);

mkdirp.sync(path.dirname(destPath));
fs.mkdirSync(path.dirname(destPath), { recursive: true });

if (micromatch.isMatch(file, IGNORE_PATTERN)) {
silent ||
process.stdout.write(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

const RNCodegen = require('../../generators/RNCodegen.js');
const fs = require('fs');
const mkdirp = require('mkdirp');

const args = process.argv.slice(2);
if (args.length < 3) {
Expand All @@ -39,7 +38,7 @@ if (schemaText == null) {
throw new Error(`Can't find schema at ${schemaPath}`);
}

mkdirp.sync(outputDirectory);
fs.mkdirSync(outputDirectory, { recursive: true });

let schema;
try {
Expand Down
1 change: 0 additions & 1 deletion packages/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@
"memoize-one": "^5.0.0",
"metro-runtime": "^0.80.10",
"metro-source-map": "^0.80.10",
"mkdirp": "^0.5.1",
"nullthrows": "^1.1.1",
"pretty-format": "^29.7.0",
"promise": "^8.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,23 @@ describe('generateSpec', () => {
const platform = 'ios';
const libraryType = 'all';
const schemaPath = './';
const componentsOutputDir = normalize(
'app/ios/build/generated/ios/react/renderer/components/library',
);
const modulesOutputDir = normalize('app/ios/build/generated/ios/library');
const outputDirectory = normalize('app/ios/build/generated/ios');
const libraryName = 'library';
const packageName = 'com.library';
const generators = ['componentsIOS', 'modulesIOS', 'modulesCxx'];

// Create a mock for fs.mkdirSync
const mkdirSyncMock = jest.fn();

jest.mock('fs', () => ({
readFileSync: (path, encoding) => {
expect(path).toBe(schemaPath);
expect(encoding).toBe('utf-8');
return fixtures.schemaText;
},
}));

let mkdirpSyncInvoked = 0;
jest.mock('mkdirp', () => ({
sync: folder => {
if (mkdirpSyncInvoked === 0) {
expect(folder).toBe(outputDirectory);
}

if (mkdirpSyncInvoked === 1) {
expect(folder).toBe(componentsOutputDir);
}

if (mkdirpSyncInvoked === 2) {
expect(folder).toBe(modulesOutputDir);
}

mkdirpSyncInvoked += 1;
},
mkdirSync: mkdirSyncMock, // Use the mock for mkdirSync
readdirSync: jest.fn().mockReturnValue([]),
renameSync: jest.fn(),
}));

// We cannot mock directly the `RNCodegen` object because the
Expand Down Expand Up @@ -83,6 +66,8 @@ describe('generateSpec', () => {
libraryType,
);

expect(mkdirpSyncInvoked).toBe(1);
huntie marked this conversation as resolved.
Show resolved Hide resolved
// Verifying that mkdirSync was called once with the correct arguments
anirudhdream11 marked this conversation as resolved.
Show resolved Hide resolved
expect(mkdirSyncMock).toHaveBeenCalledTimes(1);
expect(mkdirSyncMock).toHaveBeenCalledWith(outputDirectory, { recursive: true });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const generateSpecsCLIExecutor = require('./generate-specs-cli-executor');
const {execSync} = require('child_process');
const fs = require('fs');
const glob = require('glob');
const mkdirp = require('mkdirp');
const os = require('os');
const path = require('path');

Expand Down Expand Up @@ -513,7 +512,7 @@ function createComponentProvider(schemas, supportedApplePlatforms) {
'React',
'Fabric',
);
mkdirp.sync(outputDir);
fs.mkdirSync(outputDir, {recursive: true});
utils.getCodegen().generateFromSchemas(
{
schemas: schemas,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

const utils = require('./codegen-utils');
const fs = require('fs');
const mkdirp = require('mkdirp');
const path = require('path');

const GENERATORS = {
Expand All @@ -33,7 +32,7 @@ function createOutputDirectoryIfNeeded(outputDirectory, libraryName) {
if (!outputDirectory) {
outputDirectory = path.resolve(__dirname, '..', 'Libraries', libraryName);
}
mkdirp.sync(outputDirectory);
fs.mkdirSync(outputDirectory, { recursive: true });
}

/**
Expand Down Expand Up @@ -95,7 +94,7 @@ function generateSpecFromInMemorySchema(
// * this subdir structure is Android-only, not applicable to iOS
const files = fs.readdirSync(outputDirectory);
const jniOutputDirectory = `${outputDirectory}/jni/react/renderer/components/${libraryName}`;
mkdirp.sync(jniOutputDirectory);
fs.mkdirSync(jniOutputDirectory, { recursive: true });
files
.filter(f => f.endsWith('.h') || f.endsWith('.cpp'))
.forEach(f => {
Expand Down
3 changes: 1 addition & 2 deletions packages/react-native/scripts/generate-provider-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

const utils = require('./codegen/codegen-utils');
const fs = require('fs');
const mkdirp = require('mkdirp');
const yargs = require('yargs');

const argv = yargs
Expand Down Expand Up @@ -49,7 +48,7 @@ function generateProvider(platform, schemaListPath, outputDirectory) {
if (!outputDirectory) {
throw new Error('outputDir is required');
}
mkdirp.sync(outputDirectory);
fs.mkdirSync(outputDirectory, { recursive: true });

let schemaPaths;
try {
Expand Down
8 changes: 3 additions & 5 deletions scripts/__tests__/scm-utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {isTaggedLatest, revertFiles, saveFiles} = require('../scm-utils');

let execResult = null;
const cpMock = jest.fn();
const mkdirpSyncMock = jest.fn();
const mkdirSyncMock = jest.fn();
jest
.mock('shelljs', () => ({
exec: () => {
Expand All @@ -29,16 +29,14 @@ jest
}))
.mock('fs', () => ({
existsSync: jest.fn().mockImplementation(_ => true),
mkdirSync: mkdirSyncMock,
}))
.mock('path', () => ({
dirname: jest
.fn()
.mockImplementation(filePath =>
filePath.includes('/') ? filePath.split('/')[0] : '.',
),
}))
.mock('mkdirp', () => ({
sync: mkdirpSyncMock,
}));

describe('scm-utils', () => {
Expand All @@ -64,7 +62,7 @@ describe('scm-utils', () => {
it('it should save files in the temp folder', () => {
const tmpFolder = '/tmp';
saveFiles(['package.json', 'android/package.json'], tmpFolder);
expect(mkdirpSyncMock).toHaveBeenCalledWith(`${tmpFolder}/android`);
expect(mkdirSyncMock).toHaveBeenCalledWith(`${tmpFolder}/android`, { recursive: true });
expect(cpMock).toHaveBeenNthCalledWith(
1,
'package.json',
Expand Down
3 changes: 1 addition & 2 deletions scripts/scm-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
'use strict';

const fs = require('fs');
const mkdirp = require('mkdirp');
const path = require('path');
const {cp, echo, exec, exit} = require('shelljs');

Expand Down Expand Up @@ -75,7 +74,7 @@ function saveFiles(filePaths /*: Array<string> */, tmpFolder /*: string */) {
const dirName = path.dirname(filePath);
if (dirName !== '.') {
const destFolder = `${tmpFolder}/${dirName}`;
mkdirp.sync(destFolder);
fs.mkdirSync(destFolder, { recursive: true });
}
cp(filePath, `${tmpFolder}/${filePath}`);
}
Expand Down
Loading