Skip to content

Commit 0027ac1

Browse files
Pre-process all ES3 builds
1 parent 50de3fb commit 0027ac1

File tree

6 files changed

+142
-82
lines changed

6 files changed

+142
-82
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+
"mainES2017": "../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.es.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+
"mainES2017": "dist/index.node.esm2017.js",
2930
"browser": "dist/index.cjs.js",
3031
"module": "dist/index.esm.js",
3132
"esm2017": "dist/index.esm2017.js",
+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
const plugins = [
30+
typescriptPlugin({
31+
typescript,
32+
compilerOptions: {
33+
allowJs: true,
34+
importHelpers: true
35+
},
36+
include: ['dist/*.js']
37+
}),
38+
terser({
39+
output: {
40+
comments: 'all',
41+
beautify: true
42+
},
43+
mangle: {}
44+
}),
45+
sourcemaps()
46+
];
47+
48+
const browserBuilds = [
49+
{
50+
input: pkg.esm2017,
51+
output: { file: pkg.module, format: 'es', sourcemap: true },
52+
plugins: plugins,
53+
external: resolveBrowserExterns
54+
},
55+
{
56+
input: path.resolve('./memory', memoryPkg.esm2017),
57+
output: {
58+
file: path.resolve('./memory', memoryPkg.module),
59+
format: 'es',
60+
sourcemap: true
61+
},
62+
plugins: plugins,
63+
external: resolveBrowserExterns
64+
},
65+
{
66+
input: pkg.esm2017,
67+
output: { file: pkg.browser, format: 'cjs', sourcemap: true },
68+
plugins: plugins,
69+
external: resolveBrowserExterns
70+
},
71+
{
72+
input: path.resolve('./memory', memoryPkg.esm2017),
73+
output: {
74+
file: path.resolve('./memory', memoryPkg.browser),
75+
format: 'cjs',
76+
sourcemap: true
77+
},
78+
plugins: plugins,
79+
external: resolveBrowserExterns
80+
}
81+
];
82+
83+
const nodeBuilds = [
84+
{
85+
input: pkg.mainES2017,
86+
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
87+
plugins: plugins,
88+
external: resolveNodeExterns
89+
},
90+
{
91+
input: path.resolve('./memory', memoryPkg.mainES2017),
92+
output: [
93+
{
94+
file: path.resolve('./memory', memoryPkg.main),
95+
format: 'cjs',
96+
sourcemap: true
97+
}
98+
],
99+
plugins: plugins,
100+
external: resolveNodeExterns
101+
}
102+
];
103+
104+
export default [...browserBuilds, ...nodeBuilds];

packages/firestore/rollup.config.js renamed to packages/firestore/rollup.config.es2017.js

+17-80
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import json from 'rollup-plugin-json';
2121
import typescriptPlugin from 'rollup-plugin-typescript2';
2222
import replace from 'rollup-plugin-replace';
2323
import copy from 'rollup-plugin-copy-assets';
24-
import sourcemaps from 'rollup-plugin-sourcemaps';
2524
import typescript from 'typescript';
2625
import { terser } from 'rollup-plugin-terser';
2726

@@ -30,8 +29,10 @@ import memoryPkg from './memory/package.json';
3029

3130
import {
3231
appendPrivatePrefixTransformers,
33-
manglePrivatePropertiesOptions
34-
} from './terser.config';
32+
manglePrivatePropertiesOptions,
33+
resolveNodeExterns,
34+
resolveBrowserExterns
35+
} from './rollup.shared';
3536

3637
// This Firestore Rollup configuration provides a number of different builds:
3738
// - Browser builds that support persistence in ES5 CJS and ES5 ESM formats and
@@ -53,22 +54,6 @@ import {
5354

5455
// MARK: Browser builds
5556

56-
const browserDeps = Object.keys(
57-
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
58-
);
59-
60-
const nodeDeps = [...browserDeps, 'util', 'path'];
61-
62-
/** Resolves the external dependencies for the browser build. */
63-
function resolveBrowserExterns(id) {
64-
return browserDeps.some(dep => id === dep || id.startsWith(`${dep}/`));
65-
}
66-
67-
/** Resolves the external dependencies for the Node build. */
68-
function resolveNodeExterns(id) {
69-
return nodeDeps.some(dep => id === dep || id.startsWith(`${dep}/`));
70-
}
71-
7257
/**
7358
* Resolves the external dependencies for the Memory-based Firestore
7459
* implementation. Verifies that no persistence sources are used by Firestore's
@@ -99,95 +84,44 @@ export function resolveMemoryExterns(deps, externsId, referencedBy) {
9984
return deps.some(dep => externsId === dep || externsId.startsWith(`${dep}/`));
10085
}
10186

102-
const es5BuildPlugins = [
103-
typescriptPlugin({
104-
typescript,
105-
transformers: appendPrivatePrefixTransformers,
106-
cacheRoot: `./.cache/es5.mangled/`
107-
}),
108-
json(),
109-
terser(manglePrivatePropertiesOptions)
110-
];
111-
112-
const es2017BuildPlugins = [
87+
const browserBuildPlugins = [
11388
typescriptPlugin({
11489
typescript,
11590
tsconfigOverride: {
11691
compilerOptions: {
11792
target: 'es2017'
11893
}
11994
},
120-
cacheRoot: './.cache/es2017.mangled/',
95+
cacheRoot: './.cache/browser/',
12196
transformers: appendPrivatePrefixTransformers
12297
}),
12398
json({ preferConst: true }),
12499
terser(manglePrivatePropertiesOptions)
125100
];
126101

127102
const browserBuilds = [
128-
// ES5 ESM Build (with persistence)
129-
{
130-
input: 'index.ts',
131-
output: { file: pkg.module, format: 'es', sourcemap: true },
132-
plugins: es5BuildPlugins,
133-
external: resolveBrowserExterns
134-
},
135-
// ES5 ESM Build (memory-only)
136-
{
137-
input: 'index.memory.ts',
138-
output: {
139-
file: path.resolve('./memory', memoryPkg.module),
140-
format: 'es',
141-
sourcemap: true
142-
},
143-
plugins: es5BuildPlugins,
144-
external: (id, referencedBy) =>
145-
resolveMemoryExterns(browserDeps, id, referencedBy)
146-
},
147-
// ES2017 ESM build (with persistence)
103+
// Persistence build
148104
{
149105
input: 'index.ts',
150106
output: {
151107
file: pkg.esm2017,
152108
format: 'es',
153109
sourcemap: true
154110
},
155-
plugins: es2017BuildPlugins,
111+
plugins: browserBuildPlugins,
156112
external: resolveBrowserExterns
157113
},
158-
// ES2017 ESM build (memory-only)
114+
// Memory-only build
159115
{
160116
input: 'index.memory.ts',
161117
output: {
162118
file: path.resolve('./memory', memoryPkg.esm2017),
163119
format: 'es',
164120
sourcemap: true
165121
},
166-
plugins: es2017BuildPlugins,
122+
plugins: browserBuildPlugins,
167123
external: (id, referencedBy) =>
168124
resolveMemoryExterns(browserDeps, id, referencedBy)
169-
},
170-
// ES5 CJS Build (with persistence)
171-
//
172-
// This build is based on the mangling in the ESM build above, since
173-
// Terser's Property name mangling doesn't work well with CJS's syntax.
174-
{
175-
input: pkg.module,
176-
output: { file: pkg.browser, format: 'cjs', sourcemap: true },
177-
plugins: [sourcemaps()]
178-
},
179-
// ES5 CJS Build (memory-only)
180-
//
181-
// This build is based on the mangling in the ESM build above, since
182-
// Terser's Property name mangling doesn't work well with CJS's syntax.
183-
{
184-
input: path.resolve('./memory', memoryPkg.module),
185-
output: {
186-
file: path.resolve('./memory', memoryPkg.browser),
187-
format: 'cjs',
188-
sourcemap: true
189-
},
190-
plugins: [sourcemaps()]
191125
}
192126
];
193127

@@ -196,6 +130,9 @@ const browserBuilds = [
196130
const nodeBuildPlugins = [
197131
typescriptPlugin({
198132
typescript,
133+
compilerOptions: {
134+
target: 'es2017'
135+
},
199136
cacheRoot: `./.cache/node/`
200137
}),
201138
json(),
@@ -209,19 +146,19 @@ const nodeBuildPlugins = [
209146
];
210147

211148
const nodeBuilds = [
212-
// ES5 CJS build (with persistence)
149+
// Persistence build
213150
{
214151
input: 'index.node.ts',
215-
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
152+
output: [{ file: pkg.mainES2017, format: 'cjs', sourcemap: true }],
216153
plugins: nodeBuildPlugins,
217154
external: resolveNodeExterns
218155
},
219-
// ES5 CJS build (memory-only)
156+
// Memory-only build
220157
{
221158
input: 'index.node.memory.ts',
222159
output: [
223160
{
224-
file: path.resolve('./memory', memoryPkg.main),
161+
file: path.resolve('./memory', memoryPkg.mainES2017),
225162
format: 'cjs',
226163
sourcemap: true
227164
}

packages/firestore/terser.config.js renamed to packages/firestore/rollup.shared.js

+17
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import * as path from 'path';
2020
import { externs } from './externs.json';
2121
import { renameInternals } from './scripts/rename-internals';
2222
import { extractPublicIdentifiers } from './scripts/extract-api';
23+
import pkg from './package';
2324

2425
const externsPaths = externs.map(p => path.resolve(__dirname, '../../', p));
2526
const publicIdentifiers = extractPublicIdentifiers(externsPaths);
@@ -53,3 +54,19 @@ export const manglePrivatePropertiesOptions = {
5354
}
5455
}
5556
};
57+
58+
const browserDeps = Object.keys(
59+
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
60+
);
61+
62+
const nodeDeps = [...browserDeps, 'util', 'path'];
63+
64+
/** Resolves the external dependencies for the browser build. */
65+
export function resolveBrowserExterns(id) {
66+
return browserDeps.some(dep => id === dep || id.startsWith(`${dep}/`));
67+
}
68+
69+
/** Resolves the external dependencies for the Node build. */
70+
export function resolveNodeExterns(id) {
71+
return nodeDeps.some(dep => id === dep || id.startsWith(`${dep}/`));
72+
}

packages/firestore/test/util/helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ export function byteStringFromString(value: string): ByteString {
512512
return ByteString.fromBase64String(base64);
513513
}
514514

515-
/**
515+
/**
516516
* Decodes a base 64 decoded string.
517517
*
518518
* Note that this is typed to accept Uint8Arrays to match the types used

0 commit comments

Comments
 (0)