vite-plugin-twig-drupal 1.1.0 โ†’ 1.2.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.
@@ -10,6 +10,7 @@ jobs:
10
10
  strategy:
11
11
  matrix:
12
12
  node: [18, 20]
13
+ vite: [4, 5]
13
14
  runs-on: ubuntu-latest
14
15
  steps:
15
16
  - name: ๐Ÿ›‘ Cancel Previous Runs
@@ -28,6 +29,9 @@ jobs:
28
29
  with:
29
30
  useLockFile: false
30
31
 
32
+ - name: โšก๏ธ Setup vite
33
+ run: npm install vite@${{ matrix.vite }}
34
+
31
35
  - name: ๐Ÿงน Linting
32
36
  run: npm run lint
33
37
 
package/README.md CHANGED
@@ -90,7 +90,17 @@ export default defineConfig({
90
90
  },
91
91
  // Optional if you are using React storybook renderer. The default is 'html' and works with storybook's html
92
92
  // renderer.
93
- // framework: 'react'
93
+ // framework: 'react'
94
+ functions: {
95
+ // You can add custom functions - each is a function that is passed the active Twig instance and should call
96
+ // e.g. extendFunction to register a function
97
+ reverse: (twigInstance) => twigInstance.extendFunction("reverse", () => (text) => text.split(' ').reverse().join(' ')),
98
+ },
99
+ globalContext: {
100
+ // Global variables that should be present in all templates.
101
+ active_theme: 'my_super_theme',
102
+ is_front_page: false,
103
+ },
94
104
  }),
95
105
  // Other vite plugins.
96
106
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-twig-drupal",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Provides a โšก๏ธ Vite plugin to transform ๐ŸŒฑ Twig into HTML with a ๐Ÿ’ง Drupal flavour",
5
5
  "keywords": [
6
6
  "Vite",
@@ -31,12 +31,12 @@
31
31
  "twig": "^1.16.0"
32
32
  },
33
33
  "peerDependencies": {
34
- "vite": "^4.4.11"
34
+ "vite": "^4.4.11 || ^5"
35
35
  },
36
36
  "devDependencies": {
37
37
  "prettier": "^3.0.3",
38
38
  "semantic-release": "^22.0.5",
39
- "vite": "^4.4.11",
39
+ "vite": "^4.4.11 || ^ 5",
40
40
  "vitest": "^0.34.6"
41
41
  }
42
42
  }
package/src/index.js CHANGED
@@ -194,6 +194,8 @@ const plugin = (options = {}) => {
194
194
 
195
195
  ${functions}
196
196
 
197
+ addDrupalExtensions(Twig);
198
+
197
199
  // Disable caching.
198
200
  Twig.cache(false);
199
201
 
@@ -1,5 +1,10 @@
1
1
  // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
+ exports[`Basic smoke test > Should recognise default Drupal functions 1`] = `
4
+ "
5
+ <p>Functions work</p>"
6
+ `;
7
+
3
8
  exports[`Basic smoke test > Should support global context and functions 1`] = `
4
9
  "<section>
5
10
  <h1>Include</h1>
@@ -0,0 +1,2 @@
1
+ {{ attach_library('drupal/library') }}
2
+ <p>Functions work</p>
@@ -1,6 +1,7 @@
1
1
  import Markup from "../dist/test.js"
2
2
  import Error from "../dist/error.js"
3
3
  import ErrorInclude from "../dist/errorInclude.js"
4
+ import drupalFunctions from "../dist/drupalFunctions.js"
4
5
  import Menu from "../dist/menu.js"
5
6
  import { describe, expect, it } from "vitest"
6
7
 
@@ -35,4 +36,9 @@ describe("Basic smoke test", () => {
35
36
  expect(markup).toContain("Nested include")
36
37
  expect(markup).toContain("IT WORKS!")
37
38
  })
39
+ it("Should recognise default Drupal functions", () => {
40
+ const markup = drupalFunctions()
41
+ expect(markup).toMatchSnapshot()
42
+ expect(markup).toContain("Functions work")
43
+ })
38
44
  })
package/vite.config.js CHANGED
@@ -11,6 +11,10 @@ export default defineConfig({
11
11
  error: resolve(__dirname, "tests/fixtures/error.twig"),
12
12
  menu: resolve(__dirname, "tests/fixtures/menu.twig"),
13
13
  errorInclude: resolve(__dirname, "tests/fixtures/error-include.twig"),
14
+ drupalFunctions: resolve(
15
+ __dirname,
16
+ "tests/fixtures/drupal-functions.twig"
17
+ ),
14
18
  },
15
19
  name: "vite-plugin-twig-drupal",
16
20
  fileName: (_, entry) => `${entry}.js`,