vite-plugin-sri4 1.8.1 → 1.8.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/dist/index.cjs CHANGED
@@ -87,11 +87,23 @@ function getAllPossiblePaths(url) {
87
87
  url.replace(/^static\//, '')
88
88
  ];
89
89
 
90
- const withoutHash = url.replace(/-[a-zA-Z0-9]+\./, '.');
90
+ // Handle Vite's hashed filenames (e.g., index-DPifqqS2.js -> index.js)
91
+ const withoutHash = url.replace(/-[a-zA-Z0-9]{8}\./, '.');
91
92
  if (withoutHash !== url) {
92
93
  paths.push(...getAllPossiblePaths(withoutHash));
93
94
  }
94
95
 
96
+ // Handle variations with and without /static/ prefix for hashed files
97
+ const hashedMatch = url.match(/^(?:\/static\/)?(.*?)-[a-zA-Z0-9]{8}(\..*?)$/);
98
+ if (hashedMatch) {
99
+ const [, base, ext] = hashedMatch;
100
+ paths.push(
101
+ `${base}${ext}`,
102
+ `/static/${base}${ext}`,
103
+ `static/${base}${ext}`
104
+ );
105
+ }
106
+
95
107
  return [...new Set(paths)];
96
108
  }
97
109
 
@@ -140,6 +152,9 @@ async function processTag(tag, url, options, sriMap) {
140
152
  let integrity = null;
141
153
 
142
154
  log(`Checking possible paths for ${url}:`, options);
155
+ log(`Possible paths:`, options);
156
+ possiblePaths.forEach(path => log(` - ${path}`, options));
157
+
143
158
  for (const path of possiblePaths) {
144
159
  log(`- Checking path: ${path}`, options);
145
160
  if (sriMap.has(path)) {
package/dist/index.js CHANGED
@@ -85,11 +85,23 @@ function getAllPossiblePaths(url) {
85
85
  url.replace(/^static\//, '')
86
86
  ];
87
87
 
88
- const withoutHash = url.replace(/-[a-zA-Z0-9]+\./, '.');
88
+ // Handle Vite's hashed filenames (e.g., index-DPifqqS2.js -> index.js)
89
+ const withoutHash = url.replace(/-[a-zA-Z0-9]{8}\./, '.');
89
90
  if (withoutHash !== url) {
90
91
  paths.push(...getAllPossiblePaths(withoutHash));
91
92
  }
92
93
 
94
+ // Handle variations with and without /static/ prefix for hashed files
95
+ const hashedMatch = url.match(/^(?:\/static\/)?(.*?)-[a-zA-Z0-9]{8}(\..*?)$/);
96
+ if (hashedMatch) {
97
+ const [, base, ext] = hashedMatch;
98
+ paths.push(
99
+ `${base}${ext}`,
100
+ `/static/${base}${ext}`,
101
+ `static/${base}${ext}`
102
+ );
103
+ }
104
+
93
105
  return [...new Set(paths)];
94
106
  }
95
107
 
@@ -138,6 +150,9 @@ async function processTag(tag, url, options, sriMap) {
138
150
  let integrity = null;
139
151
 
140
152
  log(`Checking possible paths for ${url}:`, options);
153
+ log(`Possible paths:`, options);
154
+ possiblePaths.forEach(path => log(` - ${path}`, options));
155
+
141
156
  for (const path of possiblePaths) {
142
157
  log(`- Checking path: ${path}`, options);
143
158
  if (sriMap.has(path)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-sri4",
3
- "version": "1.8.1",
3
+ "version": "1.8.2",
4
4
  "description": "A Vite plugin to generate Subresource Integrity (SRI) hashes for output files.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",