Skip to content

Commit

Permalink
Fix minor issues with CLI (#115)
Browse files Browse the repository at this point in the history
Fix a couple of small issues I have found while working on the tutorial.

 - a shebang is needed in the CLI file to work with npm
- hash the indexers filename so that users can use special characters in
their indexers name
  • Loading branch information
jaipaljadeja authored Nov 27, 2024
2 parents 383d0fc + 413fd1e commit 15a81d2
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 7 deletions.
7 changes: 7 additions & 0 deletions change/apibara-f4d98eff-8f08-4f04-bf68-8ac249c3c0e7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "cli: add shebang banner to cli module",
"packageName": "apibara",
"email": "[email protected]",
"dependentChangeType": "patch"
}
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions packages/cli/build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ export default defineBuildConfig({
"apibara/runtime/meta",
...modules.map((module) => `apibara/${module}`),
],
rollup: {
output: {
banner: ({ fileName }) =>
fileName === "cli/index.mjs" ? "#!/usr/bin/env node" : undefined,
},
},
});
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"hookable": "^5.5.3",
"klona": "^2.0.6",
"magic-string": "^0.30.12",
"ohash": "^1.1.4",
"pathe": "^1.1.2",
"perfect-debounce": "^1.0.0",
"pkg-types": "^1.1.3",
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/rollup/plugins/indexers.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import virtual from "@rollup/plugin-virtual";
import type { Apibara } from "apibara/types";
import { hash } from "ohash";

export function indexers(apibara: Apibara) {
const indexers = [...new Set(apibara.indexers)];

return virtual({
"#apibara-internal-virtual/indexers": `
${indexers.map((i) => `import ${i.name} from '${i.indexer}';`).join("\n")}
${indexers.map((i) => `import _${hash(i)} from '${i.indexer}';`).join("\n")}
export const indexers = [
${indexers.map((i) => `{ name: "${i.name}", indexer: ${i.name} }`).join(",\n")}
${indexers.map((i) => `{ name: "${i.name}", indexer: _${hash(i)} }`).join(",\n")}
];
`,
});
Expand Down
13 changes: 8 additions & 5 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 15a81d2

Please sign in to comment.