GithubHelp home page GithubHelp logo

fid-umd's People

Contributors

fidian avatar haroenv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fid-umd's Issues

Try/Catch blocks are terrible for debugging

If I break on all exceptions, loading modules becomes amazingly painful. Rewrite the engine to use syntax more in line with

if (condition) {
    do stuff
} else 

and repeat those blocks until we run out. Then the root block would look like

{
    r[n] = f()
}

Error: module is not defined

Cool project! However, when I try to use it via the CLI, the output is different than your README. Steps to replicate:

  1. npm install -g fid-umd
  2. echo // *** Your JavaScript is here *** > example.js
  3. fid-umd example.js

Result:

// fid-umd {"name":"Unknown"}
(function (name, root, factory) {
    function isObject(x) { return typeof x === "object"; }
    if (isObject(module) && isObject(module.exports)) {
        module.exports = factory();
    } else if (isObject(exports)) {
        exports[name] = factory();
    } else if (isObject(root.define) && root.define.amd) {
        root.define(name, [], factory);
    } else if (isObject(root.modulejs)) {
        root.modulejs.define(name, factory);
    } else if (isObject(root.YUI)) {
        root.YUI.add(name, function (Y) { Y[name] = factory(); });
    } else {
        root[name] = factory();
    }
}("Unknown", this, function () {
    // fid-umd end
    // *** Your JavaScript is here ***
    // fid-umd post
}));
// fid-umd post-end

Your README indicates it should have been:

// fid-umd {"name":"Unknown"}
(function (name, root, factory) {
    function isObject(x) { return typeof x === "object"; }
    if (isObject(root.module) && isObject(root.module.exports)) {
        root.module.exports = factory();
    } else if (isObject(root.exports)) {
        root.exports[name] = factory();
    } else if (isObject(root.define) && root.define.amd) {
        root.define(name, [], factory);
    } else if (isObject(root.modulejs)) {
        root.modulejs.define(name, factory);
    } else if (isObject(root.YUI)) {
        root.YUI.add(name, function (Y) { Y[name] = factory(); });
    } else {
        root[name] = factory();
    }
}("Unknown", this, function () {
    // fid-umd end
    // *** Your JavaScript is here ***
    // fid-umd post
}));
// fid-umd post-end

Diff: https://www.diffchecker.com/rguNfuu6/

When I try to use it in an AMD project it throws this error: ReferenceError: module is not defined

CommonJS loading isn't quite right

The "module.exports" syntax is more of a node thing and should be renamed as such.

The "exports[x]" syntax is more of CommonJS. When pulling in dependencies from elsewhere, it should use f(require("otherModule").otherModule) or similar, as we are attaching to export. Alternately, find a way to set the object as the prototypical parent of exports or something.

Allow multiple-line format for header

The single-line format is a bit long when you start listing dependencies.

// fid-umd {"depends":[{"name":"Thing","commonjs":"./thing"},{"name":"ThingGroup","commonjs":"./thing-group"}],"jslint":1,"name":"ThingCategory"}

Splitting to multiple lines would be nice. How about a YAML syntax? Make sure to allow leading * characters on new lines. Should they be required?

/* fid-umd YAML
 * depends:
 *     -
 *         name: Thing
 *         commonjs: ./thing
 *     -
 *         name: ThingGroup
 *         commonjs: ./thing-group.js
 * jslint: true
 * name: ThingCategory
 */

Specifying the format on the line helps allow alternate formats in the future.

String minification

It would make the minified code smaller if the strings and identifiers were put into a lookup table/object. Many are repeated.

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.