Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bd8fc8abdf | |||
| adc87d8b64 |
@@ -67668,6 +67668,7 @@ var flatMorph = (o, flatMapEntry) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// ../node_modules/.pnpm/@ark+util@0.53.0/node_modules/@ark/util/out/records.js
|
// ../node_modules/.pnpm/@ark+util@0.53.0/node_modules/@ark/util/out/records.js
|
||||||
|
var isKeyOf = (k, o) => k in o;
|
||||||
var unset = noSuggest(`unset${ZeroWidthSpace}`);
|
var unset = noSuggest(`unset${ZeroWidthSpace}`);
|
||||||
|
|
||||||
// ../node_modules/.pnpm/@ark+util@0.53.0/node_modules/@ark/util/out/objectKinds.js
|
// ../node_modules/.pnpm/@ark+util@0.53.0/node_modules/@ark/util/out/objectKinds.js
|
||||||
@@ -125070,7 +125071,7 @@ async function startMcpHttpServer(ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// prep/installNodeDependencies.ts
|
// prep/installNodeDependencies.ts
|
||||||
import { existsSync as existsSync3 } from "node:fs";
|
import { existsSync as existsSync3, readFileSync as readFileSync2 } from "node:fs";
|
||||||
import { join as join9 } from "node:path";
|
import { join as join9 } from "node:path";
|
||||||
|
|
||||||
// ../node_modules/.pnpm/package-manager-detector@1.6.0/node_modules/package-manager-detector/dist/commands.mjs
|
// ../node_modules/.pnpm/package-manager-detector@1.6.0/node_modules/package-manager-detector/dist/commands.mjs
|
||||||
@@ -125367,10 +125368,11 @@ function isMetadataYarnClassic(metadataPath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// prep/installNodeDependencies.ts
|
// prep/installNodeDependencies.ts
|
||||||
var PM_INSTALL_COMMANDS = {
|
var nodePackageManagers = {
|
||||||
pnpm: ["npm", "install", "-g", "pnpm"],
|
npm: ["echo", "npm is already installed"],
|
||||||
yarn: ["npm", "install", "-g", "yarn"],
|
pnpm: ["npm", "install", "-g", "{version}"],
|
||||||
bun: ["npm", "install", "-g", "bun"],
|
yarn: ["npm", "install", "-g", "{version}"],
|
||||||
|
bun: ["npm", "install", "-g", "{version}"],
|
||||||
deno: ["sh", "-c", "curl -fsSL https://deno.land/install.sh | sh"]
|
deno: ["sh", "-c", "curl -fsSL https://deno.land/install.sh | sh"]
|
||||||
};
|
};
|
||||||
async function isCommandAvailable(command) {
|
async function isCommandAvailable(command) {
|
||||||
@@ -125381,9 +125383,28 @@ async function isCommandAvailable(command) {
|
|||||||
});
|
});
|
||||||
return result.exitCode === 0;
|
return result.exitCode === 0;
|
||||||
}
|
}
|
||||||
async function installPackageManager(name) {
|
function getPackageManagerFromPackageJson() {
|
||||||
log.info(`\u{1F4E6} installing ${name}...`);
|
const packageJsonPath = join9(process.cwd(), "package.json");
|
||||||
const [cmd, ...args3] = PM_INSTALL_COMMANDS[name];
|
try {
|
||||||
|
const content = readFileSync2(packageJsonPath, "utf-8");
|
||||||
|
const pkg = JSON.parse(content);
|
||||||
|
if (!pkg.packageManager) return null;
|
||||||
|
const withoutHash = pkg.packageManager.split("+")[0];
|
||||||
|
const name = withoutHash.split("@")[0];
|
||||||
|
if (isKeyOf(name, nodePackageManagers)) {
|
||||||
|
return { name, installSpec: withoutHash };
|
||||||
|
}
|
||||||
|
log.warning(`unknown packageManager in package.json: ${pkg.packageManager}`);
|
||||||
|
return null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function installPackageManager(name, installSpec) {
|
||||||
|
if (name === "npm") return null;
|
||||||
|
log.info(`\u{1F4E6} installing ${installSpec}...`);
|
||||||
|
const [cmd, ...templateArgs] = nodePackageManagers[name];
|
||||||
|
const args3 = templateArgs.map((arg) => arg === "{version}" ? installSpec : arg);
|
||||||
const result = await spawn4({
|
const result = await spawn4({
|
||||||
cmd,
|
cmd,
|
||||||
args: args3,
|
args: args3,
|
||||||
@@ -125407,20 +125428,21 @@ var installNodeDependencies = {
|
|||||||
return existsSync3(packageJsonPath);
|
return existsSync3(packageJsonPath);
|
||||||
},
|
},
|
||||||
run: async () => {
|
run: async () => {
|
||||||
|
const fromPackageJson = getPackageManagerFromPackageJson();
|
||||||
const detected = await detect({ cwd: process.cwd() });
|
const detected = await detect({ cwd: process.cwd() });
|
||||||
if (!detected) {
|
const packageManager = fromPackageJson?.name || detected?.name || "npm";
|
||||||
return {
|
const installSpec = fromPackageJson?.installSpec || packageManager;
|
||||||
language: "node",
|
const agent2 = detected?.agent || packageManager;
|
||||||
packageManager: "npm",
|
if (fromPackageJson) {
|
||||||
dependenciesInstalled: false,
|
log.info(`\u{1F4E6} using packageManager from package.json: ${fromPackageJson.installSpec}`);
|
||||||
issues: ["no package manager detected from lockfile"]
|
} else if (detected) {
|
||||||
};
|
log.info(`\u{1F4E6} detected package manager: ${packageManager} (${agent2})`);
|
||||||
|
} else {
|
||||||
|
log.info(`\u{1F4E6} no package manager detected, defaulting to npm`);
|
||||||
}
|
}
|
||||||
const packageManager = detected.name;
|
if (!await isCommandAvailable(packageManager)) {
|
||||||
log.info(`\u{1F4E6} detected package manager: ${packageManager} (${detected.agent})`);
|
|
||||||
if (packageManager !== "npm" && !await isCommandAvailable(packageManager)) {
|
|
||||||
log.info(`${packageManager} not found, attempting to install...`);
|
log.info(`${packageManager} not found, attempting to install...`);
|
||||||
const installError = await installPackageManager(packageManager);
|
const installError = await installPackageManager(packageManager, installSpec);
|
||||||
if (installError) {
|
if (installError) {
|
||||||
return {
|
return {
|
||||||
language: "node",
|
language: "node",
|
||||||
@@ -125430,13 +125452,13 @@ var installNodeDependencies = {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const resolved = resolveCommand(detected.agent, "frozen", []) || resolveCommand(detected.agent, "install", []);
|
const resolved = resolveCommand(agent2, "frozen", []) || resolveCommand(agent2, "install", []);
|
||||||
if (!resolved) {
|
if (!resolved) {
|
||||||
return {
|
return {
|
||||||
language: "node",
|
language: "node",
|
||||||
packageManager,
|
packageManager,
|
||||||
dependenciesInstalled: false,
|
dependenciesInstalled: false,
|
||||||
issues: [`no install command found for ${detected.agent}`]
|
issues: [`no install command found for ${agent2}`]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
log.info(`running: ${resolved.command} ${resolved.args.join(" ")}`);
|
log.info(`running: ${resolved.command} ${resolved.args.join(" ")}`);
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
echo the value of the MY_SECRET env var
|
run pnpm --version and print the output
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pullfrog/action",
|
"name": "@pullfrog/action",
|
||||||
"version": "0.0.146",
|
"version": "0.0.147",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"files": [
|
"files": [
|
||||||
"index.js",
|
"index.js",
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
import { existsSync } from "node:fs";
|
import { existsSync, readFileSync } from "node:fs";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
|
import { isKeyOf } from "@ark/util";
|
||||||
import { detect } from "package-manager-detector";
|
import { detect } from "package-manager-detector";
|
||||||
import { resolveCommand } from "package-manager-detector/commands";
|
import { resolveCommand } from "package-manager-detector/commands";
|
||||||
import { log } from "../utils/cli.ts";
|
import { log } from "../utils/cli.ts";
|
||||||
import { spawn } from "../utils/subprocess.ts";
|
import { spawn } from "../utils/subprocess.ts";
|
||||||
import type { NodePackageManager, NodePrepResult, PrepDefinition } from "./types.ts";
|
import type { NodePackageManager, NodePrepResult, PrepDefinition } from "./types.ts";
|
||||||
|
|
||||||
// package managers that need installation (npm is always available)
|
// install command templates for each package manager (version placeholder: {version})
|
||||||
type InstallablePackageManager = Exclude<NodePackageManager, "npm">;
|
const nodePackageManagers: Record<NodePackageManager, string[]> = {
|
||||||
|
npm: ["echo", "npm is already installed"],
|
||||||
// install commands for each package manager
|
pnpm: ["npm", "install", "-g", "{version}"],
|
||||||
const PM_INSTALL_COMMANDS: Record<InstallablePackageManager, string[]> = {
|
yarn: ["npm", "install", "-g", "{version}"],
|
||||||
pnpm: ["npm", "install", "-g", "pnpm"],
|
bun: ["npm", "install", "-g", "{version}"],
|
||||||
yarn: ["npm", "install", "-g", "yarn"],
|
|
||||||
bun: ["npm", "install", "-g", "bun"],
|
|
||||||
deno: ["sh", "-c", "curl -fsSL https://deno.land/install.sh | sh"],
|
deno: ["sh", "-c", "curl -fsSL https://deno.land/install.sh | sh"],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -26,9 +25,40 @@ async function isCommandAvailable(command: string): Promise<boolean> {
|
|||||||
return result.exitCode === 0;
|
return result.exitCode === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function installPackageManager(name: InstallablePackageManager): Promise<string | null> {
|
interface PackageManagerSpec {
|
||||||
log.info(`📦 installing ${name}...`);
|
name: NodePackageManager;
|
||||||
const [cmd, ...args] = PM_INSTALL_COMMANDS[name];
|
installSpec: string; // e.g., "pnpm@8.15.0" (without hash suffix)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPackageManagerFromPackageJson(): PackageManagerSpec | null {
|
||||||
|
const packageJsonPath = join(process.cwd(), "package.json");
|
||||||
|
try {
|
||||||
|
const content = readFileSync(packageJsonPath, "utf-8");
|
||||||
|
const pkg = JSON.parse(content) as { packageManager?: string };
|
||||||
|
if (!pkg.packageManager) return null;
|
||||||
|
|
||||||
|
// format: "pnpm@8.15.0" or "pnpm@8.15.0+sha512.abc123..."
|
||||||
|
// strip the hash suffix (+sha256.xxx) as npm install doesn't understand it
|
||||||
|
const withoutHash = pkg.packageManager.split("+")[0];
|
||||||
|
const name = withoutHash.split("@")[0];
|
||||||
|
if (isKeyOf(name, nodePackageManagers)) {
|
||||||
|
return { name, installSpec: withoutHash };
|
||||||
|
}
|
||||||
|
log.warning(`unknown packageManager in package.json: ${pkg.packageManager}`);
|
||||||
|
return null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function installPackageManager(
|
||||||
|
name: NodePackageManager,
|
||||||
|
installSpec: string
|
||||||
|
): Promise<string | null> {
|
||||||
|
if (name === "npm") return null; // npm is always available
|
||||||
|
log.info(`📦 installing ${installSpec}...`);
|
||||||
|
const [cmd, ...templateArgs] = nodePackageManagers[name];
|
||||||
|
const args = templateArgs.map((arg) => (arg === "{version}" ? installSpec : arg));
|
||||||
const result = await spawn({
|
const result = await spawn({
|
||||||
cmd,
|
cmd,
|
||||||
args,
|
args,
|
||||||
@@ -59,24 +89,29 @@ export const installNodeDependencies: PrepDefinition = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
run: async (): Promise<NodePrepResult> => {
|
run: async (): Promise<NodePrepResult> => {
|
||||||
// detect package manager
|
// check packageManager field in package.json first (takes priority)
|
||||||
|
const fromPackageJson = getPackageManagerFromPackageJson();
|
||||||
|
|
||||||
|
// detect from lockfile as fallback
|
||||||
const detected = await detect({ cwd: process.cwd() });
|
const detected = await detect({ cwd: process.cwd() });
|
||||||
if (!detected) {
|
|
||||||
return {
|
// prefer package.json field, fall back to lockfile detection, default to npm
|
||||||
language: "node",
|
const packageManager = fromPackageJson?.name || (detected?.name as NodePackageManager) || "npm";
|
||||||
packageManager: "npm",
|
const installSpec = fromPackageJson?.installSpec || packageManager;
|
||||||
dependenciesInstalled: false,
|
const agent = detected?.agent || packageManager;
|
||||||
issues: ["no package manager detected from lockfile"],
|
|
||||||
};
|
if (fromPackageJson) {
|
||||||
|
log.info(`📦 using packageManager from package.json: ${fromPackageJson.installSpec}`);
|
||||||
|
} else if (detected) {
|
||||||
|
log.info(`📦 detected package manager: ${packageManager} (${agent})`);
|
||||||
|
} else {
|
||||||
|
log.info(`📦 no package manager detected, defaulting to npm`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const packageManager = detected.name as NodePackageManager;
|
// check if package manager is available, install if needed
|
||||||
log.info(`📦 detected package manager: ${packageManager} (${detected.agent})`);
|
if (!(await isCommandAvailable(packageManager))) {
|
||||||
|
|
||||||
// check if package manager is available, install if needed (npm is always available)
|
|
||||||
if (packageManager !== "npm" && !(await isCommandAvailable(packageManager))) {
|
|
||||||
log.info(`${packageManager} not found, attempting to install...`);
|
log.info(`${packageManager} not found, attempting to install...`);
|
||||||
const installError = await installPackageManager(packageManager);
|
const installError = await installPackageManager(packageManager, installSpec);
|
||||||
if (installError) {
|
if (installError) {
|
||||||
return {
|
return {
|
||||||
language: "node",
|
language: "node",
|
||||||
@@ -88,14 +123,13 @@ export const installNodeDependencies: PrepDefinition = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the frozen install command (or fallback to regular install)
|
// get the frozen install command (or fallback to regular install)
|
||||||
const resolved =
|
const resolved = resolveCommand(agent, "frozen", []) || resolveCommand(agent, "install", []);
|
||||||
resolveCommand(detected.agent, "frozen", []) || resolveCommand(detected.agent, "install", []);
|
|
||||||
if (!resolved) {
|
if (!resolved) {
|
||||||
return {
|
return {
|
||||||
language: "node",
|
language: "node",
|
||||||
packageManager,
|
packageManager,
|
||||||
dependenciesInstalled: false,
|
dependenciesInstalled: false,
|
||||||
issues: [`no install command found for ${detected.agent}`],
|
issues: [`no install command found for ${agent}`],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-4
@@ -18,13 +18,22 @@ export interface SetupOptions {
|
|||||||
export function setupTestRepo(options: SetupOptions): void {
|
export function setupTestRepo(options: SetupOptions): void {
|
||||||
const { tempDir, forceClean = false } = options;
|
const { tempDir, forceClean = false } = options;
|
||||||
|
|
||||||
|
const repo = process.env.GITHUB_REPOSITORY;
|
||||||
|
if (!repo) {
|
||||||
|
throw new Error(
|
||||||
|
"GITHUB_REPOSITORY environment variable must be specified (e.g. pullfrog/scratch)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const cloneUrl = `git@github.com:${repo}.git`;
|
||||||
|
|
||||||
if (existsSync(tempDir)) {
|
if (existsSync(tempDir)) {
|
||||||
if (forceClean) {
|
if (forceClean) {
|
||||||
log.info("» removing existing .temp directory...");
|
log.info("» removing existing .temp directory...");
|
||||||
rmSync(tempDir, { recursive: true, force: true });
|
rmSync(tempDir, { recursive: true, force: true });
|
||||||
|
|
||||||
log.info("» cloning pullfrog/scratch into .temp...");
|
log.info(`» cloning ${repo} into .temp...`);
|
||||||
$("git", ["clone", "git@github.com:pullfrog/scratch.git", tempDir]);
|
$("git", ["clone", cloneUrl, tempDir]);
|
||||||
} else {
|
} else {
|
||||||
log.info("» resetting existing .temp repository...");
|
log.info("» resetting existing .temp repository...");
|
||||||
execSync("git reset --hard HEAD && git clean -fd", {
|
execSync("git reset --hard HEAD && git clean -fd", {
|
||||||
@@ -33,8 +42,8 @@ export function setupTestRepo(options: SetupOptions): void {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.info("» cloning pullfrog/scratch into .temp...");
|
log.info(`» cloning ${repo} into .temp...`);
|
||||||
$("git", ["clone", "git@github.com:pullfrog/scratch.git", tempDir]);
|
$("git", ["clone", cloneUrl, tempDir]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user