Skip to content

Commit bdae2c9

Browse files
authored
Fix release build for firebase-exp/compat (#3702)
* fix compat packages * test * compat release build * Revert "test" This reverts commit 4716a30.
1 parent 8d23612 commit bdae2c9

File tree

6 files changed

+234
-14
lines changed

6 files changed

+234
-14
lines changed

packages-exp/app-compat/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
1818
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
1919
"build": "rollup -c",
20+
"build:release": "rollup -c rollup.config.release.js",
2021
"build:deps": "lerna run --scope @firebase/app-compat --include-dependencies build",
2122
"dev": "rollup -c -w",
2223
"test": "run-p lint test:all",
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**
2+
* @license
3+
* Copyright 2018 Google LLC
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 typescriptPlugin from 'rollup-plugin-typescript2';
19+
import json from 'rollup-plugin-json';
20+
import typescript from 'typescript';
21+
import pkg from './package.json';
22+
import { importPathTransformer } from '../../scripts/exp/ts-transform-import-path';
23+
24+
const deps = Object.keys(
25+
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
26+
);
27+
28+
/**
29+
* ES5 Builds
30+
*/
31+
const es5BuildPlugins = [
32+
typescriptPlugin({
33+
typescript,
34+
clean: true,
35+
abortOnError: false,
36+
transformers: [importPathTransformer]
37+
}),
38+
json()
39+
];
40+
41+
const es5Builds = [
42+
{
43+
input: 'src/index.ts',
44+
output: [
45+
{ file: pkg.main, format: 'cjs', sourcemap: true },
46+
{ file: pkg.module, format: 'es', sourcemap: true }
47+
],
48+
plugins: es5BuildPlugins,
49+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
50+
treeshake: {
51+
moduleSideEffects: false
52+
}
53+
},
54+
{
55+
input: 'src/index.lite.ts',
56+
output: {
57+
file: pkg.lite,
58+
format: 'es',
59+
sourcemap: true
60+
},
61+
plugins: es5BuildPlugins,
62+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
63+
treeshake: {
64+
moduleSideEffects: false
65+
}
66+
}
67+
];
68+
69+
/**
70+
* ES2017 Builds
71+
*/
72+
const es2017BuildPlugins = [
73+
typescriptPlugin({
74+
typescript,
75+
clean: true,
76+
abortOnError: false,
77+
tsconfigOverride: {
78+
compilerOptions: {
79+
target: 'es2017'
80+
}
81+
},
82+
transformers: [importPathTransformer]
83+
}),
84+
json({
85+
preferConst: true
86+
})
87+
];
88+
89+
const es2017Builds = [
90+
/**
91+
* Browser Builds
92+
*/
93+
{
94+
input: 'src/index.ts',
95+
output: {
96+
file: pkg.esm2017,
97+
format: 'es',
98+
sourcemap: true
99+
},
100+
plugins: es2017BuildPlugins,
101+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
102+
treeshake: {
103+
moduleSideEffects: false
104+
}
105+
},
106+
{
107+
input: 'src/index.lite.ts',
108+
output: {
109+
file: pkg['lite-esm2017'],
110+
format: 'es',
111+
sourcemap: true
112+
},
113+
plugins: es2017BuildPlugins,
114+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
115+
treeshake: {
116+
moduleSideEffects: false
117+
}
118+
}
119+
];
120+
121+
export default [...es5Builds, ...es2017Builds];
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
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 { resolve } from 'path';
19+
import sourcemaps from 'rollup-plugin-sourcemaps';
20+
import rollupTypescriptPlugin from 'rollup-plugin-typescript2';
21+
import typescript from 'typescript';
22+
import json from 'rollup-plugin-json';
23+
import pkg from '../package.json';
24+
import compatPkg from './package.json';
25+
import appPkg from './app/package.json';
26+
27+
const external = Object.keys(pkg.dependencies || {});
28+
29+
const plugins = [sourcemaps(), json()];
30+
31+
const typescriptPlugin = rollupTypescriptPlugin({
32+
typescript,
33+
tsconfigOverride: {
34+
compilerOptions: {
35+
declaration: false
36+
}
37+
}
38+
});
39+
40+
/**
41+
* Individual Component Builds
42+
*/
43+
const appBuilds = [
44+
/**
45+
* App Browser Builds
46+
*/
47+
{
48+
input: `${__dirname}/app/index.ts`,
49+
output: [
50+
{
51+
file: resolve(__dirname, 'app', appPkg.main),
52+
format: 'cjs',
53+
sourcemap: true
54+
},
55+
{
56+
file: resolve(__dirname, 'app', appPkg.module),
57+
format: 'es',
58+
sourcemap: true
59+
}
60+
],
61+
plugins: [...plugins, typescriptPlugin],
62+
external
63+
}
64+
];
65+
66+
const componentBuilds = compatPkg.components
67+
// The "app" component is treated differently because it doesn't depend on itself.
68+
.filter(component => component !== 'app')
69+
.map(component => {
70+
const pkg = require(`${__dirname}/${component}/package.json`);
71+
return [
72+
{
73+
input: `${__dirname}/${component}/index.ts`,
74+
output: [
75+
{
76+
file: resolve(__dirname, component, pkg.main),
77+
format: 'cjs',
78+
sourcemap: true
79+
},
80+
{
81+
file: resolve(__dirname, component, pkg.module),
82+
format: 'es',
83+
sourcemap: true
84+
}
85+
],
86+
plugins: [...plugins, typescriptPlugin],
87+
external
88+
}
89+
];
90+
})
91+
.reduce((a, b) => a.concat(b), []);
92+
93+
export default [...appBuilds, ...componentBuilds];

packages-exp/firebase-exp/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
},
2929
"scripts": {
3030
"build": "rollup -c && gulp firebase-js && yarn build:compat",
31-
"build:release": "rollup -c rollup.config.release.js && gulp firebase-js && yarn build:compat",
31+
"build:release": "rollup -c rollup.config.release.js && gulp firebase-js && yarn build:compat:release",
3232
"build:compat": "rollup -c compat/rollup.config.js",
33+
"build:compat:release": "rollup -c compat/rollup.config.release.js",
3334
"dev": "rollup -c -w",
3435
"prepare": "yarn build:release",
3536
"test": "echo 'No test suite for firebase wrapper'",

packages-exp/firebase-exp/rollup.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ const componentBuilds = pkg.components
116116
.filter(component => component !== 'app')
117117
.map(component => {
118118
const pkg = require(`./${component}/package.json`);
119+
// It is needed for handling sub modules, for example firestore/lite which should produce firebase-firestore-lite.js
120+
// Otherwise, we will create a directory with '/' in the name.
121+
const componentName = component.replace('/', '-');
119122
return [
120123
{
121124
input: `${component}/index.ts`,
@@ -136,7 +139,10 @@ const componentBuilds = pkg.components
136139
},
137140
{
138141
input: `${component}/index.ts`,
139-
output: createUmdOutputConfig(`firebase-${component}.js`, component),
142+
output: createUmdOutputConfig(
143+
`firebase-${componentName}.js`,
144+
componentName
145+
),
140146
plugins: [...plugins, typescriptPluginUMD, uglify()],
141147
external: ['@firebase/app-exp']
142148
}

scripts/exp/release.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,18 @@ async function buildPackages() {
135135
}
136136
);
137137

138-
// Build exp packages except for firebase-exp
138+
// Build exp and compat packages except for firebase-exp
139139
await spawn(
140140
'yarn',
141-
['lerna', 'run', '--scope', '@firebase/*-exp', 'build:release'],
141+
[
142+
'lerna',
143+
'run',
144+
'--scope',
145+
'@firebase/*-exp',
146+
'--scope',
147+
'@firebase/*-compat',
148+
'build:release'
149+
],
142150
{
143151
cwd: projectRoot,
144152
stdio: 'inherit'
@@ -156,16 +164,6 @@ async function buildPackages() {
156164
}
157165
);
158166

159-
// Build compat packages
160-
await spawn(
161-
'yarn',
162-
['lerna', 'run', '--scope', '@firebase/*-compat', 'build'],
163-
{
164-
cwd: projectRoot,
165-
stdio: 'inherit'
166-
}
167-
);
168-
169167
// Build firebase-exp
170168
await spawn(
171169
'yarn',

0 commit comments

Comments
 (0)