Files
api/plugin/builder/build-pnpm-store.ts
Pujit Mehrotra 9f492bf217 feat: api plugin system & offline versioned dependency vendoring (#1252)
- **New Features**
- Created a dynamic plugin system for the API to enable community
augmentation of GraphQL, CLI, and Cron functionalities capabilities.
- Included an example plugin under `packages/unraid-api-plugin-health`
that adds a new graphql query for API health checks.
- Added `rc.unraid-api` commands for backing up, restoring, and
installing production dependencies, streamlining maintenance and
deployment.
- Improved dependency vendoring by bundling a versioned pnpm store
(instead of `node_modules`). Versioning will allow users to add plugins
to a specific api release without requiring an internet connection on
subsequent reboots.

- **Chores**
- Upgraded build workflows and versioning processes to ensure more
reliable artifact handling and production packaging.
2025-03-27 13:23:55 -04:00

43 lines
1.6 KiB
TypeScript

import { apiDir, deployDir } from "./utils/paths";
import { join } from "path";
import { readFileSync } from "node:fs";
import { startingDir } from "./utils/consts";
import { copyFile } from "node:fs/promises";
/**
* Get the version of the API from the package.json file
*
* Throws if package.json is not found or is invalid JSON.
* @returns The version of the API
*/
function getVersion(): string {
const packageJsonPath = join(apiDir, "package.json");
const packageJsonString = readFileSync(packageJsonPath, "utf8");
const packageJson = JSON.parse(packageJsonString);
return packageJson.version;
}
/**
* The name of the pnpm store archive that will be vendored with the plugin.
* @returns The name of the pnpm store bundle file
*/
export function getPnpmBundleName(): string {
const version = getVersion();
return `pnpm-store-for-v${version}.txz`;
}
/**
* Prepare a versioned bundle of the API's pnpm store to vendor dependencies.
*
* It expects a generic `packed-pnpm-store.txz` archive to be available in the `startingDir`.
* It copies this archive to the `deployDir` directory and adds a version to the filename.
* It does not actually create the packed pnpm store archive; that is done inside the API's build script.
*
* After this operation, the vendored store will be available inside the `deployDir`.
*/
export async function bundlePnpmStore(): Promise<void> {
const storeArchive = join(startingDir, "packed-pnpm-store.txz");
const pnpmStoreTarPath = join(deployDir, getPnpmBundleName());
await copyFile(storeArchive, pnpmStoreTarPath);
}