MCPcopy Index your code
hub / github.com/subquery/subql / runBundle

Function runBundle

packages/cli/src/controller/build-controller.ts:97–151  ·  view source on GitHub ↗
(
  buildEntries: Record<string, string>,
  projectDir: string,
  outputDir: string,
  isDev = false,
  clean = false,
  logger?: Logger
)

Source from the content-addressed store, hash-verified

95}
96
97export async function runBundle(
98 buildEntries: Record<string, string>,
99 projectDir: string,
100 outputDir: string,
101 isDev = false,
102 clean = false,
103 logger?: Logger
104): Promise<void> {
105 // Injecting polyfills if they exist, this allows setting global variables like TextDecoder/TextEncoder
106 const inject = [path.resolve(projectDir, './src/polyfill.ts'), path.resolve(projectDir, './src/polyfills.ts')].filter(
107 (file) => existsSync(file)
108 );
109
110 if (inject.length) {
111 logger?.warn(
112 'Support for pollyfill files has been removed. Please move the code to the top of your entry index.ts file'
113 );
114 }
115
116 const config = merge(
117 getBaseConfig(buildEntries, projectDir, outputDir, isDev),
118 {output: {clean}}
119 // Can allow projects to override webpack config here
120 );
121
122 const tsConfig = loadTsConfig(projectDir);
123 if (tsConfig?.compilerOptions?.paths && config.resolve && config.resolve.plugins) {
124 config.resolve.plugins.push(new TsconfigPathsPlugin());
125 }
126
127 await new Promise((resolve, reject) => {
128 const wp = webpack(config);
129
130 if (!wp) {
131 throw new Error('Webpack failed to initialize');
132 }
133
134 wp.run((error, stats) => {
135 if (error) {
136 reject(error);
137 return;
138 }
139 assert(stats, 'Webpack stats is undefined');
140
141 if (stats.hasErrors()) {
142 const info = stats.toJson();
143
144 reject(new Error(info.errors?.map((e) => e.message).join('\n') ?? 'Unknown error'));
145 return;
146 }
147
148 resolve(true);
149 });
150 });
151}
152
153export function getBuildEntries(directory: string, logger?: Logger): Record<string, string> {
154 // FIXME: this is an assumption that the default entry is src/index.ts, in reality it should read from the project manifest

Callers 1

buildAdapterFunction · 0.90

Calls 6

getBaseConfigFunction · 0.85
loadTsConfigFunction · 0.85
mapMethod · 0.80
resolveFunction · 0.50
warnMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected