Skip to content

Commit 7bef83e

Browse files
committed
fix: remove node-style-text
node-stye-text has conflicts with interopDefault of vitest and jiti, and we actually do not need the chained calls it provides, so it is replaced with node:util
1 parent 2ec440e commit 7bef83e

9 files changed

Lines changed: 40 additions & 41 deletions

File tree

build.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,13 @@ export default defineBuildConfig({
55
rollup: {
66
inlineDependencies: ["node-style-text", "changelogen"],
77
},
8+
stubOptions: {
9+
jiti: {
10+
// debug: true,
11+
// // https://github.com/fisker/node-style-text/issues/27
12+
// interopDefault: false,
13+
// nativeModules: ["node-style-text"],
14+
},
15+
},
816
failOnWarn: false,
917
});

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
"eslint-plugin-format": "^1.0.2",
9797
"husky": "^9.1.7",
9898
"lint-staged": "^16.2.6",
99-
"node-style-text": "^2.1.2",
10099
"tsx": "^4.20.6",
101100
"typescript": "^5.9.3",
102101
"unbuild": "^3.6.1",

pnpm-lock.yaml

Lines changed: 1 addition & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/builder/fluent.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import type { BaseNode, Message, MessageReference, Resource } from "@fluent/synt
22
import type { BuildConfig } from "../../types/config.js";
33
import { readFile, writeFile } from "node:fs/promises";
44
import { basename, dirname } from "node:path";
5+
import { styleText } from "node:util";
56
import { parse, serialize, Transformer } from "@fluent/syntax";
67
import { move, outputFile } from "fs-extra/esm";
7-
import styleText from "node-style-text";
88
import { glob } from "tinyglobby";
99
import { logger } from "../../utils/logger.js";
1010
import { toArray } from "../../utils/string.js";
@@ -195,7 +195,7 @@ export class MessageManager {
195195
.filter(([_, messages]) => !messages.has(msg))
196196
.map(([locale]) => locale);
197197
if (missingLocales.length > 0)
198-
logger.warn(`I10N id ${styleText.blue(msg)} missing in locale: ${missingLocales.join(", ")}`);
198+
logger.warn(`I10N id ${styleText("blue", msg)} missing in locale: ${missingLocales.join(", ")}`);
199199
});
200200
}
201201

@@ -231,12 +231,12 @@ export function processHTMLFile(
231231
foundMessages.add(id);
232232

233233
if (ignores.includes(id)) {
234-
logger.debug(`Skipped ignored ID: ${styleText.blue(id)} in ${styleText.gray(filePath)}`);
234+
logger.debug(`Skipped ignored ID: ${styleText("blue", id)} in ${styleText("gray", filePath)}`);
235235
return match;
236236
}
237237

238238
if (!allMessages.has(id)) {
239-
logger.warn(`I10N id ${styleText.blue(id)} in path ${styleText.gray(filePath)} does not exist in any locale, skip renaming it.`);
239+
logger.warn(`I10N id ${styleText("blue", id)} in path ${styleText("gray", filePath)} does not exist in any locale, skip renaming it.`);
240240
return match;
241241
}
242242

src/core/builder/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Context } from "../../types/index.js";
22
import process from "node:process";
3+
import { styleText } from "node:util";
34
import { emptyDir } from "fs-extra/esm";
4-
import styleText from "node-style-text";
55
import { dateFormat } from "../../utils/string.js";
66
import { Base } from "../base.js";
77

@@ -29,7 +29,7 @@ export default class Build extends Base {
2929
const { dist, version } = this.ctx;
3030
const t = new Date();
3131
this.buildTime = dateFormat("YYYY-mm-dd HH:MM:SS", t);
32-
this.logger.info(`Building version ${styleText.blue(version)} to ${styleText.blue(dist)} at ${styleText.blue(this.buildTime)} in ${styleText.blue(process.env.NODE_ENV)} mode.`);
32+
this.logger.info(`Building version ${styleText("blue", version)} to ${styleText("blue", dist)} at ${styleText("blue", this.buildTime)} in ${styleText("blue", process.env.NODE_ENV)} mode.`);
3333
await this.ctx.hooks.callHook("build:init", this.ctx);
3434

3535
this.logger.tip("Preparing static assets", { space: 1 });

src/core/builder/prefs.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type { Prefs } from "../../utils/prefs-manager.js";
33
import { existsSync } from "node:fs";
44
import { readFile } from "node:fs/promises";
55
import { join } from "node:path";
6+
import { styleText } from "node:util";
67
import { outputFile } from "fs-extra/esm";
7-
import styleText from "node-style-text";
88
import { glob } from "tinyglobby";
99
import { logger } from "../../utils/logger.js";
1010
import { is32BitNumber } from "../../utils/number.js";
@@ -39,7 +39,7 @@ export default async function buildPrefs(dist: string, options: BuildConfig["pre
3939
Object.entries(prefs).forEach(([key, value]) => {
4040
if (typeof value === "number") {
4141
if (!is32BitNumber(value)) {
42-
logger.warn(`Pref key '${styleText.blue(key)}' is a number, but is more than 4 bytes, which can be problematic on some OS.`);
42+
logger.warn(`Pref key '${styleText("blue", key)}' is a number, but is more than 4 bytes, which can be problematic on some OS.`);
4343
}
4444
}
4545
});
@@ -67,20 +67,20 @@ export default async function buildPrefs(dist: string, options: BuildConfig["pre
6767
for (const match of matchs) {
6868
const [matched, key] = match;
6969
if (key.startsWith(prefix)) {
70-
logger.debug(`Pref key '${styleText.blue(key)}' is already starts with '${prefix}', skip prefixing it.`);
70+
logger.debug(`Pref key '${styleText("blue", key)}' is already starts with '${prefix}', skip prefixing it.`);
7171
continue;
7272
}
7373
else if (key.startsWith("extensions.")) {
74-
logger.warn(`Pref key '${styleText.blue(key)}' in ${styleText.gray(path)} starts with 'extensions.' but not '${styleText.blue(prefix)}', skip prefixing it.`);
74+
logger.warn(`Pref key '${styleText("blue", key)}' in ${styleText("gray", path)} starts with 'extensions.' but not '${styleText("blue", prefix)}', skip prefixing it.`);
7575
continue;
7676
}
7777
else if (!(key in prefsWithPrefix) && !(key in prefsWithoutPrefix)) {
78-
logger.warn(`Pref key '${styleText.blue(key)}' in ${styleText.gray(path)} is not found in prefs.js, skip prefixing it.`);
78+
logger.warn(`Pref key '${styleText("blue", key)}' in ${styleText("gray", path)} is not found in prefs.js, skip prefixing it.`);
7979
continue;
8080
}
8181
else {
8282
const prefixed = `${prefix}.${key}`;
83-
logger.debug(`Pref key '${styleText.blue(key)}' in ${styleText.gray(path)} is prefixed to ${styleText.blue(prefixed)}.`);
83+
logger.debug(`Pref key '${styleText("blue", key)}' in ${styleText("gray", path)} is prefixed to ${styleText("blue", prefixed)}.`);
8484
content = content.replace(matched, `preference="${prefixed}"`);
8585
}
8686
}

src/core/tester/http-reporter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import http from "node:http";
2-
import styleText from "node-style-text";
2+
import { styleText } from "node:util";
33
import { logger } from "../../utils/logger.js";
44
import { findFreeTcpPort } from "../../utils/zotero/remote-zotero.js";
55

@@ -132,10 +132,10 @@ export class TestHttpReporter {
132132
logger.tip(data.title, logger_option);
133133
break;
134134
case "pass":
135-
logger.success(`${data.title} ${styleText.gray(`${data.duration}ms`)}`, logger_option);
135+
logger.success(`${data.title} ${styleText("gray", `${data.duration}ms`)}`, logger_option);
136136
break;
137137
case "fail":{
138-
logger.fail(styleText.red(`${data.title}, ${data?.error?.message}`), logger_option);
138+
logger.fail(styleText("red", `${data.title}, ${data?.error?.message}`), logger_option);
139139
let expected = data.error.expected;
140140
let received = data.error.actual;
141141

@@ -154,8 +154,8 @@ export class TestHttpReporter {
154154
if (received && typeof received === "object")
155155
received = formatOutput(received, data.indents + 1);
156156

157-
logger.log(`Expected: ${styleText.green(String(expected))}`, { space: data.indents + 0.5 });
158-
logger.log(`Received: ${styleText.red(String(received))}`, { space: data.indents + 0.5 });
157+
logger.log(`Expected: ${styleText("green", String(expected))}`, { space: data.indents + 0.5 });
158+
logger.log(`Received: ${styleText("red", String(received))}`, { space: data.indents + 0.5 });
159159
break;
160160
}
161161
case "pending":

src/utils/logger.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import process from "node:process";
22
import readline from "node:readline";
3+
import { styleText } from "node:util";
34
import { isPlainObject } from "es-toolkit";
4-
import styleText from "node-style-text";
55
import { isDebug } from "std-env";
66

77
/**
@@ -19,13 +19,13 @@ export type LogLevelType = keyof typeof LOG_LEVEL;
1919

2020
// Configuration constants
2121
const SYMBOLS = {
22-
SUCCESS: styleText.green("✔"),
23-
INFO: styleText.blue("ℹ"),
24-
FAIL: styleText.red("✖"),
25-
TIP: styleText.blue("→"),
26-
ERROR: styleText.bgRed(" ERROR "),
27-
WARN: styleText.bgYellow(" WARN "),
28-
DEBUG: styleText.grey("⚙"),
22+
SUCCESS: styleText("green", "✔"),
23+
INFO: styleText("blue", "ℹ"),
24+
FAIL: styleText("red", "✖"),
25+
TIP: styleText("blue", "→"),
26+
ERROR: styleText("bgRed", " ERROR "),
27+
WARN: styleText("bgYellow", " WARN "),
28+
DEBUG: styleText("grey", "⚙"),
2929
NONE: "",
3030
};
3131

@@ -140,7 +140,7 @@ export class Logger {
140140
}
141141

142142
private formatError(error: Error): string {
143-
return `${styleText.red(error.name)}: ${styleText.red(error.message)}\n${error.stack}`;
143+
return `${styleText("red", error.name)}: ${styleText("red", error.message)}\n${error.stack}`;
144144
}
145145

146146
/**
@@ -200,7 +200,7 @@ export class Logger {
200200
}
201201

202202
public ready(content: string): void {
203-
this.logInternal(styleText.green(content), LOG_METHODS_CONFIG.success);
203+
this.logInternal(styleText("green", content), LOG_METHODS_CONFIG.success);
204204
}
205205

206206
public log(content: unknown, options?: LoggerOptions): void {

vitest.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { defineConfig } from "vitest/config";
22

33
export default defineConfig({
44
test: {
5-
deps: {
6-
// https://github.com/fisker/node-style-text/issues/27
7-
interopDefault: false,
8-
},
5+
// deps: {
6+
// // https://github.com/fisker/node-style-text/issues/27
7+
// interopDefault: false,
8+
// },
99
},
1010
},
1111
);

0 commit comments

Comments
 (0)