Skip to content

Commit d0c74cd

Browse files
authored
fix: typegen globals expansion (#711)
1 parent 4c8b0d6 commit d0c74cd

File tree

7 files changed

+40
-24
lines changed

7 files changed

+40
-24
lines changed

.changeset/sixty-bugs-ring.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@fuel-ts/abi-typegen": patch
3+
---
4+
5+
Fixing globals pattern expasion for `--inputs` paths

packages/abi-typegen/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ $ fuels-typegen -h
3434
Usage: fuels-typegen -i ../out/*-abi.json -o ./generated/
3535

3636
Options:
37-
-V, --version output the version number
38-
-i, --input <path|glob> input path/global to your abi json files
39-
-o, --output <dir> directory path for generated files
40-
-s, --silent omit output messages
41-
-h, --help display help for command
37+
-V, --version output the version number
38+
-i, --inputs <path|glob...> input paths/globals to your abi json files
39+
-o, --output <dir> directory path for generated files
40+
-s, --silent omit output messages
41+
-h, --help display help for command
4242
```
4343

4444
## Generating types

packages/abi-typegen/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"transpile:hbs": "ts-node ./scripts/transpile.hbs.ts",
5353
"prebuild": "pnpm transpile:hbs",
5454
"build": "tsup --dts",
55+
"build:watch": "tsup --dts --watch",
5556
"build:fixtures": "ts-node ./test/fixtures/buildAll.ts"
5657
}
5758
}

packages/abi-typegen/src/cli.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ describe('cli.ts', () => {
2222
});
2323

2424
// compute filepaths
25-
const input = join(tempDir, '/out/debug/*-abi.json');
25+
const inputs = [join(tempDir, '/out/debug/*-abi.json')];
2626
const output = join(tempDir, 'generated');
2727

2828
// executes program
29-
const argv = ['node', 'fuels-typegen', '-i', input, '-o', output];
29+
const argv = ['node', 'fuels-typegen', '-i', inputs.join(' '), '-o', output];
3030
const fn = () => run({ argv, programName: 'cli.js:test' });
3131
const { error } = await executeAndCatch(fn);
3232

@@ -37,7 +37,7 @@ describe('cli.ts', () => {
3737

3838
expect(runTypegen).toHaveBeenNthCalledWith(1, {
3939
cwd: process.cwd(),
40-
input,
40+
inputs,
4141
output,
4242
silent: false,
4343
});

packages/abi-typegen/src/cli.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import { versions } from '@fuel-ts/versions';
22
import { Command } from 'commander';
3-
import { resolve } from 'path';
43

54
import { runTypegen } from './runTypegen';
65

7-
export function runCliAction(options: Record<string, string>) {
8-
const cwd = process.cwd();
9-
10-
const input = resolve(options.input);
11-
const output = resolve(options.output);
12-
const silent = Boolean(options.silent);
6+
export interface ICliParams {
7+
inputs: string[];
8+
output: string;
9+
silent: boolean;
10+
}
1311

14-
runTypegen({ cwd, input, output, silent });
12+
export function runCliAction(options: ICliParams) {
13+
const cwd = process.cwd();
14+
const { inputs, output, silent } = options;
15+
runTypegen({ cwd, inputs, output, silent: !!silent });
1516
}
1617

1718
export function configureCliOptions(program: Command) {
1819
program
19-
.requiredOption('-i, --input <path|glob>', 'input path/global to your abi json files')
20+
.requiredOption('-i, --inputs <path|glob...>', 'input paths/globals to your abi json files')
2021
.requiredOption('-o, --output <dir>', 'directory path for generated files')
2122
.option('-s, --silent', 'omit output messages')
2223
.action(runCliAction);

packages/abi-typegen/src/runTypegen.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { existsSync } from 'fs';
22
import { sync as globSync } from 'glob';
33
import { join } from 'path';
44
import rimraf from 'rimraf';
5+
// eslint-disable-next-line import/no-extraneous-dependencies
6+
import shelljs from 'shelljs';
57

68
import { contractPaths } from '../test/fixtures';
79
import { executeAndCatch } from '../test/utils/executeAndCatch';
@@ -20,17 +22,23 @@ describe('runTypegen.js', () => {
2022
autoBuild,
2123
});
2224

25+
// duplicates ABI JSON so we can validate if all inputs
26+
// are being collected (and not only the first one)
27+
const from = join(tempDir, 'out/debug/full-abi.json');
28+
const to = join(tempDir, 'out/debug/full2-abi.json');
29+
shelljs.cp(from, to);
30+
2331
// compute filepaths
2432
const cwd = process.cwd();
25-
const input = join(tempDir, '/out/debug/*-abi.json');
33+
const inputs = [join(tempDir, '/out/debug/*-abi.json')];
2634
const output = join(tempDir, 'generated');
2735
const silent = true;
2836

2937
// executes program
3038
const fn = () =>
3139
runTypegen({
3240
cwd,
33-
input,
41+
inputs,
3442
output,
3543
silent,
3644
});
@@ -45,10 +53,11 @@ describe('runTypegen.js', () => {
4553
join(output, 'index.ts'),
4654
join(output, 'common.d.ts'),
4755
join(output, `${normalizedContractName}Abi.d.ts`),
56+
join(output, `${normalizedContractName}2Abi.d.ts`),
4857
join(output, 'factories', `${normalizedContractName}Abi__factory.ts`),
4958
];
5059

51-
expect(files.length).toEqual(4);
60+
expect(files.length).toEqual(5);
5261

5362
files.forEach((f) => {
5463
expect(existsSync(f)).toEqual(true);

packages/abi-typegen/src/runTypegen.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import type { IFile } from './interfaces/IFile';
1010
export interface IGenerateFilesParams {
1111
cwd: string;
1212
filepaths?: string[];
13-
input?: string;
13+
inputs?: string[];
1414
output: string;
1515
silent?: boolean;
1616
}
1717

1818
export function runTypegen(params: IGenerateFilesParams) {
19-
const { cwd, input, output, silent, filepaths: originalFilepaths } = params;
19+
const { cwd, inputs, output, silent, filepaths: originalFilepaths } = params;
2020

2121
const cwdBasename = basename(cwd);
2222

@@ -30,8 +30,8 @@ export function runTypegen(params: IGenerateFilesParams) {
3030
*/
3131
let filepaths: string[] = [];
3232

33-
if (!originalFilepaths?.length && input) {
34-
filepaths = globSync(input, { cwd });
33+
if (!originalFilepaths?.length && inputs?.length) {
34+
filepaths = inputs.flatMap((i) => globSync(i, { cwd }));
3535
} else if (originalFilepaths?.length) {
3636
filepaths = originalFilepaths;
3737
} else {

0 commit comments

Comments
 (0)