@jsenv/plugin-supervisor 1.4.2 → 1.4.4

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.
@@ -642,7 +642,7 @@ window.__supervisor__ = (() => {
642
642
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
643
643
  }
644
644
  // firefox
645
- if (exception.message.startsWith("import not found:") || exception.message.startsWith("ambiguous indirect export:")) {
645
+ if (exception.message.startsWith("import not found:") || exception.message.startsWith("ambiguous indirect export:") || exception.message.includes("doesn't provide an export named:")) {
646
646
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
647
647
  }
648
648
  // safari
@@ -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,266 @@ const getOriginalPosition = ({
44
48
  return originalPosition;
45
49
  };
46
50
 
51
+ /* globals WorkerGlobalScope, DedicatedWorkerGlobalScope, SharedWorkerGlobalScope, ServiceWorkerGlobalScope */
52
+
53
+ const isBrowser = globalThis.window?.document !== undefined;
54
+ globalThis.process?.versions?.node !== undefined;
55
+ globalThis.process?.versions?.bun !== undefined;
56
+ globalThis.Deno?.version?.deno !== undefined;
57
+ globalThis.process?.versions?.electron !== undefined;
58
+ globalThis.navigator?.userAgent?.includes('jsdom') === true;
59
+ typeof WorkerGlobalScope !== 'undefined' && globalThis instanceof WorkerGlobalScope;
60
+ typeof DedicatedWorkerGlobalScope !== 'undefined' && globalThis instanceof DedicatedWorkerGlobalScope;
61
+ typeof SharedWorkerGlobalScope !== 'undefined' && globalThis instanceof SharedWorkerGlobalScope;
62
+ typeof ServiceWorkerGlobalScope !== 'undefined' && globalThis instanceof ServiceWorkerGlobalScope;
63
+
64
+ // Note: I'm intentionally not DRYing up the other variables to keep them "lazy".
65
+ const platform = globalThis.navigator?.userAgentData?.platform;
66
+ platform === 'macOS' || globalThis.navigator?.platform === 'MacIntel' // Even on Apple silicon Macs.
67
+ || globalThis.navigator?.userAgent?.includes(' Mac ') === true || globalThis.process?.platform === 'darwin';
68
+ platform === 'Windows' || globalThis.navigator?.platform === 'Win32' || globalThis.process?.platform === 'win32';
69
+ platform === 'Linux' || globalThis.navigator?.platform?.startsWith('Linux') === true || globalThis.navigator?.userAgent?.includes(' Linux ') === true || globalThis.process?.platform === 'linux';
70
+ platform === 'Android' || globalThis.navigator?.platform === 'Android' || globalThis.navigator?.userAgent?.includes(' Android ') === true || globalThis.process?.platform === 'android';
71
+ !isBrowser && process$1.env.TERM_PROGRAM === 'Apple_Terminal';
72
+ !isBrowser && process$1.platform === 'win32';
73
+ isBrowser ? () => {
74
+ throw new Error('`process.cwd()` only works in Node.js, not the browser.');
75
+ } : process$1.cwd;
76
+
77
+ // From: https://github.com/sindresorhus/has-flag/blob/main/index.js
78
+ /// function hasFlag(flag, argv = globalThis.Deno?.args ?? process.argv) {
79
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process$1.argv) {
80
+ const prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
81
+ const position = argv.indexOf(prefix + flag);
82
+ const terminatorPosition = argv.indexOf('--');
83
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
84
+ }
85
+ const {
86
+ env
87
+ } = process$1;
88
+ let flagForceColor;
89
+ if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false') || hasFlag('color=never')) {
90
+ flagForceColor = 0;
91
+ } else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
92
+ flagForceColor = 1;
93
+ }
94
+ function envForceColor() {
95
+ if ('FORCE_COLOR' in env) {
96
+ if (env.FORCE_COLOR === 'true') {
97
+ return 1;
98
+ }
99
+ if (env.FORCE_COLOR === 'false') {
100
+ return 0;
101
+ }
102
+ return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
103
+ }
104
+ }
105
+ function translateLevel(level) {
106
+ if (level === 0) {
107
+ return false;
108
+ }
109
+ return {
110
+ level,
111
+ hasBasic: true,
112
+ has256: level >= 2,
113
+ has16m: level >= 3
114
+ };
115
+ }
116
+ function _supportsColor(haveStream, {
117
+ streamIsTTY,
118
+ sniffFlags = true
119
+ } = {}) {
120
+ const noFlagForceColor = envForceColor();
121
+ if (noFlagForceColor !== undefined) {
122
+ flagForceColor = noFlagForceColor;
123
+ }
124
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
125
+ if (forceColor === 0) {
126
+ return 0;
127
+ }
128
+ if (sniffFlags) {
129
+ if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
130
+ return 3;
131
+ }
132
+ if (hasFlag('color=256')) {
133
+ return 2;
134
+ }
135
+ }
136
+
137
+ // Check for Azure DevOps pipelines.
138
+ // Has to be above the `!streamIsTTY` check.
139
+ if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
140
+ return 1;
141
+ }
142
+ if (haveStream && !streamIsTTY && forceColor === undefined) {
143
+ return 0;
144
+ }
145
+ const min = forceColor || 0;
146
+ if (env.TERM === 'dumb') {
147
+ return min;
148
+ }
149
+ if (process$1.platform === 'win32') {
150
+ // Windows 10 build 10586 is the first Windows release that supports 256 colors.
151
+ // Windows 10 build 14931 is the first release that supports 16m/TrueColor.
152
+ const osRelease = os.release().split('.');
153
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
154
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
155
+ }
156
+ return 1;
157
+ }
158
+ if ('CI' in env) {
159
+ if ('GITHUB_ACTIONS' in env || 'GITEA_ACTIONS' in env) {
160
+ return 3;
161
+ }
162
+ if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
163
+ return 1;
164
+ }
165
+ return min;
166
+ }
167
+ if ('TEAMCITY_VERSION' in env) {
168
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
169
+ }
170
+ if (env.COLORTERM === 'truecolor') {
171
+ return 3;
172
+ }
173
+ if (env.TERM === 'xterm-kitty') {
174
+ return 3;
175
+ }
176
+ if ('TERM_PROGRAM' in env) {
177
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
178
+ switch (env.TERM_PROGRAM) {
179
+ case 'iTerm.app':
180
+ {
181
+ return version >= 3 ? 3 : 2;
182
+ }
183
+ case 'Apple_Terminal':
184
+ {
185
+ return 2;
186
+ }
187
+ // No default
188
+ }
189
+ }
190
+ if (/-256(color)?$/i.test(env.TERM)) {
191
+ return 2;
192
+ }
193
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
194
+ return 1;
195
+ }
196
+ if ('COLORTERM' in env) {
197
+ return 1;
198
+ }
199
+ return min;
200
+ }
201
+ function createSupportsColor(stream, options = {}) {
202
+ const level = _supportsColor(stream, {
203
+ streamIsTTY: stream && stream.isTTY,
204
+ ...options
205
+ });
206
+ return translateLevel(level);
207
+ }
208
+ ({
209
+ stdout: createSupportsColor({
210
+ isTTY: tty.isatty(1)
211
+ }),
212
+ stderr: createSupportsColor({
213
+ isTTY: tty.isatty(2)
214
+ })
215
+ });
216
+ const processSupportsBasicColor = createSupportsColor(process.stdout).hasBasic;
217
+ // https://github.com/Marak/colors.js/blob/master/lib/styles.js
218
+ // https://stackoverflow.com/a/75985833/2634179
219
+ const RESET = "\x1b[0m";
220
+ const ANSI = {
221
+ supported: processSupportsBasicColor,
222
+ RED: "\x1b[31m",
223
+ GREEN: "\x1b[32m",
224
+ YELLOW: "\x1b[33m",
225
+ BLUE: "\x1b[34m",
226
+ MAGENTA: "\x1b[35m",
227
+ CYAN: "\x1b[36m",
228
+ GREY: "\x1b[90m",
229
+ color: (text, ANSI_COLOR) => {
230
+ return ANSI.supported && ANSI_COLOR ? "".concat(ANSI_COLOR).concat(text).concat(RESET) : text;
231
+ },
232
+ BOLD: "\x1b[1m",
233
+ UNDERLINE: "\x1b[4m",
234
+ STRIKE: "\x1b[9m",
235
+ effect: (text, ANSI_EFFECT) => {
236
+ return ANSI.supported && ANSI_EFFECT ? "".concat(ANSI_EFFECT).concat(text).concat(RESET) : text;
237
+ }
238
+ };
239
+
240
+ // GitHub workflow does support ANSI but "supports-color" returns false
241
+ // because stream.isTTY returns false, see https://github.com/actions/runner/issues/241
242
+ if (process.env.GITHUB_WORKFLOW &&
243
+ // Check on FORCE_COLOR is to ensure it is prio over GitHub workflow check
244
+ // in unit test we use process.env.FORCE_COLOR = 'false' to fake
245
+ // that colors are not supported. Let it have priority
246
+ process.env.FORCE_COLOR !== "false") {
247
+ ANSI.supported = true;
248
+ }
249
+ function isUnicodeSupported() {
250
+ if (process$1.platform !== 'win32') {
251
+ return process$1.env.TERM !== 'linux'; // Linux console (kernel)
252
+ }
253
+ return Boolean(process$1.env.WT_SESSION) // Windows Terminal
254
+ || Boolean(process$1.env.TERMINUS_SUBLIME) // Terminus (<0.2.27)
255
+ || process$1.env.ConEmuTask === '{cmd::Cmder}' // ConEmu and cmder
256
+ || 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';
257
+ }
258
+
259
+ // see also https://github.com/sindresorhus/figures
260
+
261
+ const UNICODE = {
262
+ supported: isUnicodeSupported(),
263
+ get COMMAND_RAW() {
264
+ return UNICODE.supported ? "\u276F" : ">";
265
+ },
266
+ get OK_RAW() {
267
+ return UNICODE.supported ? "\u2714" : "\u221A";
268
+ },
269
+ get FAILURE_RAW() {
270
+ return UNICODE.supported ? "\u2716" : "\xD7";
271
+ },
272
+ get DEBUG_RAW() {
273
+ return UNICODE.supported ? "\u25C6" : "\u2666";
274
+ },
275
+ get INFO_RAW() {
276
+ return UNICODE.supported ? "\u2139" : "i";
277
+ },
278
+ get WARNING_RAW() {
279
+ return UNICODE.supported ? "\u26A0" : "\u203C";
280
+ },
281
+ get CIRCLE_CROSS_RAW() {
282
+ return UNICODE.supported ? "\u24E7" : "(\xD7)";
283
+ },
284
+ get COMMAND() {
285
+ return ANSI.color(UNICODE.COMMAND_RAW, ANSI.GREY); // ANSI_MAGENTA)
286
+ },
287
+ get OK() {
288
+ return ANSI.color(UNICODE.OK_RAW, ANSI.GREEN);
289
+ },
290
+ get FAILURE() {
291
+ return ANSI.color(UNICODE.FAILURE_RAW, ANSI.RED);
292
+ },
293
+ get DEBUG() {
294
+ return ANSI.color(UNICODE.DEBUG_RAW, ANSI.GREY);
295
+ },
296
+ get INFO() {
297
+ return ANSI.color(UNICODE.INFO_RAW, ANSI.BLUE);
298
+ },
299
+ get WARNING() {
300
+ return ANSI.color(UNICODE.WARNING_RAW, ANSI.YELLOW);
301
+ },
302
+ get CIRCLE_CROSS() {
303
+ return ANSI.color(UNICODE.CIRCLE_CROSS_RAW, ANSI.RED);
304
+ },
305
+ get ELLIPSIS() {
306
+ return UNICODE.supported ? "\u2026" : "...";
307
+ }
308
+ };
47
309
  const formatDefault = v => v;
48
- const inspectFileContent = ({
310
+ const generateContentFrame = ({
49
311
  content,
50
312
  line,
51
313
  column,
@@ -955,7 +1217,7 @@ const jsenvPluginSupervisor = ({
955
1217
  url: file,
956
1218
  line,
957
1219
  column,
958
- codeFrame: inspectFileContent({
1220
+ codeFrame: generateContentFrame({
959
1221
  line,
960
1222
  column,
961
1223
  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.4",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,10 +26,10 @@
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",
32
- "launch-editor": "2.6.1"
29
+ "@jsenv/ast": "6.0.4",
30
+ "@jsenv/urls": "2.2.4",
31
+ "@jsenv/sourcemap": "1.2.7",
32
+ "launch-editor": "2.8.0"
33
33
  },
34
34
  "scripts": {
35
35
  "eslint": "npx eslint . --ext=.js,.mjs,.cjs,.html",
@@ -606,7 +606,8 @@ window.__supervisor__ = (() => {
606
606
  // firefox
607
607
  if (
608
608
  exception.message.startsWith("import not found:") ||
609
- exception.message.startsWith("ambiguous indirect export:")
609
+ exception.message.startsWith("ambiguous indirect export:") ||
610
+ exception.message.includes("doesn't provide an export named:")
610
611
  ) {
611
612
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
612
613
  }
@@ -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,