fidian / fid-umd Goto Github PK
View Code? Open in Web Editor NEWUMD writer for JavaScript - make your modules usable everywhere!
License: Other
UMD writer for JavaScript - make your modules usable everywhere!
License: Other
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()
}
Cool project! However, when I try to use it via the CLI, the output is different than your README. Steps to replicate:
npm install -g fid-umd
echo // *** Your JavaScript is here *** > example.js
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
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.
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.
It would make the minified code smaller if the strings and identifiers were put into a lookup table/object. Many are repeated.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.