(bindings)
| 1985 | // that is built to put symbols in the global namespace rather than |
| 1986 | // in a compartment of Package |
| 1987 | load(bindings) { |
| 1988 | var self = this; |
| 1989 | var ret = new PackageRegistry(); |
| 1990 | |
| 1991 | // XXX This is mostly duplicated from |
| 1992 | // static-assets/server/boot.js, as is Npm.require below. |
| 1993 | // Some way to avoid this? |
| 1994 | var getAsset = function (assets, assetPath, encoding, callback) { |
| 1995 | assetPath = files.convertToStandardPath(assetPath); |
| 1996 | var promise; |
| 1997 | if (! callback) { |
| 1998 | if (! Fiber.current) { |
| 1999 | throw new Error("The synchronous Assets API can " + |
| 2000 | "only be called from within a Fiber."); |
| 2001 | } |
| 2002 | |
| 2003 | promise = new Promise(function (resolve, reject) { |
| 2004 | callback = function (err, res) { |
| 2005 | err ? reject(err) : resolve(res); |
| 2006 | }; |
| 2007 | }); |
| 2008 | } |
| 2009 | |
| 2010 | var _callback = function (err, result) { |
| 2011 | if (result && ! encoding) { |
| 2012 | // Sadly, this copies in Node 0.10. |
| 2013 | result = new Uint8Array(result); |
| 2014 | } |
| 2015 | callback(err, result); |
| 2016 | }; |
| 2017 | |
| 2018 | if (!assets || !_.has(assets, assetPath)) { |
| 2019 | _callback(new Error("Unknown asset: " + assetPath)); |
| 2020 | } else { |
| 2021 | var buffer = assets[assetPath]; |
| 2022 | var result = encoding ? buffer.toString(encoding) : buffer; |
| 2023 | _callback(null, result); |
| 2024 | } |
| 2025 | |
| 2026 | if (promise) { |
| 2027 | return promise.await(); |
| 2028 | } |
| 2029 | }; |
| 2030 | |
| 2031 | const nodeModulesDirsByPackageName = new Map; |
| 2032 | |
| 2033 | _.each(self.jsToLoad, item => { |
| 2034 | _.each(item.nodeModulesDirectories, nmd => { |
| 2035 | if (nmd.local) { |
| 2036 | // Consider only non-local node_modules directories for build |
| 2037 | // plugins. |
| 2038 | return; |
| 2039 | } |
| 2040 | |
| 2041 | let name = nmd.packageName; |
| 2042 | if (name) { |
| 2043 | name = colonConverter.convert(name); |
| 2044 | } |
no test coverage detected