Skip to content

Fix release build for firebase-exp/compat #3702

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 4 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all 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-exp/app-compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
"build": "rollup -c",
"build:release": "rollup -c rollup.config.release.js",
"build:deps": "lerna run --scope @firebase/app-compat --include-dependencies build",
"dev": "rollup -c -w",
"test": "run-p lint test:all",
Expand Down
121 changes: 121 additions & 0 deletions packages-exp/app-compat/rollup.config.release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**
* @license
* Copyright 2018 Google LLC
*
* 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 typescriptPlugin from 'rollup-plugin-typescript2';
import json from 'rollup-plugin-json';
import typescript from 'typescript';
import pkg from './package.json';
import { importPathTransformer } from '../../scripts/exp/ts-transform-import-path';

const deps = Object.keys(
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
);

/**
* ES5 Builds
*/
const es5BuildPlugins = [
typescriptPlugin({
typescript,
clean: true,
abortOnError: false,
transformers: [importPathTransformer]
}),
json()
];

const es5Builds = [
{
input: 'src/index.ts',
output: [
{ file: pkg.main, format: 'cjs', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true }
],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
treeshake: {
moduleSideEffects: false
}
},
{
input: 'src/index.lite.ts',
output: {
file: pkg.lite,
format: 'es',
sourcemap: true
},
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
treeshake: {
moduleSideEffects: false
}
}
];

/**
* ES2017 Builds
*/
const es2017BuildPlugins = [
typescriptPlugin({
typescript,
clean: true,
abortOnError: false,
tsconfigOverride: {
compilerOptions: {
target: 'es2017'
}
},
transformers: [importPathTransformer]
}),
json({
preferConst: true
})
];

const es2017Builds = [
/**
* Browser Builds
*/
{
input: 'src/index.ts',
output: {
file: pkg.esm2017,
format: 'es',
sourcemap: true
},
plugins: es2017BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
treeshake: {
moduleSideEffects: false
}
},
{
input: 'src/index.lite.ts',
output: {
file: pkg['lite-esm2017'],
format: 'es',
sourcemap: true
},
plugins: es2017BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
treeshake: {
moduleSideEffects: false
}
}
];

export default [...es5Builds, ...es2017Builds];
93 changes: 93 additions & 0 deletions packages-exp/firebase-exp/compat/rollup.config.release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* @license
* Copyright 2020 Google LLC
*
* 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 { resolve } from 'path';
import sourcemaps from 'rollup-plugin-sourcemaps';
import rollupTypescriptPlugin from 'rollup-plugin-typescript2';
import typescript from 'typescript';
import json from 'rollup-plugin-json';
import pkg from '../package.json';
import compatPkg from './package.json';
import appPkg from './app/package.json';

const external = Object.keys(pkg.dependencies || {});

const plugins = [sourcemaps(), json()];

const typescriptPlugin = rollupTypescriptPlugin({
typescript,
tsconfigOverride: {
compilerOptions: {
declaration: false
}
}
});

/**
* Individual Component Builds
*/
const appBuilds = [
/**
* App Browser Builds
*/
{
input: `${__dirname}/app/index.ts`,
output: [
{
file: resolve(__dirname, 'app', appPkg.main),
format: 'cjs',
sourcemap: true
},
{
file: resolve(__dirname, 'app', appPkg.module),
format: 'es',
sourcemap: true
}
],
plugins: [...plugins, typescriptPlugin],
external
}
];

const componentBuilds = compatPkg.components
// The "app" component is treated differently because it doesn't depend on itself.
.filter(component => component !== 'app')
.map(component => {
const pkg = require(`${__dirname}/${component}/package.json`);
return [
{
input: `${__dirname}/${component}/index.ts`,
output: [
{
file: resolve(__dirname, component, pkg.main),
format: 'cjs',
sourcemap: true
},
{
file: resolve(__dirname, component, pkg.module),
format: 'es',
sourcemap: true
}
],
plugins: [...plugins, typescriptPlugin],
external
}
];
})
.reduce((a, b) => a.concat(b), []);

export default [...appBuilds, ...componentBuilds];
3 changes: 2 additions & 1 deletion packages-exp/firebase-exp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
},
"scripts": {
"build": "rollup -c && gulp firebase-js && yarn build:compat",
"build:release": "rollup -c rollup.config.release.js && gulp firebase-js && yarn build:compat",
"build:release": "rollup -c rollup.config.release.js && gulp firebase-js && yarn build:compat:release",
"build:compat": "rollup -c compat/rollup.config.js",
"build:compat:release": "rollup -c compat/rollup.config.release.js",
"dev": "rollup -c -w",
"prepare": "yarn build:release",
"test": "echo 'No test suite for firebase wrapper'",
Expand Down
8 changes: 7 additions & 1 deletion packages-exp/firebase-exp/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ const componentBuilds = pkg.components
.filter(component => component !== 'app')
.map(component => {
const pkg = require(`./${component}/package.json`);
// It is needed for handling sub modules, for example firestore/lite which should produce firebase-firestore-lite.js
// Otherwise, we will create a directory with '/' in the name.
const componentName = component.replace('/', '-');
return [
{
input: `${component}/index.ts`,
Expand All @@ -136,7 +139,10 @@ const componentBuilds = pkg.components
},
{
input: `${component}/index.ts`,
output: createUmdOutputConfig(`firebase-${component}.js`, component),
output: createUmdOutputConfig(
`firebase-${componentName}.js`,
componentName
),
plugins: [...plugins, typescriptPluginUMD, uglify()],
external: ['@firebase/app-exp']
}
Expand Down
22 changes: 10 additions & 12 deletions scripts/exp/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,18 @@ async function buildPackages() {
}
);

// Build exp packages except for firebase-exp
// Build exp and compat packages except for firebase-exp
await spawn(
'yarn',
['lerna', 'run', '--scope', '@firebase/*-exp', 'build:release'],
[
'lerna',
'run',
'--scope',
'@firebase/*-exp',
'--scope',
'@firebase/*-compat',
'build:release'
],
{
cwd: projectRoot,
stdio: 'inherit'
Expand All @@ -156,16 +164,6 @@ async function buildPackages() {
}
);

// Build compat packages
await spawn(
'yarn',
['lerna', 'run', '--scope', '@firebase/*-compat', 'build'],
{
cwd: projectRoot,
stdio: 'inherit'
}
);

// Build firebase-exp
await spawn(
'yarn',
Expand Down