Skip to content

Commit

Permalink
feat!: Define configFiles with an array to prioritize configs
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Mar 16, 2024
1 parent 6bcd381 commit 93bbeea
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 192 deletions.
22 changes: 8 additions & 14 deletions index.js
Expand Up @@ -6,7 +6,6 @@ var extend = require('extend');
var resolve = require('resolve');
var flaggedRespawn = require('flagged-respawn');
var isPlainObject = require('is-plain-object').isPlainObject;
var mapValues = require('object.map');
var fined = require('fined');

var findCwd = require('./lib/find_cwd');
Expand Down Expand Up @@ -62,7 +61,7 @@ Liftoff.prototype.buildEnvironment = function (opts) {
function findAndRegisterLoader(pathObj, defaultObj) {
var found = fined(pathObj, defaultObj);
if (!found) {
return;
return null;
}
if (isPlainObject(found.extension)) {
registerLoader(eventEmitter, found.extension, found.path, cwd);
Expand Down Expand Up @@ -135,20 +134,16 @@ Liftoff.prototype.buildEnvironment = function (opts) {
return config;
}

var configFiles = {};
if (isPlainObject(this.configFiles)) {
configFiles = mapValues(this.configFiles, function (searchPaths, fileStem) {
var defaultObj = { name: fileStem, cwd: cwd, extensions: exts };

var foundPath = arrayFind(searchPaths, function (pathObj) {
return findAndRegisterLoader(pathObj, defaultObj);
});
var configFiles = [];
if (Array.isArray(this.configFiles)) {
configFiles = this.configFiles.map(function (pathObj) {
var defaultObj = { cwd: cwd, extensions: exts };

return foundPath;
return findAndRegisterLoader(pathObj, defaultObj);
});
}

var config = mapValues(configFiles, function (startingLocation) {
var config = configFiles.map(function (startingLocation) {
var defaultConfig = {};
if (!startingLocation) {
return defaultConfig;
Expand All @@ -157,8 +152,7 @@ Liftoff.prototype.buildEnvironment = function (opts) {
return loadConfig(cwd, startingLocation, defaultConfig);
});

var configPathOverride = arrayFind(Object.keys(config), function (key) {
var cfg = config[key];
var configPathOverride = arrayFind(config, function (cfg) {
if (Object.prototype.hasOwnProperty.call(cfg, configName)) {
if (typeof cfg[configName] === "string") {
return cfg[configName];
Expand Down

0 comments on commit 93bbeea

Please sign in to comment.