Skip to content

Commit 2e636a5

Browse files
authored
Fix wrong import attribute keyword upon tsup upgrade (#487)
1 parent ac9013d commit 2e636a5

File tree

10 files changed

+800
-322
lines changed

10 files changed

+800
-322
lines changed

.changeset/cold-candies-move.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@codama/cli': patch
3+
---
4+
5+
Fix wrong import attribute keyword upon tsup upgrade

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
"happy-dom": "^17.1.8",
2828
"prettier": "^3.5.2",
2929
"rimraf": "6.0.1",
30-
"tsup": "^8.4.0",
3130
"turbo": "^2.4.4",
31+
"tsup": "^8.4.0",
3232
"typescript": "^5.7.3",
3333
"vitest": "^3.0.7",
3434
"zx": "^8.3.2"

packages/cli/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"dev": "zx ../../node_modules/@codama/internals/scripts/test-unit.mjs node --watch",
3131
"lint": "zx ../../node_modules/@codama/internals/scripts/lint.mjs",
3232
"lint:fix": "zx ../../node_modules/@codama/internals/scripts/lint.mjs --fix",
33-
"test": "pnpm test:types && pnpm test:treeshakability && pnpm test:node",
33+
"test": "pnpm test:types && pnpm test:treeshakability && pnpm test:node && pnpm test:exports",
34+
"test:exports": "node test/exports/module.mjs && node test/exports/commonjs.cjs",
3435
"test:node": "zx ../../node_modules/@codama/internals/scripts/test-unit.mjs node",
3536
"test:treeshakability": "zx ../../node_modules/@codama/internals/scripts/test-treeshakability.mjs",
3637
"test:types": "zx ../../node_modules/@codama/internals/scripts/test-types.mjs"
@@ -44,8 +45,8 @@
4445
"@codama/renderers-rust": "workspace:*",
4546
"@codama/visitors": "workspace:*",
4647
"@codama/visitors-core": "workspace:*",
47-
"chalk": "^5.4.1",
4848
"commander": "^13.1.0",
49+
"picocolors": "^1.1.1",
4950
"prompts": "^2.4.2"
5051
},
5152
"devDependencies": {

packages/cli/src/utils/logs.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import chalk from 'chalk';
1+
import pico from 'picocolors';
22

33
export function logSuccess(...args: unknown[]): void {
4-
console.log(chalk.green('[Success]'), ...args);
4+
console.log(pico.green('[Success]'), ...args);
55
}
66

77
export function logInfo(...args: unknown[]): void {
8-
console.log(chalk.blueBright('[Info]'), ...args);
8+
console.log(pico.blueBright('[Info]'), ...args);
99
}
1010

1111
export function logWarning(...args: unknown[]): void {
12-
console.log(chalk.yellow('[Warning]'), ...args);
12+
console.log(pico.yellow('[Warning]'), ...args);
1313
}
1414

1515
export function logError(...args: unknown[]): void {
16-
console.log(chalk.red('[Error]'), ...args);
16+
console.log(pico.red('[Error]'), ...args);
1717
}
1818

1919
export function logDebug(...args: unknown[]): void {
20-
console.log(chalk.magenta('[Debug]'), ...args);
20+
console.log(pico.magenta('[Debug]'), ...args);
2121
}
2222

2323
export function logBanner(): void {
@@ -26,6 +26,6 @@ export function logBanner(): void {
2626

2727
function getBanner(): string {
2828
const textBanner = 'Welcome to Codama!';
29-
const gradientBanner = chalk.bold(chalk.hex('#e7ab61')(textBanner));
29+
const gradientBanner = pico.bold(`\x1b[38;2;231;171;97m${textBanner}\x1b[0m`);
3030
return process.stdout.isTTY && process.stdout.getColorDepth() > 8 ? gradientBanner : textBanner;
3131
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const path = require('path');
2+
const { codama } = require('../../dist/index.node.cjs');
3+
4+
const configPath = path.join('test', 'exports', 'mock-config.json');
5+
codama(['run', '-c', configPath]);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"idl": "mock-idl.json",
3+
"before": ["@codama/visitors#identityVisitor"],
4+
"scripts": {}
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"kind": "rootNode",
3+
"spec": "codama",
4+
"version": "1.0.0",
5+
"program": { "kind": "programNode" }
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import path from 'path';
2+
import { codama } from '../../dist/index.node.mjs';
3+
4+
const configPath = path.join('test', 'exports', 'mock-config.json');
5+
codama(['run', '-c', configPath]);

packages/internals/tsup.config.base.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ export function getBuildConfig(options: BuildOptions): TsupConfig {
5454
publicDir: true,
5555
pure: ['process'],
5656
sourcemap: format !== 'iife',
57-
treeshake: true,
57+
58+
// Treeshaking already happens with esbuild but tsup offers this options
59+
// for "better" treeshaking strategies using Rollup as an additional step.
60+
// The issue is Rollup now uses the deprecated "assert" import keyword by default
61+
// And tsup doesn't offer a way to change this behavior. Since the CLI package
62+
// relies on using the "with" keyword to dynamically import JSON files,
63+
// we can't use Rollup for treeshaking.
64+
treeshake: false,
5865
};
5966
}

0 commit comments

Comments
 (0)