stylus / stylus

Expressive, robust, feature-rich CSS language built for nodejs
https://stylus-lang.com
MIT License
11.2k stars 1.12k forks source link

Allow for $PATH based stylus package loading #169

Closed jasonkuhrt closed 13 years ago

jasonkuhrt commented 13 years ago

I am not sure if this is possible in the short term but here goes.

I would like to be able to import stylus libraries from a central package location. Some code like:

@import reset

would look in the local project folder first, and if nothing is found, check the $PATH variable for it.

It would also be useful to be able to specify whole folders and not just single .styl files. So this code (I'm making up package syntax here, just for example):

@import *reset

would like for a folder called reset and import all of the .styl files within. To maintain order of loading a special reset.styl file (same name as folder, or, maybe nicer to have a file called package.styl) would be read which it in turn would do the @imports of it's same-folder files. In the event that such a main .styl file were missing then the assumption would be load order doesn't matter within the package so just load all the .styl files automatically.

In the longterm I can imagine a spm (stylus package manager) to allow for easy distribution. In the short term though, just allowing programmers to organize their own local files better would be a great start...

Thoughts?

tj commented 13 years ago

the api exposes something basically like require.paths, ex: .set('paths', ['/my/stylus/stuff']). I think we could get away with utilizing npm, npm install stylus-blueprint blah blah, no point re-inventing that wheel. personally im not a fan of globally installed libs of any kind though, I already hate that with npm

jasonkuhrt commented 13 years ago

I agree that using an existing manager like npm is better. I've wondered myself why there hasn't been a successful initiative to create a lower-level manager that can serve many communities i.e. merging gem/pip/brew/ etc. I guess politics/logistics are the main factors there. Using git well seems to be maybe the closest thing to this.

What are the cons of globally installed libs? being able to do npm update express and then have all existing projects using the new version seems pretty practical. As long as you can override lib version use per-project at the project-level when you don't want some project to access the global lib then what is there to rail against?

I'll take a deeper look into the api you've noted.

What do you think about being able to import a whole folder?

tj commented 13 years ago

i think a better approach would be to allow for say @import 'foo' to try foo/index.styl which in turn can import more stuff

tj commented 13 years ago

added what I just mentioned

jasonkuhrt commented 13 years ago

Great. I'm glad there's a way to add folders now. And it seems consistent with your approach to partials in jade =)

tj commented 13 years ago

yup :) I do this within node to, even in stylus if you look at ./lib/nodes/index.js