mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
7673b8dfb8
CI build runners use a Node with native TypeScript stripping enabled (process.features.typescript), so tsdown selects its native ESM config loader. That loader cannot resolve the extensionless relative import "../../scripts/tsdown-exports" in each tsdown.config.ts, so every package build failed with "Cannot find module" — cascading into the unit, runtime, and all integration jobs (which run the build first). Local builds used tsdown's bundler loader instead, which is why this passed pre-push. Ship the shared helper as scripts/tsdown-exports.mjs (real ESM) plus a hand-written tsdown-exports.d.mts, imported with the explicit .mjs extension. This resolves under the native loader, tsdown's bundler loader, and tsc alike. The generated exports are unchanged — package.json maps stay identical. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
93 lines
2.8 KiB
TypeScript
93 lines
2.8 KiB
TypeScript
/// <reference types="node" />
|
|
import { defineConfig } from "tsdown";
|
|
import fs from "fs";
|
|
import path from "path";
|
|
import { withTypesConditions } from "../../scripts/tsdown-exports.mjs";
|
|
|
|
// Side-effect CSS imports are kept in the JS output so styles auto-load for
|
|
// bundler consumers, but rolldown-plugin-dts also leaves them in the emitted
|
|
// declaration files, where TypeScript cannot resolve a `.css` as a typed module
|
|
// (an `attw` InternalResolutionError). Strip them from declarations only, via the
|
|
// `build:done` hook so every format's declarations are post-processed on disk.
|
|
const stripCssTypeImports = (dir: string) => {
|
|
const cssImport = /^[ \t]*import\s+["'][^"']+\.css["'];?[ \t]*\r?\n/gm;
|
|
const walk = (current: string) => {
|
|
for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
|
|
const full = path.join(current, entry.name);
|
|
if (entry.isDirectory()) {
|
|
walk(full);
|
|
} else if (/\.d\.[cm]?ts$/.test(entry.name)) {
|
|
const code = fs.readFileSync(full, "utf8");
|
|
const next = code.replace(cssImport, "");
|
|
if (next !== code) fs.writeFileSync(full, next);
|
|
}
|
|
}
|
|
};
|
|
if (fs.existsSync(dir)) walk(dir);
|
|
};
|
|
|
|
export default defineConfig([
|
|
{
|
|
entry: ["src/index.tsx"],
|
|
format: ["esm", "cjs"],
|
|
dts: true,
|
|
sourcemap: true,
|
|
target: "es2022",
|
|
outDir: "dist",
|
|
hooks: {
|
|
"build:done": () => stripCssTypeImports(path.resolve("dist")),
|
|
},
|
|
external: [
|
|
"react",
|
|
"react-dom",
|
|
"@copilotkit/core",
|
|
"@copilotkit/react-core/v2",
|
|
],
|
|
exports: {
|
|
customExports: (exports, ctx) =>
|
|
withTypesConditions(
|
|
{
|
|
...exports,
|
|
"./styles.css": "./dist/index.css",
|
|
"./v2/styles.css": "./dist/v2/index.css",
|
|
},
|
|
ctx,
|
|
),
|
|
},
|
|
},
|
|
{
|
|
entry: ["src/index.tsx"],
|
|
format: ["umd"],
|
|
globalName: "CopilotKitReactUI",
|
|
sourcemap: true,
|
|
target: "es2018",
|
|
outDir: "dist",
|
|
external: [
|
|
"react",
|
|
"react-dom",
|
|
"@copilotkit/react-core",
|
|
"@copilotkit/shared",
|
|
"@copilotkit/runtime-client-gql",
|
|
],
|
|
outputOptions(options) {
|
|
options.codeSplitting = false;
|
|
options.entryFileNames = "[name].umd.js";
|
|
options.globals = {
|
|
react: "React",
|
|
"react-dom": "ReactDOM",
|
|
"react/jsx-runtime": "ReactJsxRuntime",
|
|
"@copilotkit/react-core": "CopilotKitReactCore",
|
|
"@copilotkit/shared": "CopilotKitShared",
|
|
"@copilotkit/runtime-client-gql": "CopilotKitRuntimeClientGQL",
|
|
"@headlessui/react": "HeadlessUIReact",
|
|
"react-markdown": "ReactMarkdown",
|
|
"react-syntax-highlighter": "ReactSyntaxHighlighter",
|
|
"remark-gfm": "remarkGfm",
|
|
"remark-math": "remarkMath",
|
|
"rehype-raw": "rehypeRaw",
|
|
};
|
|
return options;
|
|
},
|
|
},
|
|
]);
|