Skip to content

Commit

Permalink
Require Node.js 14 and publish TypeScript types (#21)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: LitoMore <LitoMore@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 8, 2023
1 parent 09b8156 commit a2546da
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
8 changes: 8 additions & 0 deletions declaration.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"declaration": true,
"noEmit": false,
"emitDeclarationOnly": true
}
}
44 changes: 30 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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')) {
Expand All @@ -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;
}

Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
"url": "github.com/jamestalmage"
},
"engines": {
"node": ">=8"
"node": ">=14.18"
},
"scripts": {
"prepublishOnly": "npm run create-types",
"test": "xo && nyc ava",
"create-types": "tsc index.js --allowJs --declaration --emitDeclarationOnly"
"test": "xo && nyc ava && tsc",
"create-types": "tsc --project declaration.tsconfig.json"
},
"files": [
"index.js",
"index.d.ts",
"browser.js"
],
"browser": "browser.js",
Expand All @@ -33,10 +34,12 @@
"supports-color": "^7.0.0"
},
"devDependencies": {
"@tsconfig/node14": "^1.0.3",
"@types/supports-color": "^8.1.1",
"ava": "^2.2.0",
"codecov": "^3.5.0",
"nyc": "^14.1.1",
"typescript": "^3.7.2",
"typescript": "^4.9.5",
"xo": "^0.24.0"
},
"nyc": {
Expand Down
12 changes: 12 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@tsconfig/node14/tsconfig.json",
"files": [
"index.js"
],
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true,
"removeComments": true
}
}

0 comments on commit a2546da

Please sign in to comment.