|
1 | 1 | /* global __resourceQuery, __webpack_hash__ */ |
2 | 2 | /// <reference types="webpack/module" /> |
3 | 3 | import webpackHotLog from "webpack/hot/log.js"; |
4 | | -import stripAnsi from "./utils/stripAnsi.js"; |
5 | 4 | import parseURL from "./utils/parseURL.js"; |
6 | 5 | import socket from "./socket.js"; |
7 | 6 | import { formatProblem, createOverlay } from "./overlay.js"; |
@@ -165,6 +164,31 @@ const overlay = |
165 | 164 | ) |
166 | 165 | : { send: () => {} }; |
167 | 166 |
|
| 167 | +const ansiRegex = new RegExp( |
| 168 | + [ |
| 169 | + "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", |
| 170 | + "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))", |
| 171 | + ].join("|"), |
| 172 | + "g", |
| 173 | +); |
| 174 | + |
| 175 | +/** |
| 176 | + * |
| 177 | + * Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string. |
| 178 | + * Adapted from code originally released by Sindre Sorhus |
| 179 | + * Licensed the MIT License |
| 180 | + * |
| 181 | + * @param {string} string |
| 182 | + * @return {string} |
| 183 | + */ |
| 184 | +const stripAnsi = (string) => { |
| 185 | + if (typeof string !== "string") { |
| 186 | + throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``); |
| 187 | + } |
| 188 | + |
| 189 | + return string.replace(ansiRegex, ""); |
| 190 | +}; |
| 191 | + |
168 | 192 | const onSocketMessage = { |
169 | 193 | hot() { |
170 | 194 | if (parsedResourceQuery.hot === "false") { |
|
0 commit comments