Skip to content

Commit

Permalink
fix!: update package name to browser-web-worker to resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
rwv committed Nov 12, 2024
1 parent 25ce3b4 commit fef9be5
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Browser Worker
# Browser Web Worker

[![Build](https://github.com/rwv/browser-worker/actions/workflows/build.yml/badge.svg)](https://github.com/rwv/browser-worker/actions/workflows/build.yml)
[![Build](https://github.com/rwv/browser-web-worker/actions/workflows/build.yml/badge.svg)](https://github.com/rwv/browser-web-worker/actions/workflows/build.yml)

Run Web Workers in Node.js using a real Chrome browser via Puppeteer.

Expand All @@ -16,15 +16,15 @@ Run Web Workers in Node.js using a real Chrome browser via Puppeteer.
## Installation

```bash
pnpm add browser-worker puppeteer
pnpm add browser-web-worker puppeteer
```

## Usage

### Basic Example

```typescript
import { createWorkerFromString } from "browser-worker";
import { createWorkerFromString } from "browser-web-worker";
import puppeteer from "puppeteer";

// Launch browser
Expand Down Expand Up @@ -57,7 +57,7 @@ import {
createWorkerFromString,
createWorkerFromFile,
createWorkerFromURL,
} from "browser-worker";
} from "browser-web-worker";

// 1. From a string
const worker1 = await createWorkerFromString(workerScript, page);
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "browser-worker",
"name": "browser-web-worker",
"version": "1.0.0",
"description": "Run Web Workers in Node.js using a real Chrome browser via Puppeteer",
"main": "lib/index.js",
Expand Down Expand Up @@ -27,10 +27,10 @@
],
"author": "rwv",
"license": "MIT",
"repository": "https://github.com/rwv/browser-worker",
"homepage": "https://github.com/rwv/browser-worker",
"repository": "https://github.com/rwv/browser-web-worker",
"homepage": "https://github.com/rwv/browser-web-worker",
"bugs": {
"url": "https://github.com/rwv/browser-worker/issues"
"url": "https://github.com/rwv/browser-web-worker/issues"
},
"packageManager": "pnpm@9.12.3+sha512.cce0f9de9c5a7c95bef944169cc5dfe8741abfb145078c0d508b868056848a87c81e626246cb60967cbd7fd29a6c062ef73ff840d96b3c86c40ac92cf4a813ee",
"files": [
Expand Down
16 changes: 8 additions & 8 deletions src/browser-worker.test.ts → src/browser-web-worker.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, expect, vi, beforeAll } from "vitest";
import puppeteer, { Page, Browser } from "puppeteer";
import { createWorkerURLFromString } from "./utils";
import { BrowserWorker } from "./browser-worker";
import { BrowserWebWorker } from "./browser-web-worker";

const testWorkerString = `
self.addEventListener('message', (event) => {
Expand All @@ -10,7 +10,7 @@ self.addEventListener('message', (event) => {
});
`;

describe("BrowserWorker", async () => {
describe("BrowserWebWorker", async () => {
let browser: Browser;
let page: Page;
let workerScriptURL: string;
Expand All @@ -26,14 +26,14 @@ describe("BrowserWorker", async () => {
});

it("should create a worker from string", async () => {
const worker = new BrowserWorker({ workerScriptURL, page });
const worker = new BrowserWebWorker({ workerScriptURL, page });
await worker.initPromise;
expect(worker).toBeDefined();
expect(worker.postMessage).toBeDefined();
});

it("should handle message communication", async () => {
const worker = new BrowserWorker({ workerScriptURL, page });
const worker = new BrowserWebWorker({ workerScriptURL, page });
await worker.initPromise;

const messagePromise = new Promise<MessageEvent>((resolve) => {
Expand All @@ -50,7 +50,7 @@ describe("BrowserWorker", async () => {
});

it("should handle addEventListener for messages", async () => {
const worker = new BrowserWorker({ workerScriptURL, page });
const worker = new BrowserWebWorker({ workerScriptURL, page });
await worker.initPromise;

const messagePromise = new Promise<MessageEvent>((resolve) => {
Expand All @@ -67,7 +67,7 @@ describe("BrowserWorker", async () => {
});

it("should handle removeEventListener", async () => {
const worker = new BrowserWorker({ workerScriptURL, page });
const worker = new BrowserWebWorker({ workerScriptURL, page });
await worker.initPromise;

const listener = vi.fn();
Expand All @@ -83,7 +83,7 @@ describe("BrowserWorker", async () => {
});

it("should handle multiple event listeners", async () => {
const worker = new BrowserWorker({ workerScriptURL, page });
const worker = new BrowserWebWorker({ workerScriptURL, page });
await worker.initPromise;

const listener1 = vi.fn();
Expand Down Expand Up @@ -114,7 +114,7 @@ describe("BrowserWorker", async () => {
page,
);

const worker = new BrowserWorker({
const worker = new BrowserWebWorker({
workerScriptURL: invalidScriptURL,
page,
});
Expand Down
2 changes: 1 addition & 1 deletion src/browser-worker.ts → src/browser-web-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ declare global {
}
}

export class BrowserWorker implements Worker, EventTarget {
export class BrowserWebWorker implements Worker, EventTarget {
private readonly page: PuppeteerPage;
private readonly workerScriptURL: string;
private readonly eventListeners: Map<
Expand Down
2 changes: 1 addition & 1 deletion src/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("create worker", async () => {
});

it("should handle message communication using createWorkerFromFile", async () => {
const dir = await mkdtemp(path.join(tmpdir(), "browser-worker-test-"));
const dir = await mkdtemp(path.join(tmpdir(), "browser-web-worker-test-"));
const filePath = path.join(dir, `test-worker.js`);
await fs.writeFile(filePath, testWorkerString);
const worker = await createWorkerFromFile(filePath, page);
Expand Down
6 changes: 3 additions & 3 deletions src/create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Page as PuppeteerPage } from "puppeteer";
import { createWorkerURLFromString } from "./utils";
import { BrowserWorker } from "./browser-worker";
import { BrowserWebWorker } from "./browser-web-worker";
import fs from "fs/promises";

export async function createWorkerFromString(
Expand All @@ -12,7 +12,7 @@ export async function createWorkerFromString(
page,
);

const worker = new BrowserWorker({ workerScriptURL, page });
const worker = new BrowserWebWorker({ workerScriptURL, page });
await worker.initPromise;
return worker;
}
Expand All @@ -21,7 +21,7 @@ export async function createWorkerFromURL(
workerScriptURL: string,
page: PuppeteerPage,
) {
const worker = new BrowserWorker({ workerScriptURL, page });
const worker = new BrowserWebWorker({ workerScriptURL, page });
await worker.initPromise;
return worker;
}
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* v8 ignore start */
export { BrowserWorker as default } from "./browser-worker";
export { BrowserWebWorker as default } from "./browser-web-worker";

export { BrowserWorker } from "./browser-worker";
export { BrowserWebWorker } from "./browser-web-worker";
export {
createWorkerFromString,
createWorkerFromFile,
Expand Down

0 comments on commit fef9be5

Please sign in to comment.