瀏覽代碼

Fix wrong import attribute keyword upon tsup upgrade (#487)

Loris Leiva 8 月之前
父節點
當前提交
2e636a5705

+ 5 - 0
.changeset/cold-candies-move.md

@@ -0,0 +1,5 @@
+---
+'@codama/cli': patch
+---
+
+Fix wrong import attribute keyword upon tsup upgrade

+ 1 - 1
package.json

@@ -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"

+ 3 - 2
packages/cli/package.json

@@ -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"
@@ -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": {

+ 7 - 7
packages/cli/src/utils/logs.ts

@@ -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 {
@@ -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 - 0
packages/cli/test/exports/commonjs.cjs

@@ -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 - 0
packages/cli/test/exports/mock-config.json

@@ -0,0 +1,5 @@
+{
+    "idl": "mock-idl.json",
+    "before": ["@codama/visitors#identityVisitor"],
+    "scripts": {}
+}

+ 6 - 0
packages/cli/test/exports/mock-idl.json

@@ -0,0 +1,6 @@
+{
+    "kind": "rootNode",
+    "spec": "codama",
+    "version": "1.0.0",
+    "program": { "kind": "programNode" }
+}

+ 5 - 0
packages/cli/test/exports/module.mjs

@@ -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]);

+ 8 - 1
packages/internals/tsup.config.base.ts

@@ -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,
     };
 }

文件差異過大導致無法顯示
+ 414 - 154
pnpm-lock.yaml


部分文件因文件數量過多而無法顯示