Skip to content

Commit

Permalink
Cleanup dependencies and compiler fix (#1848)
Browse files Browse the repository at this point in the history
* cleanup dependencies

* chore(dependencies): updated changesets for modified dependencies

* add undici as a direct dependency

* chore(dependencies): updated changesets for modified dependencies

* remove deprecated asc flag

* properly await asc.compile()

* properly handle version and name flags

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
YaroShkvorets and github-actions[bot] authored Dec 17, 2024
1 parent 1651e60 commit f2726cb
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 58 deletions.
6 changes: 6 additions & 0 deletions .changeset/@graphprotocol_graph-cli-1848-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@graphprotocol/graph-cli": patch
---
dependencies updates:
- Added dependency [`prettier@3.4.2` ↗︎](https://www.npmjs.com/package/prettier/v/3.4.2) (to `dependencies`)
- Added dependency [`undici@7.1.1` ↗︎](https://www.npmjs.com/package/undici/v/7.1.1) (to `dependencies`)
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
"pnpm": {
"patchedDependencies": {
"oclif@4.16.0": "patches/oclif@4.16.0.patch"
},
"overrides": {
"rimraf": "^6.0.0"
}
}
}
2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
"js-yaml": "4.1.0",
"kubo-rpc-client": "^5.0.2",
"open": "10.1.0",
"prettier": "3.4.2",
"semver": "7.6.3",
"tmp-promise": "3.0.3",
"undici": "7.1.1",
"web3-eth-abi": "4.4.1",
"yaml": "2.6.1"
},
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default class DeployCommand extends Command {
type: 'input',
name: 'subgraphName',
message: () => 'What is the subgraph name?',
skip: () => !!subgraphNameArg,
initial: subgraphNameArg,
required: true,
},
Expand Down Expand Up @@ -158,6 +159,7 @@ export default class DeployCommand extends Command {
name: 'versionLabel',
message: () => 'Which version label to use? (e.g. "v0.0.1")',
initial: versionLabelFlag,
skip: () => !!versionLabelFlag,
required: true,
},
]);
Expand Down Expand Up @@ -191,10 +193,10 @@ export default class DeployCommand extends Command {
errorMessage += '\nYou may need to authenticate first.';
}
spinner.fail(errorMessage);
this.exit(1);
process.exit(1);
} else if (requestError) {
spinner.fail(`HTTP error deploying the subgraph ${requestError.code}`);
this.exit(1);
process.exit(1);
} else {
spinner.stop();

Expand Down
5 changes: 2 additions & 3 deletions packages/cli/src/compiler/asc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ export interface CompileOptions {
// it requires an asynchronous wait. Whenever you call this function,
// it doesn't matter how many times, just make sure you call `ready`
// once before everything..
export const compile = ({ inputFile, global, baseDir, libs, outputFile }: CompileOptions) => {
export const compile = async ({ inputFile, global, baseDir, libs, outputFile }: CompileOptions) => {
const exitHandler = createExitHandler(inputFile);

setupExitHandler(exitHandler);

const compilerArgs = [
'--explicitStart',
'--exportRuntime',
'--runtime',
'stub',
Expand All @@ -56,7 +55,7 @@ export const compile = ({ inputFile, global, baseDir, libs, outputFile }: Compil
'--debug',
];

assemblyScriptCompiler(compilerArgs, compilerDefaults);
await assemblyScriptCompiler(compilerArgs, compilerDefaults);

// only if compiler succeeded, that is, when the line above doesn't throw
removeExitHandler(exitHandler);
Expand Down
61 changes: 36 additions & 25 deletions packages/cli/src/compiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,30 +246,41 @@ export default class Compiler {
// Cache compiled files so identical input files are only compiled once
const compiledFiles = new Map();

subgraph = subgraph.update('dataSources', (dataSources: any[]) =>
dataSources.map((dataSource: any) =>
dataSource.updateIn(['mapping', 'file'], (mappingPath: string) =>
this._compileDataSourceMapping(
this.protocol,
dataSource,
// Handle data sources
const dataSources = subgraph.get('dataSources');
const compiledDataSources = await Promise.all(
dataSources.map(async (dataSource: any) => {
const mappingPath = dataSource.getIn(['mapping', 'file']);
const compiledPath = await this._compileDataSourceMapping(
this.protocol,
dataSource,
mappingPath,
compiledFiles,
spinner,
validate,
);
return dataSource.setIn(['mapping', 'file'], compiledPath);
}),
);
subgraph = subgraph.set('dataSources', compiledDataSources);

// Handle templates if they exist
const templates = subgraph.get('templates');
if (templates !== undefined) {
const compiledTemplates = await Promise.all(
templates.map(async (template: any) => {
const mappingPath = template.getIn(['mapping', 'file']);
const compiledPath = await this._compileTemplateMapping(
template,
mappingPath,
compiledFiles,
spinner,
validate,
),
),
),
);

subgraph = subgraph.update('templates', (templates: any) =>
templates === undefined
? templates
: templates.map((template: any) =>
template.updateIn(['mapping', 'file'], (mappingPath: string) =>
this._compileTemplateMapping(template, mappingPath, compiledFiles, spinner),
),
),
);
);
return template.setIn(['mapping', 'file'], compiledPath);
}),
);
subgraph = subgraph.set('templates', compiledTemplates);
}

return subgraph;
},
Expand Down Expand Up @@ -332,7 +343,7 @@ export default class Compiler {
return missingHandlers;
}

_compileDataSourceMapping(
async _compileDataSourceMapping(
protocol: Protocol,
dataSource: immutable.Map<any, any>,
mappingPath: string,
Expand Down Expand Up @@ -386,7 +397,7 @@ export default class Compiler {
}
const global = path.relative(baseDir, this.globalsFile);

asc.compile({
await asc.compile({
inputFile,
global,
baseDir,
Expand All @@ -413,7 +424,7 @@ export default class Compiler {
}
}

_compileTemplateMapping(
async _compileTemplateMapping(
template: immutable.Collection<any, any>,
mappingPath: string,
compiledFiles: Map<any, any>,
Expand Down Expand Up @@ -467,7 +478,7 @@ export default class Compiler {
}
const global = path.relative(baseDir, this.globalsFile);

asc.compile({
await asc.compile({
inputFile,
global,
baseDir,
Expand Down
53 changes: 25 additions & 28 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f2726cb

Please sign in to comment.