-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve source maps API #49
Comments
Yeap, I think about it too. You options changes is great and I agree with it. We can use it in 0.4 version and remove deprecated syntax in 0.5. Also I think we should show deprecated warning on old options usage. |
I think So default value of |
Is |
BTW, if we plan to change map API. Maybe we should add |
BTW. I have also 2 features for 0.4 release:
|
Definitely.
The “magic” should be on by default, yes. The question was whether it is ever useful to be able to turn it off.
That’s what I meant :)
Agreed.
Could you expand a bit on this? I don’t really follow here ...
Do you mean that you have started working on them, or just plan them?
I didn’t know you could have several CSS inputs! Please tell me more about this. We need to consider it for the API changes. How can you have several CSS inputs? Are they concatenated into one AST, and that AST is passed to the processing functions?
That would be the |
Now
Only planed :). |
About several inputs. It is very important, because we need to support CSS concatination and some other magic stuff. Right now users can get several inputs: root1 = postcss.parse(css1, from: 'a.css')
root2 = postcss.parse(css2, from: 'b.css')
root1.rules = root1.rules.concat( root2.rules )
result = root1.toResult(to: 'app.css', map: true) But it will disable source map autodetection, becase there was only one |
Providing a
I’m not sure how wise it is to expose another tool’s API, though. If we don’t provide it, I’d vote for returning the map as an object, not as a string.
Correct. I need to think about this. |
I agree, that we should return |
I started a multiinputs branch. OK, or you already start it? |
Done. I finished maps support with multiple inputs and pushed new source map code to v1.0 branch. Maybe tomorrow I try to add object in |
Sorry, I’ve got side-tracked by lots of other projects, and I haven’t had any time to look at this :( |
@lydell don’t worry, I finish your options project :) |
@lydell why we need |
Why you want this? For example, a some Grunt plugins generates maps file and PostCSS’s Grunt plugin developer don’t want to understand source maps and set correct options. |
BTW, today I also finish |
I guess we don’t need |
I thought that it wasn’t used in reality, because all tools I’ve seen put a sourceMappingURL comment in the output. And I also thought about that CoffeeScript names the source maps like this: foo.coffee → foo.js + foo.map. But if you know of tools that justify the feature, then keep it :) |
Hm. About autodetect maybe you are right. There is no tool, that miss annotation, |
@lydell maybe we should generate |
I refactored current options: 3b7d731 I will add new options on this week and we can close issue. |
Autodetection without annotation comment in CSS was disabled 9a6c042 |
I decide to not implement |
Yeah, if there is no use case I see no point in adding it. Just for the record, it wouldn’t be difficult to implement at all: Just do |
Don’t you want to support writing the source map to a different location than the same directory as the output CSS? |
@lydell and |
@lydell I already added |
Actually, I’m not so sure anymore … let’s just leave it :)
Aha, I missed that. But it seems like that is unfinished? Shouldn’t the intended map path be used in |
@lydell yeap, you right, I forget about |
What is the purpose of being able to pass the previous source map using I’d say it is to be able to do something like this: file = "./source/style.ext"
{css, map} = preprocessor.compile(fs.readFileSync(file), source: file)
result = postcss(foo).process(css, from: file, map: {prev: map}) In other words, to be able to pass an in-memory map—a map that has never been written to disk. I do not think the purpose of the Why is this important?
Then in I wanted to make a PR, but three things stopped me:
So why did I write all of this? Well, that’s because postcss’ previous source map support is incomplete in one place related to automatically finding the previous source map written to disk. I tried to fix it myself, but got stuck, because:
|
@lydell you as usual make great analyis :). You are totally right about prev map docs. Fixed: 70b26d6 Now we have same logic as you suggest:
|
But I can’t find the code …? |
@lydell maybe I am wrong and you are speaking not about |
Consider the following case:
source.css.map contains source.css contains We run this: file = "source/source.css"
result = postcss(foo).process(fs.readFileSync(file).toString(), from: file, to: "build/build.css", map: true)
map = result.map.toJSON()
|
So problem is only we didn’t use |
The problem is the tests. Should the tests for this go into test/map.coffee? How do I build that directory structure? I see that you’re using |
@lydell |
How do I create files and directories into it? |
Just |
But, maybe you didn’t need to write anything. Just set |
And The whole point here is to not use |
@lydell better use But, you don’t need to test |
The point is that, yes, you already test |
OK, you are right. You can look at |
I have some ideas for the source maps API that will:
I propose:
options.map
:false
. (Like now.)false
→ don’t generate source map. (Like now.)true
→ equivalent to{}
.map: sassMap
. But allow it until it is removed.map.annotation
:'preserve'
.'preserve'
→ Use same annotation type as input. (LikemapAnnotation: true
now.)'none'
→ No annotation. (LikemapAnnotation: false
now.)'inline'
→ Inline the source map into the annotation. (LikeinlineMap: true
now.)'path'
→ Usemap.path
as annotation. (New feature, though kind of possible now, too, at least partly…)map.path
:options.to + '.map'
. (This is actually the current behavior, more or less: We always assume that the source map will either be saved next to the CSS, or inlined into the CSS.)options.to
.opitons.to
ifmap.annotation
is'inline'
, or ifmap.annotation
is'preserve'
and the previous annotation had the previous source map inlined.map.setSourceContents
:false
.false
→ Don’ set thesourceContents
property of the source map. (Like now.)true
→ Set thesourceContents
property to the input CSS. (New feature, as requested by Inline source text along with map? #31.)map.sourceRoot
:sourceRoot
property of the source map. (Like now.)sourceRoot
property of the source map tomap.sourceRoot
. (New feature. It is very easy to add (new mozilla.SourceMapGenerator({sourceRoot: options.map.sourceRoot})
), but YAGNI?)map.previous
:map: sassMap
, for example. However, does anyone use this? YAGNI?null
(or possiblytrue
).null
→ Simply no previous source map.false
→ Disable previous source map detection, but still generate a source map. If so:true
→ Autodetect previous source map (Like now.) YAGNI?previous.map
:options.previous
to its default value (null
or possiblytrue
; see above).map: sassMap
now.previous.path
:'.'
.options.map.path
.previous.map = {map: previous.map}
. (Likemap: sassMap
now.)map.previous
be a previous source map (nothing more) and don’t care if it is not perfect.options.mapAnnotation
. Until it is removed:false
→options.map.annotation = 'none'
(unlessoptions.map.annotation
was already set).true
→options.map.annotation = 'preserve'
(unlessoptions.map.annotation
was already set).options.inlineMap
. Until it is removed:false
→ Nothing to do.true
→options.map.annotation = 'inline'
(unlessoptions.map.annotation
was already set).options.from + '.map'
. I don’t think that case exists in reality. The user could possibly passfrom: from, map: {previous: {map: fs.readFileSync(from + '.map'), path: from + '.map'}}
instead.What do you think? I could make a PR.
The text was updated successfully, but these errors were encountered: