@yunarch/config-web 0.5.6 → 0.5.7

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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{a,b as o,c as w}from"../chunk-LXZC4N54.js";import{existsSync as y}from"fs";import{mkdir as b,readFile as k,writeFile as O}from"fs/promises";import d from"path";import{styleText as n}from"util";import $ from"@inquirer/confirm";async function P(e,t){await o({name:"Generating models",command:async()=>{await a("npx",["openapi-typescript-codegen","--input",e,"--output",t,"--client","fetch"],{shell:!0})}})}import{writeFile as v}from"fs/promises";var x=`
2
+ import{a as o,b as a,c as w}from"../chunk-LXZC4N54.js";import{existsSync as y}from"fs";import{mkdir as b,readFile as k,writeFile as O}from"fs/promises";import d from"path";import{styleText as n}from"util";import $ from"@inquirer/confirm";async function P(e,t){await a({name:"Generating models",command:async()=>{await o("npx",["openapi-typescript-codegen","--input",e,"--output",t,"--client","fetch"],{shell:!0})}})}import{writeFile as B}from"fs/promises";var x=`
3
3
  import {
4
4
  http as mswHttp,
5
5
  type DefaultBodyType,
@@ -25,7 +25,13 @@ type HttpMethod =
25
25
  /**
26
26
  * Type guard to get the http methods available for a given path.
27
27
  */
28
- type Methods<Path extends keyof Paths> = Extract<keyof Paths[Path], HttpMethod>;
28
+ type Methods<Path extends keyof Paths> = {
29
+ [M in keyof Paths[Path]]: M extends HttpMethod
30
+ ? Paths[Path][M] extends undefined
31
+ ? never
32
+ : M
33
+ : never;
34
+ }[keyof Paths[Path]];
29
35
 
30
36
  /**
31
37
  * Type guard to get the content type 'application/json' or 'multipart/form-data' of a type.
@@ -116,22 +122,22 @@ export function http<P extends keyof Paths, M extends Methods<P>>(
116
122
  }
117
123
  return handlers[method as keyof typeof handlers](uri, resolver, options);
118
124
  }
119
- `;async function T(e){await o({name:"Generating openapi MSW utils",command:async()=>{await v(`${e}/openapi-msw-http.ts`,x)}})}import{readFile as E,writeFile as H}from"fs/promises";async function M(e,t){await o({name:"Generating schema types",command:async()=>{await a("npx",["openapi-typescript",e,"-o",t],{shell:!0});let s=await E(t,"utf8");await H(t,`/* eslint-disable -- Autogenerated file */
120
- ${s}`)}})}async function C(e){if(d.extname(e)!=="")throw new Error("Output must be a directory.");let t=process.cwd(),s=d.resolve(e),r=s.startsWith(t)?s:d.resolve(t,d.relative(d.parse(e).root,e));return y(r)||await o({name:"Generating output directory",command:async()=>{await b(r,{recursive:!0})}}),r}async function S(e,t){let[s,i]=await Promise.all([o({name:"Reading input openapi schema",command:async()=>{if(!e.endsWith(".json"))throw new Error(`Input file must be a JSON file: ${e}`);if(e.startsWith("http"))try{let{stdout:r}=await a("curl",["-s",e,"--fail"],{encoding:"utf8"});return r}catch{throw new Error(`Failed to fetch remote OpenAPI file: ${e}`)}if(!y(e))throw new Error(`Input file does not exist: ${e}`);return await k(e,"utf8")}}),o({name:"Reading output openapi schema",command:async()=>{if(!t.endsWith(".json"))throw new Error(`Output file must be a JSON file: ${t}`);return y(t)?await k(t,"utf8"):!1}})]);return[JSON.stringify(JSON.parse(s)),i?JSON.stringify(JSON.parse(i)):!1]}w().name("openapi-sync").description("A CLI tool to convert OpenAPI 3.0/3.1 schemas to TypeScript types and create type-safe fetching based on a openapi file and keep them in sync.").requiredOption("-i, --input <path>","The input (local or remote) openapi schema (JSON).").requiredOption("-o, --output <folder>","The output folder to save the generated models and openapi schema and type definitions.").option("-y, --yes","Skip confirmation prompts and proceed with defaults.").option("-f, --force-gen","Force generation of typescript schemas and fetching code even if the input and output schemas are identical.").option("--include-msw-utils","Include MSW mocking utilities based on the generated typescript types.").option("--post-script <script>","A package.json script to run after the code generation.").option("--verify-openapi-sync","Verifies that the generated output is up to date with the input (e.g., in CI) to catch outdated or mismatched output without making changes.").addHelpText("after",`
125
+ `;async function T(e){await a({name:"Generating openapi MSW utils",command:async()=>{await B(`${e}/openapi-msw-http.ts`,x)}})}import{readFile as H,writeFile as E}from"fs/promises";async function M(e,t){await a({name:"Generating schema types",command:async()=>{await o("npx",["openapi-typescript",e,"-o",t],{shell:!0});let s=await H(t,"utf8");await E(t,`/* eslint-disable -- Autogenerated file */
126
+ ${s}`)}})}async function C(e){if(d.extname(e)!=="")throw new Error("Output must be a directory.");let t=process.cwd(),s=d.resolve(e),r=s.startsWith(t)?s:d.resolve(t,d.relative(d.parse(e).root,e));return y(r)||await a({name:"Generating output directory",command:async()=>{await b(r,{recursive:!0})}}),r}async function S(e,t){let[s,i]=await Promise.all([a({name:"Reading input openapi schema",command:async()=>{if(!e.endsWith(".json"))throw new Error(`Input file must be a JSON file: ${e}`);if(e.startsWith("http"))try{let{stdout:r}=await o("curl",["-s",e,"--fail"],{encoding:"utf8"});return r}catch{throw new Error(`Failed to fetch remote OpenAPI file: ${e}`)}if(!y(e))throw new Error(`Input file does not exist: ${e}`);return await k(e,"utf8")}}),a({name:"Reading output openapi schema",command:async()=>{if(!t.endsWith(".json"))throw new Error(`Output file must be a JSON file: ${t}`);return y(t)?await k(t,"utf8"):!1}})]);return[JSON.stringify(JSON.parse(s)),i?JSON.stringify(JSON.parse(i)):!1]}w().name("openapi-sync").description("A CLI tool to convert OpenAPI 3.0/3.1 schemas to TypeScript types and create type-safe fetching based on a openapi file and keep them in sync.").requiredOption("-i, --input <path>","The input (local or remote) openapi schema (JSON).").requiredOption("-o, --output <folder>","The output folder to save the generated models and openapi schema and type definitions.").option("-y, --yes","Skip confirmation prompts and proceed with defaults.").option("-f, --force-gen","Force generation of typescript schemas and fetching code even if the input and output schemas are identical.").option("--include-msw-utils","Include MSW mocking utilities based on the generated typescript types.").option("--post-script <script>","A package.json script to run after the code generation.").option("--verify-openapi-sync","Verifies that the generated output is up to date with the input (e.g., in CI) to catch outdated or mismatched output without making changes.").addHelpText("after",`
121
127
  Example usage:
122
128
  ${n("dim","$")} ${n("cyan","openapi-sync")} ${n("green","-i")} ${n("yellow","./openapi.json")} ${n("green","-o")} ${n("yellow","./src/api/gen")} ${n("green","--include-msw-utils")}
123
129
  `).action(async({input:e,output:t,yes:s,forceGen:i,verifyOpenapiSync:r,includeMswUtils:R,postScript:m})=>{try{console.log(n("magenta",`
124
130
  \u{1F680} openapi-sync
125
- `));let p=await C(t),c=`${p}/openapi.json`,B=`${p}/schema.d.ts`,[f,g]=await S(e,c),h=f!==g;r&&(console.log(h?n("yellow",`
131
+ `));let p=await C(t),c=`${p}/openapi.json`,v=`${p}/schema.d.ts`,[u,g]=await S(e,c),h=u!==g;r&&(console.log(h?n("yellow",`
126
132
  \u26A0\uFE0F Local and remote schemas does not match!
127
133
  `):n("green",`
128
134
  \u2705 Local and remote schemas match!
129
- `)),process.exit(h?1:0)),g===!1&&await o({name:"Creating local schema",command:O(c,f)}),!h&&!i?(console.log(n("blue",`
135
+ `)),process.exit(h?1:0)),g===!1&&await a({name:"Creating local schema",command:O(c,u)}),!h&&!i?(console.log(n("blue",`
130
136
  No updates required.
131
137
  `)),process.exit(0)):h&&(console.log(n("yellow",`
132
138
  \u26A0\uFE0F Local and remote schemas does not match!
133
- `)),s||await $({message:"Do you want to use the remote schema? (y/n)?"})?await o({name:"Replacing local schema with input schema",command:O(c,f)}):(console.log(n("yellow",`
139
+ `)),s||await $({message:"Do you want to use the remote schema? (y/n)?"})?await a({name:"Replacing local schema with input schema",command:O(c,u)}):(console.log(n("yellow",`
134
140
  \u26A0\uFE0F Sync remote schemas skipped.
135
- `)),i||process.exit(0))),await Promise.all([M(c,B),P(c,p)]),R&&await T(p),m&&await o({name:"Running post script",command:async()=>{try{await(typeof Bun<"u"?a("bun",["run",m]):a("node",["--run",m]))}catch{await a("npm",["run",m],{shell:!0})}}}),console.log(n("green",`
141
+ `)),i||process.exit(0))),await Promise.all([M(c,v),P(c,p)]),R&&await T(p),m&&await a({name:"Running post script",command:async()=>{try{await(typeof Bun<"u"?o("bun",["run",m]):o("node",["--run",m]))}catch{await o("npm",["run",m],{shell:!0})}}}),console.log(n("green",`
136
142
  \u2705 openapi-sync process completed!
137
143
  `))}catch(p){console.error(p),process.exit(1)}}).parseAsync(process.argv);
@@ -1 +1 @@
1
- var e={printWidth:80,tabWidth:2,useTabs:!1,semi:!0,singleQuote:!0,arrowParens:"always",trailingComma:"es5",bracketSpacing:!0,bracketSameLine:!1,proseWrap:"preserve",endOfLine:"lf",quoteProps:"as-needed",singleAttributePerLine:!1,requirePragma:!1,insertPragma:!1,jsxSingleQuote:!1,htmlWhitespaceSensitivity:"css",embeddedLanguageFormatting:"auto",overrides:[{files:"**/*.jsonc",options:{trailingComma:"none"}},{files:"**/*.hbs",options:{parser:"html"}},{files:["**/package.json"],options:{useTabs:!1}},{files:["**/*.mdx"],options:{proseWrap:"preserve",htmlWhitespaceSensitivity:"ignore"}}]},i=e;export{e as config,i as default};
1
+ var e={printWidth:80,tabWidth:2,useTabs:!1,semi:!0,singleQuote:!0,arrowParens:"always",trailingComma:"es5",bracketSpacing:!0,bracketSameLine:!1,proseWrap:"preserve",endOfLine:"lf",quoteProps:"as-needed",singleAttributePerLine:!1,requirePragma:!1,insertPragma:!1,checkIgnorePragma:!0,jsxSingleQuote:!1,htmlWhitespaceSensitivity:"css",embeddedLanguageFormatting:"auto",overrides:[{files:"**/*.jsonc",options:{trailingComma:"none"}},{files:"**/*.hbs",options:{parser:"html"}},{files:["**/package.json"],options:{useTabs:!1}},{files:["**/*.mdx"],options:{proseWrap:"preserve",htmlWhitespaceSensitivity:"ignore"}}]},t=e;export{e as config,t as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "name": "@yunarch/config-web",
5
5
  "description": "Shared configurations for web projects.",
6
6
  "license": "MIT",
@@ -73,8 +73,7 @@
73
73
  "build": "bun run gen && tsup",
74
74
  "tests": "vitest --typecheck run",
75
75
  "tests:watch": "vitest --typecheck watch",
76
- "prepack": "bun run lint && bun run build && TEST_DIST=true bun run tests",
77
- "release": "bun publish --dry-run && bunx bumpp && bun publish"
76
+ "release": "bun run lint && bun run build && TEST_DIST=true bun run tests && bun publish --dry-run && bunx bumpp && bun publish"
78
77
  },
79
78
  "peerDependencies": {
80
79
  "@biomejs/biome": ">= 2 || < 3",
@@ -112,15 +111,15 @@
112
111
  "eslint-config-flat-gitignore": "2.1.0",
113
112
  "eslint-import-resolver-typescript": "4.4.4",
114
113
  "@eslint/js": "9.33.0",
115
- "typescript-eslint": "8.39.0",
114
+ "typescript-eslint": "8.39.1",
116
115
  "eslint-plugin-unicorn": "60.0.0",
117
116
  "eslint-plugin-perfectionist": "4.15.0",
118
117
  "eslint-plugin-import-x": "4.16.1",
119
118
  "eslint-plugin-unused-imports": "4.1.4",
120
- "eslint-plugin-jsdoc": "52.0.4",
119
+ "eslint-plugin-jsdoc": "54.0.0",
121
120
  "eslint-config-prettier": "10.1.8",
122
- "eslint-plugin-oxlint": "1.11.1",
123
- "@eslint-react/eslint-plugin": "1.52.3",
121
+ "eslint-plugin-oxlint": "1.11.2",
122
+ "@eslint-react/eslint-plugin": "1.52.4",
124
123
  "eslint-plugin-react-hooks": "5.2.0",
125
124
  "eslint-plugin-react-refresh": "0.4.20",
126
125
  "@tanstack/eslint-plugin-query": "5.83.1",
@@ -131,10 +130,10 @@
131
130
  "@commitlint/cli": "19.8.1",
132
131
  "@commitlint/config-conventional": "19.8.1",
133
132
  "prettier": "3.6.2",
134
- "@biomejs/biome": "2.1.4",
133
+ "@biomejs/biome": "2.2.0",
135
134
  "eslint": "9.33.0",
136
135
  "eslint-typegen": "2.3.0",
137
- "oxlint": "1.11.1",
136
+ "oxlint": "1.11.2",
138
137
  "husky": "9.1.7",
139
138
  "lint-staged": "16.1.5",
140
139
  "rimraf": "6.0.1",
@@ -142,7 +141,7 @@
142
141
  "typescript": "5.9.2",
143
142
  "vitest": "3.2.4",
144
143
  "jsonc-parser": "3.3.1",
145
- "msw": "2.10.4",
144
+ "msw": "2.10.5",
146
145
  "@types/node": "24.2.1",
147
146
  "@types/bun": "1.2.20"
148
147
  },