Skip to content

Commit fb79442

Browse files
authored
fix: pass through project root to Sass and Less (#164)
1 parent 02a9a56 commit fb79442

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

src/helpers/__tests__/getDtsSnapshot.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe('utils / cssSnapshots', () => {
5151
options,
5252
processor,
5353
compilerOptions,
54+
directory: __dirname,
5455
});
5556
});
5657

@@ -113,6 +114,7 @@ describe('utils / cssSnapshots', () => {
113114
options,
114115
processor,
115116
compilerOptions,
117+
directory: __dirname,
116118
});
117119

118120
expect(cssExports.classes.test).toMatchSnapshot();
@@ -134,6 +136,7 @@ describe('utils / cssSnapshots', () => {
134136
options,
135137
processor,
136138
compilerOptions,
139+
directory: __dirname,
137140
});
138141

139142
expect(cssExports.classes).toMatchSnapshot();
@@ -159,6 +162,7 @@ describe('utils / cssSnapshots', () => {
159162
options,
160163
processor,
161164
compilerOptions,
165+
directory: __dirname,
162166
});
163167

164168
expect(cssExports.classes).toMatchSnapshot();
@@ -185,6 +189,7 @@ describe('utils / cssSnapshots', () => {
185189
options,
186190
processor,
187191
compilerOptions,
192+
directory: __dirname,
188193
});
189194

190195
expect(cssExports.classes).toMatchSnapshot();
@@ -210,6 +215,7 @@ describe('utils / cssSnapshots', () => {
210215
options,
211216
processor,
212217
compilerOptions,
218+
directory: __dirname,
213219
});
214220

215221
expect(cssExports.classes).toMatchSnapshot();
@@ -231,6 +237,7 @@ describe('utils / cssSnapshots', () => {
231237
options,
232238
processor,
233239
compilerOptions,
240+
directory: __dirname,
234241
});
235242

236243
it('should return an object with classes, css, and a source map', () => {
@@ -269,6 +276,7 @@ describe('utils / cssSnapshots', () => {
269276
options,
270277
processor,
271278
compilerOptions,
279+
directory: __dirname,
272280
});
273281

274282
it('should return a dts file with only possibly undefined strings', () => {

src/helpers/getCssExports.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ export const getCssExports = ({
4242
options,
4343
processor,
4444
compilerOptions,
45+
directory,
4546
}: {
4647
css: string;
4748
fileName: string;
4849
logger: Logger;
4950
options: Options;
5051
processor: Processor;
5152
compilerOptions: tsModule.CompilerOptions;
53+
directory: string;
5254
}): CSSExportsWithSourceMap => {
5355
try {
5456
const fileType = getFileType(fileName);
@@ -73,6 +75,7 @@ export const getCssExports = ({
7375
{
7476
syncImport: true,
7577
filename: fileName,
78+
paths: [directory],
7679
...(rendererOptions.less ?? {}),
7780
} as Less.Options,
7881
(error?: Less.RenderError, output?: Less.RenderOutput) => {
@@ -91,7 +94,7 @@ export const getCssExports = ({
9194
case FileType.sass: {
9295
const filePath = getFilePath(fileName);
9396
const { loadPaths, ...sassOptions } = rendererOptions.sass ?? {};
94-
const { baseUrl, paths } = compilerOptions;
97+
const { baseUrl = directory, paths } = compilerOptions;
9598
const matchPath =
9699
baseUrl && paths
97100
? createMatchPath(path.resolve(baseUrl), paths)

src/helpers/getDtsSnapshot.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const getDtsSnapshot = (
1313
options: Options,
1414
logger: Logger,
1515
compilerOptions: tsModule.CompilerOptions,
16+
directory: string,
1617
): tsModule.IScriptSnapshot => {
1718
const css = scriptSnapshot.getText(0, scriptSnapshot.getLength());
1819

@@ -32,6 +33,7 @@ export const getDtsSnapshot = (
3233
options,
3334
processor,
3435
compilerOptions,
36+
directory,
3537
});
3638
const dts = createDtsExports({ cssExports, fileName, logger, options });
3739
return ts.ScriptSnapshot.fromString(dts);

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ function init({ typescript: ts }: { typescript: typeof tsModule }) {
120120
options,
121121
logger,
122122
compilerOptions,
123+
directory,
123124
);
124125
}
125126
const sourceFile = _createLanguageServiceSourceFile(
@@ -149,6 +150,7 @@ function init({ typescript: ts }: { typescript: typeof tsModule }) {
149150
options,
150151
logger,
151152
compilerOptions,
153+
directory,
152154
);
153155
}
154156
sourceFile = _updateLanguageServiceSourceFile(

0 commit comments

Comments
 (0)