Comments (22)
Generally AMD loaders can trivially transform commonJS & global export files into AMD files so that module authors do not need to add 20 lines of boilerplate to their file.
A problem trivially solved by tooling is best left to tooling.
from tern.
@Raynos I don't think it's as easy as you make it out to be. It's hard (impossible? without best guess) for these loaders to know that the file is actually in need of transformation.
from tern.
Agreed, that's why a user will configure, with meta data, that a dependency X it is loading, needs to be transformed from commonJS to AMD
from tern.
Raynos, I am really open to other ways of addressing the issues I have ran into... Could you please elaborate on what you propose I do?
from tern.
@MiguelCastillo RequireJs has a shim config option. That might help in your situation.
shim: Configure the dependencies and exports for older, traditional "browser globals" scripts that do not use define() to declare the dependencies and set a module value.
from tern.
Hi Paul. Firstly thank you for pointing out shims. I make use of them along with the changes I have made to term and acorn.
But I'm guessing that there isn't a clear understanding of the primary problem. Shims is a natural approach to define these dependencies, but that's not really the problem I'm addressing. The actual issue is circular dependencies. I encourage any suggestions, but I encourage even more trying to get tern working requirejs and then we come up with a better solution. If you take a look at my project brackets-tern, you will see exactly how I'm configuring requirejs to load tern. That could also be a spot for feedback :)
Regards,
Miguel
from tern.
My first reaction is the same as Raynos' -- that's a lot of boilerplate.
How are circular dependencies a problem? Tern/Acorn don't have any, but that's probably besides the point. The transformation done by the AMD loader shouldn't have any trouble with circular deps.
from tern.
Can't resist trolling about why RequireJS is bad: http://lisperator.net/blog/thoughts-on-commonjs-requirejs/ (and though I mention the boilerplate last, I actually think it's the biggest issue.)
from tern.
Well, I can't defend why boilerplate code is good or bad. I just like consistency. Can't explain why some people would prefer to not use requirejs because they introduce more issues than they solve. The article explains how asynchronous is evil... That's when I stop reading.
Circular dependencies are an issue and they do exist in tern. If you look at infer.js you will see a dependency for env.js. Then env.js also calls for infer.js and that's a circular dependency. The same happens with jsdoc.
The boilerplate code is addressing an issue with exports behavior being different in nodes require and requirejs. And mixing in support for non modular loading of tern and acorn, the issue gets worse. This boilerplate code is rather common practice to address these problems. Not sure whats so bad about boilerplate code that's been very well tested. I'm happy without boilerplate code if we have a better solution...
Good or bad, a dependency system is being used tern and acorn. Good or bad, boilerplate isn't bad practice. The issue still remains.
from tern.
@MiguelCastillo you're using the UMD pattern to define, and yet you have comments saying it's code from Knockoutjs. Why? Check out: https://github.com/umdjs/umd
My preferred implementation of AMD is something like what Lo-Dash uses:
https://github.com/bestiejs/lodash/blob/master/lodash.js#L5348
@mishoo That article is absolutely garbage. It's pretty much a troll on trolling AMD.
Edit: @mishoo I'm being a bit harsh on your post, I'll work up a rebuttal post.
from tern.
@tbranyen Yeah, no real reason besides the fact that I had knockoutjs open and that's where I copied/pasted the code from. I like loaddash as well, but I am just more used to UMD.
You basically said what I thought about the article; I just tried to sugar coat it. If anyone reads the article, you most definitely need to read what James Burke had to say. Furthermore, I am not even sure that article has any relevance here...
from tern.
@MiguelCastillo browserify's commonJS compiler can handle circular dependencies trivially without forcing UMD boilerplate on module authors.
But sure in the meanwhile until requirejs is patched to handle circular deps either your or @marijnh can maintain an AMD compatible codebase for tern
from tern.
@Raynos thank you for suggesting browserify. I have not tried that so I will for sure try it out later today. I tried requirejs transformation tool without success. What requirejs transformation tool does is that it wraps the definition call with something that's commonjs friendly. One thing that tern supports is loading via script tags. If you take away all the layering of wrapping I did to keep support for script tag loading, then the code can be reduced to a single define call without all the boilerplate code. E.g. You would only need the following
define(function(require, exports, modules){
});
So, the circular dependencies is one issue. The other issue is to keep what tern supports plus requirejs. So a short summary:
- Circular dependencies resolution. [new]
- Script tags loading [already in tern]
- CommonJS loading [already in tern]
- RequireJS loading [new]
I am happy to maintain an AMD friendly version of tern and acorn. Not sure if requirejs will add support for circular dependencies as they have already suggested ways of addressing this restriction in AMD.
from tern.
If circular dependencies can be trivially refactored away that's definitely a bonus
from tern.
Note that besides the boilerplate problem, the commit introducing requirejs support reverts some changes from recent tern commits (depth > 6 instead depth > 3 at least)
from tern.
See commits marijnh/tern:76be1f8eee184c104d4d328ca93c4002e42b6d72 and 711faaa . I have not tested with an AMD loader yet, so I might have made a mistake in the lines that handle that environment, but theoretically it should be okay now -- node and script tags still work.
I've simply killed the non-essential parts of the screenful of boilerplate, and also used the prelude to include dependencies, which actually results in a header that's still ugly, but small and useful enough to not be too offensive.
from tern.
Marijn, thank you for your changes... Great first step.
But, circular dependency is still a problem.
Either way, really... Thanks for adding this! It is a great start.
from tern.
Why would you change boilerplate code I added following AMD best practices for boilerplate code that "I have not tested with an AMD loader yet"?
I believe I described my reasons in this very thread.
Doesn't requireJS handle circular deps at all? That's odd. The circular deps are not going away.
from tern.
Try with cbcf6f5
from tern.
Yeap, that did the trick. Thank you! You could easily take the code below to create unittests for requirejs... I would volunteer to add one if you want. :)
var ternRequire = window.requirejs.config({
"baseUrl": require.toUrl("./tern"),
"map":{
"*": {
"acorn/acorn": "node_modules/acorn/acorn",
"acorn/acorn_loose": "node_modules/acorn/acorn_loose",
"acorn/util/walk": "node_modules/acorn/util/walk"
}
},
waitSeconds: 5
});
// Setup the dependencies for acorn...
ternRequire(["tern"], function(tern) {
console.log(tern);
});
from tern.
I'm not currently running any browser-based tests as part of the automatic test suite, but I did create a page similar to that (simpler, actually, requirejs.config({baseUrl: "..", paths: {acorn: "node_modules/acorn"}});
sufficed) to verify that my changes helped.
from tern.
Yeah, that's perfect! I am sure that the brackets team will appreciate this change
from tern.
Related Issues (20)
- Website still features "looking for maintainers" spiel HOT 1
- [Bug] The autocompletion for prototype HOT 3
- [BUG] defining the type for the argument of a function HOT 4
- how can i make any use of the !url tag?
- Tern plugin not avaliable in Jenkins
- require.js + defs
- es6 class arrow function method TypeError
- Function information tooltip
- No autocomplete on my objects HOT 2
- Failed to launch development process with webpack after installing tern@latest npm package HOT 2
- Bug fixed. Wrong filename for jump to definition
- acorn-lose error with tern 0.23.3 or up HOT 2
- Simple text search for tern HOT 4
- Is there any way to analyzed code in runtime?
- mix type definitions
- Using `es_modules` and `node` plugin together breaks jump to definition in some cases
- Jump to definition doesn't work from `export` es6 syntax
- Is Tern.js library in active development/support? HOT 9
- Tern not identifying js property references in the given case
- Avoid duplicate name definition
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tern.