@@ -19,6 +19,24 @@ class Compiler {
19
19
this . ipfs = options . ipfs
20
20
this . sourceDir = path . dirname ( options . subgraphManifest )
21
21
22
+ for (
23
+ let dir = path . resolve ( this . sourceDir ) ;
24
+ // Terminate after the root dir or when we have found node_modules
25
+ dir !== undefined && this . libsDir === undefined ;
26
+ // Continue with the parent directory, terminate after the root dir
27
+ dir = path . dirname ( dir ) === dir ? undefined : path . dirname ( dir )
28
+ ) {
29
+ if ( fs . existsSync ( path . join ( dir , 'node_modules' ) ) ) {
30
+ this . libsDir = path . join ( dir , 'node_modules' )
31
+ }
32
+ }
33
+
34
+ if ( this . libsDir === undefined ) {
35
+ throw Error (
36
+ `could not locate \`node_modules\` in parent directories of subgraph manifest` ,
37
+ )
38
+ }
39
+
22
40
process . on ( 'uncaughtException' , function ( e ) {
23
41
toolbox . print . error ( `UNCAUGHT EXCEPTION: ${ e } ` )
24
42
} )
@@ -233,7 +251,7 @@ class Compiler {
233
251
return outFile
234
252
}
235
253
236
- let outFile = path . join (
254
+ let outFile = path . resolve (
237
255
this . subgraphDir ( this . options . outputDir , dataSource ) ,
238
256
this . options . outputFormat == 'wasm'
239
257
? `${ dataSourceName } .wasm`
@@ -250,30 +268,12 @@ class Compiler {
250
268
251
269
// Create output directory
252
270
try {
253
- fs . mkdirsSync ( path . dirname ( outputFile ) )
271
+ fs . mkdirsSync ( path . dirname ( outFile ) )
254
272
} catch ( e ) {
255
273
throw e
256
274
}
257
275
258
- let libs
259
- for (
260
- let dir = path . resolve ( baseDir ) ;
261
- // Terminate after the root dir or when we have found node_modules
262
- dir !== undefined && libs === undefined ;
263
- // Continue with the parent directory, terminate after the root dir
264
- dir = path . dirname ( dir ) === dir ? undefined : path . dirname ( dir )
265
- ) {
266
- if ( fs . existsSync ( path . join ( dir , 'node_modules' ) ) ) {
267
- libs = path . join ( dir , 'node_modules' )
268
- }
269
- }
270
-
271
- if ( libs === undefined ) {
272
- throw Error (
273
- `could not locate \`node_modules\` in parent directories of subgraph manifest` ,
274
- )
275
- }
276
-
276
+ let libs = this . libsDir
277
277
let global = path . join ( libs , '@graphprotocol' , 'graph-ts' , 'global' , 'global.ts' )
278
278
global = path . relative ( baseDir , global )
279
279
@@ -301,9 +301,9 @@ class Compiler {
301
301
)
302
302
303
303
// Remember the output file to avoid compiling the same file again
304
- compiledFiles . set ( inputCacheKey , outputFile )
304
+ compiledFiles . set ( inputCacheKey , outFile )
305
305
306
- return outputFile
306
+ return outFile
307
307
} catch ( e ) {
308
308
throw Error ( `Failed to compile data source mapping: ${ e . message } ` )
309
309
}
@@ -331,7 +331,7 @@ class Compiler {
331
331
return outFile
332
332
}
333
333
334
- let outFile = path . join (
334
+ let outFile = path . resolve (
335
335
this . options . outputDir ,
336
336
'templates' ,
337
337
templateName ,
@@ -350,12 +350,12 @@ class Compiler {
350
350
351
351
// Create output directory
352
352
try {
353
- fs . mkdirsSync ( path . dirname ( outputFile ) )
353
+ fs . mkdirsSync ( path . dirname ( outFile ) )
354
354
} catch ( e ) {
355
355
throw e
356
356
}
357
357
358
- let libs = path . join ( baseDir , 'node_modules' )
358
+ let libs = this . libsDir
359
359
let global = path . join ( libs , '@graphprotocol' , 'graph-ts' , 'global' , 'global.ts' )
360
360
global = path . relative ( baseDir , global )
361
361
@@ -383,9 +383,9 @@ class Compiler {
383
383
)
384
384
385
385
// Remember the output file to avoid compiling the same file again
386
- compiledFiles . set ( inputCacheKey , outputFile )
386
+ compiledFiles . set ( inputCacheKey , outFile )
387
387
388
- return outputFile
388
+ return outFile
389
389
} catch ( e ) {
390
390
throw Error ( `Failed to compile data source template: ${ e . message } ` )
391
391
}
0 commit comments