/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *--------------------------------------------------------------------------------------------*/

// Bootstrap script for extension subprocesses.
// This is the fork target — it sets up the SDK resolver in-process,
// then dynamically imports the user's extension via the EXTENSION_PATH env var.

import { register } from "node:module";
import { pathToFileURL } from "node:url";

// Register the SDK resolver hook before loading the extension
register("./extension_sdk_resolver.mjs", import.meta.url);

// Load the user's extension
const extensionPath = process.env.EXTENSION_PATH;
if (!extensionPath) {
    console.error("[extension-bootstrap] No extension path provided");
    process.exit(1);
}

try {
    await import(pathToFileURL(extensionPath).href);
} catch (err) {
    console.error(`[extension-bootstrap] Failed to load extension: ${err}`);
    process.exit(1);
}
