@omnifyjp/ts 7.0.1 → 7.0.2

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
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnifyjp/ts",
3
- "version": "7.0.1",
3
+ "version": "7.0.2",
4
4
  "description": "TypeScript model type generator from Omnify schemas.json",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -9,7 +9,7 @@
9
9
  "omnify-ts": "dist/cli.js"
10
10
  },
11
11
  "scripts": {
12
- "build": "tsc",
12
+ "build": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\" && tsc",
13
13
  "dev": "tsc --watch",
14
14
  "generate-l12": "node dist/cli.js --config ../../examples/l12/omnify.yaml",
15
15
  "test": "vitest run"
@@ -1,57 +0,0 @@
1
- /**
2
- * Auto-format generated PHP files via Laravel Pint. Issue #100 v5.8.20.
3
- *
4
- * Reporter scenario (godx-jp/godx-kintai 2026-04-26 audit): every
5
- * `omnify generate --force` produces 150+ PHP files that fail Laravel
6
- * Pint's standard preset (`vendor/bin/pint --test`):
7
- *
8
- * - ordered_imports — `use` statements not alphabetised
9
- * - fully_qualified_strict_types — exception types referenced via FQN
10
- * - class_attributes_separation — missing blank lines between members
11
- * - function_declaration — function-keyword spacing
12
- * - unary_operator_spaces — `! \$x` vs `!\$x`
13
- * - no_unused_imports — codegen leaves the occasional dangling import
14
- * - single_line_empty_body — empty class bodies on multiple lines
15
- * - self_static_accessor — `self::` vs `static::` on enums
16
- * - blank_line_before_statement — enum `case` separators
17
- *
18
- * Auto-detect: when `<rootPath>/vendor/bin/pint` exists, run it on the
19
- * files we just wrote. Same Pint preset the project's CI already uses,
20
- * so no risk of formatter drift between codegen and CI checks.
21
- *
22
- * Opt-out: future config field; for now `chmod -x vendor/bin/pint` or
23
- * deleting it disables the auto-run.
24
- */
25
- /**
26
- * Resolve the `vendor/bin/pint` path for the project. Walks up from
27
- * the first written file until we find a sibling `vendor/bin/pint`,
28
- * stopping at filesystem root or after 12 levels (defensive against
29
- * pathological inputs). Returns the absolute path or null.
30
- */
31
- export declare function findPintBinary(anyWrittenPhpPath: string): string | null;
32
- export interface PintFormatResult {
33
- ran: boolean;
34
- pintPath: string | null;
35
- /** Files passed to pint. */
36
- formattedCount: number;
37
- /** Pint's exit status if it ran. 0 = success. */
38
- exitStatus: number | null;
39
- /** Captured stderr when pint failed (status != 0). */
40
- errorMessage?: string;
41
- /**
42
- * Why the run did not happen, when `ran` is false. The caller needs the three apart: only
43
- * `pint-not-found` is worth telling a human about, and it is the one that silently changes what
44
- * gets written to disk (godx-jp/godx-corebooks#108 — 927 files, reproduced).
45
- */
46
- skipped?: 'no-php-files' | 'opted-out' | 'pint-not-found';
47
- }
48
- /**
49
- * Run Laravel Pint on the given PHP files (absolute paths). No-op if
50
- * Pint isn't installed in the project. Pint is invoked with `--quiet`
51
- * so it stays out of the way unless something breaks.
52
- *
53
- * Pint takes a list of files (or directories) and formats them in
54
- * place. It uses the project's `pint.json` config if present, else the
55
- * Laravel preset.
56
- */
57
- export declare function runPintFormat(writtenPhpPaths: string[]): PintFormatResult;
@@ -1,102 +0,0 @@
1
- /**
2
- * Auto-format generated PHP files via Laravel Pint. Issue #100 v5.8.20.
3
- *
4
- * Reporter scenario (godx-jp/godx-kintai 2026-04-26 audit): every
5
- * `omnify generate --force` produces 150+ PHP files that fail Laravel
6
- * Pint's standard preset (`vendor/bin/pint --test`):
7
- *
8
- * - ordered_imports — `use` statements not alphabetised
9
- * - fully_qualified_strict_types — exception types referenced via FQN
10
- * - class_attributes_separation — missing blank lines between members
11
- * - function_declaration — function-keyword spacing
12
- * - unary_operator_spaces — `! \$x` vs `!\$x`
13
- * - no_unused_imports — codegen leaves the occasional dangling import
14
- * - single_line_empty_body — empty class bodies on multiple lines
15
- * - self_static_accessor — `self::` vs `static::` on enums
16
- * - blank_line_before_statement — enum `case` separators
17
- *
18
- * Auto-detect: when `<rootPath>/vendor/bin/pint` exists, run it on the
19
- * files we just wrote. Same Pint preset the project's CI already uses,
20
- * so no risk of formatter drift between codegen and CI checks.
21
- *
22
- * Opt-out: future config field; for now `chmod -x vendor/bin/pint` or
23
- * deleting it disables the auto-run.
24
- */
25
- import { existsSync, statSync } from 'node:fs';
26
- import { spawnSync } from 'node:child_process';
27
- import { dirname, join } from 'node:path';
28
- /**
29
- * Resolve the `vendor/bin/pint` path for the project. Walks up from
30
- * the first written file until we find a sibling `vendor/bin/pint`,
31
- * stopping at filesystem root or after 12 levels (defensive against
32
- * pathological inputs). Returns the absolute path or null.
33
- */
34
- export function findPintBinary(anyWrittenPhpPath) {
35
- let cur = dirname(anyWrittenPhpPath);
36
- for (let i = 0; i < 12; i++) {
37
- const candidate = join(cur, 'vendor', 'bin', 'pint');
38
- if (existsSync(candidate)) {
39
- try {
40
- const st = statSync(candidate);
41
- if (st.isFile())
42
- return candidate;
43
- }
44
- catch {
45
- // ignore stat errors and keep climbing
46
- }
47
- }
48
- const parent = dirname(cur);
49
- if (parent === cur)
50
- break;
51
- cur = parent;
52
- }
53
- return null;
54
- }
55
- /**
56
- * Run Laravel Pint on the given PHP files (absolute paths). No-op if
57
- * Pint isn't installed in the project. Pint is invoked with `--quiet`
58
- * so it stays out of the way unless something breaks.
59
- *
60
- * Pint takes a list of files (or directories) and formats them in
61
- * place. It uses the project's `pint.json` config if present, else the
62
- * Laravel preset.
63
- */
64
- export function runPintFormat(writtenPhpPaths) {
65
- if (writtenPhpPaths.length === 0) {
66
- return { ran: false, pintPath: null, formattedCount: 0, exitStatus: null, skipped: 'no-php-files' };
67
- }
68
- // Opt-out (#174). The auto-run hides what the generators actually emit: a
69
- // template that Pint rewrites looks fine here and produces churn in every
70
- // project where Pint is absent or does not run. `OMNIFY_NO_PINT=1` is how
71
- // the repo's own fixture check measures the raw output.
72
- if (process.env.OMNIFY_NO_PINT === '1') {
73
- return { ran: false, pintPath: null, formattedCount: 0, exitStatus: null, skipped: 'opted-out' };
74
- }
75
- // Resolution walks up from a written file. Trying only the first one makes
76
- // it depend on emission order — a single file outside the Laravel root and
77
- // the whole run goes unformatted, silently. Try each until one resolves.
78
- const pintPath = writtenPhpPaths.reduce((found, path) => found ?? findPintBinary(path), null);
79
- if (!pintPath) {
80
- return { ran: false, pintPath: null, formattedCount: 0, exitStatus: null, skipped: 'pint-not-found' };
81
- }
82
- // Pint's working dir should be the Laravel project root (where
83
- // composer.json + pint.json live). The pint binary is at
84
- // `<projectRoot>/vendor/bin/pint`, so projectRoot is two parents up.
85
- const projectRoot = dirname(dirname(dirname(pintPath)));
86
- // Pass each file as its own arg. Pint accepts multiple file/dir
87
- // arguments; capping the batch is unnecessary up to a few hundred
88
- // files (well under the OS arg limit).
89
- const result = spawnSync(pintPath, ['--quiet', ...writtenPhpPaths], {
90
- cwd: projectRoot,
91
- stdio: ['ignore', 'pipe', 'pipe'],
92
- encoding: 'utf-8',
93
- });
94
- const exitStatus = result.status ?? null;
95
- return {
96
- ran: true,
97
- pintPath,
98
- formattedCount: writtenPhpPaths.length,
99
- exitStatus,
100
- errorMessage: exitStatus !== 0 ? (result.stderr || result.stdout || undefined) : undefined,
101
- };
102
- }
@@ -1,23 +0,0 @@
1
- /**
2
- * Auto-format generated TypeScript files via the consuming project's Prettier.
3
- * Issue omnify-jp/omnify-go#211 (mirrors php/pint-format.ts).
4
- */
5
- /**
6
- * Resolve `node_modules/.bin/prettier` by walking up from a written `.ts` file.
7
- */
8
- export declare function findPrettierBinary(anyWrittenTsPath: string): string | null;
9
- /** Directory containing the `node_modules` that owns this Prettier binary. */
10
- export declare function prettierProjectRoot(prettierPath: string): string;
11
- export interface PrettierFormatResult {
12
- ran: boolean;
13
- prettierPath: string | null;
14
- formattedCount: number;
15
- exitStatus: number | null;
16
- errorMessage?: string;
17
- skipped?: 'no-ts-files' | 'opted-out' | 'prettier-not-found';
18
- }
19
- /**
20
- * Run the project's Prettier on the given TypeScript files (absolute paths).
21
- * Silent no-op when Prettier is not installed; never throws.
22
- */
23
- export declare function runPrettierFormat(writtenTsPaths: string[]): PrettierFormatResult;
@@ -1,102 +0,0 @@
1
- /**
2
- * Auto-format generated TypeScript files via the consuming project's Prettier.
3
- * Issue omnify-jp/omnify-go#211 (mirrors php/pint-format.ts).
4
- */
5
- import { existsSync, statSync } from 'node:fs';
6
- import { spawnSync } from 'node:child_process';
7
- import { dirname, join } from 'node:path';
8
- /** Max file paths per Prettier invocation (stay under typical ARG_MAX). */
9
- const PRETTIER_BATCH_SIZE = 100;
10
- /**
11
- * Resolve `node_modules/.bin/prettier` by walking up from a written `.ts` file.
12
- */
13
- export function findPrettierBinary(anyWrittenTsPath) {
14
- let cur = dirname(anyWrittenTsPath);
15
- for (let i = 0; i < 12; i++) {
16
- const candidate = join(cur, 'node_modules', '.bin', 'prettier');
17
- if (existsSync(candidate)) {
18
- try {
19
- const st = statSync(candidate);
20
- if (st.isFile())
21
- return candidate;
22
- }
23
- catch {
24
- // ignore stat errors and keep climbing
25
- }
26
- }
27
- const parent = dirname(cur);
28
- if (parent === cur)
29
- break;
30
- cur = parent;
31
- }
32
- return null;
33
- }
34
- /** Directory containing the `node_modules` that owns this Prettier binary. */
35
- export function prettierProjectRoot(prettierPath) {
36
- return dirname(dirname(dirname(prettierPath)));
37
- }
38
- function runPrettierBatch(prettierPath, projectRoot, files) {
39
- const result = spawnSync(prettierPath, ['--write', ...files], {
40
- cwd: projectRoot,
41
- stdio: ['ignore', 'pipe', 'pipe'],
42
- encoding: 'utf-8',
43
- });
44
- const exitStatus = result.status ?? null;
45
- return {
46
- exitStatus,
47
- errorMessage: exitStatus !== 0 ? (result.stderr || result.stdout || undefined) : undefined,
48
- };
49
- }
50
- /**
51
- * Run the project's Prettier on the given TypeScript files (absolute paths).
52
- * Silent no-op when Prettier is not installed; never throws.
53
- */
54
- export function runPrettierFormat(writtenTsPaths) {
55
- if (writtenTsPaths.length === 0) {
56
- return {
57
- ran: false,
58
- prettierPath: null,
59
- formattedCount: 0,
60
- exitStatus: null,
61
- skipped: 'no-ts-files',
62
- };
63
- }
64
- if (process.env.OMNIFY_NO_PRETTIER === '1') {
65
- return {
66
- ran: false,
67
- prettierPath: null,
68
- formattedCount: 0,
69
- exitStatus: null,
70
- skipped: 'opted-out',
71
- };
72
- }
73
- const prettierPath = writtenTsPaths.reduce((found, path) => found ?? findPrettierBinary(path), null);
74
- if (!prettierPath) {
75
- return {
76
- ran: false,
77
- prettierPath: null,
78
- formattedCount: 0,
79
- exitStatus: null,
80
- skipped: 'prettier-not-found',
81
- };
82
- }
83
- const projectRoot = prettierProjectRoot(prettierPath);
84
- let exitStatus = 0;
85
- let errorMessage;
86
- for (let i = 0; i < writtenTsPaths.length; i += PRETTIER_BATCH_SIZE) {
87
- const batch = writtenTsPaths.slice(i, i + PRETTIER_BATCH_SIZE);
88
- const batchResult = runPrettierBatch(prettierPath, projectRoot, batch);
89
- if (batchResult.exitStatus !== 0) {
90
- exitStatus = batchResult.exitStatus;
91
- errorMessage = batchResult.errorMessage;
92
- break;
93
- }
94
- }
95
- return {
96
- ran: true,
97
- prettierPath,
98
- formattedCount: writtenTsPaths.length,
99
- exitStatus,
100
- errorMessage,
101
- };
102
- }