MCPcopy
hub / github.com/webpack/webpack / compile

Function compile

test/Errors.test.js:143–183  ·  test/Errors.test.js::compile

* @param {import("../").Configuration} options options * @returns {Promise<{ errors: import("../").StatsError[], warnings: import("../").StatsError[] }>} errors and warnings

(options)

Source from the content-addressed store, hash-verified

141 * @returns {Promise<{ errors: import(class="st">"../").StatsError[], warnings: import(class="st">"../").StatsError[] }>} errors and warnings
142 */
143async function compile(options) {
144 const stats = await new Promise((resolve, reject) => {
145 const compiler = webpack(
146 /** @type {import(class="st">"../").Configuration} */ ({
147 ...defaults.options,
148 ...options
149 })
150 );
151 if (options.mode === class="st">"production") {
152 if (options.optimization) options.optimization.minimize = true;
153 else options.optimization = { minimize: true };
154 }
155 compiler.outputFileSystem = defaults.outputFileSystem;
156
157 try {
158 compiler.run((bailedError, stats) => {
159 if (bailedError) {
160 return reject(bailedError);
161 }
162 compiler.close((closeError) => {
163 if (closeError) {
164 return reject(closeError);
165 }
166 resolve(stats);
167 });
168 });
169 } catch (err) {
170 class="cm">// capture sync thrown errors
171 reject(err);
172 }
173 });
174
175 expect(typeof stats).toBe(class="st">"object");
176 const statsResult = stats.toJson({ errorDetails: false });
177 expect(typeof statsResult).toBe(class="st">"object");
178 const { errors, warnings } = statsResult;
179 expect(Array.isArray(errors)).toBe(true);
180 expect(Array.isArray(warnings)).toBe(true);
181
182 return { errors, warnings };
183}
184
185expectNoDeprecations();
186

Callers 1

Errors.test.jsFile · 0.70

Calls 6

resolveFunction · 0.85
isArrayMethod · 0.80
webpackFunction · 0.50
runMethod · 0.45
closeMethod · 0.45
toJsonMethod · 0.45

Tested by

no test coverage detected