Git Product home page Git Product logo

Comments (8)

FAGundum avatar FAGundum commented on July 17, 2024

Some of the codes for reference

define(function(require, exports, module) {

    main.consumes = ["Plugin", "commands", "tabManager", "run"];
    main.provides = ["rating"];
    return main;

    function main(options, imports, register) {

        //var opt = "/home/derek/nvm/v0.10.28/lib/node_modules";

        var Plugin = imports.Plugin;
        var commands = imports.commands;
        var tabs = imports.tabManager;
        var run = imports.run;
        var settings = imports.settings;
        var save = imports.save;
        var esprima = require("esprima");
        var estraverse = require('estraverse');
        var escope = require('escope');

from core.

FAGundum avatar FAGundum commented on July 17, 2024

The require statement will cause error because those modules are not provided in defined.

I am quite new to this, but from my understanding, the require function is used to call a bunch of defined module within cloud9. Hence it doesn't retrieve module added elsewhere. Is there a way I can call external node modules?

from core.

lennartcl avatar lennartcl commented on July 17, 2024

You can use require() for normal client-side dependencies, but for node-style modules, you need something like browserify to wrap then in a way they can be imported in the client. Note that escope appears to already have a gulp command for this at https://github.com/estools/escope/blob/548ba8b390215a29dea065fe096e20665ff98444/gulpfile.js#L82. It should be possible to do something similar with esprima. Another thing you could have a look at is our eslint plugin, which includes a browserified version of eslint (https://github.com/c9/c9.ide.language.javascript.eslint/blob/master/worker/eslint_browserified.js). eslint includes esprima and estraverse. I'm not sure you can directly use them from there, but it's worth taking a look at anyway as it shows some patterns for doing syntax analysis. The docs at https://docs.c9.io/api/#!/api/language provide some more background on this topic.

from core.

javruben avatar javruben commented on July 17, 2024

@FAGundum Did @lennartcl's answer help you? Can this issue be closed?

from core.

FAGundum avatar FAGundum commented on July 17, 2024

Hi @javruben and @lennartcl , thanks for the answer. The issue can be closed.

from core.

FAGundum avatar FAGundum commented on July 17, 2024

Hi, @lennartcl , actually I have one more issue related to browserify.

Once I have browserified, say for example, https://github.com/estools/escodegen. I use the escodegen.browser.js provided by them. It basically bundled a couple of scripts together, including esutils, estraverse, escodegen etc....

When I require this browserified script in my plugin,

var escodegen = require('./escodegen.browser');

The rendered escodegen variable is not a escodegen object, in fact, it is rendered to be a estraverse object. My guess is that the require function is not able to recognize escodgen object in escodegen.browser.js, instead it takes the last defined object in the file. (in this case, it happened to be estraverse)

This also happened to escope once I browserified it.

One screenshot of my debug window.

screenshot from 2015-03-16 00 32 56

Just wondering, how can I resolve this issue. Should I require this script with some other configurations?

from core.

nightwing avatar nightwing commented on July 17, 2024

@FAGundum by default browserify exports only one module to the global scope.
As a workaround you can create a module like

exports.esutils = require('esutils')
exports.estraverse = require('estraverse')

and browserify it instead

but that's not very nice.
I'll look if it's possible to get architect-build to work for node modules without requiring browserify step.

from core.

FAGundum avatar FAGundum commented on July 17, 2024

Great, thanks for the answer. I will look into it. I am going to close this issue.

from core.

Related Issues (20)

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.