apibara 2.1.0-beta.3 → 2.1.0-beta.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/chunks/add.mjs +16 -8
  2. package/dist/chunks/build.mjs +4 -2
  3. package/dist/chunks/dev.mjs +44 -14
  4. package/dist/chunks/init.mjs +11 -7
  5. package/dist/chunks/prepare.mjs +4 -2
  6. package/dist/chunks/start.mjs +14 -4
  7. package/dist/chunks/write-project-info.mjs +50 -0
  8. package/dist/cli/index.mjs +2 -1
  9. package/dist/core/index.mjs +98 -68
  10. package/dist/create/index.d.mts +2 -1
  11. package/dist/create/index.d.ts +2 -1
  12. package/dist/create/index.mjs +142 -112
  13. package/dist/hooks/index.mjs +1 -1
  14. package/dist/rolldown/index.d.mts +7 -0
  15. package/dist/rolldown/index.d.ts +7 -0
  16. package/dist/rolldown/index.mjs +159 -0
  17. package/dist/runtime/dev.mjs +14 -4
  18. package/dist/runtime/internal/app.d.ts +6 -1
  19. package/dist/runtime/internal/app.mjs +50 -19
  20. package/dist/runtime/internal/helper.d.ts +12 -0
  21. package/dist/runtime/internal/helper.mjs +33 -0
  22. package/dist/runtime/project-info.d.ts +3 -0
  23. package/dist/runtime/project-info.mjs +53 -0
  24. package/dist/runtime/start.mjs +18 -4
  25. package/dist/shared/apibara.63c9a277.mjs +29 -0
  26. package/dist/shared/apibara.730bb1e4.mjs +17 -0
  27. package/dist/types/index.d.mts +23 -19
  28. package/dist/types/index.d.ts +23 -19
  29. package/package.json +13 -16
  30. package/src/cli/commands/add.ts +16 -7
  31. package/src/cli/commands/build.ts +5 -2
  32. package/src/cli/commands/dev.ts +56 -13
  33. package/src/cli/commands/init.ts +12 -7
  34. package/src/cli/commands/prepare.ts +4 -2
  35. package/src/cli/commands/start.ts +16 -3
  36. package/src/cli/commands/write-project-info.ts +56 -0
  37. package/src/cli/common.ts +33 -1
  38. package/src/cli/index.ts +2 -0
  39. package/src/core/apibara.ts +5 -0
  40. package/src/core/build/build.ts +13 -5
  41. package/src/core/build/dev.ts +44 -23
  42. package/src/core/build/error.ts +9 -14
  43. package/src/core/build/prepare.ts +5 -3
  44. package/src/core/build/prod.ts +25 -16
  45. package/src/core/build/types.ts +11 -1
  46. package/src/core/config/defaults.ts +3 -0
  47. package/src/core/config/loader.ts +13 -7
  48. package/src/core/config/resolvers/preset.resolver.ts +3 -0
  49. package/src/core/config/update.ts +1 -1
  50. package/src/create/add.ts +10 -9
  51. package/src/create/constants.ts +10 -11
  52. package/src/create/init.ts +8 -5
  53. package/src/create/templates.ts +130 -102
  54. package/src/hooks/useRuntimeConfig.ts +1 -1
  55. package/src/rolldown/config.ts +111 -0
  56. package/src/rolldown/index.ts +2 -0
  57. package/src/rolldown/plugins/config.ts +17 -0
  58. package/src/{rollup → rolldown}/plugins/indexers.ts +3 -3
  59. package/src/rolldown/plugins/instrumentation.ts +68 -0
  60. package/src/runtime/dev.ts +16 -4
  61. package/src/runtime/internal/app.ts +66 -25
  62. package/src/runtime/internal/helper.ts +55 -0
  63. package/src/runtime/project-info.ts +72 -0
  64. package/src/runtime/start.ts +21 -4
  65. package/src/types/config.ts +23 -12
  66. package/src/types/hooks.ts +8 -5
  67. package/src/types/index.ts +1 -1
  68. package/src/types/rolldown.ts +5 -0
  69. package/src/types/virtual/config.d.ts +4 -1
  70. package/src/types/virtual/indexers.d.ts +4 -1
  71. package/src/types/virtual/instrumentation.d.ts +4 -0
  72. package/dist/rollup/index.d.mts +0 -6
  73. package/dist/rollup/index.d.ts +0 -6
  74. package/dist/rollup/index.mjs +0 -150
  75. package/dist/shared/apibara.1b515d04.mjs +0 -8
  76. package/src/core/config/resolvers/runtime-config.resolver.ts +0 -6
  77. package/src/rollup/config.ts +0 -87
  78. package/src/rollup/index.ts +0 -2
  79. package/src/rollup/plugins/config.ts +0 -12
  80. package/src/rollup/plugins/esm-shim.ts +0 -69
  81. package/src/types/rollup.ts +0 -8
@@ -5,7 +5,8 @@ import type { Apibara } from "apibara/types";
5
5
  import { defineCommand } from "citty";
6
6
  import { colors } from "consola/utils";
7
7
  import { join, resolve } from "pathe";
8
- import { commonArgs } from "../common";
8
+ import { blueBright, gray } from "../../create/colors";
9
+ import { checkForUnknownArgs, commonArgs } from "../common";
9
10
 
10
11
  // Hot module reloading key regex
11
12
  // for only runtimeConfig.* keys
@@ -26,10 +27,29 @@ export default defineCommand({
26
27
  type: "string",
27
28
  description: "Preset to use",
28
29
  },
30
+ "always-reindex": {
31
+ type: "boolean",
32
+ default: false,
33
+ description:
34
+ "Reindex the indexers from the starting block on every restart | default: `false`",
35
+ },
29
36
  },
30
- async run({ args }) {
37
+ async run({ args, data, cmd, rawArgs }) {
38
+ await checkForUnknownArgs(args, cmd);
39
+
31
40
  const rootDir = resolve((args.dir || args._dir || ".") as string);
32
41
 
42
+ if (args["always-reindex"]) {
43
+ process.env.APIBARA_ALWAYS_REINDEX = "true";
44
+ }
45
+
46
+ const selectedIndexers = new Set(
47
+ args.indexers
48
+ ?.split(",")
49
+ .map((i) => i.trim())
50
+ .sort() ?? [],
51
+ );
52
+
33
53
  let apibara: Apibara;
34
54
  let childProcess: ChildProcess | undefined;
35
55
 
@@ -46,6 +66,7 @@ export default defineCommand({
46
66
  apibara = await createApibara(
47
67
  {
48
68
  rootDir,
69
+ preset: args.preset,
49
70
  },
50
71
  {
51
72
  watch: true,
@@ -79,19 +100,30 @@ export default defineCommand({
79
100
  await writeTypes(apibara);
80
101
  await build(apibara);
81
102
 
82
- apibara.hooks.hook("dev:restart", () => {
103
+ apibara.hooks.hook("dev:restart", async () => {
83
104
  if (childProcess) {
84
105
  apibara.logger.info("Change detected, stopping indexers to restart");
85
- childProcess.kill();
106
+ await killProcess(childProcess);
86
107
  childProcess = undefined;
87
108
  }
88
109
  });
89
110
 
90
- apibara.hooks.hook("dev:reload", () => {
111
+ apibara.hooks.hook("dev:reload", async () => {
91
112
  if (childProcess) {
92
- childProcess.kill();
113
+ apibara.logger.info("Restarting indexers");
114
+ await killProcess(childProcess);
115
+ childProcess = undefined;
93
116
  } else {
94
- apibara.logger.success("Restarting indexers");
117
+ apibara.logger.info("Starting indexers");
118
+
119
+ const indexersText = apibara.indexers
120
+ .map((i) =>
121
+ selectedIndexers.has(i.name) || selectedIndexers.size === 0
122
+ ? blueBright(i.name)
123
+ : gray(i.name),
124
+ )
125
+ .join(", ");
126
+ apibara.logger.info("Indexers:", indexersText);
95
127
  }
96
128
 
97
129
  const childArgs = [
@@ -105,12 +137,14 @@ export default defineCommand({
105
137
  stdio: "inherit",
106
138
  });
107
139
 
108
- childProcess.on("close", (code) => {
109
- if (code !== null) {
110
- apibara.logger.log(
111
- `Indexers process exited with code ${colors.red(code)}`,
112
- );
113
- }
140
+ childProcess.on("close", (code, signal) => {
141
+ childProcess = undefined;
142
+ console.log();
143
+ apibara.logger.log(
144
+ `Indexers process exited${
145
+ code !== null ? ` with code ${colors.red(code)}` : ""
146
+ }`,
147
+ );
114
148
  });
115
149
  });
116
150
  };
@@ -118,3 +152,12 @@ export default defineCommand({
118
152
  await reload();
119
153
  },
120
154
  });
155
+
156
+ async function killProcess(childProcess: ChildProcess | undefined) {
157
+ if (childProcess) {
158
+ await new Promise((resolve) => {
159
+ childProcess.once("exit", resolve);
160
+ childProcess.kill();
161
+ });
162
+ }
163
+ }
@@ -1,5 +1,6 @@
1
1
  import { initializeProject } from "apibara/create";
2
2
  import { defineCommand } from "citty";
3
+ import { checkForUnknownArgs } from "../common";
3
4
 
4
5
  export default defineCommand({
5
6
  meta: {
@@ -14,23 +15,27 @@ export default defineCommand({
14
15
  },
15
16
  language: {
16
17
  type: "string",
17
- description: "Language to use: typescript, ts or javascript, js",
18
+ description:
19
+ "Language to use: typescript, ts or javascript, js | default: `ts`",
18
20
  default: "ts",
19
21
  alias: "l",
20
22
  },
21
- noIndexer: {
23
+ "create-indexer": {
22
24
  type: "boolean",
23
- description: "Do not create an indexer after initialization",
24
- default: false,
25
+ name: "create-indexer",
26
+ default: true,
27
+ description: "TODO",
25
28
  },
26
29
  },
27
- async run({ args }) {
28
- const { dir: targetDir, noIndexer, language } = args;
30
+ async run({ args, cmd }) {
31
+ await checkForUnknownArgs(args, cmd);
32
+
33
+ const { dir: targetDir, "create-indexer": createIndexer, language } = args;
29
34
 
30
35
  await initializeProject({
31
36
  argTargetDir: targetDir,
32
37
  argLanguage: language,
33
- argNoCreateIndexer: noIndexer,
38
+ argNoCreateIndexer: !createIndexer,
34
39
  });
35
40
  },
36
41
  });
@@ -2,7 +2,7 @@ import { createApibara, writeTypes } from "apibara/core";
2
2
  import {} from "apibara/types";
3
3
  import { defineCommand } from "citty";
4
4
  import { resolve } from "pathe";
5
- import { commonArgs } from "../common";
5
+ import { checkForUnknownArgs, commonArgs } from "../common";
6
6
 
7
7
  export default defineCommand({
8
8
  meta: {
@@ -12,7 +12,9 @@ export default defineCommand({
12
12
  args: {
13
13
  ...commonArgs,
14
14
  },
15
- async run({ args }) {
15
+ async run({ args, cmd }) {
16
+ await checkForUnknownArgs(args, cmd);
17
+
16
18
  const rootDir = resolve((args.dir || ".") as string);
17
19
  const apibara = await createApibara({ rootDir });
18
20
  await writeTypes(apibara);
@@ -1,9 +1,10 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { createApibara } from "apibara/core";
3
3
  import { defineCommand } from "citty";
4
+ import { colors } from "consola/utils";
4
5
  import fse from "fs-extra";
5
6
  import { resolve } from "pathe";
6
- import { commonArgs } from "../common";
7
+ import { checkForUnknownArgs, commonArgs } from "../common";
7
8
 
8
9
  export default defineCommand({
9
10
  meta: {
@@ -22,12 +23,15 @@ export default defineCommand({
22
23
  description: "The preset to use",
23
24
  },
24
25
  },
25
- async run({ args }) {
26
+ async run({ args, cmd }) {
26
27
  const { indexer, preset } = args;
27
28
  const rootDir = resolve((args.dir || args._dir || ".") as string);
28
29
 
30
+ await checkForUnknownArgs(args, cmd);
31
+
29
32
  const apibara = await createApibara({
30
33
  rootDir,
34
+ preset,
31
35
  });
32
36
 
33
37
  apibara.logger.start(
@@ -54,8 +58,17 @@ export default defineCommand({
54
58
  ...(preset ? ["--preset", preset] : []),
55
59
  ];
56
60
 
57
- spawn("node", childArgs, {
61
+ const childProcess = spawn("node", childArgs, {
58
62
  stdio: "inherit",
59
63
  });
64
+
65
+ childProcess.on("close", (code, signal) => {
66
+ console.log();
67
+ apibara.logger.log(
68
+ `Indexers process exited${
69
+ code !== null ? ` with code ${colors.red(code)}` : ""
70
+ }`,
71
+ );
72
+ });
60
73
  },
61
74
  });
@@ -0,0 +1,56 @@
1
+ import { spawn } from "node:child_process";
2
+ import { join } from "node:path";
3
+ import { build, createApibara, prepare, writeTypes } from "apibara/core";
4
+ import { runtimeDir } from "apibara/runtime/meta";
5
+ import { defineCommand } from "citty";
6
+ import consola from "consola";
7
+ import { resolve } from "pathe";
8
+ import { checkForUnknownArgs, commonArgs } from "../common";
9
+
10
+ export default defineCommand({
11
+ meta: {
12
+ name: "write-project-info",
13
+ description: "Write json-encoded information about the project.",
14
+ },
15
+ args: {
16
+ ...commonArgs,
17
+ },
18
+ async run({ args, cmd }) {
19
+ await checkForUnknownArgs(args, cmd);
20
+
21
+ consola.start("Generating `project-info.json`");
22
+
23
+ const rootDir = resolve((args.dir || ".") as string);
24
+ const apibara = await createApibara({ rootDir, disableLogs: true });
25
+
26
+ apibara.options.entry = join(runtimeDir, "project-info.mjs");
27
+
28
+ await prepare(apibara);
29
+ await writeTypes(apibara);
30
+ await build(apibara);
31
+
32
+ const childArgs = [
33
+ resolve(
34
+ apibara.options.outputDir || "./.apibara/build",
35
+ "project-info.mjs",
36
+ ),
37
+ "start",
38
+ "--build-dir",
39
+ apibara.options.buildDir,
40
+ ];
41
+
42
+ const child = spawn("node", childArgs, {
43
+ stdio: "inherit",
44
+ });
45
+
46
+ child.on("close", (code) => {
47
+ if (code === 0) {
48
+ consola.success("Project info written to `.apibara/project-info.json`");
49
+ }
50
+ });
51
+
52
+ child.on("error", (error) => {
53
+ consola.error(`Failed to write project info: ${error.message}`, error);
54
+ });
55
+ },
56
+ });
package/src/cli/common.ts CHANGED
@@ -1,4 +1,10 @@
1
- import type { ArgsDef } from "citty";
1
+ import {
2
+ type ArgsDef,
3
+ type CommandDef,
4
+ type ParsedArgs,
5
+ renderUsage,
6
+ } from "citty";
7
+ import consola from "consola";
2
8
 
3
9
  export const commonArgs = <ArgsDef>{
4
10
  dir: {
@@ -6,3 +12,29 @@ export const commonArgs = <ArgsDef>{
6
12
  description: "project root directory",
7
13
  },
8
14
  };
15
+
16
+ export const checkForUnknownArgs = async <T extends ArgsDef = ArgsDef>(
17
+ args: ParsedArgs<T>,
18
+ cmd: CommandDef<T>,
19
+ ) => {
20
+ // Create a list of defined args including both the main arg names and their aliases
21
+ const definedArgs: string[] = [];
22
+ if (cmd.args) {
23
+ for (const [argName, argDef] of Object.entries(cmd.args)) {
24
+ definedArgs.push(argName);
25
+ // Add alias to definedArgs if it exists
26
+ if (argDef.alias) {
27
+ definedArgs.push(argDef.alias);
28
+ }
29
+ }
30
+ }
31
+
32
+ const providedArgs = Object.keys(args).filter((arg) => arg !== "_");
33
+ const wrongArgs = providedArgs.filter((arg) => !definedArgs.includes(arg));
34
+
35
+ if (wrongArgs.length > 0) {
36
+ consola.error(`Unknown arguments: ${wrongArgs.join(", ")}`);
37
+ consola.info(await renderUsage(cmd));
38
+ process.exit(1);
39
+ }
40
+ };
package/src/cli/index.ts CHANGED
@@ -13,6 +13,8 @@ export const mainCli = defineCommand({
13
13
  prepare: () => import("./commands/prepare").then((r) => r.default),
14
14
  init: () => import("./commands/init").then((r) => r.default),
15
15
  add: () => import("./commands/add").then((r) => r.default),
16
+ "write-project-info": () =>
17
+ import("./commands/write-project-info").then((r) => r.default),
16
18
  },
17
19
  });
18
20
 
@@ -17,6 +17,11 @@ export async function createApibara(
17
17
  ): Promise<Apibara> {
18
18
  const options = await loadOptions(config, opts, dev);
19
19
 
20
+ // Enable source map support in Node
21
+ process.env.NODE_OPTIONS = process.env.NODE_OPTIONS
22
+ ? `${process.env.NODE_OPTIONS} --enable-source-maps`
23
+ : "--enable-source-maps";
24
+
20
25
  const apibara: Apibara = {
21
26
  options,
22
27
  indexers: [],
@@ -1,14 +1,22 @@
1
- import { getRollupConfig } from "apibara/rollup";
1
+ import { getRolldownConfig } from "apibara/rolldown";
2
2
  import type { Apibara } from "apibara/types";
3
+ import { colors } from "consola/utils";
3
4
  import { watchDev } from "./dev";
4
5
  import { buildProduction } from "./prod";
5
6
 
6
7
  export async function build(apibara: Apibara) {
7
- const rollupConfig = getRollupConfig(apibara);
8
+ const rolldownConfig = getRolldownConfig(apibara);
8
9
 
9
- await apibara.hooks.callHook("rollup:before", apibara, rollupConfig);
10
+ await apibara.hooks.callHook("rolldown:before", apibara, rolldownConfig);
11
+
12
+ if (apibara.options.rollupConfig) {
13
+ apibara.logger.error(
14
+ `\n${colors.cyan("apibara.config:")} rollupConfig is deprecated. Use rolldownConfig instead`,
15
+ );
16
+ process.exit(1);
17
+ }
10
18
 
11
19
  return apibara.options.dev
12
- ? await watchDev(apibara, rollupConfig)
13
- : await buildProduction(apibara, rollupConfig);
20
+ ? await watchDev(apibara, rolldownConfig)
21
+ : await buildProduction(apibara, rolldownConfig);
14
22
  }
@@ -1,59 +1,67 @@
1
- import type { Apibara, RollupConfig } from "apibara/types";
1
+ import type { Apibara } from "apibara/types";
2
2
  import { watch } from "chokidar";
3
3
  import defu from "defu";
4
4
  import { join } from "pathe";
5
5
  import { debounce } from "perfect-debounce";
6
- import * as rollup from "rollup";
7
- import { formatRollupError } from "./error";
8
-
9
- export async function watchDev(apibara: Apibara, rollupConfig: RollupConfig) {
10
- let rollupWatcher: rollup.RollupWatcher;
6
+ import * as rolldown from "rolldown";
7
+ import { formatRolldownError } from "./error";
11
8
 
9
+ export async function watchDev(
10
+ apibara: Apibara,
11
+ rolldownConfig: rolldown.RolldownOptions,
12
+ ) {
13
+ let rolldownWatcher: rolldown.RolldownWatcher;
12
14
  async function load() {
13
- if (rollupWatcher) {
14
- await rollupWatcher.close();
15
+ apibara.logger.start("Setting up a dev server");
16
+ if (rolldownWatcher) {
17
+ await rolldownWatcher.close();
15
18
  }
16
- rollupWatcher = startRollupWatcher(apibara, rollupConfig);
19
+ rolldownWatcher = startRolldownWatcher(apibara, rolldownConfig);
17
20
  }
18
- const reload = debounce(load);
21
+ const reload = debounce(async () => await load());
19
22
 
20
- const watchPatterns = [join(apibara.options.rootDir, "indexers")];
23
+ const watchPatterns = getWatchPatterns(apibara);
21
24
 
22
25
  const watchReloadEvents = new Set(["add", "addDir", "unlink", "unlinkDir"]);
23
26
  const reloadWatcher = watch(watchPatterns, { ignoreInitial: true }).on(
24
27
  "all",
25
- (event) => {
28
+ async (event) => {
26
29
  if (watchReloadEvents.has(event)) {
27
- reload();
30
+ await reload();
28
31
  }
29
32
  },
30
33
  );
31
34
 
32
35
  apibara.hooks.hook("close", () => {
33
- rollupWatcher.close();
36
+ rolldownWatcher.close();
34
37
  reloadWatcher.close();
35
38
  });
36
39
 
37
- apibara.hooks.hook("rollup:reload", () => reload());
40
+ apibara.hooks.hook("rolldown:reload", async () => await reload());
38
41
 
39
42
  await load();
40
43
  }
41
44
 
42
- function startRollupWatcher(apibara: Apibara, rollupConfig: RollupConfig) {
43
- const watcher = rollup.watch(
44
- defu(rollupConfig, {
45
+ function startRolldownWatcher(
46
+ apibara: Apibara,
47
+ rolldownConfig: rolldown.RolldownOptions,
48
+ ) {
49
+ const ignorePatterns = getIgnorePatterns(apibara);
50
+ const watcher = rolldown.watch(
51
+ defu(rolldownConfig, {
45
52
  watch: {
46
- chokidar: apibara.options.watchOptions,
53
+ exclude: ignorePatterns,
54
+ ...((apibara.options.watchOptions ?? {}) as rolldown.WatchOptions),
47
55
  },
48
56
  }),
49
57
  );
50
58
  let start: number;
51
59
 
52
- watcher.on("event", (event) => {
60
+ watcher.on("event", async (event) => {
53
61
  switch (event.code) {
54
62
  // The watcher is (re)starting
55
63
  case "START": {
56
- apibara.hooks.callHook("dev:restart");
64
+ await apibara.hooks.callHook("dev:restart");
57
65
  return;
58
66
  }
59
67
 
@@ -70,15 +78,28 @@ function startRollupWatcher(apibara: Apibara, rollupConfig: RollupConfig) {
70
78
  "Indexers built",
71
79
  start ? `in ${Date.now() - start} ms` : "",
72
80
  );
73
- apibara.hooks.callHook("dev:reload");
81
+ await apibara.hooks.callHook("dev:reload");
74
82
  return;
75
83
  }
76
84
 
77
85
  // Encountered an error while bundling
78
86
  case "ERROR": {
79
- apibara.logger.error(formatRollupError(event.error));
87
+ apibara.logger.error(formatRolldownError(event.error));
80
88
  }
81
89
  }
82
90
  });
83
91
  return watcher;
84
92
  }
93
+
94
+ const getWatchPatterns = (apibara: Apibara) => [
95
+ join(apibara.options.rootDir, "indexers"),
96
+ ];
97
+
98
+ const getIgnorePatterns = (apibara: Apibara) => [
99
+ "**/.apibara/**",
100
+ "**/.git/**",
101
+ "**/.DS_Store",
102
+ "**/node_modules/**",
103
+ "**/dist/**",
104
+ "**/.turbo/**",
105
+ ];
@@ -1,29 +1,24 @@
1
- import type esbuild from "esbuild";
2
1
  import { isAbsolute, relative } from "pathe";
3
- import type rollup from "rollup";
2
+ import type * as rolldown from "rolldown";
4
3
 
5
- export function formatRollupError(
6
- _error: rollup.RollupError | esbuild.OnResolveResult,
7
- ) {
4
+ export function formatRolldownError(_error: rolldown.RollupError) {
8
5
  try {
9
6
  const logs: string[] = [_error.toString()];
10
7
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
11
- const errors = (_error as any)?.errors || [_error as rollup.RollupError];
8
+ const errors = (_error as any)?.errors || [_error as rolldown.RollupError];
12
9
  for (const error of errors) {
13
- const id = error.path || error.id || (_error as rollup.RollupError).id;
10
+ const id = error.path || error.id || (_error as rolldown.RollupError).id;
14
11
  let path = isAbsolute(id) ? relative(process.cwd(), id) : id;
15
- const location =
16
- (error as rollup.RollupError).loc ||
17
- (error as esbuild.PartialMessage).location;
12
+ const location = (error as rolldown.RollupError).loc;
18
13
  if (location) {
19
14
  path += `:${location.line}:${location.column}`;
20
15
  }
21
- const text =
22
- (error as esbuild.PartialMessage).text ||
23
- (error as rollup.RollupError).frame;
16
+ const text = (error as rolldown.RollupError).frame;
24
17
 
25
18
  logs.push(
26
- `Rollup error while processing \`${path}\`` + text ? "\n\n" + text : "",
19
+ `Rolldown error while processing \`${path}\`` + text
20
+ ? "\n\n" + text
21
+ : "",
27
22
  );
28
23
  }
29
24
  return logs.join("\n");
@@ -7,9 +7,11 @@ export async function prepare(apibara: Apibara) {
7
7
  await prepareDir(apibara.options.buildDir);
8
8
  await prepareDir(apibara.options.outputDir);
9
9
 
10
- apibara.logger.success(
11
- `Output directory ${prettyPath(apibara.options.outputDir)} cleaned`,
12
- );
10
+ if (!apibara.options.disableLogs) {
11
+ apibara.logger.success(
12
+ `Output directory ${prettyPath(apibara.options.outputDir)} cleaned`,
13
+ );
14
+ }
13
15
  }
14
16
 
15
17
  async function prepareDir(dir: string) {
@@ -1,34 +1,43 @@
1
- import type { Apibara, RollupConfig } from "apibara/types";
1
+ import type { Apibara } from "apibara/types";
2
2
  import { colors } from "consola/utils";
3
- import { type OutputOptions, rollup } from "rollup";
3
+ import * as rolldown from "rolldown";
4
4
 
5
5
  export async function buildProduction(
6
6
  apibara: Apibara,
7
- rollupConfig: RollupConfig,
7
+ rolldownConfig: rolldown.RolldownOptions,
8
8
  ) {
9
- apibara.logger.start(
10
- `Building ${colors.cyan(apibara.indexers.length)} indexers`,
11
- );
9
+ if (!apibara.options.disableLogs) {
10
+ apibara.logger.start(
11
+ `Building ${colors.cyan(apibara.indexers.length)} indexers`,
12
+ );
13
+ }
14
+
15
+ const startTime = Date.now();
12
16
 
13
17
  try {
14
- const bundle = await rollup(rollupConfig);
18
+ const bundle = await rolldown.rolldown(rolldownConfig);
15
19
 
16
- if (Array.isArray(rollupConfig.output)) {
17
- for (const outputOptions of rollupConfig.output) {
20
+ if (Array.isArray(rolldownConfig.output)) {
21
+ for (const outputOptions of rolldownConfig.output) {
18
22
  await bundle.write(outputOptions);
19
23
  }
20
- } else if (rollupConfig.output) {
21
- await bundle.write(rollupConfig.output as OutputOptions);
24
+ } else if (rolldownConfig.output) {
25
+ await bundle.write(rolldownConfig.output as rolldown.OutputOptions);
22
26
  } else {
23
- throw new Error("No output options specified in Rollup config");
27
+ throw new Error("No output options specified in Rolldown config");
24
28
  }
25
29
 
26
30
  await bundle.close();
27
31
 
28
- apibara.logger.success("Build succeeded!");
29
- apibara.logger.info(
30
- `You can start the indexers with ${colors.cyan("apibara start")}`,
31
- );
32
+ const endTime = Date.now();
33
+ const duration = endTime - startTime;
34
+
35
+ if (!apibara.options.disableLogs) {
36
+ apibara.logger.success(`Build succeeded in ${duration}ms`);
37
+ apibara.logger.info(
38
+ `You can start the indexers with ${colors.cyan("apibara start")}`,
39
+ );
40
+ }
32
41
  } catch (error) {
33
42
  apibara.logger.error("Build failed", error);
34
43
  throw error;
@@ -5,6 +5,14 @@ import { type JSValue, generateTypes, resolveSchema } from "untyped";
5
5
  import { prettyPath } from "../path";
6
6
 
7
7
  export async function writeTypes(apibara: Apibara) {
8
+ // Check if the config file has a TypeScript extension so we assume it's a TypeScript project
9
+ const isTypeScript = apibara.options._c12.configFile?.endsWith(".ts");
10
+
11
+ if (!isTypeScript) {
12
+ // If it's not a TypeScript project, we don't need to generate the types
13
+ return;
14
+ }
15
+
8
16
  const typesDir = resolve(apibara.options.buildDir, "types");
9
17
 
10
18
  const config = [
@@ -47,5 +55,7 @@ declare module "apibara/types" {`,
47
55
  }),
48
56
  );
49
57
 
50
- apibara.logger.success(`Types written to ${prettyPath(typesDir)}`);
58
+ if (!apibara.options.disableLogs) {
59
+ apibara.logger.success(`Types written to ${prettyPath(typesDir)}`);
60
+ }
51
61
  }
@@ -14,4 +14,7 @@ export const ApibaraDefaults: ApibaraConfig = {
14
14
  generateRuntimeConfigTypes: true,
15
15
  internalPaths: false,
16
16
  },
17
+
18
+ node: true,
19
+ exportConditions: ["node"],
17
20
  };