Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
run(builderConfig) {
const architect = this.context.architect;
const options = builderConfig.options;
const root = this.context.workspace.root;
const projectRoot = core_1.resolve(root, builderConfig.root);
const [project, targetName, configuration] = options.browserTarget.split(':');
// Override browser build watch setting.
const overrides = { watch: false };
const browserTargetSpec = { project, target: targetName, configuration, overrides };
const browserBuilderConfig = architect.getBuilderConfiguration(browserTargetSpec);
const webpackBuilder = new build_webpack_1.WebpackBuilder(this.context);
const loggingCb = (stats, config, logger) => {
const json = stats.toJson();
if (stats.hasWarnings()) {
this.context.logger.warn(stats_1.statsWarningsToString(json, config.stats));
}
if (stats.hasErrors()) {
this.context.logger.error(stats_1.statsErrorsToString(json, config.stats));
}
};
return architect.getBuilderDescription(browserBuilderConfig).pipe(operators_1.concatMap(browserDescription => architect.validateBuilderOptions(browserBuilderConfig, browserDescription)), operators_1.map(browserBuilderConfig => browserBuilderConfig.options), operators_1.concatMap((validatedBrowserOptions) => {
const browserOptions = validatedBrowserOptions;
// We need to determine the outFile name so that AngularCompiler can retrieve it.
let outFile = options.outFile || getI18nOutfile(options.i18nFormat);
if (options.outputPath) {
// AngularCompilerPlugin doesn't support genDir so we have to adjust outFile instead.
outFile = path.join(options.outputPath, outFile);
run(builderConfig: BuilderConfiguration): Observable {
console.log('Hi');
const options = builderConfig.options;
const root = this.context.workspace.root;
const projectRoot = resolve(root, builderConfig.root);
const host = new virtualFs.AliasHost(this.context.host as virtualFs.Host);
const webpackBuilder = new WebpackBuilder({ ...this.context, host });
return of(null).pipe(
concatMap(() => options.deleteOutputPath
? this._deleteOutputDir(root, normalize(options.outputPath), this.context.host)
: of(null)),
concatMap(() => addFileReplacements(root, host, options.fileReplacements)),
concatMap(() => normalizeAssetPatterns(
options.assets, host, root, projectRoot, builderConfig.sourceRoot)),
// Replace the assets in options with the normalized version.
tap((assetPatternObjects => options.assets = assetPatternObjects)),
concatMap(() => {
// Ensure Build Optimizer is only used with AOT.
if (options.buildOptimizer && !options.aot) {
throw new Error('The `--build-optimizer` option cannot be used without `--aot`.');
}
run(builderConfig) {
const architect = this.context.architect;
const options = builderConfig.options;
const root = this.context.workspace.root;
const projectRoot = core_1.resolve(root, builderConfig.root);
const [project, targetName, configuration] = options.browserTarget.split(':');
// Override browser build watch setting.
const overrides = { watch: false };
const browserTargetSpec = { project, target: targetName, configuration, overrides };
const browserBuilderConfig = architect.getBuilderConfiguration(browserTargetSpec);
const webpackBuilder = new build_webpack_1.WebpackBuilder(this.context);
const loggingCb = (stats, config, logger) => {
const json = stats.toJson();
if (stats.hasWarnings()) {
this.context.logger.warn(stats_1.statsWarningsToString(json, config.stats));
}
if (stats.hasErrors()) {
this.context.logger.error(stats_1.statsErrorsToString(json, config.stats));
}
};
return architect.getBuilderDescription(browserBuilderConfig).pipe(operators_1.concatMap(browserDescription => architect.validateBuilderOptions(browserBuilderConfig, browserDescription)), operators_1.map(browserBuilderConfig => browserBuilderConfig.options), operators_1.concatMap((validatedBrowserOptions) => {
const browserOptions = validatedBrowserOptions;
// We need to determine the outFile name so that AngularCompiler can retrieve it.
let outFile = options.outFile || getI18nOutfile(options.i18nFormat);
if (options.outputPath) {
// AngularCompilerPlugin doesn't support genDir so we have to adjust outFile instead.
outFile = path.join(options.outputPath, outFile);
run(builderConfig: BuilderConfiguration): Observable {
const options = builderConfig.options;
const root = this.context.workspace.root;
const projectRoot = resolve(root, builderConfig.root);
const host = new virtualFs.AliasHost(this.context.host as virtualFs.Host);
const webpackBuilder = new WebpackBuilder({ ...this.context, host });
// TODO: verify using of(null) to kickstart things is a pattern.
return of(null).pipe(
concatMap(() => options.deleteOutputPath
? this._deleteOutputDir(root, normalize(options.outputPath), this.context.host)
: of(null)),
concatMap(() => normalizeFileReplacements(options.fileReplacements, host, root)),
tap(fileReplacements => options.fileReplacements = fileReplacements),
concatMap(() => {
const webpackConfig = this.buildWebpackConfig(root, projectRoot, host, options);
return webpackBuilder.runWebpack(webpackConfig, getBrowserLoggingCb(options.verbose));
}),
);
}
run(builderConfig: BuilderConfiguration): Observable {
const options = builderConfig.options;
const root = this.context.workspace.root;
const projectRoot = resolve(root, builderConfig.root);
const host = new virtualFs.AliasHost(this.context.host as virtualFs.Host);
const webpackBuilder = new WebpackBuilder({ ...this.context, host });
return of(null).pipe(
concatMap(() => options.deleteOutputPath
? this._deleteOutputDir(root, normalize(options.outputPath), this.context.host)
: of(null)),
concatMap(() => normalizeFileReplacements(options.fileReplacements, host, root)),
tap(fileReplacements => options.fileReplacements = fileReplacements),
concatMap(() => normalizeAssetPatterns(
options.assets, host, root, projectRoot, builderConfig.sourceRoot)),
// Replace the assets in options with the normalized version.
tap((assetPatternObjects => options.assets = assetPatternObjects)),
concatMap(() => {
let webpackConfig;
try {
webpackConfig = this.buildWebpackConfig(root, projectRoot, host,
options as NormalizedBrowserBuilderSchema);
run(builderConfig: BuilderConfiguration): Observable {
const root = this.context.workspace.root;
const projectRoot = resolve(root, builderConfig.root);
const host = new virtualFs.AliasHost(this.context.host as virtualFs.Host);
const webpackBuilder = new WebpackBuilder({ ...this.context, host });
const options = normalizeWebpackServerSchema(
host,
root,
resolve(root, builderConfig.root),
builderConfig.sourceRoot,
builderConfig.options,
);
// TODO: verify using of(null) to kickstart things is a pattern.
return of(null).pipe(
concatMap(() => options.deleteOutputPath
? this._deleteOutputDir(root, normalize(options.outputPath), this.context.host)
: of(null)),
concatMap(() => {
const webpackConfig = this.buildWebpackConfig(root, projectRoot, host, options);
run(builderConfig) {
const options = builderConfig.options;
const root = this.context.workspace.root;
const projectRoot = core_1.resolve(root, builderConfig.root);
const host = new core_1.virtualFs.AliasHost(this.context.host);
const webpackBuilder = new build_webpack_1.WebpackBuilder(Object.assign({}, this.context, { host }));
return rxjs_1.of(null).pipe(operators_1.concatMap(() => options.deleteOutputPath
? this._deleteOutputDir(root, core_1.normalize(options.outputPath), this.context.host)
: rxjs_1.of(null)), operators_1.concatMap(() => utils_1.normalizeFileReplacements(options.fileReplacements, host, root)), operators_1.tap(fileReplacements => options.fileReplacements = fileReplacements), operators_1.concatMap(() => utils_1.normalizeAssetPatterns(options.assets, host, root, projectRoot, builderConfig.sourceRoot)),
// Replace the assets in options with the normalized version.
operators_1.tap((assetPatternObjects => options.assets = assetPatternObjects)), operators_1.concatMap(() => {
let webpackConfig;
try {
webpackConfig = this.buildWebpackConfig(root, projectRoot, host, options);
}
catch (e) {
return rxjs_1.throwError(e);
}
return webpackBuilder.runWebpack(webpackConfig, exports.getBrowserLoggingCb(options.verbose));
}), operators_1.concatMap(buildEvent => {
if (buildEvent.success && !options.watch && options.serviceWorker) {
return new rxjs_1.Observable(obs => {
run(builderConfig) {
const root = this.context.workspace.root;
const projectRoot = core_1.resolve(root, builderConfig.root);
const host = new core_1.virtualFs.AliasHost(this.context.host);
const webpackBuilder = new build_webpack_1.WebpackBuilder(Object.assign({}, this.context, { host }));
const options = utils_1.normalizeBuilderSchema(host, root, builderConfig);
// TODO: verify using of(null) to kickstart things is a pattern.
return rxjs_1.of(null).pipe(operators_1.concatMap(() => options.deleteOutputPath
? this._deleteOutputDir(root, core_1.normalize(options.outputPath), this.context.host)
: rxjs_1.of(null)), operators_1.concatMap(() => {
const webpackConfig = this.buildWebpackConfig(root, projectRoot, host, options);
return webpackBuilder.runWebpack(webpackConfig, browser_1.getBrowserLoggingCb(options.verbose));
}));
}
buildWebpackConfig(root, projectRoot, host, options) {
constructor(private context: BuilderContext) {
this.webpackBuilder = new WebpackBuilder(this.context);
this.root = getSystemPath(this.context.workspace.root);
}
protected createWebpackBuilder(context: BuilderContext): WebpackBuilder {
return new WebpackBuilder(context);
}