Skip to content

Commit

Permalink
Fix wrong import attribute keyword upon tsup upgrade (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva authored Mar 1, 2025
1 parent ac9013d commit 2e636a5
Show file tree
Hide file tree
Showing 10 changed files with 800 additions and 322 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-candies-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@codama/cli': patch
---

Fix wrong import attribute keyword upon tsup upgrade
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"happy-dom": "^17.1.8",
"prettier": "^3.5.2",
"rimraf": "6.0.1",
"tsup": "^8.4.0",
"turbo": "^2.4.4",
"tsup": "^8.4.0",
"typescript": "^5.7.3",
"vitest": "^3.0.7",
"zx": "^8.3.2"
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"dev": "zx ../../node_modules/@codama/internals/scripts/test-unit.mjs node --watch",
"lint": "zx ../../node_modules/@codama/internals/scripts/lint.mjs",
"lint:fix": "zx ../../node_modules/@codama/internals/scripts/lint.mjs --fix",
"test": "pnpm test:types && pnpm test:treeshakability && pnpm test:node",
"test": "pnpm test:types && pnpm test:treeshakability && pnpm test:node && pnpm test:exports",
"test:exports": "node test/exports/module.mjs && node test/exports/commonjs.cjs",
"test:node": "zx ../../node_modules/@codama/internals/scripts/test-unit.mjs node",
"test:treeshakability": "zx ../../node_modules/@codama/internals/scripts/test-treeshakability.mjs",
"test:types": "zx ../../node_modules/@codama/internals/scripts/test-types.mjs"
Expand All @@ -44,8 +45,8 @@
"@codama/renderers-rust": "workspace:*",
"@codama/visitors": "workspace:*",
"@codama/visitors-core": "workspace:*",
"chalk": "^5.4.1",
"commander": "^13.1.0",
"picocolors": "^1.1.1",
"prompts": "^2.4.2"
},
"devDependencies": {
Expand Down
14 changes: 7 additions & 7 deletions packages/cli/src/utils/logs.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import chalk from 'chalk';
import pico from 'picocolors';

export function logSuccess(...args: unknown[]): void {
console.log(chalk.green('[Success]'), ...args);
console.log(pico.green('[Success]'), ...args);
}

export function logInfo(...args: unknown[]): void {
console.log(chalk.blueBright('[Info]'), ...args);
console.log(pico.blueBright('[Info]'), ...args);
}

export function logWarning(...args: unknown[]): void {
console.log(chalk.yellow('[Warning]'), ...args);
console.log(pico.yellow('[Warning]'), ...args);
}

export function logError(...args: unknown[]): void {
console.log(chalk.red('[Error]'), ...args);
console.log(pico.red('[Error]'), ...args);
}

export function logDebug(...args: unknown[]): void {
console.log(chalk.magenta('[Debug]'), ...args);
console.log(pico.magenta('[Debug]'), ...args);
}

export function logBanner(): void {
Expand All @@ -26,6 +26,6 @@ export function logBanner(): void {

function getBanner(): string {
const textBanner = 'Welcome to Codama!';
const gradientBanner = chalk.bold(chalk.hex('#e7ab61')(textBanner));
const gradientBanner = pico.bold(`\x1b[38;2;231;171;97m${textBanner}\x1b[0m`);
return process.stdout.isTTY && process.stdout.getColorDepth() > 8 ? gradientBanner : textBanner;
}
5 changes: 5 additions & 0 deletions packages/cli/test/exports/commonjs.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const path = require('path');
const { codama } = require('../../dist/index.node.cjs');

const configPath = path.join('test', 'exports', 'mock-config.json');
codama(['run', '-c', configPath]);
5 changes: 5 additions & 0 deletions packages/cli/test/exports/mock-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"idl": "mock-idl.json",
"before": ["@codama/visitors#identityVisitor"],
"scripts": {}
}
6 changes: 6 additions & 0 deletions packages/cli/test/exports/mock-idl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"kind": "rootNode",
"spec": "codama",
"version": "1.0.0",
"program": { "kind": "programNode" }
}
5 changes: 5 additions & 0 deletions packages/cli/test/exports/module.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import path from 'path';
import { codama } from '../../dist/index.node.mjs';

const configPath = path.join('test', 'exports', 'mock-config.json');
codama(['run', '-c', configPath]);
9 changes: 8 additions & 1 deletion packages/internals/tsup.config.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ export function getBuildConfig(options: BuildOptions): TsupConfig {
publicDir: true,
pure: ['process'],
sourcemap: format !== 'iife',
treeshake: true,

// Treeshaking already happens with esbuild but tsup offers this options
// for "better" treeshaking strategies using Rollup as an additional step.
// The issue is Rollup now uses the deprecated "assert" import keyword by default
// And tsup doesn't offer a way to change this behavior. Since the CLI package
// relies on using the "with" keyword to dynamically import JSON files,
// we can't use Rollup for treeshaking.
treeshake: false,
};
}
Loading

0 comments on commit 2e636a5

Please sign in to comment.