Migrate to ES modules

Clusterio #984 converted its packages to ESM, so a CommonJS plugin can
no longer import @clusterio/lib and plugin entrypoints must name the
full file. Every package gets "type": "module", entrypoints and relative
imports carry the .js extension, and the webpack configs become .cjs as
webpack-cli loads them with require. tsconfig.node.json moves from
node16 to nodenext to match clusterio, which needs it for the JSON
import attributes in its sources.

The tap tests and the shared test helpers use import and
import.meta.dirname. The test scripts pass --type-strip-only so tap
leaves lib's .ts subpath imports to Node's own type stripping, as its
TypeScript loader compiled them without a default export. The lua
runner resolves fengari from the test file it is given, since a bare
import from the shared test directory does not reach the plugin's
devDependencies.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Fable 5.1 authored and Cooldude2606 committed 2026-09-12 01:10:02 +01:00
1 parent 797d7501c7
commit 7fd66c6ac7
49 files changed
+91 -89

No files matched your search

+7 -6
View File
@@ -1,7 +1,6 @@
"use strict";
const path = require("node:path");
const fs = require("node:fs");
const { lua, lauxlib, lualib, to_luastring, to_jsstring } = require("fengari");
import path from "node:path";
import fs from "node:fs";
import { createRequire } from "node:module";
/**
* Run one lua test file in its own lua state and return its results.
@@ -21,6 +20,8 @@ const { lua, lauxlib, lualib, to_luastring, to_jsstring } = require("fengari");
* @returns {{ name: string, ok: boolean, detail?: string }[]}
*/
function runLuaTests(envFile, testFile) {
// fengari is a devDependency of the plugin whose tests run, so resolve it from there
const { lua, lauxlib, lualib, to_luastring, to_jsstring } = createRequire(testFile)("fengari");
const L = lauxlib.luaL_newstate();
lualib.luaL_openlibs(L);
@@ -38,7 +39,7 @@ function runLuaTests(envFile, testFile) {
};
load(envFile);
lua.lua_pushstring(L, to_luastring(__dirname));
lua.lua_pushstring(L, to_luastring(import.meta.dirname));
call();
// The environment stays on the stack and is passed to the test chunk
@@ -60,4 +61,4 @@ function reportLuaTests(t, envFile, testFile) {
t.end();
}
module.exports = { runLuaTests, reportLuaTests };
export { runLuaTests, reportLuaTests };