Skip to content

Commit

Permalink
refactor dist.ini parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
haarg committed Sep 14, 2024
1 parent 1c5a9ce commit 320d951
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
26 changes: 17 additions & 9 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22555,23 +22555,32 @@ var prefixes = {
"=": "",
"@": "Dist::Zilla::PluginBundle::",
"%": "Dist::Zilla::Stash::",
"": "Dist::Zilla::Plugin::",
"_": "Dist::Zilla"
"": "Dist::Zilla::Plugin::"
};
var prefixRx = /^(?:_$|[=@%]|)/;
var quoteMeta = (k) => k.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
var prefixRx = new RegExp("^(?:" + Object.keys(prefixes).map(quoteMeta).join("|") + ")");
var expandConfigPackageName = (section) => section.replace(prefixRx, (prefix) => prefixes[prefix]);
var parseDistINI = async (content) => {
const prereqs = [];
const rootSection = {
section: "_",
pack: "Dist::Zilla",
settings: {}
};
const sections = [rootSection];
let currentSettings = rootSection.settings;
const sections = [rootSection];
for (const { section, comment, key, value } of peg$parse2(await content)) {
if (section) {
const [, plugin, name] = section.match(/^([^\/]*)(?:\/(.*))?$/);
const pack = expandConfigPackageName(plugin);
currentSettings = {};
sections.push({ section, settings: currentSettings });
sections.push({
section,
plugin,
pack,
name,
settings: currentSettings
});
} else if (comment) {
const res = comment.match(/^\s*authordep\s*(\S+)\s*(?:=\s*([^;]+))?\s*/);
if (res !== null) {
Expand All @@ -22592,13 +22601,12 @@ var parseDistINI = async (content) => {
version: ">=0"
});
}
for (const { section, settings } of sections) {
const plugin = expandConfigPackageName(section.replace(/\s*\/.*$/, ""));
for (const { section, pack, settings } of sections) {
prereqs.push({
prereq: plugin,
prereq: pack,
version: fullVersion(settings[":version"] || "0")
});
if (plugin === "Dist::Zilla::PluginBundle::Filter" || plugin === "Dist::Zilla::PluginBundle::ConfigSlicer") {
if (pack === "Dist::Zilla::PluginBundle::Filter" || pack === "Dist::Zilla::PluginBundle::ConfigSlicer") {
prereqs.push({
prereq: expandConfigPackageName(settings["-bundle"]),
version: fullVersion(settings["-version"] || "0")
Expand Down
27 changes: 18 additions & 9 deletions src/parser/distini.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const prefixes = {
'@': 'Dist::Zilla::PluginBundle::',
'%': 'Dist::Zilla::Stash::',
'': 'Dist::Zilla::Plugin::',
'_': 'Dist::Zilla',
};

const prefixRx = /^(?:_$|[=@%]|)/;
const quoteMeta = k => k.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const prefixRx = new RegExp('^(?:' + Object.keys(prefixes).map(quoteMeta).join('|') + ')');

const expandConfigPackageName = section =>
section.replace(prefixRx, prefix => prefixes[prefix]);
Expand All @@ -19,15 +19,25 @@ export const parseDistINI = async (content) => {

const rootSection = {
section: '_',
pack: 'Dist::Zilla',
settings: {},
};
const sections = [rootSection];
let currentSettings = rootSection.settings;
const sections = [rootSection];

for (const { section, comment, key, value } of parse(await content)) {
if (section) {
const [, plugin, name] = section.match(/^([^\/]*)(?:\/(.*))?$/);
const pack = expandConfigPackageName(plugin);

currentSettings = {};
sections.push({ section, settings: currentSettings });
sections.push({
section,
plugin,
pack,
name,
settings: currentSettings,
});
}
else if (comment) {
const res = comment.match(/^\s*authordep\s*(\S+)\s*(?:=\s*([^;]+))?\s*/);
Expand All @@ -52,16 +62,15 @@ export const parseDistINI = async (content) => {
});
}

for (const { section, settings } of sections) {
const plugin = expandConfigPackageName(section.replace(/\s*\/.*$/, ''));
for (const { section, pack, settings } of sections) {
prereqs.push({
prereq: plugin,
prereq: pack,
version: fullVersion(settings[':version'] || '0'),
});

if (
plugin === 'Dist::Zilla::PluginBundle::Filter'
|| plugin === 'Dist::Zilla::PluginBundle::ConfigSlicer'
pack === 'Dist::Zilla::PluginBundle::Filter'
|| pack === 'Dist::Zilla::PluginBundle::ConfigSlicer'
) {
prereqs.push({
prereq: expandConfigPackageName(settings['-bundle']),
Expand Down

0 comments on commit 320d951

Please sign in to comment.