Skip to content

Commit 35140a2

Browse files
committed
rollback asc
1 parent 8f2f892 commit 35140a2

File tree

9 files changed

+59
-48
lines changed

9 files changed

+59
-48
lines changed

.changeset/wet-toys-fry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphprotocol/graph-cli': patch
3+
---
4+
5+
rollback asc version

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"@oclif/plugin-warn-if-update-available": "^3.1.24",
3838
"@pinax/graph-networks-registry": "^0.6.5",
3939
"@whatwg-node/fetch": "^0.10.1",
40-
"assemblyscript": "0.27.31",
40+
"assemblyscript": "0.19.23",
4141
"binary-install": "^1.1.0",
4242
"chokidar": "4.0.1",
4343
"debug": "4.3.7",

packages/cli/src/command-helpers/compiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function appendApiVersionForGraph(inputString: string) {
3333
}
3434

3535
// Helper function to construct a subgraph compiler
36-
export async function createCompiler(
36+
export function createCompiler(
3737
manifest: string,
3838
{
3939
ipfs,

packages/cli/src/commands/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default class BuildCommand extends Command {
8787
await updateSubgraphNetwork(manifest, network, networkFile, identifierName);
8888
}
8989

90-
const compiler = await createCompiler(manifest, {
90+
const compiler = createCompiler(manifest, {
9191
ipfs,
9292
outputDir,
9393
outputFormat,

packages/cli/src/commands/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export default class DeployCommand extends Command {
273273
await updateSubgraphNetwork(manifest, network, networkFile, identifierName);
274274
}
275275

276-
const compiler = await createCompiler(manifest, {
276+
const compiler = createCompiler(manifest, {
277277
ipfs,
278278
headers,
279279
outputDir,

packages/cli/src/commands/publish.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export default class PublishCommand extends Command {
145145
this.error(e, { exit: 1 });
146146
}
147147

148-
const compiler = await createCompiler(manifest, {
148+
const compiler = createCompiler(manifest, {
149149
ipfs,
150150
outputDir: 'build/',
151151
outputFormat: 'wasm',

packages/cli/src/compiler/asc.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import asc from 'assemblyscript/asc';
1+
import * as asc from 'assemblyscript/cli/asc';
22

33
const createExitHandler = (inputFile: string) => () => {
44
throw new Error(`The AssemblyScript compiler crashed when compiling this file: '${inputFile}'
@@ -14,14 +14,28 @@ const setupExitHandler = (exitHandler: (code: number) => void) =>
1414
const removeExitHandler = (exitHandler: (code: number) => void) =>
1515
process.removeListener('exit', exitHandler);
1616

17-
const assemblyScriptCompiler = async (argv: string[], options: asc.APIOptions) =>
18-
await asc.main(argv, options);
17+
// Important note, the `asc.main` callback function parameter is synchronous,
18+
// that's why this function doesn't need to be `async` and the throw works properly.
19+
const assemblyScriptCompiler = (argv: string[], options: asc.APIOptions) =>
20+
asc.main(argv, options, err => {
21+
if (err) {
22+
throw err;
23+
}
24+
return 0;
25+
});
1926

2027
const compilerDefaults = {
2128
stdout: process.stdout,
2229
stderr: process.stdout,
2330
};
2431

32+
// You MUST call this function once before compiling anything.
33+
// Internally it just delegates to the AssemblyScript compiler
34+
// which just delegates to the binaryen lib.
35+
export const ready = async () => {
36+
await asc.ready;
37+
};
38+
2539
export interface CompileOptions {
2640
inputFile: string;
2741
global: string;
@@ -34,12 +48,13 @@ export interface CompileOptions {
3448
// it requires an asynchronous wait. Whenever you call this function,
3549
// it doesn't matter how many times, just make sure you call `ready`
3650
// once before everything..
37-
export const compile = async ({ inputFile, global, baseDir, libs, outputFile }: CompileOptions) => {
51+
export const compile = ({ inputFile, global, baseDir, libs, outputFile }: CompileOptions) => {
3852
const exitHandler = createExitHandler(inputFile);
3953

4054
setupExitHandler(exitHandler);
4155

4256
const compilerArgs = [
57+
'--explicitStart',
4358
'--exportRuntime',
4459
'--runtime',
4560
'stub',
@@ -55,7 +70,7 @@ export const compile = async ({ inputFile, global, baseDir, libs, outputFile }:
5570
'--debug',
5671
];
5772

58-
await assemblyScriptCompiler(compilerArgs, compilerDefaults);
73+
assemblyScriptCompiler(compilerArgs, compilerDefaults);
5974

6075
// only if compiler succeeded, that is, when the line above doesn't throw
6176
removeExitHandler(exitHandler);

packages/cli/src/compiler/index.ts

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -246,41 +246,32 @@ export default class Compiler {
246246
// Cache compiled files so identical input files are only compiled once
247247
const compiledFiles = new Map();
248248

249-
// Handle data sources
250-
const dataSources = subgraph.get('dataSources');
251-
const compiledDataSources = await Promise.all(
252-
dataSources.map(async (dataSource: any) => {
253-
const mappingPath = dataSource.getIn(['mapping', 'file']);
254-
const compiledPath = await this._compileDataSourceMapping(
255-
this.protocol,
256-
dataSource,
257-
mappingPath,
258-
compiledFiles,
259-
spinner,
260-
validate,
261-
);
262-
return dataSource.setIn(['mapping', 'file'], compiledPath);
263-
}),
264-
);
265-
subgraph = subgraph.set('dataSources', compiledDataSources);
266-
267-
// Handle templates if they exist
268-
const templates = subgraph.get('templates');
269-
if (templates !== undefined) {
270-
const compiledTemplates = await Promise.all(
271-
templates.map(async (template: any) => {
272-
const mappingPath = template.getIn(['mapping', 'file']);
273-
const compiledPath = await this._compileTemplateMapping(
274-
template,
249+
await asc.ready();
250+
251+
subgraph = subgraph.update('dataSources', (dataSources: any[]) =>
252+
dataSources.map((dataSource: any) =>
253+
dataSource.updateIn(['mapping', 'file'], (mappingPath: string) =>
254+
this._compileDataSourceMapping(
255+
this.protocol,
256+
dataSource,
275257
mappingPath,
276258
compiledFiles,
277259
spinner,
278-
);
279-
return template.setIn(['mapping', 'file'], compiledPath);
280-
}),
281-
);
282-
subgraph = subgraph.set('templates', compiledTemplates);
283-
}
260+
validate,
261+
),
262+
),
263+
),
264+
);
265+
266+
subgraph = subgraph.update('templates', (templates: any) =>
267+
templates === undefined
268+
? templates
269+
: templates.map((template: any) =>
270+
template.updateIn(['mapping', 'file'], (mappingPath: string) =>
271+
this._compileTemplateMapping(template, mappingPath, compiledFiles, spinner),
272+
),
273+
),
274+
);
284275

285276
return subgraph;
286277
},
@@ -343,7 +334,7 @@ export default class Compiler {
343334
return missingHandlers;
344335
}
345336

346-
async _compileDataSourceMapping(
337+
_compileDataSourceMapping(
347338
protocol: Protocol,
348339
dataSource: immutable.Map<any, any>,
349340
mappingPath: string,
@@ -397,7 +388,7 @@ export default class Compiler {
397388
}
398389
const global = path.relative(baseDir, this.globalsFile);
399390

400-
await asc.compile({
391+
asc.compile({
401392
inputFile,
402393
global,
403394
baseDir,
@@ -424,7 +415,7 @@ export default class Compiler {
424415
}
425416
}
426417

427-
async _compileTemplateMapping(
418+
_compileTemplateMapping(
428419
template: immutable.Collection<any, any>,
429420
mappingPath: string,
430421
compiledFiles: Map<any, any>,
@@ -478,7 +469,7 @@ export default class Compiler {
478469
}
479470
const global = path.relative(baseDir, this.globalsFile);
480471

481-
await asc.compile({
472+
asc.compile({
482473
inputFile,
483474
global,
484475
baseDir,

pnpm-lock.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)