What C library has the functionality to do zsh's recursive globs? - javascript

I wrote a nodejs binding to glob.h (npm install glob to use it).
I'd really like to support zsh's fancy lib/**/*.js type of stuff, but I can't seem to figure out which library has that functionality.
I sure don't want to try to implement it myself, and I'm not looking for any clever solution to the programming puzzle. I just want something like this:
#include <fancy_glob.h>
int do_fancy_glob (etc) { ... }
Any pointers? I'm pretty sure Ruby has a binding to this, doesn't it?
EDIT:
I did some research, and found out interesting things.
Guido Van Rossum (of Python fame) wrote an implementation that is found now on BSD and some some other unixes. It did not include the so-called "extended" glob patterns (**, etc). When you do #include <glob.h> in your program, it is most likely that this is what you will get. man 3 glob describes its behavior.
However, Bash, Zsh, and Ksh all now have extended glob implementations, all written from scratch, as far as I can tell. NetBSD has a recognizable descendent of GVR's implementation, with extended globs added in. Ruby has extended globs implemented in dir.c as part of its standard library (definitely written in C, not ruby). Perl seems to have bindings to or implementations of all the glob libraries in existence, which is to be expected, I suppose.
Of all the ones I found, NetBSD seems the closest to what I coded against with the typical non-extended libc glob(3), and its license is most amenable to my project.
Another approach would be to rewrite it from scratch. I'd be fine with doing that, but I can't seem to find any clear specification or suite of tests. Got any suggestions?
EDIT 2: I've rewritten it in JS. https://github.com/isaacs/node-glob

I'm pretty sure Ruby does this itself, and it's probably Ruby code doing it. Besides parsing the string and walking the filesystem, there aren't many hurdles to implement this. I'm not sure, but I don't think zsh uses a library for this either, it's just in the zsh code.

Related

Using Typescript with transpiled, unsupported/custom language files

The Problem
I have JavaScript-like files with extension .gml
I can convert the source to valid JavaScript via magic-string, and can go back the other way using trace-mapping.
I want to leverage Typescript on my .gml files to get strong Intellisense, e.g. by:
Creating a Typescript "program" that acts on the .gml->.js transpiled files and reports issues back; and
Creating a VSCode extension that proxies functionality to the Typescript language server and reverse-source-maps the results back to the editor.
It feels like there should be a relatively straight forward and generalizable approach to this, but my experiments have not worked out. Reference projects are either for much-more-complex scenarios or much simpler ones, and documentation on the matter is very light.
Prior Art
VueJS and Svelte use custom filetypes (.vue and .svelte), which they pre-process into valid Typescript, HTML, and CSS prior to proxying through to those respective language servers.
Their use cases are far more complicated than mine, and their code bases to accomplish this are extensive. I'm hoping to find a much more streamlined approach.
Possible approaches
I've had a little luck following the Svelte approach of creating a Typescript service and hooking up VSCode operations onto it, but this is extremely tedious.
I suspect that there's some possibility of using a Typescript plugin, but as far as I can tell that approach doesn't support using non-js/ts extensions nor source maps.
In any case I know I'll have to do significant work with the to-and-from-sourcemap conversions, but ideally that's the only difficult work I'd need to do.
Questions
Have you seen any examples in the wild of people solving a similar problem, or solved similar problems yourself?
Are there any deep-dive write-ups about this (I've found a few shallow ones)?
Is the plugin approach viable?
What are the possible ways to get non-js/ts extensions recognized by Typescript?

Replicating exact .gitignore style parsing in nodejs

I'm trying to determine which matcher to use for a few different use cases we have. Most importantly we want to replicate the behaviour that the gitignore parser has.
We were considering using globby fast-glob or node-glob. But they all seem to have extended functionality that .gitignore default parsing doesn't provide.
I.e. globby uses fast-glob and fast-glob uses micromatch, which exposes custom functionality. And node-glob also seems extend the default syntax. Hence I've started investigating a little lower down the chain.
I'm a bit confused why there are so many packages that all seem to be doing the same/very similar things.
Minimatch
Multimatch
Anymatch
Picomatch
Nanomatch
Micromatch
Observations / Questions:
All of them seem to do file path wildcard matching one way or another (expect anymatch possibly being more generic)
Minimatch is apparently slower than Micromatch, but has the same/similar functionality?
Multimatch seems to be a simple wrapper around minimatch allowing for multiple patterns. Not sure if this is optimised in any way.
Anymatch seems to be very generic. It doesn't seem to know about file path matching?
Picomatch has "full support for standard and extended Bash glob features". I would assume this matches the gitignore processing closely?
Nanomatch seems to extend functionality of Picomatch. Is this more functionality than what the gitignore processor provides?
Micromatch seems to extend functionality of Nanomatch and appears to be a replacement for Minimatch? It claims to be a "drop-in" replacement, however that doesn't seem to be the case looking at the functionality they expose?
Anymatch, Picomatch, Nanomatch and Micromatch are all published under the github organization Micromatch (naming confusion anyone?)
There doesn't seem to be the equivalent of Multimatch for the "Micromatch organization" suite? Or did I just not find it?
The first question to answer is what standard git actually uses to process it's gitignore. And then figure out which package would match that most closely.
This library comparison has been on picomatch for as long as I can remember. It answers all of your questions, and more (full disclosure: I'm the author of picomatch).
I'm a bit confused why there are so many packages that all seem to be doing the same/very similar things.
Understandable. Your confusion should be cleared up after reading more about the libraries on their extensive readmes. Each library addresses your questions in great detail.

Textmate: jsdoc comment?

I'm pretty new to TextMate and I just can't figure out how to make JSDoc like comment when editing .js file. I'm using the PHP bundle and there it is pretty easy - I just type doc and then tab. I've already added custom snippet but the problem is that it does not handle new lines properly (it doesn't insert trailing *).
You'll need to install a JSDoc bundle, but it doesn't look like there's much available. A quick google search did bring up something though: https://github.com/tysontate/javascript-jsdoc-tmbundle
No idea if it's any good, and it actually says that the commands don't yet work, but it appears to have seen at least some activity lately (unlike the others I found). It looks like there just aren't that many people who are using JS Doc (or, at least not that many TextMate users who are using it).
Usually, googling for "something bundle textmate" will yield the right results, but apparently JSDoc just isn't that commonly used.
However, maybe someone has added some JSDoc functionality to the existing JavaScript bundle (much like you've started doing). Didn't try looking for that, but you might get lucky.
But hey, it's a good excuse to get your hands dirty (and learn a lot about TextMate in the process) by messing around with whatever the available bundles have to offer, maybe even fixing a few bugs, and giving something back to the community (you don't have to of course, it's just a suggestion).
Not much of an answer, but hopefully you'll find our way from here
An updated bundle with tools for editing JSDoc comments in TextMate 2 is available at https://github.com/rootworkit/JsDoc-Toolkit.tmbundle

Efficient usage of WebStorm IDE

I've recently fallen in love in WebStorm as an IDE for JavaScript development. The problem is, I come from a world of vim and lightweight editors, so I probably can't fully appreciate all the power that comes with IDE. Yes, I've seen the presentations and read the docs, but there's a lot of features and I'm not sure which of them are truly useful.
So, here goes my question: how do you use WebStorm and what do you find most useful? Any power-usage tips? Configuration hacks? Plugins worth mentioning?
I'm not looking for a list of features, I'm looking for a real-world usage examples and impressions.
PS. I work mostly with pure JS + Canvas element and some NodeJS.
Some random thoughts, maybe more later....
In the help, definitely read the Basic Concepts and skim the WebStorm Usage Guidelines for actions that you care about.
Learn to use Ctrl-Shift-A. It allows you to 1uickly find actions you can do by typing part of them. With that you can find anything once you know it exists.
WebStorm's (like IntelliJ) best magic is its code completion and refactoring features, which come from its code parsing and awareness. It figures a lot of stuff out, but you can help it out by making you have good source files. Put the commented versions of the libraries you use in your project so it can use those comments to display in the doc popups (just having them in the directory is all you need).
Be sure to leave the tips on.
Their forums are useful, but if you have a problem or feature request put it right into youtrack.com. They are much more responsive there. You can also vote for the stuff you want added.
And if you haven't seen it yet, there is a VIM plugin which will give you VIM editor keys, called IdeaVim.
Features I find most useful:
Code formatting. WebStorm's formatter is the best I've seen (of course, it still has some subtle bugs).
Built-in HTTP server: http://blog.jetbrains.com/webstorm/2013/03/built-in-server-in-webstorm-6/, How to open/debug current file using built-in Web server in WebStorm?
JsTestDriver integration.
Plugins. You can always find something useful.

jQuery compatible JavaScript documentation generator

I need to choose a documentation generator (similar to jdoc in java or rdoc in ruby) for my javascript project that (built with jquery, underscore and backbone)
Candidates:
jsdoc toolkit
pdoc
natural docs
docco
YUI doc
doctool http://jquery.bassistance.de/docTool/docTool.html
other ?
Requirements
should work with jquery, underscore and backbone. that means object-literal methods etc
I really like pdoc but its too centered around prototype, poorly documented, and I don't want to make extra files (sections?) to make it work (not sure about this)
docco is nice but I want structured output (as in menu + class/func structure like jdoc)
must be command line/makefile compatible (not web pastie)
Tips, tricks, tutorials, success stories, advice greatly welcomed.
Why Doesn't jQuery use JSDoc?
I would rate jsduck from Sencha on top. I have used it on many projects. Simple to use
https://github.com/senchalabs/jsduck
A single command will generate docs like this http://docs.sencha.com/touch/2-0/
You could also look at Dox by TJ Holowaychuk; it's a fork of Docco, but adds some jsDoc syntax support. I personally find that jQuery code often lends itself to looser style of inline documentation like Docco, but I'm currently in the same situation of trying to decide what doc system to use.
I am going through the same exercise at the moment, and from what I've seen YUI Doc is the best. I love the fact that you can run it in "server" mode and view the documentation as you write it. Much better than having to execute a build each time you change the documentation. Also, the documentation that is generated is very easy to read and very well organized.
This is new so it may not fit your output requirements, but you might find njsdoc interesting. Unlike most JS documenters it tries to build documentation by executing the code and investigating the stack rather than just parsing the files for annotations.
https://bitbucket.org/nexj/njsdoc
There is DocumentJS*
*I haven't used it and I am not sure how well it will integrate with Backbone.

Categories