vite-plugin-twig-drupal 1.6.0 → 1.6.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-twig-drupal",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "Provides a ⚡️ Vite plugin to transform 🌱 Twig into HTML with a 💧 Drupal flavour",
5
5
  "keywords": [
6
6
  "Vite",
package/src/index.js CHANGED
@@ -171,7 +171,7 @@ const plugin = (options = {}) => {
171
171
  functions,
172
172
  code,
173
173
  includes,
174
- seen = []
174
+ seen = {}
175
175
 
176
176
  try {
177
177
  const result = await compileTemplate(id, id, options).catch(
@@ -183,31 +183,36 @@ const plugin = (options = {}) => {
183
183
  }
184
184
  code = result.code
185
185
  includes = result.includes
186
- const includePromises = []
187
- const processIncludes = (template) => {
188
- const file = resolveFile(
189
- dirname(id),
190
- resolveNamespaceOrComponent(options.namespaces, template)
191
- )
192
- if (!seen.includes(template)) {
193
- includePromises.push(
194
- new Promise(async (resolve, reject) => {
195
- const { includes, code } = await compileTemplate(
196
- template,
197
- file,
198
- options
199
- ).catch(errorHandler(template, false))
200
- if (includes) {
201
- includes.forEach(processIncludes)
186
+
187
+ // Process includes in a queue.
188
+ const promisifyIncludes = (includes) => {
189
+ return includes.reduce(
190
+ (queue, template) =>
191
+ queue.then(() => {
192
+ const file = resolveFile(
193
+ dirname(id),
194
+ resolveNamespaceOrComponent(options.namespaces, template)
195
+ )
196
+ if (!(template in seen)) {
197
+ return compileTemplate(template, file, options)
198
+ .catch(errorHandler(template, false))
199
+ .then(({ code, includes }) => {
200
+ seen[template] = code
201
+ if (!includes) {
202
+ return Promise.resolve()
203
+ }
204
+ return promisifyIncludes(includes)
205
+ })
202
206
  }
203
- resolve(code)
204
- })
205
- )
206
- seen.push(template)
207
- }
207
+ return Promise.resolve()
208
+ }),
209
+ Promise.resolve()
210
+ )
208
211
  }
209
- includes.forEach(processIncludes)
210
- embed = includes
212
+ const includeResult = await promisifyIncludes(includes).catch(
213
+ errorHandler(id)
214
+ )
215
+ embed = Object.keys(seen)
211
216
  .filter((template) => template !== "_self")
212
217
  .map(
213
218
  (template) =>
@@ -227,14 +232,11 @@ const plugin = (options = {}) => {
227
232
  })
228
233
  .join("\n")
229
234
 
230
- const includeResult = await Promise.all(includePromises).catch(
231
- errorHandler(id)
232
- )
233
- if (!Array.isArray(includeResult) && "map" in includeResult) {
235
+ if (includeResult !== undefined && "map" in includeResult) {
234
236
  // An error occurred.
235
237
  return includeResult
236
238
  }
237
- embeddedIncludes = includeResult.reverse().join("\n")
239
+ embeddedIncludes = Object.values(seen).reverse().join("\n")
238
240
  } catch (e) {
239
241
  return errorHandler(id)(e)
240
242
  }
@@ -38,6 +38,8 @@ exports[`Basic smoke test > Should cast default attributes to attributes 1`] = `
38
38
  <div>atom badge from nested dir 🙌</div>
39
39
  <button>nested button 🙌</button>
40
40
  <div class=\\"ponies\\">hey there</div>
41
+ All received
42
+ pony town
41
43
  "
42
44
  `;
43
45
 
@@ -84,6 +86,8 @@ exports[`Basic smoke test > Should support default attributes as a map 1`] = `
84
86
  <div>atom badge from nested dir 🙌</div>
85
87
  <button>nested button 🙌</button>
86
88
  <div class=\\"ponies\\">hey there</div>
89
+ All received
90
+ pony town
87
91
  "
88
92
  `;
89
93
 
@@ -125,6 +129,8 @@ exports[`Basic smoke test > Should support global context and functions 1`] = `
125
129
  <div>atom badge from nested dir 🙌</div>
126
130
  <button>nested button 🙌</button>
127
131
  <div >hey there</div>
132
+ All received
133
+ pony town
128
134
  "
129
135
  `;
130
136
 
@@ -166,6 +172,8 @@ exports[`Basic smoke test > Should support includes 1`] = `
166
172
  <div>atom badge from nested dir 🙌</div>
167
173
  <button>nested button 🙌</button>
168
174
  <div >hey there</div>
175
+ All received
176
+ pony town
169
177
  "
170
178
  `;
171
179
 
@@ -224,6 +232,8 @@ exports[`Basic smoke test > Should support nested SDC 1`] = `
224
232
  <div>atom badge from nested dir 🙌</div>
225
233
  <button>nested button 🙌</button>
226
234
  <div >hey there</div>
235
+ All received
236
+ pony town
227
237
  "
228
238
  `;
229
239
 
@@ -265,5 +275,7 @@ exports[`Basic smoke test > Should support variables 1`] = `
265
275
  <div>atom badge from nested dir 🙌</div>
266
276
  <button>nested button 🙌</button>
267
277
  <div >hey there</div>
278
+ All received
279
+ pony town
268
280
  "
269
281
  `;
@@ -0,0 +1 @@
1
+ {{ title }}
@@ -0,0 +1,7 @@
1
+ {% if variant == 'roger' %}
2
+ All received
3
+ {% else %}
4
+ Not hearing you
5
+ {% endif %}
6
+ {% block content %}
7
+ {% endblock %}
@@ -0,0 +1,5 @@
1
+ {% set variant = 'roger' %}
2
+ {% extends "extend-me.twig" %}
3
+ {% block content %}
4
+ {% include "field.twig" %}
5
+ {% endblock %}
@@ -0,0 +1,2 @@
1
+ {% set title = "pony town" %}
2
+ {% extends "extend-level2.twig" %}
@@ -27,3 +27,4 @@
27
27
  teaser: '🏆️ winning',
28
28
  } %}
29
29
  <div {{ attributes }}>hey there</div>
30
+ {% include "extender.twig" %}
@@ -67,4 +67,9 @@ describe("Basic smoke test", () => {
67
67
  expect(markup).toContain('class="ponies"')
68
68
  expect(markup).toContain("hey there")
69
69
  })
70
+ it("Should support extends", () => {
71
+ const markup = Markup()
72
+ expect(markup).toContain("All received")
73
+ expect(markup).toContain("pony town")
74
+ })
70
75
  })