yui/yui3 — pull request #367 by solmsted (2012-12-16 23:52:19+00:00)
Title: Better script loading in Node.js.

This changes how `Y.Get.js` loads and executes a script in Node.js. It hooks a little deeper into Node's module system, trying to normalize the environment between scripts loaded by `Y.Get.js` and `require`.

I haven't tested this exhaustively in different environments but I wanted to try to get some feedback before pursuing it further.

This fixes the values and functionality of `__dirname`, `__filename`, `require`, and `module`.

From within a script loaded by `Y.Get.js`, there are still a couple of rough edges.

* When attempting to Y.Get another script using a relative path, that path may get resolved from an unexpected location; in this case it is non-trivial to exactly reproduce the functionality of `require` but `require` should still work as expected. Instead of passing a relative path to `Y.Get.js` something like `require('path').resolve(__dirname, './relative/path/to/script.js')` should be passed instead.

* When scripts are loaded from a remote location instead of from the local filesystem, `__dirname` and `__filename` will be URLs. Node's regular file path operations will produce nonsense results if these are used.

Fixes #2533010
Fixes #2533011