Skip to content

Commit

Permalink
chore: remove fs-extra dependency
Browse files Browse the repository at this point in the history
Manual rebase of #147.

Co-authored-by: Jeroen Engels <[email protected]>
  • Loading branch information
lishaduck and jfmengels committed Nov 10, 2024
1 parent 692b52e commit 62bf52c
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 99 deletions.
19 changes: 19 additions & 0 deletions lib/fs-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @import {Replacer, Reviver} from './types/json';
* @import {Path} from './types/path';
*/
const path = require('node:path');
const fs = require('graceful-fs');
const fsp = fs.promises;

Expand Down Expand Up @@ -95,6 +96,21 @@ async function remove(file) {
);
}

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

await Promise.all(promises);
}

module.exports = {
readFile,
readJsonFile,
Expand All @@ -106,6 +122,9 @@ module.exports = {
mkdirp,
mkdirpSync,

// TODO(@lishaduck) [engine:node@>=16.7.0]: Use native `cp`.
copyFiles,

remove,

readdir: fsp.readdir,
Expand Down
3 changes: 1 addition & 2 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
const path = require('node:path');
const fs = require('graceful-fs');
// TODO(@lishaduck) [engine:node@>=16.7.0]: Use native `cp`.
const fsExtra = require('fs-extra');
const chalk = require('chalk');
const prompts = require('prompts');
const FS = require('./fs-wrapper');
Expand Down Expand Up @@ -197,7 +196,7 @@ async function createElmJson(options, directory) {
* @returns {void}
*/
function createReviewConfig(directory, template) {
fsExtra.copyFileSync(
fs.copyFileSync(
path.join(__dirname, '../init-templates/', template),
path.join(directory, 'ReviewConfig.elm')
);
Expand Down
43 changes: 26 additions & 17 deletions lib/new-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
const childProcess = require('node:child_process');
const path = require('node:path');
const chalk = require('chalk');
// TODO(@lishaduck) [engine:node@>=16.7.0]: Use native `cp`.
const fsExtra = require('fs-extra');
const prompts = require('prompts');
const ErrorMessage = require('./error-message');
const FS = require('./fs-wrapper');
Expand Down Expand Up @@ -293,10 +291,15 @@ ElmjutsuDumMyM0DuL3.elm
);

Spinner.succeedAndNowDo('Adding GitHub Actions');
await fsExtra.copy(
const githubDestFiles = path.join(dir, '.github/');
await Promise.all([
FS.mkdirp(path.join(githubDestFiles, 'ISSUE_TEMPLATE')),
FS.mkdirp(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 All @@ -305,6 +308,7 @@ ElmjutsuDumMyM0DuL3.elm
const licenseArgs = options.forTests ? '--name "Test User" --year 2020' : '';
try {
childProcess.execSync(
// TODO(@lishaduck): Evaluate calling the API instead.
`npx license ${license} --projectName "${authorName}/${packageName}" ${licenseArgs}`,
{
cwd: dir,
Expand Down Expand Up @@ -334,26 +338,27 @@ ElmjutsuDumMyM0DuL3.elm
Spinner.succeedAndNowDo('Adding maintenance scripts');
const maintenancePath = path.join(process.cwd(), packageName, 'maintenance');
await FS.mkdirp(maintenancePath);
await fsExtra.copy(
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'
);
await FS.mkdirp(packageTests);
await fsExtra.copy(
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'
]
);

const checkPreviewsCompile = path.join(
Expand Down Expand Up @@ -441,6 +446,7 @@ elm-review --template ${authorName}/${packageName}/example
function packageJson(options, packageName) {
return {
name: packageName,
private: true,
scripts: {
test: 'npm-run-all --print-name --silent --sequential test:make test:format test:run test:review test:package',
'test:make': 'elm make --docs=docs.json',
Expand All @@ -455,11 +461,14 @@ function packageJson(options, packageName) {
'update-examples': 'node maintenance/update-examples-from-preview.js',
postinstall: 'elm-tooling install'
},
dependencies: {
engines: {
node: '>=14.21.3'
},
devDependencies: {
'elm-doc-preview': '^5.0.5',
'elm-review': `^${options.packageJsonVersion}`,
'elm-test': '^0.19.1-revision10',
'elm-tooling': '^1.13.1',
'elm-tooling': '^1.15.1',
'fs-extra': '^9.0.0',
glob: '^9.3.1',
'npm-run-all': '^4.1.5'
Expand Down
7 changes: 6 additions & 1 deletion new-package/maintenance/update-examples-from-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ function copyPreviewToExample(pathToPreviewFolder) {
/preview/g,
'example'
);
fs.removeSync(pathToExampleFolder);

fs.rmSync(pathToExampleFolder, {
recursive: true,
force: true,
maxRetries: 10
});
fs.copySync(pathToPreviewFolder, pathToExampleFolder, {overwrite: true});

const pathToElmJson = path.resolve(pathToExampleFolder, 'elm.json');
Expand Down
72 changes: 0 additions & 72 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
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"fastest-levenshtein": "^1.0.16",
"find-up": "^4.1.0 || ^5.0.0",
"folder-hash": "^3.3.0",
"fs-extra": "^9.0.0",
"glob": "^10.2.6",
"got": "^11.8.5",
"graceful-fs": "^4.2.11",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ function copyPreviewToExample(pathToPreviewFolder) {
/preview/g,
'example'
);
fs.removeSync(pathToExampleFolder);

fs.rmSync(pathToExampleFolder, {
recursive: true,
force: true,
maxRetries: 10
});
fs.copySync(pathToPreviewFolder, pathToExampleFolder, {overwrite: true});

const pathToElmJson = path.resolve(pathToExampleFolder, 'elm.json');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "elm-review-something",
"private": true,
"scripts": {
"test": "npm-run-all --print-name --silent --sequential test:make test:format test:run test:review test:package",
"test:make": "elm make --docs=docs.json",
Expand All @@ -13,11 +14,14 @@
"update-examples": "node maintenance/update-examples-from-preview.js",
"postinstall": "elm-tooling install"
},
"dependencies": {
"engines": {
"node": ">=14.21.3"
},
"devDependencies": {
"elm-doc-preview": "^5.0.5",
"elm-review": "^2.12.0",
"elm-test": "^0.19.1-revision10",
"elm-tooling": "^1.13.1",
"elm-tooling": "^1.15.1",
"fs-extra": "^9.0.0",
"glob": "^9.3.1",
"npm-run-all": "^4.1.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ function copyPreviewToExample(pathToPreviewFolder) {
/preview/g,
'example'
);
fs.removeSync(pathToExampleFolder);

fs.rmSync(pathToExampleFolder, {
recursive: true,
force: true,
maxRetries: 10
});
fs.copySync(pathToPreviewFolder, pathToExampleFolder, {overwrite: true});

const pathToElmJson = path.resolve(pathToExampleFolder, 'elm.json');
Expand Down
8 changes: 6 additions & 2 deletions test/run-snapshots/elm-review-something/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "elm-review-something",
"private": true,
"scripts": {
"test": "npm-run-all --print-name --silent --sequential test:make test:format test:run test:review test:package",
"test:make": "elm make --docs=docs.json",
Expand All @@ -13,11 +14,14 @@
"update-examples": "node maintenance/update-examples-from-preview.js",
"postinstall": "elm-tooling install"
},
"dependencies": {
"engines": {
"node": ">=14.21.3"
},
"devDependencies": {
"elm-doc-preview": "^5.0.5",
"elm-review": "^2.12.0",
"elm-test": "^0.19.1-revision10",
"elm-tooling": "^1.13.1",
"elm-tooling": "^1.15.1",
"fs-extra": "^9.0.0",
"glob": "^9.3.1",
"npm-run-all": "^4.1.5"
Expand Down

0 comments on commit 62bf52c

Please sign in to comment.