Skip to content

Commit 2103223

Browse files
committed
chore(4.0.0-rc.5): package optimisations
1 parent 28a21d3 commit 2103223

File tree

10 files changed

+66
-55
lines changed

10 files changed

+66
-55
lines changed

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Both are [recommended](https://github.com/es-tooling/module-replacements/blob/ma
105105
The package size in `node_modules` directory:
106106

107107
- `picocolors`: [6.37 kB][npm-picocolors] (not minimized) - A micro library with basic features.
108-
- `аnsis`: [5.87 kB][npm-ansis] (minimized) - A powerful library with a rich set of features.
108+
- `аnsis`: [5.85 kB][npm-ansis] (minimized) - A powerful library with a rich set of features.
109109
- `chalk`: [44.2 kB][npm-chalk] (not minimized) - Provides similar functionality to Ansis.
110110

111111
### ⚡ Performance
@@ -214,7 +214,7 @@ As of 2025, only **Ansis**, **Chalk**, and **Picocolors** are actively maintaine
214214
- ☑️ Picocolors: `CJS` only
215215
- ☑️ Chalk: `ESM` only
216216
- Does it matter the unpacked size?
217-
-[Ansis - 5.87 kB][npm-ansis]
217+
-[Ansis - 5.85 kB][npm-ansis]
218218
-[Picocolors - 6.37 kB][npm-picocolors]
219219
-[Chalk - 44.2 kB][npm-chalk]
220220
- Does it matter if a library performs [~60 million](#bench-simple) or [~100 million](#bench-simple) **ops/sec** when outputting to the terminal?
@@ -1158,7 +1158,7 @@ c.red(1/0) // 'Infinity' in red
11581158

11591159
| Package | Dependencies | Minified | Unpacked Size | Tarball size |
11601160
|:-----------------------------|:------------------------------:|------------------|---------------------------------------------------------:|-----------------------------------------------------------------------:|
1161-
| [`ansis`][ansis] | [0][npm-ansis] | uglified & minified | [5.87 kB][npm-ansis] | [3.5 kB](https://arve0.github.io/npm-download-size/#ansis) |
1161+
| [`ansis`][ansis] | [0][npm-ansis] | uglified & minified | [5.85 kB][npm-ansis] | [3.5 kB](https://arve0.github.io/npm-download-size/#ansis) |
11621162
| [`picocolors`][picocolors] | [0][npm-picocolors] | no | [6.37 kB][npm-picocolors] | [2.6 kB](https://arve0.github.io/npm-download-size/#picocolors) |
11631163
| [`tinyrainbow`][tinyrainbow] | [0][npm-tinyrainbow] | uglified | [8.1 kB][npm-tinyrainbow] | [3.2 kB](https://arve0.github.io/npm-download-size/#tinyrainbow) |
11641164
| [`colorette`][colorette] | [0][npm-colorette] | no | [17.0 kB][npm-colorette] | [4.9 kB](https://arve0.github.io/npm-download-size/#colorette) |
@@ -1209,19 +1209,20 @@ npm run demo
12091209

12101210
Check the minimum version of your tool required for compatibility with the latest Ansis.
12111211

1212-
| Tool | Version | Compatibility | Supports |
1213-
|--------------------|-----------|---------------|----------|
1214-
| **Node.js** | **v14+** | ✅ Full support | CJS, ESM |
1215-
| **Deno** | **v2.0+** | ✅ Full support | CJS, ESM |
1216-
| **TypeScript/tsc** | **v5.0+** | ✅ Full support | CJS, ESM |
1217-
| **esbuild** | **v0.8+** | ✅ Full support | CJS, ESM |
1218-
| **swc** | **v1.2+** | ✅ Full support | CJS, ESM, FAUX |
1219-
| **tsup** | **v4.0+** | ✅ Full support | CJS, ESM, FAUX |
1220-
| **tsx** | **v3.0+** | ✅ Full support | CJS, ESM |
1221-
| **Rollup** | **v2.0+** | ✅ Full support | CJS, ESM |
1222-
| **Vite** | **v2.5+** | ✅ Full support | ESM |
1223-
| **Turbo** | **v1.0+** | ✅ Full support | CJS, ESM |
1224-
| **Webpack** | **v5.0+** | ✅ Full support | CJS, ESM |
1212+
| Tool | Version | Compatibility | Supports |
1213+
|--------------------|--------------------|---------------|----------|
1214+
| **Node.js** | **v14+** | ✅ Full support | CJS, ESM |
1215+
| **Deno** | **v2.0+** | ✅ Full support | CJS, ESM |
1216+
| **TypeScript/tsc** | **v5.0+** | ✅ Full support | CJS, ESM |
1217+
| **esbuild** | **v0.8+** | ✅ Full support | CJS, ESM |
1218+
| **swc** | **v1.2+** | ✅ Full support | CJS, ESM, FAUX |
1219+
| **tsup** | **v4.0+** | ✅ Full support | CJS, ESM, FAUX |
1220+
| **tsx** | **v3.0+** | ✅ Full support | CJS, ESM |
1221+
| **Rollup** | **v2.0+** | ✅ Full support | CJS, ESM |
1222+
| **Rolldown** | **v1.0.0-beta.8+** | ✅ Full support | CJS, ESM |
1223+
| **Vite** | **v2.5+** | ✅ Full support | ESM |
1224+
| **Turbo** | **v1.0+** | ✅ Full support | CJS, ESM |
1225+
| **Webpack** | **v5.0+** | ✅ Full support | CJS, ESM |
12251226

12261227
**Supports:**
12271228
- **CJS**: CommonJS module support.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ansis",
3-
"version": "4.0.0-rc.4",
3+
"version": "4.0.0-rc.5",
44
"description": "A small and fast library for applying ANSI colors in terminal or browser console",
55
"keywords": [
66
"ansi",
@@ -36,13 +36,12 @@
3636
},
3737
"sideEffects": false,
3838
"type": "module",
39-
"main": "./src/index.js",
4039
"types": "./src/index.d.ts",
4140
"exports": {
4241
".": {
4342
"types": "./src/index.d.ts",
4443
"import": "./src/index.mjs",
45-
"require": "./src/index.js"
44+
"require": "./src/index.cjs"
4645
}
4746
},
4847
"scripts": {
@@ -60,7 +59,7 @@
6059
"test:ansi256": "vitest run ./test/ansi256.test.js",
6160
"test:functional": "vitest run ./test/functional.test.js",
6261
"test:flags": "vitest run ./test/flags.test.js",
63-
"test:package": "vitest run ./test/package.test.js",
62+
"test:package": "vitest run ./test/package-mode.test.js",
6463
"test:cjs": "node ./test/package/cjs/test.cjs",
6564
"test:esm": "node ./test/package/esm/test.mjs",
6665
"test:tsc": "vitest run ./test/ts-compiler.test.js",

package.npm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"name":"ansis",
3-
"version":"4.0.0-rc.4",
3+
"version":"4.0.0-rc.5",
44
"description":"ANSI color lib",
5-
"keywords":["ansi","color","cli"],
5+
"keywords":["ansi","colors","cli"],
66
"license":"ISC",
77
"author":"webdiscus",
88
"repository":"webdiscus/ansis",
9-
"types":"./index.d.ts",
9+
"type": "module",
1010
"exports":{
1111
".":{
1212
"types":"./index.d.ts",
13-
"require":"./index.js",
13+
"require":"./index.cjs",
1414
"import":"./index.mjs"
1515
}
1616
},

package.test-node16.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
"author": "webdiscus",
77
"sideEffects": false,
88
"type": "module",
9-
"main": "./src/index.js",
10-
"types": "./src/index.d.ts",
119
"exports": {
1210
".": {
1311
"types": "./src/index.d.ts",

rollup.config.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default [
4747
{
4848
intro: '/* Auto generated by rollup.\nUse `npm run build` to create new version. */',
4949
exports: 'named',
50-
file: './dist/index.js',
50+
file: './dist/index.cjs',
5151
format: 'cjs',
5252
strict: false, // disable "use strict"
5353
esModule: false, // prevents __esModule property
@@ -69,7 +69,13 @@ export default [
6969
{
7070
src: 'src/index.mjs',
7171
dest: 'dist/',
72-
transform: async (contents, name) => (await minify(contents.toString(), { ecma: 2015 })).code,
72+
transform: async (contents, name) => (
73+
await minify(
74+
contents.toString().
75+
// transform the extension of the source ESM file to output .cjs (it will be compiled to Common JS)
76+
replace('.js', '.cjs'), { ecma: 2015 }
77+
)
78+
).code,
7379
},
7480

7581
// minify d.ts file generated after cleanup

src/index.d.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,17 @@ type R = (r: N, g: N, b: N) => A;
8585
// Short alias
8686
type A = Ansis;
8787

88+
type P = { open: S; close: S };
89+
8890
type Ansis = {
8991
/**
9092
* Opening ANSI escape code for a style or color.
9193
*/
92-
open: S;
94+
//open: S;
9395
/**
9496
* Closing ANSI escape code for a style or color.
9597
*/
96-
close: S;
98+
//close: S;
9799

98100
/**
99101
* @param {unknown} v The value to be processed, can be of any type, which will be converted to a string.
@@ -174,8 +176,9 @@ type Ansis = {
174176
* @param {string | { open: string; close: string }} c A record of new colors to add, with either a string or an object containing `open` and `close` sequences.
175177
* @return {Ansis} Return extended instance.
176178
*/
177-
extend<U extends S>(c: Record<U, any>): A & Record<U, A>;
178-
}
179+
//extend<U extends S>(c: Record<U, any>): A & Record<U, A>;
180+
extend<U extends S>(c: Record<U, S | P>): A & Record<U, A>;
181+
} & P
179182
// Dynamic properties
180183
& { [K in AnsiStyles | AnsiColors]: A };
181184

@@ -189,9 +192,9 @@ declare const
189192
Ansis: new (n?: N) => A,
190193
// declare all styles and colors of type Ansis
191194
a: A,
192-
isSupported: () => B,
193-
strip: (s: S) => S,
194-
extend: A['extend'],
195+
//isSupported: () => B,
196+
//strip: (s: S) => S,
197+
//extend: A['extend'],
195198

196199
fg: Q,
197200
rgb: R,
@@ -202,13 +205,14 @@ export {
202205
a as default,
203206
Ansis,
204207

205-
// Exporting these methods is required if the `module` compiler option is `node16,
206-
// otherwise the TS compiler can't find they in default import:
208+
// Named export of instance methods is a workaround for compatibility with various TypeScript module settings.
209+
// It works under all tsconfig settings (ESNext, Node16, verbatimModuleSyntax, etc.).
210+
// It is a hack for the `compilerOptions.module = "Node16"`, otherwise the TS compiler can't find they in default import:
207211
// import ansis from 'ansis';
208212
// ansis.strip(text); // <= TS2339: Property strip does not exist on type
209-
isSupported,
210-
strip,
211-
extend,
213+
//isSupported,
214+
//strip,
215+
//extend,
212216

213217
fg,
214218
fg as bg,

src/index.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ESM wrapper
2+
13
import a from './index.js';
24

35
// default export
File renamed without changes.

test/unit.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect, describe, test } from 'vitest';
22

3-
import ansis from '../src/index.js';
3+
//import ansis from '../src/index.mjs'; // for debugging only
4+
import ansis from 'ansis';
45
import { hexToRgb, rgbToAnsi256, ansi256To16, rgbToAnsi16 } from '../src/utils.js';
56
import { getLevel } from '../src/color-support.js';
67
import { LEVEL_BW, LEVEL_16COLORS, LEVEL_256COLORS, LEVEL_TRUECOLOR } from '../src/color-levels.js';

test/utils/helpers.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,20 @@ export const executeTSFile = (testPath, compiler = 'tsc', script = null) => {
109109
this.result = { received, expected };
110110

111111
expect(received).toEqual(expected);
112-
});
112+
})
113113
//debugging inner errors
114-
// .catch((error) => {
115-
// let message;
116-
// //console.log('>> err: ', error);
117-
// if (typeof error === 'string') {
118-
// message = '\n' + error;
119-
// } else if('stdout' in error && 'stderr' in error) {
120-
// message = error.stdout + '\n' + error.stderr;
121-
// } else {
122-
// message = '\n' + error.toString();
123-
// }
124-
//
125-
// expect.fail(testPath + message);
126-
// });
114+
.catch((error) => {
115+
let message;
116+
//console.log('>> err: ', error);
117+
if (typeof error === 'string') {
118+
message = '\n' + error;
119+
} else if('stdout' in error && 'stderr' in error) {
120+
message = error.stdout + '\n' + error.stderr;
121+
} else {
122+
message = '\n' + error.toString();
123+
}
124+
125+
expect.fail(testPath + message);
126+
});
127127

128128
};

0 commit comments

Comments
 (0)