Skip to content

Commit dcbcd8a

Browse files
committed
fix: fix by new eslint config
refactor: use template literals for constant declaration The constant 'name' in the core index file has been refactored to use template literals instead of single quotes. This change does not affect the functionality but aligns with the code style guidelines.
1 parent b684e38 commit dcbcd8a

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

packages/unplugin-typia/src/core/cache.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export async function getCache(
2929
if (!option.enable) {
3030
return null;
3131
}
32-
prepareCacheDir(option);
32+
await prepareCacheDir(option);
3333

3434
const key = getKey(id, source);
3535
const path = getCachePath(key, option);
@@ -74,7 +74,7 @@ export async function setCache(
7474
if (!option.enable) {
7575
return;
7676
}
77-
prepareCacheDir(option);
77+
await prepareCacheDir(option);
7878

7979
const key = getKey(id, source);
8080
const path = getCachePath(key, option);
@@ -87,7 +87,7 @@ export async function setCache(
8787

8888
const cache = data + hashComment;
8989
if (isBun()) {
90-
Bun.write(path, cache, { createPath: true });
90+
await Bun.write(path, cache, { createPath: true });
9191
}
9292
else {
9393
await writeFile(path, cache, { encoding: 'utf8' });
@@ -125,13 +125,14 @@ async function prepareCacheDir(option: ResolvedCacheOptions) {
125125
if (cacheDir != null) {
126126
return;
127127
}
128-
await mkdir(option.base, { recursive: true });
128+
const _cacheDir = option.base;
129+
await mkdir(_cacheDir, { recursive: true });
129130

130-
if (!isWritable) {
131+
if (!await isWritable(_cacheDir)) {
131132
throw new Error('Cache directory is not writable.');
132133
}
133134

134-
cacheDir = option.base;
135+
cacheDir = _cacheDir;
135136
}
136137

137138
async function isWritable(filename: string): Promise<boolean> {

packages/unplugin-typia/src/core/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { transformTypia } from './typia.js';
1212
import { getCache, setCache } from './cache.js';
1313
import { log } from './utils.js';
1414

15-
const name = 'unplugin-typia' as const;
15+
const name = `unplugin-typia`;
1616

1717
/**
1818
* Create a filter function from the given include and exclude patterns.
@@ -36,7 +36,7 @@ const unpluginFactory: UnpluginFactory<
3636

3737
const { cache: cacheOptions, log: logOption } = options;
3838

39-
if (logOption) {
39+
if (logOption !== false) {
4040
log(
4141
'box',
4242
cacheOptions.enable ? `Cache enabled` : `Cache disabled`,

packages/unplugin-typia/src/next.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ import type { Options } from './core/options.js';
2828
* );
2929
* ```
3030
*/
31-
function next(nextConfig: Record<string, any> = {}, options: Options): Record<string, any> {
31+
function next(nextConfig: Record<string, unknown> = {}, options: Options): Record<string, unknown> {
3232
return {
3333
...nextConfig,
34-
webpack(config: Record<string, any>, webpackOptions: Record<string, any>) {
35-
config.plugins.unshift(webpack(options));
34+
webpack(config: Record<string, unknown>, webpackOptions: Record<string, unknown>) {
35+
if (Array.isArray(config?.plugins)) {
36+
config.plugins.unshift(webpack(options));
37+
}
3638

37-
if (typeof nextConfig.webpack === 'function') {
38-
return nextConfig.webpack(config, webpackOptions);
39+
if (typeof nextConfig?.webpack === 'function') {
40+
return nextConfig.webpack(config, webpackOptions) as Record<string, unknown>;
3941
}
4042

4143
return config;

packages/unplugin-typia/test/cache.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function removeComments(data: string | null) {
1212
if (data == null) {
1313
return data;
1414
}
15+
16+
// eslint-disable-next-line regexp/no-unused-capturing-group
1517
return data.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '');
1618
}
1719

0 commit comments

Comments
 (0)