Skip to content

Commit

Permalink
fix(lib-storage): fix fs error on browsers when using lib-storage upl…
Browse files Browse the repository at this point in the history
…oad (#2165)
  • Loading branch information
ajredniwja authored Mar 22, 2021
1 parent 19f978c commit 5d9bc5f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
1 change: 0 additions & 1 deletion lib/lib-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
},
"browser": {
"stream": "stream-browserify",
"fs": "./src/runtimeConfig.browser",
"./runtimeConfig": "./src/runtimeConfig.browser"
},
"react-native": {
Expand Down
4 changes: 2 additions & 2 deletions lib/lib-storage/src/bytelength.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lstatSync } from "fs";
import { ClientDefaultValues } from "./runtimeConfig";

export const byteLength = (input: any) => {
if (input === null || input === undefined) return 0;
Expand All @@ -11,7 +11,7 @@ export const byteLength = (input: any) => {
return input.size;
} else if (typeof input.path === "string") {
try {
return lstatSync(input.path).size;
return ClientDefaultValues.lstatSync(input.path).size;
} catch (error) {
return undefined;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/lib-storage/src/runtimeConfig.shared.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/**
* @internal
*/
export const ClientSharedValues = {};
export const ClientSharedValues = {
lstatSync: () => {},
};
2 changes: 2 additions & 0 deletions lib/lib-storage/src/runtimeConfig.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ClientSharedValues } from "./runtimeConfig.shared";
import { lstatSync } from "fs";

/**
* @internal
*/
export const ClientDefaultValues = {
...ClientSharedValues,
runtime: "node",
lstatSync,
};

0 comments on commit 5d9bc5f

Please sign in to comment.