Skip to content

Commit

Permalink
Use the package.json "browser" field to toggle Node.js-specific funct…
Browse files Browse the repository at this point in the history
…ionality (#145)
  • Loading branch information
goto-bus-stop authored and sindresorhus committed May 12, 2019
1 parent 5421063 commit 8fbce4a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 22 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
"webpack": "^4.29.0",
"webpack-cli": "^3.1.2"
},
"browser": {
"./dist/source/utils/infer-label.js": "./dist/source/utils/infer-label.browser.js"
},
"types": "dist",
"sideEffects": false,
"ava": {
Expand Down
2 changes: 2 additions & 0 deletions source/utils/infer-label.browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Dummy in the browser.
export const inferLabel = () => {};
7 changes: 2 additions & 5 deletions source/utils/infer-label.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {CallSite} from 'callsites';
import lazyFS from './node/fs';
import * as fs from 'fs';
import isValidIdentifier from './is-valid-identifier';
import isNode from './node/is-node';

Expand All @@ -18,9 +18,6 @@ export const inferLabel = (callsites: CallSite[]) => {
return;
}

// Load the lazy `fs` module
const fs = lazyFS();

// Grab the stackframe with the `ow` function call
const functionCallStackFrame = callsites[1];

Expand All @@ -35,7 +32,7 @@ export const inferLabel = (callsites: CallSite[]) => {
let content: string[] = [];

try {
content = (fs.readFileSync(fileName, 'utf8') as string).split('\n');
content = fs.readFileSync(fileName, 'utf8').split('\n');
} catch {
return;
}
Expand Down
4 changes: 0 additions & 4 deletions source/utils/node/fs.ts

This file was deleted.

13 changes: 0 additions & 13 deletions source/utils/node/require.ts

This file was deleted.

0 comments on commit 8fbce4a

Please sign in to comment.