Skip to content

Commit c350ce7

Browse files
dagda1mrmckeb
authored andcommitted
Add node_modules to rendererOptions.sass and extend (mrmckeb#60)
1 parent 06a6c7f commit c350ce7

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

src/helpers/__tests__/__snapshots__/getDtsSnapshot.test.ts.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`utils / cssSnapshots includePaths in sass options should find external file from includePaths 1`] = `
4+
Object {
5+
"big-font": "include-path-module__big-font---Td7hY",
6+
"class-with-mixin": "include-path-module__class-with-mixin---1u87_",
7+
}
8+
`;
9+
310
exports[`utils / cssSnapshots with a custom renderer should process a file and log 1`] = `
411
Object {
512
"exampleFileContents": "exampleFileContents__exampleFileContents---e3Nf2",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@import 'mixin';
2+
3+
.class-with-mixin {
4+
@include set-margin(0);
5+
}
6+
7+
.big-font {
8+
font-size: 82px;
9+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import 'package/external.module.scss';

src/helpers/__tests__/getDtsSnapshot.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,29 @@ describe('utils / cssSnapshots', () => {
8080
expect(mockLogger.log).toHaveBeenCalledWith('Example log');
8181
});
8282
});
83+
84+
describe('includePaths in sass options', () => {
85+
const fullFileName = join(
86+
__dirname,
87+
'fixtures',
88+
'include-path.module.scss',
89+
);
90+
const testFile = readFileSync(fullFileName, 'utf8');
91+
92+
it('should find external file from includePaths', () => {
93+
const classes = getClasses(
94+
processor,
95+
testFile,
96+
fullFileName,
97+
{
98+
rendererOptions: {
99+
sass: { includePaths: [join(__dirname, 'external')] },
100+
},
101+
},
102+
mockLogger,
103+
);
104+
105+
expect(classes).toMatchSnapshot();
106+
});
107+
});
83108
});

src/helpers/getClasses.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ export const getClasses = (
5252
);
5353
} else if (fileType === FileTypes.scss) {
5454
const filePath = getFilePath(fileName);
55+
const { includePaths, ...sassOptions } = rendererOptions.sass || {};
5556

5657
transformedCss = sass
5758
.renderSync({
5859
data: css,
59-
includePaths: [filePath],
60-
...(rendererOptions.sass || {}),
60+
includePaths: [filePath, 'node_modules', ...(includePaths || [])],
61+
...sassOptions,
6162
})
6263
.css.toString();
6364
} else {

0 commit comments

Comments
 (0)