Skip to content

Commit

Permalink
chore: embed strip-ansi dependency (webpack#4306)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludofischer authored Feb 22, 2022
1 parent 97bbfdd commit 8cd1e4c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 21 deletions.
2 changes: 1 addition & 1 deletion client-src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global __resourceQuery, __webpack_hash__ */
/// <reference types="webpack/module" />
import webpackHotLog from "webpack/hot/log.js";
import stripAnsi from "./modules/strip-ansi/index.js";
import stripAnsi from "./utils/stripAnsi.js";
import parseURL from "./utils/parseURL.js";
import socket from "./socket.js";
import { formatProblem, show, hide } from "./overlay.js";
Expand Down
3 changes: 0 additions & 3 deletions client-src/modules/strip-ansi/index.js

This file was deleted.

26 changes: 26 additions & 0 deletions client-src/utils/stripAnsi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const ansiRegex = new RegExp(
[
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
].join("|"),
"g"
);

/**
*
* Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string.
* Adapted from code originally released by Sindre Sorhus
* Licensed the MIT License
*
* @param {string} string
* @return {string}
*/
function stripAnsi(string) {
if (typeof string !== "string") {
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
}

return string.replace(ansiRegex, "");
}

export default stripAnsi;
7 changes: 0 additions & 7 deletions client-src/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ module.exports = [
),
],
}),
merge(baseForModules, {
entry: path.join(__dirname, "modules/strip-ansi/index.js"),
output: {
// @ts-ignore
filename: "strip-ansi/index.js",
},
}),
merge(baseForModules, {
entry: path.join(__dirname, "modules/sockjs-client/index.js"),
output: {
Expand Down
7 changes: 5 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"serve-index": "^1.9.1",
"sockjs": "^0.3.21",
"spdy": "^4.0.2",
"strip-ansi": "^7.0.0",
"webpack-dev-middleware": "^5.3.1",
"ws": "^8.4.2"
},
Expand Down
1 change: 0 additions & 1 deletion test/client/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe("index", () => {
},
setLogLevel: jest.fn(),
});
jest.setMock("strip-ansi", require("strip-ansi-v6"));

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

Expand Down
12 changes: 6 additions & 6 deletions test/e2e/__snapshots__/multi-compiler.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ Array [
"[HMR] Cannot apply update. Need to do a full reload!",
"[HMR] Error: Aborted because ./browser.js is not accepted
Update propagation: ./browser.js
at applyHandler (http://127.0.0.1:8103/browser.js:1017:31)
at http://127.0.0.1:8103/browser.js:717:21
at applyHandler (http://127.0.0.1:8103/browser.js:1018:31)
at http://127.0.0.1:8103/browser.js:718:21
at Array.map (<anonymous>)
at internalApply (http://127.0.0.1:8103/browser.js:716:54)
at http://127.0.0.1:8103/browser.js:690:26
at waitForBlockingPromises (http://127.0.0.1:8103/browser.js:643:55)
at http://127.0.0.1:8103/browser.js:688:24",
at internalApply (http://127.0.0.1:8103/browser.js:717:54)
at http://127.0.0.1:8103/browser.js:691:26
at waitForBlockingPromises (http://127.0.0.1:8103/browser.js:644:55)
at http://127.0.0.1:8103/browser.js:689:24",
"[HMR] Waiting for update signal from WDS...",
"Hello from the browser",
"[webpack-dev-server] Hot Module Replacement enabled.",
Expand Down

0 comments on commit 8cd1e4c

Please sign in to comment.