Skip to content

Commit 8a998e6

Browse files
authored
provide ESM for FirebaseUI (#605)
* added esm module * removed extra newline
1 parent 2db4161 commit 8a998e6

File tree

4 files changed

+1101
-1824
lines changed

4 files changed

+1101
-1824
lines changed

gulpfile.js

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,32 @@ const OPTIMIZATION_LEVEL = util.env.compilation_level ||
3737

3838
// For minified builds, wrap the output so we avoid leaking global variables.
3939
const OUTPUT_WRAPPER = OPTIMIZATION_LEVEL === 'WHITESPACE_ONLY' ?
40-
'%output%' : '(function() { %output% })();';
40+
'%output%' : '(function() { %output% }).apply(' +
41+
'typeof global !== \'undefined\' ? global : typeof self !== \'undefined\' ' +
42+
'? self : window );';
4143

42-
// Provides missing dialogPolyfill on window in npm environments.
44+
// Provides missing dialogPolyfill on window in cjs environments.
4345
const DIALOG_POLYFILL = 'if(typeof window!==\'undefined\')' +
4446
'{window.dialogPolyfill=require(\'dialog-polyfill\');}';
4547

48+
// Provides missing dialogPolyfill on window for esm.
49+
const ESM_DIALOG_POLYFILL = 'if(typeof window!==\'undefined\')' +
50+
'{window.dialogPolyfill=dialogPolyfill;}';
51+
4652
// Using default import if available.
4753
const DEFAULT_IMPORT_FIX = 'if(typeof firebase.default!==\'undefined\')' +
4854
'{firebase=firebase.default;}';
4955

50-
// Adds the module requirement and exports firebaseui.
56+
// Import esm modules.
57+
const ESM_IMPORT = 'import * as firebase from \'firebase/app\';' +
58+
'import \'firebase/auth\';' +
59+
'import dialogPolyfill from \'dialog-polyfill\';';
60+
61+
// Export firebaseui.auth module.
62+
const ESM_EXPORT = 'const auth = firebaseui.auth;' +
63+
'export { auth } ;';
64+
65+
// Adds the cjs module requirement and exports firebaseui.
5166
const NPM_MODULE_WRAPPER = OPTIMIZATION_LEVEL === 'WHITESPACE_ONLY' ?
5267
'var firebase=require(\'firebase/app\');require(\'firebase/auth\');' +
5368
DEFAULT_IMPORT_FIX + '%output%' + DIALOG_POLYFILL +
@@ -56,6 +71,16 @@ const NPM_MODULE_WRAPPER = OPTIMIZATION_LEVEL === 'WHITESPACE_ONLY' ?
5671
'require(\'firebase/auth\');' + DEFAULT_IMPORT_FIX + '%output% ' +
5772
DIALOG_POLYFILL + '})();' + 'module.exports=firebaseui;';
5873

74+
// Adds the module requirement and exports firebaseui.
75+
const ESM_MODULE_WRAPPER = OPTIMIZATION_LEVEL === 'WHITESPACE_ONLY' ?
76+
ESM_IMPORT + '%output%' +
77+
ESM_DIALOG_POLYFILL + ESM_EXPORT :
78+
ESM_IMPORT +
79+
'(function() {' + '%output%' + '}).apply(' +
80+
'typeof global !== \'undefined\' ? global : typeof self !== \'undefined\' ' +
81+
'? self : window );' +
82+
ESM_DIALOG_POLYFILL + ESM_EXPORT;
83+
5984
// The path to Closure Compiler.
6085
const COMPILER_PATH = 'node_modules/google-closure-compiler-java/compiler.jar';
6186

@@ -265,6 +290,12 @@ repeatTaskForAllLocales(
265290
'build-npm-$', ['build-firebaseui-js-$'],
266291
(locale) => concatWithDeps(locale, 'npm', NPM_MODULE_WRAPPER));
267292

293+
// Bundles the FirebaseUI JS with its dependencies as a ESM module. This builds
294+
// the NPM module for all languages.
295+
repeatTaskForAllLocales(
296+
'build-esm-$', ['build-firebaseui-js-$'],
297+
(locale) => concatWithDeps(locale, 'esm', ESM_MODULE_WRAPPER));
298+
268299
// Bundles the FirebaseUI JS with its dependencies for all locales.
269300
// Generates the gulp tasks build-js-de, build-js-fr, etc.
270301
const buildJsTasks = repeatTaskForAllLocales(
@@ -289,6 +320,12 @@ gulp.task('build-npm', gulp.series(
289320
() => makeDefaultFile('npm')
290321
));
291322

323+
// Builds the ESM module for the default language.
324+
gulp.task('build-esm', gulp.series(
325+
'build-esm-' + DEFAULT_LOCALE,
326+
() => makeDefaultFile('esm')
327+
));
328+
292329
/**
293330
* Builds the CSS for FirebaseUI.
294331
* @param {boolean} isRtl Whether to build in right-to-left mode.
@@ -336,13 +373,13 @@ gulp.task('clean', () => fse.remove(TMP_DIR));
336373
// Executes the basic tasks for the default language.
337374
gulp.task('default', gulp.series(
338375
'build-externs', 'build-ts', 'build-js',
339-
'build-npm', 'build-css', 'build-css-rtl',
376+
'build-npm', 'build-esm', 'build-css', 'build-css-rtl',
340377
'clean'
341378
));
342379

343380
// Builds everything (JS for all languages, both LTR and RTL CSS).
344381
gulp.task('build-all', gulp.series(
345382
'build-externs', 'build-ts', 'build-all-js',
346-
'build-npm', 'build-css', 'build-css-rtl',
383+
'build-npm', 'build-esm', 'build-css', 'build-css-rtl',
347384
'clean'
348385
));

javascript/ui/element/listboxdialog.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var element = firebaseui.auth.ui.element;
4646
* @this {goog.ui.Component}
4747
*/
4848
listBoxDialog.showListBoxDialog = function(items, onSelect, opt_selectedId) {
49+
var self = this;
4950
var dialogElement = goog.soy.renderAsElement(
5051
firebaseui.auth.soy2.element.listBoxDialog,
5152
{items: items},
@@ -70,7 +71,7 @@ listBoxDialog.showListBoxDialog = function(items, onSelect, opt_selectedId) {
7071
var listBoxId = pressedButton &&
7172
listBoxDialog.getListBoxIdOfButton_(pressedButton);
7273
if (listBoxId) {
73-
firebaseui.auth.ui.element.dialog.dismissDialog();
74+
firebaseui.auth.ui.element.dialog.dismissDialog.call(self);
7475

7576
// The callback should happen after the dialog is dismissed; otherwise
7677
// focus() within the callback does not work.

0 commit comments

Comments
 (0)