zephyr-agent
Version:
Zephyr plugin agent
220 lines (219 loc) • 9.36 kB
JavaScript
;
var __webpack_require__ = {};
(()=>{
__webpack_require__.d = (exports1, getters, values)=>{
var define = (defs, kind)=>{
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
enumerable: true,
[kind]: defs[key]
});
};
define(getters, "get");
define(values, "value");
};
})();
(()=>{
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
__webpack_require__.r = (exports1)=>{
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
value: 'Module'
});
Object.defineProperty(exports1, '__esModule', {
value: true
});
};
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
defineConfig: ()=>defineConfig,
getZephyrConfig: ()=>getZephyrConfig,
mergeRemoteDependencies: ()=>mergeRemoteDependencies,
resolveZephyrContextDirectory: ()=>resolveZephyrContextDirectory
});
const external_node_fs_namespaceObject = require("node:fs");
const external_node_module_namespaceObject = require("node:module");
const external_node_path_namespaceObject = require("node:path");
const external_jiti_namespaceObject = require("jiti");
const index_js_namespaceObject = require("../errors/index.js");
const redaction_js_namespaceObject = require("../security/redaction.js");
const CONFIG_FILE_NAMES = [
'zephyr.config.ts',
'zephyr.config.mts',
'zephyr.config.cts',
'zephyr.config.js',
'zephyr.config.mjs',
'zephyr.config.cjs'
];
const CONFIG_FIELDS = new Set([
'org',
'project',
'appName',
'remoteDependencies',
'dependencyUrlMode'
]);
const CONFIG_ERROR_MAX_LENGTH = 1000;
const configCache = new Map();
function defineConfig(config) {
return config;
}
function resolveZephyrContextDirectory(context) {
const startingPath = context?.trim() || process.cwd();
const absolutePath = (0, external_node_path_namespaceObject.isAbsolute)(startingPath) ? startingPath : (0, external_node_path_namespaceObject.resolve)(process.cwd(), startingPath);
try {
return (0, external_node_fs_namespaceObject.statSync)(absolutePath).isFile() ? (0, external_node_path_namespaceObject.dirname)(absolutePath) : absolutePath;
} catch {
return absolutePath;
}
}
function getZephyrConfig(context) {
const configPath = findConfigPath(resolveZephyrContextDirectory(context));
if (!configPath) return Object.freeze({});
const canonicalPath = getCanonicalConfigPath(configPath);
const fingerprint = getConfigFingerprint(canonicalPath);
const cached = configCache.get(canonicalPath);
if (cached?.fingerprint === fingerprint) return cached.config;
const config = loadConfigModule(canonicalPath);
configCache.set(canonicalPath, {
fingerprint,
config
});
return config;
}
function mergeRemoteDependencies(packageDependencies, config) {
if (!packageDependencies && !config.remoteDependencies) return;
return {
...packageDependencies,
...config.remoteDependencies
};
}
function findConfigPath(startingDirectory) {
let directory = startingDirectory;
while(true){
const matches = CONFIG_FILE_NAMES.map((fileName)=>(0, external_node_path_namespaceObject.join)(directory, fileName)).filter(isFile);
if (matches.length > 1) throwConfigError(directory, `multiple config files found: ${matches.map((file)=>(0, external_node_path_namespaceObject.basename)(file)).join(', ')}`);
if (matches[0]) return matches[0];
const parent = (0, external_node_path_namespaceObject.dirname)(directory);
if (parent === directory) return;
directory = parent;
}
}
function isFile(filePath) {
try {
return (0, external_node_fs_namespaceObject.existsSync)(filePath) && (0, external_node_fs_namespaceObject.statSync)(filePath).isFile();
} catch {
return false;
}
}
function getCanonicalConfigPath(configPath) {
try {
return (0, external_node_fs_namespaceObject.realpathSync)(configPath);
} catch (error) {
throwConfigError(configPath, `failed to resolve config path: ${safeConfigErrorMessage(error)}`);
}
}
function getConfigFingerprint(configPath) {
try {
const stats = (0, external_node_fs_namespaceObject.statSync)(configPath);
return `${stats.mtimeMs}:${stats.size}`;
} catch (error) {
throwConfigError(configPath, `failed to inspect config: ${safeConfigErrorMessage(error)}`);
}
}
function loadConfigModule(configPath) {
try {
const requireFromConfig = (0, external_node_module_namespaceObject.createRequire)(configPath);
delete requireFromConfig.cache[configPath];
const jiti = (0, external_jiti_namespaceObject.createJiti)(configPath, {
interopDefault: true,
moduleCache: false
});
const loaded = jiti(configPath);
const config = isObject(loaded) && 'default' in loaded ? loaded['default'] : loaded;
return parseConfig(config, configPath);
} catch (error) {
if (index_js_namespaceObject.ZephyrError.is(error, index_js_namespaceObject.ZeErrors.ERR_ZEPHYR_CONFIG_NOT_VALID)) throw error;
throwConfigError(configPath, `failed to load config: ${safeConfigErrorMessage(error)}`);
}
}
function parseConfig(value, configPath) {
if (!isObject(value)) throwConfigError(configPath, 'default export must be an object');
const unknownFields = Object.keys(value).filter((field)=>!CONFIG_FIELDS.has(field));
if (unknownFields.length > 0) throwConfigError(configPath, `unknown field${1 === unknownFields.length ? '' : 's'}: ${unknownFields.join(', ')}`);
const org = readOptionalString(value['org'], 'org', configPath);
const project = readOptionalString(value['project'], 'project', configPath);
const appName = readOptionalString(value['appName'], 'appName', configPath);
const remoteDependencies = readRemoteDependencies(value['remoteDependencies'], configPath);
const dependencyUrlMode = readDependencyUrlMode(value['dependencyUrlMode'], configPath);
return Object.freeze({
...org ? {
org
} : {},
...project ? {
project
} : {},
...appName ? {
appName
} : {},
...remoteDependencies ? {
remoteDependencies
} : {},
...dependencyUrlMode ? {
dependencyUrlMode
} : {}
});
}
function readDependencyUrlMode(value, configPath) {
if (void 0 === value) return;
if ('selector' !== value && 'version' !== value) throwConfigError(configPath, 'dependencyUrlMode must be either "selector" or "version"');
return value;
}
function readOptionalString(value, field, configPath) {
if (void 0 === value) return;
if ('string' != typeof value) throwConfigError(configPath, `${field} must be a string`);
const normalized = value.trim();
if (!normalized) throwConfigError(configPath, `${field} must not be empty`);
return normalized;
}
function readRemoteDependencies(value, configPath) {
if (void 0 === value) return;
if (!isObject(value)) throwConfigError(configPath, 'remoteDependencies must be an object with string values');
const dependencies = {};
for (const [name, reference] of Object.entries(value)){
if (!name.trim()) throwConfigError(configPath, 'remoteDependencies keys must not be empty');
if ('string' != typeof reference) throwConfigError(configPath, `remoteDependencies.${name} must be a string`);
if (!reference.trim()) throwConfigError(configPath, `remoteDependencies.${name} must not be empty`);
dependencies[name] = reference.trim();
}
return Object.freeze(dependencies);
}
function isObject(value) {
return null !== value && 'object' == typeof value && !Array.isArray(value);
}
function safeConfigErrorMessage(error) {
const rawMessage = error instanceof Error ? error.message : String(error);
const redacted = (0, redaction_js_namespaceObject.redactString)(rawMessage);
if (redacted.length <= CONFIG_ERROR_MAX_LENGTH) return redacted;
return `${redacted.slice(0, CONFIG_ERROR_MAX_LENGTH)}…[truncated]`;
}
function throwConfigError(configPath, message) {
throw new index_js_namespaceObject.ZephyrError(index_js_namespaceObject.ZeErrors.ERR_ZEPHYR_CONFIG_NOT_VALID, {
message: `at ${configPath}: ${safeConfigErrorMessage(message)}`
});
}
exports.defineConfig = __webpack_exports__.defineConfig;
exports.getZephyrConfig = __webpack_exports__.getZephyrConfig;
exports.mergeRemoteDependencies = __webpack_exports__.mergeRemoteDependencies;
exports.resolveZephyrContextDirectory = __webpack_exports__.resolveZephyrContextDirectory;
for(var __rspack_i in __webpack_exports__)if (-1 === [
"defineConfig",
"getZephyrConfig",
"mergeRemoteDependencies",
"resolveZephyrContextDirectory"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
value: true
});
//# sourceMappingURL=zephyr-config.js.map