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
@@ -1,5 +1,7 @@
1
1
  import { addIndexer } from 'apibara/create';
2
2
  import { defineCommand } from 'citty';
3
+ import { a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
4
+ import 'consola';
3
5
 
4
6
  const add = defineCommand({
5
7
  meta: {
@@ -9,34 +11,40 @@ const add = defineCommand({
9
11
  args: {
10
12
  indexerId: {
11
13
  type: "positional",
12
- description: "Indexer ID",
14
+ description: "Indexer ID - must be in kebab-case",
13
15
  required: false
14
16
  },
15
17
  chain: {
16
18
  type: "string",
17
- description: "Chain"
19
+ description: "Blockchain - ethereum, beaconchain, starknet"
18
20
  },
19
21
  network: {
20
22
  type: "string",
21
- description: "Network"
23
+ description: "Network - mainnet, sepolia, other"
22
24
  },
23
25
  storage: {
24
26
  type: "string",
25
- description: "Storage"
27
+ description: "Storage - postgres, none"
26
28
  },
27
29
  dnaUrl: {
28
30
  type: "string",
29
- description: "DNA URL"
31
+ description: "DNA URL - https://custom-dna-url.apibara.org"
32
+ },
33
+ dir: {
34
+ type: "string",
35
+ description: "Root directory - apibara project root where apibara.config is located | default: current working directory"
30
36
  }
31
37
  },
32
- async run({ args }) {
33
- const { indexerId, chain, network, storage, dnaUrl } = args;
38
+ async run({ args, cmd }) {
39
+ await checkForUnknownArgs(args, cmd);
40
+ const { indexerId, chain, network, storage, dnaUrl, dir } = args;
34
41
  await addIndexer({
35
42
  argIndexerId: indexerId,
36
43
  argChain: chain,
37
44
  argNetwork: network,
38
45
  argStorage: storage,
39
- argDnaUrl: dnaUrl
46
+ argDnaUrl: dnaUrl,
47
+ argRootDir: dir
40
48
  });
41
49
  }
42
50
  });
@@ -2,7 +2,8 @@ import { createApibara, prepare, writeTypes, build as build$1 } from 'apibara/co
2
2
  import { runtimeDir } from 'apibara/runtime/meta';
3
3
  import { defineCommand } from 'citty';
4
4
  import { resolve, join } from 'pathe';
5
- import { c as commonArgs } from '../shared/apibara.1b515d04.mjs';
5
+ import { c as commonArgs, a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
6
+ import 'consola';
6
7
 
7
8
  const build = defineCommand({
8
9
  meta: {
@@ -12,7 +13,8 @@ const build = defineCommand({
12
13
  args: {
13
14
  ...commonArgs
14
15
  },
15
- async run({ args }) {
16
+ async run({ args, cmd }) {
17
+ await checkForUnknownArgs(args, cmd);
16
18
  const rootDir = resolve(args.dir || args._dir || ".");
17
19
  const apibara = await createApibara({
18
20
  rootDir
@@ -4,7 +4,10 @@ import { runtimeDir } from 'apibara/runtime/meta';
4
4
  import { defineCommand } from 'citty';
5
5
  import { colors } from 'consola/utils';
6
6
  import { resolve, join } from 'pathe';
7
- import { c as commonArgs } from '../shared/apibara.1b515d04.mjs';
7
+ import { b as blueBright, g as gray } from '../shared/apibara.730bb1e4.mjs';
8
+ import { c as commonArgs, a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
9
+ import 'picocolors';
10
+ import 'consola';
8
11
 
9
12
  const hmrKeyRe = /^runtimeConfig\./;
10
13
  const dev = defineCommand({
@@ -21,10 +24,22 @@ const dev = defineCommand({
21
24
  preset: {
22
25
  type: "string",
23
26
  description: "Preset to use"
27
+ },
28
+ "always-reindex": {
29
+ type: "boolean",
30
+ default: false,
31
+ description: "Reindex the indexers from the starting block on every restart | default: `false`"
24
32
  }
25
33
  },
26
- async run({ args }) {
34
+ async run({ args, data, cmd, rawArgs }) {
35
+ await checkForUnknownArgs(args, cmd);
27
36
  const rootDir = resolve(args.dir || args._dir || ".");
37
+ if (args["always-reindex"]) {
38
+ process.env.APIBARA_ALWAYS_REINDEX = "true";
39
+ }
40
+ const selectedIndexers = new Set(
41
+ args.indexers?.split(",").map((i) => i.trim()).sort() ?? []
42
+ );
28
43
  let apibara;
29
44
  let childProcess;
30
45
  const reload = async () => {
@@ -37,7 +52,8 @@ const dev = defineCommand({
37
52
  }
38
53
  apibara = await createApibara(
39
54
  {
40
- rootDir
55
+ rootDir,
56
+ preset: args.preset
41
57
  },
42
58
  {
43
59
  watch: true,
@@ -62,18 +78,24 @@ const dev = defineCommand({
62
78
  await prepare(apibara);
63
79
  await writeTypes(apibara);
64
80
  await build(apibara);
65
- apibara.hooks.hook("dev:restart", () => {
81
+ apibara.hooks.hook("dev:restart", async () => {
66
82
  if (childProcess) {
67
83
  apibara.logger.info("Change detected, stopping indexers to restart");
68
- childProcess.kill();
84
+ await killProcess(childProcess);
69
85
  childProcess = void 0;
70
86
  }
71
87
  });
72
- apibara.hooks.hook("dev:reload", () => {
88
+ apibara.hooks.hook("dev:reload", async () => {
73
89
  if (childProcess) {
74
- childProcess.kill();
90
+ apibara.logger.info("Restarting indexers");
91
+ await killProcess(childProcess);
92
+ childProcess = void 0;
75
93
  } else {
76
- apibara.logger.success("Restarting indexers");
94
+ apibara.logger.info("Starting indexers");
95
+ const indexersText = apibara.indexers.map(
96
+ (i) => selectedIndexers.has(i.name) || selectedIndexers.size === 0 ? blueBright(i.name) : gray(i.name)
97
+ ).join(", ");
98
+ apibara.logger.info("Indexers:", indexersText);
77
99
  }
78
100
  const childArgs = [
79
101
  resolve(apibara.options.outputDir || "./.apibara/build", "dev.mjs"),
@@ -84,17 +106,25 @@ const dev = defineCommand({
84
106
  childProcess = spawn("node", childArgs, {
85
107
  stdio: "inherit"
86
108
  });
87
- childProcess.on("close", (code) => {
88
- if (code !== null) {
89
- apibara.logger.log(
90
- `Indexers process exited with code ${colors.red(code)}`
91
- );
92
- }
109
+ childProcess.on("close", (code, signal) => {
110
+ childProcess = void 0;
111
+ console.log();
112
+ apibara.logger.log(
113
+ `Indexers process exited${code !== null ? ` with code ${colors.red(code)}` : ""}`
114
+ );
93
115
  });
94
116
  });
95
117
  };
96
118
  await reload();
97
119
  }
98
120
  });
121
+ async function killProcess(childProcess) {
122
+ if (childProcess) {
123
+ await new Promise((resolve2) => {
124
+ childProcess.once("exit", resolve2);
125
+ childProcess.kill();
126
+ });
127
+ }
128
+ }
99
129
 
100
130
  export { dev as default };
@@ -1,5 +1,7 @@
1
1
  import { initializeProject } from 'apibara/create';
2
2
  import { defineCommand } from 'citty';
3
+ import { a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
4
+ import 'consola';
3
5
 
4
6
  const init = defineCommand({
5
7
  meta: {
@@ -14,22 +16,24 @@ const init = defineCommand({
14
16
  },
15
17
  language: {
16
18
  type: "string",
17
- description: "Language to use: typescript, ts or javascript, js",
19
+ description: "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
+ const { dir: targetDir, "create-indexer": createIndexer, language } = args;
29
33
  await initializeProject({
30
34
  argTargetDir: targetDir,
31
35
  argLanguage: language,
32
- argNoCreateIndexer: noIndexer
36
+ argNoCreateIndexer: !createIndexer
33
37
  });
34
38
  }
35
39
  });
@@ -1,7 +1,8 @@
1
1
  import { createApibara, writeTypes } from 'apibara/core';
2
2
  import { defineCommand } from 'citty';
3
3
  import { resolve } from 'pathe';
4
- import { c as commonArgs } from '../shared/apibara.1b515d04.mjs';
4
+ import { c as commonArgs, a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
5
+ import 'consola';
5
6
 
6
7
  const prepare = defineCommand({
7
8
  meta: {
@@ -11,7 +12,8 @@ const prepare = defineCommand({
11
12
  args: {
12
13
  ...commonArgs
13
14
  },
14
- async run({ args }) {
15
+ async run({ args, cmd }) {
16
+ await checkForUnknownArgs(args, cmd);
15
17
  const rootDir = resolve(args.dir || ".");
16
18
  const apibara = await createApibara({ rootDir });
17
19
  await writeTypes(apibara);
@@ -1,9 +1,11 @@
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 { c as commonArgs } from '../shared/apibara.1b515d04.mjs';
7
+ import { c as commonArgs, a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
8
+ import 'consola';
7
9
 
8
10
  const start = defineCommand({
9
11
  meta: {
@@ -22,11 +24,13 @@ const start = defineCommand({
22
24
  description: "The preset to use"
23
25
  }
24
26
  },
25
- async run({ args }) {
27
+ async run({ args, cmd }) {
26
28
  const { indexer, preset } = args;
27
29
  const rootDir = resolve(args.dir || args._dir || ".");
30
+ await checkForUnknownArgs(args, cmd);
28
31
  const apibara = await createApibara({
29
- rootDir
32
+ rootDir,
33
+ preset
30
34
  });
31
35
  apibara.logger.start(
32
36
  `Starting indexer ${indexer}${preset ? ` with preset ${preset}` : ""}`
@@ -47,9 +51,15 @@ const start = defineCommand({
47
51
  indexer,
48
52
  ...preset ? ["--preset", preset] : []
49
53
  ];
50
- spawn("node", childArgs, {
54
+ const childProcess = spawn("node", childArgs, {
51
55
  stdio: "inherit"
52
56
  });
57
+ childProcess.on("close", (code, signal) => {
58
+ console.log();
59
+ apibara.logger.log(
60
+ `Indexers process exited${code !== null ? ` with code ${colors.red(code)}` : ""}`
61
+ );
62
+ });
53
63
  }
54
64
  });
55
65
 
@@ -0,0 +1,50 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { join } from 'node:path';
3
+ import { createApibara, prepare, writeTypes, build } 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 { c as commonArgs, a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
9
+
10
+ const writeProjectInfo = 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
+ consola.start("Generating `project-info.json`");
21
+ const rootDir = resolve(args.dir || ".");
22
+ const apibara = await createApibara({ rootDir, disableLogs: true });
23
+ apibara.options.entry = join(runtimeDir, "project-info.mjs");
24
+ await prepare(apibara);
25
+ await writeTypes(apibara);
26
+ await build(apibara);
27
+ const childArgs = [
28
+ resolve(
29
+ apibara.options.outputDir || "./.apibara/build",
30
+ "project-info.mjs"
31
+ ),
32
+ "start",
33
+ "--build-dir",
34
+ apibara.options.buildDir
35
+ ];
36
+ const child = spawn("node", childArgs, {
37
+ stdio: "inherit"
38
+ });
39
+ child.on("close", (code) => {
40
+ if (code === 0) {
41
+ consola.success("Project info written to `.apibara/project-info.json`");
42
+ }
43
+ });
44
+ child.on("error", (error) => {
45
+ consola.error(`Failed to write project info: ${error.message}`, error);
46
+ });
47
+ }
48
+ });
49
+
50
+ export { writeProjectInfo as default };
@@ -13,7 +13,8 @@ const mainCli = defineCommand({
13
13
  start: () => import('../chunks/start.mjs').then((r) => r.default),
14
14
  prepare: () => import('../chunks/prepare.mjs').then((r) => r.default),
15
15
  init: () => import('../chunks/init.mjs').then((r) => r.default),
16
- add: () => import('../chunks/add.mjs').then((r) => r.default)
16
+ add: () => import('../chunks/add.mjs').then((r) => r.default),
17
+ "write-project-info": () => import('../chunks/write-project-info.mjs').then((r) => r.default)
17
18
  }
18
19
  });
19
20
  runMain(mainCli);
@@ -3,14 +3,13 @@ import { createHooks } from 'hookable';
3
3
  import { watchConfig, loadConfig } from 'c12';
4
4
  import { klona } from 'klona/full';
5
5
  import { resolve, join, basename, isAbsolute, relative, dirname } from 'pathe';
6
- import defu from 'defu';
7
6
  import fse from 'fs-extra';
8
- import { getRollupConfig } from 'apibara/rollup';
7
+ import { getRolldownConfig } from 'apibara/rolldown';
8
+ import { colors } from 'consola/utils';
9
9
  import { watch } from 'chokidar';
10
+ import defu from 'defu';
10
11
  import { debounce } from 'perfect-debounce';
11
- import * as rollup from 'rollup';
12
- import { rollup as rollup$1 } from 'rollup';
13
- import { colors } from 'consola/utils';
12
+ import * as rolldown from 'rolldown';
14
13
  import fsp from 'node:fs/promises';
15
14
  import { generateTypes, resolveSchema } from 'untyped';
16
15
 
@@ -24,7 +23,9 @@ const ApibaraDefaults = {
24
23
  strict: false,
25
24
  generateRuntimeConfigTypes: true,
26
25
  internalPaths: false
27
- }
26
+ },
27
+ node: true,
28
+ exportConditions: ["node"]
28
29
  };
29
30
 
30
31
  async function resolvePathOptions(options) {
@@ -37,25 +38,17 @@ async function resolvePathOptions(options) {
37
38
  }
38
39
  }
39
40
 
40
- async function presetResolver(options) {
41
- if (options.preset && options.presets?.[options.preset]) {
42
- const new_options = defu(options.presets[options.preset], options);
43
- Object.assign(options, new_options);
44
- }
45
- }
46
-
47
- async function resolveRuntimeConfigOptions(options) {
48
- options.runtimeConfig = { ...options.runtimeConfig };
49
- process.env.APIBARA_RUNTIME_CONFIG = JSON.stringify(options.runtimeConfig);
50
- }
51
-
52
- const configResolvers = [
53
- resolvePathOptions,
54
- resolveRuntimeConfigOptions,
55
- presetResolver
56
- ];
41
+ const configResolvers = [resolvePathOptions];
57
42
  async function loadOptions(configOverrides = {}, opts = {}, dev = false) {
58
43
  const options = await _loadUserConfig(configOverrides, opts, dev);
44
+ try {
45
+ JSON.stringify(options.runtimeConfig);
46
+ } catch (error) {
47
+ throw new Error(
48
+ "Non-serializable runtimeConfig. Please ensure the config is serializable.",
49
+ { cause: error }
50
+ );
51
+ }
59
52
  for (const resolver of configResolvers) {
60
53
  await resolver(options);
61
54
  }
@@ -83,7 +76,7 @@ async function _loadUserConfig(configOverrides = {}, opts = {}, dev = false) {
83
76
  }
84
77
 
85
78
  async function updateApibaraConfig(apibara, _config) {
86
- await apibara.hooks.callHook("rollup:reload");
79
+ await apibara.hooks.callHook("rolldown:reload");
87
80
  apibara.logger.success("Apibara config hot reloaded!");
88
81
  }
89
82
 
@@ -119,6 +112,7 @@ function indexerNameFromFile(file) {
119
112
 
120
113
  async function createApibara(config = {}, opts = {}, dev = false) {
121
114
  const options = await loadOptions(config, opts, dev);
115
+ process.env.NODE_OPTIONS = process.env.NODE_OPTIONS ? `${process.env.NODE_OPTIONS} --enable-source-maps` : "--enable-source-maps";
122
116
  const apibara = {
123
117
  options,
124
118
  indexers: [],
@@ -134,20 +128,20 @@ async function createApibara(config = {}, opts = {}, dev = false) {
134
128
  return apibara;
135
129
  }
136
130
 
137
- function formatRollupError(_error) {
131
+ function formatRolldownError(_error) {
138
132
  try {
139
133
  const logs = [_error.toString()];
140
134
  const errors = _error?.errors || [_error];
141
135
  for (const error of errors) {
142
136
  const id = error.path || error.id || _error.id;
143
137
  let path = isAbsolute(id) ? relative(process.cwd(), id) : id;
144
- const location = error.loc || error.location;
138
+ const location = error.loc;
145
139
  if (location) {
146
140
  path += `:${location.line}:${location.column}`;
147
141
  }
148
- const text = error.text || error.frame;
142
+ const text = error.frame;
149
143
  logs.push(
150
- `Rollup error while processing \`${path}\`` + text ? "\n\n" + text : ""
144
+ `Rolldown error while processing \`${path}\`` + text ? "\n\n" + text : ""
151
145
  );
152
146
  }
153
147
  return logs.join("\n");
@@ -156,45 +150,48 @@ function formatRollupError(_error) {
156
150
  }
157
151
  }
158
152
 
159
- async function watchDev(apibara, rollupConfig) {
160
- let rollupWatcher;
153
+ async function watchDev(apibara, rolldownConfig) {
154
+ let rolldownWatcher;
161
155
  async function load() {
162
- if (rollupWatcher) {
163
- await rollupWatcher.close();
156
+ apibara.logger.start("Setting up a dev server");
157
+ if (rolldownWatcher) {
158
+ await rolldownWatcher.close();
164
159
  }
165
- rollupWatcher = startRollupWatcher(apibara, rollupConfig);
160
+ rolldownWatcher = startRolldownWatcher(apibara, rolldownConfig);
166
161
  }
167
- const reload = debounce(load);
168
- const watchPatterns = [join(apibara.options.rootDir, "indexers")];
162
+ const reload = debounce(async () => await load());
163
+ const watchPatterns = getWatchPatterns(apibara);
169
164
  const watchReloadEvents = /* @__PURE__ */ new Set(["add", "addDir", "unlink", "unlinkDir"]);
170
165
  const reloadWatcher = watch(watchPatterns, { ignoreInitial: true }).on(
171
166
  "all",
172
- (event) => {
167
+ async (event) => {
173
168
  if (watchReloadEvents.has(event)) {
174
- reload();
169
+ await reload();
175
170
  }
176
171
  }
177
172
  );
178
173
  apibara.hooks.hook("close", () => {
179
- rollupWatcher.close();
174
+ rolldownWatcher.close();
180
175
  reloadWatcher.close();
181
176
  });
182
- apibara.hooks.hook("rollup:reload", () => reload());
177
+ apibara.hooks.hook("rolldown:reload", async () => await reload());
183
178
  await load();
184
179
  }
185
- function startRollupWatcher(apibara, rollupConfig) {
186
- const watcher = rollup.watch(
187
- defu(rollupConfig, {
180
+ function startRolldownWatcher(apibara, rolldownConfig) {
181
+ const ignorePatterns = getIgnorePatterns();
182
+ const watcher = rolldown.watch(
183
+ defu(rolldownConfig, {
188
184
  watch: {
189
- chokidar: apibara.options.watchOptions
185
+ exclude: ignorePatterns,
186
+ ...apibara.options.watchOptions ?? {}
190
187
  }
191
188
  })
192
189
  );
193
190
  let start;
194
- watcher.on("event", (event) => {
191
+ watcher.on("event", async (event) => {
195
192
  switch (event.code) {
196
193
  case "START": {
197
- apibara.hooks.callHook("dev:restart");
194
+ await apibara.hooks.callHook("dev:restart");
198
195
  return;
199
196
  }
200
197
  case "BUNDLE_START": {
@@ -207,37 +204,55 @@ function startRollupWatcher(apibara, rollupConfig) {
207
204
  "Indexers built",
208
205
  start ? `in ${Date.now() - start} ms` : ""
209
206
  );
210
- apibara.hooks.callHook("dev:reload");
207
+ await apibara.hooks.callHook("dev:reload");
211
208
  return;
212
209
  }
213
210
  case "ERROR": {
214
- apibara.logger.error(formatRollupError(event.error));
211
+ apibara.logger.error(formatRolldownError(event.error));
215
212
  }
216
213
  }
217
214
  });
218
215
  return watcher;
219
216
  }
217
+ const getWatchPatterns = (apibara) => [
218
+ join(apibara.options.rootDir, "indexers")
219
+ ];
220
+ const getIgnorePatterns = (apibara) => [
221
+ "**/.apibara/**",
222
+ "**/.git/**",
223
+ "**/.DS_Store",
224
+ "**/node_modules/**",
225
+ "**/dist/**",
226
+ "**/.turbo/**"
227
+ ];
220
228
 
221
- async function buildProduction(apibara, rollupConfig) {
222
- apibara.logger.start(
223
- `Building ${colors.cyan(apibara.indexers.length)} indexers`
224
- );
229
+ async function buildProduction(apibara, rolldownConfig) {
230
+ if (!apibara.options.disableLogs) {
231
+ apibara.logger.start(
232
+ `Building ${colors.cyan(apibara.indexers.length)} indexers`
233
+ );
234
+ }
235
+ const startTime = Date.now();
225
236
  try {
226
- const bundle = await rollup$1(rollupConfig);
227
- if (Array.isArray(rollupConfig.output)) {
228
- for (const outputOptions of rollupConfig.output) {
237
+ const bundle = await rolldown.rolldown(rolldownConfig);
238
+ if (Array.isArray(rolldownConfig.output)) {
239
+ for (const outputOptions of rolldownConfig.output) {
229
240
  await bundle.write(outputOptions);
230
241
  }
231
- } else if (rollupConfig.output) {
232
- await bundle.write(rollupConfig.output);
242
+ } else if (rolldownConfig.output) {
243
+ await bundle.write(rolldownConfig.output);
233
244
  } else {
234
- throw new Error("No output options specified in Rollup config");
245
+ throw new Error("No output options specified in Rolldown config");
235
246
  }
236
247
  await bundle.close();
237
- apibara.logger.success("Build succeeded!");
238
- apibara.logger.info(
239
- `You can start the indexers with ${colors.cyan("apibara start")}`
240
- );
248
+ const endTime = Date.now();
249
+ const duration = endTime - startTime;
250
+ if (!apibara.options.disableLogs) {
251
+ apibara.logger.success(`Build succeeded in ${duration}ms`);
252
+ apibara.logger.info(
253
+ `You can start the indexers with ${colors.cyan("apibara start")}`
254
+ );
255
+ }
241
256
  } catch (error) {
242
257
  apibara.logger.error("Build failed", error);
243
258
  throw error;
@@ -245,9 +260,16 @@ async function buildProduction(apibara, rollupConfig) {
245
260
  }
246
261
 
247
262
  async function build(apibara) {
248
- const rollupConfig = getRollupConfig(apibara);
249
- await apibara.hooks.callHook("rollup:before", apibara, rollupConfig);
250
- return apibara.options.dev ? await watchDev(apibara, rollupConfig) : await buildProduction(apibara, rollupConfig);
263
+ const rolldownConfig = getRolldownConfig(apibara);
264
+ await apibara.hooks.callHook("rolldown:before", apibara, rolldownConfig);
265
+ if (apibara.options.rollupConfig) {
266
+ apibara.logger.error(
267
+ `
268
+ ${colors.cyan("apibara.config:")} rollupConfig is deprecated. Use rolldownConfig instead`
269
+ );
270
+ process.exit(1);
271
+ }
272
+ return apibara.options.dev ? await watchDev(apibara, rolldownConfig) : await buildProduction(apibara, rolldownConfig);
251
273
  }
252
274
 
253
275
  function prettyPath(path, highlight = true) {
@@ -258,9 +280,11 @@ function prettyPath(path, highlight = true) {
258
280
  async function prepare(apibara) {
259
281
  await prepareDir(apibara.options.buildDir);
260
282
  await prepareDir(apibara.options.outputDir);
261
- apibara.logger.success(
262
- `Output directory ${prettyPath(apibara.options.outputDir)} cleaned`
263
- );
283
+ if (!apibara.options.disableLogs) {
284
+ apibara.logger.success(
285
+ `Output directory ${prettyPath(apibara.options.outputDir)} cleaned`
286
+ );
287
+ }
264
288
  }
265
289
  async function prepareDir(dir) {
266
290
  await fsp.mkdir(dir, { recursive: true });
@@ -268,6 +292,10 @@ async function prepareDir(dir) {
268
292
  }
269
293
 
270
294
  async function writeTypes(apibara) {
295
+ const isTypeScript = apibara.options._c12.configFile?.endsWith(".ts");
296
+ if (!isTypeScript) {
297
+ return;
298
+ }
271
299
  const typesDir = resolve(apibara.options.buildDir, "types");
272
300
  const config = [
273
301
  "// Generated by apibara",
@@ -303,7 +331,9 @@ declare module "apibara/types" {`,
303
331
  await fsp.writeFile(_file, file.contents);
304
332
  })
305
333
  );
306
- apibara.logger.success(`Types written to ${prettyPath(typesDir)}`);
334
+ if (!apibara.options.disableLogs) {
335
+ apibara.logger.success(`Types written to ${prettyPath(typesDir)}`);
336
+ }
307
337
  }
308
338
 
309
339
  export { build, createApibara, prepare, writeTypes };
@@ -4,8 +4,9 @@ type Options$1 = {
4
4
  argNetwork?: string;
5
5
  argStorage?: string;
6
6
  argDnaUrl?: string;
7
+ argRootDir?: string;
7
8
  };
8
- declare function addIndexer({ argIndexerId, argChain, argNetwork, argStorage, argDnaUrl, }: Options$1): Promise<void>;
9
+ declare function addIndexer({ argIndexerId, argChain, argNetwork, argStorage, argDnaUrl, argRootDir, }: Options$1): Promise<void>;
9
10
 
10
11
  type Options = {
11
12
  argTargetDir: string;
@@ -4,8 +4,9 @@ type Options$1 = {
4
4
  argNetwork?: string;
5
5
  argStorage?: string;
6
6
  argDnaUrl?: string;
7
+ argRootDir?: string;
7
8
  };
8
- declare function addIndexer({ argIndexerId, argChain, argNetwork, argStorage, argDnaUrl, }: Options$1): Promise<void>;
9
+ declare function addIndexer({ argIndexerId, argChain, argNetwork, argStorage, argDnaUrl, argRootDir, }: Options$1): Promise<void>;
9
10
 
10
11
  type Options = {
11
12
  argTargetDir: string;