Skip to content

Commit

Permalink
chore: use root from vite config if root is not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernankez committed Mar 13, 2024
1 parent cb6b519 commit c3dbde6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { CompressFont, FontCarrierOptions, FontInfo, OutputAsset } from "./
import { JS_EXT, LOG_PREFIX } from "./const";

const FontCarrier: (options: FontCarrierOptions) => PluginOption = (options) => {
const { cwd = process.cwd(), fonts, type, logLevel, clearScreen } = options;
let { root, fonts, type, logLevel, clearScreen } = options;

let fontList: CompressFont[] = [];

Expand All @@ -23,14 +23,15 @@ const FontCarrier: (options: FontCarrierOptions) => PluginOption = (options) =>

async function resolveFontList() {
const fontList = [];
assert(root, "Project root must be specified");
for (const font of fonts) {
let underPublicDir = false;
let path: string;
if (isAbsolute(font.path)) {
underPublicDir = true;
path = resolve(cwd, resolvedConfig.publicDir, font.path.slice(1));
path = resolve(root, resolvedConfig.publicDir, font.path.slice(1));
} else {
path = resolve(cwd, font.path);
path = resolve(root, font.path);
}
fontList.push({
path,
Expand Down Expand Up @@ -120,6 +121,7 @@ const FontCarrier: (options: FontCarrierOptions) => PluginOption = (options) =>
resolvedConfig = config;
resolver = resolvedConfig.createResolver();
logger = logLevel ? createLogger(logLevel, { allowClearScreen: clearScreen }) : config.logger;
root = root || resolvedConfig.root;
fontList = await resolveFontList();
},
transform: {
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Font as FCFont } from "font-carrier";

export interface FontCarrierOptions {
fonts: Font[];
cwd?: string;
root?: string;
type?: FCFont.FontType;
logLevel?: LogLevel;
clearScreen?: boolean;
Expand Down

0 comments on commit c3dbde6

Please sign in to comment.