MCPcopy Create free account
hub / github.com/webpack/webpack-cli / runWatch

Function runWatch

test/utils/test-utils.js:78–133  ·  view source on GitHub ↗
(cwd, args = [], options = {})

Source from the content-addressed store, hash-verified

76 * @returns {Promise<import("execa").Result>} The webpack output or Promise when nodeOptions are present
77 */
78const runWatch = async (cwd, args = [], options = {}) => {
79 const execa = await import("execa");
80 const process = createProcess(execa, cwd, args, options);
81 const outputKillStr = options.killString || /webpack \d+\.\d+\.\d/;
82 const { stdoutKillStr } = options;
83 const { stderrKillStr } = options;
84
85 let isStdoutDone = false;
86 let isStderrDone = false;
87
88 if (options.handler) {
89 options.handler(process);
90 } else {
91 process.stdout.pipe(
92 new Writable({
93 write(chunk, encoding, callback) {
94 const output = stripVTControlCharacters(chunk.toString("utf8"));
95
96 if (stdoutKillStr && stdoutKillStr.test(output)) {
97 isStdoutDone = true;
98 } else if (!stdoutKillStr && outputKillStr.test(output)) {
99 processKill(process);
100 }
101
102 if (isStdoutDone && isStderrDone) {
103 processKill(process);
104 }
105
106 callback();
107 },
108 }),
109 );
110
111 process.stderr.pipe(
112 new Writable({
113 write(chunk, encoding, callback) {
114 const output = stripVTControlCharacters(chunk.toString("utf8"));
115
116 if (stderrKillStr && stderrKillStr.test(output)) {
117 isStderrDone = true;
118 } else if (!stderrKillStr && outputKillStr.test(output)) {
119 processKill(process);
120 }
121
122 if (isStdoutDone && isStderrDone) {
123 processKill(process);
124 }
125
126 callback();
127 },
128 }),
129 );
130 }
131
132 return process;
133};
134
135/**

Callers 9

bail.test.jsFile · 0.50
basic.test.jsFile · 0.50
stdin.test.jsFile · 0.50

Calls 1

createProcessFunction · 0.85

Tested by

no test coverage detected