@jsenv/plugin-supervisor 1.4.1 → 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.
@@ -11,13 +11,17 @@ window.__supervisor__ = (() => {
11
11
  };
12
12
  const isWebkitOrSafari = typeof window.webkitConvertPointFromNodeToPage === "function";
13
13
  const executionResults = {};
14
- let documentExecutionStartTime;
14
+ let documentTimingsOrigin;
15
15
  try {
16
- documentExecutionStartTime = window.performance.timing.navigationStart;
16
+ documentTimingsOrigin = window.performance.timing.navigationStart;
17
17
  } catch (e) {
18
- documentExecutionStartTime = Date.now();
18
+ documentTimingsOrigin = Date.now();
19
19
  }
20
- let documentExecutionEndTime;
20
+ const documentTimings = {
21
+ origin: documentTimingsOrigin,
22
+ start: Date.now() - documentTimingsOrigin,
23
+ end: null
24
+ };
21
25
  supervisor.setup = ({
22
26
  rootDirectoryUrl,
23
27
  scriptInfos,
@@ -76,10 +80,13 @@ window.__supervisor__ = (() => {
76
80
  const createExecutionController = (src, type) => {
77
81
  const result = {
78
82
  status: "pending",
79
- duration: null,
80
83
  coverage: null,
81
84
  exception: null,
82
- value: null
85
+ value: null,
86
+ timings: {
87
+ start: null,
88
+ end: null
89
+ }
83
90
  };
84
91
  let resolve;
85
92
  const promise = new Promise(_resolve => {
@@ -88,7 +95,7 @@ window.__supervisor__ = (() => {
88
95
  promises.push(promise);
89
96
  executionResults[src] = result;
90
97
  const start = () => {
91
- result.duration = null;
98
+ result.timings.start = Date.now() - documentTimingsOrigin;
92
99
  result.coverage = null;
93
100
  result.status = "started";
94
101
  result.exception = null;
@@ -97,16 +104,15 @@ window.__supervisor__ = (() => {
97
104
  }
98
105
  };
99
106
  const end = () => {
100
- const now = Date.now();
101
107
  remainingScriptCount--;
102
- result.duration = now - documentExecutionStartTime;
108
+ result.timings.end = Date.now() - documentTimingsOrigin;
103
109
  result.coverage = window.__coverage__;
104
110
  if (logs) {
105
111
  console.log("execution ".concat(result.status));
106
112
  console.groupEnd();
107
113
  }
108
114
  if (remainingScriptCount === 0) {
109
- documentExecutionEndTime = now;
115
+ documentTimings.end = Date.now() - documentTimingsOrigin;
110
116
  }
111
117
  resolve();
112
118
  };
@@ -440,8 +446,7 @@ window.__supervisor__ = (() => {
440
446
  supervisor.getDocumentExecutionResult = async () => {
441
447
  await Promise.all(promises);
442
448
  return {
443
- startTime: documentExecutionStartTime,
444
- endTime: documentExecutionEndTime,
449
+ timings: documentTimings,
445
450
  status: "completed",
446
451
  executionResults
447
452
  };
@@ -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.1",
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": {
@@ -13,13 +13,18 @@ window.__supervisor__ = (() => {
13
13
  typeof window.webkitConvertPointFromNodeToPage === "function";
14
14
 
15
15
  const executionResults = {};
16
- let documentExecutionStartTime;
16
+ let documentTimingsOrigin;
17
17
  try {
18
- documentExecutionStartTime = window.performance.timing.navigationStart;
18
+ documentTimingsOrigin = window.performance.timing.navigationStart;
19
19
  } catch (e) {
20
- documentExecutionStartTime = Date.now();
20
+ documentTimingsOrigin = Date.now();
21
21
  }
22
- let documentExecutionEndTime;
22
+ const documentTimings = {
23
+ origin: documentTimingsOrigin,
24
+ start: Date.now() - documentTimingsOrigin,
25
+ end: null,
26
+ };
27
+
23
28
  supervisor.setup = ({
24
29
  rootDirectoryUrl,
25
30
  scriptInfos,
@@ -80,10 +85,13 @@ window.__supervisor__ = (() => {
80
85
  const createExecutionController = (src, type) => {
81
86
  const result = {
82
87
  status: "pending",
83
- duration: null,
84
88
  coverage: null,
85
89
  exception: null,
86
90
  value: null,
91
+ timings: {
92
+ start: null,
93
+ end: null,
94
+ },
87
95
  };
88
96
 
89
97
  let resolve;
@@ -94,7 +102,7 @@ window.__supervisor__ = (() => {
94
102
  executionResults[src] = result;
95
103
 
96
104
  const start = () => {
97
- result.duration = null;
105
+ result.timings.start = Date.now() - documentTimingsOrigin;
98
106
  result.coverage = null;
99
107
  result.status = "started";
100
108
  result.exception = null;
@@ -103,16 +111,15 @@ window.__supervisor__ = (() => {
103
111
  }
104
112
  };
105
113
  const end = () => {
106
- const now = Date.now();
107
114
  remainingScriptCount--;
108
- result.duration = now - documentExecutionStartTime;
115
+ result.timings.end = Date.now() - documentTimingsOrigin;
109
116
  result.coverage = window.__coverage__;
110
117
  if (logs) {
111
118
  console.log(`execution ${result.status}`);
112
119
  console.groupEnd();
113
120
  }
114
121
  if (remainingScriptCount === 0) {
115
- documentExecutionEndTime = now;
122
+ documentTimings.end = Date.now() - documentTimingsOrigin;
116
123
  }
117
124
  resolve();
118
125
  };
@@ -400,8 +407,7 @@ window.__supervisor__ = (() => {
400
407
  supervisor.getDocumentExecutionResult = async () => {
401
408
  await Promise.all(promises);
402
409
  return {
403
- startTime: documentExecutionStartTime,
404
- endTime: documentExecutionEndTime,
410
+ timings: documentTimings,
405
411
  status: "completed",
406
412
  executionResults,
407
413
  };
@@ -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,