Skip to content

fix(webpack): allow emitting assets from buildEnd - #619

Open
Huzaifa-Asif wants to merge 1 commit into
unjs:mainfrom
Huzaifa-Asif:fix/webpack-build-end-emit-file
Open

Huzaifa-Asif wants to merge 1 commit into
unjs:mainfrom
Huzaifa-Asif:fix/webpack-build-end-emit-file

Conversation

@Huzaifa-Asif

@Huzaifa-Asif Huzaifa-Asif commented Oct 3, 2026 •

Copy link
Copy Markdown

Summary

  • run webpack 5+ buildEnd hooks during processAssets at the additional-assets stage
  • keep the existing emit-hook behavior as a compatibility fallback for older webpack versions
  • add an integration regression that checks buildEnd runs before webpack begins emitting and that this.emitFile writes the requested asset

Webpack currently invokes buildEnd from compiler.hooks.emit, after compilation assets have been sealed. Calling this.emitFile there triggers webpack's DEP_WEBPACK_COMPILATION_ASSETS warning and is incompatible with webpack's asset lifecycle. Moving the hook into processAssets lets emitted assets participate in the rest of webpack's asset pipeline.

Resolves #473.

Verification

  • pnpm exec vitest run test/unit-tests/build-end/build-end.test.ts — 1 passed (the regression fails on main because buildEnd runs after emit begins)
  • pnpm test — 24 files passed, 3 skipped; 167 tests passed, 25 skipped
  • pnpm lint
  • pnpm typecheck
  • pnpm build
  • git diff --check

AI assistance

OpenAI Codex assisted with issue research, implementation, tests, verification, and drafting this description. The contributor reviewed the submitted code and tests on 2026-10-04, after the draft PR had been opened.

@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 815e387e-3319-495f-acb7-ca0c60c10428
📥 Commits

Reviewing files that changed from the base of the PR and between f2acf00 and 9a619b1.

📒 Files selected for processing (3)
  • src/webpack/index.ts
  • test/unit-tests/build-end/.gitignore
  • test/unit-tests/build-end/build-end.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Webpack runs buildEnd during processAssets at PROCESS_ASSETS_STAGE_ADDITIONAL when that stage is available. Otherwise, it uses the emit hook. An integration test checks hook order and verifies that an asset created by buildEnd reaches the output directory.

Changes

Webpack buildEnd asset emission

Layer / File(s) Summary
Schedule buildEnd and verify asset output
src/webpack/index.ts, test/unit-tests/build-end/build-end.test.ts, test/unit-tests/build-end/.gitignore
When Webpack exposes PROCESS_ASSETS_STAGE_ADDITIONAL, buildEnd runs during processAssets; otherwise, the emit fallback remains. The integration test checks that buildEnd runs before emit and that its emitted JSON asset is written to the output directory. The test output directory is ignored.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Sequence Diagram(s)

sequenceDiagram
  participant WebpackCompiler
  participant Compilation
  participant UnpluginBuildEnd
  participant Output
  WebpackCompiler->>Compilation: Start thisCompilation
  Compilation->>UnpluginBuildEnd: Run buildEnd at PROCESS_ASSETS_STAGE_ADDITIONAL
  UnpluginBuildEnd->>Compilation: Emit build-end.json
  WebpackCompiler->>Output: Write emitted asset
Loading

Merge Risk: ⚪ Minimal · up to 9a619

No actionable merge-blocking risk remains for the Webpack buildEnd change after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 9a619

The change preserves existing plugin authority and keeps asset emission under Webpack’s control. Successful execution is covered by a regression test, but failure after asset creation and repeated or interrupted builds remain unverified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The evidenced exposure is the active Webpack compilation and its downstream asset output for builds using the configured plugin. The timing change does not establish new tenant, service, credential, or environment authority.

Trust Boundaries and Controls

  • observed — Asset filenames and contents originate from the configured plugin. The existing context requires a compilation and delegates emission to compilation.emitAsset; it does not itself validate filenames as a security boundary. The changed scheduling continues to use that same context and sink.

Resilience and Maintainability Implications

  • inferred — Exclusive registration and compilation-local closures support isolation at the adapter level. They do not establish terminal output suppression or cleanup after a hook emits an asset and then rejects; those guarantees depend on Webpack lifecycle behavior not resolved by the supplied regression.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #473 asks for webpack buildEnd to support this.emitFile. The PR summary states that webpack runs buildEnd from thisCompilation at PROCESS_ASSETS_STAGE_ADDITIONAL when available, with t…
Out of Scope Changes check ✅ Passed The reported changes are limited to the webpack buildEnd lifecycle fix, its integration regression test, and a .gitignore entry for that test's output. These changes support issue #473. The whole-…
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: enabling asset emission from webpack’s buildEnd hook.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Huzaifa-Asif
Huzaifa-Asif marked this pull request as ready for review October 4, 2026 06:35

This branch has not been deployed

No deployments
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.

webpack: emitFile is not supported inside buildEnd

1 participant