Skip to content

Commit 397a2a3

Browse files
authored
GCB-sass: tslint enable/disable now symmetrical when using css modules. (microsoft#15)
* This removes the broken tslint enable that's causing lint issues downstream. * Updates. * PR feedback
1 parent 8989f34 commit 397a2a3

File tree

8 files changed

+52
-38
lines changed

8 files changed

+52
-38
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ node_modules
1313
npm*.log
1414
temp
1515
package
16+
*.scss.ts

common/npm-shrinkwrap.json

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/temp_modules/npmx-test-web-library-build/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
"version": "0.0.0",
44
"private": true,
55
"dependencies": {
6+
"@microsoft/load-themed-styles": "^1.2.2",
67
"gulp": "~3.9.1"
78
},
89
"npmxDependencies": {
9-
"@microsoft/web-library-build": ">=0.5.0 < 1.0.0"
10+
"@microsoft/web-library-build": ">=0.5.0 <1.0.0"
1011
}
1112
}

gulp-core-build-sass/src/SassTask.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export class SassTask extends GulpTask<ISassTaskConfig> {
6262
const moduleSrcPattern: string[] = srcPattern.map((value: string) => value.replace('.scss', '.module.scss'));
6363

6464
if (this.taskConfig.useCSSModules) {
65+
this.logVerbose('Generating css modules.');
6566
return this._processFiles(gulp, srcPattern, completeCallback, modulePostCssPlugins);
6667
} else {
6768
moduleSrcPattern.forEach((value: string) => srcPattern.push(`!${value}`));
@@ -79,7 +80,6 @@ export class SassTask extends GulpTask<ISassTaskConfig> {
7980
postCSSPlugins: any[]
8081
/* tslint:enable:no-any */
8182
): NodeJS.ReadWriteStream {
82-
8383
/* tslint:disable:typedef */
8484
const changed = require('gulp-changed');
8585
const cleancss = require('gulp-clean-css');
@@ -123,7 +123,6 @@ export class SassTask extends GulpTask<ISassTaskConfig> {
123123

124124
if (classNames) {
125125
const classNamesLines: string[] = [
126-
this.taskConfig.preamble || '',
127126
'const styles = {'
128127
];
129128

@@ -148,35 +147,39 @@ export class SassTask extends GulpTask<ISassTaskConfig> {
148147
classNamesLines.push(
149148
'};',
150149
'',
151-
'export default styles;',
152-
this.taskConfig.postamble || '');
150+
'export default styles;'
151+
);
153152

154153
exportClassNames = classNamesLines.join(EOL);
155154
}
156155

157156
let lines: string[] = [];
157+
158+
lines.push(this.taskConfig.preamble || '');
159+
158160
if (this.taskConfig.dropCssFiles) {
159-
lines = [
161+
lines = lines.concat([
160162
`require('${path.basename(file.path, scssTsExtName)}.css');`,
161-
'',
162-
exportClassNames,
163-
''
164-
];
163+
exportClassNames
164+
]);
165165
} else if (!!content) {
166-
lines = [
167-
this.taskConfig.preamble || '',
166+
lines = lines.concat([
168167
'import { loadStyles } from \'@microsoft/load-themed-styles\';',
169168
'',
170169
exportClassNames,
171170
'',
172-
`loadStyles(${JSON.stringify(splitStyles(content))});`,
173-
this.taskConfig.postamble || '',
174-
''
175-
];
171+
`loadStyles(${JSON.stringify(splitStyles(content))});`
172+
]);
176173
}
177174

178-
return lines.join(EOL).replace(new RegExp(`(${EOL}){3,}`, 'g'), `${EOL}${EOL}`)
179-
.replace(new RegExp(`(${EOL})+$`, 'm'), EOL);
175+
lines.push(this.taskConfig.postamble || '');
176+
177+
return (
178+
lines
179+
.join(EOL)
180+
.replace(new RegExp(`(${EOL}){3,}`, 'g'), `${EOL}${EOL}`)
181+
.replace(new RegExp(`(${EOL})+$`, 'm'), EOL)
182+
);
180183
}
181184
}))
182185
.pipe(gulp.dest('src')));

test-web-library-build/gulpfile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
let build = require('@microsoft/web-library-build');
44

5+
build.sass.setConfig({ useCSSModules: true });
56
build.webpack.setConfig({ configPath: null });
67
build.karma.setConfig({ configPath: null });
8+
79
build.initialize(require('gulp'));
810

test-web-library-build/package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
"clean": "gulp clean",
99
"test": "gulp"
1010
},
11-
"directories": {
12-
"packagePath": "package"
13-
},
1411
"dependencies": {
15-
"gulp": "~3.9.1",
16-
"@microsoft/web-library-build": ">=0.5.0 <1.0.0"
12+
"@microsoft/load-themed-styles": "^1.2.2",
13+
"@microsoft/web-library-build": ">=0.5.0 <1.0.0",
14+
"gulp": "~3.9.1"
1715
}
1816
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
body {
2+
background: red;
3+
}
4+
5+
.foo {
6+
border: 1px solid red;
7+
}

test-web-library-build/src/test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import test from './test.scss';
2+
13
export function log(message: string): void {
2-
console.log(message);
4+
console.log(test.foo);
35
}
46

57
export function add(num1: number, num2: number): number {

0 commit comments

Comments
 (0)