@yunarch/config-web 0.5.7 → 0.5.8

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 CHANGED
@@ -248,7 +248,7 @@ To use the oxlint linter, create a `.oxlintrc.json` [configuration file](https:/
248
248
 
249
249
  > [!CAUTION]
250
250
  > Currently, `Oxlint` does not resolve configuration file paths automatically. To extend a config, you must explicitly provide the full path, like so:
251
- > `"extends": ["./node_modules/@yunarch/config-web/dist/oxlint.config.json"]`
251
+ > `"extends": ["./node_modules/@yunarch/config-web/dist/config.oxlint.json"]`
252
252
 
253
253
  ### Enabling ESLint and Oxlint Simultaneously
254
254
 
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{c as M}from"../chunk-LXZC4N54.js";import{existsSync as N,statSync as T}from"fs";import v from"path";import{styleText as e}from"util";import{styleText as m}from"util";function H(f){let c=new Map;for(let o of f)c.has(o.service.name)||c.set(o.service.name,{service:o.service,handlers:[]}),c.get(o.service.name)?.handlers.push(o);if(c.size===0){console.log(m("green","\u2714 No missing handlers found"));return}for(let{service:o,handlers:i}of c.values()){console.log(`${m("underline",o.name)}${m("gray",` (${o.path})`)}`);for(let[a,s]of i.entries()){let t=a===i.length-1;console.log(` ${t?"\u2514\u2500":"\u251C\u2500"} ${m("cyan",s.service.toHandleHttpMethod)} ${m("yellow",s.service.toHandleUrl)}`),console.log(` ${t?" ":"\u2502"} \u251C\u2500 ${m("gray","Used in:")}`);for(let[p,l]of s.usedIn.entries()){let r=p===s.usedIn.length-1;console.log(` ${t?" ":"\u2502"} ${r?"\u2502 \u2514\u2500":"\u2502 \u251C\u2500"} ${l}`)}console.log(` ${t?" ":"\u2502"} \u2514\u2500 ${m("green","Suggested handler:")}`),console.log(` ${t?" ":"\u2502"} ${m("dim","\u2192")} ${s.suggestedPath}`),a<i.length-1&&console.log(` ${t?" ":"\u2502"}`)}console.log("")}console.log(m("red",`\u2718 ${f.length} missing ${f.length===1?"handler":"handlers"}`))}import{pathToFileURL as F}from"url";async function E({mswSetupFilePath:f,mswSetupConst:c}){let o=new Map,i=await import(F(f).href);if(!Object.hasOwn(i,c))throw new TypeError("MSW setup constant not found in the setup file");let a=i[c];if(!a||typeof a.listHandlers!="function")throw new TypeError("MSW setup constant does not have a listHandlers() method");let s=a.listHandlers();for(let t of s){if(!("info"in t)||!t.info?.path||!t.info.method)continue;let p=t.info.path,l=t.info.method.toUpperCase(),r=p.replaceAll(/:(?<temp1>[^/]+)/g,"{$1}"),d=`${l}:${r}`;o.set(d,{path:p,httpMethod:l,url:r})}return o}import{existsSync as C,readFileSync as U}from"fs";import I from"path";import _ from"fast-glob";import n from"typescript";async function W(f){let c=[],o=I.join(f,"services");if(!C(o))throw new Error(`Services directory not found: ${o}`);let i=await _("**/*Service.ts",{cwd:o,absolute:!0,ignore:["**/node_modules/**"]});for(let a of i){let s=I.basename(a,".ts"),t=U(a,"utf8"),p=n.createSourceFile(a,t,n.ScriptTarget.Latest,!0);n.forEachChild(p,l=>{if(n.isClassDeclaration(l)&&l.name?.text===s){for(let r of l.members)if(n.isMethodDeclaration(r)&&n.isIdentifier(r.name)&&r.modifiers&&r.modifiers.some(d=>d.kind===n.SyntaxKind.PublicKeyword)&&r.modifiers.some(d=>d.kind===n.SyntaxKind.StaticKeyword)){let d=r.name.text,y,h,x=u=>{if(n.isReturnStatement(u)&&u.expression&&n.isCallExpression(u.expression)&&n.isIdentifier(u.expression.expression)&&u.expression.expression.text==="__request"){let S=u.expression.arguments[1];if(n.isObjectLiteralExpression(S))for(let g of S.properties)n.isPropertyAssignment(g)&&n.isIdentifier(g.name)&&g.name.text==="url"&&n.isStringLiteral(g.initializer)?y=g.initializer.text:n.isPropertyAssignment(g)&&n.isIdentifier(g.name)&&g.name.text==="method"&&n.isStringLiteral(g.initializer)&&(h=g.initializer.text.toUpperCase())}n.forEachChild(u,x)};r.body&&n.forEachChild(r.body,x),y&&h?c.push({path:a,name:s,methodName:d,toHandleUrl:y,toHandleHttpMethod:h}):(y||console.warn(`No URL found for ${d} request in service ${s} (${a})`),h||console.warn(`No HTTP method found for ${d} request in service ${s} (${a})`))}}})}return c}async function P({genPath:f,srcPath:c}){let o=await W(f),i=new Map;for(let s of o)i.has(s.name)||i.set(s.name,new Map),i.get(s.name)?.set(s.methodName,{serviceInfo:s,files:new Set});let a=await _("**/*.{ts,tsx}",{cwd:c,absolute:!0,ignore:["**/node_modules/**","**/__tests__/**"]});for(let s of a)try{let t=U(s,"utf8"),p=n.createSourceFile(s,t,n.ScriptTarget.Latest,!0),l=r=>{if(n.isCallExpression(r)&&n.isPropertyAccessExpression(r.expression)&&n.isIdentifier(r.expression.expression)&&r.expression.expression.text.endsWith("Service")){let d=r.expression.expression.text,y=r.expression.name.text,h=i.get(d)?.get(y);if(!h)return;h.files.add(s)}n.forEachChild(r,l)};l(p)}catch(t){throw t instanceof Error?new TypeError(`Error parsing ${s}: ${t.message}`):new TypeError(`Error parsing ${s}: Unknown error`)}for(let[s,t]of i.entries()){for(let[p,l]of t.entries())l.files.size===0&&t.delete(p);t.size===0&&i.delete(s)}return i}import L from"path";function b(f,c,o){let i=[];for(let[a,s]of f.entries())for(let[t,p]of s.entries()){let{serviceInfo:l}=p,r=l.toHandleHttpMethod,d=l.toHandleUrl;!c.has(`${r}:${d}`)&&!c.has(`${r}:*${d}`)&&i.push({type:"missing_handler",service:l,usedIn:[...p.files],suggestedPath:L.join(o,`handlers/services/${a}/${t}.ts`)})}return i}M().name("openapi-sync-lint-msw-handlers").description("Lint MSW handlers against OpenAPI generated services from `openapi-sync`.\nIt checks for missing handlers based on generated services and your MSW setup.").requiredOption("--gen <path>","The output folder from `openapi-sync` script. Where the generated models and openapi schema and type definitions are saved.").requiredOption("--msw-setup-file <path>","Path to the MSW setup file (file that configures MSW setupServer or setupWorker).").requiredOption("--msw-setup-const <const>","Name of the constant that holds the MSW setup (e.g., server or worker).").addHelpText("after",`
2
+ import{c as M}from"../chunk-LXZC4N54.js";import{existsSync as N,statSync as F}from"fs";import v from"path";import{styleText as e}from"util";import{styleText as m}from"util";function H(f){let c=new Map;for(let o of f)c.has(o.service.name)||c.set(o.service.name,{service:o.service,handlers:[]}),c.get(o.service.name)?.handlers.push(o);if(c.size===0){console.log(m("green","\u2714 No missing handlers found"));return}for(let{service:o,handlers:i}of c.values()){console.log(`${m("underline",o.name)}${m("gray",` (${o.path})`)}`);for(let[a,s]of i.entries()){let t=a===i.length-1;console.log(` ${t?"\u2514\u2500":"\u251C\u2500"} ${m("cyan",s.service.toHandleHttpMethod)} ${m("yellow",s.service.toHandleUrl)}`),console.log(` ${t?" ":"\u2502"} \u251C\u2500 ${m("gray","Used in:")}`);for(let[p,l]of s.usedIn.entries()){let r=p===s.usedIn.length-1;console.log(` ${t?" ":"\u2502"} ${r?"\u2502 \u2514\u2500":"\u2502 \u251C\u2500"} ${l}`)}console.log(` ${t?" ":"\u2502"} \u2514\u2500 ${m("green","Suggested handler:")}`),console.log(` ${t?" ":"\u2502"} ${m("dim","\u2192")} ${s.suggestedPath}`),a<i.length-1&&console.log(` ${t?" ":"\u2502"}`)}console.log("")}console.log(m("red",`\u2718 ${f.length} missing ${f.length===1?"handler":"handlers"}`))}import{pathToFileURL as C}from"url";async function E({mswSetupFilePath:f,mswSetupConst:c}){let o=new Map,i=await import(C(f).href);if(!Object.hasOwn(i,c))throw new Error("MSW setup constant not found in the setup file");let a=i[c];if(!a||typeof a.listHandlers!="function")throw new Error("MSW setup constant does not have a listHandlers() method");let s=a.listHandlers();for(let t of s){if(!("info"in t)||!t.info?.path||!t.info.method)continue;let p=t.info.path,l=t.info.method.toUpperCase(),r=p.replaceAll(/:(?<temp1>[^/]+)/g,"{$1}"),d=`${l}:${r}`;o.set(d,{path:p,httpMethod:l,url:r})}return o}import{existsSync as W,readFileSync as U}from"fs";import I from"path";import _ from"fast-glob";import n from"typescript";async function T(f){let c=[],o=I.join(f,"services");if(!W(o))throw new Error(`Services directory not found: ${o}`);let i=await _("**/*Service.ts",{cwd:o,absolute:!0,ignore:["**/node_modules/**"]});for(let a of i){let s=I.basename(a,".ts"),t=U(a,"utf8"),p=n.createSourceFile(a,t,n.ScriptTarget.Latest,!0);n.forEachChild(p,l=>{if(n.isClassDeclaration(l)&&l.name?.text===s){for(let r of l.members)if(n.isMethodDeclaration(r)&&n.isIdentifier(r.name)&&r.modifiers&&r.modifiers.some(d=>d.kind===n.SyntaxKind.PublicKeyword)&&r.modifiers.some(d=>d.kind===n.SyntaxKind.StaticKeyword)){let d=r.name.text,y,h,x=u=>{if(n.isReturnStatement(u)&&u.expression&&n.isCallExpression(u.expression)&&n.isIdentifier(u.expression.expression)&&u.expression.expression.text==="__request"){let S=u.expression.arguments[1];if(n.isObjectLiteralExpression(S))for(let g of S.properties)n.isPropertyAssignment(g)&&n.isIdentifier(g.name)&&g.name.text==="url"&&n.isStringLiteral(g.initializer)?y=g.initializer.text:n.isPropertyAssignment(g)&&n.isIdentifier(g.name)&&g.name.text==="method"&&n.isStringLiteral(g.initializer)&&(h=g.initializer.text.toUpperCase())}n.forEachChild(u,x)};r.body&&n.forEachChild(r.body,x),y&&h?c.push({path:a,name:s,methodName:d,toHandleUrl:y,toHandleHttpMethod:h}):(y||console.warn(`No URL found for ${d} request in service ${s} (${a})`),h||console.warn(`No HTTP method found for ${d} request in service ${s} (${a})`))}}})}return c}async function P({genPath:f,srcPath:c}){let o=await T(f),i=new Map;for(let s of o)i.has(s.name)||i.set(s.name,new Map),i.get(s.name)?.set(s.methodName,{serviceInfo:s,files:new Set});let a=await _("**/*.{ts,tsx}",{cwd:c,absolute:!0,ignore:["**/node_modules/**","**/__tests__/**"]});for(let s of a)try{let t=U(s,"utf8"),p=n.createSourceFile(s,t,n.ScriptTarget.Latest,!0),l=r=>{if(n.isCallExpression(r)&&n.isPropertyAccessExpression(r.expression)&&n.isIdentifier(r.expression.expression)&&r.expression.expression.text.endsWith("Service")){let d=r.expression.expression.text,y=r.expression.name.text,h=i.get(d)?.get(y);if(!h)return;h.files.add(s)}n.forEachChild(r,l)};l(p)}catch(t){throw t instanceof Error?new Error(`Error parsing ${s}: ${t.message}`):new Error(`Error parsing ${s}: Unknown error`)}for(let[s,t]of i.entries()){for(let[p,l]of t.entries())l.files.size===0&&t.delete(p);t.size===0&&i.delete(s)}return i}import L from"path";function b(f,c,o){let i=[];for(let[a,s]of f.entries())for(let[t,p]of s.entries()){let{serviceInfo:l}=p,r=l.toHandleHttpMethod,d=l.toHandleUrl;!c.has(`${r}:${d}`)&&!c.has(`${r}:*${d}`)&&i.push({type:"missing_handler",service:l,usedIn:[...p.files],suggestedPath:L.join(o,`handlers/services/${a}/${t}.ts`)})}return i}M().name("openapi-sync-lint-msw-handlers").description("Lint MSW handlers against OpenAPI generated services from `openapi-sync`.\nIt checks for missing handlers based on generated services and your MSW setup.").requiredOption("--gen <path>","The output folder from `openapi-sync` script. Where the generated models and openapi schema and type definitions are saved.").requiredOption("--msw-setup-file <path>","Path to the MSW setup file (file that configures MSW setupServer or setupWorker).").requiredOption("--msw-setup-const <const>","Name of the constant that holds the MSW setup (e.g., server or worker).").addHelpText("after",`
3
3
  Example usage:
4
4
  ${e("dim","$")} ${e("cyan","openapi-sync-lint-msw-handlers")} ${e("green","--gen")} ${e("yellow","./src/api/gen")} ${e("green","--msw-setup-file")} ${e("yellow","./src/api/__tests__/node.js")} ${e("green","--msw-setup-const")} ${e("yellow","server")}
5
5
 
@@ -10,4 +10,4 @@ Examples:
10
10
  ${e("dim","$")} ${e("yellow","tsx")} ${e("cyan","./node_modules/@yunarch/config-web/dist/cli/openapi-sync/openapi-sync-lint-msw-handlers.cli.js")} ${e("green","--gen")} ${e("yellow","./src/api/gen")} ${e("green","--msw-setup-file")} ${e("yellow","./src/api/__tests__/node.ts")} ${e("green","--msw-setup-const")} ${e("yellow","server")}
11
11
 
12
12
  ${e("dim","$")} ${e("yellow","bun")} ${e("yellow","--bun")} ${e("cyan","openapi-sync-lint-msw-handlers")} ${e("green","--gen")} ${e("yellow","./src/api/gen")} ${e("green","--msw-setup-file")} ${e("yellow","./src/api/__tests__/node.ts")} ${e("green","--msw-setup-const")} ${e("yellow","server")}
13
- `).action(async({gen:f,mswSetupFile:c,mswSetupConst:o})=>{try{let i=process.cwd(),a=v.resolve(i,f),s=v.resolve(i,"."),t=v.resolve(i,c);if(!N(a)||!T(a).isDirectory())throw new Error("Generated API folder does not exist or is not a directory");if(!N(t)||!T(t).isFile())throw new Error("MSW setup file does not exist or is not a file");let p=await P({genPath:a,srcPath:s}),l=await E({mswSetupFilePath:t,mswSetupConst:o}),r=b(p,l,v.dirname(t));H(r),process.exit(r.length>0?1:0)}catch(i){console.error(i),process.exit(1)}}).parseAsync(process.argv);
13
+ `).action(async({gen:f,mswSetupFile:c,mswSetupConst:o})=>{try{let i=process.cwd(),a=v.resolve(i,f),s=v.resolve(i,"."),t=v.resolve(i,c);if(!N(a)||!F(a).isDirectory())throw new Error("Generated API folder does not exist or is not a directory");if(!N(t)||!F(t).isFile())throw new Error("MSW setup file does not exist or is not a file");let p=await P({genPath:a,srcPath:s}),l=await E({mswSetupFilePath:t,mswSetupConst:o}),r=b(p,l,v.dirname(t));H(r),process.exit(r.length>0?1:0)}catch(i){console.error(i),process.exit(1)}}).parseAsync(process.argv);
@@ -0,0 +1 @@
1
+ {"formatter":{"enabled":true,"includes":["**","!**/node_modules/","!**/dist/","!**/out/","!**/output","!**/.output","!**/build/","!**/*.min.*","!**/package-lock.json","!**/yarn.lock","!**/.yarn/","!**/.yarnrc.yml","!**/.pnp.*","!**/.pnp","!**/.pnp.js","!**/.pnp.cjs","!**/bun.lock","!**/bun.lockb","!**/pnpm-lock.yaml","!**/.vite-inspect","!**/.vitepress/cache","!**/vite.config.*.timestamp-*","!**/*.log","!**/npm-debug.log*","!**/yarn-debug.log*","!**/yarn-error.log*","!**/coverage/","!**/.nyc_output/","!**/__snapshots__","!**/.vscode/","!**/.idea/","!**/.cache","!**/.nuxt","!**/.next","!**/.svelte-kit","!**/.vercel","!**/.changeset","!**/.turbo/","!**/.DS_Store","!**/Thumbs.db","!**/temp","!**/.temp","!**/tmp","!**/.tmp","!**/.history","!**/mockServiceWorker.js","!**/CHANGELOG*","!**/LICENSE*"],"useEditorconfig":false,"formatWithErrors":false,"lineWidth":80,"indentWidth":2,"indentStyle":"space","bracketSpacing":true,"bracketSameLine":false,"lineEnding":"lf","attributePosition":"auto"},"javascript":{"formatter":{"semicolons":"always","quoteStyle":"single","arrowParentheses":"always","trailingCommas":"es5","quoteProperties":"asNeeded","jsxQuoteStyle":"double"}},"linter":{"enabled":false,"includes":["!**/node_modules/","!**/dist/","!**/out/","!**/output","!**/.output","!**/build/","!**/*.min.*","!**/package-lock.json","!**/yarn.lock","!**/.yarn/","!**/.yarnrc.yml","!**/.pnp.*","!**/.pnp","!**/.pnp.js","!**/.pnp.cjs","!**/bun.lock","!**/bun.lockb","!**/pnpm-lock.yaml","!**/.vite-inspect","!**/.vitepress/cache","!**/vite.config.*.timestamp-*","!**/*.log","!**/npm-debug.log*","!**/yarn-debug.log*","!**/yarn-error.log*","!**/coverage/","!**/.nyc_output/","!**/__snapshots__","!**/.vscode/","!**/.idea/","!**/.cache","!**/.nuxt","!**/.next","!**/.svelte-kit","!**/.vercel","!**/.changeset","!**/.turbo/","!**/.DS_Store","!**/Thumbs.db","!**/temp","!**/.temp","!**/tmp","!**/.tmp","!**/.history","!**/mockServiceWorker.js","!**/CHANGELOG*","!**/LICENSE*"]},"overrides":[{"includes":["**/package.json"],"formatter":{"indentStyle":"space"}}],"assist":{"actions":{"source":{"organizeImports":"off"}}}}