apibara 2.1.0-beta.7 → 2.1.0-beta.9
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.
- package/dist/chunks/add.mjs +7 -2
- package/dist/chunks/dev.mjs +15 -5
- package/dist/core/index.mjs +64 -37
- package/dist/create/index.d.mts +2 -1
- package/dist/create/index.d.ts +2 -1
- package/dist/create/index.mjs +16 -21
- package/dist/rolldown/index.d.mts +7 -0
- package/dist/rolldown/index.d.ts +7 -0
- package/dist/rolldown/index.mjs +90 -0
- package/dist/types/index.d.mts +16 -15
- package/dist/types/index.d.ts +16 -15
- package/package.json +11 -13
- package/src/cli/commands/add.ts +7 -1
- package/src/cli/commands/dev.ts +16 -5
- package/src/core/build/build.ts +13 -5
- package/src/core/build/dev.ts +44 -23
- package/src/core/build/error.ts +9 -7
- package/src/core/build/prod.ts +15 -10
- package/src/core/build/types.ts +8 -0
- package/src/core/config/update.ts +1 -1
- package/src/create/add.ts +10 -12
- package/src/create/constants.ts +0 -1
- package/src/create/init.ts +2 -4
- package/src/create/templates.ts +3 -12
- package/src/rolldown/config.ts +83 -0
- package/src/rolldown/index.ts +2 -0
- package/src/{rollup → rolldown}/plugins/config.ts +2 -1
- package/src/{rollup → rolldown}/plugins/indexers.ts +2 -2
- package/src/types/config.ts +10 -7
- package/src/types/hooks.ts +8 -5
- package/src/types/index.ts +1 -1
- package/src/types/rolldown.ts +5 -0
- package/dist/rollup/index.d.mts +0 -6
- package/dist/rollup/index.d.ts +0 -6
- package/dist/rollup/index.mjs +0 -151
- package/src/rollup/config.ts +0 -89
- package/src/rollup/index.ts +0 -2
- package/src/rollup/plugins/esm-shim.ts +0 -69
- package/src/types/rollup.ts +0 -8
package/dist/chunks/add.mjs
CHANGED
|
@@ -27,16 +27,21 @@ const add = defineCommand({
|
|
|
27
27
|
dnaUrl: {
|
|
28
28
|
type: "string",
|
|
29
29
|
description: "DNA URL - https://custom-dna-url.apibara.org"
|
|
30
|
+
},
|
|
31
|
+
dir: {
|
|
32
|
+
type: "string",
|
|
33
|
+
description: "Root directory - apibara project root where apibara.config is located | default: current working directory"
|
|
30
34
|
}
|
|
31
35
|
},
|
|
32
36
|
async run({ args }) {
|
|
33
|
-
const { indexerId, chain, network, storage, dnaUrl } = args;
|
|
37
|
+
const { indexerId, chain, network, storage, dnaUrl, dir } = args;
|
|
34
38
|
await addIndexer({
|
|
35
39
|
argIndexerId: indexerId,
|
|
36
40
|
argChain: chain,
|
|
37
41
|
argNetwork: network,
|
|
38
42
|
argStorage: storage,
|
|
39
|
-
argDnaUrl: dnaUrl
|
|
43
|
+
argDnaUrl: dnaUrl,
|
|
44
|
+
argRootDir: dir
|
|
40
45
|
});
|
|
41
46
|
}
|
|
42
47
|
});
|
package/dist/chunks/dev.mjs
CHANGED
|
@@ -62,18 +62,20 @@ const dev = defineCommand({
|
|
|
62
62
|
await prepare(apibara);
|
|
63
63
|
await writeTypes(apibara);
|
|
64
64
|
await build(apibara);
|
|
65
|
-
apibara.hooks.hook("dev:restart", () => {
|
|
65
|
+
apibara.hooks.hook("dev:restart", async () => {
|
|
66
66
|
if (childProcess) {
|
|
67
67
|
apibara.logger.info("Change detected, stopping indexers to restart");
|
|
68
|
-
childProcess
|
|
68
|
+
await killProcess(childProcess);
|
|
69
69
|
childProcess = void 0;
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
|
-
apibara.hooks.hook("dev:reload", () => {
|
|
72
|
+
apibara.hooks.hook("dev:reload", async () => {
|
|
73
73
|
if (childProcess) {
|
|
74
|
-
|
|
74
|
+
apibara.logger.info("Restarting indexers");
|
|
75
|
+
await killProcess(childProcess);
|
|
76
|
+
childProcess = void 0;
|
|
75
77
|
} else {
|
|
76
|
-
apibara.logger.
|
|
78
|
+
apibara.logger.info("Starting indexers");
|
|
77
79
|
}
|
|
78
80
|
const childArgs = [
|
|
79
81
|
resolve(apibara.options.outputDir || "./.apibara/build", "dev.mjs"),
|
|
@@ -96,5 +98,13 @@ const dev = defineCommand({
|
|
|
96
98
|
await reload();
|
|
97
99
|
}
|
|
98
100
|
});
|
|
101
|
+
async function killProcess(childProcess) {
|
|
102
|
+
if (childProcess) {
|
|
103
|
+
await new Promise((resolve2) => {
|
|
104
|
+
childProcess.once("exit", resolve2);
|
|
105
|
+
childProcess.kill();
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
99
109
|
|
|
100
110
|
export { dev as default };
|
package/dist/core/index.mjs
CHANGED
|
@@ -5,12 +5,11 @@ import { klona } from 'klona/full';
|
|
|
5
5
|
import { resolve, join, basename, isAbsolute, relative, dirname } from 'pathe';
|
|
6
6
|
import defu from 'defu';
|
|
7
7
|
import fse from 'fs-extra';
|
|
8
|
-
import {
|
|
8
|
+
import { getRolldownConfig } from 'apibara/rolldown';
|
|
9
|
+
import { colors } from 'consola/utils';
|
|
9
10
|
import { watch } from 'chokidar';
|
|
10
11
|
import { debounce } from 'perfect-debounce';
|
|
11
|
-
import * as
|
|
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
|
|
|
@@ -85,7 +84,7 @@ async function _loadUserConfig(configOverrides = {}, opts = {}, dev = false) {
|
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
async function updateApibaraConfig(apibara, _config) {
|
|
88
|
-
await apibara.hooks.callHook("
|
|
87
|
+
await apibara.hooks.callHook("rolldown:reload");
|
|
89
88
|
apibara.logger.success("Apibara config hot reloaded!");
|
|
90
89
|
}
|
|
91
90
|
|
|
@@ -136,7 +135,7 @@ async function createApibara(config = {}, opts = {}, dev = false) {
|
|
|
136
135
|
return apibara;
|
|
137
136
|
}
|
|
138
137
|
|
|
139
|
-
function
|
|
138
|
+
function formatRolldownError(_error) {
|
|
140
139
|
try {
|
|
141
140
|
const logs = [_error.toString()];
|
|
142
141
|
const errors = _error?.errors || [_error];
|
|
@@ -149,7 +148,7 @@ function formatRollupError(_error) {
|
|
|
149
148
|
}
|
|
150
149
|
const text = error.frame;
|
|
151
150
|
logs.push(
|
|
152
|
-
`
|
|
151
|
+
`Rolldown error while processing \`${path}\`` + text ? "\n\n" + text : ""
|
|
153
152
|
);
|
|
154
153
|
}
|
|
155
154
|
return logs.join("\n");
|
|
@@ -158,45 +157,48 @@ function formatRollupError(_error) {
|
|
|
158
157
|
}
|
|
159
158
|
}
|
|
160
159
|
|
|
161
|
-
async function watchDev(apibara,
|
|
162
|
-
let
|
|
160
|
+
async function watchDev(apibara, rolldownConfig) {
|
|
161
|
+
let rolldownWatcher;
|
|
163
162
|
async function load() {
|
|
164
|
-
|
|
165
|
-
|
|
163
|
+
apibara.logger.start("Setting up a dev server");
|
|
164
|
+
if (rolldownWatcher) {
|
|
165
|
+
await rolldownWatcher.close();
|
|
166
166
|
}
|
|
167
|
-
|
|
167
|
+
rolldownWatcher = startRolldownWatcher(apibara, rolldownConfig);
|
|
168
168
|
}
|
|
169
|
-
const reload = debounce(load);
|
|
170
|
-
const watchPatterns =
|
|
169
|
+
const reload = debounce(async () => await load());
|
|
170
|
+
const watchPatterns = getWatchPatterns(apibara);
|
|
171
171
|
const watchReloadEvents = /* @__PURE__ */ new Set(["add", "addDir", "unlink", "unlinkDir"]);
|
|
172
172
|
const reloadWatcher = watch(watchPatterns, { ignoreInitial: true }).on(
|
|
173
173
|
"all",
|
|
174
|
-
(event) => {
|
|
174
|
+
async (event) => {
|
|
175
175
|
if (watchReloadEvents.has(event)) {
|
|
176
|
-
reload();
|
|
176
|
+
await reload();
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
);
|
|
180
180
|
apibara.hooks.hook("close", () => {
|
|
181
|
-
|
|
181
|
+
rolldownWatcher.close();
|
|
182
182
|
reloadWatcher.close();
|
|
183
183
|
});
|
|
184
|
-
apibara.hooks.hook("
|
|
184
|
+
apibara.hooks.hook("rolldown:reload", async () => await reload());
|
|
185
185
|
await load();
|
|
186
186
|
}
|
|
187
|
-
function
|
|
188
|
-
const
|
|
189
|
-
|
|
187
|
+
function startRolldownWatcher(apibara, rolldownConfig) {
|
|
188
|
+
const ignorePatterns = getIgnorePatterns();
|
|
189
|
+
const watcher = rolldown.watch(
|
|
190
|
+
defu(rolldownConfig, {
|
|
190
191
|
watch: {
|
|
191
|
-
|
|
192
|
+
exclude: ignorePatterns,
|
|
193
|
+
...apibara.options.watchOptions ?? {}
|
|
192
194
|
}
|
|
193
195
|
})
|
|
194
196
|
);
|
|
195
197
|
let start;
|
|
196
|
-
watcher.on("event", (event) => {
|
|
198
|
+
watcher.on("event", async (event) => {
|
|
197
199
|
switch (event.code) {
|
|
198
200
|
case "START": {
|
|
199
|
-
apibara.hooks.callHook("dev:restart");
|
|
201
|
+
await apibara.hooks.callHook("dev:restart");
|
|
200
202
|
return;
|
|
201
203
|
}
|
|
202
204
|
case "BUNDLE_START": {
|
|
@@ -209,34 +211,48 @@ function startRollupWatcher(apibara, rollupConfig) {
|
|
|
209
211
|
"Indexers built",
|
|
210
212
|
start ? `in ${Date.now() - start} ms` : ""
|
|
211
213
|
);
|
|
212
|
-
apibara.hooks.callHook("dev:reload");
|
|
214
|
+
await apibara.hooks.callHook("dev:reload");
|
|
213
215
|
return;
|
|
214
216
|
}
|
|
215
217
|
case "ERROR": {
|
|
216
|
-
apibara.logger.error(
|
|
218
|
+
apibara.logger.error(formatRolldownError(event.error));
|
|
217
219
|
}
|
|
218
220
|
}
|
|
219
221
|
});
|
|
220
222
|
return watcher;
|
|
221
223
|
}
|
|
224
|
+
const getWatchPatterns = (apibara) => [
|
|
225
|
+
join(apibara.options.rootDir, "indexers")
|
|
226
|
+
];
|
|
227
|
+
const getIgnorePatterns = (apibara) => [
|
|
228
|
+
"**/.apibara/**",
|
|
229
|
+
"**/.git/**",
|
|
230
|
+
"**/.DS_Store",
|
|
231
|
+
"**/node_modules/**",
|
|
232
|
+
"**/dist/**",
|
|
233
|
+
"**/.turbo/**"
|
|
234
|
+
];
|
|
222
235
|
|
|
223
|
-
async function buildProduction(apibara,
|
|
236
|
+
async function buildProduction(apibara, rolldownConfig) {
|
|
224
237
|
apibara.logger.start(
|
|
225
238
|
`Building ${colors.cyan(apibara.indexers.length)} indexers`
|
|
226
239
|
);
|
|
240
|
+
const startTime = Date.now();
|
|
227
241
|
try {
|
|
228
|
-
const bundle = await
|
|
229
|
-
if (Array.isArray(
|
|
230
|
-
for (const outputOptions of
|
|
242
|
+
const bundle = await rolldown.rolldown(rolldownConfig);
|
|
243
|
+
if (Array.isArray(rolldownConfig.output)) {
|
|
244
|
+
for (const outputOptions of rolldownConfig.output) {
|
|
231
245
|
await bundle.write(outputOptions);
|
|
232
246
|
}
|
|
233
|
-
} else if (
|
|
234
|
-
await bundle.write(
|
|
247
|
+
} else if (rolldownConfig.output) {
|
|
248
|
+
await bundle.write(rolldownConfig.output);
|
|
235
249
|
} else {
|
|
236
|
-
throw new Error("No output options specified in
|
|
250
|
+
throw new Error("No output options specified in Rolldown config");
|
|
237
251
|
}
|
|
238
252
|
await bundle.close();
|
|
239
|
-
|
|
253
|
+
const endTime = Date.now();
|
|
254
|
+
const duration = endTime - startTime;
|
|
255
|
+
apibara.logger.success(`Build succeeded in ${duration}ms`);
|
|
240
256
|
apibara.logger.info(
|
|
241
257
|
`You can start the indexers with ${colors.cyan("apibara start")}`
|
|
242
258
|
);
|
|
@@ -247,9 +263,16 @@ async function buildProduction(apibara, rollupConfig) {
|
|
|
247
263
|
}
|
|
248
264
|
|
|
249
265
|
async function build(apibara) {
|
|
250
|
-
const
|
|
251
|
-
await apibara.hooks.callHook("
|
|
252
|
-
|
|
266
|
+
const rolldownConfig = getRolldownConfig(apibara);
|
|
267
|
+
await apibara.hooks.callHook("rolldown:before", apibara, rolldownConfig);
|
|
268
|
+
if (apibara.options.rollupConfig) {
|
|
269
|
+
apibara.logger.error(
|
|
270
|
+
`
|
|
271
|
+
${colors.cyan("apibara.config:")} rollupConfig is deprecated. Use rolldownConfig instead`
|
|
272
|
+
);
|
|
273
|
+
process.exit(1);
|
|
274
|
+
}
|
|
275
|
+
return apibara.options.dev ? await watchDev(apibara, rolldownConfig) : await buildProduction(apibara, rolldownConfig);
|
|
253
276
|
}
|
|
254
277
|
|
|
255
278
|
function prettyPath(path, highlight = true) {
|
|
@@ -270,6 +293,10 @@ async function prepareDir(dir) {
|
|
|
270
293
|
}
|
|
271
294
|
|
|
272
295
|
async function writeTypes(apibara) {
|
|
296
|
+
const isTypeScript = apibara.options._c12.configFile?.endsWith(".ts");
|
|
297
|
+
if (!isTypeScript) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
273
300
|
const typesDir = resolve(apibara.options.buildDir, "types");
|
|
274
301
|
const config = [
|
|
275
302
|
"// Generated by apibara",
|
package/dist/create/index.d.mts
CHANGED
|
@@ -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;
|
package/dist/create/index.d.ts
CHANGED
|
@@ -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;
|
package/dist/create/index.mjs
CHANGED
|
@@ -76,7 +76,6 @@ const packageVersions = {
|
|
|
76
76
|
"drizzle-kit": "^0.29.0",
|
|
77
77
|
// Typescript Dependencies
|
|
78
78
|
typescript: "^5.6.2",
|
|
79
|
-
"@rollup/plugin-typescript": "^11.1.6",
|
|
80
79
|
"@types/node": "^20.5.2"
|
|
81
80
|
};
|
|
82
81
|
const dnaUrls = {
|
|
@@ -386,7 +385,7 @@ function generatePackageJson(isTypeScript) {
|
|
|
386
385
|
private: true,
|
|
387
386
|
type: "module",
|
|
388
387
|
scripts: {
|
|
389
|
-
prepare: "apibara prepare",
|
|
388
|
+
...isTypeScript && { prepare: "apibara prepare" },
|
|
390
389
|
dev: "apibara dev",
|
|
391
390
|
start: "apibara start",
|
|
392
391
|
build: "apibara build",
|
|
@@ -399,7 +398,6 @@ function generatePackageJson(isTypeScript) {
|
|
|
399
398
|
},
|
|
400
399
|
devDependencies: {
|
|
401
400
|
...isTypeScript && {
|
|
402
|
-
"@rollup/plugin-typescript": packageVersions["@rollup/plugin-typescript"],
|
|
403
401
|
"@types/node": packageVersions["@types/node"],
|
|
404
402
|
typescript: packageVersions.typescript
|
|
405
403
|
}
|
|
@@ -427,13 +425,10 @@ function generateTsConfig() {
|
|
|
427
425
|
};
|
|
428
426
|
}
|
|
429
427
|
function generateApibaraConfig(isTypeScript) {
|
|
430
|
-
return
|
|
428
|
+
return `import { defineConfig } from "apibara/config";
|
|
431
429
|
|
|
432
430
|
export default defineConfig({
|
|
433
|
-
runtimeConfig: {}
|
|
434
|
-
rollupConfig: {
|
|
435
|
-
plugins: [typescript()${isTypeScript ? " as Plugin" : ""}],
|
|
436
|
-
},` : ""}
|
|
431
|
+
runtimeConfig: {},
|
|
437
432
|
});
|
|
438
433
|
`;
|
|
439
434
|
}
|
|
@@ -842,7 +837,7 @@ async function initializeProject({
|
|
|
842
837
|
consola$1.success("Created", cyan("tsconfig.json"));
|
|
843
838
|
}
|
|
844
839
|
const apibaraConfigPath = path.join(root, `apibara.config.${configExt}`);
|
|
845
|
-
const apibaraConfig = generateApibaraConfig(
|
|
840
|
+
const apibaraConfig = generateApibaraConfig();
|
|
846
841
|
fs.writeFileSync(apibaraConfigPath, apibaraConfig);
|
|
847
842
|
await formatFile(apibaraConfigPath);
|
|
848
843
|
consola$1.success("Created", cyan(`apibara.config.${configExt}`));
|
|
@@ -857,14 +852,12 @@ async function initializeProject({
|
|
|
857
852
|
console.log();
|
|
858
853
|
if (!argNoCreateIndexer) {
|
|
859
854
|
consola$1.info("Let's create an indexer\n");
|
|
860
|
-
await addIndexer({});
|
|
855
|
+
await addIndexer({ argRootDir: argTargetDir });
|
|
861
856
|
} else {
|
|
862
857
|
const pkgManager = getPackageManager();
|
|
863
858
|
consola$1.info(
|
|
864
859
|
"Run ",
|
|
865
|
-
green(
|
|
866
|
-
`${pkgManager.name}${pkgManager.name === "npm" ? " run" : ""} install`
|
|
867
|
-
),
|
|
860
|
+
green(`${pkgManager.name} install`),
|
|
868
861
|
" to install all dependencies"
|
|
869
862
|
);
|
|
870
863
|
}
|
|
@@ -875,9 +868,11 @@ async function addIndexer({
|
|
|
875
868
|
argChain,
|
|
876
869
|
argNetwork,
|
|
877
870
|
argStorage,
|
|
878
|
-
argDnaUrl
|
|
871
|
+
argDnaUrl,
|
|
872
|
+
argRootDir
|
|
879
873
|
}) {
|
|
880
|
-
const
|
|
874
|
+
const cwd = path.join(process.cwd(), argRootDir ?? ".");
|
|
875
|
+
const configExists = hasApibaraConfig(cwd);
|
|
881
876
|
if (!configExists) {
|
|
882
877
|
consola$1.error("No apibara.config found in the current directory.");
|
|
883
878
|
const prompt_initialize = await prompts({
|
|
@@ -901,7 +896,7 @@ async function addIndexer({
|
|
|
901
896
|
);
|
|
902
897
|
}
|
|
903
898
|
}
|
|
904
|
-
const language = getApibaraConfigLanguage(
|
|
899
|
+
const language = getApibaraConfigLanguage(cwd);
|
|
905
900
|
validateIndexerId(argIndexerId, true);
|
|
906
901
|
validateChain(argChain, true);
|
|
907
902
|
validateNetwork(argChain, argNetwork, true);
|
|
@@ -916,7 +911,7 @@ async function addIndexer({
|
|
|
916
911
|
initial: argIndexerId ?? "my-indexer",
|
|
917
912
|
validate: (id) => validateIndexerId(id) ? checkFileExists(
|
|
918
913
|
path.join(
|
|
919
|
-
|
|
914
|
+
cwd,
|
|
920
915
|
"indexers",
|
|
921
916
|
`${id}.indexer.${language === "typescript" ? "ts" : "js"}`
|
|
922
917
|
)
|
|
@@ -998,7 +993,7 @@ async function addIndexer({
|
|
|
998
993
|
const indexerFileId = argIndexerId ?? prompt_indexerId;
|
|
999
994
|
const pkgManager = getPackageManager();
|
|
1000
995
|
const options = {
|
|
1001
|
-
cwd
|
|
996
|
+
cwd,
|
|
1002
997
|
indexerFileId,
|
|
1003
998
|
indexerId: convertKebabToCamelCase(indexerFileId),
|
|
1004
999
|
chain: argChain ?? prompt_chain?.name,
|
|
@@ -1020,10 +1015,10 @@ async function addIndexer({
|
|
|
1020
1015
|
);
|
|
1021
1016
|
await createStorageRelatedFiles(options);
|
|
1022
1017
|
console.log();
|
|
1018
|
+
const baseCommand = `${options.packageManager} install`;
|
|
1019
|
+
const tsCommand = `${baseCommand} && ${options.packageManager} run prepare`;
|
|
1023
1020
|
consola$1.info(
|
|
1024
|
-
`Before running the indexer, run ${cyan(
|
|
1025
|
-
`${options.packageManager}${options.packageManager === "npm" ? " run" : ""} prepare`
|
|
1026
|
-
) : ""}`
|
|
1021
|
+
`Before running the indexer, run ${cyan(language === "typescript" ? tsCommand : baseCommand)}`
|
|
1027
1022
|
);
|
|
1028
1023
|
}
|
|
1029
1024
|
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { builtinModules } from 'node:module';
|
|
3
|
+
import defu from 'defu';
|
|
4
|
+
import { join } from 'pathe';
|
|
5
|
+
import virtual from '@rollup/plugin-virtual';
|
|
6
|
+
import { hash } from 'ohash';
|
|
7
|
+
|
|
8
|
+
function appConfig(apibara) {
|
|
9
|
+
return virtual({
|
|
10
|
+
"#apibara-internal-virtual/config": `
|
|
11
|
+
import * as projectConfig from '${apibara.options._c12.configFile}';
|
|
12
|
+
|
|
13
|
+
export const config = projectConfig.default;
|
|
14
|
+
`
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function indexers(apibara) {
|
|
19
|
+
const indexers2 = [...new Set(apibara.indexers)];
|
|
20
|
+
return virtual({
|
|
21
|
+
"#apibara-internal-virtual/indexers": `
|
|
22
|
+
${indexers2.map((i) => `import * as _${hash(i)} from '${i.indexer}';`).join("\n")}
|
|
23
|
+
|
|
24
|
+
export const indexers = [
|
|
25
|
+
${indexers2.map((i) => `{ name: "${i.name}", indexer: _${hash(i)} }`).join(",\n")}
|
|
26
|
+
];
|
|
27
|
+
`
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const runtimeDependencies = [
|
|
32
|
+
"better-sqlite3",
|
|
33
|
+
"@electric-sql/pglite",
|
|
34
|
+
"pg",
|
|
35
|
+
// https://socket.io/docs/v4/server-installation/#additional-packages
|
|
36
|
+
"utf-8-validate",
|
|
37
|
+
"bufferutil",
|
|
38
|
+
"node-fetch"
|
|
39
|
+
];
|
|
40
|
+
function getRolldownConfig(apibara) {
|
|
41
|
+
const extensions = [
|
|
42
|
+
".ts",
|
|
43
|
+
".mjs",
|
|
44
|
+
".js",
|
|
45
|
+
".json",
|
|
46
|
+
".node",
|
|
47
|
+
".tsx",
|
|
48
|
+
".jsx"
|
|
49
|
+
];
|
|
50
|
+
const tsConfigExists = existsSync(
|
|
51
|
+
join(apibara.options.rootDir, "tsconfig.json")
|
|
52
|
+
);
|
|
53
|
+
const rolldownConfig = defu(
|
|
54
|
+
// biome-ignore lint/suspicious/noExplicitAny: apibara.options.rolldownConfig is typed
|
|
55
|
+
apibara.options.rolldownConfig,
|
|
56
|
+
{
|
|
57
|
+
platform: "node",
|
|
58
|
+
input: apibara.options.entry,
|
|
59
|
+
output: {
|
|
60
|
+
dir: join(apibara.options.outputDir || "./.apibara/build"),
|
|
61
|
+
format: "esm",
|
|
62
|
+
entryFileNames: "[name].mjs",
|
|
63
|
+
chunkFileNames: "chunks/[name]-[hash].mjs",
|
|
64
|
+
sourcemap: true
|
|
65
|
+
},
|
|
66
|
+
plugins: [],
|
|
67
|
+
onwarn(warning, rolldownWarn) {
|
|
68
|
+
if (!["CIRCULAR_DEPENDENCY", "EVAL", "THIS_IS_UNDEFINED"].includes(
|
|
69
|
+
warning.code || ""
|
|
70
|
+
) && !warning.message.includes("Unsupported source map comment") && !warning.message.includes("@__PURE__") && !warning.message.includes("/*#__PURE__*/")) {
|
|
71
|
+
rolldownWarn(warning);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
resolve: {
|
|
75
|
+
extensions,
|
|
76
|
+
preferBuiltins: !!apibara.options.node,
|
|
77
|
+
mainFields: ["main"],
|
|
78
|
+
exportConditions: apibara.options.exportConditions,
|
|
79
|
+
tsconfigFilename: tsConfigExists ? "tsconfig.json" : void 0
|
|
80
|
+
},
|
|
81
|
+
treeshake: true,
|
|
82
|
+
external: [...builtinModules, ...runtimeDependencies]
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
rolldownConfig.plugins?.push(indexers(apibara));
|
|
86
|
+
rolldownConfig.plugins?.push(appConfig(apibara));
|
|
87
|
+
return rolldownConfig;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { getRolldownConfig };
|
package/dist/types/index.d.mts
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
import { ConsolaInstance } from 'consola';
|
|
2
2
|
import { NestedHooks, Hookable } from 'hookable';
|
|
3
3
|
import { ConsolaReporter } from '@apibara/indexer/plugins';
|
|
4
|
-
import { RollupCommonJSOptions } from '@rollup/plugin-commonjs';
|
|
5
4
|
import { C12InputConfig, WatchConfigOptions, ResolvedConfig, ConfigWatcher } from 'c12';
|
|
6
|
-
import { WatchOptions } from '
|
|
7
|
-
import { InputOptions, OutputOptions } from 'rollup';
|
|
5
|
+
import { RolldownOptions, WatchOptions, InputOptions, OutputOptions } from 'rolldown';
|
|
8
6
|
|
|
9
7
|
type DeepPartial<T> = T extends Record<string, any> ? {
|
|
10
8
|
[P in keyof T]?: DeepPartial<T[P]> | T[P];
|
|
11
9
|
} : T;
|
|
12
10
|
|
|
13
|
-
type RollupConfig = InputOptions & {
|
|
14
|
-
output: OutputOptions;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
11
|
interface ApibaraHooks {
|
|
18
|
-
"
|
|
12
|
+
"rolldown:before": (apibara: Apibara, rolldownConfig: RolldownOptions) => void;
|
|
19
13
|
compiled: (apibara: Apibara) => void;
|
|
20
|
-
"dev:restart": () => void
|
|
21
|
-
"dev:reload": () => void
|
|
22
|
-
"
|
|
14
|
+
"dev:restart": () => Promise<void>;
|
|
15
|
+
"dev:reload": () => Promise<void>;
|
|
16
|
+
"rolldown:reload": () => Promise<void>;
|
|
23
17
|
restart: () => void;
|
|
24
18
|
close: () => void;
|
|
25
19
|
}
|
|
@@ -58,13 +52,16 @@ interface ApibaraOptions<T extends Record<string, DeepPartial<Pick<ApibaraConfig
|
|
|
58
52
|
outputDir: string;
|
|
59
53
|
indexersDir: string;
|
|
60
54
|
dev: boolean;
|
|
61
|
-
watchOptions: WatchOptions;
|
|
55
|
+
watchOptions: WatchOptions["watch"];
|
|
62
56
|
hooks: NestedHooks<ApibaraHooks>;
|
|
63
57
|
logger?: LoggerFactory;
|
|
64
|
-
|
|
58
|
+
rolldownConfig?: Partial<RolldownOptions>;
|
|
59
|
+
/**
|
|
60
|
+
* @deprecated Use rolldownConfig instead. This option will be removed in future releases.
|
|
61
|
+
*/
|
|
62
|
+
rollupConfig?: unknown;
|
|
65
63
|
sourceMap?: boolean;
|
|
66
64
|
entry: string;
|
|
67
|
-
commonJS?: RollupCommonJSOptions;
|
|
68
65
|
node: boolean;
|
|
69
66
|
exportConditions?: string[];
|
|
70
67
|
typescript: {
|
|
@@ -87,6 +84,10 @@ interface Apibara {
|
|
|
87
84
|
updateConfig: (config: ApibaraDynamicConfig) => void | Promise<void>;
|
|
88
85
|
}
|
|
89
86
|
|
|
87
|
+
type RolldownConfig = InputOptions & {
|
|
88
|
+
output: OutputOptions;
|
|
89
|
+
};
|
|
90
|
+
|
|
90
91
|
type ApibaraRuntimeConfig = Record<string, unknown>;
|
|
91
92
|
|
|
92
|
-
export type { Apibara, ApibaraConfig, ApibaraDynamicConfig, ApibaraHooks, ApibaraOptions, ApibaraRuntimeConfig, DeepPartial, IndexerDefinition, LoadConfigOptions, LoggerFactory,
|
|
93
|
+
export type { Apibara, ApibaraConfig, ApibaraDynamicConfig, ApibaraHooks, ApibaraOptions, ApibaraRuntimeConfig, DeepPartial, IndexerDefinition, LoadConfigOptions, LoggerFactory, RolldownConfig };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
import { ConsolaInstance } from 'consola';
|
|
2
2
|
import { NestedHooks, Hookable } from 'hookable';
|
|
3
3
|
import { ConsolaReporter } from '@apibara/indexer/plugins';
|
|
4
|
-
import { RollupCommonJSOptions } from '@rollup/plugin-commonjs';
|
|
5
4
|
import { C12InputConfig, WatchConfigOptions, ResolvedConfig, ConfigWatcher } from 'c12';
|
|
6
|
-
import { WatchOptions } from '
|
|
7
|
-
import { InputOptions, OutputOptions } from 'rollup';
|
|
5
|
+
import { RolldownOptions, WatchOptions, InputOptions, OutputOptions } from 'rolldown';
|
|
8
6
|
|
|
9
7
|
type DeepPartial<T> = T extends Record<string, any> ? {
|
|
10
8
|
[P in keyof T]?: DeepPartial<T[P]> | T[P];
|
|
11
9
|
} : T;
|
|
12
10
|
|
|
13
|
-
type RollupConfig = InputOptions & {
|
|
14
|
-
output: OutputOptions;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
11
|
interface ApibaraHooks {
|
|
18
|
-
"
|
|
12
|
+
"rolldown:before": (apibara: Apibara, rolldownConfig: RolldownOptions) => void;
|
|
19
13
|
compiled: (apibara: Apibara) => void;
|
|
20
|
-
"dev:restart": () => void
|
|
21
|
-
"dev:reload": () => void
|
|
22
|
-
"
|
|
14
|
+
"dev:restart": () => Promise<void>;
|
|
15
|
+
"dev:reload": () => Promise<void>;
|
|
16
|
+
"rolldown:reload": () => Promise<void>;
|
|
23
17
|
restart: () => void;
|
|
24
18
|
close: () => void;
|
|
25
19
|
}
|
|
@@ -58,13 +52,16 @@ interface ApibaraOptions<T extends Record<string, DeepPartial<Pick<ApibaraConfig
|
|
|
58
52
|
outputDir: string;
|
|
59
53
|
indexersDir: string;
|
|
60
54
|
dev: boolean;
|
|
61
|
-
watchOptions: WatchOptions;
|
|
55
|
+
watchOptions: WatchOptions["watch"];
|
|
62
56
|
hooks: NestedHooks<ApibaraHooks>;
|
|
63
57
|
logger?: LoggerFactory;
|
|
64
|
-
|
|
58
|
+
rolldownConfig?: Partial<RolldownOptions>;
|
|
59
|
+
/**
|
|
60
|
+
* @deprecated Use rolldownConfig instead. This option will be removed in future releases.
|
|
61
|
+
*/
|
|
62
|
+
rollupConfig?: unknown;
|
|
65
63
|
sourceMap?: boolean;
|
|
66
64
|
entry: string;
|
|
67
|
-
commonJS?: RollupCommonJSOptions;
|
|
68
65
|
node: boolean;
|
|
69
66
|
exportConditions?: string[];
|
|
70
67
|
typescript: {
|
|
@@ -87,6 +84,10 @@ interface Apibara {
|
|
|
87
84
|
updateConfig: (config: ApibaraDynamicConfig) => void | Promise<void>;
|
|
88
85
|
}
|
|
89
86
|
|
|
87
|
+
type RolldownConfig = InputOptions & {
|
|
88
|
+
output: OutputOptions;
|
|
89
|
+
};
|
|
90
|
+
|
|
90
91
|
type ApibaraRuntimeConfig = Record<string, unknown>;
|
|
91
92
|
|
|
92
|
-
export type { Apibara, ApibaraConfig, ApibaraDynamicConfig, ApibaraHooks, ApibaraOptions, ApibaraRuntimeConfig, DeepPartial, IndexerDefinition, LoadConfigOptions, LoggerFactory,
|
|
93
|
+
export type { Apibara, ApibaraConfig, ApibaraDynamicConfig, ApibaraHooks, ApibaraOptions, ApibaraRuntimeConfig, DeepPartial, IndexerDefinition, LoadConfigOptions, LoggerFactory, RolldownConfig };
|