vite-plugin-twig-drupal 1.6.2 โ†’ 1.6.4

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.
@@ -0,0 +1,40 @@
1
+ name: validate
2
+ on:
3
+ pull_request: {}
4
+ jobs:
5
+ main:
6
+ strategy:
7
+ matrix:
8
+ node: [18, 20, 22]
9
+ vite: [4, 5, 6, 7, 8]
10
+ exclude:
11
+ - node: 18
12
+ vite: 7
13
+ - node: 18
14
+ vite: 8
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - name: ๐Ÿ›‘ Cancel Previous Runs
18
+ uses: styfle/cancel-workflow-action@0.9.0
19
+
20
+ - name: โฌ‡๏ธ Checkout repo
21
+ uses: actions/checkout@v2
22
+
23
+ - name: โŽ” Setup node
24
+ uses: actions/setup-node@v2
25
+ with:
26
+ node-version: ${{ matrix.node }}
27
+
28
+ - name: ๐Ÿ“ฅ Download deps
29
+ uses: bahmutov/npm-install@v1
30
+ with:
31
+ useLockFile: false
32
+
33
+ - name: โšก๏ธ Setup vite
34
+ run: npm install vite@${{ matrix.vite }}
35
+
36
+ - name: ๐Ÿงน Linting
37
+ run: npm run lint
38
+
39
+ - name: โœ… Tests
40
+ run: npm run test
@@ -0,0 +1,41 @@
1
+ name: Release
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+
7
+ permissions:
8
+ contents: read # for checkout
9
+
10
+ jobs:
11
+ release:
12
+ name: Release
13
+ runs-on: ubuntu-latest
14
+ permissions:
15
+ contents: write # to be able to publish a GitHub release
16
+ issues: write # to be able to comment on released issues
17
+ pull-requests: write # to be able to comment on released pull requests
18
+ id-token: write # to enable use of OIDC for trusted publishing and npm provenance
19
+ steps:
20
+ - name: Checkout
21
+ uses: actions/checkout@v4
22
+ with:
23
+ fetch-depth: 0
24
+ - name: Setup Node.js
25
+ uses: actions/setup-node@v4
26
+ with:
27
+ node-version: "lts/*"
28
+ - name: Install dependencies
29
+ run: npm install
30
+ - name: Verify the integrity of provenance attestations and registry signatures for installed dependencies
31
+ run: npm audit signatures
32
+ - name: Lint
33
+ run: npm run lint
34
+ - name: Test
35
+ run: npm run test
36
+ - name: Build
37
+ run: npm run build
38
+ - name: Release
39
+ env:
40
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41
+ run: npx semantic-release
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-twig-drupal",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "Provides a โšก๏ธ Vite plugin to transform ๐ŸŒฑ Twig into HTML with a ๐Ÿ’ง Drupal flavour",
5
5
  "keywords": [
6
6
  "Vite",
@@ -18,8 +18,7 @@
18
18
  "format": "prettier --write \"{test,src}/**/*.js\"",
19
19
  "lint": "prettier --check \"{test,src}/**/*.js\"",
20
20
  "test": "vitest run",
21
- "pretest": "npm run-script build",
22
- "semantic-release": "semantic-release"
21
+ "pretest": "npm run-script build"
23
22
  },
24
23
  "repository": {
25
24
  "type": "git",
@@ -31,11 +30,10 @@
31
30
  "twig": "^1.16.0"
32
31
  },
33
32
  "peerDependencies": {
34
- "vite": "^4.4.11 || ^5 || ^6 || ^7"
33
+ "vite": "^4.4.11 || ^5 || ^6 || ^7 || ^8"
35
34
  },
36
35
  "devDependencies": {
37
36
  "prettier": "^3.0.3",
38
- "semantic-release": "^22.0.5",
39
37
  "vite": "^4.4.11 || ^ 5",
40
38
  "vitest": "^0.34.6"
41
39
  }
package/src/index.js CHANGED
@@ -146,9 +146,6 @@ const plugin = (options = {}) => {
146
146
  options.root = root
147
147
  }
148
148
  },
149
- async shouldTransformCachedModule(src, id) {
150
- return options.pattern.test(id)
151
- },
152
149
  async transform(src, id) {
153
150
  if (options.pattern.test(id)) {
154
151
  let frameworkInclude = ""
@@ -189,10 +186,16 @@ const plugin = (options = {}) => {
189
186
  return includes.reduce(
190
187
  (queue, template) =>
191
188
  queue.then(() => {
189
+ // _self is a special Twig variable referring to the current
190
+ // template โ€” it is not a real file import.
191
+ if (template === "_self") {
192
+ return Promise.resolve()
193
+ }
192
194
  const file = resolveFile(
193
195
  dirname(id),
194
196
  resolveNamespaceOrComponent(options.namespaces, template)
195
197
  )
198
+ this.addWatchFile(file)
196
199
  if (!(template in seen)) {
197
200
  return compileTemplate(template, file, options)
198
201
  .catch(errorHandler(template, false))
@@ -134,6 +134,20 @@ exports[`Basic smoke test > Should support global context and functions 1`] = `
134
134
  "
135
135
  `;
136
136
 
137
+ exports[`Basic smoke test > Should support import _self for recursive macros 1`] = `
138
+ "
139
+
140
+ <nav>
141
+ <ul>
142
+ <li><a href=\\"/home\\">Home</a></li>
143
+
144
+ <li><a href=\\"/about\\">About</a></li>
145
+
146
+ </ul>
147
+ </nav>
148
+ "
149
+ `;
150
+
137
151
  exports[`Basic smoke test > Should support includes 1`] = `
138
152
  "<section>
139
153
  <h1>Include</h1>
@@ -0,0 +1,12 @@
1
+ {% import _self as nav %}
2
+
3
+ {% macro menu_link(title, href) %}
4
+ <li><a href="{{ href }}">{{ title }}</a></li>
5
+ {% endmacro %}
6
+
7
+ <nav>
8
+ <ul>
9
+ {{ nav.menu_link('Home', '/home') }}
10
+ {{ nav.menu_link('About', '/about') }}
11
+ </ul>
12
+ </nav>
@@ -3,6 +3,7 @@ import Error from "../dist/error.js"
3
3
  import ErrorInclude from "../dist/errorInclude.js"
4
4
  import drupalFunctions from "../dist/drupalFunctions.js"
5
5
  import Menu from "../dist/menu.js"
6
+ import SelfImport from "../dist/selfImport.js"
6
7
  import { describe, expect, it } from "vitest"
7
8
 
8
9
  describe("Basic smoke test", () => {
@@ -72,4 +73,10 @@ describe("Basic smoke test", () => {
72
73
  expect(markup).toContain("All received")
73
74
  expect(markup).toContain("pony town")
74
75
  })
76
+ it("Should support import _self for recursive macros", () => {
77
+ const markup = SelfImport()
78
+ expect(markup).toContain("Home")
79
+ expect(markup).toContain("About")
80
+ expect(markup).toMatchSnapshot()
81
+ })
75
82
  })
package/vite.config.js CHANGED
@@ -15,8 +15,10 @@ export default defineConfig({
15
15
  __dirname,
16
16
  "tests/fixtures/drupal-functions.twig"
17
17
  ),
18
+ selfImport: resolve(__dirname, "tests/fixtures/self-import.twig"),
18
19
  },
19
20
  name: "vite-plugin-twig-drupal",
21
+ formats: ["es"],
20
22
  fileName: (_, entry) => `${entry}.js`,
21
23
  },
22
24
  },
@@ -1,77 +0,0 @@
1
- name: validate
2
- on:
3
- push:
4
- branches:
5
- - 'main'
6
- - 'beta'
7
- pull_request: {}
8
- jobs:
9
- main:
10
- strategy:
11
- matrix:
12
- node: [18, 20]
13
- vite: [4, 5, 6, 7]
14
- runs-on: ubuntu-latest
15
- steps:
16
- - name: ๐Ÿ›‘ Cancel Previous Runs
17
- uses: styfle/cancel-workflow-action@0.9.0
18
-
19
- - name: โฌ‡๏ธ Checkout repo
20
- uses: actions/checkout@v2
21
-
22
- - name: โŽ” Setup node
23
- uses: actions/setup-node@v2
24
- with:
25
- node-version: ${{ matrix.node }}
26
-
27
- - name: ๐Ÿ“ฅ Download deps
28
- uses: bahmutov/npm-install@v1
29
- with:
30
- useLockFile: false
31
-
32
- - name: โšก๏ธ Setup vite
33
- run: npm install vite@${{ matrix.vite }}
34
-
35
- - name: ๐Ÿงน Linting
36
- run: npm run lint
37
-
38
- - name: โœ… Tests
39
- run: npm run test
40
-
41
- release:
42
- needs: main
43
- runs-on: ubuntu-latest
44
- if:
45
- ${{ github.repository == 'larowlan/vite-plugin-twig-drupal' &&
46
- contains('refs/heads/main',github.ref) && github.event_name == 'push' }}
47
- steps:
48
- - name: ๐Ÿ›‘ Cancel Previous Runs
49
- uses: styfle/cancel-workflow-action@0.9.0
50
-
51
- - name: โฌ‡๏ธ Checkout repo
52
- uses: actions/checkout@v2
53
-
54
- - name: โŽ” Setup node
55
- uses: actions/setup-node@v2
56
- with:
57
- node-version: 18
58
-
59
- - name: ๐Ÿ“ฅ Download deps
60
- uses: bahmutov/npm-install@v1
61
- with:
62
- useLockFile: false
63
-
64
- - name: ๐Ÿ— Run build script
65
- run: npm run build
66
-
67
- - name: ๐Ÿš€ Release
68
- uses: cycjimmy/semantic-release-action@v4
69
- with:
70
- semantic_version: 22
71
- branches: |
72
- [
73
- 'main'
74
- ]
75
- env:
76
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}