Skip to content

Commit 4c8bed5

Browse files
committed
fix: 🐛 linter
1 parent 4b4d9f0 commit 4c8bed5

5 files changed

Lines changed: 34 additions & 28 deletions

File tree

plugins/css-colocate/css-preprocess.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import postcss from 'postcss';
44
import postcssModules from 'postcss-modules';
55
import { getTempDir, findFiles, generateScopedName } from './utils';
66

7-
export async function preprocessCssModules(rootDir: string): Promise<void> {
7+
export const preprocessCssModules = async (rootDir: string): Promise<void> => {
88
const srcDir = path.join(rootDir, 'src');
99
const tempDir = getTempDir(rootDir);
1010

@@ -50,4 +50,4 @@ export async function preprocessCssModules(rootDir: string): Promise<void> {
5050
console.log(
5151
`\n✅ Pre-processing complete: ${files.length} file(s), ${totalClasses} class(es)\n`
5252
);
53-
}
53+
};

plugins/css-colocate/import-inject.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const copyAndResolveCss = async (
5252
jsOutputFile: string
5353
): Promise<string | null> => {
5454
const cssSourcePath = resolveCssPath(cssImportPath, sourceFile, srcDir);
55-
if (!cssSourcePath || !(await fileExists(cssSourcePath))) return null;
55+
if (!cssSourcePath || !(await fileExists(cssSourcePath))) {return null;}
5656

5757
const cssRelativeToSrc = path.relative(srcDir, cssSourcePath);
5858
const cssOutputPath = path.join(distDir, cssRelativeToSrc);
@@ -111,10 +111,10 @@ export const injectComponentCss = async (
111111
const component = path.basename(dir);
112112
const cssFile = path.join(dir, `${component}.css`);
113113

114-
if (!(await fileExists(cssFile))) continue;
114+
if (!(await fileExists(cssFile))) {continue;}
115115

116116
const content = await fs.readFile(jsFile, 'utf-8');
117-
if (content.includes(`${component}.css`)) continue;
117+
if (content.includes(`${component}.css`)) {continue;}
118118

119119
const importStmt = createImportStatement(`./${component}.css`, format) + '\n';
120120
const updated = insertAtTop(content, importStmt);
@@ -133,7 +133,7 @@ export const injectRegularCssImports = async (
133133
distDir: string,
134134
format: 'esm' | 'cjs'
135135
): Promise<void> => {
136-
if (trackedImports.length === 0) return;
136+
if (trackedImports.length === 0) {return;}
137137

138138
const srcDir = path.join(rootDir, 'src');
139139

@@ -144,7 +144,7 @@ export const injectRegularCssImports = async (
144144
relativeToSrc.replace(/\.tsx?$/, `.${format === 'esm' ? 'js' : 'cjs'}`)
145145
);
146146

147-
if (!(await fileExists(jsOutputFile))) continue;
147+
if (!(await fileExists(jsOutputFile))) {continue;}
148148

149149
let content = await fs.readFile(jsOutputFile, 'utf-8');
150150

plugins/css-colocate/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,28 @@ export const cssColocatePlugin = (): Plugin => {
2727
name: 'vite-plugin-css-colocate',
2828
apply: 'build',
2929

30-
async buildStart() {
30+
buildStart: async () => {
3131
// WARN: Reset between rebuilds
3232
// to prevent future build:watch transform to keep
3333
// appending, causing duplicate CSS imports
3434
// on each rebuild
3535
trackedImports.length = 0;
36+
3637
await preprocessCssModules(config.root);
3738
},
3839

39-
configResolved(resolvedConfig) {
40+
configResolved: resolvedConfig => {
4041
config = resolvedConfig;
4142
},
4243

43-
async resolveId(id, importer) {
44-
return resolveCssModule(id, importer, config.root);
45-
},
44+
resolveId: async (id, importer) => resolveCssModule(id, importer, config.root),
4645

4746
async load(id) {
4847
return loadCssModule(id, this, config.root);
4948
},
5049

51-
transform(code, id) {
52-
if (id.includes('node_modules') || !/\.[jt]sx?$/.test(id)) return null;
50+
transform: (code, id) => {
51+
if (id.includes('node_modules') || !/\.[jt]sx?$/.test(id)) {return null;}
5352

5453
// Track regular CSS imports (not .module.css)
5554
const cssImports: string[] = [];
@@ -69,7 +68,7 @@ export const cssColocatePlugin = (): Plugin => {
6968
return null;
7069
},
7170

72-
async closeBundle() {
71+
closeBundle: async () => {
7372
const formats = [
7473
{ format: 'esm' as const, ext: 'js' as const },
7574
{ format: 'cjs' as const, ext: 'cjs' as const },

plugins/css-colocate/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const preventCssNameOverwrites = async (rootDir: string): Promise<void> =
5151

5252
const srcFiles = await findFiles(srcDir, '**/*.css');
5353
for (const file of srcFiles) {
54-
if (file.endsWith('.module.css')) continue;
54+
if (file.endsWith('.module.css')) {continue;}
5555

5656
const destPath = path.relative(srcDir, file);
5757

@@ -82,7 +82,7 @@ export const copyCssFiles = async (rootDir: string, distDir: string): Promise<vo
8282
const srcFiles = await findFiles(srcDir, '**/*.css');
8383
await Promise.all(
8484
srcFiles.map(async file => {
85-
if (file.endsWith('.module.css')) return;
85+
if (file.endsWith('.module.css')) {return;}
8686
const dest = path.join(distDir, path.relative(srcDir, file));
8787
await fs.ensureDir(path.dirname(dest));
8888
await fs.copy(file, dest, { overwrite: true });

plugins/css-colocate/virtual-modules.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import { getTempDir } from './utils';
55

66
const VIRTUAL_PREFIX = 'virtual:css-module:';
77

8-
export async function resolveCssModule(
8+
export const resolveCssModule = async (
99
id: string,
1010
importer: string | undefined,
1111
rootDir: string
12-
): Promise<string | null> {
13-
if (!id.endsWith('.module.css') || !importer) return null;
12+
): Promise<string | null> => {
13+
if (!id.endsWith('.module.css') || !importer) {
14+
return null;
15+
}
1416

1517
const resolved = path.resolve(path.dirname(importer), id);
1618
const relative = path.relative(path.join(rootDir, 'src'), resolved);
@@ -19,17 +21,21 @@ export async function resolveCssModule(
1921
relative.replace('.module.css', '.module.json')
2022
);
2123

22-
if (!(await fs.pathExists(jsonPath))) return null;
24+
if (!(await fs.pathExists(jsonPath))) {
25+
return null;
26+
}
2327

2428
return VIRTUAL_PREFIX + relative;
25-
}
29+
};
2630

27-
export async function loadCssModule(
31+
export const loadCssModule = async (
2832
id: string,
2933
ctx: PluginContext,
3034
rootDir: string
31-
): Promise<string | null> {
32-
if (!id.startsWith(VIRTUAL_PREFIX)) return null;
35+
): Promise<string | null> => {
36+
if (!id.startsWith(VIRTUAL_PREFIX)) {
37+
return null;
38+
}
3339

3440
const relative = id.slice(VIRTUAL_PREFIX.length);
3541
const jsonPath = path.join(
@@ -48,7 +54,8 @@ export async function loadCssModule(
4854
})
4955
.join(',\n ');
5056
return `export default {\n ${exports}\n};`;
51-
} catch (e: any) {
52-
ctx.error(`Failed to load CSS module from ${jsonPath}: ${e.message}`);
57+
} catch (e) {
58+
const msg = e instanceof Error ? e.message : String(e);
59+
ctx.error(`Failed to load CSS module from ${jsonPath}: ${msg}`);
5360
}
54-
}
61+
};

0 commit comments

Comments
 (0)