Skip to content

Commit b7738aa

Browse files
committed
make the manifest a bit nicer by normalizing filenames to the root directory
1 parent a8313d4 commit b7738aa

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) {
@@ -133,7 +154,7 @@ module.exports = function (browserify, options) {
133154

134155
// write the classname manifest
135156
if (jsonOutFilename) {
136-
fs.writeFile(jsonOutFilename, JSON.stringify(tokensByFile), function (err) {
157+
fs.writeFile(jsonOutFilename, JSON.stringify(normalizeManifestPaths(tokensByFile, rootDir)), function (err) {
137158
if (err) {
138159
browserify.emit('error', err);
139160
}

0 commit comments

Comments
 (0)