diff --git a/src/config/resolve-config.js b/src/config/resolve-config.js index 3203c0156..c32067876 100644 --- a/src/config/resolve-config.js +++ b/src/config/resolve-config.js @@ -18,14 +18,8 @@ const getExplorerMemoized = mem( if (result && result.config) { if (typeof result.config === "string") { const dir = path.dirname(result.filepath); - try { - const modulePath = resolve(result.config, { paths: [dir] }); - result.config = eval("require")(modulePath); - } catch (error) { - // Original message contains `__filename`, can't pass tests - error.message = `Cannot find module '${result.config}' from '${dir}'`; - throw error; - } + const modulePath = resolve(result.config, { paths: [dir] }); + result.config = eval("require")(modulePath); } if (typeof result.config !== "object") { diff --git a/tests_integration/__tests__/__snapshots__/config-invalid.js.snap b/tests_integration/__tests__/__snapshots__/config-invalid.js.snap index 3c5f74c75..f6713ed29 100644 --- a/tests_integration/__tests__/__snapshots__/config-invalid.js.snap +++ b/tests_integration/__tests__/__snapshots__/config-invalid.js.snap @@ -1,5 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`resolves external configuration from package.json (stderr) 1`] = ` +"[error] Invalid configuration file \`syntax-error.js\`: THIS ERROR MESSAGE MUST COME FROM THIS syntax-error.js FILE +" +`; + +exports[`resolves external configuration from package.json (stdout) 1`] = `""`; + +exports[`resolves external configuration from package.json (write) 1`] = `Array []`; + exports[`show warning with kebab-case option key (stderr) 1`] = ` "[warn] Ignored unknown option { \\"print-width\\": 3 }. Did you mean printWidth? " @@ -27,11 +36,6 @@ exports[`throw error for unsupported extension (stdout) 1`] = `""`; exports[`throw error for unsupported extension (write) 1`] = `Array []`; -exports[`throw error with invalid config format (stderr) 1`] = ` -"[error] Invalid configuration file \`/tests_integration/cli/config/invalid\`: Cannot find module '--invalid--' from '/tests_integration/cli/config/invalid/file' -" -`; - exports[`throw error with invalid config format (stdout) 1`] = `""`; exports[`throw error with invalid config format (write) 1`] = `Array []`; diff --git a/tests_integration/__tests__/config-invalid.js b/tests_integration/__tests__/config-invalid.js index a7a264615..f5054b8fb 100644 --- a/tests_integration/__tests__/config-invalid.js +++ b/tests_integration/__tests__/config-invalid.js @@ -16,6 +16,9 @@ describe("throw error for unsupported extension", () => { describe("throw error with invalid config format", () => { runPrettier("cli/config/invalid", ["--config", "file/.prettierrc"]).test({ status: "non-zero", + stderr: expect.stringMatching( + /Cannot (?:resolve|find) module '--invalid--' from/ + ), }); }); @@ -49,6 +52,14 @@ describe("throw error with invalid config precedence option (configPrecedence)", }); }); +describe("resolves external configuration from package.json", () => { + runPrettier("cli/config-external-config-syntax-error", [ + "syntax-error.js", + ]).test({ + status: 2, + }); +}); + // Tests below require --parser to prevent an error (no parser/filepath specified) describe("show warning with unknown option", () => { diff --git a/tests_integration/cli/config-external-config-syntax-error/package.json b/tests_integration/cli/config-external-config-syntax-error/package.json new file mode 100644 index 000000000..6cc7c0d42 --- /dev/null +++ b/tests_integration/cli/config-external-config-syntax-error/package.json @@ -0,0 +1,3 @@ +{ + "prettier": "./syntax-error" +} diff --git a/tests_integration/cli/config-external-config-syntax-error/syntax-error.js b/tests_integration/cli/config-external-config-syntax-error/syntax-error.js new file mode 100644 index 000000000..5eb40cfcf --- /dev/null +++ b/tests_integration/cli/config-external-config-syntax-error/syntax-error.js @@ -0,0 +1,3 @@ +"use strict"; + +throw new SyntaxError("THIS ERROR MESSAGE MUST COME FROM THIS syntax-error.js FILE");