Skip to content
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

Add support for sourcemaps #28

Merged
merged 2 commits into from
Jan 15, 2017

Conversation

webuniverseio
Copy link
Contributor

No description provided.

@nitriques
Copy link
Collaborator

Hey @szarouski, this is great! But can you fix the build ? Right now, it's not working. See https://travis-ci.org/t32k/grunt-csso/jobs/176102824. You can run it locally before pushing, npm run test. Thanks!

@webuniverseio
Copy link
Contributor Author

Fixed. Don't know how I missed travis 😛

@webuniverseio
Copy link
Contributor Author

@nitriques does it look good now?

@nitriques nitriques changed the base branch from master to dev December 14, 2016 21:09
}).css;
});
css = result.css;
map = result.map || map;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The || map is useless IMHO

}
catch (err) {
return next(err);
}

if (proceed.length === 0) {
if (css.length === 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be better to do !css

@nitriques
Copy link
Collaborator

Yes! Sorry @szarouski I was a lot busy in the past weeks. I've made another quick review: could you check it/argue with me/fix it ? Thanks!

@webuniverseio
Copy link
Contributor Author

@nitriques Thanks for review! 🍺 Updated.

}
if (map) {
grunt.file.write(mapDest, map);
grunt.log.write('File ' + chalk.cyan(mapDest) + ' created' + (options.report ? ': ' : '.'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing ! Both writes could happen in parallel with fs.writeFile. If you do not want to do it, just tell me ;)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@szarouski ping!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nitriques Hey, I didn't forget, just didn't have time yet. I'll look into that during weekend :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok great ! Ping me if you have any questions.
If you can't do it, I'll merge as is and do it ;) Thanks again!!!

fs.readFileSync('tmp/sourcemap.css', 'utf8'),
'should create sourcemap');
test.equal(
fs.readFileSync('test/expected/sourcemap.css.map', 'utf8').replace(/(\\r)?\\n/g, eol === '\r\n' ? '\\r\\n' : '\\n'),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to write those replacements due to the way how sourcemaps are generated. Hacky but tests pass on windows, so i hope it is not a big deal.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'll try to create a better solution ;) Not a problem right now ;) Maybe force EOL to LF in tests...

@nitriques nitriques merged commit 2703de5 into t32k:dev Jan 15, 2017
@nitriques
Copy link
Collaborator

@szarouski Thanks! Check out the attached commits I've just pushed ;) And please test on Windows !

nitriques pushed a commit that referenced this pull request Jan 15, 2017
Grunt offers us a way to set globally the EOL characters so we should use it.
Simply usign the OS version is not ideal since many Windows users would like to have LF endings.

Re #28
nitriques pushed a commit that referenced this pull request Jan 15, 2017
Which is faster then writing a file

Re #28
nitriques pushed a commit that referenced this pull request Jan 15, 2017
async.map will do exactly what we need here, i.e. wait for 1 or 2 operations to complete.
Report any errors.

Re #28
nitriques pushed a commit that referenced this pull request Jan 15, 2017
* Add support for sourcemaps 7b968bc
* Add support for sourcemaps 22598a9
nitriques pushed a commit that referenced this pull request Jan 15, 2017
Grunt offers us a way to set globally the EOL characters so we should use it.
Simply usign the OS version is not ideal since many Windows users would like to have LF endings.

Re #28
nitriques pushed a commit that referenced this pull request Jan 15, 2017
Which is faster then writing a file

Re #28
nitriques pushed a commit that referenced this pull request Jan 15, 2017
async.map will do exactly what we need here, i.e. wait for 1 or 2 operations to complete.
Report any errors.

Re #28
@webuniverseio
Copy link
Contributor Author

@nitriques, checked out latest version from dev tests are failing on windows for sourcemap:

Running "nodeunit:tests" (nodeunit) task
Testing csso-test.js.FF......
>> csso - sourcemap
>> Message: should create sourcemap
>> Error: '.a{-webkit-fi1ter:blur(5px);filter:blur(5px)}.b{-webkit-padding-before:10px;pad
ding-block-start:10px}\r\n/*# sourceMappingURL=sourcemap.css.map */' == '.a{-webkit-fi1ter
:blur(5px);filter:blur(5px)}.b{-webkit-padding-before:10px;padding-block-start:10px}\n/*#
sourceMappingURL=sourcemap.css.map */'
>>   at Object.sourcemap (test\csso-test.js:20:10)
>>   at runCallback (timers.js:574:20)
>>   at tryOnImmediate (timers.js:554:5)
>>   at processImmediate [as _immediateCallback] (timers.js:533:5)

>> csso - sourcemap
>> Message: should create sourcemap
>> Error: '{"version":3,"sources":["<unknown>"],"names":[],"mappings":"AAAA,E,CACC,wB,CACA
,gB,CAED,E,CACC,2B,CACA,wB","file":"<unknown>","sourcesContent":[".a {\\n\\t-webkit-fi1ter
: blur(5px);\\n\\tfilter: blur(5px);\\n}\\n.b {\\n\\t-webkit-padding-before: 10px;\\n\\tpa
dding-block-start: 10px;\\n}\\n\\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZX
JzaW9uIjozLCJzb3VyY2VzIjpbInNvdXJjZS5jc3MiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7SUFDSSww
QkFBa0I7WUFBbEIsa0JBQWtCO0NBQ3JCO0FBQ0Q7SUFDSSw2QkFBMEI7WUFBMUIsMEJBQTBCO0NBQzdCIiwiZmlsZS
I6InNvdXJjZS5jc3MiLCJzb3VyY2VzQ29udGVudCI6WyIuYSB7XG4gICAgZmlsdGVyOiBibHVyKDVweCk7XG59XG4u
YiB7XG4gICAgcGFkZGluZy1ibG9jay1zdGFydDogMTBweDtcbn1cbiJdfQ== */"]}' == '{"version":3,"sour
ces":["<unknown>"],"names":[],"mappings":"AAAA,E,CACC,wB,CACA,gB,CAED,E,CACC,2B,CACA,wB","
file":"<unknown>","sourcesContent":[".a {\\r\\n\\t-webkit-fi1ter: blur(5px);\\r\\n\\tfilte
r: blur(5px);\\r\\n}\\r\\n.b {\\r\\n\\t-webkit-padding-before: 10px;\\r\\n\\tpadding-block
-start: 10px;\\r\\n}\\r\\n\\r\\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJz
aW9uIjozLCJzb3VyY2VzIjpbInNvdXJjZS5jc3MiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7SUFDSSwwQk
FBa0I7WUFBbEIsa0JBQWtCO0NBQ3JCO0FBQ0Q7SUFDSSw2QkFBMEI7WUFBMUIsMEJBQTBCO0NBQzdCIiwiZmlsZSI6
InNvdXJjZS5jc3MiLCJzb3VyY2VzQ29udGVudCI6WyIuYSB7XG4gICAgZmlsdGVyOiBibHVyKDVweCk7XG59XG4uYi
B7XG4gICAgcGFkZGluZy1ibG9jay1zdGFydDogMTBweDtcbn1cbiJdfQ== */"]}'
>>   at Object.sourcemap (test\csso-test.js:24:10)
>>   at runCallback (timers.js:574:20)
>>   at tryOnImmediate (timers.js:554:5)
>>   at processImmediate [as _immediateCallback] (timers.js:533:5)

>> csso - comments
>> Message: should minify and remove all but the first exclamation comment
>> Error: '.a{-webkit-fi1ter:blur(5px);filter:blur(5px)}.b{-webkit-padding-before:10px;pad
ding-block-start:10px}\r\n/*# sourceMappingURL=sourcemap.css.map */' == '.a{-webkit-fi1ter
:blur(5px);filter:blur(5px)}.b{-webkit-padding-before:10px;padding-block-start:10px}\n/*#
sourceMappingURL=sourcemap.css.map */'
>>   at Object.comments (test\csso-test.js:34:10)
>>   at runCallback (timers.js:574:20)
>>   at tryOnImmediate (timers.js:554:5)
>>   at processImmediate [as _immediateCallback] (timers.js:533:5)

Warning: 3/12 assertions failed (15ms) Use --force to continue.

@nitriques
Copy link
Collaborator

Ok thanks. At home, I do not have a Windows machine (I've tested in on Ubuntu) but I do at work. Will test ASAP.

@nitriques
Copy link
Collaborator

I have no problems running the test on my Windows machine.

I think it depends on your git config: if git converts LF to CRLF, then the test might not pass.

I've juste pushed a .gitattributes file to make sure your git config does not make the test fails.

@webuniverseio
Copy link
Contributor Author

I had an issue even after I pulled, so I decided to delete everything except for .git and try again. After reset everything works fine. Good job 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants