@amritk/mjst 0.7.4 → 0.7.6

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/dist/cli.js CHANGED
@@ -79,8 +79,12 @@ const buildOutput = async (outputDir, tsFiles, typesOnly) => {
79
79
  try {
80
80
  await execFileAsync('npx', ['tsc', '--project', tsconfigPath]);
81
81
  }
82
- catch {
83
- throw new Error('TypeScript compilation failed. Check the generated files for errors.');
82
+ catch (error) {
83
+ // tsc reports the actual errors on stdout; surface them so the user sees
84
+ // *what* failed instead of a bare "compilation failed".
85
+ const details = error;
86
+ const output = [details.stdout, details.stderr].filter(Boolean).join('\n').trim();
87
+ throw new Error(`TypeScript compilation failed. Check the generated files for errors.${output ? `\n\n${output}` : ''}`);
84
88
  }
85
89
  finally {
86
90
  await unlink(tsconfigPath);
@@ -1 +1 @@
1
- {"version":3,"file":"parse-cli-args.d.ts","sourceRoot":"","sources":["../src/parse-cli-args.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AA0G7C;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,SAAU,SAAS,MAAM,EAAE,KAAG,OAAO,CAAC,SAAS,CA0DvE,CAAA"}
1
+ {"version":3,"file":"parse-cli-args.d.ts","sourceRoot":"","sources":["../src/parse-cli-args.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAgH7C;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,SAAU,SAAS,MAAM,EAAE,KAAG,OAAO,CAAC,SAAS,CA0DvE,CAAA"}
@@ -43,14 +43,18 @@ const assignValue = (config, key, value) => {
43
43
  return true;
44
44
  case 'input': {
45
45
  const parsed = parseInputValue(value);
46
- if (parsed)
47
- config.input = parsed;
46
+ if (!parsed) {
47
+ throw new Error(`Invalid --input value "${value}". Expected one of: ${SOURCE_FORMATS.join(', ')}.`);
48
+ }
49
+ config.input = parsed;
48
50
  return true;
49
51
  }
50
52
  case 'helpers': {
51
53
  const parsed = parseHelpersValue(value);
52
- if (parsed)
53
- config.helpers = parsed;
54
+ if (!parsed) {
55
+ throw new Error(`Invalid --helpers value "${value}". Expected one of: package, embedded.`);
56
+ }
57
+ config.helpers = parsed;
54
58
  return true;
55
59
  }
56
60
  default:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amritk/mjst",
3
- "version": "0.7.4",
3
+ "version": "0.7.6",
4
4
  "description": "Generate TypeScript parsers and type definitions from JSON Schemas.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -42,10 +42,10 @@
42
42
  "generate-readme": "bun run ./scripts/generate-readme.ts"
43
43
  },
44
44
  "dependencies": {
45
- "@amritk/adapters": "0.2.6",
46
- "@amritk/generate-parsers": "0.7.0",
47
- "@amritk/generate-markdown": "0.2.3",
48
- "@amritk/helpers": "0.7.0"
45
+ "@amritk/adapters": "0.2.8",
46
+ "@amritk/generate-parsers": "0.7.2",
47
+ "@amritk/generate-markdown": "0.2.4",
48
+ "@amritk/helpers": "0.8.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "json-schema-typed": "^8.0.1"
package/src/cli.ts CHANGED
@@ -101,8 +101,14 @@ const buildOutput = async (outputDir: string, tsFiles: readonly string[], typesO
101
101
 
102
102
  try {
103
103
  await execFileAsync('npx', ['tsc', '--project', tsconfigPath])
104
- } catch {
105
- throw new Error('TypeScript compilation failed. Check the generated files for errors.')
104
+ } catch (error) {
105
+ // tsc reports the actual errors on stdout; surface them so the user sees
106
+ // *what* failed instead of a bare "compilation failed".
107
+ const details = error as { stdout?: string; stderr?: string }
108
+ const output = [details.stdout, details.stderr].filter(Boolean).join('\n').trim()
109
+ throw new Error(
110
+ `TypeScript compilation failed. Check the generated files for errors.${output ? `\n\n${output}` : ''}`,
111
+ )
106
112
  } finally {
107
113
  await unlink(tsconfigPath)
108
114
  }
@@ -234,14 +234,22 @@ describe('parse-cli-args', () => {
234
234
  expect(result).toEqual({ helpers: 'embedded' })
235
235
  })
236
236
 
237
- it('ignores invalid --helpers values', () => {
238
- const result = parseCliArgs(['--helpers', 'bogus', '--schema', 's.json'])
239
- expect(result).toEqual({ schema: 's.json' })
237
+ it('throws on an invalid --helpers value instead of silently ignoring it', () => {
238
+ expect(() => parseCliArgs(['--helpers', 'bogus', '--schema', 's.json'])).toThrow(/Invalid --helpers value "bogus"/)
240
239
  })
241
240
 
242
- it('ignores invalid --helpers=foo values', () => {
243
- const result = parseCliArgs(['--helpers=foo', '--schema', 's.json'])
244
- expect(result).toEqual({ schema: 's.json' })
241
+ it('throws on an invalid --helpers=foo value', () => {
242
+ expect(() => parseCliArgs(['--helpers=foo', '--schema', 's.json'])).toThrow(/package, embedded/)
243
+ })
244
+
245
+ it('parses a valid --input value', () => {
246
+ expect(parseCliArgs(['--input', 'zod'])).toEqual({ input: 'zod' })
247
+ })
248
+
249
+ it('throws on an invalid --input value, listing the valid formats', () => {
250
+ expect(() => parseCliArgs(['--input', 'typscript'])).toThrow(
251
+ /Invalid --input value "typscript".*json, typebox, zod, valibot, effect/,
252
+ )
245
253
  })
246
254
 
247
255
  it('accepts kebab-case flag names', () => {
@@ -70,12 +70,18 @@ const assignValue = (config: MutableConfig, key: string, value: string): boolean
70
70
  return true
71
71
  case 'input': {
72
72
  const parsed = parseInputValue(value)
73
- if (parsed) config.input = parsed
73
+ if (!parsed) {
74
+ throw new Error(`Invalid --input value "${value}". Expected one of: ${SOURCE_FORMATS.join(', ')}.`)
75
+ }
76
+ config.input = parsed
74
77
  return true
75
78
  }
76
79
  case 'helpers': {
77
80
  const parsed = parseHelpersValue(value)
78
- if (parsed) config.helpers = parsed
81
+ if (!parsed) {
82
+ throw new Error(`Invalid --helpers value "${value}". Expected one of: package, embedded.`)
83
+ }
84
+ config.helpers = parsed
79
85
  return true
80
86
  }
81
87
  default: