Skip to content

fix(worker): preserve regexp options for process workers - #749

Merged
alexander-akait merged 4 commits into
mainfrom
fix/regexp-child-process-worker
Oct 2, 2026
Merged

alexander-akait merged 4 commits into
mainfrom
fix/regexp-child-process-worker

Conversation

@xiaoxiaojx

@xiaoxiaojx xiaoxiaojx commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Fallback to the serialized worker path when regular expression options are used with process workers that cannot preserve them. This keeps module-path minification on worker threads while fixing Node 10 CSS comment options.\n\nTests: implementation and parallel option suites (61 tests).

Summary by CodeRabbit

  • Bug Fixes
    • Regular-expression options are now handled correctly during minification, with a compatible fallback when process workers cannot preserve them.
    • Worker-thread availability is detected automatically. When threads are unavailable or unsuitable for the configured options, minification uses an alternative processing path, helping ensure configured options are applied correctly.

@changeset-bot

changeset-bot Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c8c8df5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
minimizer-webpack-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.29412% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.64%. Comparing base (0039e4c) to head (c8c8df5).

Files with missing lines Patch % Lines
src/implementation.js 78.26% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #749      +/-   ##
==========================================
- Coverage   97.89%   97.64%   -0.26%     
==========================================
  Files           5        5              
  Lines        1665     1697      +32     
  Branches      640      652      +12     
==========================================
+ Hits         1630     1657      +27     
- Misses         35       39       +4     
- Partials        0        1       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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

Walkthrough

The plugin detects whether Node worker threads can be required and combines that result with minimizer capability settings. When worker threads are disabled, canMinifyByPath checks minimizer and embedded options for regular expressions before allowing path-based minification. Tests cover regular-expression options with worker threads enabled and disabled. A changeset describes the serialized-worker fallback.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to c8c8d

The fallback currently preserves regular-expression options, but coverage does not directly protect the embedded-options case or force fallback dispatch on worker_threads-capable CI runtimes. These are bounded test-confidence risks; the PR is mergeable with follow-up awareness.

Security Architecture Review

Security architecture risk: 🔵 Low · up to c8c8d

The change affects worker selection rather than introducing a new external entrypoint or demonstrated privilege increase. No security finding is established, but worker execution across all runtime configurations has not been fully verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The evidenced effect is confined to worker handling of configured minification options; no new externally callable production entrypoint is established.

Trust Boundaries and Controls

  • observed — Worker routing depends on both configuration and runtime thread availability, while the capability check still rejects options containing functions from path-based minification.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving regular-expression options for process workers.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 5 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

test/parallel-option.test.js

Oops! Something went wrong! :(

ESLint: 10.10.0

Error: Error while loading rule 'jest/no-deprecated-functions': Unable to detect Jest version - please ensure jest package is installed, or otherwise set version explicitly
Occurred while linting /test/parallel-option.test.js
at detectJestVersion (/.eslint-tmp/node_modules/eslint-plugin-jest/lib/rules/utils/detectJestVersion.js:22:9)
at create (/.eslint-tmp/node_modules/eslint-plugin-jest/lib/rules/no-deprecated-functions.js:31:107)
at Object.create (/.eslint-tmp/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:39:20)
at createRuleListeners (/.eslint-tmp/node_modules/eslint/lib/linter/linter.js:497:15)
at /.eslint-tmp/node_modules/eslint/lib/linter/linter.js:623:7
at Array.forEach ()
at runRules (/.eslint-tmp/node_modules/eslint/lib/linter/linter.js:557:31)
at #flatVerifyWithoutProcessors (/.eslint-tmp/node_modules/eslint/lib/linter/linter.js:1264:4)
at Linter._verifyWithFlatConfigArrayAndWithoutProcessors (/.eslint-tmp/node_modules/eslint/lib/linter/linter.js:1349:43)
at Linter._verifyWithFlatConfigArray (/.eslint-tmp/node_modules/eslint/lib/linter/linter.js:1416:15)


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
test/parallel-option.test.js (1)

248-248: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the unavailable-worker path on modern Node versions.

The guard skips the assertions whenever worker_threads loads. CI uses Node 12–24, where this module is available, so this test does not exercise the new plugin-level fallback on those runtimes. CI also pins Jest 27 or 29 for Node 10–16, so the Jest 30 premise does not apply to every supported runtime.

Load MinimizerPlugin in an isolated module after mocking worker_threads to throw. Keep the existing compile and workerTransform/workerMinify assertions.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 2969b16b-6795-4e0d-b36a-1534eaa2ec4a

📥 Commits

Reviewing files that changed from the base of the PR and between 0ab8b33 and 381e0c0.

📒 Files selected for processing (3)
  • src/index.js
  • test/parallel-option.test.js
  • types/implementation.d.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
test/implementation.test.js (1)

167-193: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Add coverage for RegExp values in embedded.options.

When worker threads are disabled, an embedded RegExp must make canMinifyByPath return false. Otherwise src/index.js selects worker.minify(options), whose process IPC serializer does not preserve regular expressions. The current tests cover only minimizer.options, so removing the embedded check would leave them passing.

Suggested fix
+  it("should reject an embedded RegExp option when the worker cannot transfer it", () => {
+    expect(
+      canMinifyByPath(
+        {
+          minimizer: { implementation: [pathImpl] },
+          embedded: {
+            implementation: pathImpl,
+            options: { comments: /license/i },
+            claims: [],
+            offers: [],
+            at: [0],
+          },
+        },
+        { enableWorkerThreads: false },
+      ),
+    ).toBe(false);
+  });
+

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: a1219ac1-fc53-40fb-8281-bb7642f6f17f

📥 Commits

Reviewing files that changed from the base of the PR and between 381e0c0 and c8c8df5.

📒 Files selected for processing (1)
  • test/parallel-option.test.js

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@alexander-akait
alexander-akait merged commit 7c7c64c into main Oct 2, 2026
29 of 31 checks passed
@alexander-akait
alexander-akait deleted the fix/regexp-child-process-worker branch October 2, 2026 12:55
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.

2 participants