Skip to content

Commit f2726cb

Browse files
Cleanup dependencies and compiler fix (#1848)
* 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>
1 parent 1651e60 commit f2726cb

File tree

7 files changed

+78
-58
lines changed

7 files changed

+78
-58
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@graphprotocol/graph-cli": patch
3+
---
4+
dependencies updates:
5+
- Added dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/prettier/v/3.4.2) (to `dependencies`)
6+
- Added dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/undici/v/7.1.1) (to `dependencies`)

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
"pnpm": {
4343
"patchedDependencies": {
4444
45+
},
46+
"overrides": {
47+
"rimraf": "^6.0.0"
4548
}
4649
}
4750
}

packages/cli/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@
5151
"js-yaml": "4.1.0",
5252
"kubo-rpc-client": "^5.0.2",
5353
"open": "10.1.0",
54+
"prettier": "3.4.2",
5455
"semver": "7.6.3",
5556
"tmp-promise": "3.0.3",
57+
"undici": "7.1.1",
5658
"web3-eth-abi": "4.4.1",
5759
"yaml": "2.6.1"
5860
},

packages/cli/src/commands/deploy.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export default class DeployCommand extends Command {
116116
type: 'input',
117117
name: 'subgraphName',
118118
message: () => 'What is the subgraph name?',
119+
skip: () => !!subgraphNameArg,
119120
initial: subgraphNameArg,
120121
required: true,
121122
},
@@ -158,6 +159,7 @@ export default class DeployCommand extends Command {
158159
name: 'versionLabel',
159160
message: () => 'Which version label to use? (e.g. "v0.0.1")',
160161
initial: versionLabelFlag,
162+
skip: () => !!versionLabelFlag,
161163
required: true,
162164
},
163165
]);
@@ -191,10 +193,10 @@ export default class DeployCommand extends Command {
191193
errorMessage += '\nYou may need to authenticate first.';
192194
}
193195
spinner.fail(errorMessage);
194-
this.exit(1);
196+
process.exit(1);
195197
} else if (requestError) {
196198
spinner.fail(`HTTP error deploying the subgraph ${requestError.code}`);
197-
this.exit(1);
199+
process.exit(1);
198200
} else {
199201
spinner.stop();
200202

packages/cli/src/compiler/asc.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ export interface CompileOptions {
3434
// it requires an asynchronous wait. Whenever you call this function,
3535
// it doesn't matter how many times, just make sure you call `ready`
3636
// once before everything..
37-
export const compile = ({ inputFile, global, baseDir, libs, outputFile }: CompileOptions) => {
37+
export const compile = async ({ inputFile, global, baseDir, libs, outputFile }: CompileOptions) => {
3838
const exitHandler = createExitHandler(inputFile);
3939

4040
setupExitHandler(exitHandler);
4141

4242
const compilerArgs = [
43-
'--explicitStart',
4443
'--exportRuntime',
4544
'--runtime',
4645
'stub',
@@ -56,7 +55,7 @@ export const compile = ({ inputFile, global, baseDir, libs, outputFile }: Compil
5655
'--debug',
5756
];
5857

59-
assemblyScriptCompiler(compilerArgs, compilerDefaults);
58+
await assemblyScriptCompiler(compilerArgs, compilerDefaults);
6059

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

packages/cli/src/compiler/index.ts

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

249-
subgraph = subgraph.update('dataSources', (dataSources: any[]) =>
250-
dataSources.map((dataSource: any) =>
251-
dataSource.updateIn(['mapping', 'file'], (mappingPath: string) =>
252-
this._compileDataSourceMapping(
253-
this.protocol,
254-
dataSource,
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,
255275
mappingPath,
256276
compiledFiles,
257277
spinner,
258-
validate,
259-
),
260-
),
261-
),
262-
);
263-
264-
subgraph = subgraph.update('templates', (templates: any) =>
265-
templates === undefined
266-
? templates
267-
: templates.map((template: any) =>
268-
template.updateIn(['mapping', 'file'], (mappingPath: string) =>
269-
this._compileTemplateMapping(template, mappingPath, compiledFiles, spinner),
270-
),
271-
),
272-
);
278+
);
279+
return template.setIn(['mapping', 'file'], compiledPath);
280+
}),
281+
);
282+
subgraph = subgraph.set('templates', compiledTemplates);
283+
}
273284

274285
return subgraph;
275286
},
@@ -332,7 +343,7 @@ export default class Compiler {
332343
return missingHandlers;
333344
}
334345

335-
_compileDataSourceMapping(
346+
async _compileDataSourceMapping(
336347
protocol: Protocol,
337348
dataSource: immutable.Map<any, any>,
338349
mappingPath: string,
@@ -386,7 +397,7 @@ export default class Compiler {
386397
}
387398
const global = path.relative(baseDir, this.globalsFile);
388399

389-
asc.compile({
400+
await asc.compile({
390401
inputFile,
391402
global,
392403
baseDir,
@@ -413,7 +424,7 @@ export default class Compiler {
413424
}
414425
}
415426

416-
_compileTemplateMapping(
427+
async _compileTemplateMapping(
417428
template: immutable.Collection<any, any>,
418429
mappingPath: string,
419430
compiledFiles: Map<any, any>,
@@ -467,7 +478,7 @@ export default class Compiler {
467478
}
468479
const global = path.relative(baseDir, this.globalsFile);
469480

470-
asc.compile({
481+
await asc.compile({
471482
inputFile,
472483
global,
473484
baseDir,

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)