-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
Don't load Node-specific code when bundled via Webpack #166
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"use strict"; | ||
|
||
const isBrowser = ((typeof process === "undefined") || process.browser); | ||
const isNode = !isBrowser; | ||
|
||
module.exports.isBrowser = isBrowser; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC don't use camelCase anywhere in fengari; please use snake_case for consistency. |
||
module.exports.isNode = isNode; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,10 +75,13 @@ const { | |
to_jsstring, | ||
to_luastring | ||
} = require("./fengaricore.js"); | ||
const { | ||
isBrowser | ||
} = require("./isnode.js"); | ||
|
||
let lua_writestring; | ||
let lua_writeline; | ||
if (typeof process === "undefined") { | ||
if (isBrowser) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is actually checking for the |
||
if (typeof TextDecoder === "function") { /* Older browsers don't have TextDecoder */ | ||
let buff = ""; | ||
let decoder = new TextDecoder("utf-8"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,9 +71,13 @@ const { | |
to_uristring | ||
} = require("./fengaricore.js"); | ||
const fengari = require('./fengari.js'); | ||
const { | ||
isBrowser, | ||
isNode | ||
} = require("./isnode.js"); | ||
|
||
const global_env = (function() { | ||
if (typeof process !== "undefined") { | ||
if (isNode) { | ||
/* node */ | ||
return global; | ||
} else if (typeof window !== "undefined") { | ||
|
@@ -120,7 +124,7 @@ const AUXMARK = to_luastring("\x01"); | |
** error string in the stack. | ||
*/ | ||
let lsys_load; | ||
if (typeof process === "undefined") { | ||
if (isBrowser) { | ||
lsys_load = function(L, path, seeglb) { | ||
path = to_uristring(path); | ||
let xhr = new XMLHttpRequest(); | ||
|
@@ -195,7 +199,7 @@ const noenv = function(L) { | |
}; | ||
|
||
let readable; | ||
if (typeof process !== "undefined") { // Only with Node | ||
if (isNode) { // Only with Node | ||
const fs = require('fs'); | ||
|
||
readable = function(filename) { | ||
|
@@ -270,7 +274,7 @@ const ll_loadlib = function(L) { | |
}; | ||
|
||
const env = (function() { | ||
if (typeof process !== "undefined") { | ||
if (isNode) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might want to leave this one as actually checking |
||
/* node */ | ||
return process.env; | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love a new source file for this. I think put it into defs.js?