chore(core): replace wait-on dependency with custom lighter code (#9547)

This commit is contained in:
Nick Gerleman 2023-11-20 08:45:01 -08:00 committed by GitHub
parent 7dcad0c632
commit 424ffd2e29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 48 deletions

View file

@ -97,7 +97,6 @@
"tslib": "^2.6.0", "tslib": "^2.6.0",
"update-notifier": "^6.0.2", "update-notifier": "^6.0.2",
"url-loader": "^4.1.1", "url-loader": "^4.1.1",
"wait-on": "^7.0.1",
"webpack": "^5.88.1", "webpack": "^5.88.1",
"webpack-bundle-analyzer": "^4.9.0", "webpack-bundle-analyzer": "^4.9.0",
"webpack-dev-server": "^4.15.1", "webpack-dev-server": "^4.15.1",
@ -113,7 +112,6 @@
"@types/rtl-detect": "^1.0.0", "@types/rtl-detect": "^1.0.0",
"@types/serve-handler": "^6.1.1", "@types/serve-handler": "^6.1.1",
"@types/update-notifier": "^6.0.4", "@types/update-notifier": "^6.0.4",
"@types/wait-on": "^5.3.1",
"@types/webpack-bundle-analyzer": "^4.6.0", "@types/webpack-bundle-analyzer": "^4.6.0",
"react-test-renderer": "^18.0.0", "react-test-renderer": "^18.0.0",
"tmp-promise": "^3.0.3", "tmp-promise": "^3.0.3",

View file

@ -5,9 +5,7 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import path from 'path';
import fs from 'fs-extra'; import fs from 'fs-extra';
import waitOn from 'wait-on';
import type {Compiler} from 'webpack'; import type {Compiler} from 'webpack';
type WaitPluginOptions = { type WaitPluginOptions = {
@ -23,21 +21,36 @@ export default class WaitPlugin {
apply(compiler: Compiler): void { apply(compiler: Compiler): void {
// Before finishing the compilation step // Before finishing the compilation step
compiler.hooks.make.tapAsync('WaitPlugin', (compilation, callback) => { compiler.hooks.make.tapPromise('WaitPlugin', () => waitOn(this.filepath));
// To prevent 'waitFile' error on waiting non-existing directory }
fs.ensureDir(path.dirname(this.filepath), {}, () => { }
// Wait until file exist
waitOn({ // This is a re-implementation of the algorithm used by the "wait-on" package
resources: [this.filepath], // https://github.com/jeffbski/wait-on/blob/master/lib/wait-on.js#L200
interval: 300, async function waitOn(filepath: string): Promise<void> {
}) const pollingIntervalMs = 300;
.then(() => { const stabilityWindowMs = 750;
callback();
}) let lastFileSize = -1;
.catch((error: Error) => { let lastFileTime = -1;
console.warn(`WaitPlugin error: ${error}`);
}); for (;;) {
}); let size = -1;
try {
size = (await fs.stat(filepath)).size;
} catch (err) {}
if (size !== -1) {
if (lastFileTime === -1 || size !== lastFileSize) {
lastFileSize = size;
lastFileTime = performance.now();
} else if (performance.now() - lastFileTime >= stabilityWindowMs) {
return;
}
}
await new Promise((resolve) => {
setTimeout(resolve, pollingIntervalMs);
}); });
} }
} }

View file

@ -3691,13 +3691,6 @@
"@types/configstore" "*" "@types/configstore" "*"
boxen "^7.0.0" boxen "^7.0.0"
"@types/wait-on@^5.3.1":
version "5.3.1"
resolved "https://registry.yarnpkg.com/@types/wait-on/-/wait-on-5.3.1.tgz#bc5520d1d8b90b9caab1bef23315685ded73320d"
integrity sha512-2FFOKCF/YydrMUaqg+fkk49qf0e5rDgwt6aQsMzFQzbS419h2gNOXyiwp/o2yYy27bi/C1z+HgfncryjGzlvgQ==
dependencies:
"@types/node" "*"
"@types/webpack-bundle-analyzer@^4.6.0": "@types/webpack-bundle-analyzer@^4.6.0":
version "4.6.0" version "4.6.0"
resolved "https://registry.yarnpkg.com/@types/webpack-bundle-analyzer/-/webpack-bundle-analyzer-4.6.0.tgz#8863d62d2432126c2b3a9239cafa469215981c24" resolved "https://registry.yarnpkg.com/@types/webpack-bundle-analyzer/-/webpack-bundle-analyzer-4.6.0.tgz#8863d62d2432126c2b3a9239cafa469215981c24"
@ -4461,14 +4454,6 @@ axe-core@^4.6.2:
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.7.2.tgz#040a7342b20765cb18bb50b628394c21bccc17a0" resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.7.2.tgz#040a7342b20765cb18bb50b628394c21bccc17a0"
integrity sha512-zIURGIS1E1Q4pcrMjp+nnEh+16G56eG/MUllJH8yEvw7asDo7Ac9uhC9KIH5jzpITueEZolfYglnCGIuSBz39g== integrity sha512-zIURGIS1E1Q4pcrMjp+nnEh+16G56eG/MUllJH8yEvw7asDo7Ac9uhC9KIH5jzpITueEZolfYglnCGIuSBz39g==
axios@^0.27.2:
version "0.27.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972"
integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==
dependencies:
follow-redirects "^1.14.9"
form-data "^4.0.0"
axios@^1, axios@^1.0.0, axios@^1.5.0: axios@^1, axios@^1.0.0, axios@^1.5.0:
version "1.5.1" version "1.5.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.5.1.tgz#11fbaa11fc35f431193a9564109c88c1f27b585f" resolved "https://registry.yarnpkg.com/axios/-/axios-1.5.1.tgz#11fbaa11fc35f431193a9564109c88c1f27b585f"
@ -7776,7 +7761,7 @@ flux@~4.0.1:
fbemitter "^3.0.0" fbemitter "^3.0.0"
fbjs "^3.0.1" fbjs "^3.0.1"
follow-redirects@^1.0.0, follow-redirects@^1.14.9, follow-redirects@^1.15.0: follow-redirects@^1.0.0, follow-redirects@^1.15.0:
version "1.15.2" version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
@ -9958,7 +9943,7 @@ jkroso-type@1:
resolved "https://registry.yarnpkg.com/jkroso-type/-/jkroso-type-1.1.1.tgz#bc4ced6d6c45fe0745282bafc86a9f8c4fc9ce61" resolved "https://registry.yarnpkg.com/jkroso-type/-/jkroso-type-1.1.1.tgz#bc4ced6d6c45fe0745282bafc86a9f8c4fc9ce61"
integrity sha512-zZgay+fPG6PgMUrpyFADmQmvLo39+AZa7Gc5pZhev2RhDxwANEq2etwD8d0e6rTg5NkwOIlQmaEmns3draC6Ng== integrity sha512-zZgay+fPG6PgMUrpyFADmQmvLo39+AZa7Gc5pZhev2RhDxwANEq2etwD8d0e6rTg5NkwOIlQmaEmns3draC6Ng==
joi@^17.7.0, joi@^17.9.2: joi@^17.9.2:
version "17.9.2" version "17.9.2"
resolved "https://registry.yarnpkg.com/joi/-/joi-17.9.2.tgz#8b2e4724188369f55451aebd1d0b1d9482470690" resolved "https://registry.yarnpkg.com/joi/-/joi-17.9.2.tgz#8b2e4724188369f55451aebd1d0b1d9482470690"
integrity sha512-Itk/r+V4Dx0V3c7RLFdRh12IOjySm2/WGPMubBT92cQvRfYZhPM2W0hZlctjj72iES8jsRCwp7S/cRmWBnJ4nw== integrity sha512-Itk/r+V4Dx0V3c7RLFdRh12IOjySm2/WGPMubBT92cQvRfYZhPM2W0hZlctjj72iES8jsRCwp7S/cRmWBnJ4nw==
@ -11804,7 +11789,7 @@ minimist-options@4.1.0:
is-plain-obj "^1.1.0" is-plain-obj "^1.1.0"
kind-of "^6.0.3" kind-of "^6.0.3"
minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5, minimist@^1.2.6, minimist@^1.2.7: minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5, minimist@^1.2.6:
version "1.2.8" version "1.2.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA== integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==
@ -16574,17 +16559,6 @@ w3c-xmlserializer@^4.0.0:
dependencies: dependencies:
xml-name-validator "^4.0.0" xml-name-validator "^4.0.0"
wait-on@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/wait-on/-/wait-on-7.0.1.tgz#5cff9f8427e94f4deacbc2762e6b0a489b19eae9"
integrity sha512-9AnJE9qTjRQOlTZIldAaf/da2eW0eSRSgcqq85mXQja/DW3MriHxkpODDSUEg+Gri/rKEcXUZHe+cevvYItaog==
dependencies:
axios "^0.27.2"
joi "^17.7.0"
lodash "^4.17.21"
minimist "^1.2.7"
rxjs "^7.8.0"
walk-up-path@^1.0.0: walk-up-path@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/walk-up-path/-/walk-up-path-1.0.0.tgz#d4745e893dd5fd0dbb58dd0a4c6a33d9c9fec53e" resolved "https://registry.yarnpkg.com/walk-up-path/-/walk-up-path-1.0.0.tgz#d4745e893dd5fd0dbb58dd0a4c6a33d9c9fec53e"