Skip to content

Commit 602c762

Browse files
author
Barthélémy Ledoux
authored
fix: make component testing windows compatible (#15889)
1 parent a5bb2e0 commit 602c762

File tree

22 files changed

+5497
-136
lines changed

22 files changed

+5497
-136
lines changed
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
25+
/demo
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
...require('../../.releaserc.base'),
3+
branches: [
4+
{ name: 'master', channel: 'latest' },
5+
],
6+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 X.L
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<div align="center">
2+
<a href="https://github.com/webpack/webpack">
3+
<img width="200" height="200"
4+
src="https://webpack.js.org/assets/icon-square-big.svg">
5+
</a>
6+
<h1>Lazy Compile Webpack Plugin</h1>
7+
<p>Plugin that saves a tremendous amount of time.</p>
8+
</div>
9+
10+
## Fork from https://github.com/liximomo/lazy-compile-webpack-plugin/
11+
12+
To enable windows compatibility we forked this repo and fixed the windows issue.
13+
14+
## Why
15+
16+
Starting the development server is taking you a long time when the codebase is large. You have tried dynamic imports, it only does a load-on-demand, the whole project was still been compiled. We don't want to wait a couple of minutes for a simple modification. People don't waste time for the things they have never used!
17+
18+
## Install
19+
20+
```sh
21+
# npm
22+
npm i -D lazy-compile-webpack-plugin
23+
24+
# yarn
25+
yarn add -D lazy-compile-webpack-plugin
26+
```
27+
28+
## Usage
29+
30+
```js
31+
const LazyCompilePlugin = require('lazy-compile-webpack-plugin');
32+
33+
module.exports = {
34+
entry: 'index.js',
35+
output: {
36+
path: __dirname + '/dist',
37+
filename: 'bundle.js',
38+
},
39+
plugins: [new LazyCompilePlugin()],
40+
};
41+
```
42+
43+
## Options
44+
45+
| Name | Type | Default | Description |
46+
| :-----------------------------------------------: | :---------------------: | :---------: | :------------------------------------------------------- |
47+
| **[`refreshAfterCompile`](#refreshAfterCompile)** | `boolean` | `false` | Enable/Disable _page refresh_ when compilation is finish |
48+
| **[`ignores`](#ignores)** | `RegExp[] \| Function[]` | `undefined` | Request to be ignored from lazy compiler |
49+
50+
### `refreshAfterCompile`
51+
52+
Type: `boolean`
53+
Default: `false`
54+
55+
Set `false` for a seamless dev experience.
56+
57+
### `ignores`
58+
59+
Type: `RegExp[] | ((request: string, wpModule: object) => boolean)`
60+
Default: `undefined`
61+
62+
Request to be ignored from lazy compiler, `html-webpack-plugin` is always ignored.
63+
64+
Specifically, an Angular app should enable this option like following:
65+
66+
```js
67+
new LazyCompileWebpackPlugin({
68+
ignores: [
69+
/\b(html|raw|to-string)-loader\b/,
70+
/\bexports-loader[^?]*\?exports\.toString\(\)/
71+
],
72+
});
73+
```
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./lib/plugin')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* eslint-env browser */
2+
let isBrowser = typeof window !== 'undefined'
3+
4+
let GLOBAL_ANIMATION_KEY = '__lazyCompileWebpackPlugin'
5+
6+
function noop () {}
7+
8+
// modified from https://matthewrayfield.com/articles/animating-urls-with-javascript-and-emojis
9+
let figures = [
10+
'🕐',
11+
'🕑',
12+
'🕒',
13+
'🕓',
14+
'🕔',
15+
'🕕',
16+
'🕖',
17+
'🕗',
18+
'🕘',
19+
'🕙',
20+
'🕚',
21+
'🕛',
22+
]
23+
24+
function startAnimation () {
25+
if (!isBrowser) return noop
26+
27+
if (window[GLOBAL_ANIMATION_KEY]) return noop
28+
29+
window[GLOBAL_ANIMATION_KEY] = true
30+
31+
let originTitle = document.title
32+
33+
let loopHandle
34+
35+
function animatioLoop () {
36+
loopHandle = setTimeout(animatioLoop, 50)
37+
document.title =
38+
`Compiling ${ figures[Math.floor((Date.now() / 100) % figures.length)]}`
39+
}
40+
animatioLoop()
41+
42+
return () => {
43+
window[GLOBAL_ANIMATION_KEY] = false
44+
clearTimeout(loopHandle)
45+
document.title = originTitle
46+
}
47+
}
48+
49+
function compile (endpoints, activationUrl) {
50+
let ready
51+
let prom = new Promise((resolve) => {
52+
ready = resolve
53+
if (!isBrowser) return
54+
55+
endpoints.forEach(function (endpoint) {
56+
let img = new Image()
57+
58+
img.src = activationUrl.replace('{host}', endpoint)
59+
})
60+
})
61+
62+
prom.ready = ready
63+
64+
return prom
65+
}
66+
67+
module.exports = {
68+
isBrowser,
69+
startAnimation,
70+
compile,
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const path = require('path')
2+
const loaderUtils = require('loader-utils')
3+
const apiPath = path.join(__dirname, 'api.js')
4+
5+
module.exports = function () {
6+
const { activationUrl, ips } = loaderUtils.getOptions(this) || {}
7+
8+
return `
9+
// @activationUrl ${activationUrl}
10+
11+
var api = require(${loaderUtils.stringifyRequest(this, `!!${apiPath}`)});
12+
api.compile(${JSON.stringify(ips)}, '${activationUrl}');
13+
14+
if (api.isBrowser) {
15+
setTimeout(function () {
16+
window.location.reload()
17+
}, 0)
18+
}
19+
`.trim()
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const path = require('path')
2+
const loaderUtils = require('loader-utils')
3+
const apiPath = path.join(__dirname, 'api.js')
4+
5+
module.exports = function () {
6+
const { activationUrl, ips, hmr } = loaderUtils.getOptions(this) || {}
7+
const hmrCode = `
8+
if (module.hot) {
9+
module.hot.dispose(function() {
10+
stopAnimation();
11+
12+
// wait for the module to install
13+
setTimeout(() => {
14+
// depressed warning: "unexpected require from disposed module"
15+
module.hot.active = true;
16+
compilation.ready(__webpack_require__(module.id));
17+
module.hot.active = false;
18+
}, 0);
19+
});
20+
module.hot.accept(function() {
21+
// error handle
22+
});
23+
}
24+
`.trim()
25+
26+
const refreshCode = `
27+
window.onbeforeunload = function() {
28+
stopAnimation();
29+
}
30+
`.trim()
31+
32+
return `
33+
//############################ NOTICE ############################//
34+
// //
35+
// This is a placeholder module generated by //
36+
// lazy-compile-webpack-plugin. //
37+
// https://github.com/liximomo/lazy-compile-webpack-plugin //
38+
// //
39+
// The real content is in the corresponding hot-update file. //
40+
// You won't see this after the page refresh. //
41+
// //
42+
//################################################################//
43+
44+
// @activationUrl ${activationUrl}
45+
46+
// modified from https://matthewrayfield.com/articles/animating-urls-with-javascript-and-emojis
47+
var api = require(${loaderUtils.stringifyRequest(this, `!!${apiPath}`)});
48+
var stopAnimation = api.startAnimation();
49+
var compilation = api.compile(${JSON.stringify(ips)}, '${activationUrl}');
50+
51+
${hmr ? hmrCode : refreshCode}
52+
53+
module.exports = {
54+
then(resolve) {
55+
resolve(compilation)
56+
}
57+
}
58+
`.trim()
59+
}

0 commit comments

Comments
 (0)