From 2706aeb0af7d2403487fbf9978386b3d33ed7621 Mon Sep 17 00:00:00 2001 From: Evan Farina Date: Tue, 7 Jan 2020 16:22:49 -0500 Subject: [PATCH 1/4] Allow assets to be loaded without a manifest if a 'noManifestLookup' option is supplied by the host app or addon --- app/config/asset-manifest.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/app/config/asset-manifest.js b/app/config/asset-manifest.js index f0bbe8b..131592e 100644 --- a/app/config/asset-manifest.js +++ b/app/config/asset-manifest.js @@ -1,24 +1,30 @@ import require from 'require'; import environment from './environment'; + const modulePrefix = environment.modulePrefix; const metaName = `${modulePrefix}/config/asset-manifest`; const nodeName = `${modulePrefix}/config/node-asset-manifest`; let config = {}; +const lookupManifest = !environment.noManifestLookup; -try { - // If we have a Node version of the asset manifest, use that for FastBoot and - // similar environments. - if (require.has(nodeName)) { - config = require(nodeName).default; // eslint-disable-line - } else { - const rawConfig = document.querySelector('meta[name="' + metaName + '"]').getAttribute('content'); - config = JSON.parse(unescape(rawConfig)); +if (lookupManifest) { + try { + // If we have a Node version of the asset manifest, use that for FastBoot and + // similar environments. + if (require.has(nodeName)) { + config = require(nodeName).default; // eslint-disable-line + } else { + const rawConfig = document.querySelector('meta[name="' + metaName + '"]').getAttribute('content'); + config = JSON.parse(unescape(rawConfig)); + } + } catch(err) { + throw new Error('No manifest was found with the name "' + metaName + + '". To hide this message you can set the config option `noManifestLookup` to `true`. For non-browser environments, verify that you included the node-asset-manifest module.', { + id: 'no-manifest-found' + }); } -} catch(err) { - throw new Error('Failed to load asset manifest. For browser environments, verify the meta tag with name "'+ metaName + - '" is present. For non-browser environments, verify that you included the node-asset-manifest module.'); } export default config; From 1c4cbb7aa11eba7e195f75e496405e80ab19ff93 Mon Sep 17 00:00:00 2001 From: Evan Farina Date: Tue, 7 Jan 2020 16:22:49 -0500 Subject: [PATCH 2/4] Updated the README to document the new option --- README.md | 10 ++++++++++ tests/unit/asset-manifest-test.js | 2 ++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 899bf5a..c01c557 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,16 @@ the asset manifest. This defaults to `[ 'js', 'css' ]`. _Note: This class provides default `contentFor`, `postprocessTree`, and `postBuild` hooks so be sure that you call `_super` if you override one of those methods._ +### Options + +##### noManifest +* Type: `boolean` +* If `true`, a tag which would eventually hold the manifest will not be inserted into the DOM. + +##### noManifestLookup +* Type: `boolean` +* If `true`, no error will be thrown in the event that a manifest was not generated for the current environment + ### Why isn't a manifest generated by default? This addon doesn't perform manifest generation just by virtue of being installed because there is no convention for diff --git a/tests/unit/asset-manifest-test.js b/tests/unit/asset-manifest-test.js index 4776aaf..e9841dd 100644 --- a/tests/unit/asset-manifest-test.js +++ b/tests/unit/asset-manifest-test.js @@ -6,6 +6,8 @@ import require from 'require'; module('Unit | asset-manifest', { beforeEach() { resetModules(); + console.log(this.owner); + debugger; this.originalNodeModule = requirejs.entries['dummy/config/node-asset-manifest']; }, From 02495b6213355c39ca64774a15a4bb6ac9830a00 Mon Sep 17 00:00:00 2001 From: Evan Farina Date: Tue, 7 Jan 2020 16:56:33 -0500 Subject: [PATCH 3/4] Remove debug code --- tests/unit/asset-manifest-test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/unit/asset-manifest-test.js b/tests/unit/asset-manifest-test.js index e9841dd..4776aaf 100644 --- a/tests/unit/asset-manifest-test.js +++ b/tests/unit/asset-manifest-test.js @@ -6,8 +6,6 @@ import require from 'require'; module('Unit | asset-manifest', { beforeEach() { resetModules(); - console.log(this.owner); - debugger; this.originalNodeModule = requirejs.entries['dummy/config/node-asset-manifest']; }, From 245f6ea41f1a966aecc6bb627bd48023c6a2dcb2 Mon Sep 17 00:00:00 2001 From: Evan Farina Date: Tue, 7 Jan 2020 17:24:59 -0500 Subject: [PATCH 4/4] Add a default value to the options documentation in the README --- README.md | 2 ++ app/config/asset-manifest.js | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c01c557..be464b7 100644 --- a/README.md +++ b/README.md @@ -45,10 +45,12 @@ _Note: This class provides default `contentFor`, `postprocessTree`, and `postBui ##### noManifest * Type: `boolean` +* Default: `undefined` * If `true`, a tag which would eventually hold the manifest will not be inserted into the DOM. ##### noManifestLookup * Type: `boolean` +* Default: `undefined` * If `true`, no error will be thrown in the event that a manifest was not generated for the current environment ### Why isn't a manifest generated by default? diff --git a/app/config/asset-manifest.js b/app/config/asset-manifest.js index 131592e..b2ce0bc 100644 --- a/app/config/asset-manifest.js +++ b/app/config/asset-manifest.js @@ -1,7 +1,6 @@ import require from 'require'; import environment from './environment'; - const modulePrefix = environment.modulePrefix; const metaName = `${modulePrefix}/config/asset-manifest`; const nodeName = `${modulePrefix}/config/node-asset-manifest`;