* @memberOf PackageAPI * @instance * @summary Depend on package `packagename`. * @locus package.js * @param {String|String[]} packageNames Packages being depended on. * Package names may be suffixed with an @version tag. * * In general, you must specify a package's version (e.g.
(names, arch, options)
| 174 | * circular dependencies. |
| 175 | */ |
| 176 | use(names, arch, options) { |
| 177 | var self = this; |
| 178 | |
| 179 | // Support `api.use(package, {weak: true})` without arch. |
| 180 | if (_.isObject(arch) && !_.isArray(arch) && !options) { |
| 181 | options = arch; |
| 182 | arch = null; |
| 183 | } |
| 184 | options = options || {}; |
| 185 | |
| 186 | names = toArray(names); |
| 187 | arch = toArchArray(arch); |
| 188 | |
| 189 | // A normal dependency creates an ordering constraint and a "if I'm |
| 190 | // used, use that" constraint. Unordered dependencies lack the |
| 191 | // former; weak dependencies lack the latter. There's no point to a |
| 192 | // dependency that lacks both! |
| 193 | if (options.unordered && options.weak) { |
| 194 | buildmessage.error( |
| 195 | "A dependency may not be both unordered and weak.", |
| 196 | { useMyCaller: true }); |
| 197 | // recover by ignoring |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | // using for loop rather than underscore to help with useMyCaller |
| 202 | for (var i = 0; i < names.length; ++i) { |
| 203 | var name = names[i]; |
| 204 | try { |
| 205 | var parsed = utils.parsePackageConstraint(name); |
| 206 | } catch (e) { |
| 207 | if (!e.versionParserError) { |
| 208 | throw e; |
| 209 | } |
| 210 | buildmessage.error(e.message, {useMyCaller: true}); |
| 211 | // recover by ignoring |
| 212 | continue; |
| 213 | } |
| 214 | |
| 215 | forAllMatchingArchs(arch, function (a) { |
| 216 | self.uses[a].push({ |
| 217 | package: parsed.package, |
| 218 | constraint: parsed.constraintString, |
| 219 | unordered: options.unordered || false, |
| 220 | weak: options.weak || false |
| 221 | }); |
| 222 | }); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | // Called when this package wants packages using it to also use |
| 227 | // another package. eg, for umbrella packages which want packages |
no test coverage detected