Skip to content

Commit 6d21be3

Browse files
author
Angular Builds
committed
a491b09 fix(@ngtools/webpack): import factory from original declaration file
1 parent 28526c6 commit 6d21be3

File tree

15 files changed

+83
-64
lines changed

15 files changed

+83
-64
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "@angular-devkit/build-angular",
3-
"version": "0.800.0-beta.18+93.3bf929f",
3+
"version": "0.800.0-beta.18+99.a491b09",
44
"description": "Angular Webpack Build Facade",
55
"experimental": true,
66
"main": "src/index.js",
77
"typings": "src/index.d.ts",
88
"builders": "builders.json",
99
"dependencies": {
10-
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#3bf929f",
11-
"@angular-devkit/build-optimizer": "github:angular/angular-devkit-build-optimizer-builds#3bf929f",
12-
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#3bf929f",
13-
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#3bf929f",
14-
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#3bf929f",
10+
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#a491b09",
11+
"@angular-devkit/build-optimizer": "github:angular/angular-devkit-build-optimizer-builds#a491b09",
12+
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#a491b09",
13+
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#a491b09",
14+
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#a491b09",
1515
"ajv": "6.10.0",
1616
"autoprefixer": "9.5.1",
1717
"browserslist": "4.6.0",

src/angular-cli-files/models/webpack-configs/browser.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
88
* found in the LICENSE file at https://angular.io/license
99
*/
1010
const license_webpack_plugin_1 = require("license-webpack-plugin");
11-
const path = require("path");
12-
const index_html_webpack_plugin_1 = require("../../plugins/index-html-webpack-plugin");
13-
const package_chunk_sort_1 = require("../../utilities/package-chunk-sort");
1411
const utils_1 = require("./utils");
1512
const SubresourceIntegrityPlugin = require('webpack-subresource-integrity');
1613
function getBrowserConfig(wco) {
17-
const { root, buildOptions } = wco;
14+
const { buildOptions } = wco;
1815
const extraPlugins = [];
1916
let isEval = false;
2017
const { styles: stylesOptimization, scripts: scriptsOptimization } = buildOptions.optimization;
@@ -27,17 +24,6 @@ function getBrowserConfig(wco) {
2724
// Produce eval sourcemaps for development with serve, which are faster.
2825
isEval = true;
2926
}
30-
if (buildOptions.index) {
31-
extraPlugins.push(new index_html_webpack_plugin_1.IndexHtmlWebpackPlugin({
32-
input: path.resolve(root, buildOptions.index),
33-
output: path.basename(buildOptions.index),
34-
baseHref: buildOptions.baseHref,
35-
entrypoints: package_chunk_sort_1.generateEntryPoints(buildOptions),
36-
deployUrl: buildOptions.deployUrl,
37-
sri: buildOptions.subresourceIntegrity,
38-
noModuleEntrypoints: ['polyfills-es5'],
39-
}));
40-
}
4127
if (buildOptions.subresourceIntegrity) {
4228
extraPlugins.push(new SubresourceIntegrityPlugin({
4329
hashFuncNames: ['sha384'],

src/angular-cli-files/plugins/index-html-webpack-plugin.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Compiler } from 'webpack';
2+
import { IndexHtmlTransform } from '../utilities/index-file/write-index-html';
23
export interface IndexHtmlWebpackPluginOptions {
34
input: string;
45
output: string;
@@ -7,6 +8,7 @@ export interface IndexHtmlWebpackPluginOptions {
78
deployUrl?: string;
89
sri: boolean;
910
noModuleEntrypoints: string[];
11+
postTransform?: IndexHtmlTransform;
1012
}
1113
export declare class IndexHtmlWebpackPlugin {
1214
private _options;

src/angular-cli-files/plugins/index-html-webpack-plugin.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
88
* found in the LICENSE file at https://angular.io/license
99
*/
1010
const path = require("path");
11+
const webpack_sources_1 = require("webpack-sources");
1112
const augment_index_html_1 = require("../utilities/index-file/augment-index-html");
13+
const strip_bom_1 = require("../utilities/strip-bom");
1214
function readFile(filename, compilation) {
1315
return new Promise((resolve, reject) => {
1416
compilation.inputFileSystem.readFile(filename, (err, data) => {
1517
if (err) {
1618
reject(err);
1719
return;
1820
}
19-
let content;
20-
if (data.length >= 3 && data[0] === 0xEF && data[1] === 0xBB && data[2] === 0xBF) {
21-
// Strip UTF-8 BOM
22-
content = data.toString('utf8', 3);
23-
}
24-
else if (data.length >= 2 && data[0] === 0xFF && data[1] === 0xFE) {
25-
// Strip UTF-16 LE BOM
26-
content = data.toString('utf16le', 2);
27-
}
28-
else {
29-
content = data.toString();
30-
}
31-
resolve(content);
21+
resolve(strip_bom_1.stripBom(data.toString()));
3222
});
3323
});
3424
}
@@ -67,7 +57,7 @@ class IndexHtmlWebpackPlugin {
6757
}
6858
}
6959
const loadOutputFile = (name) => compilation.assets[name].source();
70-
const indexSource = await augment_index_html_1.augmentIndexHtml({
60+
let indexSource = await augment_index_html_1.augmentIndexHtml({
7161
input: this._options.input,
7262
inputContent,
7363
baseHref: this._options.baseHref,
@@ -78,8 +68,11 @@ class IndexHtmlWebpackPlugin {
7868
loadOutputFile,
7969
entrypoints: this._options.entrypoints,
8070
});
71+
if (this._options.postTransform) {
72+
indexSource = await this._options.postTransform(indexSource);
73+
}
8174
// Add to compilation assets
82-
compilation.assets[this._options.output] = indexSource;
75+
compilation.assets[this._options.output] = new webpack_sources_1.RawSource(indexSource);
8376
});
8477
}
8578
}

src/angular-cli-files/utilities/index-file/augment-index-html.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { Source } from 'webpack-sources';
98
export declare type LoadOutputFileFunctionType = (file: string) => Promise<string>;
109
export interface AugmentIndexHtmlOptions {
1110
input: string;
@@ -27,4 +26,4 @@ export interface FileInfo {
2726
name: string;
2827
extension: string;
2928
}
30-
export declare function augmentIndexHtml(params: AugmentIndexHtmlOptions): Promise<Source>;
29+
export declare function augmentIndexHtml(params: AugmentIndexHtmlOptions): Promise<string>;

src/angular-cli-files/utilities/index-file/augment-index-html.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ async function augmentIndexHtml(params) {
156156
treeAdapter.appendChild(styleElements, element);
157157
}
158158
indexSource.insert(styleInsertionPoint, parse5.serialize(styleElements, { treeAdapter }));
159-
return indexSource;
159+
return indexSource.source();
160160
}
161161
exports.augmentIndexHtml = augmentIndexHtml;
162162
function _generateSriAttributes(content) {

src/angular-cli-files/utilities/index-file/write-index-html.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ export interface WriteIndexHtmlOptions {
1313
host: virtualFs.Host;
1414
outputPath: Path;
1515
indexPath: Path;
16-
ES5BuildFiles: EmittedFiles[];
17-
ES2015BuildFiles: EmittedFiles[];
16+
files?: EmittedFiles[];
17+
noModuleFiles?: EmittedFiles[];
18+
moduleFiles?: EmittedFiles[];
1819
baseHref?: string;
1920
deployUrl?: string;
2021
sri?: boolean;
2122
scripts?: ExtraEntryPoint[];
2223
styles?: ExtraEntryPoint[];
24+
postTransform?: IndexHtmlTransform;
2325
}
24-
export declare function writeIndexHtml({ host, outputPath, indexPath, ES5BuildFiles, ES2015BuildFiles, baseHref, deployUrl, sri, scripts, styles, }: WriteIndexHtmlOptions): Observable<void>;
26+
export declare type IndexHtmlTransform = (content: string) => Promise<string>;
27+
export declare function writeIndexHtml({ host, outputPath, indexPath, files, noModuleFiles, moduleFiles, baseHref, deployUrl, sri, scripts, styles, postTransform, }: WriteIndexHtmlOptions): Observable<void>;

src/angular-cli-files/utilities/index-file/write-index-html.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
*/
99
Object.defineProperty(exports, "__esModule", { value: true });
1010
const core_1 = require("@angular-devkit/core");
11+
const rxjs_1 = require("rxjs");
1112
const operators_1 = require("rxjs/operators");
1213
const package_chunk_sort_1 = require("../package-chunk-sort");
1314
const strip_bom_1 = require("../strip-bom");
1415
const augment_index_html_1 = require("./augment-index-html");
15-
function writeIndexHtml({ host, outputPath, indexPath, ES5BuildFiles, ES2015BuildFiles, baseHref, deployUrl, sri = false, scripts = [], styles = [], }) {
16+
function writeIndexHtml({ host, outputPath, indexPath, files = [], noModuleFiles = [], moduleFiles = [], baseHref, deployUrl, sri = false, scripts = [], styles = [], postTransform, }) {
1617
return host.read(indexPath)
1718
.pipe(operators_1.map(content => strip_bom_1.stripBom(core_1.virtualFs.fileBufferToString(content))), operators_1.switchMap(content => augment_index_html_1.augmentIndexHtml({
1819
input: core_1.getSystemPath(outputPath),
@@ -21,21 +22,24 @@ function writeIndexHtml({ host, outputPath, indexPath, ES5BuildFiles, ES2015Buil
2122
deployUrl,
2223
sri,
2324
entrypoints: package_chunk_sort_1.generateEntryPoints({ scripts, styles }),
24-
files: filterAndMapBuildFiles(ES5BuildFiles, '.css'),
25-
noModuleFiles: filterAndMapBuildFiles(ES5BuildFiles, '.js'),
26-
moduleFiles: filterAndMapBuildFiles(ES2015BuildFiles, '.js'),
25+
files: filterAndMapBuildFiles(files, ['.js', '.css']),
26+
noModuleFiles: filterAndMapBuildFiles(noModuleFiles, '.js'),
27+
moduleFiles: filterAndMapBuildFiles(moduleFiles, '.js'),
2728
loadOutputFile: async (filePath) => {
2829
return host.read(core_1.join(outputPath, filePath))
2930
.pipe(operators_1.map(data => core_1.virtualFs.fileBufferToString(data)))
3031
.toPromise();
3132
},
32-
})), operators_1.map(content => core_1.virtualFs.stringToFileBuffer(content.source())), operators_1.switchMap(content => host.write(core_1.join(outputPath, core_1.basename(indexPath)), content)));
33+
})), operators_1.switchMap(content => postTransform ? postTransform(content) : rxjs_1.of(content)), operators_1.map(content => core_1.virtualFs.stringToFileBuffer(content)), operators_1.switchMap(content => host.write(core_1.join(outputPath, core_1.basename(indexPath)), content)));
3334
}
3435
exports.writeIndexHtml = writeIndexHtml;
3536
function filterAndMapBuildFiles(files, extensionFilter) {
3637
const filteredFiles = [];
38+
const validExtensions = Array.isArray(extensionFilter)
39+
? extensionFilter
40+
: [extensionFilter];
3741
for (const { file, name, extension, initial } of files) {
38-
if (name && initial && extension === extensionFilter) {
42+
if (name && initial && validExtensions.includes(extension)) {
3943
filteredFiles.push({ file, extension, name });
4044
}
4145
}

src/browser/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { WebpackLoggingCallback } from '@angular-devkit/build-webpack';
1111
import { experimental, json, logging, virtualFs } from '@angular-devkit/core';
1212
import * as fs from 'fs';
1313
import * as webpack from 'webpack';
14+
import { IndexHtmlTransform } from '../angular-cli-files/utilities/index-file/write-index-html';
1415
import { ExecutionTransformer } from '../transforms';
1516
import { Schema as BrowserBuilderSchema } from './schema';
1617
export declare type BrowserBuilderOutput = json.JsonObject & BuilderOutput & {
@@ -24,6 +25,7 @@ export declare function buildBrowserWebpackConfigFromContext(options: BrowserBui
2425
export declare function buildWebpackBrowser(options: BrowserBuilderSchema, context: BuilderContext, transforms?: {
2526
webpackConfiguration?: ExecutionTransformer<webpack.Configuration>;
2627
logging?: WebpackLoggingCallback;
28+
indexHtml?: IndexHtmlTransform;
2729
}): import("rxjs").Observable<BrowserBuilderOutput>;
2830
declare const _default: import("@angular-devkit/architect/src/internal").Builder<json.JsonObject & BrowserBuilderSchema>;
2931
export default _default;

src/browser/index.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,34 @@ function buildWebpackBrowser(options, context, transforms = {}) {
130130
}
131131
}, { success: true }, 1), operators_1.bufferCount(configs.length), operators_1.switchMap(buildEvents => {
132132
const success = buildEvents.every(r => r.success);
133-
if (success && buildEvents.length === 2 && options.index) {
134-
const { emittedFiles: ES5BuildFiles = [] } = buildEvents[0];
135-
const { emittedFiles: ES2015BuildFiles = [] } = buildEvents[1];
133+
if (success && options.index) {
134+
let noModuleFiles;
135+
let moduleFiles;
136+
let files;
137+
const [ES5Result, ES2015Result] = buildEvents;
138+
if (buildEvents.length === 2) {
139+
noModuleFiles = ES5Result.emittedFiles;
140+
moduleFiles = ES2015Result.emittedFiles || [];
141+
files = moduleFiles.filter(x => x.extension === '.css');
142+
}
143+
else {
144+
const { emittedFiles = [] } = ES5Result;
145+
files = emittedFiles.filter(x => x.name !== 'polyfills-es5');
146+
noModuleFiles = emittedFiles.filter(x => x.name === 'polyfills-es5');
147+
}
136148
return write_index_html_1.writeIndexHtml({
137149
host,
138150
outputPath: core_1.join(root, options.outputPath),
139151
indexPath: core_1.join(root, options.index),
140-
ES5BuildFiles,
141-
ES2015BuildFiles,
152+
files,
153+
noModuleFiles,
154+
moduleFiles,
142155
baseHref: options.baseHref,
143156
deployUrl: options.deployUrl,
144157
sri: options.subresourceIntegrity,
145158
scripts: options.scripts,
146159
styles: options.styles,
160+
postTransform: transforms.indexHtml,
147161
})
148162
.pipe(operators_1.map(() => ({ success: true })), operators_1.catchError(() => rxjs_1.of({ success: false })));
149163
}

0 commit comments

Comments
 (0)