"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomWebpackBuilder = exports.defaultWebpackConfigPath = void 0; const core_1 = require("@angular-devkit/core"); const webpack_config_merger_1 = require("./webpack-config-merger"); const utils_1 = require("./utils"); exports.defaultWebpackConfigPath = 'webpack.config.js'; class CustomWebpackBuilder { static buildWebpackConfig(root, config, baseWebpackConfig, buildOptions, targetOptions) { return __awaiter(this, void 0, void 0, function* () { if (!config) { return baseWebpackConfig; } const webpackConfigPath = config.path || exports.defaultWebpackConfigPath; const path = `${core_1.getSystemPath(root)}/${webpackConfigPath}`; const tsConfig = `${core_1.getSystemPath(root)}/${buildOptions.tsConfig}`; const configOrFactoryOrPromise = resolveCustomWebpackConfig(path, tsConfig); if (typeof configOrFactoryOrPromise === 'function') { // That exported function can be synchronous either // asynchronous. Given the following example: // `module.exports = async (config) => { ... }` return configOrFactoryOrPromise(baseWebpackConfig, buildOptions, targetOptions); } // The user can also export a `Promise` that resolves `Configuration` // object. Given the following example: // `module.exports = new Promise(resolve => resolve({ ... }))` // If the user has exported a plain object, like: // `module.exports = { ... }` // then it will promisified and awaited const resolvedConfig = yield configOrFactoryOrPromise; return webpack_config_merger_1.mergeConfigs(baseWebpackConfig, resolvedConfig, config.mergeRules, config.replaceDuplicatePlugins); }); } } exports.CustomWebpackBuilder = CustomWebpackBuilder; function resolveCustomWebpackConfig(path, tsConfig) { utils_1.tsNodeRegister(path, tsConfig); const customWebpackConfig = require(path); // If the user provides a configuration in TS file // then there are 2 cases for exporing an object. The first one is: // `module.exports = { ... }`. And the second one is: // `export default { ... }`. The ESM format is compiled into: // `{ default: { ... } }` return customWebpackConfig.default || customWebpackConfig; } // Dummy changes //# sourceMappingURL=custom-webpack-builder.js.map