Skip to content

Commit

Permalink
fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
argyleink committed Nov 29, 2022
1 parent ded14e9 commit ac917c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.js
Expand Up @@ -19,6 +19,7 @@ module.exports = (opts = {}) => {
promisesList.push(
new Promise((resolve) => {
const globList = [];
let layer = new Map();

const params = valueParser(rule.params).nodes;

Expand All @@ -33,6 +34,9 @@ module.exports = (opts = {}) => {
path.join(dirName, param.value).replace(/\\/g, '/')
);
}
if (param.type === 'function' && param.value === 'layer') {
layer.set(dirName, param.nodes[0].value)
}
}

if (globList.length) {
Expand All @@ -46,10 +50,11 @@ module.exports = (opts = {}) => {
const sortedEntries = sort(entries)[sorter]();

sortedEntries.forEach((entry) => {
let paramValue = layer.get(dirName) ? `"${entry}" layer(${layer.get(dirName)})` : `"${entry}"`
rule.before(
new AtRule({
name: 'import',
params: `"${entry}"`,
params: paramValue,
source: rule.source,
})
);
Expand Down
13 changes: 13 additions & 0 deletions test.js
Expand Up @@ -169,3 +169,16 @@ test('no entries warning', async (t) => {
pluginsAfter: [postcssImport],
});
});

test('layer test', async (t) => {
const input = `
@import-glob "fixtures/css/foo/**/*.css" layer(test);
`;

const output = `
@import "${__dirname}/fixtures/css/foo/bar.css" layer(test);
@import "${__dirname}/fixtures/css/foo/foo.css" layer(test);
`;

await tester.test(input, output, t);
});

0 comments on commit ac917c5

Please sign in to comment.