From 6192990509cf793c4b10b88884d626893dee89df Mon Sep 17 00:00:00 2001 From: Max Isom Date: Wed, 20 Apr 2022 12:12:10 -0400 Subject: [PATCH] feat: add browser.d.ts and check for existence of Error.captureStackTrace() (#2144) --- browser.d.ts | 5 +++++ lib/yerror.ts | 4 +++- package.json | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 browser.d.ts diff --git a/browser.d.ts b/browser.d.ts new file mode 100644 index 000000000..21f3fc691 --- /dev/null +++ b/browser.d.ts @@ -0,0 +1,5 @@ +import {YargsFactory} from './build/lib/yargs-factory'; + +declare const Yargs: ReturnType; + +export default Yargs; diff --git a/lib/yerror.ts b/lib/yerror.ts index b282e0975..1daed0f6a 100644 --- a/lib/yerror.ts +++ b/lib/yerror.ts @@ -2,6 +2,8 @@ export class YError extends Error { name = 'YError'; constructor(msg?: string | null) { super(msg || 'yargs error'); - Error.captureStackTrace(this, YError); + if (Error.captureStackTrace) { + Error.captureStackTrace(this, YError); + } } } diff --git a/package.json b/package.json index b9c7cb6bf..ac9efb6d6 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,10 @@ "import": "./helpers/helpers.mjs", "require": "./helpers/index.js" }, + "./browser": { + "import": "./browser.mjs", + "types": "./browser.d.ts" + }, "./yargs": [ { "require": "./yargs"