Skip to content

Add Node.js support to Storage v9 #4985

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

Merged
merged 7 commits into from
Jun 25, 2021
Merged

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Jun 4, 2021

This adds Node support to Storage (via node-fetch).

It uses the same platform injection logic that Firestore uses.

@changeset-bot
Copy link

changeset-bot bot commented Jun 4, 2021

⚠️ No Changeset found

Latest commit: 9d0042f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 4, 2021

Binary Size Report

Affected SDKs

  • @firebase/storage

    Type Base (cf636ae) Head (a6c1a3b) Diff
    browser 63.4 kB 63.5 kB +172 B (+0.3%)
    esm2017 54.6 kB 54.7 kB +111 B (+0.2%)
    main 63.8 kB 64.0 kB +172 B (+0.3%)
    module 63.4 kB 63.5 kB +172 B (+0.3%)
  • @firebase/storage-compat

    Type Base (cf636ae) Head (a6c1a3b) Diff
    browser 10.2 kB 10.3 kB +60 B (+0.6%)
    main 29.1 kB 29.1 kB +49 B (+0.2%)
    module 10.2 kB 10.3 kB +60 B (+0.6%)
  • @firebase/storage-exp

    Type Base (cf636ae) Head (a6c1a3b) Diff
    browser 51.5 kB 51.6 kB +111 B (+0.2%)
    main 52.6 kB 52.8 kB +208 B (+0.4%)
    module 51.5 kB 51.6 kB +111 B (+0.2%)
  • firebase

    Type Base (cf636ae) Head (a6c1a3b) Diff
    firebase-storage.js 41.5 kB 41.5 kB +10 B (+0.0%)
    firebase.js 891 kB 891 kB +10 B (+0.0%)

Test Logs

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 4, 2021

Size Analysis Report

Affected Products

No changes between base commit (870dd5e) and head commit (0664b45).

@schmidt-sebastian
Copy link
Contributor Author

Tested this locally in Node:

const storage = getStorage();
const path = ref(storage, 'foo')
  
async function run() {
 await uploadBytes(path, new Uint8Array([1,2,3]));
 console.log("Upload done");
 const url = await  getDownloadURL(path);
 console.log(url);
}

run();

I did have to manually change the "main" entry in node_modules/@firebase/storage/package.json to "main": "exp/dist/index.node.cjs.js" (for v9). Not sure where this gets generated.

@@ -0,0 +1,19 @@
<component name="ProjectRunConfigurationManager">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is basically the entire reason behind this PR. I want to be able to debug Storage tests in IntelliJ. Since it is not harmful for VSCode users, I'd like to leave it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Should we follow the same folder structure in Firestore, i.e. .idea/runConfigurations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like IntelliJ changed the locations. All new profiles are added under .run


// This file is only used under ts-node.
// eslint-disable-next-line @typescript-eslint/no-require-imports
const platform = require(`./${process.env.TEST_PLATFORM ?? 'node'}/base64`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is TEST_PLATFORM set? Do we always default to node currently?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to set it. It is meant to be overridden for the Karma browser run. Fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually seems it's unnecessary to set it, because we default to browser in the webpack.config if TEST_PLATFORM is not set.

I think it also means we can just import ./node/base64 here since this file is only used for node tests as you pointed out in the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I simplified it.

@Feiyang1
Copy link
Member

woohoo! ❤️

@Feiyang1
Copy link
Member

Addresses #18

@Feiyang1 Feiyang1 added this to the v9 GA milestone Jun 23, 2021
@samtstern
Copy link
Contributor

@schmidt-sebastian how hard would it be to port this to v8 as well?

@schmidt-sebastian
Copy link
Contributor Author

@samtstern Pretty easy, we likely only need a new Rollup config. We would have to change the "main" entry in the package.json to point to the new build, which is probably a breaking change. That's why I did not do this so far.

@schmidt-sebastian schmidt-sebastian merged commit 1e6bd3e into master Jun 25, 2021
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/storagenode branch June 25, 2021 23:09
hsubox76 pushed a commit that referenced this pull request Jun 28, 2021
@samtstern
Copy link
Contributor

cc @yuchenshi

@firebase firebase locked and limited conversation to collaborators Jul 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants