Skip to content

Commit ec84685

Browse files
committed
Fix build
1 parent 2f0843a commit ec84685

4 files changed

Lines changed: 120 additions & 9 deletions

File tree

packages/mcp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"repository": {
66
"type": "git",
77
"url": "git+https://github.com/jpmorganchase/salt-ds.git",
8-
"directory": "packages/salt-mcp"
8+
"directory": "packages/mcp"
99
},
1010
"bugs": "https://github.com/jpmorganchase/salt-ds/issues",
1111
"main": "src/index.ts",

packages/mcp/scripts/buildRegistry.mjs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
22
import { createRequire } from "node:module";
33
import path from "node:path";
44
import { fileURLToPath } from "node:url";
5+
import { ensureSiteBuildInputs } from "./ensureSiteBuildInputs.mjs";
56

67
const ALLOWED_FLAGS = new Set(["source-root", "output-dir"]);
78

@@ -46,6 +47,13 @@ const distIndexPath = path.join(
4647
"index.js",
4748
);
4849
const require = createRequire(import.meta.url);
50+
const flags = parseFlags(process.argv.slice(2));
51+
const sourceRoot = flags["source-root"]
52+
? path.resolve(flags["source-root"])
53+
: repoRoot;
54+
const outputDir = flags["output-dir"]
55+
? path.resolve(flags["output-dir"])
56+
: path.join(packageRoot, "generated");
4957

5058
try {
5159
await fs.access(distIndexPath);
@@ -56,13 +64,7 @@ try {
5664
}
5765

5866
const { buildRegistry } = require(distIndexPath);
59-
const flags = parseFlags(process.argv.slice(2));
60-
const sourceRoot = flags["source-root"]
61-
? path.resolve(flags["source-root"])
62-
: repoRoot;
63-
const outputDir = flags["output-dir"]
64-
? path.resolve(flags["output-dir"])
65-
: path.join(packageRoot, "generated");
67+
await ensureSiteBuildInputs(sourceRoot);
6668

6769
const registry = await buildRegistry({
6870
sourceRoot,
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { spawnSync } from "node:child_process";
2+
import fs from "node:fs/promises";
3+
import path from "node:path";
4+
5+
const REQUIRED_PROP_FILES = [
6+
"ag-grid-theme-props.json",
7+
"core-props.json",
8+
"countries-props.json",
9+
"data-grid-props.json",
10+
"embla-carousel-props.json",
11+
"icons-props.json",
12+
"lab-props.json",
13+
"react-resizable-panel-theme-props.json",
14+
];
15+
16+
async function pathExists(targetPath) {
17+
try {
18+
await fs.access(targetPath);
19+
return true;
20+
} catch {
21+
return false;
22+
}
23+
}
24+
25+
async function getMissingInputs(repoRoot) {
26+
const missing = [];
27+
const searchDataPath = path.join(
28+
repoRoot,
29+
"site",
30+
"public",
31+
"search-data.json",
32+
);
33+
const snapshotRoot = path.join(
34+
repoRoot,
35+
"site",
36+
"snapshots",
37+
"latest",
38+
"salt",
39+
);
40+
const propsDir = path.join(repoRoot, "site", "src", "props");
41+
42+
if (!(await pathExists(searchDataPath))) {
43+
missing.push(searchDataPath);
44+
}
45+
if (!(await pathExists(snapshotRoot))) {
46+
missing.push(snapshotRoot);
47+
}
48+
49+
for (const fileName of REQUIRED_PROP_FILES) {
50+
const filePath = path.join(propsDir, fileName);
51+
if (!(await pathExists(filePath))) {
52+
missing.push(filePath);
53+
}
54+
}
55+
56+
return missing;
57+
}
58+
59+
function runYarnGenSnapshot(repoRoot) {
60+
const command = process.platform === "win32" ? "yarn.cmd" : "yarn";
61+
const result = spawnSync(
62+
command,
63+
["workspace", "@salt-ds/site", "gen:snapshot"],
64+
{
65+
cwd: repoRoot,
66+
stdio: "inherit",
67+
env: process.env,
68+
},
69+
);
70+
71+
if (result.status !== 0) {
72+
throw new Error("Failed to generate required Salt site artifacts for MCP.");
73+
}
74+
}
75+
76+
export async function ensureSiteBuildInputs(repoRoot) {
77+
const missingBefore = await getMissingInputs(repoRoot);
78+
if (missingBefore.length === 0) {
79+
return;
80+
}
81+
82+
console.error(
83+
"Missing Salt site artifacts required for MCP registry build. Regenerating with `yarn workspace @salt-ds/site gen:snapshot`.",
84+
);
85+
86+
await fs.rm(path.join(repoRoot, "site", "snapshots", "latest"), {
87+
recursive: true,
88+
force: true,
89+
});
90+
await fs.rm(path.join(repoRoot, "site", "public", "search-data.json"), {
91+
force: true,
92+
});
93+
94+
runYarnGenSnapshot(repoRoot);
95+
96+
const missingAfter = await getMissingInputs(repoRoot);
97+
if (missingAfter.length > 0) {
98+
throw new Error(
99+
`Salt site artifact generation completed, but required MCP inputs are still missing:\n${missingAfter.join("\n")}`,
100+
);
101+
}
102+
}

scripts/build.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import { transformWorkspaceDeps } from "./transformWorkspaceDeps.mjs";
1313
import { distinct } from "./utils.mjs";
1414

1515
const cwd = process.cwd();
16+
const repoRoot = path.resolve(
17+
path.dirname(url.fileURLToPath(import.meta.url)),
18+
"..",
19+
);
1620

1721
const packageJson = (
1822
await import(url.pathToFileURL(path.join(cwd, "package.json")), {
@@ -128,7 +132,10 @@ await fs.writeJSON(
128132
);
129133

130134
for (const file of FILES_TO_COPY) {
131-
const filePath = path.join(cwd, file);
135+
let filePath = path.join(cwd, file);
136+
if (file === "LICENSE" && !(await fs.pathExists(filePath))) {
137+
filePath = path.join(repoRoot, file);
138+
}
132139
try {
133140
await fs.copy(filePath, path.join(outputDir, file));
134141
} catch (error) {

0 commit comments

Comments
 (0)