Skip to content

Commit 5bcacf3

Browse files
fubhyJannis
authored andcommitted
Fixing path lookups in compiler script.
1 parent 045c81c commit 5bcacf3

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/compiler.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ class Compiler {
1919
this.ipfs = options.ipfs
2020
this.sourceDir = path.dirname(options.subgraphManifest)
2121

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+
2240
process.on('uncaughtException', function(e) {
2341
toolbox.print.error(`UNCAUGHT EXCEPTION: ${e}`)
2442
})
@@ -233,7 +251,7 @@ class Compiler {
233251
return outFile
234252
}
235253

236-
let outFile = path.join(
254+
let outFile = path.resolve(
237255
this.subgraphDir(this.options.outputDir, dataSource),
238256
this.options.outputFormat == 'wasm'
239257
? `${dataSourceName}.wasm`
@@ -250,30 +268,12 @@ class Compiler {
250268

251269
// Create output directory
252270
try {
253-
fs.mkdirsSync(path.dirname(outputFile))
271+
fs.mkdirsSync(path.dirname(outFile))
254272
} catch (e) {
255273
throw e
256274
}
257275

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
277277
let global = path.join(libs, '@graphprotocol', 'graph-ts', 'global', 'global.ts')
278278
global = path.relative(baseDir, global)
279279

@@ -301,9 +301,9 @@ class Compiler {
301301
)
302302

303303
// Remember the output file to avoid compiling the same file again
304-
compiledFiles.set(inputCacheKey, outputFile)
304+
compiledFiles.set(inputCacheKey, outFile)
305305

306-
return outputFile
306+
return outFile
307307
} catch (e) {
308308
throw Error(`Failed to compile data source mapping: ${e.message}`)
309309
}
@@ -331,7 +331,7 @@ class Compiler {
331331
return outFile
332332
}
333333

334-
let outFile = path.join(
334+
let outFile = path.resolve(
335335
this.options.outputDir,
336336
'templates',
337337
templateName,
@@ -350,12 +350,12 @@ class Compiler {
350350

351351
// Create output directory
352352
try {
353-
fs.mkdirsSync(path.dirname(outputFile))
353+
fs.mkdirsSync(path.dirname(outFile))
354354
} catch (e) {
355355
throw e
356356
}
357357

358-
let libs = path.join(baseDir, 'node_modules')
358+
let libs = this.libsDir
359359
let global = path.join(libs, '@graphprotocol', 'graph-ts', 'global', 'global.ts')
360360
global = path.relative(baseDir, global)
361361

@@ -383,9 +383,9 @@ class Compiler {
383383
)
384384

385385
// Remember the output file to avoid compiling the same file again
386-
compiledFiles.set(inputCacheKey, outputFile)
386+
compiledFiles.set(inputCacheKey, outFile)
387387

388-
return outputFile
388+
return outFile
389389
} catch (e) {
390390
throw Error(`Failed to compile data source template: ${e.message}`)
391391
}

0 commit comments

Comments
 (0)