Skip to content

Commit

Permalink
report build variants for packages (#5596)
Browse files Browse the repository at this point in the history
* report build variants for app

* report build target for firestore

* report runtime env for app

* report build target for auth

* report build target for database and analytics

* report build variants for functions

* report build variants for installations

* report things for fcm

* report build variant for perf

* report build variants for storage

* Create stupid-scissors-compare.md

* fix lint

* prettier

* update typing paths
  • Loading branch information
Feiyang1 authored Oct 12, 2021
1 parent f5a1714 commit 93795c7
Show file tree
Hide file tree
Showing 32 changed files with 458 additions and 89 deletions.
15 changes: 15 additions & 0 deletions .changeset/stupid-scissors-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@firebase/analytics": patch
"@firebase/app": patch
"@firebase/auth": patch
"@firebase/database": patch
"@firebase/firestore": patch
"@firebase/functions": patch
"@firebase/installations": patch
"@firebase/messaging": patch
"@firebase/performance": patch
"@firebase/remote-config": patch
"@firebase/storage": patch
---

report build variants for packages
26 changes: 20 additions & 6 deletions packages/analytics/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

import json from '@rollup/plugin-json';
import typescriptPlugin from 'rollup-plugin-typescript2';
import replace from 'rollup-plugin-replace';
import typescript from 'typescript';
import { generateBuildTargetReplaceConfig } from '../../scripts/build/rollup_replace_build_target';
import pkg from './package.json';

const deps = [
Expand All @@ -40,12 +42,21 @@ const es5Builds = [
*/
{
input: 'src/index.ts',
output: [
{ file: pkg.main, format: 'cjs', sourcemap: true },
{ file: pkg.esm5, format: 'es', sourcemap: true }
],
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
plugins: es5BuildPlugins
plugins: [
...es5BuildPlugins,
replace(generateBuildTargetReplaceConfig('cjs', 5))
]
},
{
input: 'src/index.ts',
output: [{ file: pkg.esm5, format: 'es', sourcemap: true }],
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
plugins: [
...es5BuildPlugins,
replace(generateBuildTargetReplaceConfig('esm', 5))
]
}
];

Expand Down Expand Up @@ -76,7 +87,10 @@ const es2017Builds = [
sourcemap: true
},
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
plugins: es2017BuildPlugins
plugins: [
...es2017BuildPlugins,
replace(generateBuildTargetReplaceConfig('esm', 2017))
]
}
];

Expand Down
2 changes: 2 additions & 0 deletions packages/analytics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ function registerAnalytics(): void {
);

registerVersion(name, version);
// BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
registerVersion(name, version, '__BUILD_TARGET__');

function internalFactory(
container: ComponentContainer
Expand Down
26 changes: 23 additions & 3 deletions packages/app/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
*/

import typescriptPlugin from 'rollup-plugin-typescript2';
import replace from 'rollup-plugin-replace';
import typescript from 'typescript';
import json from '@rollup/plugin-json';
import { generateBuildTargetReplaceConfig } from '../../scripts/build/rollup_replace_build_target';
import pkg from './package.json';

const deps = Object.keys(
Expand All @@ -42,7 +44,13 @@ const es5Builds = [
input: 'src/index.ts',
output: [{ file: pkg.esm5, format: 'es', sourcemap: true }],
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
plugins: es5BuildPlugins
plugins: [
...es5BuildPlugins,
replace({
...generateBuildTargetReplaceConfig('esm', 5),
'__RUNTIME_ENV__': ''
})
]
},
/**
* Node.js Build
Expand All @@ -51,7 +59,13 @@ const es5Builds = [
input: 'src/index.ts',
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
plugins: es5BuildPlugins
plugins: [
...es5BuildPlugins,
replace({
...generateBuildTargetReplaceConfig('cjs', 5),
'__RUNTIME_ENV__': 'node'
})
]
}
];

Expand Down Expand Up @@ -84,7 +98,13 @@ const es2017Builds = [
sourcemap: true
},
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
plugins: es2017BuildPlugins
plugins: [
...es2017BuildPlugins,
replace({
...generateBuildTargetReplaceConfig('esm', 2017),
'__RUNTIME_ENV__': ''
})
]
}
];

Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ export * from './api';
export * from './internal';
export * from './public-types';

registerCoreComponents();
registerCoreComponents('__RUNTIME_ENV__');
2 changes: 2 additions & 0 deletions packages/app/src/registerCoreComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export function registerCoreComponents(variant?: string): void {

// Register `app` package.
registerVersion(name, version, variant);
// BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
registerVersion(name, version, '__BUILD_TARGET__');
// Register platform SDK identifier (no version).
registerVersion('fire-js', '');
}
42 changes: 29 additions & 13 deletions packages/auth/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import strip from '@rollup/plugin-strip';
import typescriptPlugin from 'rollup-plugin-typescript2';
import json from '@rollup/plugin-json';
import replace from 'rollup-plugin-replace';
import typescript from 'typescript';
import alias from '@rollup/plugin-alias';
import { generateBuildTargetReplaceConfig } from '../../scripts/build/rollup_replace_build_target';
import pkg from './package.json';

const deps = Object.keys(Object.assign({}, pkg.peerDependencies, pkg.dependencies));
Expand All @@ -30,14 +32,14 @@ const deps = Object.keys(Object.assign({}, pkg.peerDependencies, pkg.dependencie
* more info. This regex tests explicitly ./src/platform_browser so that the
* only impacted file is the main index.ts
*/
const nodeAliasPlugin = alias({
const nodeAliasPlugin = alias({
entries: [
{
find: /^\.\/src\/platform_browser(\/.*)?$/,
replacement: `./src/platform_node`
}
{
find: /^\.\/src\/platform_browser(\/.*)?$/,
replacement: `./src/platform_node`
}
]
});
});
/**
* ES5 Builds
*/
Expand All @@ -60,8 +62,8 @@ const es5Builds = [
index: 'index.ts',
internal: 'internal/index.ts'
},
output: [{ dir: 'dist/esm5', format: 'esm', sourcemap: true }],
plugins: es5BuildPlugins,
output: [{ dir: 'dist/esm5', format: 'es', sourcemap: true }],
plugins: [...es5BuildPlugins, replace(generateBuildTargetReplaceConfig('esm', 5))],
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},
/**
Expand All @@ -86,7 +88,8 @@ const es5Builds = [
]
}

})
}),
replace(generateBuildTargetReplaceConfig('esm', 5))
],
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},
Expand All @@ -99,7 +102,11 @@ const es5Builds = [
internal: 'internal/index.ts'
},
output: [{ dir: 'dist/node', format: 'cjs', sourcemap: true }],
plugins: [nodeAliasPlugin, ...es5BuildPlugins],
plugins: [
nodeAliasPlugin,
...es5BuildPlugins,
replace(generateBuildTargetReplaceConfig('cjs', 5))
],
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},
/**
Expand All @@ -111,7 +118,10 @@ const es5Builds = [
internal: 'internal/index.ts'
},
output: [{ dir: 'dist/cordova', format: 'es', sourcemap: true }],
plugins: es5BuildPlugins,
plugins: [
...es5BuildPlugins,
replace(generateBuildTargetReplaceConfig('esm', 5))
],
external: id =>
[...deps, 'cordova'].some(dep => id === dep || id.startsWith(`${dep}/`))
},
Expand All @@ -124,7 +134,10 @@ const es5Builds = [
internal: 'internal/index.ts'
},
output: [{ dir: 'dist/rn', format: 'cjs', sourcemap: true }],
plugins: es5BuildPlugins,
plugins: [
...es5BuildPlugins,
replace(generateBuildTargetReplaceConfig('cjs', 5))
],
external: id =>
[...deps, 'react-native'].some(
dep => id === dep || id.startsWith(`${dep}/`)
Expand Down Expand Up @@ -164,7 +177,10 @@ const es2017Builds = [
format: 'es',
sourcemap: true
},
plugins: es2017BuildPlugins,
plugins: [
...es2017BuildPlugins,
replace(generateBuildTargetReplaceConfig('esm', 2017))
],
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];
Expand Down
2 changes: 2 additions & 0 deletions packages/auth/src/core/auth/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,6 @@ export function registerAuth(clientPlatform: ClientPlatform): void {
);

registerVersion(name, version, getVersionForPlatform(clientPlatform));
// BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
registerVersion(name, version, '__BUILD_TARGET__');
}
17 changes: 14 additions & 3 deletions packages/database/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

import json from '@rollup/plugin-json';
import typescriptPlugin from 'rollup-plugin-typescript2';
import replace from 'rollup-plugin-replace';
import typescript from 'typescript';
import { generateBuildTargetReplaceConfig } from '../../scripts/build/rollup_replace_build_target';
import pkg from './package.json';

const deps = [
Expand Down Expand Up @@ -50,7 +52,10 @@ const es5Builds = [
{
input: 'src/index.node.ts',
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
plugins: es5BuildPlugins,
plugins: [
...es5BuildPlugins,
replace(generateBuildTargetReplaceConfig('cjs', 5))
],
treeshake: {
moduleSideEffects: false
},
Expand All @@ -69,7 +74,10 @@ const es5Builds = [
sourcemap: true
}
],
plugins: es5BuildPlugins,
plugins: [
...es5BuildPlugins,
replace(generateBuildTargetReplaceConfig('esm', 5))
],
treeshake: {
moduleSideEffects: false
},
Expand Down Expand Up @@ -120,7 +128,10 @@ const es2017Builds = [
sourcemap: true
}
],
plugins: es2017BuildPlugins,
plugins: [
...es2017BuildPlugins,
replace(generateBuildTargetReplaceConfig('esm', 2017))
],
treeshake: {
moduleSideEffects: false
},
Expand Down
2 changes: 2 additions & 0 deletions packages/database/src/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ export function registerDatabase(variant?: string): void {
).setMultipleInstances(true)
);
registerVersion(name, version, variant);
// BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
registerVersion(name, version, '__BUILD_TARGET__');
}
4 changes: 3 additions & 1 deletion packages/firestore/lite/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ export function registerFirestore(): void {
ComponentType.PUBLIC
)
);
registerVersion('firestore-lite', version, 'node');
// RUNTIME_ENV and BUILD_TARGET are replaced by real values during the compilation
registerVersion('firestore-lite', version, '__RUNTIME_ENV__');
registerVersion('firestore-lite', version, '__BUILD_TARGET__');
}
Loading

0 comments on commit 93795c7

Please sign in to comment.