@@ -18,25 +18,39 @@ class Compiler {
18
18
this . options = options
19
19
this . ipfs = options . ipfs
20
20
this . sourceDir = path . dirname ( options . subgraphManifest )
21
+ this . libsDirs = [ ]
21
22
22
23
for (
23
24
let dir = path . resolve ( this . sourceDir ) ;
24
25
// Terminate after the root dir or when we have found node_modules
25
- dir !== undefined && this . libsDir === undefined ;
26
+ dir !== undefined ;
26
27
// Continue with the parent directory, terminate after the root dir
27
28
dir = path . dirname ( dir ) === dir ? undefined : path . dirname ( dir )
28
29
) {
29
30
if ( fs . existsSync ( path . join ( dir , 'node_modules' ) ) ) {
30
- this . libsDir = path . join ( dir , 'node_modules' )
31
+ this . libsDirs . push ( path . join ( dir , 'node_modules' ) )
31
32
}
32
33
}
33
34
34
- if ( this . libsDir === undefined ) {
35
+ if ( this . libsDirs . length === 0 ) {
35
36
throw Error (
36
37
`could not locate \`node_modules\` in parent directories of subgraph manifest` ,
37
38
)
38
39
}
39
40
41
+ const globalsFile = path . join ( '@graphprotocol' , 'graph-ts' , 'global' , 'global.ts' )
42
+ const globalsLib = this . libsDirs . find ( item => {
43
+ return fs . existsSync ( path . join ( item , globalsFile ) )
44
+ } )
45
+
46
+ if ( ! globalsLib ) {
47
+ throw Error (
48
+ 'Could not locate `@graphprotocol/graph-ts` package in parent directories of subgraph manifest.' ,
49
+ )
50
+ }
51
+
52
+ this . globalsFile = path . join ( globalsLib , globalsFile )
53
+
40
54
process . on ( 'uncaughtException' , function ( e ) {
41
55
toolbox . print . error ( `UNCAUGHT EXCEPTION: ${ e } ` )
42
56
} )
@@ -273,9 +287,8 @@ class Compiler {
273
287
throw e
274
288
}
275
289
276
- let libs = this . libsDir
277
- let global = path . join ( libs , '@graphprotocol' , 'graph-ts' , 'global' , 'global.ts' )
278
- global = path . relative ( baseDir , global )
290
+ let libs = this . libsDirs . join ( ',' )
291
+ let global = path . relative ( baseDir , this . globalsFile )
279
292
280
293
asc . main (
281
294
[
@@ -355,9 +368,8 @@ class Compiler {
355
368
throw e
356
369
}
357
370
358
- let libs = this . libsDir
359
- let global = path . join ( libs , '@graphprotocol' , 'graph-ts' , 'global' , 'global.ts' )
360
- global = path . relative ( baseDir , global )
371
+ let libs = this . libsDirs . join ( ',' )
372
+ let global = path . relative ( baseDir , this . globalsFile )
361
373
362
374
asc . main (
363
375
[
0 commit comments