Skip to content

Commit baa70b1

Browse files
committed
softening to a warning
1 parent 3bd5344 commit baa70b1

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

lib/WebpackConfig.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
const path = require('path');
1313
const fs = require('fs');
14+
const logger = require('./logger');
1415

1516
/**
1617
* @param {RuntimeConfig} runtimeConfig
@@ -111,12 +112,12 @@ class WebpackConfig {
111112
* Normally, we make sure that the manifest keys don't start
112113
* with an opening "/" ever... for consistency. If you need
113114
* to manually specify the manifest key (e.g. because you're
114-
* publicPath is absolute), we're *still* adding this restriction,
115-
* to help avoid a user accidentally adding an opening "/"
116-
* and changing their keys from what they looked like before.
115+
* publicPath is absolute), it's easy to accidentally add
116+
* an opening slash (thereby changing your key prefix) without
117+
* intending to. Hence, the warning.
117118
*/
118119
if (manifestKeyPrefix.indexOf('/') === 0) {
119-
throw new Error(`For consistency, the value passed to setManifestKeyPrefix() cannot start with "/". Try setManifestKeyPrefix('${manifestKeyPrefix.replace(/^\//, '')}') instead.`);
120+
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.`);
120121
}
121122

122123
// guarantee a single trailing slash, except for blank strings

test/WebpackConfig.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const RuntimeConfig = require('../lib/config/RuntimeConfig');
1515
const path = require('path');
1616
const fs = require('fs');
1717
const webpack = require('webpack');
18+
const logger = require('../lib/logger');
1819

1920
function createConfig() {
2021
const runtimeConfig = new RuntimeConfig();
@@ -162,12 +163,13 @@ describe('WebpackConfig object', () => {
162163
expect(config.manifestKeyPrefix).to.equal('');
163164
});
164165

165-
it('You cannot use an opening slash', () => {
166+
it('You can use an opening slash, but get a warning', () => {
166167
const config = createConfig();
167168

168-
expect(() => {
169-
config.setManifestKeyPrefix('/foo/');
170-
}).to.throw('the value passed to setManifestKeyPrefix() cannot start with "/"');
169+
logger.reset();
170+
logger.quiet();
171+
config.setManifestKeyPrefix('/foo/');
172+
expect(logger.getMessages().warning).to.have.lengthOf(1);
171173
});
172174
});
173175

0 commit comments

Comments
 (0)