Giter VIP home page Giter VIP logo

Comments (7)

glathoud avatar glathoud commented on May 29, 2024

Neat. Thanks a lot. I'll add a link to your npm page.

If the generated js files included shims like this at the top (...) Then packaging for Node.js could be done automatically.

I lack experience with Node.js packaging so I need to clarify. Ideally
the changes I'll do should bring optional Node.js support. In the
non-Node.js case (e.g. V8 alone, or browser), this would forbid
reading or writing the global variable named global.

So on the top of my head:

/*global global metaparse jsm2js cp2fmtree codeparse need$ load console*/

var global;

// With Node.js
if (typeof exports !== 'undefined'   &&  typeof require === 'function') {
    global = global || exports;
    codeparse = require('./codeparse').codeparse;
    cp2fmtree = require('./cp2fmtree').cp2fmtree;
    metaparse = require('./metaparse').metaparse;
}

// Without Node.js
// Support both use cases: browser development (example: jsm_dev) and
// command-line transformation (example: jsm_dev -> jsm_out).
if (typeof codeparse === 'undefined')
    (typeof need$ !== 'undefined'  ?  need$  :  load)( "codeparse.js" );

if (typeof cp2fmtree === 'undefined')
    (typeof need$ !== 'undefined'  ?  need$  :  load)( "cp2fmtree.js" );

if (typeof metaparse === 'undefined')
    (typeof need$ !== 'undefined'  ?  need$  :  load)( "metaret.js" );


(function (global) {

    global.jsm2js = jsm2js;

    function jsm2js( /*string*/jsm_code ) { ... unchanged ... }

})(global  ||  this);  // used to be just: `this`

Lest you comment, I'll add this support soon.

(Note to myself: this also means dropping the "With Node.js" header when building metaret_standalone.js)

from js.metaret.

i-e-b avatar i-e-b commented on May 29, 2024

Thanks for the reply; Those extended headers look good.

It might work like this too, if it's preferable:

if (typeof require === 'function') {
    codeparse = require('./codeparse').codeparse;
 . . . 
}
 . . . 

(function (global) {
    . . .
})(global  || exports || this);  // <-- this order should work for all so far

from js.metaret.

glathoud avatar glathoud commented on May 29, 2024

Iain, feel free to try the automatic packaging. (Warning: I had a slightly uneasy feeling about the integration of acorn...util.walk)

On my side (V8 alone, browser) all tests pass. If you encounter any issue with npm let me know and I'll adjust the code.

from js.metaret.

i-e-b avatar i-e-b commented on May 29, 2024

Your feelings serve you well. Needs an adjustment to codeparse.js:

// With Node.js
var global, exports;
if (typeof require === 'function')
{
    acorn = require('./acorn.25.03.2014/acorn');
    acorn.walk = require('./acorn.25.03.2014/util/walk');
}

apart from that, all generated and tested ok.

from js.metaret.

i-e-b avatar i-e-b commented on May 29, 2024

This seems all good from my end. Happy to close the issue if you are.

Many thanks.

from js.metaret.

glathoud avatar glathoud commented on May 29, 2024

I did one last commit, a cleanup for the integrated build system, it should however not affect the npm side of things: 67c3f25

If everything is still fine, yes, you are welcome to close the issue. Thank you as well for the initiative !

from js.metaret.

i-e-b avatar i-e-b commented on May 29, 2024

Everything seems fine with that, thanks :-)

from js.metaret.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.