Skip to content

fix: pass through project root to Sass and Less #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/helpers/__tests__/getDtsSnapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('utils / cssSnapshots', () => {
options,
processor,
compilerOptions,
directory: __dirname,
});
});

Expand Down Expand Up @@ -113,6 +114,7 @@ describe('utils / cssSnapshots', () => {
options,
processor,
compilerOptions,
directory: __dirname,
});

expect(cssExports.classes.test).toMatchSnapshot();
Expand All @@ -134,6 +136,7 @@ describe('utils / cssSnapshots', () => {
options,
processor,
compilerOptions,
directory: __dirname,
});

expect(cssExports.classes).toMatchSnapshot();
Expand All @@ -159,6 +162,7 @@ describe('utils / cssSnapshots', () => {
options,
processor,
compilerOptions,
directory: __dirname,
});

expect(cssExports.classes).toMatchSnapshot();
Expand All @@ -185,6 +189,7 @@ describe('utils / cssSnapshots', () => {
options,
processor,
compilerOptions,
directory: __dirname,
});

expect(cssExports.classes).toMatchSnapshot();
Expand All @@ -210,6 +215,7 @@ describe('utils / cssSnapshots', () => {
options,
processor,
compilerOptions,
directory: __dirname,
});

expect(cssExports.classes).toMatchSnapshot();
Expand All @@ -231,6 +237,7 @@ describe('utils / cssSnapshots', () => {
options,
processor,
compilerOptions,
directory: __dirname,
});

it('should return an object with classes, css, and a source map', () => {
Expand Down Expand Up @@ -269,6 +276,7 @@ describe('utils / cssSnapshots', () => {
options,
processor,
compilerOptions,
directory: __dirname,
});

it('should return a dts file with only possibly undefined strings', () => {
Expand Down
5 changes: 4 additions & 1 deletion src/helpers/getCssExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ export const getCssExports = ({
options,
processor,
compilerOptions,
directory,
}: {
css: string;
fileName: string;
logger: Logger;
options: Options;
processor: Processor;
compilerOptions: tsModule.CompilerOptions;
directory: string;
}): CSSExportsWithSourceMap => {
try {
const fileType = getFileType(fileName);
Expand All @@ -73,6 +75,7 @@ export const getCssExports = ({
{
syncImport: true,
filename: fileName,
paths: [directory],
...(rendererOptions.less ?? {}),
} as Less.Options,
(error?: Less.RenderError, output?: Less.RenderOutput) => {
Expand All @@ -91,7 +94,7 @@ export const getCssExports = ({
case FileType.sass: {
const filePath = getFilePath(fileName);
const { loadPaths, ...sassOptions } = rendererOptions.sass ?? {};
const { baseUrl, paths } = compilerOptions;
const { baseUrl = directory, paths } = compilerOptions;
const matchPath =
baseUrl && paths
? createMatchPath(path.resolve(baseUrl), paths)
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/getDtsSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const getDtsSnapshot = (
options: Options,
logger: Logger,
compilerOptions: tsModule.CompilerOptions,
directory: string,
): tsModule.IScriptSnapshot => {
const css = scriptSnapshot.getText(0, scriptSnapshot.getLength());

Expand All @@ -32,6 +33,7 @@ export const getDtsSnapshot = (
options,
processor,
compilerOptions,
directory,
});
const dts = createDtsExports({ cssExports, fileName, logger, options });
return ts.ScriptSnapshot.fromString(dts);
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ function init({ typescript: ts }: { typescript: typeof tsModule }) {
options,
logger,
compilerOptions,
directory,
);
}
const sourceFile = _createLanguageServiceSourceFile(
Expand Down Expand Up @@ -149,6 +150,7 @@ function init({ typescript: ts }: { typescript: typeof tsModule }) {
options,
logger,
compilerOptions,
directory,
);
}
sourceFile = _updateLanguageServiceSourceFile(
Expand Down