Skip to content

Commit 84a2036

Browse files
authored
feat: make Stylus an optional dependency (#289)
1 parent c0cb871 commit 84a2036

File tree

5 files changed

+24
-151
lines changed

5 files changed

+24
-151
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@
6060
"reserved-words": "^0.1.2",
6161
"sass": "^1.70.0",
6262
"source-map-js": "^1.0.2",
63-
"stylus": "^0.62.0",
6463
"tsconfig-paths": "^4.2.0"
6564
},
65+
"optionalDependencies": {
66+
"stylus": "^0.62.0"
67+
},
6668
"devDependencies": {
6769
"@types/icss-utils": "^5.1.2",
6870
"@types/jest": "^29.5.12",

pnpm-lock.yaml

Lines changed: 13 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -134,27 +134,6 @@ export const __cssModule: true;
134134
export type AllClassNames = '';"
135135
`;
136136

137-
exports[`helpers / cssSnapshots with file 'empty.module.styl' createExports should create an exports file 1`] = `
138-
"declare let _classes: {
139-
140-
};
141-
export default _classes;
142-
"
143-
`;
144-
145-
exports[`helpers / cssSnapshots with file 'empty.module.styl' getCssExports should return an object matching expected CSS 1`] = `{}`;
146-
147-
exports[`helpers / cssSnapshots with file 'empty.module.styl' with a custom template should transform the generated dts 1`] = `
148-
"/* eslint-disable */
149-
declare let _classes: {
150-
151-
};
152-
export default _classes;
153-
154-
export const __cssModule: true;
155-
export type AllClassNames = '';"
156-
`;
157-
158137
exports[`helpers / cssSnapshots with file 'import.module.css' createExports should create an exports file 1`] = `
159138
"declare let _classes: {
160139
'classA': string;
@@ -280,64 +259,6 @@ export const __cssModule: true;
280259
export type AllClassNames = 'nested-class-parent' | 'child-class' | 'selector-blue' | 'selector-green' | 'selector-red' | 'column-1' | 'column-2' | 'column-3' | 'column-4' | 'color-set';"
281260
`;
282261

283-
exports[`helpers / cssSnapshots with file 'import.module.styl' createExports should create an exports file 1`] = `
284-
"declare let _classes: {
285-
'foo': string;
286-
'bar': string;
287-
'baz': string;
288-
'col-1': string;
289-
'col-2': string;
290-
'col-3': string;
291-
'local-class-1': string;
292-
'inside-local': string;
293-
'inside-1-name-2': string;
294-
'inside-2-name-1': string;
295-
};
296-
export default _classes;
297-
export let foo: string;
298-
export let bar: string;
299-
export let baz: string;
300-
"
301-
`;
302-
303-
exports[`helpers / cssSnapshots with file 'import.module.styl' getCssExports should return an object matching expected CSS 1`] = `
304-
{
305-
"bar": "bar",
306-
"baz": "baz",
307-
"col-1": "col-1",
308-
"col-2": "col-2",
309-
"col-3": "col-3",
310-
"foo": "foo",
311-
"inside-1-name-2": "inside-1-name-2",
312-
"inside-2-name-1": "inside-2-name-1",
313-
"inside-local": "inside-local",
314-
"local-class-1": "local-class-1",
315-
}
316-
`;
317-
318-
exports[`helpers / cssSnapshots with file 'import.module.styl' with a custom template should transform the generated dts 1`] = `
319-
"/* eslint-disable */
320-
declare let _classes: {
321-
'foo': string;
322-
'bar': string;
323-
'baz': string;
324-
'col-1': string;
325-
'col-2': string;
326-
'col-3': string;
327-
'local-class-1': string;
328-
'inside-local': string;
329-
'inside-1-name-2': string;
330-
'inside-2-name-1': string;
331-
};
332-
export default _classes;
333-
export let foo: string;
334-
export let bar: string;
335-
export let baz: string;
336-
337-
export const __cssModule: true;
338-
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';"
339-
`;
340-
341262
exports[`helpers / cssSnapshots with file 'postcss.module.css' createExports should create an exports file 1`] = `
342263
"declare let _classes: {
343264
'classA': string;
@@ -691,64 +612,6 @@ export const __cssModule: true;
691612
export type AllClassNames = 'local-class-inside-global' | 'local-class' | 'local-class-2' | 'local-class-inside-local' | 'reserved-words' | 'default' | 'const' | 'nested-class-parent' | 'child-class' | 'nested-class-parent--extended' | 'section-1' | 'section-2' | 'section-3' | 'section-4' | 'section-5' | 'section-6' | 'section-7' | 'section-8' | 'section-9' | 'class-with-mixin' | 'App_logo' | 'App-logo' | 'my-animation' | 'my-folder-index';"
692613
`;
693614

694-
exports[`helpers / cssSnapshots with file 'test.module.styl' createExports should create an exports file 1`] = `
695-
"declare let _classes: {
696-
'foo': string;
697-
'bar': string;
698-
'baz': string;
699-
'col-1': string;
700-
'col-2': string;
701-
'col-3': string;
702-
'local-class-1': string;
703-
'inside-local': string;
704-
'inside-1-name-2': string;
705-
'inside-2-name-1': string;
706-
};
707-
export default _classes;
708-
export let foo: string;
709-
export let bar: string;
710-
export let baz: string;
711-
"
712-
`;
713-
714-
exports[`helpers / cssSnapshots with file 'test.module.styl' getCssExports should return an object matching expected CSS 1`] = `
715-
{
716-
"bar": "bar",
717-
"baz": "baz",
718-
"col-1": "col-1",
719-
"col-2": "col-2",
720-
"col-3": "col-3",
721-
"foo": "foo",
722-
"inside-1-name-2": "inside-1-name-2",
723-
"inside-2-name-1": "inside-2-name-1",
724-
"inside-local": "inside-local",
725-
"local-class-1": "local-class-1",
726-
}
727-
`;
728-
729-
exports[`helpers / cssSnapshots with file 'test.module.styl' with a custom template should transform the generated dts 1`] = `
730-
"/* eslint-disable */
731-
declare let _classes: {
732-
'foo': string;
733-
'bar': string;
734-
'baz': string;
735-
'col-1': string;
736-
'col-2': string;
737-
'col-3': string;
738-
'local-class-1': string;
739-
'inside-local': string;
740-
'inside-1-name-2': string;
741-
'inside-2-name-1': string;
742-
};
743-
export default _classes;
744-
export let foo: string;
745-
export let bar: string;
746-
export let baz: string;
747-
748-
export const __cssModule: true;
749-
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';"
750-
`;
751-
752615
exports[`helpers / cssSnapshots with goToDefinition enabled with CSS should return a line-accurate dts file 1`] = `
753616
"export let classA: string;export let composed: string;export let composedFromOtherFile: string;
754617

src/helpers/__tests__/getDtsSnapshot.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ const testFileNames = [
1313
'empty.module.less',
1414
'empty.module.sass',
1515
'empty.module.scss',
16-
'empty.module.styl',
16+
// 'empty.module.styl',
1717
'import.module.css',
1818
'import.module.less',
19-
'import.module.styl',
19+
// 'import.module.styl',
2020
'postcss.module.css',
2121
'test.module.css',
2222
'test.module.less',
2323
'test.module.sass',
2424
'test.module.scss',
25-
'test.module.styl',
25+
// 'test.module.styl',
2626
];
2727

2828
const logger: Logger = {
@@ -197,7 +197,7 @@ describe('helpers / cssSnapshots', () => {
197197
});
198198
});
199199

200-
describe('with loadPaths in stylus options', () => {
200+
describe.skip('with loadPaths in stylus options', () => {
201201
const fileName = join(__dirname, 'fixtures', 'include-path.module.styl');
202202
const css = readFileSync(fileName, 'utf8');
203203

src/helpers/getCssExports.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import path from 'path';
22
import Processor from 'postcss/lib/processor';
33
import less from 'less';
44
import sass from 'sass';
5-
import stylus from 'stylus';
65
import { CSSExports, extractICSS } from 'icss-utils';
76
import { RawSourceMap } from 'source-map-js';
87
import type tsModule from 'typescript/lib/tsserverlibrary';
@@ -190,12 +189,15 @@ export const getCssExports = ({
190189
break;
191190
}
192191

193-
case FileType.styl:
192+
case FileType.styl: {
193+
// eslint-disable-next-line @typescript-eslint/no-var-requires
194+
const stylus = require('stylus') as typeof import('stylus');
194195
transformedCss = stylus(rawCss, {
195196
...(rendererOptions.stylus ?? {}),
196197
filename: fileName,
197198
}).render();
198199
break;
200+
}
199201

200202
default:
201203
transformedCss = rawCss;

0 commit comments

Comments
 (0)