diff --git a/lib/plugins/save-resource-to-fs-plugin.js b/lib/plugins/save-resource-to-fs-plugin.js index b5cfab02..c66b18f5 100644 --- a/lib/plugins/save-resource-to-fs-plugin.js +++ b/lib/plugins/save-resource-to-fs-plugin.js @@ -1,5 +1,6 @@ import path from 'path'; -import fs from 'fs-extra'; +import fs from 'fs'; +import { outputFile } from '../utils/fs.js'; class SaveResourceToFileSystemPlugin { apply (registerAction) { @@ -20,13 +21,13 @@ class SaveResourceToFileSystemPlugin { registerAction('saveResource', async ({resource}) => { const filename = path.join(absoluteDirectoryPath, resource.getFilename()); const text = resource.getText(); - await fs.outputFile(filename, text, { encoding: resource.getEncoding() }); + await outputFile(filename, text, resource.getEncoding()); loadedResources.push(resource); }); registerAction('error', async () => { if (loadedResources.length > 0) { - await fs.remove(absoluteDirectoryPath); + fs.rmSync(absoluteDirectoryPath, {force: true, recursive: true}); } }); } diff --git a/lib/utils/fs.js b/lib/utils/fs.js new file mode 100644 index 00000000..38618024 --- /dev/null +++ b/lib/utils/fs.js @@ -0,0 +1,13 @@ +import path from 'path'; +import fs from 'fs/promises'; + +async function outputFile (file, data, encoding) { + const dir = path.dirname(file); + await fs.mkdir(dir, { recursive: true}); + + return fs.writeFile(file, data, { encoding: encoding }); +} + +export { + outputFile +}; diff --git a/package.json b/package.json index 2c58b324..9fb10e18 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,6 @@ "cheerio": "^1.1.2", "css-url-parser": "^1.0.0", "debug": "^4.3.1", - "fs-extra": "^11.1.0", "got": "^14.4.7", "normalize-url": "^8.0.0", "p-queue": "^9.0.0", @@ -50,6 +49,7 @@ "devDependencies": { "c8": "^10.0.0", "eslint": "^8.5.0", + "fs-extra": "^11.1.0", "mocha": "^11.0.1", "nock": "^14.0.0", "should": "^13.2.3",