Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions packages/angular_devkit/build_angular/src/app-shell/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,12 @@ async function _renderUniversal(

const {
AppServerModule,
AppServerModuleNgFactory,
renderModule,
renderModuleFactory,
} = await import(serverBundlePath);

let renderModuleFn: (module: unknown, options: {}) => Promise<string>;
let AppServerModuleDef: unknown;
const renderModuleFn: ((module: unknown, options: {}) => Promise<string>) | undefined = renderModule;

if (renderModuleFactory && AppServerModuleNgFactory) {
renderModuleFn = renderModuleFactory;
AppServerModuleDef = AppServerModuleNgFactory;
} else if (renderModule && AppServerModule) {
renderModuleFn = renderModule;
AppServerModuleDef = AppServerModule;
} else {
if (!(renderModuleFn && AppServerModule)) {
throw new Error(`renderModule method and/or AppServerModule were not exported from: ${serverBundlePath}.`);
}

Expand All @@ -96,7 +87,7 @@ async function _renderUniversal(
url: options.route,
};

let html = await renderModuleFn(AppServerModuleDef, renderOpts);
let html = await renderModuleFn(AppServerModule, renderOpts);
// Overwrite the client index file.
const outputIndexPath = options.outputIndexPath
? path.join(root, options.outputIndexPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
const CircularDependencyPlugin = require('circular-dependency-plugin');
extraPlugins.push(
new CircularDependencyPlugin({
exclude: /([\\\/]node_modules[\\\/])|(ngfactory\.js$)/,
exclude: /[\\\/]node_modules[\\\/]/,
}),
);
}
Expand Down Expand Up @@ -332,8 +332,8 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
extraRules.push({
test: /\.m?js$/,
exclude: vendorSourceMap
? /(ngfactory|ngstyle)\.js$/
: [/[\\\/]node_modules[\\\/]/, /(ngfactory|ngstyle)\.js$/],
? undefined
: /[\\\/]node_modules[\\\/]/,
enforce: 'pre',
loader: require.resolve('source-map-loader'),
});
Expand Down Expand Up @@ -496,7 +496,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
},
{
test: /\.[cm]?js$|\.tsx?$/,
exclude: [/[\/\\](?:core-js|\@babel|tslib|web-animations-js)[\/\\]/, /(ngfactory|ngstyle)\.js$/],
exclude: [/[\/\\](?:core-js|\@babel|tslib|web-animations-js)[\/\\]/],
use: [
{
loader: require.resolve('../../babel/webpack-loader'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ export class NgBuildAnalyticsPlugin {
this._stats.numberOfNgOnInit += countOccurrences(module._source.source(), 'ngOnInit', true);

// Count the number of `Component({` strings (case sensitive), which happens in __decorate().
// This does not include View Engine AOT compilation, we use the ngfactory for it.
this._stats.numberOfComponents += countOccurrences(module._source.source(), 'Component({');
// For Ivy we just count ɵcmp.
this._stats.numberOfComponents += countOccurrences(module._source.source(), '.ɵcmp', true);
Expand All @@ -166,19 +165,6 @@ export class NgBuildAnalyticsPlugin {
}
}

protected _checkNgFactoryNormalModule(module: NormalModule) {
if (module._source) {
// PLEASE REMEMBER:
// We're dealing with ES5 _or_ ES2015 JavaScript at this point (we don't know for sure).

// Count the number of `.ɵccf(` strings (case sensitive). They're calls to components
// factories.
this._stats.numberOfComponents += countOccurrences(module._source.source(), '.ɵccf(');
// for ascii_only true
this._stats.numberOfComponents += countOccurrences(module._source.source(), '.\u0275ccf(');
}
}

protected _collectErrors(stats: Stats) {
if (stats.hasErrors()) {
for (const errObject of stats.compilation.errors) {
Expand Down Expand Up @@ -267,8 +253,6 @@ export class NgBuildAnalyticsPlugin {
// Check that it's a source file from the project.
if (module.resource.endsWith('.ts')) {
this._checkTsNormalModule(module);
} else if (module.resource.endsWith('.ngfactory.js')) {
this._checkNgFactoryNormalModule(module);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ const knownSideEffectFreeAngularModules = [
/[\\/]node_modules[\\/]rxjs[\\/]/,
];

// Factories created by AOT are known to have no side effects.
const ngFactories = [
'.ngfactory.js',
'.ngstyle.js',
];

// Known locations for the source files of @angular/core.
const coreFilesRegex = /[\\/]node_modules[\\/]@angular[\\/]core[\\/][f]?esm2015[\\/]/;

Expand All @@ -59,8 +53,7 @@ function isKnownSideEffectFree(filePath: string) {
return false;
}

return ngFactories.some((s) => filePath.endsWith(s)) ||
knownSideEffectFreeAngularModules.some((re) => re.test(filePath));
return knownSideEffectFreeAngularModules.some((re) => re.test(filePath));
}

export interface BuildOptimizerOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ describe('build-optimizer', () => {
'/node_modules/@angular/core/esm2015/core.js',
'\\node_modules\\@angular\\core\\fesm2015\\core.js',
'\\node_modules\\@angular\\core\\esm2015\\core.js',
'/project/file.ngfactory.js',
'/project/file.ngstyle.js',
];

inputPaths.forEach((inputFilePath) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ interface BuildOptimizerLoaderOptions {

export const buildOptimizerLoaderPath = __filename;

const alwaysProcess = (path: string) =>
// Always process TS files.
path.endsWith('.ts') ||
path.endsWith('.tsx') ||
// Always process factory files.
path.endsWith('.ngfactory.js') ||
path.endsWith('.ngstyle.js');
const alwaysProcess = (path: string) => path.endsWith('.ts') || path.endsWith('.tsx');

export default function buildOptimizerLoader(
// Webpack 5 does not provide a LoaderContext type
Expand Down