Skip to content

Commit 965bf18

Browse files
devversionmmalerba
authored andcommitted
build: no sourcemaps in inline styles (#4885)
* In components inline styles there shouldn't be any Sourcemap reference. This adds bloat and also doesn't do anything right now. * No longer builds sourcemaps for all compiled SCSS. The sourcemaps don't work for development either (styles are inlined too) * Prebuilt themes no longer contain source-maps.
1 parent 1ca7632 commit 965bf18

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
"gulp-markdown": "^1.2.0",
8282
"gulp-rename": "^1.2.2",
8383
"gulp-sass": "^3.1.0",
84-
"gulp-sourcemaps": "^2.6.0",
8584
"gulp-transform": "^2.0.0",
8685
"hammerjs": "^2.0.8",
8786
"highlight.js": "^9.11.0",

tools/gulp/gulpfile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ import './tasks/payload';
2020
import './tasks/coverage';
2121
import './tasks/material-release';
2222
import './tasks/universal';
23+
import './tasks/validate-release';

tools/gulp/tasks/publish.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ task(':publish', async () => {
9898
task('publish', sequenceTask(
9999
':publish:whoami',
100100
':publish:build-releases',
101+
'validate-release:check-bundles',
101102
':publish',
102103
':publish:logout',
103104
));
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {task} from 'gulp';
2+
import {DIST_RELEASES, RELEASE_PACKAGES} from '../build-config';
3+
import {readFileSync} from 'fs';
4+
import {join} from 'path';
5+
import {green, red} from 'chalk';
6+
import {sequenceTask} from '../util/task_helpers';
7+
8+
/** RegExp that matches Angular component inline styles that contain a sourcemap reference. */
9+
const inlineStylesSourcemapRegex = /styles: ?\[(?:"|').*sourceMappingURL=.*(?:"|')/;
10+
11+
task('validate-release', sequenceTask(':publish:build-releases', 'validate-release:check-bundles'));
12+
13+
/** Task that checks the release bundles for any common mistakes before releasing to the public. */
14+
task('validate-release:check-bundles', () => {
15+
const bundleFailures = RELEASE_PACKAGES
16+
.map(packageName => join(DIST_RELEASES, packageName, '@angular', `${packageName}.js`))
17+
.map(packageBundle => checkPackageBundle(packageBundle))
18+
.map((failures, index) => ({failures, packageName: RELEASE_PACKAGES[index]}));
19+
20+
bundleFailures.forEach(({failures, packageName}) => {
21+
failures.forEach(failure => console.error(red(`Failure (${packageName}): ${failure}`)));
22+
});
23+
24+
if (bundleFailures.some(({failures}) => failures.length > 0)) {
25+
// Throw an error to notify Gulp about the failures that have been detected.
26+
throw 'Release bundles are not valid and ready for being released.';
27+
} else {
28+
console.log(green('Release bundles have been checked and are looking fine.'));
29+
}
30+
});
31+
32+
/** Task that checks the given release bundle for common mistakes. */
33+
function checkPackageBundle(bundlePath: string): string[] {
34+
const bundleContent = readFileSync(bundlePath, 'utf8');
35+
const failures = [];
36+
37+
if (inlineStylesSourcemapRegex.exec(bundleContent) !== null) {
38+
failures.push('Bundles contain sourcemap references in component styles.');
39+
}
40+
41+
return failures;
42+
}

tools/gulp/util/task_helpers.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {yellow} from 'chalk';
99
const gulpClean = require('gulp-clean');
1010
const gulpRunSequence = require('run-sequence');
1111
const gulpSass = require('gulp-sass');
12-
const gulpSourcemaps = require('gulp-sourcemaps');
1312
const gulpConnect = require('gulp-connect');
1413
const gulpIf = require('gulp-if');
1514
const gulpCleanCss = require('gulp-clean-css');
@@ -47,10 +46,8 @@ export function ngcBuildTask(tsConfigPath: string) {
4746
export function sassBuildTask(dest: string, root: string, minify = false) {
4847
return () => {
4948
return gulp.src(_globify(root, '**/*.scss'))
50-
.pipe(gulpSourcemaps.init({ loadMaps: true }))
5149
.pipe(gulpSass().on('error', gulpSass.logError))
5250
.pipe(gulpIf(minify, gulpCleanCss()))
53-
.pipe(gulpSourcemaps.write('.'))
5451
.pipe(gulp.dest(dest));
5552
};
5653
}

0 commit comments

Comments
 (0)