Browse Source

Import the `fs` module only in Node.js environments (#117)

master
Sam Verschueren 6 years ago
committed by Sindre Sorhus
parent
commit
d24f2ef021
  1. 5
      source/lib/utils/infer-label.ts
  2. 4
      source/lib/utils/node/fs.ts

5
source/lib/utils/infer-label.ts

@ -1,4 +1,4 @@
import fs from './node/fs';
import lazyFS from './node/fs';
import {CallSite} from 'callsites';
import * as isNode from 'is-node';
import isValidIdentifier from './is-valid-identifier';
@ -17,6 +17,9 @@ 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];

4
source/lib/utils/node/fs.ts

@ -1,4 +1,4 @@
import nodeRequire from './require';
// Re-export the Node.js `fs` module to make sure it doesn't get bundled with front-end apps
export default nodeRequire('fs');
// Re-export the Node.js `fs` module lazily to make sure it doesn't get bundled with front-end apps
export default () => nodeRequire('fs');

Loading…
Cancel
Save