Skip to content

Minified Console Build #3805

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 8 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 1 addition & 2 deletions packages/firestore/index.console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

export { Firestore, FirestoreDatabase } from './src/api/database';
export { Firestore } from './src/api/database';
export {
CollectionReference,
DocumentReference,
Expand All @@ -24,7 +24,6 @@ export {
} from './src/api/database';
export { Blob } from './src/api/blob';
export { GeoPoint } from './src/api/geo_point';
export { FirstPartyCredentialsSettings } from './src/api/credentials';
export { FieldPath } from './src/api/field_path';
export { FieldValue } from './src/api/field_value';
export { Timestamp } from './src/api/timestamp';
12 changes: 8 additions & 4 deletions packages/firestore/rollup.shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ exports.es2017ToEs5Plugins = function (mangled = false) {
return [
typescriptPlugin({
typescript,
compilerOptions: {
allowJs: true
tsconfigOverride: {
compilerOptions: {
allowJs: true
}
},
include: ['dist/*.js', 'dist/exp/*.js']
}),
Expand All @@ -193,8 +195,10 @@ exports.es2017ToEs5Plugins = function (mangled = false) {
return [
typescriptPlugin({
typescript,
compilerOptions: {
allowJs: true
tsconfigOverride: {
compilerOptions: {
allowJs: true
}
},
include: ['dist/*.js', 'dist/exp/*.js']
}),
Expand Down
20 changes: 11 additions & 9 deletions packages/firestore/src/api/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ import { logDebug } from '../util/log';
// moved to an auth/ folder to match other platforms.

export interface FirstPartyCredentialsSettings {
type: 'gapi';
client: unknown;
sessionIndex: string;
// These are external types. Prevent minification.
['type']: 'gapi';
['client']: unknown;
['sessionIndex']: string;
}

export interface ProviderCredentialsSettings {
type: 'provider';
client: CredentialsProvider;
// These are external types. Prevent minification.
['type']: 'provider';
['client']: CredentialsProvider;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make any difference? These are just types which won't be minified anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are making the change to be able to do credentials['type'], it's not necessary. Typescript will allow you to do indexing as expected.

Copy link
Contributor Author

@schmidt-sebastian schmidt-sebastian Sep 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This blocks the rename during the TypeScript transformation, which is probably sane to do if we want the source to also not be minified.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. that makes sense

}

/** Settings for private credentials */
Expand Down Expand Up @@ -336,9 +338,9 @@ export function makeCredentialsProvider(
return new EmptyCredentialsProvider();
}

switch (credentials.type) {
switch (credentials['type']) {
case 'gapi':
const client = credentials.client as Gapi;
const client = credentials['client'] as Gapi;
// Make sure this really is a Gapi client.
hardAssert(
!!(
Expand All @@ -351,11 +353,11 @@ export function makeCredentialsProvider(
);
return new FirstPartyCredentialsProvider(
client,
credentials.sessionIndex || '0'
credentials['sessionIndex'] || '0'
);

case 'provider':
return credentials.client;
return credentials['client'];

default:
throw new FirestoreError(
Expand Down
69 changes: 40 additions & 29 deletions packages/firestore/tools/console.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,50 @@
* This file creates a build target for it.
*/
const rollup = require('rollup');
const typescriptPlugin = require('rollup-plugin-typescript2');
const typescript = require('typescript');
const json = require('rollup-plugin-json');
const alias = require('@rollup/plugin-alias');
const resolve = require('rollup-plugin-node-resolve');
const { uglify } = require('rollup-plugin-uglify');
const fs = require('fs');
const util = require('util');
const fs_writeFile = util.promisify(fs.writeFile);

const rollupUtil = require('../rollup.shared');

const plugins = [
alias(rollupUtil.generateAliasConfig('browser')),
resolve(),
typescriptPlugin({
typescript
}),
json(),
uglify({
output: {
ascii_only: true // escape unicode chars
}
})
];

const EXPORTNAME = '__firestore_exports__';

const inputOptions = {
const esm2017OutputFile = 'dist/standalone.esm2017.js';
const esm5OutputFile = 'dist/standalone.js';

const es2017InputOptions = {
input: 'index.console.ts',
plugins
plugins: rollupUtil.es2017Plugins('browser', /* mangled= */ true),
external: rollupUtil.resolveBrowserExterns,
treeshake: {
moduleSideEffects: false
}
};

const es2017OutputOptions = {
file: esm2017OutputFile,
format: 'es'
};
const outputOptions = {
file: 'dist/standalone.js',

const es2017toEs5InputOptions = {
input: esm2017OutputFile,
plugins: [
...rollupUtil.es2017ToEs5Plugins(/* mangled= */ true),
uglify({
output: {
ascii_only: true // escape unicode chars
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! Found the solution for #414

}
})
],
external: rollupUtil.resolveBrowserExterns,
treeshake: {
moduleSideEffects: false
}
};

const es2017toEs5OutputOptions = {
file: esm5OutputFile,
name: EXPORTNAME,
format: 'iife'
};
Expand All @@ -65,17 +75,18 @@ exports = eval(`;
const POSTFIX = ` + '${EXPORTNAME};');`;

async function build() {
// create a bundle
const bundle = await rollup.rollup(inputOptions);
// Create an ES2017 bundle
const es2017Bundle = await rollup.rollup(es2017InputOptions);
await es2017Bundle.write(es2017OutputOptions);

// generate code
// Transpile down to ES5
const es5Bundle = await rollup.rollup(es2017toEs5InputOptions);
const {
output: [{ code }]
} = await bundle.generate(outputOptions);
} = await es5Bundle.generate(es2017toEs5OutputOptions);

const output = `${PREFIX}${JSON.stringify(String(code))}${POSTFIX}`;

await fs_writeFile(outputOptions.file, output, 'utf-8');
await fs_writeFile(es2017toEs5OutputOptions.file, output, 'utf-8');
}

build();