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

Conversation

anirudhdream11
Copy link
Contributor

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.

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.

@facebook-github-bot
Copy link
Contributor

Hi @anirudhdream11!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@react-native-bot
Copy link
Collaborator

react-native-bot commented Sep 8, 2024

Warnings
⚠️ 🔒 package.json - Changes were made to package.json. This will require a manual import by a Facebook employee.

Generated by 🚫 dangerJS against 321f531

@anirudhdream11 anirudhdream11 marked this pull request as ready for review September 8, 2024 16:39
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Sep 8, 2024
@trivikr
Copy link

trivikr commented Sep 9, 2024

Fixes: react-native-community/discussions-and-proposals#815

Comment on lines 38 to 40
if (folder === outputDirectory) {
expect(options).toEqual({ recursive: true });
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test does not verify that the first call was for value in outputDirectory.

It attempts to verify that if any call included value from outputDirectory, it contained options set to { recursive: true } which isn't the same.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the testing should be similar to how it's done in scripts/__tests__/scm-utils-test.js

Create mock function using jest.fn(), and validate it's Nth calls using https://jestjs.io/docs/expect#tohavebeennthcalledwithnthcall-arg1-arg2-

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback @trivikr
I've updated the test to ensure it explicitly verifies that mkdirSync is called exactly once with outputDirectory and the correct options { recursive: true }. Since the function logic only requires one directory creation, I removed unnecessary checks for multiple invocations.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified update in commit b8c406c (#46388).

I don't have permission to resolve this thread though.

Copy link
Member

@huntie huntie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me with one nit. Thanks for this change!

@anirudhdream11
Copy link
Contributor Author

Hi @cortinico

I’ve made some changes, including:

  • Replacing mkdirp with fs.mkdirSync({ recursive: true }).
  • Adjusting the test to verify the correct number of calls to mkdirSync and its arguments.
  • Ensuring that the logic aligns with the current function behavior (creating only the necessary directories).

Could you please take a look when you have some time? I'd appreciate any additional feedback or approval if everything looks good.

@huntie
Copy link
Member

huntie commented Sep 13, 2024

@anirudhdream11 Changes look good but we can't move forward until we have passing CI.

I think this is due to Prettier! Please run yarn format from the repo root and see if that fixes the lint workflow.

@facebook-github-bot
Copy link
Contributor

@huntie has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Sep 17, 2024
@facebook-github-bot
Copy link
Contributor

@huntie merged this pull request in 7cdb87e.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @anirudhdream11 in 7cdb87e

When will my fix make it into a release? | How to file a pick request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants