From 4bf559aef4bf14a4822d22d5101cdaef428f7c6e Mon Sep 17 00:00:00 2001 From: David Anson Date: Fri, 22 Nov 2024 20:08:10 -0800 Subject: [PATCH] wip --- package.json | 2 +- test/fs-virtual-test.mjs | 2 +- test/markdownlint-cli2-test.mjs | 2 +- webworker/{fs-virtual.mjs => fs-virtual.cjs} | 6 +++++- webworker/module-stub.cjs | 8 ++++++++ webworker/process-stub.cjs | 1 + webworker/webpack.config.cjs | 2 +- 7 files changed, 18 insertions(+), 5 deletions(-) rename webworker/{fs-virtual.mjs => fs-virtual.cjs} (96%) create mode 100644 webworker/module-stub.cjs diff --git a/package.json b/package.json index 46e500f7..336de6eb 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 88860c7b..ac33a79a 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 fbf43b6e..91301f94 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 8435a5ff..14d1ef3b 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 00000000..fec94871 --- /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 f4245d09..6db93931 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 336498f9..6b9377b6 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"),