Skip to content

Commit 21c4737

Browse files
committed
WIP
1 parent 74b52ae commit 21c4737

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ function generateShortName (name, filename, css) {
3131
Appends a hash of the css source.
3232
*/
3333
function generateLongName (name, filename) {
34-
var sanitisedPath = filename.replace(/\.[^\.\/\\]+$/, '')
34+
var relativePath = path.relative(rootDir, filename)
35+
var sanitisedPath = relativePath.replace(/\.[^\.\/\\]+$/, '')
3536
.replace(/[\W_]+/g, '_')
3637
.replace(/^_|_$/g, '');
3738
d('@@@@sanitiedPath', sanitisedPath, filename)
@@ -67,12 +68,13 @@ var tokensByEntrypoint = {};
6768

6869
// we need a separate loader for each entry point
6970
var bundledCss = ''
71+
var rootDir
7072

7173
module.exports = function (browserify, options) {
7274
options = options || {};
7375

7476
// if no root directory is specified, assume the cwd
75-
var rootDir = options.rootDir || options.d || browserify._options.basedir;
77+
rootDir = options.rootDir || options.d || browserify._options.basedir;
7678
if (rootDir) { rootDir = path.resolve(rootDir); }
7779
if (!rootDir) { rootDir = process.cwd(); }
7880

@@ -104,12 +106,12 @@ module.exports = function (browserify, options) {
104106

105107
postcss(modules({
106108
generateScopedName: generateLongName,
107-
getJSON: (cssFilename, css) => {
108-
d('======getJSON========', cssFilename)
109-
self.push('module.exports = ' + JSON.stringify(css))
109+
getJSON: (cssFilename, json) => {
110+
d('======getJSON========', cssFilename, json)
111+
self.push('module.exports = ' + JSON.stringify(json))
110112
},
111113
}))
112-
.process(this._data, {from: '/' + relFilename})
114+
.process(this._data, {from: relFilename})
113115
.then((result) => {
114116
d('=========result=======');
115117
d(result.css);

playground/test/test.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ test('aaa', (t) => {
5858
`)
5959
})
6060

61-
// test('aaa', (t) => {
62-
// t.is(child_process.execSync('$(npm bin)/browserify ./fixture/composes-from-others/1.js -p [ ../../ -o bundle.css ] | node').toString(),
63-
// `{ aaa: '_fixture_composes_from_others_1__aaa _fixture_composes_from_others_shared__bbb' }
64-
// `)
61+
test('aaa', (t) => {
62+
t.is(child_process.execSync('$(npm bin)/browserify ./fixture/composes-from-others/1.js -p [ ../../ -o bundle.css ] | node').toString(),
63+
`{ aaa: '_fixture_composes_from_others_1__aaa _fixture_composes_from_others_shared__bbb' }
64+
`)
6565

66-
// t.is(fs.readFileSync('./bundle.css').toString(),
67-
// `._fixture_composes_from_others_shared__bbb {
68-
// color: yellow;
69-
// }
70-
// ._fixture_composes_from_others_1__aaa {
71-
// font-size: 10em;
72-
// }
73-
// `)
74-
// })
66+
t.is(fs.readFileSync('./bundle.css').toString(),
67+
`._fixture_composes_from_others_shared__bbb {
68+
color: yellow;
69+
}
70+
._fixture_composes_from_others_1__aaa {
71+
font-size: 10em;
72+
}
73+
`)
74+
})

0 commit comments

Comments
 (0)