apibara 2.1.0-beta.1 → 2.1.0-beta.10
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 +12 -7
- package/dist/chunks/dev.mjs +23 -5
- package/dist/chunks/init.mjs +3 -7
- package/dist/core/index.mjs +69 -40
- package/dist/create/index.d.mts +2 -1
- package/dist/create/index.d.ts +2 -1
- package/dist/create/index.mjs +185 -121
- 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/runtime/dev.mjs +3 -0
- package/dist/runtime/internal/app.d.ts +1 -1
- package/dist/runtime/internal/app.mjs +11 -3
- package/dist/runtime/start.mjs +5 -0
- package/dist/types/index.d.mts +18 -15
- package/dist/types/index.d.ts +18 -15
- package/package.json +12 -15
- package/src/cli/commands/add.ts +12 -6
- package/src/cli/commands/dev.ts +26 -5
- package/src/cli/commands/init.ts +3 -7
- package/src/core/build/build.ts +13 -5
- package/src/core/build/dev.ts +44 -23
- package/src/core/build/error.ts +9 -14
- package/src/core/build/prod.ts +15 -10
- package/src/core/build/types.ts +8 -0
- package/src/core/config/defaults.ts +3 -0
- package/src/core/config/update.ts +1 -1
- package/src/create/add.ts +26 -12
- package/src/create/constants.ts +9 -10
- package/src/create/init.ts +28 -14
- package/src/create/templates.ts +154 -118
- package/src/create/utils.ts +10 -0
- 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 +3 -3
- package/src/runtime/dev.ts +3 -0
- package/src/runtime/internal/app.ts +13 -5
- package/src/runtime/start.ts +5 -0
- package/src/types/config.ts +12 -7
- package/src/types/hooks.ts +8 -5
- package/src/types/index.ts +1 -1
- package/src/types/rolldown.ts +5 -0
- package/src/types/virtual/indexers.d.ts +4 -1
- package/dist/rollup/index.d.mts +0 -6
- package/dist/rollup/index.d.ts +0 -6
- package/dist/rollup/index.mjs +0 -150
- package/src/rollup/config.ts +0 -87
- package/src/rollup/index.ts +0 -2
- package/src/rollup/plugins/esm-shim.ts +0 -69
- package/src/types/rollup.ts +0 -8
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
inMemoryPersistence,
|
|
7
7
|
logger
|
|
8
8
|
} from "@apibara/indexer/plugins";
|
|
9
|
+
import consola from "consola";
|
|
9
10
|
import { config } from "#apibara-internal-virtual/config";
|
|
10
11
|
import { indexers } from "#apibara-internal-virtual/indexers";
|
|
11
12
|
import { createLogger } from "./logger.mjs";
|
|
@@ -30,7 +31,14 @@ export function createIndexer(indexerName, preset) {
|
|
|
30
31
|
`Specified indexer "${indexerName}" but it was not defined`
|
|
31
32
|
);
|
|
32
33
|
}
|
|
33
|
-
const
|
|
34
|
+
const indexerModule = indexerDefinition.indexer?.default;
|
|
35
|
+
if (indexerModule === void 0) {
|
|
36
|
+
consola.warn(
|
|
37
|
+
`Specified indexer "${indexerName}" but it does not export a default. Ignoring.`
|
|
38
|
+
);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const definition = typeof indexerModule === "function" ? indexerModule(runtimeConfig) : indexerModule;
|
|
34
42
|
let reporter = createLogger({
|
|
35
43
|
indexer: indexerName,
|
|
36
44
|
preset,
|
|
@@ -48,9 +56,9 @@ export function createIndexer(indexerName, preset) {
|
|
|
48
56
|
indexerName,
|
|
49
57
|
availableIndexers
|
|
50
58
|
}),
|
|
59
|
+
logger({ logger: reporter }),
|
|
51
60
|
inMemoryPersistence(),
|
|
52
|
-
...definition.plugins ?? []
|
|
53
|
-
logger({ logger: reporter })
|
|
61
|
+
...definition.plugins ?? []
|
|
54
62
|
];
|
|
55
63
|
return _createIndexer(definition);
|
|
56
64
|
}
|
package/dist/runtime/start.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { runWithReconnect } from "@apibara/indexer";
|
|
2
2
|
import { createClient } from "@apibara/protocol";
|
|
3
3
|
import { defineCommand, runMain } from "citty";
|
|
4
|
+
import consola from "consola";
|
|
4
5
|
import { createIndexer } from "./internal/app.mjs";
|
|
5
6
|
const startCommand = defineCommand({
|
|
6
7
|
meta: {
|
|
@@ -21,6 +22,10 @@ const startCommand = defineCommand({
|
|
|
21
22
|
async run({ args }) {
|
|
22
23
|
const { indexer, preset } = args;
|
|
23
24
|
const indexerInstance = createIndexer(indexer, preset);
|
|
25
|
+
if (!indexerInstance) {
|
|
26
|
+
consola.error(`Specified indexer "${indexer}" but it was not defined`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
24
29
|
const client = createClient(
|
|
25
30
|
indexerInstance.streamConfig,
|
|
26
31
|
indexerInstance.options.streamUrl
|
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,18 @@ 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
|
-
|
|
65
|
+
node: boolean;
|
|
66
|
+
exportConditions?: string[];
|
|
68
67
|
typescript: {
|
|
69
68
|
strict?: boolean;
|
|
70
69
|
internalPaths?: boolean;
|
|
@@ -85,6 +84,10 @@ interface Apibara {
|
|
|
85
84
|
updateConfig: (config: ApibaraDynamicConfig) => void | Promise<void>;
|
|
86
85
|
}
|
|
87
86
|
|
|
87
|
+
type RolldownConfig = InputOptions & {
|
|
88
|
+
output: OutputOptions;
|
|
89
|
+
};
|
|
90
|
+
|
|
88
91
|
type ApibaraRuntimeConfig = Record<string, unknown>;
|
|
89
92
|
|
|
90
|
-
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,18 @@ 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
|
-
|
|
65
|
+
node: boolean;
|
|
66
|
+
exportConditions?: string[];
|
|
68
67
|
typescript: {
|
|
69
68
|
strict?: boolean;
|
|
70
69
|
internalPaths?: boolean;
|
|
@@ -85,6 +84,10 @@ interface Apibara {
|
|
|
85
84
|
updateConfig: (config: ApibaraDynamicConfig) => void | Promise<void>;
|
|
86
85
|
}
|
|
87
86
|
|
|
87
|
+
type RolldownConfig = InputOptions & {
|
|
88
|
+
output: OutputOptions;
|
|
89
|
+
};
|
|
90
|
+
|
|
88
91
|
type ApibaraRuntimeConfig = Record<string, unknown>;
|
|
89
92
|
|
|
90
|
-
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/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.10",
|
|
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.10",
|
|
80
82
|
"@types/fs-extra": "^11.0.4",
|
|
81
83
|
"@types/node": "^20.14.0",
|
|
82
84
|
"@types/prompts": "^2.4.9",
|
|
@@ -87,19 +89,14 @@
|
|
|
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.10",
|
|
93
|
+
"@apibara/protocol": "2.1.0-beta.10",
|
|
96
94
|
"@rollup/plugin-virtual": "^3.0.2",
|
|
97
95
|
"c12": "^1.11.1",
|
|
98
96
|
"chokidar": "^3.6.0",
|
|
99
97
|
"citty": "^0.1.6",
|
|
100
98
|
"consola": "^3.2.3",
|
|
101
99
|
"defu": "^6.1.4",
|
|
102
|
-
"esbuild": "^0.23.0",
|
|
103
100
|
"fs-extra": "^11.2.0",
|
|
104
101
|
"hookable": "^5.5.3",
|
|
105
102
|
"klona": "^2.0.6",
|
|
@@ -109,9 +106,9 @@
|
|
|
109
106
|
"perfect-debounce": "^1.0.0",
|
|
110
107
|
"picocolors": "^1.1.1",
|
|
111
108
|
"pkg-types": "^1.1.3",
|
|
109
|
+
"prettier": "^3.5.2",
|
|
112
110
|
"prompts": "^2.4.2",
|
|
113
|
-
"
|
|
114
|
-
"rollup-plugin-esbuild": "^6.1.1",
|
|
111
|
+
"rolldown": "1.0.0-beta.3",
|
|
115
112
|
"ts-morph": "^25.0.1",
|
|
116
113
|
"tslib": "^2.6.3",
|
|
117
114
|
"untyped": "^1.4.2"
|
package/src/cli/commands/add.ts
CHANGED
|
@@ -10,28 +10,33 @@ export default defineCommand({
|
|
|
10
10
|
args: {
|
|
11
11
|
indexerId: {
|
|
12
12
|
type: "positional",
|
|
13
|
-
description: "Indexer ID",
|
|
13
|
+
description: "Indexer ID - must be in kebab-case",
|
|
14
14
|
required: false,
|
|
15
15
|
},
|
|
16
16
|
chain: {
|
|
17
17
|
type: "string",
|
|
18
|
-
description: "
|
|
18
|
+
description: "Blockchain - ethereum, beaconchain, starknet",
|
|
19
19
|
},
|
|
20
20
|
network: {
|
|
21
21
|
type: "string",
|
|
22
|
-
description: "Network",
|
|
22
|
+
description: "Network - mainnet, sepolia, other",
|
|
23
23
|
},
|
|
24
24
|
storage: {
|
|
25
25
|
type: "string",
|
|
26
|
-
description: "Storage",
|
|
26
|
+
description: "Storage - postgres, none",
|
|
27
27
|
},
|
|
28
28
|
dnaUrl: {
|
|
29
29
|
type: "string",
|
|
30
|
-
description: "DNA URL",
|
|
30
|
+
description: "DNA URL - https://custom-dna-url.apibara.org",
|
|
31
|
+
},
|
|
32
|
+
dir: {
|
|
33
|
+
type: "string",
|
|
34
|
+
description:
|
|
35
|
+
"Root directory - apibara project root where apibara.config is located | default: current working directory",
|
|
31
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
|
@@ -26,10 +26,20 @@ export default defineCommand({
|
|
|
26
26
|
type: "string",
|
|
27
27
|
description: "Preset to use",
|
|
28
28
|
},
|
|
29
|
+
alwaysReindex: {
|
|
30
|
+
type: "boolean",
|
|
31
|
+
default: false,
|
|
32
|
+
description:
|
|
33
|
+
"Reindex the indexers from the starting block on every restart (default: false)",
|
|
34
|
+
},
|
|
29
35
|
},
|
|
30
36
|
async run({ args }) {
|
|
31
37
|
const rootDir = resolve((args.dir || args._dir || ".") as string);
|
|
32
38
|
|
|
39
|
+
if (args.alwaysReindex) {
|
|
40
|
+
process.env.APIBARA_ALWAYS_REINDEX = "true";
|
|
41
|
+
}
|
|
42
|
+
|
|
33
43
|
let apibara: Apibara;
|
|
34
44
|
let childProcess: ChildProcess | undefined;
|
|
35
45
|
|
|
@@ -79,19 +89,21 @@ export default defineCommand({
|
|
|
79
89
|
await writeTypes(apibara);
|
|
80
90
|
await build(apibara);
|
|
81
91
|
|
|
82
|
-
apibara.hooks.hook("dev:restart", () => {
|
|
92
|
+
apibara.hooks.hook("dev:restart", async () => {
|
|
83
93
|
if (childProcess) {
|
|
84
94
|
apibara.logger.info("Change detected, stopping indexers to restart");
|
|
85
|
-
childProcess
|
|
95
|
+
await killProcess(childProcess);
|
|
86
96
|
childProcess = undefined;
|
|
87
97
|
}
|
|
88
98
|
});
|
|
89
99
|
|
|
90
|
-
apibara.hooks.hook("dev:reload", () => {
|
|
100
|
+
apibara.hooks.hook("dev:reload", async () => {
|
|
91
101
|
if (childProcess) {
|
|
92
|
-
|
|
102
|
+
apibara.logger.info("Restarting indexers");
|
|
103
|
+
await killProcess(childProcess);
|
|
104
|
+
childProcess = undefined;
|
|
93
105
|
} else {
|
|
94
|
-
apibara.logger.
|
|
106
|
+
apibara.logger.info("Starting indexers");
|
|
95
107
|
}
|
|
96
108
|
|
|
97
109
|
const childArgs = [
|
|
@@ -118,3 +130,12 @@ export default defineCommand({
|
|
|
118
130
|
await reload();
|
|
119
131
|
},
|
|
120
132
|
});
|
|
133
|
+
|
|
134
|
+
async function killProcess(childProcess: ChildProcess | undefined) {
|
|
135
|
+
if (childProcess) {
|
|
136
|
+
await new Promise((resolve) => {
|
|
137
|
+
childProcess.once("exit", resolve);
|
|
138
|
+
childProcess.kill();
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
package/src/cli/commands/init.ts
CHANGED
|
@@ -18,23 +18,19 @@ export default defineCommand({
|
|
|
18
18
|
default: "ts",
|
|
19
19
|
alias: "l",
|
|
20
20
|
},
|
|
21
|
-
|
|
21
|
+
noIndexer: {
|
|
22
22
|
type: "boolean",
|
|
23
23
|
description: "Do not create an indexer after initialization",
|
|
24
24
|
default: false,
|
|
25
25
|
},
|
|
26
26
|
},
|
|
27
27
|
async run({ args }) {
|
|
28
|
-
const {
|
|
29
|
-
dir: targetDir,
|
|
30
|
-
"no-create-indexer": noCreateIndexer,
|
|
31
|
-
language,
|
|
32
|
-
} = args;
|
|
28
|
+
const { dir: targetDir, noIndexer, language } = args;
|
|
33
29
|
|
|
34
30
|
await initializeProject({
|
|
35
31
|
argTargetDir: targetDir,
|
|
36
32
|
argLanguage: language,
|
|
37
|
-
argNoCreateIndexer:
|
|
33
|
+
argNoCreateIndexer: noIndexer,
|
|
38
34
|
});
|
|
39
35
|
},
|
|
40
36
|
});
|
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,29 +1,24 @@
|
|
|
1
|
-
import type esbuild from "esbuild";
|
|
2
1
|
import { isAbsolute, relative } from "pathe";
|
|
3
|
-
import type
|
|
2
|
+
import type * as rolldown from "rolldown";
|
|
4
3
|
|
|
5
|
-
export function
|
|
6
|
-
_error: rollup.RollupError | esbuild.OnResolveResult,
|
|
7
|
-
) {
|
|
4
|
+
export function formatRolldownError(_error: rolldown.RollupError) {
|
|
8
5
|
try {
|
|
9
6
|
const logs: string[] = [_error.toString()];
|
|
10
7
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
11
|
-
const errors = (_error as any)?.errors || [_error as
|
|
8
|
+
const errors = (_error as any)?.errors || [_error as rolldown.RollupError];
|
|
12
9
|
for (const error of errors) {
|
|
13
|
-
const id = error.path || error.id || (_error as
|
|
10
|
+
const id = error.path || error.id || (_error as rolldown.RollupError).id;
|
|
14
11
|
let path = isAbsolute(id) ? relative(process.cwd(), id) : id;
|
|
15
|
-
const location =
|
|
16
|
-
(error as rollup.RollupError).loc ||
|
|
17
|
-
(error as esbuild.PartialMessage).location;
|
|
12
|
+
const location = (error as rolldown.RollupError).loc;
|
|
18
13
|
if (location) {
|
|
19
14
|
path += `:${location.line}:${location.column}`;
|
|
20
15
|
}
|
|
21
|
-
const text =
|
|
22
|
-
(error as esbuild.PartialMessage).text ||
|
|
23
|
-
(error as rollup.RollupError).frame;
|
|
16
|
+
const text = (error as rolldown.RollupError).frame;
|
|
24
17
|
|
|
25
18
|
logs.push(
|
|
26
|
-
`
|
|
19
|
+
`Rolldown error while processing \`${path}\`` + text
|
|
20
|
+
? "\n\n" + text
|
|
21
|
+
: "",
|
|
27
22
|
);
|
|
28
23
|
}
|
|
29
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 = [
|