@11ty/client 4.0.0-alpha.5 → 4.0.0-alpha.6

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 v4.0.0-alpha.5 (@11ty/client Bundle) */
1
+ /*! Eleventy v4.0.0-alpha.6 (@11ty/client Bundle) */
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -2985,7 +2985,7 @@ var init_package = __esm({
2985
2985
  "../../package.json"() {
2986
2986
  package_default = {
2987
2987
  name: "@11ty/eleventy",
2988
- version: "4.0.0-alpha.5",
2988
+ version: "4.0.0-alpha.6",
2989
2989
  description: "A simpler static site generator.",
2990
2990
  publishConfig: {
2991
2991
  access: "public",
@@ -3120,14 +3120,16 @@ var init_package = __esm({
3120
3120
  dependencies: {
3121
3121
  "@11ty/dependency-tree": "^4.0.1",
3122
3122
  "@11ty/dependency-tree-esm": "^2.0.3",
3123
- "@11ty/eleventy-dev-server": "^3.0.0-alpha.5",
3123
+ "@11ty/eleventy-dev-server": "^3.0.0-alpha.6",
3124
3124
  "@11ty/eleventy-plugin-bundle": "^3.0.7",
3125
3125
  "@11ty/eleventy-utils": "^2.0.7",
3126
3126
  "@11ty/gray-matter": "^2.0.1",
3127
3127
  "@11ty/lodash-custom": "^4.17.21",
3128
+ "@11ty/node-version-check": "^1.0.1",
3129
+ "@11ty/nunjucks": "^4.0.0-alpha.1",
3128
3130
  "@11ty/parse-date-strings": "^2.0.6",
3129
3131
  "@11ty/posthtml-urls": "^1.0.2",
3130
- "@11ty/recursive-copy": "^4.0.3",
3132
+ "@11ty/recursive-copy": "^5.0.0",
3131
3133
  "@sindresorhus/slugify": "^3.0.0",
3132
3134
  "bcp-47-normalize": "^2.3.0",
3133
3135
  chokidar: "^5.0.0",
@@ -3142,19 +3144,14 @@ var init_package = __esm({
3142
3144
  minimist: "^1.2.8",
3143
3145
  moo: "^0.5.2",
3144
3146
  "node-retrieve-globals": "^6.0.1",
3145
- nunjucks: "^3.2.4",
3146
3147
  picomatch: "^4.0.3",
3147
- "please-upgrade-node": "^3.2.0",
3148
3148
  posthtml: "^0.16.7",
3149
3149
  "posthtml-match-helper": "^2.0.3",
3150
3150
  semver: "^7.7.3",
3151
3151
  tinyglobby: "^0.2.15"
3152
3152
  },
3153
3153
  overrides: {
3154
- commander: "^14",
3155
- chokidar: "$chokidar",
3156
- fdir: "6.4.6",
3157
- "posthtml-parser": "^0.12"
3154
+ fdir: "6.4.6"
3158
3155
  }
3159
3156
  };
3160
3157
  }
@@ -7029,6 +7026,22 @@ var init_JavaScript = __esm({
7029
7026
  }
7030
7027
  return new mod();
7031
7028
  } else {
7029
+ if (mod.toString().trimStart().startsWith("class ")) {
7030
+ let modInstance = new mod();
7031
+ if (Object.hasOwn(modInstance, "data") || Object.hasOwn(modInstance, "render")) {
7032
+ if (!Object.hasOwn(modInstance, "render")) {
7033
+ mod.prototype.render = noop2;
7034
+ }
7035
+ if (!Object.hasOwn(modInstance, "data") && !mod.data && originalModData) {
7036
+ mod.prototype.data = originalModData;
7037
+ }
7038
+ return modInstance;
7039
+ } else {
7040
+ throw new Error(
7041
+ "Invalid class signature for an 11ty.js template: needs a render or data instance property."
7042
+ );
7043
+ }
7044
+ }
7032
7045
  return {
7033
7046
  ...originalModData ? { data: originalModData } : void 0,
7034
7047
  render: mod
@@ -7835,6 +7848,98 @@ init_EleventyBaseError();
7835
7848
 
7836
7849
  // ../../src/Data/TemplateDataInitialGlobalData.js
7837
7850
  var import_lodash_custom = __toESM(require_lodash_custom(), 1);
7851
+
7852
+ // ../../src/Util/ReservedData.js
7853
+ var EleventyReservedDataError = class extends TypeError {
7854
+ };
7855
+ var ReservedData = class _ReservedData {
7856
+ static fullProperties = [
7857
+ "pkg",
7858
+ // Object.freeze’d upstream
7859
+ "eleventy",
7860
+ // Object.freeze’d upstream
7861
+ // "page" is only frozen for specific subproperties below
7862
+ "content",
7863
+ "collections"
7864
+ ];
7865
+ static properties = [
7866
+ // "page" is only frozen for specific subproperties below
7867
+ "content",
7868
+ "collections"
7869
+ ];
7870
+ static pageProperties = [
7871
+ "date",
7872
+ "inputPath",
7873
+ "fileSlug",
7874
+ "filePathStem",
7875
+ "outputFileExtension",
7876
+ "templateSyntax",
7877
+ "url",
7878
+ "outputPath"
7879
+ // not yet `excerpt` or `lang` set via front matter and computed data
7880
+ ];
7881
+ // Check in the data cascade for reserved data properties.
7882
+ static getReservedKeys(data, globalProperties = this.fullProperties) {
7883
+ if (!data) {
7884
+ return [];
7885
+ }
7886
+ let keys = globalProperties.filter((key) => {
7887
+ return key in data;
7888
+ });
7889
+ if ("page" in data) {
7890
+ if (typeof data.page === "object") {
7891
+ for (let key of this.pageProperties) {
7892
+ if (key in data.page) {
7893
+ keys.push(`page.${key}`);
7894
+ }
7895
+ }
7896
+ } else {
7897
+ keys.push("page");
7898
+ }
7899
+ }
7900
+ return keys;
7901
+ }
7902
+ static #check(data, sourceLocation, propertiesList) {
7903
+ let reservedNames = _ReservedData.getReservedKeys(data, propertiesList);
7904
+ if (reservedNames.length === 0) {
7905
+ return;
7906
+ }
7907
+ throw this.getError({
7908
+ reservedNames,
7909
+ sourceLocation
7910
+ });
7911
+ }
7912
+ // check for frozen objects too
7913
+ static check(data, sourceLocation) {
7914
+ this.#check(data, sourceLocation, this.fullProperties);
7915
+ }
7916
+ static checkSubset(data, sourceLocation) {
7917
+ this.#check(data, sourceLocation, this.properties);
7918
+ }
7919
+ static getError(options = {}) {
7920
+ let { reservedNames, cause, sourceLocation } = options || {};
7921
+ if (cause) {
7922
+ reservedNames ??= cause.reservedNames;
7923
+ }
7924
+ let e = new EleventyReservedDataError(
7925
+ `You attempted to set one of Eleventy\u2019s reserved data property names${reservedNames ? `: ${reservedNames.join(", ")}` : ""}${sourceLocation ? ` (source: ${sourceLocation})` : ""}. You can opt-out of this behavior with \`eleventyConfig.setFreezeReservedData(false)\` or rename/remove the property in your data cascade that conflicts with Eleventy\u2019s reserved property names (e.g. \`eleventy\`, \`pkg\`, and others). Learn more: https://v3.11ty.dev/docs/data-eleventy-supplied/`,
7926
+ { cause }
7927
+ );
7928
+ if (reservedNames) {
7929
+ e.reservedNames = reservedNames;
7930
+ }
7931
+ return e;
7932
+ }
7933
+ static isFrozenError(e) {
7934
+ return e instanceof TypeError && e.message.startsWith("Cannot add property") && e.message.endsWith("not extensible");
7935
+ }
7936
+ static isReservedDataError(e) {
7937
+ return e instanceof EleventyReservedDataError;
7938
+ }
7939
+ };
7940
+ var ReservedData_default = ReservedData;
7941
+
7942
+ // ../../src/Data/TemplateDataInitialGlobalData.js
7838
7943
  init_EleventyBaseError();
7839
7944
  var { set: lodashSet } = import_lodash_custom.default;
7840
7945
  var TemplateDataConfigError = class extends EleventyBaseError_default {
@@ -7859,6 +7964,9 @@ var TemplateDataInitialGlobalData = class {
7859
7964
  lodashSet(globalData, key, returnValue);
7860
7965
  }
7861
7966
  }
7967
+ if (this.config.freezeReservedData) {
7968
+ ReservedData_default.check(globalData, this.templateConfig.getActiveConfigPath());
7969
+ }
7862
7970
  return globalData;
7863
7971
  }
7864
7972
  };
@@ -8149,6 +8257,9 @@ var TemplateData = class _TemplateData {
8149
8257
  dataFileConflicts[objectPathTargetString] = files[j];
8150
8258
  debug3(`Found global data file ${files[j]} and adding as: ${objectPathTarget}`);
8151
8259
  lodashSet2(globalData, objectPathTarget, data);
8260
+ if (this.config.freezeReservedData) {
8261
+ ReservedData_default.check(globalData, files[j]);
8262
+ }
8152
8263
  }
8153
8264
  return globalData;
8154
8265
  }
@@ -9870,7 +9981,8 @@ var TemplateLayoutPathResolver = class {
9870
9981
  return true;
9871
9982
  }
9872
9983
  let fullPath = this.templateConfig.directories.getLayoutPath(layoutPath);
9873
- if (this.templateConfig.existsCache.exists(fullPath)) {
9984
+ let existsCache = this.templateConfig.existsCache;
9985
+ if (existsCache.exists(fullPath) && !existsCache.isDirectory(fullPath)) {
9874
9986
  return true;
9875
9987
  }
9876
9988
  return false;
@@ -9996,12 +10108,12 @@ var debugDev3 = debug_default("Dev:Eleventy:TemplateLayout");
9996
10108
  var CdataWrapper = class _CdataWrapper {
9997
10109
  static PREFIX = "<![CDATA[STARTRAW";
9998
10110
  static POSTFIX = "ENDRAW]]>";
9999
- constructor(templateSyntax) {
10000
- this.isEligible = _CdataWrapper.isEligible(templateSyntax);
10111
+ constructor(pageTemplateSyntax = "", layoutTemplateSyntax = "") {
10112
+ this.isEligible = _CdataWrapper.isEligible(pageTemplateSyntax, layoutTemplateSyntax);
10001
10113
  }
10002
- // Markdown only
10003
- static isEligible(templateSyntax) {
10004
- return templateSyntax.split(",").includes("md");
10114
+ // Markdown in Markdown layout only
10115
+ static isEligible(templateSyntax, layoutTemplateSyntax) {
10116
+ return templateSyntax.split(",").includes("md") && layoutTemplateSyntax.split(",").includes("md");
10005
10117
  }
10006
10118
  wrap(content) {
10007
10119
  if (this.isEligible) {
@@ -10173,14 +10285,18 @@ var TemplateLayout = class _TemplateLayout extends TemplateContent_default {
10173
10285
  // Trouble: layouts may need data variables present downstream/upstream
10174
10286
  // This is called from Template->renderPageEntry
10175
10287
  async renderPageEntry(pageEntry) {
10288
+ let pageTemplateSyntax = pageEntry.template?.getEngineNames(
10289
+ pageEntry.data[this.config.keys.engineOverride]
10290
+ );
10176
10291
  let templateContent = pageEntry.templateContent;
10177
10292
  let compiledFunctions = await this.getCompiledLayoutFunctions();
10178
10293
  for (let { render, template } of compiledFunctions) {
10179
- let templateSyntax = template.getEngineNames(pageEntry.data[this.config.keys.engineOverride]);
10180
- let cdata = new CdataWrapper(templateSyntax);
10294
+ let layoutTemplateSyntax = template.getEngineNames();
10295
+ let cdata = new CdataWrapper(pageTemplateSyntax, layoutTemplateSyntax);
10181
10296
  let data = {
10182
- content: cdata.wrap(templateContent),
10183
- ...pageEntry.data
10297
+ ...pageEntry.data,
10298
+ // This should come *after* data, so `content` have override `content` props set in data cascade
10299
+ content: cdata.wrap(templateContent)
10184
10300
  };
10185
10301
  templateContent = cdata.unwrap(await render(data));
10186
10302
  }
@@ -11103,66 +11219,6 @@ function fromISOtoDateUTC(dateValue, inputPath) {
11103
11219
  }
11104
11220
  }
11105
11221
 
11106
- // ../../src/Util/ReservedData.js
11107
- var EleventyReservedDataError = class extends TypeError {
11108
- };
11109
- var ReservedData = class _ReservedData {
11110
- static properties = [
11111
- // "pkg", // Object.freeze’d upstream
11112
- // "eleventy", // Object.freeze’d upstream
11113
- // "page" is only frozen for specific subproperties below
11114
- "content",
11115
- "collections"
11116
- ];
11117
- static pageProperties = [
11118
- "date",
11119
- "inputPath",
11120
- "fileSlug",
11121
- "filePathStem",
11122
- "outputFileExtension",
11123
- "templateSyntax",
11124
- "url",
11125
- "outputPath"
11126
- // not yet `excerpt` or `lang` set via front matter and computed data
11127
- ];
11128
- // Check in the data cascade for reserved data properties.
11129
- static getReservedKeys(data) {
11130
- if (!data) {
11131
- return [];
11132
- }
11133
- let keys = this.properties.filter((key) => {
11134
- return key in data;
11135
- });
11136
- if ("page" in data) {
11137
- if (typeof data.page === "object") {
11138
- for (let key of this.pageProperties) {
11139
- if (key in data.page) {
11140
- keys.push(`page.${key}`);
11141
- }
11142
- }
11143
- } else {
11144
- keys.push("page");
11145
- }
11146
- }
11147
- return keys;
11148
- }
11149
- static check(data) {
11150
- let reserved = _ReservedData.getReservedKeys(data);
11151
- if (reserved.length === 0) {
11152
- return;
11153
- }
11154
- let error = new EleventyReservedDataError(
11155
- `Cannot override reserved Eleventy properties: ${reserved.join(", ")}`
11156
- );
11157
- error.reservedNames = reserved;
11158
- throw error;
11159
- }
11160
- static isReservedDataError(e) {
11161
- return e instanceof EleventyReservedDataError;
11162
- }
11163
- };
11164
- var ReservedData_default = ReservedData;
11165
-
11166
11222
  // ../../src/Util/TransformsUtil.js
11167
11223
  init_EleventyBaseError();
11168
11224
  var import_eleventy_utils18 = __toESM(require_eleventy_utils(), 1);
@@ -11676,7 +11732,7 @@ var Template = class _Template extends TemplateContent_default {
11676
11732
  let globalData = {};
11677
11733
  if (this.templateData) {
11678
11734
  localData = await this.templateData.getTemplateDirectoryData(this.inputPath);
11679
- globalData = await this.templateData.getGlobalData(this.inputPath);
11735
+ globalData = await this.templateData.getGlobalData();
11680
11736
  debugDev4("%o getData getTemplateDirectoryData and getGlobalData", this.inputPath);
11681
11737
  }
11682
11738
  let { data: frontMatterData } = await this.getFrontMatterData();
@@ -11693,17 +11749,14 @@ var Template = class _Template extends TemplateContent_default {
11693
11749
  try {
11694
11750
  let mergedData = (0, import_eleventy_utils20.Merge)({}, globalData, mergedLayoutData, localData, frontMatterData);
11695
11751
  if (this.config.freezeReservedData) {
11696
- ReservedData_default.check(mergedData);
11752
+ ReservedData_default.checkSubset(mergedData);
11697
11753
  }
11698
11754
  await this.addPage(mergedData);
11699
11755
  debugDev4("%o getData mergedData", this.inputPath);
11700
11756
  return mergedData;
11701
11757
  } catch (e) {
11702
- if (ReservedData_default.isReservedDataError(e) || e instanceof TypeError && e.message.startsWith("Cannot add property") && e.message.endsWith("not extensible")) {
11703
- throw new EleventyBaseError_default(
11704
- `You attempted to set one of Eleventy\u2019s reserved data property names${e.reservedNames ? `: ${e.reservedNames.join(", ")}` : ""}. You can opt-out of this behavior with \`eleventyConfig.setFreezeReservedData(false)\` or rename/remove the property in your data cascade that conflicts with Eleventy\u2019s reserved property names (e.g. \`eleventy\`, \`pkg\`, and others). Learn more: https://v3.11ty.dev/docs/data-eleventy-supplied/`,
11705
- e
11706
- );
11758
+ if (!ReservedData_default.isReservedDataError(e) && ReservedData_default.isFrozenError(e)) {
11759
+ throw ReservedData_default.getError({ cause: e });
11707
11760
  }
11708
11761
  throw e;
11709
11762
  }
@@ -11854,7 +11907,7 @@ var Template = class _Template extends TemplateContent_default {
11854
11907
  this
11855
11908
  );
11856
11909
  if (this.config.freezeReservedData) {
11857
- ReservedData_default.check(data[this.config.keys.computed]);
11910
+ ReservedData_default.checkSubset(data[this.config.keys.computed]);
11858
11911
  }
11859
11912
  this._addComputedEntry(this.computedData, data[this.config.keys.computed]);
11860
11913
  debug13("First round of computed data for %o", this.inputPath);
@@ -14395,7 +14448,6 @@ var Benchmark = class {
14395
14448
  return this.timeSpent;
14396
14449
  }
14397
14450
  };
14398
- var Benchmark_default = Benchmark;
14399
14451
 
14400
14452
  // ../../src/Benchmark/BenchmarkGroup.js
14401
14453
  var debugBenchmark = debug_default("Eleventy:Benchmark");
@@ -14418,7 +14470,7 @@ var BenchmarkGroup = class {
14418
14470
  }
14419
14471
  // TODO use addAsync everywhere instead
14420
14472
  add(type, callback) {
14421
- let benchmark = this.benchmarks[type] = new Benchmark_default();
14473
+ let benchmark = this.benchmarks[type] = new Benchmark();
14422
14474
  let fn = function(...args) {
14423
14475
  benchmark.before();
14424
14476
  let ret = callback.call(this, ...args);
@@ -14463,7 +14515,7 @@ var BenchmarkGroup = class {
14463
14515
  }
14464
14516
  get(type) {
14465
14517
  if (!this.benchmarks[type]) {
14466
- this.benchmarks[type] = new Benchmark_default();
14518
+ this.benchmarks[type] = new Benchmark();
14467
14519
  }
14468
14520
  return this.benchmarks[type];
14469
14521
  }