diff --git a/lib/WebpackConfig.js b/lib/WebpackConfig.js index 706ec597..dd3b7816 100644 --- a/lib/WebpackConfig.js +++ b/lib/WebpackConfig.js @@ -11,6 +11,7 @@ const path = require('path'); const fs = require('fs'); +const logger = require('./logger'); /** * @param {RuntimeConfig} runtimeConfig @@ -107,6 +108,18 @@ class WebpackConfig { } setManifestKeyPrefix(manifestKeyPrefix) { + /* + * Normally, we make sure that the manifest keys don't start + * with an opening "/" ever... for consistency. If you need + * to manually specify the manifest key (e.g. because you're + * publicPath is absolute), it's easy to accidentally add + * an opening slash (thereby changing your key prefix) without + * intending to. Hence, the warning. + */ + if (manifestKeyPrefix.indexOf('/') === 0) { + logger.warning(`The value passed to setManifestKeyPrefix "${manifestKeyPrefix}" starts with "/". This is allowed, but since the key prefix does not normally start with a "/", you may have just changed the prefix accidentally.`); + } + // guarantee a single trailing slash, except for blank strings if (manifestKeyPrefix !== '') { manifestKeyPrefix = manifestKeyPrefix.replace(/\/$/, ''); diff --git a/test/WebpackConfig.js b/test/WebpackConfig.js index 8cfdccea..fcb0dad5 100644 --- a/test/WebpackConfig.js +++ b/test/WebpackConfig.js @@ -15,6 +15,7 @@ const RuntimeConfig = require('../lib/config/RuntimeConfig'); const path = require('path'); const fs = require('fs'); const webpack = require('webpack'); +const logger = require('../lib/logger'); function createConfig() { const runtimeConfig = new RuntimeConfig(); @@ -148,10 +149,10 @@ describe('WebpackConfig object', () => { it('You can set it!', () => { const config = createConfig(); - config.setManifestKeyPrefix('/foo'); + config.setManifestKeyPrefix('foo'); // trailing slash added - expect(config.manifestKeyPrefix).to.equal('/foo/'); + expect(config.manifestKeyPrefix).to.equal('foo/'); }); it('You can set it blank', () => { @@ -161,6 +162,15 @@ describe('WebpackConfig object', () => { // trailing slash not added expect(config.manifestKeyPrefix).to.equal(''); }); + + it('You can use an opening slash, but get a warning', () => { + const config = createConfig(); + + logger.reset(); + logger.quiet(); + config.setManifestKeyPrefix('/foo/'); + expect(logger.getMessages().warning).to.have.lengthOf(1); + }); }); describe('addEntry', () => {