diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2020-07-22 12:03:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-22 12:03:46 -0400 |
commit | bf9930066d3a5d26baad22fb1766de26be49c2ae (patch) | |
tree | e6176c72fdf2d89bb3e45855aba03d8a535b599c /cli/tsc/01_colors.js | |
parent | 9d13b539b5dfc96e2b5a0e89fc8e0312d6500fff (diff) |
Reduce size of TypeScript Compiler snapshot (#6809)
This PR is intentionally ugly. It duplicates all of the code in cli/js2/ into
cli/tsc/ ... because it's very important that we all understand that this code
is unnecessarily duplicated in our binary. I hope this ugliness provides the
motivation to clean it up.
The typescript git submodule is removed, because it's a very large repo and
contains all sorts of stuff we don't need. Instead the necessary files are
copied directly into the deno repo. Hence +200k lines.
COMPILER_SNAPSHOT.bin size
```
master 3448139
this branch 3320972
```
Fixes #6812
Diffstat (limited to 'cli/tsc/01_colors.js')
-rw-r--r-- | cli/tsc/01_colors.js | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/cli/tsc/01_colors.js b/cli/tsc/01_colors.js new file mode 100644 index 000000000..2dc559186 --- /dev/null +++ b/cli/tsc/01_colors.js @@ -0,0 +1,89 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +((window) => { + function code(open, close) { + return { + open: `\x1b[${open}m`, + close: `\x1b[${close}m`, + regexp: new RegExp(`\\x1b\\[${close}m`, "g"), + }; + } + + function run(str, code) { + return !globalThis || !globalThis.Deno || globalThis.Deno.noColor + ? str + : `${code.open}${str.replace(code.regexp, code.open)}${code.close}`; + } + + function bold(str) { + return run(str, code(1, 22)); + } + + function italic(str) { + return run(str, code(3, 23)); + } + + function yellow(str) { + return run(str, code(33, 39)); + } + + function cyan(str) { + return run(str, code(36, 39)); + } + + function red(str) { + return run(str, code(31, 39)); + } + + function green(str) { + return run(str, code(32, 39)); + } + + function bgRed(str) { + return run(str, code(41, 49)); + } + + function white(str) { + return run(str, code(37, 39)); + } + + function gray(str) { + return run(str, code(90, 39)); + } + + function magenta(str) { + return run(str, code(35, 39)); + } + + function dim(str) { + return run(str, code(2, 22)); + } + + // https://github.com/chalk/ansi-regex/blob/2b56fb0c7a07108e5b54241e8faec160d393aedb/index.js + const ANSI_PATTERN = new RegExp( + [ + "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", + "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", + ].join("|"), + "g", + ); + + function stripColor(string) { + return string.replace(ANSI_PATTERN, ""); + } + + window.__bootstrap.colors = { + bold, + italic, + yellow, + cyan, + red, + green, + bgRed, + white, + gray, + magenta, + dim, + stripColor, + }; +})(this); |