Skip to content

Commit

Permalink
fix: 🐛 take care of case when fs is empty object (#152)
Browse files Browse the repository at this point in the history
In browser environment with current package.json `fs` is empty object,
which results in `constants` being undefined.
  • Loading branch information
streamich authored Jun 19, 2023
1 parent 6c30681 commit 8f37671
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions constants.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const constants = { // just for envs without fs
S_IFMT: 61440,
S_IFDIR: 16384,
S_IFCHR: 8192,
S_IFBLK: 24576,
S_IFIFO: 4096,
S_IFLNK: 40960
}

try {
module.exports = require('fs').constants
module.exports = require('fs').constants || constants
} catch {
module.exports = { // just for envs without fs
S_IFMT: 61440,
S_IFDIR: 16384,
S_IFCHR: 8192,
S_IFBLK: 24576,
S_IFIFO: 4096,
S_IFLNK: 40960
}
module.exports = constants
}

0 comments on commit 8f37671

Please sign in to comment.