Skip to content

refactor: make rslint compatible with browser#303

Merged
hardfist merged 5 commits intomainfrom
yj/refactor-service
Aug 26, 2025
Merged

refactor: make rslint compatible with browser#303
hardfist merged 5 commits intomainfrom
yj/refactor-service

Conversation

@hardfist
Copy link
Copy Markdown
Contributor

make service compatible with web worker and prepare for browser support

Copilot AI review requested due to automatic review settings August 26, 2025 03:39
@netlify
Copy link
Copy Markdown

netlify bot commented Aug 26, 2025

Deploy Preview for rslint canceled.

Name Link
🔨 Latest commit e84f0d1
🔍 Latest deploy log https://app.netlify.com/projects/rslint/deploys/68ad305445a26400085f4461

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the rslint service to support browser environments by abstracting the service implementation behind a common interface. The changes enable rslint to run in both Node.js (using child processes) and browser environments (using web workers), preparing the codebase for cross-platform compatibility.

Key changes:

  • Split the monolithic service into environment-specific implementations (Node.js and browser)
  • Introduced a factory pattern to automatically select the appropriate service implementation
  • Created shared type definitions for IPC protocol consistency across environments

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/rslint/src/worker.ts New web worker implementation for browser environment with simulated rslint process communication
packages/rslint/src/types.ts Extracted shared type definitions for IPC protocol and service interfaces
packages/rslint/src/service.ts Refactored main service to use factory pattern and delegate to environment-specific implementations
packages/rslint/src/node.ts Extracted Node.js-specific service implementation using child processes
packages/rslint/src/index.ts Updated exports to include new service implementations and types
packages/rslint/src/browser.ts New browser service implementation using web workers
packages/rslint/package.json Updated package exports to support browser field and worker entry point

Comment on lines +125 to +133
for (const [id, pending] of pendingMessages) {
self.postMessage({
id,
kind: 'error',
data: {
message: `Worker error: ${error.message}`,
},
});
}
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

The pendingMessages variable is declared globally but never populated in this worker implementation. The error handling loop will never execute because the Map is always empty.

Copilot uses AI. Check for mistakes.

// Handle the message
try {
const parsed: IpcMessage = JSON.parse(message);
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

JSON.parse() is called without validation on data received from an external process. Consider adding schema validation to ensure the parsed data conforms to the IpcMessage interface.

Copilot uses AI. Check for mistakes.
/**
* Handle messages from the worker
*/
private handleWorkerMessage(message: IpcMessage): void {
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

The worker message handler doesn't validate that the incoming message conforms to the IpcMessage interface. Consider adding runtime validation for messages received from the worker.

Suggested change
private handleWorkerMessage(message: IpcMessage): void {
private handleWorkerMessage(message: any): void {
if (!isIpcMessage(message)) {
console.error('Received invalid message from worker:', message);
return;
}

Copilot uses AI. Check for mistakes.
@hardfist hardfist merged commit 2795b0a into main Aug 26, 2025
12 checks passed
@hardfist hardfist deleted the yj/refactor-service branch August 26, 2025 04:04
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