From 8f3767181a9516b96aae14a25e62a5af51c73b10 Mon Sep 17 00:00:00 2001 From: Vadim Dalecky Date: Mon, 19 Jun 2023 11:50:46 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20take=20care=20of=20case?= =?UTF-8?q?=20when=20`fs`=20is=20empty=20object=20(#152)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In browser environment with current package.json `fs` is empty object, which results in `constants` being undefined. --- constants.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/constants.js b/constants.js index 15601d2..7bffb37 100644 --- a/constants.js +++ b/constants.js @@ -1,12 +1,14 @@ -try { - module.exports = require('fs').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 - } +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 || constants +} catch { + module.exports = constants }