apibara 2.0.0-beta.8 → 2.1.0-beta.1

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 (83) hide show
  1. package/dist/chunks/add.mjs +44 -0
  2. package/dist/chunks/build.mjs +3 -3
  3. package/dist/chunks/dev.mjs +22 -18
  4. package/dist/chunks/init.mjs +41 -0
  5. package/dist/chunks/prepare.mjs +0 -2
  6. package/dist/chunks/start.mjs +56 -0
  7. package/dist/cli/index.mjs +5 -1
  8. package/dist/config/index.d.mts +1 -1
  9. package/dist/config/index.d.ts +1 -1
  10. package/dist/core/index.mjs +61 -97
  11. package/dist/create/index.d.mts +17 -0
  12. package/dist/create/index.d.ts +17 -0
  13. package/dist/create/index.mjs +961 -0
  14. package/dist/rollup/index.d.mts +2 -1
  15. package/dist/rollup/index.d.ts +2 -1
  16. package/dist/rollup/index.mjs +130 -167
  17. package/dist/runtime/dev.d.ts +3 -0
  18. package/dist/runtime/dev.mjs +55 -0
  19. package/dist/runtime/index.d.ts +2 -0
  20. package/dist/runtime/index.mjs +2 -0
  21. package/dist/runtime/internal/app.d.ts +2 -0
  22. package/dist/runtime/internal/app.mjs +56 -0
  23. package/dist/runtime/internal/logger.d.ts +14 -0
  24. package/dist/runtime/internal/logger.mjs +45 -0
  25. package/dist/runtime/start.d.ts +3 -0
  26. package/dist/runtime/start.mjs +41 -0
  27. package/dist/types/index.d.mts +22 -19
  28. package/dist/types/index.d.ts +22 -19
  29. package/package.json +34 -13
  30. package/runtime-meta.d.ts +2 -0
  31. package/runtime-meta.mjs +7 -0
  32. package/src/cli/commands/add.ts +44 -0
  33. package/src/cli/commands/build.ts +5 -3
  34. package/src/cli/commands/dev.ts +28 -18
  35. package/src/cli/commands/init.ts +40 -0
  36. package/src/cli/commands/prepare.ts +0 -2
  37. package/src/cli/commands/start.ts +61 -0
  38. package/src/cli/index.ts +3 -0
  39. package/src/config/index.ts +5 -4
  40. package/src/core/apibara.ts +4 -2
  41. package/src/core/build/build.ts +2 -0
  42. package/src/core/build/dev.ts +1 -0
  43. package/src/core/build/error.ts +0 -1
  44. package/src/core/build/prepare.ts +5 -2
  45. package/src/core/build/prod.ts +10 -6
  46. package/src/core/build/types.ts +4 -95
  47. package/src/core/config/defaults.ts +1 -4
  48. package/src/core/config/loader.ts +1 -0
  49. package/src/core/config/resolvers/runtime-config.resolver.ts +1 -1
  50. package/src/core/config/update.ts +2 -3
  51. package/src/core/path.ts +11 -0
  52. package/src/core/scan.ts +40 -0
  53. package/src/create/add.ts +225 -0
  54. package/src/create/colors.ts +15 -0
  55. package/src/create/constants.ts +98 -0
  56. package/src/create/index.ts +2 -0
  57. package/src/create/init.ts +164 -0
  58. package/src/create/templates.ts +465 -0
  59. package/src/create/types.ts +34 -0
  60. package/src/create/utils.ts +412 -0
  61. package/src/rollup/config.ts +67 -189
  62. package/src/rollup/index.ts +1 -0
  63. package/src/rollup/plugins/config.ts +12 -0
  64. package/src/rollup/plugins/esm-shim.ts +69 -0
  65. package/src/rollup/plugins/indexers.ts +17 -0
  66. package/src/runtime/dev.ts +64 -0
  67. package/src/runtime/index.ts +2 -0
  68. package/src/runtime/internal/app.ts +78 -0
  69. package/src/runtime/internal/logger.ts +70 -0
  70. package/src/runtime/start.ts +48 -0
  71. package/src/types/apibara.ts +8 -0
  72. package/src/types/config.ts +28 -27
  73. package/src/types/hooks.ts +1 -0
  74. package/src/types/virtual/config.d.ts +3 -0
  75. package/src/types/virtual/indexers.d.ts +10 -0
  76. package/dist/internal/citty/index.d.mts +0 -1
  77. package/dist/internal/citty/index.d.ts +0 -1
  78. package/dist/internal/citty/index.mjs +0 -1
  79. package/dist/internal/consola/index.d.mts +0 -2
  80. package/dist/internal/consola/index.d.ts +0 -2
  81. package/dist/internal/consola/index.mjs +0 -1
  82. package/src/internal/citty/index.ts +0 -1
  83. package/src/internal/consola/index.ts +0 -1
@@ -0,0 +1,412 @@
1
+ import fs from "node:fs";
2
+ import path, { basename } from "node:path";
3
+ import prompts from "prompts";
4
+ import { blue, cyan, red, yellow } from "./colors";
5
+ import { dnaUrls, networks } from "./constants";
6
+ import type { Chain, Language, Network, PkgInfo } from "./types";
7
+
8
+ export function isEmpty(path: string) {
9
+ const files = fs.readdirSync(path);
10
+ return files.length === 0 || (files.length === 1 && files[0] === ".git");
11
+ }
12
+ export function emptyDir(dir: string) {
13
+ if (!fs.existsSync(dir)) {
14
+ return;
15
+ }
16
+ for (const file of fs.readdirSync(dir)) {
17
+ if (file === ".git") {
18
+ continue;
19
+ }
20
+ fs.rmSync(path.resolve(dir, file), { recursive: true, force: true });
21
+ }
22
+ }
23
+
24
+ export function validateLanguage(language?: string, throwError = false) {
25
+ if (!language) {
26
+ return false;
27
+ }
28
+
29
+ if (
30
+ language === "typescript" ||
31
+ language === "ts" ||
32
+ language === "javascript" ||
33
+ language === "js"
34
+ ) {
35
+ return true;
36
+ }
37
+
38
+ if (throwError) {
39
+ throw new Error(
40
+ `Invalid language ${cyan("(--language | -l)")}: ${red(language)}. Options: ${blue("typescript, ts")} or ${yellow("javascript, js")} | default: ${cyan("typescript")}`,
41
+ );
42
+ }
43
+
44
+ return false;
45
+ }
46
+
47
+ export function getLanguageFromAlias(alias: string): Language {
48
+ if (alias === "ts" || alias === "typescript") {
49
+ return "typescript";
50
+ }
51
+ if (alias === "js" || alias === "javascript") {
52
+ return "javascript";
53
+ }
54
+
55
+ throw new Error(
56
+ `Invalid language ${cyan("(--language | -l)")}: ${red(alias)}. Options: ${blue("typescript, ts")} or ${yellow("javascript, js")}`,
57
+ );
58
+ }
59
+
60
+ export function validateIndexerId(indexerId?: string, throwError = false) {
61
+ if (!indexerId) {
62
+ return false;
63
+ }
64
+ if (!/^[a-z0-9-]+$/.test(indexerId)) {
65
+ if (throwError) {
66
+ throw new Error(
67
+ `Invalid indexer ID ${cyan("(--indexer-id)")}: ${red(indexerId)}. Indexer ID must contain only lowercase letters, numbers, and hyphens.`,
68
+ );
69
+ }
70
+ return false;
71
+ }
72
+ return true;
73
+ }
74
+
75
+ export function validateChain(chain?: string, throwError = false) {
76
+ if (!chain) {
77
+ return false;
78
+ }
79
+ if (chain) {
80
+ if (chain === "starknet" || chain === "ethereum" || chain === "beaconchain")
81
+ return true;
82
+ if (throwError) {
83
+ throw new Error(
84
+ `Invalid chain ${cyan("(--chain)")}: ${red(chain)}. Chain must be one of ${blue("starknet, ethereum, beaconchain")}.`,
85
+ );
86
+ }
87
+ return false;
88
+ }
89
+ return true;
90
+ }
91
+
92
+ export function validateNetwork(
93
+ chain?: string,
94
+ network?: string,
95
+ throwError = false,
96
+ ) {
97
+ if (!network) {
98
+ return false;
99
+ }
100
+
101
+ if (network === "other") {
102
+ return true;
103
+ }
104
+
105
+ if (chain) {
106
+ if (chain === "starknet") {
107
+ if (network === "mainnet" || network === "sepolia") {
108
+ return true;
109
+ }
110
+ if (throwError) {
111
+ throw new Error(
112
+ `Invalid network ${cyan("(--network)")}: ${red(network)}. For chain ${blue("starknet")}, network must be one of ${blue("mainnet, sepolia, other")}.`,
113
+ );
114
+ }
115
+ return false;
116
+ }
117
+ if (chain === "ethereum") {
118
+ if (network === "mainnet" || network === "goerli") {
119
+ return true;
120
+ }
121
+ if (throwError) {
122
+ throw new Error(
123
+ `Invalid network ${cyan("(--network)")}: ${red(network)}. For chain ${blue("ethereum")}, network must be one of ${blue("mainnet, goerli, other")}.`,
124
+ );
125
+ }
126
+ return false;
127
+ }
128
+ if (chain === "beaconchain") {
129
+ if (network === "mainnet") {
130
+ return true;
131
+ }
132
+ if (throwError) {
133
+ throw new Error(
134
+ `Invalid network ${cyan("(--network)")}: ${red(network)}. For chain ${blue("beaconchain")}, network must be ${blue("mainnet, other")}.`,
135
+ );
136
+ }
137
+ return false;
138
+ }
139
+ }
140
+
141
+ if (networks.find((n) => n.name === network)) {
142
+ return true;
143
+ }
144
+
145
+ if (throwError) {
146
+ throw new Error(
147
+ `Invalid network ${cyan("(--network)")}: ${red(network)}. Network must be one of ${blue("mainnet, sepolia, goerli, other")}.`,
148
+ );
149
+ }
150
+ return false;
151
+ }
152
+
153
+ export function validateStorage(storage?: string, throwError = false) {
154
+ if (!storage) {
155
+ return false;
156
+ }
157
+ if (storage === "postgres" || storage === "none") {
158
+ return true;
159
+ }
160
+ if (throwError) {
161
+ throw new Error(
162
+ `Invalid storage ${cyan("(--storage)")}: ${red(storage)}. Storage must be one of ${blue("postgres, none")}.`,
163
+ );
164
+ }
165
+ return false;
166
+ }
167
+
168
+ export function validateDnaUrl(dnaUrl?: string, throwError = false) {
169
+ if (!dnaUrl) {
170
+ return false;
171
+ }
172
+ if (!dnaUrl.startsWith("https://") && !dnaUrl.startsWith("http://")) {
173
+ if (throwError) {
174
+ throw new Error(
175
+ `Invalid DNA URL ${cyan("(--dna-url)")}: ${red(dnaUrl)}. DNA URL must start with ${blue("https:// or http://")}.`,
176
+ );
177
+ }
178
+ return false;
179
+ }
180
+ return true;
181
+ }
182
+
183
+ export function hasApibaraConfig(cwd: string): boolean {
184
+ const configPathJS = path.join(cwd, "apibara.config.js");
185
+ const configPathTS = path.join(cwd, "apibara.config.ts");
186
+
187
+ return fs.existsSync(configPathJS) || fs.existsSync(configPathTS);
188
+ }
189
+
190
+ export function getApibaraConfigLanguage(cwd: string): Language {
191
+ const configPathJS = path.join(cwd, "apibara.config.js");
192
+ const configPathTS = path.join(cwd, "apibara.config.ts");
193
+
194
+ if (fs.existsSync(configPathJS)) {
195
+ return "javascript";
196
+ }
197
+ if (fs.existsSync(configPathTS)) {
198
+ return "typescript";
199
+ }
200
+
201
+ throw new Error(red("✖") + " No apibara.config found");
202
+ }
203
+
204
+ export function getDnaUrl(chain: Chain, network: Network) {
205
+ if (chain === "ethereum") {
206
+ if (network === "mainnet") {
207
+ return dnaUrls.ethereum;
208
+ }
209
+ if (network === "sepolia") {
210
+ return dnaUrls.ethereumSepolia;
211
+ }
212
+ }
213
+
214
+ if (chain === "beaconchain") {
215
+ if (network === "mainnet") {
216
+ return dnaUrls.beaconchain;
217
+ }
218
+ }
219
+
220
+ if (chain === "starknet") {
221
+ if (network === "mainnet") {
222
+ return dnaUrls.starknet;
223
+ }
224
+ if (network === "sepolia") {
225
+ return dnaUrls.starknetSepolia;
226
+ }
227
+ }
228
+
229
+ throw new Error(red("✖") + " Invalid chain or network");
230
+ }
231
+
232
+ /**
233
+ * Converts a kebab-case string to camelCase.
234
+ *
235
+ * Examples:
236
+ * - "hello-world" → "helloWorld"
237
+ * - "my-long-variable-name" → "myLongVariableName"
238
+ * - "MY-CAPS" → "myCaps"
239
+ * - "-leading-dash" → "leadingDash"
240
+ * - "trailing-dash-" → "trailingDash"
241
+ * - "double--dash" → "doubleDash"
242
+ * - "hello---world" → "helloWorld"
243
+ * - "mixed_dash-and_underscore" → "mixedDashAndUnderscore"
244
+ *
245
+ * @param str The kebab-case string to convert
246
+ * @returns The camelCase version of the string
247
+ */
248
+ export function convertKebabToCamelCase(_str: string): string {
249
+ let str = _str;
250
+
251
+ // Handle empty or invalid input
252
+ if (!str || typeof str !== "string") {
253
+ return "";
254
+ }
255
+
256
+ // Check if already camelCase
257
+ if (/^[a-z][a-zA-Z0-9]*$/.test(str)) {
258
+ return str;
259
+ }
260
+
261
+ // Trim leading/trailing dashes and spaces
262
+ str = str.trim().replace(/^-+|-+$/g, "");
263
+
264
+ // Handle empty string after trim
265
+ if (!str) {
266
+ return "";
267
+ }
268
+
269
+ return (
270
+ str
271
+ // Replace multiple consecutive dashes/underscores with a single dash
272
+ .replace(/[-_]+/g, "-")
273
+ // Split on dash
274
+ .split("-")
275
+ // Filter out empty strings (from consecutive dashes)
276
+ .filter(Boolean)
277
+ // Convert each word
278
+ .map((word, index) => {
279
+ // Convert word to lowercase
280
+ const _word = word.toLowerCase();
281
+
282
+ // Capitalize first letter if not the first word
283
+ if (index > 0) {
284
+ return _word.charAt(0).toUpperCase() + _word.slice(1);
285
+ }
286
+
287
+ return _word;
288
+ })
289
+ .join("")
290
+ );
291
+ }
292
+
293
+ export async function checkFileExists(
294
+ path: string,
295
+ options?: {
296
+ askPrompt?: boolean;
297
+ fileName?: string;
298
+ allowIgnore?: boolean;
299
+ },
300
+ ): Promise<{
301
+ exists: boolean;
302
+ overwrite: boolean;
303
+ }> {
304
+ const { askPrompt = false, fileName, allowIgnore = false } = options ?? {};
305
+
306
+ if (!fs.existsSync(path)) {
307
+ return {
308
+ exists: false,
309
+ overwrite: false,
310
+ };
311
+ }
312
+
313
+ if (askPrompt) {
314
+ const { overwrite } = await prompts({
315
+ type: "select",
316
+ name: "overwrite",
317
+ message: `${fileName ?? basename(path)} already exists. Please choose how to proceed:`,
318
+ initial: 0,
319
+ choices: [
320
+ ...(allowIgnore
321
+ ? [
322
+ {
323
+ title: "Keep original file",
324
+ value: "ignore",
325
+ },
326
+ ]
327
+ : []),
328
+ {
329
+ title: "Cancel operation",
330
+ value: "no",
331
+ },
332
+ {
333
+ title: "Overwrite file",
334
+ value: "yes",
335
+ },
336
+ ],
337
+ });
338
+
339
+ if (overwrite === "no") {
340
+ cancelOperation();
341
+ }
342
+
343
+ if (overwrite === "ignore") {
344
+ return {
345
+ exists: true,
346
+ overwrite: false,
347
+ };
348
+ }
349
+
350
+ return {
351
+ exists: true,
352
+ overwrite: true,
353
+ };
354
+ }
355
+
356
+ return {
357
+ exists: true,
358
+ overwrite: false,
359
+ };
360
+ }
361
+
362
+ export function cancelOperation(message?: string) {
363
+ throw new Error(red("✖") + (message ?? " Operation cancelled"));
364
+ }
365
+
366
+ export function getPackageManager(): PkgInfo {
367
+ const userAgent = process.env.npm_config_user_agent;
368
+ const pkgInfo = pkgFromUserAgent(userAgent);
369
+ if (pkgInfo) {
370
+ return pkgInfo;
371
+ }
372
+ return {
373
+ name: "npm",
374
+ };
375
+ }
376
+
377
+ /**
378
+
379
+ https://github.com/vitejs/vite/blob/07091a1e804e5934208ef0b6324a04317dd0d815/packages/create-vite/src/index.ts#L585
380
+
381
+ MIT License
382
+
383
+ Copyright (c) 2019-present, VoidZero Inc. and Vite contributors
384
+
385
+ Permission is hereby granted, free of charge, to any person obtaining a copy
386
+ of this software and associated documentation files (the "Software"), to deal
387
+ in the Software without restriction, including without limitation the rights
388
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
389
+ copies of the Software, and to permit persons to whom the Software is
390
+ furnished to do so, subject to the following conditions:
391
+
392
+ The above copyright notice and this permission notice shall be included in all
393
+ copies or substantial portions of the Software.
394
+
395
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
396
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
397
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
398
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
399
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
400
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
401
+ SOFTWARE.
402
+
403
+ */
404
+ function pkgFromUserAgent(userAgent: string | undefined): PkgInfo | undefined {
405
+ if (!userAgent) return undefined;
406
+ const pkgSpec = userAgent.split(" ")[0];
407
+ const pkgSpecArr = pkgSpec.split("/");
408
+ return {
409
+ name: pkgSpecArr[0],
410
+ version: pkgSpecArr[1],
411
+ };
412
+ }
@@ -1,17 +1,19 @@
1
- import { existsSync } from "node:fs";
2
1
  import { builtinModules } from "node:module";
3
2
  import commonjs from "@rollup/plugin-commonjs";
4
3
  import json from "@rollup/plugin-json";
5
4
  import { nodeResolve } from "@rollup/plugin-node-resolve";
6
- import typescript from "@rollup/plugin-typescript";
7
5
  import type { Apibara, RollupConfig } from "apibara/types";
8
- import fsExtra from "fs-extra";
9
- import { basename, join } from "pathe";
6
+ import { join } from "pathe";
7
+ import type { OutputPluginOption } from "rollup";
10
8
 
11
- export const getRollupConfig = (
12
- apibara: Apibara,
13
- dev = false,
14
- ): RollupConfig => {
9
+ import defu from "defu";
10
+ import { appConfig } from "./plugins/config";
11
+ import { esmShim } from "./plugins/esm-shim";
12
+ import { indexers } from "./plugins/indexers";
13
+
14
+ const runtimeDependencies = ["better-sqlite3", "@electric-sql/pglite"];
15
+
16
+ export function getRollupConfig(apibara: Apibara): RollupConfig {
15
17
  const extensions: string[] = [
16
18
  ".ts",
17
19
  ".mjs",
@@ -22,188 +24,64 @@ export const getRollupConfig = (
22
24
  ".jsx",
23
25
  ];
24
26
 
25
- const indexerDir = join(apibara.options.rootDir, "indexers");
26
- const configPath = join(apibara.options.rootDir, "./apibara.config.ts");
27
-
28
- // Check if the indexers directory and config file exist
29
- if (!existsSync(indexerDir)) {
30
- throw new Error(`Indexers directory not found: ${indexerDir}`);
31
- }
32
- if (!existsSync(configPath)) {
33
- throw new Error(`Config file not found: ${configPath}`);
34
- }
35
-
36
- // Check if the indexers directory exists and is not empty
37
- let indexerFiles: string[] = [];
38
- try {
39
- indexerFiles = fsExtra
40
- .readdirSync(indexerDir)
41
- .filter((file) => file.endsWith(".indexer.ts"));
42
- if (indexerFiles.length === 0) {
43
- console.warn(`No indexer files found in ${indexerDir}`);
44
- }
45
- } catch (error) {
46
- console.error(`Error reading indexers directory: ${error}`);
47
- }
48
-
49
- const indexerImports = indexerFiles
50
- .map(
51
- (file, index) =>
52
- `import indexer${index} from '${join(indexerDir, file)}';`,
53
- )
54
- .join("\n");
55
-
56
- // Generate main.ts content
57
- const mainContent = `
58
- import { createClient } from "@apibara/protocol";
59
- import { createIndexer, run } from "@apibara/indexer";
60
- import { consola as _consola } from "apibara/internal/consola";
61
- import { defineCommand, runMain } from "apibara/internal/citty";
62
- import config from './${configPath}';
63
-
64
- const consola = _consola.withTag("Apibara | ");
65
-
66
- ${indexerImports}
67
-
68
- const indexers = {
69
- ${indexerFiles
70
- .map(
71
- (file, index) => `'${basename(file, ".indexer.ts")}': indexer${index},`,
72
- )
73
- .join("\n ")}
74
- };
75
-
76
- const command = defineCommand({
77
- meta: {
78
- name: "run-indexers",
79
- description: "Run Apibara indexers",
80
- },
81
- args: {
82
- indexers: {
83
- type: "string",
84
- description: "Comma-separated list of indexers to run",
85
- },
86
- preset: {
87
- type: "string",
88
- description: "Preset to use",
89
- },
90
- sink: {
91
- type: "string",
92
- description: "Sink to use",
93
- },
94
- },
95
- async run({ args }) {
96
- const selectedIndexers = args.indexers ? args.indexers.split(',') : Object.keys(indexers);
97
- const preset = args.preset || config.preset || 'default';
98
- const sinkName = args.sink || 'default';
99
-
100
- // Apply preset
101
- let runtimeConfig = { ...config.runtimeConfig };
102
- if (preset && config.presets && config.presets[preset]) {
103
- runtimeConfig = { ...runtimeConfig, ...config.presets[preset].runtimeConfig };
104
- }
105
-
106
- // Get sink function
107
- const sinkFunction = config.sink?.[sinkName];
108
- if (!sinkFunction) {
109
- throw new Error(\`Sink \${sinkName} not found\`);
110
- }
111
-
112
- await Promise.all(selectedIndexers.map(async (name) => {
113
- if (!indexers[name]) {
114
- console.error(\`Indexer \${name} not found\`);
115
- return;
116
- }
117
-
118
- const indexerConfig = indexers[name]
119
- const indexer = typeof indexerConfig === 'function'
120
- ? await createIndexer(indexerConfig(runtimeConfig))
121
- : createIndexer(indexerConfig);
122
-
123
- const client = createClient(indexer.streamConfig, indexer.options.streamUrl);
124
- const sink = sinkFunction();
125
-
126
- try {
127
- consola.log("Running Indexer: ", name);
128
- await run(client, indexer, sink);
129
- } catch (error) {
130
- consola.error(\`Error in indexer \${name}:\`, error);
131
- }
132
- }));
133
- },
134
- });
135
-
136
- runMain(command);
137
- `;
138
-
139
- return {
140
- input: {
141
- main: "virtual:main.ts",
142
- },
143
- output: {
144
- dir: join(apibara.options.outputDir || "./.apibara/build"),
145
- format: "esm",
146
- exports: "auto",
147
- entryFileNames: "[name].mjs",
148
- chunkFileNames: "chunks/[name]-[hash].mjs",
149
- generatedCode: {
150
- constBindings: true,
151
- },
152
- sourcemap: true,
153
- sourcemapExcludeSources: true,
154
- sourcemapIgnoreList(relativePath, sourcemapPath) {
155
- return relativePath.includes("node_modules");
156
- },
157
- },
158
- plugins: [
159
- {
160
- name: "virtual",
161
- resolveId(id) {
162
- if (id === "virtual:main.ts") {
163
- return id;
164
- }
165
- return null;
27
+ const rollupConfig: RollupConfig & { plugins: OutputPluginOption[] } = defu(
28
+ // biome-ignore lint/suspicious/noExplicitAny: apibara.options.rollupConfig is typed
29
+ apibara.options.rollupConfig as any,
30
+ <RollupConfig>{
31
+ input: apibara.options.entry,
32
+ output: {
33
+ dir: join(apibara.options.outputDir || "./.apibara/build"),
34
+ format: "esm",
35
+ exports: "auto",
36
+ entryFileNames: "[name].mjs",
37
+ chunkFileNames: "chunks/[name]-[hash].mjs",
38
+ generatedCode: {
39
+ constBindings: true,
166
40
  },
167
- load(id) {
168
- if (id === "virtual:main.ts") {
169
- return mainContent;
170
- }
171
- return null;
41
+ sourcemap: true,
42
+ sourcemapExcludeSources: true,
43
+ sourcemapIgnoreList(relativePath, sourcemapPath) {
44
+ return relativePath.includes("node_modules");
172
45
  },
173
46
  },
174
- nodeResolve({
175
- extensions,
176
- preferBuiltins: true,
177
- }),
178
- commonjs(),
179
- json(),
180
- typescript({
181
- tsconfig: join(apibara.options.rootDir, "./tsconfig.json"),
182
- compilerOptions: {
183
- outDir: join(apibara.options.outputDir || "./.apibara/build"),
184
- declarationDir: join(apibara.options.outputDir || "./.apibara/build"),
185
- noEmit: false,
186
- types: ["node"],
187
- },
188
- }),
189
- ],
190
- onwarn(warning, rollupWarn) {
191
- if (
192
- !["CIRCULAR_DEPENDENCY", "EVAL"].includes(warning.code || "") &&
193
- !warning.message.includes("Unsupported source map comment") &&
194
- !warning.message.includes("@__PURE__")
195
- ) {
196
- rollupWarn(warning);
197
- }
47
+ plugins: [],
48
+ onwarn(warning, rollupWarn) {
49
+ if (
50
+ !["CIRCULAR_DEPENDENCY", "EVAL", "THIS_IS_UNDEFINED"].includes(
51
+ warning.code || "",
52
+ ) &&
53
+ !warning.message.includes("Unsupported source map comment") &&
54
+ !warning.message.includes("@__PURE__") &&
55
+ !warning.message.includes("/*#__PURE__*/")
56
+ ) {
57
+ rollupWarn(warning);
58
+ }
59
+ },
60
+ treeshake: true,
61
+ external: [...builtinModules, ...runtimeDependencies],
198
62
  },
199
- treeshake: true,
200
- external: [
201
- ...builtinModules,
202
- "@apibara/indexer",
203
- "@apibara/protocol",
204
- "@apibara/evm",
205
- "@apibara/starknet",
206
- "@apibara/beaconchain",
207
- ],
208
- };
209
- };
63
+ );
64
+
65
+ rollupConfig.plugins.push(esmShim());
66
+ rollupConfig.plugins.push(json());
67
+
68
+ rollupConfig.plugins.push(
69
+ commonjs({
70
+ strictRequires: true,
71
+ requireReturnsDefault: "auto",
72
+ ...apibara.options.commonJS,
73
+ }),
74
+ );
75
+
76
+ rollupConfig.plugins.push(
77
+ nodeResolve({
78
+ extensions,
79
+ preferBuiltins: true,
80
+ mainFields: ["main"],
81
+ }),
82
+ );
83
+ rollupConfig.plugins.push(indexers(apibara));
84
+ rollupConfig.plugins.push(appConfig(apibara));
85
+
86
+ return rollupConfig;
87
+ }
@@ -1 +1,2 @@
1
1
  export * from "./config";
2
+ export type { Plugin } from "rollup";
@@ -0,0 +1,12 @@
1
+ import virtual from "@rollup/plugin-virtual";
2
+ import type { Apibara } from "apibara/types";
3
+
4
+ export function appConfig(apibara: Apibara) {
5
+ return virtual({
6
+ "#apibara-internal-virtual/config": `
7
+ import * as projectConfig from '${apibara.options._c12.configFile}';
8
+
9
+ export const config = projectConfig.default;
10
+ `,
11
+ });
12
+ }