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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@

## [Unreleased]

- Removed the dependency on `fs-extra`.

## [2.11.1] - 2024-03-16

- Fixed a crash when running in watch mode related to not being able to fetch cache results.
Expand Down
19 changes: 19 additions & 0 deletions lib/fs-wrapper.js
@@ -1,7 +1,10 @@
const path = require('path');
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.


// TODO When we drop support for Node.js v10, use natively promisified functions

/**
Expand Down Expand Up @@ -87,6 +90,20 @@ function mkdirpSync(dir) {
fs.mkdirSync(dir, {recursive: true});
}

/**
* Copy files from srcFolder to destFolder.
* @param {Path} srcFolder
* @param {Path} destFolder
* @param {Path[]} files
* @returns {Promise<void>}
*/
function copyFiles(srcFolder, destFolder, files) {
const promises = files.map((file) =>
copyFile(path.join(srcFolder, file), path.join(destFolder, file))
);
return Promise.all(promises).then(() => undefined);
}

module.exports = {
readFile,
readJsonFile,
Expand All @@ -98,6 +115,8 @@ module.exports = {
mkdirp,
mkdirpSync,

copyFiles,

readdir: util.promisify(fs.readdir),

remove: rimraf
Expand Down
3 changes: 1 addition & 2 deletions lib/init.js
@@ -1,6 +1,5 @@
const fs = require('fs');
const path = require('path');
const fsExtra = require('fs-extra');
const chalk = require('chalk');
const prompts = require('prompts');
const FS = require('./fs-wrapper');
Expand Down Expand Up @@ -155,7 +154,7 @@ async function createElmJson(options, directory) {
}

function createReviewConfig(directory, template) {
fsExtra.copyFileSync(
fs.copyFileSync(
path.join(__dirname, '../init-templates/', template),
path.join(directory, 'ReviewConfig.elm')
);
Expand Down
31 changes: 17 additions & 14 deletions lib/new-package.js
Expand Up @@ -3,7 +3,6 @@ const path = require('path');
const childProcess = require('child_process');
const chalk = require('chalk');
const prompts = require('prompts');
const fsExtra = require('fs-extra');
const Init = require('./init');
const Spinner = require('./spinner');
const NewRule = require('./new-rule');
Expand Down Expand Up @@ -236,10 +235,13 @@ ElmjutsuDumMyM0DuL3.elm
);

Spinner.succeedAndNowDo('Adding GitHub Actions');
fsExtra.copySync(
const githubDestFiles = path.join(dir, '.github/');
FS.mkdirpSync(path.join(githubDestFiles, 'ISSUE_TEMPLATE'));
FS.mkdirpSync(path.join(githubDestFiles, 'workflows'));
await FS.copyFiles(
path.join(__dirname, '../new-package/github/'),
path.join(dir, '.github/'),
{overwrite: true}
githubDestFiles,
['ISSUE_TEMPLATE/new-rule-idea.md', 'workflows/test.yml']
);

Spinner.succeedAndNowDo(
Expand Down Expand Up @@ -277,26 +279,27 @@ ElmjutsuDumMyM0DuL3.elm
Spinner.succeedAndNowDo('Adding maintenance scripts');
const maintenancePath = path.join(process.cwd(), packageName, 'maintenance');
FS.mkdirpSync(maintenancePath);
fsExtra.copySync(
await FS.copyFiles(
path.join(__dirname, '../new-package/maintenance/'),
maintenancePath,
{
overwrite: true
}
['MAINTENANCE.md', 'update-examples-from-preview.js']
);

const packageTests = path.join(
process.cwd(),
packageName,
'elm-review-package-tests'
);
FS.mkdirpSync(packageTests);
fsExtra.copySync(
path.join(__dirname, '../new-package/elm-review-package-tests/'),
FS.mkdirpSync(path.join(packageTests, 'helpers'));
await FS.copyFiles(
path.join(__dirname, '../new-package/elm-review-package-tests'),
packageTests,
{
overwrite: true
}
[
'check-previews-compile.js',
'check-examples-were-updated.js',
'helpers/ansi.js',
'helpers/find-configurations.js'
]
);

Spinner.succeed();
Expand Down
62 changes: 0 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -83,7 +83,6 @@
"fastest-levenshtein": "^1.0.16",
"find-up": "^4.1.0",
"folder-hash": "^3.3.0",
"fs-extra": "^9.0.0",
"glob": "^7.1.4",
"got": "^11.8.5",
"graceful-fs": "^4.2.11",
Expand Down