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

Commit aaba678

Browse files
digitalsadhuSimenB
authored andcommitted
fix: nested dep references with tilde characters
1 parent c274514 commit aaba678

File tree

7 files changed

+21
-17
lines changed

7 files changed

+21
-17
lines changed

lib/util.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,7 @@ const readFile = promisify(fs.readFile);
77
const readPkgUp = require('read-pkg-up');
88
const postcss = require('postcss');
99
const atImport = require('postcss-import');
10-
11-
const removeTilde = postcss.plugin(
12-
'postcss-import-remove-tilde',
13-
() =>
14-
function(css) {
15-
css.walkAtRules('import', rule => {
16-
rule.params = rule.params.replace(
17-
/((?:url\s*\(\s*)?['"])~/,
18-
'$1'
19-
);
20-
});
21-
}
22-
);
10+
const resolve = require('postcss-import/lib/resolve-id');
2311

2412
module.exports.identifyCssModule = async function identifyCssModule(filePath) {
2513
const { pkg: { name, version }, path: packagePath } = await readPkgUp({
@@ -34,8 +22,14 @@ module.exports.identifyCssModule = async function identifyCssModule(filePath) {
3422
module.exports.bundleCssModule = async function bundleCssModule(filePath) {
3523
const fileContents = await readFile(filePath, 'utf8');
3624
const { css } = await postcss()
37-
.use(removeTilde())
38-
.use(atImport())
25+
.use(
26+
atImport({
27+
resolve(id, basedir, options) {
28+
id = id.replace(/^~/, '');
29+
return resolve(id, basedir, options);
30+
},
31+
})
32+
)
3933
.process(fileContents, { from: filePath });
4034
return css;
4135
};

test/test-assets/my-module-3/css/main.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
@import url("./dep.css");
44
@import url("dep/main.css");
5-
@import url("~@dep/main.css");
5+
@import url("~@dep/module/main.css");
66
@import "dep/secondary.css";
77
@import "~dep/secondary.css";
8+
@import "~@dep/module/main.css";

test/test-assets/my-module-3/node_modules/@dep-2/module/main.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test-assets/my-module-3/node_modules/@dep-2/module/package.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test-assets/my-module-3/node_modules/@dep/main.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/test-assets/my-module-3/node_modules/@dep/module/main.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test-assets/my-module-3/node_modules/@dep/module/package.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)