Skip to content

Commit 6b39c9c

Browse files
petebacondarwinjasonaden
authored andcommittedApr 2, 2019
fix(compiler-cli): ngcc - cope with processing entry-points multiple times (#29657)
With the new API, where you can choose to only process the first matching format, it is possible to process an entry-point multiple times, if you pass in a different format each time. Previously, ngcc would always try to process the typings files for the entry-point along with processing the first format of the current execution of ngcc. But this meant that it would be trying to process the typings a second time. Now we only process the typings if they have not already been processed as part of processing another format in another even if it was in a different execution of ngcc. PR Close #29657
1 parent c579949 commit 6b39c9c

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed
 

‎packages/compiler-cli/ngcc/src/main.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ export function mainNgcc({basePath, targetEntryPointPath,
110110
const entryPointPackageJson = entryPoint.packageJson;
111111
const entryPointPackageJsonPath = AbsoluteFsPath.from(resolve(entryPoint.path, 'package.json'));
112112

113+
const hasProcessedDts = hasBeenProcessed(entryPointPackageJson, 'typings');
114+
113115
for (let i = 0; i < propertiesToConsider.length; i++) {
114116
const property = propertiesToConsider[i] as EntryPointJsonProperty;
115117
const formatPath = entryPointPackageJson[property];
@@ -124,12 +126,14 @@ export function mainNgcc({basePath, targetEntryPointPath,
124126
continue;
125127
}
126128

129+
const isFirstFormat = compiledFormats.size === 0;
130+
const processDts = !hasProcessedDts && isFirstFormat;
131+
127132
// We don't break if this if statement fails because we still want to mark
128133
// the property as processed even if its underlying format has been built already.
129-
if (!compiledFormats.has(formatPath) && (compileAllFormats || compiledFormats.size === 0)) {
134+
if (!compiledFormats.has(formatPath) && (compileAllFormats || isFirstFormat)) {
130135
const bundle = makeEntryPointBundle(
131-
entryPoint.path, formatPath, entryPoint.typings, isCore, property, format,
132-
compiledFormats.size === 0);
136+
entryPoint.path, formatPath, entryPoint.typings, isCore, property, format, processDts);
133137
if (bundle) {
134138
logger.info(`Compiling ${entryPoint.name} : ${property} as ${format}`);
135139
const transformedFiles = transformer.transform(bundle);
@@ -147,6 +151,9 @@ export function mainNgcc({basePath, targetEntryPointPath,
147151
// previous property.
148152
if (compiledFormats.has(formatPath)) {
149153
markAsProcessed(entryPointPackageJson, entryPointPackageJsonPath, property);
154+
if (processDts) {
155+
markAsProcessed(entryPointPackageJson, entryPointPackageJsonPath, 'typings');
156+
}
150157
}
151158
}
152159

‎packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts

+32
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe('ngcc main()', () => {
4141
esm2015: '0.0.0-PLACEHOLDER',
4242
fesm5: '0.0.0-PLACEHOLDER',
4343
fesm2015: '0.0.0-PLACEHOLDER',
44+
typings: '0.0.0-PLACEHOLDER',
4445
});
4546
// * `common` is a dependency of `common/http`, so is compiled.
4647
expect(loadPackage('@angular/common').__processed_by_ivy_ngcc__).toEqual({
@@ -50,6 +51,7 @@ describe('ngcc main()', () => {
5051
esm2015: '0.0.0-PLACEHOLDER',
5152
fesm5: '0.0.0-PLACEHOLDER',
5253
fesm2015: '0.0.0-PLACEHOLDER',
54+
typings: '0.0.0-PLACEHOLDER',
5355
});
5456
// * `core` is a dependency of `common`, so is compiled.
5557
expect(loadPackage('@angular/core').__processed_by_ivy_ngcc__).toEqual({
@@ -59,6 +61,7 @@ describe('ngcc main()', () => {
5961
esm2015: '0.0.0-PLACEHOLDER',
6062
fesm5: '0.0.0-PLACEHOLDER',
6163
fesm2015: '0.0.0-PLACEHOLDER',
64+
typings: '0.0.0-PLACEHOLDER',
6265
});
6366

6467
// * `common/testing` is not a dependency of `common/http` so is not compiled.
@@ -94,21 +97,25 @@ describe('ngcc main()', () => {
9497
esm5: '0.0.0-PLACEHOLDER',
9598
module: '0.0.0-PLACEHOLDER',
9699
fesm5: '0.0.0-PLACEHOLDER',
100+
typings: '0.0.0-PLACEHOLDER',
97101
});
98102
expect(loadPackage('@angular/common').__processed_by_ivy_ngcc__).toEqual({
99103
esm5: '0.0.0-PLACEHOLDER',
100104
module: '0.0.0-PLACEHOLDER',
101105
fesm5: '0.0.0-PLACEHOLDER',
106+
typings: '0.0.0-PLACEHOLDER',
102107
});
103108
expect(loadPackage('@angular/common/testing').__processed_by_ivy_ngcc__).toEqual({
104109
esm5: '0.0.0-PLACEHOLDER',
105110
module: '0.0.0-PLACEHOLDER',
106111
fesm5: '0.0.0-PLACEHOLDER',
112+
typings: '0.0.0-PLACEHOLDER',
107113
});
108114
expect(loadPackage('@angular/common/http').__processed_by_ivy_ngcc__).toEqual({
109115
esm5: '0.0.0-PLACEHOLDER',
110116
module: '0.0.0-PLACEHOLDER',
111117
fesm5: '0.0.0-PLACEHOLDER',
118+
typings: '0.0.0-PLACEHOLDER',
112119
});
113120
});
114121
});
@@ -127,20 +134,45 @@ describe('ngcc main()', () => {
127134
expect(loadPackage('@angular/core').__processed_by_ivy_ngcc__).toEqual({
128135
fesm5: '0.0.0-PLACEHOLDER',
129136
module: '0.0.0-PLACEHOLDER',
137+
typings: '0.0.0-PLACEHOLDER',
130138
});
131139
expect(loadPackage('@angular/common').__processed_by_ivy_ngcc__).toEqual({
132140
fesm5: '0.0.0-PLACEHOLDER',
133141
module: '0.0.0-PLACEHOLDER',
142+
typings: '0.0.0-PLACEHOLDER',
134143
});
135144
expect(loadPackage('@angular/common/testing').__processed_by_ivy_ngcc__).toEqual({
136145
fesm5: '0.0.0-PLACEHOLDER',
137146
module: '0.0.0-PLACEHOLDER',
147+
typings: '0.0.0-PLACEHOLDER',
138148
});
139149
expect(loadPackage('@angular/common/http').__processed_by_ivy_ngcc__).toEqual({
140150
fesm5: '0.0.0-PLACEHOLDER',
141151
module: '0.0.0-PLACEHOLDER',
152+
typings: '0.0.0-PLACEHOLDER',
142153
});
143154
});
155+
156+
it('should cope with compiling the same entry-point multiple times with different formats',
157+
() => {
158+
mainNgcc({
159+
basePath: '/node_modules',
160+
propertiesToConsider: ['module'],
161+
compileAllFormats: false
162+
});
163+
expect(loadPackage('@angular/core').__processed_by_ivy_ngcc__).toEqual({
164+
module: '0.0.0-PLACEHOLDER',
165+
typings: '0.0.0-PLACEHOLDER',
166+
});
167+
// If ngcc tries to write out the typings files again, this will throw an exception.
168+
mainNgcc(
169+
{basePath: '/node_modules', propertiesToConsider: ['esm5'], compileAllFormats: false});
170+
expect(loadPackage('@angular/core').__processed_by_ivy_ngcc__).toEqual({
171+
esm5: '0.0.0-PLACEHOLDER',
172+
module: '0.0.0-PLACEHOLDER',
173+
typings: '0.0.0-PLACEHOLDER',
174+
});
175+
});
144176
});
145177

146178
describe('with createNewEntryPointFormats', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.