From 6535caab7d709d9d65c1ca1efc655798864692bb Mon Sep 17 00:00:00 2001 From: Romain Date: Sat, 16 Dec 2023 09:28:19 +0000 Subject: [PATCH] chore: replace fs-extra by fs when possible --- bin/thumbsup.js | 4 ++-- src/components/index/index.js | 4 ++-- src/steps/actions.js | 4 ++-- src/steps/step-process.js | 4 ++-- src/website/theme.js | 9 +++++---- test/fixtures.js | 5 +++-- test/steps/actions.spec.js | 8 ++++---- test/themes/theme.spec.js | 2 +- 8 files changed, 21 insertions(+), 19 deletions(-) diff --git a/bin/thumbsup.js b/bin/thumbsup.js index 3553a48..182f770 100755 --- a/bin/thumbsup.js +++ b/bin/thumbsup.js @@ -1,6 +1,6 @@ #!/usr/bin/env node -const fs = require('fs-extra') +const fs = require('node:fs') const moment = require('moment') const dependencies = require('../src/cli/dependencies') const messages = require('../src/cli/messages') @@ -13,7 +13,7 @@ const args = process.argv.slice(2) const opts = options.get(args) // Only require the index after logging options have been set -fs.mkdirpSync(opts.output) +fs.mkdirSync(opts.output, { recursive: true }) require('./log').init(opts.log, opts.logFile) const index = require('../src/index') diff --git a/src/components/index/index.js b/src/components/index/index.js index 0f530b4..d6e6d65 100644 --- a/src/components/index/index.js +++ b/src/components/index/index.js @@ -1,8 +1,8 @@ const EventEmitter = require('node:events') +const fs = require('node:fs') const path = require('node:path') const _ = require('lodash') const Database = require('better-sqlite3') -const fs = require('fs-extra') const moment = require('moment') const delta = require('./delta') const exiftool = require('../exiftool/parallel') @@ -13,7 +13,7 @@ const EXIF_DATE_FORMAT = 'YYYY:MM:DD HH:mm:ssZ' class Index { constructor (indexPath) { // create the database if it doesn't exist - fs.mkdirpSync(path.dirname(indexPath)) + fs.mkdirSync(path.dirname(indexPath), { recursive: true }) this.db = new Database(indexPath, {}) this.db.exec('CREATE TABLE IF NOT EXISTS files (path TEXT PRIMARY KEY, timestamp INTEGER, metadata BLOB)') } diff --git a/src/steps/actions.js b/src/steps/actions.js index 673d719..cae703b 100644 --- a/src/steps/actions.js +++ b/src/steps/actions.js @@ -1,5 +1,5 @@ +const fs = require('node:fs') const downsize = require('thumbsup-downsize') -const fs = require('fs-extra') exports.createMap = function (opts) { const thumbSize = opts.thumbSize || 120 @@ -37,7 +37,7 @@ exports.createMap = function (opts) { hwaccel: opts.videoHwaccel } return { - 'fs:copy': (task, done) => fs.copy(task.src, task.dest, done), + 'fs:copy': (task, done) => fs.copyFile(task.src, task.dest, done), 'fs:symlink': (task, done) => fs.symlink(task.src, task.dest, done), 'photo:thumbnail': (task, done) => downsize.image(task.src, task.dest, thumbnail, done), 'photo:small': (task, done) => downsize.image(task.src, task.dest, small, done), diff --git a/src/steps/step-process.js b/src/steps/step-process.js index 1ae857e..b839ea6 100644 --- a/src/steps/step-process.js +++ b/src/steps/step-process.js @@ -1,5 +1,5 @@ const path = require('node:path') -const fs = require('fs-extra') +const fs = require('node:fs') const debug = require('debug')('thumbsup:debug') const error = require('debug')('thumbsup:error') const info = require('debug')('thumbsup:info') @@ -46,7 +46,7 @@ exports.create = function (files, opts, problems) { dest, rel: f.output[out].rel, action: (done) => { - fs.mkdirsSync(path.dirname(dest)) + fs.mkdirSync(path.dirname(dest), { recursive: true }) debug(`${f.output[out].rel} from ${src} to ${dest}`) return action({ src, dest }, err => { if (err) { diff --git a/src/website/theme.js b/src/website/theme.js index dadddf4..3eaf9c6 100644 --- a/src/website/theme.js +++ b/src/website/theme.js @@ -1,7 +1,8 @@ +const fs = require('node:fs') const path = require('node:path') const async = require('async') const debug = require('debug')('thumbsup:debug') -const fs = require('fs-extra') +const fsextra = require('fs-extra') const handlebars = require('handlebars') const less = require('less') @@ -62,7 +63,7 @@ class Theme { const fullPath = path.join(this.dest, targetPath) debug(`Theme rendering ${targetPath}`) const contents = this.template(data) - fs.mkdirpSync(path.dirname(fullPath)) + fs.mkdirSync(path.dirname(fullPath), { recursive: true }) fs.writeFile(fullPath, contents, next) } @@ -114,7 +115,7 @@ class Theme { if (err) return done(err) const filename = this.opts.stylesheetName || 'theme.css' const dest = path.join(this.dest, 'public', filename) - fs.mkdirpSync(path.join(this.dest, 'public')) + fs.mkdirSync(path.join(this.dest, 'public'), { recursive: true }) fs.writeFile(dest, output.css, done) }) } @@ -137,7 +138,7 @@ class Theme { // copy all files in the folder const src = path.join(this.dir, 'public') const dest = path.join(this.dest, 'public') - fs.copy(src, dest, done) + fsextra.copy(src, dest, done) } } diff --git a/test/fixtures.js b/test/fixtures.js index e869365..bced5ee 100644 --- a/test/fixtures.js +++ b/test/fixtures.js @@ -1,6 +1,6 @@ +const fs = require('node:fs') const path = require('node:path') const _ = require('lodash') -const fs = require('fs-extra') const moment = require('moment') const tmp = require('tmp') const File = require('../src/model/file') @@ -66,7 +66,8 @@ exports.fromDisk = function (filename) { exports.createTempStructure = function (files) { const tmpdir = tmp.dirSync({ unsafeCleanup: true }).name _.each(files, (content, filepath) => { - fs.ensureFileSync(`${tmpdir}/${filepath}`) + const folder = path.dirname(`${tmpdir}/${filepath}`) + fs.mkdirSync(folder, { recursive: true }) fs.writeFileSync(`${tmpdir}/${filepath}`, content) }) return tmpdir diff --git a/test/steps/actions.spec.js b/test/steps/actions.spec.js index 5f01f77..9e3df80 100644 --- a/test/steps/actions.spec.js +++ b/test/steps/actions.spec.js @@ -1,5 +1,5 @@ +const fs = require('node:fs') const downsize = require('thumbsup-downsize') -const fs = require('fs-extra') const should = require('should/as-function') const sinon = require('sinon') const actions = require('../../src/steps/actions') @@ -11,7 +11,7 @@ const ANY_TASK = { describe('actions', () => { beforeEach(() => { - sinon.stub(fs, 'copy').yields(null) + sinon.stub(fs, 'copyFile').yields(null) sinon.stub(fs, 'symlink').yields(null) sinon.stub(downsize, 'image').yields(null) sinon.stub(downsize, 'video').yields(null) @@ -19,7 +19,7 @@ describe('actions', () => { }) afterEach(() => { - fs.copy.restore() + fs.copyFile.restore() fs.symlink.restore() downsize.image.restore() downsize.video.restore() @@ -31,7 +31,7 @@ describe('actions', () => { const action = map['fs:copy'] action(ANY_TASK, err => { should(err).eql(null) - sinon.assert.calledWith(fs.copy, + sinon.assert.calledWith(fs.copyFile, ANY_TASK.src, ANY_TASK.dest, sinon.match.func diff --git a/test/themes/theme.spec.js b/test/themes/theme.spec.js index 5e002db..0b1d133 100644 --- a/test/themes/theme.spec.js +++ b/test/themes/theme.spec.js @@ -1,5 +1,5 @@ const path = require('node:path') -const fs = require('fs-extra') +const fs = require('node:fs') const should = require('should/as-function') const fixtures = require('../fixtures') const Theme = require('../../src/website/theme')