Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove querystring from filenames when writing to disk #361

Merged
merged 2 commits into from
Jan 17, 2019
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
5 changes: 3 additions & 2 deletions lib/fs.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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