()
| 266 | }); |
| 267 | } |
| 268 | function processManifest() { |
| 269 | const manifestPath = path.join(outputDir, 'manifest.json'); |
| 270 | if (fs.existsSync(manifestPath)) { |
| 271 | const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); |
| 272 | const checkManifestField = (obj) => { |
| 273 | if (typeof obj === 'string' && /\.(js|css|png|jpg|jpeg|gif|svg)$/i.test(obj)) { |
| 274 | const normalizedPath = obj.startsWith('/') ? obj.slice(1) : obj; |
| 275 | if (!shouldExcludeFile(normalizedPath)) { |
| 276 | referencedFiles.add(normalizedPath); |
| 277 | } |
| 278 | } else if (Array.isArray(obj)) { |
| 279 | obj.forEach(item => checkManifestField(item)); |
| 280 | } else if (typeof obj === 'object' && obj !== null) { |
| 281 | Object.values(obj).forEach(value => checkManifestField(value)); |
| 282 | } |
| 283 | }; |
| 284 | if (manifest.content_scripts) { |
| 285 | manifest.content_scripts.forEach(script => { |
| 286 | if (script.js) { |
| 287 | script.js.forEach(js => { |
| 288 | const normalizedPath = js.startsWith('/') ? js.slice(1) : js; |
| 289 | referencedFiles.add(normalizedPath); |
| 290 | }); |
| 291 | } |
| 292 | if (script.css) { |
| 293 | script.css.forEach(css => { |
| 294 | const normalizedPath = css.startsWith('/') ? css.slice(1) : css; |
| 295 | referencedFiles.add(normalizedPath); |
| 296 | }); |
| 297 | } |
| 298 | }); |
| 299 | } |
| 300 | checkManifestField(manifest); |
| 301 | } |
| 302 | } |
| 303 | function runTests() { |
| 304 | if (!isSilentDetect) console.log('\n运行单元测试...'); |
| 305 | assert.strictEqual(shouldExcludeFile('path/to/content-script.js'), true, 'Should exclude content-script.js'); |
no test coverage detected