react-native-builder-bob
Version:
CLI to build JavaScript files for React Native libraries
56 lines (55 loc) • 1.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.loadConfig = void 0;
var _path = require("path");
var _package = require("../../package.json");
const searchPlaces = ['bob.config.mjs', 'bob.config.cjs', 'bob.config.js', 'package.json'];
const loadConfig = root => {
for (const filename of searchPlaces) {
const result = requireConfig(root, filename);
if (filename === 'package.json' && result != null) {
if (result.content[_package.name] != null) {
return {
filepath: result.filepath,
config: result.content[_package.name]
};
}
}
if (result != null) {
const content = result.content;
if (content?.__esModule) {
return {
filepath: result.filepath,
config: content.default
};
}
return {
filepath: result.filepath,
config: content
};
}
}
return undefined;
};
exports.loadConfig = loadConfig;
const requireConfig = (root, filename) => {
const filepath = (0, _path.join)(root, filename);
try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const content = require(filepath);
return {
filepath,
content
};
} catch (e) {
if (typeof e === 'object' && e != null && 'code' in e && e.code === 'MODULE_NOT_FOUND') {
// We expect that some of the config files won't exist
// So we just return undefined in that case
return undefined;
}
throw e;
}
};
//# sourceMappingURL=loadConfig.js.map