Last active
February 5, 2016 06:51
-
-
Save cspotcode/27b0c93885864508f273 to your computer and use it in GitHub Desktop.
stylus-deps-bug
This file contains hidden or 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
"use strict"; | |
const stylus = require('stylus'); | |
const path = require('path'); | |
const fs = require('fs'); | |
if(['before', 'after'].indexOf(process.argv[2]) === -1) throw new Error('bad argument'); | |
const getDepsBeforeRender = process.argv[2] === 'before'; | |
const files = [ | |
's-a.styl', | |
's-b.styl' | |
]; | |
files.forEach((file) => { | |
// Render the given stylus file | |
const absPath = path.join(__dirname, file); | |
const code = fs.readFileSync(absPath, 'utf8'); | |
const styl = stylus(code); | |
styl.set('filename', absPath); | |
styl.set('sourcemap', { | |
comment: false | |
}); | |
let deps; | |
// GET DEPENDENCIES BEFORE RENDERING | |
if(getDepsBeforeRender) deps = styl.deps(); | |
styl.render((err, css) => { | |
const sourcemap = styl.sourcemap; | |
// GET DEPENDENCIES AFTER RENDERING | |
if(!getDepsBeforeRender) deps = styl.deps(); | |
console.log(`\n\nRendered:`); | |
console.log(` ${absPath}`); | |
console.log(`Sourcemap "sources":`); | |
console.dir(sourcemap.sources); | |
console.log(`Dependencies:`); | |
console.dir(deps); | |
}); | |
}); |
This file contains hidden or 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
{ | |
"name": "stylus-bug", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"stylus": "^0.53.0" | |
} | |
} |
This file contains hidden or 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
someOption = 'a' | |
.s-a | |
display: block | |
@require './s-main' |
This file contains hidden or 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
someOption = 'b' | |
.s-b | |
display: block | |
@require './s-main' |
This file contains hidden or 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
// Specify our charset | |
@charset "UTF-8" | |
@require './s-other' |
This file contains hidden or 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
.other:after | |
content: someOption |
This file contains hidden or 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
# Compare the outputs of these two invocations. | |
# This one generates an incorrect sourcemap | |
node index.js before > z-deps-before.txt | |
# This one generates a correct sourcemap | |
node index.js after > z-deps-after.txt |
This file contains hidden or 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
Rendered: | |
/Users/abradley/Desktop/stylus-bug/s-a.styl | |
Sourcemap "sources": | |
[ 's-a.styl', 's-main.styl', 's-other.styl' ] | |
Dependencies: | |
[ '/Users/abradley/Desktop/stylus-bug/s-main.styl', | |
'/Users/abradley/Desktop/stylus-bug/s-other.styl' ] | |
Rendered: | |
/Users/abradley/Desktop/stylus-bug/s-b.styl | |
Sourcemap "sources": | |
[ 's-b.styl', 's-main.styl', 's-other.styl' ] | |
Dependencies: | |
[ '/Users/abradley/Desktop/stylus-bug/s-main.styl', | |
'/Users/abradley/Desktop/stylus-bug/s-other.styl' ] |
This file contains hidden or 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
Rendered: | |
/Users/abradley/Desktop/stylus-bug/s-a.styl | |
Sourcemap "sources": | |
[ 's-a.styl' ] | |
Dependencies: | |
[ '/Users/abradley/Desktop/stylus-bug/s-main.styl', | |
'/Users/abradley/Desktop/stylus-bug/s-other.styl' ] | |
Rendered: | |
/Users/abradley/Desktop/stylus-bug/s-b.styl | |
Sourcemap "sources": | |
[ 's-b.styl', 's-a.styl' ] | |
Dependencies: | |
[ '/Users/abradley/Desktop/stylus-bug/s-main.styl', | |
'/Users/abradley/Desktop/stylus-bug/s-other.styl' ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment