mirror of
https://github.com/nodejs/node.git
synced 2024-11-29 23:16:30 +01:00
1f5261b7c8
Even though the doc tool supports version arrays in theory, it fails to sort them properly causing the tool to crash. PR-URL: https://github.com/nodejs/node/pull/22766 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
47 lines
1.0 KiB
JavaScript
47 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
const yaml =
|
|
require(`${__dirname}/../node_modules/eslint/node_modules/js-yaml`);
|
|
|
|
function isYAMLBlock(text) {
|
|
return /^<!-- YAML/.test(text);
|
|
}
|
|
|
|
function arrify(value) {
|
|
return Array.isArray(value) ? value : [value];
|
|
}
|
|
|
|
function extractAndParseYAML(text) {
|
|
text = text.trim()
|
|
.replace(/^<!-- YAML/, '')
|
|
.replace(/-->$/, '');
|
|
|
|
// js-yaml.safeLoad() throws on error.
|
|
const meta = yaml.safeLoad(text);
|
|
|
|
if (meta.added) {
|
|
// Since semver-minors can trickle down to previous major versions,
|
|
// features may have been added in multiple versions.
|
|
meta.added = arrify(meta.added);
|
|
}
|
|
|
|
if (meta.napiVersion) {
|
|
meta.napiVersion = arrify(meta.napiVersion);
|
|
}
|
|
|
|
if (meta.deprecated) {
|
|
// Treat deprecated like added for consistency.
|
|
meta.deprecated = arrify(meta.deprecated);
|
|
}
|
|
|
|
if (meta.removed) {
|
|
meta.removed = arrify(meta.removed);
|
|
}
|
|
|
|
meta.changes = meta.changes || [];
|
|
|
|
return meta;
|
|
}
|
|
|
|
module.exports = { arrify, isYAMLBlock, extractAndParseYAML };
|