Skip to content

Commit 0f18e35

Browse files
clydinmgechev
authored andcommitted
fix(@angular-devkit/build-angular): add sourcemap comment for ES2015 differential loading (#15461)
Fixes #15460
1 parent 84680d0 commit 0f18e35

File tree

2 files changed

+42
-23
lines changed

2 files changed

+42
-23
lines changed

packages/angular_devkit/build_angular/src/utils/process-bundle.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,11 @@ async function mangleOriginal(options: ProcessBundleOptions): Promise<void> {
201201
throw resultOriginal.error;
202202
}
203203

204-
if (options.cachePath && options.cacheKeys && options.cacheKeys[CacheKey.OriginalCode]) {
205-
await cacache.put(
206-
options.cachePath,
207-
options.cacheKeys[CacheKey.OriginalCode],
208-
resultOriginal.code,
209-
);
210-
}
211-
212-
fs.writeFileSync(options.filename, resultOriginal.code);
213-
214204
if (resultOriginal.map) {
205+
if (!options.hiddenSourceMaps) {
206+
resultOriginal.code += `\n//# sourceMappingURL=${path.basename(options.filename)}.map`;
207+
}
208+
215209
if (options.cachePath && options.cacheKeys && options.cacheKeys[CacheKey.OriginalMap]) {
216210
await cacache.put(
217211
options.cachePath,
@@ -222,4 +216,14 @@ async function mangleOriginal(options: ProcessBundleOptions): Promise<void> {
222216

223217
fs.writeFileSync(options.filename + '.map', resultOriginal.map);
224218
}
219+
220+
if (options.cachePath && options.cacheKeys && options.cacheKeys[CacheKey.OriginalCode]) {
221+
await cacache.put(
222+
options.cachePath,
223+
options.cacheKeys[CacheKey.OriginalCode],
224+
resultOriginal.code,
225+
);
226+
}
227+
228+
fs.writeFileSync(options.filename, resultOriginal.code);
225229
}
Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
1-
import {ng} from '../../utils/process';
2-
import {expectFileToExist} from '../../utils/fs';
3-
import {expectToFail} from '../../utils/utils';
1+
import * as fs from 'fs';
2+
import { expectFileToExist } from '../../utils/fs';
3+
import { ng } from '../../utils/process';
44

5+
export default async function() {
6+
await ng('build', '--prod', '--output-hashing=none', '--source-map');
57

6-
export default function() {
7-
// TODO(architect): Delete this test. It is now in devkit/build-angular.
8+
await expectFileToExist('dist/test-project/main-es5.js.map');
89

9-
return ng('build', '--source-map')
10-
.then(() => expectFileToExist('dist/test-project/main-es5.js.map'))
10+
const files = fs.readdirSync('./dist/test-project');
1111

12-
.then(() => ng('build', '--source-map', 'false'))
13-
.then(() => expectToFail(() => expectFileToExist('dist/test-project/main-es5.js.map')))
12+
let count = 0;
13+
for (const file of files) {
14+
if (!file.endsWith('.js')) {
15+
continue;
16+
}
1417

15-
.then(() => ng('build', '--optimization', '--output-hashing=none', '--source-map', 'false'))
16-
.then(() => expectToFail(() => expectFileToExist('dist/test-project/main-es5.js.map')))
18+
++count;
1719

18-
.then(() => ng('build', '--optimization', '--output-hashing=none', '--source-map'))
19-
.then(() => expectFileToExist('dist/test-project/main-es5.js.map'));
20+
if (!files.includes(file + '.map')) {
21+
throw new Error('Sourcemap not generated for ' + file);
22+
}
23+
24+
const content = fs.readFileSync('./dist/test-project/' + file, 'utf8');
25+
const lastLineIndex = content.lastIndexOf('\n');
26+
const comment = lastLineIndex !== -1 && content.slice(lastLineIndex).trim();
27+
if (comment !== `//# sourceMappingURL=${file}.map`) {
28+
throw new Error('Sourcemap comment not generated for ' + file);
29+
}
30+
}
31+
32+
if (count < 6) {
33+
throw new Error('Javascript file count is low');
34+
}
2035
}

0 commit comments

Comments
 (0)