Skip to content

fix(maker): keep generated and updated files valid - #11

Merged
brianvarskonst merged 8 commits into
mainfrom
fix/generated-file-correctness
Nov 23, 2026
Merged

brianvarskonst merged 8 commits into
mainfrom
fix/generated-file-correctness

Conversation

@brianvarskonst

Copy link
Copy Markdown
Member

Problem

The Fable re-audit (2026-11-22) found several cases where makers write broken or misplaced files:

  1. make:sympress-package rewrote empty objects in the root composer.json as [] → Composer schema error on every command (Medium).
  2. YAML service definitions were appended to the end of services.yaml; a following when@dev:/parameters: key swallowed them silently (Low).
  3. ltrim($path, './') in make:asset-entry stripped a character set: ./.config/x.ts → config/x.ts, ../x.ts → x.ts (Low).
  4. Default webpack.config.js negated Encore.isProduction instead of calling it, so output cleanup never ran (Low).
  5. block.json had "attributes": []; JS literals contained \/ (Info).
  6. PackageContext::relativePath() skipped the symlink/traversal checks used by packageRelativePath() (Info, hardening).

Fix

One commit per finding: decode root composer.json into stdClass (JsonFile::readObject(), encode() accepts stdClass); insert YAML definitions before the next top-level key (add a services: block if missing, fail with a hint for inline services:); strip only a leading ./; call Encore.isProduction(); emit {} for attributes and JSON_UNESCAPED_SLASHES; route relativePath() through ProjectPath::relative().

Tests

Regression test per fix, each verified to fail on main and pass here (new PackageServiceConfiguratorTest, WebpackEncoreEntryConfiguratorTest, extended MakerInputSafetyTest / GeneratedSourceSafetyTest). Local: composer qa green (PHPCS, PHPStan, 30 tests / 202 assertions), composer validate --strict OK. Manually checked that a rewritten root composer.json with empty objects passes composer validate.

Release

Patch release 1.0.5 (chore(release): prepare 1.0.5); changelog also covers the unreleased Dependabot CI commit and drops the stale "Unreleased — Initial…" section.

make:sympress-package decoded the root composer.json into PHP arrays,
so empty objects such as "require-dev": {}, "extra": {} or
"config.allow-plugins": {} were written back as []. Composer then
rejects the file with a schema error on every command. Decode into
stdClass instead and only touch the require section being updated.
New definitions were appended to the end of services.yaml. When another
top-level key such as "when@dev:" or "parameters:" followed "services:",
the class landed under that key and was silently never registered.
Insert before the next top-level key instead, add a services block when
none exists, and fail with a hint when "services" is not a block mapping.
ltrim($sourcePath, './') removes a character set, not a prefix. A path
like "./.config/x.ts" became "config/x.ts" and "../x.ts" became "x.ts",
so the source file was created somewhere other than the path written to
webpack.config.js, and a leading ".." was swallowed instead of rejected.
The generated webpack.config.js negated the function reference
Encore.isProduction instead of calling it, so the condition was always
false and stale bundles were never cleaned from the output directory.
make:block encoded an empty PHP array, producing "attributes": [] while
the block.json schema expects an object. Emit {} instead.
SourceLiteral::javascript() left json_encode()'s "\/" escapes in place,
so generated webpack entries and block sources read '.\/Resources\/...'.
JSON_HEX_TAG already neutralises "</script>", so the slash escape adds
nothing.
PackageContext::relativePath() stripped the project prefix without the
traversal and symlink checks that packageRelativePath() applies. When a
package directory was a symlink to a target outside the project, the
service and webpack.config.js updates were still written there. Route
the result through ProjectPath::relative() like the other helper.
@brianvarskonst
brianvarskonst merged commit cf09442 into main Nov 23, 2026
3 checks passed
@brianvarskonst
brianvarskonst deleted the fix/generated-file-correctness branch November 23, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant