Skip to content

Commit 7f8f417

Browse files
committed
Allow tabris module to parse in browser without packager or client mock
Change-Id: Ia7e4289216debdbcf71248adff12f44b4a9aa004
1 parent a12e3da commit 7f8f417

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

rollup.tabris.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export default {
66
input: './src/tabris/main.js',
77
output: {
88
file: 'build/tabris-bundle.js',
9-
format: 'cjs'
9+
format: 'cjs',
10+
intro: 'if (typeof global === \'undefined\') { window.global = window; }' // May be running in browser
1011
},
1112
plugins: [
1213
typescript({

src/tabris/main.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ const WHATWG = Object.freeze({
160160
ImageData,
161161
ImageBitmap,
162162
ProgressEvent,
163+
Promise,
163164
Storage,
164165
WebSocket,
165166
XMLHttpRequest,
@@ -227,13 +228,22 @@ const OTHER = Object.freeze({
227228
const tabrisMain = Object.assign(new Tabris(), WIDGETS, POPUPS, WHATWG, NATIVE_OBJECT, UTILS, OTHER);
228229

229230
/** @typedef {typeof tabrisMain} TabrisMain */
230-
module.exports = tabrisMain;
231-
// @ts-ignore
232-
global.tabris = tabrisMain;
233-
// @ts-ignore
234-
global.tabris.tabris = tabrisMain;
231+
if (typeof module !== 'undefined') { // Allow loading in browser
232+
module.exports = tabrisMain;
233+
}
235234

236-
Object.assign(global, WHATWG, {$});
235+
if (global.document) {
236+
// Running in browser
237+
global.tabris = tabrisMain;
238+
global.JSX = tabrisMain.JSX;
239+
} else {
240+
global.tabris = tabrisMain;
241+
global.tabris.tabris = tabrisMain;
242+
Object.assign(global, WHATWG, {$});
243+
addDOMDocument(global);
244+
addDOMEventTargetMethods(global);
245+
addWindowTimerMethods(global);
246+
}
237247

238248
tabrisMain.on('start', (options) => {
239249
// @ts-ignore
@@ -287,7 +297,3 @@ tabrisMain.on('start', (options) => {
287297
global.process = tabrisMain.process;
288298
}
289299
});
290-
291-
addDOMDocument(global);
292-
addDOMEventTargetMethods(global);
293-
addWindowTimerMethods(global);

0 commit comments

Comments
 (0)