Skip to content

add node_modules to sass options includePaths and stop overwritting includePaths #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`utils / cssSnapshots includePaths in sass options should find external file from includePaths 1`] = `
Object {
"big-font": "include-path-module__big-font---Td7hY",
"class-with-mixin": "include-path-module__class-with-mixin---1u87_",
}
`;

exports[`utils / cssSnapshots with a custom renderer should process a file and log 1`] = `
Object {
"exampleFileContents": "exampleFileContents__exampleFileContents---e3Nf2",
Expand Down
9 changes: 9 additions & 0 deletions src/helpers/__tests__/external/package/_external.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@import 'mixin';

.class-with-mixin {
@include set-margin(0);
}

.big-font {
font-size: 82px;
}
1 change: 1 addition & 0 deletions src/helpers/__tests__/fixtures/include-path.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import 'package/external.module.scss';
25 changes: 25 additions & 0 deletions src/helpers/__tests__/getDtsSnapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,29 @@ describe('utils / cssSnapshots', () => {
expect(mockLogger.log).toHaveBeenCalledWith('Example log');
});
});

describe('includePaths in sass options', () => {
const fullFileName = join(
__dirname,
'fixtures',
'include-path.module.scss',
);
const testFile = readFileSync(fullFileName, 'utf8');

it('should find external file from includePaths', () => {
const classes = getClasses(
processor,
testFile,
fullFileName,
{
rendererOptions: {
sass: { includePaths: [join(__dirname, 'external')] },
},
},
mockLogger,
);

expect(classes).toMatchSnapshot();
});
});
});
5 changes: 3 additions & 2 deletions src/helpers/getClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ export const getClasses = (
);
} else if (fileType === FileTypes.scss) {
const filePath = getFilePath(fileName);
const { includePaths, ...sassOptions } = rendererOptions.sass || {};

transformedCss = sass
.renderSync({
data: css,
includePaths: [filePath],
...(rendererOptions.sass || {}),
includePaths: [filePath, 'node_modules', ...(includePaths || [])],
...sassOptions,
})
.css.toString();
} else {
Expand Down