Skip to content

chore: remove fs-extra #1271

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

Merged
merged 6 commits into from
Oct 11, 2020
Merged

Conversation

JCMais
Copy link
Contributor

@JCMais JCMais commented Sep 23, 2020

Closes #1241

- Summary

See issue above.

I've left a few comments about some changes that need to be addressed before this is merged.

I also wrote this using Node.js 14, so I need to run the tests again using Node.js 8 as it's probably going to yell at me. 😄 I will do that when I find some time tomorrow.

- Test plan

This PR adds no new features/changes other than removing all usages of fs-extra, so the existing test suite was sufficient.

There are some tests failing locally here, but it should not be related to these changes, as they were already failing before I started working on this. I will take a look later into this.

- Description for the changelog

remove fs-extra and use util.promisify instead

- A picture of a cute animal (not mandatory but encouraged)

baby capybara

@@ -22,74 +33,75 @@ const createSiteBuilder = ({ siteName }) => {
const dest = path.join(directory, pathPrefix, 'netlify.toml')
const content = toToml(config, { space: 2 })
tasks.push(async () => {
await fs.ensureFile(dest)
await ensureDir(path.dirname(dest))
Copy link
Contributor Author

@JCMais JCMais Sep 23, 2020

Choose a reason for hiding this comment

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

We only need to ensure that the directory is created, as writeFile already creates the file if it does not exists (default mode is 'w').

Copy link
Contributor

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

Thanks @JCMais, nice work.
Added some comments.

@JCMais
Copy link
Contributor Author

JCMais commented Sep 23, 2020

@erezrokah @ehmicky I've addressed the requested changes. 👍

del could have been a dev dependency, as it's only used in tests, but I decided to create a separated function inside lib/fs.js just in case it would be useful later on. This is the reason it is a normal dependency.

Almost all tests are green here now, the tests that were failing before were due to missing the NETLIFY_AUTH_TOKEN environment variable. The only one not working now is the one related to Edge Handlers, most probably because I don't have access to the preview.

I also took the opportunity to do a small refactor on site/{sync,watch}.js to use async/await instead of .then() and also created a separated fs file with some utils, this is the second commit above (they are only used inside watch.js and sync.js).

@JCMais JCMais marked this pull request as ready for review September 23, 2020 18:49
@erezrokah erezrokah added the type: chore work needed to keep the product and development running smoothly label Sep 24, 2020
Copy link
Contributor

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

Thanks for the quick follow up @JCMais, add a few minor comments and suggestions.
You're correct about Edge Handlers, they are not available for all accounts yet.

// ignore erros for mkdir
}

const childrenItems = await fs.readdir(src)
Copy link
Contributor

Choose a reason for hiding this comment

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

This has the potential to create a lot of promises.
I don't think we should optimise this yet since it's only used for our docs site that doesn't contain many of files.

const binExists = await fs.exists(binPath)
if (!binExists) {
return false
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice cleanup!

@JCMais JCMais force-pushed the chore-remove-fs-extra branch from 22bca29 to 814ba72 Compare September 24, 2020 15:14
@JCMais
Copy link
Contributor Author

JCMais commented Sep 24, 2020

Rebased on top of master and addressed all your comments @erezrokah, thanks for the review!

@JCMais
Copy link
Contributor Author

JCMais commented Sep 24, 2020

By the way, if we look further into this change, it probably makes sense to use graceful-fs directly instead of just fs. As just using fs is not going to handle some scenarios that were being handled before when using fs-extra (which uses graceful-fs internally).

v4 does not monkey-patch fs anymore.

edit: and from looking at fs-extra it seems that it was already using graceful-fs v4: https://github.com/jprichardson/node-fs-extra/blob/b7df7cce3f7ca5bc0ab85110aa997bd0ad33482f/package.json#L39

with the above in mind, I don't know if this PR makes sense anymore, given the original context. If it does, let me know and I will finish the remaining requested changes.

@erezrokah
Copy link
Contributor

@JCMais, this PR brings value in the form of:

  1. Doing some refactoring and wrapping fs with our own layer (making it easier to make the relevant changes once we drop Node 8 support).
  2. Using Node core when possible and falling back to specific dependencies when needed seems to make more sense in our case.

It would be great if you could follow up with the remaining changes.

@JCMais
Copy link
Contributor Author

JCMais commented Sep 28, 2020

Thanks @erezrokah, I will do that as soon as I get a chance today.

@JCMais
Copy link
Contributor Author

JCMais commented Sep 29, 2020

added cpy as a dependency to ./site and used it instead of the custom implementation.

The test failure is weird, I will try running the project on Windows to take a look if it's also reproducible locally (looks like there are a few EPERM / EBUSY errors too).

I have not rebased with master yet, will do after the latest changes are reviewed.

@erezrokah
Copy link
Contributor

I have not rebased with master yet, will do after the latest changes are reviewed.

Latest changes are good, thanks! Can you follow up with a rebase? I'm re-running the tests to verify

@JCMais JCMais force-pushed the chore-remove-fs-extra branch from d486341 to 54403f4 Compare September 30, 2020 13:06
@JCMais
Copy link
Contributor Author

JCMais commented Sep 30, 2020

the branch has been rebased with master

@JCMais
Copy link
Contributor Author

JCMais commented Oct 6, 2020

Resolved the conflict directly in the GitHub UI (thus the merge commit), if you need me to rebase with master just let me know.

@erezrokah
Copy link
Contributor

Sorry for the delay with this @JCMais, going to merge and publish after https://jamstackconf.com/virtual/

@JCMais
Copy link
Contributor Author

JCMais commented Oct 6, 2020

no hurries @erezrokah , looking forward to the conf too. 😄

@erezrokah erezrokah force-pushed the chore-remove-fs-extra branch from 106d407 to 6c2a274 Compare October 11, 2020 15:29
@JCMais JCMais requested a review from a team as a code owner October 11, 2020 15:29
Copy link
Contributor

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

Thank you for your patience with this @JCMais

@erezrokah erezrokah merged commit 91b147e into netlify:master Oct 11, 2020
@JCMais JCMais deleted the chore-remove-fs-extra branch October 13, 2020 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: chore work needed to keep the product and development running smoothly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chore: remove fs-extra as a dependecy
3 participants