@@ -18,11 +18,32 @@ function createScopedNameFunc (plugin) {
18
18
}
19
19
} ;
20
20
21
+ /*
22
+
23
+ Normalize the manifest paths so that they are always relative
24
+ to the project root directory.
25
+
26
+ */
27
+ function normalizeManifestPaths ( tokensByFile , rootDir ) {
28
+ var output = { } ;
29
+ var rootDirLength = rootDir . length + 1 ;
30
+
31
+ Object . keys ( tokensByFile ) . forEach ( function ( filename ) {
32
+ var normalizedFilename = filename . substr ( rootDirLength ) ;
33
+ output [ normalizedFilename ] = tokensByFile [ filename ] ;
34
+ } ) ;
35
+
36
+ return output ;
37
+ }
38
+
21
39
var cssExt = / \. c s s $ / ;
22
40
module . exports = function ( browserify , options ) {
23
41
options = options || { } ;
24
42
25
- var rootDir = options . rootDir || options . d || '/' ;
43
+ // if no root directory is specified, assume the cwd
44
+ var rootDir = options . rootDir || options . d ;
45
+ if ( rootDir ) { rootDir = path . resolve ( rootDir ) ; }
46
+ if ( ! rootDir ) { rootDir = process . cwd ( ) ; }
26
47
27
48
var cssOutFilename = options . output || options . o ;
28
49
if ( ! cssOutFilename ) {
@@ -133,7 +154,7 @@ module.exports = function (browserify, options) {
133
154
134
155
// write the classname manifest
135
156
if ( jsonOutFilename ) {
136
- fs . writeFile ( jsonOutFilename , JSON . stringify ( tokensByFile ) , function ( err ) {
157
+ fs . writeFile ( jsonOutFilename , JSON . stringify ( normalizeManifestPaths ( tokensByFile , rootDir ) ) , function ( err ) {
137
158
if ( err ) {
138
159
browserify . emit ( 'error' , err ) ;
139
160
}
0 commit comments