From 631705388d6ee0a3880ea3d128ffc7e2dd2da022 Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Thu, 12 Dec 2024 10:13:33 -0600 Subject: [PATCH] Fixes #3585 --- src/TemplateContent.js | 9 +++------ src/TemplateMap.js | 9 +++++---- src/UserConfig.js | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/TemplateContent.js b/src/TemplateContent.js index a2077ed38..4c066ebae 100644 --- a/src/TemplateContent.js +++ b/src/TemplateContent.js @@ -19,7 +19,6 @@ 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 {} @@ -27,9 +26,7 @@ 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; @@ -96,7 +93,7 @@ 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."); } } @@ -104,7 +101,7 @@ class TemplateContent { 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() { diff --git a/src/TemplateMap.js b/src/TemplateMap.js index c77d2c3fe..305147717 100644 --- a/src/TemplateMap.js +++ b/src/TemplateMap.js @@ -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"; @@ -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 = []; @@ -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) { diff --git a/src/UserConfig.js b/src/UserConfig.js index 84e744336..39e45d782 100644 --- a/src/UserConfig.js +++ b/src/UserConfig.js @@ -1,3 +1,4 @@ +import os from "node:os"; import chalk from "kleur"; import { DateTime } from "luxon"; import yaml from "js-yaml"; @@ -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 @@ -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 @@ -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)