Skip to content

Commit

Permalink
fix: remove querystring from filenames when writing to disk (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
GregWeil authored and evilebottnawi committed Jan 17, 2019
1 parent 0e8ac82 commit 90d0d94
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/fs.js
Expand Up @@ -26,8 +26,9 @@ module.exports = {
for (const assetPath of Object.keys(assets)) {
const asset = assets[assetPath];
const source = asset.source();
const isAbsolute = path.isAbsolute(assetPath);
const writePath = isAbsolute ? assetPath : path.join(outputPath, assetPath);
const [assetPathClean] = assetPath.split('?');
const isAbsolute = path.isAbsolute(assetPathClean);
const writePath = isAbsolute ? assetPathClean : path.join(outputPath, assetPathClean);
const relativePath = path.relative(process.cwd(), writePath);
const allowWrite = filter && typeof filter === 'function' ? filter(writePath) : true;

Expand Down
20 changes: 20 additions & 0 deletions test/fixtures/server-test/webpack.querystring.config.js
@@ -0,0 +1,20 @@
'use strict';

module.exports = {
mode: 'development',
context: __dirname,
entry: './foo.js',
output: {
filename: 'bundle.js?[contenthash]',
path: '/'
},
module: {
rules: [
{
test: /\.(svg|html)$/,
loader: 'file-loader',
query: { name: '[name].[ext]' }
}
]
}
};
33 changes: 33 additions & 0 deletions test/tests/server.js
Expand Up @@ -11,6 +11,7 @@ const request = require('supertest');
const middleware = require('../../');
const webpackConfig = require('../fixtures/server-test/webpack.config');
const webpackMultiConfig = require('../fixtures/server-test/webpack.array.config');
const webpackQuerystringConfig = require('../fixtures/server-test/webpack.querystring.config');
const webpackClientServerConfig = require('../fixtures/server-test/webpack.client.server.config');

describe('Server', () => {
Expand Down Expand Up @@ -460,6 +461,38 @@ describe('Server', () => {
});
});

function querystringToDisk(value, done) {
app = express();
const compiler = webpack(webpackQuerystringConfig);
instance = middleware(compiler, {
stats: 'errors-only',
logLevel,
writeToDisk: value
});
app.use(instance);
app.use((req, res) => {
res.sendStatus(200);
});
listen = listenShorthand(done);
}

describe('write to disk without including querystrings', () => {
before((done) => {
querystringToDisk(true, done);
});
after(close);

it('should find the bundle file on disk with no querystring', (done) => {
request(app).get('/foo/bar')
.expect(200, () => {
const bundlePath = path.join(__dirname, '../fixtures/server-test/bundle.js');
assert(fs.existsSync(bundlePath));
fs.unlinkSync(bundlePath);
done();
});
});
});

function multiToDisk(value, done) {
app = express();
const compiler = webpack(webpackMultiConfig);
Expand Down

0 comments on commit 90d0d94

Please sign in to comment.