diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml index 252f706c..1676ca88 100644 --- a/.github/workflows/cli.yml +++ b/.github/workflows/cli.yml @@ -71,7 +71,18 @@ jobs: - name: Run tests run: npm run cli@test + - name: Pack CLI for smoke tests + id: pack-cli + working-directory: cli + run: | + set -euo pipefail + PACK_JSON="$(npm pack --pack-destination "$RUNNER_TEMP" --json)" + TARBALL="$(node -e 'process.stdout.write(JSON.parse(process.argv[1])[0].filename)' "$PACK_JSON")" + echo "tarball=$RUNNER_TEMP/$TARBALL" >> "$GITHUB_OUTPUT" + - name: Smoke test Foundry counter base + env: + COMPOSE_CLI_DEPENDENCY_SPEC: file:${{ steps.pack-cli.outputs.tarball }} run: | set -euo pipefail rm -rf ci-foundry @@ -84,6 +95,8 @@ jobs: forge build - name: Smoke test Hardhat counter base (ethers) + env: + COMPOSE_CLI_DEPENDENCY_SPEC: file:${{ steps.pack-cli.outputs.tarball }} run: | set -euo pipefail rm -rf ci-hardhat diff --git a/cli/src/adapters/IFrameworkAdapter/foundryAdapter/helpers.ts b/cli/src/adapters/IFrameworkAdapter/foundryAdapter/helpers.ts index c9a40d31..77edf5d7 100644 --- a/cli/src/adapters/IFrameworkAdapter/foundryAdapter/helpers.ts +++ b/cli/src/adapters/IFrameworkAdapter/foundryAdapter/helpers.ts @@ -1,5 +1,5 @@ import { withComposeProjectScripts } from "../../../modules/init/projectScripts"; -import { CLI_DEV_DEPENDENCY_VERSION, CLI_PACKAGE_NAME } from "../../../utils/metadata"; +import { CLI_DEV_DEPENDENCY_SPEC, CLI_PACKAGE_NAME } from "../../../utils/metadata"; /** Adds missing settings to a TOML section without overwriting existing values. */ export function ensureTomlSectionSettings( @@ -53,7 +53,7 @@ export function buildFoundryPackageJson(projectName: string): string { fmt: "forge fmt", }), devDependencies: { - [CLI_PACKAGE_NAME]: CLI_DEV_DEPENDENCY_VERSION, + [CLI_PACKAGE_NAME]: CLI_DEV_DEPENDENCY_SPEC, }, }; diff --git a/cli/src/adapters/IFrameworkAdapter/hardhatAdapter/adapter.ts b/cli/src/adapters/IFrameworkAdapter/hardhatAdapter/adapter.ts index 08d41e90..96a7d5cf 100644 --- a/cli/src/adapters/IFrameworkAdapter/hardhatAdapter/adapter.ts +++ b/cli/src/adapters/IFrameworkAdapter/hardhatAdapter/adapter.ts @@ -16,7 +16,7 @@ import { } from "../types"; import { toPosixPath, writeFileIfMissing } from "../../../utils/files"; import { runCommand } from "../../../utils/exec"; -import { CLI_DEV_DEPENDENCY_VERSION, CLI_PACKAGE_NAME } from "../../../utils/metadata"; +import { CLI_DEV_DEPENDENCY_SPEC, CLI_PACKAGE_NAME } from "../../../utils/metadata"; import { composePackageSubpath, isComposePackagePath, @@ -81,7 +81,7 @@ function updatePackageManifest( }, devDependencies: { ...currentDevDependencies, - [CLI_PACKAGE_NAME]: CLI_DEV_DEPENDENCY_VERSION, + [CLI_PACKAGE_NAME]: CLI_DEV_DEPENDENCY_SPEC, }, scripts: withComposeProjectScripts({ ...currentScripts, diff --git a/cli/src/modules/init/frameworkDeps.ts b/cli/src/modules/init/frameworkDeps.ts index 06bd87ae..9ecb626e 100644 --- a/cli/src/modules/init/frameworkDeps.ts +++ b/cli/src/modules/init/frameworkDeps.ts @@ -1,4 +1,4 @@ -import { CLI_DEV_DEPENDENCY_VERSION, CLI_PACKAGE_NAME } from "../../utils/metadata"; +import { CLI_DEV_DEPENDENCY_SPEC, CLI_PACKAGE_NAME } from "../../utils/metadata"; import { FrameworkDependencies } from "./types"; /** Hardhat release line used by Compose's generated Hardhat 3 projects. */ @@ -40,7 +40,7 @@ export function getFrameworkDependencies( { name: "Perfect-Abstractions/Compose", version: "(git submodule)" }, { name: CLI_PACKAGE_NAME, - version: `${CLI_DEV_DEPENDENCY_VERSION} (npm dev dependency)`, + version: `${CLI_DEV_DEPENDENCY_SPEC} (npm dev dependency)`, }, ], packageType: "packages", @@ -58,7 +58,7 @@ export function getFrameworkDependencies( "@nomicfoundation/hardhat-toolbox-mocha-ethers": "^3.0.7", }; - devDeps[CLI_PACKAGE_NAME] = CLI_DEV_DEPENDENCY_VERSION; + devDeps[CLI_PACKAGE_NAME] = CLI_DEV_DEPENDENCY_SPEC; return { deps: [ diff --git a/cli/src/utils/metadata.ts b/cli/src/utils/metadata.ts index de2f19a0..2a5eb891 100644 --- a/cli/src/utils/metadata.ts +++ b/cli/src/utils/metadata.ts @@ -15,8 +15,16 @@ export const LOCK_FILE_NAME = "compose.lock"; /** npm package that provides the `compose` binary. */ export const CLI_PACKAGE_NAME = "@perfect-abstractions/compose-cli"; -/** Version range written into generated projects so they run the CLI locally. */ -export const CLI_DEV_DEPENDENCY_VERSION = `^${VERSION}`; +/** Resolves the CLI dependency written into generated projects. */ +export function getCliDependencySpec(version: string, override?: string): string { + return override || `^${version}`; +} + +/** Dependency spec written into generated projects so they run the CLI locally. */ +export const CLI_DEV_DEPENDENCY_SPEC = getCliDependencySpec( + VERSION, + process.env.COMPOSE_CLI_DEPENDENCY_SPEC, +); export const COMPOSE_HEADER = ` _____ ____ __ __ _____ ____ _____ ______ _____ _ _____ diff --git a/cli/test/adapters/IFrameworkAdapter/foundryAdapter/scaffolding.test.ts b/cli/test/adapters/IFrameworkAdapter/foundryAdapter/scaffolding.test.ts index e36076a9..4c8c5130 100644 --- a/cli/test/adapters/IFrameworkAdapter/foundryAdapter/scaffolding.test.ts +++ b/cli/test/adapters/IFrameworkAdapter/foundryAdapter/scaffolding.test.ts @@ -2,7 +2,7 @@ import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; -import { CLI_DEV_DEPENDENCY_VERSION, CLI_PACKAGE_NAME } from "../../../../src/utils/metadata"; +import { CLI_DEV_DEPENDENCY_SPEC, CLI_PACKAGE_NAME } from "../../../../src/utils/metadata"; const { runCommand } = vi.hoisted(() => ({ runCommand: vi.fn(async () => undefined) })); @@ -61,7 +61,7 @@ describe("foundryAdapter project scaffolding", () => { validate: "compose validate", }); expect(packageJson.devDependencies).toEqual({ - [CLI_PACKAGE_NAME]: CLI_DEV_DEPENDENCY_VERSION, + [CLI_PACKAGE_NAME]: CLI_DEV_DEPENDENCY_SPEC, }); expect(runCommand).toHaveBeenCalledWith("forge", ["init", "."], { cwd: projectRoot }); }); diff --git a/cli/test/adapters/IFrameworkAdapter/hardhatAdapter/hardhatAdapter.test.ts b/cli/test/adapters/IFrameworkAdapter/hardhatAdapter/hardhatAdapter.test.ts index 306cfd2b..7b9d3627 100644 --- a/cli/test/adapters/IFrameworkAdapter/hardhatAdapter/hardhatAdapter.test.ts +++ b/cli/test/adapters/IFrameworkAdapter/hardhatAdapter/hardhatAdapter.test.ts @@ -13,7 +13,7 @@ import { import { resolveHardhatAstSourcePath } from "../../../../src/adapters/IFrameworkAdapter/hardhatAdapter/helpers"; import { Context } from "../../../../src/context/context"; import { ConfigModule } from "../../../../src/modules/config/module"; -import { CLI_DEV_DEPENDENCY_VERSION, CLI_PACKAGE_NAME } from "../../../../src/utils/metadata"; +import { CLI_DEV_DEPENDENCY_SPEC, CLI_PACKAGE_NAME } from "../../../../src/utils/metadata"; import { canonicalizeAst } from "../canonicalAst"; import { createHardhatAdapterFixtureHarness, @@ -208,7 +208,7 @@ describe("hardhatAdapter.writeConfig", () => { expect(config).toContain("npmFilesToBuild:"); const packageJson = JSON.parse(await fs.readFile(path.join(projectRoot, "package.json"), "utf8")); - expect(packageJson.devDependencies[CLI_PACKAGE_NAME]).toBe(CLI_DEV_DEPENDENCY_VERSION); + expect(packageJson.devDependencies[CLI_PACKAGE_NAME]).toBe(CLI_DEV_DEPENDENCY_SPEC); expect(packageJson.dependencies["@perfect-abstractions/compose"]).toBe("latest"); expect(packageJson.devDependencies["@nomicfoundation/hardhat-toolbox-mocha-ethers"]).toBe("^3.0.7"); expect(packageJson.engines.node).toBe(">=22.13.0"); diff --git a/cli/test/utils/metadata.test.ts b/cli/test/utils/metadata.test.ts new file mode 100644 index 00000000..f8cfa162 --- /dev/null +++ b/cli/test/utils/metadata.test.ts @@ -0,0 +1,21 @@ +import { readFile } from "node:fs/promises"; +import { describe, expect, it } from "vitest"; +import { + getCliDependencySpec, + VERSION, +} from "../../src/utils/metadata"; + +describe("CLI metadata", () => { + it("uses the CLI package.json version as its version source", async () => { + const packageJson = JSON.parse( + await readFile(new URL("../../package.json", import.meta.url), "utf8"), + ) as { version: string }; + + expect(VERSION).toBe(packageJson.version); + expect(getCliDependencySpec(VERSION)).toBe(`^${packageJson.version}`); + }); + + it("allows smoke tests to install the CLI from the checkout", () => { + expect(getCliDependencySpec("0.4.0", "file:../cli")).toBe("file:../cli"); + }); +});