forked from mrmckeb/typescript-plugin-css-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetDtsSnapshot.ts
30 lines (29 loc) · 867 Bytes
/
getDtsSnapshot.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { readFileSync } from 'fs';
import type tsModule from 'typescript/lib/tsserverlibrary';
import { Options } from '../options';
import { getCssExports } from './getCssExports';
import { createDtsExports } from './createDtsExports';
import { Logger } from './logger';
import Processor from 'postcss/lib/processor';
export const getDtsSnapshot = (
ts: typeof tsModule,
processor: Processor,
fileName: string,
options: Options,
logger: Logger,
compilerOptions: tsModule.CompilerOptions,
directory: string,
): tsModule.IScriptSnapshot => {
const css = readFileSync(fileName, 'utf-8');
const cssExports = getCssExports({
css,
fileName,
logger,
options,
processor,
compilerOptions,
directory,
});
const dts = createDtsExports({ cssExports, fileName, logger, options });
return ts.ScriptSnapshot.fromString(dts);
};