Skip to content

Commit e062933

Browse files
Pre-process all ES5 builds (#2840)
1 parent d9b599f commit e062933

File tree

6 files changed

+288
-236
lines changed

6 files changed

+288
-236
lines changed

packages/firestore/memory/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@firebase/firestore/memory",
33
"description": "A memory-only build of the Cloud Firestore JS SDK.",
44
"main": "../dist/index.memory.node.cjs.js",
5+
"main-esm2017": "../dist/index.memory.node.esm2017.js",
56
"browser": "../dist/index.memory.cjs.js",
67
"module": "../dist/index.memory.esm.js",
78
"esm2017": "../dist/index.memory.esm2017.js",

packages/firestore/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
66
"scripts": {
77
"prebuild": "tsc -d --downlevelIteration --declarationDir dist/lib --emitDeclarationOnly && tsc -m es2015 --moduleResolution node scripts/*.ts ",
8-
"build": "rollup -c",
8+
"build": "rollup -c rollup.config.es2017.js && rollup -c rollup.config.es5.js",
99
"build:deps": "lerna run --scope @firebase/'{app,firestore}' --include-dependencies build",
1010
"build:console": "node tools/console.build.js",
1111
"predev": "yarn prebuild",
@@ -26,6 +26,7 @@
2626
"prepare": "yarn build"
2727
},
2828
"main": "dist/index.node.cjs.js",
29+
"main-esm2017": "dist/index.node.esm2017.js",
2930
"browser": "dist/index.cjs.js",
3031
"module": "dist/index.esm.js",
3132
"esm2017": "dist/index.esm2017.js",
+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/**
2+
* @license
3+
* Copyright 2018 Google Inc.
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+
import * as path from 'path';
19+
20+
import json from 'rollup-plugin-json';
21+
import typescriptPlugin from 'rollup-plugin-typescript2';
22+
import replace from 'rollup-plugin-replace';
23+
import copy from 'rollup-plugin-copy-assets';
24+
import typescript from 'typescript';
25+
import { terser } from 'rollup-plugin-terser';
26+
27+
import pkg from './package.json';
28+
import memoryPkg from './memory/package.json';
29+
30+
import {
31+
appendPrivatePrefixTransformers,
32+
manglePrivatePropertiesOptions,
33+
resolveNodeExterns,
34+
resolveBrowserExterns
35+
} from './rollup.shared';
36+
37+
// Firestore is released in a number of different build configurations:
38+
// - Browser builds that support persistence in ES5 CJS and ES5 ESM formats and
39+
// ES2017 in ESM format.
40+
// - In-memory Browser builds that support persistence in ES5 CJS and ES5 ESM
41+
// formats and ES2017 in ESM format.
42+
// - A NodeJS build that supports persistence (to be used with an IndexedDb
43+
// shim)
44+
// - A in-memory only NodeJS build
45+
//
46+
// The in-memory builds are roughly 130 KB smaller, but throw an exception
47+
// for calls to `enablePersistence()` or `clearPersistence()`.
48+
//
49+
// We use two different rollup pipelines to take advantage of tree shaking,
50+
// as Rollup does not support tree shaking for Typescript classes transpiled
51+
// down to ES5 (see https://bit.ly/340P23U). The build pipeline in this file
52+
// produces tree-shaken ES2017 builds that are consumed by the ES5 builds in
53+
// `rollup.config.es.js`.
54+
//
55+
// All browser builds rely on Terser's property name mangling to reduce code
56+
// size.
57+
//
58+
// See https://g3doc/firebase/jscore/g3doc/contributing/builds.md
59+
// for a description of the various JavaScript formats used in our SDKs.
60+
61+
// MARK: Browser builds
62+
63+
const browserBuildPlugins = [
64+
typescriptPlugin({
65+
typescript,
66+
tsconfigOverride: {
67+
compilerOptions: {
68+
target: 'es2017'
69+
}
70+
},
71+
clean: true,
72+
transformers: appendPrivatePrefixTransformers
73+
}),
74+
json({ preferConst: true }),
75+
terser(manglePrivatePropertiesOptions)
76+
];
77+
78+
const browserBuilds = [
79+
// Persistence build
80+
{
81+
input: 'index.ts',
82+
output: {
83+
file: pkg.esm2017,
84+
format: 'es',
85+
sourcemap: true
86+
},
87+
plugins: browserBuildPlugins,
88+
external: resolveBrowserExterns
89+
},
90+
// Memory-only build
91+
{
92+
input: 'index.memory.ts',
93+
output: {
94+
file: path.resolve('./memory', memoryPkg.esm2017),
95+
format: 'es',
96+
sourcemap: true
97+
},
98+
plugins: browserBuildPlugins,
99+
external: resolveBrowserExterns
100+
}
101+
];
102+
103+
// MARK: Node builds
104+
105+
const nodeBuildPlugins = [
106+
typescriptPlugin({
107+
typescript,
108+
tsconfigOverride: {
109+
compilerOptions: {
110+
target: 'es2017'
111+
}
112+
},
113+
clean: true
114+
}),
115+
json(),
116+
// Needed as we also use the *.proto files
117+
copy({
118+
assets: ['./src/protos']
119+
}),
120+
replace({
121+
'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('src/protos')
122+
})
123+
];
124+
125+
const nodeBuilds = [
126+
// Persistence build
127+
{
128+
input: 'index.node.ts',
129+
output: [{ file: pkg['main-esm2017'], format: 'es', sourcemap: true }],
130+
plugins: nodeBuildPlugins,
131+
external: resolveNodeExterns
132+
},
133+
// Memory-only build
134+
{
135+
input: 'index.node.memory.ts',
136+
output: [
137+
{
138+
file: path.resolve('./memory', memoryPkg['main-esm2017']),
139+
format: 'es',
140+
sourcemap: true
141+
}
142+
],
143+
plugins: nodeBuildPlugins,
144+
external: resolveNodeExterns
145+
}
146+
];
147+
148+
export default [...browserBuilds, ...nodeBuilds];
+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**
2+
* @license
3+
* Copyright 2018 Google Inc.
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+
import * as path from 'path';
19+
20+
import typescriptPlugin from 'rollup-plugin-typescript2';
21+
import sourcemaps from 'rollup-plugin-sourcemaps';
22+
import typescript from 'typescript';
23+
import { terser } from 'rollup-plugin-terser';
24+
import { resolveNodeExterns, resolveBrowserExterns } from './rollup.shared';
25+
26+
import pkg from './package.json';
27+
import memoryPkg from './memory/package.json';
28+
29+
// This file defines the second rollup pipeline and transpiles the ES2017 SDK
30+
// into ES5 code. By splitting the build process into two independent build
31+
// pipelines, we take advantage of tree shaking in ES2017 builds even for
32+
// language levels that don't support tree shaking.
33+
34+
const browserPlugins = [
35+
typescriptPlugin({
36+
typescript,
37+
compilerOptions: {
38+
allowJs: true
39+
},
40+
include: ['dist/*.js']
41+
}),
42+
terser({
43+
output: {
44+
comments: 'all',
45+
beautify: true
46+
},
47+
mangle: true
48+
}),
49+
sourcemaps()
50+
];
51+
52+
const nodePlugins = [
53+
typescriptPlugin({
54+
typescript,
55+
compilerOptions: {
56+
allowJs: true
57+
},
58+
include: ['dist/*.js']
59+
}),
60+
sourcemaps()
61+
];
62+
63+
const browserBuilds = [
64+
{
65+
input: pkg.esm2017,
66+
output: { file: pkg.module, format: 'es', sourcemap: true },
67+
plugins: browserPlugins,
68+
external: resolveBrowserExterns
69+
},
70+
{
71+
input: path.resolve('./memory', memoryPkg.esm2017),
72+
output: {
73+
file: path.resolve('./memory', memoryPkg.module),
74+
format: 'es',
75+
sourcemap: true
76+
},
77+
plugins: browserPlugins,
78+
external: resolveBrowserExterns
79+
},
80+
{
81+
input: pkg.esm2017,
82+
output: { file: pkg.browser, format: 'cjs', sourcemap: true },
83+
plugins: browserPlugins,
84+
external: resolveBrowserExterns
85+
},
86+
{
87+
input: path.resolve('./memory', memoryPkg.esm2017),
88+
output: {
89+
file: path.resolve('./memory', memoryPkg.browser),
90+
format: 'cjs',
91+
sourcemap: true
92+
},
93+
plugins: browserPlugins,
94+
external: resolveBrowserExterns
95+
}
96+
];
97+
98+
const nodeBuilds = [
99+
{
100+
input: pkg['main-esm2017'],
101+
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
102+
plugins: nodePlugins,
103+
external: resolveNodeExterns
104+
},
105+
{
106+
input: path.resolve('./memory', memoryPkg['main-esm2017']),
107+
output: [
108+
{
109+
file: path.resolve('./memory', memoryPkg.main),
110+
format: 'cjs',
111+
sourcemap: true
112+
}
113+
],
114+
plugins: nodePlugins,
115+
external: resolveNodeExterns
116+
}
117+
];
118+
119+
export default [...browserBuilds, ...nodeBuilds];

0 commit comments

Comments
 (0)