Skip to content

Pre-process all ES5 builds #2840

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 9 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/firestore/memory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@firebase/firestore/memory",
"description": "A memory-only build of the Cloud Firestore JS SDK.",
"main": "../dist/index.memory.node.cjs.js",
"main-esm2017": "../dist/index.memory.node.esm2017.js",
"browser": "../dist/index.memory.cjs.js",
"module": "../dist/index.memory.esm.js",
"esm2017": "../dist/index.memory.esm2017.js",
Expand Down
3 changes: 2 additions & 1 deletion packages/firestore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"scripts": {
"prebuild": "tsc -d --downlevelIteration --declarationDir dist/lib --emitDeclarationOnly && tsc -m es2015 --moduleResolution node scripts/*.ts ",
"build": "rollup -c",
"build": "rollup -c rollup.config.es2017.js && rollup -c rollup.config.es5.js",
"build:deps": "lerna run --scope @firebase/'{app,firestore}' --include-dependencies build",
"build:console": "node tools/console.build.js",
"predev": "yarn prebuild",
Expand All @@ -26,6 +26,7 @@
"prepare": "yarn build"
},
"main": "dist/index.node.cjs.js",
"main-esm2017": "dist/index.node.esm2017.js",
"browser": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"esm2017": "dist/index.esm2017.js",
Expand Down
148 changes: 148 additions & 0 deletions packages/firestore/rollup.config.es2017.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/**
* @license
* Copyright 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as path from 'path';

import json from 'rollup-plugin-json';
import typescriptPlugin from 'rollup-plugin-typescript2';
import replace from 'rollup-plugin-replace';
import copy from 'rollup-plugin-copy-assets';
import typescript from 'typescript';
import { terser } from 'rollup-plugin-terser';

import pkg from './package.json';
import memoryPkg from './memory/package.json';

import {
appendPrivatePrefixTransformers,
manglePrivatePropertiesOptions,
resolveNodeExterns,
resolveBrowserExterns
} from './rollup.shared';

// Firestore is released in a number of different build configurations:
// - Browser builds that support persistence in ES5 CJS and ES5 ESM formats and
// ES2017 in ESM format.
// - In-memory Browser builds that support persistence in ES5 CJS and ES5 ESM
// formats and ES2017 in ESM format.
// - A NodeJS build that supports persistence (to be used with an IndexedDb
// shim)
// - A in-memory only NodeJS build
//
// The in-memory builds are roughly 130 KB smaller, but throw an exception
// for calls to `enablePersistence()` or `clearPersistence()`.
//
// We use two different rollup pipelines to take advantage of tree shaking,
// as Rollup does not support tree shaking for Typescript classes transpiled
// down to ES5 (see https://bit.ly/340P23U). The build pipeline in this file
// produces tree-shaken ES2017 builds that are consumed by the ES5 builds in
// `rollup.config.es.js`.
//
// All browser builds rely on Terser's property name mangling to reduce code
// size.
//
// See https://g3doc/firebase/jscore/g3doc/contributing/builds.md
// for a description of the various JavaScript formats used in our SDKs.

// MARK: Browser builds

const browserBuildPlugins = [
typescriptPlugin({
typescript,
tsconfigOverride: {
compilerOptions: {
target: 'es2017'
}
},
clean: true,
transformers: appendPrivatePrefixTransformers
}),
json({ preferConst: true }),
terser(manglePrivatePropertiesOptions)
];

const browserBuilds = [
// Persistence build
{
input: 'index.ts',
output: {
file: pkg.esm2017,
format: 'es',
sourcemap: true
},
plugins: browserBuildPlugins,
external: resolveBrowserExterns
},
// Memory-only build
{
input: 'index.memory.ts',
output: {
file: path.resolve('./memory', memoryPkg.esm2017),
format: 'es',
sourcemap: true
},
plugins: browserBuildPlugins,
external: resolveBrowserExterns
}
];

// MARK: Node builds

const nodeBuildPlugins = [
typescriptPlugin({
typescript,
tsconfigOverride: {
compilerOptions: {
target: 'es2017'
}
},
clean: true
}),
json(),
// Needed as we also use the *.proto files
copy({
assets: ['./src/protos']
}),
replace({
'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('src/protos')
})
];

const nodeBuilds = [
// Persistence build
{
input: 'index.node.ts',
output: [{ file: pkg['main-esm2017'], format: 'es', sourcemap: true }],
plugins: nodeBuildPlugins,
external: resolveNodeExterns
},
// Memory-only build
{
input: 'index.node.memory.ts',
output: [
{
file: path.resolve('./memory', memoryPkg['main-esm2017']),
format: 'es',
sourcemap: true
}
],
plugins: nodeBuildPlugins,
external: resolveNodeExterns
}
];

export default [...browserBuilds, ...nodeBuilds];
119 changes: 119 additions & 0 deletions packages/firestore/rollup.config.es5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* @license
* Copyright 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as path from 'path';

import typescriptPlugin from 'rollup-plugin-typescript2';
import sourcemaps from 'rollup-plugin-sourcemaps';
import typescript from 'typescript';
import { terser } from 'rollup-plugin-terser';
import { resolveNodeExterns, resolveBrowserExterns } from './rollup.shared';

import pkg from './package.json';
import memoryPkg from './memory/package.json';

// This file defines the second rollup pipeline and transpiles the ES2017 SDK
// into ES5 code. By splitting the build process into two independent build
// pipelines, we take advantage of tree shaking in ES2017 builds even for
// language levels that don't support tree shaking.

const browserPlugins = [
typescriptPlugin({
typescript,
compilerOptions: {
allowJs: true
},
include: ['dist/*.js']
}),
terser({
output: {
comments: 'all',
beautify: true
},
mangle: true
}),
sourcemaps()
];

const nodePlugins = [
typescriptPlugin({
typescript,
compilerOptions: {
allowJs: true
},
include: ['dist/*.js']
}),
sourcemaps()
];

const browserBuilds = [
{
input: pkg.esm2017,
output: { file: pkg.module, format: 'es', sourcemap: true },
plugins: browserPlugins,
external: resolveBrowserExterns
},
{
input: path.resolve('./memory', memoryPkg.esm2017),
output: {
file: path.resolve('./memory', memoryPkg.module),
format: 'es',
sourcemap: true
},
plugins: browserPlugins,
external: resolveBrowserExterns
},
{
input: pkg.esm2017,
output: { file: pkg.browser, format: 'cjs', sourcemap: true },
plugins: browserPlugins,
external: resolveBrowserExterns
},
{
input: path.resolve('./memory', memoryPkg.esm2017),
output: {
file: path.resolve('./memory', memoryPkg.browser),
format: 'cjs',
sourcemap: true
},
plugins: browserPlugins,
external: resolveBrowserExterns
}
];

const nodeBuilds = [
{
input: pkg['main-esm2017'],
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
plugins: nodePlugins,
external: resolveNodeExterns
},
{
input: path.resolve('./memory', memoryPkg['main-esm2017']),
output: [
{
file: path.resolve('./memory', memoryPkg.main),
format: 'cjs',
sourcemap: true
}
],
plugins: nodePlugins,
external: resolveNodeExterns
}
];

export default [...browserBuilds, ...nodeBuilds];
Loading