@plaudit/webpack-extensions 2.24.0 → 2.24.2

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.
@@ -160,16 +160,26 @@ class BlockJSONManagingPlugin {
160
160
  }
161
161
  else {
162
162
  let validTemplateLocation, invalidTemplateLocation;
163
- if (!json["acf"] && (json["plaudit"] === "native" || (typeof json["plaudit"] === 'object' && json["plaudit"]?.["type"] === "native"))) {
163
+ if (json["acf"] || (json["plaudit"] && (json["plaudit"] !== "native" && (typeof json["plaudit"] !== 'object' || json["plaudit"]?.["type"] !== "native")))) {
164
+ // ACF-like blocks need to have the template stored in render_template.
165
+ // Because we can statically detect ACF-like blocks, we can make the move here instead of at run-time.
166
+ validTemplateLocation = "render_template";
167
+ invalidTemplateLocation = "render";
168
+ }
169
+ else {
164
170
  validTemplateLocation = "render";
165
171
  invalidTemplateLocation = "render_template";
166
172
  }
173
+ delete json[invalidTemplateLocation];
174
+ if (renderTemplate.length > 1) {
175
+ const error = new webpack_1.WebpackError("Encountered a block with multiple possible render files");
176
+ error.file = node_path_1.default.join(sourceDir, 'block.json');
177
+ compilation.warnings.push(error);
178
+ json[validTemplateLocation] = renderTemplate.find(p => p.endsWith(".php")) ?? renderTemplate[0];
179
+ }
167
180
  else {
168
- validTemplateLocation = "render_template";
169
- invalidTemplateLocation = "render";
181
+ json[validTemplateLocation] = renderTemplate[0];
170
182
  }
171
- delete json[invalidTemplateLocation];
172
- json[validTemplateLocation] = renderTemplate.length === 1 ? renderTemplate[0] : renderTemplate;
173
183
  }
174
184
  compilation.updateAsset(name, new webpack_1.sources.RawSource(JSON.stringify(json, undefined, " ")));
175
185
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.24.0",
3
+ "version": "2.24.2",
4
4
  "scripts": {
5
5
  "prepublishOnly": "rm -rf build && mkdir build && tsc",
6
6
  "build": "tsc",