Skip to content

Commit

Permalink
Fixes #3585
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Dec 12, 2024
1 parent 7bd5295 commit 6317053
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
9 changes: 3 additions & 6 deletions src/TemplateContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ const { set: lodashSet } = lodash;
const debug = debugUtil("Eleventy:TemplateContent");
const debugDev = debugUtil("Dev:Eleventy:TemplateContent");

class TemplateContentConfigError extends EleventyBaseError {}
class TemplateContentFrontMatterError extends EleventyBaseError {}
class TemplateContentCompileError extends EleventyBaseError {}
class TemplateContentRenderError extends EleventyBaseError {}

class TemplateContent {
constructor(inputPath, templateConfig) {
if (!templateConfig || templateConfig.constructor.name !== "TemplateConfig") {
throw new TemplateContentConfigError(
"Missing or invalid `templateConfig` argument to TemplateContent",
);
throw new Error("Missing or invalid `templateConfig` argument");
}
this.eleventyConfig = templateConfig;
this.inputPath = inputPath;
Expand Down Expand Up @@ -96,15 +93,15 @@ class TemplateContent {
if (this._config.constructor.name === "TemplateConfig") {
this._configOptions = this._config.getConfig();
} else {
throw new TemplateContentConfigError("Tried to get an TemplateConfig but none was found.");
throw new Error("Tried to get an TemplateConfig but none was found.");
}
}

get eleventyConfig() {
if (this._config.constructor.name === "TemplateConfig") {
return this._config;
}
throw new TemplateContentConfigError("Tried to get an TemplateConfig but none was found.");
throw new Error("Tried to get an TemplateConfig but none was found.");
}

get config() {
Expand Down
9 changes: 5 additions & 4 deletions src/TemplateMap.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DepGraph as DependencyGraph } from "dependency-graph";
import { isPlainObject, TemplatePath } from "@11ty/eleventy-utils";
import debugUtil from "debug";
import os from "node:os";
import pMap from "p-map";

import TemplateCollection from "./TemplateCollection.js";
Expand All @@ -26,8 +25,8 @@ const EXTENSIONLESS_URL_ALLOWLIST = [

class TemplateMap {
constructor(eleventyConfig) {
if (!eleventyConfig) {
throw new Error("Missing config argument.");
if (!eleventyConfig || eleventyConfig.constructor.name !== "TemplateConfig") {
throw new Error("Missing or invalid `eleventyConfig` argument.");
}
this.eleventyConfig = eleventyConfig;
this.map = [];
Expand Down Expand Up @@ -569,7 +568,9 @@ class TemplateMap {
}
debugDev("Added this.map[...].templateContent, outputPath, et al for one map entry");
},
{ concurrency: os.availableParallelism() },
{
concurrency: this.userConfig.getConcurrency(),
},
);

for (let map of usedTemplateContentTooEarlyMap) {
Expand Down
17 changes: 17 additions & 0 deletions src/UserConfig.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os from "node:os";
import chalk from "kleur";
import { DateTime } from "luxon";
import yaml from "js-yaml";
Expand Down Expand Up @@ -36,6 +37,8 @@ class UserConfig {
#dataDeepMergeModified = false;
/** @type {number|undefined} */
#uniqueId;
/** @type {number} */
#concurrency = os.availableParallelism();

constructor() {
// These are completely unnecessary lines to satisfy TypeScript
Expand Down Expand Up @@ -238,6 +241,8 @@ class UserConfig {
this.errorReporting = {};
/** @type {object} */
this.templateHandling = {};

this.#concurrency = os.availableParallelism();
}

// compatibleRange is optional in 2.0.0-beta.2
Expand Down Expand Up @@ -1223,6 +1228,18 @@ class UserConfig {
return augmentFunction(fn, options);
}

setConcurrency(number) {
if (typeof number !== "number") {
throw new UserConfigError("Argument passed to `setConcurrency` must be a number.");
}

this.#concurrency = number;
}

getConcurrency() {
return this.#concurrency;
}

getMergingConfigObject() {
let obj = {
// filters removed in 1.0 (use addTransform instead)
Expand Down

0 comments on commit 6317053

Please sign in to comment.