buddy

node MVC discord bot
Log | Files | Refs | README

commit 0cb8a1a06177f07f2f02d73eb08118aca06a7583
parent c8391f5de6eff97564fb042de2a9501d02786845
Author: underd0g1 <hide4@comcast.net>
Date:   Tue, 29 Sep 2020 00:35:15 -0400

added youtube base

Diffstat:
Mlib/3party.js | 14+++++++++++++-
Mlib/processing.js | 3+++
Anode_modules/browser-resolve/LICENSE | 21+++++++++++++++++++++
Anode_modules/browser-resolve/README.md | 146+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/browser-resolve/empty.js | 0
Anode_modules/browser-resolve/index.js | 345+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/browser-resolve/package.json | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/resolve/.travis.yml | 4++++
Anode_modules/resolve/LICENSE | 18++++++++++++++++++
Anode_modules/resolve/example/async.js | 5+++++
Anode_modules/resolve/example/sync.js | 3+++
Anode_modules/resolve/index.js | 5+++++
Anode_modules/resolve/lib/async.js | 192+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/resolve/lib/caller.js | 8++++++++
Anode_modules/resolve/lib/core.js | 4++++
Anode_modules/resolve/lib/core.json | 38++++++++++++++++++++++++++++++++++++++
Anode_modules/resolve/lib/node-modules-paths.js | 38++++++++++++++++++++++++++++++++++++++
Anode_modules/resolve/lib/sync.js | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/resolve/package.json | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/resolve/readme.markdown | 148+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/resolve/test/core.js | 12++++++++++++
Anode_modules/resolve/test/dotdot.js | 29+++++++++++++++++++++++++++++
Anode_modules/resolve/test/dotdot/abc/index.js | 2++
Anode_modules/resolve/test/dotdot/index.js | 1+
Anode_modules/resolve/test/faulty_basedir.js | 17+++++++++++++++++
Anode_modules/resolve/test/filter.js | 18++++++++++++++++++
Anode_modules/resolve/test/filter_sync.js | 15+++++++++++++++
Anode_modules/resolve/test/mock.js | 142+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/resolve/test/mock_sync.js | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/resolve/test/module_dir.js | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/resolve/test/module_dir/xmodules/aaa/index.js | 1+
Anode_modules/resolve/test/module_dir/ymodules/aaa/index.js | 1+
Anode_modules/resolve/test/module_dir/zmodules/bbb/main.js | 1+
Anode_modules/resolve/test/module_dir/zmodules/bbb/package.json | 3+++
Anode_modules/resolve/test/node_path.js | 48++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/resolve/test/node_path/x/aaa/index.js | 1+
Anode_modules/resolve/test/node_path/x/ccc/index.js | 1+
Anode_modules/resolve/test/node_path/y/bbb/index.js | 1+
Anode_modules/resolve/test/node_path/y/ccc/index.js | 1+
Anode_modules/resolve/test/nonstring.js | 9+++++++++
Anode_modules/resolve/test/pathfilter.js | 35+++++++++++++++++++++++++++++++++++
Anode_modules/resolve/test/pathfilter/deep_ref/main.js | 0
Anode_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/alt.js | 0
Anode_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/deeper/ref.js | 0
Anode_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/package.json | 4++++
Anode_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/ref.js | 0
Anode_modules/resolve/test/precedence.js | 23+++++++++++++++++++++++
Anode_modules/resolve/test/precedence/aaa.js | 1+
Anode_modules/resolve/test/precedence/aaa/index.js | 1+
Anode_modules/resolve/test/precedence/aaa/main.js | 1+
Anode_modules/resolve/test/precedence/bbb.js | 1+
Anode_modules/resolve/test/precedence/bbb/main.js | 1+
Anode_modules/resolve/test/resolver.js | 281+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/resolve/test/resolver/bar/node_modules/foo/index.js | 1+
Anode_modules/resolve/test/resolver/baz/doom.js | 0
Anode_modules/resolve/test/resolver/baz/package.json | 3+++
Anode_modules/resolve/test/resolver/baz/quux.js | 1+
Anode_modules/resolve/test/resolver/biz/node_modules/garply/lib/index.js | 1+
Anode_modules/resolve/test/resolver/biz/node_modules/garply/package.json | 3+++
Anode_modules/resolve/test/resolver/biz/node_modules/grux/index.js | 1+
Anode_modules/resolve/test/resolver/biz/node_modules/tiv/index.js | 1+
Anode_modules/resolve/test/resolver/cup.coffee | 1+
Anode_modules/resolve/test/resolver/foo.js | 1+
Anode_modules/resolve/test/resolver/incorrect_main/index.js | 2++
Anode_modules/resolve/test/resolver/incorrect_main/package.json | 3+++
Anode_modules/resolve/test/resolver/mug.coffee | 0
Anode_modules/resolve/test/resolver/mug.js | 0
Anode_modules/resolve/test/resolver/other_path/lib/other-lib.js | 0
Anode_modules/resolve/test/resolver/other_path/root.js | 0
Anode_modules/resolve/test/resolver/punycode/node_modules/punycode/index.js | 0
Anode_modules/resolve/test/resolver/quux/foo/index.js | 1+
Anode_modules/resolve/test/resolver/without_basedir/main.js | 6++++++
Anode_modules/resolve/test/resolver/without_basedir/node_modules/mymodule.js | 1+
Anode_modules/resolve/test/resolver_sync.js | 180+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/resolve/test/subdirs.js | 13+++++++++++++
Anode_modules/resolve/test/subdirs/node_modules/a/b/c/x.json | 1+
Anode_modules/resolve/test/subdirs/node_modules/a/package.json | 1+
Anode_modules/youtube-api-v3-search/.travis.yml | 9+++++++++
Anode_modules/youtube-api-v3-search/CHANGELOG.md | 17+++++++++++++++++
Anode_modules/youtube-api-v3-search/README.md | 129+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/youtube-api-v3-search/dist/youtube-api-v3-search.js | 358+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/youtube-api-v3-search/dist/youtube-api-v3-search.min.js | 2++
Anode_modules/youtube-api-v3-search/karma.conf.js | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/youtube-api-v3-search/package.json | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/youtube-api-v3-search/src/browser.js | 6++++++
Anode_modules/youtube-api-v3-search/src/common.js | 22++++++++++++++++++++++
Anode_modules/youtube-api-v3-search/src/index.js | 5+++++
Anode_modules/youtube-api-v3-search/src/request/browser-request.js | 24++++++++++++++++++++++++
Anode_modules/youtube-api-v3-search/src/request/node-request.js | 18++++++++++++++++++
Anode_modules/youtube-api-v3-search/test/browser/browser.spec.js | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/youtube-api-v3-search/test/index.spec.js | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/youtube-api-v3-search/webpack.config.js | 44++++++++++++++++++++++++++++++++++++++++++++
Anode_modules/youtube-api-v3-search/youtube-api-v3-search-1.0.0.tgz | 0
Mpackage-lock.json | 47++++++++++++++++++++++++++++++++++-------------
Mpackage.json | 3++-
95 files changed, 3140 insertions(+), 15 deletions(-)

diff --git a/lib/3party.js b/lib/3party.js @@ -1,5 +1,6 @@ const fetch = require('node-fetch'); const config = require("../config/config.js") +const ytcall = require('youtube-api-v3-search'); const urls = { iss: 'https://api.wheretheiss.at/v1/satellites/25544', @@ -109,11 +110,22 @@ console.log("index 0 " + arguements[0]); } +const ytresults =async (arguements, message) => { + options ={ + q: arguements[0], + part: "snippet", + type: "video" + } + let result = await ytcall(config.token.youtubekey,options); + return result; +} + module.exports = { iss, joke, beer, foas1, code, - stocks + stocks, + ytresults } diff --git a/lib/processing.js b/lib/processing.js @@ -35,6 +35,9 @@ const tool = require("./tools.js"); case "stocks": message.channel.send(await apiroute.stocks(arguements, message)); break; + case "yt": + message.channel.send(await apiroute.ytresults(arguements, message)); + break; default: tool.help(arguements, message); break; diff --git a/node_modules/browser-resolve/LICENSE b/node_modules/browser-resolve/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2013-2015 Roman Shtylman <shtylman@gmail.com> + +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. diff --git a/node_modules/browser-resolve/README.md b/node_modules/browser-resolve/README.md @@ -0,0 +1,146 @@ +# browser-resolve [![Build Status](https://travis-ci.org/defunctzombie/node-browser-resolve.png?branch=master)](https://travis-ci.org/defunctzombie/node-browser-resolve) + +node.js resolve algorithm with [browser field](https://github.com/defunctzombie/package-browser-field-spec) support. + +## api + +### resolve(id, opts={}, cb) + +Resolve a module path and call `cb(err, path [, pkg])` + +Options: + +* `basedir` - directory to begin resolving from +* `browser` - the 'browser' property to use from package.json (defaults to 'browser') +* `filename` - the calling filename where the `require()` call originated (in the source) +* `modules` - object with module id/name -> path mappings to consult before doing manual resolution (use to provide core modules) +* `packageFilter` - transform the parsed `package.json` contents before looking at the `main` field +* `paths` - `require.paths` array to use if nothing is found on the normal `node_modules` recursive walk + +Options supported by [node-resolve](https://github.com/substack/node-resolve#resolveid-opts-cb) can be used. + +### resolve.sync(id, opts={}) + +Same as the async resolve, just uses sync methods. + +Options supported by [node-resolve](https://github.com/substack/node-resolve#resolvesyncid-opts) `sync` can be used. + +## basic usage + +you can resolve files like `require.resolve()`: +``` js +var resolve = require('browser-resolve'); +resolve('../', { filename: __filename }, function(err, path) { + console.log(path); +}); +``` + +``` +$ node example/resolve.js +/home/substack/projects/node-browser-resolve/index.js +``` + +## core modules + +By default, core modules (http, dgram, etc) will return their same name as the path. If you want to have specific paths returned, specify a `modules` property in the options object. + +``` js +var shims = { + http: '/your/path/to/http.js' +}; + +var resolve = require('browser-resolve'); +resolve('fs', { modules: shims }, function(err, path) { + console.log(path); +}); +``` + +``` +$ node example/builtin.js +/home/substack/projects/node-browser-resolve/builtin/fs.js +``` + +## browser field +browser-specific versions of modules + +``` js +{ + "name": "custom", + "version": "0.0.0", + "browser": { + "./main.js": "custom.js" + }, + "chromeapp": { + "./main.js": "custom-chromeapp.js" + } +} +``` + +``` js +var resolve = require('browser-resolve'); +var parent = { filename: __dirname + '/custom/file.js' /*, browser: 'chromeapp' */ }; +resolve('./main.js', parent, function(err, path) { + console.log(path); +}); +``` + +``` +$ node example/custom.js +/home/substack/projects/node-browser-resolve/example/custom/custom.js +``` + +## skip + +You can skip over dependencies by setting a +[browser field](https://gist.github.com/defunctzombie/4339901) +value to `false`: + +``` json +{ + "name": "skip", + "version": "0.0.0", + "browser": { + "tar": false + } +} +``` + +This is handy if you have code like: + +``` js +var tar = require('tar'); + +exports.add = function (a, b) { + return a + b; +}; + +exports.parse = function () { + return tar.Parse(); +}; +``` + +so that `require('tar')` will just return `{}` in the browser because you don't +intend to support the `.parse()` export in a browser environment. + +``` js +var resolve = require('browser-resolve'); +var parent = { filename: __dirname + '/skip/main.js' }; +resolve('tar', parent, function(err, path) { + console.log(path); +}); +``` + +``` +$ node example/skip.js +/home/substack/projects/node-browser-resolve/empty.js +``` + +# license + +MIT + +# upgrade notes + +Prior to v1.x this library provided shims for node core modules. These have since been removed. If you want to have alternative core modules provided, use the `modules` option when calling resolve. + +This was done to allow package managers to choose which shims they want to use without browser-resolve being the central point of update. diff --git a/node_modules/browser-resolve/empty.js b/node_modules/browser-resolve/empty.js diff --git a/node_modules/browser-resolve/index.js b/node_modules/browser-resolve/index.js @@ -0,0 +1,345 @@ +// builtin +var fs = require('fs'); +var path = require('path'); + +// vendor +var resv = require('resolve'); + +// given a path, create an array of node_module paths for it +// borrowed from substack/resolve +function nodeModulesPaths (start, cb) { + var splitRe = process.platform === 'win32' ? /[\/\\]/ : /\/+/; + var parts = start.split(splitRe); + + var dirs = []; + for (var i = parts.length - 1; i >= 0; i--) { + if (parts[i] === 'node_modules') continue; + var dir = path.join.apply( + path, parts.slice(0, i + 1).concat(['node_modules']) + ); + if (!parts[0].match(/([A-Za-z]:)/)) { + dir = '/' + dir; + } + dirs.push(dir); + } + return dirs; +} + +function find_shims_in_package(pkgJson, cur_path, shims, browser) { + try { + var info = JSON.parse(pkgJson); + } + catch (err) { + err.message = pkgJson + ' : ' + err.message + throw err; + } + + var replacements = getReplacements(info, browser); + + // no replacements, skip shims + if (!replacements) { + return; + } + + // if browser mapping is a string + // then it just replaces the main entry point + if (typeof replacements === 'string') { + var key = path.resolve(cur_path, info.main || 'index.js'); + shims[key] = path.resolve(cur_path, replacements); + return; + } + + // http://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders + Object.keys(replacements).forEach(function(key) { + var val; + if (replacements[key] === false) { + val = path.normalize(__dirname + '/empty.js'); + } + else { + val = replacements[key]; + // if target is a relative path, then resolve + // otherwise we assume target is a module + if (val[0] === '.') { + val = path.resolve(cur_path, val); + } + } + + if (key[0] === '/' || key[0] === '.') { + // if begins with / ../ or ./ then we must resolve to a full path + key = path.resolve(cur_path, key); + } + shims[key] = val; + }); + + [ '.js', '.json' ].forEach(function (ext) { + Object.keys(shims).forEach(function (key) { + if (!shims[key + ext]) { + shims[key + ext] = shims[key]; + } + }); + }); +} + +// paths is mutated +// load shims from first package.json file found +function load_shims(paths, browser, cb) { + // identify if our file should be replaced per the browser field + // original filename|id -> replacement + var shims = Object.create(null); + + (function next() { + var cur_path = paths.shift(); + if (!cur_path) { + return cb(null, shims); + } + + var pkg_path = path.join(cur_path, 'package.json'); + + fs.readFile(pkg_path, 'utf8', function(err, data) { + if (err) { + // ignore paths we can't open + // avoids an exists check + if (err.code === 'ENOENT') { + return next(); + } + + return cb(err); + } + try { + find_shims_in_package(data, cur_path, shims, browser); + return cb(null, shims); + } + catch (err) { + return cb(err); + } + }); + })(); +}; + +// paths is mutated +// synchronously load shims from first package.json file found +function load_shims_sync(paths, browser) { + // identify if our file should be replaced per the browser field + // original filename|id -> replacement + var shims = Object.create(null); + var cur_path; + + while (cur_path = paths.shift()) { + var pkg_path = path.join(cur_path, 'package.json'); + + try { + var data = fs.readFileSync(pkg_path, 'utf8'); + find_shims_in_package(data, cur_path, shims, browser); + return shims; + } + catch (err) { + // ignore paths we can't open + // avoids an exists check + if (err.code === 'ENOENT') { + continue; + } + + throw err; + } + } + return shims; +} + +function build_resolve_opts(opts, base) { + var packageFilter = opts.packageFilter; + var browser = normalizeBrowserFieldName(opts.browser) + + opts.basedir = base; + opts.packageFilter = function (info, pkgdir) { + if (packageFilter) info = packageFilter(info, pkgdir); + + var replacements = getReplacements(info, browser); + + // no browser field, keep info unchanged + if (!replacements) { + return info; + } + + info[browser] = replacements; + + // replace main + if (typeof replacements === 'string') { + info.main = replacements; + return info; + } + + var replace_main = replacements[info.main || './index.js'] || + replacements['./' + info.main || './index.js']; + + info.main = replace_main || info.main; + return info; + }; + + var pathFilter = opts.pathFilter; + opts.pathFilter = function(info, resvPath, relativePath) { + if (relativePath[0] != '.') { + relativePath = './' + relativePath; + } + var mappedPath; + if (pathFilter) { + mappedPath = pathFilter.apply(this, arguments); + } + if (mappedPath) { + return mappedPath; + } + + var replacements = info[browser]; + if (!replacements) { + return; + } + + mappedPath = replacements[relativePath]; + if (!mappedPath && path.extname(relativePath) === '') { + mappedPath = replacements[relativePath + '.js']; + if (!mappedPath) { + mappedPath = replacements[relativePath + '.json']; + } + } + return mappedPath; + }; + + return opts; +} + +function resolve(id, opts, cb) { + + // opts.filename + // opts.paths + // opts.modules + // opts.packageFilter + + opts = opts || {}; + opts.filename = opts.filename || ''; + + var base = path.dirname(opts.filename); + + if (opts.basedir) { + base = opts.basedir; + } + + var paths = nodeModulesPaths(base); + + if (opts.paths) { + paths.push.apply(paths, opts.paths); + } + + paths = paths.map(function(p) { + return path.dirname(p); + }); + + // we must always load shims because the browser field could shim out a module + load_shims(paths, opts.browser, function(err, shims) { + if (err) { + return cb(err); + } + + var resid = path.resolve(opts.basedir || path.dirname(opts.filename), id); + if (shims[id] || shims[resid]) { + var xid = shims[id] ? id : resid; + // if the shim was is an absolute path, it was fully resolved + if (shims[xid][0] === '/') { + return resv(shims[xid], build_resolve_opts(opts, base), function(err, full, pkg) { + cb(null, full, pkg); + }); + } + + // module -> alt-module shims + id = shims[xid]; + } + + var modules = opts.modules || Object.create(null); + var shim_path = modules[id]; + if (shim_path) { + return cb(null, shim_path); + } + + // our browser field resolver + // if browser field is an object tho? + var full = resv(id, build_resolve_opts(opts, base), function(err, full, pkg) { + if (err) { + return cb(err); + } + + var resolved = (shims) ? shims[full] || full : full; + cb(null, resolved, pkg); + }); + }); +}; + +resolve.sync = function (id, opts) { + + // opts.filename + // opts.paths + // opts.modules + // opts.packageFilter + + opts = opts || {}; + opts.filename = opts.filename || ''; + + var base = path.dirname(opts.filename); + + if (opts.basedir) { + base = opts.basedir; + } + + var paths = nodeModulesPaths(base); + + if (opts.paths) { + paths.push.apply(paths, opts.paths); + } + + paths = paths.map(function(p) { + return path.dirname(p); + }); + + // we must always load shims because the browser field could shim out a module + var shims = load_shims_sync(paths, opts.browser); + var resid = path.resolve(opts.basedir || path.dirname(opts.filename), id); + + if (shims[id] || shims[resid]) { + var xid = shims[id] ? id : resid; + // if the shim was is an absolute path, it was fully resolved + if (shims[xid][0] === '/') { + return resv.sync(shims[xid], build_resolve_opts(opts, base)); + } + + // module -> alt-module shims + id = shims[xid]; + } + + var modules = opts.modules || Object.create(null); + var shim_path = modules[id]; + if (shim_path) { + return shim_path; + } + + // our browser field resolver + // if browser field is an object tho? + var full = resv.sync(id, build_resolve_opts(opts, base)); + + return (shims) ? shims[full] || full : full; +}; + +function normalizeBrowserFieldName(browser) { + return browser || 'browser'; +} + +function getReplacements(info, browser) { + browser = normalizeBrowserFieldName(browser); + var replacements = info[browser] || info.browser; + + // support legacy browserify field for easier migration from legacy + // many packages used this field historically + if (typeof info.browserify === 'string' && !replacements) { + replacements = info.browserify; + } + + return replacements; +} + +module.exports = resolve; diff --git a/node_modules/browser-resolve/package.json b/node_modules/browser-resolve/package.json @@ -0,0 +1,61 @@ +{ + "_from": "browser-resolve@^1.11.3", + "_id": "browser-resolve@1.11.3", + "_inBundle": false, + "_integrity": "sha512-exDi1BYWB/6raKHmDTCicQfTkqwN5fioMFV4j8BsfMU4R2DK/QfZfK7kOVkmWCNANf0snkBzqGqAJBao9gZMdQ==", + "_location": "/browser-resolve", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "browser-resolve@^1.11.3", + "name": "browser-resolve", + "escapedName": "browser-resolve", + "rawSpec": "^1.11.3", + "saveSpec": null, + "fetchSpec": "^1.11.3" + }, + "_requiredBy": [ + "/youtube-api-v3-search" + ], + "_resolved": "https://registry.npmjs.org/browser-resolve/-/browser-resolve-1.11.3.tgz", + "_shasum": "9b7cbb3d0f510e4cb86bdbd796124d28b5890af6", + "_spec": "browser-resolve@^1.11.3", + "_where": "/home/pi/Documents/buddy/node_modules/youtube-api-v3-search", + "author": { + "name": "Roman Shtylman", + "email": "shtylman@gmail.com" + }, + "bugs": { + "url": "https://github.com/shtylman/node-browser-resolve/issues" + }, + "bundleDependencies": false, + "dependencies": { + "resolve": "1.1.7" + }, + "deprecated": false, + "description": "resolve which handles browser field support in package.json", + "devDependencies": { + "mocha": "1.14.0" + }, + "files": [ + "index.js", + "empty.js" + ], + "homepage": "https://github.com/shtylman/node-browser-resolve#readme", + "keywords": [ + "resolve", + "browser" + ], + "license": "MIT", + "main": "index.js", + "name": "browser-resolve", + "repository": { + "type": "git", + "url": "git://github.com/shtylman/node-browser-resolve.git" + }, + "scripts": { + "test": "mocha --reporter list test/*.js" + }, + "version": "1.11.3" +} diff --git a/node_modules/resolve/.travis.yml b/node_modules/resolve/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - 0.6 + - 0.8 diff --git a/node_modules/resolve/LICENSE b/node_modules/resolve/LICENSE @@ -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. diff --git a/node_modules/resolve/example/async.js b/node_modules/resolve/example/async.js @@ -0,0 +1,5 @@ +var resolve = require('../'); +resolve('tap', { basedir: __dirname }, function (err, res) { + if (err) console.error(err) + else console.log(res) +}); diff --git a/node_modules/resolve/example/sync.js b/node_modules/resolve/example/sync.js @@ -0,0 +1,3 @@ +var resolve = require('../'); +var res = resolve.sync('tap', { basedir: __dirname }); +console.log(res); diff --git a/node_modules/resolve/index.js b/node_modules/resolve/index.js @@ -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'); diff --git a/node_modules/resolve/lib/async.js b/node_modules/resolve/lib/async.js @@ -0,0 +1,192 @@ +var core = require('./core'); +var fs = require('fs'); +var path = require('path'); +var caller = require('./caller.js'); +var nodeModulesPaths = require('./node-modules-paths.js'); +var splitRe = process.platform === 'win32' ? /[\/\\]/ : /\//; + +module.exports = function resolve (x, opts, cb) { + if (typeof opts === 'function') { + cb = opts; + opts = {}; + } + if (!opts) opts = {}; + if (typeof x !== 'string') { + return process.nextTick(function () { + cb(new Error('path must be a string')); + }); + } + + 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()); + + opts.paths = opts.paths || []; + + if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[\\\/])/.test(x)) { + var res = path.resolve(y, x); + if (x === '..') res += '/'; + if (/\/$/.test(x) && res === y) { + loadAsDirectory(res, opts.package, onfile); + } + else loadAsFile(res, opts.package, onfile); + } + 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 onfile (err, m, pkg) { + if (err) cb(err) + else if (m) cb(null, m, pkg) + else loadAsDirectory(res, 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 + "'")) + }) + } + + function loadAsFile (x, pkg, cb) { + if (typeof pkg === 'function') { + cb = pkg; + pkg = undefined; + } + + var exts = [''].concat(extensions); + load(exts, x, pkg) + + function load (exts, x, pkg) { + if (exts.length === 0) return cb(null, undefined, pkg); + var file = x + exts[0]; + + if (pkg) onpkg(null, pkg) + else loadpkg(path.dirname(file), onpkg); + + function onpkg (err, pkg_, dir) { + pkg = pkg_; + if (err) return cb(err) + if (dir && pkg && opts.pathFilter) { + var rfile = path.relative(dir, file); + var rel = rfile.slice(0, rfile.length - exts[0].length); + var r = opts.pathFilter(pkg, x, rel); + if (r) return load( + [''].concat(extensions.slice()), + path.resolve(dir, r), + pkg + ); + } + isFile(file, onex); + } + function onex (err, ex) { + if (err) cb(err) + else if (!ex) load(exts.slice(1), x, pkg) + else cb(null, file, pkg) + } + } + } + + function loadpkg (dir, cb) { + if (dir === '' || dir === '/') return cb(null); + if (process.platform === 'win32' && /^\w:[\\\/]*$/.test(dir)) { + return cb(null); + } + if (/[\\\/]node_modules[\\\/]*$/.test(dir)) return cb(null); + + var pkgfile = path.join(dir, 'package.json'); + isFile(pkgfile, function (err, ex) { + // on err, ex is false + if (!ex) return loadpkg( + path.dirname(dir), cb + ); + + readFile(pkgfile, function (err, body) { + if (err) cb(err); + try { var pkg = JSON.parse(body) } + catch (err) {} + + if (pkg && opts.packageFilter) { + pkg = opts.packageFilter(pkg, pkgfile); + } + cb(null, pkg, dir); + }); + }); + } + + 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, pkgfile); + } + + 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]; + + var file = path.join(dir, '/', x); + loadAsFile(file, undefined, onfile); + + function onfile (err, m, pkg) { + if (err) return cb(err); + if (m) return cb(null, m, pkg); + loadAsDirectory(path.join(dir, '/', x), undefined, ondir); + } + + function ondir (err, n, pkg) { + if (err) return cb(err); + if (n) return cb(null, n, pkg); + process(dirs.slice(1)); + } + })(nodeModulesPaths(start, opts)); + } +}; diff --git a/node_modules/resolve/lib/caller.js b/node_modules/resolve/lib/caller.js @@ -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(); +}; diff --git a/node_modules/resolve/lib/core.js b/node_modules/resolve/lib/core.js @@ -0,0 +1,4 @@ +module.exports = require('./core.json').reduce(function (acc, x) { + acc[x] = true; + return acc; +}, {}); diff --git a/node_modules/resolve/lib/core.json b/node_modules/resolve/lib/core.json @@ -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" +] diff --git a/node_modules/resolve/lib/node-modules-paths.js b/node_modules/resolve/lib/node-modules-paths.js @@ -0,0 +1,38 @@ +var path = require('path'); + +module.exports = function (start, opts) { + var modules = opts.moduleDirectory + ? [].concat(opts.moduleDirectory) + : ['node_modules'] + ; + + // ensure that `start` is an absolute path at this point, + // resolving against the process' current working directory + start = path.resolve(start); + + 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 (modules.indexOf(parts[i]) !== -1) continue; + dirs = dirs.concat(modules.map(function(module_dir) { + return prefix + path.join( + path.join.apply(path, parts.slice(0, i + 1)), + module_dir + ); + })); + } + if (process.platform === 'win32'){ + dirs[dirs.length-1] = dirs[dirs.length-1].replace(":", ":\\"); + } + return dirs.concat(opts.paths); +} diff --git a/node_modules/resolve/lib/sync.js b/node_modules/resolve/lib/sync.js @@ -0,0 +1,81 @@ +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 (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[\\\/])/.test(x)) { + var res = path.resolve(y, x); + if (x === '..') res += '/'; + var m = loadAsFileSync(res) || loadAsDirectorySync(res); + 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; + } + } +}; diff --git a/node_modules/resolve/package.json b/node_modules/resolve/package.json @@ -0,0 +1,58 @@ +{ + "_from": "resolve@1.1.7", + "_id": "resolve@1.1.7", + "_inBundle": false, + "_integrity": "sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=", + "_location": "/resolve", + "_phantomChildren": {}, + "_requested": { + "type": "version", + "registry": true, + "raw": "resolve@1.1.7", + "name": "resolve", + "escapedName": "resolve", + "rawSpec": "1.1.7", + "saveSpec": null, + "fetchSpec": "1.1.7" + }, + "_requiredBy": [ + "/browser-resolve" + ], + "_resolved": "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz", + "_shasum": "203114d82ad2c5ed9e8e0411b3932875e889e97b", + "_spec": "resolve@1.1.7", + "_where": "/home/pi/Documents/buddy/node_modules/browser-resolve", + "author": { + "name": "James Halliday", + "email": "mail@substack.net", + "url": "http://substack.net" + }, + "bugs": { + "url": "https://github.com/substack/node-resolve/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "resolve like require.resolve() on behalf of files asynchronously and synchronously", + "devDependencies": { + "tap": "0.4.13", + "tape": "^3.5.0" + }, + "homepage": "https://github.com/substack/node-resolve#readme", + "keywords": [ + "resolve", + "require", + "node", + "module" + ], + "license": "MIT", + "main": "index.js", + "name": "resolve", + "repository": { + "type": "git", + "url": "git://github.com/substack/node-resolve.git" + }, + "scripts": { + "test": "tape test/*.js" + }, + "version": "1.1.7" +} diff --git a/node_modules/resolve/readme.markdown b/node_modules/resolve/readme.markdown @@ -0,0 +1,148 @@ +# 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(id, opts={}, cb) + +Asynchronously resolve the module path string `id` into `cb(err, res [, pkg])`, where `pkg` (if defined) is the data from `package.json`. + +options are: + +* opts.basedir - directory to begin resolving from + +* opts.package - `package.json` data applicable to the module 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.pathFilter(pkg, path, relativePath) - transform a path within a package + * pkg - package data + * path - the path being resolved + * relativePath - the path relative from the package.json location + * returns - a relative path that will be joined from the package.json location + +* 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 (or directories) in which to recursively look for modules. 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(id, opts) + +Synchronously resolve the module path string `id`, returning the result and +throwing an error when `id` 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(pkg, pkgfile)` - 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 (or directories) in which to recursively look for modules. 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 diff --git a/node_modules/resolve/test/core.js b/node_modules/resolve/test/core.js @@ -0,0 +1,12 @@ +var test = require('tape'); +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(); +}); diff --git a/node_modules/resolve/test/dotdot.js b/node_modules/resolve/test/dotdot.js @@ -0,0 +1,29 @@ +var path = require('path'); +var test = require('tape'); +var resolve = require('../'); + +test('dotdot', function (t) { + t.plan(4); + var dir = __dirname + '/dotdot/abc'; + + resolve('..', { basedir : dir }, function (err, res, pkg) { + t.ifError(err); + t.equal(res, __dirname + '/dotdot/index.js'); + }); + + resolve('.', { basedir : dir }, function (err, res, pkg) { + t.ifError(err); + t.equal(res, dir + '/index.js'); + }); +}); + +test('dotdot sync', function (t) { + t.plan(2); + var dir = __dirname + '/dotdot/abc'; + + var a = resolve.sync('..', { basedir : dir }); + t.equal(a, __dirname + '/dotdot/index.js'); + + var b = resolve.sync('.', { basedir : dir }); + t.equal(b, dir + '/index.js'); +}); diff --git a/node_modules/resolve/test/dotdot/abc/index.js b/node_modules/resolve/test/dotdot/abc/index.js @@ -0,0 +1,2 @@ +var x = require('..'); +console.log(x); diff --git a/node_modules/resolve/test/dotdot/index.js b/node_modules/resolve/test/dotdot/index.js @@ -0,0 +1 @@ +module.exports = 'whatever' diff --git a/node_modules/resolve/test/faulty_basedir.js b/node_modules/resolve/test/faulty_basedir.js @@ -0,0 +1,17 @@ +var path = require('path'); +var test = require('tape'); +var resolve = require('../'); + +// not sure what's up with this test anymore +if (process.platform !== 'win32') return; + +test('faulty basedir must produce error in windows', function (t) { + t.plan(1); + + var resolverDir = 'C:\\a\\b\\c\\d'; + + resolve('tape/lib/test.js', { basedir : resolverDir }, function (err, res, pkg) { + t.equal(true, !!err); + }); + +}); diff --git a/node_modules/resolve/test/filter.js b/node_modules/resolve/test/filter.js @@ -0,0 +1,18 @@ +var test = require('tape'); +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'); + }); +}); diff --git a/node_modules/resolve/test/filter_sync.js b/node_modules/resolve/test/filter_sync.js @@ -0,0 +1,15 @@ +var test = require('tape'); +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(); +}); diff --git a/node_modules/resolve/test/mock.js b/node_modules/resolve/test/mock.js @@ -0,0 +1,142 @@ +var test = require('tape'); +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'); + }); +}); diff --git a/node_modules/resolve/test/mock_sync.js b/node_modules/resolve/test/mock_sync.js @@ -0,0 +1,68 @@ +var test = require('tape'); +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' + ); +}); diff --git a/node_modules/resolve/test/module_dir.js b/node_modules/resolve/test/module_dir.js @@ -0,0 +1,56 @@ +var path = require('path'); +var test = require('tape'); +var resolve = require('../'); + +test('moduleDirectory strings', function (t) { + t.plan(4); + var dir = __dirname + '/module_dir'; + var xopts = { + basedir : dir, + moduleDirectory: 'xmodules' + }; + resolve('aaa', xopts, function (err, res, pkg) { + t.ifError(err); + t.equal(res, dir + '/xmodules/aaa/index.js'); + }); + + var yopts = { + basedir : dir, + moduleDirectory: 'ymodules' + }; + resolve('aaa', yopts, function (err, res, pkg) { + t.ifError(err); + t.equal(res, dir + '/ymodules/aaa/index.js'); + }); +}); + +test('moduleDirectory array', function (t) { + t.plan(6); + var dir = __dirname + '/module_dir'; + var aopts = { + basedir : dir, + moduleDirectory: [ 'xmodules', 'ymodules', 'zmodules' ] + }; + resolve('aaa', aopts, function (err, res, pkg) { + t.ifError(err); + t.equal(res, dir + '/xmodules/aaa/index.js'); + }); + + var bopts = { + basedir : dir, + moduleDirectory: [ 'zmodules', 'ymodules', 'xmodules' ] + }; + resolve('aaa', bopts, function (err, res, pkg) { + t.ifError(err); + t.equal(res, dir + '/ymodules/aaa/index.js'); + }); + + var copts = { + basedir : dir, + moduleDirectory: [ 'xmodules', 'ymodules', 'zmodules' ] + }; + resolve('bbb', copts, function (err, res, pkg) { + t.ifError(err); + t.equal(res, dir + '/zmodules/bbb/main.js'); + }); +}); diff --git a/node_modules/resolve/test/module_dir/xmodules/aaa/index.js b/node_modules/resolve/test/module_dir/xmodules/aaa/index.js @@ -0,0 +1 @@ +module.exports = function (x) { return x * 100 } diff --git a/node_modules/resolve/test/module_dir/ymodules/aaa/index.js b/node_modules/resolve/test/module_dir/ymodules/aaa/index.js @@ -0,0 +1 @@ +module.exports = function (x) { return x + 100 } diff --git a/node_modules/resolve/test/module_dir/zmodules/bbb/main.js b/node_modules/resolve/test/module_dir/zmodules/bbb/main.js @@ -0,0 +1 @@ +module.exports = function (n) { return n * 111 } diff --git a/node_modules/resolve/test/module_dir/zmodules/bbb/package.json b/node_modules/resolve/test/module_dir/zmodules/bbb/package.json @@ -0,0 +1,3 @@ +{ + "main": "main.js" +} diff --git a/node_modules/resolve/test/node_path.js b/node_modules/resolve/test/node_path.js @@ -0,0 +1,48 @@ +var path = require('path'); +var test = require('tape'); +var resolve = require('../'); + +test('$NODE_PATH', function (t) { + t.plan(4); + + 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'); + }); + + // ensure that relative paths still resolve against the + // regular `node_modules` correctly + resolve('tap', { + paths: [ + 'node_path', + ], + basedir: 'node_path/x', + }, function (err, res) { + t.equal(res, path.resolve(__dirname, '..', 'node_modules/tap/lib/main.js')); + }); +}); diff --git a/node_modules/resolve/test/node_path/x/aaa/index.js b/node_modules/resolve/test/node_path/x/aaa/index.js @@ -0,0 +1 @@ +module.exports = 'A' diff --git a/node_modules/resolve/test/node_path/x/ccc/index.js b/node_modules/resolve/test/node_path/x/ccc/index.js @@ -0,0 +1 @@ +module.exports = 'C' diff --git a/node_modules/resolve/test/node_path/y/bbb/index.js b/node_modules/resolve/test/node_path/y/bbb/index.js @@ -0,0 +1 @@ +module.exports = 'B' diff --git a/node_modules/resolve/test/node_path/y/ccc/index.js b/node_modules/resolve/test/node_path/y/ccc/index.js @@ -0,0 +1 @@ +module.exports = 'CY' diff --git a/node_modules/resolve/test/nonstring.js b/node_modules/resolve/test/nonstring.js @@ -0,0 +1,9 @@ +var test = require('tape'); +var resolve = require('../'); + +test('nonstring', function (t) { + t.plan(1); + resolve(555, function (err, res, pkg) { + t.ok(err); + }); +}); diff --git a/node_modules/resolve/test/pathfilter.js b/node_modules/resolve/test/pathfilter.js @@ -0,0 +1,35 @@ +var test = require('tape'); +var resolve = require('../'); + +test('#62: deep module references and the pathFilter', function(t){ + t.plan(9); + + var resolverDir = __dirname + '/pathfilter/deep_ref'; + var pathFilter = function(pkg, x, remainder){ + t.equal(pkg.version, "1.2.3"); + t.equal(x, resolverDir + '/node_modules/deep/ref'); + t.equal(remainder, "ref"); + return "alt"; + }; + + resolve('deep/ref', { basedir : resolverDir }, function (err, res, pkg) { + if (err) t.fail(err); + + t.equal(pkg.version, "1.2.3"); + t.equal(res, resolverDir + '/node_modules/deep/ref.js'); + }); + + resolve('deep/deeper/ref', { basedir: resolverDir }, + function(err, res, pkg) { + if(err) t.fail(err); + t.notEqual(pkg, undefined); + t.equal(pkg.version, "1.2.3"); + t.equal(res, resolverDir + '/node_modules/deep/deeper/ref.js'); + }); + + resolve('deep/ref', { basedir : resolverDir, pathFilter : pathFilter }, + function (err, res, pkg) { + if (err) t.fail(err); + t.equal(res, resolverDir + '/node_modules/deep/alt.js'); + }); +}); diff --git a/node_modules/resolve/test/pathfilter/deep_ref/main.js b/node_modules/resolve/test/pathfilter/deep_ref/main.js diff --git a/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/alt.js b/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/alt.js diff --git a/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/deeper/ref.js b/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/deeper/ref.js diff --git a/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/package.json b/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/package.json @@ -0,0 +1,4 @@ +{ + "name": "deep", + "version": "1.2.3" +} diff --git a/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/ref.js b/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/ref.js diff --git a/node_modules/resolve/test/precedence.js b/node_modules/resolve/test/precedence.js @@ -0,0 +1,23 @@ +var path = require('path'); +var test = require('tape'); +var resolve = require('../'); + +test('precedence', function (t) { + t.plan(3); + var dir = path.join(__dirname, 'precedence/aaa'); + + resolve('./', { basedir : dir }, function (err, res, pkg) { + t.ifError(err); + t.equal(res, path.join(dir, 'index.js')); + t.equal(pkg.name, 'resolve'); + }); +}); + +test('./ should not load ${dir}.js', function (t) { + t.plan(1); + var dir = path.join(__dirname, 'precedence/bbb'); + + resolve('./', { basedir : dir }, function (err, res, pkg) { + t.ok(err); + }); +}); diff --git a/node_modules/resolve/test/precedence/aaa.js b/node_modules/resolve/test/precedence/aaa.js @@ -0,0 +1 @@ +module.exports = 'wtf' diff --git a/node_modules/resolve/test/precedence/aaa/index.js b/node_modules/resolve/test/precedence/aaa/index.js @@ -0,0 +1 @@ +module.exports = 'okok' diff --git a/node_modules/resolve/test/precedence/aaa/main.js b/node_modules/resolve/test/precedence/aaa/main.js @@ -0,0 +1 @@ +console.log(require('./')) diff --git a/node_modules/resolve/test/precedence/bbb.js b/node_modules/resolve/test/precedence/bbb.js @@ -0,0 +1 @@ +module.exports '>_<' diff --git a/node_modules/resolve/test/precedence/bbb/main.js b/node_modules/resolve/test/precedence/bbb/main.js @@ -0,0 +1 @@ +console.log(require('./')); // should throw diff --git a/node_modules/resolve/test/resolver.js b/node_modules/resolve/test/resolver.js @@ -0,0 +1,281 @@ +var path = require('path'); +var test = require('tape'); +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.name, 'resolve'); + }); + + resolve('./foo.js', { basedir : dir }, function (err, res, pkg) { + if (err) t.fail(err); + t.equal(res, dir + '/foo.js'); + t.equal(pkg.name, 'resolve'); + }); + + 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'); + }); +}); diff --git a/node_modules/resolve/test/resolver/bar/node_modules/foo/index.js b/node_modules/resolve/test/resolver/bar/node_modules/foo/index.js @@ -0,0 +1 @@ +module.exports = 1; diff --git a/node_modules/resolve/test/resolver/baz/doom.js b/node_modules/resolve/test/resolver/baz/doom.js diff --git a/node_modules/resolve/test/resolver/baz/package.json b/node_modules/resolve/test/resolver/baz/package.json @@ -0,0 +1,3 @@ +{ + "main" : "quux.js" +} diff --git a/node_modules/resolve/test/resolver/baz/quux.js b/node_modules/resolve/test/resolver/baz/quux.js @@ -0,0 +1 @@ +module.exports = 1; diff --git a/node_modules/resolve/test/resolver/biz/node_modules/garply/lib/index.js b/node_modules/resolve/test/resolver/biz/node_modules/garply/lib/index.js @@ -0,0 +1 @@ +module.exports = 'hello garply'; diff --git a/node_modules/resolve/test/resolver/biz/node_modules/garply/package.json b/node_modules/resolve/test/resolver/biz/node_modules/garply/package.json @@ -0,0 +1,3 @@ +{ + "main" : "./lib" +} diff --git a/node_modules/resolve/test/resolver/biz/node_modules/grux/index.js b/node_modules/resolve/test/resolver/biz/node_modules/grux/index.js @@ -0,0 +1 @@ +module.exports = require('tiv') * 100; diff --git a/node_modules/resolve/test/resolver/biz/node_modules/tiv/index.js b/node_modules/resolve/test/resolver/biz/node_modules/tiv/index.js @@ -0,0 +1 @@ +module.exports = 3; diff --git a/node_modules/resolve/test/resolver/cup.coffee b/node_modules/resolve/test/resolver/cup.coffee @@ -0,0 +1 @@ + diff --git a/node_modules/resolve/test/resolver/foo.js b/node_modules/resolve/test/resolver/foo.js @@ -0,0 +1 @@ +module.exports = 1; diff --git a/node_modules/resolve/test/resolver/incorrect_main/index.js b/node_modules/resolve/test/resolver/incorrect_main/index.js @@ -0,0 +1,2 @@ +// this is the actual main file 'index.js', not 'wrong.js' like the package.json would indicate +module.exports = 1; diff --git a/node_modules/resolve/test/resolver/incorrect_main/package.json b/node_modules/resolve/test/resolver/incorrect_main/package.json @@ -0,0 +1,3 @@ +{ + "main" : "wrong.js" +} diff --git a/node_modules/resolve/test/resolver/mug.coffee b/node_modules/resolve/test/resolver/mug.coffee diff --git a/node_modules/resolve/test/resolver/mug.js b/node_modules/resolve/test/resolver/mug.js diff --git a/node_modules/resolve/test/resolver/other_path/lib/other-lib.js b/node_modules/resolve/test/resolver/other_path/lib/other-lib.js diff --git a/node_modules/resolve/test/resolver/other_path/root.js b/node_modules/resolve/test/resolver/other_path/root.js diff --git a/node_modules/resolve/test/resolver/punycode/node_modules/punycode/index.js b/node_modules/resolve/test/resolver/punycode/node_modules/punycode/index.js diff --git a/node_modules/resolve/test/resolver/quux/foo/index.js b/node_modules/resolve/test/resolver/quux/foo/index.js @@ -0,0 +1 @@ +module.exports = 1; diff --git a/node_modules/resolve/test/resolver/without_basedir/main.js b/node_modules/resolve/test/resolver/without_basedir/main.js @@ -0,0 +1,6 @@ +resolve = require('../../../'); + +module.exports = function(t, cb) { + resolve('mymodule', null, cb); +} + diff --git a/node_modules/resolve/test/resolver/without_basedir/node_modules/mymodule.js b/node_modules/resolve/test/resolver/without_basedir/node_modules/mymodule.js @@ -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" diff --git a/node_modules/resolve/test/resolver_sync.js b/node_modules/resolve/test/resolver_sync.js @@ -0,0 +1,180 @@ +var test = require('tape'); +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() +}); diff --git a/node_modules/resolve/test/subdirs.js b/node_modules/resolve/test/subdirs.js @@ -0,0 +1,13 @@ +var test = require('tape'); +var resolve = require('../'); +var path = require('path'); + +test('subdirs', function (t) { + t.plan(2); + + var dir = path.join(__dirname, '/subdirs'); + resolve('a/b/c/x.json', { basedir: dir }, function (err, res) { + t.ifError(err); + t.equal(res, path.join(dir, 'node_modules/a/b/c/x.json')); + }); +}); diff --git a/node_modules/resolve/test/subdirs/node_modules/a/b/c/x.json b/node_modules/resolve/test/subdirs/node_modules/a/b/c/x.json @@ -0,0 +1 @@ +[1,2,3] diff --git a/node_modules/resolve/test/subdirs/node_modules/a/package.json b/node_modules/resolve/test/subdirs/node_modules/a/package.json @@ -0,0 +1 @@ +{} diff --git a/node_modules/youtube-api-v3-search/.travis.yml b/node_modules/youtube-api-v3-search/.travis.yml @@ -0,0 +1,9 @@ +language: node_js +node_js: + - "stable" +dist: trusty # needs Ubuntu Trusty +# Note: if you switch to sudo: false, you'll need to launch Chrome with --no-sandbox. +# See https://github.com/travis-ci/travis-ci/issues/8836 +sudo: required +addons: + chrome: stable # have Travis install Chrome stable. diff --git a/node_modules/youtube-api-v3-search/CHANGELOG.md b/node_modules/youtube-api-v3-search/CHANGELOG.md @@ -0,0 +1,17 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.2.0] - 2018-12-6 +## Fixed +- support React-Native + +## [1.1.0] - 2018-10-28 +### Added +- support for Safari and older browsers by [@MaximVanhove](https://github.com/MaximVanhove) +- support for CommonJS and Modules [@MaximVanhove](https://github.com/MaximVanhove) + +### Security +- Dependency updates diff --git a/node_modules/youtube-api-v3-search/README.md b/node_modules/youtube-api-v3-search/README.md @@ -0,0 +1,129 @@ +# youtube-api-v3-search + +[![Build Status](https://travis-ci.org/LionRoar/youtube-api-v3-search.svg?branch=master)](https://travis-ci.org/LionRoar/youtube-api-v3-search) + +## YouTube Search Google API for [Node.js](https://nodejs.org/en) and Browser + +### Search for YouTube videos, channels, playlists and live events via Google API + +* [Node.js](https://nodejs.org/en) using [https](https://nodejs.org/api/https.html) and in the Browser using [XMLHttpRequests](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) + +* <del>Super light no third-party libraries</del> **Added** [browser-resolve](https://www.npmjs.com/package/browser-resolve) for performance. +* Supports the [Prmise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) API + +* Thanks to @MaximVanhove for adding Support for CommonJS, AMD and global variable. + +----------------- + +Installing + +========== + +Using npm: + +``` bash + npm install youtube-api-v3-search +``` + +Using cdn: + +```html + + + <script src="https://unpkg.com/youtube-api-v3-search@1.2.1/dist/youtube-api-v3-search.min.js"></script> + + + ``` + +----------------- + +Example Usage + +============= + +```js + +const searchYoutube = require('youtube-api-v3-search'); +``` + +or + +```js +import searchYoutube from 'youtube-api-v3-search'; + +``` + +----------------- + +## Callbacks + +```js + +/** + * Searching YouTube. + * @param {string} $YOUTUBE_KEY youtube api-key + * @param {Object} $options search parameters. + * @param {function} callback( @param error , @param result). + * @return {void} + */ + +searchYoutube($YOUTUBE_KEY,$options,callback); +``` + +----------------- + +## Promises __Just don't callback and you'll get a Promise :)__ + +```js + +// NOT passing callback as the 3rd argument it returns Promise +/** + * Searching YouTube. + * @param {string} $YOUTUBE_KEY youtube api-key + * @param {Object} $options search parameters. + * @return {Promise} The result of the search . + */ + +searchYoutube($YOUTUBE_KEY,$options); +``` + +## Async/Await + +```js +async () => { + let result = await searchYoutube($YOUTUBE_KEY,options); +} +``` + +----------------- + +## Options + +### [options/parameters] + +### **Search Options** + +_The **q** parameter specifies the query term to search for._ + +_The **part** parameter specifies a comma-separated list of one or more search resource properties that the API response will include. Set the parameter value to snippet._ + +_The **type** parameter restricts a search query to only retrieve a particular type of resource. The value is a comma-separated list of resource types. The default value is video,channel,playlist._ + +_Acceptable values are:_ + +* _channel_ +* _playlist_ +* _video_ + +#### Example + +```js + +const options = { + q:'nodejs', + part:'snippet', + type:'video' +} +``` + +#### [YouTube API Reference Search#parameters](https://developers.google.com/youtube/v3/docs/search/list#parameters) diff --git a/node_modules/youtube-api-v3-search/dist/youtube-api-v3-search.js b/node_modules/youtube-api-v3-search/dist/youtube-api-v3-search.js @@ -0,0 +1,357 @@ +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(); + else if(typeof define === 'function' && define.amd) + define([], factory); + else if(typeof exports === 'object') + exports["searchYoutube"] = factory(); + else + root["searchYoutube"] = factory(); +})(typeof self !== 'undefined' ? self : this, function() { +return /******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { +/******/ configurable: false, +/******/ enumerable: true, +/******/ get: getter +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +var request = __webpack_require__(1); +var common = __webpack_require__(2); +module.exports = function (key, options, cb) { + console.log('browserJS'); + return common(request, key, options, cb); +}; + +/***/ }), +/* 1 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +module.exports = function (url) { + var req = new XMLHttpRequest(); + return new Promise(function (resolve, reject) { + req.onreadystatechange = function () { + if (this.readyState == 4) { + if (this.status == 200) { + var response = JSON.parse(this.response); + resolve(response); + } else { + var err = JSON.parse(this.response); + reject(err); + } + } + }; + req.onerror = function (e) { + reject(new Error(this.statusText)); + }; + req.open('GET', url, true); + req.send(null); + }); +}; + +/***/ }), +/* 2 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +var config = __webpack_require__(3); +var querystring = __webpack_require__(4); + +module.exports = function (request, key, options, cb) { + if (!key && typeof cb === 'function') return cb(new Error('API Key is required'));else if (!key) throw new Error('API Key is required'); + fillData(key, options); + var q = querystring.stringify(config.options); + if (typeof cb === 'function') request(config.URL + q).then(function (res) { + return cb(null, res); + }).catch(function (err) { + return cb(err); + });else return request(config.URL + q); +}; + +function fillData(key, options) { + config.options.key = key; + for (var i in options) { + config.options[i] = options[i]; + } +} + +/***/ }), +/* 3 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +module.exports.URL = 'https://www.googleapis.com/youtube/v3/search?'; +module.exports.options = { + q: '', + part: 'snippet', + type: 'video' +}; + +/***/ }), +/* 4 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +exports.decode = exports.parse = __webpack_require__(5); +exports.encode = exports.stringify = __webpack_require__(6); + + +/***/ }), +/* 5 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +// Copyright Joyent, Inc. and other Node contributors. +// +// 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. + + + +// If obj.hasOwnProperty has been overridden, then calling +// obj.hasOwnProperty(prop) will break. +// See: https://github.com/joyent/node/issues/1707 +function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +} + +module.exports = function(qs, sep, eq, options) { + sep = sep || '&'; + eq = eq || '='; + var obj = {}; + + if (typeof qs !== 'string' || qs.length === 0) { + return obj; + } + + var regexp = /\+/g; + qs = qs.split(sep); + + var maxKeys = 1000; + if (options && typeof options.maxKeys === 'number') { + maxKeys = options.maxKeys; + } + + var len = qs.length; + // maxKeys <= 0 means that we should not limit keys count + if (maxKeys > 0 && len > maxKeys) { + len = maxKeys; + } + + for (var i = 0; i < len; ++i) { + var x = qs[i].replace(regexp, '%20'), + idx = x.indexOf(eq), + kstr, vstr, k, v; + + if (idx >= 0) { + kstr = x.substr(0, idx); + vstr = x.substr(idx + 1); + } else { + kstr = x; + vstr = ''; + } + + k = decodeURIComponent(kstr); + v = decodeURIComponent(vstr); + + if (!hasOwnProperty(obj, k)) { + obj[k] = v; + } else if (isArray(obj[k])) { + obj[k].push(v); + } else { + obj[k] = [obj[k], v]; + } + } + + return obj; +}; + +var isArray = Array.isArray || function (xs) { + return Object.prototype.toString.call(xs) === '[object Array]'; +}; + + +/***/ }), +/* 6 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +// Copyright Joyent, Inc. and other Node contributors. +// +// 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. + + + +var stringifyPrimitive = function(v) { + switch (typeof v) { + case 'string': + return v; + + case 'boolean': + return v ? 'true' : 'false'; + + case 'number': + return isFinite(v) ? v : ''; + + default: + return ''; + } +}; + +module.exports = function(obj, sep, eq, name) { + sep = sep || '&'; + eq = eq || '='; + if (obj === null) { + obj = undefined; + } + + if (typeof obj === 'object') { + return map(objectKeys(obj), function(k) { + var ks = encodeURIComponent(stringifyPrimitive(k)) + eq; + if (isArray(obj[k])) { + return map(obj[k], function(v) { + return ks + encodeURIComponent(stringifyPrimitive(v)); + }).join(sep); + } else { + return ks + encodeURIComponent(stringifyPrimitive(obj[k])); + } + }).join(sep); + + } + + if (!name) return ''; + return encodeURIComponent(stringifyPrimitive(name)) + eq + + encodeURIComponent(stringifyPrimitive(obj)); +}; + +var isArray = Array.isArray || function (xs) { + return Object.prototype.toString.call(xs) === '[object Array]'; +}; + +function map (xs, f) { + if (xs.map) return xs.map(f); + var res = []; + for (var i = 0; i < xs.length; i++) { + res.push(f(xs[i], i)); + } + return res; +} + +var objectKeys = Object.keys || function (obj) { + var res = []; + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key); + } + return res; +}; + + +/***/ }) +/******/ ]); +});+ \ No newline at end of file diff --git a/node_modules/youtube-api-v3-search/dist/youtube-api-v3-search.min.js b/node_modules/youtube-api-v3-search/dist/youtube-api-v3-search.min.js @@ -0,0 +1 @@ +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.searchYoutube=t():e.searchYoutube=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,r){"use strict";var n=r(1),o=r(2);e.exports=function(e,t,r){return console.log("browserJS"),o(n,e,t,r)}},function(e,t,r){"use strict";e.exports=function(e){var t=new XMLHttpRequest;return new Promise(function(r,n){t.onreadystatechange=function(){if(4==this.readyState)if(200==this.status){var e=JSON.parse(this.response);r(e)}else{var t=JSON.parse(this.response);n(t)}},t.onerror=function(e){n(new Error(this.statusText))},t.open("GET",e,!0),t.send(null)})}},function(e,t,r){"use strict";function n(e,t){o.options.key=e;for(var r in t)o.options[r]=t[r]}var o=r(3),u=r(4);e.exports=function(e,t,r,i){if(!t&&"function"==typeof i)return i(new Error("API Key is required"));if(!t)throw new Error("API Key is required");n(t,r);var s=u.stringify(o.options);if("function"!=typeof i)return e(o.URL+s);e(o.URL+s).then(function(e){return i(null,e)}).catch(function(e){return i(e)})}},function(e,t,r){"use strict";e.exports.URL="https://www.googleapis.com/youtube/v3/search?",e.exports.options={q:"",part:"snippet",type:"video"}},function(e,t,r){"use strict";t.decode=t.parse=r(5),t.encode=t.stringify=r(6)},function(e,t,r){"use strict";function n(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.exports=function(e,t,r,u){t=t||"&",r=r||"=";var i={};if("string"!=typeof e||0===e.length)return i;var s=/\+/g;e=e.split(t);var c=1e3;u&&"number"==typeof u.maxKeys&&(c=u.maxKeys);var f=e.length;c>0&&f>c&&(f=c);for(var p=0;p<f;++p){var a,l,y,d,v=e[p].replace(s,"%20"),b=v.indexOf(r);b>=0?(a=v.substr(0,b),l=v.substr(b+1)):(a=v,l=""),y=decodeURIComponent(a),d=decodeURIComponent(l),n(i,y)?o(i[y])?i[y].push(d):i[y]=[i[y],d]:i[y]=d}return i};var o=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}},function(e,t,r){"use strict";function n(e,t){if(e.map)return e.map(t);for(var r=[],n=0;n<e.length;n++)r.push(t(e[n],n));return r}var o=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};e.exports=function(e,t,r,s){return t=t||"&",r=r||"=",null===e&&(e=void 0),"object"==typeof e?n(i(e),function(i){var s=encodeURIComponent(o(i))+r;return u(e[i])?n(e[i],function(e){return s+encodeURIComponent(o(e))}).join(t):s+encodeURIComponent(o(e[i]))}).join(t):s?encodeURIComponent(o(s))+r+encodeURIComponent(o(e)):""};var u=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},i=Object.keys||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.push(r);return t}}])});+ \ No newline at end of file diff --git a/node_modules/youtube-api-v3-search/karma.conf.js b/node_modules/youtube-api-v3-search/karma.conf.js @@ -0,0 +1,93 @@ +// Karma configuration +// Generated on Thu Dec 06 2018 05:35:05 GMT+0200 (Eastern European Standard Time) + +require('dotenv').config(); + + +module.exports = function (config) { + config.set({ + + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['env', 'mocha', 'chai'], + + client: { + env: { + YOUTUBE_KEY: process.env.YOUTUBE_KEY + }, + mocha: { + timeout: 10000 + } + }, + + // list of files / patterns to load in the browser + files: [ + 'src/**/*.js', + 'test/browser/*.js' + ], + + + // list of files / patterns to exclude + exclude: [], + + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + // add webpack as preprocessor + 'src/**/*.js': ['webpack'], + 'test/browser/*.js': ['webpack'] + }, + + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], + + webpackMiddleware: { + // webpack-dev-middleware configuration + // i.e. + noInfo: true, + // and use stats to turn off verbose output + stats: { + // options i.e. + chunks: false + } + }, + + // web server port + port: 9876, + + + // enable / disable colors in the output (reporters and logs) + colors: true, + + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['ChromeHeadless'], + + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, + + // Concurrency level + // how many browser should be started simultaneous + concurrency: Infinity + }) +}+ \ No newline at end of file diff --git a/node_modules/youtube-api-v3-search/package.json b/node_modules/youtube-api-v3-search/package.json @@ -0,0 +1,90 @@ +{ + "_from": "youtube-api-v3-search", + "_id": "youtube-api-v3-search@1.2.1", + "_inBundle": false, + "_integrity": "sha512-CsH8oqX6wZ1b82Xdd4hddx3fSHEIaU85gdYGfQXNbaHOXq5GbaHs7Pro0mEnDt5WzQ5r0eI10gqGeM2mJolJDg==", + "_location": "/youtube-api-v3-search", + "_phantomChildren": {}, + "_requested": { + "type": "tag", + "registry": true, + "raw": "youtube-api-v3-search", + "name": "youtube-api-v3-search", + "escapedName": "youtube-api-v3-search", + "rawSpec": "", + "saveSpec": null, + "fetchSpec": "latest" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/youtube-api-v3-search/-/youtube-api-v3-search-1.2.1.tgz", + "_shasum": "b7b2840d705026812c292ee40df4e9e6b558f662", + "_spec": "youtube-api-v3-search", + "_where": "/home/pi/Documents/buddy", + "author": { + "name": "Ferris Ateniese", + "email": "lionroar07@gmail.com" + }, + "browser": { + "./src/index.js": "./src/browser.js" + }, + "bugs": { + "url": "https://github.com/LionRoar/youtube-api-v3-search/issues" + }, + "bundleDependencies": false, + "dependencies": { + "browser-resolve": "^1.11.3" + }, + "deprecated": false, + "description": " Searching YouTube with the YouTube Data API v3", + "devDependencies": { + "babel-core": "^6.26.0", + "babel-loader": "^7.1.2", + "babel-preset-env": "^1.6.1", + "babel-preset-es2015": "^6.24.1", + "chai": "^4.2.0", + "dotenv": "^5.0.0", + "karma": "^3.1.3", + "karma-chai": "^0.1.0", + "karma-chrome-launcher": "^2.2.0", + "karma-env": "^0.1.0", + "karma-mocha": "^1.3.0", + "karma-webpack": "^3.0.5", + "mocha": "^5.2.0", + "nyc": "^11.4.1", + "webpack": "^3.11.0" + }, + "homepage": "https://github.com/LionRoar/youtube-api-v3-search#readme", + "keywords": [ + "Youtube", + "api", + "v3", + "search", + "ytp", + "api3", + "googleapi", + "search", + "xhr", + "https", + "Promise", + "callback" + ], + "license": "MIT", + "main": "./src/index.js", + "name": "youtube-api-v3-search", + "repository": { + "type": "git", + "url": "git+https://github.com/LionRoar/youtube-api-v3-search.git" + }, + "scripts": { + "build": "webpack", + "test": "npm run test:mocha && npm run test:browser", + "test:browser": "karma start --single-run --browsers ChromeHeadless karma.conf.js", + "test:browser:o": "karma start --single-run --browsers Chrome karma.conf.js", + "test:mocha": "nyc mocha -t 100000", + "test:r:html": "nyc --reporter=html mocha" + }, + "version": "1.2.1" +} diff --git a/node_modules/youtube-api-v3-search/src/browser.js b/node_modules/youtube-api-v3-search/src/browser.js @@ -0,0 +1,6 @@ +const request = require('./request/browser-request'); +const common = require('./common'); +module.exports = function(key , options , cb){ + return common(request , key , options , cb); +} + diff --git a/node_modules/youtube-api-v3-search/src/common.js b/node_modules/youtube-api-v3-search/src/common.js @@ -0,0 +1,22 @@ + +const config = require('./config'); +const querystring = require('querystring'); + + +module.exports = function(request, key, options, cb){ + if(!key && typeof cb === 'function') + return cb(new Error('API Key is required')); + else if(!key) throw new Error('API Key is required'); + fillData(key , options); + const q = querystring.stringify(config.options); + if(typeof cb === 'function') + request(config.URL+q).then(res => cb(null,res)).catch(err => cb(err)); + else + return request(config.URL+q); +} + +function fillData(key , options){ + config.options.key = key; + for(let i in options) + config.options[i] = options[i]; +} diff --git a/node_modules/youtube-api-v3-search/src/index.js b/node_modules/youtube-api-v3-search/src/index.js @@ -0,0 +1,5 @@ +const request = require('./request/node-request'); +const common = require('./common'); +module.exports = function(key , options , cb){ + return common(request , key , options , cb); +} diff --git a/node_modules/youtube-api-v3-search/src/request/browser-request.js b/node_modules/youtube-api-v3-search/src/request/browser-request.js @@ -0,0 +1,24 @@ + + +module.exports = function(url){ + const req = new XMLHttpRequest(); + return new Promise(( resolve , reject )=>{ + req.onreadystatechange = function() { + if (this.readyState == 4){ + if(this.status == 200){ + let response = JSON.parse(this.response); + resolve(response); + }else{ + let err = JSON.parse(this.response); + reject(err); + } + } + } + req.onerror = function(e){ + reject(new Error (this.statusText) ); + } + req.open('GET',url,true); + req.send(null); + }); + +} diff --git a/node_modules/youtube-api-v3-search/src/request/node-request.js b/node_modules/youtube-api-v3-search/src/request/node-request.js @@ -0,0 +1,18 @@ +const https = require('https'); + +module.exports = function(url){ + return new Promise(( resolve ,reject )=>{ + https.get(url, + (res) => { + let data = ''; + res.on('data', (chunk) => { + data += chunk; + }); + res.on('end', () => { + resolve(JSON.parse(data)); + }); + }).on('error', (err) => { + reject(JSON.parse(err)); + }); + }); +} diff --git a/node_modules/youtube-api-v3-search/test/browser/browser.spec.js b/node_modules/youtube-api-v3-search/test/browser/browser.spec.js @@ -0,0 +1,50 @@ +"use strict"; + +const searchYoutube = require('../../src'); +const assert = require('assert'); + +const YOUTUBE_KEY = window.__env.YOUTUBE_KEY; + + describe('Search The Youtube Api', function () { + "use strict"; + //key , options , cb + const options = { + q: 'nodejs', + part: 'snippet', + type: 'video' + }; + + it('should Throw API Key is required! using callback', function (done) { + searchYoutube(null, null, (err, res) => { + assert.equal(err.message, 'API Key is required', 'did not throw API Key is required message') + done(); + }); + }); + + + it('should Throw API Key is required! using Promise', function (done) { + assert.throws(searchYoutube, /API Key is required/, 'did not throw API Key is required message'); + done(); + }); + + it('should return a Response object using a callback', function (done) { + searchYoutube(YOUTUBE_KEY, options, function (err, result) { + //result.kind: 'youtube#searchListResponse' + if (err) done(err); + assert.deepEqual(result.kind, 'youtube#searchListResponse'); + done(); + }); + }); + + it('should return a Response object using a Promise', function (done) { + + searchYoutube(YOUTUBE_KEY, options) + .then(result => { + assert.deepEqual(result.kind, 'youtube#searchListResponse'); + done(); + }) + .catch(err => { + done(err) + }); + }); + }); diff --git a/node_modules/youtube-api-v3-search/test/index.spec.js b/node_modules/youtube-api-v3-search/test/index.spec.js @@ -0,0 +1,49 @@ +const searchYoutube = require('../src'); +const assert = require('assert'); + +require('dotenv').config(); + +describe('Search The Youtube Api',function(){ + //key , options , cb + const options = { + q:'nodejs', + part:'snippet', + type:'video' + } + it('should return a Response object using a callback',function(done){ + searchYoutube(process.env.YOUTUBE_KEY,options,function(err, result){ + //result.kind: 'youtube#searchListResponse' + if(err) done(err); + assert.deepEqual(result.kind,'youtube#searchListResponse'); + done(); + }); + }); + + it('should return a Response object using a Promise',function(done){ + + searchYoutube(process.env.YOUTUBE_KEY,options) + .then(result => { + assert.deepEqual(result.kind,'youtube#searchListResponse'); + done(); + }) + .catch(err => {done(err)}); + }); + + it('should Throw API Key is required! using callback',function(done){ + searchYoutube(null,null,(err,res)=>{ + assert.equal(err.message, 'API Key is required','did not throw API Key is required message') + done(); + }); + }); + + + it('should Throw API Key is required! using Promise',function(done){ + assert.throws(searchYoutube,/API Key is required/,'did not throw API Key is required message'); + done(); + }); + + it('should return a response #Async' , async () => { + let result = await searchYoutube(process.env.YOUTUBE_KEY,options); + assert.deepEqual(result.kind,'youtube#searchListResponse'); + }) +}); diff --git a/node_modules/youtube-api-v3-search/webpack.config.js b/node_modules/youtube-api-v3-search/webpack.config.js @@ -0,0 +1,44 @@ +const path = require('path'); +const webpack = require('webpack'); + +var browserConfig = { + target: 'web', + entry:{ + "youtube-api-v3-search": './src', + "youtube-api-v3-search.min": "./src", + }, + output: { + path: path.resolve(__dirname, 'dist'), + filename: '[name].js', + libraryTarget: 'umd', + library:'searchYoutube' + }, + node: { + process: false + }, + module:{ + loaders:[ + { + test:/\.js$/, + exclude:/(node_modules)/, + loader:'babel-loader', + query:{ + presets:['env'] + } + + }] + }, + plugins: [ + new webpack.optimize.UglifyJsPlugin({ + include: /\.min\.js$/, + minimize: true + }), + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) + }) + ] + +}; + + +module.exports = [ browserConfig ]; diff --git a/node_modules/youtube-api-v3-search/youtube-api-v3-search-1.0.0.tgz b/node_modules/youtube-api-v3-search/youtube-api-v3-search-1.0.0.tgz Binary files differ. diff --git a/package-lock.json b/package-lock.json @@ -14,9 +14,9 @@ "resolved": "https://registry.npmjs.org/@discordjs/form-data/-/form-data-3.0.1.tgz", "integrity": "sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==", "requires": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" + "asynckit": "0.4.0", + "combined-stream": "1.0.8", + "mime-types": "2.1.27" } }, "abort-controller": { @@ -24,7 +24,7 @@ "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", "requires": { - "event-target-shim": "^5.0.0" + "event-target-shim": "5.0.1" } }, "asynckit": { @@ -32,12 +32,20 @@ "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" }, + "browser-resolve": { + "version": "1.11.3", + "resolved": "https://registry.npmjs.org/browser-resolve/-/browser-resolve-1.11.3.tgz", + "integrity": "sha512-exDi1BYWB/6raKHmDTCicQfTkqwN5fioMFV4j8BsfMU4R2DK/QfZfK7kOVkmWCNANf0snkBzqGqAJBao9gZMdQ==", + "requires": { + "resolve": "1.1.7" + } + }, "combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", "requires": { - "delayed-stream": "~1.0.0" + "delayed-stream": "1.0.0" } }, "delayed-stream": { @@ -50,14 +58,14 @@ "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.2.0.tgz", "integrity": "sha512-Ueb/0SOsxXyqwvwFYFe0msMrGqH1OMqpp2Dpbplnlr4MzcRrFWwsBM9gKNZXPVBHWUKiQkwU8AihXBXIvTTSvg==", "requires": { - "@discordjs/collection": "^0.1.5", - "@discordjs/form-data": "^3.0.1", - "abort-controller": "^3.0.0", - "node-fetch": "^2.6.0", - "prism-media": "^1.2.0", - "setimmediate": "^1.0.5", - "tweetnacl": "^1.0.3", - "ws": "^7.2.1" + "@discordjs/collection": "0.1.5", + "@discordjs/form-data": "3.0.1", + "abort-controller": "3.0.0", + "node-fetch": "2.6.1", + "prism-media": "1.2.2", + "setimmediate": "1.0.5", + "tweetnacl": "1.0.3", + "ws": "7.3.0" } }, "event-target-shim": { @@ -88,6 +96,11 @@ "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.2.tgz", "integrity": "sha512-I+nkWY212lJ500jLe4tN9tWO7nRiBAVdMv76P9kffZjYhw20raMlW1HSSvS+MLXC9MmbNZCazMrAr+5jEEgTuw==" }, + "resolve": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz", + "integrity": "sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=" + }, "setimmediate": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", @@ -102,6 +115,14 @@ "version": "7.3.0", "resolved": "https://registry.npmjs.org/ws/-/ws-7.3.0.tgz", "integrity": "sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w==" + }, + "youtube-api-v3-search": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/youtube-api-v3-search/-/youtube-api-v3-search-1.2.1.tgz", + "integrity": "sha512-CsH8oqX6wZ1b82Xdd4hddx3fSHEIaU85gdYGfQXNbaHOXq5GbaHs7Pro0mEnDt5WzQ5r0eI10gqGeM2mJolJDg==", + "requires": { + "browser-resolve": "1.11.3" + } } } } diff --git a/package.json b/package.json @@ -16,6 +16,7 @@ "license": "MIT", "dependencies": { "discord.js": "^12.2.0", - "node-fetch": "^2.6.1" + "node-fetch": "^2.6.1", + "youtube-api-v3-search": "^1.2.1" } }