Skip to content

Commit

Permalink
Modified for use with less.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-Dax committed Feb 11, 2017
1 parent 0613459 commit a068a36
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
21 changes: 7 additions & 14 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
### detective-sass [![npm](http://img.shields.io/npm/v/detective-sass.svg)](https://npmjs.org/package/detective-sass) [![npm](http://img.shields.io/npm/dm/detective-sass.svg)](https://npmjs.org/package/detective-sass)
### detective-less [![npm](http://img.shields.io/npm/v/detective-less.svg)](https://npmjs.org/package/detective-less) [![npm](http://img.shields.io/npm/dm/detective-less.svg)](https://npmjs.org/package/detective-less)

> Find the dependencies of a sass file
> Find the dependencies of a less file
`npm install --save detective-sass`
`npm install --save detective-less`

**Note:** This is specific to the .sass style syntax of the Sass preprocessor. For SCSS support, please see [node-detective-scss](https://github.com/dependents/node-detective-scss)

It's the SASS counterpart to [detective](https://github.com/substack/node-detective), [detective-amd](https://github.com/mrjoelkemp/node-detective-amd), and [detective-es6](https://github.com/mrjoelkemp/node-detective-es6).
This is a fork of a package by [mrjoelkemp](https://github.com/mrjoelkemp/) given a lack of a less detective, it is the counterpart to [detective](https://github.com/substack/node-detective), [detective-amd](https://github.com/mrjoelkemp/node-detective-amd), [detective-sass](https://github.com/mrjoelkemp/node-detective-sass), [detective-scss](https://github.com/mrjoelkemp/node-detective-scss) and [detective-es6](https://github.com/mrjoelkemp/node-detective-es6).

* The AST is generated using the [gonzales-pe](https://github.com/tonyganch/gonzales-pe) parser.

### Usage

```js
var detective = require('detective-sass');
var detective = require('detective-less');

var content = fs.readFileSync('styles.sass', 'utf8');
var content = fs.readFileSync('styles.less', 'utf8');

// list of imported file names (ex: '_foo.sass', '_foo', etc)
// list of imported file names (ex: 'foo.less', 'foo', etc)
var dependencies = detective(content);
```

### Related

* [node-sass-lookup](https://github.com/dependents/node-sass-lookup) if you want to map a sass/scss dependency to a file on your filesystem.
* [node-precinct](https://github.com/dependents/node-precinct) if you want to also support finding dependencies for JavaScript and other languages.

### License

MIT
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var Walker = require('node-source-walk');
var sass = require('gonzales-pe');
var debug = require('debug')('detective-sass');
var gonzales = require('gonzales-pe');
var debug = require('debug')('detective-less');

/**
* Extract the @import statements from a given sass file's content
* Extract the @import statements from a given less file's content
*
* @param {String} fileContent
* @return {String[]}
Expand All @@ -17,7 +17,7 @@ module.exports = function detective(fileContent) {

try {
debug('content: ' + fileContent);
ast = sass.parse(fileContent, { syntax: 'sass' });
ast = gonzales.parse(fileContent, { syntax: 'less' });
} catch (e) {
debug('parse error: ', e.message);
ast = {};
Expand Down
23 changes: 15 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
{
"name": "detective-sass",
"version": "2.0.0",
"description": "Find the dependencies of a sass file",
"name": "detective-less",
"version": "1.0.0",
"description": "Find the dependencies of a less file",
"main": "index.js",
"scripts": {
"test": "mocha test/test.js"
},
"repository": {
"type": "git",
"url": "https://github.com/mrjoelkemp/node-detective-sass.git"
"url": "https://github.com/Mike-Dax/node-detective-less.git"
},
"keywords": [
"detective",
"sass",
"less",
"ast",
"dependencies"
],
"author": "Joel Kemp <joel@mrjoelkemp.com>",
"contributors": [{
"name": "Joel Kemp",
"email": "joel@mrjoelkemp.com"
},
{
"name": "Michael Orenstein",
"email": "michael@whiteshadows.me"
}],
"license": "MIT",
"bugs": {
"url": "https://github.com/mrjoelkemp/node-detective-sass/issues"
"url": "https://github.com/Mike-Dax/node-detective-less/issues"
},
"homepage": "https://github.com/mrjoelkemp/node-detective-sass",
"homepage": "https://github.com/Mike-Dax/node-detective-less",
"devDependencies": {
"mocha": "~2.0.1"
},
Expand Down
10 changes: 5 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var detective = require('../');
var assert = require('assert');

describe('detective-sass', function() {
describe('detective-less', function() {
function test(src, deps, opts) {
assert.deepEqual(detective(src, opts), deps);
}
Expand Down Expand Up @@ -33,7 +33,7 @@ describe('detective-sass', function() {
});

it('dangles the parsed AST', function() {
detective('@import "_foo.sass";');
detective('@import "foo.less";');
assert.ok(detective.ast);
});

Expand All @@ -45,9 +45,9 @@ describe('detective-sass', function() {
});

describe('sass', function() {
it('returns the dependencies of the given .sass file content', function() {
test('@import _foo', ['_foo']);
test('@import _foo', ['_foo']);
it('returns the dependencies of the given .less file content', function() {
test('@import foo', ['foo']);
test('@import foo', ['foo']);
test('@import reset', ['reset']);
});
});
Expand Down

0 comments on commit a068a36

Please sign in to comment.