@@ -6,8 +6,6 @@ import * as toolbox from 'gluegun';
6
6
import immutable from 'immutable' ;
7
7
import type { IPFSHTTPClient } from 'ipfs-http-client' ;
8
8
import yaml from 'js-yaml' ;
9
- import memo from 'memoizee' ;
10
- import { parseSync } from '@babel/core' ;
11
9
import { Spinner , step , withSpinner } from '../command-helpers/spinner' ;
12
10
import debug from '../debug' ;
13
11
import { applyMigrations } from '../migrations' ;
@@ -18,18 +16,6 @@ import * as asc from './asc';
18
16
19
17
const compilerDebug = debug ( 'graph-cli:compiler' ) ;
20
18
21
- /** memoize the reading of the file so we don't have to read it every time */
22
- const readFile = memo ( ( filename : string ) => fs . readFileSync ( filename , 'utf-8' ) ) ;
23
-
24
- /** Memoized parser for Babel, so we can simply just read from cache */
25
- const babelAst = memo ( ( filename : string ) => {
26
- const data = readFile ( filename ) ;
27
- return parseSync ( data , {
28
- presets : [ '@babel/preset-typescript' ] ,
29
- filename,
30
- } ) ;
31
- } ) ;
32
-
33
19
interface CompilerOptions {
34
20
ipfs : any ;
35
21
subgraphManifest : string ;
@@ -364,19 +350,12 @@ export default class Compiler {
364
350
365
351
try {
366
352
const dataSourceName = dataSource . getIn ( [ 'name' ] ) ;
353
+
367
354
const baseDir = this . sourceDir ;
368
355
const absoluteMappingPath = path . resolve ( baseDir , mappingPath ) ;
369
356
const inputFile = path . relative ( baseDir , absoluteMappingPath ) ;
370
-
371
357
this . _validateMappingContent ( absoluteMappingPath ) ;
372
358
373
- const eventHandlers = dataSource . getIn ( [ 'mapping' , 'eventHandlers' ] ) ;
374
- // TODO: improve the types
375
- for ( const eventHandler of ( eventHandlers as any ) . toJS ( ) ) {
376
- compilerDebug ( 'Validating Event Handler %s' , eventHandler . handler ) ;
377
- this . _validateHandler ( absoluteMappingPath , eventHandler . handler ) ;
378
- }
379
-
380
359
// If the file has already been compiled elsewhere, just use that output
381
360
// file and return early
382
361
const inputCacheKey = this . cacheKeyForFile ( absoluteMappingPath ) ;
@@ -452,13 +431,6 @@ export default class Compiler {
452
431
const inputFile = path . relative ( baseDir , absoluteMappingPath ) ;
453
432
this . _validateMappingContent ( absoluteMappingPath ) ;
454
433
455
- const eventHandlers = template . getIn ( [ 'mapping' , 'eventHandlers' ] ) ;
456
- // TODO: improve the types
457
- for ( const eventHandler of ( eventHandlers as any ) . toJS ( ) ) {
458
- compilerDebug ( 'Validating Template handler %s' , eventHandler . handler ) ;
459
- this . _validateHandler ( absoluteMappingPath , eventHandler . handler ) ;
460
- }
461
-
462
434
// If the file has already been compiled elsewhere, just use that output
463
435
// file and return early
464
436
const inputCacheKey = this . cacheKeyForFile ( absoluteMappingPath ) ;
@@ -517,7 +489,7 @@ export default class Compiler {
517
489
}
518
490
519
491
_validateMappingContent ( filePath : string ) {
520
- const data = readFile ( filePath ) ;
492
+ const data = fs . readFileSync ( filePath ) ;
521
493
if ( this . blockIpfsMethods && ( data . includes ( 'ipfs.cat' ) || data . includes ( 'ipfs.map' ) ) ) {
522
494
throw Error ( `
523
495
Subgraph Studio does not support mappings with ipfs methods.
@@ -527,31 +499,6 @@ export default class Compiler {
527
499
}
528
500
}
529
501
530
- _validateHandler ( filePath : string , handlerName : string ) {
531
- const baselAst = babelAst ( filePath ) ;
532
-
533
- const body = baselAst ?. program . body ;
534
-
535
- if ( ! body ) {
536
- throw Error ( `Could not parse ${ filePath } ` ) ;
537
- }
538
-
539
- const exportedFunctionNames = body
540
- . map ( statement => {
541
- if (
542
- statement . type === 'ExportNamedDeclaration' &&
543
- statement ?. declaration ?. type === 'FunctionDeclaration'
544
- ) {
545
- return statement . declaration . id ?. name ;
546
- }
547
- } )
548
- . filter ( Boolean ) ;
549
-
550
- if ( ! exportedFunctionNames . includes ( handlerName ) ) {
551
- throw Error ( `Could not find handler '${ handlerName } ' in ${ filePath } ` ) ;
552
- }
553
- }
554
-
555
502
async writeSubgraphToOutputDirectory ( protocol : Protocol , subgraph : immutable . Map < any , any > ) {
556
503
const displayDir = `${ this . displayPath ( this . options . outputDir ) } ${ toolbox . filesystem . separator } ` ;
557
504
0 commit comments