(cwd, args = [], options = {})
| 76 | * @returns {Promise<import("execa").Result>} The webpack output or Promise when nodeOptions are present |
| 77 | */ |
| 78 | const 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 | /** |
no test coverage detected