Skip to content

Commit 2b2b501

Browse files
committed
Update build config and some types
1 parent f0f0639 commit 2b2b501

File tree

4 files changed

+87
-36
lines changed

4 files changed

+87
-36
lines changed

packages/storage-types/index.d.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,15 @@ export interface UploadMetadata extends SettableMetadata {
8484
md5Hash?: string | null;
8585
}
8686

87+
export interface FirebaseStorageError {
88+
name: string;
89+
code: string;
90+
message: string;
91+
serverResponse: null | string;
92+
}
93+
8794
export type NextFn<T> = (value: T) => void;
88-
export type ErrorFn = (error: Error | Error) => void;
95+
export type ErrorFn = (error: FirebaseStorageError) => void;
8996
export type CompleteFn = () => void;
9097
export type Unsubscribe = () => void;
9198
export interface StorageObserver<T> {
@@ -96,22 +103,22 @@ export interface StorageObserver<T> {
96103

97104
export interface UploadTask {
98105
cancel(): boolean;
99-
catch(onRejected: (a: Error) => any): Promise<any>;
106+
catch(onRejected: (a: FirebaseStorageError) => any): Promise<any>;
100107
on(
101108
event: TaskEvent,
102109
nextOrObserver?:
103110
| Partial<StorageObserver<UploadTaskSnapshot>>
104111
| null
105112
| ((a: UploadTaskSnapshot) => unknown),
106-
error?: ((a: Error) => any) | null,
113+
error?: ((a: FirebaseStorageError) => any) | null,
107114
complete?: Unsubscribe | null
108115
): Function;
109116
pause(): boolean;
110117
resume(): boolean;
111118
snapshot: UploadTaskSnapshot;
112119
then(
113120
onFulfilled?: ((a: UploadTaskSnapshot) => any) | null,
114-
onRejected?: ((a: Error) => any) | null
121+
onRejected?: ((a: FirebaseStorageError) => any) | null
115122
): Promise<any>;
116123
}
117124

packages/storage/exp/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"name": "@firebase/storage/exp",
33
"description": "A tree-shakeable version of the Storage SDK",
4-
"main": "../dist/exp/index.cjs.js",
5-
"module": "../dist/exp/index.esm2017.js",
6-
"browser": "../dist/exp/index.esm2017.js",
4+
"main": "../dist/exp/index.node.umd.js",
5+
"main-esm": "../dist/exp/index.node.esm2017.js",
6+
"module": "../dist/exp/index.browser.esm2017.js",
7+
"browser": "../dist/exp/index.browser.esm2017.js",
78
"typings": "./dist/exp/index.d.ts",
89
"private": true,
910
"dependencies": {

packages/storage/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"main": "dist/index.cjs.js",
77
"module": "dist/index.esm.js",
88
"esm2017": "dist/index.esm2017.js",
9-
"files": ["dist"],
9+
"files": [
10+
"dist"
11+
],
1012
"scripts": {
1113
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
1214
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
@@ -39,7 +41,9 @@
3941
"@firebase/auth": "0.14.9",
4042
"rollup": "2.28.1",
4143
"rollup-plugin-json": "4.0.0",
44+
"rollup-plugin-sourcemaps": "0.6.2",
4245
"rollup-plugin-typescript2": "0.27.2",
46+
"tmp": "0.2.1",
4347
"typescript": "4.0.2"
4448
},
4549
"repository": {

packages/storage/rollup.config.exp.js

Lines changed: 67 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,66 +15,105 @@
1515
* limitations under the License.
1616
*/
1717

18+
import tmp from 'tmp';
1819
import json from 'rollup-plugin-json';
1920
import typescriptPlugin from 'rollup-plugin-typescript2';
21+
import sourcemaps from 'rollup-plugin-sourcemaps';
2022
import typescript from 'typescript';
23+
import pkgExp from './exp/package.json';
2124
import pkg from './package.json';
2225
import path from 'path';
2326

2427
const deps = Object.keys(
2528
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
2629
).concat('@firebase/app-exp');
2730

28-
/**
29-
* ES5 Builds
30-
*/
31-
const es5BuildPlugins = [
31+
const nodePlugins = [
32+
typescriptPlugin({
33+
typescript,
34+
tsconfigOverride: {
35+
compilerOptions: {
36+
target: 'es2017'
37+
}
38+
},
39+
cacheDir: tmp.dirSync(),
40+
abortOnError: false
41+
}),
42+
json({ preferConst: true })
43+
];
44+
45+
const browserPlugins = [
46+
typescriptPlugin({
47+
typescript,
48+
tsconfigOverride: {
49+
compilerOptions: {
50+
target: 'es2017'
51+
}
52+
},
53+
cacheDir: tmp.dirSync(),
54+
abortOnError: false
55+
}),
56+
json({ preferConst: true })
57+
];
58+
59+
const es2017ToEs5Plugins = [
3260
typescriptPlugin({
33-
typescript
61+
typescript,
62+
compilerOptions: {
63+
allowJs: true
64+
},
65+
include: ['dist/*.js', 'dist/exp/*.js']
3466
}),
35-
json()
67+
sourcemaps()
3668
];
3769

38-
const es5Builds = [
70+
const nodeBuilds = [
71+
// Node ESM build
3972
{
4073
input: './exp/index.ts',
4174
output: {
42-
file: path.resolve('./exp', pkg.main),
43-
format: 'cjs',
75+
file: path.resolve('./exp', pkgExp['main-esm']),
76+
format: 'es',
4477
sourcemap: true
4578
},
46-
plugins: es5BuildPlugins,
79+
plugins: nodePlugins,
4780
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
4881
treeshake: {
4982
moduleSideEffects: false
5083
}
51-
}
52-
];
53-
54-
/**
55-
* ES2017 Builds
56-
*/
57-
const es2017BuildPlugins = [
58-
typescriptPlugin({
59-
typescript,
60-
tsconfigOverride: {
61-
compilerOptions: {
62-
target: 'es2017'
84+
},
85+
// Node UMD build
86+
{
87+
input: path.resolve('./exp', pkgExp['main-esm']),
88+
output: {
89+
file: path.resolve('./exp', pkgExp.main),
90+
format: 'umd',
91+
name: 'firebase.storage',
92+
sourcemap: true,
93+
globals: {
94+
'tslib': 'tslib',
95+
'@firebase/app-exp': 'appExp',
96+
'@firebase/app': 'firebase',
97+
'@firebase/component': 'component'
6398
}
99+
},
100+
plugins: es2017ToEs5Plugins,
101+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
102+
treeshake: {
103+
moduleSideEffects: false
64104
}
65-
}),
66-
json({ preferConst: true })
105+
}
67106
];
68107

69-
const es2017Builds = [
108+
const browserBuilds = [
70109
{
71110
input: './exp/index.ts',
72111
output: {
73-
file: path.resolve('./exp', pkg.esm2017),
112+
file: path.resolve('./exp', pkgExp.browser),
74113
format: 'es',
75114
sourcemap: true
76115
},
77-
plugins: es2017BuildPlugins,
116+
plugins: browserPlugins,
78117
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
79118
treeshake: {
80119
moduleSideEffects: false
@@ -83,4 +122,4 @@ const es2017Builds = [
83122
];
84123

85124
// eslint-disable-next-line import/no-default-export
86-
export default [...es5Builds, ...es2017Builds];
125+
export default [...nodeBuilds, ...browserBuilds];

0 commit comments

Comments
 (0)