Skip to content

feat(commands): add monorail:sync-assets to keep npm version aligned with Composer - #6

Merged
maherelgamil merged 1 commit into
mainfrom
feat/sync-assets-command
May 28, 2026
Merged

feat(commands): add monorail:sync-assets to keep npm version aligned with Composer#6
maherelgamil merged 1 commit into
mainfrom
feat/sync-assets-command

Conversation

@maherelgamil

Copy link
Copy Markdown
Contributor

Problem

The Composer package and the npm package are released together (composer require monorailphp/monorailnpm install monorailphp), but they live in two separate manifests. Host apps that bump the Composer constraint via composer update still have to remember to bump monorailphp in their package.json and re-run npm install — and forgetting leaves the frontend pinned to an older version with stale TSX/CSS.

Solution

A new Artisan command, monorail:sync-assets:

  1. Reads the installed Composer package version from vendor/monorailphp/monorail/package.json.
  2. Rewrites the host app's package.json so the monorailphp dependency is pinned to a matching ^x.y.z range.
  3. Runs npm install.

Flags:

  • --skip-install — only rewrite package.json; skip npm install. Intended for wiring into a Composer post-update-cmd hook so the sync runs automatically without forcing npm install on every composer update.

Example post-update hook (documented in installation.md):

```json
"scripts": {
"post-update-cmd": [
"@php artisan monorail:sync-assets --skip-install"
]
}
```

Files

  • src/Commands/SyncAssetsCommand.php — new command.
  • src/MonorailServiceProvider.php — register it.
  • docs/getting-started/installation.md — new "Keep the npm package in sync with Composer" section with usage and the post-update-cmd snippet.

Test plan

  • Run php artisan monorail:sync-assets in a host app pinned to an older monorailphp version → package.json is rewritten and npm install runs.
  • Re-run with no version drift → command exits with "already pinned; nothing to do."
  • Run with --skip-installpackage.json is rewritten, npm install is skipped.
  • Run in a directory missing package.json or the vendor package → command fails with a clear error message.

…with Composer

The Composer package and the npm package are released together but live in
two separate manifests, so host apps that bump `monorailphp/monorail` via
`composer update` still have to remember to bump `monorailphp` in
package.json and re-run `npm install`.

`monorail:sync-assets` reads the installed Composer package's version from
`vendor/monorailphp/monorail/package.json`, rewrites the host's package.json
so `monorailphp` is pinned to a matching `^x.y.z` range, and runs
`npm install`. Pass `--skip-install` to only rewrite package.json — useful
for wiring it into a Composer `post-update-cmd` hook without forcing
`npm install` on every Composer run.

Docs updated with usage and an example `post-update-cmd` snippet.
@maherelgamil
maherelgamil merged commit 9cb9008 into main May 28, 2026
9 checks passed
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