Skip to content

Commit a47ad19

Browse files
committed
add event emitter support in docs
1 parent ae43c99 commit a47ad19

File tree

3 files changed

+71
-27
lines changed

3 files changed

+71
-27
lines changed

packages/docs/docusaurus.config.js

+19-15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import dotenv from "dotenv";
33

44
dotenv.config();
55

6+
// Import the EventEmitter polyfill
7+
require("./src/polyfills/eventEmitter.js");
8+
69
const config = {
710
title: "eliza",
811
tagline: "Flexible, scalable AI agents for everyone",
@@ -15,7 +18,16 @@ const config = {
1518
trailingSlash: true,
1619
onBrokenLinks: "ignore",
1720
onBrokenMarkdownLinks: "warn",
18-
21+
customFields: {
22+
// This is a workaround for the EventEmitter issue in the docs build
23+
EventEmitter: class EventEmitter {
24+
constructor() {}
25+
on() {}
26+
once() {}
27+
emit() {}
28+
removeListener() {}
29+
},
30+
},
1931
i18n: {
2032
defaultLocale: "en",
2133
locales: ["en"],
@@ -24,6 +36,7 @@ const config = {
2436
mermaid: true,
2537
},
2638
themes: ["@docusaurus/theme-mermaid"],
39+
clientModules: [require.resolve("./src/polyfills/eventEmitter.js")],
2740
plugins: [
2841
[
2942
"@docusaurus/plugin-content-docs",
@@ -88,19 +101,11 @@ const config = {
88101
readme: "none",
89102
commentStyle: "all",
90103
preserveAnchorCasing: false,
91-
hideBreadcrumbs: false,
92-
publicPath: "/api/",
93-
treatWarningsAsErrors: false,
94-
treatValidationWarningsAsErrors: false,
95-
searchInComments: true,
96-
disableGit: false,
97-
validation: {
98-
invalidLink: true,
99-
notDocumented: false,
100-
},
101-
navigationLinks: {
102-
GitHub: "https://github.com/elizaos/eliza",
103-
Documentation: "/docs/intro",
104+
externalSymbolLinkMappings: {
105+
"node:events": {
106+
EventEmitter:
107+
"https://nodejs.org/api/events.html#class-eventemitter",
108+
},
104109
},
105110
},
106111
],
@@ -113,7 +118,6 @@ const config = {
113118
routeBasePath: "api",
114119
},
115120
],
116-
require.resolve("./plugin/event-emitter-polyfill"),
117121
],
118122
presets: [
119123
[

packages/docs/package.json

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elizaos/docs",
3-
"version": "1.0.0-alpha.1",
3+
"version": "1.0.0-alpha.0",
44
"private": true,
55
"packageManager": "bun@9.4.0",
66
"scripts": {
@@ -21,30 +21,23 @@
2121
"@docusaurus/plugin-content-docs": "3.7.0",
2222
"@docusaurus/plugin-ideal-image": "3.7.0",
2323
"@docusaurus/preset-classic": "3.7.0",
24-
"@docusaurus/theme-common": "3.7.0",
2524
"@docusaurus/theme-mermaid": "3.7.0",
25+
"@docusaurus/theme-common": "3.7.0",
2626
"@mdx-js/react": "3.0.1",
2727
"clsx": "2.1.1",
2828
"docusaurus-lunr-search": "3.5.0",
29-
"dotenv": "^16.4.7",
3029
"lunr": "2.3.9",
30+
"dotenv": "^16.4.7",
3131
"prism-react-renderer": "2.3.1",
3232
"react": "^19.0.0",
3333
"react-dom": "^19.0.0"
3434
},
3535
"devDependencies": {
3636
"@docusaurus/module-type-aliases": "3.7.0",
37-
"@docusaurus/remark-plugin-npm2yarn": "^3.7.0",
3837
"@docusaurus/types": "3.7.0",
39-
"@types/node": "^22.13.9",
40-
"assert": "^2.1.0",
41-
"docusaurus-plugin-typedoc": "1.2.2",
42-
"events": "^3.3.0",
43-
"path-browserify": "^1.0.1",
44-
"stream-browserify": "^3.0.0",
38+
"docusaurus-plugin-typedoc": "1.0.5",
4539
"typedoc": "0.26.11",
46-
"typedoc-plugin-markdown": "4.2.10",
47-
"util": "^0.12.5"
40+
"typedoc-plugin-markdown": "4.2.10"
4841
},
4942
"browserslist": {
5043
"production": [">0.5%", "not dead", "not op_mini all"],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Simple EventEmitter polyfill for documentation
3+
*/
4+
if (typeof global !== "undefined" && !global.EventEmitter) {
5+
global.EventEmitter = class EventEmitter {
6+
constructor() {
7+
this.events = {};
8+
}
9+
10+
on(event, listener) {
11+
if (!this.events[event]) {
12+
this.events[event] = [];
13+
}
14+
this.events[event].push(listener);
15+
return this;
16+
}
17+
18+
once(event, listener) {
19+
const onceWrapper = (...args) => {
20+
listener(...args);
21+
this.removeListener(event, onceWrapper);
22+
};
23+
return this.on(event, onceWrapper);
24+
}
25+
26+
emit(event, ...args) {
27+
if (!this.events[event]) {
28+
return false;
29+
}
30+
this.events[event].forEach((listener) => listener(...args));
31+
return true;
32+
}
33+
34+
removeListener(event, listener) {
35+
if (!this.events[event]) {
36+
return this;
37+
}
38+
this.events[event] = this.events[event].filter((l) => l !== listener);
39+
return this;
40+
}
41+
};
42+
}
43+
44+
// Also add to window for client-side rendering
45+
if (typeof window !== "undefined" && !window.EventEmitter) {
46+
window.EventEmitter = global.EventEmitter;
47+
}

0 commit comments

Comments
 (0)