diff --git a/package.json b/package.json index 46e500f..336de6e 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "test-watch": "git ls-files | entr npm run test", "update-snapshots": "ava --timeout=1m --update-snapshots test/markdownlint-cli2-test-exec.mjs test/markdownlint-cli2-test-fs.mjs test/markdownlint-cli2-test-main.mjs", "webworker": "cd webworker && webpack --mode none", - "webworker-install": "npm install --no-package-lock --no-save path-browserify setimmediate stream-browserify util webpack-cli && cpy ./node_modules/setimmediate/setImmediate.js ./webworker/setImmediate.cjs --flat" + "webworker-install": "npm install --no-package-lock --no-save path-browserify setimmediate stream-browserify util webpack-cli && cpy ./node_modules/setimmediate/setImmediate.js ./webworker --flat --rename=setImmediate.cjs" }, "engines": { "node": ">=18" diff --git a/test/fs-virtual-test.mjs b/test/fs-virtual-test.mjs index 88860c7..ac33a79 100644 --- a/test/fs-virtual-test.mjs +++ b/test/fs-virtual-test.mjs @@ -4,7 +4,7 @@ import path from "node:path"; import { promisify } from "node:util"; import test from "ava"; import { __filename } from "./esm-helpers.mjs"; -import FsVirtual from "../webworker/fs-virtual.mjs"; +import FsVirtual from "../webworker/fs-virtual.cjs"; const mockPath = "/mock"; const thisFile = path.basename(__filename(import.meta)); diff --git a/test/markdownlint-cli2-test.mjs b/test/markdownlint-cli2-test.mjs index fbf43b6..91301f9 100644 --- a/test/markdownlint-cli2-test.mjs +++ b/test/markdownlint-cli2-test.mjs @@ -12,7 +12,7 @@ import { "main" as markdownlintCli2 } from "../markdownlint-cli2.mjs"; import jsoncParse from "../parsers/jsonc-parse.mjs"; import yamlParse from "../parsers/yaml-parse.mjs"; import FsMock from "./fs-mock.mjs"; -import FsVirtual from "../webworker/fs-virtual.mjs"; +import FsVirtual from "../webworker/fs-virtual.cjs"; import firstLine from "./customRules/rules/first-line.cjs"; const schemaIdVersionRe = /^.*v(?\d+\.\d+\.\d+).*$/u; diff --git a/webworker/fs-virtual.mjs b/webworker/fs-virtual.cjs similarity index 96% rename from webworker/fs-virtual.mjs rename to webworker/fs-virtual.cjs index 8435a5f..14d1ef3 100644 --- a/webworker/fs-virtual.mjs +++ b/webworker/fs-virtual.cjs @@ -1,5 +1,7 @@ // @ts-check +"use strict"; + const dirent = (path, directory) => { const name = path.replace(/^.*\//u, ""); return { @@ -97,4 +99,6 @@ class FsVirtual { } } -export default FsVirtual; +if (typeof module !== "undefined") { + module.exports = FsVirtual; +} diff --git a/webworker/module-stub.cjs b/webworker/module-stub.cjs new file mode 100644 index 0000000..fec9487 --- /dev/null +++ b/webworker/module-stub.cjs @@ -0,0 +1,8 @@ +// @ts-check + +"use strict"; + +module.exports = { + // @ts-ignore + "createRequire": () => require +}; diff --git a/webworker/process-stub.cjs b/webworker/process-stub.cjs index f4245d0..6db9393 100644 --- a/webworker/process-stub.cjs +++ b/webworker/process-stub.cjs @@ -3,6 +3,7 @@ "use strict"; module.exports = { + "argv": [], "cwd": () => "/", "env": {}, "versions": { diff --git a/webworker/webpack.config.cjs b/webworker/webpack.config.cjs index 336498f..6b9377b 100644 --- a/webworker/webpack.config.cjs +++ b/webworker/webpack.config.cjs @@ -51,7 +51,7 @@ module.exports = { "fallback": { "buffer": false, "fs": false, - "module": false, + "module": require.resolve("./module-stub.cjs"), "os": require.resolve("./os-stub.cjs"), "path": require.resolve("path-browserify"), "process": require.resolve("./process-stub.cjs"),