@omnifyjp/ts 6.3.7 → 6.3.9
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 +16 -1
- package/dist/php/model-generator.d.ts +2 -1
- package/dist/php/model-generator.js +33 -28
- package/dist/php/pint-format.d.ts +6 -0
- package/dist/php/pint-format.js +3 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -322,7 +322,17 @@ program
|
|
|
322
322
|
// Laravel Pint when it's installed in the project. Same preset
|
|
323
323
|
// the project's CI already uses, so codegen output stops failing
|
|
324
324
|
// `pint --test` and devs no longer need a manual sweep after
|
|
325
|
-
// every `omnify generate`.
|
|
325
|
+
// every `omnify generate`.
|
|
326
|
+
//
|
|
327
|
+
// NOT a silent no-op when Pint is missing any more. It used to be, and that cost a
|
|
328
|
+
// consumer several investigation sessions: their CI regenerated without Pint on PATH,
|
|
329
|
+
// wrote 927 files differing from the committed (Pint-formatted) tree, and the only
|
|
330
|
+
// evidence was one ABSENT log line. It was read as a Linux/Darwin build divergence and
|
|
331
|
+
// chased as far as "pick a canonical platform" before anyone ran the two commands that
|
|
332
|
+
// settle it (godx-jp/godx-corebooks#108, reproduced exactly: hide `vendor/bin/pint`,
|
|
333
|
+
// regenerate, 927 files; restore it, 0).
|
|
334
|
+
//
|
|
335
|
+
// The opt-out (`OMNIFY_NO_PINT=1`) stays quiet — that one is a choice, not a surprise.
|
|
326
336
|
if (writtenPaths.length > 0) {
|
|
327
337
|
const pintResult = runPintFormat(writtenPaths);
|
|
328
338
|
if (pintResult.ran) {
|
|
@@ -337,6 +347,11 @@ program
|
|
|
337
347
|
}
|
|
338
348
|
}
|
|
339
349
|
}
|
|
350
|
+
else if (pintResult.skipped === 'pint-not-found') {
|
|
351
|
+
console.warn(` [omnify] Laravel Pint not found — ${writtenPaths.length} PHP file(s) written UNFORMATTED.`);
|
|
352
|
+
console.warn(' If this project commits generated PHP, the output will differ from a tree formatted by Pint.');
|
|
353
|
+
console.warn(' Run `composer install` before `omnify generate`, or set OMNIFY_NO_PINT=1 to silence this deliberately.');
|
|
354
|
+
}
|
|
340
355
|
}
|
|
341
356
|
// Orphan cleanup: when a schema is removed, renamed, flipped from
|
|
342
357
|
// kind:object → kind:pivot, or opted out via `options.service: false`,
|
|
@@ -4,5 +4,6 @@
|
|
|
4
4
|
import { SchemaReader } from './schema-reader.js';
|
|
5
5
|
import type { GeneratedFile, PhpConfig } from './types.js';
|
|
6
6
|
/** Generate base model and user model for all project-owned object schemas,
|
|
7
|
-
* plus
|
|
7
|
+
* plus, for each package schema the project extends, a user model that
|
|
8
|
+
* extends the package model and carries the extend's columns. */
|
|
8
9
|
export declare function generateModels(reader: SchemaReader, config: PhpConfig): GeneratedFile[];
|
|
@@ -8,24 +8,34 @@ import { buildRelation } from './relation-builder.js';
|
|
|
8
8
|
import { baseFile, userFile, shadowingPropertyConflicts, resolveModularBasePath, resolveModularBaseNamespace, resolveSharedBaseNamespace, resolveGlobalTraitNamespace, resolveGlobalEnumNamespace, resolveBaseClass, resolveEditableClass, nestByGroup, nestEditableByGroup, } from './types.js';
|
|
9
9
|
import { enumClassName } from './enum-generator.js';
|
|
10
10
|
/** Generate base model and user model for all project-owned object schemas,
|
|
11
|
-
* plus
|
|
11
|
+
* plus, for each package schema the project extends, a user model that
|
|
12
|
+
* extends the package model and carries the extend's columns. */
|
|
12
13
|
export function generateModels(reader, config) {
|
|
13
14
|
const files = [];
|
|
14
15
|
// Project-owned schemas: base model + user model
|
|
15
16
|
for (const [name, schema] of Object.entries(reader.getProjectObjectSchemas())) {
|
|
16
17
|
files.push(...generateForSchema(name, schema, reader, config));
|
|
17
18
|
}
|
|
18
|
-
// Package schemas
|
|
19
|
-
//
|
|
19
|
+
// Package schemas the project extends with `kind: extend`: a trait carrying
|
|
20
|
+
// the added columns (#164) plus a user model in the project namespace that
|
|
21
|
+
// `use`s it — the trait needs a class to live in, and the package's own
|
|
22
|
+
// model cannot be that class once it is installed under `vendor/`.
|
|
23
|
+
//
|
|
24
|
+
// A package schema the project does NOT extend gets nothing: the package
|
|
25
|
+
// model is the model, and relations already point at it. Every such
|
|
26
|
+
// schema used to get an empty `extends Package<Name>` stub anyway, and a
|
|
27
|
+
// workspace of three packages saw sixteen of them on every fresh checkout
|
|
28
|
+
// after deleting them (#182). A project that wants a local subclass for one
|
|
29
|
+
// of these writes the five lines itself, or extends the schema.
|
|
20
30
|
for (const [name, schema] of Object.entries(reader.getPackageObjectSchemas())) {
|
|
21
31
|
const pkgNs = reader.resolveModelNamespace(name, config.models.namespace);
|
|
22
|
-
if (pkgNs
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
if (pkgNs === config.models.namespace)
|
|
33
|
+
continue;
|
|
34
|
+
const extended = extendedPropertyNames(schema);
|
|
35
|
+
if (extended.length === 0)
|
|
36
|
+
continue;
|
|
37
|
+
files.push(generateExtendAttributesTrait(name, schema, extended, reader, config));
|
|
38
|
+
files.push(generatePackageUserModel(name, pkgNs, config, schema.kind === 'pivot'));
|
|
29
39
|
}
|
|
30
40
|
return files;
|
|
31
41
|
}
|
|
@@ -1056,8 +1066,9 @@ function buildAccessors(expandedProperties) {
|
|
|
1056
1066
|
}
|
|
1057
1067
|
return methods.join('\n');
|
|
1058
1068
|
}
|
|
1059
|
-
/** Generate a user model for a package schema
|
|
1060
|
-
|
|
1069
|
+
/** Generate a user model for a package schema the project extends: it
|
|
1070
|
+
* extends the package's model class and `use`s the extend-attributes trait. */
|
|
1071
|
+
function generatePackageUserModel(name, packageNamespace, config, isPivot = false) {
|
|
1061
1072
|
const modelName = toPascalCase(name);
|
|
1062
1073
|
const modelNamespace = config.models.namespace;
|
|
1063
1074
|
// #178: a `kind: pivot` schema's editable model is emitted under the
|
|
@@ -1074,12 +1085,8 @@ function generatePackageUserModel(name, packageNamespace, config, hasExtendAttri
|
|
|
1074
1085
|
// predates its extend keeps the file it has, and `generateModels` warns with
|
|
1075
1086
|
// the one line to add — overwriting somebody's model to add an import is the
|
|
1076
1087
|
// worse of the two.
|
|
1077
|
-
const traitImport =
|
|
1078
|
-
|
|
1079
|
-
: '';
|
|
1080
|
-
const traitUse = hasExtendAttributes
|
|
1081
|
-
? ` use ${traitName};\n\n`
|
|
1082
|
-
: '';
|
|
1088
|
+
const traitImport = `use ${modelNamespace}\\Concerns\\${traitName};\n`;
|
|
1089
|
+
const traitUse = ` use ${traitName};\n\n`;
|
|
1083
1090
|
const content = `<?php
|
|
1084
1091
|
|
|
1085
1092
|
namespace ${modelNamespace};
|
|
@@ -1097,16 +1104,14 @@ class ${modelName} extends Package${modelName}
|
|
|
1097
1104
|
${traitUse} // Add your custom methods here
|
|
1098
1105
|
}
|
|
1099
1106
|
`;
|
|
1100
|
-
return userFile(`${config.models.path}/${modelName}.php`, content,
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
}
|
|
1109
|
-
: undefined);
|
|
1107
|
+
return userFile(`${config.models.path}/${modelName}.php`, content, {
|
|
1108
|
+
needle: `use ${traitName};`,
|
|
1109
|
+
hint: `this project's \`kind: extend\` adds columns to the package-owned `
|
|
1110
|
+
+ `${modelName} schema, but this model predates the trait that carries `
|
|
1111
|
+
+ `them, so those columns are still not fillable or cast. Add `
|
|
1112
|
+
+ `\`use ${config.models.namespace}\\Concerns\\${traitName};\` and `
|
|
1113
|
+
+ `\`use ${traitName};\` inside the class (#164).`,
|
|
1114
|
+
});
|
|
1110
1115
|
}
|
|
1111
1116
|
/**
|
|
1112
1117
|
* Detect whether a schema uses nested set (tree structure).
|
|
@@ -38,6 +38,12 @@ export interface PintFormatResult {
|
|
|
38
38
|
exitStatus: number | null;
|
|
39
39
|
/** Captured stderr when pint failed (status != 0). */
|
|
40
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';
|
|
41
47
|
}
|
|
42
48
|
/**
|
|
43
49
|
* Run Laravel Pint on the given PHP files (absolute paths). No-op if
|
package/dist/php/pint-format.js
CHANGED
|
@@ -63,21 +63,21 @@ export function findPintBinary(anyWrittenPhpPath) {
|
|
|
63
63
|
*/
|
|
64
64
|
export function runPintFormat(writtenPhpPaths) {
|
|
65
65
|
if (writtenPhpPaths.length === 0) {
|
|
66
|
-
return { ran: false, pintPath: null, formattedCount: 0, exitStatus: null };
|
|
66
|
+
return { ran: false, pintPath: null, formattedCount: 0, exitStatus: null, skipped: 'no-php-files' };
|
|
67
67
|
}
|
|
68
68
|
// Opt-out (#174). The auto-run hides what the generators actually emit: a
|
|
69
69
|
// template that Pint rewrites looks fine here and produces churn in every
|
|
70
70
|
// project where Pint is absent or does not run. `OMNIFY_NO_PINT=1` is how
|
|
71
71
|
// the repo's own fixture check measures the raw output.
|
|
72
72
|
if (process.env.OMNIFY_NO_PINT === '1') {
|
|
73
|
-
return { ran: false, pintPath: null, formattedCount: 0, exitStatus: null };
|
|
73
|
+
return { ran: false, pintPath: null, formattedCount: 0, exitStatus: null, skipped: 'opted-out' };
|
|
74
74
|
}
|
|
75
75
|
// Resolution walks up from a written file. Trying only the first one makes
|
|
76
76
|
// it depend on emission order — a single file outside the Laravel root and
|
|
77
77
|
// the whole run goes unformatted, silently. Try each until one resolves.
|
|
78
78
|
const pintPath = writtenPhpPaths.reduce((found, path) => found ?? findPintBinary(path), null);
|
|
79
79
|
if (!pintPath) {
|
|
80
|
-
return { ran: false, pintPath: null, formattedCount: 0, exitStatus: null };
|
|
80
|
+
return { ran: false, pintPath: null, formattedCount: 0, exitStatus: null, skipped: 'pint-not-found' };
|
|
81
81
|
}
|
|
82
82
|
// Pint's working dir should be the Laravel project root (where
|
|
83
83
|
// composer.json + pint.json live). The pint binary is at
|