Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaces chalk with picocolors & fixes Hermes runtime #181

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,7 @@ docs/.vuepress/.temp
docs/.vuepress/.cache

# other environments
deno.lock
deno.lock

# intellij
.idea
12 changes: 6 additions & 6 deletions docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ property of the [UserConfiguration](#user-configuration).

### LevelConfiguration Interface

> Refer to the [ChalkJS documentation](https://github.com/chalk/chalk?tab=readme-ov-file#styles) for information about terminal style values.
> Refer to the [picocolors documentation](https://github.com/alexeyraspopov/picocolors#usage) for information about terminal style values.

```typescript
interface LevelConfiguration {
levelName: string;
level: number;
style: string;
terminalStyle: ChalkStyle[];
terminalStyle: ConsoleStyle[];
method: Method;
emoji: string;
}
Expand Down Expand Up @@ -210,12 +210,12 @@ to change the padding based on the browser environment. These functions are also

### Default Server Styles

Adze styling for the server makes use of a library named [Chalk](https://github.com/chalk/chalk).
Chalk exposes several formatting functions for server text styling that Adze exposes in its
Adze styling for the server makes use of a library named [picocolors](https://github.com/alexeyraspopov/picocolors).
picocolors exposes several formatting functions for server text styling that Adze exposes in its
configuration.

For a list of styles available for use with Chalk, refer to the
[Chalk styles documentation](https://github.com/chalk/chalk?tab=readme-ov-file#styles).
For a list of styles available for use with picocolors, refer to the
[picocolors styles documentation](https://github.com/alexeyraspopov/picocolors#usage).

#### Default Level Styles

Expand Down
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
{
"imports": {
"./src": "./dist/index.js",
"chalk": "./dist/functions/chalk-dummy.js",
"picocolors": "./dist/functions/picocolors-dummy.js",
"@ungap/structured-clone": "/node_modules/@ungap/structured-clone/esm/index.js",
"date-fns/formatISO": "/node_modules/date-fns/formatISO.mjs",
"date-fns/format": "/node_modules/date-fns/format.mjs"
}
Expand Down
67 changes: 34 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "adze",
"description": "A universal, modern, and extendable logging library for JavaScript and TypeScript.",
"version": "2.0.0",
"main": "index.js",
"main": "dist/index.js",
AJStacy marked this conversation as resolved.
Show resolved Hide resolved
"type": "module",
"engines": {
"node": ">=18.19.0"
Expand Down Expand Up @@ -57,6 +57,7 @@
"@types/eslint__js": "^8.42.3",
"@types/eslint-config-prettier": "^6.11.3",
"@types/jsdom": "^21.1.7",
"@types/ungap__structured-clone": "1.2.0",
"@vitest/ui": "^2.0.5",
"@vuepress/bundler-vite": "^2.0.0-rc.7",
"@vuepress/plugin-markdown-container": "^2.0.0-rc.42",
Expand Down Expand Up @@ -87,8 +88,10 @@
"**/*.{js,ts}": "eslint --fix"
},
"dependencies": {
"@ungap/structured-clone": "1.2.0",
AJStacy marked this conversation as resolved.
Show resolved Hide resolved
"chalk": "^5.3.0",
"date-fns": "^3.6.0",
"chalk": "^5.3.0"
"picocolors": "1.1.1"
},
"size-limit": [
{
Expand Down
4 changes: 2 additions & 2 deletions src/_types/log.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import adze, { ChalkStyle, ConfigurationData } from '..';
import adze, { ConsoleStyle, ConfigurationData } from '..';
import {
methodsWithArgs,
levels,
Expand Down Expand Up @@ -100,7 +100,7 @@ export interface LevelConfiguration {
levelName: string;
level: number;
style: string;
terminalStyle: ChalkStyle[];
terminalStyle: ConsoleStyle[];
method: Method;
emoji: string;
}
Expand Down
13 changes: 5 additions & 8 deletions src/_types/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const styles_raw = [
'cyan',
'white',
'gray',
'grey',
'blackBright',
'redBright',
'greenBright',
Expand All @@ -25,8 +24,6 @@ const styles_raw = [
'bgMagenta',
'bgCyan',
'bgWhite',
'bgGray',
'bgGrey',
'bgBlackBright',
'bgRedBright',
'bgGreenBright',
Expand All @@ -43,15 +40,15 @@ const styles_raw = [
'inverse',
'hidden',
'strikethrough',
'visible',
] as const;

type StylesRaw = typeof styles_raw;
/**
* String union representing all possible Chalk styles.
* String union representing all possible Console styles.
*/
export type ChalkStyle = (typeof styles_raw)[number];
export type ConsoleStyle = StylesRaw[number];

/**
* Immutable array of all possible chalk styles.
* Immutable array of all possible console styles.
*/
export const chalk_styles = Object.freeze(styles_raw);
export const console_styles = Object.freeze(styles_raw);
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export function getLogConfig(overrides: Partial<LevelConfiguration> = {}): Level
level: 6,
style:
'font-size: 12px; border-radius: 4px; padding-right: 51px; background: linear-gradient(to right, #ecedef, #d9dce0); color: #333435; border-color: #bfc1c5;',
terminalStyle: ['white', 'bgGray'],
terminalStyle: ['white', 'bgBlackBright'],
method: 'log',
emoji: '🪵',
...overrides,
Expand Down
4 changes: 2 additions & 2 deletions src/formatters/pretty/pretty.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Formatter from '../formatter';
import {
addPadding,
applyChalkStyles,
applyStyles,
formatAssert,
formatCount,
formatIf,
Expand Down Expand Up @@ -36,7 +36,7 @@ export default class PrettyFormatter extends Formatter {
const leader = `${leaderRaw} `;
const meta = this.formatMeta(mods, timestamp);

const styledLeader = applyChalkStyles(leader, this.level.terminalStyle);
const styledLeader = applyStyles(leader, this.level.terminalStyle);

message.push(styledLeader);
meta !== '' ? message.push(meta) : null;
Expand Down
4 changes: 0 additions & 4 deletions src/functions/chalk-dummy.ts

This file was deleted.

7 changes: 6 additions & 1 deletion src/functions/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ export function isGlobalInitialized(global: unknown): global is AdzeGlobal {
* Validates that the current environment is `Window`.
*/
export function isBrowser(): boolean {
return typeof window !== 'undefined' && !isDeno();
return (
typeof window !== 'undefined' &&
typeof window.location !== 'undefined' &&
typeof window.navigator.userAgent !== 'undefined' &&
!isDeno()
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/functions/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './chalk-dummy';
export * from './picocolors-dummy';
export * from './data';
export * from './filters';
export * from './formatters';
Expand Down
2 changes: 2 additions & 0 deletions src/functions/picocolors-dummy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* eslint-disable */
export const picocolors = {};
4 changes: 4 additions & 0 deletions src/functions/picocolors-loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as _picocolors from 'picocolors';

//@ts-expect-error - This is workaround for not having picocolors exported as esm module.
export const picocolors = (_picocolors.default ?? _picocolors) as typeof _picocolors;
1 change: 1 addition & 0 deletions src/functions/seal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Modifier, ModifierData } from '..';
import { Configuration } from '../configuration';
import Log from '../log';
import structuredClone from '@ungap/structured-clone';

/**
* Required type for creating mixins in TypeScript.
Expand Down
Loading