yyqdbngt opened a new pull request, #5346:
URL: https://github.com/apache/rocketmq-dashboard/pull/5346

   ### Which Issue(s) This PR Fixes
   
   - Fixes #5018
   
   ### Brief Description
   
   `web/scripts/licenses.mjs` hashed every bundle entry inside the license 
plugin's `generateBundle`
   hook and emitted `legal/manifest.json` from those hashes. The Vite build 
rewrites the entry chunk
   right after that hook — `vite:build-import-analysis` prepends the `const 
__vite__mapDeps=...`
   helper and resolves the `__VITE_PRELOAD__` markers — so the manifest 
recorded an intermediate
   chunk. A clean `npm run build` therefore failed at the gate with
   `license gate: build artifact verification failed: assets/index-*.js`. 
Recomputing every hash in
   `manifest.outputFiles` against the failed build's `dist/` showed the entry 
chunk as the only
   mismatch, exactly as the report describes.
   
   The fix adds a `writeBundle` hook that refreshes `outputFiles` from the 
bytes that were written to
   the output directory and rewrites `legal/manifest.json`, so the manifest 
describes the distributed
   files rather than the pre-rewrite bundle state. `checkDistribution` is 
unchanged, so a file that is
   modified after the gate ran is still rejected.
   
   ### How Did You Test This Change?
   
   The new `lateEntryRewriteStillPassesTheGateTest` builds a small fixture with 
`write: true` and a
   second post plugin that rewrites the entry chunk after the license manifest 
has been emitted, then
   runs the gate over `dist/` and tampers with the entry chunk afterwards:
   
   ```sh
   $ cd web && node --test scripts/licenses.test.mjs      # before the fix 
(test added, licenses.mjs unmodified)
   ✖ lateEntryRewriteStillPassesTheGateTest (855.831ms)
     Error: build artifact verification failed: assets/index-Lw_UK5FK.js
         at checkDistribution (.../web/scripts/licenses.mjs:218:106)
         at TestContext.<anonymous> (.../web/scripts/licenses.test.mjs:130:3)
   ℹ tests 5
   ℹ pass 2
   ℹ fail 3
   ```
   
   The same defect through the real pipeline, on the unmodified tree:
   
   ```sh
   $ cd web && npm run build
   > tsc -b && vite build && npm run license:check
   ✓ built in 39.06s
   > [email protected] license:check
   > node scripts/licenses.mjs check
   license gate: build artifact verification failed: assets/index-Cla9ejFP.js
   ```
   
   After the fix:
   
   ```sh
   $ cd web && node --test scripts/licenses.test.mjs
   ✔ lateEntryRewriteStillPassesTheGateTest (946.2772ms)
   ℹ tests 5
   ℹ pass 3
   ℹ fail 2
   
   $ cd web && npm run build
   ✓ built in 31.89s
   > [email protected] license:check
   > node scripts/licenses.mjs check
   web license check passed: 133 actual components, 140 license files
   ```
   
   `npx eslint scripts/licenses.mjs scripts/licenses.test.mjs` exits 0.
   
   Note for the reviewer: `vendoredSvgAndRuntimeOnlyTest` and 
`vitePackagingAndTamperGateTest` fail on
   this Windows checkout only. The first one because `collectLicenses` splits 
the base license on the
   literal `"\nThird-party source materials\n"`, which never matches a CRLF 
working tree, so the
   appended vendored-icon section stays in the generated `LICENSE`; the second 
one because its fixture
   imports absolute paths with backslashes, which Rollup rejects as a bad 
escape sequence. A pristine
   copy of `scripts/licenses.test.mjs` from the base commit reports `pass 2 / 
fail 2` with the same two
   names, so neither is related to this change; the real build, which is the 
gate this issue is about,
   passes.
   
   ### Checklist
   
   - [x] One coherent change; unrelated modifications are not bundled in
   - [x] Commit subject follows Conventional Commits
   - [x] Tests added or updated for non-trivial changes
   - [x] New UI text has both Chinese and English entries under `web/src/i18n/` 
— not applicable, no UI
     text is added or changed
   - [x] Architecture constraints stay green (`mvn test` runs the ArchUnit 
checks) — not applicable, no
     Java source is touched
   - [x] New source files carry the ASF license header — not applicable, no new 
file is added
   - [x] Documentation touched where behaviour changed (README / `docs/` / 
in-app help) — not
     applicable, the generated license manifest keeps its documented shape and 
contents
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to