Skip to content

Instantly share code, notes, and snippets.

@cspotcode
Last active February 5, 2016 06:51
Show Gist options
  • Save cspotcode/27b0c93885864508f273 to your computer and use it in GitHub Desktop.
Save cspotcode/27b0c93885864508f273 to your computer and use it in GitHub Desktop.
stylus-deps-bug
"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);
});
});
{
"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"
}
}
someOption = 'a'
.s-a
display: block
@require './s-main'
someOption = 'b'
.s-b
display: block
@require './s-main'
// Specify our charset
@charset "UTF-8"
@require './s-other'
.other:after
content: someOption
# 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
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' ]
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