Remove fs-extra and klaw (#882)

These packages are obsoleted by the promises API to the built-in Node fs
module.  The fs-extra package is also causing problems with broken APIs
that don't behave the same as Node's fs module, and throwing errors
without code properties on them.
This commit is contained in:
Hornwitser authored and GitHub committed 2026-04-09 22:53:13 +02:00
1 parent 130dca4261
commit 2e48b728dd
74 files changed
+570 -529

No files matched your search

+5 -5
View File
@@ -1,7 +1,7 @@
/* eslint-disable node/no-sync */
"use strict";
const assert = require("assert").strict;
const fs = require("fs-extra");
const fs = require("node:fs/promises");
const path = require("path");
const { LockFile } = require("@clusterio/lib");
@@ -15,7 +15,7 @@ describe("class LockFile", function () {
let lock;
before(async function () {
await fs.ensureDir(baseDir);
await fs.mkdir(baseDir, { recursive: true });
});
beforeEach(function() {
@@ -30,7 +30,7 @@ describe("class LockFile", function () {
describe("acquire()", function () {
it("should create the lock file when acquiring", async function () {
await lock.acquire();
assert.ok(fs.existsSync(filePath));
await fs.access(filePath);
});
it("should throw LockFileBusyError if called when not idle", async function () {
@@ -41,7 +41,7 @@ describe("class LockFile", function () {
it("should remove stale lock file and acquire it", async function () {
await fs.writeFile(filePath, "999999\n"); // stale lock
await lock.acquire();
assert.ok(fs.existsSync(filePath));
await fs.access(filePath);
});
it("should throw if existing lock file is not stale", async function () {
@@ -54,7 +54,7 @@ describe("class LockFile", function () {
it("should remove the lock file when releasing", async function () {
await lock.acquire();
await lock.release();
assert.ok(!fs.existsSync(filePath));
await assert.rejects(fs.access(filePath));
});
it("should throw LockFileBusyError if called when not acquired", async function () {
+14 -11
View File
@@ -1,7 +1,7 @@
"use strict";
const assert = require("assert").strict;
const path = require("path");
const fs = require("fs-extra");
const fs = require("node:fs/promises");
const stream = require("node:stream");
const JSZip = require("jszip"); // Added for creating mock zips
@@ -44,7 +44,7 @@ async function waitBriefly() {
describe("lib/ModStore", function () {
before(async function () {
await fs.ensureDir(MODS_DIR);
await fs.mkdir(MODS_DIR, { recursive: true });
});
after(function() {
@@ -59,7 +59,8 @@ describe("lib/ModStore", function () {
});
afterEach(async function () {
await fs.emptyDir(MODS_DIR);
await fs.rm(MODS_DIR, { force: true, recursive: true, maxRetries: 10 });
await fs.mkdir(MODS_DIR, { recursive: true });
});
describe("constructor", function () {
@@ -120,7 +121,7 @@ describe("lib/ModStore", function () {
// Add other file types and directories
await fs.writeFile(path.join(MODS_DIR, "some-text.txt"), "hello");
await fs.ensureDir(path.join(MODS_DIR, "a-directory"));
await fs.mkdir(path.join(MODS_DIR, "a-directory"), { recursive: true });
await fs.writeFile(path.join(MODS_DIR, "archive.tar.gz"), "not a zip");
await createMockModZip(path.join(MODS_DIR, "temp_file.tmp.zip"), "temp", "1.0.0"); // Should ignore .tmp.zip
@@ -139,7 +140,7 @@ describe("lib/ModStore", function () {
await createMockModZip(modPath, modName, modVersion);
let modStore = await ModStore.fromDirectory(MODS_DIR);
assert.equal(modStore.files.size, 1);
assert(await fs.pathExists(CACHE_FILE), "Cache file should exist");
await assert.doesNotReject(fs.access(CACHE_FILE), "Cache file should exist");
// Wait and recreate the file to update mtime
await waitBriefly();
@@ -197,7 +198,9 @@ describe("lib/ModStore", function () {
beforeEach(async function () {
// Start with an empty store for download tests
await fs.emptyDir(MODS_DIR); // Clear any existing files in the temp dir
// Clear any existing files in the temp dir
await fs.rm(MODS_DIR, { force: true, recursive: true, maxRetries: 10 });
await fs.mkdir(MODS_DIR, { recursive: true });
modStore = await ModStore.fromDirectory(MODS_DIR); // Initialize using fromDirectory
// Restore fetch before each test in this suite to avoid pollution
@@ -269,7 +272,7 @@ describe("lib/ModStore", function () {
assert.equal(modStore.files.size, 1, "Should have 1 mod after download");
const filename = "download-mod-1_1.1.0.zip";
assert(modStore.files.has(filename), `Mod ${filename} should be in the store`);
assert(await fs.pathExists(path.join(MODS_DIR, filename)), `File ${filename} should exist`);
await assert.doesNotReject(fs.access(path.join(MODS_DIR, filename)), `File ${filename} should exist`);
const modInfo = modStore.files.get(filename);
assert(modInfo instanceof ModInfo);
assert.equal(modInfo.name, "download-mod-1");
@@ -290,8 +293,8 @@ describe("lib/ModStore", function () {
assert.equal(modStore.files.size, 2);
assert(modStore.files.has("multi-mod-a_1.0.0.zip"));
assert(modStore.files.has("multi-mod-b_2.0.0.zip"));
assert(await fs.pathExists(path.join(MODS_DIR, "multi-mod-a_1.0.0.zip")));
assert(await fs.pathExists(path.join(MODS_DIR, "multi-mod-b_2.0.0.zip")));
await fs.access(path.join(MODS_DIR, "multi-mod-a_1.0.0.zip"));
await fs.access(path.join(MODS_DIR, "multi-mod-b_2.0.0.zip"));
});
it("should throw when no releases available", async function () {
const modsToDownload = [{ name: "download-mod-1", version: ModVersionEquality.fromString("1.1.0") }];
@@ -803,12 +806,12 @@ describe("lib/ModStore", function () {
describe("deleteFile", function () {
it("should delete an existing file from store and filesystem", async function () {
assert(modStore.files.has(testMod1Filename), "Mod should exist before deletion");
assert(await fs.pathExists(testMod1Path), "Mod file should exist before deletion");
await assert.doesNotReject(fs.access(testMod1Path), "Mod file should exist before deletion");
await modStore.deleteFile(testMod1Filename);
assert(!modStore.files.has(testMod1Filename), "Mod should not exist in store after deletion");
assert(!(await fs.pathExists(testMod1Path)), "Mod file should not exist after deletion");
await assert.rejects(fs.access(testMod1Path), "Mod file should not exist after deletion");
});
it("should emit 'change' event with isDeleted flag when deleting", async function () {
+15 -16
View File
@@ -1,7 +1,6 @@
"use strict";
const lib = require("@clusterio/lib");
const { optional } = require("@clusterio/lib/dist/node/src/config/validators");
const fs = require("fs-extra");
const fs = require("node:fs/promises");
const path = require("path");
const assert = require("assert").strict;
const CA = lib.ConfigAccess;
@@ -289,10 +288,10 @@ describe("lib/config/classes", function() {
await assert.rejects(TestConfig.fromFile("local", filepath));
});
it("should load defaults for missing fields", async function() {
await fs.writeJSON(filepath, {
await fs.writeFile(filepath, JSON.stringify({
"alpha.foo": "a",
"test.enum": "a",
});
}));
const testInstance = await TestConfig.fromFile("local", filepath);
assert.equal(testInstance.get("alpha.foo"), "a");
assert.deepEqual(testInstance.get("beta.bar"), {});
@@ -302,14 +301,14 @@ describe("lib/config/classes", function() {
assert.equal(testInstance.filepath, filepath);
});
it("should load fields", async function() {
await fs.writeJSON(filepath, {
await fs.writeFile(filepath, JSON.stringify({
"test.enum": "c",
"test.test": "blah",
"test.func": 22,
"test.bool": null,
"test.json": { valid: true },
"test.priv": "bar",
});
}));
const testInstance = await TestConfig.fromFile("local", filepath);
assert.equal(testInstance.get("test.enum"), "c");
assert.equal(testInstance.get("test.test"), "blah");
@@ -335,13 +334,13 @@ describe("lib/config/classes", function() {
"test.beta": "decay",
"test.gamma": 99,
};
await fs.writeJson(filepath, testFields);
await fs.writeFile(filepath, JSON.stringify(testFields));
const testInstance = await TestConfig.fromFile("local", filepath);
assert.deepEqual(testInstance.toJSON(), testFields);
assert.equal(testInstance.filepath, filepath);
});
it("should ignore inaccessible fields", async function() {
await fs.writeJSON(filepath, { "test.priv": "bad" });
await fs.writeFile(filepath, JSON.stringify({ "test.priv": "bad" }));
const testInstance = await TestConfig.fromFile("remote", filepath);
assert.equal(testInstance.fields["test.priv"], undefined);
assert.equal(testInstance.fields["test.func"], 42);
@@ -352,8 +351,8 @@ describe("lib/config/classes", function() {
describe(".save()", function() {
const filepath = path.join("temp", "test", "config_test.json");
beforeEach(async function() {
await fs.remove(filepath);
assert(!await fs.exists(filepath), "File was not removed");
await fs.rm(filepath, { force: true });
await assert.rejects(fs.access(filepath), "File was not removed");
});
it("should throw if there is no filepath", async function() {
const testInstance = new TestConfig("local", { "alpha.foo": "a" });
@@ -366,24 +365,24 @@ describe("lib/config/classes", function() {
it("should do nothing when not dirty", async function() {
const testInstance = new TestConfig("local", { "alpha.foo": "a" }, filepath);
await testInstance.save();
assert(!await fs.exists(filepath), "File was created");
await assert.rejects(fs.access(filepath), "File was created");
});
it("should save data to file", async function() {
const testInstance = new TestConfig("local", { "alpha.foo": "a" }, filepath);
testInstance.set("alpha.foo", "b"); // Sets the dirty flag
await testInstance.save();
const json = await fs.readJSON(filepath);
const json = JSON.parse(await fs.readFile(filepath, "utf8"));
assert.deepEqual(json, testInstance.toJSON());
});
it("should clear the dirty flag after saving", async function() {
const testInstance = new TestConfig("local", { "alpha.foo": "a" }, filepath);
testInstance.set("alpha.foo", "b"); // Sets the dirty flag
await testInstance.save();
assert(await fs.exists(filepath), "File was not created");
await fs.remove(filepath);
assert(!await fs.exists(filepath), "File was not removed");
await assert.doesNotReject(fs.access(filepath), "File was not created");
await fs.rm(filepath);
await assert.rejects(fs.access(filepath), "File was was not removed");
await testInstance.save();
assert(!await fs.exists(filepath), "File was created");
await assert.rejects(fs.access(filepath), "File was created");
});
it("should be round trip savable", async function() {
const testInstance = new TestConfig("local", {
+1 -1
View File
@@ -1,6 +1,6 @@
"use strict";
const assert = require("assert").strict;
const fs = require("fs-extra");
const fs = require("node:fs/promises");
const path = require("path");
const lib = require("@clusterio/lib");
+1 -1
View File
@@ -1,6 +1,6 @@
"use strict";
const assert = require("assert").strict;
const fs = require("fs-extra");
const fs = require("node:fs/promises");
const path = require("path");
const lib = require("@clusterio/lib");
+7 -6
View File
@@ -2,7 +2,7 @@
const events = require("events");
const assert = require("assert").strict;
const lib = require("@clusterio/lib");
const fs = require("fs-extra");
const fs = require("node:fs/promises");
const path = require("path");
class MockDatastoreProvider extends lib.DatastoreProvider {
@@ -37,7 +37,8 @@ describe("lib/datastore", function() {
const baseDir = path.join("temp", "test", "datastore");
const testFiles = path.join("test", "file");
before(async function() {
await fs.emptyDir(baseDir);
await fs.rm(baseDir, { force: true, recursive: true, maxRetries: 10 });
await fs.mkdir(baseDir, { recursive: true });
});
describe("class DatastoreProvider", function() {
@@ -107,7 +108,7 @@ describe("lib/datastore", function() {
});
beforeEach(async function() {
await fs.copy(path.join(testFiles, "json", "load_map.json"), dataPath);
await fs.copyFile(path.join(testFiles, "json", "load_map.json"), dataPath);
datastoreProvider = new lib.JsonDatastoreProvider(dataPath);
});
@@ -170,7 +171,7 @@ describe("lib/datastore", function() {
assert.equal(loadedData.size, 0);
});
it("throws for invalid file contents", async function() {
await fs.copy(path.join(testFiles, "json", "invalid.json"), dataPath);
await fs.copyFile(path.join(testFiles, "json", "invalid.json"), dataPath);
await assert.rejects(() => datastoreProvider.load(dataPath));
});
it("writes a backup if size changes after load", async function() {
@@ -201,7 +202,7 @@ describe("lib/datastore", function() {
});
beforeEach(async function() {
await fs.copy(path.join(testFiles, "json", "load_array_map.json"), dataPath);
await fs.copyFile(path.join(testFiles, "json", "load_array_map.json"), dataPath);
datastoreProvider = new lib.JsonIdDatastoreProvider(dataPath);
});
@@ -265,7 +266,7 @@ describe("lib/datastore", function() {
assert.equal(loadedData.size, 0);
});
it("throws for invalid file contents", async function() {
await fs.copy(path.join(testFiles, "json", "invalid.json"), dataPath);
await fs.copyFile(path.join(testFiles, "json", "invalid.json"), dataPath);
await assert.rejects(() => datastoreProvider.load(dataPath));
});
it("writes a backup if size changes after load", async function() {
+1 -1
View File
@@ -1,5 +1,5 @@
const assert = require("assert").strict;
const { readFile } = require("fs-extra");
const { readFile } = require("node:fs/promises");
const { fetchFactorioVersions } = require("@clusterio/lib");
const { slowTest } = require("../../integration");
+27 -25
View File
@@ -1,6 +1,6 @@
"use strict";
const assert = require("assert").strict;
const fs = require("fs-extra");
const fs = require("node:fs/promises");
const http = require("node:http");
const path = require("path");
const util = require("node:util");
@@ -10,20 +10,21 @@ const lib = require("@clusterio/lib");
describe("lib/file_ops", function() {
let baseDir = path.join("temp", "test", "file_ops");
async function setupTestingEnv() {
await fs.ensureDir(path.join(baseDir, "test", "folder"));
await fs.ensureDir(path.join(baseDir, "test", "another folder"));
await fs.remove(path.join(baseDir, "safe"));
await fs.ensureDir(path.join(baseDir, "safe"));
await fs.mkdir(path.join(baseDir, "test", "folder"), { recursive: true });
await fs.mkdir(path.join(baseDir, "test", "another folder"), { recursive: true });
await fs.rm(path.join(baseDir, "safe"), { force: true, recursive: true, maxRetries: 10 });
await fs.mkdir(path.join(baseDir, "safe"), { recursive: true });
await fs.outputFile(path.join(baseDir, "test", "file.txt"), "contents");
await fs.outputFile(path.join(baseDir, "test", "another file.txt"), "more contents");
await fs.writeFile(path.join(baseDir, "test", "file.txt"), "contents");
await fs.writeFile(path.join(baseDir, "test", "another file.txt"), "more contents");
await fs.outputFile(path.join(baseDir, "find", "file"), "contents");
await fs.outputFile(path.join(baseDir, "find", "file.txt"), "contents");
await fs.outputFile(path.join(baseDir, "find", "foo-1"), "contents");
await fs.outputFile(path.join(baseDir, "find", "foo-2"), "contents");
await fs.outputFile(path.join(baseDir, "find", "bar-1.txt"), "contents");
await fs.outputFile(path.join(baseDir, "find", "bar-2.txt"), "contents");
await fs.mkdir(path.join(baseDir, "find"), { recursive: true });
await fs.writeFile(path.join(baseDir, "find", "file"), "contents");
await fs.writeFile(path.join(baseDir, "find", "file.txt"), "contents");
await fs.writeFile(path.join(baseDir, "find", "foo-1"), "contents");
await fs.writeFile(path.join(baseDir, "find", "foo-2"), "contents");
await fs.writeFile(path.join(baseDir, "find", "bar-1.txt"), "contents");
await fs.writeFile(path.join(baseDir, "find", "bar-2.txt"), "contents");
}
before(setupTestingEnv);
@@ -90,14 +91,14 @@ describe("lib/file_ops", function() {
it("should write new target file", async function() {
let target = path.join(baseDir, "safe", "simple.txt");
await lib.safeOutputFile(target, "a text file", "utf8");
assert(!await fs.pathExists(target.replace(".txt", ".tmp.txt")), "temporary was left behind");
await assert.rejects(fs.access(target.replace(".txt", ".tmp.txt")), "temporary was left behind");
assert.equal(await fs.readFile(target, "utf8"), "a text file");
});
it("should overwrite existing target file", async function() {
let target = path.join(baseDir, "safe", "exists.txt");
await fs.outputFile(target, "previous", "utf8");
await fs.writeFile(target, "previous", "utf8");
await lib.safeOutputFile(target, "current", "utf8");
assert(!await fs.pathExists(target.replace(".txt", ".tmp.txt")), "temporary was left behind");
await assert.rejects(fs.access(target.replace(".txt", ".tmp.txt")), "temporary was left behind");
assert.equal(await fs.readFile(target, "utf8"), "current");
});
it("should handle creating file in current working directory", async function() {
@@ -228,7 +229,8 @@ describe("lib/file_ops", function() {
let server;
before(async function () {
await fs.emptyDir(downloadDir);
await fs.rm(downloadDir, { force: true, recursive: true, maxRetries: 10 });
await fs.mkdir(downloadDir, { recursive: true });
server = http.createServer();
server.unref();
server.on("request", (req, res) => {
@@ -303,7 +305,7 @@ describe("lib/file_ops", function() {
it("should throw if file exists and overwriteMode is error", async function () {
const downloadPath = path.join(downloadDir, "exists.txt");
await fs.outputFile(downloadPath, "");
await fs.writeFile(downloadPath, "");
await assert.rejects(
lib.downloadFile(new URL("/simple-file", baseUrl), downloadPath, "error"),
{ code: "EEXIST" },
@@ -322,7 +324,7 @@ describe("lib/file_ops", function() {
it("should write a new file if it exists and overwriteMode is rename", async function () {
const downloadPath = path.join(downloadDir, "exists.txt");
await fs.outputFile(downloadPath, "");
await fs.writeFile(downloadPath, "");
const newDownloadPath = await lib.downloadFile(new URL("/simple-file", baseUrl), downloadPath, "rename");
assert.equal(newDownloadPath, path.join(downloadDir, "exists-2.txt"));
const writtenContent = await fs.readFile(newDownloadPath, "utf8");
@@ -336,9 +338,9 @@ describe("lib/file_ops", function() {
path.join(downloadDir, "contended-3.txt"),
path.join(downloadDir, "contended-4.txt"),
];
await fs.outputFile(downloadPath, "");
await fs.writeFile(downloadPath, "");
for (const additionalPath of additionalPaths) {
await fs.outputFile(additionalPath, "");
await fs.writeFile(additionalPath, "");
}
const newDownloadPath = await lib.downloadFile(new URL("/simple-file", baseUrl), downloadPath, "rename");
assert.equal(newDownloadPath, path.join(downloadDir, "contended-5.txt"));
@@ -348,7 +350,7 @@ describe("lib/file_ops", function() {
it("should overwrite existing file if overwriteMode is overwrite", async function () {
const downloadPath = path.join(downloadDir, "overwrite.txt");
await fs.outputFile(downloadPath, "original content");
await fs.writeFile(downloadPath, "original content");
const newDownloadPath = await lib.downloadFile(new URL("/simple-file", baseUrl), downloadPath, "overwrite");
assert.equal(newDownloadPath, downloadPath);
const writtenContent = await fs.readFile(newDownloadPath, "utf8");
@@ -357,7 +359,7 @@ describe("lib/file_ops", function() {
it("should not overwrite existing temp files", async function () {
const tempPath = path.join(downloadDir, "temp-exists.tmp.txt");
await fs.outputFile(tempPath, "original content");
await fs.writeFile(tempPath, "original content");
const downloadPath = path.join(downloadDir, "temp-exists.txt");
await lib.downloadFile(new URL("/simple-file", baseUrl), downloadPath, "overwrite");
const writtenContent = await fs.readFile(tempPath, "utf8");
@@ -377,7 +379,7 @@ describe("lib/file_ops", function() {
const downloadSubdir = path.join(downloadDir, "subdir");
const downloadPath = path.join(downloadSubdir, "test.txt");
await fs.ensureDir(downloadSubdir);
await fs.mkdir(downloadSubdir, { recursive: true });
const [stage1, waitForStage1] = stageWaiter();
const [stage2, waitForStage2] = stageWaiter();
@@ -391,7 +393,7 @@ describe("lib/file_ops", function() {
download.catch(() => {});
await waitForStage1;
await fs.remove(downloadSubdir);
await fs.rm(downloadSubdir, { recursive: true, maxRetries: 10 });
stage2();
await assert.rejects(
+2 -2
View File
@@ -1,6 +1,6 @@
"use strict";
const assert = require("assert").strict;
const fs = require("fs");
const fs = require("node:fs/promises");
const path = require("path");
const lib = require("@clusterio/lib");
@@ -9,7 +9,7 @@ const lib = require("@clusterio/lib");
describe("lib/hash", function() {
describe("hashStream()", function() {
it("should hash a stream of bytes", async function() {
let stream = fs.createReadStream(path.join("test", "file", "hash.txt"));
let stream = (await fs.open(path.join("test", "file", "hash.txt"))).createReadStream();
let result = await lib.hashStream(stream);
assert.equal(result, "be417768b5c3c5c1d9bcb2e7c119196dd76b5570");
});
+1 -1
View File
@@ -1,6 +1,6 @@
"use strict";
const assert = require("assert").strict;
const fs = require("fs-extra");
const fs = require("node:fs/promises");
const lib = require("@clusterio/lib");
describe("lib/ini", function() {
+3 -3
View File
@@ -1,6 +1,6 @@
"use strict";
const assert = require("assert").strict;
const fs = require("fs-extra");
const fs = require("node:fs/promises");
const path = require("path");
const { testLines } = require("./factorio/lines");
@@ -47,7 +47,7 @@ describe("lib/logging_utils.js", function() {
});
it("should handle loading broken index", async function() {
let tempDir = path.join("temp", "test", "log");
await fs.outputFile(path.join(tempDir, "index.json"), "Broken JSON");
await fs.writeFile(path.join(tempDir, "index.json"), "Broken JSON");
let logIndex = await lib.LogIndex.load(tempDir);
assert.deepEqual(logIndex.index, new Map());
});
@@ -60,7 +60,7 @@ describe("lib/logging_utils.js", function() {
if (file === "excluded.txt") {
continue;
}
let fileStream = fs.createReadStream(path.join(logDir, file));
let fileStream = (await fs.open(path.join(logDir, file))).createReadStream();
let lineStream = new lib.LineSplitter({ readableObjectMode: true });
fileStream.pipe(lineStream);
for await (let line of lineStream) {
+19 -14
View File
@@ -1,6 +1,6 @@
"use strict";
const assert = require("assert").strict;
const fs = require("fs-extra");
const fs = require("node:fs/promises");
const path = require("path");
const lib = require("@clusterio/lib");
@@ -16,11 +16,12 @@ describe("lib/plugin_loader", function() {
let invalidPlugin = path.join(baseDir, "invalid_plugin");
before(async function() {
async function writePlugin(pluginPath, infoName) {
await fs.outputFile(
await fs.mkdir(pluginPath, { recursive: true });
await fs.writeFile(
path.join(pluginPath, "index.js"),
`module.exports.plugin = { name: "${infoName}" };`
);
await fs.outputFile(
await fs.writeFile(
path.join(pluginPath, "package.json"),
'{ "version": "0.0.1" }'
);
@@ -28,7 +29,7 @@ describe("lib/plugin_loader", function() {
await writePlugin(testPlugin, "test");
await writePlugin(brokenPlugin, "broken");
await fs.outputFile(path.join(brokenPlugin, "index.js"), "Syntax Error");
await fs.writeFile(path.join(brokenPlugin, "index.js"), "Syntax Error");
await writePlugin(invalidPlugin, "wrong");
});
@@ -70,7 +71,8 @@ describe("lib/plugin_loader", function() {
let wrongParentClass = path.join(baseDir, "wrong_parent_class_plugin");
before(async function() {
async function writeEntrypoint(pluginPath, content) {
await fs.outputFile(path.join(pluginPath, "controller.js"), content);
await fs.mkdir(pluginPath, { recursive: true });
await fs.writeFile(path.join(pluginPath, "controller.js"), content);
}
await writeEntrypoint(missingClass, "");
@@ -122,16 +124,18 @@ describe("lib/plugin_loader", function() {
const npmPluginPath = path.join(baseDir, "node_modules", "npm-plugin");
const monorepoPluginPath = path.join(baseDir, "external_plugins", "monorepo", "monorepo-plugin");
const monorepoPluginPathAbs = path.resolve(monorepoPluginPath);
const notAPluginPath = path.join(baseDir, "node_modules", "not-a-plugin");
let pluginList;
before(async function() {
// Setup test plugins
async function writePlugin(pluginPath, name) {
await fs.outputFile(
await fs.mkdir(pluginPath, { recursive: true });
await fs.writeFile(
path.join(pluginPath, "index.js"),
`module.exports.plugin = { name: "${name}" };`
);
await fs.outputFile(
await fs.writeFile(
path.join(pluginPath, "package.json"),
JSON.stringify({
name: path.basename(pluginPath),
@@ -150,7 +154,7 @@ describe("lib/plugin_loader", function() {
// Write a monorepo plugin
await writePlugin(monorepoPluginPath, "monorepo-plugin");
// Create root package.json
await fs.outputFile(
await fs.writeFile(
path.join(baseDir, "package.json"),
JSON.stringify({
dependencies: {
@@ -160,8 +164,9 @@ describe("lib/plugin_loader", function() {
})
);
// Create an npm module that is not a plugin
await fs.outputFile(
path.join(baseDir, "node_modules", "not-a-plugin", "package.json"),
await fs.mkdir(notAPluginPath, { recursive: true });
await fs.writeFile(
path.join(notAPluginPath, "package.json"),
JSON.stringify({ name: "not-a-plugin", version: "1.0.0" })
);
@@ -169,7 +174,7 @@ describe("lib/plugin_loader", function() {
pluginList = await lib.loadPluginList(pluginListPath, true);
});
beforeEach(async function() {
await fs.remove(pluginListPath);
await fs.rm(pluginListPath, { force: true });
});
it("should discover local plugins", async function() {
@@ -188,7 +193,7 @@ describe("lib/plugin_loader", function() {
it("should load existing plugin list", async function() {
const existingList = new Map([["test", "/test/path"]]);
await fs.outputFile(pluginListPath, JSON.stringify([...existingList]));
await fs.writeFile(pluginListPath, JSON.stringify([...existingList]));
const loadedPlugins = await lib.loadPluginList(pluginListPath, false);
assert.ok(loadedPlugins.has("test"));
assert.strictEqual(loadedPlugins.get("test"), "/test/path");
@@ -201,7 +206,7 @@ describe("lib/plugin_loader", function() {
it("should not throw when package.json has no dependencies field", async function() {
// Create a package.json without dependencies
await fs.outputFile(
await fs.writeFile(
path.join("package.json"),
JSON.stringify({
name: "test-package",
@@ -217,7 +222,7 @@ describe("lib/plugin_loader", function() {
after(async function() {
process.chdir(old_cwd);
await fs.remove(baseDir);
await fs.rm(baseDir, { force: true, recursive: true, maxRetries: 10 });
});
});
});
+3 -3
View File
@@ -1,6 +1,6 @@
"use strict";
const assert = require("assert").strict;
const fs = require("fs-extra");
const fs = require("node:fs/promises");
const path = require("path");
const stream = require("stream");
const util = require("util");
@@ -109,7 +109,7 @@ describe("lib/stream", function() {
it("should read chunks in a file in reverse", async function() {
let content = "";
for (let i = 0; i < 10; i++) { content += String(i).repeat(10); }
await fs.outputFile(path.join("temp", "test", "reverse.txt"), content);
await fs.writeFile(path.join("temp", "test", "reverse.txt"), content);
let reverseStream = await lib.createReverseReadStream(
path.join("temp", "test", "reverse.txt"),
{ encoding: "utf8", highWaterMark: 10 }
@@ -123,7 +123,7 @@ describe("lib/stream", function() {
});
it("should reverse the lines of a file", async function() {
let ws = fs.createWriteStream(path.join("temp", "test", "reverse.txt"));
let ws = (await fs.open(path.join("temp", "test", "reverse.txt"), "w")).createWriteStream();
for (let i = 1; i < 100000; i++) {
ws.write(Buffer.from(`${i}\n`));
}