diff --git a/lib/content/read.js b/lib/content/read.js index 5f6192c3..98007081 100644 --- a/lib/content/read.js +++ b/lib/content/read.js @@ -1,6 +1,6 @@ 'use strict' -const fs = require('fs/promises') +const fs = require('fs-extra') const fsm = require('fs-minipass') const ssri = require('ssri') const contentPath = require('./path') diff --git a/lib/content/rm.js b/lib/content/rm.js index ce58d679..c583ef02 100644 --- a/lib/content/rm.js +++ b/lib/content/rm.js @@ -1,6 +1,6 @@ 'use strict' -const fs = require('fs/promises') +const fs = require('fs-extra') const contentPath = require('./path') const { hasContent } = require('./read') diff --git a/lib/content/write.js b/lib/content/write.js index e7187abc..2e22434e 100644 --- a/lib/content/write.js +++ b/lib/content/write.js @@ -3,7 +3,7 @@ const events = require('events') const contentPath = require('./path') -const fs = require('fs/promises') +const fs = require('fs-extra') const { moveFile } = require('@npmcli/fs') const { Minipass } = require('minipass') const Pipeline = require('minipass-pipeline') diff --git a/lib/entry-index.js b/lib/entry-index.js index 0e09b108..a5c7a2a0 100644 --- a/lib/entry-index.js +++ b/lib/entry-index.js @@ -8,7 +8,7 @@ const { readdir, rm, writeFile, -} = require('fs/promises') +} = require('fs-extra') const { Minipass } = require('minipass') const path = require('path') const ssri = require('ssri') diff --git a/lib/rm.js b/lib/rm.js index a94760c7..d73dda42 100644 --- a/lib/rm.js +++ b/lib/rm.js @@ -1,6 +1,6 @@ 'use strict' -const { rm } = require('fs/promises') +const { rm } = require('fs-extra') const glob = require('./util/glob.js') const index = require('./entry-index') const memo = require('./memoization') diff --git a/lib/util/tmp.js b/lib/util/tmp.js index 0bf53021..98d1bb37 100644 --- a/lib/util/tmp.js +++ b/lib/util/tmp.js @@ -1,7 +1,7 @@ 'use strict' const { withTempDir } = require('@npmcli/fs') -const fs = require('fs/promises') +const fs = require('fs-extra') const path = require('path') module.exports.mkdir = mktmpdir diff --git a/lib/verify.js b/lib/verify.js index dcff3aa7..9176a39c 100644 --- a/lib/verify.js +++ b/lib/verify.js @@ -7,7 +7,7 @@ const { stat, truncate, writeFile, -} = require('fs/promises') +} = require('fs-extra') const contentPath = require('./content/path') const fsm = require('fs-minipass') const glob = require('./util/glob.js') diff --git a/package.json b/package.json index 15432301..a4a1cec0 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "license": "ISC", "dependencies": { "@npmcli/fs": "^4.0.0", + "fs-extra": "^11.2.0", "fs-minipass": "^3.0.0", "glob": "^10.2.2", "lru-cache": "^10.0.1", diff --git a/test/content/read.js b/test/content/read.js index 5b103f04..29f8003b 100644 --- a/test/content/read.js +++ b/test/content/read.js @@ -24,7 +24,7 @@ const getReadStatFailure = (t, err) => getRead(t, { throw err }, }, - 'fs/promises': { + 'fs-extra': { ...fs.promises, stat: async () => { throw err @@ -219,7 +219,7 @@ t.test('read: returns only first result if other hashes fails', function (t) { t.test('read: opening large files', function (t) { const CACHE = t.testdir() const mockedRead = getRead(t, { - 'fs/promises': { + 'fs-extra': { ...fs.promises, stat: async () => { return { size: Number.MAX_SAFE_INTEGER } diff --git a/test/entry-index.insert.js b/test/entry-index.insert.js index fb548206..0fc8e20e 100644 --- a/test/entry-index.insert.js +++ b/test/entry-index.insert.js @@ -224,7 +224,7 @@ t.test('ENOENT from appendFile is ignored', async (t) => { const cache = t.testdir() const indexMocked = t.mock('../lib/entry-index.js', { - 'fs/promises': { + 'fs-extra': { ...fs, appendFile: async () => { throw Object.assign(new Error('fake enoent'), { code: 'ENOENT' }) @@ -239,7 +239,7 @@ t.test('generic error from appendFile rejects', async (t) => { const cache = t.testdir() const indexMocked = t.mock('../lib/entry-index.js', { - 'fs/promises': { + 'fs-extra': { ...fs, appendFile: async () => { throw Object.assign(new Error('fake eperm'), { code: 'EPERM' }) diff --git a/test/entry-index.js b/test/entry-index.js index 07a5fab9..cda125c9 100644 --- a/test/entry-index.js +++ b/test/entry-index.js @@ -17,7 +17,7 @@ missingFileError.code = 'ENOENT' const getEntryIndex = (t, opts) => t.mock('../lib/entry-index', opts) const getEntryIndexReadFileFailure = (t, err) => getEntryIndex(t, { - 'fs/promises': { + 'fs-extra': { ...fs.promises, readFile: async () => { throw err @@ -233,7 +233,7 @@ t.test('lsStream: missing files error', async (t) => { t.test('lsStream: unknown error reading dirs', (t) => { const cache = t.testdir(cacheContent) const { lsStream } = getEntryIndex(t, { - 'fs/promises': { + 'fs-extra': { ...fs.promises, readdir: async () => { throw genericError diff --git a/test/verify.js b/test/verify.js index 72627e3e..ef5def65 100644 --- a/test/verify.js +++ b/test/verify.js @@ -216,7 +216,7 @@ t.test('missing file error when validating cache content', async t => { const missingFileError = new Error('ENOENT') missingFileError.code = 'ENOENT' const mockVerify = getVerify(t, { - 'fs/promises': Object.assign({}, fs, { + 'fs-extra': Object.assign({}, fs, { stat: async () => { throw missingFileError }, @@ -238,7 +238,7 @@ t.test('missing file error when validating cache content', async t => { t.test('unknown error when validating content', async t => { const mockVerify = getVerify(t, { - 'fs/promises': Object.assign({}, fs, { + 'fs-extra': Object.assign({}, fs, { stat: async () => { throw genericError }, @@ -274,7 +274,7 @@ t.test('unknown error when rebuilding bucket', async t => { // shouldFail controls the right time to mock the error let shouldFail = false const mockVerify = getVerify(t, { - 'fs/promises': Object.assign({}, fs, { + 'fs-extra': Object.assign({}, fs, { stat: async (path) => { if (shouldFail) { throw genericError