Skip to content

Commit cf8359f

Browse files
committed
Merge branch 'release/2.1.0'
2 parents 88e0d73 + fda898a commit cf8359f

File tree

7 files changed

+50
-5
lines changed

7 files changed

+50
-5
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,15 @@ The [internal `logger`](https://github.com/mrmckeb/typescript-plugin-css-modules
143143
| `less` | `{}` | Set [renderer options for Less](http://lesscss.org/usage/#less-options). |
144144
| `sass` | `{}` | Set [renderer options for Sass](https://sass-lang.com/documentation/js-api#options). |
145145

146+
> For convenience, `includePaths` for Sass are extended, not replaced. The defaults are the path of the current file, and `'node_modules'`.
147+
146148
### Visual Studio Code
147149

148150
#### Recommended usage
149151

150152
To use this plugin with Visual Studio Code, you should set your workspace's version of TypeScript, which will load plugins from your `tsconfig.json` file.
151153

152-
For instructions, see: [Using the workspace version of TypeScript](https://code.visualstudio.com/docs/languages/typescript#_using-the-workspace-version-of-typescript).
154+
For instructions, see: [Using the workspace version of TypeScript](https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-the-workspace-version-of-typescript).
153155

154156
#### Alternative usage
155157

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-plugin-css-modules",
3-
"version": "2.0.2",
3+
"version": "2.1.0",
44
"main": "lib/index.js",
55
"author": "Brody McKee <[email protected]>",
66
"license": "MIT",

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

+7
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,10 @@ Object {
210210
"section-9": "test-module__section-9---2EMR_",
211211
}
212212
`;
213+
214+
exports[`utils / cssSnapshots with includePaths in sass options should find external file from includePaths 1`] = `
215+
Object {
216+
"big-font": "include-path-module__big-font---Td7hY",
217+
"class-with-mixin": "include-path-module__class-with-mixin---1u87_",
218+
}
219+
`;
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import 'package/external.module.scss';

src/helpers/__tests__/getDtsSnapshot.test.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('utils / cssSnapshots', () => {
6363
});
6464
});
6565

66-
describe(`with a custom renderer`, () => {
66+
describe('with a custom renderer', () => {
6767
const fullFileName = 'exampleFileContents';
6868
const testFile = 'exampleFileName';
6969
const customRenderer = join(__dirname, 'fixtures', 'customRenderer.js');
@@ -80,4 +80,29 @@ describe('utils / cssSnapshots', () => {
8080
expect(mockLogger.log).toHaveBeenCalledWith('Example log');
8181
});
8282
});
83+
84+
describe('with 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

+3-2
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)