Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lib-storage): fix fs error on browsers when using lib-storage upload #2165

Merged
merged 1 commit into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
};