detective-vue2 1.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 +23 -0
- package/index.js +59 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
> Get the dependencies of Vue module
|
|
2
|
+
|
|
3
|
+
Supports Vue2 and Vue3
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install detective-vue2
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
### Usage
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const detective = require('detective-vue2');
|
|
14
|
+
|
|
15
|
+
const mySourceCode = fs.readFileSync('myfile.vue', 'utf8');
|
|
16
|
+
|
|
17
|
+
// Pass in a file's content or an AST
|
|
18
|
+
const dependencies = detective(mySourceCode);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
#### License
|
|
22
|
+
|
|
23
|
+
MIT
|
package/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
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')
|
|
9
|
+
|
|
10
|
+
const isVue3 = typeof compiler.parseComponent === 'undefined';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Extracts the dependencies of the supplied Vue module
|
|
14
|
+
*/
|
|
15
|
+
module.exports = function vueDetective(fileContent, opts) {
|
|
16
|
+
if (typeof fileContent === 'undefined') throw new Error('content not given');
|
|
17
|
+
if (typeof fileContent !== 'string') throw new Error('content is not a string');
|
|
18
|
+
|
|
19
|
+
let script, styles;
|
|
20
|
+
|
|
21
|
+
if (isVue3) {
|
|
22
|
+
const result = compiler.parse(fileContent, {sourceMap: false})
|
|
23
|
+
styles = result.descriptor.styles;
|
|
24
|
+
script = result.descriptor.script;
|
|
25
|
+
} else {
|
|
26
|
+
const result = compiler.parse({source: fileContent, sourceMap: false})
|
|
27
|
+
styles = result.styles;
|
|
28
|
+
script = result.script;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const dependencies = [];
|
|
32
|
+
|
|
33
|
+
if (script && script.content) {
|
|
34
|
+
if (script.attrs && script.attrs.lang === 'ts') {
|
|
35
|
+
dependencies.push(...detectiveTypeScript(script.content, opts))
|
|
36
|
+
} else {
|
|
37
|
+
dependencies.push(...detectiveEs6(script.content, opts))
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (styles) {
|
|
42
|
+
for (let i = 0; i < styles.length; i++) {
|
|
43
|
+
const style = styles[i];
|
|
44
|
+
const styleLan = style.attrs.lang;
|
|
45
|
+
|
|
46
|
+
if (styleLan === 'scss') {
|
|
47
|
+
dependencies.push(...detectiveScss(style.content))
|
|
48
|
+
} else if (styleLan === 'stylus') {
|
|
49
|
+
dependencies.push(...detectiveStylus(style.content))
|
|
50
|
+
} else if (styleLan === 'sass') {
|
|
51
|
+
dependencies.push(...detectiveSass(style.content))
|
|
52
|
+
} else {
|
|
53
|
+
// css has no deps
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return dependencies;
|
|
59
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "detective-vue2",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"author": "Havunen <sampo.kivisto@live.fi>",
|
|
5
|
+
"description": "Get the dependencies of a Vue module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.js"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"lint": "eslint index.js test/test.js",
|
|
12
|
+
"mocha": "mocha",
|
|
13
|
+
"test": "npm run lint && npm run mocha",
|
|
14
|
+
"watch": "npm run mocha -- -w"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/havunen/detective-vue2.git"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"detective",
|
|
22
|
+
"dependencies",
|
|
23
|
+
"module",
|
|
24
|
+
"ast",
|
|
25
|
+
"import",
|
|
26
|
+
"vue"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": "^12.20.0 || ^14.14.0 || >=16.0.0"
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"homepage": "https://github.com/dependents/detective-typescript",
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@vue/compiler-sfc": ">= 2 < 4"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"detective-es6": "^3.0.0",
|
|
38
|
+
"detective-sass": "^4.0.1",
|
|
39
|
+
"detective-scss": "^3.0.0",
|
|
40
|
+
"detective-stylus": "^2.0.1",
|
|
41
|
+
"detective-typescript": "^9.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"eslint": "^8.34.0",
|
|
45
|
+
"mocha": "^10.2.0",
|
|
46
|
+
"@vue/compiler-sfc": "^2.7.14"
|
|
47
|
+
}
|
|
48
|
+
}
|