Skip to content

Commit 3a7845e

Browse files
committed
fix: node:events import
1 parent 74898fe commit 3a7845e

File tree

5 files changed

+9
-11
lines changed

5 files changed

+9
-11
lines changed

packages/electron-chrome-extensions/spec/crx-helpers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as path from 'node:path'
22
import { app, BrowserWindow, session, webContents } from 'electron'
33
import { uuid } from './spec-helpers'
4-
import { ElectronChromeExtensions } from '../dist'
54

65
export const createCrxSession = () => {
76
const partitionName = `crx-${uuid()}`

packages/electron-chrome-extensions/spec/extensions-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai'
22
import { session } from 'electron'
3-
import { ElectronChromeExtensions } from '../dist'
3+
import { ElectronChromeExtensions } from '../'
44

55
describe('Extensions', () => {
66
const testSession = session.fromPartition('test-extensions')

packages/electron-chrome-extensions/spec/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ipcMain, BrowserWindow, app, Extension, webContents } from 'electron'
22
import * as http from 'http'
33
import * as path from 'node:path'
44
import { AddressInfo } from 'net'
5-
import { ElectronChromeExtensions } from '../dist'
5+
import { ElectronChromeExtensions } from '../'
66
import { emittedOnce } from './events-helpers'
77
import { addCrxPreload, createCrxSession, waitForBackgroundScriptEvaluated } from './crx-helpers'
88

packages/electron-chrome-extensions/src/browser-action.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import { ipcRenderer, contextBridge, webFrame } from 'electron'
44
* Injects `<browser-action>` custom element into the current webpage.
55
*/
66
export const injectBrowserAction = () => {
7-
// Load node:events directly from Electron rather than bundling
8-
const { EventEmitter } = require('node:events')
9-
107
const actionMap = new Map<string, any>()
11-
const internalEmitter = new EventEmitter()
128
const observerCounts = new Map<string, number>()
139

10+
// Reuse `process` to avoid bundling custom EventEmitter
11+
const internalEmitter = process as NodeJS.EventEmitter
12+
1413
const invoke = <T>(name: string, partition: string, ...args: any[]): Promise<T> => {
1514
return ipcRenderer.invoke('crx-msg-remote', partition, name, ...args)
1615
}
@@ -24,10 +23,10 @@ export const injectBrowserAction = () => {
2423

2524
const __browserAction__ = {
2625
addEventListener(name: string, listener: (...args: any[]) => void) {
27-
internalEmitter.addListener(name, listener)
26+
internalEmitter.addListener(`-actions-${name}`, listener)
2827
},
2928
removeEventListener(name: string, listener: (...args: any[]) => void) {
30-
internalEmitter.removeListener(name, listener)
29+
internalEmitter.removeListener(`-actions-${name}`, listener)
3130
},
3231

3332
getAction(extensionId: string) {
@@ -38,7 +37,7 @@ export const injectBrowserAction = () => {
3837
for (const action of state.actions) {
3938
actionMap.set(action.id, action)
4039
}
41-
queueMicrotask(() => internalEmitter.emit('update', state))
40+
queueMicrotask(() => internalEmitter.emit('-actions-update', state))
4241
return state
4342
},
4443

packages/electron-chrome-extensions/src/browser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class ElectronChromeExtensions extends EventEmitter {
8585
store,
8686
}
8787

88-
this.modulePath = modulePath || path.join(__dirname, '..')
88+
this.modulePath = modulePath || path.join(__dirname, '../..')
8989

9090
this.api = {
9191
browserAction: new BrowserActionAPI(this.ctx),

0 commit comments

Comments
 (0)