diff --git a/src/config/prettier-config/load-external-config.js b/src/config/prettier-config/load-external-config.js index 9c2c90764..aa7362b5f 100644 --- a/src/config/prettier-config/load-external-config.js +++ b/src/config/prettier-config/load-external-config.js @@ -17,10 +17,8 @@ async function loadExternalConfig(externalConfig, configFile) { */ try { const required = requireFromFile(externalConfig, configFile); - // Since Node.js v23 onwards, it is possible to load ESM using require. + // Since Node.js v22.12 onwards, it is possible to load ESM via `require()`. // If that feature is enabled, it is necessary to return the default. - // https://github.com/prettier/prettier/issues/16812 - // FIXME: We want to add tests but https://github.com/jestjs/jest/issues/15363 blocks // @ts-expect-error if (process.features.require_module && required.__esModule) { return required.default; diff --git a/tests/integration/__tests__/__snapshots__/config-resolution.js.snap b/tests/integration/__tests__/__snapshots__/config-resolution.js.snap index ccabbd11a..34277cde9 100644 --- a/tests/integration/__tests__/__snapshots__/config-resolution.js.snap +++ b/tests/integration/__tests__/__snapshots__/config-resolution.js.snap @@ -24,6 +24,8 @@ exports[`resolves external configuration from package.json (cjs package) (stdout exports[`resolves external configuration from package.json (esm file) (stdout) 1`] = `"console.log("should have no semi")"`; +exports[`resolves external configuration from package.json (esm package with TLA) (stdout) 1`] = `"console.log("should have no semi")"`; + exports[`resolves external configuration from package.json (esm package) (stdout) 1`] = `"console.log("should have no semi")"`; exports[`resolves json configuration file with --find-config-path file (stderr) 1`] = `""`; diff --git a/tests/integration/__tests__/config-resolution.js b/tests/integration/__tests__/config-resolution.js index f6396d1e5..63f13d9d5 100644 --- a/tests/integration/__tests__/config-resolution.js +++ b/tests/integration/__tests__/config-resolution.js @@ -37,6 +37,14 @@ describe("resolves external configuration from package.json (esm package)", () = }); }); +describe("resolves external configuration from package.json (esm package with TLA)", () => { + runCli("cli/config/external-config/esm-package-with-tla", ["index.js"]).test({ + status: 0, + stderr: "", + write: [], + }); +}); + describe("resolves external configuration from package.json (esm file)", () => { runCli("cli/config/external-config/esm-package", ["index.js"]).test({ status: 0, diff --git a/tests/integration/cli/config/external-config/esm-package-with-tla/index.js b/tests/integration/cli/config/external-config/esm-package-with-tla/index.js new file mode 100644 index 000000000..b4639445c --- /dev/null +++ b/tests/integration/cli/config/external-config/esm-package-with-tla/index.js @@ -0,0 +1 @@ +console.log("should have no semi"); diff --git a/tests/integration/cli/config/external-config/esm-package-with-tla/node_modules/@company/prettier-config/index.js b/tests/integration/cli/config/external-config/esm-package-with-tla/node_modules/@company/prettier-config/index.js new file mode 100644 index 000000000..2587ec9e8 --- /dev/null +++ b/tests/integration/cli/config/external-config/esm-package-with-tla/node_modules/@company/prettier-config/index.js @@ -0,0 +1,4 @@ +export default await Promise.resolve({ + "printWidth": await Promise.resolve(77), + "semi": await Promise.resolve(false) +}) diff --git a/tests/integration/cli/config/external-config/esm-package-with-tla/node_modules/@company/prettier-config/package.json b/tests/integration/cli/config/external-config/esm-package-with-tla/node_modules/@company/prettier-config/package.json new file mode 100644 index 000000000..fb040ee6e --- /dev/null +++ b/tests/integration/cli/config/external-config/esm-package-with-tla/node_modules/@company/prettier-config/package.json @@ -0,0 +1,7 @@ +{ + "name": "@company/prettier-config", + "private": true, + "version": "0.0.0", + "type": "module", + "exports": "./index.js" +} diff --git a/tests/integration/cli/config/external-config/esm-package-with-tla/package.json b/tests/integration/cli/config/external-config/esm-package-with-tla/package.json new file mode 100644 index 000000000..58ab00285 --- /dev/null +++ b/tests/integration/cli/config/external-config/esm-package-with-tla/package.json @@ -0,0 +1,3 @@ +{ + "prettier": "@company/prettier-config" +}