forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ianc/improved-change-error
- Loading branch information
Showing
9 changed files
with
267 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,3 +67,6 @@ temp | |
# Rush files | ||
common/temp/** | ||
package-deps.json | ||
|
||
# OS X | ||
.DS_Store |
11 changes: 11 additions & 0 deletions
11
common/changes/@microsoft/gulp-core-build-sass/jowedeki-hash-fix_2019-05-29-04-35.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@microsoft/gulp-core-build-sass", | ||
"comment": "Make css modules class hash names consistent relative to root path.", | ||
"type": "minor" | ||
} | ||
], | ||
"packageName": "@microsoft/gulp-core-build-sass", | ||
"email": "[email protected]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"isEnabled": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
'use strict'; | ||
|
||
let build = require('@microsoft/node-library-build'); | ||
build.mocha.enabled = false; | ||
|
||
build.initialize(require('gulp')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import * as path from 'path'; | ||
|
||
import * as postcss from 'postcss'; | ||
import * as cssModules from 'postcss-modules'; | ||
import * as crypto from 'crypto'; | ||
|
||
export interface IClassMap { | ||
[className: string]: string; | ||
} | ||
|
||
export interface ICSSModules { | ||
/** | ||
* Return a configured postcss plugin that will map class names to a | ||
* consistently generated scoped name. | ||
*/ | ||
getPlugin(): postcss.AcceptedPlugin; | ||
|
||
/** | ||
* Return the CSS class map that is stored after postcss-modules runs. | ||
*/ | ||
getClassMap(): IClassMap; | ||
} | ||
|
||
export default class CSSModules implements ICSSModules { | ||
private _classMap: IClassMap; | ||
private _rootPath: string; | ||
|
||
/** | ||
* CSSModules includes the source file's path relative to the project root | ||
* as part of the class name hashing algorithm. | ||
* This should be configured with the setting: | ||
* {@link @microsoft/gulp-core-build#IBuildConfig.rootPath} | ||
* That is used in {@link ./SassTask#SassTask} | ||
* But will default the process' current working dir. | ||
*/ | ||
constructor(rootPath?: string) { | ||
this._classMap = {}; | ||
if (rootPath) { | ||
this._rootPath = rootPath; | ||
} else { | ||
this._rootPath = process.cwd(); | ||
} | ||
} | ||
|
||
public getPlugin(): postcss.AcceptedPlugin { | ||
return cssModules({ | ||
getJSON: this.saveJson.bind(this), | ||
generateScopedName: this.generateScopedName.bind(this) | ||
}); | ||
} | ||
|
||
public getClassMap(): IClassMap { | ||
return this._classMap; | ||
} | ||
|
||
protected saveJson(cssFileName: string, json: IClassMap): void { | ||
this._classMap = json; | ||
} | ||
|
||
protected generateScopedName(name: string, fileName: string, css: string) | ||
: string { | ||
const fileBaseName: string = path.relative(this._rootPath, fileName); | ||
const safeFileBaseName: string = fileBaseName.replace(/\\/g, '/'); | ||
const hash: string = crypto.createHmac('sha1', safeFileBaseName) | ||
.update(css) | ||
.digest('hex') | ||
.substring(0, 8); | ||
return `${name}_${hash}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.