Skip to content
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

Added ES module bundle to the auth package #819

Merged
merged 17 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
36 changes: 28 additions & 8 deletions packages/auth/buildtools/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,33 @@
#
# Travis will run `npm test -- --saucelabs`.

# Since yarn workspaces might hoist our packages, we have to fallback to
# ../../node_modules when we want to execute a script.
declare -a nodeModulesBasedirs=(
"./node_modules/.bin"
"../../node_modules/.bin"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add new line after this


# Tries to resolve the first argument as an npm executable, taking hoisting into
# account. If case of a successful resolution, executes the binary, passing
# the rest of given arguments to an invocation.
function evalModule {
for basedir in "${nodeModulesBasedirs[@]}"
do
if [ -f "$basedir/$1" ]; then
eval "$basedir/$1 ${@:2}"
break
fi
done
}

cd "$(dirname $(dirname "$0"))"

function killServer () {
if [ "$seleniumStarted" = true ]; then
echo "Stopping Selenium..."
./node_modules/.bin/webdriver-manager shutdown
./node_modules/.bin/webdriver-manager clean
evalModule webdriver-manager shutdown
evalModule webdriver-manager clean
# Selenium is not getting shutdown. Send a kill signal.
lsof -t -i :4444 | xargs kill
fi
Expand All @@ -62,7 +82,7 @@ function killServer () {
}

# Start the local webserver.
./node_modules/.bin/gulp serve &
evalModule gulp "serve &"
serverPid=$!
echo "Local HTTP Server started with PID $serverPid."

Expand All @@ -75,17 +95,17 @@ if [[ $1 = "--saucelabs" ]]; then
sleep 2
echo "Using SauceLabs."
# $2 contains the tunnelIdentifier argument if specified, otherwise is empty.
./node_modules/.bin/protractor protractor.conf.js --saucelabs $2
evalModule protractor protractor.conf.js --saucelabs $2
else
echo "Using Chrome and Firefox."
./node_modules/.bin/webdriver-manager clean
evalModule webdriver-manager clean
# Updates Selenium Webdriver.
./node_modules/.bin/webdriver-manager update
evalModule webdriver-manager update
# Start Selenium Webdriver.
./node_modules/.bin/webdriver-manager start &>/dev/null &
evalModule webdriver-manager start &>/dev/null &
seleniumStarted=true
echo "Selenium Server started."
# Wait for servers to come up.
sleep 10
./node_modules/.bin/protractor protractor.conf.js
evalModule protractor protractor.conf.js
fi
102 changes: 71 additions & 31 deletions packages/auth/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,90 @@ const closureCompiler = require('gulp-closure-compiler');
const del = require('del');
const express = require('express');
const path = require('path');
const { through } = require('event-stream');
const File = require('vinyl');

// The optimization level for the JS compiler.
// Valid levels: WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, ADVANCED_OPTIMIZATIONS.
// TODO: Add ability to pass this in as a flag.
const OPTIMIZATION_LEVEL = 'ADVANCED_OPTIMIZATIONS';

// For minified builds, wrap the output so we avoid leaking global variables.
const OUTPUT_WRAPPER = `(function() {
var firebase = require('@firebase/app').default;
%output%
}).call(typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : {});`;
const CJS_WRAPPER_PREFIX =
`(function() {var firebase = require('@firebase/app').default;`;
const EMS_WRAPPER_PREFIX = `import firebase from '@firebase/app';(function() {`;
const WRAPPER_SUFFIX =
`}).call(typeof global !== 'undefined' ? ` +
`global : typeof self !== 'undefined' ? ` +
`self : typeof window !== 'undefined' ? window : {});`;

/*
* Re-emits file variations surrounding a content of an input file with
* CommonJS and EcmaScript modules wrappers.
*/
const wrap = through(function(file) {
const makeFile = (prefix, path) =>
new File({
path,
contents: Buffer.concat([
Buffer.from(prefix),
file.contents,
Buffer.from(WRAPPER_SUFFIX)
])
});

this.emit('data', makeFile(CJS_WRAPPER_PREFIX, 'auth.js'));
this.emit('data', makeFile(EMS_WRAPPER_PREFIX, 'auth.esm.js'));
});

// The path to Closure Compiler.
const COMPILER_PATH = `${path.dirname(require.resolve('google-closure-compiler/package.json'))}/compiler.jar`;
const COMPILER_PATH = `${path.dirname(
require.resolve('google-closure-compiler/package.json')
)}/compiler.jar`;

const closureLibRoot = path.dirname(require.resolve('google-closure-library/package.json'));
// Builds the core Firebase-auth JS.
const closureLibRoot = path.dirname(
require.resolve('google-closure-library/package.json')
);

function buildFirebaseAuth() {
return gulp
// Builds the core Firebase-auth JS.
const buildFirebaseAuth = () =>
gulp
.src([
`${closureLibRoot}/closure/goog/**/*.js`,
`${closureLibRoot}/third_party/closure/goog/**/*.js`,
'src/**/*.js'
])
.pipe(closureCompiler({
compilerPath: COMPILER_PATH,
fileName: 'auth.js',
compilerFlags: {
closure_entry_point: 'fireauth.exports',
compilation_level: OPTIMIZATION_LEVEL,
externs: [
'externs/externs.js',
'externs/grecaptcha.js',
'externs/gapi.iframes.js',
path.resolve(__dirname, '../firebase/externs/firebase-app-externs.js'),
path.resolve(__dirname, '../firebase/externs/firebase-error-externs.js'),
path.resolve(__dirname, '../firebase/externs/firebase-app-internal-externs.js')
],
language_out: 'ES5',
only_closure_dependencies: true,
output_wrapper: OUTPUT_WRAPPER
}
}))
.pipe(
closureCompiler({
compilerPath: COMPILER_PATH,
fileName: 'unwrapped.js',
compilerFlags: {
closure_entry_point: 'fireauth.exports',
compilation_level: OPTIMIZATION_LEVEL,
externs: [
'externs/externs.js',
'externs/grecaptcha.js',
'externs/gapi.iframes.js',
path.resolve(
__dirname,
'../firebase/externs/firebase-app-externs.js'
),
path.resolve(
__dirname,
'../firebase/externs/firebase-error-externs.js'
),
path.resolve(
__dirname,
'../firebase/externs/firebase-app-internal-externs.js'
)
],
language_out: 'ES5',
only_closure_dependencies: true
}
})
)
.pipe(wrap)
.pipe(gulp.dest('dist'));
}

gulp.task('build-firebase-auth-js', buildFirebaseAuth);

Expand All @@ -75,11 +113,13 @@ gulp.task('clean', done => del(['dist/*', 'dist'], done));
gulp.task('serve', () => {
const app = express();

app.use('/node_modules', express.static(path.resolve(__dirname, '../../node_modules')));
app.use(
'/node_modules',
express.static(path.resolve(__dirname, '../../node_modules'))
);
app.use(express.static(__dirname));

app.listen(4000);
});


gulp.task('default', buildFirebaseAuth);
13 changes: 8 additions & 5 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "@firebase/auth",
"version": "0.5.3",
"version": "0.6.0",
"main": "dist/auth.js",
"module": "dist/auth.esm.js",
"description": "Javascript library for Firebase Auth SDK",
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
"files": [
Expand All @@ -10,11 +11,11 @@
],
"scripts": {
"build": "gulp",
"test": "npm run build && npm run generate-test-files && ./buildtools/run_tests.sh",
"serve": "npm run build && npm run generate-test-files && gulp serve",
"demo": "./buildtools/run_demo.sh",
"generate-test-files": "./buildtools/generate_test_files.sh",
"prepare": "npm run build"
"prepare": "npm run build",
"serve": "npm run build && npm run generate-test-files && gulp serve",
"test": "npm run generate-test-files && ./buildtools/run_tests.sh"
},
"license": "Apache-2.0",
"dependencies": {
Expand All @@ -23,14 +24,16 @@
"devDependencies": {
"closure-builder": "2.2.39",
"del": "3.0.0",
"event-stream": "^3.3.4",
"express": "4.16.3",
"firebase-functions": "1.0.1",
"firebase-tools": "3.18.2",
"google-closure-compiler": "20180402.0.0",
"google-closure-library": "20180405.0.0",
"gulp": "4.0.0",
"gulp-closure-compiler": "0.4.0",
"protractor": "5.3.1"
"protractor": "5.3.1",
"vinyl": "^2.1.0"
},
"repository": {
"type": "git",
Expand Down