@jsenv/plugin-supervisor 1.4.2 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,9 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { fileURLToPath } from "node:url";
3
+ import "string-width";
4
+ import process$1 from "node:process";
5
+ import os from "node:os";
6
+ import tty from "node:tty";
3
7
  import { applyBabelPlugins, parseHtml, visitHtmlNodes, analyzeScriptNode, getHtmlNodeAttribute, getHtmlNodeText, injectHtmlNodeAsEarlyAsPossible, createHtmlNode, stringifyHtmlAst, getHtmlNodePosition, getUrlForContentInsideHtml, setHtmlNodeText, setHtmlNodeAttributes } from "@jsenv/ast";
4
8
 
5
9
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
@@ -44,8 +48,242 @@ const getOriginalPosition = ({
44
48
  return originalPosition;
45
49
  };
46
50
 
51
+ /* global window */
52
+ const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
53
+ !isBrowser && process$1.env.TERM_PROGRAM === 'Apple_Terminal';
54
+ !isBrowser && process$1.platform === 'win32';
55
+ isBrowser ? () => {
56
+ throw new Error('`process.cwd()` only works in Node.js, not the browser.');
57
+ } : process$1.cwd;
58
+
59
+ // From: https://github.com/sindresorhus/has-flag/blob/main/index.js
60
+ /// function hasFlag(flag, argv = globalThis.Deno?.args ?? process.argv) {
61
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process$1.argv) {
62
+ const prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
63
+ const position = argv.indexOf(prefix + flag);
64
+ const terminatorPosition = argv.indexOf('--');
65
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
66
+ }
67
+ const {
68
+ env
69
+ } = process$1;
70
+ let flagForceColor;
71
+ if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false') || hasFlag('color=never')) {
72
+ flagForceColor = 0;
73
+ } else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
74
+ flagForceColor = 1;
75
+ }
76
+ function envForceColor() {
77
+ if ('FORCE_COLOR' in env) {
78
+ if (env.FORCE_COLOR === 'true') {
79
+ return 1;
80
+ }
81
+ if (env.FORCE_COLOR === 'false') {
82
+ return 0;
83
+ }
84
+ return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
85
+ }
86
+ }
87
+ function translateLevel(level) {
88
+ if (level === 0) {
89
+ return false;
90
+ }
91
+ return {
92
+ level,
93
+ hasBasic: true,
94
+ has256: level >= 2,
95
+ has16m: level >= 3
96
+ };
97
+ }
98
+ function _supportsColor(haveStream, {
99
+ streamIsTTY,
100
+ sniffFlags = true
101
+ } = {}) {
102
+ const noFlagForceColor = envForceColor();
103
+ if (noFlagForceColor !== undefined) {
104
+ flagForceColor = noFlagForceColor;
105
+ }
106
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
107
+ if (forceColor === 0) {
108
+ return 0;
109
+ }
110
+ if (sniffFlags) {
111
+ if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
112
+ return 3;
113
+ }
114
+ if (hasFlag('color=256')) {
115
+ return 2;
116
+ }
117
+ }
118
+
119
+ // Check for Azure DevOps pipelines.
120
+ // Has to be above the `!streamIsTTY` check.
121
+ if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
122
+ return 1;
123
+ }
124
+ if (haveStream && !streamIsTTY && forceColor === undefined) {
125
+ return 0;
126
+ }
127
+ const min = forceColor || 0;
128
+ if (env.TERM === 'dumb') {
129
+ return min;
130
+ }
131
+ if (process$1.platform === 'win32') {
132
+ // Windows 10 build 10586 is the first Windows release that supports 256 colors.
133
+ // Windows 10 build 14931 is the first release that supports 16m/TrueColor.
134
+ const osRelease = os.release().split('.');
135
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
136
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
137
+ }
138
+ return 1;
139
+ }
140
+ if ('CI' in env) {
141
+ if ('GITHUB_ACTIONS' in env || 'GITEA_ACTIONS' in env) {
142
+ return 3;
143
+ }
144
+ if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
145
+ return 1;
146
+ }
147
+ return min;
148
+ }
149
+ if ('TEAMCITY_VERSION' in env) {
150
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
151
+ }
152
+ if (env.COLORTERM === 'truecolor') {
153
+ return 3;
154
+ }
155
+ if (env.TERM === 'xterm-kitty') {
156
+ return 3;
157
+ }
158
+ if ('TERM_PROGRAM' in env) {
159
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
160
+ switch (env.TERM_PROGRAM) {
161
+ case 'iTerm.app':
162
+ {
163
+ return version >= 3 ? 3 : 2;
164
+ }
165
+ case 'Apple_Terminal':
166
+ {
167
+ return 2;
168
+ }
169
+ // No default
170
+ }
171
+ }
172
+ if (/-256(color)?$/i.test(env.TERM)) {
173
+ return 2;
174
+ }
175
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
176
+ return 1;
177
+ }
178
+ if ('COLORTERM' in env) {
179
+ return 1;
180
+ }
181
+ return min;
182
+ }
183
+ function createSupportsColor(stream, options = {}) {
184
+ const level = _supportsColor(stream, {
185
+ streamIsTTY: stream && stream.isTTY,
186
+ ...options
187
+ });
188
+ return translateLevel(level);
189
+ }
190
+ ({
191
+ stdout: createSupportsColor({
192
+ isTTY: tty.isatty(1)
193
+ }),
194
+ stderr: createSupportsColor({
195
+ isTTY: tty.isatty(2)
196
+ })
197
+ });
198
+ const processSupportsBasicColor = createSupportsColor(process.stdout).hasBasic;
199
+ // https://github.com/Marak/colors.js/blob/master/lib/styles.js
200
+ // https://stackoverflow.com/a/75985833/2634179
201
+ const RESET = "\x1b[0m";
202
+ const ANSI = {
203
+ supported: processSupportsBasicColor,
204
+ RED: "\x1b[31m",
205
+ GREEN: "\x1b[32m",
206
+ YELLOW: "\x1b[33m",
207
+ BLUE: "\x1b[34m",
208
+ MAGENTA: "\x1b[35m",
209
+ GREY: "\x1b[90m",
210
+ color: (text, ANSI_COLOR) => {
211
+ return ANSI.supported ? "".concat(ANSI_COLOR).concat(text).concat(RESET) : text;
212
+ },
213
+ BOLD: "\x1b[1m",
214
+ effect: (text, ANSI_EFFECT) => {
215
+ return ANSI.supported ? "".concat(ANSI_EFFECT).concat(text).concat(RESET) : text;
216
+ }
217
+ };
218
+
219
+ // GitHub workflow does support ANSI but "supports-color" returns false
220
+ // because stream.isTTY returns false, see https://github.com/actions/runner/issues/241
221
+ if (process.env.GITHUB_WORKFLOW &&
222
+ // Check on FORCE_COLOR is to ensure it is prio over GitHub workflow check
223
+ // in unit test we use process.env.FORCE_COLOR = 'false' to fake
224
+ // that colors are not supported. Let it have priority
225
+ process.env.FORCE_COLOR !== "false") {
226
+ ANSI.supported = true;
227
+ }
228
+ function isUnicodeSupported() {
229
+ if (process$1.platform !== 'win32') {
230
+ return process$1.env.TERM !== 'linux'; // Linux console (kernel)
231
+ }
232
+ return Boolean(process$1.env.WT_SESSION) // Windows Terminal
233
+ || Boolean(process$1.env.TERMINUS_SUBLIME) // Terminus (<0.2.27)
234
+ || process$1.env.ConEmuTask === '{cmd::Cmder}' // ConEmu and cmder
235
+ || process$1.env.TERM_PROGRAM === 'Terminus-Sublime' || process$1.env.TERM_PROGRAM === 'vscode' || process$1.env.TERM === 'xterm-256color' || process$1.env.TERM === 'alacritty' || process$1.env.TERMINAL_EMULATOR === 'JetBrains-JediTerm';
236
+ }
237
+
238
+ // see also https://github.com/sindresorhus/figures
239
+
240
+ const UNICODE = {
241
+ supported: isUnicodeSupported(),
242
+ get COMMAND_RAW() {
243
+ return UNICODE.supported ? "\u276F" : ">";
244
+ },
245
+ get OK_RAW() {
246
+ return UNICODE.supported ? "\u2714" : "\u221A";
247
+ },
248
+ get FAILURE_RAW() {
249
+ return UNICODE.supported ? "\u2716" : "\xD7";
250
+ },
251
+ get DEBUG_RAW() {
252
+ return UNICODE.supported ? "\u25C6" : "\u2666";
253
+ },
254
+ get INFO_RAW() {
255
+ return UNICODE.supported ? "\u2139" : "i";
256
+ },
257
+ get WARNING_RAW() {
258
+ return UNICODE.supported ? "\u26A0" : "\u203C";
259
+ },
260
+ get CIRCLE_CROSS_RAW() {
261
+ return UNICODE.supported ? "\u24E7" : "(\xD7)";
262
+ },
263
+ get COMMAND() {
264
+ return ANSI.color(UNICODE.COMMAND_RAW, ANSI.GREY); // ANSI_MAGENTA)
265
+ },
266
+ get OK() {
267
+ return ANSI.color(UNICODE.OK_RAW, ANSI.GREEN);
268
+ },
269
+ get FAILURE() {
270
+ return ANSI.color(UNICODE.FAILURE_RAW, ANSI.RED);
271
+ },
272
+ get DEBUG() {
273
+ return ANSI.color(UNICODE.DEBUG_RAW, ANSI.GREY);
274
+ },
275
+ get INFO() {
276
+ return ANSI.color(UNICODE.INFO_RAW, ANSI.BLUE);
277
+ },
278
+ get WARNING() {
279
+ return ANSI.color(UNICODE.WARNING_RAW, ANSI.YELLOW);
280
+ },
281
+ get CIRCLE_CROSS() {
282
+ return ANSI.color(UNICODE.CIRCLE_CROSS_RAW, ANSI.RED);
283
+ }
284
+ };
47
285
  const formatDefault = v => v;
48
- const inspectFileContent = ({
286
+ const generateContentFrame = ({
49
287
  content,
50
288
  line,
51
289
  column,
@@ -955,7 +1193,7 @@ const jsenvPluginSupervisor = ({
955
1193
  url: file,
956
1194
  line,
957
1195
  column,
958
- codeFrame: inspectFileContent({
1196
+ codeFrame: generateContentFrame({
959
1197
  line,
960
1198
  column,
961
1199
  content: urlInfo.originalContent
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-supervisor",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,9 +26,9 @@
26
26
  "/dist/"
27
27
  ],
28
28
  "dependencies": {
29
- "@jsenv/ast": "6.0.2",
30
- "@jsenv/urls": "2.2.2",
31
- "@jsenv/sourcemap": "1.2.5",
29
+ "@jsenv/ast": "6.0.3",
30
+ "@jsenv/urls": "2.2.3",
31
+ "@jsenv/sourcemap": "1.2.6",
32
32
  "launch-editor": "2.6.1"
33
33
  },
34
34
  "scripts": {
@@ -6,7 +6,7 @@
6
6
  import { createRequire } from "node:module";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { getOriginalPosition } from "@jsenv/sourcemap";
9
- import { inspectFileContent } from "@jsenv/inspect";
9
+ import { generateContentFrame } from "@jsenv/humanize";
10
10
 
11
11
  import {
12
12
  supervisorFileUrl,
@@ -71,7 +71,7 @@ export const jsenvPluginSupervisor = ({
71
71
  url: file,
72
72
  line,
73
73
  column,
74
- codeFrame: inspectFileContent({
74
+ codeFrame: generateContentFrame({
75
75
  line,
76
76
  column,
77
77
  content: urlInfo.originalContent,