@11ty/client 4.0.0-alpha.10 → 4.0.0-alpha.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- /*! Eleventy (Build Awesome) v4.0.0-alpha.10 (@11ty/client/njk Engine Bundle) */
1
+ /*! Eleventy (Build Awesome) v4.0.0-alpha.12 (@11ty/client/njk Engine Bundle) */
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1115,18 +1115,30 @@ var require_TemplatePath = __commonJS({
1115
1115
  TemplatePath2.stripLeadingDotSlash = function(path2) {
1116
1116
  return typeof path2 === "string" ? path2.replace(/^\.\//, "") : path2;
1117
1117
  };
1118
+ function getSubPathRemainder(filePath, subPath) {
1119
+ if (filePath === subPath) {
1120
+ return "";
1121
+ }
1122
+ if (subPath === ".") {
1123
+ let isOutside = filePath === ".." || filePath.startsWith("../") || path.isAbsolute(filePath);
1124
+ return isOutside ? void 0 : filePath;
1125
+ }
1126
+ let prefix = subPath.endsWith("/") ? subPath : `${subPath}/`;
1127
+ return filePath.startsWith(prefix) ? filePath.slice(prefix.length) : void 0;
1128
+ }
1129
+ __name(getSubPathRemainder, "getSubPathRemainder");
1118
1130
  TemplatePath2.startsWithSubPath = function(path2, subPath) {
1119
1131
  path2 = TemplatePath2.normalize(path2);
1120
1132
  subPath = TemplatePath2.normalize(subPath);
1121
- return path2.startsWith(subPath);
1133
+ return getSubPathRemainder(path2, subPath) !== void 0;
1122
1134
  };
1123
1135
  TemplatePath2.stripLeadingSubPath = function(path2, subPath) {
1124
1136
  path2 = TemplatePath2.normalize(path2);
1125
1137
  subPath = TemplatePath2.normalize(subPath);
1126
- if (subPath !== "." && path2.startsWith(subPath)) {
1127
- return path2.slice(subPath.length + 1);
1138
+ if (subPath === ".") {
1139
+ return path2;
1128
1140
  }
1129
- return path2;
1141
+ return getSubPathRemainder(path2, subPath) ?? path2;
1130
1142
  };
1131
1143
  TemplatePath2.isDirectorySync = function(path2) {
1132
1144
  return fs2.existsSync(path2) && fs2.statSync(path2).isDirectory();
@@ -1188,7 +1200,7 @@ var require_TemplatePath = __commonJS({
1188
1200
  var require_IsPlainObject = __commonJS({
1189
1201
  "../../node_modules/@11ty/eleventy-utils/src/IsPlainObject.js"(exports, module) {
1190
1202
  module.exports = function(value) {
1191
- if (value === null || typeof value !== "object") {
1203
+ if (value === null || typeof value !== "object" || value === Object.prototype) {
1192
1204
  return false;
1193
1205
  }
1194
1206
  let proto = Object.getPrototypeOf(value);
@@ -1203,6 +1215,7 @@ var require_Merge = __commonJS({
1203
1215
  "use strict";
1204
1216
  var isPlainObject = require_IsPlainObject();
1205
1217
  var OVERRIDE_PREFIX = "override:";
1218
+ var UNSAFE_KEY = "__proto__";
1206
1219
  function cleanKey(key, prefix) {
1207
1220
  if (prefix && key.startsWith(prefix)) {
1208
1221
  return key.slice(prefix.length);
@@ -1212,21 +1225,32 @@ var require_Merge = __commonJS({
1212
1225
  __name(cleanKey, "cleanKey");
1213
1226
  function getMergedItem(target, source, prefixes = {}) {
1214
1227
  let { override } = prefixes;
1215
- if (!target && isPlainObject(source) && Object.isFrozen(source)) {
1216
- return source;
1228
+ let sourcePlainObjectShortcut = isPlainObject(source);
1229
+ let targetPlainObjectShortcut = false;
1230
+ if (!target) {
1231
+ if (Object.isFrozen(source)) {
1232
+ return source;
1233
+ }
1234
+ if (sourcePlainObjectShortcut) {
1235
+ targetPlainObjectShortcut = true;
1236
+ target = {};
1237
+ }
1217
1238
  }
1218
- let sourcePlainObjectShortcut;
1219
- if (!target && isPlainObject(source)) {
1220
- target = {};
1221
- sourcePlainObjectShortcut = true;
1239
+ if (sourcePlainObjectShortcut && Object.isFrozen(target) && isPlainObject(target)) {
1240
+ target = Object.assign({}, target);
1222
1241
  }
1223
1242
  if (Array.isArray(target) && Array.isArray(source)) {
1224
1243
  return target.concat(source);
1225
- } else if (isPlainObject(target)) {
1226
- if (sourcePlainObjectShortcut || isPlainObject(source)) {
1244
+ }
1245
+ if (targetPlainObjectShortcut || isPlainObject(target)) {
1246
+ if (sourcePlainObjectShortcut) {
1227
1247
  for (let key in source) {
1228
1248
  let overrideKey = cleanKey(key, override);
1229
- target[overrideKey] = getMergedItem(target[key], source[key], prefixes);
1249
+ if (overrideKey === UNSAFE_KEY) {
1250
+ continue;
1251
+ }
1252
+ let targetValue = Object.hasOwn(target, key) ? target[key] : void 0;
1253
+ target[overrideKey] = getMergedItem(targetValue, source[key], prefixes);
1230
1254
  }
1231
1255
  }
1232
1256
  return target;
@@ -1248,7 +1272,13 @@ var require_Merge = __commonJS({
1248
1272
  if (isPlainObject(target)) {
1249
1273
  for (let key in target) {
1250
1274
  if (key.indexOf(OVERRIDE_PREFIX) === 0) {
1251
- target[key.slice(OVERRIDE_PREFIX.length)] = target[key];
1275
+ if (Object.isFrozen(target)) {
1276
+ target = Object.assign({}, target);
1277
+ }
1278
+ let cleanedKey = key.slice(OVERRIDE_PREFIX.length);
1279
+ if (cleanedKey !== UNSAFE_KEY) {
1280
+ target[cleanedKey] = target[key];
1281
+ }
1252
1282
  delete target[key];
1253
1283
  }
1254
1284
  }
@@ -1264,8 +1294,8 @@ var require_Merge = __commonJS({
1264
1294
  return target;
1265
1295
  }
1266
1296
  __name(Merge, "Merge");
1297
+ Merge.DeepCopy = DeepCopy;
1267
1298
  module.exports = Merge;
1268
- module.exports.DeepCopy = DeepCopy;
1269
1299
  }
1270
1300
  });
1271
1301
 
@@ -1329,22 +1359,6 @@ var require_Url = __commonJS({
1329
1359
  }
1330
1360
  });
1331
1361
 
1332
- // ../../node_modules/@11ty/eleventy-utils/src/Buffer.js
1333
- var require_Buffer = __commonJS({
1334
- "../../node_modules/@11ty/eleventy-utils/src/Buffer.js"(exports, module) {
1335
- function isBuffer(inst) {
1336
- if (typeof Buffer !== "undefined") {
1337
- return Buffer.isBuffer(inst);
1338
- }
1339
- return inst instanceof Uint8Array;
1340
- }
1341
- __name(isBuffer, "isBuffer");
1342
- module.exports = {
1343
- isBuffer
1344
- };
1345
- }
1346
- });
1347
-
1348
1362
  // ../../node_modules/@11ty/eleventy-utils/src/lib-sha256.js
1349
1363
  var require_lib_sha256 = __commonJS({
1350
1364
  "../../node_modules/@11ty/eleventy-utils/src/lib-sha256.js"(exports, module) {
@@ -1470,7 +1484,10 @@ var require_lib_sha256 = __commonJS({
1470
1484
  buf[bp++] = L >>> 8 & 255;
1471
1485
  buf[bp++] = L & 255;
1472
1486
  process2();
1473
- let reply = new Uint8Array(32);
1487
+ let reply = (
1488
+ /** @type {Uint8Array & { hex?: () => string }} */
1489
+ new Uint8Array(32)
1490
+ );
1474
1491
  reply[0] = h0 >>> 24;
1475
1492
  reply[1] = h0 >>> 16 & 255;
1476
1493
  reply[2] = h0 >>> 8 & 255;
@@ -1521,7 +1538,6 @@ var require_lib_sha256 = __commonJS({
1521
1538
  var require_HashTypes = __commonJS({
1522
1539
  "../../node_modules/@11ty/eleventy-utils/src/HashTypes.js"(exports, module) {
1523
1540
  var { base64UrlSafe } = require_Url();
1524
- var { isBuffer } = require_Buffer();
1525
1541
  var sha256 = require_lib_sha256();
1526
1542
  function hasNodeCryptoModule() {
1527
1543
  try {
@@ -1585,7 +1601,7 @@ var require_HashTypes = __commonJS({
1585
1601
  static async toHash(...content) {
1586
1602
  let encoder = new TextEncoder();
1587
1603
  let input = this.mergeUint8Array(...content.map((c) => {
1588
- if (isBuffer(c)) {
1604
+ if (c instanceof Uint8Array) {
1589
1605
  return c;
1590
1606
  }
1591
1607
  return encoder.encode(c);
@@ -1637,7 +1653,10 @@ var require_HashTypes = __commonJS({
1637
1653
  __name(this, "ScriptHash");
1638
1654
  }
1639
1655
  static toHash(...content) {
1640
- let hash = sha256();
1656
+ let hash = (
1657
+ /** @type {{ add: (data: any) => void, digest: () => Uint8Array }} */
1658
+ sha256()
1659
+ );
1641
1660
  for (let c of content) {
1642
1661
  hash.add(c);
1643
1662
  }
@@ -1688,6 +1707,22 @@ var require_CreateHash = __commonJS({
1688
1707
  }
1689
1708
  });
1690
1709
 
1710
+ // ../../node_modules/@11ty/eleventy-utils/src/Buffer.js
1711
+ var require_Buffer = __commonJS({
1712
+ "../../node_modules/@11ty/eleventy-utils/src/Buffer.js"(exports, module) {
1713
+ function isBuffer(inst) {
1714
+ if (typeof Buffer !== "undefined") {
1715
+ return Buffer.isBuffer(inst);
1716
+ }
1717
+ return inst instanceof Uint8Array;
1718
+ }
1719
+ __name(isBuffer, "isBuffer");
1720
+ module.exports = {
1721
+ isBuffer
1722
+ };
1723
+ }
1724
+ });
1725
+
1691
1726
  // ../../node_modules/@11ty/eleventy-utils/index.js
1692
1727
  var require_eleventy_utils = __commonJS({
1693
1728
  "../../node_modules/@11ty/eleventy-utils/index.js"(exports, module) {
@@ -1745,7 +1780,7 @@ var require_lib = __commonJS({
1745
1780
  err.Update(path);
1746
1781
  if (!withInternals) {
1747
1782
  const old = err;
1748
- err = new Error(old.message);
1783
+ err = old.cause ? new Error(old.message, { cause: old.cause }) : new Error(old.message);
1749
1784
  err.name = old.name;
1750
1785
  }
1751
1786
  return err;
@@ -4309,11 +4344,11 @@ var require_parser = __commonJS({
4309
4344
  const nextToken = this.peekToken();
4310
4345
  const nextVal = nextToken && nextToken.value;
4311
4346
  if (this.dropLeadingWhitespace) {
4312
- data = data.replace(/^\s*/, "");
4347
+ data = data.trimStart();
4313
4348
  this.dropLeadingWhitespace = false;
4314
4349
  }
4315
4350
  if (nextToken && (nextToken.type === lexer.TOKEN_BLOCK_START && nextVal.charAt(nextVal.length - 1) === "-" || nextToken.type === lexer.TOKEN_VARIABLE_START && nextVal.charAt(this.tokens.tags.VARIABLE_START.length) === "-" || nextToken.type === lexer.TOKEN_COMMENT && nextVal.charAt(this.tokens.tags.COMMENT_START.length) === "-")) {
4316
- data = data.replace(/\s*$/, "");
4351
+ data = data.trimEnd();
4317
4352
  }
4318
4353
  buf.push(new nodes.Output(
4319
4354
  tok.lineno,
@@ -7584,15 +7619,16 @@ function matchesTemplate(search, template) {
7584
7619
  let templateIndex = 0;
7585
7620
  let starIndex = -1;
7586
7621
  let matchIndex = 0;
7587
- while (searchIndex < search.length) if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) if (template[templateIndex] === "*") {
7588
- starIndex = templateIndex;
7589
- matchIndex = searchIndex;
7590
- templateIndex++;
7591
- } else {
7592
- searchIndex++;
7593
- templateIndex++;
7594
- }
7595
- else if (starIndex !== -1) {
7622
+ while (searchIndex < search.length) if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) {
7623
+ if (template[templateIndex] === "*") {
7624
+ starIndex = templateIndex;
7625
+ matchIndex = searchIndex;
7626
+ templateIndex++;
7627
+ } else {
7628
+ searchIndex++;
7629
+ templateIndex++;
7630
+ }
7631
+ } else if (starIndex !== -1) {
7596
7632
  templateIndex = starIndex + 1;
7597
7633
  matchIndex++;
7598
7634
  searchIndex = matchIndex;
@@ -7612,7 +7648,7 @@ function createDebug(namespace, options) {
7612
7648
  let enableOverride;
7613
7649
  let namespacesCache;
7614
7650
  let enabledCache;
7615
- const debug3 = /* @__PURE__ */ __name((...args) => {
7651
+ const debug3 = /* @__PURE__ */ __name(((...args) => {
7616
7652
  if (!debug3.enabled) return;
7617
7653
  const curr = Date.now();
7618
7654
  const diff = curr - (prevTime || curr);
@@ -7634,7 +7670,7 @@ function createDebug(namespace, options) {
7634
7670
  });
7635
7671
  options.formatArgs.call(debug3, diff, args);
7636
7672
  debug3.log(...args);
7637
- }, "debug");
7673
+ }), "debug");
7638
7674
  debug3.extend = function(namespace2, delimiter = ":") {
7639
7675
  return createDebug(this.namespace + delimiter + namespace2, {
7640
7676
  useColors: this.useColors,
@@ -7684,6 +7720,48 @@ function enabled(name) {
7684
7720
  }
7685
7721
  __name(enabled, "enabled");
7686
7722
 
7723
+ // ../../node_modules/obug/dist/plain.js
7724
+ function formatArgs(diff, args) {
7725
+ args[0] = `${this.namespace} ${args[0]} +${this.humanize(diff)}`;
7726
+ }
7727
+ __name(formatArgs, "formatArgs");
7728
+ var defaultOptions = {
7729
+ useColors: false,
7730
+ color: "",
7731
+ formatArgs,
7732
+ formatters: {
7733
+ /**
7734
+ * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
7735
+ */
7736
+ j(v) {
7737
+ try {
7738
+ return JSON.stringify(v);
7739
+ } catch (error) {
7740
+ return `[UnexpectedJSONParseError]: ${error.message}`;
7741
+ }
7742
+ }
7743
+ },
7744
+ inspectOpts: {},
7745
+ humanize,
7746
+ log: console.debug || console.log || (() => {
7747
+ })
7748
+ };
7749
+ function createDebug2(namespace, options) {
7750
+ return createDebug(namespace, Object.assign({}, defaultOptions, options));
7751
+ }
7752
+ __name(createDebug2, "createDebug");
7753
+ function load() {
7754
+ let r;
7755
+ try {
7756
+ r = localStorage.getItem("debug") || localStorage.getItem("DEBUG");
7757
+ } catch (_unused) {
7758
+ }
7759
+ if (!r && typeof process !== "undefined" && "env" in process) r = process.env.DEBUG;
7760
+ return r || "";
7761
+ }
7762
+ __name(load, "load");
7763
+ enable(load());
7764
+
7687
7765
  // ../../node_modules/obug/dist/browser.js
7688
7766
  var colors = [
7689
7767
  "#0000CC",
@@ -7763,7 +7841,7 @@ var colors = [
7763
7841
  "#FFCC00",
7764
7842
  "#FFCC33"
7765
7843
  ];
7766
- function formatArgs(diff, args) {
7844
+ function formatArgs2(diff, args) {
7767
7845
  const { useColors } = this;
7768
7846
  args[0] = `${(useColors ? "%c" : "") + this.namespace + (useColors ? " %c" : " ") + args[0] + (useColors ? "%c " : " ")}+${this.humanize(diff)}`;
7769
7847
  if (!useColors) return;
@@ -7778,53 +7856,17 @@ function formatArgs(diff, args) {
7778
7856
  });
7779
7857
  args.splice(lastC, 0, c);
7780
7858
  }
7781
- __name(formatArgs, "formatArgs");
7782
- var log = console.debug || console.log || (() => {
7783
- });
7784
- var storage = localstorage();
7785
- var defaultOptions = {
7786
- useColors: true,
7787
- formatArgs,
7788
- formatters: {
7789
- /**
7790
- * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
7791
- */
7792
- j(v) {
7793
- try {
7794
- return JSON.stringify(v);
7795
- } catch (error) {
7796
- return `[UnexpectedJSONParseError]: ${error.message}`;
7797
- }
7798
- }
7799
- },
7800
- inspectOpts: {},
7801
- humanize,
7802
- log
7803
- };
7804
- function createDebug2(namespace, options) {
7859
+ __name(formatArgs2, "formatArgs");
7860
+ function createDebug3(namespace, options) {
7805
7861
  var _ref;
7806
7862
  const color = (_ref = options && options.color) !== null && _ref !== void 0 ? _ref : selectColor(colors, namespace);
7807
- return createDebug(namespace, Object.assign(defaultOptions, { color }, options));
7808
- }
7809
- __name(createDebug2, "createDebug");
7810
- function localstorage() {
7811
- try {
7812
- return localStorage;
7813
- } catch (_unused) {
7814
- }
7815
- }
7816
- __name(localstorage, "localstorage");
7817
- function load() {
7818
- let r;
7819
- try {
7820
- r = storage.getItem("debug") || storage.getItem("DEBUG");
7821
- } catch (_unused2) {
7822
- }
7823
- if (!r && typeof process !== "undefined" && "env" in process) r = process.env.DEBUG;
7824
- return r || "";
7863
+ return createDebug2(namespace, Object.assign({
7864
+ useColors: true,
7865
+ color,
7866
+ formatArgs: formatArgs2
7867
+ }, options));
7825
7868
  }
7826
- __name(load, "load");
7827
- enable(load());
7869
+ __name(createDebug3, "createDebug");
7828
7870
 
7829
7871
  // ../../src/Util/IsBuildAwesome.js
7830
7872
  function isUsingBuildAwesome() {
@@ -7834,10 +7876,10 @@ __name(isUsingBuildAwesome, "isUsingBuildAwesome");
7834
7876
 
7835
7877
  // ../../src/Util/DebugLogUtil.js
7836
7878
  var PREFIX = isUsingBuildAwesome() ? "BuildAwesome:" : "Eleventy:";
7837
- function createDebug3(name) {
7838
- return createDebug2(`${PREFIX}:${name}`);
7879
+ function createDebug4(name) {
7880
+ return createDebug3(`${PREFIX}${name}`);
7839
7881
  }
7840
- __name(createDebug3, "createDebug");
7882
+ __name(createDebug4, "createDebug");
7841
7883
 
7842
7884
  // ../../src/Errors/BaseError.js
7843
7885
  var BaseError = class extends Error {
@@ -7862,6 +7904,14 @@ var BaseError = class extends Error {
7862
7904
  this.originalError = originalError;
7863
7905
  }
7864
7906
  }
7907
+ /**
7908
+ * @param {string} filePath - The file that caused the error.
7909
+ * @returns {this}
7910
+ */
7911
+ setFilePath(filePath) {
7912
+ this.filePath = filePath;
7913
+ return this;
7914
+ }
7865
7915
  };
7866
7916
 
7867
7917
  // ../../src/Engines/TemplateEngine.js
@@ -7870,7 +7920,7 @@ var TemplateEngineConfigError = class extends BaseError {
7870
7920
  __name(this, "TemplateEngineConfigError");
7871
7921
  }
7872
7922
  };
7873
- var debug = createDebug3("TemplateEngine");
7923
+ var debug = createDebug4("TemplateEngine");
7874
7924
  var AMENDED_INSTANCES = /* @__PURE__ */ new Set();
7875
7925
  var TemplateEngine = class {
7876
7926
  static {
@@ -7879,6 +7929,7 @@ var TemplateEngine = class {
7879
7929
  #extensionMap;
7880
7930
  #engineManager;
7881
7931
  #benchmarks;
7932
+ #configEventListeners = [];
7882
7933
  constructor(name, eleventyConfig) {
7883
7934
  this.name = name;
7884
7935
  this.engineLib = null;
@@ -7890,6 +7941,18 @@ var TemplateEngine = class {
7890
7941
  get cacheable() {
7891
7942
  return false;
7892
7943
  }
7944
+ // Engine instances are replaced on each build, so their listeners must not outlive them
7945
+ addConfigEventListener(eventName, fn) {
7946
+ let events = this.config.events;
7947
+ this.#configEventListeners.push([events, eventName, fn]);
7948
+ events.on(eventName, fn);
7949
+ }
7950
+ removeConfigEventListeners() {
7951
+ for (let [events, eventName, fn] of this.#configEventListeners) {
7952
+ events.off(eventName, fn);
7953
+ }
7954
+ this.#configEventListeners = [];
7955
+ }
7893
7956
  get dirs() {
7894
7957
  return this.eleventyConfig.directories;
7895
7958
  }
@@ -8005,6 +8068,9 @@ var TemplateEngine = class {
8005
8068
  needsCompilation(str) {
8006
8069
  return true;
8007
8070
  }
8071
+ // Runs at compile time for pipeline steps that compile later, during render
8072
+ async ready() {
8073
+ }
8008
8074
  /**
8009
8075
  * Make sure compile is implemented downstream.
8010
8076
  * @abstract
@@ -8023,13 +8089,23 @@ var TemplateEngine = class {
8023
8089
  }
8024
8090
  return true;
8025
8091
  }
8092
+ // e.g. a template’s include, import, extends, or layout file, recorded when it is used
8093
+ // `from` is the engine name for string templates (e.g. the Render plugin’s `renderTemplate`)
8094
+ addDependency(from, to) {
8095
+ if (!from || !to) {
8096
+ return;
8097
+ }
8098
+ this.config.uses.addDependency(from, [to]);
8099
+ }
8026
8100
  isFileRelevantTo(inputPath, comparisonFile) {
8027
8101
  return this.config.uses.isFileRelevantTo(inputPath, comparisonFile);
8028
8102
  }
8029
8103
  };
8030
8104
 
8031
8105
  // ../../src/Engines/Util/ContextAugmenter.js
8032
- var DATA_KEYS = ["page", "eleventy"];
8106
+ var DATA_KEYS = ["page", "eleventy", "buildawesome", "collections"];
8107
+ var DATA_METHOD = "getData";
8108
+ var augmented = /* @__PURE__ */ new WeakMap();
8033
8109
  function augmentObject(targetObject, options = {}) {
8034
8110
  options = Object.assign(
8035
8111
  {
@@ -8039,11 +8115,15 @@ function augmentObject(targetObject, options = {}) {
8039
8115
  lazy: false
8040
8116
  // lazily fetch the property
8041
8117
  // getter: function() {},
8118
+ // dataGetter: function(source) {}, // defaults to `source`
8042
8119
  },
8043
8120
  options
8044
8121
  );
8122
+ if (targetObject === options.source) {
8123
+ return targetObject;
8124
+ }
8045
8125
  for (let key of DATA_KEYS) {
8046
- if (!options.overwrite && targetObject[key]) {
8126
+ if (!options.overwrite && isUserDefined(targetObject, key)) {
8047
8127
  continue;
8048
8128
  }
8049
8129
  if (options.lazy) {
@@ -8053,12 +8133,7 @@ function augmentObject(targetObject, options = {}) {
8053
8133
  } else {
8054
8134
  value = /* @__PURE__ */ __name(() => options.source?.[key], "value");
8055
8135
  }
8056
- Object.defineProperty(targetObject, key, {
8057
- writable: true,
8058
- configurable: true,
8059
- enumerable: true,
8060
- value
8061
- });
8136
+ defineGetter(targetObject, key, value);
8062
8137
  } else {
8063
8138
  let value;
8064
8139
  if (typeof options.getter == "function") {
@@ -8068,15 +8143,49 @@ function augmentObject(targetObject, options = {}) {
8068
8143
  }
8069
8144
  if (value) {
8070
8145
  targetObject[key] = value;
8146
+ markAugmented(targetObject, key);
8071
8147
  }
8072
8148
  }
8073
8149
  }
8150
+ if (options.overwrite || !isUserDefined(targetObject, DATA_METHOD)) {
8151
+ let dataGetter = options.dataGetter ?? ((source) => source);
8152
+ targetObject[DATA_METHOD] = () => dataGetter(options.source);
8153
+ markAugmented(targetObject, DATA_METHOD);
8154
+ }
8074
8155
  return targetObject;
8075
8156
  }
8076
8157
  __name(augmentObject, "augmentObject");
8158
+ function isUserDefined(targetObject, key) {
8159
+ return Boolean(targetObject[key]) && !augmented.get(targetObject)?.has(key);
8160
+ }
8161
+ __name(isUserDefined, "isUserDefined");
8162
+ function markAugmented(targetObject, key) {
8163
+ if (!augmented.has(targetObject)) {
8164
+ augmented.set(targetObject, /* @__PURE__ */ new Set());
8165
+ }
8166
+ augmented.get(targetObject).add(key);
8167
+ }
8168
+ __name(markAugmented, "markAugmented");
8169
+ function defineGetter(targetObject, key, get) {
8170
+ markAugmented(targetObject, key);
8171
+ Object.defineProperty(targetObject, key, {
8172
+ configurable: true,
8173
+ enumerable: true,
8174
+ get,
8175
+ set(value) {
8176
+ Object.defineProperty(this, key, {
8177
+ value,
8178
+ writable: true,
8179
+ configurable: true,
8180
+ enumerable: true
8181
+ });
8182
+ }
8183
+ });
8184
+ }
8185
+ __name(defineGetter, "defineGetter");
8077
8186
 
8078
8187
  // ../../src/Engines/Nunjucks.js
8079
- var debug2 = createDebug3("Nunjucks");
8188
+ var debug2 = createDebug4("Nunjucks");
8080
8189
  var BuildAwesomeNunjucksError = class extends BaseError {
8081
8190
  static {
8082
8191
  __name(this, "BuildAwesomeNunjucksError");
@@ -8093,10 +8202,20 @@ var Nunjucks = class _Nunjucks extends TemplateEngine {
8093
8202
  this._usingPrecompiled = Object.keys(this.nunjucksPrecompiledTemplates).length > 0;
8094
8203
  this.setLibrary(this.config.libraryOverrides.njk);
8095
8204
  }
8096
- // v3.1.0-alpha.1 we’ve moved to use Nunjucks’ internal cache instead of Eleventy’s
8097
- // get cacheable() {
8098
- // return false;
8099
- // }
8205
+ // Nunjucks’ internal cache only covers loader templates (includes, layouts), not compiled strings
8206
+ get cacheable() {
8207
+ return true;
8208
+ }
8209
+ #recompiledKeys = /* @__PURE__ */ new Set();
8210
+ // A cached template keeps the environment (and included templates) of the build that compiled it
8211
+ getCompileCacheKey(str, inputPath) {
8212
+ let entry = super.getCompileCacheKey(str, inputPath);
8213
+ if (!this.#recompiledKeys.has(entry.key) && this.config.uses.isChangedFileUsedBy(inputPath)) {
8214
+ this.#recompiledKeys.add(entry.key);
8215
+ entry.useCache = false;
8216
+ }
8217
+ return entry;
8218
+ }
8100
8219
  #getFileSystemDirs() {
8101
8220
  let paths = /* @__PURE__ */ new Set();
8102
8221
  paths.add(super.getIncludesDir());
@@ -8105,6 +8224,11 @@ var Nunjucks = class _Nunjucks extends TemplateEngine {
8105
8224
  }
8106
8225
  #setEnv(override) {
8107
8226
  if (override) {
8227
+ if (!(override instanceof import_nunjucks.Environment)) {
8228
+ debug2(
8229
+ "WARNING: the Nunjucks environment passed to `setLibrary` was not created by `@11ty/nunjucks`. Import from `@11ty/nunjucks` instead of `nunjucks` to avoid mixing library versions."
8230
+ );
8231
+ }
8108
8232
  this.njkEnv = override;
8109
8233
  } else if (this._usingPrecompiled) {
8110
8234
  const NodePrecompiledLoader = /* @__PURE__ */ __name(function() {
@@ -8130,14 +8254,41 @@ var Nunjucks = class _Nunjucks extends TemplateEngine {
8130
8254
  }
8131
8255
  this.njkEnv = new import_nunjucks.Environment(loaders, this.nunjucksEnvironmentOptions);
8132
8256
  }
8257
+ this.#trackTemplates();
8133
8258
  this.config.events.emit("buildawesome.engine.njk", {
8134
8259
  nunjucks: import_nunjucks.default,
8135
8260
  environment: this.njkEnv
8136
8261
  });
8137
8262
  }
8263
+ // Records `include`, `import`, `from`, and `extends` files in the dependency graph for incremental builds
8264
+ #trackTemplates() {
8265
+ let env = this.njkEnv;
8266
+ let getTemplate = env.getTemplate;
8267
+ if (typeof getTemplate !== "function") {
8268
+ return;
8269
+ }
8270
+ let engine = this;
8271
+ env.getTemplate = function(name, ...args) {
8272
+ let parentName = typeof args[1] === "string" ? args[1] : args.length > 1 ? engine.name : void 0;
8273
+ let cbIndex = args.findIndex((arg) => typeof arg === "function");
8274
+ if (parentName && cbIndex > -1) {
8275
+ let cb = args[cbIndex];
8276
+ args[cbIndex] = (error, tmpl) => {
8277
+ engine.addDependency(parentName, tmpl?.path);
8278
+ cb(error, tmpl);
8279
+ };
8280
+ }
8281
+ let result = getTemplate.call(this, name, ...args);
8282
+ if (parentName && cbIndex === -1) {
8283
+ engine.addDependency(parentName, result?.path);
8284
+ }
8285
+ return result;
8286
+ };
8287
+ }
8138
8288
  setLibrary(override) {
8139
8289
  this.#setEnv(override);
8140
- this.config.events.on("buildawesome#templatemodified", (templatePath) => {
8290
+ this.removeConfigEventListeners();
8291
+ this.addConfigEventListener("buildawesome#templatemodified", (templatePath) => {
8141
8292
  let absTmplPath = import_eleventy_utils.TemplatePath.normalizeOperatingSystemFilePath(
8142
8293
  import_eleventy_utils.TemplatePath.absolutePath(templatePath)
8143
8294
  );
@@ -8173,23 +8324,28 @@ var Nunjucks = class _Nunjucks extends TemplateEngine {
8173
8324
  }
8174
8325
  addFilters(filters, isAsync) {
8175
8326
  for (let name in filters) {
8176
- this.njkEnv.addFilter(name, _Nunjucks.wrapFilter(name, filters[name]), isAsync);
8327
+ this.njkEnv.addFilter(name, _Nunjucks.wrapFilter(name, filters[name], isAsync), isAsync);
8177
8328
  }
8178
8329
  }
8179
- static wrapFilter(name, fn) {
8330
+ static wrapFilter(name, fn, isAsync = false) {
8180
8331
  return function(...args) {
8332
+ let getError = /* @__PURE__ */ __name((e) => new BuildAwesomeNunjucksError(
8333
+ `Error in Nunjucks Filter \`${name}\`${this.page ? ` (${this.page.inputPath})` : ""}`,
8334
+ e
8335
+ ), "getError");
8181
8336
  try {
8182
8337
  augmentObject(this, {
8183
8338
  source: this.ctx,
8184
8339
  lazy: false
8185
8340
  // context.env?.opts.throwOnUndefined,
8186
8341
  });
8342
+ if (isAsync) {
8343
+ let cb = args.pop();
8344
+ args.push((error, result) => cb(error ? getError(error) : null, result));
8345
+ }
8187
8346
  return fn.call(this, ...args);
8188
8347
  } catch (e) {
8189
- throw new BuildAwesomeNunjucksError(
8190
- `Error in Nunjucks Filter \`${name}\`${this.page ? ` (${this.page.inputPath})` : ""}`,
8191
- e
8192
- );
8348
+ throw getError(e);
8193
8349
  }
8194
8350
  };
8195
8351
  }