supports-hyperlinks 2.2.0 → 3.0.0

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.
Files changed (3) hide show
  1. package/index.d.ts +5 -0
  2. package/index.js +39 -17
  3. package/package.json +8 -5
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export function supportsHyperlink(stream: {
2
+ isTTY?: boolean | undefined;
3
+ }): boolean;
4
+ export declare const stdout: boolean;
5
+ export declare const stderr: boolean;
package/index.js CHANGED
@@ -2,10 +2,14 @@
2
2
  const supportsColor = require('supports-color');
3
3
  const hasFlag = require('has-flag');
4
4
 
5
+ /**
6
+ @param {string} versionString
7
+ @returns {{ major: number, minor: number, patch: number }}
8
+ */
5
9
  function parseVersion(versionString) {
6
10
  if (/^\d{3,4}$/.test(versionString)) {
7
11
  // Env var doesn't always use dots. example: 4601 => 46.1.0
8
- const m = /(\d{1,2})(\d{2})/.exec(versionString);
12
+ const m = /(\d{1,2})(\d{2})/.exec(versionString) || [];
9
13
  return {
10
14
  major: 0,
11
15
  minor: parseInt(m[1], 10),
@@ -21,11 +25,23 @@ function parseVersion(versionString) {
21
25
  };
22
26
  }
23
27
 
28
+ /**
29
+ @param {{ isTTY?: boolean | undefined }} stream
30
+ @returns {boolean}
31
+ */
24
32
  function supportsHyperlink(stream) {
25
- const {env} = process;
26
-
27
- if ('FORCE_HYPERLINK' in env) {
28
- return !(env.FORCE_HYPERLINK.length > 0 && parseInt(env.FORCE_HYPERLINK, 10) === 0);
33
+ const {
34
+ CI,
35
+ FORCE_HYPERLINK,
36
+ NETLIFY,
37
+ TEAMCITY_VERSION,
38
+ TERM_PROGRAM,
39
+ TERM_PROGRAM_VERSION,
40
+ VTE_VERSION
41
+ } = process.env;
42
+
43
+ if (FORCE_HYPERLINK) {
44
+ return !(FORCE_HYPERLINK.length > 0 && parseInt(FORCE_HYPERLINK, 10) === 0);
29
45
  }
30
46
 
31
47
  if (hasFlag('no-hyperlink') || hasFlag('no-hyperlinks') || hasFlag('hyperlink=false') || hasFlag('hyperlink=never')) {
@@ -36,6 +52,11 @@ function supportsHyperlink(stream) {
36
52
  return true;
37
53
  }
38
54
 
55
+ // Netlify does not run a TTY, it does not need `supportsColor` check
56
+ if (NETLIFY) {
57
+ return true;
58
+ }
59
+
39
60
  // If they specify no colors, they probably don't want hyperlinks.
40
61
  if (!supportsColor.supportsColor(stream)) {
41
62
  return false;
@@ -49,39 +70,40 @@ function supportsHyperlink(stream) {
49
70
  return false;
50
71
  }
51
72
 
52
- if ('NETLIFY' in env) {
53
- return true;
54
- }
55
-
56
- if ('CI' in env) {
73
+ if (CI) {
57
74
  return false;
58
75
  }
59
76
 
60
- if ('TEAMCITY_VERSION' in env) {
77
+ if (TEAMCITY_VERSION) {
61
78
  return false;
62
79
  }
63
80
 
64
- if ('TERM_PROGRAM' in env) {
65
- const version = parseVersion(env.TERM_PROGRAM_VERSION);
81
+ if (TERM_PROGRAM) {
82
+ const version = parseVersion(TERM_PROGRAM_VERSION || '');
66
83
 
67
- switch (env.TERM_PROGRAM) {
84
+ switch (TERM_PROGRAM) {
68
85
  case 'iTerm.app':
69
86
  if (version.major === 3) {
70
87
  return version.minor >= 1;
71
88
  }
72
89
 
73
90
  return version.major > 3;
91
+ case 'WezTerm':
92
+ return version.major >= 20200620;
93
+ case 'vscode':
94
+ // eslint-disable-next-line no-mixed-operators
95
+ return version.major > 1 || version.major === 1 && version.minor >= 72;
74
96
  // No default
75
97
  }
76
98
  }
77
99
 
78
- if ('VTE_VERSION' in env) {
100
+ if (VTE_VERSION) {
79
101
  // 0.50.0 was supposed to support hyperlinks, but throws a segfault
80
- if (env.VTE_VERSION === '0.50.0') {
102
+ if (VTE_VERSION === '0.50.0') {
81
103
  return false;
82
104
  }
83
105
 
84
- const version = parseVersion(env.VTE_VERSION);
106
+ const version = parseVersion(VTE_VERSION);
85
107
  return version.major > 0 || version.minor >= 50;
86
108
  }
87
109
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supports-hyperlinks",
3
- "version": "2.2.0",
3
+ "version": "3.0.0",
4
4
  "description": "Detect if your terminal emulator supports hyperlinks",
5
5
  "license": "MIT",
6
6
  "repository": "jamestalmage/supports-hyperlinks",
@@ -10,15 +10,16 @@
10
10
  "url": "github.com/jamestalmage"
11
11
  },
12
12
  "engines": {
13
- "node": ">=8"
13
+ "node": ">=14.18"
14
14
  },
15
15
  "scripts": {
16
16
  "prepublishOnly": "npm run create-types",
17
- "test": "xo && nyc ava",
18
- "create-types": "tsc index.js --allowJs --declaration --emitDeclarationOnly"
17
+ "test": "xo && nyc ava && tsc",
18
+ "create-types": "tsc --project declaration.tsconfig.json"
19
19
  },
20
20
  "files": [
21
21
  "index.js",
22
+ "index.d.ts",
22
23
  "browser.js"
23
24
  ],
24
25
  "browser": "browser.js",
@@ -33,10 +34,12 @@
33
34
  "supports-color": "^7.0.0"
34
35
  },
35
36
  "devDependencies": {
37
+ "@tsconfig/node14": "^1.0.3",
38
+ "@types/supports-color": "^8.1.1",
36
39
  "ava": "^2.2.0",
37
40
  "codecov": "^3.5.0",
38
41
  "nyc": "^14.1.1",
39
- "typescript": "^3.7.2",
42
+ "typescript": "^4.9.5",
40
43
  "xo": "^0.24.0"
41
44
  },
42
45
  "nyc": {