Skip to content

Commit 90d0d94

Browse files
GregWeilevilebottnawi
authored andcommitted
fix: remove querystring from filenames when writing to disk (#361)
1 parent 0e8ac82 commit 90d0d94

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

lib/fs.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ module.exports = {
2626
for (const assetPath of Object.keys(assets)) {
2727
const asset = assets[assetPath];
2828
const source = asset.source();
29-
const isAbsolute = path.isAbsolute(assetPath);
30-
const writePath = isAbsolute ? assetPath : path.join(outputPath, assetPath);
29+
const [assetPathClean] = assetPath.split('?');
30+
const isAbsolute = path.isAbsolute(assetPathClean);
31+
const writePath = isAbsolute ? assetPathClean : path.join(outputPath, assetPathClean);
3132
const relativePath = path.relative(process.cwd(), writePath);
3233
const allowWrite = filter && typeof filter === 'function' ? filter(writePath) : true;
3334

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
module.exports = {
4+
mode: 'development',
5+
context: __dirname,
6+
entry: './foo.js',
7+
output: {
8+
filename: 'bundle.js?[contenthash]',
9+
path: '/'
10+
},
11+
module: {
12+
rules: [
13+
{
14+
test: /\.(svg|html)$/,
15+
loader: 'file-loader',
16+
query: { name: '[name].[ext]' }
17+
}
18+
]
19+
}
20+
};

test/tests/server.js

+33
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const request = require('supertest');
1111
const middleware = require('../../');
1212
const webpackConfig = require('../fixtures/server-test/webpack.config');
1313
const webpackMultiConfig = require('../fixtures/server-test/webpack.array.config');
14+
const webpackQuerystringConfig = require('../fixtures/server-test/webpack.querystring.config');
1415
const webpackClientServerConfig = require('../fixtures/server-test/webpack.client.server.config');
1516

1617
describe('Server', () => {
@@ -460,6 +461,38 @@ describe('Server', () => {
460461
});
461462
});
462463

464+
function querystringToDisk(value, done) {
465+
app = express();
466+
const compiler = webpack(webpackQuerystringConfig);
467+
instance = middleware(compiler, {
468+
stats: 'errors-only',
469+
logLevel,
470+
writeToDisk: value
471+
});
472+
app.use(instance);
473+
app.use((req, res) => {
474+
res.sendStatus(200);
475+
});
476+
listen = listenShorthand(done);
477+
}
478+
479+
describe('write to disk without including querystrings', () => {
480+
before((done) => {
481+
querystringToDisk(true, done);
482+
});
483+
after(close);
484+
485+
it('should find the bundle file on disk with no querystring', (done) => {
486+
request(app).get('/foo/bar')
487+
.expect(200, () => {
488+
const bundlePath = path.join(__dirname, '../fixtures/server-test/bundle.js');
489+
assert(fs.existsSync(bundlePath));
490+
fs.unlinkSync(bundlePath);
491+
done();
492+
});
493+
});
494+
});
495+
463496
function multiToDisk(value, done) {
464497
app = express();
465498
const compiler = webpack(webpackMultiConfig);

0 commit comments

Comments
 (0)