Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
91 lines
3.3 KiB
JavaScript
91 lines
3.3 KiB
JavaScript
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
const { execFileSync } = require("node:child_process");
|
|
const {
|
|
buildWindowsHelloHelper,
|
|
normalizeWindowsHelperArch,
|
|
} = require("./build-windows-hello-helper.cjs");
|
|
|
|
const CURSOR_PLATFORM_PACKAGES = {
|
|
darwin: ["@cursor/sdk-darwin-arm64", "@cursor/sdk-darwin-x64"],
|
|
linux: ["@cursor/sdk-linux-arm64", "@cursor/sdk-linux-x64"],
|
|
win32: ["@cursor/sdk-win32-x64"],
|
|
};
|
|
|
|
function readJson(filePath) {
|
|
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
}
|
|
|
|
function getCursorSdkVersion(projectDir) {
|
|
const sdkPackagePath = path.join(projectDir, "node_modules", "@cursor", "sdk", "package.json");
|
|
if (fs.existsSync(sdkPackagePath)) {
|
|
return readJson(sdkPackagePath).version;
|
|
}
|
|
|
|
const lockPath = path.join(projectDir, "package-lock.json");
|
|
if (fs.existsSync(lockPath)) {
|
|
const lock = readJson(lockPath);
|
|
const lockedVersion = lock.packages?.["node_modules/@cursor/sdk"]?.version;
|
|
if (lockedVersion) return lockedVersion;
|
|
}
|
|
|
|
const packageJson = readJson(path.join(projectDir, "package.json"));
|
|
const spec = packageJson.optionalDependencies?.["@cursor/sdk"];
|
|
return typeof spec === "string" ? spec.replace(/^[^\d]*/, "") : null;
|
|
}
|
|
|
|
function npmExecutable() {
|
|
return process.platform === "win32" ? "npm.cmd" : "npm";
|
|
}
|
|
|
|
function ensureCursorSdkPlatformPackages({
|
|
projectDir,
|
|
platform,
|
|
run = execFileSync,
|
|
logger = console,
|
|
}) {
|
|
const packages = CURSOR_PLATFORM_PACKAGES[platform] || [];
|
|
if (packages.length === 0) return [];
|
|
|
|
const version = getCursorSdkVersion(projectDir);
|
|
if (!version) {
|
|
logger.warn("[beforePackCursorSdk] Cursor SDK version not found; skipping platform package install.");
|
|
return [];
|
|
}
|
|
|
|
const missingPackages = packages.filter((packageName) => (
|
|
!fs.existsSync(path.join(projectDir, "node_modules", ...packageName.split("/"), "package.json"))
|
|
));
|
|
if (missingPackages.length === 0) return [];
|
|
|
|
const packageSpecs = missingPackages.map((packageName) => `${packageName}@${version}`);
|
|
logger.log(`[beforePackCursorSdk] Installing Cursor SDK platform packages: ${packageSpecs.join(", ")}`);
|
|
run(npmExecutable(), ["install", "--no-save", "--force", "--ignore-scripts", ...packageSpecs], {
|
|
cwd: projectDir,
|
|
stdio: "inherit",
|
|
});
|
|
|
|
return missingPackages;
|
|
}
|
|
|
|
function beforePackCursorSdk(context = {}) {
|
|
const projectDir = context.appDir || process.cwd();
|
|
const platform = context.electronPlatformName || process.platform;
|
|
const arch = normalizeWindowsHelperArch(context.arch || process.env.npm_config_arch || process.arch);
|
|
const ensureCursor = context.ensureCursorSdkPlatformPackages || ensureCursorSdkPlatformPackages;
|
|
ensureCursor({ projectDir, platform });
|
|
const buildHelper = context.buildWindowsHelloHelper || buildWindowsHelloHelper;
|
|
if (platform === "win32") {
|
|
const result = buildHelper({ projectDir, platform, arch });
|
|
if (result?.skipped) {
|
|
throw new Error(`Windows Hello helper was not built: ${result.reason || "unknown"}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = beforePackCursorSdk;
|
|
module.exports.default = beforePackCursorSdk;
|
|
module.exports.beforePackCursorSdk = beforePackCursorSdk;
|
|
module.exports.ensureCursorSdkPlatformPackages = ensureCursorSdkPlatformPackages;
|
|
module.exports.CURSOR_PLATFORM_PACKAGES = CURSOR_PLATFORM_PACKAGES;
|