detective-sass
Advanced tools
Comparing version 4.0.1 to 4.1.0
26
index.js
@@ -13,8 +13,12 @@ 'use strict'; | ||
* @param {String} fileContent | ||
* @param {Object} options | ||
* @param {Boolean} options.url - detect any url() references to images, fonts, etc. | ||
* @return {String[]} | ||
*/ | ||
module.exports = function detective(fileContent) { | ||
module.exports = function detective(fileContent, options) { | ||
if (typeof fileContent === 'undefined') throw new Error('content not given'); | ||
if (typeof fileContent !== 'string') throw new Error('content is not a string'); | ||
const isEnabledUrl = options && options.url; | ||
let dependencies = []; | ||
@@ -35,5 +39,11 @@ let ast = {}; | ||
walker.walk(ast, (node) => { | ||
if (!isImportStatement(node)) return; | ||
if (isImportStatement(node)) { | ||
dependencies = dependencies.concat(extractDependencies(node)); | ||
return; | ||
} | ||
dependencies = dependencies.concat(extractDependencies(node)); | ||
if (isEnabledUrl && isUrlNode(node)) { | ||
dependencies = dependencies.concat(extractUriDependencies(node)); | ||
return; | ||
} | ||
}); | ||
@@ -64,1 +74,11 @@ | ||
} | ||
function isUrlNode(node) { | ||
return node.type === 'uri'; | ||
} | ||
function extractUriDependencies(importStatementNode) { | ||
return importStatementNode.content | ||
.filter((innerNode) => innerNode.type === 'string' || innerNode.type === 'ident' || innerNode.type === 'raw') | ||
.map((identifierNode) => identifierNode.content.replace(/["']/g, '')); | ||
} |
{ | ||
"name": "detective-sass", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"description": "Find the dependencies of a sass file", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -25,2 +25,5 @@ ### detective-sass [![CI](https://img.shields.io/github/workflow/status/dependents/node-detective-sass/CI/main?label=CI&logo=github)](https://github.com/dependents/node-detective-sass/actions/workflows/ci.yml?query=branch%3Amain) [![npm](https://img.shields.io/npm/v/detective-sass)](https://www.npmjs.com/package/detective-sass) [![npm](https://img.shields.io/npm/dm/detective-sass)](https://www.npmjs.com/package/detective-sass) | ||
const dependencies = detective(content); | ||
// or to also detect any url() references to images, fonts, etc. | ||
const allDependencies = detective(content, { url: true }); | ||
``` | ||
@@ -27,0 +30,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6058
61
38