Skip to content

Commit 874a727

Browse files
committed
Add gulpfile
1 parent 7e63eb5 commit 874a727

File tree

5 files changed

+156
-7
lines changed

5 files changed

+156
-7
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/** @type {!Object} */
2+
const module = {};

packages/webchannel-wrapper/externs/overrides.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ goog.net.WebChannel.Options.messageHeaders;
3030
/** @type {Object<string, string>|undefined} */
3131
goog.net.WebChannel.Options.initMessageHeaders;
3232

33-
/** @type {stringboolean|undefined} */
33+
/** @type {string|boolean|undefined} */
3434
goog.net.WebChannel.Options.messageContentType;
3535

3636
/** @type {Object<string, string>|undefined|undefined} */
@@ -63,4 +63,4 @@ goog.net.WebChannel.Options.fastHandshake;
6363
goog.net.WebChannel.Options.internalChannelParams;
6464

6565
/** @type {boolean|undefined} */
66-
goog.net.WebChannel.Options.forceLongPolling;
66+
goog.net.WebChannel.Options.forceLongPolling;
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/**
2+
* @license
3+
* Copyright 2017 Google Inc.
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+
const gulp = require('gulp');
19+
const rollup = require('rollup');
20+
const closureCompiler = require('google-closure-compiler').gulp();
21+
const del = require('del');
22+
const path = require('path');
23+
const sourcemaps = require('gulp-sourcemaps');
24+
const { resolve } = require('path');
25+
const commonjs = require('rollup-plugin-commonjs');
26+
const rollupSourcemaps = require('rollup-plugin-sourcemaps');
27+
28+
// The optimization level for the JS compiler.
29+
// Valid levels: WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, ADVANCED_OPTIMIZATIONS.
30+
// TODO: Add ability to pass this in as a flag.
31+
const OPTIMIZATION_LEVEL = 'ADVANCED_OPTIMIZATIONS';
32+
33+
// For minified builds, wrap the output so we avoid leaking global variables.
34+
// For minified builds, wrap the output so we avoid leaking global variables.
35+
const CJS_WRAPPER_PREFIX = `(function() {var firebase = require('@firebase/app').default;`;
36+
const CJS_WRAPPER_SUFFIX =
37+
`}).apply(typeof global !== 'undefined' ? ` +
38+
`global : typeof self !== 'undefined' ? ` +
39+
`self : typeof window !== 'undefined' ? window : {});`;
40+
41+
const closureLibRoot = path.dirname(
42+
require.resolve('google-closure-library/package.json')
43+
);
44+
45+
const closureDefines = [
46+
// Avoid unsafe eval() calls (https://github.com/firebase/firebase-js-sdk/issues/798)
47+
'goog.json.USE_NATIVE_JSON=true',
48+
// Disable debug logging (saves 8780 bytes).
49+
'goog.DEBUG=false',
50+
// Disable fallbacks for running async code (saves 1472 bytes).
51+
'goog.ASSUME_NATIVE_PROMISE=true',
52+
// Disables IE8-specific event fallback code (saves 523 bytes).
53+
'goog.events.CAPTURE_SIMULATION_MODE=0',
54+
// Disable IE-Specific ActiveX fallback for XHRs (saves 524 bytes).
55+
'goog.net.XmlHttpDefines.ASSUME_NATIVE_XHR=true'
56+
];
57+
58+
/**
59+
* Builds the core Firebase-auth JS.
60+
* @param {string} filename name of the generated file
61+
* @param {string} prefix prefix to the compiled code
62+
* @param {string} suffix suffix to the compiled code
63+
*/
64+
function createBuildTask(filename, prefix, suffix) {
65+
return function closureBuild () {
66+
return gulp
67+
.src(
68+
[
69+
`${closureLibRoot}/closure/goog/**/*.js`,
70+
`${closureLibRoot}/third_party/closure/goog/**/*.js`,
71+
'src/**/*.js'
72+
],
73+
{ base: '.' }
74+
)
75+
.pipe(sourcemaps.init())
76+
.pipe(
77+
closureCompiler({
78+
js_output_file: filename,
79+
output_wrapper: `${prefix}%output%${suffix}`,
80+
entry_point: 'firebase.webchannel.wrapper',
81+
compilation_level: OPTIMIZATION_LEVEL,
82+
externs: [
83+
resolve(__dirname, './externs/overrides.js'),
84+
resolve(__dirname, './externs/module.js')
85+
],
86+
language_out: 'ES5',
87+
dependency_mode: 'PRUNE',
88+
define: closureDefines
89+
// process_common_js_modules: true,
90+
// module_resolution: 'NODE'
91+
})
92+
)
93+
.pipe(sourcemaps.write('.'))
94+
.pipe(gulp.dest('dist'));
95+
}
96+
}
97+
98+
function createRollupTask(inputPath) {
99+
return async function rollupBuild() {
100+
console.log('inputPath', inputPath);
101+
const inputOptions = {
102+
input: inputPath,
103+
plugins: [rollupSourcemaps(), commonjs()]
104+
};
105+
106+
const outputOptions = {
107+
file: 'dist/index.esm.js',
108+
format: 'es',
109+
sourcemap: true
110+
};
111+
112+
const bundle = await rollup.rollup(inputOptions);
113+
return bundle.write(outputOptions);
114+
};
115+
}
116+
117+
async function deleteIntermediateFiles() {
118+
await del('dist/temp');
119+
}
120+
121+
// commonjs build
122+
const cjsBuild = createBuildTask(
123+
'index.js',
124+
CJS_WRAPPER_PREFIX,
125+
CJS_WRAPPER_SUFFIX
126+
);
127+
gulp.task('cjs', cjsBuild);
128+
129+
// esm build
130+
const intermediateEsmFile = 'temp/esm.js';
131+
const intermediateEsmPath = resolve(__dirname, 'dist/', intermediateEsmFile);
132+
const esmBuild = createBuildTask(
133+
intermediateEsmFile, '', ''
134+
);
135+
const rollupTask = createRollupTask(intermediateEsmPath);
136+
gulp.task(
137+
'esm',
138+
gulp.series(esmBuild, rollupTask, deleteIntermediateFiles)
139+
);
140+
141+
// Deletes intermediate files.
142+
gulp.task('clean', done => del([resolve(__dirname, intermediateEsmFile)], done));
143+
144+
gulp.task('default', gulp.parallel('cjs', 'esm'));

packages/webchannel-wrapper/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
},
1616
"license": "Apache-2.0",
1717
"devDependencies": {
18-
"closure-builder": "2.3.8",
18+
"google-closure-compiler": "20200112.0.0",
1919
"google-closure-library": "20200224.0.0",
20+
"gulp": "4.0.2",
21+
"gulp-sourcemaps": "2.6.5",
22+
"closure-builder": "2.3.8",
2023
"rollup": "2.0.6",
2124
"rollup-plugin-commonjs": "10.1.0",
2225
"rollup-plugin-sourcemaps": "0.5.0"

packages/webchannel-wrapper/tools/build.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ closureBuilder.build({
4242
name: 'firebase.webchannel.wrapper',
4343
srcs: glob([resolve(__dirname, '../src/**/*.js')]),
4444
externs: [resolve(__dirname, '../externs/overrides.js')],
45-
out: 'dist/index.js',
46-
out_source_map: 'dist/index.js.map',
45+
out: 'dist/indexOLD.js',
46+
out_source_map: 'dist/indexOLD.js.map',
4747
options: {
4848
closure: {
4949
output_wrapper:
@@ -65,7 +65,7 @@ closureBuilder.build(
6565
srcs: glob([resolve(__dirname, '../src/**/*.js')]),
6666
externs: [resolve(__dirname, '../externs/overrides.js')],
6767
out: filePath,
68-
out_source_map: `${filePath}.map`,
68+
out_source_map: `${filePath}.OLD.map`,
6969
options: {
7070
closure: {
7171
output_wrapper: '%output%\n//# sourceMappingURL=index.js.map',
@@ -82,7 +82,7 @@ closureBuilder.build(
8282
};
8383

8484
const outputOptions = {
85-
file: 'dist/index.esm.js',
85+
file: 'dist/indexOLD.esm.js',
8686
format: 'es',
8787
sourcemap: true
8888
};

0 commit comments

Comments
 (0)