detective-vue2 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -7
- package/index.js +38 -29
- package/package.json +56 -13
package/README.md
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
# detective-vue2
|
|
2
|
+
|
|
3
|
+
[](https://github.com/havunen/detective-vue2/actions/workflows/ci.yml?query=branch%3Amain)
|
|
4
|
+
[](https://www.npmjs.com/package/detective-vue2)
|
|
5
|
+
[](https://www.npmjs.com/package/detective-vue2)
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
> Get the dependencies of Vue module
|
|
8
|
+
> Supports Vue2 and Vue3
|
|
4
9
|
|
|
5
10
|
```sh
|
|
6
11
|
npm install detective-vue2
|
|
7
12
|
```
|
|
8
|
-
|
|
9
|
-
### Usage
|
|
13
|
+
## Usage
|
|
10
14
|
|
|
11
15
|
```js
|
|
12
16
|
const fs = require('fs');
|
|
13
17
|
const detective = require('detective-vue2');
|
|
14
18
|
|
|
15
|
-
const
|
|
19
|
+
const content = fs.readFileSync('myfile.vue', 'utf8');
|
|
16
20
|
|
|
17
21
|
// Pass in a file's content or an AST
|
|
18
|
-
const dependencies = detective(
|
|
22
|
+
const dependencies = detective(content);
|
|
19
23
|
```
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
## License
|
|
22
26
|
|
|
23
27
|
MIT
|
package/index.js
CHANGED
|
@@ -1,49 +1,58 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const compiler = require('@vue/compiler-sfc')
|
|
4
|
-
const detectiveTypeScript = require('detective-typescript')
|
|
5
|
-
const detectiveEs6 = require('detective-es6')
|
|
6
|
-
const detectiveScss = require('detective-scss')
|
|
7
|
-
const detectiveStylus = require('detective-stylus')
|
|
8
|
-
const detectiveSass = require('detective-sass')
|
|
3
|
+
const compiler = require('@vue/compiler-sfc');
|
|
4
|
+
const detectiveTypeScript = require('detective-typescript');
|
|
5
|
+
const detectiveEs6 = require('detective-es6');
|
|
6
|
+
const detectiveScss = require('detective-scss');
|
|
7
|
+
const detectiveStylus = require('detective-stylus');
|
|
8
|
+
const detectiveSass = require('detective-sass');
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Extracts the dependencies of the supplied Vue module
|
|
12
12
|
*/
|
|
13
|
-
module.exports = function
|
|
14
|
-
if (
|
|
13
|
+
module.exports = function(fileContent, opts) {
|
|
14
|
+
if (fileContent === undefined) throw new Error('content not given');
|
|
15
15
|
if (typeof fileContent !== 'string') throw new Error('content is not a string');
|
|
16
16
|
|
|
17
|
-
const result = compiler.parse(fileContent, {sourceMap: false})
|
|
18
|
-
const styles = result.descriptor
|
|
19
|
-
const script = result.descriptor.script;
|
|
17
|
+
const result = compiler.parse(fileContent, { sourceMap: false });
|
|
18
|
+
const { styles, script } = result.descriptor;
|
|
20
19
|
|
|
21
20
|
const dependencies = [];
|
|
22
21
|
|
|
23
|
-
if (script
|
|
24
|
-
if (script.attrs
|
|
25
|
-
dependencies.push(...detectiveTypeScript(script.content, opts))
|
|
22
|
+
if (script?.content) {
|
|
23
|
+
if (script.attrs?.lang === 'ts') {
|
|
24
|
+
dependencies.push(...detectiveTypeScript(script.content, opts));
|
|
26
25
|
} else {
|
|
27
|
-
dependencies.push(...detectiveEs6(script.content, opts))
|
|
26
|
+
dependencies.push(...detectiveEs6(script.content, opts));
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
if (styles)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
if (!styles) return dependencies;
|
|
31
|
+
|
|
32
|
+
for (const style of styles) {
|
|
33
|
+
switch (style.attrs.lang) {
|
|
34
|
+
case 'scss': {
|
|
35
|
+
dependencies.push(...detectiveScss(style.content));
|
|
36
|
+
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
case 'stylus': {
|
|
41
|
+
dependencies.push(...detectiveStylus(style.content));
|
|
42
|
+
|
|
43
|
+
break;
|
|
44
44
|
}
|
|
45
|
+
|
|
46
|
+
case 'sass': {
|
|
47
|
+
dependencies.push(...detectiveSass(style.content));
|
|
48
|
+
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
default:
|
|
53
|
+
// css has no deps
|
|
45
54
|
}
|
|
46
55
|
}
|
|
47
56
|
|
|
48
57
|
return dependencies;
|
|
49
|
-
}
|
|
58
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "detective-vue2",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"author": "Havunen <sampo.kivisto@live.fi>",
|
|
5
5
|
"description": "Get the dependencies of a Vue module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -8,9 +8,11 @@
|
|
|
8
8
|
"index.js"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
|
-
"lint": "
|
|
11
|
+
"lint": "xo",
|
|
12
|
+
"fix": "xo --fix",
|
|
12
13
|
"mocha": "mocha",
|
|
13
14
|
"test": "npm run lint && npm run mocha",
|
|
15
|
+
"test:ci": "c8 npm run mocha",
|
|
14
16
|
"watch": "npm run mocha -- -w"
|
|
15
17
|
},
|
|
16
18
|
"repository": {
|
|
@@ -25,21 +27,62 @@
|
|
|
25
27
|
"import",
|
|
26
28
|
"vue"
|
|
27
29
|
],
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/havunen/detective-vue2/issues"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/havunen/detective-vue2",
|
|
28
35
|
"engines": {
|
|
29
|
-
"node": "
|
|
36
|
+
"node": ">=18"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"typescript": "^5.4.4"
|
|
30
40
|
},
|
|
31
|
-
"license": "MIT",
|
|
32
|
-
"homepage": "https://github.com/dependents/detective-typescript",
|
|
33
41
|
"dependencies": {
|
|
34
|
-
"@vue/compiler-sfc": "
|
|
35
|
-
"detective-es6": "
|
|
36
|
-
"detective-sass": "
|
|
37
|
-
"detective-scss": "
|
|
38
|
-
"detective-stylus": "
|
|
39
|
-
"detective-typescript": "
|
|
42
|
+
"@vue/compiler-sfc": "^3.4.21",
|
|
43
|
+
"detective-es6": "^5.0.0",
|
|
44
|
+
"detective-sass": "^6.0.0",
|
|
45
|
+
"detective-scss": "^5.0.0",
|
|
46
|
+
"detective-stylus": "^5.0.0",
|
|
47
|
+
"detective-typescript": "^13.0.0"
|
|
40
48
|
},
|
|
41
49
|
"devDependencies": {
|
|
42
|
-
"
|
|
43
|
-
"mocha": "^10.
|
|
50
|
+
"c8": "^9.1.0",
|
|
51
|
+
"mocha": "^10.4.0",
|
|
52
|
+
"xo": "^0.58.0"
|
|
53
|
+
},
|
|
54
|
+
"xo": {
|
|
55
|
+
"space": true,
|
|
56
|
+
"ignores": [
|
|
57
|
+
"test/fixtures/*"
|
|
58
|
+
],
|
|
59
|
+
"rules": {
|
|
60
|
+
"arrow-body-style": "off",
|
|
61
|
+
"capitalized-comments": "off",
|
|
62
|
+
"comma-dangle": [
|
|
63
|
+
"error",
|
|
64
|
+
"never"
|
|
65
|
+
],
|
|
66
|
+
"curly": [
|
|
67
|
+
"error",
|
|
68
|
+
"multi-line"
|
|
69
|
+
],
|
|
70
|
+
"operator-linebreak": [
|
|
71
|
+
"error",
|
|
72
|
+
"after"
|
|
73
|
+
],
|
|
74
|
+
"object-curly-spacing": [
|
|
75
|
+
"error",
|
|
76
|
+
"always"
|
|
77
|
+
],
|
|
78
|
+
"space-before-function-paren": [
|
|
79
|
+
"error",
|
|
80
|
+
"never"
|
|
81
|
+
],
|
|
82
|
+
"unicorn/prefer-module": "off",
|
|
83
|
+
"unicorn/prefer-node-protocol": "off",
|
|
84
|
+
"unicorn/prefer-top-level-await": "off",
|
|
85
|
+
"unicorn/prevent-abbreviations": "off"
|
|
86
|
+
}
|
|
44
87
|
}
|
|
45
88
|
}
|