diff --git a/home-directory-browser.js b/home-directory-browser.js index 79ff1df..733cde0 100644 --- a/home-directory-browser.js +++ b/home-directory-browser.js @@ -1,3 +1,3 @@ -const homeDirectory = ''; +const getHomeDirectory = () => ''; -export default homeDirectory; +export default getHomeDirectory; diff --git a/home-directory.js b/home-directory.js index 03617b7..7899fcd 100644 --- a/home-directory.js +++ b/home-directory.js @@ -1,5 +1,5 @@ import os from 'node:os'; -const homeDirectory = os.homedir().replace(/\\/g, '/'); +const getHomeDirectory = () => os.homedir().replace(/\\/g, '/'); -export default homeDirectory; +export default getHomeDirectory; diff --git a/index.js b/index.js index d927542..649da79 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,12 @@ import escapeStringRegexp from 'escape-string-regexp'; -import homeDirectory from '#home-directory'; +import getHomeDirectory from '#home-directory'; const extractPathRegex = /\s+at.*[(\s](.*)\)?/; const pathRegex = /^(?:(?:(?:node|node:[\w/]+|(?:(?:node:)?internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)(?:\.js)?:\d+:\d+)|native)/; export default function cleanStack(stack, {pretty = false, basePath} = {}) { const basePathRegex = basePath && new RegExp(`(file://)?${escapeStringRegexp(basePath.replace(/\\/g, '/'))}/?`, 'g'); + const homeDirectory = pretty ? getHomeDirectory() : ''; if (typeof stack !== 'string') { return undefined; diff --git a/test.js b/test.js index b700146..a91cff4 100644 --- a/test.js +++ b/test.js @@ -1,5 +1,7 @@ import os from 'node:os'; import test from 'ava'; +import getHomeDirectoryNode from './home-directory.js'; +import getHomeDirectoryBrowser from './home-directory-browser.js'; import cleanStack from './index.js'; test('default', t => { @@ -270,3 +272,8 @@ test('handle undefined', t => { const expected = undefined; t.is(cleanStack(stack, {pretty: true}), expected); }); + +test('exports for home-directory files match', t => { + t.is(typeof getHomeDirectoryNode, 'function'); + t.is(typeof getHomeDirectoryBrowser, 'function'); +});