Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular-devkit/build-angular): add sourcemap comment for ES2015 differential loading #15461

Merged
merged 1 commit into from
Aug 28, 2019
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
24 changes: 14 additions & 10 deletions packages/angular_devkit/build_angular/src/utils/process-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,11 @@ async function mangleOriginal(options: ProcessBundleOptions): Promise<void> {
throw resultOriginal.error;
}

if (options.cachePath && options.cacheKeys && options.cacheKeys[CacheKey.OriginalCode]) {
await cacache.put(
options.cachePath,
options.cacheKeys[CacheKey.OriginalCode],
resultOriginal.code,
);
}

fs.writeFileSync(options.filename, resultOriginal.code);

if (resultOriginal.map) {
if (!options.hiddenSourceMaps) {
resultOriginal.code += `\n//# sourceMappingURL=${path.basename(options.filename)}.map`;
}

if (options.cachePath && options.cacheKeys && options.cacheKeys[CacheKey.OriginalMap]) {
await cacache.put(
options.cachePath,
Expand All @@ -222,4 +216,14 @@ async function mangleOriginal(options: ProcessBundleOptions): Promise<void> {

fs.writeFileSync(options.filename + '.map', resultOriginal.map);
}

if (options.cachePath && options.cacheKeys && options.cacheKeys[CacheKey.OriginalCode]) {
await cacache.put(
options.cachePath,
options.cacheKeys[CacheKey.OriginalCode],
resultOriginal.code,
);
}

fs.writeFileSync(options.filename, resultOriginal.code);
}
41 changes: 28 additions & 13 deletions tests/legacy-cli/e2e/tests/build/sourcemap.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
import {ng} from '../../utils/process';
import {expectFileToExist} from '../../utils/fs';
import {expectToFail} from '../../utils/utils';
import * as fs from 'fs';
import { expectFileToExist } from '../../utils/fs';
import { ng } from '../../utils/process';

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

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

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

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

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

.then(() => ng('build', '--optimization', '--output-hashing=none', '--source-map'))
.then(() => expectFileToExist('dist/test-project/main-es5.js.map'));
if (!files.includes(file + '.map')) {
throw new Error('Sourcemap not generated for ' + file);
}

const content = fs.readFileSync('./dist/test-project/' + file, 'utf8');
const lastLineIndex = content.lastIndexOf('\n');
const comment = lastLineIndex !== -1 && content.slice(lastLineIndex).trim();
if (comment !== `//# sourceMappingURL=${file}.map`) {
throw new Error('Sourcemap comment not generated for ' + file);
}
}

if (count < 6) {
throw new Error('Javascript file count is low');
}
}