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 5 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
24 changes: 10 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,16 @@ 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(filename.substring(0, filename.lastIndexOf("/")+1) + "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.

can you use path.dirname, url.resolve please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed, please review the same

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