Hey folks,
I've been working on improving Node.js support for the next release of
FlexJS. Sorry for forcing you to wipe your builds of flex-falcon after I
added new externs downloads!
In FlexJS 0.6, you could use require() to load Node modules, but you'd have
untyped objects:
var http:Object = require("http");
It's just enough to make things work, but you probably wouldn't want to do
a whole project that way.
Starting today, if a class in an externs SWC has [JSModule] metadata, the
compiler will automatically require the module in the generated JS.
package {
[JSModule]
public class http {}
}
package http
{
[JSModule(name="http")]
public class Server {}
}
If you use http or http.Server in your ActionScript code, the compiler will
know to require it in the generated JavaScript.
In the process, I fixed several issues in externc. I also added a new
named-module command line argument to externc that lets you specify exactly
which packages should include [JSModule] metadata. I updated the Node.js
externs, and it works great!
Here's a little example:
package
{
public class HelloNode
{
public function HelloNode()
{
var newPath:String =
path.normalize("./sub/../test/./whatever.txt");
console.log(newPath);
}
}
}
The path class is required automatically by the compiler. It's in the
top-level package, so it doesn't need to be imported. Classes in
sub-packages are imported normally in ActionScript. The console class is
used in this example too, but because it considered a global, it doesn't
have [JSModule] metadata, so it gets treated normally.
- Josh