Skip to content

Commit 468b6a1

Browse files
committed
Merge branch 'release/2.1.2'
2 parents b7f68de + 9593126 commit 468b6a1

File tree

9 files changed

+198
-42
lines changed

9 files changed

+198
-42
lines changed

package.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-plugin-css-modules",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"main": "lib/index.js",
55
"author": "Brody McKee <[email protected]>",
66
"license": "MIT",
@@ -36,6 +36,7 @@
3636
}
3737
},
3838
"jest": {
39+
"clearMocks": true,
3940
"collectCoverageFrom": [
4041
"src/**/*.{ts}"
4142
],
@@ -82,13 +83,14 @@
8283
"@types/jest": "^24.0.23",
8384
"@types/less": "^3.0.1",
8485
"@types/lodash.camelcase": "^4.3.6",
85-
"@types/node": "^12.12.14",
86+
"@types/node": "^12.12.17",
8687
"@types/postcss-load-config": "^2.0.1",
8788
"@types/postcss-nested": "^4.1.0",
8889
"@types/reserved-words": "^0.1.0",
8990
"@types/sass": "^1.16.0",
90-
"@typescript-eslint/eslint-plugin": "^2.9.0",
91-
"@typescript-eslint/parser": "^2.9.0",
91+
"@typescript-eslint/eslint-plugin": "^2.11.0",
92+
"@typescript-eslint/parser": "^2.11.0",
93+
"bootstrap": "4.4.1",
9294
"eslint": "^6.7.2",
9395
"eslint-config-prettier": "^6.7.0",
9496
"husky": "^3.1.0",
@@ -97,7 +99,7 @@
9799
"postcss-import-sync2": "^1.1.0",
98100
"prettier": "^1.19.1",
99101
"ts-jest": "^24.2.0",
100-
"typescript": "^3.7.2"
102+
"typescript": "^3.7.3"
101103
},
102104
"peerDependencies": {
103105
"typescript": "^3.0.0"

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

+64
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`utils / cssSnapshots with a Bootstrap import should find external files 1`] = `"bootstrap-module__test---WRms9"`;
4+
35
exports[`utils / cssSnapshots with a custom renderer should process a file and log 1`] = `
46
Object {
57
"exampleFileContents": "exampleFileContents__exampleFileContents---e3Nf2",
@@ -17,6 +19,16 @@ export default classes;
1719

1820
exports[`utils / cssSnapshots with file 'empty.module.less' getClasses should return an object matching expected CSS 1`] = `Object {}`;
1921

22+
exports[`utils / cssSnapshots with file 'empty.module.sass' createExports should create an exports file 1`] = `
23+
"declare const classes: {
24+
25+
};
26+
export default classes;
27+
"
28+
`;
29+
30+
exports[`utils / cssSnapshots with file 'empty.module.sass' getClasses should return an object matching expected CSS 1`] = `Object {}`;
31+
2032
exports[`utils / cssSnapshots with file 'empty.module.scss' createExports should create an exports file 1`] = `
2133
"declare const classes: {
2234
@@ -159,6 +171,58 @@ Object {
159171
}
160172
`;
161173

174+
exports[`utils / cssSnapshots with file 'test.module.sass' createExports should create an exports file 1`] = `
175+
"declare const classes: {
176+
'local-class-inside-global': string;
177+
'local-class': string;
178+
'local-class-2': string;
179+
'local-class-inside-local': string;
180+
'reserved-words': string;
181+
'default': string;
182+
'const': string;
183+
'nested-class-parent': string;
184+
'child-class': string;
185+
'nested-class-parent--extended': string;
186+
'section-1': string;
187+
'section-2': string;
188+
'section-3': string;
189+
'section-4': string;
190+
'section-5': string;
191+
'section-6': string;
192+
'section-7': string;
193+
'section-8': string;
194+
'section-9': string;
195+
'class-with-mixin': string;
196+
};
197+
export default classes;
198+
"
199+
`;
200+
201+
exports[`utils / cssSnapshots with file 'test.module.sass' getClasses should return an object matching expected CSS 1`] = `
202+
Object {
203+
"child-class": "test-module__child-class---2vfhc",
204+
"class-with-mixin": "test-module__class-with-mixin---3zUq-",
205+
"const": "test-module__const---39o_j",
206+
"default": "test-module__default---h-tcC",
207+
"local-class": "test-module__local-class---1yStp",
208+
"local-class-2": "test-module__local-class-2---3xCgt",
209+
"local-class-inside-global": "test-module__local-class-inside-global---Mznd5",
210+
"local-class-inside-local": "test-module__local-class-inside-local---1z2Qf",
211+
"nested-class-parent": "test-module__nested-class-parent---3oyeq",
212+
"nested-class-parent--extended": "test-module__nested-class-parent--extended---cjRbg",
213+
"reserved-words": "test-module__reserved-words---3hGie",
214+
"section-1": "test-module__section-1---2QkaE",
215+
"section-2": "test-module__section-2---23KHs",
216+
"section-3": "test-module__section-3---2BttW",
217+
"section-4": "test-module__section-4---1TrSo",
218+
"section-5": "test-module__section-5---1PIYZ",
219+
"section-6": "test-module__section-6---tbEch",
220+
"section-7": "test-module__section-7---i7uWX",
221+
"section-8": "test-module__section-8---1jfNT",
222+
"section-9": "test-module__section-9---1akFT",
223+
}
224+
`;
225+
162226
exports[`utils / cssSnapshots with file 'test.module.scss' createExports should create an exports file 1`] = `
163227
"declare const classes: {
164228
'local-class-inside-global': string;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import '~bootstrap/scss/bootstrap';
2+
3+
.test {
4+
color: $blue;
5+
}

src/helpers/__tests__/fixtures/empty.module.sass

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
:global .global-class
2+
color: rebeccapurple
3+
4+
5+
:global(.global-class-2)
6+
.local-class-inside-global
7+
color: rebeccapurple
8+
9+
10+
11+
:local .local-class
12+
color: rebeccapurple
13+
14+
15+
:local(.local-class-2)
16+
.local-class-inside-local
17+
color: rebeccapurple
18+
19+
20+
21+
.reserved-words
22+
.default
23+
color: rebeccapurple
24+
25+
.const
26+
color: rebeccapurple
27+
28+
29+
.nested-class-parent
30+
.child-class
31+
color: rebeccapurple
32+
33+
&--extended
34+
color: rebeccapurple
35+
36+
37+
38+
$color: rebeccapurple !default
39+
40+
@for $section from 1 to 10
41+
.section-#{$section}
42+
color: $color
43+
44+
@import 'mixin'
45+
46+
.class-with-mixin
47+
@include set-margin(0)
48+
49+
// .commented-parent-class {
50+
// .commented-child-class
51+
// }

src/helpers/__tests__/getDtsSnapshot.test.ts

+27-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const testFileNames = [
1313
'test.module.css',
1414
'test.module.less',
1515
'test.module.scss',
16+
'test.module.sass',
1617
'empty.module.less',
18+
'empty.module.sass',
1719
'empty.module.scss',
1820
'import.module.css',
1921
'import.module.less',
@@ -63,19 +65,37 @@ describe('utils / cssSnapshots', () => {
6365
});
6466
});
6567

68+
describe('with a Bootstrap import', () => {
69+
const fullFileName = join(__dirname, 'fixtures', 'bootstrap.module.scss');
70+
const testFile = readFileSync(fullFileName, 'utf8');
71+
72+
it('should find external files', () => {
73+
const classes = getClasses(
74+
processor,
75+
testFile,
76+
fullFileName,
77+
mockOptions,
78+
mockLogger,
79+
);
80+
81+
expect(classes.test).toMatchSnapshot();
82+
});
83+
});
84+
6685
describe('with a custom renderer', () => {
6786
const fullFileName = 'exampleFileContents';
6887
const testFile = 'exampleFileName';
6988
const customRenderer = join(__dirname, 'fixtures', 'customRenderer.js');
70-
const classes = getClasses(
71-
processor,
72-
testFile,
73-
fullFileName,
74-
{ customRenderer },
75-
mockLogger,
76-
);
7789

7890
it('should process a file and log', () => {
91+
const classes = getClasses(
92+
processor,
93+
testFile,
94+
fullFileName,
95+
{ customRenderer },
96+
mockLogger,
97+
);
98+
7999
expect(classes).toMatchSnapshot();
80100
expect(mockLogger.log).toHaveBeenCalledWith('Example log');
81101
});

src/helpers/getClasses.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import { Options, CustomRenderer } from '../options';
99
export const enum FileTypes {
1010
css = 'css',
1111
less = 'less',
12+
sass = 'sass',
1213
scss = 'scss',
1314
}
1415

1516
export const getFileType = (fileName: string) => {
1617
if (fileName.endsWith('.css')) return FileTypes.css;
1718
if (fileName.endsWith('.less')) return FileTypes.less;
19+
if (fileName.endsWith('.sass')) return FileTypes.sass;
1820
return FileTypes.scss;
1921
};
2022

@@ -50,13 +52,17 @@ export const getClasses = (
5052
transformedCss = output.css.toString();
5153
},
5254
);
53-
} else if (fileType === FileTypes.scss) {
55+
} else if (fileType === FileTypes.scss || fileType === FileTypes.sass) {
5456
const filePath = getFilePath(fileName);
5557
const { includePaths, ...sassOptions } = rendererOptions.sass || {};
5658

5759
transformedCss = sass
5860
.renderSync({
59-
data: css,
61+
// NOTE: Solves an issue where tilde imports fail.
62+
// https://github.com/sass/dart-sass/issues/801
63+
// Will strip `~` from imports, unless followed by a slash.
64+
data: css.replace(/(@import ['"])~(?!\/)/gm, '$1'),
65+
indentedSyntax: fileType === FileTypes.sass,
6066
includePaths: [filePath, 'node_modules', ...(includePaths || [])],
6167
...sassOptions,
6268
})

src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ function init({ typescript: ts }: { typescript: typeof tsModule }) {
2727
const logger = createLogger(info);
2828
const directory = info.project.getCurrentDirectory();
2929

30+
// TypeScript plugins have a `cwd` of `/`, which causes issues with import resolution.
31+
process.chdir(directory);
32+
3033
// User options for plugin.
3134
const options: Options = info.config.options || {};
3235
logger.log(`options: ${JSON.stringify(options)}`);

yarn.lock

+33-28
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,10 @@
440440
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.0.2.tgz#3452a24edf9fea138b48fad4a0a028a683da1e40"
441441
integrity sha512-5tabW/i+9mhrfEOUcLDu2xBPsHJ+X5Orqy9FKpale3SjDA17j5AEpYq5vfy3oAeAHGcvANRCO3NV3d2D6q3NiA==
442442

443-
"@types/node@^12.12.14":
444-
version "12.12.14"
445-
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.14.tgz#1c1d6e3c75dba466e0326948d56e8bd72a1903d2"
446-
integrity sha512-u/SJDyXwuihpwjXy7hOOghagLEV1KdAST6syfnOk6QZAMzZuWZqXy5aYYZbh8Jdpd4escVFP0MvftHNDb9pruA==
443+
"@types/node@^12.12.17":
444+
version "12.12.17"
445+
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.17.tgz#191b71e7f4c325ee0fb23bc4a996477d92b8c39b"
446+
integrity sha512-Is+l3mcHvs47sKy+afn2O1rV4ldZFU7W8101cNlOd+MRbjM4Onida8jSZnJdTe/0Pcf25g9BNIUsuugmE6puHA==
447447

448448
"@types/normalize-package-data@^2.4.0":
449449
version "2.4.0"
@@ -499,40 +499,40 @@
499499
dependencies:
500500
"@types/yargs-parser" "*"
501501

502-
"@typescript-eslint/eslint-plugin@^2.9.0":
503-
version "2.9.0"
504-
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.9.0.tgz#fa810282c0e45f6c2310b9c0dfcd25bff97ab7e9"
505-
integrity sha512-98rfOt3NYn5Gr9wekTB8TexxN6oM8ZRvYuphPs1Atfsy419SDLYCaE30aJkRiiTCwGEY98vOhFsEVm7Zs4toQQ==
502+
"@typescript-eslint/eslint-plugin@^2.11.0":
503+
version "2.11.0"
504+
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.11.0.tgz#4477c33491ccf0a9a3f4a30ef84978fa0ea0cad2"
505+
integrity sha512-G2HHA1vpMN0EEbUuWubiCCfd0R3a30BB+UdvnFkxwZIxYEGOrWEXDv8tBFO9f44CWc47Xv9lLM3VSn4ORLI2bA==
506506
dependencies:
507-
"@typescript-eslint/experimental-utils" "2.9.0"
507+
"@typescript-eslint/experimental-utils" "2.11.0"
508508
eslint-utils "^1.4.3"
509509
functional-red-black-tree "^1.0.1"
510510
regexpp "^3.0.0"
511511
tsutils "^3.17.1"
512512

513-
"@typescript-eslint/experimental-utils@2.9.0":
514-
version "2.9.0"
515-
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.9.0.tgz#bbe99a8d9510240c055fc4b17230dd0192ba3c7f"
516-
integrity sha512-0lOLFdpdJsCMqMSZT7l7W2ta0+GX8A3iefG3FovJjrX+QR8y6htFlFdU7aOVPL6pDvt6XcsOb8fxk5sq+girTw==
513+
"@typescript-eslint/experimental-utils@2.11.0":
514+
version "2.11.0"
515+
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.11.0.tgz#cef18e6b122706c65248a5d8984a9779ed1e52ac"
516+
integrity sha512-YxcA/y0ZJaCc/fB/MClhcDxHI0nOBB7v2/WxBju2cOTanX7jO9ttQq6Fy4yW9UaY5bPd9xL3cun3lDVqk67sPQ==
517517
dependencies:
518518
"@types/json-schema" "^7.0.3"
519-
"@typescript-eslint/typescript-estree" "2.9.0"
519+
"@typescript-eslint/typescript-estree" "2.11.0"
520520
eslint-scope "^5.0.0"
521521

522-
"@typescript-eslint/parser@^2.9.0":
523-
version "2.9.0"
524-
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.9.0.tgz#2e9cf438de119b143f642a3a406e1e27eb70b7cd"
525-
integrity sha512-fJ+dNs3CCvEsJK2/Vg5c2ZjuQ860ySOAsodDPwBaVlrGvRN+iCNC8kUfLFL8cT49W4GSiLPa/bHiMjYXA7EhKQ==
522+
"@typescript-eslint/parser@^2.11.0":
523+
version "2.11.0"
524+
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.11.0.tgz#cdcc3be73ee31cbef089af5ff97ccaa380ef6e8b"
525+
integrity sha512-DyGXeqhb3moMioEFZIHIp7oXBBh7dEfPTzGrlyP0Mi9ScCra4SWEGs3kPd18mG7Sy9Wy8z88zmrw5tSGL6r/6A==
526526
dependencies:
527527
"@types/eslint-visitor-keys" "^1.0.0"
528-
"@typescript-eslint/experimental-utils" "2.9.0"
529-
"@typescript-eslint/typescript-estree" "2.9.0"
528+
"@typescript-eslint/experimental-utils" "2.11.0"
529+
"@typescript-eslint/typescript-estree" "2.11.0"
530530
eslint-visitor-keys "^1.1.0"
531531

532-
"@typescript-eslint/typescript-estree@2.9.0":
533-
version "2.9.0"
534-
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.9.0.tgz#09138daf8f47d0e494ba7db9e77394e928803017"
535-
integrity sha512-v6btSPXEWCP594eZbM+JCXuFoXWXyF/z8kaSBSdCb83DF+Y7+xItW29SsKtSULgLemqJBT+LpT+0ZqdfH7QVmA==
532+
"@typescript-eslint/typescript-estree@2.11.0":
533+
version "2.11.0"
534+
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.11.0.tgz#21ada6504274cd1644855926312c798fc697e9fb"
535+
integrity sha512-HGY4+d4MagO6cKMcKfIKaTMxcAv7dEVnji2Zi+vi5VV8uWAM631KjAB5GxFcexMYrwKT0EekRiiGK1/Sd7VFGA==
536536
dependencies:
537537
debug "^4.1.1"
538538
eslint-visitor-keys "^1.1.0"
@@ -843,6 +843,11 @@ binary-extensions@^2.0.0:
843843
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.0.0.tgz#23c0df14f6a88077f5f986c0d167ec03c3d5537c"
844844
integrity sha512-Phlt0plgpIIBOGTT/ehfFnbNlfsDEiqmzE2KRXoX1bLIlir4X/MR+zSyBEkL05ffWgnRSf/DXv+WrUAVr93/ow==
845845

846+
847+
version "4.4.1"
848+
resolved "https://registry.yarnpkg.com/bootstrap/-/bootstrap-4.4.1.tgz#8582960eea0c5cd2bede84d8b0baf3789c3e8b01"
849+
integrity sha512-tbx5cHubwE6e2ZG7nqM3g/FZ5PQEDMWmMGNrCUBVRPHXTJaH7CBDdsLeu3eCh3B1tzAxTnAbtmrzvWEvT2NNEA==
850+
846851
brace-expansion@^1.1.7:
847852
version "1.1.11"
848853
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
@@ -4985,10 +4990,10 @@ type-fest@^0.8.1:
49854990
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d"
49864991
integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==
49874992

4988-
typescript@^3.7.2:
4989-
version "3.7.2"
4990-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.2.tgz#27e489b95fa5909445e9fef5ee48d81697ad18fb"
4991-
integrity sha512-ml7V7JfiN2Xwvcer+XAf2csGO1bPBdRbFCkYBczNZggrBZ9c7G3riSUeJmqEU5uOtXNPMhE3n+R4FA/3YOAWOQ==
4993+
typescript@^3.7.3:
4994+
version "3.7.3"
4995+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.3.tgz#b36840668a16458a7025b9eabfad11b66ab85c69"
4996+
integrity sha512-Mcr/Qk7hXqFBXMN7p7Lusj1ktCBydylfQM/FZCk5glCNQJrCUKPkMHdo9R0MTFWsC/4kPFvDS0fDPvukfCkFsw==
49924997

49934998
uglify-js@^3.1.4:
49944999
version "3.6.0"

0 commit comments

Comments
 (0)