Skip to content

Commit

Permalink
Internal eleventy# events automatically reset on every build
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Dec 5, 2024
1 parent b5b85a4 commit 5d4069a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ class Eleventy {

if (!this.#hasConfigInitialized) {
await this.initializeConfig();
} else {
this.config.events.reset();
}

await this.config.events.emit("eleventy.config", this.eleventyConfig);
Expand Down
2 changes: 1 addition & 1 deletion src/EventBus.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ debug("Setting up global EventBus.");
* @type {module:11ty/eleventy/Util/AsyncEventEmitter~AsyncEventEmitter}
*/
let bus = new EventEmitter();
bus.setMaxListeners(100);
bus.setMaxListeners(100); // defaults to 10

debug("EventBus max listener count: %o", bus.getMaxListeners());

Expand Down
9 changes: 9 additions & 0 deletions src/Util/AsyncEventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ class AsyncEventEmitter extends EventEmitter {
super(...args);
}

reset() {
// `eleventy#` event type listeners are removed at the start of each build (singletons)
for (let type of this.eventNames()) {
if (typeof type === "string" && type.startsWith("eleventy#")) {
this.removeAllListeners(type);
}
}
}

/**
* @param {string} type - The event name to emit.
* @param {...*} args - Additional arguments that get passed to listeners.
Expand Down

0 comments on commit 5d4069a

Please sign in to comment.