Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions apps/cli/scripts/__tests__/ensure-superdoc-build.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from 'bun:test';
import { ensureDocumentApiBuild, ensureSuperdocBuild } from '../ensure-superdoc-build.js';
import { ensureDocumentApiBuild, ensureNodeSdkBuild, ensureSuperdocBuild } from '../ensure-superdoc-build.js';

type CommandCall = {
command: string;
Expand Down Expand Up @@ -30,8 +30,31 @@ describe('ensureDocumentApiBuild', () => {
});
});

describe('ensureNodeSdkBuild', () => {
test('generates SDK artifacts and rebuilds the Node SDK package', () => {
const calls: CommandCall[] = [];

ensureNodeSdkBuild((command, args, label) => {
calls.push({ command, args, label });
});

expect(calls).toEqual([
{
command: 'pnpm',
args: ['--prefix', expect.stringContaining('/packages/sdk'), 'run', 'generate'],
label: 'Generate SDK artifacts for CLI runtime',
},
{
command: 'pnpm',
args: ['--prefix', expect.stringContaining('/packages/sdk/langs/node'), 'run', 'build'],
label: 'Build Node SDK for CLI runtime',
},
]);
});
});

describe('ensureSuperdocBuild', () => {
test('builds document-api first, then the fast packaged superdoc build by default', () => {
test('builds SDK first, then the fast packaged superdoc build by default', () => {
const calls: CommandCall[] = [];

ensureSuperdocBuild({}, (command, args, label) => {
Expand All @@ -41,13 +64,13 @@ describe('ensureSuperdocBuild', () => {
expect(calls).toEqual([
{
command: 'pnpm',
args: ['exec', 'tsc', '-b', '--clean', 'packages/document-api'],
label: 'Clean document-api dist for CLI runtime',
args: ['--prefix', expect.stringContaining('/packages/sdk'), 'run', 'generate'],
label: 'Generate SDK artifacts for CLI runtime',
},
{
command: 'pnpm',
args: ['exec', 'tsc', '-b', 'packages/document-api'],
label: 'Build document-api dist for CLI runtime',
args: ['--prefix', expect.stringContaining('/packages/sdk/langs/node'), 'run', 'build'],
label: 'Build Node SDK for CLI runtime',
},
{
command: 'pnpm',
Expand Down
22 changes: 20 additions & 2 deletions apps/cli/scripts/ensure-superdoc-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { ensureNoUnknownFlags, isDirectExecution, repoRoot, runCommand } from '.
const allowedFlags = new Set(['--types']);
const superdocRoot = path.join(repoRoot, 'packages/superdoc');
const documentApiRoot = path.join(repoRoot, 'packages/document-api');
const sdkWorkspaceRoot = path.join(repoRoot, 'packages/sdk');
const nodeSdkRoot = path.join(sdkWorkspaceRoot, 'langs/node');
const documentApiProject = path.relative(repoRoot, documentApiRoot);

/**
Expand All @@ -16,9 +18,25 @@ export function ensureDocumentApiBuild(run = runCommand) {
run('pnpm', ['exec', 'tsc', '-b', documentApiProject], 'Build document-api dist for CLI runtime');
}

/**
* Ensures the Node SDK package resolves for CLI builds.
*
* The CLI imports `@superdoc-dev/sdk` for `doc.preset.*`; Bun resolves that
* package through its dist export while compiling native binaries. SDK
* generation exports the CLI contract first, which builds document-api dist
* for clean checkouts.
*
* @returns {void}
*/
export function ensureNodeSdkBuild(run = runCommand) {
run('pnpm', ['--prefix', sdkWorkspaceRoot, 'run', 'generate'], 'Generate SDK artifacts for CLI runtime');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid full SDK generation in CLI prebuild

This runs the workspace SDK generator from every CLI prebuild/pretest path, but that generator writes more than the Node SDK files needed by the CLI: it also rewrites tracked artifacts such as apps/mcp/src/generated/* and packages/sdk/tools/intent_dispatch_generated.py. After a document-api or CLI metadata edit, a developer running pnpm --prefix apps/cli run build or tests will now silently mutate unrelated generated outputs and can leave CI/release jobs building from uncommitted files. Please use a Node-SDK-only generation path here, or keep unrelated generated outputs in a non-mutating check.

Useful? React with 👍 / 👎.

run('pnpm', ['--prefix', nodeSdkRoot, 'run', 'build'], 'Build Node SDK for CLI runtime');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stage SDK tool assets for packaged CLI builds

Building the Node SDK dist here makes @superdoc-dev/sdk resolvable, but it still does not make the SDK legacy preset's tools/*.json assets available in the bundled/native CLI layout. The CLI exposes doc.preset.* with the SDK default preset still being legacy, and that preset reads the tool catalog from disk relative to the compiled module; apps/cli only copies prompt files, so packaged/native calls such as superdoc preset get-tools --provider openai without --preset core can pass the build and then fail at runtime with missing tool assets. Please copy/embed the SDK tool artifacts as part of this ensure step or switch the packaged default path to an embedded asset source.

Useful? React with 👍 / 👎.

}

/**
* Ensures the CLI's runtime dependencies are freshly built:
* - document-api contract/catalog dist consumed by CLI + SDK generation
* - document-api contract/catalog dist consumed by CLI metadata export
* - Node SDK dist consumed by `doc.preset.*`
* - packaged `superdoc` for the v1 runtime path
*
* `--types` performs the full published build so package type exports exist.
Expand All @@ -32,7 +50,7 @@ export function ensureSuperdocBuild(options = {}, run = runCommand) {
const scriptName = includeTypes ? 'build:es' : 'build:dev';
const label = includeTypes ? 'Build packaged SuperDoc runtime and types' : 'Build packaged SuperDoc runtime';

ensureDocumentApiBuild(run);
ensureNodeSdkBuild(run);
run('pnpm', ['--prefix', superdocRoot, 'run', scriptName], label);
}

Expand Down
Loading