Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

const path = require('path');
const fs = require('fs');
const logger = require('./logger');

/**
* @param {RuntimeConfig} runtimeConfig
Expand Down Expand Up @@ -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(/\/$/, '');
Expand Down
14 changes: 12 additions & 2 deletions test/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down