Prefix clusterio/lib imports with lib

Use lib* prefix for the modules impored from the lib package to help
distinguish them more from ordinary variables.  Fix up the naming
convention for files to be consistently lowercase_underscore for
JavaScript files.
This commit is contained in:
Hornwitser committed 2020-10-23 21:22:43 +02:00
1 parent fbbaf3dd3a
commit 24397b75cc
55 files changed
+692 -668

No files matched your search

+16 -16
View File
@@ -4,7 +4,7 @@ const fs = require("fs-extra");
const jszip = require("jszip");
const path = require("path");
const factorio = require("@clusterio/lib/factorio");
const libFactorio = require("@clusterio/lib/factorio");
describe("lib/factorio", function() {
@@ -14,7 +14,7 @@ describe("lib/factorio", function() {
zip.file("root/foo.txt", "");
zip.file("root/bar.txt", "");
assert.equal(factorio._findRoot(zip), "root");
assert.equal(libFactorio._findRoot(zip), "root");
});
it("should throw if files are at the root of the zip", function() {
@@ -23,7 +23,7 @@ describe("lib/factorio", function() {
zip.file("bar.txt", "");
assert.throws(
() => factorio._findRoot(zip),
() => libFactorio._findRoot(zip),
new Error("Zip contains file 'bar.txt' in root dir")
);
});
@@ -34,7 +34,7 @@ describe("lib/factorio", function() {
zip.file("root-2/bar.txt", "");
assert.throws(
() => factorio._findRoot(zip),
() => libFactorio._findRoot(zip),
new Error("Zip contains multiple root folders")
);
});
@@ -43,7 +43,7 @@ describe("lib/factorio", function() {
let zip = new jszip();
assert.throws(
() => factorio._findRoot(zip),
() => libFactorio._findRoot(zip),
new Error("Empty zip file")
);
});
@@ -79,7 +79,7 @@ describe("lib/factorio", function() {
};
it("should produce output matching the reference", function() {
assert.equal(factorio._generateLoader(patchInfo), reference);
assert.equal(libFactorio._generateLoader(patchInfo), reference);
});
});
@@ -89,7 +89,7 @@ describe("lib/factorio", function() {
{ name: "a", version: "1.0.0", dependencies: {"b": "*"} },
{ name: "b", version: "1.0.0", dependencies: {} },
];
factorio._reorderDependencies(modules);
libFactorio._reorderDependencies(modules);
assert(modules[0].name === "b", "Dependency was not reorederd");
});
it("should throw on invalid version", function() {
@@ -97,7 +97,7 @@ describe("lib/factorio", function() {
{ name: "a", version: "foo", dependencies: {} },
];
assert.throws(
() => factorio._reorderDependencies(modules),
() => libFactorio._reorderDependencies(modules),
new Error("Invalid version 'foo' for module a")
);
});
@@ -106,7 +106,7 @@ describe("lib/factorio", function() {
{ name: "a", version: "1.0.0", dependencies: {"b": "invalid"} },
];
assert.throws(
() => factorio._reorderDependencies(modules),
() => libFactorio._reorderDependencies(modules),
new Error("Invalid version range 'invalid' for dependency b on module a")
);
});
@@ -115,7 +115,7 @@ describe("lib/factorio", function() {
{ name: "a", version: "1.0.0", dependencies: {"b": "*"} },
];
assert.throws(
() => factorio._reorderDependencies(modules),
() => libFactorio._reorderDependencies(modules),
new Error("Missing dependency b for module a")
);
modules = [
@@ -124,7 +124,7 @@ describe("lib/factorio", function() {
{ name: "c", version: "1.0.0", dependencies: {"d": "*"} },
];
assert.throws(
() => factorio._reorderDependencies(modules),
() => libFactorio._reorderDependencies(modules),
new Error("Missing dependency d for module c")
);
});
@@ -134,7 +134,7 @@ describe("lib/factorio", function() {
{ name: "b", version: "1.0.0", dependencies: {"a": ">=2"} },
];
assert.throws(
() => factorio._reorderDependencies(modules),
() => libFactorio._reorderDependencies(modules),
new Error("Module b requires a >=2")
);
});
@@ -144,7 +144,7 @@ describe("lib/factorio", function() {
{ name: "b", version: "1.0.0", dependencies: {"a": "*"} },
];
assert.throws(
() => factorio._reorderDependencies(modules),
() => libFactorio._reorderDependencies(modules),
new Error("Module dependency loop detected: a -> b -> a")
);
modules = [
@@ -154,7 +154,7 @@ describe("lib/factorio", function() {
{ name: "c", version: "1.0.0", dependencies: {"a": "*"} },
];
assert.throws(
() => factorio._reorderDependencies(modules),
() => libFactorio._reorderDependencies(modules),
new Error("Module dependency loop detected: b -> c -> a -> b")
);
});
@@ -194,7 +194,7 @@ describe("lib/factorio", function() {
}
let success = false;
try {
factorio._reorderDependencies(modules);
libFactorio._reorderDependencies(modules);
success = true;
} catch (err) { }
if (success) {
@@ -217,7 +217,7 @@ describe("lib/factorio", function() {
await fs.outputFile(zipPath, await zip.generateAsync({ type: "nodebuffer" }));
await assert.rejects(
factorio.patch(zipPath, []),
libFactorio.patch(zipPath, []),
new Error("Unable to patch save, unknown scenario (3acc3be3861144e55604f5ac2f2555071885ebc4)")
);
});