mirror of
https://github.com/facebook/react-native.git
synced 2024-11-22 06:29:46 +00:00
7cdb87eb19
Summary: This pull request replaces the use of mkdirp with Node.js's built-in fs.mkdirSync({ recursive: true }) function, which is available in Node.js version 10.12.0 and above. This change reduces the number of external dependencies and simplifies the codebase by using the native capabilities of Node.js. The motivation behind this change is to remove the unnecessary mkdirp dependency, as Node.js natively supports recursive directory creation since version 10.12.0. This streamlines the code and reduces the reliance on external libraries. ## Changelog: [INTERNAL] [REMOVED] - Replaced mkdirp with fs.mkdirSync({ recursive: true }) in build scripts and codegen. Requires Node.js 10.12.0 and above. Pull Request resolved: https://github.com/facebook/react-native/pull/46388 Test Plan: I ran the build and codegen scripts locally with Node.js version 10.12.0 and above after replacing mkdirp, ensuring the scripts work as expected. No issues were encountered, and all processes, including directory creation and file handling, function correctly. Reviewed By: cortinico Differential Revision: D62852488 Pulled By: huntie fbshipit-source-id: 76f44102a80b499521c156308d276a17d279ce38
98 lines
2.5 KiB
JavaScript
98 lines
2.5 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
const {isTaggedLatest, revertFiles, saveFiles} = require('../scm-utils');
|
|
|
|
let execResult = null;
|
|
const cpMock = jest.fn();
|
|
const mkdirSyncMock = jest.fn();
|
|
jest
|
|
.mock('shelljs', () => ({
|
|
exec: () => {
|
|
return {
|
|
stdout: execResult,
|
|
};
|
|
},
|
|
echo: message => {
|
|
console.log(message);
|
|
},
|
|
exit: exitCode => {
|
|
exit(exitCode);
|
|
},
|
|
cp: cpMock,
|
|
}))
|
|
.mock('fs', () => ({
|
|
existsSync: jest.fn().mockImplementation(_ => true),
|
|
mkdirSync: mkdirSyncMock,
|
|
}))
|
|
.mock('path', () => ({
|
|
dirname: jest
|
|
.fn()
|
|
.mockImplementation(filePath =>
|
|
filePath.includes('/') ? filePath.split('/')[0] : '.',
|
|
),
|
|
}));
|
|
|
|
describe('scm-utils', () => {
|
|
beforeEach(() => {
|
|
jest.resetModules();
|
|
jest.resetAllMocks();
|
|
});
|
|
|
|
describe('isTaggedLatest', () => {
|
|
it('it should identify commit as tagged `latest`', () => {
|
|
execResult = '6c19dc3266b84f47a076b647a1c93b3c3b69d2c5\n';
|
|
expect(isTaggedLatest('6c19dc3266b84f47a076b647a1c93b3c3b69d2c5')).toBe(
|
|
true,
|
|
);
|
|
});
|
|
it('it should not identify commit as tagged `latest`', () => {
|
|
execResult = '6c19dc3266b84f47a076b647a1c93b3c3b69d2c5\n';
|
|
expect(isTaggedLatest('6c19dc3266b8')).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('saveFiles', () => {
|
|
it('it should save files in the temp folder', () => {
|
|
const tmpFolder = '/tmp';
|
|
saveFiles(['package.json', 'android/package.json'], tmpFolder);
|
|
expect(mkdirSyncMock).toHaveBeenCalledWith(`${tmpFolder}/android`, {
|
|
recursive: true,
|
|
});
|
|
expect(cpMock).toHaveBeenNthCalledWith(
|
|
1,
|
|
'package.json',
|
|
'/tmp/package.json',
|
|
);
|
|
expect(cpMock).toHaveBeenNthCalledWith(
|
|
2,
|
|
'android/package.json',
|
|
`${tmpFolder}/android/package.json`,
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('revertFiles', () => {
|
|
it('it should revert files from the temp folder', () => {
|
|
const tmpFolder = '/tmp';
|
|
revertFiles(['package.json', 'android/package.json'], tmpFolder);
|
|
expect(cpMock).toHaveBeenNthCalledWith(
|
|
1,
|
|
`${tmpFolder}/package.json`,
|
|
'package.json',
|
|
);
|
|
expect(cpMock).toHaveBeenNthCalledWith(
|
|
2,
|
|
`${tmpFolder}/android/package.json`,
|
|
'android/package.json',
|
|
);
|
|
});
|
|
});
|
|
});
|