larry babby and threejs for glsl

This commit is contained in:
Sam
2024-06-24 21:24:00 +12:00
parent 87d5dc634d
commit 907ebae4c0
6474 changed files with 1279596 additions and 8 deletions

View File

@@ -0,0 +1,2 @@
fixtures
test.js

View File

@@ -0,0 +1,21 @@
## The MIT License (MIT) ##
Copyright (c) 2014 Hugh Kennedy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,38 @@
# glsl-resolve [![Flattr this!](https://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=hughskennedy&url=http://github.com/hughsk/glsl-resolve&title=glsl-resolve&description=hughsk/glsl-resolve%20on%20GitHub&language=en_GB&tags=flattr,github,javascript&category=software)[![experimental](http://hughsk.github.io/stability-badges/dist/experimental.svg)](http://github.com/hughsk/stability-badges) #
A wrapper for the [resolve](https://github.com/substack/node-resolve) module
that targets GLSL shaders instead of JavaScript.
## Usage ##
[![glsl-resolve](https://nodei.co/npm/glsl-resolve.png?mini=true)](https://nodei.co/npm/glsl-resolve)
The API is equivalent to *resolve* for both `resolve.async` and `resolve.sync`,
with the following exceptions:
* Node's core modules are excluded.
* The "main" file for a module is looked for first in a package.json's `glslify`
property, then if `main` isn't a JavaScript file it'll look there too.
Otherwise, it will default to trying `index.glsl`.
* Listed in order of priority, the following extensions are resolved instead of
`.js` and `.json`:
* `.glsl`
* `.vert`
* `.frag`
* `.geom`
* `.vs`
* `.fs`
* `.gs`
* `.vsh`
* `.fsh`
* `.gsh`
* `.vshader`
* `.fshader`
* `.gshader`
## License ##
MIT. See [LICENSE.md](http://github.com/hughsk/glsl-resolve/blob/master/LICENSE.md) for details.

View File

@@ -0,0 +1,55 @@
var resolver = require('resolve')
var xtend = require('xtend')
var path = require('path')
var core = {}
var exts = [
'.glsl'
, '.vert'
, '.frag'
, '.geom'
, '.vs'
, '.fs'
, '.gs'
, '.vsh'
, '.fsh'
, '.gsh'
, '.vshader'
, '.fshader'
, '.gshader'
]
module.exports = resolve
module.exports.sync = resolveSync
function resolve(target, opts, next) {
return resolver(target
, glslOpts(opts || {})
, next
)
}
function resolveSync(target, opts) {
return resolver.sync(target
, glslOpts(opts || {})
)
}
function glslOpts(opts) {
return xtend(opts, {
modules: core
, extensions: exts
, packageFilter: packageFilter
})
}
// find the "glslify", "main", or assume main == "index.glsl"
// if main is a .js file then ignore it.
function packageFilter(pkg, root) {
pkg.main = pkg.glslify || (
path.extname(pkg.main || '') !== '.js' &&
pkg.main
) || 'index.glsl'
return pkg
}

View File

@@ -0,0 +1,4 @@
language: node_js
node_js:
- 0.6
- 0.8

View File

@@ -0,0 +1,18 @@
This software is released under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,5 @@
var resolve = require('../');
resolve('tap', { basedir: __dirname }, function (err, res) {
if (err) console.error(err)
else console.log(res)
});

View File

@@ -0,0 +1,3 @@
var resolve = require('../');
var res = resolve.sync('tap', { basedir: __dirname });
console.log(res);

View File

@@ -0,0 +1,5 @@
var core = require('./lib/core');
exports = module.exports = require('./lib/async');
exports.core = core;
exports.isCore = function (x) { return core[x] };
exports.sync = require('./lib/sync');

View File

@@ -0,0 +1,127 @@
var core = require('./core');
var fs = require('fs');
var path = require('path');
var caller = require('./caller.js');
var nodeModulesPaths = require('./node-modules-paths.js');
module.exports = function resolve (x, opts, cb) {
if (typeof opts === 'function') {
cb = opts;
opts = {};
}
if (!opts) opts = {};
var isFile = opts.isFile || function (file, cb) {
fs.stat(file, function (err, stat) {
if (err && err.code === 'ENOENT') cb(null, false)
else if (err) cb(err)
else cb(null, stat.isFile() || stat.isFIFO())
});
};
var readFile = opts.readFile || fs.readFile;
var extensions = opts.extensions || [ '.js' ];
var y = opts.basedir || path.dirname(caller());
var modules = opts.moduleDirectory || 'node_modules';
opts.paths = opts.paths || [];
if (x.match(/^(?:\.\.?\/|\/|([A-Za-z]:)?\\)/)) {
loadAsFile(path.resolve(y, x), function (err, m, pkg) {
if (err) cb(err)
else if (m) cb(null, m, pkg)
else loadAsDirectory(path.resolve(y, x), function (err, d, pkg) {
if (err) cb(err)
else if (d) cb(null, d, pkg)
else cb(new Error("Cannot find module '" + x + "' from '" + y + "'"))
})
});
}
else loadNodeModules(x, y, function (err, n, pkg) {
if (err) cb(err)
else if (n) cb(null, n, pkg)
else if (core[x]) return cb(null, x);
else cb(new Error("Cannot find module '" + x + "' from '" + y + "'"))
});
function loadAsFile (x, pkg, cb) {
if (typeof pkg === 'function') {
cb = pkg;
pkg = opts.package;
}
(function load (exts) {
if (exts.length === 0) return cb(null, undefined, pkg);
var file = x + exts[0];
isFile(file, function (err, ex) {
if (err) cb(err)
else if (ex) cb(null, file, pkg)
else load(exts.slice(1))
});
})([''].concat(extensions));
}
function loadAsDirectory (x, fpkg, cb) {
if (typeof fpkg === 'function') {
cb = fpkg;
fpkg = opts.package;
}
var pkgfile = path.join(x, '/package.json');
isFile(pkgfile, function (err, ex) {
if (err) return cb(err);
if (!ex) return loadAsFile(path.join(x, '/index'), fpkg, cb);
readFile(pkgfile, function (err, body) {
if (err) return cb(err);
try {
var pkg = JSON.parse(body);
}
catch (err) {}
if (opts.packageFilter) {
pkg = opts.packageFilter(pkg, x);
}
if (pkg.main) {
if (pkg.main === '.' || pkg.main === './'){
pkg.main = 'index'
}
loadAsFile(path.resolve(x, pkg.main), pkg, function (err, m, pkg) {
if (err) return cb(err);
if (m) return cb(null, m, pkg);
if (!pkg) return loadAsFile(path.join(x, '/index'), pkg, cb);
var dir = path.resolve(x, pkg.main);
loadAsDirectory(dir, pkg, function (err, n, pkg) {
if (err) return cb(err);
if (n) return cb(null, n, pkg);
loadAsFile(path.join(x, '/index'), pkg, cb);
});
});
return;
}
loadAsFile(path.join(x, '/index'), pkg, cb);
});
});
}
function loadNodeModules (x, start, cb) {
(function process (dirs) {
if (dirs.length === 0) return cb(null, undefined);
var dir = dirs[0];
loadAsFile(path.join(dir, '/', x), undefined, function (err, m, pkg) {
if (err) return cb(err);
if (m) return cb(null, m, pkg);
loadAsDirectory(path.join(dir, '/', x), undefined, function (err, n, pkg) {
if (err) return cb(err);
if (n) return cb(null, n, pkg);
process(dirs.slice(1));
});
});
})(nodeModulesPaths(start, opts));
}
};

View File

@@ -0,0 +1,8 @@
module.exports = function () {
// see https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
var origPrepareStackTrace = Error.prepareStackTrace;
Error.prepareStackTrace = function (_, stack) { return stack };
var stack = (new Error()).stack;
Error.prepareStackTrace = origPrepareStackTrace;
return stack[2].getFileName();
};

View File

@@ -0,0 +1,4 @@
module.exports = require('./core.json').reduce(function (acc, x) {
acc[x] = true;
return acc;
}, {});

View File

@@ -0,0 +1,38 @@
[
"assert",
"buffer_ieee754",
"buffer",
"child_process",
"cluster",
"console",
"constants",
"crypto",
"_debugger",
"dgram",
"dns",
"domain",
"events",
"freelist",
"fs",
"http",
"https",
"_linklist",
"module",
"net",
"os",
"path",
"punycode",
"querystring",
"readline",
"repl",
"stream",
"string_decoder",
"sys",
"timers",
"tls",
"tty",
"url",
"util",
"vm",
"zlib"
]

View File

@@ -0,0 +1,28 @@
var path = require('path');
module.exports = function (start, opts) {
var modules = opts.moduleDirectory || 'node_modules';
var prefix = '/';
if (/^([A-Za-z]:)/.test(start)) {
prefix = '';
} else if (/^\\\\/.test(start)) {
prefix = '\\\\';
}
var splitRe = process.platform === 'win32' ? /[\/\\]/ : /\/+/;
var parts = start.split(splitRe);
var dirs = [];
for (var i = parts.length - 1; i >= 0; i--) {
if (parts[i] === modules) continue;
var dir = path.join(
path.join.apply(path, parts.slice(0, i + 1)),
modules
);
dirs.push(prefix + dir);
}
if(process.platform === 'win32'){
dirs[dirs.length-1] = dirs[dirs.length-1].replace(":", ":\\");
}
return dirs.concat(opts.paths);
}

View File

@@ -0,0 +1,80 @@
var core = require('./core');
var fs = require('fs');
var path = require('path');
var caller = require('./caller.js');
var nodeModulesPaths = require('./node-modules-paths.js');
module.exports = function (x, opts) {
if (!opts) opts = {};
var isFile = opts.isFile || function (file) {
try { var stat = fs.statSync(file) }
catch (err) { if (err && err.code === 'ENOENT') return false }
return stat.isFile() || stat.isFIFO();
};
var readFileSync = opts.readFileSync || fs.readFileSync;
var extensions = opts.extensions || [ '.js' ];
var y = opts.basedir || path.dirname(caller());
opts.paths = opts.paths || [];
if (x.match(/^(?:\.\.?\/|\/|([A-Za-z]:)?\\)/)) {
var m = loadAsFileSync(path.resolve(y, x))
|| loadAsDirectorySync(path.resolve(y, x));
if (m) return m;
} else {
var n = loadNodeModulesSync(x, y);
if (n) return n;
}
if (core[x]) return x;
throw new Error("Cannot find module '" + x + "' from '" + y + "'");
function loadAsFileSync (x) {
if (isFile(x)) {
return x;
}
for (var i = 0; i < extensions.length; i++) {
var file = x + extensions[i];
if (isFile(file)) {
return file;
}
}
}
function loadAsDirectorySync (x) {
var pkgfile = path.join(x, '/package.json');
if (isFile(pkgfile)) {
var body = readFileSync(pkgfile, 'utf8');
try {
var pkg = JSON.parse(body);
if (opts.packageFilter) {
pkg = opts.packageFilter(pkg, x);
}
if (pkg.main) {
var m = loadAsFileSync(path.resolve(x, pkg.main));
if (m) return m;
var n = loadAsDirectorySync(path.resolve(x, pkg.main));
if (n) return n;
}
}
catch (err) {}
}
return loadAsFileSync(path.join( x, '/index'));
}
function loadNodeModulesSync (x, start) {
var dirs = nodeModulesPaths(start, opts);
for (var i = 0; i < dirs.length; i++) {
var dir = dirs[i];
var m = loadAsFileSync(path.join( dir, '/', x));
if (m) return m;
var n = loadAsDirectorySync(path.join( dir, '/', x ));
if (n) return n;
}
}
};

View File

@@ -0,0 +1,28 @@
{
"name" : "resolve",
"description" : "resolve like require.resolve() on behalf of files asynchronously and synchronously",
"version" : "0.6.3",
"repository" : {
"type" : "git",
"url" : "git://github.com/substack/node-resolve.git"
},
"main" : "index.js",
"keywords" : [
"resolve",
"require",
"node",
"module"
],
"scripts" : {
"test" : "tap test/*.js"
},
"devDependencies" : {
"tap" : "~0.4.0"
},
"license" : "MIT",
"author" : {
"name" : "James Halliday",
"email" : "mail@substack.net",
"url" : "http://substack.net"
}
}

View File

@@ -0,0 +1,144 @@
# resolve
implements the [node `require.resolve()`
algorithm](http://nodejs.org/docs/v0.4.8/api/all.html#all_Together...)
such that you can `require.resolve()` on behalf of a file asynchronously and
synchronously
[![build status](https://secure.travis-ci.org/substack/node-resolve.png)](http://travis-ci.org/substack/node-resolve)
# example
asynchronously resolve:
``` js
var resolve = require('resolve');
resolve('tap', { basedir: __dirname }, function (err, res) {
if (err) console.error(err)
else console.log(res)
});
```
```
$ node example/async.js
/home/substack/projects/node-resolve/node_modules/tap/lib/main.js
```
synchronously resolve:
``` js
var resolve = require('resolve');
var res = resolve.sync('tap', { basedir: __dirname });
console.log(res);
```
```
$ node example/sync.js
/home/substack/projects/node-resolve/node_modules/tap/lib/main.js
```
# methods
``` js
var resolve = require('resolve')
```
## resolve(pkg, opts={}, cb)
Asynchronously resolve the module path string `pkg` into `cb(err, res)`.
options are:
* opts.basedir - directory to begin resolving from
* opts.package - package from which module is being loaded
* opts.extensions - array of file extensions to search in order
* opts.readFile - how to read files asynchronously
* opts.isFile - function to asynchronously test whether a file exists
* opts.packageFilter - transform the parsed package.json contents before looking
at the "main" field
* opts.paths - require.paths array to use if nothing is found on the normal
node_modules recursive walk (probably don't use this)
* opts.moduleDirectory - directory to recursively look for modules in. default:
`"node_modules"`
default `opts` values:
``` javascript
{
paths: [],
basedir: __dirname,
extensions: [ '.js' ],
readFile: fs.readFile,
isFile: function (file, cb) {
fs.stat(file, function (err, stat) {
if (err && err.code === 'ENOENT') cb(null, false)
else if (err) cb(err)
else cb(null, stat.isFile())
});
},
moduleDirectory: 'node_modules'
}
```
## resolve.sync(pkg, opts)
Synchronously resolve the module path string `pkg`, returning the result and
throwing an error when `pkg` can't be resolved.
options are:
* opts.basedir - directory to begin resolving from
* opts.extensions - array of file extensions to search in order
* opts.readFile - how to read files synchronously
* opts.isFile - function to synchronously test whether a file exists
* opts.packageFilter - transform the parsed package.json contents before looking
at the "main" field
* opts.paths - require.paths array to use if nothing is found on the normal
node_modules recursive walk (probably don't use this)
* opts.moduleDirectory - directory to recursively look for modules in. default:
`"node_modules"`
default `opts` values:
``` javascript
{
paths: [],
basedir: __dirname,
extensions: [ '.js' ],
readFileSync: fs.readFileSync,
isFile: function (file) {
try { return fs.statSync(file).isFile() }
catch (e) { return false }
},
moduleDirectory: 'node_modules'
}
````
## resolve.isCore(pkg)
Return whether a package is in core.
# install
With [npm](https://npmjs.org) do:
```
npm install resolve
```
# license
MIT

View File

@@ -0,0 +1,12 @@
var test = require('tap').test;
var resolve = require('../');
test('core modules', function (t) {
t.ok(resolve.isCore('fs'));
t.ok(resolve.isCore('net'));
t.ok(resolve.isCore('http'));
t.ok(!resolve.isCore('seq'));
t.ok(!resolve.isCore('../'));
t.end();
});

View File

@@ -0,0 +1,14 @@
var path = require('path');
var test = require('tap').test;
var resolve = require('../');
test('faulty basedir must produce error in windows', function (t) {
t.plan(1);
var resolverDir = 'C:\\a\\b\\c\\d';
resolve('tap/lib/main.js', { basedir : resolverDir }, function (err, res, pkg) {
t.equal(true, !!err);
});
});

View File

@@ -0,0 +1,18 @@
var test = require('tap').test;
var resolve = require('../');
test('filter', function (t) {
t.plan(2);
var dir = __dirname + '/resolver';
resolve('./baz', {
basedir : dir,
packageFilter : function (pkg) {
pkg.main = 'doom';
return pkg;
}
}, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/baz/doom.js');
t.equal(pkg.main, 'doom');
});
});

View File

@@ -0,0 +1,15 @@
var test = require('tap').test;
var resolve = require('../');
test('filter', function (t) {
var dir = __dirname + '/resolver';
var res = resolve.sync('./baz', {
basedir : dir,
packageFilter : function (pkg) {
pkg.main = 'doom'
return pkg;
}
});
t.equal(res, dir + '/baz/doom.js');
t.end();
});

View File

@@ -0,0 +1,142 @@
var test = require('tap').test;
var resolve = require('../');
test('mock', function (t) {
t.plan(6);
var files = {
'/foo/bar/baz.js' : 'beep'
};
function opts (basedir) {
return {
basedir : basedir,
isFile : function (file, cb) {
cb(null, files.hasOwnProperty(file));
},
readFile : function (file, cb) {
cb(null, files[file]);
}
}
}
resolve('./baz', opts('/foo/bar'), function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, '/foo/bar/baz.js');
t.equal(pkg, undefined);
});
resolve('./baz.js', opts('/foo/bar'), function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, '/foo/bar/baz.js');
t.equal(pkg, undefined);
});
resolve('baz', opts('/foo/bar'), function (err, res) {
t.equal(err.message, "Cannot find module 'baz' from '/foo/bar'");
});
resolve('../baz', opts('/foo/bar'), function (err, res) {
t.equal(err.message, "Cannot find module '../baz' from '/foo/bar'");
});
});
test('mock from package', function (t) {
t.plan(6);
var files = {
'/foo/bar/baz.js' : 'beep'
};
function opts (basedir) {
return {
basedir : basedir,
package : { main: 'bar' },
isFile : function (file, cb) {
cb(null, files.hasOwnProperty(file));
},
readFile : function (file, cb) {
cb(null, files[file]);
}
}
}
resolve('./baz', opts('/foo/bar'), function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, '/foo/bar/baz.js');
t.equal(pkg.main, 'bar');
});
resolve('./baz.js', opts('/foo/bar'), function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, '/foo/bar/baz.js');
t.equal(pkg.main, 'bar');
});
resolve('baz', opts('/foo/bar'), function (err, res) {
t.equal(err.message, "Cannot find module 'baz' from '/foo/bar'");
});
resolve('../baz', opts('/foo/bar'), function (err, res) {
t.equal(err.message, "Cannot find module '../baz' from '/foo/bar'");
});
});
test('mock package', function (t) {
t.plan(2);
var files = {
'/foo/node_modules/bar/baz.js' : 'beep',
'/foo/node_modules/bar/package.json' : JSON.stringify({
main : './baz.js'
})
};
function opts (basedir) {
return {
basedir : basedir,
isFile : function (file, cb) {
cb(null, files.hasOwnProperty(file));
},
readFile : function (file, cb) {
cb(null, files[file]);
}
}
}
resolve('bar', opts('/foo'), function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, '/foo/node_modules/bar/baz.js');
t.equal(pkg.main, './baz.js');
});
});
test('mock package from package', function (t) {
t.plan(2);
var files = {
'/foo/node_modules/bar/baz.js' : 'beep',
'/foo/node_modules/bar/package.json' : JSON.stringify({
main : './baz.js'
})
};
function opts (basedir) {
return {
basedir : basedir,
package : { main: 'bar' },
isFile : function (file, cb) {
cb(null, files.hasOwnProperty(file));
},
readFile : function (file, cb) {
cb(null, files[file]);
}
}
}
resolve('bar', opts('/foo'), function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, '/foo/node_modules/bar/baz.js');
t.equal(pkg.main, './baz.js');
});
});

View File

@@ -0,0 +1,68 @@
var test = require('tap').test;
var resolve = require('../');
test('mock', function (t) {
t.plan(4);
var files = {
'/foo/bar/baz.js' : 'beep'
};
function opts (basedir) {
return {
basedir : basedir,
isFile : function (file) {
return files.hasOwnProperty(file)
},
readFileSync : function (file) {
return files[file]
}
}
}
t.equal(
resolve.sync('./baz', opts('/foo/bar')),
'/foo/bar/baz.js'
);
t.equal(
resolve.sync('./baz.js', opts('/foo/bar')),
'/foo/bar/baz.js'
);
t.throws(function () {
resolve.sync('baz', opts('/foo/bar'));
});
t.throws(function () {
resolve.sync('../baz', opts('/foo/bar'));
});
});
test('mock package', function (t) {
t.plan(1);
var files = {
'/foo/node_modules/bar/baz.js' : 'beep',
'/foo/node_modules/bar/package.json' : JSON.stringify({
main : './baz.js'
})
};
function opts (basedir) {
return {
basedir : basedir,
isFile : function (file) {
return files.hasOwnProperty(file)
},
readFileSync : function (file) {
return files[file]
}
}
}
t.equal(
resolve.sync('bar', opts('/foo')),
'/foo/node_modules/bar/baz.js'
);
});

View File

@@ -0,0 +1,36 @@
var test = require('tap').test;
var resolve = require('../');
test('$NODE_PATH', function (t) {
t.plan(3);
resolve('aaa', {
paths: [
__dirname + '/node_path/x',
__dirname + '/node_path/y'
],
basedir: __dirname,
}, function (err, res) {
t.equal(res, __dirname + '/node_path/x/aaa/index.js');
});
resolve('bbb', {
paths: [
__dirname + '/node_path/x',
__dirname + '/node_path/y'
],
basedir: __dirname,
}, function (err, res) {
t.equal(res, __dirname + '/node_path/y/bbb/index.js');
});
resolve('ccc', {
paths: [
__dirname + '/node_path/x',
__dirname + '/node_path/y'
],
basedir: __dirname,
}, function (err, res) {
t.equal(res, __dirname + '/node_path/x/ccc/index.js');
});
});

View File

@@ -0,0 +1 @@
module.exports = 'A'

View File

@@ -0,0 +1 @@
module.exports = 'C'

View File

@@ -0,0 +1 @@
module.exports = 'B'

View File

@@ -0,0 +1 @@
module.exports = 'CY'

View File

@@ -0,0 +1,281 @@
var path = require('path');
var test = require('tap').test;
var resolve = require('../');
test('async foo', function (t) {
t.plan(9);
var dir = __dirname + '/resolver';
resolve('./foo', { basedir : dir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/foo.js');
t.equal(pkg, undefined);
});
resolve('./foo.js', { basedir : dir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/foo.js');
t.equal(pkg, undefined);
});
resolve('./foo', { basedir : dir, package: { main: 'resolver' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/foo.js');
t.equal(pkg.main, 'resolver');
});
resolve('./foo.js', { basedir : dir, package: { main: 'resolver' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/foo.js');
t.equal(pkg.main, 'resolver');
});
resolve('foo', { basedir : dir }, function (err) {
t.equal(err.message, "Cannot find module 'foo' from '" + path.resolve(dir) + "'");
});
});
test('bar', function (t) {
t.plan(6);
var dir = __dirname + '/resolver';
resolve('foo', { basedir : dir + '/bar' }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/bar/node_modules/foo/index.js');
t.equal(pkg, undefined);
});
resolve('foo', { basedir : dir + '/bar' }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/bar/node_modules/foo/index.js');
t.equal(pkg, undefined);
});
resolve('foo', { basedir : dir + '/bar', package: { main: 'bar' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/bar/node_modules/foo/index.js');
t.equal(pkg, undefined);
});
});
test('baz', function (t) {
t.plan(4);
var dir = __dirname + '/resolver';
resolve('./baz', { basedir : dir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/baz/quux.js');
t.equal(pkg.main, 'quux.js');
});
resolve('./baz', { basedir : dir, package: { main: 'resolver' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/baz/quux.js');
t.equal(pkg.main, 'quux.js');
});
});
test('biz', function (t) {
t.plan(24);
var dir = __dirname + '/resolver/biz/node_modules';
resolve('./grux', { basedir : dir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/grux/index.js');
t.equal(pkg, undefined);
});
resolve('./grux', { basedir : dir, package: { main: 'biz' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/grux/index.js');
t.equal(pkg.main, 'biz');
});
resolve('./garply', { basedir : dir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/garply/lib/index.js');
t.equal(pkg.main, './lib');
});
resolve('./garply', { basedir : dir, package: { main: 'biz' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/garply/lib/index.js');
t.equal(pkg.main, './lib');
});
resolve('tiv', { basedir : dir + '/grux' }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/tiv/index.js');
t.equal(pkg, undefined);
});
resolve('tiv', { basedir : dir + '/grux', package: { main: 'grux' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/tiv/index.js');
t.equal(pkg, undefined);
});
resolve('tiv', { basedir : dir + '/garply' }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/tiv/index.js');
t.equal(pkg, undefined);
});
resolve('tiv', { basedir : dir + '/garply', package: { main: './lib' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/tiv/index.js');
t.equal(pkg, undefined);
});
resolve('grux', { basedir : dir + '/tiv' }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/grux/index.js');
t.equal(pkg, undefined);
});
resolve('grux', { basedir : dir + '/tiv', package: { main: 'tiv' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/grux/index.js');
t.equal(pkg, undefined);
});
resolve('garply', { basedir : dir + '/tiv' }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/garply/lib/index.js');
t.equal(pkg.main, './lib');
});
resolve('garply', { basedir : dir + '/tiv', package: { main: 'tiv' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/garply/lib/index.js');
t.equal(pkg.main, './lib');
});
});
test('quux', function (t) {
t.plan(2);
var dir = __dirname + '/resolver/quux';
resolve('./foo', { basedir : dir, package: { main: 'quux' } }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/foo/index.js');
t.equal(pkg.main, 'quux');
});
});
test('normalize', function (t) {
t.plan(2);
var dir = __dirname + '/resolver/biz/node_modules/grux';
resolve('../grux', { basedir : dir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/index.js');
t.equal(pkg, undefined);
});
});
test('cup', function (t) {
t.plan(3);
var dir = __dirname + '/resolver';
resolve('./cup', { basedir : dir, extensions : [ '.js', '.coffee' ] },
function (err, res) {
if (err) t.fail(err);
t.equal(res, dir + '/cup.coffee');
});
resolve('./cup.coffee', { basedir : dir }, function (err, res) {
if (err) t.fail(err);
t.equal(res, dir + '/cup.coffee');
});
resolve('./cup', { basedir : dir, extensions : [ '.js' ] },
function (err, res) {
t.equal(err.message, "Cannot find module './cup' from '" + path.resolve(dir) + "'");
});
});
test('mug', function (t) {
t.plan(3);
var dir = __dirname + '/resolver';
resolve('./mug', { basedir : dir }, function (err, res) {
if (err) t.fail(err);
t.equal(res, dir + '/mug.js');
});
resolve('./mug', { basedir : dir, extensions : [ '.coffee', '.js' ] },
function (err, res) {
if (err) t.fail(err);
t.equal(res, dir + '/mug.coffee');
});
resolve('./mug', { basedir : dir, extensions : [ '.js', '.coffee' ] },
function (err, res) {
t.equal(res, dir + '/mug.js');
});
});
test('other path', function (t) {
t.plan(4);
var resolverDir = __dirname + '/resolver';
var dir = resolverDir + '/bar';
var otherDir = resolverDir + '/other_path';
resolve('root', { basedir : dir, paths: [otherDir] }, function (err, res) {
if (err) t.fail(err);
t.equal(res, resolverDir + '/other_path/root.js');
});
resolve('lib/other-lib', { basedir : dir, paths: [otherDir] },
function (err, res) {
if (err) t.fail(err);
t.equal(res, resolverDir + '/other_path/lib/other-lib.js');
});
resolve('root', { basedir : dir, }, function (err, res) {
t.equal(err.message, "Cannot find module 'root' from '" + path.resolve(dir) + "'");
});
resolve('zzz', { basedir : dir, paths: [otherDir] }, function (err, res) {
t.equal(err.message, "Cannot find module 'zzz' from '" + path.resolve(dir) + "'");
});
});
test('incorrect main', function (t) {
t.plan(1)
var resolverDir = __dirname + '/resolver';
var dir = resolverDir + '/incorrect_main';
resolve('./incorrect_main', { basedir : resolverDir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/index.js');
});
});
test('without basedir', function (t) {
t.plan(1);
var dir = __dirname + '/resolver/without_basedir';
var tester = require(dir + '/main.js');
tester(t, function (err, res, pkg){
if (err) {
t.fail(err);
} else {
t.equal(res, dir + '/node_modules/mymodule.js');
}
});
});
test('#25: node modules with the same name as node stdlib modules', function (t) {
t.plan(1);
var resolverDir = __dirname + '/resolver/punycode';
resolve('punycode', { basedir : resolverDir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, resolverDir + '/node_modules/punycode/index.js');
});
});

View File

@@ -0,0 +1 @@
module.exports = 1;

View File

@@ -0,0 +1,3 @@
{
"main" : "quux.js"
}

View File

@@ -0,0 +1 @@
module.exports = 1;

View File

@@ -0,0 +1 @@
module.exports = 'hello garply';

View File

@@ -0,0 +1,3 @@
{
"main" : "./lib"
}

View File

@@ -0,0 +1 @@
module.exports = require('tiv') * 100;

View File

@@ -0,0 +1 @@
module.exports = 3;

View File

@@ -0,0 +1 @@
module.exports = 1;

View File

@@ -0,0 +1,2 @@
// this is the actual main file 'index.js', not 'wrong.js' like the package.json would indicate
module.exports = 1;

View File

@@ -0,0 +1,3 @@
{
"main" : "wrong.js"
}

View File

@@ -0,0 +1 @@
module.exports = 1;

View File

@@ -0,0 +1,6 @@
resolve = require('../../../');
module.exports = function(t, cb) {
resolve('mymodule', null, cb);
}

View File

@@ -0,0 +1 @@
module.exports = "The tools we use have a profound (and devious!) influence on our thinking habits, and, therefore, on our thinking abilities.- E. Dijkstra"

View File

@@ -0,0 +1,180 @@
var test = require('tap').test;
var resolve = require('../');
test('foo', function (t) {
var dir = __dirname + '/resolver';
t.equal(
resolve.sync('./foo', { basedir : dir }),
dir + '/foo.js'
);
t.equal(
resolve.sync('./foo.js', { basedir : dir }),
dir + '/foo.js'
);
t.throws(function () {
resolve.sync('foo', { basedir : dir });
});
t.end();
});
test('bar', function (t) {
var dir = __dirname + '/resolver';
t.equal(
resolve.sync('foo', { basedir : dir + '/bar' }),
dir + '/bar/node_modules/foo/index.js'
);
t.end();
});
test('baz', function (t) {
var dir = __dirname + '/resolver';
t.equal(
resolve.sync('./baz', { basedir : dir }),
dir + '/baz/quux.js'
);
t.end();
});
test('biz', function (t) {
var dir = __dirname + '/resolver/biz/node_modules';
t.equal(
resolve.sync('./grux', { basedir : dir }),
dir + '/grux/index.js'
);
t.equal(
resolve.sync('tiv', { basedir : dir + '/grux' }),
dir + '/tiv/index.js'
);
t.equal(
resolve.sync('grux', { basedir : dir + '/tiv' }),
dir + '/grux/index.js'
);
t.end();
});
test('normalize', function (t) {
var dir = __dirname + '/resolver/biz/node_modules/grux';
t.equal(
resolve.sync('../grux', { basedir : dir }),
dir + '/index.js'
);
t.end();
});
test('cup', function (t) {
var dir = __dirname + '/resolver';
t.equal(
resolve.sync('./cup', {
basedir : dir,
extensions : [ '.js', '.coffee' ]
}),
dir + '/cup.coffee'
);
t.equal(
resolve.sync('./cup.coffee', {
basedir : dir
}),
dir + '/cup.coffee'
);
t.throws(function () {
resolve.sync('./cup', {
basedir : dir,
extensions : [ '.js' ]
})
});
t.end();
});
test('mug', function (t) {
var dir = __dirname + '/resolver';
t.equal(
resolve.sync('./mug', { basedir : dir }),
dir + '/mug.js'
);
t.equal(
resolve.sync('./mug', {
basedir : dir,
extensions : [ '.coffee', '.js' ]
}),
dir + '/mug.coffee'
);
t.equal(
resolve.sync('./mug', {
basedir : dir,
extensions : [ '.js', '.coffee' ]
}),
dir + '/mug.js'
);
t.end();
});
test('other path', function (t) {
var resolverDir = __dirname + '/resolver';
var dir = resolverDir + '/bar';
var otherDir = resolverDir + '/other_path';
var path = require('path');
t.equal(
resolve.sync('root', {
basedir : dir,
paths: [otherDir] }),
resolverDir + '/other_path/root.js'
);
t.equal(
resolve.sync('lib/other-lib', {
basedir : dir,
paths: [otherDir] }),
resolverDir + '/other_path/lib/other-lib.js'
);
t.throws(function () {
resolve.sync('root', { basedir : dir, });
});
t.throws(function () {
resolve.sync('zzz', {
basedir : dir,
paths: [otherDir] });
});
t.end();
});
test('incorrect main', function (t) {
var resolverDir = __dirname + '/resolver';
var dir = resolverDir + '/incorrect_main';
t.equal(
resolve.sync('./incorrect_main', { basedir : resolverDir }),
dir + '/index.js'
)
t.end()
});
test('#25: node modules with the same name as node stdlib modules', function (t) {
var resolverDir = __dirname + '/resolver/punycode';
t.equal(
resolve.sync('punycode', { basedir : resolverDir }),
resolverDir + '/node_modules/punycode/index.js'
)
t.end()
});

View File

@@ -0,0 +1,33 @@
{
"name": "glsl-resolve",
"description": "A wrapper for the \"resolve\" module that targets GLSL shaders instead of JavaScript",
"version": "0.0.1",
"main": "index.js",
"dependencies": {
"resolve": "^0.6.1",
"xtend": "^2.1.2"
},
"devDependencies": {
"tape": "^2.10.2",
"faucet": "^0.0.1"
},
"scripts": {
"test": "node test | faucet"
},
"author": "Hugh Kennedy <hughskennedy@gmail.com> (http://hughsk.io/)",
"license": "MIT",
"homepage": "http://hughsk.github.io/glsl-resolve",
"repository": {
"type": "git",
"url": "git://github.com/hughsk/glsl-resolve"
},
"bugs": {
"url": "https://github.com/hughsk/glsl-resolve/issues"
},
"keywords": [
"glsl",
"resolve",
"shader",
"modules"
]
}