Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 12b58a1

Browse files
authored
build: avoid incorrect provider definition renaming (#1191)
NGC already supports lazy providers and generates definitions for these providers. Previously those definitions were called `ngInjectableDef`. With recent changes in Angular, these definition members have been renamed to `ɵprov`. This conflicts with the legacy build system that was originally designed for View Engine. The build system / package-tools rename this member to be unique. The logic for renaming private members generated by the NGC flat module bundler exists because individual secondary entry-points are re-exported in the primary entry-point, and we want to avoid symbol conflicts there. To fix this in a more reasonable way (same concept used in `@angular/bazel`), we specify a unique prefix for each entry-point by leveraging the `flatModulePrivateSymbolPrefix` option.
1 parent f8e9d75 commit 12b58a1

File tree

8 files changed

+8
-41
lines changed

8 files changed

+8
-41
lines changed

src/lib/core/tsconfig-build.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"strictMetadataEmit": true,
1010
"flatModuleOutFile": "index.js",
1111
"flatModuleId": "@angular/flex-layout/core",
12+
"flatModulePrivateSymbolPrefix": "core_private",
1213
"skipTemplateCodegen": true,
1314
"fullTemplateTypeCheck": true
1415
}

src/lib/extended/tsconfig-build.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"strictMetadataEmit": true,
1010
"flatModuleOutFile": "index.js",
1111
"flatModuleId": "@angular/flex-layout/extended",
12+
"flatModulePrivateSymbolPrefix": "extended_private",
1213
"skipTemplateCodegen": true,
1314
"fullTemplateTypeCheck": true
1415
}

src/lib/flex/tsconfig-build.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"strictMetadataEmit": true,
1010
"flatModuleOutFile": "index.js",
1111
"flatModuleId": "@angular/flex-layout/flex",
12+
"flatModulePrivateSymbolPrefix": "flex_private",
1213
"skipTemplateCodegen": true,
1314
"fullTemplateTypeCheck": true
1415
}

src/lib/grid/tsconfig-build.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"strictMetadataEmit": true,
1010
"flatModuleOutFile": "index.js",
1111
"flatModuleId": "@angular/flex-layout/grid",
12+
"flatModulePrivateSymbolPrefix": "grid_private",
1213
"skipTemplateCodegen": true,
1314
"fullTemplateTypeCheck": true
1415
}

src/lib/server/tsconfig-build.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"strictMetadataEmit": true,
1010
"flatModuleOutFile": "index.js",
1111
"flatModuleId": "@angular/flex-layout/server",
12+
"flatModulePrivateSymbolPrefix": "server_private",
1213
"skipTemplateCodegen": true,
1314
"fullTemplateTypeCheck": true
1415
}

src/lib/tsconfig-build.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"strictMetadataEmit": true,
4444
"flatModuleOutFile": "index.js",
4545
"flatModuleId": "@angular/flex-layout",
46+
"flatModulePrivateSymbolPrefix": "flex_layout_private",
4647
"skipTemplateCodegen": true,
4748
"fullTemplateTypeCheck": true
4849
}

tools/package-tools/build-package.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import {join} from 'path';
22
import {PackageBundler} from './build-bundles';
33
import {buildConfig} from './build-config';
4-
import {
5-
addImportAsToAllMetadata,
6-
compileEntryPoint,
7-
renamePrivateReExportsToBeUnique,
8-
} from './compile-entry-point';
4+
import {addImportAsToAllMetadata, compileEntryPoint} from './compile-entry-point';
95
import {getSecondaryEntryPointsForPackage} from './secondary-entry-points';
106

117
const {packagesDir, outputDir} = buildConfig;
@@ -97,8 +93,7 @@ export class BuildPackage {
9793
/** Compiles TS into both ES2015 and ES5, then updates exports. */
9894
private async _compileBothTargets(p = '') {
9995
return compileEntryPoint(this, buildTsconfigName, p)
100-
.then(() => compileEntryPoint(this, buildTsconfigName, p, this.esm5OutputDir))
101-
.then(() => renamePrivateReExportsToBeUnique(this, p));
96+
.then(() => compileEntryPoint(this, buildTsconfigName, p, this.esm5OutputDir));
10297
}
10398

10499
/** Stores the secondary entry-points for this package if they haven't been computed already. */

tools/package-tools/compile-entry-point.ts

-34
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import {red} from 'chalk';
55
import {BuildPackage} from './build-package';
66
import {ngcCompile} from './ngc-compile';
77

8-
/** Incrementing ID counter. */
9-
let nextId = 0;
10-
118
/** Compiles the TypeScript sources of a primary or secondary entry point. */
129
export async function compileEntryPoint(buildPackage: BuildPackage, tsconfigName: string,
1310
secondaryEntryPoint = '', es5OutputPath?: string) {
@@ -39,24 +36,6 @@ export function addImportAsToAllMetadata(buildPackage: BuildPackage) {
3936
}
4037
}
4138

42-
/** Renames `ɵa`-style re-exports generated by Angular to be unique across compilation units. */
43-
export function renamePrivateReExportsToBeUnique(buildPackage: BuildPackage,
44-
secondaryEntryPoint = '') {
45-
// When we compiled the typescript sources with ngc, we do entry-point individually.
46-
// If the root-level module re-exports multiple of these entry-points, the private-export
47-
// identifiers (e.g., `ɵa`) generated by ngc will collide. We work around this by suffixing
48-
// each of these identifiers with an ID specific to this entry point. We make this
49-
// replacement in the js, d.ts, and metadata output.
50-
if (buildPackage.exportsSecondaryEntryPointsAtRoot && secondaryEntryPoint) {
51-
const entryPointId = nextId++;
52-
const outputPath = join(buildPackage.outputDir, secondaryEntryPoint);
53-
const esm5OutputPath = join(buildPackage.esm5OutputDir, secondaryEntryPoint);
54-
55-
addIdToGlob(outputPath, entryPointId);
56-
addIdToGlob(esm5OutputPath, entryPointId);
57-
}
58-
}
59-
6039
/** Adds `importAs` property to generated all metadata.json files for an entry-point. */
6140
function addImportAs(packageName: string, outputPath: string, secondaryEntryPoint: string): void {
6241
const path = join(outputPath, secondaryEntryPoint);
@@ -66,16 +45,3 @@ function addImportAs(packageName: string, outputPath: string, secondaryEntryPoin
6645
writeFileSync(metadataPath, JSON.stringify(metadata), 'utf-8');
6746
});
6847
}
69-
70-
/** Updates exports in designated folder with identifier specified. */
71-
function addIdToGlob(outputPath: string, entryPointId: number): void {
72-
glob(join(outputPath, '**/*.+(js|d.ts|metadata.json)')).forEach(filePath => {
73-
let fileContent = readFileSync(filePath, 'utf-8');
74-
// We check for double ɵ to avoid mangling symbols like `ɵɵdefineInjectable`.
75-
fileContent = fileContent.replace(/ɵ(ɵ)?[a-z]+/g,
76-
(match, isDoubleTheta) => {
77-
return isDoubleTheta ? match : match + entryPointId;
78-
});
79-
writeFileSync(filePath, fileContent, 'utf-8');
80-
});
81-
}

0 commit comments

Comments
 (0)