Skip to content

Commit 25fc061

Browse files
committed
Replaced chalk by ansis to keep Pongo compatible with CommonJS
It seems that Chalk from v5 is ESModules-only
1 parent 7e86922 commit 25fc061

File tree

9 files changed

+65
-46
lines changed

9 files changed

+65
-46
lines changed

src/package-lock.json

Lines changed: 19 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@event-driven-io/pongo-core",
3-
"version": "0.16.3",
3+
"version": "0.16.4-alpha.1",
44
"description": "Pongo - Mongo with strong consistency on top of Postgres",
55
"type": "module",
66
"engines": {
@@ -88,11 +88,11 @@
8888
"vitepress": "^1.3.3"
8989
},
9090
"peerDependencies": {
91+
"cli-table3": "^0.6.5",
92+
"commander": "^12.1.0",
9193
"pg": "^8.12.0",
9294
"pg-connection-string": "^2.6.4",
93-
"chalk": "^5.3.0",
94-
"cli-table3": "^0.6.5",
95-
"commander": "^12.1.0"
95+
"ansis": "^3.3.2"
9696
},
9797
"dependencies": {
9898
"@types/benchmark": "^2.1.5",

src/packages/dumbo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@event-driven-io/dumbo",
3-
"version": "0.12.0",
3+
"version": "0.12.1-alpha.1",
44
"description": "Dumbo - tools for dealing with PostgreSQL",
55
"type": "module",
66
"scripts": {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import ansis from 'ansis';
2+
3+
let enableColors = true;
4+
5+
export const color = {
6+
set level(value: 0 | 1) {
7+
enableColors = value === 1;
8+
},
9+
hex:
10+
(value: string) =>
11+
(text: string): string =>
12+
enableColors ? ansis.hex(value)(text) : text,
13+
red: (value: string): string => (enableColors ? ansis.red(value) : value),
14+
green: (value: string): string => (enableColors ? ansis.green(value) : value),
15+
blue: (value: string): string => (enableColors ? ansis.blue(value) : value),
16+
cyan: (value: string): string => (enableColors ? ansis.cyan(value) : value),
17+
yellow: (value: string): string =>
18+
enableColors ? ansis.yellow(value) : value,
19+
};
20+
21+
export default color;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * from './color';
12
export * from './pretty';

src/packages/dumbo/src/core/tracing/printing/pretty.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chalk from 'chalk';
1+
import chalk from './color';
22

33
const TWO_SPACES = ' ';
44

src/packages/dumbo/src/core/tracing/printing/pretty.unit.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from 'assert';
2-
import chalk from 'chalk';
32
import { describe, it } from 'node:test';
3+
import chalk from './color';
44
import { prettyJson } from './pretty';
55

66
void describe('prettyPrintJson', () => {

src/packages/pongo/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@event-driven-io/pongo",
3-
"version": "0.16.3",
3+
"version": "0.16.4-alpha.1",
44
"description": "Pongo - Mongo with strong consistency on top of Postgres",
55
"type": "module",
66
"scripts": {
@@ -87,13 +87,13 @@
8787
"pongo": "./dist/cli.js"
8888
},
8989
"peerDependencies": {
90-
"@event-driven-io/dumbo": "0.12.0",
90+
"@event-driven-io/dumbo": "0.12.1-alpha.1",
9191
"@types/mongodb": "^4.0.7",
9292
"@types/pg": "^8.11.6",
9393
"@types/uuid": "^10.0.0",
9494
"pg": "^8.12.0",
9595
"uuid": "^10.0.0",
96-
"chalk": "^5.3.0",
96+
"ansis": "^3.3.2",
9797
"cli-table3": "^0.6.5",
9898
"commander": "^12.1.0",
9999
"pg-connection-string": "^2.6.4"

src/packages/pongo/src/commandLine/shell.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {
22
checkConnection,
3+
color,
34
LogLevel,
45
LogStyle,
56
prettyJson,
67
SQL,
78
type MigrationStyle,
89
} from '@event-driven-io/dumbo';
9-
import chalk from 'chalk';
1010
import Table from 'cli-table3';
1111
import { Command } from 'commander';
1212
import repl from 'node:repl';
@@ -52,7 +52,7 @@ const printOutput = (obj: any): string =>
5252
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5353
const displayResultsAsTable = (results: any[]): string => {
5454
if (results.length === 0) {
55-
return chalk.yellow('No documents found.');
55+
return color.yellow('No documents found.');
5656
}
5757

5858
const columnNames = results
@@ -66,7 +66,7 @@ const displayResultsAsTable = (results: any[]): string => {
6666
const columnWidths = calculateColumnWidths(results, columnNames);
6767

6868
const table = new Table({
69-
head: columnNames.map((col) => chalk.cyan(col)),
69+
head: columnNames.map((col) => color.cyan(col)),
7070
colWidths: columnWidths,
7171
});
7272

@@ -124,10 +124,10 @@ const startRepl = async (options: {
124124
setLogLevel(process.env.DUMBO_LOG_LEVEL ?? options.logging.logLevel);
125125
setLogStyle(process.env.DUMBO_LOG_STYLE ?? options.logging.logStyle);
126126

127-
console.log(chalk.green('Starting Pongo Shell (version: 0.16.3)'));
127+
console.log(color.green('Starting Pongo Shell (version: 0.16.4-alpha.1)'));
128128

129129
if (options.logging.printOptions) {
130-
console.log(chalk.green('With Options:'));
130+
console.log(color.green('With Options:'));
131131
console.log(prettyJson(options));
132132
}
133133

@@ -138,7 +138,7 @@ const startRepl = async (options: {
138138

139139
if (!(options.connectionString ?? process.env.DB_CONNECTION_STRING)) {
140140
console.log(
141-
chalk.yellow(
141+
color.yellow(
142142
`No connection string provided, using: 'postgresql://postgres:postgres@localhost:5432/postgres'`,
143143
),
144144
);
@@ -149,28 +149,28 @@ const startRepl = async (options: {
149149
if (!connectionCheck.successful) {
150150
if (connectionCheck.errorType === 'ConnectionRefused') {
151151
console.error(
152-
chalk.red(
152+
color.red(
153153
`Connection was refused. Check if the PostgreSQL server is running and accessible.`,
154154
),
155155
);
156156
} else if (connectionCheck.errorType === 'Authentication') {
157157
console.error(
158-
chalk.red(
158+
color.red(
159159
`Authentication failed. Check the username and password in the connection string.`,
160160
),
161161
);
162162
} else {
163-
console.error(chalk.red('Error connecting to PostgreSQL server'));
163+
console.error(color.red('Error connecting to PostgreSQL server'));
164164
}
165-
console.log(chalk.red('Exiting Pongo Shell...'));
165+
console.log(color.red('Exiting Pongo Shell...'));
166166
process.exit();
167167
}
168168

169-
console.log(chalk.green(`Successfully connected`));
170-
console.log(chalk.green('Use db.<collection>.<method>() to query.'));
169+
console.log(color.green(`Successfully connected`));
170+
console.log(color.green('Use db.<collection>.<method>() to query.'));
171171

172172
const shell = repl.start({
173-
prompt: chalk.green('pongo> '),
173+
prompt: color.green('pongo> '),
174174
useGlobal: true,
175175
breakEvalOnSigint: true,
176176
writer: printOutput,
@@ -237,7 +237,7 @@ const startRepl = async (options: {
237237
};
238238

239239
const teardown = async () => {
240-
console.log(chalk.yellow('Exiting Pongo Shell...'));
240+
console.log(color.yellow('Exiting Pongo Shell...'));
241241
await pongo.close();
242242
};
243243

0 commit comments

Comments
 (0)