fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #2335 from hey-api/chore/check-node-version

chore: check Node version

authored by

Lubos and committed by
GitHub
a382ae6c 68142247

+70 -8
+1
packages/openapi-ts/package.json
··· 101 101 }, 102 102 "devDependencies": { 103 103 "@config/vite-base": "workspace:*", 104 + "@types/bun": "1.2.19", 104 105 "@types/cross-spawn": "6.0.6", 105 106 "@types/express": "4.17.21", 106 107 "axios": "1.8.2",
+19
packages/openapi-ts/src/config/engine.ts
··· 1 + import { ConfigError } from '../error'; 2 + 3 + export const checkNodeVersion = () => { 4 + if (typeof Bun !== 'undefined') { 5 + const [major] = Bun.version.split('.').map(Number); 6 + if (major! < 1) { 7 + throw new ConfigError( 8 + `Unsupported Bun version ${Bun.version}. Please use Bun 1.0.0 or newer.`, 9 + ); 10 + } 11 + } else if (typeof process !== 'undefined' && process.versions?.node) { 12 + const [major] = process.versions.node.split('.').map(Number); 13 + if (major! < 18) { 14 + throw new ConfigError( 15 + `Unsupported Node version ${process.versions.node}. Please use Node 18 or newer.`, 16 + ); 17 + } 18 + } 19 + };
+5 -2
packages/openapi-ts/src/config/init.ts
··· 2 2 3 3 import { loadConfig } from 'c12'; 4 4 5 + import { ConfigError } from '../error'; 5 6 import type { Config, UserConfig } from '../types/config'; 6 7 import { isLegacyClient, setConfig } from '../utils/config'; 7 8 import { getInput } from './input'; ··· 70 71 71 72 if (!input.path) { 72 73 errors.push( 73 - new Error( 74 + new ConfigError( 74 75 'missing input - which OpenAPI specification should we use to generate your output?', 75 76 ), 76 77 ); ··· 78 79 79 80 if (!output.path) { 80 81 errors.push( 81 - new Error('missing output - where should we generate your output?'), 82 + new ConfigError( 83 + 'missing output - where should we generate your output?', 84 + ), 82 85 ); 83 86 } 84 87
+19 -5
packages/openapi-ts/src/error.ts
··· 8 8 9 9 export const isInteractive = process.stdin.isTTY && process.stdout.isTTY; 10 10 11 + export class ConfigError extends Error {} 12 + 11 13 export class HeyApiError extends Error { 12 14 args: ReadonlyArray<unknown>; 13 15 event: string; ··· 38 40 } 39 41 } 40 42 41 - export const logCrashReport = (error: unknown, logsDir: string): string => { 43 + export const logCrashReport = ( 44 + error: unknown, 45 + logsDir: string, 46 + ): string | undefined => { 47 + if (error instanceof ConfigError) { 48 + return; 49 + } 50 + 42 51 const logName = `openapi-ts-error-${Date.now()}.log`; 43 52 const fullDir = path.resolve(process.cwd(), logsDir); 44 53 ensureDirSync(fullDir); ··· 138 147 `\n\n${colors.red('❗️ Error:')} ${colors.white(typeof error === 'string' ? error : error instanceof Error ? error.message : 'Unknown error')}` + 139 148 (logPath 140 149 ? `\n\n${colors.cyan('📄 Crash log saved to:')} ${colors.gray(logPath)}` 141 - : ''), 150 + : '') + 151 + '\n', 142 152 ); 143 153 }; 144 154 145 - export const shouldReportCrash = async (): Promise<boolean> => { 146 - if (!isInteractive) { 155 + export const shouldReportCrash = async ({ 156 + error, 157 + }: { 158 + error: unknown; 159 + }): Promise<boolean> => { 160 + if (!isInteractive || error instanceof ConfigError) { 147 161 return false; 148 162 } 149 163 150 164 return new Promise((resolve) => { 151 165 process.stdout.write( 152 - `${colors.yellow('\n\n📢 Open a GitHub issue with crash details?')} ${colors.yellow('(y/N):')}`, 166 + `${colors.yellow('\n📢 Open a GitHub issue with crash details?')} ${colors.yellow('(y/N):')}`, 153 167 ); 154 168 process.stdin.setEncoding('utf8'); 155 169 process.stdin.once('data', (data: string) => {
+4 -1
packages/openapi-ts/src/index.ts
··· 2 2 // @ts-expect-error 3 3 import colorSupport from 'color-support'; 4 4 5 + import { checkNodeVersion } from './config/engine'; 5 6 import { initConfigs } from './config/init'; 6 7 import { getLogs } from './config/logs'; 7 8 import { createClient as pCreateClient } from './createClient'; ··· 35 36 const configs: Array<Config> = []; 36 37 37 38 try { 39 + checkNodeVersion(); 40 + 38 41 Performance.start('createClient'); 39 42 40 43 Performance.start('config'); ··· 90 93 91 94 if (logs.level !== 'silent') { 92 95 printCrashReport({ error, logPath }); 93 - if (await shouldReportCrash()) { 96 + if (await shouldReportCrash({ error })) { 94 97 await openGitHubIssueWithCrashReport(error); 95 98 } 96 99 }
+22
pnpm-lock.yaml
··· 808 808 '@config/vite-base': 809 809 specifier: workspace:* 810 810 version: link:../config-vite-base 811 + '@types/bun': 812 + specifier: 1.2.19 813 + version: 1.2.19(@types/react@19.0.1) 811 814 '@types/cross-spawn': 812 815 specifier: 6.0.6 813 816 version: 6.0.6 ··· 5080 5083 '@types/bonjour@3.5.13': 5081 5084 resolution: {integrity: sha512-z9fJ5Im06zvUL548KvYNecEVlA7cVDkGUi6kZusb04mpyEFKCIZJvloCcmpmLaIahDpOQGHaHmG6imtPMmPXGQ==} 5082 5085 5086 + '@types/bun@1.2.19': 5087 + resolution: {integrity: sha512-d9ZCmrH3CJ2uYKXQIUuZ/pUnTqIvLDS0SK7pFmbx8ma+ziH/FRMoAq5bYpRG7y+w1gl+HgyNZbtqgMq4W4e2Lg==} 5088 + 5083 5089 '@types/connect-history-api-fallback@1.5.4': 5084 5090 resolution: {integrity: sha512-n6Cr2xS1h4uAulPRdlw6Jl6s1oG8KrVilPN2yUITEs+K48EzMJJ3W1xy8K5eWuFvjp3R74AOIGSmp2UfBJ8HFw==} 5085 5091 ··· 6027 6033 6028 6034 buffer@6.0.3: 6029 6035 resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==} 6036 + 6037 + bun-types@1.2.19: 6038 + resolution: {integrity: sha512-uAOTaZSPuYsWIXRpj7o56Let0g/wjihKCkeRqUBhlLVM/Bt+Fj9xTo+LhC1OV1XDaGkz4hNC80et5xgy+9KTHQ==} 6039 + peerDependencies: 6040 + '@types/react': ^19 6030 6041 6031 6042 bundle-name@4.1.0: 6032 6043 resolution: {integrity: sha512-tjwM5exMg6BGRI+kNmTntNsvdZS1X8BFYS6tnJ2hdH0kVxM6/eVZ2xy+FqStSWvYmtfFMDLIxurorHwDKfDz5Q==} ··· 16523 16534 dependencies: 16524 16535 '@types/node': 22.10.5 16525 16536 16537 + '@types/bun@1.2.19(@types/react@19.0.1)': 16538 + dependencies: 16539 + bun-types: 1.2.19(@types/react@19.0.1) 16540 + transitivePeerDependencies: 16541 + - '@types/react' 16542 + 16526 16543 '@types/connect-history-api-fallback@1.5.4': 16527 16544 dependencies: 16528 16545 '@types/express-serve-static-core': 5.0.6 ··· 17786 17803 dependencies: 17787 17804 base64-js: 1.5.1 17788 17805 ieee754: 1.2.1 17806 + 17807 + bun-types@1.2.19(@types/react@19.0.1): 17808 + dependencies: 17809 + '@types/node': 22.10.5 17810 + '@types/react': 19.0.1 17789 17811 17790 17812 bundle-name@4.1.0: 17791 17813 dependencies: