From 62bf52c86cddb0d7822a5bb04f0f95053beb094b Mon Sep 17 00:00:00 2001 From: Eli <88557639+lishaduck@users.noreply.github.com> Date: Sat, 9 Nov 2024 21:49:36 -0600 Subject: [PATCH] chore: remove fs-extra dependency Manual rebase of #147. Co-authored-by: Jeroen Engels --- lib/fs-wrapper.js | 19 +++++ lib/init.js | 3 +- lib/new-package.js | 43 ++++++----- .../update-examples-from-preview.js | 7 +- package-lock.json | 72 ------------------- package.json | 1 - .../update-examples-from-preview.js | 7 +- .../package.json | 8 ++- .../update-examples-from-preview.js | 7 +- .../elm-review-something/package.json | 8 ++- 10 files changed, 76 insertions(+), 99 deletions(-) diff --git a/lib/fs-wrapper.js b/lib/fs-wrapper.js index e2444b8c1..b22179065 100644 --- a/lib/fs-wrapper.js +++ b/lib/fs-wrapper.js @@ -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; @@ -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} + */ +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, @@ -106,6 +122,9 @@ module.exports = { mkdirp, mkdirpSync, + // TODO(@lishaduck) [engine:node@>=16.7.0]: Use native `cp`. + copyFiles, + remove, readdir: fsp.readdir, diff --git a/lib/init.js b/lib/init.js index f173d1f6c..878d0f204 100644 --- a/lib/init.js +++ b/lib/init.js @@ -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'); @@ -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') ); diff --git a/lib/new-package.js b/lib/new-package.js index 8fef31728..ca771c04b 100644 --- a/lib/new-package.js +++ b/lib/new-package.js @@ -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'); @@ -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( @@ -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, @@ -334,12 +338,10 @@ 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( @@ -347,13 +349,16 @@ ElmjutsuDumMyM0DuL3.elm 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( @@ -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', @@ -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' diff --git a/new-package/maintenance/update-examples-from-preview.js b/new-package/maintenance/update-examples-from-preview.js index 7c229ef0c..ccf6bcb55 100755 --- a/new-package/maintenance/update-examples-from-preview.js +++ b/new-package/maintenance/update-examples-from-preview.js @@ -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'); diff --git a/package-lock.json b/package-lock.json index 5bdb2c2ac..3164f262b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,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", @@ -2664,14 +2663,6 @@ "node": ">=8" } }, - "node_modules/at-least-node": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", - "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==", - "engines": { - "node": ">= 4.0.0" - } - }, "node_modules/available-typed-arrays": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", @@ -4753,20 +4744,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/fs-extra": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", - "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", - "dependencies": { - "at-least-node": "^1.0.0", - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/fs-minipass": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-3.0.3.tgz", @@ -6775,17 +6752,6 @@ "node": ">=6" } }, - "node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, "node_modules/jsonp": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/jsonp/-/jsonp-0.2.1.tgz", @@ -10472,14 +10438,6 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, - "node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/update-browserslist-db": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.1.tgz", @@ -12796,11 +12754,6 @@ "integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==", "dev": true }, - "at-least-node": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", - "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==" - }, "available-typed-arrays": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", @@ -14320,17 +14273,6 @@ "signal-exit": "^4.0.1" } }, - "fs-extra": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", - "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", - "requires": { - "at-least-node": "^1.0.0", - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - } - }, "fs-minipass": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-3.0.3.tgz", @@ -15775,15 +15717,6 @@ "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "dev": true }, - "jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "requires": { - "graceful-fs": "^4.1.6", - "universalify": "^2.0.0" - } - }, "jsonp": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/jsonp/-/jsonp-0.2.1.tgz", @@ -18520,11 +18453,6 @@ "imurmurhash": "^0.1.4" } }, - "universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==" - }, "update-browserslist-db": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.1.tgz", diff --git a/package.json b/package.json index 3fbcc3719..4b3cc753e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/run-snapshots/elm-review-something-for-new-rule/maintenance/update-examples-from-preview.js b/test/run-snapshots/elm-review-something-for-new-rule/maintenance/update-examples-from-preview.js index 7c229ef0c..ccf6bcb55 100755 --- a/test/run-snapshots/elm-review-something-for-new-rule/maintenance/update-examples-from-preview.js +++ b/test/run-snapshots/elm-review-something-for-new-rule/maintenance/update-examples-from-preview.js @@ -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'); diff --git a/test/run-snapshots/elm-review-something-for-new-rule/package.json b/test/run-snapshots/elm-review-something-for-new-rule/package.json index f3024db52..fb565f6e8 100644 --- a/test/run-snapshots/elm-review-something-for-new-rule/package.json +++ b/test/run-snapshots/elm-review-something-for-new-rule/package.json @@ -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", @@ -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" diff --git a/test/run-snapshots/elm-review-something/maintenance/update-examples-from-preview.js b/test/run-snapshots/elm-review-something/maintenance/update-examples-from-preview.js index 7c229ef0c..ccf6bcb55 100755 --- a/test/run-snapshots/elm-review-something/maintenance/update-examples-from-preview.js +++ b/test/run-snapshots/elm-review-something/maintenance/update-examples-from-preview.js @@ -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'); diff --git a/test/run-snapshots/elm-review-something/package.json b/test/run-snapshots/elm-review-something/package.json index f3024db52..fb565f6e8 100644 --- a/test/run-snapshots/elm-review-something/package.json +++ b/test/run-snapshots/elm-review-something/package.json @@ -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", @@ -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"