MCPcopy
hub / github.com/zxlie/FeHelper / findReferences

Function findReferences

gulpfile.js:235–267  ·  view source on GitHub ↗
(content, filePath)

Source from the content-addressed store, hash-verified

233 });
234 }
235 function findReferences(content, filePath) {
236 const fileDir = path.dirname(filePath);
237 const patterns = [
238 /['"`][^`'\"]*?([./\w-]+\.(?:js|css|png|jpg|jpeg|gif|svg|woff2?|ttf|eot))['"`]/g,
239 /url\(['"]?([./\w-]+(?:\.(?:png|jpg|jpeg|gif|svg|woff2?|ttf|eot))?)['"]?\)/gi,
240 /@import\s+['"]([^'\"]+\.css)['"];?/gi,
241 /(?:src|href)=['"](chrome-extension:\/\/[^/]+\/)?([^'"?#]+(?:\.(?:js|css|png|jpg|jpeg|gif|svg|woff2?|ttf|eot)))['"]/gi
242 ];
243 patterns.forEach((pattern, index) => {
244 let match;
245 while ((match = pattern.exec(content)) !== null) {
246 let extractedPath = '';
247 if (index === 3) {
248 extractedPath = match[2];
249 } else {
250 extractedPath = match[1];
251 }
252 if (!extractedPath || typeof extractedPath !== 'string') continue;
253 if (shouldExcludeFile(extractedPath)) continue;
254 let finalPathToAdd = '';
255 const isChromeExt = index === 3 && match[1];
256 if (isChromeExt || extractedPath.startsWith('/')) {
257 finalPathToAdd = extractedPath.startsWith('/') ? extractedPath.slice(1) : extractedPath;
258 } else {
259 const absolutePath = path.resolve(fileDir, extractedPath);
260 finalPathToAdd = path.relative(outputDir, absolutePath);
261 }
262 if (finalPathToAdd && !shouldExcludeFile(finalPathToAdd)) {
263 referencedFiles.add(finalPathToAdd.replace(/\\/g, '/'));
264 }
265 }
266 });
267 }
268 function processManifest() {
269 const manifestPath = path.join(outputDir, 'manifest.json');
270 if (fs.existsSync(manifestPath)) {

Callers 2

runTestsFunction · 0.85
detectUnusedFilesFunction · 0.85

Calls 2

shouldExcludeFileFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected