-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suppress confusable theme import when tweaking (#33)
* Suppress confusable import in inline style by import suppress plugin * Update README.md * [ci skip] Update CHANGELOG.md
- Loading branch information
Showing
6 changed files
with
76 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** @module */ | ||
import postcss from 'postcss' | ||
import postcssImportParse from './parse' | ||
|
||
/** | ||
* Marpit PostCSS import suppress plugin. | ||
* | ||
* Comment out `@import` / `@import-theme` rules that have imported theme. | ||
* | ||
* This plugin is useful to prevent the inline style's rolled-up theme import by | ||
* unexpected order. | ||
* | ||
* @alias module:postcss/import/suppress | ||
* @param {ThemeSet} themeSet ThemeSet instance. | ||
*/ | ||
const plugin = postcss.plugin('marpit-postcss-import-suppress', themeSet => | ||
postcss([ | ||
postcssImportParse, | ||
css => { | ||
css.walk(node => { | ||
if (node.marpitImportParse && themeSet.has(node.marpitImportParse)) | ||
node.replaceWith(`${node.raw('before')}/* ${node.toString()}; */`) | ||
}) | ||
}, | ||
]) | ||
) | ||
|
||
export default plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import assert from 'assert' | ||
import postcss from 'postcss' | ||
import importSuppress from '../../../src/postcss/import/suppress' | ||
|
||
describe('Marpit PostCSS import suppress plugin', () => { | ||
const themeSetStub = new Map() | ||
themeSetStub.set('imported', { css: '' }) | ||
|
||
const run = input => | ||
postcss([importSuppress(themeSetStub)]).process(input, { from: undefined }) | ||
|
||
it('comments out @import and @import-theme rules with valid theme', () => | ||
run('@import "imported";\n@import-theme "imported";').then(({ css }) => | ||
assert( | ||
css === '/* @import "imported"; */\n/* @import-theme "imported"; */' | ||
) | ||
)) | ||
|
||
it('ignores @import and @import-theme rules with invalid theme', () => { | ||
const style = '@import "invalid";\n@import-theme "invalid";' | ||
return run(style).then(({ css }) => assert(css === style)) | ||
}) | ||
}) |