mirror of
https://github.com/facebook/docusaurus.git
synced 2025-12-26 01:33:02 +00:00
refactor(core): remove useless Webpack wait plugin (#10579)
Some checks failed
Argos CI / take-screenshots (push) Has been cancelled
Build Hash Router / Build Hash Router (push) Has been cancelled
Canary Release / Publish Canary (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Continuous Releases / Continuous Releases (push) Has been cancelled
E2E Tests / E2E — Yarn v1 (18.0) (push) Has been cancelled
E2E Tests / E2E — Yarn v1 (20) (push) Has been cancelled
E2E Tests / E2E — Yarn v1 (22) (push) Has been cancelled
E2E Tests / E2E — Yarn Berry (node-modules, -s) (push) Has been cancelled
E2E Tests / E2E — Yarn Berry (node-modules, -st) (push) Has been cancelled
E2E Tests / E2E — Yarn Berry (pnp, -s) (push) Has been cancelled
E2E Tests / E2E — Yarn Berry (pnp, -st) (push) Has been cancelled
E2E Tests / E2E — npm (push) Has been cancelled
E2E Tests / E2E — pnpm (push) Has been cancelled
Some checks failed
Argos CI / take-screenshots (push) Has been cancelled
Build Hash Router / Build Hash Router (push) Has been cancelled
Canary Release / Publish Canary (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Continuous Releases / Continuous Releases (push) Has been cancelled
E2E Tests / E2E — Yarn v1 (18.0) (push) Has been cancelled
E2E Tests / E2E — Yarn v1 (20) (push) Has been cancelled
E2E Tests / E2E — Yarn v1 (22) (push) Has been cancelled
E2E Tests / E2E — Yarn Berry (node-modules, -s) (push) Has been cancelled
E2E Tests / E2E — Yarn Berry (node-modules, -st) (push) Has been cancelled
E2E Tests / E2E — Yarn Berry (pnp, -s) (push) Has been cancelled
E2E Tests / E2E — Yarn Berry (pnp, -st) (push) Has been cancelled
E2E Tests / E2E — npm (push) Has been cancelled
E2E Tests / E2E — pnpm (push) Has been cancelled
This commit is contained in:
parent
74c09aee35
commit
97e6c42099
|
|
@ -1,56 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import type {Compiler} from 'webpack';
|
||||
|
||||
type WaitPluginOptions = {
|
||||
filepath: string;
|
||||
};
|
||||
|
||||
export default class WaitPlugin {
|
||||
filepath: string;
|
||||
|
||||
constructor(options: WaitPluginOptions) {
|
||||
this.filepath = options.filepath;
|
||||
}
|
||||
|
||||
apply(compiler: Compiler): void {
|
||||
// Before finishing the compilation step
|
||||
compiler.hooks.make.tapPromise('WaitPlugin', () => waitOn(this.filepath));
|
||||
}
|
||||
}
|
||||
|
||||
// This is a re-implementation of the algorithm used by the "wait-on" package
|
||||
// https://github.com/jeffbski/wait-on/blob/master/lib/wait-on.js#L200
|
||||
async function waitOn(filepath: string): Promise<void> {
|
||||
const pollingIntervalMs = 300;
|
||||
const stabilityWindowMs = 750;
|
||||
|
||||
let lastFileSize = -1;
|
||||
let lastFileTime = -1;
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue