Skip to content

Commit

Permalink
fix: Fix exposed API
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Feb 28, 2025
1 parent d33455e commit da45c6e
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
},
"license": "MIT",
"author": "YFM Team <[email protected]>",
"main": "lib/index.js",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"exports": {
".": {
"types": "lib/index.d.ts",
"default": "lib/index.js"
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
}
},
"files": [
Expand Down
4 changes: 2 additions & 2 deletions src/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export function applyConditions(

if (!ifTag) {
// TODO(3y3): make lint rule
this.log.error(
this.logger.error(
`If block must be opened before close${path ? ` in ${chalk.bold(path)}` : ''}`,
);
break;
Expand All @@ -299,7 +299,7 @@ export function applyConditions(
}

if (tagStack.length !== 0) {
this.log.error(`Condition block must be closed${path ? ` in ${chalk.bold(path)}` : ''}`);
this.logger.error(`Condition block must be closed${path ? ` in ${chalk.bold(path)}` : ''}`);
}

return input;
Expand Down
8 changes: 4 additions & 4 deletions src/cycles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function inlineConditions(
let collection = evaluate.call(this, forTag.collectionName, vars);
if (!collection || !Array.isArray(collection)) {
collection = [];
this.log.error(`${chalk.bold(forTag.collectionName)} is undefined or not iterable`);
this.logger.error(`${chalk.bold(forTag.collectionName)} is undefined or not iterable`);
}

const results = collection.map((item) => {
Expand Down Expand Up @@ -133,7 +133,7 @@ export function applyCycles(

const matches = args.match(FOR_SYNTAX);
if (!matches) {
this.log.error(
this.logger.error(
`Incorrect syntax in if condition${path ? ` in ${chalk.bold(path)}` : ''}`,
);
break;
Expand All @@ -160,7 +160,7 @@ export function applyCycles(
const forTag = tagStack.pop();

if (!forTag) {
this.log.error(
this.logger.error(
`For block must be opened before close${path ? ` in ${chalk.bold(path)}` : ''}`,
);
break;
Expand All @@ -179,7 +179,7 @@ export function applyCycles(
}

if (tagStack.length !== 0) {
this.log.error(`For block must be closed${path ? ` in ${chalk.bold(path)}` : ''}`);
this.logger.error(`For block must be closed${path ? ` in ${chalk.bold(path)}` : ''}`);
}

return input;
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ export function liquidDocument(
return composedFrontmatter + liquidedResult;
}

export function createContext(log: Logger, settings?: Partial<LiquidSettings>): LiquidContext {
export function createContext(logger: Logger, settings?: Partial<LiquidSettings>): LiquidContext {
return {
log,
logger,
settings: {
cycles: true,
conditions: true,
Expand Down
4 changes: 2 additions & 2 deletions src/substitutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function applySubstitutions(
const value = substituteVariable.call(this, trimVarPath, vars);

if (value === undefined) {
this.log.warn(
this.logger.warn(
`Variable ${chalk.bold(trimVarPath)} not found${path ? ` in ${chalk.bold(path)}` : ''}`,
);

Expand All @@ -54,7 +54,7 @@ export function applySubstitutions(
const value = substituteVariable.call(this, trimVarPath, vars);

if (value === undefined) {
this.log.warn(
this.logger.warn(
`Variable ${chalk.bold(trimVarPath)} not found${path ? ` in ${chalk.bold(path)}` : ''}`,
);

Expand Down
2 changes: 1 addition & 1 deletion src/syntax/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function evaluate(

return evalValue(exp, scope, strict);
} catch (e) {
const log = this?.log || logger();
const log = this?.logger || logger();

if (e instanceof SkippedEvalError) {
log.warn(`Skip error: ${e}`);
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type Logger = {
log: (...args: unknown[]) => void;
info: (...args: unknown[]) => void;
warn: (...args: unknown[]) => void;
error: (...args: unknown[]) => void;
};
Expand All @@ -13,7 +13,7 @@ export type LiquidSettings = {
};

export type LiquidContext = {
log: Logger;
logger: Logger;
settings: LiquidSettings;
path?: string;
};
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function getObject(path: string, obj: Record<string, any>, fallback?: any

export function logger() {
return {
log: () => {},
info: () => {},
warn: () => {},
error: () => {},
};
Expand Down

0 comments on commit da45c6e

Please sign in to comment.