apibara 2.1.0-beta.8 → 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 +12 -15
- 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 +7 -4
- package/src/create/constants.ts +0 -1
- package/src/create/init.ts +1 -1
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apibara",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/core/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"types": "./dist/core/index.d.ts",
|
|
21
21
|
"import": "./dist/core/index.mjs"
|
|
22
22
|
},
|
|
23
|
-
"./
|
|
24
|
-
"types": "./dist/
|
|
25
|
-
"import": "./dist/
|
|
23
|
+
"./rolldown": {
|
|
24
|
+
"types": "./dist/rolldown/index.d.ts",
|
|
25
|
+
"import": "./dist/rolldown/index.mjs"
|
|
26
26
|
},
|
|
27
27
|
"./types": {
|
|
28
28
|
"types": "./dist/types/index.d.ts",
|
|
@@ -73,10 +73,12 @@
|
|
|
73
73
|
"playground:prepare": "pnpm playground prepare --dir playground",
|
|
74
74
|
"playground:dev": "pnpm playground dev --dir playground",
|
|
75
75
|
"playground:build": "pnpm playground build --dir playground",
|
|
76
|
-
"playground:start": "pnpm playground start --dir playground --indexer starknet"
|
|
76
|
+
"playground:start": "pnpm playground start --dir playground --indexer starknet",
|
|
77
|
+
"playground:init": "pnpm playground init playground",
|
|
78
|
+
"playground:add": "pnpm playground add --dir playground"
|
|
77
79
|
},
|
|
78
80
|
"devDependencies": {
|
|
79
|
-
"@apibara/starknet": "2.1.0-beta.
|
|
81
|
+
"@apibara/starknet": "2.1.0-beta.9",
|
|
80
82
|
"@types/fs-extra": "^11.0.4",
|
|
81
83
|
"@types/node": "^20.14.0",
|
|
82
84
|
"@types/prompts": "^2.4.9",
|
|
@@ -87,12 +89,8 @@
|
|
|
87
89
|
"vitest": "^1.6.0"
|
|
88
90
|
},
|
|
89
91
|
"dependencies": {
|
|
90
|
-
"@apibara/indexer": "2.1.0-beta.
|
|
91
|
-
"@apibara/protocol": "2.1.0-beta.
|
|
92
|
-
"@rollup/plugin-commonjs": "^26.0.1",
|
|
93
|
-
"@rollup/plugin-json": "^6.1.0",
|
|
94
|
-
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
95
|
-
"@rollup/plugin-typescript": "^11.1.6",
|
|
92
|
+
"@apibara/indexer": "2.1.0-beta.9",
|
|
93
|
+
"@apibara/protocol": "2.1.0-beta.9",
|
|
96
94
|
"@rollup/plugin-virtual": "^3.0.2",
|
|
97
95
|
"c12": "^1.11.1",
|
|
98
96
|
"chokidar": "^3.6.0",
|
|
@@ -110,7 +108,7 @@
|
|
|
110
108
|
"pkg-types": "^1.1.3",
|
|
111
109
|
"prettier": "^3.5.2",
|
|
112
110
|
"prompts": "^2.4.2",
|
|
113
|
-
"
|
|
111
|
+
"rolldown": "1.0.0-beta.3",
|
|
114
112
|
"ts-morph": "^25.0.1",
|
|
115
113
|
"tslib": "^2.6.3",
|
|
116
114
|
"untyped": "^1.4.2"
|
package/src/cli/commands/add.ts
CHANGED
|
@@ -29,9 +29,14 @@ export default defineCommand({
|
|
|
29
29
|
type: "string",
|
|
30
30
|
description: "DNA URL - https://custom-dna-url.apibara.org",
|
|
31
31
|
},
|
|
32
|
+
dir: {
|
|
33
|
+
type: "string",
|
|
34
|
+
description:
|
|
35
|
+
"Root directory - apibara project root where apibara.config is located | default: current working directory",
|
|
36
|
+
},
|
|
32
37
|
},
|
|
33
38
|
async run({ args }) {
|
|
34
|
-
const { indexerId, chain, network, storage, dnaUrl } = args;
|
|
39
|
+
const { indexerId, chain, network, storage, dnaUrl, dir } = args;
|
|
35
40
|
|
|
36
41
|
await addIndexer({
|
|
37
42
|
argIndexerId: indexerId,
|
|
@@ -39,6 +44,7 @@ export default defineCommand({
|
|
|
39
44
|
argNetwork: network,
|
|
40
45
|
argStorage: storage,
|
|
41
46
|
argDnaUrl: dnaUrl,
|
|
47
|
+
argRootDir: dir,
|
|
42
48
|
});
|
|
43
49
|
},
|
|
44
50
|
});
|
package/src/cli/commands/dev.ts
CHANGED
|
@@ -79,19 +79,21 @@ export default defineCommand({
|
|
|
79
79
|
await writeTypes(apibara);
|
|
80
80
|
await build(apibara);
|
|
81
81
|
|
|
82
|
-
apibara.hooks.hook("dev:restart", () => {
|
|
82
|
+
apibara.hooks.hook("dev:restart", async () => {
|
|
83
83
|
if (childProcess) {
|
|
84
84
|
apibara.logger.info("Change detected, stopping indexers to restart");
|
|
85
|
-
childProcess
|
|
85
|
+
await killProcess(childProcess);
|
|
86
86
|
childProcess = undefined;
|
|
87
87
|
}
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
apibara.hooks.hook("dev:reload", () => {
|
|
90
|
+
apibara.hooks.hook("dev:reload", async () => {
|
|
91
91
|
if (childProcess) {
|
|
92
|
-
|
|
92
|
+
apibara.logger.info("Restarting indexers");
|
|
93
|
+
await killProcess(childProcess);
|
|
94
|
+
childProcess = undefined;
|
|
93
95
|
} else {
|
|
94
|
-
apibara.logger.
|
|
96
|
+
apibara.logger.info("Starting indexers");
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
const childArgs = [
|
|
@@ -118,3 +120,12 @@ export default defineCommand({
|
|
|
118
120
|
await reload();
|
|
119
121
|
},
|
|
120
122
|
});
|
|
123
|
+
|
|
124
|
+
async function killProcess(childProcess: ChildProcess | undefined) {
|
|
125
|
+
if (childProcess) {
|
|
126
|
+
await new Promise((resolve) => {
|
|
127
|
+
childProcess.once("exit", resolve);
|
|
128
|
+
childProcess.kill();
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
package/src/core/build/build.ts
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
import {
|
|
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
|
|
8
|
+
const rolldownConfig = getRolldownConfig(apibara);
|
|
8
9
|
|
|
9
|
-
await apibara.hooks.callHook("
|
|
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,
|
|
13
|
-
: await buildProduction(apibara,
|
|
20
|
+
? await watchDev(apibara, rolldownConfig)
|
|
21
|
+
: await buildProduction(apibara, rolldownConfig);
|
|
14
22
|
}
|
package/src/core/build/dev.ts
CHANGED
|
@@ -1,59 +1,67 @@
|
|
|
1
|
-
import type { Apibara
|
|
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
|
|
7
|
-
import {
|
|
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
|
-
|
|
14
|
-
|
|
15
|
+
apibara.logger.start("Setting up a dev server");
|
|
16
|
+
if (rolldownWatcher) {
|
|
17
|
+
await rolldownWatcher.close();
|
|
15
18
|
}
|
|
16
|
-
|
|
19
|
+
rolldownWatcher = startRolldownWatcher(apibara, rolldownConfig);
|
|
17
20
|
}
|
|
18
|
-
const reload = debounce(load);
|
|
21
|
+
const reload = debounce(async () => await load());
|
|
19
22
|
|
|
20
|
-
const watchPatterns =
|
|
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
|
-
|
|
36
|
+
rolldownWatcher.close();
|
|
34
37
|
reloadWatcher.close();
|
|
35
38
|
});
|
|
36
39
|
|
|
37
|
-
apibara.hooks.hook("
|
|
40
|
+
apibara.hooks.hook("rolldown:reload", async () => await reload());
|
|
38
41
|
|
|
39
42
|
await load();
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
+
];
|
package/src/core/build/error.ts
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { isAbsolute, relative } from "pathe";
|
|
2
|
-
import type
|
|
2
|
+
import type * as rolldown from "rolldown";
|
|
3
3
|
|
|
4
|
-
export function
|
|
4
|
+
export function formatRolldownError(_error: rolldown.RollupError) {
|
|
5
5
|
try {
|
|
6
6
|
const logs: string[] = [_error.toString()];
|
|
7
7
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
8
|
-
const errors = (_error as any)?.errors || [_error as
|
|
8
|
+
const errors = (_error as any)?.errors || [_error as rolldown.RollupError];
|
|
9
9
|
for (const error of errors) {
|
|
10
|
-
const id = error.path || error.id || (_error as
|
|
10
|
+
const id = error.path || error.id || (_error as rolldown.RollupError).id;
|
|
11
11
|
let path = isAbsolute(id) ? relative(process.cwd(), id) : id;
|
|
12
|
-
const location = (error as
|
|
12
|
+
const location = (error as rolldown.RollupError).loc;
|
|
13
13
|
if (location) {
|
|
14
14
|
path += `:${location.line}:${location.column}`;
|
|
15
15
|
}
|
|
16
|
-
const text = (error as
|
|
16
|
+
const text = (error as rolldown.RollupError).frame;
|
|
17
17
|
|
|
18
18
|
logs.push(
|
|
19
|
-
`
|
|
19
|
+
`Rolldown error while processing \`${path}\`` + text
|
|
20
|
+
? "\n\n" + text
|
|
21
|
+
: "",
|
|
20
22
|
);
|
|
21
23
|
}
|
|
22
24
|
return logs.join("\n");
|
package/src/core/build/prod.ts
CHANGED
|
@@ -1,31 +1,36 @@
|
|
|
1
|
-
import type { Apibara
|
|
1
|
+
import type { Apibara } from "apibara/types";
|
|
2
2
|
import { colors } from "consola/utils";
|
|
3
|
-
import
|
|
3
|
+
import * as rolldown from "rolldown";
|
|
4
4
|
|
|
5
5
|
export async function buildProduction(
|
|
6
6
|
apibara: Apibara,
|
|
7
|
-
|
|
7
|
+
rolldownConfig: rolldown.RolldownOptions,
|
|
8
8
|
) {
|
|
9
9
|
apibara.logger.start(
|
|
10
10
|
`Building ${colors.cyan(apibara.indexers.length)} indexers`,
|
|
11
11
|
);
|
|
12
12
|
|
|
13
|
+
const startTime = Date.now();
|
|
14
|
+
|
|
13
15
|
try {
|
|
14
|
-
const bundle = await
|
|
16
|
+
const bundle = await rolldown.rolldown(rolldownConfig);
|
|
15
17
|
|
|
16
|
-
if (Array.isArray(
|
|
17
|
-
for (const outputOptions of
|
|
18
|
+
if (Array.isArray(rolldownConfig.output)) {
|
|
19
|
+
for (const outputOptions of rolldownConfig.output) {
|
|
18
20
|
await bundle.write(outputOptions);
|
|
19
21
|
}
|
|
20
|
-
} else if (
|
|
21
|
-
await bundle.write(
|
|
22
|
+
} else if (rolldownConfig.output) {
|
|
23
|
+
await bundle.write(rolldownConfig.output as rolldown.OutputOptions);
|
|
22
24
|
} else {
|
|
23
|
-
throw new Error("No output options specified in
|
|
25
|
+
throw new Error("No output options specified in Rolldown config");
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
await bundle.close();
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
const endTime = Date.now();
|
|
31
|
+
const duration = endTime - startTime;
|
|
32
|
+
|
|
33
|
+
apibara.logger.success(`Build succeeded in ${duration}ms`);
|
|
29
34
|
apibara.logger.info(
|
|
30
35
|
`You can start the indexers with ${colors.cyan("apibara start")}`,
|
|
31
36
|
);
|
package/src/core/build/types.ts
CHANGED
|
@@ -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 = [
|
package/src/create/add.ts
CHANGED
|
@@ -37,6 +37,7 @@ type Options = {
|
|
|
37
37
|
argNetwork?: string;
|
|
38
38
|
argStorage?: string;
|
|
39
39
|
argDnaUrl?: string;
|
|
40
|
+
argRootDir?: string;
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
export async function addIndexer({
|
|
@@ -45,8 +46,10 @@ export async function addIndexer({
|
|
|
45
46
|
argNetwork,
|
|
46
47
|
argStorage,
|
|
47
48
|
argDnaUrl,
|
|
49
|
+
argRootDir,
|
|
48
50
|
}: Options) {
|
|
49
|
-
const
|
|
51
|
+
const cwd = path.join(process.cwd(), argRootDir ?? ".");
|
|
52
|
+
const configExists = hasApibaraConfig(cwd);
|
|
50
53
|
|
|
51
54
|
if (!configExists) {
|
|
52
55
|
consola.error("No apibara.config found in the current directory.");
|
|
@@ -74,7 +77,7 @@ export async function addIndexer({
|
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
|
|
77
|
-
const language = getApibaraConfigLanguage(
|
|
80
|
+
const language = getApibaraConfigLanguage(cwd);
|
|
78
81
|
|
|
79
82
|
validateIndexerId(argIndexerId, true);
|
|
80
83
|
validateChain(argChain, true);
|
|
@@ -93,7 +96,7 @@ export async function addIndexer({
|
|
|
93
96
|
validateIndexerId(id)
|
|
94
97
|
? checkFileExists(
|
|
95
98
|
path.join(
|
|
96
|
-
|
|
99
|
+
cwd,
|
|
97
100
|
"indexers",
|
|
98
101
|
`${id}.indexer.${language === "typescript" ? "ts" : "js"}`,
|
|
99
102
|
),
|
|
@@ -197,7 +200,7 @@ export async function addIndexer({
|
|
|
197
200
|
const pkgManager = getPackageManager();
|
|
198
201
|
|
|
199
202
|
const options: IndexerOptions = {
|
|
200
|
-
cwd:
|
|
203
|
+
cwd: cwd,
|
|
201
204
|
indexerFileId,
|
|
202
205
|
indexerId: convertKebabToCamelCase(indexerFileId),
|
|
203
206
|
chain: (argChain as Chain) ?? prompt_chain?.name!,
|
package/src/create/constants.ts
CHANGED
package/src/create/init.ts
CHANGED
|
@@ -166,7 +166,7 @@ export async function initializeProject({
|
|
|
166
166
|
if (!argNoCreateIndexer) {
|
|
167
167
|
consola.info("Let's create an indexer\n");
|
|
168
168
|
|
|
169
|
-
await addIndexer({});
|
|
169
|
+
await addIndexer({ argRootDir: argTargetDir });
|
|
170
170
|
} else {
|
|
171
171
|
const pkgManager = getPackageManager();
|
|
172
172
|
consola.info(
|
package/src/create/templates.ts
CHANGED
|
@@ -15,7 +15,7 @@ export function generatePackageJson(isTypeScript: boolean) {
|
|
|
15
15
|
private: true,
|
|
16
16
|
type: "module",
|
|
17
17
|
scripts: {
|
|
18
|
-
prepare: "apibara prepare",
|
|
18
|
+
...(isTypeScript && { prepare: "apibara prepare" }),
|
|
19
19
|
dev: "apibara dev",
|
|
20
20
|
start: "apibara start",
|
|
21
21
|
build: "apibara build",
|
|
@@ -28,8 +28,6 @@ export function generatePackageJson(isTypeScript: boolean) {
|
|
|
28
28
|
},
|
|
29
29
|
devDependencies: {
|
|
30
30
|
...(isTypeScript && {
|
|
31
|
-
"@rollup/plugin-typescript":
|
|
32
|
-
packageVersions["@rollup/plugin-typescript"],
|
|
33
31
|
"@types/node": packageVersions["@types/node"],
|
|
34
32
|
typescript: packageVersions.typescript,
|
|
35
33
|
}),
|
|
@@ -59,17 +57,10 @@ export function generateTsConfig() {
|
|
|
59
57
|
}
|
|
60
58
|
|
|
61
59
|
export function generateApibaraConfig(isTypeScript: boolean) {
|
|
62
|
-
return
|
|
60
|
+
return `import { defineConfig } from "apibara/config";
|
|
63
61
|
|
|
64
62
|
export default defineConfig({
|
|
65
|
-
runtimeConfig: {}
|
|
66
|
-
isTypeScript
|
|
67
|
-
? `
|
|
68
|
-
rollupConfig: {
|
|
69
|
-
plugins: [typescript()${isTypeScript ? " as Plugin" : ""}],
|
|
70
|
-
},`
|
|
71
|
-
: ""
|
|
72
|
-
}
|
|
63
|
+
runtimeConfig: {},
|
|
73
64
|
});\n`;
|
|
74
65
|
}
|
|
75
66
|
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { builtinModules } from "node:module";
|
|
3
|
+
import type { Apibara } from "apibara/types";
|
|
4
|
+
import defu from "defu";
|
|
5
|
+
import { join } from "pathe";
|
|
6
|
+
import type {
|
|
7
|
+
ConfigExport,
|
|
8
|
+
RolldownOptions,
|
|
9
|
+
RolldownPluginOption,
|
|
10
|
+
} from "rolldown";
|
|
11
|
+
import { appConfig } from "./plugins/config";
|
|
12
|
+
import { indexers } from "./plugins/indexers";
|
|
13
|
+
|
|
14
|
+
const runtimeDependencies = [
|
|
15
|
+
"better-sqlite3",
|
|
16
|
+
"@electric-sql/pglite",
|
|
17
|
+
"pg",
|
|
18
|
+
// https://socket.io/docs/v4/server-installation/#additional-packages
|
|
19
|
+
"utf-8-validate",
|
|
20
|
+
"bufferutil",
|
|
21
|
+
"node-fetch",
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
export function getRolldownConfig(apibara: Apibara): RolldownOptions {
|
|
25
|
+
const extensions: string[] = [
|
|
26
|
+
".ts",
|
|
27
|
+
".mjs",
|
|
28
|
+
".js",
|
|
29
|
+
".json",
|
|
30
|
+
".node",
|
|
31
|
+
".tsx",
|
|
32
|
+
".jsx",
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
const tsConfigExists = existsSync(
|
|
36
|
+
join(apibara.options.rootDir, "tsconfig.json"),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const rolldownConfig: RolldownOptions & {
|
|
40
|
+
plugins: RolldownPluginOption[];
|
|
41
|
+
} = defu(
|
|
42
|
+
// biome-ignore lint/suspicious/noExplicitAny: apibara.options.rolldownConfig is typed
|
|
43
|
+
apibara.options.rolldownConfig as any,
|
|
44
|
+
<ConfigExport>{
|
|
45
|
+
platform: "node",
|
|
46
|
+
input: apibara.options.entry,
|
|
47
|
+
output: {
|
|
48
|
+
dir: join(apibara.options.outputDir || "./.apibara/build"),
|
|
49
|
+
format: "esm",
|
|
50
|
+
entryFileNames: "[name].mjs",
|
|
51
|
+
chunkFileNames: "chunks/[name]-[hash].mjs",
|
|
52
|
+
sourcemap: true,
|
|
53
|
+
},
|
|
54
|
+
plugins: [],
|
|
55
|
+
onwarn(warning, rolldownWarn) {
|
|
56
|
+
if (
|
|
57
|
+
!["CIRCULAR_DEPENDENCY", "EVAL", "THIS_IS_UNDEFINED"].includes(
|
|
58
|
+
warning.code || "",
|
|
59
|
+
) &&
|
|
60
|
+
!warning.message.includes("Unsupported source map comment") &&
|
|
61
|
+
!warning.message.includes("@__PURE__") &&
|
|
62
|
+
!warning.message.includes("/*#__PURE__*/")
|
|
63
|
+
) {
|
|
64
|
+
rolldownWarn(warning);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
resolve: {
|
|
68
|
+
extensions,
|
|
69
|
+
preferBuiltins: !!apibara.options.node,
|
|
70
|
+
mainFields: ["main"],
|
|
71
|
+
exportConditions: apibara.options.exportConditions,
|
|
72
|
+
tsconfigFilename: tsConfigExists ? "tsconfig.json" : undefined,
|
|
73
|
+
},
|
|
74
|
+
treeshake: true,
|
|
75
|
+
external: [...builtinModules, ...runtimeDependencies],
|
|
76
|
+
},
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
rolldownConfig.plugins?.push(indexers(apibara));
|
|
80
|
+
rolldownConfig.plugins?.push(appConfig(apibara));
|
|
81
|
+
|
|
82
|
+
return rolldownConfig;
|
|
83
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import virtual from "@rollup/plugin-virtual";
|
|
2
2
|
import type { Apibara } from "apibara/types";
|
|
3
|
+
import type { RolldownPluginOption } from "rolldown";
|
|
3
4
|
|
|
4
5
|
export function appConfig(apibara: Apibara) {
|
|
5
6
|
return virtual({
|
|
@@ -8,5 +9,5 @@ export function appConfig(apibara: Apibara) {
|
|
|
8
9
|
|
|
9
10
|
export const config = projectConfig.default;
|
|
10
11
|
`,
|
|
11
|
-
});
|
|
12
|
+
}) as RolldownPluginOption;
|
|
12
13
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import virtual from "@rollup/plugin-virtual";
|
|
2
2
|
import type { Apibara } from "apibara/types";
|
|
3
3
|
import { hash } from "ohash";
|
|
4
|
+
import type { RolldownPluginOption } from "rolldown";
|
|
4
5
|
|
|
5
6
|
export function indexers(apibara: Apibara) {
|
|
6
7
|
const indexers = [...new Set(apibara.indexers)];
|
|
7
|
-
|
|
8
8
|
return virtual({
|
|
9
9
|
"#apibara-internal-virtual/indexers": `
|
|
10
10
|
${indexers.map((i) => `import * as _${hash(i)} from '${i.indexer}';`).join("\n")}
|
|
@@ -13,5 +13,5 @@ export function indexers(apibara: Apibara) {
|
|
|
13
13
|
${indexers.map((i) => `{ name: "${i.name}", indexer: _${hash(i)} }`).join(",\n")}
|
|
14
14
|
];
|
|
15
15
|
`,
|
|
16
|
-
});
|
|
16
|
+
}) as RolldownPluginOption;
|
|
17
17
|
}
|
package/src/types/config.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import type { ConsolaReporter } from "@apibara/indexer/plugins";
|
|
2
|
-
import type { RollupCommonJSOptions } from "@rollup/plugin-commonjs";
|
|
3
2
|
import type {
|
|
4
3
|
C12InputConfig,
|
|
5
4
|
ConfigWatcher,
|
|
6
5
|
ResolvedConfig,
|
|
7
6
|
WatchConfigOptions,
|
|
8
7
|
} from "c12";
|
|
9
|
-
import type { WatchOptions } from "chokidar";
|
|
10
8
|
import type { NestedHooks } from "hookable";
|
|
9
|
+
import type { WatchOptions } from "rolldown";
|
|
10
|
+
import type { RolldownOptions } from "rolldown";
|
|
11
11
|
import type { DeepPartial } from "./_utils";
|
|
12
12
|
import type { ApibaraHooks } from "./hooks";
|
|
13
|
-
import type { RollupConfig } from "./rollup";
|
|
14
13
|
|
|
15
14
|
export type LoggerFactory = ({
|
|
16
15
|
indexer,
|
|
@@ -71,7 +70,7 @@ export interface ApibaraOptions<
|
|
|
71
70
|
|
|
72
71
|
// Dev
|
|
73
72
|
dev: boolean;
|
|
74
|
-
watchOptions: WatchOptions;
|
|
73
|
+
watchOptions: WatchOptions["watch"];
|
|
75
74
|
|
|
76
75
|
// Hooks
|
|
77
76
|
hooks: NestedHooks<ApibaraHooks>;
|
|
@@ -79,11 +78,15 @@ export interface ApibaraOptions<
|
|
|
79
78
|
// Logging
|
|
80
79
|
logger?: LoggerFactory;
|
|
81
80
|
|
|
82
|
-
//
|
|
83
|
-
|
|
81
|
+
// Rolldown
|
|
82
|
+
rolldownConfig?: Partial<RolldownOptions>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @deprecated Use rolldownConfig instead. This option will be removed in future releases.
|
|
86
|
+
*/
|
|
87
|
+
rollupConfig?: unknown;
|
|
84
88
|
sourceMap?: boolean;
|
|
85
89
|
entry: string;
|
|
86
|
-
commonJS?: RollupCommonJSOptions;
|
|
87
90
|
node: boolean;
|
|
88
91
|
exportConditions?: string[];
|
|
89
92
|
|
package/src/types/hooks.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import type { RolldownOptions } from "rolldown";
|
|
1
2
|
import type { Apibara } from "./apibara";
|
|
2
|
-
import type { RollupConfig } from "./rollup";
|
|
3
3
|
|
|
4
4
|
export interface ApibaraHooks {
|
|
5
|
-
"
|
|
5
|
+
"rolldown:before": (
|
|
6
|
+
apibara: Apibara,
|
|
7
|
+
rolldownConfig: RolldownOptions,
|
|
8
|
+
) => void;
|
|
6
9
|
compiled: (apibara: Apibara) => void;
|
|
7
|
-
"dev:restart": () => void
|
|
8
|
-
"dev:reload": () => void
|
|
9
|
-
"
|
|
10
|
+
"dev:restart": () => Promise<void>;
|
|
11
|
+
"dev:reload": () => Promise<void>;
|
|
12
|
+
"rolldown:reload": () => Promise<void>;
|
|
10
13
|
restart: () => void;
|
|
11
14
|
close: () => void;
|
|
12
15
|
}
|