Skip to content

Commit 87e1aef

Browse files
authored
refactor: include diagnostics within CSSModule object (#274)
1 parent d1c2051 commit 87e1aef

File tree

13 files changed

+596
-613
lines changed

13 files changed

+596
-613
lines changed

.changeset/icy-pets-wave.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@css-modules-kit/core': minor
3+
'@css-modules-kit/ts-plugin': patch
4+
'@css-modules-kit/codegen': patch
5+
---
6+
7+
refactor: include diagnostics within `CSSModule` object

packages/codegen/src/runner.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type {
55
Diagnostic,
66
DiagnosticWithLocation,
77
MatchesPattern,
8-
ParseCSSModuleResult,
98
Resolver,
109
} from '@css-modules-kit/core';
1110
import {
@@ -27,7 +26,7 @@ import type { Logger } from './logger/logger.js';
2726
/**
2827
* @throws {ReadCSSModuleFileError} When failed to read CSS Module file.
2928
*/
30-
async function parseCSSModuleByFileName(fileName: string, config: CMKConfig): Promise<ParseCSSModuleResult> {
29+
async function parseCSSModuleByFileName(fileName: string, config: CMKConfig): Promise<CSSModule> {
3130
let text: string;
3231
try {
3332
text = await readFile(fileName, 'utf-8');
@@ -96,19 +95,17 @@ export async function runCMK(args: ParsedArgs, logger: Logger): Promise<void> {
9695
// eslint-disable-next-line n/no-process-exit
9796
process.exit(1);
9897
}
99-
const parseResults = await Promise.all(fileNames.map(async (fileName) => parseCSSModuleByFileName(fileName, config)));
100-
for (const parseResult of parseResults) {
101-
cssModuleMap.set(parseResult.cssModule.fileName, parseResult.cssModule);
102-
syntacticDiagnostics.push(...parseResult.diagnostics);
98+
const cssModules = await Promise.all(fileNames.map(async (fileName) => parseCSSModuleByFileName(fileName, config)));
99+
for (const cssModule of cssModules) {
100+
cssModuleMap.set(cssModule.fileName, cssModule);
101+
syntacticDiagnostics.push(...cssModule.diagnostics);
103102
}
104103

105104
if (args.clean) {
106105
await rm(config.dtsOutDir, { recursive: true, force: true });
107106
}
108107
await Promise.all(
109-
parseResults.map(async (parseResult) =>
110-
writeDtsByCSSModule(parseResult.cssModule, config, resolver, matchesPattern),
111-
),
108+
cssModules.map(async (cssModule) => writeDtsByCSSModule(cssModule, config, resolver, matchesPattern)),
112109
);
113110

114111
if (syntacticDiagnostics.length > 0) {
@@ -120,7 +117,7 @@ export async function runCMK(args: ParsedArgs, logger: Logger): Promise<void> {
120117
const getCSSModule = (path: string) => cssModuleMap.get(path);
121118
const exportBuilder = createExportBuilder({ getCSSModule, matchesPattern, resolver });
122119
const semanticDiagnostics: Diagnostic[] = [];
123-
for (const { cssModule } of parseResults) {
120+
for (const cssModule of cssModules) {
124121
const diagnostics = checkCSSModule(cssModule, config, exportBuilder, matchesPattern, resolver, getCSSModule);
125122
semanticDiagnostics.push(...diagnostics);
126123
}

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export type { CMKConfig } from './config.js';
22
export { readConfigFile } from './config.js';
33
export { TsConfigFileNotFoundError, SystemError } from './error.js';
4-
export { parseCSSModule, type ParseCSSModuleOptions, type ParseCSSModuleResult } from './parser/css-module-parser.js';
4+
export { parseCSSModule, type ParseCSSModuleOptions } from './parser/css-module-parser.js';
55
export { parseRule } from './parser/rule-parser.js';
66
export {
77
type Location,

0 commit comments

Comments
 (0)