Skip to content

Commit 36eb98a

Browse files
Add Node build for Firebase Storage
This adds a Node and a Browser specific build so we can have getStream() in Node and getBlob() in browsers
1 parent 66d4a1e commit 36eb98a

File tree

9 files changed

+124
-7
lines changed

9 files changed

+124
-7
lines changed

packages/storage/.run/All Tests.run.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<env name="TS_NODE_CACHE" value="NO" />
1212
</envs>
1313
<ui>bdd</ui>
14-
<extra-mocha-options>--require ts-node/register/type-check --require index.ts</extra-mocha-options>
14+
<extra-mocha-options>--require ts-node/register/type-check --require index.node.ts</extra-mocha-options>
1515
<test-kind>PATTERN</test-kind>
1616
<test-pattern>test/{,!(browser)/**/}*.test.ts</test-pattern>
1717
<method v="2" />

packages/storage/karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = function (config) {
3232

3333
function getTestFiles(argv) {
3434
let unitTestFiles = ['test/unit/*'];
35-
let integrationTestFiles = ['test/integration/*'];
35+
let integrationTestFiles = ['test/integration/*', 'test/browser/*'];
3636

3737
if (argv.unit) {
3838
return unitTestFiles;

packages/storage/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"test:browser:unit": "karma start --single-run --unit",
2323
"test:browser:integration": "karma start --single-run --integration",
2424
"test:browser": "karma start --single-run",
25-
"test:node": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file src/index.ts --config ../../config/mocharc.node.js",
25+
"test:node": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file src/index.node.ts --config ../../config/mocharc.node.js",
2626
"test:debug": "karma start --browser=Chrome",
2727
"prettier": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
2828
"api-report": "api-extractor run --local --verbose && ts-node-script ../../repo-scripts/prune-dts/prune-dts.ts --input dist/storage-public.d.ts --output dist/storage-public.d.ts",

packages/storage/rollup.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const es2017Plugins = [
7878
const es2017Builds = [
7979
// Node
8080
{
81-
input: './src/index.ts',
81+
input: './src/index.node.ts',
8282
output: {
8383
file: pkg.main,
8484
format: 'cjs',

packages/storage/src/api.browser.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
// TODO(mrschmidt): Add getBlob()
19+
20+
export {};

packages/storage/src/api.node.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
// TODO(mrschmidt): Add getStream()
19+
20+
export {};

packages/storage/src/api.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export {
7474
TaskEvent as _TaskEvent,
7575
TaskState as _TaskState
7676
} from './implementation/taskenums';
77+
export {StringFormat};
7778

7879
/**
7980
* Uploads data to this object's location.
@@ -290,8 +291,6 @@ export function _getChild(ref: StorageReference, childPath: string): Reference {
290291
return _getChildInternal(ref as Reference, childPath);
291292
}
292293

293-
export { StringFormat } from './implementation/string';
294-
295294
/**
296295
* Gets a {@link FirebaseStorage} instance for the given Firebase app.
297296
* @public

packages/storage/src/index.node.ts

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Cloud Storage for Firebase
3+
*
4+
* @packageDocumentation
5+
*/
6+
7+
/**
8+
* @license
9+
* Copyright 2021 Google LLC
10+
*
11+
* Licensed under the Apache License, Version 2.0 (the "License");
12+
* you may not use this file except in compliance with the License.
13+
* You may obtain a copy of the License at
14+
*
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*
17+
* Unless required by applicable law or agreed to in writing, software
18+
* distributed under the License is distributed on an "AS IS" BASIS,
19+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
* See the License for the specific language governing permissions and
21+
* limitations under the License.
22+
*/
23+
24+
// eslint-disable-next-line import/no-extraneous-dependencies
25+
import {
26+
_registerComponent,
27+
registerVersion,
28+
SDK_VERSION
29+
} from '@firebase/app';
30+
31+
import { FirebaseStorageImpl } from './service';
32+
import {
33+
Component,
34+
ComponentType,
35+
ComponentContainer,
36+
InstanceFactoryOptions
37+
} from '@firebase/component';
38+
39+
import { name, version } from '../package.json';
40+
41+
import { FirebaseStorage } from './public-types';
42+
import { STORAGE_TYPE } from './constants';
43+
import { ConnectionPool } from './implementation/connectionPool';
44+
45+
export * from './api';
46+
export * from './api.node';
47+
48+
function factory(
49+
container: ComponentContainer,
50+
{ instanceIdentifier: url }: InstanceFactoryOptions
51+
): FirebaseStorage {
52+
const app = container.getProvider('app').getImmediate();
53+
const authProvider = container.getProvider('auth-internal');
54+
const appCheckProvider = container.getProvider('app-check-internal');
55+
56+
return new FirebaseStorageImpl(
57+
app,
58+
authProvider,
59+
appCheckProvider,
60+
new ConnectionPool(),
61+
url,
62+
SDK_VERSION
63+
);
64+
}
65+
66+
function registerStorage(): void {
67+
_registerComponent(
68+
new Component(
69+
STORAGE_TYPE,
70+
factory,
71+
ComponentType.PUBLIC
72+
).setMultipleInstances(true)
73+
);
74+
75+
registerVersion(name, version);
76+
}
77+
78+
registerStorage();

packages/storage/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ import { name, version } from '../package.json';
4141
import { FirebaseStorage } from './public-types';
4242
import { STORAGE_TYPE } from './constants';
4343

44-
export { StringFormat } from '../src/implementation/string';
4544
export * from './api';
45+
export * from './api.browser';
4646

4747
function factory(
4848
container: ComponentContainer,

0 commit comments

Comments
 (0)