From 5be2aeabc3cac046593b4f99eda4f304eaad30ed Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Fri, 7 Oct 2022 12:10:07 +0200 Subject: [PATCH 01/13] Generate declaration map --- .gitignore | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index afec2af..c70aa05 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ node_modules yarn.lock .nyc_output coverage -index.d.ts +*.d.ts* diff --git a/package.json b/package.json index 40a45ff..b432520 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "scripts": { "prepublishOnly": "npm run create-types", "test": "xo && nyc ava", - "create-types": "tsc index.js --allowJs --declaration --emitDeclarationOnly" + "create-types": "tsc index.js --allowJs --declaration --emitDeclarationOnly --declarationMap" }, "files": [ "index.js", From bcedb7c28046a9a2413b32bd034eb15067c330a2 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Fri, 7 Oct 2022 12:11:13 +0200 Subject: [PATCH 02/13] Publish type definitions --- package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.json b/package.json index b432520..73b7d00 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,8 @@ }, "files": [ "index.js", + "index.d.ts", + "index.d.ts.map", "browser.js" ], "browser": "browser.js", From 5ba74e503fdcb19e7d1103468cbb14dadb7c468d Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Fri, 7 Oct 2022 12:13:39 +0200 Subject: [PATCH 03/13] BREAKING: Support Node 14 and up --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 73b7d00..97bf753 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "github.com/jamestalmage" }, "engines": { - "node": ">=8" + "node": "^14.18.0 || >=16.0.0" }, "scripts": { "prepublishOnly": "npm run create-types", From 4ad0fb854b706808f26973b8b7dc18d91428536e Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Fri, 7 Oct 2022 12:19:12 +0200 Subject: [PATCH 04/13] Add `tsconfig.json` + validate types --- declaration.tsconfig.json | 10 ++++++++++ package.json | 7 ++++--- tsconfig.json | 12 ++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 declaration.tsconfig.json create mode 100644 tsconfig.json diff --git a/declaration.tsconfig.json b/declaration.tsconfig.json new file mode 100644 index 0000000..5c1b2cb --- /dev/null +++ b/declaration.tsconfig.json @@ -0,0 +1,10 @@ + +{ + "extends": "./tsconfig", + "compilerOptions": { + "declaration": true, + "declarationMap": true, + "noEmit": false, + "emitDeclarationOnly": true + } +} diff --git a/package.json b/package.json index 97bf753..dbb60dd 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,8 @@ }, "scripts": { "prepublishOnly": "npm run create-types", - "test": "xo && nyc ava", - "create-types": "tsc index.js --allowJs --declaration --emitDeclarationOnly --declarationMap" + "test": "xo && nyc ava && tsc", + "create-types": "tsc -p declaration.tsconfig.json" }, "files": [ "index.js", @@ -35,10 +35,11 @@ "supports-color": "^7.0.0" }, "devDependencies": { + "@tsconfig/node14": "^1.0.3", "ava": "^2.2.0", "codecov": "^3.5.0", "nyc": "^14.1.1", - "typescript": "^3.7.2", + "typescript": "^4.8.4", "xo": "^0.24.0" }, "nyc": { diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..ad59fa0 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "@tsconfig/node14/tsconfig.json", + "files": [ + "index.js" + ], + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "noEmit": true, + "strict": false + } +} From e757ae8672a820a86fa74d3b39f92dea1890f88d Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Fri, 7 Oct 2022 12:26:16 +0200 Subject: [PATCH 05/13] Actually annotate with types --- index.js | 44 ++++++++++++++++++++++++++++++-------------- package.json | 1 + tsconfig.json | 3 +-- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 89f1b2c..cdb440c 100644 --- a/index.js +++ b/index.js @@ -2,10 +2,14 @@ const supportsColor = require('supports-color'); const hasFlag = require('has-flag'); +/** + * @param {string} versionString + * @returns {{ major: number, minor: number, patch: number }} + */ function parseVersion(versionString) { if (/^\d{3,4}$/.test(versionString)) { // Env var doesn't always use dots. example: 4601 => 46.1.0 - const m = /(\d{1,2})(\d{2})/.exec(versionString); + const m = /(\d{1,2})(\d{2})/.exec(versionString) || []; return { major: 0, minor: parseInt(m[1], 10), @@ -21,11 +25,23 @@ function parseVersion(versionString) { }; } +/** + * @param {{ isTTY?: boolean | undefined }} stream + * @returns {boolean} + */ function supportsHyperlink(stream) { - const {env} = process; - - if ('FORCE_HYPERLINK' in env) { - return !(env.FORCE_HYPERLINK.length > 0 && parseInt(env.FORCE_HYPERLINK, 10) === 0); + const { + CI, + FORCE_HYPERLINK, + NETLIFY, + TEAMCITY_VERSION, + TERM_PROGRAM, + TERM_PROGRAM_VERSION, + VTE_VERSION + } = process.env; + + if (FORCE_HYPERLINK) { + return !(FORCE_HYPERLINK.length > 0 && parseInt(FORCE_HYPERLINK, 10) === 0); } if (hasFlag('no-hyperlink') || hasFlag('no-hyperlinks') || hasFlag('hyperlink=false') || hasFlag('hyperlink=never')) { @@ -37,7 +53,7 @@ function supportsHyperlink(stream) { } // Netlify does not run a TTY, it does not need `supportsColor` check - if ('NETLIFY' in env) { + if (NETLIFY) { return true; } @@ -54,18 +70,18 @@ function supportsHyperlink(stream) { return false; } - if ('CI' in env) { + if (CI) { return false; } - if ('TEAMCITY_VERSION' in env) { + if (TEAMCITY_VERSION) { return false; } - if ('TERM_PROGRAM' in env) { - const version = parseVersion(env.TERM_PROGRAM_VERSION); + if (TERM_PROGRAM) { + const version = parseVersion(TERM_PROGRAM_VERSION || ''); - switch (env.TERM_PROGRAM) { + switch (TERM_PROGRAM) { case 'iTerm.app': if (version.major === 3) { return version.minor >= 1; @@ -80,13 +96,13 @@ function supportsHyperlink(stream) { } } - if ('VTE_VERSION' in env) { + if (VTE_VERSION) { // 0.50.0 was supposed to support hyperlinks, but throws a segfault - if (env.VTE_VERSION === '0.50.0') { + if (VTE_VERSION === '0.50.0') { return false; } - const version = parseVersion(env.VTE_VERSION); + const version = parseVersion(VTE_VERSION); return version.major > 0 || version.minor >= 50; } diff --git a/package.json b/package.json index dbb60dd..ad655e3 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ }, "devDependencies": { "@tsconfig/node14": "^1.0.3", + "@types/supports-color": "^8.1.1", "ava": "^2.2.0", "codecov": "^3.5.0", "nyc": "^14.1.1", diff --git a/tsconfig.json b/tsconfig.json index ad59fa0..a28919f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,6 @@ "compilerOptions": { "allowJs": true, "checkJs": true, - "noEmit": true, - "strict": false + "noEmit": true } } From 6dbd40aad87d2bcbd8bd4cb122acc73bcf585327 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Fri, 7 Oct 2022 13:02:16 +0200 Subject: [PATCH 06/13] Skip comments in type file --- tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index a28919f..382ca3e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ "compilerOptions": { "allowJs": true, "checkJs": true, - "noEmit": true + "noEmit": true, + "removeComments": true } } From 792503903e26bb21ac0ca76382e41b8937db8e16 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Fri, 7 Oct 2022 13:21:28 +0200 Subject: [PATCH 07/13] Apply suggestions from code review Co-authored-by: Sindre Sorhus --- index.js | 2 +- package.json | 2 +- tsconfig.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index cdb440c..a6f6fc1 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,7 @@ const hasFlag = require('has-flag'); function parseVersion(versionString) { if (/^\d{3,4}$/.test(versionString)) { // Env var doesn't always use dots. example: 4601 => 46.1.0 - const m = /(\d{1,2})(\d{2})/.exec(versionString) || []; + const m = /(\d{1,2})(\d{2})/.exec(versionString) ?? []; return { major: 0, minor: parseInt(m[1], 10), diff --git a/package.json b/package.json index ad655e3..ce27214 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "github.com/jamestalmage" }, "engines": { - "node": "^14.18.0 || >=16.0.0" + "node": ">=14.18" }, "scripts": { "prepublishOnly": "npm run create-types", diff --git a/tsconfig.json b/tsconfig.json index 382ca3e..1aa521a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,7 @@ "compilerOptions": { "allowJs": true, "checkJs": true, - "noEmit": true, + "noEmit": true, "removeComments": true } } From e107711a0a823a07477ea5bff51e820c2630e2d0 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Fri, 7 Oct 2022 13:27:31 +0200 Subject: [PATCH 08/13] Skip declaration map --- .gitignore | 2 +- declaration.tsconfig.json | 1 - package.json | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index c70aa05..afec2af 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ node_modules yarn.lock .nyc_output coverage -*.d.ts* +index.d.ts diff --git a/declaration.tsconfig.json b/declaration.tsconfig.json index 5c1b2cb..05be443 100644 --- a/declaration.tsconfig.json +++ b/declaration.tsconfig.json @@ -3,7 +3,6 @@ "extends": "./tsconfig", "compilerOptions": { "declaration": true, - "declarationMap": true, "noEmit": false, "emitDeclarationOnly": true } diff --git a/package.json b/package.json index ce27214..106ee86 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "files": [ "index.js", "index.d.ts", - "index.d.ts.map", "browser.js" ], "browser": "browser.js", From 86869157935e6d32ef966e96ff3ec36eaf408df8 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Sat, 8 Oct 2022 13:54:58 +0200 Subject: [PATCH 09/13] Update declaration.tsconfig.json Co-authored-by: LitoMore --- declaration.tsconfig.json | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/declaration.tsconfig.json b/declaration.tsconfig.json index 05be443..c8d2a71 100644 --- a/declaration.tsconfig.json +++ b/declaration.tsconfig.json @@ -1,9 +1,8 @@ - { - "extends": "./tsconfig", - "compilerOptions": { - "declaration": true, - "noEmit": false, - "emitDeclarationOnly": true - } + "extends": "./tsconfig", + "compilerOptions": { + "declaration": true, + "noEmit": false, + "emitDeclarationOnly": true + } } From 41425ec65e95769c05635d0144a8c70da3ed8451 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 6 Mar 2023 14:13:48 +0700 Subject: [PATCH 10/13] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 106ee86..035b719 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "ava": "^2.2.0", "codecov": "^3.5.0", "nyc": "^14.1.1", - "typescript": "^4.8.4", + "typescript": "^4.9.5", "xo": "^0.24.0" }, "nyc": { From 758eba29205dbcc0cfbc2ad841f41dda1c6aa3e4 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 6 Mar 2023 14:16:04 +0700 Subject: [PATCH 11/13] Update index.js --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index a6f6fc1..fa1e0b8 100644 --- a/index.js +++ b/index.js @@ -3,9 +3,9 @@ const supportsColor = require('supports-color'); const hasFlag = require('has-flag'); /** - * @param {string} versionString - * @returns {{ major: number, minor: number, patch: number }} - */ +@param {string} versionString +@returns {{ major: number, minor: number, patch: number }} +*/ function parseVersion(versionString) { if (/^\d{3,4}$/.test(versionString)) { // Env var doesn't always use dots. example: 4601 => 46.1.0 @@ -26,9 +26,9 @@ function parseVersion(versionString) { } /** - * @param {{ isTTY?: boolean | undefined }} stream - * @returns {boolean} - */ +@param {{ isTTY?: boolean | undefined }} stream +@returns {boolean} +*/ function supportsHyperlink(stream) { const { CI, From 8fc6980de01b6a5a90e599c5b465ea79099ae984 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Tue, 7 Mar 2023 15:34:45 +0100 Subject: [PATCH 12/13] Move back from `??` to `||` --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index fa1e0b8..aab476a 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,7 @@ const hasFlag = require('has-flag'); function parseVersion(versionString) { if (/^\d{3,4}$/.test(versionString)) { // Env var doesn't always use dots. example: 4601 => 46.1.0 - const m = /(\d{1,2})(\d{2})/.exec(versionString) ?? []; + const m = /(\d{1,2})(\d{2})/.exec(versionString) || []; return { major: 0, minor: parseInt(m[1], 10), From 57b934f9109ba733ee5d5fa1c3cd13a8213050d9 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Tue, 7 Mar 2023 15:36:33 +0100 Subject: [PATCH 13/13] Use the long-flag rather than `-p` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 035b719..76786c1 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "scripts": { "prepublishOnly": "npm run create-types", "test": "xo && nyc ava && tsc", - "create-types": "tsc -p declaration.tsconfig.json" + "create-types": "tsc --project declaration.tsconfig.json" }, "files": [ "index.js",