Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
fix: nested dep references with tilde characters
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalsadhu authored and SimenB committed May 14, 2018
1 parent c274514 commit aaba678
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 17 deletions.
24 changes: 9 additions & 15 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,7 @@ const readFile = promisify(fs.readFile);
const readPkgUp = require('read-pkg-up');
const postcss = require('postcss');
const atImport = require('postcss-import');

const removeTilde = postcss.plugin(
'postcss-import-remove-tilde',
() =>
function(css) {
css.walkAtRules('import', rule => {
rule.params = rule.params.replace(
/((?:url\s*\(\s*)?['"])~/,
'$1'
);
});
}
);
const resolve = require('postcss-import/lib/resolve-id');

module.exports.identifyCssModule = async function identifyCssModule(filePath) {
const { pkg: { name, version }, path: packagePath } = await readPkgUp({
Expand All @@ -34,8 +22,14 @@ module.exports.identifyCssModule = async function identifyCssModule(filePath) {
module.exports.bundleCssModule = async function bundleCssModule(filePath) {
const fileContents = await readFile(filePath, 'utf8');
const { css } = await postcss()
.use(removeTilde())
.use(atImport())
.use(
atImport({
resolve(id, basedir, options) {
id = id.replace(/^~/, '');
return resolve(id, basedir, options);
},
})
)
.process(fileContents, { from: filePath });
return css;
};
3 changes: 2 additions & 1 deletion test/test-assets/my-module-3/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

@import url("./dep.css");
@import url("dep/main.css");
@import url("~@dep/main.css");
@import url("~@dep/module/main.css");
@import "dep/secondary.css";
@import "~dep/secondary.css";
@import "~@dep/module/main.css";

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion test/test-assets/my-module-3/node_modules/@dep/main.css

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aaba678

Please sign in to comment.