WebReflection / jsgtk

A simplified approach to GJS for Node.JS and JavaScript developers.
https://webreflection.github.io/jsgtk/
Other
85 stars 9 forks source link

Improve npm module loading #3

Closed benwaffle closed 8 years ago

benwaffle commented 8 years ago

This makes react load successfully.

Although, loading something as large as react can take multiple seconds:

var start = new Date().getTime();
var r = require('react');
var end = new Date().getTime();
console.log(`loaded react, took ${end-start}ms`);
WebReflection commented 8 years ago

will test later on if there are side effects but it looks OK to me.

Have you tried dropping babel standalone ?

jsgtk --no-transform your-file.js

benwaffle commented 8 years ago

oh, thats much faster

WebReflection commented 8 years ago

so here's the catch: GJS is unfortunately based on moz24 engine which is a pre ES6 era. I've introduced babel standalone at runtime to be able to use modern code like it's possible already in node.

However, if you use already transpiled code that's a huge overhead, but if you don't use the runtime transformer you also miss all modern fun parts of the language, and you cannot extend with ease native GTK classes.

The fact it loads slow is a real bummer, the fact if it's faster you cannot use ES6 is even worst. I've opted for the least bummer by default, and unless GJS updates to a modern engine I have no idea how to solve this.

benwaffle commented 8 years ago

can you run js files through babel unless they are in node_modules?

WebReflection commented 8 years ago

not sure I should ... if some cowboy publishes an ES6 comaptible module the whole system would be doomed.

Since the main goal here is to simulate, as seamless as possible, what a node-js env would do, considering that node 4 and 6 already have way more ES6 than moz24 ever dreamed about, I guess, and I am afraid, there's no silver bullet here.

WebReflection commented 8 years ago

However, if you were thinking about a flag, then maybe it makes sense, as long as you are sure about the module you are using as dependency.

WebReflection commented 8 years ago

actually thinking about a --no-modules-transform to have hybrid solution to this ... it's not future proof but sounds like a reasonable approach for now ... thoughts?

benwaffle commented 8 years ago

yeah sounds like the best option at this point

WebReflection commented 8 years ago

actually, after quick better analysis, a node module can be pretty much anything. Are you talking about modules defined as dependency in the initial package.json where you launch the first jsgtk compatible script?

benwaffle commented 8 years ago

anything installed by npm, thus anything in node_modules. technically it doesn't have to be saved in package.json

WebReflection commented 8 years ago

so, absolute and relative paths would still be transpiled ... deal?

benwaffle commented 8 years ago

what makes those special?

WebReflection commented 8 years ago

because that's how you include files in node. Either you want only the main file to be transpiled at runtime, or if you want to keep ES6 compatibility and still use require('./myfile') we need to agree that only pre-installed modules should not be parsed.

Otherwise --no-transform already covers your case, right?

WebReflection commented 8 years ago

thinking about it, a module can have nested dependencies and/or include its own files via relative paths.

TL;DR I am not sure how to solve this, looks more like an overhead full of problems rather than a handy use case.

hints welcome