adamantite 0.40.0 → 0.42.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.
- package/README.md +194 -52
- package/dist/index.js +26 -35
- package/dist/presets/analyze.d.ts +19 -1
- package/dist/presets/analyze.js +16 -1
- package/dist/presets/lint/plugin/index.d.ts +15 -0
- package/dist/presets/lint/plugin/index.js +16 -0
- package/dist/presets/lint/plugin/options.d.ts +12 -0
- package/dist/presets/lint/plugin/options.js +33 -0
- package/dist/presets/lint/plugin/rules/no-overzealous-destructuring.d.ts +5 -0
- package/dist/presets/lint/plugin/rules/no-overzealous-destructuring.js +92 -0
- package/dist/presets/lint/plugin/rules/no-react-state-hooks.d.ts +10 -0
- package/dist/presets/lint/plugin/rules/no-react-state-hooks.js +160 -0
- package/dist/presets/lint/react-doctor.d.ts +5 -0
- package/dist/presets/lint/react-doctor.js +20 -0
- package/dist/presets/lint/react-strict.d.ts +5 -0
- package/dist/presets/lint/react-strict.js +11 -0
- package/dist/presets/lint/shadcn.d.ts +5 -0
- package/dist/presets/lint/shadcn.js +22 -0
- package/dist/presets/lint/strict.d.ts +5 -0
- package/dist/presets/lint/strict.js +18 -0
- package/dist/presets/lint/vendor/antislop/plugin.d.mts +18 -2
- package/package.json +10 -6
- package/skills/adamantite/SKILL.md +62 -23
package/dist/index.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import*as e from"@effect/platform-node/NodeRuntime";import*as t from"
|
|
2
|
-
`)}`}function
|
|
3
|
-
`)}var
|
|
4
|
-
`)}},Ce=class extends m.TaggedError(`FailedToReadFile`){get message(){return`Failed to read ${this.path?`\`${this.path}\``:`the target file`}.${E(this.cause)}`}},we=class extends m.TaggedError(`FailedToWriteFile`){get message(){return`Failed to write ${this.path?`\`${this.path}\``:`the target file`}.${E(this.cause)}`}},Te=class extends m.TaggedError(`FileNotFound`){get message(){return this.path?`File not found: \`${this.path}\`.`:`File not found.`}},Ee=class extends m.TaggedError(`InvalidConfigFormat`){get message(){return`Invalid config format in ${this.path?`\`${this.path}\``:`the target config file`}. The config must be a JSON object (for example: {}).`}},O=class extends m.TaggedError(`InvalidInitOptions`){get message(){return`Invalid init options. ${this.reason}`}},De=class extends m.TaggedError(`UnsupportedConfigState`){get message(){return`Unsupported config state in ${this.path?`\`${this.path}\``:`the target config file`}.${this.reason?` ${this.reason}`:``}`}},Oe=class extends m.TaggedError(`NoPackageManager`){get message(){return`No package manager detected. Please run this command from a project with a lockfile.${E(this.cause)}`}};m.TaggedError(`MissingPackageVersion`);var ke=class extends m.TaggedError(`OperationCancelled`){get message(){return`Operation cancelled.${this.reason?` Reason: ${this.reason}`:``}`}},Ae=class extends m.TaggedError(`PassthroughNotSupported`){get message(){return`Command \`adamantite ${this.command}\` does not invoke a single underlying CLI and cannot accept passthrough arguments.`}},je=class extends m.TaggedError(`VscodeCliNotFound`){get message(){return`VS Code CLI (\`code\`) not found. Please install it to manage extensions.${E(this.cause)}`}},k=class extends d.Service()(`CommandRunner`){static layer=i.succeed(this)({run:n.fn(`CommandRunner.run`)(function*({args:e,command:t,cwd:r,detached:i,stderr:a=`inherit`,stdin:o=`ignore`,stdout:s=`inherit`}){return yield*n.scoped(n.gen(function*(){return yield*(yield*f.make(t,e,{cwd:r,detached:i,stderr:a,stdin:o,stdout:s})).exitCode})).pipe(n.mapError(e=>e.reason._tag===`NotFound`?new _e({command:t}):e))})})};const A=d.Reference(`adamantite/ForwardedArguments`,{defaultValue:()=>[]});function j(e){return e}const Me=e=>b.FileSystem.pipe(n.flatMap(t=>t.makeDirectory(e,{recursive:!0})),n.mapError(t=>new ve({cause:t,path:e}))),M=e=>b.FileSystem.pipe(n.flatMap(t=>t.readFileString(e)),n.mapError(t=>new Ce({cause:t,path:e}))),N=e=>b.FileSystem.pipe(n.flatMap(t=>t.readFileString(e)),n.map(e=>h(e,g.some)),n.catch(t=>t.reason._tag===`NotFound`?n.succeedNone:n.fail(new Ce({cause:t,path:e})))),P=(e,t)=>b.FileSystem.pipe(n.flatMap(n=>n.writeFileString(e,t)),n.mapError(t=>new we({cause:t,path:e}))),F=(e,t)=>P(e,`${JSON.stringify(t,null,2)}\n`),I=(e,t)=>n.suspend(()=>{let r=[],i=ee(e,r,{allowTrailingComma:!0});return r.length>0?n.fail(new Se({errors:r,path:t})):n.succeed(i)}),L=e=>_.isObject(e),Ne=e=>Array.isArray(e);function Pe(e){return e===`__proto__`?`["__proto__"]`:/^[A-Za-z_$][\w$]*$/.test(e)?e:JSON.stringify(e)}function Fe(e,t={}){let{continuationIndent:n,indentation:r=2}=t,i=JSON.stringify(e,null,r).replaceAll(/(?<!\\)"__proto__":/g,`["__proto__"]:`).replaceAll(/(?<!\\)"([A-Za-z_$][\w$]*)":/g,`$1:`);return n?i.replaceAll(`
|
|
5
|
-
|
|
6
|
-
`):`
|
|
7
|
-
`):[`
|
|
8
|
-
`)}
|
|
9
|
-
`);
|
|
10
|
-
`)}const xt=g.liftThrowable(e=>ae(`oxlint.config.ts`,e,{astType:`ts`,lang:`ts`,sourceType:`module`}));function St(e){return xt(e).pipe(g.flatMap(e=>e.errors.length===0?g.fromNullishOr(e.program):g.none()))}function Ct(e){let{code:t}=se(e,ce({quotes:`double`}));return t.endsWith(`
|
|
11
|
-
`)?t:`${t}\n`}function wt(e){return e.type===`Identifier`?h(e.name,g.some):e.type===`Literal`&&_.isString(e.value)?h(e.value,g.some):g.none()}function Tt(e){return e.type===`ObjectExpression`?h(e,g.some):e.type!==`CallExpression`||e.callee.type!==`Identifier`||e.callee.name!==`defineConfig`?g.none():h(e.arguments.length===1?c.head(e.arguments):g.none(),g.filter(e=>e.type===`ObjectExpression`))}function Et(e){return h(e.body,c.filter(e=>e.type===`ExportDefaultDeclaration`),e=>e.length===1?c.head(e):g.none(),g.flatMap(e=>Tt(e.declaration)))}function Dt(e,t){let n=null;for(let r of e.properties){if(r.type===`SpreadElement`||r.computed)return{status:`manual`};let e=g.contains(wt(r.key),t);if(r.method||r.kind!==`init`){if(e)return{status:`manual`};continue}if(e){if(n)return{status:`manual`};n=r}}return n?{property:n,status:`found`}:{status:`missing`}}function Ot(e){return{computed:!1,end:0,key:{end:0,name:e,start:0,type:`Identifier`},kind:`init`,method:!1,shorthand:!1,start:0,type:`Property`,value:{end:0,raw:`true`,start:0,type:`Literal`,value:!0}}}function kt(){return{computed:!1,end:0,key:{end:0,name:`options`,start:0,type:`Identifier`},kind:`init`,method:!1,shorthand:!1,start:0,type:`Property`,value:{end:0,properties:ft.map(e=>Ot(e)),start:0,type:`ObjectExpression`}}}function At(e,t){let n=[],r=!1;for(let e of ft){let i=Dt(t,e);if(i.status===`manual`)return{kind:`manual`,reason:ht};if(i.status===`missing`){n.push(e);continue}let a=i.property.value;if(a.type!==`Literal`||!_.isBoolean(a.value))return{kind:`manual`,reason:ht};a.value||(a.raw=`true`,a.value=!0,r=!0)}return n.length>0&&(t.properties.unshift(...n.map(e=>Ot(e))),r=!0),r?{kind:`patchable`,updatedContent:Ct(e)}:{kind:`configured`}}function jt(e){let t=St(e);if(g.isNone(t))return{kind:`manual`,reason:pt};let n=Et(t.value);if(g.isNone(n))return{kind:`manual`,reason:pt};let r=Dt(n.value,`options`);return r.status===`manual`?{kind:`manual`,reason:mt}:r.status===`missing`?(n.value.properties.unshift(kt()),{kind:`patchable`,updatedContent:Ct(t.value)}):r.property.value.type===`ObjectExpression`?At(t.value,r.property.value):{kind:`manual`,reason:mt}}const V=`oxlint.config.ts`,Mt=`.oxlintrc.json`,Nt=[{path:V,type:`config`},{path:Mt,type:`legacy_config`}],Pt={config:V,legacyConfigs:[Mt]},Ft=`1.83.0`,It=e=>Je(e,`oxlint`,Pt);var H=j({assess:(e,t)=>n.gen(function*(){let n=He(t);if(!n.includes(`check`)&&!n.includes(`fix`))return{applicable:!1,warnings:[]};let r=yield*It(e),i=Ye(t,{name:`oxlint`,version:Ft},`the managed lint scripts`),a=r.active,o;if(a?.format===`ts`){let e=jt(yield*M(a.path));o=e.kind===`configured`?{kind:`configured`}:{kind:`invalid`,reason:e.kind===`manual`?e.reason:`The required Oxlint options are missing or set to false.`}}let s=bt({},gt());return{applicable:!0,findings:[...Xe(i,`oxlint`),...Ze(r,{configContent:s,configFile:V,inspection:o,invalidGoal:"Set `respectEslintDisableDirectives`, `typeAware`, and `typeCheck` to `true` in the `options` object. Preserve every other project setting.",toolName:`oxlint`})],packageActions:i,warnings:r.warnings}}),config:V,create:(e,t=[])=>n.gen(function*(){let n=yield*x.Path,r=bt({},gt(t));yield*P(n.join(e,V),r)}),detect:It,files:Nt,kind:`tooling`,name:`oxlint`,update:e=>n.gen(function*(){let t=yield*b.FileSystem,n=(yield*x.Path).join(e,V);if(!(yield*t.exists(n)))return yield*new Te({path:V});let r=jt(yield*M(n));if(r.kind!==`configured`){if(r.kind===`manual`)return yield*new De({path:V,reason:r.reason});yield*P(n,r.updatedContent)}}),version:Ft});const Lt=C.File(`files`,{mustExist:!0}).pipe(C.withDescription(`Specific files to lint (optional)`),C.variadic());var Rt=l.make(`check`,{files:Lt}).pipe(l.withDescription(`Find issues and type errors in code using oxlint`),l.withHandler(({files:e})=>n.gen(function*(){let t=yield*A,n=yield*(yield*k).run({args:[...e,...t],command:H.name});n!==s.ExitCode(0)&&(yield*new D({command:H.name,exitCode:n}))})));const zt=[{command:`claude`,name:`Claude Code`,seedArguments:e=>[e]},{command:`codex`,name:`Codex`,seedArguments:e=>[e]},{command:`cursor-agent`,name:`Cursor`,seedArguments:e=>[e]},{command:`gemini`,name:`Gemini CLI`,seedArguments:e=>[`-i`,e]},{command:`grok`,name:`Grok Build`,probeArguments:[`version`],seedArguments:e=>[e]},{command:`opencode`,name:`OpenCode`,seedArguments:e=>[`--prompt`,e]}],Bt=e=>n.gen(function*(){let t=yield*k;return(yield*n.forEach(zt,r=>t.run({args:[...r.probeArguments??[`--version`]],command:r.command,cwd:e,stderr:`ignore`,stdout:`ignore`}).pipe(n.timeout(`10 seconds`),n.as(r),n.catch(()=>n.succeed(null))),{concurrency:zt.length})).filter(e=>e!==null)});var Vt=class extends m.TaggedError(`AgentSessionFailed`){};const Ht=()=>{},Ut=e=>n.acquireUseRelease(n.sync(()=>{let e=S.listeners(`SIGINT`);return S.removeAllListeners(`SIGINT`),S.on(`SIGINT`,Ht),e}),()=>e,e=>n.sync(()=>{S.removeAllListeners(`SIGINT`);for(let t of e)S.on(`SIGINT`,t)})),Wt=({agent:e,cwd:t})=>n.gen(function*(){let n=yield*k;yield*Ut(n.run({args:e.seedArguments("Run `adamantite doctor` — through your package runner, such as `npx` or `pnpm exec`, if it is not on PATH — and resolve every finding it reports. Rerun `adamantite doctor` until it exits 0."),command:e.command,cwd:t,detached:!1,stderr:`inherit`,stdin:`inherit`,stdout:`inherit`}))}).pipe(n.asVoid,n.mapError(e=>new Vt({cause:e,reason:e._tag===`CliNotFound`?`not-found`:`spawn-failed`}))),Gt=e=>n.gen(function*(){let t=yield*(yield*k).run({args:[`diff`,`--quiet`,`HEAD`],command:`git`,cwd:e,stderr:`ignore`,stdout:`ignore`});return t===s.ExitCode(0)?`clean`:t===s.ExitCode(1)?`dirty`:`unknown`}).pipe(n.catch(()=>n.succeed(`unknown`))),Kt=[{name:`check`,script:`check`},{args:[`--check`],name:`format`,script:`format`},{name:`monorepo`,script:`check:monorepo`},{name:`analyze`,script:`analyze`}];function qt(e,t){let n=[];for(let r of Kt)t.includes(r.script)&&n.push({command:de(e,r.script,{args:r.args}),name:r.name});return n}function Jt(e){return Kt.some(t=>e.includes(t.script))}var U=class extends d.Service()(`DependencyInstaller`){static layer=i.succeed(this)({addDevDependencies:n.fn(`DependencyInstaller.addDevDependencies`)((e,t,r)=>n.tryPromise({catch:t=>new ye({cause:t,packages:e}),try:()=>le(e,{...r,cwd:t})}).pipe(n.asVoid)),detectPackageManager:n.fn(`DependencyInstaller.detectPackageManager`)(e=>n.tryPromise({catch:e=>new Oe({cause:e}),try:()=>ue(e)}).pipe(n.map(e=>e??null)))})};function Yt(e){return{_tag:`File`,path:e}}function Xt(e){return{_tag:`Version`,value:e}}const Zt=[`.node-version`,`.nvmrc`],Qt=w.Struct({volta:w.Struct({node:w.NonEmptyString})}),$t=w.Struct({engines:w.Struct({node:w.NonEmptyString})}),en=w.Struct({name:w.NonEmptyString,version:w.NonEmptyString});function tn(e){return e.split(`
|
|
12
|
-
`).map(e=>e.split(`#`)[0]?.trim()??``).some(e=>/^node(?:js)?\s+\S/.test(e))}function nn(e){return w.is(en)(e)&&e.name.toLowerCase()===`node`}function rn(e){if(w.is(Qt)(e))return!0;if(_.isObject(e)&&_.isObject(e.devEngines)){let t=e.devEngines.runtime;if((Array.isArray(t)?t:[t]).some(e=>nn(e)))return!0}return w.is($t)(e)}var an=class extends d.Service()(`NodeVersionResolver`){static layer=i.effect(this,n.gen(function*(){let e=yield*b.FileSystem,t=yield*x.Path,r=(r,i)=>N(t.join(r,i)).pipe(n.provideService(b.FileSystem,e));return{resolve:n.fn(`NodeVersionResolver.resolve`)(function*(e){for(let t of Zt){let n=yield*r(e,t);if(g.exists(n,e=>v.isNonEmpty(e.trim())))return Yt(t)}let n=yield*r(e,`.tool-versions`);if(g.exists(n,e=>tn(e)))return Yt(`.tool-versions`);let i=yield*r(e,`package.json`);return g.isSome(i)&&rn(yield*I(i.value,t.join(e,`package.json`)))?Yt(`package.json`):Xt(`lts/*`)})}}))};const on=/^\s*node-version:\s*"?\d/m,sn=/^[>|](?:[1-9][+-]?|[+-][1-9]?)?(?:\s+#.*)?$/,cn=/\b(?:(?:bun|npm|pnpm|yarn)(?:\s+(?!run\b)\S+)*\s+run\s+check|deno(?:\s+(?!task\b)\S+)*\s+task\s+check)\b/,ln=/^(\s*)(?:-\s*)?(?:command|run):\s*(.*)$/;function un(e){let t=e.split(`
|
|
13
|
-
`);for(let[e,n]of t.entries()){let r=ln.exec(n);if(!r)continue;let i=r[1]?.length??0,a=(r[2]??``).trim();if(cn.test(a))return!0;if(sn.test(a))for(let n of t.slice(e+1)){let e=n.trim();if(e.length!==0){if(n.length-n.trimStart().length<=i)break;if(cn.test(e))return!0}}}return!1}function dn(e){return` - name: Setup Node.js
|
|
1
|
+
import*as e from"@effect/platform-node/NodeRuntime";import*as t from"effect/Effect";import*as n from"effect/Exit";import*as r from"effect/process/ChildProcessSpawner";import*as i from"effect/Runtime";import*as a from"effect/Stdio";import*as o from"@effect/platform-node/NodeServices";import*as s from"effect/Array";import*as c from"effect/cli/Command";import*as l from"effect/Layer";import*as u from"effect/cli/Flag";import*as d from"effect/Option";import f from"node:process";import{stripVTControlCharacters as p,styleText as m}from"node:util";import*as h from"effect/Console";import*as g from"effect/Context";import*as ee from"effect/process/ChildProcess";import*as _ from"effect/Result";import*as v from"effect/Data";import{pipe as y}from"effect/Function";import*as b from"effect/Predicate";import*as x from"effect/String";import{parse as te,printParseErrorCode as ne}from"jsonc-parser";import*as S from"effect/FileSystem";import*as C from"effect/Path";import*as re from"effect/Record";import{defu as ie}from"defu";import{Visitor as ae,parseSync as oe}from"oxc-parser";import*as w from"effect/cli/Argument";import{addDevDependency as se,detectPackageManager as ce,runScriptCommand as le}from"nypm";import*as T from"effect/Schema";import*as E from"@clack/prompts";import*as ue from"effect/Terminal";function de(e){return b.isError(e)?y(p(e.message),x.split(/\r\n|[\r\n]/),s.map(e=>x.trimEnd(e)),s.filter(e=>x.isNonEmpty(e))):[]}function D(e){return y(de(e),s.head,d.map(e=>{let t=x.trim(e);return/[.!?]$/.test(t)?` Cause: ${t}`:` Cause: ${t}.`}),d.getOrElse(()=>``))}function fe(e){let t=de(e);if(!s.isReadonlyArrayNonEmpty(t))return``;let n=s.takeRight(t,20);return`\n${(n.length<t.length?[`…`,...n]:n).join(`
|
|
2
|
+
`)}`}function pe(e=[]){return e.length===0?`- Unknown JSON/JSONC parsing error`:e.slice(0,3).map(e=>`- ${ne(e.error)} (offset: ${e.offset})`).join(`
|
|
3
|
+
`)}var me=class extends v.TaggedError(`CliNotFound`){get message(){return`Command \`${this.command}\` not found. ${this.hint??`Please install it and try again.`}`}},he=class extends v.TaggedError(`CommandFailed`){get message(){return`Command \`${this.command}\` failed with exit code ${this.exitCode}.`}},ge=class extends v.TaggedError(`FailedToCreateDirectory`){get message(){return`Failed to create directory ${this.path?`\`${this.path}\``:`the target directory`}.${D(this.cause)}`}},_e=class extends v.TaggedError(`FailedToInstallDependency`){get message(){return`Failed to install dependencies${this.packages?.length?`: ${this.packages.join(`, `)}`:``}.${fe(this.cause)}`}},ve=class extends v.TaggedError(`FailedToInstallExtension`){get message(){let e=this.extension?`\`${this.extension}\``:`the target extension`;return b.isNumber(this.cause)?`Failed to install ${e}. The \`code\` CLI exited with code ${this.cause}.`:`Failed to install ${e}.${D(this.cause)}`}},ye=class extends v.TaggedError(`FailedToMergeConfig`){get message(){return`Failed to merge configuration.${D(this.cause)}`}},be=class extends v.TaggedError(`FailedToParseFile`){get message(){return[`Failed to parse ${this.path?`\`${this.path}\``:`the target file`}.`,`Please fix the JSON/JSONC syntax and run the command again.`,``,`Parse details:`,pe(this.errors)].join(`
|
|
4
|
+
`)}},xe=class extends v.TaggedError(`FailedToReadFile`){get message(){return`Failed to read ${this.path?`\`${this.path}\``:`the target file`}.${D(this.cause)}`}},Se=class extends v.TaggedError(`FailedToWriteFile`){get message(){return`Failed to write ${this.path?`\`${this.path}\``:`the target file`}.${D(this.cause)}`}},Ce=class extends v.TaggedError(`InvalidConfigFormat`){get message(){return`Invalid config format in ${this.path?`\`${this.path}\``:`the target config file`}. The config must be a JSON object (for example: {}).`}},we=class extends v.TaggedError(`InvalidAnalyzeOptions`){get message(){return`Invalid analyze options. ${this.reason}`}},Te=class extends v.TaggedError(`InvalidFixOptions`){get message(){return`Invalid fix options. ${this.reason}`}},O=class extends v.TaggedError(`InvalidInitOptions`){get message(){return`Invalid init options. ${this.reason}`}},Ee=class extends v.TaggedError(`NoPackageManager`){get message(){return`No package manager detected. Please run this command from a project with a lockfile.${D(this.cause)}`}};v.TaggedError(`MissingPackageVersion`);var De=class extends v.TaggedError(`OperationCancelled`){get message(){return`Operation cancelled.${this.reason?` Reason: ${this.reason}`:``}`}},Oe=class extends v.TaggedError(`PassthroughNotSupported`){get message(){return`Command \`adamantite ${this.command}\` does not invoke a single underlying CLI and cannot accept passthrough arguments.`}},ke=class extends v.TaggedError(`VscodeCliNotFound`){get message(){return`VS Code CLI (\`code\`) not found. Please install it to manage extensions.${D(this.cause)}`}};const Ae=(e,t)=>h.log(`${m(`bold`,e)} ${m(`dim`,`· adamantite (${t})`)}`),je=()=>[f.env.NODE_OPTIONS,`--disable-warning=MODULE_TYPELESS_PACKAGE_JSON`].filter(Boolean).join(` `),Me=t.fn(`CommandRunner.exitCode`)(function*({args:e,command:n,cwd:r,detached:i,stderr:a=`inherit`,stdin:o=`ignore`,stdout:s=`inherit`}){return yield*t.scoped(t.gen(function*(){return yield*(yield*ee.make(n,e,{cwd:r,detached:i,env:{NODE_OPTIONS:je()},extendEnv:!0,stderr:a,stdin:o,stdout:s})).exitCode})).pipe(t.mapError(e=>e.reason._tag===`NotFound`?new me({command:n}):e))});var k=class e extends g.Service()(`CommandRunner`){static make(e){let n=t.fn(`CommandRunner.run`)(function*(t){t.title!==void 0&&(yield*Ae(t.title,t.command));let n=yield*e(t);n!==r.ExitCode(0)&&(yield*new he({command:t.command,exitCode:n}))}),i=e=>e.map((e,r)=>r===0?n(e):t.andThen(h.log(``),n(e)));return{exitCode:e,run:n,runAll:t.fn(`CommandRunner.runAll`)(function*(e){let n=yield*t.all(i(e),{concurrency:1,mode:`result`});yield*t.fromResult(_.all(n))}),runUntilFailure:t.fn(`CommandRunner.runUntilFailure`)(function*(e){yield*t.all(i(e),{concurrency:1,discard:!0})})}}static layer=l.effect(this)(t.gen(function*(){let n=yield*r.ChildProcessSpawner;return e.make(e=>Me(e).pipe(t.provideService(r.ChildProcessSpawner,n)))}))};const Ne=g.Reference(`adamantite/ForwardedArguments`,{defaultValue:()=>[]});function A(e){return e}const Pe=e=>S.FileSystem.pipe(t.flatMap(t=>t.makeDirectory(e,{recursive:!0})),t.mapError(t=>new ge({cause:t,path:e}))),j=e=>S.FileSystem.pipe(t.flatMap(t=>t.readFileString(e)),t.mapError(t=>new xe({cause:t,path:e}))),M=e=>S.FileSystem.pipe(t.flatMap(t=>t.readFileString(e)),t.map(e=>y(e,d.some)),t.catch(n=>n.reason._tag===`NotFound`?t.succeedNone:t.fail(new xe({cause:n,path:e})))),N=(e,n)=>S.FileSystem.pipe(t.flatMap(t=>t.writeFileString(e,n)),t.mapError(t=>new Se({cause:t,path:e}))),P=(e,t)=>N(e,`${JSON.stringify(t,null,2)}\n`),F=(e,n)=>t.suspend(()=>{let r=[],i=te(e,r,{allowTrailingComma:!0});return r.length>0?t.fail(new be({errors:r,path:n})):t.succeed(i)}),I=e=>b.isObject(e),Fe=e=>Array.isArray(e),Ie=(e,n)=>t.try({catch:e=>new ye({cause:e}),try:()=>ie(e,n)}),Le=/^workspace:/,Re=/^[\^~]/;function ze(e){return e.trim().replace(Le,``).replace(Re,``)}const L=(e=f.cwd())=>t.gen(function*(){let t=(yield*C.Path).join(e,`package.json`),n=yield*j(t);return yield*F(n,t)}),Be=(e,n)=>t.gen(function*(){let t=yield*C.Path;yield*P(t.join(e,`package.json`),n)});function Ve(e){return e===`bun`||e===`deno`||e===`npm`||e===`pnpm`||e===`yarn`}const R={analyze:`adamantite analyze`,check:`adamantite check`,fix:`adamantite fix`};function z(e){let t=e.scripts??{};return y(re.keys(R),s.filter(e=>t[e]===R[e]))}function He(e,t){let n=e.scripts??{};return s.filterMap(t,e=>{let t=n[e];return t!==void 0&&t!==``&&t!==R[e]?_.succeed({command:t,script:e}):_.failVoid})}const Ue=/^(?:packages|"packages"|'packages')\s*:/u;function We(e){return e.replace(/(?:^|\s+)#.*$/u,``).trim()}function Ge(e){let t=e.replace(/^\uFEFF/u,``).split(/\r?\n/u),n=t.findIndex(e=>Ue.test(e));if(n===-1)return!1;let r=We((t[n]??``).replace(Ue,``));if(r===`[`){for(let e of t.slice(n+1)){let t=We(e);if(t.length!==0)return t!==`]`}return!1}if(r&&!r.startsWith(`#`))return!/^\[\s*\]$/u.test(r);for(let e of t.slice(n+1)){if(/^\s*-\s*[^#\s]/u.test(e))return!0;if(/^\S/u.test(e)&&!e.startsWith(`#`))return!1}return!1}const B=(e=f.cwd())=>t.gen(function*(){let t=yield*C.Path,n=yield*M(t.join(e,`pnpm-workspace.yaml`));if(d.isSome(n)&&Ge(n.value))return!0;let r=(yield*L(e)).workspaces;return((s.isArray(r)?r:r?.packages)?.length??0)>0});function Ke(e){return e.endsWith(`.jsonc`)?`jsonc`:e.endsWith(`.json`)?`json`:`ts`}function qe(e,t){return s.findFirst(e.legacyConfigs,e=>Ke(e)===t)}function Je(e){let t=qe(e,`json`),n=qe(e,`jsonc`);return y(d.zipWith(t,n,e=>`${e}(c)`),d.orElse(()=>n),d.orElse(()=>t),d.getOrElse(()=>``))}function Ye(e,t,n,r){return n===null||r.length===0?[]:n.format===`ts`?[`Found both \`${t.config}\` and \`${Je(t)}\`. Adamantite will use \`${t.config}\`.`]:y(d.zipWith(qe(t,`json`),qe(t,`jsonc`),(t,n)=>`Found both \`${t}\` and \`${n}\`. Multiple legacy ${e} configs exist; Adamantite will treat \`${n}\` as the source of truth in its findings.`),d.toArray)}const Xe=t.fn(`detectToolingConfig`)(function*(e,n,r){let i=yield*S.FileSystem,a=yield*C.Path,o=[r.config,...r.legacyConfigs].map(t=>({file:t,format:Ke(t),path:a.join(e,t)})),c=yield*t.forEach(o,e=>i.exists(e.path),{concurrency:`unbounded`}),l=o.filter((e,t)=>c[t]),u=y(s.findFirst(l,e=>e.format===`ts`),d.orElse(()=>s.findFirst(l,e=>e.format===`jsonc`)),d.orElse(()=>s.findFirst(l,e=>e.format===`json`)),d.getOrNull),f=l.filter(e=>e!==u&&e.format!==`ts`);return{active:u,legacy:f,warnings:Ye(n,r,u,f)}});function Ze(e,t,n){let r=e.devDependencies?.[t.name]??e.dependencies?.[t.name];return r?ze(r)===t.version?[]:[{currentVersion:r,description:`Update \`${t.name}\` from \`${r}\` to \`${t.version}\`.`,package:t.name,targetVersion:t.version,type:`update_package`}]:[{description:`Install \`${t.name}@${t.version}\` for ${n}.`,package:t.name,targetVersion:t.version,type:`install_package`}]}function Qe(e,t){return e.map(e=>({currentState:e.type===`install_package`?`The required package \`${e.package}\` is not installed.`:`The installed \`${e.package}\` version is \`${e.currentVersion}\`, but Adamantite requires \`${e.targetVersion}\`.`,goal:[`Run \`adamantite update\` so \`${e.package}@${e.targetVersion}\` is installed.`],id:`${e.type===`install_package`?`missing`:`outdated`}-${e.package}`,integration:t,title:e.type===`install_package`?`Missing ${e.package}`:`Outdated ${e.package}`}))}function $e(e,t){if(e.active===null)return[{currentState:`The managed \`${t.configFile}\` file is missing.`,goal:[`Create \`${t.configFile}\` with the reference content.`,`Do not create a legacy JSON or JSONC ${t.toolName} config.`],id:`missing-${t.toolName}-config`,integration:t.toolName,reference:{content:t.configContent,language:`ts`},title:`Missing ${t.toolName} configuration`}];if(e.active.format!==`ts`)return[{currentState:`Legacy \`${e.active.file}\` is the active ${t.toolName} configuration.`,goal:[`Port the project settings into \`${t.configFile}\` using the reference content as the base.`,`Delete every legacy ${t.toolName} JSON or JSONC config after its settings are preserved.`],id:`legacy-${t.toolName}-config`,integration:t.toolName,notes:[`Preserve project-specific settings. Do not replace them with the reference defaults.`],reference:{content:t.configContent,language:`ts`},title:`Legacy ${t.toolName} configuration`}];let n=[];return e.legacy.length>0&&n.push({currentState:`Legacy ${t.toolName} config files remain next to \`${t.configFile}\`: ${e.legacy.map(({file:e})=>`\`${e}\``).join(`, `)}.`,goal:[`Delete the legacy files after you confirm that \`${t.configFile}\` preserves their project-specific settings.`],id:`shadowed-legacy-${t.toolName}-config`,integration:t.toolName,title:`Legacy ${t.toolName} files remain`}),t.inspection?.kind===`invalid`&&n.push({currentState:`\`${t.configFile}\` does not meet Adamantite's required shape. ${t.inspection.reason}`,goal:[t.invalidGoal??t.inspection.goal??`Update \`${t.configFile}\` so it includes the required Adamantite preset while preserving project-specific settings.`],id:`invalid-${t.toolName}-config`,integration:t.toolName,notes:[`Treat the reference as a known-good example, not an exact replacement.`],reference:{content:t.configContent,language:`ts`},title:`Invalid ${t.toolName} configuration`}),n}function et(e,t){let n=z(e);return t.some(e=>n.includes(e))}function tt(e){return A({assess:(n,r)=>t.gen(function*(){let t=et(r,e.scripts)&&(!e.monorepoOnly||(yield*B(n)))&&(e.isRequired===void 0||(yield*e.isRequired(n))),i=e.legacyFindings?.(r)??[];if(!t)return i.length>0?{applicable:!0,findings:[...i],packageActions:[],warnings:[]}:{applicable:!1,warnings:[]};let a=Ze(r,e,e.purpose);return{applicable:!0,findings:[...Qe(a,e.name),...i],packageActions:a,warnings:[]}}),kind:`tooling`,name:e.name,version:e.version})}function nt(e){let n=[{path:e.configFiles.config,type:`config`},...e.configFiles.legacyConfigs.map(e=>({path:e,type:`legacy_config`}))],r=t=>Xe(t,e.name,e.configFiles);return A({assess:(n,i)=>t.gen(function*(){let t=e.legacyFindings?.(i)??[];if(!et(i,e.scripts))return t.length>0?{applicable:!0,findings:t,packageActions:[],warnings:[]}:{applicable:!1,warnings:[]};let a=yield*r(n),o=Ze(i,e,e.purpose),s={isMonorepo:yield*B(n)},c=e.configContent(s),l=a.active?.format===`ts`?e.inspectConfig(yield*j(a.active.path),s):void 0;return{applicable:!0,findings:[...Qe(o,e.name),...$e(a,{configContent:c,configFile:e.configFiles.config,inspection:l,toolName:e.name}),...t],packageActions:o,warnings:a.warnings}}),config:e.configFiles.config,create:n=>t.gen(function*(){let t=yield*C.Path;yield*N(t.join(n,e.configFiles.config),e.configContent({isMonorepo:yield*B(n)}))}),detect:r,files:n,kind:`tooling`,name:e.name,version:e.version})}function rt(e,t){for(let n of e.body)if(n.type===`ImportDeclaration`&&n.source.value===t){for(let e of n.specifiers)if(e.type===`ImportDefaultSpecifier`)return e.local.name}return null}function it(e,t){for(let n of e.body)if(n.type===`VariableDeclaration`){for(let e of n.declarations)if(e.id.type===`Identifier`&&e.id.name===t)return e.init}return null}function at(e,t,n){let r=!1;return new ae({Identifier:e=>{e.start>=n.start&&e.end<=n.end&&e.name===t&&(r=!0)}}).visit(e),r}function ot(e,t){let n=e.body.filter(e=>e.type===`ExportDefaultDeclaration`);if(n.length!==1)return!1;let r=n[0]?.declaration;if(!r)return!1;if(r.type!==`Identifier`)return at(e,t,r);if(r.name===t)return!0;let i=it(e,r.name);return i!==null&&at(e,t,i)}function st(e,t){let n=oe(`config.ts`,e,{astType:`ts`,lang:`ts`,sourceType:`module`});if(n.errors.length>0)return{kind:`invalid`,reason:`The file is not valid TypeScript.`};let r=rt(n.program,t.moduleName);return r?ot(n.program,r)?{kind:`configured`}:{kind:`invalid`,reason:`The imported ${t.presetName} preset is not used by the exported configuration.`}:{kind:`invalid`,reason:`The file must import the ${t.presetName} preset from \`${t.moduleName}\`.`}}const ct={isMonorepo:!1},lt=/ignoreDependencies\s*:\s*\[[^\]]*?sherif/u,ut=/ignoreDependencies\s*:\s*(?:ignoreDependencies\.monorepo|\[[^\]]*?ignoreDependencies\.monorepo)/u,dt=/import\s[^;]*?\{[^}]*\bignoreDependencies\b[^}]*\}\s*from\s*["']adamantite\/analyze["']/u;function ft(e){return lt.test(e)||ut.test(e)&&dt.test(e)}function pt(e,t){let n=st(e,{moduleName:`adamantite/analyze`,presetName:`Adamantite analyze`});return n.kind!==`configured`||!t.isMonorepo||ft(e)?n:{goal:"Set `ignoreDependencies: ignoreDependencies.monorepo` in `knip.config.ts`, with the named `ignoreDependencies` import from `adamantite/analyze`, and keep the other settings.",kind:`invalid`,reason:"The file must set `ignoreDependencies: ignoreDependencies.monorepo` from `adamantite/analyze`, because Knip cannot see that `adamantite analyze` runs Sherif in a monorepo."}}function mt(e=ct){return[`import type { KnipConfig } from "knip"`,e.isMonorepo?`import analyze, { ignoreDependencies } from "adamantite/analyze"`:`import analyze from "adamantite/analyze"`,``,...e.isMonorepo?[`const config: KnipConfig = {`,` ...analyze,`,` ignoreDependencies: ignoreDependencies.monorepo,`,`}`]:[`const config: KnipConfig = analyze`],``,`export default config`,``].join(`
|
|
5
|
+
`)}var V=nt({configContent:mt,configFiles:{config:`knip.config.ts`,legacyConfigs:[`knip.json`,`knip.jsonc`]},inspectConfig:pt,name:`knip`,purpose:"the managed `analyze` script",scripts:[`analyze`],version:`6.32.2`});const ht=new Set([`check:monorepo`,`fix:monorepo`]),gt=/^adamantite\s+monorepo(?:\s|$)/u,_t=new Map([[`--fail-on-warnings`,{key:`failOnWarnings`,takesValue:!1}],[`--ignore-dependency`,{key:`ignoreDependency`,takesValue:!0}],[`--ignore-package`,{key:`ignorePackage`,takesValue:!0}],[`--ignore-rule`,{key:`ignoreRule`,takesValue:!0}],[`--no-install`,{key:`noInstall`,takesValue:!1}],[`--select`,{key:`select`,takesValue:!0}],[`-i`,{key:`ignoreDependency`,takesValue:!0}],[`-p`,{key:`ignorePackage`,takesValue:!0}],[`-r`,{key:`ignoreRule`,takesValue:!0}],[`-s`,{key:`select`,takesValue:!0}]]);function vt(e){return Object.entries(e.scripts??{}).flatMap(([e,t])=>t!==void 0&&(ht.has(e)||gt.test(t.trim()))?[{command:t,name:e}]:[])}function yt(e){let t=e.command.trim().split(/\s+/u),n=[];for(let[e,r]of t.entries()){let[i=r,a]=r.split(`=`,2),o=_t.get(i);if(!o)continue;if(!o.takesValue){n.push(`Set \`sherif.${o.key}\` to \`true\` in the root \`package.json\`.`);continue}let s=a??t[e+1];s!==void 0&&n.push(o.key===`select`?`Set \`sherif.select\` to \`"${s}"\` in the root \`package.json\`.`:`Add \`"${s}"\` to the \`sherif.${o.key}\` array in the root \`package.json\`.`)}return n}function bt(e){let t=vt(e);if(t.length===0)return[];let n=z(e).includes(`analyze`);return[{currentState:`Legacy monorepo scripts are present in \`package.json\`: ${t.map(({command:e,name:t})=>`\`${t}\` (\`${e}\`)`).join(`, `)}.${n?``:" The project has no managed `analyze` script."}`,goal:[...n?[]:["Adopt the managed `analyze` script with `adamantite init --non-interactive --script analyze`. It runs Sherif in a detected monorepo."],...s.dedupe(t.flatMap(e=>yt(e))),...t.map(({name:e})=>`Remove the \`${e}\` script from \`package.json\`.`)],id:`legacy-monorepo-scripts`,integration:`sherif`,notes:["`adamantite analyze` replaces `check:monorepo`, and `adamantite analyze --only monorepo --fix` replaces `fix:monorepo`. `adamantite analyze --fix` without `--only` also lets Knip remove unused files and dependencies.","`adamantite analyze` runs Sherif without flags. Sherif reads project exceptions from the `sherif` field of the root `package.json`, with the CLI options in camelCase: `ignoreDependency`, `ignoreRule`, `ignorePackage`, `select`, `noInstall`, and `failOnWarnings`.","Doctor does not assess `AGENTS.md`. Remove the lines that mention the monorepo scripts from its Adamantite section."],title:`Legacy monorepo scripts`}]}var H=tt({legacyFindings:bt,monorepoOnly:!0,name:`sherif`,purpose:"the managed `analyze` script in a monorepo",scripts:[`analyze`],version:`1.13.0`});const xt=[{command:H.name,fixArguments:[`--fix`],name:`monorepo`,stdin:`inherit`,strictArguments:[],title:`📦 Analyzing the monorepo`},{command:V.name,fixArguments:[`--fix`,`--allow-remove-files`],name:`unused`,stdin:`ignore`,strictArguments:[`--production`,`--strict`],title:`🧹 Analyzing unused code`}],St=u.Boolean(`fix`).pipe(u.withDefault(!1),u.withDescription(`Automatically fix issues in every stage that runs`)),Ct=u.Boolean(`strict`).pipe(u.withDefault(!1),u.withDescription(`Enable strict mode for the unused stage (knip)`)),wt=u.Literals(`only`,[`monorepo`,`unused`]).pipe(u.optional,u.withDescription("Run one stage: `monorepo` (sherif, monorepos only) or `unused` (knip). Arguments after `--` go to that stage"));var Tt=c.make(`analyze`,{fix:St,only:wt,strict:Ct}).pipe(c.withDescription(`Find monorepo issues using sherif, then unused dependencies, exports, and files using knip`),c.withExamples([{command:`adamantite analyze -- --directory packages/app`,description:`Run knip from a specific directory`},{command:`adamantite analyze --only monorepo --fix -- --select highest`,description:`Fix only the monorepo issues and use the highest version on a mismatch`}]),c.withHandler(({fix:e,only:n,strict:r})=>t.gen(function*(){let i=yield*Ne,a=yield*k,o=d.getOrUndefined(n),s=yield*B().pipe(t.catchTags({FailedToParseFile:()=>t.succeed(!1),FailedToReadFile:()=>t.succeed(!1)}));if(o===`monorepo`){if(r)return yield*new we({reason:"`--strict` applies to the unused stage. Remove it or `--only monorepo`."});if(!s)return yield*new we({reason:"`--only monorepo` needs a monorepo, and no monorepo was detected."})}let c=xt.filter(e=>o===void 0?e.name===`unused`||s:e.name===o),l=o??`unused`,u=c.map(t=>({args:[...e?t.fixArguments:[],...r?t.strictArguments:[],...t.name===l?i:[]],command:t.command,stdin:t.stdin,title:t.title}));yield*(e?a.runUntilFailure(u):a.runAll(u)).pipe(t.mapError(e=>e._tag===`CliNotFound`&&e.command===H.name?new me({command:e.command,hint:"Run `adamantite update` to install it."}):e))})));function Et(e){return st(e,{moduleName:`adamantite/format`,presetName:`Adamantite format`})}function Dt(){return[`import { defineConfig } from "oxfmt"`,`import format from "adamantite/format"`,``,`export default defineConfig(format)`,``].join(`
|
|
6
|
+
`)}var U=nt({configContent:Dt,configFiles:{config:`oxfmt.config.ts`,legacyConfigs:[`.oxfmtrc.json`,`.oxfmtrc.jsonc`]},inspectConfig:Et,legacyFindings:e=>e.scripts?.format===`adamantite format`?[{currentState:"The legacy managed `format` script is present in `package.json`.",goal:["Remove the `format` script from `package.json`."],id:`legacy-format-script`,integration:`oxfmt`,notes:["The managed `check` script verifies formatting and the managed `fix` script applies it.","Doctor does not assess `AGENTS.md`. Remove the `format` line from its Adamantite section."],title:`Legacy format script`}]:[],name:`oxfmt`,purpose:"the managed `check` and `fix` scripts",scripts:[`check`,`fix`],version:`0.65.0`});const Ot=[`respectEslintDisableDirectives`,`typeAware`,`typeCheck`],kt="`oxlint.config.ts` must export an object literal directly, with or without `defineConfig(...)`, for Adamantite to inspect `options`.",At="`oxlint.config.ts` has an `options` property, but it is not an object literal that Adamantite can inspect.",jt=[`react`,`react-strict`,`react-doctor`,`nextjs`,`vue`,`jest`,`vitest`,`node`,`strict`,`antislop`,`shadcn`];function Mt(e){return e.replaceAll(/-([a-z])/g,(e,t)=>t.toUpperCase())}function Nt(e=[]){let t=e.includes(`core`)?e:[`core`,...e];return[`import { defineConfig } from "oxlint"`,...t.map(e=>`import ${Mt(e)} from "${e===`core`?`adamantite/lint`:`adamantite/lint/${e}`}"`),``,`export default defineConfig({`,` extends: [${t.map(e=>Mt(e)).join(`, `)}],`,` ignorePatterns: core.ignorePatterns,`,` options: {`,...Ot.map(e=>` ${e}: true,`),` },`,`})`,``].join(`
|
|
7
|
+
`)}const Pt=d.liftThrowable(e=>oe(`oxlint.config.ts`,e,{astType:`ts`,lang:`ts`,sourceType:`module`}));function Ft(e){return Pt(e).pipe(d.flatMap(e=>e.errors.length===0?d.fromNullishOr(e.program):d.none()))}function It(e){return y(Ft(e),d.map(e=>e.body.flatMap(e=>e.type===`ImportDeclaration`&&e.source.value.startsWith(`adamantite/lint/`)?[e.source.value.slice(16)]:[])),d.getOrElse(()=>[]))}function Lt(e){return e.type===`Identifier`?y(e.name,d.some):e.type===`Literal`&&b.isString(e.value)?y(e.value,d.some):d.none()}function Rt(e){return e.type===`ObjectExpression`?y(e,d.some):e.type!==`CallExpression`||e.callee.type!==`Identifier`||e.callee.name!==`defineConfig`?d.none():y(e.arguments.length===1?s.head(e.arguments):d.none(),d.filter(e=>e.type===`ObjectExpression`))}function zt(e){return y(e.body,s.filter(e=>e.type===`ExportDefaultDeclaration`),e=>e.length===1?s.head(e):d.none(),d.flatMap(e=>Rt(e.declaration)))}function Bt(e,t){let n=null;for(let r of e.properties){if(r.type===`SpreadElement`||r.computed)return{status:`invalid`};let e=d.contains(Lt(r.key),t);if(r.method||r.kind!==`init`){if(e)return{status:`invalid`};continue}if(e){if(n)return{status:`invalid`};n=r}}return n?{property:n,status:`found`}:{status:`missing`}}function Vt(e){for(let t of Ot){let n=Bt(e,t);if(n.status===`invalid`)return{kind:`invalid`,reason:"`oxlint.config.ts` has an `options` object Adamantite cannot inspect. Make sure each required option is a plain `key: true | false` property. Avoid spreads (`...rest`), computed keys (`[name]: ...`), duplicate keys, methods/getters/setters, and non-boolean-literal values."};if(n.status===`missing`||n.property.value.type!==`Literal`||n.property.value.value!==!0)return{kind:`invalid`,reason:`The required Oxlint options are missing or are not set to true.`}}return{kind:`configured`}}function Ht(e){let t=Ft(e);if(d.isNone(t))return{kind:`invalid`,reason:kt};let n=zt(t.value);if(d.isNone(n))return{kind:`invalid`,reason:kt};let r=Bt(n.value,`options`);return r.status===`invalid`?{kind:`invalid`,reason:At}:r.status===`missing`?{kind:`invalid`,reason:`The required Oxlint options are missing.`}:r.property.value.type===`ObjectExpression`?Vt(r.property.value):{kind:`invalid`,reason:At}}const W=`oxlint.config.ts`,Ut=`.oxlintrc.json`,Wt=[{path:W,type:`config`},{path:Ut,type:`legacy_config`}],Gt={config:W,legacyConfigs:[Ut]},Kt=`1.83.0`,qt=e=>Xe(e,`oxlint`,Gt);var G=A({assess:(e,n)=>t.gen(function*(){let t=z(n);if(!t.includes(`check`)&&!t.includes(`fix`))return{applicable:!1,warnings:[]};let r=yield*qt(e),i=Ze(n,{name:`oxlint`,version:Kt},`the managed lint scripts`),a=r.active,o;a?.format===`ts`&&(o=Ht(yield*j(a.path)));let s=Nt();return{applicable:!0,findings:[...Qe(i,`oxlint`),...$e(r,{configContent:s,configFile:W,inspection:o,invalidGoal:"Set `respectEslintDisableDirectives`, `typeAware`, and `typeCheck` to `true` in the `options` object. Preserve every other project setting.",toolName:`oxlint`})],packageActions:i,warnings:r.warnings}}),config:W,create:(e,n=[])=>t.gen(function*(){let t=yield*C.Path,r=Nt(n);yield*N(t.join(e,W),r)}),detect:qt,files:Wt,kind:`tooling`,name:`oxlint`,version:Kt});const Jt=w.File(`files`,{mustExist:!0}).pipe(w.withDescription(`Specific files to check (optional)`),w.variadic()),Yt=u.Literals(`only`,[`format`,`lint`]).pipe(u.optional,u.withDescription("Run one stage: `format` (oxfmt) or `lint` (oxlint). Arguments after `--` go to that stage"));var Xt=c.make(`check`,{files:Jt,only:Yt}).pipe(c.withDescription(`Check formatting, code issues, and type errors`),c.withHandler(({files:e,only:n})=>t.gen(function*(){let t=yield*Ne,r=yield*k,i=d.getOrUndefined(n),a=i??`lint`,o=[{args:[`--check`,...e],command:U.name,name:`format`,title:`✨ Checking formatting`},{args:[...e],command:G.name,name:`lint`,title:`🔍 Linting`}];yield*r.runAll(o.filter(e=>i===void 0||e.name===i).map(e=>({args:[...e.args,...e.name===a?t:[]],command:e.command,title:e.title})))})));const Zt=[`check`,`analyze`];function Qt(e,t){return Zt.filter(e=>t.includes(e)).map(t=>({command:le(e,t),name:t}))}function $t(e){return Zt.some(t=>e.includes(t))}var en=class extends g.Service()(`DependencyInstaller`){static layer=l.succeed(this)({addDevDependencies:t.fn(`DependencyInstaller.addDevDependencies`)((e,n,r)=>t.tryPromise({catch:t=>new _e({cause:t,packages:e}),try:()=>se(e,{...r,cwd:n})}).pipe(t.asVoid)),detectPackageManager:t.fn(`DependencyInstaller.detectPackageManager`)(e=>t.tryPromise({catch:e=>new Ee({cause:e}),try:()=>ce(e)}).pipe(t.map(e=>e??null)))})};function tn(e,t){return t&&e!==`npm`}const nn=(e,n)=>t.gen(function*(){let t=yield*en,r=yield*B(e),i=yield*t.detectPackageManager(e);yield*t.addDevDependencies(n,e,{silent:!0,workspace:tn(i?.name,r)})});function rn(e){return{_tag:`File`,path:e}}function an(e){return{_tag:`Version`,value:e}}const on=[`.node-version`,`.nvmrc`],sn=T.Struct({volta:T.Struct({node:T.NonEmptyString})}),cn=T.Struct({engines:T.Struct({node:T.NonEmptyString})}),ln=T.Struct({name:T.NonEmptyString,version:T.NonEmptyString});function un(e){return e.split(`
|
|
8
|
+
`).map(e=>e.split(`#`)[0]?.trim()??``).some(e=>/^node(?:js)?\s+\S/.test(e))}function dn(e){return T.is(ln)(e)&&e.name.toLowerCase()===`node`}function fn(e){if(T.is(sn)(e))return!0;if(b.isObject(e)&&b.isObject(e.devEngines)){let t=e.devEngines.runtime;if((Array.isArray(t)?t:[t]).some(e=>dn(e)))return!0}return T.is(cn)(e)}var pn=class extends g.Service()(`NodeVersionResolver`){static layer=l.effect(this,t.gen(function*(){let e=yield*S.FileSystem,n=yield*C.Path,r=(r,i)=>M(n.join(r,i)).pipe(t.provideService(S.FileSystem,e));return{resolve:t.fn(`NodeVersionResolver.resolve`)(function*(e){for(let t of on){let n=yield*r(e,t);if(d.exists(n,e=>x.isNonEmpty(e.trim())))return rn(t)}let t=yield*r(e,`.tool-versions`);if(d.exists(t,e=>un(e)))return rn(`.tool-versions`);let i=yield*r(e,`package.json`);return d.isSome(i)&&fn(yield*F(i.value,n.join(e,`package.json`)))?rn(`package.json`):an(`lts/*`)})}}))};const mn=/^\s*node-version:\s*"?\d/m,hn=/^[>|](?:[1-9][+-]?|[+-][1-9]?)?(?:\s+#.*)?$/,gn=/\b(?:(?:bun|npm|pnpm|yarn)(?:\s+(?!run\b)\S+)*\s+run\s+check|deno(?:\s+(?!task\b)\S+)*\s+task\s+check)\b/,_n=/\b(?:(?:bun|npm|pnpm|yarn)(?:\s+(?!run\b)\S+)*\s+run\s+format|deno(?:\s+(?!task\b)\S+)*\s+task\s+format)(?:\s+--)?\s+--check\b/,vn=/\b(?:(?:bun|npm|pnpm|yarn)(?:\s+(?!run\b)\S+)*\s+run\s+(?:check|fix):monorepo|deno(?:\s+(?!task\b)\S+)*\s+task\s+(?:check|fix):monorepo|adamantite\s+monorepo)(?=\s|$)/,yn=/^(\s*)(?:-\s*)?(?:command|run):\s*(.*)$/;function bn(e,t){let n=e.split(`
|
|
9
|
+
`);for(let[e,r]of n.entries()){let i=yn.exec(r);if(!i)continue;let a=i[1]?.length??0,o=(i[2]??``).trim();if(t.test(o))return!0;if(hn.test(o))for(let r of n.slice(e+1)){let e=r.trim();if(e.length!==0){if(r.length-r.trimStart().length<=a)break;if(t.test(e))return!0}}}return!1}function xn(e){return` - name: Setup Node.js
|
|
14
10
|
uses: actions/setup-node@v7
|
|
15
11
|
with:
|
|
16
|
-
${e._tag===`File`?`node-version-file: "${e.path}"`:`node-version: "${e.value}"`}`}function
|
|
12
|
+
${e._tag===`File`?`node-version-file: "${e.path}"`:`node-version: "${e.value}"`}`}function Sn(e){return{bun:`${xn(e)}
|
|
17
13
|
|
|
18
14
|
- name: Setup Bun
|
|
19
15
|
uses: oven-sh/setup-bun@v2
|
|
@@ -33,22 +29,22 @@ import*as e from"@effect/platform-node/NodeRuntime";import*as t from"@effect/pla
|
|
|
33
29
|
uses: denoland/setup-deno@v2
|
|
34
30
|
|
|
35
31
|
- name: Install dependencies
|
|
36
|
-
run: deno install --frozen`,npm:`${
|
|
32
|
+
run: deno install --frozen`,npm:`${xn(e)}
|
|
37
33
|
cache: "npm"
|
|
38
34
|
|
|
39
35
|
- name: Install dependencies
|
|
40
36
|
run: npm ci`,pnpm:` - name: Setup pnpm
|
|
41
37
|
uses: pnpm/action-setup@v4
|
|
42
38
|
|
|
43
|
-
${
|
|
39
|
+
${xn(e)}
|
|
44
40
|
cache: "pnpm"
|
|
45
41
|
|
|
46
42
|
- name: Install dependencies
|
|
47
|
-
run: pnpm install --frozen-lockfile`,yarn:`${
|
|
43
|
+
run: pnpm install --frozen-lockfile`,yarn:`${xn(e)}
|
|
48
44
|
cache: "yarn"
|
|
49
45
|
|
|
50
46
|
- name: Install dependencies
|
|
51
|
-
run: yarn install --frozen-lockfile`}}function
|
|
47
|
+
run: yarn install --frozen-lockfile`}}function Cn({packageManager:e,scripts:t},n){let r=Qt(e,t);return r.length===0?null:`${`name: adamantite
|
|
52
48
|
|
|
53
49
|
on:
|
|
54
50
|
push:
|
|
@@ -80,32 +76,27 @@ ${r.map(e=>` - name: ${e.name}\n command: ${e.command}`).joi
|
|
|
80
76
|
- name: Checkout
|
|
81
77
|
uses: actions/checkout@v7
|
|
82
78
|
|
|
83
|
-
${
|
|
79
|
+
${Sn(n)[e]}
|
|
84
80
|
|
|
85
81
|
- name: Run \${{ matrix.name }}
|
|
86
|
-
run: \${{ matrix.command }}`}\n`}const
|
|
87
|
-
`)
|
|
88
|
-
`)}function wn(e,t){let n=Cn(Fe(t));return[` ${e}: {`,` ...format.${e},`,...n===``?[]:[n],` },`].join(`
|
|
89
|
-
`)}function Tn(e={}){let t=Object.entries(e).map(([e,t])=>{if(xn.has(e)&&L(t))return wn(e,t);let n=Fe(t,{continuationIndent:` `});return` ${Pe(e)}: ${n},`});return t.length===0?[`import { defineConfig } from "oxfmt"`,`import format from "adamantite/format"`,``,`export default defineConfig(format)`,``].join(`
|
|
90
|
-
`):[`import { defineConfig } from "oxfmt"`,`import format from "adamantite/format"`,``,`export default defineConfig({`,` ...format,`,...t,`})`,``].join(`
|
|
91
|
-
`)}var q=et({configContent:()=>Tn(),configFiles:{config:`oxfmt.config.ts`,legacyConfigs:[`.oxfmtrc.json`,`.oxfmtrc.jsonc`]},inspectConfig:Sn,name:`oxfmt`,purpose:"the managed `format` script",scripts:[`format`],version:`0.65.0`}),J=$e({name:`sherif`,purpose:`the managed monorepo scripts`,scripts:[`check:monorepo`,`fix:monorepo`],version:`1.13.0`}),En=$e({name:`oxlint-tsgolint`,purpose:`the managed lint scripts`,scripts:[`check`,`fix`],version:`7.0.2001`});const Dn=/^(?:packages|"packages"|'packages')\s*:/u;function On(e){return e.replace(/(?:^|\s+)#.*$/u,``).trim()}function kn(e){let t=e.replace(/^\uFEFF/u,``).split(/\r?\n/u),n=t.findIndex(e=>Dn.test(e));if(n===-1)return!1;let r=On((t[n]??``).replace(Dn,``));if(r===`[`){for(let e of t.slice(n+1)){let t=On(e);if(t.length!==0)return t!==`]`}return!1}if(r&&!r.startsWith(`#`))return!/^\[\s*\]$/u.test(r);for(let e of t.slice(n+1)){if(/^\s*-\s*[^#\s]/u.test(e))return!0;if(/^\S/u.test(e)&&!e.startsWith(`#`))return!1}return!1}const An=(e=S.cwd())=>n.gen(function*(){let t=yield*x.Path,n=yield*N(t.join(e,`pnpm-workspace.yaml`));if(g.isSome(n)&&kn(n.value))return!0;let r=(yield*R(e)).workspaces;return((c.isArray(r)?r:r?.packages)?.length??0)>0}),Y=[{path:`tsconfig.json`,type:`config`}],X=`adamantite/typescript`,jn={extends:X},Mn=["Skipping `tsconfig.json` setup: a root config in a monorepo makes TypeScript treat all packages as one project.",`To use the TypeScript preset, add \`"extends": "${X}"\` to each package's \`tsconfig.json\` or to a shared base config.`];function Nn(e){return _.isString(e)?e===X?e:[e,X]:c.isArray(e)?e.includes(X)?e:[...e,X]:X}var Z=j({assess:(e,t)=>n.gen(function*(){let n=He(t);if(!n.includes(`check`)&&!n.includes(`fix`))return{applicable:!1,warnings:[]};if(yield*An(e))return{applicable:!0,findings:[],packageActions:[],warnings:Mn};let r=(yield*x.Path).join(e,Y[0].path),i=yield*N(r);if(i._tag===`None`)return{applicable:!0,findings:[{currentState:"`tsconfig.json` is missing.",goal:["Create `tsconfig.json` and set `extends` to include `adamantite/typescript`."],id:`missing-tsconfig`,integration:`tsconfig`,reference:{content:`${JSON.stringify(jn,null,2)}\n`,language:`json`},title:`Missing TypeScript configuration`}],packageActions:[],warnings:[]};let a=yield*I(i.value,r);return{applicable:!0,findings:_.isObject(a)&&(a.extends===X||c.isArray(a.extends)&&a.extends.includes(X))?[]:[{currentState:"`tsconfig.json` does not extend `adamantite/typescript`.",goal:["Add `adamantite/typescript` to `extends`. Preserve every existing TypeScript option and existing base config."],id:`missing-adamantite-tsconfig-extends`,integration:`tsconfig`,reference:{content:`${JSON.stringify(jn,null,2)}\n`,language:`json`},title:`TypeScript preset is not configured`}],packageActions:[],warnings:[]}}),config:Y[0].path,create:e=>n.gen(function*(){let t=yield*x.Path;yield*F(t.join(e,Y[0].path),jn)}),detect:e=>n.gen(function*(){let t=yield*b.FileSystem,n=yield*x.Path;return yield*t.exists(n.join(e,Y[0].path))}),files:Y,kind:`workspace`,name:`tsconfig`,update:e=>n.gen(function*(){let t=(yield*x.Path).join(e,Y[0].path),n=yield*M(t),r=yield*I(n,t);if(!_.isObject(r))return yield*new Ee({path:t});let i=yield*Ie(jn,r),a=Object.fromEntries([...Object.entries(i),[`extends`,Nn(`extends`in r?r.extends:void 0)]]);yield*F(t,a)})});const Pn=[B,q,H,J,En,Z,W,K],Fn=n.fn(`collectApplicableAssessments`)(function*(e,t,r){return yield*n.forEach(e,e=>e.assess(t,r).pipe(n.map(t=>t.applicable?g.some({assessment:t,name:e.name}):g.none())),{concurrency:`unbounded`}).pipe(n.map(e=>c.getSomes(e)))});function In(e,t,n){return Fn(e,t,n)}const Ln=n.fn(`assessProject`)(function*(e,t){let n=t??(yield*R(e)),r=yield*In(Pn,e,n);return{applicableIntegrations:r.map(({name:e})=>e),findings:r.flatMap(({assessment:e})=>e.findings),packageActions:r.flatMap(({assessment:e})=>e.packageActions),warnings:r.flatMap(({assessment:e})=>e.warnings)}});function Rn(e,t){return e.findings.length===0?zn(e.warnings,t):Bn(e.findings,e.warnings,t)}function zn(e,t){return[`# Adamantite doctor warnings`,``,`This project uses Adamantite ${t} to manage linting, formatting, and type tooling.`,"`adamantite doctor` found no repair findings, but reported these warnings:",``,...e.map(e=>`- ${e}`),``].join(`
|
|
92
|
-
`)}function Bn(e,t,n){let r=e.map((e,t)=>{let n=e.goal.map(e=>` - ${e}`).join(`
|
|
82
|
+
run: \${{ matrix.command }}`}\n`}const wn={currentState:"The workflow still runs the legacy `format` script with `--check`.",goal:["Remove the workflow step or matrix entry that runs the `format` script with `--check`."],id:`legacy-format-workflow-step`,integration:`github`,notes:["The managed `check` script verifies formatting. Preserve unrelated workflow jobs and project-specific settings."],title:`Legacy format workflow step`},Tn={currentState:"The workflow still runs a legacy monorepo script or `adamantite monorepo`.",goal:["Remove the workflow step or matrix entry that runs `check:monorepo`, `fix:monorepo`, or `adamantite monorepo`.","Make the workflow run the managed `analyze` script. It runs Sherif in a detected monorepo."],id:`legacy-monorepo-workflow-step`,integration:`github`,notes:[`Preserve unrelated workflow jobs and project-specific settings.`],title:`Legacy monorepo workflow step`},K=[{path:`.github/workflows/adamantite.yml`,type:`ci`}],En=(e,n)=>t.gen(function*(){let t=yield*C.Path,r=yield*pn,i=t.join(e,K[0].path),a=Cn(n,yield*r.resolve(e));a&&(yield*N(i,a))});var Dn=A({assess:(e,n)=>t.gen(function*(){let t=(yield*C.Path).join(e,K[0].path),r=yield*M(t);if(r._tag===`None`)return{applicable:!1,warnings:[]};let i=z(n),a=mn.test(r.value),o=i.includes(`check`)&&!bn(r.value,gn),s=[...bn(r.value,_n)?[wn]:[],...bn(r.value,vn)?[Tn]:[]];if(!a&&!o)return{applicable:!0,findings:s,packageActions:[],warnings:[]};if(!$t(i))return{applicable:!0,findings:s,packageActions:[],warnings:[`No CI-compatible managed scripts were found, so the GitHub Actions workflow cannot be regenerated.`]};let c=yield*(yield*en).detectPackageManager(e);return c?Ve(c.name)?{applicable:!0,findings:[{currentState:[...a?[`The workflow contains a hard-coded Node.js version.`]:[],...o?["The workflow does not run the managed `check` script."]:[]].join(` `),goal:["Make the workflow run the managed `check` script.",`Use the project's Node.js version declaration instead of a hard-coded version.`],id:`outdated-adamantite-workflow`,integration:`github`,notes:[`The detected package manager is \`${c.name}\`. Preserve unrelated workflow jobs and project-specific settings.`],title:`Outdated Adamantite workflow`},...s],packageActions:[],warnings:[]}:{applicable:!0,findings:s,packageActions:[],warnings:[`\`${c.name}\` is not a supported package manager for CI workflow generation, so the GitHub Actions workflow cannot be regenerated.`]}:{applicable:!0,findings:s,packageActions:[],warnings:[`Could not detect a package manager, so the GitHub Actions workflow cannot be regenerated.`]}}),create:(e,n)=>t.gen(function*(){let t=yield*C.Path;yield*Pe(t.dirname(t.join(e,K[0].path))),yield*En(e,n)}),detect:e=>t.gen(function*(){let t=yield*S.FileSystem,n=yield*C.Path;return yield*t.exists(n.join(e,K[0].path))}),files:K,kind:`ci`,name:`github`,update:En});const q=[{path:`.zed/settings.json`,type:`config`}],On={languages:{Astro:{format_on_save:`on`,prettier:{allowed:!0,plugins:[`prettier-plugin-astro`]}},CSS:{format_on_save:`on`,formatter:[{language_server:{name:`oxfmt`}}],prettier:{allowed:!1}},HTML:{format_on_save:`on`,formatter:[{language_server:{name:`oxfmt`}}],prettier:{allowed:!1}},JSON:{format_on_save:`on`,formatter:[{language_server:{name:`oxfmt`}}],prettier:{allowed:!1}},JSONC:{format_on_save:`on`,formatter:[{language_server:{name:`oxfmt`}}],prettier:{allowed:!1}},JavaScript:{format_on_save:`on`,formatter:[{language_server:{name:`oxfmt`}},{code_action:`source.fixAll.oxc`}],prettier:{allowed:!1}},MDX:{format_on_save:`on`,formatter:[{language_server:{name:`oxfmt`}}],prettier:{allowed:!1}},Markdown:{format_on_save:`on`,formatter:[{language_server:{name:`oxfmt`}}],prettier:{allowed:!1}},TSX:{format_on_save:`on`,formatter:[{language_server:{name:`oxfmt`}},{code_action:`source.fixAll.oxc`}],prettier:{allowed:!1}},TypeScript:{format_on_save:`on`,formatter:[{language_server:{name:`oxfmt`}},{code_action:`source.fixAll.oxc`}],prettier:{allowed:!1}},YAML:{format_on_save:`on`,formatter:[{language_server:{name:`oxfmt`}}],prettier:{allowed:!1}}},lsp:{oxfmt:{initialization_options:{settings:{"fmt.configPath":null,run:`onSave`}}},oxlint:{initialization_options:{settings:{configPath:null,fixKind:`safe_fix`,run:`onType`,typeAware:!0,unusedDisableDirectives:`deny`}}}}},kn={configPath:null,"fmt.experimental":!0,typeAware:!1,unusedDisableDirectives:!1};function An(e){let t=e.lsp,n=I(t)?t.oxfmt:void 0,r=I(n)?n.initialization_options:void 0,i=I(r)?r.settings:void 0;if(!I(i))return[];let a=Object.entries(kn);return Object.entries(i).filter(([e,t])=>a.some(([n,r])=>n===e&&r===t)).map(([e])=>e)}function jn(e){return!I(e)||!Fe(e.plugins)?e:Object.fromEntries([...Object.entries(e),[`plugins`,s.dedupe(e.plugins)]])}function Mn(e){let t=e.languages;if(!I(t))return e;let n=Object.fromEntries(Object.entries(t).map(([e,t])=>!(e in On.languages)||!I(t)?[e,t]:[e,Object.fromEntries(Object.entries(t).map(([e,t])=>e===`formatter`&&Fe(t)?[e,s.dedupe(t)]:e===`prettier`?[e,jn(t)]:[e,t]))]));return Object.fromEntries([...Object.entries(e),[`languages`,n]])}var J=A({assess:(e,n)=>t.gen(function*(){let t=(yield*C.Path).join(e,q[0].path),n=yield*M(t);if(n._tag===`None`)return{applicable:!1,warnings:[]};let r=yield*F(n.value,t),i=I(r)?An(r):[];return{applicable:!0,findings:i.length===0?[]:[{currentState:`\`${q[0].path}\` contains stale oxfmt settings: ${i.map(e=>`\`${e}\``).join(`, `)}.`,goal:[`Remove only the stale oxfmt entries that still have Adamantite's old default values.`,`Preserve entries that the project changed.`],id:`legacy-zed-oxfmt-settings`,integration:`zed`,title:`Legacy Zed oxfmt settings`}],packageActions:[],warnings:[]}}),config:q[0].path,create:e=>t.gen(function*(){let t=yield*C.Path,n=t.join(e,q[0].path);yield*Pe(t.dirname(n)),yield*P(n,On)}),detect:e=>t.gen(function*(){let t=yield*S.FileSystem,n=yield*C.Path;return yield*t.exists(n.join(e,q[0].path))}),files:q,kind:`editor`,name:`zed`,update:e=>t.gen(function*(){let t=(yield*C.Path).join(e,q[0].path),n=yield*j(t),r=yield*F(n,t);if(!b.isObject(r))return yield*new Ce({path:t});let i=Mn(yield*Ie(On,r));yield*P(t,i)})});const Nn=t.fn(`checkImportsLintPreset`)(function*(e,t){let n=yield*C.Path,r=yield*M(n.join(e,`oxlint.config.ts`));return d.match(r,{onNone:()=>!1,onSome:e=>It(e).includes(t)})});function Pn(e){return{...tt({isRequired:t=>Nn(t,e.preset),name:e.name,purpose:`the \`adamantite/lint/${e.preset}\` preset`,scripts:[`check`,`fix`],version:e.version}),preset:e.preset}}var Fn=Pn({name:`oxlint-plugin-react-doctor`,preset:`react-doctor`,version:`0.9.14`});const In=[Pn({name:`@shadcn/lint`,preset:`shadcn`,version:`0.1.5`}),Fn];var Ln=tt({name:`oxlint-tsgolint`,purpose:`the managed lint scripts`,scripts:[`check`,`fix`],version:`7.0.2001`});const Y=[{path:`tsconfig.json`,type:`config`}],X=`adamantite/typescript`,Rn={extends:X},zn=["Skipping `tsconfig.json` setup: a root config in a monorepo makes TypeScript treat all packages as one project.",`To use the TypeScript preset, add \`"extends": "${X}"\` to each package's \`tsconfig.json\` or to a shared base config.`];function Bn(e){return b.isString(e)?e===X?e:[e,X]:s.isArray(e)?e.includes(X)?e:[...e,X]:X}var Z=A({assess:(e,n)=>t.gen(function*(){let t=z(n);if(!t.includes(`check`)&&!t.includes(`fix`))return{applicable:!1,warnings:[]};if(yield*B(e))return{applicable:!0,findings:[],packageActions:[],warnings:zn};let r=(yield*C.Path).join(e,Y[0].path),i=yield*M(r);if(i._tag===`None`)return{applicable:!0,findings:[{currentState:"`tsconfig.json` is missing.",goal:["Create `tsconfig.json` and set `extends` to include `adamantite/typescript`."],id:`missing-tsconfig`,integration:`tsconfig`,reference:{content:`${JSON.stringify(Rn,null,2)}\n`,language:`json`},title:`Missing TypeScript configuration`}],packageActions:[],warnings:[]};let a=yield*F(i.value,r);return{applicable:!0,findings:b.isObject(a)&&(a.extends===X||s.isArray(a.extends)&&a.extends.includes(X))?[]:[{currentState:"`tsconfig.json` does not extend `adamantite/typescript`.",goal:["Add `adamantite/typescript` to `extends`. Preserve every existing TypeScript option and existing base config."],id:`missing-adamantite-tsconfig-extends`,integration:`tsconfig`,reference:{content:`${JSON.stringify(Rn,null,2)}\n`,language:`json`},title:`TypeScript preset is not configured`}],packageActions:[],warnings:[]}}),config:Y[0].path,create:e=>t.gen(function*(){let t=yield*C.Path;yield*P(t.join(e,Y[0].path),Rn)}),detect:e=>t.gen(function*(){let t=yield*S.FileSystem,n=yield*C.Path;return yield*t.exists(n.join(e,Y[0].path))}),files:Y,kind:`workspace`,name:`tsconfig`,update:e=>t.gen(function*(){let t=(yield*C.Path).join(e,Y[0].path),n=yield*j(t),r=yield*F(n,t);if(!b.isObject(r))return yield*new Ce({path:t});let i=yield*Ie(Rn,r),a=Object.fromEntries([...Object.entries(i),[`extends`,Bn(`extends`in r?r.extends:void 0)]]);yield*P(t,a)})});const Vn=[V,U,G,...In,H,Ln,Z,Dn,J],Hn=t.fn(`collectApplicableAssessments`)(function*(e,n,r){return yield*t.forEach(e,e=>e.assess(n,r).pipe(t.map(t=>t.applicable?d.some({assessment:t,name:e.name}):d.none())),{concurrency:`unbounded`}).pipe(t.map(e=>s.getSomes(e)))});function Un(e,t,n){return Hn(e,t,n)}const Wn=t.fn(`assessProject`)(function*(e,t){let n=t??(yield*L(e)),r=yield*Un(Vn,e,n);return{applicableIntegrations:r.map(({name:e})=>e),findings:r.flatMap(({assessment:e})=>e.findings),packageActions:r.flatMap(({assessment:e})=>e.packageActions),warnings:r.flatMap(({assessment:e})=>e.warnings)}});function Gn(e,t){return e.findings.length===0?Kn(e.warnings,t):qn(e.findings,e.warnings,t)}function Kn(e,t){return[`# Adamantite doctor warnings`,``,`This project uses Adamantite ${t} to manage linting, formatting, and type tooling.`,"`adamantite doctor` found no repair findings, but reported these warnings:",``,...e.map(e=>`- ${e}`),``].join(`
|
|
83
|
+
`)}function qn(e,t,n){let r=e.map((e,t)=>{let n=e.goal.map(e=>` - ${e}`).join(`
|
|
93
84
|
`),r=e.reference?`\n- **Reference:**\n\n\`\`\`${e.reference.language}\n${e.reference.content.trimEnd()}\n\`\`\``:``,i=e.notes&&e.notes.length>0?`\n- **Notes:**\n${e.notes.map(e=>` - ${e}`).join(`
|
|
94
|
-
`)}`:``;return`## ${t+1}. ${e.title}\n\n- **Current state:** ${e.currentState}\n- **Goal:**\n${n}${r}${i}`}),i=t.length>0?[`## Assessment warnings`,``,`Account for these warnings while fixing the findings:`,``,...t.map(e=>`- ${e}`),``]:[];return[`# Adamantite doctor findings`,``,`This project uses Adamantite ${n} to manage linting, formatting, and type tooling.`,`\`adamantite doctor\` found ${e.length} issue(s). Fix them so that \`adamantite doctor\` exits 0
|
|
85
|
+
`)}`:``;return`## ${t+1}. ${e.title}\n\n- **Current state:** ${e.currentState}\n- **Goal:**\n${n}${r}${i}`}),i=t.length>0?[`## Assessment warnings`,``,`Account for these warnings while fixing the findings:`,``,...t.map(e=>`- ${e}`),``]:[];return[`# Adamantite doctor findings`,``,`This project uses Adamantite ${n} to manage linting, formatting, and type tooling.`,`\`adamantite doctor\` found ${e.length} issue(s). Fix them so that \`adamantite doctor\` exits 0.`,``,...i,r.join(`
|
|
95
86
|
|
|
96
|
-
`),``,`## Verify`,``,"Run `adamantite doctor
|
|
97
|
-
`)}var
|
|
87
|
+
`),``,`## Verify`,``,"Run `adamantite doctor` — through your package runner, such as `npx` or `pnpm exec`, if it is not on PATH.",`All findings above must be gone and it must exit 0.`,`Do not suppress or work around checks; fix the underlying state.`,``].join(`
|
|
88
|
+
`)}const Jn=[{command:`claude`,name:`Claude Code`,seedArguments:e=>[e]},{command:`codex`,name:`Codex`,seedArguments:e=>[e]},{command:`cursor-agent`,name:`Cursor`,seedArguments:e=>[e]},{command:`gemini`,name:`Gemini CLI`,seedArguments:e=>[`-i`,e]},{command:`grok`,name:`Grok Build`,probeArguments:[`version`],seedArguments:e=>[e]},{command:`opencode`,name:`OpenCode`,seedArguments:e=>[`--prompt`,e]}];var Yn=class extends v.TaggedError(`AgentSessionFailed`){};const Xn=()=>{},Zn=t.acquireRelease(t.sync(()=>{let e=f.listeners(`SIGINT`);return f.removeAllListeners(`SIGINT`),f.on(`SIGINT`,Xn),e}),e=>t.sync(()=>{f.removeAllListeners(`SIGINT`);for(let t of e)f.on(`SIGINT`,t)}));var Qn=class e extends g.Service()(`CodingAgents`){static layer=l.effect(this,t.gen(function*(){let n=yield*k,r=(e,r)=>n.exitCode({args:[...e.probeArguments??[`--version`]],command:e.command,cwd:r,stderr:`ignore`,stdout:`ignore`}).pipe(t.timeout(`10 seconds`),t.isSuccess);return e.of({detectInstalled:t.fn(`CodingAgents.detectInstalled`)(e=>t.forEach(Jn,t=>r(t,e),{concurrency:`unbounded`}).pipe(t.map(e=>Jn.filter((t,n)=>e[n])))),runSession:t.fn(`CodingAgents.runSession`)(function*({agent:e,cwd:t,prompt:r}){yield*Zn,yield*n.exitCode({args:e.seedArguments(r),command:e.command,cwd:t,detached:!1,stderr:`inherit`,stdin:`inherit`,stdout:`inherit`})},t.scoped,t.mapError(e=>new Yn({cause:e,reason:e._tag===`CliNotFound`?`not-found`:`spawn-failed`})))})}))},$n=class extends g.Service()(`TerminalCapabilities`){static layer=l.succeed(this)({copyToClipboard:e=>t.sync(()=>{let t=Buffer.from(e).toString(`base64`);f.stdout.write(`\u001B]52;c;${t}\u0007`)}),isInteractive:t.sync(()=>f.stdin.isTTY&&f.stdout.isTTY)})},Q=class extends g.Service()(`Prompter`){static layerWithSpinner(e){return l.succeed(this)({cancel:e=>t.sync(()=>{E.cancel(e)}),confirm:e=>t.promise(()=>E.confirm(e)).pipe(t.filterOrFail(e=>!E.isCancel(e),()=>new De({}))),intro:e=>t.sync(()=>{E.intro(e)}),log:{error:e=>t.sync(()=>{E.log.error(e)}),info:e=>t.sync(()=>{E.log.info(e)}),success:e=>t.sync(()=>{E.log.success(e)}),warning:e=>t.sync(()=>{E.log.warning(e)})},message:e=>t.sync(()=>{E.log.message(e,{spacing:0,withGuide:!1})}),multiselect:e=>t.promise(()=>E.multiselect(e)).pipe(t.filterOrFail(e=>!E.isCancel(e),()=>new De({}))),note:(e,n)=>t.sync(()=>{E.note(e,n)}),outro:e=>t.sync(()=>{E.outro(e)}),select:e=>t.promise(()=>E.select(e)).pipe(t.filterOrFail(e=>!E.isCancel(e),()=>new De({}))),withSpinner:(r,i)=>t.acquireUseRelease(t.sync(()=>{let t=e();return t.start(i.start),t}),e=>r({message:n=>t.sync(()=>{e.message(n)})}),(e,r)=>t.sync(()=>{e.stop(n.match(r,{onFailure:()=>i.failure,onSuccess:e=>b.isFunction(i.success)?i.success(e):i.success}))}))})}static layer=this.layerWithSpinner(E.spinner)};function er(e){let t=[`Current state\n${e.currentState}`,`Goal\n${e.goal.map(e=>`• ${e}`).join(`
|
|
98
89
|
`)}`];return e.reference&&t.push(`Reference\n${e.reference.content.trimEnd()}`),e.notes&&e.notes.length>0&&t.push(`Notes\n${e.notes.map(e=>`• ${e}`).join(`
|
|
99
90
|
`)}`),t.join(`
|
|
100
91
|
|
|
101
|
-
`)}const
|
|
102
|
-
`).reduce((e,t)=>Math.max(e,t.trim().length),0);!e||e<t||(yield*fe.info(Wn))}),Kn=`0.40.0`;var qn=l.make(`doctor`).pipe(l.withDescription(`Assess Adamantite-managed integrations in the current project`),l.withHandler(()=>n.gen(function*(){let e=S.cwd(),t=yield*Q,r=yield*Vn,i=yield*r.isInteractive;i&&(yield*Gn(),yield*t.intro(`💠 adamantite doctor`));let a=n.gen(function*(){return yield*t.outro(`⚠️ Doctor found issues.`),yield*new D({command:`doctor`,exitCode:s.ExitCode(1)})}),o=yield*R(e);if(!o.devDependencies?.adamantite&&!o.dependencies?.adamantite){let e="`adamantite` is not installed in this project. Install it before running `adamantite doctor`.";return i?(yield*t.log.warning(e),yield*t.outro(`⚠️ Doctor found issues.`)):yield*t.message(e),yield*new D({command:`doctor`,exitCode:s.ExitCode(1)})}let c=yield*Ln(e);if(i)for(let e of c.warnings)yield*t.log.warning(e);if(c.applicableIntegrations.length===0){i&&(yield*t.log.success(`No applicable integrations found.`),yield*t.outro(`✅ Doctor completed successfully!`));return}if(c.findings.length===0){i?(yield*t.log.success(`No issues found.`),yield*t.outro(`✅ Doctor completed successfully!`)):c.warnings.length>0&&(yield*t.message(Rn(c,Kn)));return}if(!i)return yield*t.message(Rn(c,Kn)),yield*new D({command:`doctor`,exitCode:s.ExitCode(1)});let l=e=>n.gen(function*(){(yield*t.confirm({initialValue:!0,message:`Copy the Markdown prompt for a coding agent?`}))&&(yield*t.message(e),yield*r.copyToClipboard(e),yield*t.log.success(`The Markdown prompt was printed and sent to the terminal clipboard.`))});yield*Un(c.findings);let u=yield*t.withSpinner(()=>Bt(e),{start:`Checking for installed coding agents...`,success:e=>e.length===0?`No supported coding agent CLI was found on PATH.`:`Found ${e.map(e=>e.name).join(`, `)}.`});u.length===0&&(yield*t.log.info(`Doctor can hand findings off when one of these CLIs is installed: ${zt.map(e=>`\`${e.command}\``).join(`, `)}.`));let d=Rn(c,Kn),f=yield*t.select({message:`How do you want to resolve these findings?`,options:[...u.map(e=>({label:`Hand off to ${e.name}`,value:e})),{label:`Copy the Markdown prompt for a coding agent`,value:`copy`},{label:`Do nothing`,value:`done`}]});if(f===`done`)return yield*a;if(f===`copy`)return yield*t.message(d),yield*r.copyToClipboard(d),yield*t.log.success(`The Markdown prompt was printed and sent to the terminal clipboard.`),yield*a;let p=f,m=yield*Gt(e);if(m!==`clean`&&(yield*t.log.warning(m===`dirty`?`The Git working tree has uncommitted changes. The agent will edit files on top of them.`:`Doctor could not confirm a clean Git working tree. The agent will edit files without a checkpoint to return to.`),!(yield*t.confirm({initialValue:!1,message:`Hand off to ${p.name} anyway?`})))||(yield*t.log.info(`Handing the terminal to ${p.name}. Exit the agent to return to Doctor.`),!(yield*Wt({agent:p,cwd:e}).pipe(n.as(!0),n.catchTag(`AgentSessionFailed`,e=>t.log.error(e.reason===`not-found`?`\`${p.command}\` was not found on PATH. Install ${p.name} or copy the prompt instead.`:`Failed to start ${p.name}: ${e.cause.message}`).pipe(n.as(!1)))))))return yield*l(d),yield*a;let h=yield*Ln(e);if(h.findings.length===0){yield*t.log.success(`All findings were resolved by ${p.name}.`),yield*t.outro(`✅ Doctor completed successfully!`);return}return yield*t.log.warning(`${h.findings.length} of ${c.findings.length} findings remain after the ${p.name} session.`),yield*Un(h.findings),yield*l(Rn(h,Kn)),yield*a}).pipe(n.catchTag(`OperationCancelled`,()=>n.gen(function*(){return yield*(yield*Q).cancel(`Doctor was cancelled. The findings remain.`),yield*new D({command:`doctor`,exitCode:s.ExitCode(1)})})))));const Jn=C.File(`files`,{mustExist:!0}).pipe(C.withDescription(`Specific files to fix (optional)`),C.variadic()),Yn=u.Boolean(`suggested`).pipe(u.withDefault(!1),u.withDescription(`Apply suggested fixes`)),Xn=u.Boolean(`dangerous`).pipe(u.withDefault(!1),u.withDescription(`Apply dangerous fixes`)),Zn=u.Boolean(`all`).pipe(u.withDefault(!1),u.withDescription(`Apply all fixes, including suggested and dangerous fixes`));var Qn=l.make(`fix`,{all:Zn,dangerous:Xn,files:Jn,suggested:Yn}).pipe(l.withDescription(`Fix issues in code using oxlint`),l.withHandler(({all:e,dangerous:t,files:r,suggested:i})=>n.gen(function*(){let n=yield*A,a=yield*k,o=c.dedupe([`--fix`,...i||e?[`--fix-suggestions`]:[],...t||e?[`--fix-dangerously`]:[],...r]),l=yield*a.run({args:[...o,...n],command:H.name});l!==s.ExitCode(0)&&(yield*new D({command:H.name,exitCode:l}))})));const $n=C.File(`files`,{mustExist:!0}).pipe(C.withDescription(`Specific files to format (optional)`),C.variadic()),er=u.Boolean(`check`).pipe(u.withDefault(!1),u.withDescription(`Check if files are formatted without writing`));var tr=l.make(`format`,{check:er,files:$n}).pipe(l.withDescription(`Format files using oxfmt`),l.withHandler(({check:e,files:t})=>n.gen(function*(){let n=yield*A,r=yield*k,i=[];e&&i.push(`--check`),i.push(...t,...n);let a=yield*r.run({args:i,command:q.name});a!==s.ExitCode(0)&&(yield*new D({command:q.name,exitCode:a}))})));const nr=[`check`,`fix`,`format`,`check:monorepo`,`fix:monorepo`,`analyze`],rr=[`react`,`nextjs`,`vue`,`jest`,`vitest`,`node`,`antislop`],ir=[`vscode`,`zed`],ar=n.fn(`validateInitOptions`)(function*(e,t){let n={agents:e.agents,editors:c.dedupe(e.editors),githubActions:e.githubActions,installExtensions:e.installExtensions,overwriteScripts:e.overwriteScripts,presets:c.dedupe(e.presets),scripts:c.dedupe(e.scripts),typescript:e.typescript};if(n.scripts.length===0)return yield*new O({reason:"Select at least one script with `--script <name>`."});let r=n.scripts.includes(`check`)||n.scripts.includes(`fix`);return(n.scripts.includes(`check:monorepo`)||n.scripts.includes(`fix:monorepo`))&&!t.isMonorepo?yield*new O({reason:`Monorepo scripts can only be selected in a detected monorepo.`}):n.presets.length>0&&!r?yield*new O({reason:"`--preset` requires the `check` or `fix` script."}):n.typescript&&!r?yield*new O({reason:"`--typescript` requires the `check` or `fix` script."}):n.installExtensions&&n.editors.length===0?yield*new O({reason:"`--install-extensions` requires at least one `--editor`."}):n.githubActions&&!Jt(n.scripts)?yield*new O({reason:"`--github-actions` requires a CI-compatible script."}):n.githubActions&&t.nonInteractive&&!Ve(t.packageManager)?yield*new O({reason:`\`--github-actions\` does not support the detected package manager \`${t.packageManager}\`. Use bun, deno, npm, pnpm, or yarn.`}):n}),or=u.Boolean(`non-interactive`).pipe(u.withDefault(!1),u.withDescription(`Configure without prompts; requires at least one --script`)),sr=u.Literals(`script`,nr).pipe(u.atMost(nr.length),u.withDescription(`Package script to configure; repeatable and required in non-interactive mode. Monorepo scripts require a detected monorepo`)),cr=u.Literals(`preset`,rr).pipe(u.atMost(rr.length),u.withDescription(`Oxlint preset to configure; repeatable and requires --script check or fix`)),lr=u.Literals(`editor`,ir).pipe(u.atMost(ir.length),u.withDescription(`Editor to configure; may be specified multiple times`)),ur=u.Boolean(`typescript`).pipe(u.withDefault(!1),u.withDescription(`Configure the TypeScript preset; requires --script check or fix`)),dr=u.Boolean(`install-extensions`).pipe(u.withDefault(!1),u.withDescription(`Install recommended extensions; requires at least one --editor`)),fr=u.Boolean(`github-actions`).pipe(u.withDefault(!1),u.withDescription(`Configure CI; requires a compatible script and bun, deno, npm, pnpm, or yarn`)),pr={agents:u.Boolean(`agents`).pipe(u.withDefault(!1),u.withDescription(`Add Adamantite guidance to AGENTS.md`)),editors:lr,githubActions:fr,installExtensions:dr,nonInteractive:or,overwriteScripts:u.Boolean(`overwrite-scripts`).pipe(u.withDefault(!1),u.withDescription(`Replace existing package scripts that conflict with Adamantite's managed commands`)),presets:cr,scripts:sr,typescript:ur},mr=e=>`\`${e.script}\` is currently \`${e.command}\`; Adamantite would replace it with \`${z[e.script]}\`.`,hr=n.fn(`collectInteractiveInitOptions`)(function*(e,t){let n=yield*Q,r=yield*n.multiselect({message:"Which scripts do you want to add to your `package.json`?",options:[{hint:`recommended`,label:`check - find issues and type errors using oxlint`,value:`check`},{hint:`recommended`,label:`fix - fix code issues using oxlint`,value:`fix`},{hint:`recommended`,label:`format - code formatting using oxfmt`,value:`format`},{disabled:!t,hint:t?void 0:`available for monorepo projects`,label:`check:monorepo - check for monorepo-specific issues using Sherif`,value:`check:monorepo`},{disabled:!t,hint:t?void 0:`available for monorepo projects`,label:`fix:monorepo - fix monorepo-specific issues using Sherif`,value:`fix:monorepo`},{label:`analyze - find unused dependencies, exports, and files using knip`,value:`analyze`}]}),i=Ue(yield*R(e),r),a=!1;if(i.length>0){for(let e of i)yield*n.log.warning(mr(e));a=yield*n.confirm({initialValue:!1,message:i.length===1?`Overwrite this existing script with Adamantite's command?`:`Overwrite these existing scripts with Adamantite's commands?`})}let o=r.includes(`check`)||r.includes(`fix`),s=[];o&&(s=yield*n.multiselect({message:`Which presets do you want to install? (core is always included)`,options:[{hint:`React correctness, JSX accessibility, and render performance rules`,label:`react`,value:`react`},{hint:`Next.js pitfalls around scripts, fonts, images, and document/head usage`,label:`next.js`,value:`nextjs`},{hint:`Vue 3 correctness rules and deprecated API detection`,label:`vue`,value:`vue`},{hint:`Jest test hygiene: focused/disabled tests, matcher and snapshot discipline`,label:`jest`,value:`jest`},{hint:`Vitest test hygiene: focused/disabled tests, matcher and snapshot discipline`,label:`vitest`,value:`vitest`},{hint:`Node.js callback and CommonJS pitfalls`,label:`node`,value:`node`},{hint:`Rejects low-signal escape hatches: unjustified assertions, unknown leaks, module mocks`,label:`antislop`,value:`antislop`}],required:!1}));let c=o?yield*n.confirm({initialValue:!0,message:t?"Adamantite provides a TypeScript preset to enforce strict type-safety. In a monorepo, each package's `tsconfig.json` must extend it. Would you like instructions on how to set it up?":`Adamantite provides a TypeScript preset to enforce strict type-safety. Would you like to use it?`}):!1,l=yield*n.multiselect({message:`Which editors do you want to configure? (optional)`,options:[{label:`VSCode / Cursor / Windsurf`,value:`vscode`},{label:`Zed`,value:`zed`}],required:!1}),u=l.length>0?yield*n.confirm({initialValue:!0,message:`Do you want to install the recommended editor extensions?`}):!1,d=Jt(r)?yield*n.confirm({message:`Do you want to add a GitHub Actions workflow to run checks in CI?`}):!1;return{agents:yield*n.confirm({initialValue:!0,message:`Add Adamantite guidance to AGENTS.md so coding agents know how to run project checks?`}),editors:l,githubActions:d,installExtensions:u,overwriteScripts:a,presets:s,scripts:r,typescript:c}}),gr=[{path:`.vscode/settings.json`,type:`config`}],_r={"[css]":{"editor.defaultFormatter":`oxc.oxc-vscode`},"[graphql]":{"editor.defaultFormatter":`oxc.oxc-vscode`},"[javascript]":{"editor.defaultFormatter":`oxc.oxc-vscode`},"[javascriptreact]":{"editor.defaultFormatter":`oxc.oxc-vscode`},"[json]":{"editor.defaultFormatter":`oxc.oxc-vscode`},"[jsonc]":{"editor.defaultFormatter":`oxc.oxc-vscode`},"[typescript]":{"editor.defaultFormatter":`oxc.oxc-vscode`},"[typescriptreact]":{"editor.defaultFormatter":`oxc.oxc-vscode`},"editor.codeActionsOnSave":{"source.fixAll.oxc":`explicit`},"editor.defaultFormatter":`oxc.oxc-vscode`,"editor.formatOnPaste":!0,"editor.formatOnSave":!0,"oxc.typeAware":!0};var $=j({config:gr[0].path,create:e=>n.gen(function*(){let t=yield*x.Path,n=t.join(e,gr[0].path);yield*Me(t.dirname(n)),yield*F(n,_r)}),detect:e=>n.gen(function*(){let t=yield*b.FileSystem,n=yield*x.Path;return yield*t.exists(n.join(e,gr[0].path))}),extension:(e=[])=>n.gen(function*(){let t=[];(e.includes(`check`)||e.includes(`fix`)||e.includes(`format`))&&t.push(`oxc.oxc-vscode`),e.includes(`analyze`)&&t.push(`webpro.vscode-knip`);for(let e of t){let t=yield*(yield*k).run({args:[`--install-extension`,e],command:`code`}).pipe(n.mapError(t=>t._tag===`CliNotFound`&&t.command===`code`?new je({cause:t}):new be({cause:t,extension:e})));if(t!==s.ExitCode(0))return yield*new be({cause:t,extension:e})}}),files:gr,kind:`editor`,name:`vscode`,update:e=>n.gen(function*(){let t=(yield*x.Path).join(e,gr[0].path),n=yield*M(t),r=yield*I(n,t);if(!_.isObject(r))return yield*new Ee({path:t});let i=yield*Ie(_r,r);yield*F(t,i)})});const vr=`<!-- ADAMANTITE:START -->`,yr=`<!-- ADAMANTITE:END -->`;function br(e,t){let n=de(e,t),r=z[t];switch(t){case`analyze`:return`- Run \`${n}\` after changing dependencies, imports, or exports. Direct command: \`${r}\`.`;case`check`:return`- Run \`${n}\` to catch lint and type issues. Direct command: \`${r}\`.`;case`check:monorepo`:return`- Run \`${n}\` to check monorepo package consistency. Direct command: \`${r}\`.`;case`fix`:return`- Run \`${n}\` to apply safe lint fixes. Direct command: \`${r}\`.`;case`fix:monorepo`:return`- Run \`${n}\` to fix monorepo package consistency. Direct command: \`${r}\`.`;case`format`:return`- Run \`${n}\` after editing files. Direct command: \`${r}\`.`}}function xr({packageManager:e,scripts:t}){let n=[`format`,`check`,`fix`,`analyze`,`check:monorepo`,`fix:monorepo`].filter(e=>t.includes(e)).map(t=>br(e,t)),r=[`## Adamantite`,``,`This project uses Adamantite for its managed formatting, linting, type checking, and dependency-analysis setup.`,``,...n.length>0?[`- Prefer the package scripts Adamantite added for this workspace.`,...n]:[],"- Run `adamantite doctor` and follow its findings to repair managed setup."].join(`
|
|
103
|
-
`);return[
|
|
104
|
-
`)}const
|
|
105
|
-
`)?a:`${a}\n`),`updated`}if(
|
|
92
|
+
`)}const tr=t.fn(`printFindings`)(function*(e){let t=yield*Q;for(let[n,r]of e.entries())yield*t.note(er(r),`${n+1}. ${r.title}`)}),nr=`0.42.0`;var rr=c.make(`doctor`).pipe(c.withDescription(`Assess Adamantite-managed integrations in the current project`),c.withHandler(()=>t.gen(function*(){let e=f.cwd(),n=yield*Qn,i=yield*Q,a=yield*$n,o=yield*a.isInteractive;o&&(yield*i.intro(`💠 adamantite doctor`));let s=t.gen(function*(){return yield*i.outro(`⚠️ Doctor found issues.`),yield*new he({command:`doctor`,exitCode:r.ExitCode(1)})}),c=yield*L(e);if(!c.devDependencies?.adamantite&&!c.dependencies?.adamantite){let e="`adamantite` is not installed in this project. Install it before running `adamantite doctor`.";return o?(yield*i.log.warning(e),yield*i.outro(`⚠️ Doctor found issues.`)):yield*i.message(e),yield*new he({command:`doctor`,exitCode:r.ExitCode(1)})}let l=yield*Wn(e);if(o)for(let e of l.warnings)yield*i.log.warning(e);if(l.applicableIntegrations.length===0){o&&(yield*i.log.success(`No applicable integrations found.`),yield*i.outro(`✅ Doctor completed successfully!`));return}if(l.findings.length===0){o?(yield*i.log.success(`No issues found.`),yield*i.outro(`✅ Doctor completed successfully!`)):l.warnings.length>0&&(yield*i.message(Gn(l,nr)));return}if(!o)return yield*i.message(Gn(l,nr)),yield*new he({command:`doctor`,exitCode:r.ExitCode(1)});let u=e=>t.gen(function*(){(yield*i.confirm({initialValue:!0,message:`Copy the Markdown prompt for a coding agent?`}))&&(yield*i.message(e),yield*a.copyToClipboard(e),yield*i.log.success(`The Markdown prompt was printed and sent to the terminal clipboard.`))});yield*tr(l.findings);let d=yield*i.withSpinner(()=>n.detectInstalled(e),{start:`Checking for installed coding agents...`,success:e=>e.length===0?`No supported coding agent CLI was found on PATH.`:`Found ${e.map(e=>e.name).join(`, `)}.`});d.length===0&&(yield*i.log.info(`Doctor can hand findings off when one of these CLIs is installed: ${Jn.map(e=>`\`${e.command}\``).join(`, `)}.`));let p=Gn(l,nr),m=yield*i.select({message:`How do you want to resolve these findings?`,options:[...d.map(e=>({label:`Hand off to ${e.name}`,value:e})),{label:`Copy the Markdown prompt for a coding agent`,value:`copy`},{label:`Do nothing`,value:`done`}]});if(m===`done`)return yield*s;if(m===`copy`)return yield*i.message(p),yield*a.copyToClipboard(p),yield*i.log.success(`The Markdown prompt was printed and sent to the terminal clipboard.`),yield*s;let h=m;if(yield*i.log.info(`Handing the terminal to ${h.name}. Exit the agent to return to Doctor.`),!(yield*n.runSession({agent:h,cwd:e,prompt:p}).pipe(t.as(!0),t.catchTag(`AgentSessionFailed`,e=>i.log.error(e.reason===`not-found`?`\`${h.command}\` was not found on PATH. Install ${h.name} or copy the prompt instead.`:`Failed to start ${h.name}: ${e.cause.message}`).pipe(t.as(!1))))))return yield*u(p),yield*s;let g=yield*Wn(e);if(g.findings.length===0){yield*i.log.success(`All findings were resolved by ${h.name}.`),yield*i.outro(`✅ Doctor completed successfully!`);return}return yield*i.log.warning(`${g.findings.length} of ${l.findings.length} findings remain after the ${h.name} session.`),yield*tr(g.findings),yield*u(Gn(g,nr)),yield*s}).pipe(t.catchTag(`OperationCancelled`,()=>t.gen(function*(){return yield*(yield*Q).cancel(`Doctor was cancelled. The findings remain.`),yield*new he({command:`doctor`,exitCode:r.ExitCode(1)})})))));const ir=w.File(`files`,{mustExist:!0}).pipe(w.withDescription(`Specific files to fix (optional)`),w.variadic()),ar=u.Boolean(`suggested`).pipe(u.withDefault(!1),u.withDescription(`Apply suggested fixes`)),or=u.Boolean(`dangerous`).pipe(u.withDefault(!1),u.withDescription(`Apply dangerous fixes`)),sr=u.Boolean(`all`).pipe(u.withDefault(!1),u.withDescription(`Apply all fixes, including suggested and dangerous fixes`)),cr=u.Literals(`only`,[`format`,`lint`]).pipe(u.optional,u.withDescription("Run one stage: `format` (oxfmt) or `lint` (oxlint). Arguments after `--` go to that stage"));var lr=c.make(`fix`,{all:sr,dangerous:or,files:ir,only:cr,suggested:ar}).pipe(c.withDescription(`Fix lint and formatting issues in code`),c.withHandler(({all:e,dangerous:n,files:r,only:i,suggested:a})=>t.gen(function*(){let t=yield*Ne,o=yield*k,c=d.getOrUndefined(i);if(c===`format`&&(e||n||a))return yield*new Te({reason:"`--suggested`, `--dangerous`, and `--all` apply to the lint stage. Remove them or `--only format`."});let l=s.dedupe(r),u=c??`lint`,f=[{args:s.dedupe([`--fix`,...a||e?[`--fix-suggestions`]:[],...n||e?[`--fix-dangerously`]:[],...l]),command:G.name,name:`lint`,title:`🔧 Fixing lint issues`},{args:[`--write`,...l],command:U.name,name:`format`,title:`✨ Formatting`}];yield*o.runAll(f.filter(e=>c===void 0||e.name===c).map(e=>({args:[...e.args,...e.name===u?t:[]],command:e.command,title:e.title})))})));const ur=' .o8 . o8o . \n "888 .o8 `"\' .o8 \n .oooo. .oooo888 .oooo. ooo. .oo. .oo. .oooo. ooo. .oo. .o888oo oooo .o888oo .ooooo. \n`P )88b d88\' `888 `P )88b `888P"Y88bP"Y88b `P )88b `888P"Y88b 888 `888 888 d88\' `88b \n .oP"888 888 888 .oP"888 888 888 888 .oP"888 888 888 888 888 888 888ooo888 \nd8( 888 888 888 d8( 888 888 888 888 d8( 888 888 888 888 . 888 888 . 888 .o \n`Y888""8o `Y8bod88P" `Y888""8o o888o o888o o888o `Y888""8o o888o o888o "888" o888o "888" `Y8bod8P\' \n \n \n ',dr=()=>t.gen(function*(){let e=yield*(yield*ue.Terminal).columns,t=ur.split(`
|
|
93
|
+
`).reduce((e,t)=>Math.max(e,t.trim().length),0);!e||e<t||(yield*h.info(ur))}),fr=[`check`,`fix`,`analyze`],pr=[`vscode`,`zed`],mr=t.fn(`validateInitOptions`)(function*(e,t){let n={agents:e.agents,editors:s.dedupe(e.editors),githubActions:e.githubActions,installExtensions:e.installExtensions,overwriteScripts:e.overwriteScripts,presets:s.dedupe(e.presets),scripts:s.dedupe(e.scripts),typescript:e.typescript};if(n.scripts.length===0)return yield*new O({reason:"Select at least one script with `--script <name>`."});let r=n.scripts.includes(`check`)||n.scripts.includes(`fix`);return n.presets.length>0&&!r?yield*new O({reason:"`--preset` requires the `check` or `fix` script."}):n.presets.includes(`react-doctor`)&&!n.presets.includes(`react`)?yield*new O({reason:"`--preset react-doctor` requires `--preset react`."}):n.typescript&&!r?yield*new O({reason:"`--typescript` requires the `check` or `fix` script."}):n.installExtensions&&n.editors.length===0?yield*new O({reason:"`--install-extensions` requires at least one `--editor`."}):n.githubActions&&!$t(n.scripts)?yield*new O({reason:"`--github-actions` requires a CI-compatible script."}):n.githubActions&&t.nonInteractive&&!Ve(t.packageManager)?yield*new O({reason:`\`--github-actions\` does not support the detected package manager \`${t.packageManager}\`. Use bun, deno, npm, pnpm, or yarn.`}):n}),hr=u.Boolean(`non-interactive`).pipe(u.withDefault(!1),u.withDescription(`Configure without prompts; requires at least one --script`)),gr=u.Literals(`script`,fr).pipe(u.atMost(fr.length),u.withDescription(`Package script to configure; repeatable and required in non-interactive mode`)),_r=u.Literals(`preset`,jt).pipe(u.atMost(jt.length),u.withDescription(`Oxlint preset to configure; repeatable and requires --script check or fix`)),vr=u.Literals(`editor`,pr).pipe(u.atMost(pr.length),u.withDescription(`Editor to configure; may be specified multiple times`)),yr=u.Boolean(`typescript`).pipe(u.withDefault(!1),u.withDescription(`Configure the TypeScript preset; requires --script check or fix`)),br=u.Boolean(`install-extensions`).pipe(u.withDefault(!1),u.withDescription(`Install recommended extensions; requires at least one --editor`)),xr=u.Boolean(`github-actions`).pipe(u.withDefault(!1),u.withDescription(`Configure CI; requires a compatible script and bun, deno, npm, pnpm, or yarn`)),Sr={agents:u.Boolean(`agents`).pipe(u.withDefault(!1),u.withDescription(`Add Adamantite guidance to AGENTS.md`)),editors:vr,githubActions:xr,installExtensions:br,nonInteractive:hr,overwriteScripts:u.Boolean(`overwrite-scripts`).pipe(u.withDefault(!1),u.withDescription(`Replace existing package scripts that conflict with Adamantite's managed commands`)),presets:_r,scripts:gr,typescript:yr},Cr=e=>`\`${e.script}\` is currently \`${e.command}\`; Adamantite would replace it with \`${R[e.script]}\`.`,wr=t.fn(`collectInteractiveInitOptions`)(function*(e,t){let n=yield*Q,r=yield*n.multiselect({message:"Which scripts do you want to add to your `package.json`?",options:[{hint:`recommended`,label:`check - check formatting, lint issues, and type errors`,value:`check`},{hint:`recommended`,label:`fix - apply safe lint fixes and format code`,value:`fix`},{label:t?`analyze - check monorepo consistency using Sherif and find unused dependencies, exports, and files using knip`:`analyze - find unused dependencies, exports, and files using knip`,value:`analyze`}]}),i=He(yield*L(e),r),a=!1;if(i.length>0){for(let e of i)yield*n.log.warning(Cr(e));a=yield*n.confirm({initialValue:!1,message:i.length===1?`Overwrite this existing script with Adamantite's command?`:`Overwrite these existing scripts with Adamantite's commands?`})}let o=r.includes(`check`)||r.includes(`fix`),s=[];o&&(s=yield*n.multiselect({message:`Which presets do you want to install? (core is always included)`,options:[{hint:`React correctness, JSX accessibility, and render performance rules`,label:`react`,value:`react`},{hint:`Strict React feature code: no state, effect, or memoization hooks outside hook modules`,label:`react-strict`,value:`react-strict`},{hint:`React state and effect misuse, such as effects used as event handlers and fetches in effects; requires react`,label:`react-doctor`,value:`react-doctor`},{hint:`Next.js pitfalls around scripts, fonts, images, and document/head usage`,label:`next.js`,value:`nextjs`},{hint:`Vue 3 correctness rules and deprecated API detection`,label:`vue`,value:`vue`},{hint:`Jest test hygiene: focused/disabled tests, matcher and snapshot discipline`,label:`jest`,value:`jest`},{hint:`Vitest test hygiene: focused/disabled tests, matcher and snapshot discipline`,label:`vitest`,value:`vitest`},{hint:`Node.js callback and CommonJS pitfalls`,label:`node`,value:`node`},{hint:`Framework-neutral strictness: no deep or wide destructuring, no type assertions outside tests`,label:`strict`,value:`strict`},{hint:`Rejects low-signal escape hatches: unjustified assertions, unknown leaks, module mocks`,label:`antislop`,value:`antislop`},{hint:`Tailwind v4 design system: no restyled components, raw colors, arbitrary values, or unknown classes`,label:`shadcn`,value:`shadcn`}],required:!1}),s.includes(`react-doctor`)&&!s.includes(`react`)&&(s=[`react`,...s],yield*n.log.info("Added the `react` preset, which `react-doctor` requires.")));let c=o?yield*n.confirm({initialValue:!0,message:t?"Adamantite provides a TypeScript preset to enforce strict type-safety. In a monorepo, each package's `tsconfig.json` must extend it. Would you like instructions on how to set it up?":`Adamantite provides a TypeScript preset to enforce strict type-safety. Would you like to use it?`}):!1,l=yield*n.multiselect({message:`Which editors do you want to configure? (optional)`,options:[{label:`VSCode / Cursor / Windsurf`,value:`vscode`},{label:`Zed`,value:`zed`}],required:!1}),u=l.length>0?yield*n.confirm({initialValue:!0,message:`Do you want to install the recommended editor extensions?`}):!1,d=$t(r)?yield*n.confirm({message:`Do you want to add a GitHub Actions workflow to run checks in CI?`}):!1;return{agents:yield*n.confirm({initialValue:!0,message:`Add Adamantite guidance to AGENTS.md so coding agents know how to run project checks?`}),editors:l,githubActions:d,installExtensions:u,overwriteScripts:a,presets:s,scripts:r,typescript:c}}),Tr=[{path:`.vscode/settings.json`,type:`config`}],Er={"[css]":{"editor.defaultFormatter":`oxc.oxc-vscode`},"[graphql]":{"editor.defaultFormatter":`oxc.oxc-vscode`},"[javascript]":{"editor.defaultFormatter":`oxc.oxc-vscode`},"[javascriptreact]":{"editor.defaultFormatter":`oxc.oxc-vscode`},"[json]":{"editor.defaultFormatter":`oxc.oxc-vscode`},"[jsonc]":{"editor.defaultFormatter":`oxc.oxc-vscode`},"[typescript]":{"editor.defaultFormatter":`oxc.oxc-vscode`},"[typescriptreact]":{"editor.defaultFormatter":`oxc.oxc-vscode`},"editor.codeActionsOnSave":{"source.fixAll.oxc":`explicit`},"editor.defaultFormatter":`oxc.oxc-vscode`,"editor.formatOnPaste":!0,"editor.formatOnSave":!0,"oxc.typeAware":!0};var $=A({config:Tr[0].path,create:e=>t.gen(function*(){let t=yield*C.Path,n=t.join(e,Tr[0].path);yield*Pe(t.dirname(n)),yield*P(n,Er)}),detect:e=>t.gen(function*(){let t=yield*S.FileSystem,n=yield*C.Path;return yield*t.exists(n.join(e,Tr[0].path))}),extension:(e=[])=>t.gen(function*(){let n=[];(e.includes(`check`)||e.includes(`fix`))&&n.push(`oxc.oxc-vscode`),e.includes(`analyze`)&&n.push(`webpro.vscode-knip`);for(let e of n)yield*(yield*k).run({args:[`--install-extension`,e],command:`code`}).pipe(t.mapError(t=>t._tag===`CliNotFound`&&t.command===`code`?new ke({cause:t}):new ve({cause:t._tag===`CommandFailed`?t.exitCode:t,extension:e})))}),files:Tr,kind:`editor`,name:`vscode`,update:e=>t.gen(function*(){let t=(yield*C.Path).join(e,Tr[0].path),n=yield*j(t),r=yield*F(n,t);if(!b.isObject(r))return yield*new Ce({path:t});let i=yield*Ie(Er,r);yield*P(t,i)})});const Dr=`<!-- ADAMANTITE:START -->`,Or=`<!-- ADAMANTITE:END -->`;function kr(e,t,n){let r=le(e,t),i=R[t];switch(t){case`analyze`:return`- Run \`${r}\` after changing dependencies, imports, or exports.${n?` It also checks monorepo package consistency.`:``} Direct command: \`${i}\`.`;case`check`:return`- Run \`${r}\` to catch formatting, lint, and type issues. Direct command: \`${i}\`.`;case`fix`:return`- Run \`${r}\` to apply safe lint fixes and format code. Direct command: \`${i}\`.`}}function Ar({isMonorepo:e,packageManager:t,scripts:n}){let r=[`check`,`fix`,`analyze`].filter(e=>n.includes(e)).map(n=>kr(t,n,e)),i=[`## Adamantite`,``,`This project uses Adamantite for its managed formatting, linting, type checking, and dependency-analysis setup.`,``,...r.length>0?[`- Prefer the package scripts Adamantite added for this workspace.`,...r]:[],"- Run `adamantite doctor` and follow its findings to repair managed setup."].join(`
|
|
94
|
+
`);return[Dr,``,i,``,Or,``].join(`
|
|
95
|
+
`)}const jr=(e,n)=>t.gen(function*(){let t=(yield*C.Path).join(e,`AGENTS.md`),r=y(yield*M(t),d.getOrElse(()=>``)),i=y(r,x.indexOf(Dr)),a=y(r,x.indexOf(Or)),o=y(d.all({end:a,start:i}),d.filter(({end:e,start:t})=>t<e)),s=Ar(n);if(d.isSome(o)){let{end:e,start:n}=o.value,i=e+23,a=`${r.slice(0,n)}${s.trimEnd()}${r.slice(i)}`;return yield*N(t,a.endsWith(`
|
|
96
|
+
`)?a:`${a}\n`),`updated`}if(d.isSome(i)||d.isSome(a))return`malformed`;let c=r.length===0||r.endsWith(`
|
|
106
97
|
|
|
107
98
|
`)?``:r.endsWith(`
|
|
108
99
|
`)?`
|
|
109
100
|
`:`
|
|
110
101
|
|
|
111
|
-
`;return yield*P(n,`${r}${c}${s}`),`updated`}),Cr=(e,t)=>n.gen(function*(){let r=yield*U;yield*(yield*Q).withSpinner(()=>n.gen(function*(){let n=yield*An(e);yield*r.addDevDependencies(t,e,{silent:!0,workspace:n})}),{failure:`Failed to install dependencies.`,start:`Installing dependencies...`,success:`Dependencies installed.`})});function wr(e,t,r){return n.gen(function*(){let i=yield*Q,a=yield*i.withSpinner(a=>n.gen(function*(){let n=yield*t.detect(e);for(let e of n.warnings)yield*i.log.warning(e);return n.active===null?(yield*a.message(`\`${t.config}\` not found, creating...`),yield*r,{created:!0,legacyConfig:null}):n.active.format===`ts`?(yield*a.message(`Found \`${t.config}\`, keeping existing config.`),{created:!1,legacyConfig:null}):(yield*a.message(`Found \`${n.active.file}\`, keeping existing config.`),{created:!1,legacyConfig:n.active.file})}),{failure:`Failed to set up ${t.name} config.`,start:`Setting up ${t.name} config...`,success:e=>e.created?`${t.name} config created successfully.`:`${t.name} config is ready.`});a.legacyConfig&&(yield*i.log.info(`Legacy \`${a.legacyConfig}\` was preserved during \`adamantite init\`. Run \`adamantite doctor\` and follow its findings to migrate it to the latest ${t.name} config.`))})}const Tr=(e,t,r)=>n.gen(function*(){let i=yield*Q,a=yield*R(e),o=r.overwriteScripts?[]:Ue(a,t),s=new Set(o.map(e=>e.script)),c=t.filter(e=>!s.has(e));yield*i.withSpinner(()=>n.gen(function*(){if(c.length!==0){a.scripts??={};for(let e of c)a.scripts[e]=z[e];yield*Be(e,a)}}),{failure:"Failed to add scripts to `package.json`.",start:"Adding scripts to your `package.json`...",success:o.length===0?"Scripts added to your `package.json`":c.length===0?"Kept your existing `package.json` scripts.":"Scripts added to your `package.json`; conflicting scripts were kept."});let l=r.nonInteractive?"Use `--overwrite-scripts` to replace it.":"Re-run `adamantite init` and confirm overwriting to replace it.";for(let e of o)yield*i.log.warning(`Kept existing \`${e.script}\` script (\`${e.command}\`) instead of \`${z[e.script]}\`. ${l}`);return o.length>0&&(yield*i.log.info("Adamantite commands forward extra arguments after `--`, so custom flags can be kept, e.g. `adamantite monorepo -- --ignore-dependency tailwindcss`.")),c}),Er=(e,t)=>n.gen(function*(){let r=yield*Q;if(t){yield*h(Mn,n.forEach(e=>r.log.info(e)));return}yield*r.withSpinner(t=>n.gen(function*(){return(yield*Z.detect(e))?(yield*t.message(`\`${Z.config}\` found, updating...`),yield*Z.update(e),!1):(yield*t.message(`\`${Z.config}\` not found, creating...`),yield*Z.create(e),!0)}),{failure:`Failed to set up TypeScript config.`,start:`Setting up TypeScript config...`,success:e=>e?`\`${Z.config}\` created successfully`:`\`${Z.config}\` updated successfully`})}),Dr=(e,t)=>n.gen(function*(){let r=yield*Q;t.includes(`vscode`)&&(yield*r.withSpinner(t=>n.gen(function*(){let n=yield*$.detect(e);return yield*t.message(`\`${$.config}\` ${n?`found, updating`:`not found, creating`}...`),yield*n?$.update(e):$.create(e),!n}),{failure:`Failed to set up VS Code config.`,start:`Checking for \`${$.config}\`...`,success:e=>`\`${$.config}\` ${e?`created`:`updated`} with Adamantite preset.`})),t.includes(`zed`)&&(yield*r.withSpinner(t=>n.gen(function*(){let n=yield*K.detect(e);return yield*t.message(`\`${K.config}\` ${n?`found, updating`:`not found, creating`}...`),yield*n?K.update(e):K.create(e),!n}),{failure:`Failed to set up Zed config.`,start:`Checking for \`${K.config}\`...`,success:e=>`\`${K.config}\` ${e?`created`:`updated`} with Adamantite preset.`}))}),Or=(e,t)=>n.gen(function*(){let r=yield*Q,i=e.includes(`zed`),a=e.includes(`vscode`);yield*r.withSpinner(e=>n.gen(function*(){return a&&(yield*e.message(`Installing VS Code extension...`),yield*$.extension(t)),!0}),{start:`Installing editor extensions...`,success:i&&!a?`Zed extensions require manual install.`:`Editor extensions installed successfully.`}).pipe(n.catchTag(`FailedToInstallExtension`,e=>n.gen(function*(){return yield*r.log.warning(`⚠️ ${e.message}`),yield*r.log.warning(`Please install it manually after setup completes.`),!1})),n.catchTag(`VscodeCliNotFound`,()=>n.gen(function*(){return yield*r.log.error(`VSCode CLI ('code' command) not found.`),yield*r.log.info(`To install it:`),yield*r.log.info(` 1. Open VS Code`),yield*r.log.info(` 2. Press Cmd+Shift+P (macOS) or Ctrl+Shift+P (Windows/Linux)`),yield*r.log.info(` 3. Run 'Shell Command: Install "code" command in PATH'`),!1}))),i&&(yield*r.log.info("Install the Zed `oxc` extension: zed://extension/oxc"))}),kr=(e,t,r)=>n.gen(function*(){let i=yield*Q,a=W.files[0].path;yield*i.withSpinner(i=>n.gen(function*(){let n=yield*W.detect(e);return yield*i.message(n?`\`${a}\` found, updating...`:`Creating \`${a}\`...`),yield*n?W.update(e,{packageManager:t,scripts:r}):W.create(e,{packageManager:t,scripts:r}),!n}),{failure:`Failed to set up GitHub Actions workflow.`,start:`Setting up GitHub Actions workflow...`,success:e=>`GitHub Actions workflow ${e?`created`:`updated`} successfully.`})}).pipe(n.catchTag([`FailedToCreateDirectory`,`FailedToParseFile`,`FailedToReadFile`,`FailedToWriteFile`,`PlatformError`],e=>n.gen(function*(){let t=yield*Q;yield*t.log.warning(`Could not set up the GitHub Actions workflow. ${e.message}`),yield*t.log.warning("Fix the reported problem and run `adamantite init` again, or create the workflow manually.")}))),Ar=(e,t,r)=>n.gen(function*(){let i=yield*Q,a=yield*i.withSpinner(()=>Sr(e,{packageManager:t,scripts:r}),{failure:`Failed to update AGENTS.md.`,start:`Updating AGENTS.md...`,success:`AGENTS.md check complete.`}).pipe(n.catchTag([`FailedToReadFile`,`FailedToWriteFile`],e=>n.gen(function*(){return yield*i.log.warning(`Could not update AGENTS.md. ${e.message} Adamantite will continue initialization.`),`failed`})));a!==`failed`&&a===`malformed`&&(yield*i.log.warning(`Could not update AGENTS.md because Adamantite markers are incomplete. Remove the stale ADAMANTITE marker and run adamantite init again.`))});var jr=l.make(`init`,pr).pipe(l.withDescription(`Initialize Adamantite in the current directory. Setup flags require --non-interactive; omitted boolean setup flags are disabled`),l.withExamples([{command:`adamantite init --non-interactive --script check`,description:`Configure linting without prompts`},{command:`adamantite init --non-interactive --script check --script format --preset react --editor vscode --typescript --install-extensions --github-actions --agents`,description:`Configure a React project with VS Code, TypeScript, CI, and agent guidance`},{command:`adamantite init --non-interactive --script check:monorepo`,description:`Configure monorepo checks in a detected monorepo`}]),l.withHandler(e=>n.gen(function*(){let t=S.cwd(),n=yield*Q;yield*Gn(),yield*n.intro(`💠 adamantite init`);let r=yield*(yield*U).detectPackageManager(t);if(!r)return yield*new Oe({});if(r.warnings?.length)for(let e of r.warnings)yield*n.log.warning(e);yield*n.log.info(`Detected package manager: ${r.name}`);let i=yield*An(t);if(i&&(yield*n.log.info(`We've detected a monorepo setup in your project.`)),!e.nonInteractive&&c.some([e.scripts.length>0,e.presets.length>0,e.editors.length>0,e.typescript,e.installExtensions,e.githubActions,e.agents,e.overwriteScripts],_.isTruthy))return yield*new O({reason:"Setup flags require `--non-interactive`."});let a=e.nonInteractive?e:yield*hr(t,i),o=yield*ar(a,{isMonorepo:i,nonInteractive:e.nonInteractive,packageManager:r.name}),s=o.scripts,l=o.presets,u=o.editors,d=o.typescript,f=o.installExtensions,p=o.githubActions,m=o.agents,h=s.includes(`check`)||s.includes(`fix`),g=s.includes(`format`),v=s.includes(`check:monorepo`)||s.includes(`fix:monorepo`),ee=s.includes(`analyze`),y=[`adamantite`];h&&y.push(`${H.name}@${H.version}`,`${En.name}@${En.version}`),g&&y.push(`${q.name}@${q.version}`),v&&y.push(`${J.name}@${J.version}`),ee&&y.push(`${B.name}@${B.version}`),yield*Cr(t,y),g&&(yield*wr(t,q,q.create(t))),h&&(yield*wr(t,H,H.create(t,l))),ee&&(yield*wr(t,B,B.create(t)));let b=yield*Tr(t,s,{nonInteractive:e.nonInteractive,overwriteScripts:o.overwriteScripts});if(m&&(yield*Ar(t,r.name,b)),d&&(yield*Er(t,i)),yield*Dr(t,u),f&&(yield*Or(u,s)),p){let e=r.name;Ve(e)?yield*kr(t,e,s):yield*n.log.warning(`Skipping GitHub Actions setup: \`${e}\` is not a supported package manager for CI workflow generation.`)}yield*n.log.success(`Your project is now configured`),yield*n.outro(`💠 Adamantite initialized successfully!`)}).pipe(n.catchTags({OperationCancelled:()=>n.gen(function*(){yield*(yield*Q).cancel(`You've cancelled the initialization process.`)})}))));const Mr=u.Boolean(`fix`).pipe(u.withDefault(!1),u.withDescription(`Automatically fix issues`));var Nr=l.make(`monorepo`,{fix:Mr}).pipe(l.withDescription(`Find and fix monorepo-specific issues using Sherif`),l.withHandler(({fix:e})=>n.gen(function*(){let t=yield*A,n=yield*k,r=e?[`--fix`,...t]:[...t],i=yield*n.run({args:r,command:J.name,stdin:`inherit`});i!==s.ExitCode(0)&&(yield*new D({command:J.name,exitCode:i}))})));const Pr=[H,En,q,J,B];function Fr(e,t){return c.filterMap(Pr,n=>{if(t.has(n.name))return ne.failVoid;let r=e.devDependencies?.[n.name]??e.dependencies?.[n.name];return r&&ze(r)!==n.version?ne.succeed({currentVersion:r,name:n.name,targetVersion:n.version}):ne.failVoid})}var Ir=l.make(`update`).pipe(l.withDescription(`Update Adamantite-managed dependencies and report setup findings`),l.withHandler(()=>n.gen(function*(){let e=S.cwd(),t=yield*Q,n=yield*U;yield*Gn(),yield*t.intro(`💠 adamantite update`);let r=yield*R(e),i=yield*Ln(e,r),a=i.packageActions,o=new Set(a.map(e=>e.package)),s=[...a.map(e=>({currentVersion:e.type===`install_package`?`not installed`:e.currentVersion,name:e.package,targetVersion:e.targetVersion})),...Fr(r,o)];if(s.length>0){yield*t.log.info(`The following dependencies will be updated:`);for(let e of s)yield*t.log.info(` ${e.name}: ${e.currentVersion} → ${e.targetVersion}`);yield*t.withSpinner(()=>n.addDevDependencies(s.map(e=>`${e.name}@${e.targetVersion}`),e,{silent:!0}),{failure:`Failed to update dependencies`,start:`Updating dependencies...`,success:`Dependencies updated successfully`}),yield*t.log.success(`Dependencies updated successfully.`)}let c=s.length===0?i:yield*Ln(e);for(let e of c.warnings)yield*t.log.warning(e);let l=c.findings;return l.length>0&&(yield*Un(l),yield*t.log.info("Run `adamantite doctor` to get the combined Markdown repair prompt.")),s.length===0&&l.length===0?(yield*t.log.success(`No changes needed.`),`no-changes`):`success`}).pipe(n.tapError(()=>n.gen(function*(){yield*(yield*Q).outro(`❌ Update failed`)})),n.tap(e=>n.gen(function*(){yield*(yield*Q).outro(e===`no-changes`?`✅ Adamantite is already up to date.`:`✅ Update completed successfully!`)})))));const Lr=[ut,Rt,Qn,tr,Nr],Rr=[ut,Rt,qn,Qn,tr,jr,Nr,Ir],zr=new Set(Rr.map(e=>e.name)),Br=new Set(Lr.map(e=>e.name)),Vr=l.make(`adamantite`).pipe(l.withDescription(`Opinionated preset package for modern TypeScript applications`),l.withSubcommands(Rr)),Hr=n.fn(`runCli`)(function*(e,t){let[r,i]=c.splitWhere(e,e=>e===`--`),a=c.drop(i,1),o=r.find(e=>zr.has(e));if(a.length>0&&o!==void 0&&!Br.has(o))return yield*new Ae({command:o});yield*l.runWith(Vr,{version:t})(r).pipe(n.provideService(A,a))}),Ur=n.gen(function*(){let e=yield*(yield*o.Stdio).args;yield*Hr(e,`0.40.0`)}).pipe(n.as(0),n.catchTag(`CommandFailed`,e=>n.succeed(e.exitCode)),n.catch(e=>n.service(Q).pipe(n.flatMap(t=>t.log.error(e.message)),n.as(s.ExitCode(1)))),n.provide(i.mergeAll(t.layer,an.layer.pipe(i.provide(t.layer)),Q.layer,k.layer,U.layer,Vn.layer)));e.runMain(Ur,{teardown:(e,t)=>{if(r.isSuccess(e)){t(Number(e.value));return}a.defaultTeardown(e,t)}});export{};
|
|
102
|
+
`;return yield*N(t,`${r}${c}${s}`),`updated`}),Mr=(e,n)=>t.gen(function*(){yield*(yield*Q).withSpinner(()=>nn(e,n),{failure:`Failed to install dependencies.`,start:`Installing dependencies...`,success:`Dependencies installed.`})});function Nr(e,n,r){return t.gen(function*(){let i=yield*Q,a=yield*i.withSpinner(a=>t.gen(function*(){let t=yield*n.detect(e);for(let e of t.warnings)yield*i.log.warning(e);return t.active===null?(yield*a.message(`\`${n.config}\` not found, creating...`),yield*r,{created:!0,legacyConfig:null}):t.active.format===`ts`?(yield*a.message(`Found \`${n.config}\`, keeping existing config.`),{created:!1,legacyConfig:null}):(yield*a.message(`Found \`${t.active.file}\`, keeping existing config.`),{created:!1,legacyConfig:t.active.file})}),{failure:`Failed to set up ${n.name} config.`,start:`Setting up ${n.name} config...`,success:e=>e.created?`${n.name} config created successfully.`:`${n.name} config is ready.`});a.legacyConfig&&(yield*i.log.info(`Legacy \`${a.legacyConfig}\` was preserved during \`adamantite init\`. Run \`adamantite doctor\` and follow its findings to migrate it to the latest ${n.name} config.`))})}const Pr=(e,n,r)=>t.gen(function*(){let i=yield*Q,a=yield*L(e),o=r.overwriteScripts?[]:He(a,n),s=new Set(o.map(e=>e.script)),c=n.filter(e=>!s.has(e));yield*i.withSpinner(()=>t.gen(function*(){if(c.length!==0){a.scripts??={};for(let e of c)a.scripts[e]=R[e];yield*Be(e,a)}}),{failure:"Failed to add scripts to `package.json`.",start:"Adding scripts to your `package.json`...",success:o.length===0?"Scripts added to your `package.json`":c.length===0?"Kept your existing `package.json` scripts.":"Scripts added to your `package.json`; conflicting scripts were kept."});let l=r.nonInteractive?"Use `--overwrite-scripts` to replace it.":"Re-run `adamantite init` and confirm overwriting to replace it.";for(let e of o)yield*i.log.warning(`Kept existing \`${e.script}\` script (\`${e.command}\`) instead of \`${R[e.script]}\`. ${l}`);return o.length>0&&(yield*i.log.info("Adamantite commands forward extra arguments after `--`, so custom flags can be kept, e.g. `adamantite analyze -- --directory packages/app`.")),c}),Fr=(e,n)=>t.gen(function*(){let r=yield*Q;if(n){yield*y(zn,t.forEach(e=>r.log.info(e)));return}yield*r.withSpinner(n=>t.gen(function*(){return(yield*Z.detect(e))?(yield*n.message(`\`${Z.config}\` found, updating...`),yield*Z.update(e),!1):(yield*n.message(`\`${Z.config}\` not found, creating...`),yield*Z.create(e),!0)}),{failure:`Failed to set up TypeScript config.`,start:`Setting up TypeScript config...`,success:e=>e?`\`${Z.config}\` created successfully`:`\`${Z.config}\` updated successfully`})}),Ir=(e,n)=>t.gen(function*(){let r=yield*Q;n.includes(`vscode`)&&(yield*r.withSpinner(n=>t.gen(function*(){let t=yield*$.detect(e);return yield*n.message(`\`${$.config}\` ${t?`found, updating`:`not found, creating`}...`),yield*t?$.update(e):$.create(e),!t}),{failure:`Failed to set up VS Code config.`,start:`Checking for \`${$.config}\`...`,success:e=>`\`${$.config}\` ${e?`created`:`updated`} with Adamantite preset.`})),n.includes(`zed`)&&(yield*r.withSpinner(n=>t.gen(function*(){let t=yield*J.detect(e);return yield*n.message(`\`${J.config}\` ${t?`found, updating`:`not found, creating`}...`),yield*t?J.update(e):J.create(e),!t}),{failure:`Failed to set up Zed config.`,start:`Checking for \`${J.config}\`...`,success:e=>`\`${J.config}\` ${e?`created`:`updated`} with Adamantite preset.`}))}),Lr=(e,n)=>t.gen(function*(){let r=yield*Q,i=e.includes(`zed`),a=e.includes(`vscode`);yield*r.withSpinner(e=>t.gen(function*(){return a&&(yield*e.message(`Installing VS Code extension...`),yield*$.extension(n)),!0}),{start:`Installing editor extensions...`,success:i&&!a?`Zed extensions require manual install.`:`Editor extensions installed successfully.`}).pipe(t.catchTag(`FailedToInstallExtension`,e=>t.gen(function*(){return yield*r.log.warning(`⚠️ ${e.message}`),yield*r.log.warning(`Please install it manually after setup completes.`),!1})),t.catchTag(`VscodeCliNotFound`,()=>t.gen(function*(){return yield*r.log.error(`VSCode CLI ('code' command) not found.`),yield*r.log.info(`To install it:`),yield*r.log.info(` 1. Open VS Code`),yield*r.log.info(` 2. Press Cmd+Shift+P (macOS) or Ctrl+Shift+P (Windows/Linux)`),yield*r.log.info(` 3. Run 'Shell Command: Install "code" command in PATH'`),!1}))),i&&(yield*r.log.info("Install the Zed `oxc` extension: zed://extension/oxc"))}),Rr=(e,n,r)=>t.gen(function*(){let i=yield*Q,a=Dn.files[0].path;yield*i.withSpinner(i=>t.gen(function*(){let t=yield*Dn.detect(e);return yield*i.message(t?`\`${a}\` found, updating...`:`Creating \`${a}\`...`),yield*t?Dn.update(e,{packageManager:n,scripts:r}):Dn.create(e,{packageManager:n,scripts:r}),!t}),{failure:`Failed to set up GitHub Actions workflow.`,start:`Setting up GitHub Actions workflow...`,success:e=>`GitHub Actions workflow ${e?`created`:`updated`} successfully.`})}).pipe(t.catchTag([`FailedToCreateDirectory`,`FailedToParseFile`,`FailedToReadFile`,`FailedToWriteFile`,`PlatformError`],e=>t.gen(function*(){let t=yield*Q;yield*t.log.warning(`Could not set up the GitHub Actions workflow. ${e.message}`),yield*t.log.warning("Fix the reported problem and run `adamantite init` again, or create the workflow manually.")}))),zr=(e,n,r,i)=>t.gen(function*(){let a=yield*Q,o=yield*a.withSpinner(()=>jr(e,{isMonorepo:i,packageManager:n,scripts:r}),{failure:`Failed to update AGENTS.md.`,start:`Updating AGENTS.md...`,success:`AGENTS.md check complete.`}).pipe(t.catchTag([`FailedToReadFile`,`FailedToWriteFile`],e=>t.gen(function*(){return yield*a.log.warning(`Could not update AGENTS.md. ${e.message} Adamantite will continue initialization.`),`failed`})));o!==`failed`&&o===`malformed`&&(yield*a.log.warning(`Could not update AGENTS.md because Adamantite markers are incomplete. Remove the stale ADAMANTITE marker and run adamantite init again.`))});var Br=c.make(`init`,Sr).pipe(c.withDescription(`Initialize Adamantite in the current directory. Setup flags require --non-interactive; omitted boolean setup flags are disabled`),c.withExamples([{command:`adamantite init --non-interactive --script check`,description:`Configure linting without prompts`},{command:`adamantite init --non-interactive --script check --preset react --editor vscode --typescript --install-extensions --github-actions --agents`,description:`Configure a React project with VS Code, TypeScript, CI, and agent guidance`},{command:`adamantite init --non-interactive --script analyze`,description:`Configure analysis; in a detected monorepo it includes Sherif`}]),c.withHandler(e=>t.gen(function*(){let t=f.cwd(),n=yield*Q;yield*dr(),yield*n.intro(`💠 adamantite init`);let r=yield*(yield*en).detectPackageManager(t);if(!r)return yield*new Ee({});if(r.warnings?.length)for(let e of r.warnings)yield*n.log.warning(e);yield*n.log.info(`Detected package manager: ${r.name}`);let i=yield*B(t);if(i&&(yield*n.log.info(`We've detected a monorepo setup in your project.`)),!e.nonInteractive&&s.some([e.scripts.length>0,e.presets.length>0,e.editors.length>0,e.typescript,e.installExtensions,e.githubActions,e.agents,e.overwriteScripts],b.isTruthy))return yield*new O({reason:"Setup flags require `--non-interactive`."});let a=e.nonInteractive?e:yield*wr(t,i),o=yield*mr(a,{nonInteractive:e.nonInteractive,packageManager:r.name}),c=o.scripts,l=o.presets,u=o.editors,d=o.typescript,p=o.installExtensions,m=o.githubActions,h=o.agents,g=c.includes(`check`)||c.includes(`fix`),ee=c.includes(`analyze`),_=ee&&i,v=[`adamantite`];g&&v.push(`${G.name}@${G.version}`,`${Ln.name}@${Ln.version}`,`${U.name}@${U.version}`,...In.filter(e=>l.includes(e.preset)).map(e=>`${e.name}@${e.version}`)),_&&v.push(`${H.name}@${H.version}`),ee&&v.push(`${V.name}@${V.version}`),yield*Mr(t,v),g&&(yield*Nr(t,U,U.create(t)),yield*Nr(t,G,G.create(t,l))),ee&&(yield*Nr(t,V,V.create(t)));let y=yield*Pr(t,c,{nonInteractive:e.nonInteractive,overwriteScripts:o.overwriteScripts});if(h&&(yield*zr(t,r.name,y,i)),d&&(yield*Fr(t,i)),yield*Ir(t,u),p&&(yield*Lr(u,c)),m){let e=r.name;Ve(e)?yield*Rr(t,e,c):yield*n.log.warning(`Skipping GitHub Actions setup: \`${e}\` is not a supported package manager for CI workflow generation.`)}yield*n.log.success(`Your project is now configured`),yield*n.outro(`💠 Adamantite initialized successfully!`)}).pipe(t.catchTags({OperationCancelled:()=>t.gen(function*(){yield*(yield*Q).cancel(`You've cancelled the initialization process.`)})}))));const Vr=[G,Ln,U,H,V];function Hr(e,t){return s.filterMap(Vr,n=>{if(t.has(n.name))return _.failVoid;let r=e.devDependencies?.[n.name]??e.dependencies?.[n.name];return r&&ze(r)!==n.version?_.succeed({currentVersion:r,name:n.name,targetVersion:n.version}):_.failVoid})}var Ur=c.make(`update`).pipe(c.withDescription(`Update Adamantite-managed dependencies and report setup findings`),c.withHandler(()=>t.gen(function*(){let e=f.cwd(),t=yield*Q;yield*t.intro(`💠 adamantite update`);let n=yield*L(e),r=yield*Wn(e,n),i=r.packageActions,a=new Set(i.map(e=>e.package)),o=[...i.map(e=>({currentVersion:e.type===`install_package`?`not installed`:e.currentVersion,name:e.package,targetVersion:e.targetVersion})),...Hr(n,a)];if(o.length>0){yield*t.log.info(`The following dependencies will be updated:`);for(let e of o)yield*t.log.info(` ${e.name}: ${e.currentVersion} → ${e.targetVersion}`);yield*t.withSpinner(()=>nn(e,o.map(e=>`${e.name}@${e.targetVersion}`)),{failure:`Failed to update dependencies`,start:`Updating dependencies...`,success:`Dependencies updated successfully`}),yield*t.log.success(`Dependencies updated successfully.`)}let s=o.length===0?r:yield*Wn(e);for(let e of s.warnings)yield*t.log.warning(e);let c=s.findings;return c.length>0&&(yield*tr(c),yield*t.log.info("Run `adamantite doctor` to get the combined Markdown repair prompt.")),o.length===0&&c.length===0?(yield*t.log.success(`No changes needed.`),`no-changes`):`success`}).pipe(t.tapError(()=>t.gen(function*(){yield*(yield*Q).outro(`❌ Update failed`)})),t.tap(e=>t.gen(function*(){yield*(yield*Q).outro(e===`no-changes`?`✅ Adamantite is already up to date.`:`✅ Update completed successfully!`)})))));const Wr=[Tt,Xt,lr],Gr=[Tt,Xt,rr,lr,Br,Ur],Kr=new Set(Gr.map(e=>e.name)),qr=new Set(Wr.map(e=>e.name)),Jr=c.make(`adamantite`).pipe(c.withDescription(`Opinionated preset package for modern TypeScript applications`),c.withSubcommands(Gr)),Yr=e=>l.mergeAll(o.layer,pn.layer.pipe(l.provide(o.layer)),Q.layer,Qn.layer.pipe(l.provideMerge(e),l.provide(o.layer)),en.layer,$n.layer),Xr=t.fn(`runCli`)(function*(e,n){let[r,i]=s.splitWhere(e,e=>e===`--`),a=s.drop(i,1),o=r.find(e=>Kr.has(e));if(a.length>0&&o!==void 0&&!qr.has(o))return yield*new Oe({command:o});yield*c.runWith(Jr,{version:n})(r).pipe(t.provideService(Ne,a))}),Zr=t.gen(function*(){let e=yield*(yield*a.Stdio).args;yield*Xr(e,`0.42.0`)}).pipe(t.as(0),t.catchTag(`CommandFailed`,e=>t.succeed(e.exitCode)),t.catch(e=>t.service(Q).pipe(t.flatMap(t=>t.log.error(e.message)),t.as(r.ExitCode(1)))),t.provide(Yr(k.layer)));e.runMain(Zr,{teardown:(e,t)=>{if(n.isSuccess(e)){t(Number(e.value));return}i.defaultTeardown(e,t)}});export{};
|
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { KnipConfiguration } from "knip";
|
|
2
2
|
//#region presets/analyze.d.ts
|
|
3
|
+
interface SuggestedIgnoreDependencies {
|
|
4
|
+
monorepo: string[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Suggested `ignoreDependencies` lists, grouped by the kind of project that needs them. The default
|
|
8
|
+
* export does not include them, because Knip prints a configuration hint for an ignore that matches
|
|
9
|
+
* nothing.
|
|
10
|
+
*
|
|
11
|
+
* - `monorepo`: `adamantite analyze` runs Sherif in a monorepo, and Knip has no plugin that sees that
|
|
12
|
+
* reference, so it reports Sherif as an unused devDependency.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import analyze, { ignoreDependencies } from "adamantite/analyze"
|
|
16
|
+
*
|
|
17
|
+
* export default { ...analyze, ignoreDependencies: ignoreDependencies.monorepo }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare const ignoreDependencies: SuggestedIgnoreDependencies;
|
|
3
21
|
declare const config: KnipConfiguration;
|
|
4
22
|
//#endregion
|
|
5
|
-
export { config as default };
|
|
23
|
+
export { config as default, ignoreDependencies };
|
package/dist/presets/analyze.js
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
//#region presets/analyze.ts
|
|
2
|
+
/**
|
|
3
|
+
* Suggested `ignoreDependencies` lists, grouped by the kind of project that needs them. The default
|
|
4
|
+
* export does not include them, because Knip prints a configuration hint for an ignore that matches
|
|
5
|
+
* nothing.
|
|
6
|
+
*
|
|
7
|
+
* - `monorepo`: `adamantite analyze` runs Sherif in a monorepo, and Knip has no plugin that sees that
|
|
8
|
+
* reference, so it reports Sherif as an unused devDependency.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import analyze, { ignoreDependencies } from "adamantite/analyze"
|
|
12
|
+
*
|
|
13
|
+
* export default { ...analyze, ignoreDependencies: ignoreDependencies.monorepo }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
const ignoreDependencies = { monorepo: ["sherif"] };
|
|
2
17
|
const config = {
|
|
3
18
|
ignoreExportsUsedInFile: true,
|
|
4
19
|
rules: {
|
|
@@ -20,4 +35,4 @@ const config = {
|
|
|
20
35
|
}
|
|
21
36
|
};
|
|
22
37
|
//#endregion
|
|
23
|
-
export { config as default };
|
|
38
|
+
export { config as default, ignoreDependencies };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Plugin, Rule } from "@oxlint/plugins";
|
|
2
|
+
//#region presets/lint/plugin/index.d.ts
|
|
3
|
+
interface AdamantitePlugin extends Plugin {
|
|
4
|
+
readonly rules: {
|
|
5
|
+
readonly "no-overzealous-destructuring": Rule;
|
|
6
|
+
readonly "no-react-state-hooks": Rule;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Adamantite's first-party Oxlint plugin. Presets load it by file URL, so target projects install
|
|
11
|
+
* nothing extra.
|
|
12
|
+
*/
|
|
13
|
+
declare const plugin: AdamantitePlugin;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { plugin as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import rule from "./rules/no-overzealous-destructuring.js";
|
|
2
|
+
import rule$1 from "./rules/no-react-state-hooks.js";
|
|
3
|
+
//#region presets/lint/plugin/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Adamantite's first-party Oxlint plugin. Presets load it by file URL, so target projects install
|
|
6
|
+
* nothing extra.
|
|
7
|
+
*/
|
|
8
|
+
const plugin = {
|
|
9
|
+
meta: { name: "adamantite" },
|
|
10
|
+
rules: {
|
|
11
|
+
"no-overzealous-destructuring": rule,
|
|
12
|
+
"no-react-state-hooks": rule$1
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { plugin as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Options } from "@oxlint/plugins";
|
|
2
|
+
//#region presets/lint/plugin/options.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Read a string array from the rule's first option object.
|
|
5
|
+
*/
|
|
6
|
+
declare function readStringArrayOption(options: Readonly<Options>, key: string): string[] | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Read a positive integer from the rule's first option object.
|
|
9
|
+
*/
|
|
10
|
+
declare function readPositiveIntegerOption(options: Readonly<Options>, key: string): number | undefined;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { readPositiveIntegerOption, readStringArrayOption };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region presets/lint/plugin/options.ts
|
|
2
|
+
function isOptionObject(value) {
|
|
3
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function isString(value) {
|
|
6
|
+
return typeof value === "string";
|
|
7
|
+
}
|
|
8
|
+
function isStringArray(value) {
|
|
9
|
+
return Array.isArray(value) && value.every((entry) => isString(entry));
|
|
10
|
+
}
|
|
11
|
+
function isPositiveInteger(value) {
|
|
12
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
13
|
+
}
|
|
14
|
+
function readOption(options, key) {
|
|
15
|
+
const [first] = options;
|
|
16
|
+
return isOptionObject(first) ? first[key] : void 0;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Read a string array from the rule's first option object.
|
|
20
|
+
*/
|
|
21
|
+
function readStringArrayOption(options, key) {
|
|
22
|
+
const value = readOption(options, key);
|
|
23
|
+
return isStringArray(value) ? value : void 0;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Read a positive integer from the rule's first option object.
|
|
27
|
+
*/
|
|
28
|
+
function readPositiveIntegerOption(options, key) {
|
|
29
|
+
const value = readOption(options, key);
|
|
30
|
+
return isPositiveInteger(value) ? value : void 0;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { readPositiveIntegerOption, readStringArrayOption };
|