Skip to content

Commit

Permalink
Adds support for less styling
Browse files Browse the repository at this point in the history
  • Loading branch information
Havunen committed Oct 19, 2024
1 parent 75b3e02 commit bddd3ad
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const detectiveEs6 = require('detective-es6');
const detectiveScss = require('detective-scss');
const detectiveStylus = require('detective-stylus');
const detectiveSass = require('detective-sass');
const detectiveLess = require('@dependents/detective-less');

function detectiveVue(content, options) {
if (content === undefined) throw new Error('content not given');
Expand All @@ -31,19 +32,25 @@ function detectiveVue(content, options) {
for (const style of styles) {
switch (style.attrs.lang) {
case 'scss': {
dependencies.push(...detectiveScss(style.content));
dependencies.push(...detectiveScss(style.content, options));

break;
}

case 'stylus': {
dependencies.push(...detectiveStylus(style.content));
dependencies.push(...detectiveStylus(style.content, options));

break;
}

case 'sass': {
dependencies.push(...detectiveSass(style.content));
dependencies.push(...detectiveSass(style.content, options));

break;
}

case 'less': {
dependencies.push(...detectiveLess(style.content, options));

break;
}
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"typescript": "^5.4.4"
},
"dependencies": {
"@dependents/detective-less": "^5.0.0",
"@vue/compiler-sfc": "^3.5.12",
"detective-es6": "^5.0.0",
"detective-sass": "^6.0.0",
Expand Down
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ describe('detective-vue2', () => {
assert.equal(deps[1], 'vars.scss');
});

it('retrieves the dependencies of less and script block lang js', () => {
const deps = detective('<template></template> <script>import {foo, bar} from "mylib"; </script> <style lang="less">@import \'vars.scss\' </style>');
assert.equal(deps.length, 2);
assert.equal(deps[0], 'mylib');
assert.equal(deps[1], 'vars.scss');
});

it('retrieves the dependencies of script block lang ts using setup syntax', () => {
const deps = detective(`<script lang="ts" setup>
import { foo, bar } from "mylib";
Expand Down

0 comments on commit bddd3ad

Please sign in to comment.