Skip to content

Commit ffaf493

Browse files
author
vpanov
committed
fixes export issue when file contains nothing but imports
1 parent 66896b3 commit ffaf493

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

index.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,29 @@ function insertStartMarker(nodes) {
5757
curNode = nodes[curIndex];
5858
}
5959

60+
// In case if module contains only imports we need to add at least one rule
61+
// otherwise module will be removed and won't be able to restore imports
62+
if (!curNode && requiredImports.length) {
63+
curNode = emptyNode.clone();
64+
65+
// source required to properly output module content
66+
curNode.source = nodes[0].source;
67+
68+
nodes.push(curNode);
69+
}
6070

6171
if (curNode) {
6272
curNode.reexportRequiredImports = requiredImports;
6373

6474
let contentStart = postcss()
6575
.process('.postcss-reexport[data-type="start"]{display: none;}\n').root.nodes[0];
6676

67-
curNode.parent.source.input
68-
6977
// postcss-import will look for source in first node with type="media"
7078
contentStart.source = nodes[0].source;
7179

7280
nodes.splice(curIndex, 0, contentStart);
7381
hasStart = true;
82+
7483
}
7584

7685
return hasStart;
@@ -220,10 +229,10 @@ function extractImportedBlocksRecursive(styles, options) {
220229
});
221230

222231
let offset = 0;
223-
232+
224233
extractIndexes.forEach((extracData, index) => {
225234
var sliceCount = extracData.end - extracData.start + 1;
226-
235+
227236
var extractedStyles = styles.nodes
228237
// excract previously imported block
229238
.splice(extracData.start - offset, sliceCount);
@@ -232,7 +241,6 @@ function extractImportedBlocksRecursive(styles, options) {
232241
extractedStyles = extractedStyles.splice(1, extractedStyles.length - 2);
233242

234243
// TODO: better solution for wrong "\" direction
235-
236244
var curFile = extractedStyles[0].source.input.file;
237245
var contextRelativePath = path.relative(contextPath, path.dirname(curFile));
238246
var fileName = path.basename(curFile);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-reexport",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)