Skip to content

Commit 8cd1e4c

Browse files
authored
chore: embed strip-ansi dependency (#4306)
1 parent 97bbfdd commit 8cd1e4c

File tree

8 files changed

+38
-21
lines changed

8 files changed

+38
-21
lines changed

client-src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* global __resourceQuery, __webpack_hash__ */
22
/// <reference types="webpack/module" />
33
import webpackHotLog from "webpack/hot/log.js";
4-
import stripAnsi from "./modules/strip-ansi/index.js";
4+
import stripAnsi from "./utils/stripAnsi.js";
55
import parseURL from "./utils/parseURL.js";
66
import socket from "./socket.js";
77
import { formatProblem, show, hide } from "./overlay.js";

client-src/modules/strip-ansi/index.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

client-src/utils/stripAnsi.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const ansiRegex = new RegExp(
2+
[
3+
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
4+
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
5+
].join("|"),
6+
"g"
7+
);
8+
9+
/**
10+
*
11+
* Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string.
12+
* Adapted from code originally released by Sindre Sorhus
13+
* Licensed the MIT License
14+
*
15+
* @param {string} string
16+
* @return {string}
17+
*/
18+
function stripAnsi(string) {
19+
if (typeof string !== "string") {
20+
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
21+
}
22+
23+
return string.replace(ansiRegex, "");
24+
}
25+
26+
export default stripAnsi;

client-src/webpack.config.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,6 @@ module.exports = [
7878
),
7979
],
8080
}),
81-
merge(baseForModules, {
82-
entry: path.join(__dirname, "modules/strip-ansi/index.js"),
83-
output: {
84-
// @ts-ignore
85-
filename: "strip-ansi/index.js",
86-
},
87-
}),
8881
merge(baseForModules, {
8982
entry: path.join(__dirname, "modules/sockjs-client/index.js"),
9083
output: {

package-lock.json

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
"serve-index": "^1.9.1",
6363
"sockjs": "^0.3.21",
6464
"spdy": "^4.0.2",
65-
"strip-ansi": "^7.0.0",
6665
"webpack-dev-middleware": "^5.3.1",
6766
"ws": "^8.4.2"
6867
},

test/client/index.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ describe("index", () => {
2727
},
2828
setLogLevel: jest.fn(),
2929
});
30-
jest.setMock("strip-ansi", require("strip-ansi-v6"));
3130

3231
log = require("../../client-src/utils/log");
3332

test/e2e/__snapshots__/multi-compiler.test.js.snap.webpack5

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ Array [
5555
"[HMR] Cannot apply update. Need to do a full reload!",
5656
"[HMR] Error: Aborted because ./browser.js is not accepted
5757
Update propagation: ./browser.js
58-
at applyHandler (http://127.0.0.1:8103/browser.js:1017:31)
59-
at http://127.0.0.1:8103/browser.js:717:21
58+
at applyHandler (http://127.0.0.1:8103/browser.js:1018:31)
59+
at http://127.0.0.1:8103/browser.js:718:21
6060
at Array.map (<anonymous>)
61-
at internalApply (http://127.0.0.1:8103/browser.js:716:54)
62-
at http://127.0.0.1:8103/browser.js:690:26
63-
at waitForBlockingPromises (http://127.0.0.1:8103/browser.js:643:55)
64-
at http://127.0.0.1:8103/browser.js:688:24",
61+
at internalApply (http://127.0.0.1:8103/browser.js:717:54)
62+
at http://127.0.0.1:8103/browser.js:691:26
63+
at waitForBlockingPromises (http://127.0.0.1:8103/browser.js:644:55)
64+
at http://127.0.0.1:8103/browser.js:689:24",
6565
"[HMR] Waiting for update signal from WDS...",
6666
"Hello from the browser",
6767
"[webpack-dev-server] Hot Module Replacement enabled.",

0 commit comments

Comments
 (0)