nx
Version:
50 lines (49 loc) • 2.3 kB
JavaScript
;
// Source map keys are dot-delimited paths into a ProjectConfiguration,
// e.g. `targets.build.inputs.0.projects`.
Object.defineProperty(exports, "__esModule", { value: true });
exports.forEachSourceMapKeyForArray = forEachSourceMapKeyForArray;
exports.readArrayItemSourceInfo = readArrayItemSourceInfo;
exports.readObjectPropertySourceInfo = readObjectPropertySourceInfo;
exports.recordSourceMapInfo = recordSourceMapInfo;
exports.recordSourceMapKeysByIndex = recordSourceMapKeysByIndex;
exports.targetSourceMapKey = targetSourceMapKey;
exports.targetOptionSourceMapKey = targetOptionSourceMapKey;
exports.targetConfigurationsSourceMapKey = targetConfigurationsSourceMapKey;
// Iterates `${prefixKey}.0`, `${prefixKey}.1`, ... for each index of `array`.
function forEachSourceMapKeyForArray(prefixKey, array, callback, startIndex = 0) {
for (let i = startIndex; i < array.length; i++) {
callback(`${prefixKey}.${i}`, i);
}
}
// Reads per-index source info, falling back to the array's top-level entry.
function readArrayItemSourceInfo(sourceMap, arrayKey, itemIndex) {
return sourceMap[`${arrayKey}.${itemIndex}`] ?? sourceMap[arrayKey];
}
// Reads per-property source info, falling back to the object's top-level entry.
function readObjectPropertySourceInfo(sourceMap, objectKey, propertyKey) {
return sourceMap[`${objectKey}.${propertyKey}`] ?? sourceMap[objectKey];
}
function recordSourceMapInfo(sourceMap, key, sourceInfo) {
sourceMap[key] = sourceInfo;
}
// Records the same source info under every `${prefixKey}.${i}` entry.
function recordSourceMapKeysByIndex(sourceMap, prefixKey, array, sourceInfo, startIndex = 0) {
forEachSourceMapKeyForArray(prefixKey, array, (key) => recordSourceMapInfo(sourceMap, key, sourceInfo), startIndex);
}
function targetSourceMapKey(targetName) {
return `targets.${targetName}`;
}
function targetOptionSourceMapKey(targetName, optionKey) {
return `targets.${targetName}.options.${optionKey}`;
}
function targetConfigurationsSourceMapKey(targetName, configurationName, configurationKey) {
let key = `targets.${targetName}.configurations`;
if (configurationName) {
key += `.${configurationName}`;
}
if (configurationKey) {
key += `.${configurationKey}`;
}
return key;
}