Skip to content

Commit 39b37d8

Browse files
committed
make the manifest a bit nicer by normalizing filenames to the root directory
1 parent af805b5 commit 39b37d8

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

index.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,32 @@ function createScopedNameFunc (plugin) {
1818
}
1919
};
2020

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+
2139
var cssExt = /\.css$/;
2240
module.exports = function (browserify, options) {
2341
options = options || {};
2442

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(); }
2647

2748
var cssOutFilename = options.output || options.o;
2849
if (!cssOutFilename) {
@@ -136,7 +157,7 @@ module.exports = function (browserify, options) {
136157

137158
// write the classname manifest
138159
if (jsonOutFilename) {
139-
fs.writeFile(jsonOutFilename, JSON.stringify(tokensByFile), function (err) {
160+
fs.writeFile(jsonOutFilename, JSON.stringify(normalizeManifestPaths(tokensByFile, rootDir)), function (err) {
140161
if (err) {
141162
browserify.emit('error', err);
142163
}

0 commit comments

Comments
 (0)