diff --git a/.eslintrc.js b/.eslintrc.js index e359bc89..13f79bd6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -240,7 +240,7 @@ module.exports = { }, }, { - files: ["rollup.config.js"], + files: ["rollup.config.js", "web-ext-config.mjs"], parserOptions: { sourceType: "module", }, diff --git a/scripts/build-post.ts b/scripts/build-post.ts index b1d18de9..19d155ba 100644 --- a/scripts/build-post.ts +++ b/scripts/build-post.ts @@ -58,7 +58,7 @@ async function makeSourceCodeBundle(): Promise { "project.config.ts", "rollup.config.js", "tsconfig.json", - "web-ext-config.cjs", + "web-ext-config.mjs", ].map((file) => path.join(BASE_DIR, file)); const dirs = ["@types", "docs", "patches", "scripts", "src"]; diff --git a/tsconfig.json b/tsconfig.json index 6c1fe212..96d85d96 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,6 +25,7 @@ }, "exclude": [ "compiled*", - "html" + "html", + "web-ext-config.mjs" ] } diff --git a/web-ext-config.cjs b/web-ext-config.cjs deleted file mode 100644 index 8e21d6f9..00000000 --- a/web-ext-config.cjs +++ /dev/null @@ -1,19 +0,0 @@ -const optionalRequire = require("optional-require")(require); - -const config = require("./project.config").default; - -const customConfig = optionalRequire("./custom.config.cjs") || {}; - -module.exports = { - sourceDir: config.compiled, - artifactsDir: config.dist, - ignoreFiles: config.webextIgnoreFiles, - build: { - overwriteDest: true, - }, - lint: { - warningsAsErrors: true, - }, - run: customConfig.run || {}, - sign: customConfig.sign || {}, -}; diff --git a/web-ext-config.mjs b/web-ext-config.mjs new file mode 100644 index 00000000..c28a95f5 --- /dev/null +++ b/web-ext-config.mjs @@ -0,0 +1,28 @@ +import { createRequire } from "module"; + +// This config needs to be an ES module. web-ext loads it with `import()`, and on +// newer Node versions importing a `.cjs` file also exposes a `module.exports` +// named export, which web-ext then rejects: `The config option "module.exports" +// must be specified in camel case`. Reading project.config.ts still needs a +// CommonJS `require` (so the sucrase-node hook kicks in), hence createRequire. +const require = createRequire(import.meta.url); + +const optionalRequire = require("optional-require")(require); + +const config = require("./project.config").default; + +const customConfig = optionalRequire("./custom.config.cjs") || {}; + +export default { + sourceDir: config.compiled, + artifactsDir: config.dist, + ignoreFiles: config.webextIgnoreFiles, + build: { + overwriteDest: true, + }, + lint: { + warningsAsErrors: true, + }, + run: customConfig.run || {}, + sign: customConfig.sign || {}, +};