@politty/loculus 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +65 -2
  3. package/bin/cli.mjs +3 -0
  4. package/dist/agent.d.ts +2 -0
  5. package/dist/agent.js +1 -0
  6. package/dist/argv-parser-BRSUT6IV.js +1 -0
  7. package/dist/cli-main-CoQp6CjD.js +1 -0
  8. package/dist/cli-main-D4rJTFFd.js +2 -0
  9. package/dist/cli-run-DABESHM4.js +1 -0
  10. package/dist/cli.d.ts +1 -0
  11. package/dist/cli.js +2 -0
  12. package/dist/command-BXsTrIgI.js +1 -0
  13. package/dist/compile-cache-6u9hgeWu.js +1 -0
  14. package/dist/compile-cache.d.ts +80 -0
  15. package/dist/compile-cache.js +1 -0
  16. package/dist/completion-BGidlN43.js +1 -0
  17. package/dist/completion-Cyw4RN-l.js +116 -0
  18. package/dist/completion.d.ts +333 -0
  19. package/dist/completion.js +1 -0
  20. package/dist/detect-agent-D7KSeWMh.js +3 -0
  21. package/dist/detect-agent-EHaSY1KW.d.ts +49 -0
  22. package/dist/docs.d.ts +770 -0
  23. package/dist/docs.js +94 -0
  24. package/dist/dynamic-BbeRdUqR.js +1 -0
  25. package/dist/dynamic-Hg5BDHzz.js +6 -0
  26. package/dist/import-meta-resolve-DgKm4LYW.js +3 -0
  27. package/dist/index.d.ts +1088 -0
  28. package/dist/index.js +1 -0
  29. package/dist/log-collector-uhRWYT-z.js +1 -0
  30. package/dist/logger-CoeDrmRr.js +1 -0
  31. package/dist/prompt-clack.d.ts +15 -0
  32. package/dist/prompt-clack.js +1 -0
  33. package/dist/prompt-fl79dWPz.js +1 -0
  34. package/dist/prompt-inquirer.d.ts +15 -0
  35. package/dist/prompt-inquirer.js +1 -0
  36. package/dist/prompt.d.ts +106 -0
  37. package/dist/prompt.js +1 -0
  38. package/dist/register-Ceh-HlVN.js +1 -0
  39. package/dist/registry-BEz5iex_.js +1 -0
  40. package/dist/runner-D-n1xa2K.js +33 -0
  41. package/dist/runner-nPWQnqQ3.js +1 -0
  42. package/dist/schema--6eHVfwR.js +1 -0
  43. package/dist/schema-extractor-DFawzmtj.js +1 -0
  44. package/dist/skill.d.ts +581 -0
  45. package/dist/skill.js +2 -0
  46. package/dist/subcommand-router-iqmWGZyU.js +2 -0
  47. package/dist/types-Dhar1ua6.d.ts +1125 -0
  48. package/dist/with-completion-command-CARvhYvv.d.ts +384 -0
  49. package/dist/with-completion-command-yg7HB6Zu.js +3 -0
  50. package/package.json +101 -3
package/dist/docs.js ADDED
@@ -0,0 +1,94 @@
1
+ import{t as e}from"./registry-BEz5iex_.js";import{c as t,n,o as r,r as i,s as a,t as o}from"./schema-extractor-DFawzmtj.js";import{r as s}from"./subcommand-router-iqmWGZyU.js";import{t as c}from"./log-collector-uhRWYT-z.js";import"./register-Ceh-HlVN.js";import*as l from"node:fs";import*as u from"node:path";import d from"node:path";import{isDeepStrictEqual as f}from"node:util";const p=[`option`,`alias`,`description`,`required`,`default`];function m(e){return`(↔ \`--${e.cliName}\`)`}function h(e){return e.placeholder??e.cliName.toUpperCase().replace(/-/g,`_`)}function g(e){return e.type===`boolean`?`--${e.cliName}`:`--${e.cliName} <${h(e)}>`}function _(e){let t=g(e),n=[];if(e.alias)for(let t of e.alias)n.push(t.length===1?`-${t}`:`--${t}`);let r=e.type===`boolean`&&!!e.negationDisplay,i=r&&!e.negationDescription?`--${e.negationDisplay}`:void 0,a=r&&e.negationDescription?{flag:`--${e.negationDisplay}`,description:e.negationDescription,relationMarker:m(e),required:e.required}:void 0;return{longFlag:t,aliases:n,inlineNegation:i,description:e.description,required:e.required,hasDefault:e.defaultValue!==void 0,defaultValue:e.defaultValue,env:e.env,negationRow:a}}function v(e){return e.map(_)}function y(e){return e.replace(/\r?\n/g,`<br>`)}function b(e){return y(e.replace(/\|/g,`\\|`))}function x(e){return`\`${e}\``}function S(e){return e.hasDefault?`\`${JSON.stringify(e.defaultValue)}\``:`-`}function C(e){return e?Array.isArray(e)?e.map(e=>`\`${e}\``).join(`, `):`\`${e}\``:`-`}function w(e){return e?` [env: ${(Array.isArray(e)?e:[e]).join(`, `)}]`:``}const T={option:{header:`Option`,separator:`--------`},alias:{header:`Alias`,separator:`-------`},description:{header:`Description`,separator:`-------------`},required:{header:`Required`,separator:`----------`},default:{header:`Default`,separator:`---------`},env:{header:`Env`,separator:`-----`}};function E(e,t){switch(t){case`option`:{let t=x(e.longFlag);return e.inlineNegation?`${t} / ${x(e.inlineNegation)}`:t}case`alias`:return e.aliases.length>0?e.aliases.map(x).join(`, `):`-`;case`description`:return b(e.description??``);case`required`:return e.required?`Yes`:`No`;case`default`:return S(e);case`env`:return C(e.env)}}function D(e,t){switch(t){case`option`:return x(e.flag);case`description`:return`${b(e.description)} ${e.relationMarker}`;case`required`:return e.required?`Yes`:`No`;case`alias`:case`default`:case`env`:return`-`}}function O(e,t){if(e.length===0)return``;let n=t??(e.some(e=>e.env)?[...p,`env`]:p),r=[];r.push(`| ${n.map(e=>T[e].header).join(` | `)} |`),r.push(`|${n.map(e=>T[e].separator).join(`|`)}|`);for(let t of e)r.push(`| ${n.map(e=>E(t,e)).join(` | `)} |`),t.negationRow&&r.push(`| ${n.map(e=>D(t.negationRow,e)).join(` | `)} |`);return r.join(`
2
+ `)}function k(e){if(e.length===0)return``;let t=[];for(let n of e){let e=n.aliases.filter(e=>!e.startsWith(`--`)),r=n.aliases.filter(e=>e.startsWith(`--`)),i=[...e,n.longFlag,...r].map(x).join(`, `);n.inlineNegation&&(i+=` / ${x(n.inlineNegation)}`);let a=n.description?` - ${y(n.description)}`:``,o=n.required?` (required)`:``,s=n.hasDefault?` (default: ${JSON.stringify(n.defaultValue)})`:``,c=w(n.env);t.push(`- ${i}${a}${o}${s}${c}`),n.negationRow&&t.push(`- ${x(n.negationRow.flag)} - ${y(n.negationRow.description)} ${n.negationRow.relationMarker}`)}return t.join(`
3
+ `)}const A=`POLITTY_DOCS_UPDATE`,j=`POLITTY_DOCS_DOCTOR`,M=[`heading`,`description`,`usage`,`arguments`,`options`,`global-options-link`,`subcommands`,`examples`,`notes`],N=`politty:command`;function P(e,t){return`<!-- ${N}:${t}:${e}:start -->`}function F(e,t){return`<!-- ${N}:${t}:${e}:end -->`}const I=`politty:global-options`;function L(){return`<!-- ${I}:start -->`}function ee(){return`<!-- ${I}:end -->`}const R=`politty:root-header`;function te(){return`<!-- ${R}:start -->`}function ne(){return`<!-- ${R}:end -->`}const z=`politty:root-footer`;function re(){return`<!-- ${z}:start -->`}function ie(){return`<!-- ${z}:end -->`}const B=`politty:index`;function V(e){return`<!-- ${B}:${e}:start -->`}function ae(e){return`<!-- ${B}:${e}:end -->`}function oe(e){return y(e.replace(/\|/g,`\\|`))}function se(e){let t=[e.fullCommandPath];e.options.length>0&&t.push(`[options]`),e.subCommands.length>0&&(e.command.run||e.command.defaultSubCommand?t.push(`[command]`):t.push(`<command>`));for(let n of e.positionalArgs)n.required?t.push(`<${n.name}>`):t.push(`[${n.name}]`);return t.join(` `)}function ce(e){return de(e,Se)}function le(e){return e.named?`\`${e.name}\`, \`${g(e)}\``:`\`${e.name}\``}function ue(e){return de(e,Ce)}function de(e,t,n=e.positionalArgs){let r=fe(e.extracted),i=r.length>0?o(r):void 0,a=new Set(n.map(e=>e.name)),s=[],c=n.filter(e=>i===void 0||i.has(e.name));c.length>0&&s.push(t(c));for(let e of r){let n=e.fields.filter(e=>e.positional&&!i?.has(e.name)&&a.has(e.name));n.length>0&&s.push(`${e.label}\n\n${t(n)}`)}return s.join(`
4
+
5
+ `)}function fe(e){if(e?.schemaType===`discriminatedUnion`&&e.discriminator){let t=e.discriminator;return(e.variants??[]).map(e=>({label:pe(t,e),fields:e.fields}))}return(e?.schemaType===`union`||e?.schemaType===`xor`)&&e.unionOptions?e.unionOptions.map((e,t)=>({label:me(e,t),fields:e.fields})):[]}function pe(e,t){let n=t.description?` ${t.description}`:``;return`**When \`${e}\` = \`${t.discriminatorValue}\`:**${n}`}function me(e,t){return`**${e.description??`Variant ${t+1}`}:**`}function he(e){return O(v(e.options))}function ge(e){return k(v(e.options))}function _e(e){return e.join(`-`).toLowerCase()}function ve(e,t){let n=e.replace(/\\/g,`/`),r=t.replace(/\\/g,`/`);return d.posix.relative(d.posix.dirname(n),r)}function ye(e,t=!0){return we(e.subCommands,e,t)}function H(e){return O(v(e))}function be(e,t=`table`){let n=e.unionOptions??[];if(n.length===0)return``;let r=[],i=o(n),a=e.fields.filter(e=>i.has(e.name)&&!e.positional);a.length>0&&r.push(t===`table`?H(a):U(a)),r.push(`> One of the following option groups is required:`);for(let e=0;e<n.length;e++){let a=n[e];if(!a)continue;let o=a.fields.filter(e=>!i.has(e.name)&&!e.positional),s=me(a,e);if(o.length===0){r.push(`${s}\n\n_no options_`);continue}let c=t===`table`?H(o):U(o);r.push(`${s}\n\n${c}`)}return r.join(`
6
+
7
+ `)}function xe(e,t=`table`){let n=e.discriminator,i=e.variants??[];if(!n||i.length===0)return``;let a=[],s=o(i,n),c=r(e,n),l=i.map(e=>e.discriminatorValue).join(`\\|`),u=[];c&&u.push({...c,placeholder:l});for(let t of s){let n=e.fields.find(e=>e.name===t);n&&!n.positional&&u.push(n)}u.length>0&&a.push(t===`table`?H(u):U(u));for(let e of i){let r=e.fields.filter(e=>e.name!==n&&!s.has(e.name)&&!e.positional);if(r.length===0)continue;let i=pe(n,e),o=t===`table`?H(r):U(r);a.push(`${i}\n\n${o}`)}return a.join(`
8
+
9
+ `)}function U(e){return k(v(e))}function Se(e){if(e.length===0)return``;let t=[];t.push(`| Argument | Description | Required |`),t.push(`|----------|-------------|----------|`);for(let n of e){let e=oe(n.description??``),r=n.required?`Yes`:`No`;t.push(`| ${le(n)} | ${e} | ${r} |`)}return t.join(`
10
+ `)}function Ce(e){if(e.length===0)return``;let t=[];for(let n of e){let e=n.required?`(required)`:`(optional)`,r=n.description?` - ${y(n.description)}`:``;t.push(`- ${le(n)}${r} ${e}`)}return t.join(`
11
+ `)}function we(e,t,n=!0){if(e.length===0)return``;let r=e.some(e=>e.aliases&&e.aliases.length>0),i=[];r?(i.push(`| Command | Aliases | Description |`),i.push(`|---------|---------|-------------|`)):(i.push(`| Command | Description |`),i.push(`|---------|-------------|`));let a=t.filePath,o=t.fileMap;for(let t of e){let e=t.fullPath.join(` `),s=oe(t.description??``),c=t.fullPath.join(` `),l=r?t.aliases&&t.aliases.length>0?t.aliases.map(e=>`\`${oe(e)}\``).join(`, `):`-`:``,u;if(n){let n=_e(t.fullPath),r=o!==void 0&&Object.prototype.hasOwnProperty.call(o,c),i=r?o[c]:void 0;u=a&&i&&a!==i?`[\`${e}\`](${ve(a,i)}#${n})`:o&&!r?`\`${e}\``:`[\`${e}\`](#${n})`}else u=`\`${e}\``;r?i.push(`| ${u} | ${l} | ${s} |`):i.push(`| ${u} | ${s} |`)}return i.join(`
12
+ `)}function Te(e,t,n){if(e.length===0)return``;let r=n?.showOutput??!0,i=n?.commandPrefix?`${n.commandPrefix} `:``,a=[];for(let n=0;n<e.length;n++){let o=e[n];if(!o)continue;let s=t?.[n];a.push(`**${o.desc}**`),a.push(``),a.push("```bash"),a.push(`$ ${i}${o.cmd}`),r&&(s?(s.stdout&&a.push(s.stdout),s.stderr&&a.push(`[stderr] ${s.stderr}`)):o.output&&a.push(o.output)),a.push("```"),a.push(``)}for(;a.length>0&&a[a.length-1]===``;)a.pop();return a.join(`
13
+ `)}function Ee(e,t,n){return`${P(e,t)}\n${n}\n${F(e,t)}`}function De(e){return!e.hasGlobalOptions||e.commandPath===``?null:`See [Global Options](${e.rootDocPath&&e.filePath&&e.filePath!==e.rootDocPath?`${ve(e.filePath,e.rootDocPath)}#global-options`:`#global-options`}) for options available to all commands.`}function W(e={}){let{headingLevel:t=1,optionStyle:n=`table`,generateAnchors:r=!0,includeSubcommandDetails:i=!0,markerless:a=!1,renderDescription:o,renderUsage:s,renderArguments:c,renderOptions:l,renderSubcommands:u,renderNotes:d,renderFooter:f,renderExamples:p}=e,m=a?(e,t,n)=>n:Ee;return e=>{let a=[],h=e.commandPath,g=Math.min(t+(e.depth-1),6),_=`#`.repeat(g),v=e.commandPath||e.name;a.push(m(`heading`,h,`${_} ${v}`));{let t=[];if(e.description&&t.push(e.description),e.aliases&&e.aliases.length>0&&t.push(`**Aliases:** ${e.aliases.map(e=>`\`${e}\``).join(`, `)}`),t.length>0){let n={content:t.join(`
14
+
15
+ `),heading:``,info:e},r=o?o(n):n.content;r&&a.push(m(`description`,h,r))}}{let t={content:`**Usage**\n\n\`\`\`\n${se(e)}\n\`\`\``,heading:`**Usage**`,info:e},n=s?s(t):t.content;n&&a.push(m(`usage`,h,n))}if(e.positionalArgs.length>0){let t=(t,r)=>{let i=r?.style??n,a=r?.withHeading??!0,o=i===`table`?Se:Ce,s=fe(e.extracted).length>0?de(e,o,t):o(t);return a?`**Arguments**\n\n${s}`:s},r={args:e.positionalArgs,render:t,heading:`**Arguments**`,info:e},i=c?c(r):t(r.args);i&&a.push(m(`arguments`,h,i))}if(e.options.length>0){let t=(t,r)=>{let i=r?.style??n,a=r?.withHeading??!0,o=e.extracted,s;return s=o&&(o.schemaType===`union`||o.schemaType===`xor`)&&o.unionOptions?be(o,i):o&&o.schemaType===`discriminatedUnion`&&o.discriminator?xe(o,i):i===`table`?H(t):U(t),a?`**Options**\n\n${s}`:s},r={options:e.options,render:t,heading:`**Options**`,info:e},i=l?l(r):t(r.options);i&&a.push(m(`options`,h,i))}{let t=De(e);t&&a.push(m(`global-options-link`,h,t))}if(e.subCommands.length>0){let t=r&&i,n=(n,r)=>{let i=r?.generateAnchors??t,a=r?.withHeading??!0,o=we(n,e,i);return a?`**Commands**\n\n${o}`:o},o={subcommands:e.subCommands,render:n,heading:`**Commands**`,info:e},s=u?u(o):n(o.subcommands);s&&a.push(m(`subcommands`,h,s))}if(e.examples&&e.examples.length>0){let t=(t,n,r)=>{let i=r?.withHeading??!0,a=Te(t,n,{commandPrefix:e.fullCommandPath,...r});return i?`**Examples**\n\n${a}`:a},n={examples:e.examples,results:e.exampleResults,render:t,heading:`**Examples**`,info:e},r=p?p(n):t(n.examples,n.results);r&&a.push(m(`examples`,h,r))}if(e.notes){let t={content:`**Notes**\n\n${e.notes}`,heading:`**Notes**`,info:e},n=d?d(t):t.content;n&&a.push(m(`notes`,h,n))}{let t={content:``,heading:``,info:e},n=f?f(t):t.content;n&&a.push(n)}return a.join(`
16
+
17
+ `)+`
18
+ `}}const Oe={command:e=>W(e),tableStyle:W({optionStyle:`table`}),listStyle:W({optionStyle:`list`})};function ke(e,t){let n=u.resolve(t);if(!l.existsSync(n))return{match:!1,fileExists:!1};let r=l.readFileSync(n,`utf-8`);return e===r?{match:!0,fileExists:!0}:{match:!1,diff:G(r,e),fileExists:!0}}function G(e,t){let n=e.split(`
19
+ `),r=t.split(`
20
+ `),i=[];i.push(`--- existing`),i.push(`+++ generated`),i.push(``);let a=Math.max(n.length,r.length),o=!1,s=0,c=[],l=()=>{c.length>0&&(i.push(`@@ -${s+1},${c.length} @@`),i.push(...c),c.length=0),o=!1};for(let e=0;e<a;e++){let t=n[e],i=r[e];if(t===i){if(o){c.push(` ${t??``}`);let e=c.findIndex((e,t)=>(e.startsWith(`-`)||e.startsWith(`+`))&&c.slice(t+1).every(e=>e.startsWith(` `)));e!==-1&&c.length-e>3&&l()}}else{if(!o){o=!0,s=e;let t=Math.max(0,e-3);for(let r=t;r<e;r++)c.push(` ${n[r]??``}`)}t!==void 0&&(i===void 0||t!==i)&&c.push(`-${t}`),i!==void 0&&(t===void 0||t!==i)&&c.push(`+${i}`)}}return l(),i.join(`
21
+ `)}function K(e,t){let n=u.resolve(e),r=u.dirname(n);l.existsSync(r)||l.mkdirSync(r,{recursive:!0}),l.writeFileSync(n,t,`utf-8`)}function Ae(e){let t=u.resolve(e);return l.existsSync(t)?l.readFileSync(t,`utf-8`):null}function je(e,t=l){let n=u.resolve(e);t.existsSync(n)&&t.unlinkSync(n)}async function Me(e,t,n=[]){return Ne(e,t,n,!1)}async function Ne(e,n,r,o){let c=i(e),l=c?t(c):[],u=c?a(c):[],d=[];if(e.subCommands)for(let[t,n]of Object.entries(e.subCommands)){let i=await s(n,t=>o||!!e.requiredPackages?.length||!!t.requiredPackages?.length),a=[...r,t];d.push({name:t,description:i.description,aliases:i.aliases,fullPath:a})}return{name:e.name??``,description:e.description,aliases:e.aliases,fullCommandPath:r.length>0?`${n} ${r.join(` `)}`:n,commandPath:r.join(` `),depth:r.length+1,positionalArgs:l,options:u,subCommands:d,extracted:c,command:e,notes:e.notes,examples:e.examples}}async function Pe(e,t){let n=t??e.name??`command`,r=/* @__PURE__ */ new Map;async function i(e,t,a){a||=!!e.requiredPackages?.length;let o=await Ne(e,n,t,a),c=t.join(` `);if(r.set(c,o),e.subCommands)for(let[n,r]of Object.entries(e.subCommands))await i(await s(r,e=>a||!!e.requiredPackages?.length),[...t,n],a)}return await i(e,[],!1),r}async function Fe(e,t,n,r=[]){let i=[];t.mock&&await t.mock();try{for(let t of e){let e=await Ie(t,n,r);i.push(e)}}finally{t.cleanup&&await t.cleanup()}return i}async function Ie(e,t,n){let r=Le(e.cmd),i=[...n,...r],a=c({passthrough:!1});a.start();let o=!0;try{let{runCommand:e}=await import(`./runner-nPWQnqQ3.js`),n=await e(t,i);o=n.success,!n.success&&n.error&&console.error(n.error.message)}catch(e){o=!1,console.error(e instanceof Error?e.message:String(e))}finally{a.stop()}let s=a.getLogs(),l=s.entries.filter(e=>e.stream===`stdout`).map(e=>e.message).join(`
22
+ `),u=s.entries.filter(e=>e.stream===`stderr`).map(e=>e.message).join(`
23
+ `);return{cmd:e.cmd,desc:e.desc,expectedOutput:e.output,stdout:l,stderr:u,success:o}}function Le(e){let t=[],n=``,r=!1,i=``;for(let a=0;a<e.length;a++){let o=e[a];(o===`"`||o===`'`)&&!r?(r=!0,i=o):o===i&&r?(r=!1,i=``):o===` `&&!r?n&&=(t.push(n),``):n+=o}return n&&t.push(n),t}function Re(t){let n=e();return Object.entries(t).map(([e,t])=>n.resolveFieldMeta(e,t))}function ze(e,t){let n=Re(e).filter(e=>!e.positional);return n.length===0?``:O(v(n),t?.columns)}function Be(e){return e.replace(/\|/g,`\\|`).replace(/\n/g,` `)}function Ve(e){return e.replace(/\s+/g,`-`).toLowerCase()}function He(e){return e.subCommands.length===0}function Ue(e,t){return e===t?!0:t===``?e!==``:e.startsWith(t+` `)}function We(e,t,n){let r=[];for(let i of e){let e=t.get(i);if(e){if(He(e))r.push(i);else for(let[e,a]of t)(i===``?e.length>0:e.startsWith(i+` `)||e===i)&&(He(a)||!n)&&r.push(e)}}return r}function Ge(e,t,n,r){let i=`#`.repeat(n),a=[];a.push(`${i} [${e.title}](${e.docPath})`),a.push(``),a.push(e.description),a.push(``);let o=e.noExpand?e.commands:We(e.commands,t,r),s=o,c=/* @__PURE__ */ new Set;if(e.allowedCommands){let t=new Set(e.allowedCommands);s=o.filter(e=>t.has(e));for(let n of e.commands)t.has(n)&&!s.some(e=>Ue(e,n))&&(s.push(n),c.add(n))}a.push(`| Command | Description |`),a.push(`|---------|-------------|`);for(let n of s){let i=t.get(n);if(!i||!e.noExpand&&r&&!c.has(n)&&!He(i))continue;let o=n||i.name,s=Ve(o),l=Be(i.description??``);a.push(`| [${o}](${e.docPath}#${s}) | ${l} |`)}return a.join(`
24
+ `)}async function Ke(e,t,n){let r=n?.headingLevel??3,i=n?.leafOnly??!0,a=await Pe(e),o=[];for(let e of t){let t=Ge(e,a,r,i);o.push(t)}return o.join(`
25
+
26
+ `)}async function q(e,t){if(!t)return e;let n=await t(e);return!e.endsWith(`
27
+ `)&&n.endsWith(`
28
+ `)?n.slice(0,-1):n}function qe(e){let t=process.env[e];return t===`true`||t===`1`}function Je(e){let t=e.split(/\r?\n/);if(t[0]!==`---`)return null;let n=[];for(let e=1;e<t.length;e++){let r=t[e];if(r===`---`||r===`...`)return n.join(`
29
+ `);n.push(r??``)}return null}function Ye(e){let t=Et(e),n=e.split(/\r?\n/);if(n[0]!==`---`)return e;let r=-1;for(let e=1;e<n.length;e++){let t=n[e];if(t===`---`||t===`...`){r=e;break}}if(r===-1)return e;let i=n.slice(1,r),a=[];for(let e=0;e<i.length;e++){let t=i[e]??``;if(!/^politty\s*:\s*(.*)$/.test(t)){a.push(t);continue}for(;e+1<i.length;){let t=i[e+1]??``;if(t.trim()!==``&&!t.startsWith(` `)&&!t.startsWith(` `))break;e++}}let o=n.slice(r+1);return a.some(e=>e.trim()!==``)?[`---`,...a,n[r]??`---`,...o].join(t):o.join(t).replace(RegExp(`^${t}`),``)}function Xe(e){let t=e.trim();return t.length>=2&&(t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`))?t.slice(1,-1):t}function Ze(e){let t=Xe(e);if(t===``)return null;let n=t.match(/^\{\{politty:([^{}]*)\}\}$/);return n?t=n[1]??``:t.startsWith(`politty:`)&&(t=t.slice(8)),t===``?null:t}function Qe(e){return e.slice(2,-2).slice(8)}function $e(e){let t=e.trim();return!t.startsWith(`[`)||!t.endsWith(`]`)?[t]:t.slice(1,-1).split(`,`).map(e=>e.trim()).filter(e=>e.length>0)}function et(e,t){let n=Ze(t);n!==null&&e.add(n)}function tt(e){let t=/* @__PURE__ */ new Set,n=Je(e);if(n===null)return t;let r=!1,i=!1,a=0;for(let e of n.split(/\r?\n/)){let n=e.trim();if(n===``||n.startsWith(`#`))continue;let o=e.match(/^politty\s*:\s*(.*)$/);if(o){r=(o[1]?.trim()??``)===``,i=!1;continue}if(!e.startsWith(` `)&&!e.startsWith(` `)){r=!1,i=!1;continue}if(!r)continue;let s=e.match(/^(\s+)(?:exclude|excludes)\s*:\s*(.*)$/);if(s){let e=s[2]?.trim()??``;if(e===``)i=!0,a=s[1]?.length??0;else{i=!1;for(let n of $e(e))et(t,n)}continue}if(!i)continue;let c=e.match(/^(\s*)-\s*(.+)$/);if(!c||(c[1]?.length??0)<=a){i=!1;continue}et(t,c[2]??``)}return t}function nt(e){let t=Je(e);if(t===null)return{};let n=!1,r=!1,i=0,a={};for(let e of t.split(/\r?\n/)){let t=e.trim();if(t===``||t.startsWith(`#`))continue;let o=e.match(/^politty\s*:\s*(.*)$/);if(o){n=(o[1]?.trim()??``)===``,r=!1;continue}if(!e.startsWith(` `)&&!e.startsWith(` `)){n=!1,r=!1;continue}if(!n)continue;let s=e.match(/^(\s+)index\s*:\s*(.*)$/);if(s){r=(s[2]?.trim()??``)===``,i=s[1]?.length??0;continue}if(!r)continue;if((e.match(/^(\s*)/)?.[1]?.length??0)<=i){r=!1;continue}let c=e.match(/^\s+(title|description)\s*:\s*(.+)$/);if(!c)continue;let l=c[1],u=Xe(c[2]??``);l===`title`?a.title=u:l===`description`&&(a.description=u)}return a}function rt(e){return{rawKeys:e,commandScopes:/* @__PURE__ */ new Set,commandSections:/* @__PURE__ */ new Map,globalOptions:!1,index:!1}}function it(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0})}function at(e){if(Array.isArray(e))return{commands:e};if(!(`commands`in e)||!Array.isArray(e.commands))throw Error(`Invalid file config: object form must include a "commands" array. Use [] to skip generation intentionally.`);return e}function J(e,t){return t===``||e===t||e.startsWith(t+` `)}function Y(e){return e.includes(`*`)}function ot(e,t){let n=e===``?[]:e.split(` `),r=t===``?[]:t.split(` `);if(n.length!==r.length)return!1;for(let e=0;e<r.length;e++){let t=r[e],i=n[e];if(t!==`*`&&t!==i)return!1}return!0}function st(e,t){let n=[];for(let r of t.keys())ot(r,e)&&n.push(r);return n}function ct(e,t){if(Y(t)){if(ot(e,t))return!0;let n=e===``?[]:e.split(` `),r=t===``?[]:t.split(` `);return n.length>r.length&&ot(n.slice(0,r.length).join(` `),t)}return J(e,t)}function lt(e,t){let n=/* @__PURE__ */ new Set,r=e.flatMap(e=>Y(e)?st(e,t):[e]);for(let e of r)for(let r of t.keys())J(r,e)&&n.add(r);return Array.from(n)}function ut(e,t){return e.filter(e=>!t.some(t=>ct(e,t)))}function dt(e,t){let n=[];for(let r of e)Y(r)?n.push(...st(r,t)):t.has(r)&&n.push(r);return n}function X(e,t,n){let r=at(e),i=r.commands;return{fileConfig:r,specifiedCommands:i,commandPaths:ut(r.noExpand?i.filter(e=>t.has(e)):lt(i,t),n),topLevelCommands:ut(dt(i,t),n)}}function ft(e,t,n){let r=[];for(let i of e){let e=Y(i)?st(i,n):[i];for(let n of e)for(let e of t)Y(e)?ot(n,e)&&r.push(`"${n}" is both in files and ignored by "${e}"`):(n===e||J(n,e))&&r.push(`"${n}" is both in files and ignored by "${e}"`)}if(r.length>0)throw Error(`Conflict between files and ignores:\n - ${r.join(`
30
+ - `)}`)}function pt(e,t){let n=[];for(let r of e)Y(r)?st(r,t).length===0&&n.push(`"${r}"`):t.has(r)||n.push(`"${r}"`);if(n.length>0)throw Error(`Ignored command paths do not exist: ${n.join(`, `)}`)}function mt(e,t){let n=new Set(e),r=t.filter(e=>n.has(e));for(let t of e)(t===``?0:t.split(` `).length)===1&&!r.includes(t)&&r.push(t);let i=[],a=/* @__PURE__ */ new Set;function o(t){if(a.has(t)||!n.has(t))return;a.add(t),i.push(t);let r=e.filter(e=>e===t||a.has(e)?!1:t===``?e.split(` `).length===1:e.startsWith(t+` `)&&e.split(` `).length===t.split(` `).length+1).sort((e,t)=>e.localeCompare(t));for(let e of r)o(e)}for(let e of r)o(e);for(let t of e)a.has(t)||i.push(t);return i}function ht(e){if(!e.title&&!e.description)return null;let t=[];if(e.title){let n=`#`.repeat(e.headingLevel??1);t.push(`${n} ${e.title}`)}return e.description&&(t.push(``),t.push(e.description)),t.push(``),t.join(`
31
+ `)}function gt(e){if(!/^#{1,6} /.test(e))return null;let t=e.indexOf(`
32
+ `);if(t===-1)return e;let n=t+1;for(e[n]===`
33
+ `&&(n+=1);n<e.length;){let t=e.indexOf(`
34
+ `,n),r=t===-1?e.slice(n):e.slice(n,t);if(r.length===0||/^#{1,6}\s/.test(r)||r.startsWith(`<!-- politty:`))break;n=t===-1?e.length:t+1}return e.slice(0,n)}function _t(e,t,n){let r=ht(t);if(!r||e.startsWith(r))return{content:e,hasError:!1,wasUpdated:!1};let i=gt(e)??``;return n?{content:`${r}${(i?e.slice(i.length):e).replace(/^\n+/,``)}`,hasError:!1,wasUpdated:!0}:{content:e,diff:G(i,r),hasError:!0,wasUpdated:!1}}function Z(e){return e===``?`<root>`:e}function Q(e,t,n){return Ht(e,P(t,n),F(t,n))}function vt(e,t,n,r){return Ut(e,P(t,n),F(t,n),r)}function yt(e,t,n,r){let i=M.indexOf(t),a=P(t,n),o=F(t,n),s=null;for(let t=i-1;t>=0;t--){let r=M[t],i=F(r,n),a=e.indexOf(i);if(a!==-1){s=a+i.length;break}}let c=null;for(let t=i+1;t<M.length;t++){let r=M[t],i=P(r,n),a=e.indexOf(i);if(a!==-1){c=a;break}}if(s!=null&&c!=null){let t=a+e.slice(s,c).replace(/^\n+/,`
35
+ `).replace(/\n+$/,`
36
+ `)+o;return e.slice(0,s)+`
37
+
38
+ `+t+`
39
+
40
+ `+e.slice(c)}if(s!=null){let t=s;for(;t<e.length&&e[t]===`
41
+ `;)t++;return e.slice(0,s)+`
42
+
43
+ `+r+(t<e.length?`
44
+
45
+ `:`
46
+ `)+e.slice(t)}if(c!=null){let t=c;for(;t>0&&e[t-1]===`
47
+ `;)t--;let n=t===0?``:`
48
+
49
+ `;return e.slice(0,t)+n+r+`
50
+
51
+ `+e.slice(c)}throw Error(`No insertion point found for section "${t}" (scope="${n}"). This should be unreachable when at least one marker exists for the command.`)}function bt(e,t){let n=[];for(let r of M)Q(e,r,t)!==null&&n.push(r);return n}function xt(e){let t=M.join(`|`),n=RegExp(`<!--\\s*politty:command:(.*?):(?:${t}):start\\s*-->`,`g`),r=/* @__PURE__ */ new Set;for(let t of e.matchAll(n))r.add(t[1]??``);return Array.from(r)}function St(e,t,n,r){let i=r.indexOf(t);if(i===-1)return e.trimEnd()+`
52
+
53
+ `+n+`
54
+ `;for(let t=i+1;t<r.length;t++){let i=r[t];if(i===void 0)continue;let a=P(`heading`,i),o=e.indexOf(a);if(o!==-1){let t=o;for(;t>0&&e[t-1]===`
55
+ `;)t--;return t<o&&t++,e.slice(0,t)+n+`
56
+ `+e.slice(o)}}for(let t=i-1;t>=0;t--){let i=r[t];if(i===void 0)continue;let a=bt(e,i);if(a.length>0){let t=a[a.length-1],r=F(t,i),o=e.indexOf(r);if(o!==-1){let t=o+r.length;return e.slice(0,t)+`
57
+ `+n+e.slice(t)}}}return e.trimEnd()+`
58
+ `+n+`
59
+ `}function Ct(e,t){let n=bt(e,t);for(let r of n){let n=P(r,t),i=F(r,t),a=e.indexOf(n);for(;a!==-1;){let t=e.indexOf(i,a);if(t===-1)break;e=e.slice(0,a)+e.slice(t+i.length),a=e.indexOf(n,a)}}return e=e.replace(/\n{3,}/g,`
60
+
61
+ `),e}function wt(e){let t=Tt(e.split(`
62
+ `).filter(e=>!/^<!-- politty:.*-->$/.test(e.trim())).join(`
63
+ `));return t=t.replace(/^\n+/,``).replace(/\n+$/,``),t}function Tt(e){let t=e.split(`
64
+ `),n=[],r=!1,i=0;for(let e of t){let t=e.trim();if(t.startsWith("```")||t.startsWith(`~~~`)){r=!r,i=0,n.push(e);continue}if(!r&&e.trim()===``){if(i++,i>=2)continue}else r||(i=0);n.push(e)}return n.join(`
65
+ `)}function Et(e){return e.includes(`\r
66
+ `)?`\r
67
+ `:`
68
+ `}function Dt(e){return(e.match(/\n/g)??[]).length}function Ot(e){return M.some(t=>t===e)}function kt(e){switch(Math.min(6,Math.max(1,Math.trunc(e)))){case 1:return 1;case 2:return 2;case 3:return 3;case 4:return 4;case 5:return 5;default:return 6}}function At(e,t){if(e.length===0)return t===void 0||t.has(``)?``:null;let n=e.join(`:`);if(t?.has(n))return n;let r=e.join(` `);return t?.has(r)||t===void 0?r:null}function jt(e){return e.join(` `)}function Mt(e,t){let n=e.slice(2,-2).split(`:`),r=n[1];if(r===`command`){let r=n.slice(2);if(r.length===1&&r[0]===``)return{kind:`invalid`,reason:`Trailing colon in "${e}"; use {{politty:command}} for the root command.`};let i=At(r,t);if(i!==null)return{kind:`command`,scope:i,type:void 0};if(r.length>=2){let e=r[r.length-1],n=r.slice(0,-1),i=At(n,t);if(e!==void 0&&Ot(e))return{kind:`command`,scope:i??jt(n),type:e};if(e!==void 0&&i!==null)return{kind:`invalid`,reason:`Unknown section type "${e}" for command scope "${Z(i)}". Valid section types: ${M.join(`, `)}`}}return{kind:`command`,scope:jt(r),type:void 0}}return r===`global-options`?n.length===2?{kind:`global-options`}:{kind:`invalid`,reason:`Malformed placeholder "${e}". Expected {{politty:global-options}}.`}:r===`index`?n.length===2?{kind:`index`}:{kind:`invalid`,reason:`Malformed placeholder "${e}". Expected {{politty:index}}.`}:{kind:`invalid`,reason:`Unknown politty directive "${r??``}" in "${e}". Valid directives: command, global-options, index`}}function Nt(e,t){let n=rt(e);for(let r of e){let e=Mt(`{{politty:${r}}}`,t);if(e.kind===`command`){if(e.type===void 0)n.commandScopes.add(e.scope);else{let t=n.commandSections.get(e.scope);t||(t=/* @__PURE__ */ new Set,n.commandSections.set(e.scope,t)),t.add(e.type)}}else e.kind===`global-options`?n.globalOptions=!0:e.kind===`index`&&(n.index=!0)}return n}function Pt(e,t){for(let n of t)if(J(e,n))return!0;return!1}function Ft(e,t,n){return Pt(e,n.commandScopes)?!0:n.commandSections.get(e)?.has(t)??!1}function It(e,t,n,r){return mt(ut(lt([e],t),n).filter(e=>!Pt(e,r.commandScopes)),[e])}function Lt(e,t,n){return n.rawKeys.has(Qe(e))?!0:t.kind===`command`?Pt(t.scope,n.commandScopes)?!0:t.type!==void 0&&(n.commandSections.get(t.scope)?.has(t.type)??!1):t.kind===`global-options`?n.globalOptions:t.kind===`index`&&n.index}function Rt(e,t){if(!e.startsWith(`command:`))return!1;let n=e.slice(8).split(`:`);for(let e of t.commandScopes){if(e===``)return!0;let t=e.split(` `);if(n.slice(0,t.length).join(` `)===e)return!0;let r=e.split(`:`);if(n.slice(0,r.length).join(`:`)===e)return!0}return!1}const zt=/\{\{politty:[^{}]*\}\}/g;function Bt(e,t){let n=/* @__PURE__ */ new Set;for(let r of e.matchAll(zt)){let i=r.index,a=i+r[0].length;if(e[i-1]===`{`||e[a]===`}`){let n=e.slice(Math.max(0,i-1),Math.min(e.length,a+1)).split(`
69
+ `)[0];throw Error(`Malformed politty placeholder in template "${t}": "${n}". Expected {{politty:...}}.`)}n.add(i)}let r=0;for(;;){let i=e.indexOf(`{{politty:`,r);if(i===-1)return;if(!n.has(i)){let n=e.slice(i,i+80).split(`
70
+ `)[0];throw Error(`Malformed politty placeholder in template "${t}": "${n}". Expected {{politty:...}}.`)}r=i+10}}function Vt(e,t){let n=e.lastIndexOf(`:`);if(n===-1)return null;let r=e.slice(0,n),i=e.slice(n+1);return i===``||!t.has(r)?null:`Unknown section type "${i}" for command scope "${Z(r)}". Valid section types: ${M.join(`, `)}`}function Ht(e,t,n){let r=e.indexOf(t);if(r===-1)return null;let i=e.indexOf(n,r);return i===-1?null:e.slice(r,i+n.length)}function Ut(e,t,n,r){let i=e.indexOf(t);if(i===-1)return null;let a=e.indexOf(n,i);return a===-1?null:e.slice(0,i)+r+e.slice(a+n.length)}function Wt(e){if(typeof e!=`object`||!e)return!1;let t=e[`~standard`];if(typeof t!=`object`||!t)return!1;let{vendor:n,validate:r}=t;return typeof n==`string`&&typeof r==`function`}function Gt(e){return typeof e!=`object`||!e||!(`args`in e)?!1:!Wt(e.args)}function Kt(t){let n=e();return Object.entries(t).map(([e,t])=>n.resolveFieldMeta(e,t)).filter(e=>!e.positional)}function qt(e,t){let{schema:n,...r}=e,{schema:i,...a}=t;return f(r,a)}function Jt(e){if(e)return Gt(e)?e:{args:e}}function Yt(e){if(!e)return;let t=n(e).fields.filter(e=>!e.positional);if(t.length!==0)return Object.fromEntries(t.map(e=>[e.name,e.schema]))}function Xt(e){let t=/* @__PURE__ */ new Map;if(!e?.globalOptions)return t;let n=Jt(e.globalOptions);if(!n)return t;for(let e of Kt(n.args))t.set(e.name,e);return t}function Zt(e,t,n,r){let i=[];for(let[a,o]of Object.entries(e)){let{commandPaths:e,topLevelCommands:s}=X(o,n,r);if(e.length===0)continue;let c=`./`+u.relative(u.dirname(t),a).replace(/\\/g,`/`),l=e[0],d=l===void 0?void 0:n.get(l),f=Array.isArray(o)?void 0:o;i.push({title:f?.title??d?.name??u.basename(a,u.extname(a)),description:f?.description??d?.description??``,commands:s,allowedCommands:e,docPath:c})}return i}function Qt(e,t,n,r){let i=$(t),a=[];for(let[t,o]of e.entries()){if($(t)===i)continue;let e=o.headingScopes;if(e.length===0)continue;let s=`./`+u.relative(u.dirname(n),t).replace(/\\/g,`/`),c=e[0],l=c===void 0?void 0:r.get(c);a.push({title:o.indexTitle??l?.name??u.basename(t,u.extname(t)),description:o.indexDescription??l?.description??``,commands:e,docPath:s,noExpand:!0})}return a}function $t(e,t,n){let r=/* @__PURE__ */ new Set;for(let i of Object.values(e)){let{commandPaths:e}=X(i,t,n);for(let t of e)r.add(t)}return r}function en(e,t,n,r){let i=/* @__PURE__ */ new Set;for(let a of Object.keys(t)){let o=pn(e,a,t,n,r);for(let e of o)i.add(e)}return i}function tn(e,t){return t.some(t=>J(e,t))}function nn(e,t){return e.referencedScopes.some(e=>tn(e,t))}function rn(e,t){return e.emitsIndex||e.emitsGlobalOptions||nn(e,t)}function an(e,t,n){if(n.size===0)return;let r=[];for(let i of e){let e=t.get(i);if(e)for(let t of e.options){let e=n.get(t.name);e&&(qt(e,t)||r.push(`Command "${Z(i)}" option "--${t.cliName}" does not match globalOptions definition for "${t.name}".`))}}if(r.length>0)throw Error(`Invalid globalOptions configuration:\n - ${r.join(`
71
+ - `)}`)}function on(e){return[`<a id="global-options"></a>`,ze(e.args,e.options)].join(`
72
+ `)}function sn(e){return[L(),on(e),ee()].join(`
73
+ `)}async function cn(e,t,n,r){let i=V(n),a=ae(n);return[i,await Ke(t,e,r),a].join(`
74
+ `)}function $(e){return u.resolve(e)}async function ln(e,t,n,r,i){let a=e,o=[],s=!1,c=!1,l=L(),u=ee(),d=await q(sn(t),r),f=Ht(a,l,u);if(!f)return n&&i?(a=a.trimEnd()+`
75
+
76
+ `+d+`
77
+ `,c=!0,{content:a,diffs:o,hasError:s,wasUpdated:c}):(s=!0,o.push(`Global options marker not found in file. Expected markers:\n${l}\n...\n${u}`),{content:a,diffs:o,hasError:s,wasUpdated:c});if(f!==d){if(n){let e=Ut(a,l,u,d);e?(a=e,c=!0):(s=!0,o.push(`Failed to replace global options section`))}else s=!0,o.push(G(f,d))}return{content:a,diffs:o,hasError:s,wasUpdated:c}}async function un(e,t,n,r,i,a,o,s){let c=e,l=[],u=!1,d=!1,f=[n,await q(i,o),r].join(`
78
+ `),p=Ht(c,n,r);if(!p)return a&&s?(c=c.trimEnd()+`
79
+
80
+ `+f+`
81
+ `,d=!0,{content:c,diffs:l,hasError:u,wasUpdated:d}):(u=!0,l.push(`${t} marker not found in file. Expected markers:\n${n}\n...\n${r}`),{content:c,diffs:l,hasError:u,wasUpdated:d});if(p!==f){if(a){let e=Ut(c,n,r,f);e?(c=e,d=!0):(u=!0,l.push(`Failed to replace ${t} section`))}else u=!0,l.push(G(p,f))}return{content:c,diffs:l,hasError:u,wasUpdated:d}}async function dn(e,t,n,r,i,a,o){let s=e,c=[],l=!1,u=!1,d=V(r),f=ae(r),p=s.includes(d),m=s.includes(f);if(!p&&!m)return{content:s,diffs:c,hasError:l,wasUpdated:u};if(!p||!m)return l=!0,c.push(`Index marker section is malformed: both start and end markers are required.`),{content:s,diffs:c,hasError:l,wasUpdated:u};let h=Ht(s,d,f);if(!h)return l=!0,c.push(`Index marker section is malformed: start marker must appear before end marker.`),{content:s,diffs:c,hasError:l,wasUpdated:u};let g=await q(await cn(t,n,r,o),a);if(h!==g){if(i){let e=Ut(s,d,f,g);e?(s=e,u=!0):(l=!0,c.push(`Failed to replace index section`))}else l=!0,c.push(G(h,g))}return{content:s,diffs:c,hasError:l,wasUpdated:u}}function fn(e,t,n,r){for(let[i,a]of Object.entries(t)){let{commandPaths:t}=X(a,n,r);if(t.includes(e))return i}return null}function pn(e,t,n,r,i){let a=n[t];if(!a)return[];let{specifiedCommands:o,commandPaths:s}=X(a,r,i),c=/* @__PURE__ */ new Set;for(let t of e)if(s.includes(t)){c.add(t);for(let e of s)J(e,t)&&!o.includes(e)&&c.add(e)}return Array.from(c)}function mn(e,t,n,r,i,a,o,s=[],c,l){let u=t.get(e);if(!u||l&&Pt(u.commandPath,l.commandScopes))return null;let d={...u,filePath:r,fileMap:i,rootDocPath:a};(s.length>0||l&&l.commandScopes.size>0)&&(d.subCommands=u.subCommands.filter(e=>{let t=e.fullPath.join(` `);return!s.some(e=>ct(t,e))&&!(l&&Pt(t,l.commandScopes))})),o!==void 0&&(d.hasGlobalOptions=o),c&&c.size>0&&(d.options=u.options.filter(e=>!c.has(e.name)),u.extracted&&(d.extracted=gn(u.extracted,c)));let f=n(d);if(l){for(let[e,t]of l.commandSections)if(e===u.commandPath){for(let n of t){let t=Q(f,n,e);t!==null&&(f=f.replace(t,``))}f=Tt(f)}}return f}function hn(e,t,n,r,i,a,o,s,c,l){let u=It(e,t,r,l),d=[];for(let e of u){let u=mn(e,t,n,i,a,o,s,r,c,l);u!==null&&d.push(u)}return d.length===0?null:d.join(`
82
+ `)}function gn(e,t){let n={...e,fields:e.fields.filter(e=>!t.has(e.name))};return e.unionOptions&&(n.unionOptions=e.unionOptions.map(e=>gn(e,t))),e.variants&&(n.variants=e.variants.map(e=>({...e,fields:e.fields.filter(e=>!t.has(e.name))}))),n}function _n(e,t,n,r,i,a,o,s,c,l=[]){let u=[],d=o?ht(o):null;d&&u.push(d);let f=mt(e,a??[]);for(let e of f){let a=mn(e,t,n,r,i,s,c,l);a&&u.push(a)}return`${u.join(`
83
+ `)}\n`}function vn(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let{commandPaths:e}=X(a,t,n);for(let t of e)it(r,t,i)}return r}async function yn(e,t,n){for(let[r,i]of Object.entries(t)){let t=e.get(r);if(!t?.examples?.length)continue;let a=i===!0?{}:i,o=r?r.split(` `):[];t.exampleResults=await Fe(t.examples,a,n,o)}}function bn(e,t){if(typeof e==`string`)return{files:{[e]:Array.from(t.keys())},rootDocPath:e};let{root:n,commands:r={}}=e,i={},a=/* @__PURE__ */ new Set,o=Object.entries(r).sort(([e],[t])=>t.split(` `).length-e.split(` `).length);for(let[e,n]of o){i[n]||(i[n]={commands:[],noExpand:!0});let r=i[n];for(let n of t.keys())(n===e||n.startsWith(e+` `))&&!a.has(n)&&(r.commands.push(n),a.add(n))}return i[n]={commands:Array.from(t.keys()).filter(e=>!a.has(e)),noExpand:!0},{files:i,rootDocPath:n}}async function xn(e){let{command:t,ignores:r=[],format:i={},formatter:a,examples:o,targetCommands:s,globalArgs:c,customizable:l=!1}=e,d=await Pe(t),f,p=!1,m;if(e.path!==void 0){if(e.files!==void 0)throw Error(`Cannot specify both "path" and "files". Use one or the other.`);let t=bn(e.path,d);f=t.files,m=t.rootDocPath,p=!0}else if(e.files!==void 0)f=e.files;else if(e.templates!==void 0)f={};else throw Error(`Either "path", "files", or "templates" must be specified.`);let h=e.rootDoc;if(!h&&p&&(c||e.rootInfo)&&(h={path:m}),c&&h&&!h.globalOptions){let e=n(c).fields.filter(e=>!e.positional);if(e.length>0){let t=Object.fromEntries(e.map(e=>[e.name,e.schema]));h={...h,globalOptions:t}}}let g=qe(A),_=qe(j),v=!1;if(h&&!p){let e=$(h.path);if(Object.keys(f).some(t=>$(t)===e))throw Error(`rootDoc.path "${h.path}" must not also appear as a key in files.`)}o&&await yn(d,o,t);let y=s!==void 0&&s.length>0,b=Xt(h),x=/* @__PURE__ */ new Map;if(e.templates){if(b.size>0)for(let[e,t]of b)x.set(e,t);else{let e=Yt(c);if(e)for(let t of Kt(e))x.set(t.name,t)}}let S=y?en(s,f,d,r):$t(f,d,r),C=[];for(let e of Object.values(f)){let t=at(e);C.push(...t.commands)}pt(r,d),ft(C,r,d);let w=vn(f,d,r),T=/* @__PURE__ */ new Map,E=/* @__PURE__ */ new Map;if(e.templates)for(let[t,n]of Object.entries(e.templates)){let e=Ae(n);T.set(t,e),e!==null&&E.set(t,Nt(tt(e),d))}let D=Object.entries(e.templates??{}),O=/* @__PURE__ */ new Map,k=/* @__PURE__ */ new Map;if(D.length>0){let e=h?$(h.path):null,t=new Set(Object.keys(f).map($)),n=/* @__PURE__ */ new Set,i=new Set(D.map(([e])=>$(e)));for(let[r,a]of D){let o=$(r),s=$(a);if(t.has(o))throw Error(`Template output path "${r}" conflicts with an existing files key.`);if(e&&o===e)throw Error(`Template output path "${r}" conflicts with rootDoc.path "${h.path}".`);if(n.has(o))throw Error(`Duplicate template output path: "${r}".`);if(n.add(o),s===o)throw Error(`Template output path "${r}" must not be the same as its source template path.`);if(t.has(s))throw Error(`Template source path "${a}" conflicts with a files output key.`);if(e&&s===e)throw Error(`Template source path "${a}" conflicts with rootDoc.path "${h.path}".`);if(i.has(s))throw Error(`Template source path "${a}" conflicts with a template output path.`)}let a=Array.from(d.keys()).join(`, `);for(let[e,t]of D){let n=T.get(e)??null,i=[];if(n===null){O.set(e,{referencedScopes:[],headingScopes:[],commandTreeRoots:[],emitsGlobalOptions:!1,emitsIndex:!1}),k.set(e,i);continue}try{Bt(n,t)}catch(e){i.push(e instanceof Error?e.message:String(e))}let o=Array.from(new Set(n.match(zt)??[])),s=/* @__PURE__ */ new Set,l=/* @__PURE__ */ new Set,u=/* @__PURE__ */ new Set,f=!1,p=!1,m=E.get(e)??rt(/* @__PURE__ */ new Set),g=nt(n);for(let e of o){let n=Qe(e);if(m.rawKeys.has(n)||Rt(n,m))continue;let o=Mt(e,d);if(!Lt(e,o,m)){if(o.kind===`invalid`){i.push(`${o.reason} (in template "${t}")`);continue}if(o.kind===`command`){let{scope:e,type:n}=o;if(!d.has(e)){let n=Vt(e,d);if(n){i.push(`${n} (in template "${t}")`);continue}i.push(`Unknown command scope "${e}" in template "${t}". Available: ${a}`);continue}if(r.some(t=>ct(e,t))){i.push(`Command scope "${e}" in template "${t}" conflicts with ignores configuration.`);continue}if(n===void 0){let t=It(e,d,r,m);Ft(e,`heading`,m)||u.add(e);for(let e of t)s.add(e),Ft(e,`heading`,m)||l.add(e)}else s.add(e),n===`heading`&&!Ft(e,`heading`,m)&&(l.add(e),u.add(e))}else o.kind===`global-options`?f=!0:o.kind===`index`&&(p=!0)}}f&&(h?.globalOptions||Yt(c)!==void 0||i.push(`Template "${t}" uses {{politty:global-options}} but no global options are configured (neither rootDoc.globalOptions nor globalArgs with non-positional options).`)),O.set(e,{referencedScopes:Array.from(s),headingScopes:Array.from(l),commandTreeRoots:Array.from(u),emitsGlobalOptions:f,emitsIndex:p,...g.title===void 0?{}:{indexTitle:g.title},...g.description===void 0?{}:{indexDescription:g.description}}),k.set(e,i)}for(let e of O.values())if(!y||rn(e,s))for(let t of e.referencedScopes)S.add(t)}if(y)for(let e of s){let t=fn(e,f,d,r),n=Array.from(O.values()).some(t=>nn(t,[e]));if(!t&&!n)throw Error(`Target command "${e}" not found in any file or template configuration`)}let M=y&&e.templates?new Map(Array.from(O.entries()).filter(([,e])=>rn(e,s))):O;for(let[e,t]of k.entries())if(t.length>0&&M.has(e))throw Error(t.join(`
84
+ `));let N=Array.from(O.entries()).filter(([,e])=>e.emitsGlobalOptions).map(([e])=>e),I=N.length===1?N[0]:void 0;if(an(S,d,b),b.size===0&&x.size>0){let e=/* @__PURE__ */ new Set;for(let t of M.values())if(t.emitsGlobalOptions||I!==void 0)for(let n of t.referencedScopes)e.add(n);an(e,d,x)}if(b.size>0)for(let e of d.values())e.options=e.options.filter(e=>!b.has(e.name)),e.extracted&&=gn(e.extracted,new Set(b.keys()));let L={};for(let[e,t]of Object.entries(w))it(L,e,t);let ee=e=>e===``?0:e.split(` `).length,R=/* @__PURE__ */ new Map;for(let[e,t]of O.entries())for(let n of t.headingScopes){if(Object.prototype.hasOwnProperty.call(w,n))continue;let r=-1;for(let e of t.commandTreeRoots)J(n,e)&&(r=Math.max(r,ee(e)));if(r<0)continue;let i=R.get(n);(!i||r>i.rootLen)&&R.set(n,{outputPath:e,rootLen:r})}for(let[e,{outputPath:t}]of R)it(L,e,t);let z=[],B=!1;for(let[e,t]of Object.entries(f)){let{fileConfig:n,specifiedCommands:o,commandPaths:c}=X(t,d,r);if(o.length===0||c.length===0)continue;let u=y?pn(s,e,f,d,r):[];if(y&&u.length===0)continue;let m=`match`,x=[],S=Math.min(...c.map(e=>d.get(e)?.depth??1)),C=Math.max(1,(i?.headingLevel??1)-(S-1)),w=p&&h&&$(e)===$(h.path),T=p||l,E=W({...i,headingLevel:C,markerless:!T}),D=n.render??E;if(w||y&&T){let t=Ae(e),i=mt(c,o),s=y?u:c;for(let o of s){let s=mn(o,d,D,e,L,h?.path,b.size>0,r);if(!s)throw Error(`Target command "${o}" not found in commands`);let c=await q(s,a);if(!t){if(g){let r=o===``&&n?ht(n):null,i=r?`${r}\n${c}`:c;K(e,i),t=i,m=`created`}else B=!0,m=`diff`,x.push(`File does not exist. Target command "${o}" section cannot be validated.`);continue}let u=bt(t,o);if(u.length===0){g?(t=St(t,o,c,i),K(e,t),m!==`created`&&(m=`updated`)):(B=!0,m=`diff`,x.push(`Existing file does not contain section markers for command "${o}"`));continue}for(let n of u){let r=Q(t,n,o),i=Q(c,n,o);if(r){if(!i){let i=P(n,o)+`
85
+ `+F(n,o);if(r!==i){if(g){let r=vt(t,n,o,i);if(!r)throw Error(`Failed to replace stale ${n} section for command "${o}"`);t=r.replace(/\n{3,}/g,`
86
+
87
+ `),K(e,t),m!==`created`&&(m=`updated`)}else B=!0,m=`diff`,x.push(G(r,i))}continue}if(r!==i){if(g){let r=vt(t,n,o,i);if(r)t=r,K(e,t),m!==`created`&&(m=`updated`);else throw Error(`Failed to replace ${n} section for command "${o}"`)}else B=!0,m=`diff`,x.push(G(r,i))}}}if(_||l){let n=bt(c,o),r=new Set(u);for(let i of n){if(r.has(i))continue;let n=Q(c,i,o);n&&(_&&g?(t=yt(t,i,o,n),K(e,t),m!==`created`&&(m=`updated`)):_?(B=!0,v=!0,m=`diff`,x.push(`[doctor] Missing section marker "${i}" for command "${Z(o)}". Run with ${j}=true ${A}=true to insert.\n${n}`)):console.warn(`[politty] Missing "${i}" section for command "${Z(o)}" in ${e}. Run with ${j}=true ${A}=true to insert it, or leave it removed to opt that section out.`))}}}if(t){let n=xt(t),r=new Set(c);if(g){let i=!1;for(let e of n)r.has(e)||(t=Ct(t,e),i=!0);i&&(K(e,t),m!==`created`&&(m=`updated`))}else for(let e of n)r.has(e)||(B=!0,m=`diff`,x.push(`Found orphaned section markers for deleted command "${Z(e)}"`))}}else{let t=await q(_n(c,d,D,e,L,o,n,h?.path,b.size>0,r),a),i=ke(t,e);i.match||(g?(K(e,t),m=i.fileExists?`updated`:`created`):(B=!0,m=`diff`,i.diff&&x.push(i.diff)))}x.length>0&&(m=`diff`),z.push({path:e,status:m,diff:x.length>0?x.join(`
88
+
89
+ `):void 0})}let V;if(h?.globalOptions)V=Jt(h.globalOptions);else{let e=Yt(c);e&&(V={args:e})}for(let[e,n]of D){if(!M.has(e))continue;let o=T.get(e)??null;if(o===null){B=!0,z.push({path:e,status:`diff`,diff:`Template file not found: ${n}`});continue}let s=O.get(e),c=Et(o),l=Ye(o),u=(s?.headingScopes??[]).map(e=>d.get(e)?.depth??1),p=u.length>0?Math.min(...u):1,m=kt((i?.headingLevel??1)-(p-1)),_=W({...i,headingLevel:m}),v=s?.emitsGlobalOptions??!1,y=(h!==void 0&&b.size>0||v||I!==void 0)&&x.size>0?new Set(x.keys()):void 0,S=y!==void 0,C=v?e:h?.path??I,w=Array.from(new Set(l.match(zt)??[])),D=/* @__PURE__ */ new Map,k=E.get(e)??rt(/* @__PURE__ */ new Set);for(let i of w){let a=Qe(i);if(k.rawKeys.has(a)||Rt(a,k)){D.set(i,``);continue}let o=Mt(i,d);if(Lt(i,o,k)){D.set(i,``);continue}if(o.kind===`invalid`)throw Error(`Internal error: unresolved placeholder "${i}" in template "${n}": ${o.reason}`);if(o.kind===`command`){let{scope:t,type:n}=o;if(n===void 0){let n=hn(t,d,_,r,e,L,C,S,y,k);if(n===null){D.set(i,``);continue}D.set(i,wt(n))}else{let a=mn(t,d,_,e,L,C,S,r,y,k);if(a===null){D.set(i,``);continue}let o=Q(a,n,t);D.set(i,o===null?``:wt(o))}}else if(o.kind===`global-options`)V?D.set(i,on(V)):D.set(i,``);else if(o.kind===`index`){let n=await Ke(t,[...Zt(f,e,d,r),...Qt(O,e,e,d)],h?.index);D.set(i,n)}}let A=l.replace(/((?:\r?\n)*)([ \t]*)(\{\{politty:[^{}]*\}\})([ \t]*)((?:\r?\n)*)/g,(e,t,r,i,a,o,s,c)=>{let l=D.get(i);if(l===void 0)throw Error(`Internal error: unresolved placeholder "${i}" in template "${n}".`);let u=t!==``||s===0||c[s-1]===`
90
+ `,d=o!==``||s+e.length===c.length;if(l===``&&u&&d){if(t===``||o===``)return``;let e=Dt(t),n=Dt(o),r=Math.max(e,n),i=Et(e>=n?t:o);return r>=2?i+i:r===1?i:``}return`${t}${r}${l}${a}${o}`});A=`${A.trimEnd()}${c}`,A=await q(A,a);let j=ke(A,e),N=`match`,P;j.match||(g?(K(e,A),N=j.fileExists?`updated`:`created`):(B=!0,N=`diff`,j.diff&&(P=j.diff))),z.push({path:e,status:N,diff:P})}if(h){let n=h.path,i=`match`,o=[],s=Ae(n);if(s===null)B=!0,i=`diff`,o.push(`File does not exist. Cannot validate rootDoc markers.`);else{let c=s,l=!1,m=e.rootInfo,_={title:m?.title??t.name};h.headingLevel!==void 0&&(_.headingLevel=h.headingLevel);let v=m?.description??t.description;v!==void 0&&(_.description=v);let y=_t(c,_,g);if(c=y.content,y.diff&&o.push(y.diff),y.hasError&&(B=!0),y.wasUpdated&&(l=!0),m?.header){let e=await un(c,`Root header`,te(),ne(),m.header,g,a,p);c=e.content,o.push(...e.diffs),e.hasError&&(B=!0),e.wasUpdated&&(l=!0)}if(!p){let e=xt(c);if(e.length>0){if(g){for(let t of e)c=Ct(c,t);l=!0}else B=!0,o.push(`Found unexpected section markers in rootDoc: ${e.map(e=>`"${Z(e)}"`).join(`, `)}.`)}}let b=Jt(h.globalOptions);if(b){let e=await ln(c,b,g,a,p);c=e.content,o.push(...e.diffs),e.hasError&&(B=!0),e.wasUpdated&&(l=!0)}let x=Zt(f,n,d,r),S=u.relative(process.cwd(),n).replace(/\\/g,`/`),C=await dn(c,x,t,S,g,a,h.index);if(c=C.content,o.push(...C.diffs),C.hasError&&(B=!0),C.wasUpdated&&(l=!0),m?.footer){let e=await un(c,`Root footer`,re(),ie(),m.footer,g,a,p);c=e.content,o.push(...e.diffs),e.hasError&&(B=!0),e.wasUpdated&&(l=!0)}g&&l&&(K(n,c),i===`match`&&(i=`updated`))}o.length>0&&(i=`diff`),z.push({path:n,status:i,diff:o.length>0?o.join(`
91
+
92
+ `):void 0})}return{success:!B,files:z,error:B?`Documentation is out of date. ${v?`Run with ${j}=true ${A}=true to fix missing markers.`:`Run with ${A}=true to update.`}`:void 0}}async function Sn(e){let t=await xn(e);if(!t.success){let e=t.files.filter(e=>e.status===`diff`).map(e=>{let t=`File: ${e.path}\n`;return e.diff&&(t+=e.diff),t}).join(`
93
+
94
+ `);throw Error(`Documentation does not match golden files.\n\n${e}\n\n`+(t.error??`Run with POLITTY_DOCS_UPDATE=true to update the documentation.`))}}function Cn(e,t){if(qe(`POLITTY_DOCS_UPDATE`)){if(typeof e==`string`)je(e,t);else{let n=new Set(Object.values(e.templates??{}).map($));e.rootDoc&&n.add($(e.rootDoc.path));let r=e=>n.has($(e));if(e.files)for(let n of Object.keys(e.files))r(n)||je(n,t);if(e.templates)for(let n of Object.keys(e.templates))r(n)||je(n,t)}}}export{j as DOCTOR_ENV,I as GLOBAL_OPTIONS_MARKER_PREFIX,B as INDEX_MARKER_PREFIX,z as ROOT_FOOTER_MARKER_PREFIX,R as ROOT_HEADER_MARKER_PREFIX,N as SECTION_MARKER_PREFIX,M as SECTION_TYPES,A as UPDATE_GOLDEN_ENV,Sn as assertDocMatch,Me as buildCommandInfo,Pe as collectAllCommands,ke as compareWithExisting,W as createCommandRenderer,Oe as defaultRenderers,Fe as executeExamples,G as formatDiff,xn as generateDoc,ee as globalOptionsEndMarker,L as globalOptionsStartMarker,ae as indexEndMarker,V as indexStartMarker,Cn as initDocFile,ze as renderArgsTable,ue as renderArgumentsList,Ce as renderArgumentsListFromArray,ce as renderArgumentsTable,Se as renderArgumentsTableFromArray,Ke as renderCommandIndex,Te as renderExamplesDefault,ge as renderOptionsList,U as renderOptionsListFromArray,he as renderOptionsTable,H as renderOptionsTableFromArray,ye as renderSubcommandsTable,we as renderSubcommandsTableFromArray,se as renderUsage,s as resolveLazyCommand,ie as rootFooterEndMarker,re as rootFooterStartMarker,ne as rootHeaderEndMarker,te as rootHeaderStartMarker,F as sectionEndMarker,P as sectionStartMarker,K as writeFile};
@@ -0,0 +1 @@
1
+ import{t as e}from"./dynamic-Hg5BDHzz.js";export{e as createDynamicCompleteCommand};
@@ -0,0 +1,6 @@
1
+ import{i as e,o as t}from"./registry-BEz5iex_.js";import{a as n,l as r,n as i}from"./schema-extractor-DFawzmtj.js";import{n as a}from"./command-BXsTrIgI.js";import{c as o,i as s}from"./subcommand-router-iqmWGZyU.js";import{i as c,s as l}from"./argv-parser-BRSUT6IV.js";import{t as u}from"./schema--6eHVfwR.js";import{execSync as d}from"node:child_process";function f(e,t,n){return{fieldName:e.name,isArrayOption:e.valueType===`array`,isGlobal:e.isGlobal===!0,resolvedDeps:m(e.valueCompletion,e.isGlobal===!0,t,n)}}function p(e,t,n){return{fieldName:e.name,isArrayOption:!1,isGlobal:!1,resolvedDeps:m(e.valueCompletion,!1,t,n)}}function m(e,t,n,r=[]){if(e?.type!==`expand`)return[];let i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set;for(let e of n)e.isGlobal===!0?i.add(e.name):a.add(e.name);for(let e of r)a.add(e.name);return e.dependsOn.map(e=>({name:e,isGlobal:t||i.has(e)&&!a.has(e)}))}function h(e){let t=`$'`;for(let n of e){let e=n.codePointAt(0);t+=n===`\\`?`\\\\`:n===`'`?`\\'`:n===`
2
+ `?`\\n`:n===`\r`?`\\r`:n===` `?`\\t`:e<32||e===127?`\\x${e.toString(16).padStart(2,`0`)}`:n}return t+=`'`,t}function g(e){return`'${e.replace(/'/g,`'\\''`)}'`}function _(e,t){let n=t.withSize?`%Y:%s`:`%Y`,r=t.withSize?`%m:%z`:`%m`,i=`stat -L -c '${n}' "${e}" 2>/dev/null`,a=`stat -L -f '${r}' "${e}" 2>/dev/null`;return t.shell===`fish`?`(${i}; or ${a})`:`$(${i} || ${a})`}function v(e){return e.length===1?`-${e}`:`--${e}`}function y(e,n){b(e,v(n)),n.length===1?b(e,`--${n}`):n.includes(`-`)&&b(e,`--${t(n)}`)}function b(e,t){e.includes(t)||e.push(t)}function x(e,n){let r=[`--${e}`];e.length===1&&r.push(`-${e}`),e.includes(`-`)&&r.push(`--${t(e)}`);for(let e of n??[])y(r,e);return r}function S(e){let t=/* @__PURE__ */ new Set;for(let n of e)if(n.isGlobal===!0){n.cliName.length===1&&t.add(`-${n.cliName}`);for(let e of n.alias??[])e.length===1&&t.add(`-${e}`)}return t}function C(e,n,r,i){let a=new Set(x(e,n));if(r&&(a.add(`--${r}`),r.includes(`-`)&&a.add(`--${t(r)}`)),i?.frameOptions){if(i.isGlobal===!0){for(let e of i.frameOptions)if(e.isGlobal!==!0)for(let t of D(e.cliName,e.alias))a.delete(t)}else{let e=S(i.frameOptions);if(e.size>0){let t=new Set((n??[]).filter(e=>e.length===1).map(e=>`-${e}`));for(let n of e)t.has(n)||a.delete(n)}}}return[...a].map(e=>`"${e}"`)}function w(e,t){return e.map(e=>{let n=t.find(t=>t.isGlobal!==!0&&t.name===e.name);return n&&C(n.cliName,n.alias,n.negation,{frameOptions:t})})}function T(e,t,n,r=`$_pos_count`){let i=w(e,t);if(i.every(e=>e===void 0))return;let a=[` local _slot=-1 _left=${r}`];return e.forEach((e,t)=>{let r=i[t],o=r?` && __${n}_not_used ${r.join(` `)}`:``,s=e.variadic?`_slot=${e.position}`:`if (( _left == 0 )); then _slot=${e.position}; else (( _left-- )); fi`;a.push(` if (( _slot < 0 ))${o}; then ${s}; fi`)}),a}function E(e,t){let n=[`__${e}_track_positionals() {`,` local _k=0 _w`,' for _w in "${_pos_words[@]}"; do',` local _slot=$_k`,` case "$_subcmd" in`];for(let r of t){n.push(` ${r.pathStrs.map(e=>`"${e}"`).join(`|`)})`);for(let t of T(r.positionals,r.options,e,`$_k`)??[])n.push(` ${t}`);n.push(` ;;`)}return n.push(` esac`,` __${e}_track_pos "$_subcmd" "$_slot" "$_w"`,` (( _k++ ))`,` done`,`}`,``),n}function D(e,n){let r=[`--${e}`];e.includes(`-`)&&r.push(`--${t(e)}`);for(let e of n??[])y(r,e);return r}function O(e){let t=e.completion;if(t?.custom){let n=t.custom,r=[];if(n.expand&&r.push(`expand`),n.resolve&&r.push(`resolve`),n.choices&&n.choices.length>0&&r.push(`choices`),n.shellCommand&&r.push(`shellCommand`),r.length>1)throw Error(`Field "${e.name??`<unknown>`}": completion.custom may only specify one of choices, shellCommand, resolve, expand (got ${r.join(`, `)}).`);if(n.expand)return{type:`pending-expand`,spec:n.expand};if(n.resolve)return{type:`dynamic`,resolve:n.resolve};if(n.choices&&n.choices.length>0)return{type:`choices`,choices:n.choices};if(n.shellCommand)return{type:`command`,shellCommand:n.shellCommand}}if(t?.type){if(t.type===`file`)return t.matcher?{type:`file`,matcher:t.matcher}:t.extensions?{type:`file`,extensions:t.extensions}:{type:`file`};if(t.type===`directory`)return{type:`directory`};if(t.type===`none`)return{type:`none`}}if(e.enumValues&&e.enumValues.length>0)return{type:`choices`,choices:e.enumValues}}function k(e){if(e)return e.type===`pending-expand`?{type:`runtime-expand`,dependsOn:e.spec.dependsOn,enumerate:e.spec.enumerate}:e}function ee(e){return e.args?A(e.args):[]}function A(e){return n(i(e)).map(j)}function j(t){let n=e(t);return{name:t.name,cliName:t.cliName,alias:n.length>0?n:void 0,negation:t.negationDisplay,negationDescription:t.negationDescription,description:t.description,takesValue:t.type!==`boolean`,valueType:t.type,required:t.required,defaultNegationAccepted:t.type===`boolean`&&t.negation===!0,valueCompletion:k(O(t))}}function M(e){return new Set(x(e.cliName,e.alias))}function te(e,t){let n=M(t);for(let t of e)for(let e of M(t))if(n.has(e))return t}function ne(e,t,n){let r=/* @__PURE__ */ new Set;if(t.length===0)return r;let i=/* @__PURE__ */ new Set,a=(e,t)=>{U(n,e,t,i),r.add(e.name)},o=0;for(;o<e.length;){let i=e[o];if(i===`--`||!i.startsWith(`-`))break;if(!i.startsWith(`--`)&&i.length>2){let e=i.indexOf(`=`);if((e>=0?i.slice(1,e):i.slice(1)).length>1)break}let s=L(i),c=G(t,s);if(!c){if(ce(t,s)){o++;continue}break}if(c.takesValue){if(R(i)){let e=i.indexOf(`=`);a(c,i.slice(e+1)),o++}else if(o+1<e.length){let t=e[o+1];if(t.startsWith(`-`)){o++;continue}a(c,t),o+=2}else break}else{let e=z(c,s,i);e!==void 0&&(n[c.name]=e),r.add(c.name),o++}}return r}function re(e,t){return t.valueType===`array`?Array.isArray(e)?e:[e]:Array.isArray(e)?e.at(-1):e}function N(e,t){return t.length===0?e:[...e,...t]}function P(e,t){let n=t.length-1;if(!(n<0))return e>n?n:e}function F(e,t){return n=>{let r={...e};return c(n,e).forEach((e,n)=>{n<t.length&&(r[e.name]=t[n])}),r}}function ie(e,t,n){if(!e.args)return;let a=i(e.args),o=r(a,F(t,n));if(o!==a)return o.fields.filter(e=>e.named).map(j)}function ae(e,t,n){if(!e.args)return[];let a=r(i(e.args),F(t,n));return c(a,t).map((e,t)=>({name:e.name,cliName:e.cliName,position:t,description:e.description,required:e.required,variadic:e.type===`array`,valueCompletion:k(O(e))}))}function oe(e){if(!e.subCommands)return[];let t=[];for(let[n,r]of Object.entries(e.subCommands)){if(n.startsWith(`__`))continue;t.push(n);let e=o(r);e?.aliases&&t.push(...e.aliases)}return t}function se(e,t){if(!e.subCommands)return null;let n=Object.hasOwn(e.subCommands,t)?e.subCommands[t]:void 0;if(n)return o(n);let r=s(e,t);return r?o(e.subCommands[r]):null}function I(e){return e.startsWith(`-`)}function L(e){if(e.startsWith(`--`)){let t=e.slice(2),n=t.indexOf(`=`);return{name:n>=0?t.slice(0,n):t,isLong:!0}}return e.startsWith(`-`)?{name:e.slice(1,2),isLong:!1}:{name:e,isLong:!0}}function R(e){return e.includes(`=`)}function z(e,t,n){let r=le(e,t);return R(n)?r?void 0:l(n.slice(n.indexOf(`=`)+1)):!r}function B(e,n,r){if(!r||e.valueType!==`boolean`)return!1;let i=[e.cliName,...e.alias??[]];for(let e of i){let r=`no-${e}`;if(n===r||n===t(r))return!0}return!1}function V(e,t,n){return e.defaultNegationAccepted===!0&&B(e,t,n)}function ce(e,t){return e.some(e=>e.defaultNegationAccepted!==!0&&B(e,t.name,t.isLong))}function H(e,n){return e!==void 0&&e.includes(`-`)&&t(e)===n}function U(e,t,n,r){if(t.valueType!==`array`){e[t.name]=n;return}if(r.has(t.name)){let r=e[t.name];e[t.name]=Array.isArray(r)?[...r,n]:[n]}else e[t.name]=[n],r.add(t.name)}function le(e,t){return t.isLong?e.negation!==void 0&&(e.negation===t.name||H(e.negation,t.name))?!0:V(e,t.name,t.isLong):!1}function W(e,t,n){if(e.cliName===t&&(n||e.cliName.length===1))return!0;if(e.alias){for(let r of e.alias)if(r===t&&(n||r.length===1))return!0}return n&&e.negation===t?!0:!n||t.length<=1?!1:H(e.cliName,t)||e.alias?.some(e=>H(e,t))?!0:H(e.negation,t)}function G(e,t){if(!t.isLong){let n=e.find(e=>e.isGlobal!==!0&&e.alias?.includes(t.name)===!0);if(n)return n;let r=e.find(e=>e.isGlobal===!0&&W(e,t.name,t.isLong));if(r)return r}return e.find(e=>W(e,t.name,t.isLong))||e.find(e=>V(e,t.name,t.isLong))}function K(e,t,n){let r=q(e,t,n);return r.variantOptions?q(e,t,n,{command:r.context.currentCommand,options:r.variantOptions}).context:r.context}function q(e,t,n,r){let i=e=>e===r?.command?r.options:ee(e),a=t,o=[],s=n?A(n).map(e=>({...e,isGlobal:!0})):[],c=/* @__PURE__ */ new Set,l=!1,u=0,d={},f=[],p={},m=/* @__PURE__ */ new Set,h=0,g=/* @__PURE__ */ new Set,_=e=>{c.add(e.cliName);for(let t of e.alias??[])c.add(t);e.negation&&c.add(e.negation),l=!0},v=(e,t)=>{U(e.isGlobal===!0?p:d,e,t,g)},y=(e,t,n=``)=>{let r=e.isGlobal===!0?p:d,i=z(e,t,n);i!==void 0&&(r[e.name]=i)},b=0,x=N(i(a),s),S=!1;for(;b<e.length-1;){let t=e[b];if(!S&&t===`--`){S=!0,b++;continue}if(!S&&t.startsWith(`-`)&&!t.startsWith(`--`)&&t.length>2&&!t.includes(`=`)){l=!0;let e=Array.from(t.slice(1)),n=x.filter(e=>e.isGlobal!==!0);for(let t of e){let e=G(n,{name:t,isLong:!1});e&&!e.takesValue&&(_(e),y(e,{name:t,isLong:!1}))}b++;continue}if(!S&&I(t)){l=!0;let n=L(t),r=G(x,n);if(r){if(_(r),r.takesValue){if(R(t)){let e=t.indexOf(`=`);v(r,t.slice(e+1))}else if(b+1<e.length-1){let t=e[b+1];I(t)||(v(r,t),b++)}}else y(r,n,t)}b++;continue}let n=S?null:se(a,t);if(n){o.push(t);let r=i(a),l=e.slice(h,b);for(let e of ne(l,s,p))m.add(e);a=n,x=N(i(a),s);for(let e of Object.keys(d)){let t=r.find(t=>t.name===e),n=s.find(t=>t.name===e)??(t?te(s,t):void 0);n&&(m.has(n.name)||(p[n.name]=re(d[e],n)))}c.clear(),u=0,d={},f=[],g=/* @__PURE__ */ new Set,h=b+1,b++;continue}f.push(t),u++,b++}let C=e[e.length-1]??``,w=e[e.length-2]??``,T=ie(a,d,f),E=ae(a,d,f),D=oe(a);for(let e=0;e<E.length;e++){let t=E[e];if(t.variadic){d[t.name]=f.slice(e);break}e<f.length&&(d[t.name]=f[e])}let O,k,j;if(!S&&w&&I(w)&&!R(w)){let e=G(x,L(w));e&&e.takesValue?(O=`option-value`,k=e):C.startsWith(`-`)?O=`option-name`:(O=J(C,D,E,u),O===`positional`&&(j=u))}else if(!S&&C.startsWith(`-`)&&R(C)){let e=G(x,L(C));e&&e.takesValue?(O=`option-value`,k=e):O=`option-name`}else!S&&C.startsWith(`-`)?O=`option-name`:(O=J(C,D,E,u,S),O===`positional`&&(j=u));let M=[];if(k){if(k.valueType===`array`){let e=(k.isGlobal===!0?p:d)[k.name];M=Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}}else if(O===`positional`&&j!==void 0){let e=P(j,E);e!==void 0&&E[e]?.variadic&&(M=f.slice(e))}let F={...p,...d};return{context:{subcommandPath:o,currentCommand:a,currentWord:C,previousWord:w,completionType:O,targetOption:k,positionalIndex:j,options:x,subcommands:D,positionals:E,usedOptions:c,hasAnyOptionBeenUsed:l,providedPositionalCount:u,parsedArgs:F,previousValues:M},variantOptions:T}}function J(e,t,n,r,i){return i?`positional`:t.length>0&&(t.filter(t=>t.startsWith(e)).length>0||e===``)?`subcommand`:r<n.length||n.length>0&&n[n.length-1].variadic?`positional`:`subcommand`}const Y={Default:0,NoSpace:1,NoFileCompletion:2,FilterPrefix:4,KeepOrder:8,FileCompletion:16,DirectoryCompletion:32,Error:64};function X(e){if(!e.startsWith(`-`))return;let t=e.indexOf(`=`);if(!(t<=0))return e.slice(0,t+1)}async function ue(e,t){switch(e.completionType){case`subcommand`:return ye(e);case`option-name`:return be(e);case`option-value`:{let n=e.targetOption,r=n?X(e.currentWord):void 0;return Ce(r?{...e,currentWord:e.currentWord.slice(r.length)}:e,t,n?.name,n?.valueCompletion,void 0,n?.valueType===`array`)}case`positional`:{let n=de(e);return n?Ce(e,t,n.name,n.valueCompletion,n.description,!1):{candidates:[],directive:Y.NoFileCompletion}}}}function de(e){let t=e.positionalIndex??0,n=P(t,e.positionals);if(n===void 0)return;let r=e.positionals[n];if(r)return n===t||r.variadic?r:void 0}function fe(e){try{return d(e,{encoding:`utf-8`,timeout:5e3}).split(`
3
+ `).map(e=>e.trim()).filter(e=>e.length>0).map(e=>({value:e,type:`value`}))}catch{return[]}}function Z(e){return e?.type===`choices`?e.choices:void 0}function pe(e,t){let n=e.options.find(e=>e.name===t&&e.isGlobal!==!0);if(n)return Z(n.valueCompletion);let r=e.positionals.find(e=>e.name===t);return Z(r?r.valueCompletion:e.options.find(e=>e.name===t&&e.isGlobal===!0)?.valueCompletion)}function me(e,t){let n=!t.includes(`=`),r=n?he(e):ge(e,t);return{candidates:r,hasEqSuffix:n&&r.some(e=>e.value.endsWith(`=`))}}function he(e){let t=/* @__PURE__ */ new Set,n=[];for(let r of e){let e=r.value.indexOf(`=`);if(e<=0){n.push(r);continue}let i=r.value.slice(0,e+1);t.has(i)||(t.add(i),n.push({...r,value:i}))}return n}function ge(e,t){let n=t.slice(0,t.indexOf(`=`)+1);return e.filter(e=>e.value!==n)}async function _e(e,t,n,r,i){let a=[],o=Y.FilterPrefix,s,c;switch(e.type){case`choices`:if(e.choices)for(let t of e.choices)a.push({value:t,description:r,type:`value`});o|=Y.NoFileCompletion;break;case`file`:e.matcher&&e.matcher.length>0?(c=e.matcher.filter(e=>e.trim().length>0),c.length===0&&(c=void 0,o|=Y.FileCompletion)):e.extensions&&e.extensions.length>0?(s=Array.from(new Set(e.extensions.map(e=>e.trim().replace(/^\./,``)).filter(e=>e.length>0))),s.length===0&&(s=void 0,o|=Y.FileCompletion)):o|=Y.FileCompletion;break;case`directory`:o|=Y.DirectoryCompletion;break;case`command`:e.shellCommand&&a.push(...fe(e.shellCommand)),o|=Y.NoFileCompletion;break;case`none`:o|=Y.NoFileCompletion;break;case`dynamic`:try{let n=await e.resolve(t);for(let e of n.candidates){let t=typeof e==`string`?{value:e}:e;a.push({...t,type:`value`})}o=n.directive??Y.FilterPrefix|Y.NoFileCompletion}catch{o=Y.NoFileCompletion|Y.Error}break;case`expand`:o|=Y.NoFileCompletion;break;case`runtime-expand`:{let r={},i=!1;for(let a of e.dependsOn){let e=t.parsedArgs[a],o=Array.isArray(e)?e[e.length-1]:e,s=pe(n,a);if(typeof o!=`string`||s===void 0||!s.includes(o)){i=!0;break}r[a]=o}if(!i)try{let t=/* @__PURE__ */ new Set;for(let n of e.enumerate(r)){let e=typeof n==`string`?{value:n}:n;t.has(e.value)||(t.add(e.value),a.push({...e,type:`value`}))}}catch{o=Y.NoFileCompletion|Y.Error;break}o|=Y.NoFileCompletion;break}}if(e.type===`dynamic`||e.type===`expand`||e.type===`runtime-expand`){let n=me(e.type===`runtime-expand`&&i===!0?ve(a,t.previousValues):a,t.currentWord);return n.hasEqSuffix&&(o|=Y.NoSpace),{candidates:n.candidates,directive:o,fileExtensions:s,fileMatchers:c}}return{candidates:a,directive:o,fileExtensions:s,fileMatchers:c}}function ve(e,t){let n=/* @__PURE__ */ new Set;for(let e of t){let t=e.indexOf(`=`);t>0&&n.add(e.slice(0,t))}return n.size===0?[...e]:e.filter(e=>{let t=e.value.indexOf(`=`);return t<=0||!n.has(e.value.slice(0,t))})}function ye(e){let t=[];for(let n of e.subcommands){let r=e.currentCommand.subCommands,i=r?.[n],a=i?void 0:s(e.currentCommand,n),c=i??(a?r?.[a]:void 0),l=c?o(c)?.description:void 0;t.push({value:n,description:l,type:`subcommand`})}if(t.length===0||e.currentWord.startsWith(`-`)){let n=be(e);t.push(...n.candidates)}return{candidates:t,directive:Y.FilterPrefix|Y.NoFileCompletion}}function be(e){let t=[],n=e.options.filter(t=>t.valueType===`array`||!(e.usedOptions.has(t.cliName)||t.alias&&t.alias.some(t=>e.usedOptions.has(t))||t.negation&&e.usedOptions.has(t.negation)));for(let e of n)t.push({value:`--${e.cliName}`,description:e.description,type:`option`}),e.negation&&t.push({value:`--${e.negation}`,description:e.negationDescription??e.description,type:`option`});return e.hasAnyOptionBeenUsed||t.push({value:`--help`,description:`Show help information`,type:`option`},{value:`--help-all`,description:`Show help with all subcommand options`,type:`option`},{value:`--help-json`,description:`Show help as JSON`,type:`option`}),{candidates:t,directive:Y.FilterPrefix|Y.NoFileCompletion}}function xe(e,t,n){return{currentWord:e.currentWord,shell:t.shell,parsedArgs:Se(e.parsedArgs,n),previousValues:e.previousValues,subcommandPath:e.subcommandPath}}function Se(e,t){if(t===void 0||!(t in e))return e;let n={...e};return delete n[t],n}async function Ce(e,t,n,r,i,a){return r?_e(r,xe(e,t,n),e,i,a):{candidates:[],directive:Y.FilterPrefix}}function Q(e,t){switch(t.shell){case`bash`:return we(e,t);case`zsh`:return Te(e,t);case`fish`:return Ee(e,t)}}function $(e,t){let n=`:${t.directive}`;t.fileExtensions&&t.fileExtensions.length>0&&(n+=`\t@ext:${t.fileExtensions.join(`,`)}`),t.fileMatchers&&t.fileMatchers.length>0&&(n+=`\t@matcher:${t.fileMatchers.join(`,`)}`),e.push(n)}function we(e,t){let n=((e.directive&Y.FilterPrefix)!==0&&t.currentWord?e.candidates.filter(e=>e.value.startsWith(t.currentWord)):e.candidates).map(e=>t.inlinePrefix?`${t.inlinePrefix}${e.value}`:e.value);return $(n,e),n.join(`
4
+ `)}function Te(e,t){let n=e.candidates.map(e=>{let t=e.value.replace(/:/g,`\\:`);return e.description?`${t}:${e.description.replace(/:/g,`\\:`)}`:t});return $(n,e),n.join(`
5
+ `)}function Ee(e,t){let n=e.candidates.map(e=>e.description?`${e.value}\t${e.description}`:e.value);return $(n,e),n.join(`
6
+ `)}function De(e,t,n){return a({name:`__complete`,args:u,async run(t){let r=K(t.args,e,n),i=r.completionType===`option-value`&&r.targetOption?X(r.currentWord):void 0,a=i?r.currentWord.slice(i.length):r.currentWord,o=Q(await ue(r,{shell:t.shell}),{shell:t.shell,currentWord:a,inlinePrefix:i});console.log(o)}})}function Oe(e){return!!e.subCommands?.__complete}export{C as _,ue as a,h as c,D as d,w as f,E as g,T as h,Y as i,x as l,p as m,Oe as n,K as o,f as p,Q as r,O as s,De as t,S as u,g as v,_ as y};
@@ -0,0 +1,3 @@
1
+ import{builtinModules as e}from"node:module";import t,{realpathSync as n,statSync as r}from"node:fs";import i from"node:path";import{fileURLToPath as a,pathToFileURL as o}from"node:url";import{format as s,inspect as c}from"node:util";import l from"node:assert";import u from"node:process";import d from"node:v8";const f={}.hasOwnProperty,ee=/^([A-Z][a-z\d]*)+$/,te=/* @__PURE__ */ new Set([`string`,`function`,`number`,`object`,`Function`,`Object`,`boolean`,`bigint`,`symbol`]),p={};function m(e,t=`and`){return e.length<3?e.join(` ${t} `):`${e.slice(0,-1).join(`, `)}, ${t} ${e[e.length-1]}`}const h=/* @__PURE__ */ new Map;let g;p.ERR_INVALID_ARG_TYPE=_(`ERR_INVALID_ARG_TYPE`,(e,t,n)=>{l.ok(typeof e==`string`,`'name' must be a string`),Array.isArray(t)||(t=[t]);let r=`The `;if(e.endsWith(` argument`))r+=`${e} `;else{let t=e.includes(`.`)?`property`:`argument`;r+=`"${e}" ${t} `}r+=`must be `;let i=[],a=[],o=[];for(let e of t)l.ok(typeof e==`string`,`All expected entries have to be of type string`),te.has(e)?i.push(e.toLowerCase()):ee.exec(e)===null?(l.ok(e!==`object`,`The value "object" should be written as "Object"`),o.push(e)):a.push(e);if(a.length>0){let e=i.indexOf(`object`);e!==-1&&(i.slice(e,1),a.push(`Object`))}return i.length>0&&(r+=`${i.length>1?`one of type`:`of type`} ${m(i,`or`)}`,(a.length>0||o.length>0)&&(r+=` or `)),a.length>0&&(r+=`an instance of ${m(a,`or`)}`,o.length>0&&(r+=` or `)),o.length>0&&(o.length>1?r+=`one of ${m(o,`or`)}`:(o[0].toLowerCase()!==o[0]&&(r+=`an `),r+=`${o[0]}`)),r+=`. Received ${b(n)}`,r},TypeError),p.ERR_INVALID_MODULE_SPECIFIER=_(`ERR_INVALID_MODULE_SPECIFIER`,(e,t,n=void 0)=>`Invalid module "${e}" ${t}${n?` imported from ${n}`:``}`,TypeError),p.ERR_INVALID_PACKAGE_CONFIG=_(`ERR_INVALID_PACKAGE_CONFIG`,(e,t,n)=>`Invalid package config ${e}${t?` while importing ${t}`:``}${n?`. ${n}`:``}`,Error),p.ERR_INVALID_PACKAGE_TARGET=_(`ERR_INVALID_PACKAGE_TARGET`,(e,t,n,r=!1,i=void 0)=>{let a=typeof n==`string`&&!r&&n.length>0&&!n.startsWith(`./`);return t===`.`?(l.ok(r===!1),`Invalid "exports" main target ${JSON.stringify(n)} defined in the package config ${e}package.json${i?` imported from ${i}`:``}${a?`; targets must start with "./"`:``}`):`Invalid "${r?`imports`:`exports`}" target ${JSON.stringify(n)} defined for '${t}' in the package config ${e}package.json${i?` imported from ${i}`:``}${a?`; targets must start with "./"`:``}`},Error),p.ERR_MODULE_NOT_FOUND=_(`ERR_MODULE_NOT_FOUND`,(e,t,n=!1)=>`Cannot find ${n?`module`:`package`} '${e}' imported from ${t}`,Error),p.ERR_NETWORK_IMPORT_DISALLOWED=_(`ERR_NETWORK_IMPORT_DISALLOWED`,`import of '%s' by %s is not supported: %s`,Error),p.ERR_PACKAGE_IMPORT_NOT_DEFINED=_(`ERR_PACKAGE_IMPORT_NOT_DEFINED`,(e,t,n)=>`Package import specifier "${e}" is not defined${t?` in package ${t}package.json`:``} imported from ${n}`,TypeError),p.ERR_PACKAGE_PATH_NOT_EXPORTED=_(`ERR_PACKAGE_PATH_NOT_EXPORTED`,(e,t,n=void 0)=>t===`.`?`No "exports" main defined in ${e}package.json${n?` imported from ${n}`:``}`:`Package subpath '${t}' is not defined by "exports" in ${e}package.json${n?` imported from ${n}`:``}`,Error),p.ERR_UNSUPPORTED_DIR_IMPORT=_(`ERR_UNSUPPORTED_DIR_IMPORT`,`Directory import '%s' is not supported resolving ES modules imported from %s`,Error),p.ERR_UNSUPPORTED_RESOLVE_REQUEST=_(`ERR_UNSUPPORTED_RESOLVE_REQUEST`,`Failed to resolve module specifier "%s" from "%s": Invalid relative URL or base scheme is not hierarchical.`,TypeError),p.ERR_UNKNOWN_FILE_EXTENSION=_(`ERR_UNKNOWN_FILE_EXTENSION`,(e,t)=>`Unknown file extension "${e}" for ${t}`,TypeError),p.ERR_INVALID_ARG_VALUE=_(`ERR_INVALID_ARG_VALUE`,(e,t,n=`is invalid`)=>{let r=c(t);return r.length>128&&(r=`${r.slice(0,128)}...`),`The ${e.includes(`.`)?`property`:`argument`} '${e}' ${n}. Received ${r}`},TypeError);function _(e,t,n){return h.set(e,t),ne(n,e)}function ne(e,t){return n;function n(...n){let r=Error.stackTraceLimit;v()&&(Error.stackTraceLimit=0);let i=new e;v()&&(Error.stackTraceLimit=r);let a=ie(t,n,i);return Object.defineProperties(i,{message:{value:a,enumerable:!1,writable:!0,configurable:!0},toString:{value(){return`${this.name} [${t}]: ${this.message}`},enumerable:!1,writable:!0,configurable:!0}}),y(i),i.code=t,i}}function v(){try{if(d.startupSnapshot.isBuildingSnapshot())return!1}catch{}let e=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return e===void 0?Object.isExtensible(Error):f.call(e,`writable`)&&e.writable!==void 0?e.writable:e.set!==void 0}function re(e){let t=`__node_internal_`+e.name;return Object.defineProperty(e,"name",{value:t}),e}const y=re(function(e){let t=v();return t&&(g=Error.stackTraceLimit,Error.stackTraceLimit=1/0),Error.captureStackTrace(e),t&&(Error.stackTraceLimit=g),e});function ie(e,t,n){let r=h.get(e);if(l.ok(r!==void 0,"expected `message` to be found"),typeof r==`function`)return l.ok(r.length<=t.length,`Code: ${e}; The provided arguments length (${t.length}) does not match the required ones (${r.length}).`),Reflect.apply(r,n,t);let i=/%[dfijoOs]/g,a=0;for(;i.exec(r)!==null;)a++;return l.ok(a===t.length,`Code: ${e}; The provided arguments length (${t.length}) does not match the required ones (${a}).`),t.length===0?r:(t.unshift(r),Reflect.apply(s,null,t))}function b(e){if(e==null)return String(e);if(typeof e==`function`&&e.name)return`function ${e.name}`;if(typeof e==`object`)return e.constructor&&e.constructor.name?`an instance of ${e.constructor.name}`:`${c(e,{depth:-1})}`;let t=c(e,{colors:!1});return t.length>28&&(t=`${t.slice(0,25)}...`),`type ${typeof e} (${t})`}const x={}.hasOwnProperty,{ERR_INVALID_PACKAGE_CONFIG:ae}=p,S=/* @__PURE__ */ new Map;function C(e,{base:n,specifier:r}){let o=S.get(e);if(o)return o;let s;try{s=t.readFileSync(i.toNamespacedPath(e),`utf8`)}catch(e){let t=e;if(t.code!==`ENOENT`)throw t}let c={exists:!1,pjsonPath:e,main:void 0,name:void 0,type:`none`,exports:void 0,imports:void 0};if(s!==void 0){let t;try{t=JSON.parse(s)}catch(t){let i=t,o=new ae(e,(n?`"${r}" from `:``)+a(n||r),i.message);throw o.cause=i,o}c.exists=!0,x.call(t,`name`)&&typeof t.name==`string`&&(c.name=t.name),x.call(t,`main`)&&typeof t.main==`string`&&(c.main=t.main),x.call(t,`exports`)&&(c.exports=t.exports),x.call(t,`imports`)&&(c.imports=t.imports),x.call(t,`type`)&&(t.type===`commonjs`||t.type===`module`)&&(c.type=t.type)}return S.set(e,c),c}function w(e){let t=new URL(`package.json`,e);for(;!t.pathname.endsWith(`node_modules/package.json`);){let n=C(a(t),{specifier:e});if(n.exists)return n;let r=t;if(t=new URL(`../package.json`,t),t.pathname===r.pathname)break}return{pjsonPath:a(t),exists:!1,type:`none`}}function T(e){return w(e).type}const{ERR_UNKNOWN_FILE_EXTENSION:oe}=p,se={}.hasOwnProperty,ce={__proto__:null,".cjs":`commonjs`,".js":`module`,".json":`json`,".mjs":`module`};function le(e){return e&&/\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(e)?`module`:e===`application/json`?`json`:null}const E={__proto__:null,"data:":ue,"file:":fe,"http:":D,"https:":D,"node:"(){return`builtin`}};function ue(e){let{1:t}=/^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(e.pathname)||[null,null,null];return le(t)}function de(e){let t=e.pathname,n=t.length;for(;n--;){let e=t.codePointAt(n);if(e===47)return``;if(e===46)return t.codePointAt(n-1)===47?``:t.slice(n)}return``}function fe(e,t,n){let r=de(e);if(r===`.js`){let t=T(e);return t===`none`?`commonjs`:t}if(r===``){let t=T(e);return t===`none`||t===`commonjs`?`commonjs`:`module`}let i=ce[r];if(i)return i;if(n)return;let o=a(e);throw new oe(r,o)}function D(){}function O(e,t){let n=e.protocol;return se.call(E,n)&&E[n](e,t,!0)||null}const{ERR_INVALID_ARG_VALUE:pe}=p,k=Object.freeze([`node`,`import`]),me=new Set(k);function he(){return k}function ge(){return me}function A(e){if(e!==void 0&&e!==he()){if(!Array.isArray(e))throw new pe(`conditions`,e,`expected an array`);return new Set(e)}return ge()}const j=RegExp.prototype[Symbol.replace],{ERR_NETWORK_IMPORT_DISALLOWED:M,ERR_INVALID_MODULE_SPECIFIER:N,ERR_INVALID_PACKAGE_CONFIG:P,ERR_INVALID_PACKAGE_TARGET:_e,ERR_MODULE_NOT_FOUND:F,ERR_PACKAGE_IMPORT_NOT_DEFINED:I,ERR_PACKAGE_PATH_NOT_EXPORTED:ve,ERR_UNSUPPORTED_DIR_IMPORT:ye,ERR_UNSUPPORTED_RESOLVE_REQUEST:L}=p,R={}.hasOwnProperty,z=/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i,B=/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i,be=/^\.|%|\\/,V=/\*/g,xe=/%2f|%5c/i,H=/* @__PURE__ */ new Set,Se=/[/\\]{2}/;function U(e,t,n,r,i,o,s){if(u.noDeprecation)return;let c=a(r),l=Se.exec(s?e:t)!==null;u.emitWarning(`Use of deprecated ${l?`double slash`:`leading or trailing slash matching`} resolving "${e}" for module request "${t}" ${t===n?``:`matched to "${n}" `}in the "${i?`imports`:`exports`}" field module resolution of the package at ${c}${o?` imported from ${a(o)}`:``}.`,`DeprecationWarning`,`DEP0166`)}function W(e,t,n,r){if(u.noDeprecation||O(e,{parentURL:n.href})!==`module`)return;let o=a(e.href),s=a(new URL(`.`,t)),c=a(n);r?i.resolve(s,r)!==o&&u.emitWarning(`Package ${s} has a "main" field set to "${r}", excluding the full filename and extension to the resolved file at "${o.slice(s.length)}", imported from ${c}.\n Automatic extension resolution of the "main" field is deprecated for ES modules.`,`DeprecationWarning`,`DEP0151`):u.emitWarning(`No "main" or "exports" field defined in the package.json for ${s} resolving the main entry point "${o.slice(s.length)}", imported from ${c}.\nDefault "index" lookups for the main are deprecated for ES modules.`,`DeprecationWarning`,`DEP0151`)}function G(e){try{return r(e)}catch{}}function K(e){let t=r(e,{throwIfNoEntry:!1});return(t?t.isFile():void 0)??!1}function Ce(e,t,n){let r;if(t.main!==void 0){if(r=new URL(t.main,e),K(r))return r;let i=[`./${t.main}.js`,`./${t.main}.json`,`./${t.main}.node`,`./${t.main}/index.js`,`./${t.main}/index.json`,`./${t.main}/index.node`],a=-1;for(;++a<i.length&&(r=new URL(i[a],e),!K(r));)r=void 0;if(r)return W(r,e,n,t.main),r}let i=[`./index.js`,`./index.json`,`./index.node`],o=-1;for(;++o<i.length&&(r=new URL(i[o],e),!K(r));)r=void 0;if(r)return W(r,e,n,t.main),r;throw new F(a(new URL(`.`,e)),a(n))}function we(e,t,r){if(xe.exec(e.pathname)!==null)throw new N(e.pathname,`must not include encoded "/" or "\\" characters`,a(t));let s;try{s=a(e)}catch(n){let r=n;throw Object.defineProperty(r,"input",{value:String(e)}),Object.defineProperty(r,"module",{value:String(t)}),r}let c=G(s.endsWith(`/`)?s.slice(-1):s);if(c&&c.isDirectory()){let n=new ye(s,a(t));throw n.url=String(e),n}if(!c||!c.isFile()){let n=new F(s||e.pathname,t&&a(t),!0);throw n.url=String(e),n}if(!r){let t=n(s),{search:r,hash:a}=e;e=o(t+(s.endsWith(i.sep)?`/`:``)),e.search=r,e.hash=a}return e}function Te(e,t,n){return new I(e,t&&a(new URL(`.`,t)),a(n))}function q(e,t,n){return new ve(a(new URL(`.`,t)),e,n&&a(n))}function Ee(e,t,n,r,i){let o=`request is not a valid match in pattern "${t}" for the "${r?`imports`:`exports`}" resolution of ${a(n)}`;throw new N(e,o,i&&a(i))}function J(e,t,n,r,i){return t=typeof t==`object`&&t?JSON.stringify(t,null,``):`${t}`,new _e(a(new URL(`.`,n)),e,t,r,i&&a(i))}function De(e,t,n,r,i,a,o,s,c){if(t!==``&&!a&&e[e.length-1]!==`/`)throw J(n,e,r,o,i);if(!e.startsWith(`./`)){if(o&&!e.startsWith(`../`)&&!e.startsWith(`/`)){let n=!1;try{new URL(e),n=!0}catch{}if(!n)return Q(a?j.call(V,e,()=>t):e+t,r,c)}throw J(n,e,r,o,i)}if(z.exec(e.slice(2))!==null){if(B.exec(e.slice(2))===null){if(!s){let s=a?n.replace(`*`,()=>t):n+t;U(a?j.call(V,e,()=>t):e,s,n,r,o,i,!0)}}else throw J(n,e,r,o,i)}let l=new URL(e,r),u=l.pathname,d=new URL(`.`,r).pathname;if(!u.startsWith(d))throw J(n,e,r,o,i);if(t===``)return l;if(z.exec(t)!==null){let c=a?n.replace(`*`,()=>t):n+t;B.exec(t)===null?s||U(a?j.call(V,e,()=>t):e,c,n,r,o,i,!1):Ee(c,n,r,o,i)}return a?new URL(j.call(V,l.href,()=>t)):new URL(t,l)}function Oe(e){let t=Number(e);return`${t}`===e&&t>=0&&t<4294967295}function Y(e,t,n,r,i,o,s,c,l){if(typeof t==`string`)return De(t,n,r,e,i,o,s,c,l);if(Array.isArray(t)){let a=t;if(a.length===0)return null;let u,d=-1;for(;++d<a.length;){let t=a[d],f;try{f=Y(e,t,n,r,i,o,s,c,l)}catch(e){let t=e;if(u=t,t.code===`ERR_INVALID_PACKAGE_TARGET`)continue;throw e}if(f!==void 0){if(f===null){u=null;continue}return f}}if(u==null)return null;throw u}if(typeof t==`object`&&t){let u=Object.getOwnPropertyNames(t),d=-1;for(;++d<u.length;){let t=u[d];if(Oe(t))throw new P(a(e),i,`"exports" cannot contain numeric property keys.`)}for(d=-1;++d<u.length;){let a=u[d];if(a==="default"||l&&l.has(a)){let u=t[a],d=Y(e,u,n,r,i,o,s,c,l);if(d===void 0)continue;return d}}return null}if(t===null)return null;throw J(r,t,e,s,i)}function ke(e,t,n){if(typeof e==`string`||Array.isArray(e))return!0;if(typeof e!=`object`||!e)return!1;let r=Object.getOwnPropertyNames(e),i=!1,o=0,s=-1;for(;++s<r.length;){let e=r[s],c=e===``||e[0]!==`.`;if(o++===0)i=c;else if(i!==c)throw new P(a(t),n,`"exports" cannot contain some keys starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.`)}return i}function Ae(e,t,n){if(u.noDeprecation)return;let r=a(t);H.has(r+`|`+e)||(H.add(r+`|`+e),u.emitWarning(`Use of deprecated trailing slash pattern mapping "${e}" in the "exports" field module resolution of the package at ${r}${n?` imported from ${a(n)}`:``}. Mapping specifiers ending in "/" is no longer supported.`,`DeprecationWarning`,`DEP0155`))}function X(e,t,n,r,i){let a=n.exports;if(ke(a,e,r)&&(a={".":a}),R.call(a,t)&&!t.includes(`*`)&&!t.endsWith(`/`)){let n=a[t],o=Y(e,n,``,t,r,!1,!1,!1,i);if(o==null)throw q(t,e,r);return o}let o=``,s=``,c=Object.getOwnPropertyNames(a),l=-1;for(;++l<c.length;){let n=c[l],i=n.indexOf(`*`);if(i!==-1&&t.startsWith(n.slice(0,i))){t.endsWith(`/`)&&Ae(t,e,r);let a=n.slice(i+1);t.length>=n.length&&t.endsWith(a)&&Z(o,n)===1&&n.lastIndexOf(`*`)===i&&(o=n,s=t.slice(i,t.length-a.length))}}if(o){let n=a[o],c=Y(e,n,s,o,r,!0,!1,t.endsWith(`/`),i);if(c==null)throw q(t,e,r);return c}throw q(t,e,r)}function Z(e,t){let n=e.indexOf(`*`),r=t.indexOf(`*`),i=n===-1?e.length:n+1,a=r===-1?t.length:r+1;return i>a?-1:a>i||n===-1?1:r===-1||e.length>t.length?-1:+(t.length>e.length)}function je(e,t,n){if(e===`#`||e.startsWith(`#/`)||e.endsWith(`/`))throw new N(e,`is not a valid internal imports specifier name`,a(t));let r,i=w(t);if(i.exists){r=o(i.pjsonPath);let a=i.imports;if(a){if(R.call(a,e)&&!e.includes(`*`)){let i=Y(r,a[e],``,e,t,!1,!0,!1,n);if(i!=null)return i}else{let i=``,o=``,s=Object.getOwnPropertyNames(a),c=-1;for(;++c<s.length;){let t=s[c],n=t.indexOf(`*`);if(n!==-1&&e.startsWith(t.slice(0,-1))){let r=t.slice(n+1);e.length>=t.length&&e.endsWith(r)&&Z(i,t)===1&&t.lastIndexOf(`*`)===n&&(i=t,o=e.slice(n,e.length-r.length))}}if(i){let e=a[i],s=Y(r,e,o,i,t,!0,!0,!1,n);if(s!=null)return s}}}}throw Te(e,r,t)}function Me(e,t){let n=e.indexOf(`/`),r=!0,i=!1;e[0]===`@`&&(i=!0,n===-1||e.length===0?r=!1:n=e.indexOf(`/`,n+1));let o=n===-1?e:e.slice(0,n);if(be.exec(o)!==null&&(r=!1),!r)throw new N(e,`is not a valid package name`,a(t));return{packageName:o,packageSubpath:`.`+(n===-1?``:e.slice(n)),isScoped:i}}function Q(t,n,r){if(e.includes(t))return new URL(`node:`+t);let{packageName:i,packageSubpath:s,isScoped:c}=Me(t,n),l=w(n);
2
+ /* c8 ignore next 16 */
3
+ if(l.exists){let e=o(l.pjsonPath);if(l.name===i&&l.exports!==void 0&&l.exports!==null)return X(e,s,l,n,r)}let u=new URL(`./node_modules/`+i+`/package.json`,n),d=a(u),f;do{let e=G(d.slice(0,-13));if(!e||!e.isDirectory()){f=d,u=new URL((c?`../../../../node_modules/`:`../../../node_modules/`)+i+`/package.json`,u),d=a(u);continue}let o=C(d,{base:n,specifier:t});return o.exports!==void 0&&o.exports!==null?X(u,s,o,n,r):s===`.`?Ce(u,o,n):new URL(s,u)}while(d.length!==f.length);throw new F(i,a(n),!1)}function Ne(e){return!(e[0]!==`.`||e.length!==1&&e[1]!==`/`&&(e[1]!==`.`||e.length!==2&&e[2]!==`/`))}function $(e){return e===``?!1:e[0]===`/`||Ne(e)}function Pe(t,n,r,i){r===void 0&&(r=A());let a=n.protocol,o=a===`data:`||a===`http:`||a===`https:`,s;if($(t))try{s=new URL(t,n)}catch(e){let r=new L(t,n);throw r.cause=e,r}else if(a===`file:`&&t[0]===`#`)s=je(t,n,r);else try{s=new URL(t)}catch(i){if(o&&!e.includes(t)){let e=new L(t,n);throw e.cause=i,e}s=Q(t,n,r)}return l.ok(s!==void 0,`expected to be defined`),s.protocol===`file:`?we(s,n,i):s}function Fe(t,n,r){if(r){let i=r.protocol;if(i===`http:`||i===`https:`){if($(t)){let e=n?.protocol;if(e&&e!==`https:`&&e!==`http:`)throw new M(t,r,`remote imports cannot import from a local location.`);return{url:n?.href||``}}throw e.includes(t)?new M(t,r,`remote imports cannot import from a local location.`):new M(t,r,`only relative and absolute specifiers are supported.`)}}}function Ie(e){return!!(e&&typeof e==`object`&&`href`in e&&typeof e.href==`string`&&`protocol`in e&&typeof e.protocol==`string`&&e.href&&e.protocol)}function Le(e){if(e!==void 0&&typeof e!=`string`&&!Ie(e))throw new p.ERR_INVALID_ARG_TYPE(`parentURL`,[`string`,`URL`],e)}function Re(e,t={}){let{parentURL:n}=t;l.ok(n!==void 0,"expected `parentURL` to be defined"),Le(n);let r;if(n)try{r=new URL(n)}catch{}let i,a;try{if(i=$(e)?new URL(e,r):new URL(e),a=i.protocol,a===`data:`)return{url:i.href,format:null}}catch{}let o=Fe(e,i,r);if(o)return o;if(a===void 0&&i&&(a=i.protocol),a===`node:`||i&&i.protocol===`node:`)return{url:e};let s=A(t.conditions),c=Pe(e,new URL(n),s,!1);return{url:c.href,format:O(c,{parentURL:n})}}function ze(e,t){if(!t)throw Error("Please pass `parent`: `import-meta-resolve` cannot ponyfill that");try{return Re(e,{parentURL:t}).url}catch(e){let t=e;if((t.code===`ERR_UNSUPPORTED_DIR_IMPORT`||t.code===`ERR_MODULE_NOT_FOUND`)&&typeof t.url==`string`)return t.url;throw e}}export{ze as resolve};