@spark-ui/cli-utils 2.12.9-beta.2 → 2.12.9-beta.3
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spark-ui/cli-utils",
|
|
3
|
-
"version": "2.12.9-beta.
|
|
3
|
+
"version": "2.12.9-beta.3",
|
|
4
4
|
"description": "Spark CLI utils",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -15,12 +15,6 @@
|
|
|
15
15
|
"spark-generate": "./bin/spark-generate.mjs",
|
|
16
16
|
"spark-scan": "./bin/spark-scan.mjs"
|
|
17
17
|
},
|
|
18
|
-
"exports": {
|
|
19
|
-
".": {
|
|
20
|
-
"import": "./src/index.mjs",
|
|
21
|
-
"require": "./src/index.js"
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
18
|
"type": "module",
|
|
25
19
|
"repository": {
|
|
26
20
|
"type": "git",
|
package/src/scan/index.mjs
CHANGED
|
@@ -35,28 +35,28 @@ export async function adoption(options) {
|
|
|
35
35
|
|
|
36
36
|
const extensions = config.adoption.extensions
|
|
37
37
|
|
|
38
|
-
let
|
|
39
|
-
const importCount = 0
|
|
38
|
+
let importCount = 0
|
|
40
39
|
const importResults = {}
|
|
41
40
|
let importsUsed = {}
|
|
42
41
|
let importsCount = {}
|
|
43
42
|
config.adoption.imports.forEach(moduleName => {
|
|
44
43
|
console.log(`scanning adoption for ${moduleName}`)
|
|
45
44
|
const directoryPath = path.join(process.cwd(), config.adoption.directory)
|
|
46
|
-
|
|
45
|
+
|
|
46
|
+
const response = scanDirectories(directoryPath, moduleName, extensions, scanCallback, {
|
|
47
47
|
importCount,
|
|
48
48
|
importResults,
|
|
49
49
|
importsUsed,
|
|
50
50
|
importsCount,
|
|
51
51
|
})
|
|
52
|
-
if (importCount !==
|
|
52
|
+
if (importCount !== response.importCount) {
|
|
53
53
|
logger.success(
|
|
54
|
-
`Found ${importCount -
|
|
54
|
+
`Found ${response.importCount - importCount} imports with "${moduleName}" modules across directory ${directoryPath}.`
|
|
55
55
|
)
|
|
56
56
|
} else {
|
|
57
57
|
logger.warn(`No files found with "${moduleName}" imports across directory ${directoryPath}.`)
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
importCount = response.importCount
|
|
60
60
|
})
|
|
61
61
|
|
|
62
62
|
// Sort importsUsed by alphabet
|
|
@@ -64,9 +64,9 @@ export async function adoption(options) {
|
|
|
64
64
|
importsUsed = Object.fromEntries(
|
|
65
65
|
Object.entries(importsUsed)
|
|
66
66
|
.sort(([pkgNameA], [pkgNameB]) => pkgNameA.localeCompare(pkgNameB))
|
|
67
|
-
.map(([
|
|
67
|
+
.map(([pkgName, content]) => {
|
|
68
68
|
return [
|
|
69
|
-
|
|
69
|
+
pkgName,
|
|
70
70
|
{
|
|
71
71
|
default: Object.fromEntries(
|
|
72
72
|
Object.entries(content.default).sort(([a], [b]) => a.localeCompare(b))
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import extractImports from './utils/extract-imports.mjs'
|
|
2
2
|
|
|
3
|
-
export function scanCallback(
|
|
4
|
-
|
|
3
|
+
export function scanCallback(
|
|
4
|
+
f,
|
|
5
|
+
moduleName,
|
|
6
|
+
{ importCount, importResults, importsUsed, importsCount }
|
|
7
|
+
) {
|
|
8
|
+
const response = { importCount, importResults, importsUsed, importsCount }
|
|
9
|
+
if (!f.fileContent) return response
|
|
5
10
|
|
|
6
11
|
const imports = extractImports(f.filePath, moduleName)
|
|
7
12
|
|
|
@@ -39,18 +44,19 @@ export function scanCallback(f, moduleName, { importResults, importsUsed, import
|
|
|
39
44
|
importsUsed.importsCount = importsCount[defaultImport] + 1
|
|
40
45
|
|
|
41
46
|
importsCount[defaultImport] = importsCount[defaultImport] + 1 || 1
|
|
47
|
+
response.importCount++
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
if (namedImports.length) {
|
|
45
51
|
namedImports.forEach(n => {
|
|
46
52
|
importsUsed[moduleName].named[n] = importsUsed[moduleName].named[n] + 1 || 1
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
namedImports.forEach(n => {
|
|
50
53
|
importsUsed[moduleName].importsCount = importsUsed[moduleName].importsCount + 1
|
|
51
54
|
importsCount[n] = importsCount[n] + 1 || 1
|
|
55
|
+
response.importCount++
|
|
52
56
|
})
|
|
53
57
|
}
|
|
54
58
|
})
|
|
55
59
|
})
|
|
60
|
+
|
|
61
|
+
return response
|
|
56
62
|
}
|
|
@@ -12,35 +12,34 @@ export function scanDirectories(
|
|
|
12
12
|
) {
|
|
13
13
|
const files = fs.readdirSync(directoryPath)
|
|
14
14
|
|
|
15
|
+
let response = {
|
|
16
|
+
importCount,
|
|
17
|
+
importResults,
|
|
18
|
+
importsUsed,
|
|
19
|
+
importsCount,
|
|
20
|
+
}
|
|
21
|
+
|
|
15
22
|
for (const file of files) {
|
|
16
23
|
const filePath = path.join(directoryPath, file)
|
|
17
24
|
const stats = fs.statSync(filePath)
|
|
18
25
|
|
|
19
26
|
if (stats.isDirectory()) {
|
|
20
|
-
scanDirectories(filePath, importName, extensions, scanningCallback,
|
|
21
|
-
importCount,
|
|
22
|
-
importResults,
|
|
23
|
-
importsUsed,
|
|
24
|
-
importsCount,
|
|
25
|
-
})
|
|
27
|
+
response = scanDirectories(filePath, importName, extensions, scanningCallback, response)
|
|
26
28
|
} else if (stats.isFile() && extensions.includes(path.extname(filePath))) {
|
|
27
29
|
const f = fileContainsImport(filePath, importName)
|
|
28
30
|
|
|
29
31
|
if (f) {
|
|
30
|
-
scanningCallback(
|
|
32
|
+
response = scanningCallback(
|
|
31
33
|
{
|
|
32
34
|
filePath: f.filePath,
|
|
33
35
|
fileContent: f.fileContent,
|
|
34
36
|
},
|
|
35
37
|
importName,
|
|
36
|
-
|
|
37
|
-
importCount,
|
|
38
|
-
importResults,
|
|
39
|
-
importsUsed,
|
|
40
|
-
importsCount,
|
|
41
|
-
}
|
|
38
|
+
response
|
|
42
39
|
)
|
|
43
40
|
}
|
|
44
41
|
}
|
|
45
42
|
}
|
|
43
|
+
|
|
44
|
+
return response
|
|
46
45
|
}
|