Skip to content
Merged
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
67 changes: 64 additions & 3 deletions scripts/smoke-registry-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// @ts-check

import { execFileSync } from "node:child_process";
import { mkdtempSync, rmSync } from "node:fs";
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import {
Expand All @@ -12,6 +12,16 @@ import {
} from "./install-smoke-utils.js";
import { getPackageMetadata } from "./package-metadata.js";

/**
* @param {unknown} value
* @returns {string[]}
*/
function asStringArray(value) {
return Array.isArray(value)
? value.filter((entry) => typeof entry === "string" && entry.length > 0)
: [];
}

function parseArgs(argv) {
/** @type {{packageName: string; version: string; cliCommand: string}} */
const options = {
Expand Down Expand Up @@ -62,6 +72,56 @@ function sleep(milliseconds) {
return new Promise((resolve) => setTimeout(resolve, milliseconds));
}

function installedPackageJsonPath(packageName, installRoot) {
return join(
installRoot,
"node_modules",
...packageName.split("/"),
"package.json",
);
}

function readInstalledBundledDependencies(installRoot) {
const packageJsonPath = installedPackageJsonPath(name, installRoot);
try {
const parsed = JSON.parse(readFileSync(packageJsonPath, "utf8"));
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
throw new Error("installed package.json did not contain an object");
}
return asStringArray(
parsed.bundleDependencies ?? parsed.bundledDependencies,
);
} catch (error) {
const reason =
error instanceof Error ? error.message : "unknown package read error";
throw new Error(
`Could not read installed package metadata at ${packageJsonPath}: ${reason}`,
);
}
}

function shouldRunBunInstallSmoke(bundledDependencies) {
if (process.env.MAESTRO_SKIP_BUN_INSTALL_SMOKE === "1") {
console.log(`Skipping Bun install smoke for ${packageSpec}.`);
return false;
}

if (process.env.MAESTRO_FORCE_BUN_INSTALL_SMOKE === "1") {
return true;
}

if (bundledDependencies.length > 0) {
console.log(
`Skipping Bun install smoke for ${packageSpec}; package bundles ${bundledDependencies.join(
", ",
)}, and the npm install smoke already verified the published tarball contents.`,
);
return false;
}

return true;
}

async function waitForPackage() {
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
try {
Expand Down Expand Up @@ -98,6 +158,7 @@ async function waitForPackage() {
async function main() {
await waitForPackage();

let installedBundledDependencies = [];
const tempDir = mkdtempSync(join(tmpdir(), "maestro-registry-smoke-"));
try {
execFileSync(npmCommand, ["init", "-y"], {
Expand All @@ -108,6 +169,7 @@ async function main() {
cwd: tempDir,
stdio: "inherit",
});
installedBundledDependencies = readInstalledBundledDependencies(tempDir);
runInstalledPackageAudit(tempDir, {
label: packageSpec,
});
Expand All @@ -132,8 +194,7 @@ async function main() {
rmSync(tempDir, { recursive: true, force: true });
}

if (process.env.MAESTRO_SKIP_BUN_INSTALL_SMOKE === "1") {
console.log(`Skipping Bun install smoke for ${packageSpec}.`);
if (!shouldRunBunInstallSmoke(installedBundledDependencies)) {
return;
}

Expand Down
Loading