Skip to content

Commit b9d0ee2

Browse files
committed
fix(client): stricter reg exp to redirect sockjs client path (webpack#2069)
* fix(client): stricter reg exp to redirect sockjs client path * fix(client): check resource context for normal module replacement * fix(client): remove dev server string from context path * fix(client): remove console logs * fix(client): fixed resource context match to use cwd
1 parent 401ccea commit b9d0ee2

File tree

5 files changed

+141
-12
lines changed

5 files changed

+141
-12
lines changed

client-src/default/webpack.config.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ module.exports = {
1616
],
1717
},
1818
plugins: [
19-
new webpack.NormalModuleReplacementPlugin(/\/clients\//, (resource) => {
20-
resource.request = resource.request.replace(
21-
/\/clients\//,
22-
'/../clients/'
23-
);
24-
}),
19+
new webpack.NormalModuleReplacementPlugin(
20+
/^\.\/clients\/SockJSClient$/,
21+
(resource) => {
22+
if (resource.context.startsWith(process.cwd())) {
23+
resource.request = resource.request.replace(
24+
/^\.\/clients\/SockJSClient$/,
25+
'../clients/SockJSClient'
26+
);
27+
}
28+
}
29+
),
2530
],
2631
};

client-src/live/webpack.config.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ module.exports = {
3232
to: path.resolve(__dirname, '../../client/live.html'),
3333
},
3434
]),
35-
new webpack.NormalModuleReplacementPlugin(/\/clients\//, (resource) => {
36-
resource.request = resource.request.replace(
37-
/\/clients\//,
38-
'/../clients/'
39-
);
40-
}),
35+
new webpack.NormalModuleReplacementPlugin(
36+
/^\.\/clients\/SockJSClient$/,
37+
(resource) => {
38+
if (resource.context.startsWith(process.cwd())) {
39+
resource.request = resource.request.replace(
40+
/^\.\/clients\/SockJSClient$/,
41+
'../clients/SockJSClient'
42+
);
43+
}
44+
}
45+
),
4146
],
4247
};

test/e2e/Iframe.test.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
'use strict';
2+
3+
const testServer = require('../helpers/test-server');
4+
const config = require('../fixtures/client-config/webpack.config');
5+
const runBrowser = require('../helpers/run-browser');
6+
const port = require('../ports-map').Iframe;
7+
8+
// iframe mode should be tested while still supported, because
9+
// its sources differ from those of inline mode, which can cause unexpected
10+
// breaking changes: https://github.com/webpack/webpack-dev-server/issues/2006
11+
describe('Client iframe console.log', () => {
12+
const baseOptions = {
13+
port,
14+
host: '0.0.0.0',
15+
};
16+
const cases = [
17+
{
18+
title: 'hot disabled',
19+
options: {
20+
hot: false,
21+
},
22+
},
23+
{
24+
title: 'hot enabled',
25+
options: {
26+
hot: true,
27+
},
28+
},
29+
{
30+
title: 'liveReload disabled',
31+
options: {
32+
liveReload: false,
33+
},
34+
},
35+
{
36+
title: 'liveReload enabled',
37+
options: {
38+
liveReload: true,
39+
},
40+
},
41+
{
42+
title: 'clientLogLevel is silent',
43+
options: {
44+
clientLogLevel: 'silent',
45+
},
46+
},
47+
];
48+
49+
for (const { title, options } of cases) {
50+
it(title, () => {
51+
const res = [];
52+
const testOptions = Object.assign({}, baseOptions, options);
53+
54+
// TODO: use async/await when Node.js v6 support is dropped
55+
return Promise.resolve()
56+
.then(() => {
57+
return new Promise((resolve) => {
58+
testServer.startAwaitingCompilation(config, testOptions, resolve);
59+
});
60+
})
61+
.then(runBrowser)
62+
.then(({ page, browser }) => {
63+
return new Promise((resolve) => {
64+
page.goto(`http://localhost:${port}/webpack-dev-server/main`);
65+
page.on('console', ({ _text }) => {
66+
res.push(_text);
67+
});
68+
setTimeout(() => {
69+
browser.close().then(() => {
70+
expect(res).toMatchSnapshot();
71+
resolve();
72+
});
73+
}, 3000);
74+
});
75+
})
76+
.then(() => {
77+
return new Promise((resolve) => {
78+
testServer.close(resolve);
79+
});
80+
});
81+
});
82+
}
83+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Client iframe console.log clientLogLevel is silent 1`] = `
4+
Array [
5+
"Hey.",
6+
]
7+
`;
8+
9+
exports[`Client iframe console.log hot disabled 1`] = `
10+
Array [
11+
"Hey.",
12+
"[WDS] Live Reloading enabled.",
13+
]
14+
`;
15+
16+
exports[`Client iframe console.log hot enabled 1`] = `
17+
Array [
18+
"[HMR] Waiting for update signal from WDS...",
19+
"Hey.",
20+
"[WDS] Hot Module Replacement enabled.",
21+
"[WDS] Live Reloading enabled.",
22+
]
23+
`;
24+
25+
exports[`Client iframe console.log liveReload disabled 1`] = `
26+
Array [
27+
"Hey.",
28+
]
29+
`;
30+
31+
exports[`Client iframe console.log liveReload enabled 1`] = `
32+
Array [
33+
"Hey.",
34+
]
35+
`;

test/ports-map.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const portsList = {
4343
Progress: 1,
4444
'progress-option': 1,
4545
'profile-option': 1,
46+
Iframe: 1,
4647
};
4748

4849
let startPort = 8079;

0 commit comments

Comments
 (0)