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

run spark platform mjs before source #2004

Open
wants to merge 6 commits into
base: _webgl
Choose a base branch
from
Open
Changes from all commits
Commits
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
25 changes: 11 additions & 14 deletions examples/pxScene2d/src/initGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,17 +481,7 @@ async function getModule(specifier, referencingModule) {
{
// mjs module
var treatAsLocal = false;
if(specifier.indexOf("wpe-lightning-spark") == 0)
{
treatAsLocal = true;
specifier = path.resolve(__dirname ,"node_modules/wpe-lightning-spark/src/lightning.mjs") ;
}
else if(specifier.indexOf("wpe-lightning") == 0)
{
treatAsLocal = true;
specifier = path.resolve(__dirname ,"node_modules/" + specifier);
}
else if (specifier.indexOf(".mjs") != -1)
if (specifier.indexOf(".mjs") != -1)
{
if (isLocalApp) {
specifier = path.resolve(baseString.substring(0, baseString.lastIndexOf("/")+1), specifier);
Expand Down Expand Up @@ -682,10 +672,17 @@ async function loadMjs(source, url, context)
let framework = await getFile(_frameworkURL);
vm.runInContext(framework.data, contextifiedSandbox, {filename:framework.uri});
}

let file = await getFile(filename);
let source = file.data, rpath = file.uri;
app = await loadMjs(source, rpath, contextifiedSandbox);

// define platform
var platformsource = "";
if (filename.indexOf(".mjs") != -1) {
let platformfile = await getFile(urlmain.resolve(path.dirname(filename) + "/", "lib/lightning-spark.js"));
Copy link
Contributor

Choose a reason for hiding this comment

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

just let platformfile = await getFile(urlmain.resolve(filename, "lib/lightning-spark.js")); is enough, however your code works too

platformsource = platformfile.data;
}
app = await loadMjs(platformsource + source, rpath, contextifiedSandbox);
app.instantiate();
instantiated = true;
succeeded = true;
Expand All @@ -696,7 +693,7 @@ async function loadMjs(source, url, context)
try {
new app.namespace.default(_options);
} catch (err) {
console.log(err);
console.log(err);
}
}
endDrawing();
Expand Down