@wwkit/cft 1.0.30 → 1.0.31

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/src/exefinder.js CHANGED
@@ -1,110 +1,110 @@
1
- import fs from 'node:fs'
2
- import path from 'node:path'
3
- import process from 'node:process'
4
-
5
- function getPossibleNames(baseName) {
6
- const names = new Set()
7
- if (baseName === 'chrome') {
8
- ['chrome', 'google chrome', 'google chrome for testing'].forEach(n => {
9
- names.add(n.toLowerCase())
10
- names.add(n.toLowerCase() + '.exe')
11
- })
12
- } else if (baseName === 'chromedriver') {
13
- names.add('chromedriver')
14
- names.add('chromedriver.exe')
15
- } else {
16
- names.add(baseName.toLowerCase())
17
- names.add(baseName.toLowerCase() + '.exe')
18
- }
19
- return names
20
- }
21
-
22
- function findFallback(directory, baseName, isMacos) {
23
- if (baseName === 'chrome' && isMacos) {
24
- const paths = [
25
- path.join(directory, 'Google Chrome for Testing.app', 'Contents', 'MacOS', 'Google Chrome for Testing'),
26
- path.join(directory, 'Chrome.app', 'Contents', 'MacOS', 'Chrome'),
27
- path.join(directory, 'Google Chrome.app', 'Contents', 'MacOS', 'Google Chrome'),
28
- ]
29
- for (const p of paths) {
30
- if (fs.existsSync(p)) return p
31
- }
32
- } else if (baseName === 'chromedriver') {
33
- const paths = [
34
- path.join(directory, 'chromedriver'),
35
- path.join(directory, 'chromedriver.exe'),
36
- ]
37
- for (const p of paths) {
38
- if (fs.existsSync(p)) return p
39
- }
40
- }
41
- return null
42
- }
43
-
44
- function setAppPermissions(appBundlePath) {
45
- if (!fs.existsSync(appBundlePath)) return
46
- for (const entry of fs.readdirSync(appBundlePath, { withFileTypes: true })) {
47
- const fullPath = path.join(appBundlePath, entry.name)
48
- if (entry.isDirectory()) {
49
- setAppPermissions(fullPath)
50
- } else {
51
- try { fs.chmodSync(fullPath, 0o755) } catch {}
52
- }
53
- }
54
- }
55
-
56
- function ensureExecutable(filePath, isMacos = false, baseName = '') {
57
- if (process.platform === 'win32') return filePath
58
- try {
59
- fs.accessSync(filePath, fs.constants.X_OK)
60
- return filePath
61
- } catch {}
62
- try {
63
- fs.chmodSync(filePath, 0o755)
64
- if (isMacos && baseName === 'chrome') {
65
- const parts = filePath.split('/Contents/MacOS/')
66
- if (parts.length > 1 && parts[0].endsWith('.app')) {
67
- setAppPermissions(parts[0])
68
- }
69
- }
70
- } catch {}
71
- return filePath
72
- }
73
-
74
- export function find(directory, baseName) {
75
- const isMacos = process.platform === 'darwin'
76
-
77
- if (!fs.existsSync(directory)) {
78
- throw new Error(`Directory not found: ${directory}`)
79
- }
80
-
81
- if (fs.statSync(directory).isFile()) {
82
- try {
83
- fs.accessSync(directory, fs.constants.X_OK)
84
- return ensureExecutable(directory)
85
- } catch {}
86
- }
87
-
88
- const possibleNames = getPossibleNames(baseName)
89
-
90
- function walkDir(dir) {
91
- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
92
- const fullPath = path.join(dir, entry.name)
93
- if (entry.isDirectory()) {
94
- const result = walkDir(fullPath)
95
- if (result) return result
96
- } else if (possibleNames.has(entry.name.toLowerCase())) {
97
- return fullPath
98
- }
99
- }
100
- return null
101
- }
102
-
103
- const found = walkDir(directory)
104
- if (found) return ensureExecutable(found, isMacos, baseName)
105
-
106
- const fallback = findFallback(directory, baseName, isMacos)
107
- if (fallback) return ensureExecutable(fallback, isMacos, baseName)
108
-
109
- throw new Error(`Executable not found: ${baseName} in ${directory}`)
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import process from 'node:process'
4
+
5
+ function getPossibleNames(baseName) {
6
+ const names = new Set()
7
+ if (baseName === 'chrome') {
8
+ ['chrome', 'google chrome', 'google chrome for testing'].forEach(n => {
9
+ names.add(n.toLowerCase())
10
+ names.add(n.toLowerCase() + '.exe')
11
+ })
12
+ } else if (baseName === 'chromedriver') {
13
+ names.add('chromedriver')
14
+ names.add('chromedriver.exe')
15
+ } else {
16
+ names.add(baseName.toLowerCase())
17
+ names.add(baseName.toLowerCase() + '.exe')
18
+ }
19
+ return names
20
+ }
21
+
22
+ function findFallback(directory, baseName, isMacos) {
23
+ if (baseName === 'chrome' && isMacos) {
24
+ const paths = [
25
+ path.join(directory, 'Google Chrome for Testing.app', 'Contents', 'MacOS', 'Google Chrome for Testing'),
26
+ path.join(directory, 'Chrome.app', 'Contents', 'MacOS', 'Chrome'),
27
+ path.join(directory, 'Google Chrome.app', 'Contents', 'MacOS', 'Google Chrome'),
28
+ ]
29
+ for (const p of paths) {
30
+ if (fs.existsSync(p)) return p
31
+ }
32
+ } else if (baseName === 'chromedriver') {
33
+ const paths = [
34
+ path.join(directory, 'chromedriver'),
35
+ path.join(directory, 'chromedriver.exe'),
36
+ ]
37
+ for (const p of paths) {
38
+ if (fs.existsSync(p)) return p
39
+ }
40
+ }
41
+ return null
42
+ }
43
+
44
+ function setAppPermissions(appBundlePath) {
45
+ if (!fs.existsSync(appBundlePath)) return
46
+ for (const entry of fs.readdirSync(appBundlePath, { withFileTypes: true })) {
47
+ const fullPath = path.join(appBundlePath, entry.name)
48
+ if (entry.isDirectory()) {
49
+ setAppPermissions(fullPath)
50
+ } else {
51
+ try { fs.chmodSync(fullPath, 0o755) } catch {}
52
+ }
53
+ }
54
+ }
55
+
56
+ function ensureExecutable(filePath, isMacos = false, baseName = '') {
57
+ if (process.platform === 'win32') return filePath
58
+ try {
59
+ fs.accessSync(filePath, fs.constants.X_OK)
60
+ return filePath
61
+ } catch {}
62
+ try {
63
+ fs.chmodSync(filePath, 0o755)
64
+ if (isMacos && baseName === 'chrome') {
65
+ const parts = filePath.split('/Contents/MacOS/')
66
+ if (parts.length > 1 && parts[0].endsWith('.app')) {
67
+ setAppPermissions(parts[0])
68
+ }
69
+ }
70
+ } catch {}
71
+ return filePath
72
+ }
73
+
74
+ export function find(directory, baseName) {
75
+ const isMacos = process.platform === 'darwin'
76
+
77
+ if (!fs.existsSync(directory)) {
78
+ throw new Error(`Directory not found: ${directory}`)
79
+ }
80
+
81
+ if (fs.statSync(directory).isFile()) {
82
+ try {
83
+ fs.accessSync(directory, fs.constants.X_OK)
84
+ return ensureExecutable(directory)
85
+ } catch {}
86
+ }
87
+
88
+ const possibleNames = getPossibleNames(baseName)
89
+
90
+ function walkDir(dir) {
91
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
92
+ const fullPath = path.join(dir, entry.name)
93
+ if (entry.isDirectory()) {
94
+ const result = walkDir(fullPath)
95
+ if (result) return result
96
+ } else if (possibleNames.has(entry.name.toLowerCase())) {
97
+ return fullPath
98
+ }
99
+ }
100
+ return null
101
+ }
102
+
103
+ const found = walkDir(directory)
104
+ if (found) return ensureExecutable(found, isMacos, baseName)
105
+
106
+ const fallback = findFallback(directory, baseName, isMacos)
107
+ if (fallback) return ensureExecutable(fallback, isMacos, baseName)
108
+
109
+ throw new Error(`Executable not found: ${baseName} in ${directory}`)
110
110
  }
package/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { install, status, clear } from './installer.js'
2
- export { getOs, isWindows, isMacos, isLinux, VALID_OS_TYPES } from './platform.js'
3
- export { getConfig, getVersion, getRegistry, getProxy, getLocation, copyBuiltinConfig, mergeBuiltinConfig, INSTALL_LOCATION, USER_CONFIG_FILE, showConfig } from './config.js'
1
+ export { install, status, clear } from './installer.js'
2
+ export { getOs, isWindows, isMacos, isLinux, VALID_OS_TYPES } from './platform.js'
3
+ export { getConfig, getVersion, getRegistry, getProxy, getLocation, copyBuiltinConfig, mergeBuiltinConfig, INSTALL_LOCATION, USER_CONFIG_FILE, showConfig } from './config.js'
4
4
  export { showEnv } from './env.js'