detective-vue2 2.2.0 → 3.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 +10 -2
  2. package/index.js +16 -26
  3. package/package.json +22 -53
package/README.md CHANGED
@@ -12,9 +12,11 @@ npm install detective-vue2 typescript
12
12
 
13
13
  ## Usage
14
14
 
15
+ ### ESM
16
+
15
17
  ```js
16
- const fs = require('fs');
17
- const detective = require('detective-vue2');
18
+ import fs from 'node:fs';
19
+ import detective from 'detective-vue2';
18
20
 
19
21
  const content = fs.readFileSync('myfile.vue', 'utf8');
20
22
 
@@ -22,6 +24,12 @@ const content = fs.readFileSync('myfile.vue', 'utf8');
22
24
  const dependencies = detective(content);
23
25
  ```
24
26
 
27
+ ### CommonJS
28
+
29
+ ```js
30
+ const { default: detective } = require('detective-vue2');
31
+ ```
32
+
25
33
  ## License
26
34
 
27
35
  [MIT](LICENSE)
package/index.js CHANGED
@@ -1,32 +1,28 @@
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
- const detectiveLess = require('@dependents/detective-less');
1
+ import { parse } from '@vue/compiler-sfc';
2
+ import detectiveTypeScript from 'detective-typescript';
3
+ import detectiveEs6 from 'detective-es6';
4
+ import detectiveScss from 'detective-scss';
5
+ import detectiveStylus from 'detective-stylus';
6
+ import detectiveSass from 'detective-sass';
7
+ import detectiveLess from '@dependents/detective-less';
10
8
 
11
9
  /**
12
10
  * Extracts the dependencies of the supplied Vue module
13
11
  */
14
- function detectiveVue(content, options) {
12
+ export default function detective(content, options) {
15
13
  if (content === undefined) throw new Error('content not given');
16
14
  if (typeof content !== 'string') throw new Error('content is not a string');
17
15
 
18
- const result = compiler.parse(content, { sourceMap: false });
19
- const { styles, script, scriptSetup } = result.descriptor;
20
-
16
+ const { styles, script, scriptSetup } = parse(content, { sourceMap: false }).descriptor;
21
17
  const dependencies = [];
22
18
 
23
19
  for (const usedScript of [script, scriptSetup]) {
24
- if (usedScript?.content) {
25
- if (usedScript.attrs?.lang === 'ts') {
26
- dependencies.push(...detectiveTypeScript(usedScript.content, options));
27
- } else {
28
- dependencies.push(...detectiveEs6(usedScript.content, options));
29
- }
20
+ if (!usedScript || !usedScript.content) continue;
21
+
22
+ if (usedScript.attrs && usedScript.attrs.lang === 'ts') {
23
+ dependencies.push(...detectiveTypeScript(usedScript.content, options));
24
+ } else {
25
+ dependencies.push(...detectiveEs6(usedScript.content, options));
30
26
  }
31
27
  }
32
28
 
@@ -36,34 +32,28 @@ function detectiveVue(content, options) {
36
32
  switch (style.attrs.lang) {
37
33
  case 'scss': {
38
34
  dependencies.push(...detectiveScss(style.content, options));
39
-
40
35
  break;
41
36
  }
42
37
 
43
38
  case 'stylus': {
44
39
  dependencies.push(...detectiveStylus(style.content, options));
45
-
46
40
  break;
47
41
  }
48
42
 
49
43
  case 'sass': {
50
44
  dependencies.push(...detectiveSass(style.content, options));
51
-
52
45
  break;
53
46
  }
54
47
 
55
48
  case 'less': {
56
49
  dependencies.push(...detectiveLess(style.content, options));
57
-
58
50
  break;
59
51
  }
60
52
 
61
53
  default:
62
- // css has no deps
54
+ // css has no deps
63
55
  }
64
56
  }
65
57
 
66
58
  return dependencies;
67
59
  }
68
-
69
- module.exports = detectiveVue;
package/package.json CHANGED
@@ -1,19 +1,22 @@
1
1
  {
2
2
  "name": "detective-vue2",
3
- "version": "2.2.0",
3
+ "version": "3.0.0",
4
4
  "author": "Havunen <sampo.kivisto@live.fi>",
5
5
  "description": "Get the dependencies of a Vue module",
6
- "main": "index.js",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": "./index.js"
9
+ },
7
10
  "files": [
8
11
  "index.js"
9
12
  ],
10
13
  "scripts": {
11
14
  "lint": "xo",
12
15
  "fix": "xo --fix",
13
- "mocha": "mocha",
14
- "test": "npm run lint && npm run mocha",
15
- "test:ci": "c8 npm run mocha",
16
- "watch": "npm run mocha -- -w"
16
+ "uvu": "uvu test",
17
+ "test": "npm run lint && npm run uvu",
18
+ "test:ci": "c8 npm run uvu",
19
+ "watch": "node --watch test/test.js"
17
20
  },
18
21
  "repository": {
19
22
  "type": "git",
@@ -33,58 +36,24 @@
33
36
  },
34
37
  "homepage": "https://github.com/dependents/detective-vue2",
35
38
  "engines": {
36
- "node": ">=18"
39
+ "node": ">=20.19.0 || >=22.12.0"
37
40
  },
38
41
  "peerDependencies": {
39
- "typescript": "^5.4.4"
42
+ "typescript": "^5.4.4 || ^6.0.2"
40
43
  },
41
44
  "dependencies": {
42
- "@dependents/detective-less": "^5.0.1",
43
- "@vue/compiler-sfc": "^3.5.13",
44
- "detective-es6": "^5.0.1",
45
- "detective-sass": "^6.0.1",
46
- "detective-scss": "^5.0.1",
47
- "detective-stylus": "^5.0.1",
48
- "detective-typescript": "^14.0.0"
45
+ "@dependents/detective-less": "^6.0.0",
46
+ "@vue/compiler-sfc": "^3.5.34",
47
+ "detective-es6": "^6.0.0",
48
+ "detective-sass": "^7.0.0",
49
+ "detective-scss": "^6.0.0",
50
+ "detective-stylus": "^6.0.0",
51
+ "detective-typescript": "^15.0.0"
49
52
  },
50
53
  "devDependencies": {
51
- "c8": "^10.1.3",
52
- "mocha": "^11.1.0",
53
- "typescript": "^5.7.3",
54
- "xo": "^0.60.0"
55
- },
56
- "xo": {
57
- "space": true,
58
- "ignores": [
59
- "test/fixtures/*"
60
- ],
61
- "rules": {
62
- "arrow-body-style": "off",
63
- "capitalized-comments": "off",
64
- "comma-dangle": [
65
- "error",
66
- "never"
67
- ],
68
- "curly": [
69
- "error",
70
- "multi-line"
71
- ],
72
- "operator-linebreak": [
73
- "error",
74
- "after"
75
- ],
76
- "object-curly-spacing": [
77
- "error",
78
- "always"
79
- ],
80
- "space-before-function-paren": [
81
- "error",
82
- "never"
83
- ],
84
- "unicorn/prefer-module": "off",
85
- "unicorn/prefer-node-protocol": "off",
86
- "unicorn/prefer-top-level-await": "off",
87
- "unicorn/prevent-abbreviations": "off"
88
- }
54
+ "c8": "^11.0.0",
55
+ "typescript": "^6.0.3",
56
+ "uvu": "^0.5.6",
57
+ "xo": "^2.0.2"
89
58
  }
90
59
  }