Skip to content

Fix webpack-subresource-integrity v5 named export handling#978

Merged
justin808 merged 2 commits intomainfrom
jg-codex/issue-972-sri-plugin-export
Mar 16, 2026
Merged

Fix webpack-subresource-integrity v5 named export handling#978
justin808 merged 2 commits intomainfrom
jg-codex/issue-972-sri-plugin-export

Conversation

@justin808
Copy link
Copy Markdown
Member

@justin808 justin808 commented Mar 15, 2026

Summary

  • support both export styles from webpack-subresource-integrity in webpack plugins:
    • default export constructor (older versions)
    • named SubresourceIntegrityPlugin export (v5.1+)
  • keep runtime behavior unchanged for existing setups
  • add regression tests covering both module shapes

Testing

  • yarn test test/package/plugins/webpackSubresourceIntegrity.test.js --runInBand
  • yarn lint
  • yarn prettier --check package/plugins/webpack.ts test/package/plugins/webpackSubresourceIntegrity.test.js

Closes #972.


Note

Low Risk
Low risk: small compatibility tweak to plugin loading plus focused unit tests; behavior should be unchanged except preventing runtime breakage with newer webpack-subresource-integrity exports.

Overview
Updates the webpack plugin setup to support both webpack-subresource-integrity module shapes by using the named SubresourceIntegrityPlugin export when present and falling back to the default export.

Adds regression tests that mock each export style to ensure the plugin is instantiated with the expected SRI options.

Written by Cursor Bugbot for commit 0a5972f. Configure here.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 15, 2026

Warning

Rate limit exceeded

@justin808 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 10 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2b4eac71-4c9f-4b70-974f-372f902824bd

📥 Commits

Reviewing files that changed from the base of the PR and between b259a0e and a6b4bbb.

📒 Files selected for processing (2)
  • package/plugins/webpack.ts
  • test/package/plugins/webpackSubresourceIntegrity.test.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jg-codex/issue-972-sri-plugin-export
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 15, 2026

Greptile Summary

This PR fixes compatibility with webpack-subresource-integrity v5+ which changed from a default export to a named SubresourceIntegrityPlugin export. The fix uses the same "PropertyName" in module detection pattern already established in this codebase for WebpackAssetsManifest, keeping the approach consistent.

  • Adds runtime detection in package/plugins/webpack.ts to handle both default export (v1.x) and named export (v5+) from webpack-subresource-integrity
  • Adds regression tests covering both module export shapes using jest.isolateModules for proper isolation
  • No behavioral changes for existing setups; the plugin constructor invocation and options remain identical

Confidence Score: 5/5

  • This PR is safe to merge — it's a small, well-tested compatibility fix following an established pattern in the codebase.
  • The change is minimal (5 lines of production code), follows the identical pattern already used for WebpackAssetsManifest in the same file, includes comprehensive regression tests covering both code paths, and has no risk of breaking existing setups since the fallback preserves the original behavior.
  • No files require special attention.

Important Files Changed

Filename Overview
package/plugins/webpack.ts Adds runtime detection of webpack-subresource-integrity v5 named export vs older default export, following the same in operator pattern already used for WebpackAssetsManifest. Minor version inaccuracy in comment (says >=5.1, should be v5+).
test/package/plugins/webpackSubresourceIntegrity.test.js New regression tests covering both module export shapes (named export for v5+ and default export for v1.x). Uses jest.isolateModules for proper module isolation. Correctly mocks all dependencies including top-level requires.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["require('webpack-subresource-integrity')"] --> B{"'SubresourceIntegrityPlugin' in module?"}
    B -->|Yes v5+| C["Use module.SubresourceIntegrityPlugin"]
    B -->|No v1.x| D["Use module directly as constructor"]
    C --> E["new SubresourceIntegrityPlugin(options)"]
    D --> E
    E --> F["Push to plugins array"]
Loading

Last reviewed commit: 0a5972f

Comment thread package/plugins/webpack.ts Outdated
Comment thread package/plugins/webpack.ts Outdated
Comment thread test/package/plugins/webpackSubresourceIntegrity.test.js
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Mar 15, 2026

Review

The fix is correct and well-structured. Using "SubresourceIntegrityPlugin" in subresourceIntegrityModule mirrors the existing WebpackAssetsManifest pattern (lines 17–21) exactly, which is the right approach for consistency.

Two minor observations (see inline comments):

  1. Version in comment — the >=5.1 annotation looks inaccurate; the named export landed in v5.0.0. Either drop the version or cite the exact one.
  2. Redundant jest.resetModules()jest.isolateModules() already gives each test an isolated registry, so the resetModules() call in afterEach is a no-op. Only clearAllMocks() is needed there.

Otherwise this looks good to merge.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Mar 15, 2026

Review (follow-up)

The current state of this PR looks good. The implementation is correct and the tests are clean.

Verified:

  • The named-export detection uses the in operator, which works correctly on both plain objects and functions (functions are objects in JS), covering both the v5.1+ named-export shape and the older default-export shape.
  • The pattern mirrors the existing WebpackAssetsManifest handling in the same file (lines 18–21), keeping things consistent.
  • afterEach only calls jest.clearAllMocks() — no redundant resetModules() call.
  • Tests properly exercise both code paths via jest.isolateModules.

One remaining minor nit (non-blocking):
The inline comment says v5+ while the PR description says v5.1+. Worth pinning to the exact version where the named export was introduced so future readers can verify the changelog. Either way it doesn't affect correctness.

Ready to merge.

@justin808 justin808 merged commit 5d55b9a into main Mar 16, 2026
63 checks passed
@justin808 justin808 deleted the jg-codex/issue-972-sri-plugin-export branch March 16, 2026 04:48
justin808 added a commit that referenced this pull request Mar 17, 2026
Promote v9.7.0-rc.0 to v9.7.0 stable and add missing PR #978
(webpack-subresource-integrity v5 named export fix).

Co-Authored-By: Claude Opus 4.6 <[email protected]>
justin808 added a commit that referenced this pull request Mar 17, 2026
### Summary

Adds the v9.7.0 changelog section with release notes for all
user-visible changes since v9.6.1:

- **Added**: rspack v2 support (PR #975)
- **Fixed**: Config exporter path traversal and annotation format
validation (PR #914)
- **Fixed**: `webpack-subresource-integrity` v5 named export handling
(PR #978, fixes #972)

Version diff links at the bottom of the file are updated accordingly.

### Pull Request checklist

- [x] ~Add/update test to cover these changes~
- [x] ~Update documentation~
- [x] Update CHANGELOG file

### Other Information

Non-user-visible PRs (#920, #965, #970, #971, #977, #979, #981, #982)
were intentionally excluded per changelog policy.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Documentation-only change updating `CHANGELOG.md`; no runtime code or
dependency changes are introduced in this PR.
> 
> **Overview**
> Adds a new `v9.7.0` section to `CHANGELOG.md` documenting user-visible
changes (rspack v2 support and two fixes around config export
security/validation and `webpack-subresource-integrity` v5 exports).
> 
> Updates the compare links at the bottom so `[Unreleased]` now compares
from `v9.7.0`, and adds the new `[v9.7.0]` tag link.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
8942a43. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
  * Added rspack v2 support

* **Bug Fixes**
  * Improved security and validation handling

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
justin808 added a commit that referenced this pull request Mar 18, 2026
## Summary
- support both export styles from `webpack-subresource-integrity` in
webpack plugins:
  - default export constructor (older versions)
  - named `SubresourceIntegrityPlugin` export (v5.1+)
- keep runtime behavior unchanged for existing setups
- add regression tests covering both module shapes

## Testing
- `yarn test test/package/plugins/webpackSubresourceIntegrity.test.js
--runInBand`
- `yarn lint`
- `yarn prettier --check package/plugins/webpack.ts
test/package/plugins/webpackSubresourceIntegrity.test.js`

Closes #972.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Low risk: small compatibility tweak to plugin loading plus focused
unit tests; behavior should be unchanged except preventing runtime
breakage with newer `webpack-subresource-integrity` exports.
> 
> **Overview**
> Updates the webpack plugin setup to support both
`webpack-subresource-integrity` module shapes by using the named
`SubresourceIntegrityPlugin` export when present and falling back to the
default export.
> 
> Adds regression tests that mock each export style to ensure the plugin
is instantiated with the expected SRI options.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
0a5972f. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
justin808 added a commit that referenced this pull request Mar 18, 2026
### Summary

Adds the v9.7.0 changelog section with release notes for all
user-visible changes since v9.6.1:

- **Added**: rspack v2 support (PR #975)
- **Fixed**: Config exporter path traversal and annotation format
validation (PR #914)
- **Fixed**: `webpack-subresource-integrity` v5 named export handling
(PR #978, fixes #972)

Version diff links at the bottom of the file are updated accordingly.

### Pull Request checklist

- [x] ~Add/update test to cover these changes~
- [x] ~Update documentation~
- [x] Update CHANGELOG file

### Other Information

Non-user-visible PRs (#920, #965, #970, #971, #977, #979, #981, #982)
were intentionally excluded per changelog policy.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Documentation-only change updating `CHANGELOG.md`; no runtime code or
dependency changes are introduced in this PR.
> 
> **Overview**
> Adds a new `v9.7.0` section to `CHANGELOG.md` documenting user-visible
changes (rspack v2 support and two fixes around config export
security/validation and `webpack-subresource-integrity` v5 exports).
> 
> Updates the compare links at the bottom so `[Unreleased]` now compares
from `v9.7.0`, and adds the new `[v9.7.0]` tag link.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
8942a43. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
  * Added rspack v2 support

* **Bug Fixes**
  * Improved security and validation handling

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
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-subresource-integrity v5.2 incompatibility

1 participant