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
|
@@ -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,17 +1,17 @@
|
|
|
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
|
-
${indexers.map((i) => `import _${hash(i)} from '${i.indexer}';`).join("\n")}
|
|
10
|
+
${indexers.map((i) => `import * as _${hash(i)} from '${i.indexer}';`).join("\n")}
|
|
11
11
|
|
|
12
12
|
export const indexers = [
|
|
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/runtime/dev.ts
CHANGED
|
@@ -37,6 +37,9 @@ const startCommand = defineCommand({
|
|
|
37
37
|
await Promise.all(
|
|
38
38
|
selectedIndexers.map(async (indexer) => {
|
|
39
39
|
const indexerInstance = createIndexer(indexer, preset);
|
|
40
|
+
if (!indexerInstance) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
40
43
|
|
|
41
44
|
const client = createClient(
|
|
42
45
|
indexerInstance.streamConfig,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
inMemoryPersistence,
|
|
9
9
|
logger,
|
|
10
10
|
} from "@apibara/indexer/plugins";
|
|
11
|
+
import consola from "consola";
|
|
11
12
|
import { config } from "#apibara-internal-virtual/config";
|
|
12
13
|
import { indexers } from "#apibara-internal-virtual/indexers";
|
|
13
14
|
import { createLogger } from "./logger";
|
|
@@ -42,10 +43,18 @@ export function createIndexer(indexerName: string, preset?: string) {
|
|
|
42
43
|
);
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
const indexerModule = indexerDefinition.indexer?.default;
|
|
47
|
+
if (indexerModule === undefined) {
|
|
48
|
+
consola.warn(
|
|
49
|
+
`Specified indexer "${indexerName}" but it does not export a default. Ignoring.`,
|
|
50
|
+
);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
45
54
|
const definition =
|
|
46
|
-
typeof
|
|
47
|
-
?
|
|
48
|
-
:
|
|
55
|
+
typeof indexerModule === "function"
|
|
56
|
+
? indexerModule(runtimeConfig)
|
|
57
|
+
: indexerModule;
|
|
49
58
|
|
|
50
59
|
let reporter: ConsolaReporter = createLogger({
|
|
51
60
|
indexer: indexerName,
|
|
@@ -63,15 +72,14 @@ export function createIndexer(indexerName: string, preset?: string) {
|
|
|
63
72
|
|
|
64
73
|
// Put the in-memory persistence plugin first so that it can be overridden by any user-defined
|
|
65
74
|
// persistence plugin.
|
|
66
|
-
// Put the logger last since we want to override any user-defined logger.
|
|
67
75
|
definition.plugins = [
|
|
68
76
|
internalContext({
|
|
69
77
|
indexerName,
|
|
70
78
|
availableIndexers,
|
|
71
79
|
} as InternalContext),
|
|
80
|
+
logger({ logger: reporter }),
|
|
72
81
|
inMemoryPersistence(),
|
|
73
82
|
...(definition.plugins ?? []),
|
|
74
|
-
logger({ logger: reporter }),
|
|
75
83
|
];
|
|
76
84
|
|
|
77
85
|
return _createIndexer(definition);
|
package/src/runtime/start.ts
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";
|
|
5
6
|
|
|
6
7
|
const startCommand = defineCommand({
|
|
@@ -23,6 +24,10 @@ const startCommand = defineCommand({
|
|
|
23
24
|
const { indexer, preset } = args;
|
|
24
25
|
|
|
25
26
|
const indexerInstance = createIndexer(indexer, preset);
|
|
27
|
+
if (!indexerInstance) {
|
|
28
|
+
consola.error(`Specified indexer "${indexer}" but it was not defined`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
26
31
|
|
|
27
32
|
const client = createClient(
|
|
28
33
|
indexerInstance.streamConfig,
|
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,17 @@ 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
|
-
|
|
90
|
+
node: boolean;
|
|
91
|
+
exportConditions?: string[];
|
|
87
92
|
|
|
88
93
|
// Advanced
|
|
89
94
|
typescript: {
|
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
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -7,4 +7,7 @@ export type IndexerConstructor =
|
|
|
7
7
|
) => IndexerWithStreamConfig<unknown, unknown, unknown>)
|
|
8
8
|
| IndexerWithStreamConfig<unknown, unknown, unknown>;
|
|
9
9
|
|
|
10
|
-
export const indexers: {
|
|
10
|
+
export const indexers: {
|
|
11
|
+
name: string;
|
|
12
|
+
indexer: { default?: IndexerConstructor | undefined };
|
|
13
|
+
}[] = [];
|
package/dist/rollup/index.d.mts
DELETED
package/dist/rollup/index.d.ts
DELETED
package/dist/rollup/index.mjs
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { builtinModules } from 'node:module';
|
|
2
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
3
|
-
import json from '@rollup/plugin-json';
|
|
4
|
-
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
5
|
-
import { join } from 'pathe';
|
|
6
|
-
import defu from 'defu';
|
|
7
|
-
import virtual from '@rollup/plugin-virtual';
|
|
8
|
-
import MagicString from 'magic-string';
|
|
9
|
-
import { hash } from 'ohash';
|
|
10
|
-
|
|
11
|
-
function appConfig(apibara) {
|
|
12
|
-
return virtual({
|
|
13
|
-
"#apibara-internal-virtual/config": `
|
|
14
|
-
import * as projectConfig from '${apibara.options._c12.configFile}';
|
|
15
|
-
|
|
16
|
-
export const config = projectConfig.default;
|
|
17
|
-
`
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function esmShim() {
|
|
22
|
-
const ESMShim = `
|
|
23
|
-
// -- Shims --
|
|
24
|
-
import cjsUrl from 'node:url';
|
|
25
|
-
import cjsPath from 'node:path';
|
|
26
|
-
const __filename = cjsUrl.fileURLToPath(import.meta.url);
|
|
27
|
-
const __dirname = cjsPath.dirname(__filename);
|
|
28
|
-
// -- End Shims --
|
|
29
|
-
`;
|
|
30
|
-
const CJSyntaxRegex = /__filename|__dirname/;
|
|
31
|
-
return {
|
|
32
|
-
name: "esm-shim",
|
|
33
|
-
renderChunk(code, _chunk, opts) {
|
|
34
|
-
if (opts.format === "es") {
|
|
35
|
-
if (code.includes(ESMShim) || !CJSyntaxRegex.test(code)) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
let endIndexOfLastImport = -1;
|
|
39
|
-
for (const match of code.matchAll(/^import\s.*';$/gm)) {
|
|
40
|
-
if (match.length === 0 || typeof match.index !== "number") {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
endIndexOfLastImport = match.index + match[0].length;
|
|
44
|
-
}
|
|
45
|
-
const s = new MagicString(code);
|
|
46
|
-
s.appendRight(endIndexOfLastImport, ESMShim);
|
|
47
|
-
const sourceMap = s.generateMap({
|
|
48
|
-
includeContent: true
|
|
49
|
-
});
|
|
50
|
-
let sourcesContent;
|
|
51
|
-
if (Array.isArray(sourceMap.sourcesContent)) {
|
|
52
|
-
sourcesContent = [];
|
|
53
|
-
for (let i = 0; i < sourceMap.sourcesContent.length; i++) {
|
|
54
|
-
const content = sourceMap.sourcesContent[i];
|
|
55
|
-
if (typeof content === "string") {
|
|
56
|
-
sourcesContent.push(content);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return {
|
|
61
|
-
code: s.toString(),
|
|
62
|
-
map: {
|
|
63
|
-
...sourceMap,
|
|
64
|
-
sourcesContent
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function indexers(apibara) {
|
|
74
|
-
const indexers2 = [...new Set(apibara.indexers)];
|
|
75
|
-
return virtual({
|
|
76
|
-
"#apibara-internal-virtual/indexers": `
|
|
77
|
-
${indexers2.map((i) => `import _${hash(i)} from '${i.indexer}';`).join("\n")}
|
|
78
|
-
|
|
79
|
-
export const indexers = [
|
|
80
|
-
${indexers2.map((i) => `{ name: "${i.name}", indexer: _${hash(i)} }`).join(",\n")}
|
|
81
|
-
];
|
|
82
|
-
`
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const runtimeDependencies = ["better-sqlite3", "@electric-sql/pglite"];
|
|
87
|
-
function getRollupConfig(apibara) {
|
|
88
|
-
const extensions = [
|
|
89
|
-
".ts",
|
|
90
|
-
".mjs",
|
|
91
|
-
".js",
|
|
92
|
-
".json",
|
|
93
|
-
".node",
|
|
94
|
-
".tsx",
|
|
95
|
-
".jsx"
|
|
96
|
-
];
|
|
97
|
-
const rollupConfig = defu(
|
|
98
|
-
// biome-ignore lint/suspicious/noExplicitAny: apibara.options.rollupConfig is typed
|
|
99
|
-
apibara.options.rollupConfig,
|
|
100
|
-
{
|
|
101
|
-
input: apibara.options.entry,
|
|
102
|
-
output: {
|
|
103
|
-
dir: join(apibara.options.outputDir || "./.apibara/build"),
|
|
104
|
-
format: "esm",
|
|
105
|
-
exports: "auto",
|
|
106
|
-
entryFileNames: "[name].mjs",
|
|
107
|
-
chunkFileNames: "chunks/[name]-[hash].mjs",
|
|
108
|
-
generatedCode: {
|
|
109
|
-
constBindings: true
|
|
110
|
-
},
|
|
111
|
-
sourcemap: true,
|
|
112
|
-
sourcemapExcludeSources: true,
|
|
113
|
-
sourcemapIgnoreList(relativePath, sourcemapPath) {
|
|
114
|
-
return relativePath.includes("node_modules");
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
plugins: [],
|
|
118
|
-
onwarn(warning, rollupWarn) {
|
|
119
|
-
if (!["CIRCULAR_DEPENDENCY", "EVAL", "THIS_IS_UNDEFINED"].includes(
|
|
120
|
-
warning.code || ""
|
|
121
|
-
) && !warning.message.includes("Unsupported source map comment") && !warning.message.includes("@__PURE__") && !warning.message.includes("/*#__PURE__*/")) {
|
|
122
|
-
rollupWarn(warning);
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
treeshake: true,
|
|
126
|
-
external: [...builtinModules, ...runtimeDependencies]
|
|
127
|
-
}
|
|
128
|
-
);
|
|
129
|
-
rollupConfig.plugins.push(esmShim());
|
|
130
|
-
rollupConfig.plugins.push(json());
|
|
131
|
-
rollupConfig.plugins.push(
|
|
132
|
-
commonjs({
|
|
133
|
-
strictRequires: true,
|
|
134
|
-
requireReturnsDefault: "auto",
|
|
135
|
-
...apibara.options.commonJS
|
|
136
|
-
})
|
|
137
|
-
);
|
|
138
|
-
rollupConfig.plugins.push(
|
|
139
|
-
nodeResolve({
|
|
140
|
-
extensions,
|
|
141
|
-
preferBuiltins: true,
|
|
142
|
-
mainFields: ["main"]
|
|
143
|
-
})
|
|
144
|
-
);
|
|
145
|
-
rollupConfig.plugins.push(indexers(apibara));
|
|
146
|
-
rollupConfig.plugins.push(appConfig(apibara));
|
|
147
|
-
return rollupConfig;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export { getRollupConfig };
|
package/src/rollup/config.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { builtinModules } from "node:module";
|
|
2
|
-
import commonjs from "@rollup/plugin-commonjs";
|
|
3
|
-
import json from "@rollup/plugin-json";
|
|
4
|
-
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
5
|
-
import type { Apibara, RollupConfig } from "apibara/types";
|
|
6
|
-
import { join } from "pathe";
|
|
7
|
-
import type { OutputPluginOption } from "rollup";
|
|
8
|
-
|
|
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 {
|
|
17
|
-
const extensions: string[] = [
|
|
18
|
-
".ts",
|
|
19
|
-
".mjs",
|
|
20
|
-
".js",
|
|
21
|
-
".json",
|
|
22
|
-
".node",
|
|
23
|
-
".tsx",
|
|
24
|
-
".jsx",
|
|
25
|
-
];
|
|
26
|
-
|
|
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,
|
|
40
|
-
},
|
|
41
|
-
sourcemap: true,
|
|
42
|
-
sourcemapExcludeSources: true,
|
|
43
|
-
sourcemapIgnoreList(relativePath, sourcemapPath) {
|
|
44
|
-
return relativePath.includes("node_modules");
|
|
45
|
-
},
|
|
46
|
-
},
|
|
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],
|
|
62
|
-
},
|
|
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
|
-
}
|
package/src/rollup/index.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import MagicString from "magic-string";
|
|
2
|
-
import type { Plugin } from "rollup";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* An alternative to @rollup/plugin-esm-shim
|
|
6
|
-
*/
|
|
7
|
-
export function esmShim(): Plugin {
|
|
8
|
-
const ESMShim = `
|
|
9
|
-
// -- Shims --
|
|
10
|
-
import cjsUrl from 'node:url';
|
|
11
|
-
import cjsPath from 'node:path';
|
|
12
|
-
const __filename = cjsUrl.fileURLToPath(import.meta.url);
|
|
13
|
-
const __dirname = cjsPath.dirname(__filename);
|
|
14
|
-
// -- End Shims --
|
|
15
|
-
`;
|
|
16
|
-
|
|
17
|
-
const CJSyntaxRegex = /__filename|__dirname/;
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
name: "esm-shim",
|
|
21
|
-
|
|
22
|
-
renderChunk(code, _chunk, opts) {
|
|
23
|
-
if (opts.format === "es") {
|
|
24
|
-
if (code.includes(ESMShim) || !CJSyntaxRegex.test(code)) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let endIndexOfLastImport = -1;
|
|
29
|
-
|
|
30
|
-
// Find the last import statement and its ending index
|
|
31
|
-
for (const match of code.matchAll(/^import\s.*';$/gm)) {
|
|
32
|
-
if (match.length === 0 || typeof match.index !== "number") {
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
endIndexOfLastImport = match.index + match[0].length;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const s = new MagicString(code);
|
|
40
|
-
s.appendRight(endIndexOfLastImport, ESMShim);
|
|
41
|
-
|
|
42
|
-
const sourceMap = s.generateMap({
|
|
43
|
-
includeContent: true,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
let sourcesContent: string[] | undefined;
|
|
47
|
-
if (Array.isArray(sourceMap.sourcesContent)) {
|
|
48
|
-
sourcesContent = [];
|
|
49
|
-
for (let i = 0; i < sourceMap.sourcesContent.length; i++) {
|
|
50
|
-
const content = sourceMap.sourcesContent[i];
|
|
51
|
-
if (typeof content === "string") {
|
|
52
|
-
sourcesContent.push(content);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
code: s.toString(),
|
|
59
|
-
map: {
|
|
60
|
-
...sourceMap,
|
|
61
|
-
sourcesContent,
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return null;
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
}
|