UNPKG

@embroider/macros

Version:

Standardized build-time macros for ember apps.

38 lines 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = getConfig; function getConfig(node, userConfigs, // when we're running in traditional ember-cli, baseDir is configured and we // do all lookups relative to that (single) package. But when we're running in // embroider stage3 we process all packages simultaneously, so baseDir is left // unconfigured and moduleName will be the full path to the source file. baseDir, moduleName, own, packageCache) { let targetConfig; let params = node.params.slice(); if (!params.every((p) => p.type === 'StringLiteral')) { throw new Error(`all arguments to ${own ? 'macroGetOwnConfig' : 'macroGetConfig'} must be string literals`); } let us = packageCache.ownerOfFile(baseDir || moduleName); if (!us) { return undefined; } if (own) { us = packageCache.original(us); targetConfig = userConfigs[us.root]; } else { let packageName = params.shift(); if (!packageName) { throw new Error(`macroGetConfig requires at least one argument`); } let targetPkg = packageCache.resolve(packageName.value, us); targetPkg = packageCache.original(targetPkg); targetConfig = userConfigs[targetPkg.root]; } while (typeof targetConfig === 'object' && targetConfig && params.length > 0) { let key = params.shift(); targetConfig = targetConfig[key.value]; } return targetConfig; } //# sourceMappingURL=get-config.js.map