Skip to content

Commit

Permalink
fix(types): index and utils
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoTomeES committed Nov 4, 2023
1 parent ec9c2a3 commit fe4bbec
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 28 deletions.
10 changes: 2 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from './utils.js';

import type { AstroIntegration } from 'astro';
import type { InteralRenameOptions, RenameOptions } from './types.js';
import type { InternalRenameOptions, RenameOptions } from './types.js';

export default function renameIntegration(
options?: RenameOptions,
Expand Down Expand Up @@ -60,7 +60,7 @@ export default function renameIntegration(
options?.rename?.outputMapCallback?.(map);
},
},
} satisfies InteralRenameOptions;
} satisfies InternalRenameOptions;

return {
name: 'astro-rename',
Expand All @@ -74,16 +74,10 @@ export default function renameIntegration(
} catch (_) {}

updateConfig({
// TODO: Check types
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
vite: await getViteConfiguration(_options?.rename, config.vite),
});
},
'astro:config:done': async ({ config }) => {
// TODO: Check types
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (config.output !== 'static') {
throw new Error(
`[astrojs-rename] \`output: "static"\` is only supported right now for this plugin.`,
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export type RenameOptions =
}
| undefined;

export type InteralRenameOptions = {
export type InternalRenameOptions = {
rename: {
strategy: PostcssRenameOptions['strategy'];
by: PostcssRenameOptions['by'];
Expand Down
25 changes: 6 additions & 19 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { resolve } from 'node:path';
import postcssRename from 'postcss-rename';

import type { AstroConfig } from 'astro';
import type { RenameOptions } from './types.js';
import type { InternalRenameOptions } from './types.js';
import type { Options as PostcssRenameOptions } from 'postcss-rename';
import type { CSSOptions, UserConfig } from 'vite'; // import CSSOptions type

export const MAPS_DIRECTORY = './class-maps';

Expand All @@ -12,10 +14,7 @@ export const escapeRegExp = (string: string) =>
export const calculatePercent = (before: number, after: number) =>
(100 - (after / before) * 100) | 0;

// TODO: Check types
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
export async function* walkFiles(dir: string) {
export async function* walkFiles(dir: string): AsyncGenerator<string> {
const dirents = await readdir(dir, { withFileTypes: true });

for (const dirent of dirents) {
Expand All @@ -27,13 +26,7 @@ export async function* walkFiles(dir: string) {
}

export const getPostCssConfig = async (
// TODO: Check types
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
root: UserConfig['root'],
// TODO: Check types
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
postcssInlineOptions: CSSOptions['postcss'],
) => {
let postcssConfigResult;
Expand Down Expand Up @@ -61,13 +54,7 @@ export const getPostCssConfig = async (
};

export const getViteConfiguration = async (
// TODO: Check types
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
options: RenameOptions['rename'],
// TODO: Check types
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
options: InternalRenameOptions['rename'],
viteConfig: AstroConfig['vite'],
) => {
// We need to manually load postcss config files because when inlining the tailwind and autoprefixer plugins,
Expand All @@ -83,7 +70,7 @@ export const getViteConfiguration = async (
? postcssConfigResult.plugins.slice()
: [];

postcssPlugins.push(postcssRename(options));
postcssPlugins.push(postcssRename(options as PostcssRenameOptions));

return {
css: {
Expand Down

0 comments on commit fe4bbec

Please sign in to comment.