Skip to content

Auto-include built JS in releases — no manual list updates per bundle#93

Merged
epeicher merged 1 commit intotrunkfrom
fix/auto-include-built-js
May 6, 2026
Merged

Auto-include built JS in releases — no manual list updates per bundle#93
epeicher merged 1 commit intotrunkfrom
fix/auto-include-built-js

Conversation

@epeicher
Copy link
Copy Markdown
Collaborator

@epeicher epeicher commented May 6, 2026

Summary

Adding a new Vite-built bundle previously required editing two files:

  1. .gitignore — to keep the build output out of git.
  2. bin/package.sh — to splice the build output into the plugin zip.

Both were hand-maintained lists that drift the first time anyone forgets a step. Concretely, assets/js/sw.js and assets/js/sw.min.js recently appeared in the worktree as new build output but with no entries in either list.

This PR collapses both spots to a wildcard.

.gitignore

/assets/js/*.js
!/assets/js/admin-bar.js
!/assets/js/media-library-enhanced.js

Anything new built into assets/js/ is gitignored automatically; the two hand-written tracked files are explicitly re-included.

bin/package.sh

The hard-coded built array is replaced with:

mapfile -t built < <(git ls-files --others --ignored --exclude-standard -- 'assets/js/*.js')

git ls-files --others --ignored only returns files that exist on disk, so:

  • If the build was run → all built bundles get spliced into the zip, including new ones.
  • If the build was not run → empty array → the script errors with the same "run npm run build first" message as before.

Sync script

bin/sync-to-wp-develop.sh already rsyncs the entire assets/ directory, so no change is needed there. Same allow-list philosophy, different mechanism.

Verification

Local zip after this change:

$ unzip -l desktop-mode.zip | grep 'assets/js/.*\.js$' | sort
desktop-mode/assets/js/admin-bar.js
desktop-mode/assets/js/desktop.js
desktop-mode/assets/js/desktop.min.js
desktop-mode/assets/js/iframe-bridge.js
desktop-mode/assets/js/iframe-bridge.min.js
desktop-mode/assets/js/media-library-enhanced.js
desktop-mode/assets/js/recycle-bin.js
desktop-mode/assets/js/recycle-bin.min.js
desktop-mode/assets/js/sw.js
desktop-mode/assets/js/sw.min.js

sw.js / sw.min.js are picked up without any explicit listing in the script.

git check-ignore confirms the right files are ignored:

ignored:    desktop.js, desktop.min.js, iframe-bridge.js, iframe-bridge.min.js,
            recycle-bin.js, recycle-bin.min.js, sw.js, sw.min.js
not ignored: admin-bar.js, media-library-enhanced.js  (still tracked)

Test plan

  • npm run build && npm run package produces a zip with all 8 built bundles + the 2 hand-written tracked ones.
  • rm -rf assets/js/*.js && npm run package errors with the "build first" message instead of producing an empty zip.
  • git status after running npm run build shows nothing under assets/js/ (all built files correctly ignored).
  • Adding a hypothetical build:foo script that emits assets/js/foo.js and foo.min.js, then re-running npm run package, includes both files in the zip with no edits to .gitignore or bin/package.sh.
Open WordPress Playground Preview

Adding a new Vite-built bundle previously required editing two files:
- .gitignore (so the build output stays out of git)
- bin/package.sh (so the build output gets spliced into the release zip)

Both were manual lists that drift the moment someone forgets a step.

Now both work from a wildcard:

- .gitignore ignores `/assets/js/*.js` and explicitly re-includes the
  two hand-written tracked files (admin-bar.js, media-library-enhanced.js).
  Adding a new bundle in vite.config.js no longer requires touching
  this file.

- bin/package.sh derives its splice list from
  `git ls-files --others --ignored --exclude-standard -- 'assets/js/*.js'`,
  which lists every gitignored .js that exists on disk. Empty result =
  the build wasn't run, same error case as before. New bundles are
  picked up automatically.

The sync-to-wp-develop script already rsyncs the whole assets/ tree, so
no change is needed there.
@epeicher epeicher enabled auto-merge (squash) May 6, 2026 09:53
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

✅ WordPress Plugin Check Report

✅ Status: Passed

📊 Report

All checks passed! No errors or warnings found.


🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

@epeicher epeicher merged commit 34344da into trunk May 6, 2026
5 checks passed
@epeicher epeicher deleted the fix/auto-include-built-js branch May 6, 2026 09:54
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