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

Remove fs-extra #147

Closed
wants to merge 3 commits into from
Closed

Remove fs-extra #147

wants to merge 3 commits into from

Conversation

jfmengels
Copy link
Owner

Fixes #120

Removes the dependency on fs-extra. As @lydell pointed out, fs.copyFileSync already exists in core fs.
fs.copy (which copies entire directories) however doesn't. I chose to fix this by hardcoding which files to copy (which is faster, though potentially error-prone 🤷)

Now that fs-extra is absent from the dependencies, tsc complains about the files that reference it in the new-package/ folder. Those files are copied over and not included, but do use fs-extra (mostly because of the "need" to copy entire directories, ideally in a sync manner). I don't know how to suppress this error, and if I ignore the file, then ESLint complains that it can't parse it.

If anyone has an idea on how to fix this, I'm all ears!

@jfmengels jfmengels added the help wanted We could use your help label Mar 17, 2024
Copy link

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/fs-extra@9.1.0 filesystem Transitive: environment +5 222 kB ryanzim

🚮 Removed packages: npm/fs-extra@9.0.0

View full report↗︎

@lydell
Copy link
Contributor

lydell commented Mar 17, 2024

You can use fs.cpSync(src, dest, { recursive: true }) to copy whole dirs. https://nodejs.org/api/fs.html#fscpsyncsrc-dest-options

Available since 16.7.0, marked as Experimental, though. I use it in scripts without trouble, but I’m not sure if I’d dare doing it in package code.

const util = require('util');
const fs = require('graceful-fs');
const {rimraf} = require('rimraf');

const copyFile = util.promisify(fs.copyFile);
Copy link
Contributor

Choose a reason for hiding this comment

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

Btw, there’s a a promises API: https://nodejs.org/api/fs.html#promises-api

Copy link
Owner Author

Choose a reason for hiding this comment

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

Ah yes, I looked for it in my code but didn't see any usages, so I thought they must have appeared after v10.

Copy link
Contributor

Choose a reason for hiding this comment

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

From the page above:

Version Changes
v14.0.0 Exposed as require('fs/promises').
v11.14.0, v10.17.0 This API is no longer experimental.
v10.1.0 The API is accessible via require('fs').promises only.
v10.0.0 Added in: v10.0.0

So you can use it in 10+, but it'll be experimental, and getting at it might be annoying.

@jfmengels
Copy link
Owner Author

For now elm-review supports v10 of Node.js and above, although I think that support for v10 and v12 is broken because of indirect dependencies 😞, but supporting older versions including v14 is still the aim.

Maybe I should break this in a future version because for a soon-to-be feature I'll need a more recent version of glob which only supports ">=16 || 14 >=14.17". Maybe that would be a good time to cut a major version of the CLI 🤷

@lydell
Copy link
Contributor

lydell commented Mar 19, 2024

You are correct, Node.js 10 and 12 are currently broken. Given that:

  • Not very many people have complained about it.
  • Node.js 10 and 12 have been EOL for quite some time now.
  • You can release major versions of the CLI without causing problems like with the Elm package (which would make all rule packages incompatible).

… I would say that it could be time to release that major version with some cleanups :)

@lishaduck

This comment was marked as outdated.

@lishaduck
Copy link
Contributor

lishaduck commented Jun 15, 2024

Now that fs-extra is absent from the dependencies, tsc complains about the files that reference it in the new-package/ folder. Those files are copied over and not included, but do use fs-extra (mostly because of the "need" to copy entire directories, ideally in a sync manner). I don't know how to suppress this error, and if I ignore the file, then ESLint complains that it can't parse it.

Wait, are these being copied into new elm-review packages? As in, they have to be run in the context of a new project? If so, I'd probably drop fs-extra there, because unless I'm misunderstanding this code, fs-extra isn't going to be there, right?
Nope. I see, you're generating that dynamically. I'd make fs-extra a devdep, given that you can't inline the files b/c back compat. It is, after all, a devdep in the sense that it provides types.

Oh, or you could just exclude it from ts, or @ts-expect-error. Honestly, the last option might be best. It's not like an @ts-ignore, it asserts that it doesn't work, and fails once it starts working.

const promises = files.map((file) =>
copyFile(path.join(srcFolder, file), path.join(destFolder, file))
);
return Promise.all(promises).then(() => undefined);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not this?

Suggested change
return Promise.all(promises).then(() => undefined);
return Promise.all(promises);

Maybe I've forgotten something, but the noop shouldn't be necessary.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I think it's to have the return type @returns {Promise<void>} instead of @returns {Promise<void[]>} or @returns {Promise<something[]>}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's to have the return type @returns {Promise<void>} instead of @returns {Promise<void[]>} or @returns {Promise<something[]>}

Hmm. That makes sense. I would think that void[] is assignable to void, but maybe not.

This was referenced Jun 22, 2024
@lishaduck lishaduck mentioned this pull request Jul 19, 2024
10 tasks
lishaduck added a commit to lishaduck/node-elm-review that referenced this pull request Nov 10, 2024
Manual rebase of jfmengels#147.

Co-authored-by: Jeroen Engels <jfm.engels@gmail.com>
@jfmengels
Copy link
Owner Author

Supersed by #303

@jfmengels jfmengels closed this Nov 10, 2024
@jfmengels jfmengels deleted the remove-fs-extra branch November 10, 2024 22:39
lishaduck added a commit to lishaduck/node-elm-review that referenced this pull request Nov 10, 2024
Manual rebase of jfmengels#147.

Co-authored-by: Jeroen Engels <jfm.engels@gmail.com>
lishaduck added a commit to lishaduck/node-elm-review that referenced this pull request Nov 10, 2024
Manual rebase of jfmengels#147.

Co-authored-by: Jeroen Engels <jfm.engels@gmail.com>
jfmengels added a commit that referenced this pull request Nov 10, 2024
Manual rebase of #147.

Co-authored-by: Jeroen Engels <jfm.engels@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted We could use your help
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace fs-extra
3 participants