Skip to content

Commit

Permalink
Merge pull request #181 from tiagobnobrega/picocolors
Browse files Browse the repository at this point in the history
Replaces chalk with picocolors & fixes Hermes runtime
  • Loading branch information
AJStacy authored Oct 29, 2024
2 parents 55e9a54 + 9e8596f commit 7bf7d93
Show file tree
Hide file tree
Showing 21 changed files with 149 additions and 138 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ jobs:
uses: actions/download-artifact@v4
with:
name: dist
path: ./dist
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
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
72 changes: 37 additions & 35 deletions package-lock.json

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

6 changes: 4 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",
"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,9 @@
"**/*.{js,ts}": "eslint --fix"
},
"dependencies": {
"@ungap/structured-clone": "1.2.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
Loading

0 comments on commit 7bf7d93

Please sign in to comment.