From 1188e59f87ec8d899152932d7c3eec1b18cc2579 Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Tue, 2 Feb 2021 20:17:18 +0100 Subject: [PATCH] Fix diagnostic for bundler config errors (#5704) --- .../bundlers/default/src/DefaultBundler.js | 2 +- packages/core/integration-tests/test/html.js | 33 +++++++++++++++++++ .../invalid-bundler-config/index.html | 1 + .../invalid-bundler-config/package.json | 5 +++ .../invalid-bundler-config/yarn.lock | 0 packages/core/utils/src/config.js | 7 ++-- 6 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 packages/core/integration-tests/test/integration/invalid-bundler-config/index.html create mode 100644 packages/core/integration-tests/test/integration/invalid-bundler-config/package.json create mode 100644 packages/core/integration-tests/test/integration/invalid-bundler-config/yarn.lock diff --git a/packages/bundlers/default/src/DefaultBundler.js b/packages/bundlers/default/src/DefaultBundler.js index 56be5f70306..42601ce94c0 100644 --- a/packages/bundlers/default/src/DefaultBundler.js +++ b/packages/bundlers/default/src/DefaultBundler.js @@ -488,7 +488,7 @@ async function loadBundlerConfig(options: PluginOptions) { CONFIG_SCHEMA, { data: config, - source: JSON.stringify(config), + source: await options.inputFS.readFile(result.files[0].filePath, 'utf8'), filePath: result.files[0].filePath, prependKey: `/${encodeJSONKeyComponent('@parcel/bundler-default')}`, }, diff --git a/packages/core/integration-tests/test/html.js b/packages/core/integration-tests/test/html.js index 8c00c052172..4b15a125ea7 100644 --- a/packages/core/integration-tests/test/html.js +++ b/packages/core/integration-tests/test/html.js @@ -1853,4 +1853,37 @@ describe('html', function() { ``, ); }); + + it('should print a diagnostic for invalid bundler options', async () => { + let dir = path.join(__dirname, 'integration/invalid-bundler-config'); + let pkg = path.join(dir, 'package.json'); + let code = await inputFS.readFileSync(pkg, 'utf8'); + await assert.rejects(() => bundle(path.join(dir, 'index.html')), { + name: 'BuildError', + diagnostics: [ + { + message: 'Invalid config for @parcel/bundler-default', + origin: '@parcel/bundler-default', + filePath: pkg, + language: 'json', + codeFrame: { + code, + codeHighlights: [ + { + message: 'Did you mean "minBundleSize", "minBundles"?', + start: { + column: 30, + line: 3, + }, + end: { + column: 45, + line: 3, + }, + }, + ], + }, + }, + ], + }); + }); }); diff --git a/packages/core/integration-tests/test/integration/invalid-bundler-config/index.html b/packages/core/integration-tests/test/integration/invalid-bundler-config/index.html new file mode 100644 index 00000000000..986a4a1a25b --- /dev/null +++ b/packages/core/integration-tests/test/integration/invalid-bundler-config/index.html @@ -0,0 +1 @@ +