Skip to content

Commit 94ca128

Browse files
committed
Fixes #3874
1 parent 8053d2c commit 94ca128

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

src/Eleventy.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,11 @@ class Eleventy {
279279
debug("Eleventy warm up time: %o (ms)", performance.now());
280280
}
281281

282-
// We must destroy the previous one (if it exists) or the process will hang on SIGINT, issue #3873
283-
if (this.eleventyServe) {
284-
await this.eleventyServe.close();
282+
// Careful to make sure the previous server closes on SIGINT, issue #3873
283+
if (!this.eleventyServe) {
284+
/** @type {object} */
285+
this.eleventyServe = new EleventyServe();
285286
}
286-
287-
/** @type {object} */
288-
this.eleventyServe = new EleventyServe();
289287
this.eleventyServe.eleventyConfig = this.eleventyConfig;
290288

291289
/** @type {object} */

src/EleventyServe.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const DEFAULT_SERVER_OPTIONS = {
2525
};
2626

2727
class EleventyServe {
28+
#eleventyConfig;
29+
2830
constructor() {
2931
this.logger = new ConsoleLogger();
3032
this._initOptionsFetched = false;
@@ -55,19 +57,20 @@ class EleventyServe {
5557
}
5658

5759
get eleventyConfig() {
58-
if (!this._eleventyConfig) {
60+
if (!this.#eleventyConfig) {
5961
throw new EleventyServeConfigError(
6062
"You need to set the eleventyConfig property on EleventyServe.",
6163
);
6264
}
6365

64-
return this._eleventyConfig;
66+
return this.#eleventyConfig;
6567
}
6668

6769
set eleventyConfig(config) {
68-
this._eleventyConfig = config;
69-
if (checkPassthroughCopyBehavior(this._eleventyConfig.userConfig, "serve")) {
70-
this._eleventyConfig.userConfig.events.on("eleventy.passthrough", ({ map }) => {
70+
this.#eleventyConfig = config;
71+
72+
if (checkPassthroughCopyBehavior(this.#eleventyConfig.userConfig, "serve")) {
73+
this.#eleventyConfig.userConfig.events.on("eleventy.passthrough", ({ map }) => {
7174
// for-free passthrough copy
7275
this.setAliases(map);
7376
});
@@ -84,7 +87,7 @@ class EleventyServe {
8487
async getServerModule(name) {
8588
try {
8689
if (!name || name === DEFAULT_SERVER_OPTIONS.module) {
87-
return import("@11ty/eleventy-dev-server").then(i=>i.default)
90+
return import("@11ty/eleventy-dev-server").then((i) => i.default);
8891
}
8992

9093
// Look for peer dep in local project
@@ -134,7 +137,7 @@ class EleventyServe {
134137
e.message,
135138
);
136139
debug("Eleventy server error %o", e);
137-
return import("@11ty/eleventy-dev-server").then(i=>i.default)
140+
return import("@11ty/eleventy-dev-server").then((i) => i.default);
138141
}
139142
}
140143

0 commit comments

Comments
 (0)