Skip to content

Commit 74893c8

Browse files
committed
Merge branch 'release/2.8.0'
2 parents fac9719 + 88866fd commit 74893c8

File tree

7 files changed

+114
-38
lines changed

7 files changed

+114
-38
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-plugin-css-modules",
3-
"version": "2.7.0",
3+
"version": "2.8.0",
44
"main": "lib/index.js",
55
"author": "Brody McKee <[email protected]>",
66
"license": "MIT",
@@ -75,7 +75,8 @@
7575
"postcss-load-config": "^2.1.0",
7676
"reserved-words": "^0.1.2",
7777
"sass": "^1.26.5",
78-
"stylus": "^0.54.7"
78+
"stylus": "^0.54.7",
79+
"tsconfig-paths": "^3.9.0"
7980
},
8081
"devDependencies": {
8182
"@types/icss-utils": "^4.1.0",

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

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ Object {
99
}
1010
`;
1111

12+
exports[`utils / cssSnapshots with baseUrl and paths in compilerOptions sass should find the files 1`] = `
13+
Object {
14+
"big-font": "tsconfig-paths-module__big-font---3FOK9",
15+
"class-with-mixin": "tsconfig-paths-module__class-with-mixin---Uo34z",
16+
"public-module": "tsconfig-paths-module__public-module---2IHe1",
17+
}
18+
`;
19+
1220
exports[`utils / cssSnapshots with file 'empty.module.less' createExports should create an exports file 1`] = `
1321
"declare let classes: {
1422
@@ -105,12 +113,12 @@ exports[`utils / cssSnapshots with file 'import.module.css' createExports should
105113
'nestedChild': string;
106114
};
107115
export default classes;
108-
export const classA: string;
109-
export const ClassB: string;
110-
export const parent: string;
111-
export const childA: string;
112-
export const childB: string;
113-
export const nestedChild: string;
116+
export let classA: string;
117+
export let ClassB: string;
118+
export let parent: string;
119+
export let childA: string;
120+
export let childB: string;
121+
export let nestedChild: string;
114122
"
115123
`;
116124

@@ -140,12 +148,12 @@ declare let classes: {
140148
'nestedChild': string;
141149
};
142150
export default classes;
143-
export const classA: string;
144-
export const ClassB: string;
145-
export const parent: string;
146-
export const childA: string;
147-
export const childB: string;
148-
export const nestedChild: string;
151+
export let classA: string;
152+
export let ClassB: string;
153+
export let parent: string;
154+
export let childA: string;
155+
export let childB: string;
156+
export let nestedChild: string;
149157
150158
export const __cssModule: true;
151159
export type AllClassNames = 'classA' | 'ClassB' | 'class-c' | 'class_d' | 'parent' | 'childA' | 'childB' | 'nestedChild';"
@@ -217,9 +225,9 @@ exports[`utils / cssSnapshots with file 'import.module.styl' createExports shoul
217225
'inside-2-name-1': string;
218226
};
219227
export default classes;
220-
export const foo: string;
221-
export const bar: string;
222-
export const baz: string;
228+
export let foo: string;
229+
export let bar: string;
230+
export let baz: string;
223231
"
224232
`;
225233

@@ -253,9 +261,9 @@ declare let classes: {
253261
'inside-2-name-1': string;
254262
};
255263
export default classes;
256-
export const foo: string;
257-
export const bar: string;
258-
export const baz: string;
264+
export let foo: string;
265+
export let bar: string;
266+
export let baz: string;
259267
260268
export const __cssModule: true;
261269
export type AllClassNames = 'foo' | 'bar' | 'baz' | 'col-1' | 'col-2' | 'col-3' | 'local-class-1' | 'inside-local' | 'inside-1-name-2' | 'inside-2-name-1';"
@@ -273,12 +281,12 @@ exports[`utils / cssSnapshots with file 'test.module.css' createExports should c
273281
'nestedChild': string;
274282
};
275283
export default classes;
276-
export const classA: string;
277-
export const ClassB: string;
278-
export const parent: string;
279-
export const childA: string;
280-
export const childB: string;
281-
export const nestedChild: string;
284+
export let classA: string;
285+
export let ClassB: string;
286+
export let parent: string;
287+
export let childA: string;
288+
export let childB: string;
289+
export let nestedChild: string;
282290
"
283291
`;
284292

@@ -308,12 +316,12 @@ declare let classes: {
308316
'nestedChild': string;
309317
};
310318
export default classes;
311-
export const classA: string;
312-
export const ClassB: string;
313-
export const parent: string;
314-
export const childA: string;
315-
export const childB: string;
316-
export const nestedChild: string;
319+
export let classA: string;
320+
export let ClassB: string;
321+
export let parent: string;
322+
export let childA: string;
323+
export let childB: string;
324+
export let nestedChild: string;
317325
318326
export const __cssModule: true;
319327
export type AllClassNames = 'classA' | 'ClassB' | 'class-c' | 'class_d' | 'parent' | 'childA' | 'childB' | 'nestedChild';"
@@ -549,9 +557,9 @@ exports[`utils / cssSnapshots with file 'test.module.styl' createExports should
549557
'inside-2-name-1': string;
550558
};
551559
export default classes;
552-
export const foo: string;
553-
export const bar: string;
554-
export const baz: string;
560+
export let foo: string;
561+
export let bar: string;
562+
export let baz: string;
555563
"
556564
`;
557565

@@ -585,9 +593,9 @@ declare let classes: {
585593
'inside-2-name-1': string;
586594
};
587595
export default classes;
588-
export const foo: string;
589-
export const bar: string;
590-
export const baz: string;
596+
export let foo: string;
597+
export let bar: string;
598+
export let baz: string;
591599
592600
export const __cssModule: true;
593601
export type AllClassNames = 'foo' | 'bar' | 'baz' | 'col-1' | 'col-2' | 'col-3' | 'local-class-1' | 'inside-local' | 'inside-1-name-2' | 'inside-2-name-1';"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.public-module {
2+
color: green;
3+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@import '@scss/_external.module.scss';
2+
@import 'alias.scss';

src/helpers/__tests__/getDtsSnapshot.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,29 @@ describe('utils / cssSnapshots', () => {
186186
expect(classes).toMatchSnapshot();
187187
});
188188
});
189+
190+
describe('with baseUrl and paths in compilerOptions', () => {
191+
const fileName = join(__dirname, 'fixtures', 'tsconfig-paths.module.scss');
192+
const css = readFileSync(fileName, 'utf8');
193+
const compilerOptions = {
194+
baseUrl: __dirname,
195+
paths: {
196+
'@scss/*': ['external/package/*'],
197+
'alias.scss': ['external/package/public.module.scss'],
198+
},
199+
};
200+
201+
it('sass should find the files', () => {
202+
const classes = getClasses({
203+
css,
204+
fileName,
205+
logger,
206+
options,
207+
processor,
208+
compilerOptions,
209+
});
210+
211+
expect(classes).toMatchSnapshot();
212+
});
213+
});
189214
});

src/helpers/getClasses.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import sass from 'sass';
55
import stylus from 'stylus';
66
import { extractICSS } from 'icss-utils';
77
import tsModule from 'typescript/lib/tsserverlibrary';
8+
import { createMatchPath } from 'tsconfig-paths';
89
import { Logger } from './logger';
910
import { Options, CustomRenderer } from '../options';
1011

@@ -71,6 +72,14 @@ export const getClasses = ({
7172
} else if (fileType === FileTypes.scss || fileType === FileTypes.sass) {
7273
const filePath = getFilePath(fileName);
7374
const { includePaths, ...sassOptions } = rendererOptions.sass || {};
75+
const { baseUrl, paths } = compilerOptions;
76+
const matchPath =
77+
baseUrl && paths ? createMatchPath(path.resolve(baseUrl), paths) : null;
78+
79+
const aliasImporter: sass.Importer = (url) => {
80+
const newUrl = matchPath !== null ? matchPath(url) : undefined;
81+
return newUrl ? { file: newUrl } : null;
82+
};
7483

7584
transformedCss = sass
7685
.renderSync({
@@ -80,6 +89,7 @@ export const getClasses = ({
8089
data: css.replace(/(@import ['"])~(?!\/)/gm, '$1'),
8190
indentedSyntax: fileType === FileTypes.sass,
8291
includePaths: [filePath, 'node_modules', ...(includePaths || [])],
92+
importer: [aliasImporter],
8393
...sassOptions,
8494
})
8595
.css.toString();

yarn.lock

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,11 @@
605605
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
606606
integrity sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==
607607

608+
"@types/json5@^0.0.29":
609+
version "0.0.29"
610+
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
611+
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=
612+
608613
"@types/less@^3.0.1":
609614
version "3.0.1"
610615
resolved "https://registry.yarnpkg.com/@types/less/-/less-3.0.1.tgz#625694093c72f8356c4042754e222407e50d6b08"
@@ -3084,6 +3089,13 @@ json5@^0.5.0:
30843089
resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"
30853090
integrity sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=
30863091

3092+
json5@^1.0.1:
3093+
version "1.0.1"
3094+
resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.1.tgz#779fb0018604fa854eacbf6252180d83543e3dbe"
3095+
integrity sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==
3096+
dependencies:
3097+
minimist "^1.2.0"
3098+
30873099
jsprim@^1.2.2:
30883100
version "1.4.1"
30893101
resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2"
@@ -4567,6 +4579,11 @@ strip-ansi@^6.0.0:
45674579
dependencies:
45684580
ansi-regex "^5.0.0"
45694581

4582+
strip-bom@^3.0.0:
4583+
version "3.0.0"
4584+
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
4585+
integrity sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=
4586+
45704587
strip-bom@^4.0.0:
45714588
version "4.0.0"
45724589
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-4.0.0.tgz#9c3505c1db45bcedca3d9cf7a16f5c5aa3901878"
@@ -4790,6 +4807,16 @@ ts-jest@^25.4.0:
47904807
semver "6.x"
47914808
yargs-parser "18.x"
47924809

4810+
tsconfig-paths@^3.9.0:
4811+
version "3.9.0"
4812+
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz#098547a6c4448807e8fcb8eae081064ee9a3c90b"
4813+
integrity sha512-dRcuzokWhajtZWkQsDVKbWyY+jgcLC5sqJhg2PSgf4ZkH2aHPvaOY8YWGhmjb68b5qqTfasSsDO9k7RUiEmZAw==
4814+
dependencies:
4815+
"@types/json5" "^0.0.29"
4816+
json5 "^1.0.1"
4817+
minimist "^1.2.0"
4818+
strip-bom "^3.0.0"
4819+
47934820
tslib@^1.10.0:
47944821
version "1.11.0"
47954822
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.11.0.tgz#f1f3528301621a53220d58373ae510ff747a66bc"

0 commit comments

Comments
 (0)