22
22
23
23
const mod = require ( 'module' ) ;
24
24
const path = require ( 'path' ) ;
25
- const fs = require ( 'fs' ) . promises ;
25
+ const fs = require ( 'fs' ) ;
26
26
const { URL } = require ( 'url' ) ; /* TODO: RPC Loader */
27
27
28
- async function findFilesRecursively ( dirPattern , filePattern , depthLimit = Infinity ) {
28
+ const findFilesRecursively = ( dirPattern , filePattern , depthLimit = Infinity ) => {
29
29
const stack = [ { dir : dirPattern , depth : 0 } ] ;
30
30
const files = [ ] ;
31
31
const dirRegex = new RegExp ( dirPattern ) ;
@@ -43,11 +43,11 @@ async function findFilesRecursively(dirPattern, filePattern, depthLimit = Infini
43
43
continue ;
44
44
}
45
45
46
- const items = await fs . readdir ( dir ) ;
46
+ const items = fs . readdirSync ( dir ) ;
47
47
48
48
for ( const item of items ) {
49
49
const fullPath = path . join ( dir , item ) ;
50
- const stat = await fs . stat ( fullPath ) ;
50
+ const stat = fs . statSync ( fullPath ) ;
51
51
52
52
if ( stat . isDirectory ( ) ) {
53
53
stack . push ( { dir : fullPath , depth : depth + 1 } ) ;
@@ -61,7 +61,7 @@ async function findFilesRecursively(dirPattern, filePattern, depthLimit = Infini
61
61
}
62
62
63
63
return files ;
64
- }
64
+ } ;
65
65
66
66
const platformInstallPaths = ( ) => {
67
67
switch ( process . platform ) {
@@ -83,7 +83,7 @@ const platformInstallPaths = () => {
83
83
}
84
84
85
85
throw new Error ( `Platform ${ process . platform } not supported` )
86
- }
86
+ } ;
87
87
88
88
const searchPaths = ( ) => {
89
89
const customPath = process . env [ 'METACALL_INSTALL_PATH' ] ;
@@ -96,21 +96,21 @@ const searchPaths = () => {
96
96
}
97
97
98
98
return platformInstallPaths ( )
99
- }
99
+ } ;
100
100
101
- const findLibrary = async ( ) => {
101
+ const findLibrary = ( ) => {
102
102
const searchData = searchPaths ( ) ;
103
103
104
104
for ( const p of searchData . paths ) {
105
- const files = await findFilesRecursively ( p , searchData . name , 0 ) ;
105
+ const files = findFilesRecursively ( p , searchData . name , 0 ) ;
106
106
107
107
if ( files . length !== 0 ) {
108
108
return files [ 0 ] ;
109
109
}
110
110
}
111
111
112
112
throw new Error ( 'MetaCall library not found, if you have it in a special folder, define it through METACALL_INSTALL_PATH' )
113
- }
113
+ } ;
114
114
115
115
const addon = ( ( ) => {
116
116
try {
@@ -127,7 +127,9 @@ const addon = (() => {
127
127
*/
128
128
process . env [ 'METACALL_HOST' ] = 'node' ;
129
129
130
- findLibrary ( ) . then ( library => {
130
+ try {
131
+ const library = findLibrary ( ) ;
132
+
131
133
const { constants } = require ( 'os' ) ;
132
134
const m = { exports : { } } ;
133
135
@@ -148,10 +150,10 @@ const addon = (() => {
148
150
process . argv = argv ;
149
151
150
152
return m . exports ;
151
- } ) . catch ( err => {
153
+ } catch ( err ) {
152
154
console . log ( err ) ;
153
155
process . exit ( 1 ) ;
154
- } ) ;
156
+ }
155
157
}
156
158
} ) ( ) ;
157
159
0 commit comments