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.
Files changed (3) hide show
  1. package/README.md +11 -7
  2. package/index.js +38 -29
  3. package/package.json +56 -13
package/README.md CHANGED
@@ -1,23 +1,27 @@
1
- > Get the dependencies of Vue module
1
+ # detective-vue2
2
+
3
+ [![CI](https://img.shields.io/github/actions/workflow/status/havunen/detective-vue2/ci.yml?branch=main&label=CI&logo=github)](https://github.com/havunen/detective-vue2/actions/workflows/ci.yml?query=branch%3Amain)
4
+ [![npm version](https://img.shields.io/npm/v/detective-vue2?logo=npm&logoColor=fff)](https://www.npmjs.com/package/detective-vue2)
5
+ [![npm downloads](https://img.shields.io/npm/dm/detective-vue2)](https://www.npmjs.com/package/detective-vue2)
2
6
 
3
- Supports Vue2 and Vue3
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 mySourceCode = fs.readFileSync('myfile.vue', 'utf8');
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(mySourceCode);
22
+ const dependencies = detective(content);
19
23
  ```
20
24
 
21
- #### License
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 vueDetective(fileContent, opts) {
14
- if (typeof fileContent === 'undefined') throw new Error('content not given');
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.styles;
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 && script.content) {
24
- if (script.attrs && script.attrs.lang === 'ts') {
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
- for (let i = 0; i < styles.length; i++) {
33
- const style = styles[i];
34
- const styleLan = style.attrs.lang;
35
-
36
- if (styleLan === 'scss') {
37
- dependencies.push(...detectiveScss(style.content))
38
- } else if (styleLan === 'stylus') {
39
- dependencies.push(...detectiveStylus(style.content))
40
- } else if (styleLan === 'sass') {
41
- dependencies.push(...detectiveSass(style.content))
42
- } else {
43
- // css has no deps
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": "1.0.1",
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": "eslint index.js test/test.js",
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": "^12.20.0 || ^14.14.0 || >=16.0.0"
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": ">=3",
35
- "detective-es6": ">=4",
36
- "detective-sass": ">=5",
37
- "detective-scss": ">=4",
38
- "detective-stylus": ">=4",
39
- "detective-typescript": ">=11"
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
- "eslint": "^8.48.0",
43
- "mocha": "^10.2.0"
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
  }