vite-plugin-twig-drupal 1.6.0 → 1.6.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.
- package/.github/workflows/node.js.yml +1 -1
- package/package.json +2 -2
- package/src/index.js +31 -29
- package/tests/__snapshots__/smoke.test.js.snap +12 -0
- package/tests/fixtures/extend-level2.twig +1 -0
- package/tests/fixtures/extend-me.twig +7 -0
- package/tests/fixtures/extender.twig +5 -0
- package/tests/fixtures/field.twig +2 -0
- package/tests/fixtures/mockup.twig +1 -0
- package/tests/smoke.test.js +5 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-twig-drupal",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "Provides a ⚡️ Vite plugin to transform 🌱 Twig into HTML with a 💧 Drupal flavour",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Vite",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"twig": "^1.16.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"vite": "^4.4.11 || ^5 || ^6"
|
|
34
|
+
"vite": "^4.4.11 || ^5 || ^6 || ^7"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"prettier": "^3.0.3",
|
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
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
file,
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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(
|
|
204
|
-
})
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
}
|
|
207
|
+
return Promise.resolve()
|
|
208
|
+
}),
|
|
209
|
+
Promise.resolve()
|
|
210
|
+
)
|
|
208
211
|
}
|
|
209
|
-
includes.
|
|
210
|
-
|
|
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
|
-
|
|
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 =
|
|
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 }}
|
package/tests/smoke.test.js
CHANGED
|
@@ -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
|
})
|