Skip to content

Commit

Permalink
fix: css comments should be discarded irrespective of cssUrl (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-agius4 authored and dherges committed Jan 27, 2018
1 parent b0a6377 commit d6eb971
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
24 changes: 12 additions & 12 deletions integration/samples/custom/specs/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ describe(`sample-custom`, () => {
expect(foo).to.be.ok;
expect(foo.selector).to.equal('custom-foo');
expect(foo.template).to.contain('<h1>Foo!</h1>');
expect(foo.styles[0]).to.contain('h1 {');
expect(foo.styles[0]).to.contain('color: #ff0000; }');
expect(foo.styles[0]).to.contain('h1{');
expect(foo.styles[0]).to.contain('color:#ff0000; }');
});

describe(`BazComponent`, () => {
Expand All @@ -59,41 +59,41 @@ describe(`sample-custom`, () => {
const foo = METADATA['metadata']['FooComponent']['decorators'][0]['arguments'][0];

expect(foo).to.be.ok;
expect(foo.styles[0]).to.contain(`color: #ff0000`);
expect(foo.styles[0]).to.not.contain(`$color: #ff0000`);
expect(foo.styles[0]).to.contain(`color:#ff0000`);
expect(foo.styles[0]).to.not.contain(`$color:#ff0000`);
});

it(`should contain less-rendered styles`, () => {
const baz = METADATA['metadata']['BazComponent']['decorators'][0]['arguments'][0];

expect(baz).to.be.ok;
expect(baz.styles[0]).to.contain(`color: #ff0000`);
expect(baz.styles[0]).to.not.contain(`@red: #ff0000`);
expect(baz.styles[0]).to.contain(`color:#ff0000`);
expect(baz.styles[0]).to.not.contain(`@red:#ff0000`);
});

describe(`stylus styles`, () => {
it(`should contain rendered styles`, () => {
const fooBar = METADATA['metadata']['FooBarComponent']['decorators'][0]['arguments'][0];

expect(fooBar).to.be.ok;
expect(fooBar.styles[0]).to.contain(`color: #f00;`);
expect(fooBar.styles[0]).to.not.contain(`color: $color`);
expect(fooBar.styles[0]).to.contain(`color:#f00;`);
expect(fooBar.styles[0]).to.not.contain(`color:$color`);
});

it(`should contain imported styles`, () => {
const fooBar = METADATA['metadata']['FooBarComponent']['decorators'][0]['arguments'][0];

expect(fooBar).to.be.ok;
expect(fooBar.styles[0]).to.contain(`background-color: #008000;`);
expect(fooBar.styles[0]).to.not.contain(`background-color: $color-green;`);
expect(fooBar.styles[0]).to.contain(`background-color:#008000;`);
expect(fooBar.styles[0]).to.not.contain(`background-color:$color-green;`);
});

it(`should contain imported image path`, () => {
const fooBar = METADATA['metadata']['FooBarComponent']['decorators'][0]['arguments'][0];

expect(fooBar).to.be.ok;
expect(fooBar.styles[0]).to.contain(`background-image: url("../styles/assets/test.png");`);
expect(fooBar.styles[0]).to.not.contain(`background-color: url(./assets/test.png);`);
expect(fooBar.styles[0]).to.contain(`background-image:url("../styles/assets/test.png");`);
expect(fooBar.styles[0]).to.not.contain(`background-color:url(./assets/test.png);`);
});
});

Expand Down
4 changes: 2 additions & 2 deletions integration/samples/material/specs/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ describe(`@sample/material`, () => {
});

it(`should have style with: "color: red"`, () => {
expect(METADATA['metadata'].BazComponent.decorators[0].arguments[0].styles[0]).to.have.string('color: "red"');
expect(METADATA['metadata'].BazComponent.decorators[0].arguments[0].styles[0]).to.have.string('color:"red"');
});
it(`should have style with: "content: \\2014 \\00A0"`, () => {
expect(METADATA['metadata'].BazComponent.decorators[0].arguments[0].styles[0]).to.have.string('content: "\\2014 \\00A0"');
expect(METADATA['metadata'].BazComponent.decorators[0].arguments[0].styles[0]).to.have.string('content:"\\2014 \\00A0"');
});
});

Expand Down
8 changes: 4 additions & 4 deletions integration/samples/scss-paths/specs/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ describe(`@sample/scss-paths`, () => {

it(`should resolve the styles from the theme`, () => {
const styles = METADATA['metadata']['BazComponent']['decorators'][0]['arguments'][0]['styles'][0];
expect(styles).to.contain(`color: "red"`);
expect(styles).to.contain(`background-color: "yellow"`);
expect(styles).to.contain(`color:"red"`);
expect(styles).to.contain(`background-color:"yellow"`);
});
});

Expand All @@ -39,12 +39,12 @@ describe(`@sample/scss-paths`, () => {

it(`should resolve the styles from the parent theme`, () => {
const styles = METADATA['metadata']['BarComponent']['decorators'][0]['arguments'][0]['styles'][0];
expect(styles).to.contain(`background-color: "yellow"`);
expect(styles).to.contain(`background-color:"yellow"`);
});

it(`should resolve the styles from the sub-module common utilities`, () => {
const styles = METADATA['metadata']['BarComponent']['decorators'][0]['arguments'][0]['styles'][0];
expect(styles).to.contain(`border: 10px solid "yellow"`);
expect(styles).to.contain(`border:10px solid "yellow"`);
});
});
});
11 changes: 6 additions & 5 deletions src/lib/steps/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,16 @@ const processStylesheet =
const browsers = browserslist(undefined, { stylesheetFilePath });

log.debug(`postcss with autoprefixer for ${stylesheetFilePath}`);
const postCssPlugins = [autoprefixer({ browsers })];
const postCssPlugins = [
autoprefixer({ browsers }),
postcssComments({ removeAll: true })
];

if (cssUrl !== CssUrl.none) {
log.debug(`postcssUrl: ${cssUrl}`);
postCssPlugins.push(
postcssUrl({ url: cssUrl }),
postcssComments({ removeAll: true })
);
postCssPlugins.push(postcssUrl({ url: cssUrl }));
}

const result: postcss.Result = await postcss(postCssPlugins)
.process(cssStyles, {
from: stylesheetFilePath,
Expand Down

0 comments on commit d6eb971

Please sign in to comment.