diff --git a/action-env-setup.ts b/action-env-setup.ts deleted file mode 100644 index 75c7e92..0000000 --- a/action-env-setup.ts +++ /dev/null @@ -1 +0,0 @@ -process.env.INPUT_QUIET ??= "false"; diff --git a/src/index.ts b/src/index.ts index 3e18064..927c727 100755 --- a/src/index.ts +++ b/src/index.ts @@ -9,8 +9,7 @@ import { getBooleanInput, } from "@actions/core"; import { execSync, exec } from "node:child_process"; -import { existsSync } from "node:fs"; -import * as path from "node:path"; +import { checkWorkingDirectory, getNpxCmd, semverCompare } from "./utils"; import * as util from "node:util"; const execAsync = util.promisify(exec); @@ -31,10 +30,6 @@ const config = { QUIET_MODE: getBooleanInput("quiet"), } as const; -function getNpxCmd() { - return process.env.RUNNER_OS === "Windows" ? "npx.cmd" : "npx"; -} - function info(message: string, bypass?: boolean): void { if (!config.QUIET_MODE || bypass) { originalInfo(message); @@ -59,26 +54,6 @@ function endGroup(): void { } } -/** - * A helper function to compare two semver versions. If the second arg is greater than the first arg, it returns true. - */ -function semverCompare(version1: string, version2: string) { - if (version2 === "latest") return true; - - const version1Parts = version1.split("."); - const version2Parts = version2.split("."); - - for (const version1Part of version1Parts) { - const version2Part = version2Parts.shift(); - - if (version1Part !== version2Part && version2Part) { - return version1Part < version2Part ? true : false; - } - } - - return false; -} - async function main() { try { installWrangler(); @@ -112,15 +87,6 @@ async function runProcess( } } -function checkWorkingDirectory(workingDirectory = ".") { - const normalizedPath = path.normalize(workingDirectory); - if (existsSync(normalizedPath)) { - return normalizedPath; - } else { - throw new Error(`Directory ${workingDirectory} does not exist.`); - } -} - function installWrangler() { if (config["WRANGLER_VERSION"].startsWith("1")) { throw new Error( @@ -310,7 +276,4 @@ export { uploadSecrets, authenticationSetup, installWrangler, - checkWorkingDirectory, - getNpxCmd, - semverCompare, }; diff --git a/src/index.test.ts b/src/utils.test.ts similarity index 79% rename from src/index.test.ts rename to src/utils.test.ts index 8210778..cfe65cf 100644 --- a/src/index.test.ts +++ b/src/utils.test.ts @@ -1,18 +1,7 @@ import { expect, test, describe } from "vitest"; -import { checkWorkingDirectory, getNpxCmd, semverCompare } from "./index"; +import { checkWorkingDirectory, getNpxCmd, semverCompare } from "./utils"; import path from "node:path"; -const config = { - WRANGLER_VERSION: "mockVersion", - secrets: ["mockSercret", "mockSecretAgain"], - workingDirectory: "./mockWorkingDirectory", - CLOUDFLARE_API_TOKEN: "mockAPIToken", - CLOUDFLARE_ACCOUNT_ID: "mockAccountID", - ENVIRONMENT: undefined, - VARS: ["mockVar", "mockVarAgain"], - COMMANDS: ["mockCommand", "mockCommandAgain"], -}; - test("getNpxCmd ", async () => { process.env.RUNNER_OS = "Windows"; expect(getNpxCmd()).toBe("npx.cmd"); diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..ab6d0d2 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,35 @@ +import { existsSync } from "node:fs"; +import * as path from "node:path"; + +export function getNpxCmd() { + return process.env.RUNNER_OS === "Windows" ? "npx.cmd" : "npx"; +} + +/** + * A helper function to compare two semver versions. If the second arg is greater than the first arg, it returns true. + */ +export function semverCompare(version1: string, version2: string) { + if (version2 === "latest") return true; + + const version1Parts = version1.split("."); + const version2Parts = version2.split("."); + + for (const version1Part of version1Parts) { + const version2Part = version2Parts.shift(); + + if (version1Part !== version2Part && version2Part) { + return version1Part < version2Part ? true : false; + } + } + + return false; +} + +export function checkWorkingDirectory(workingDirectory = ".") { + const normalizedPath = path.normalize(workingDirectory); + if (existsSync(normalizedPath)) { + return normalizedPath; + } else { + throw new Error(`Directory ${workingDirectory} does not exist.`); + } +} diff --git a/tsconfig.json b/tsconfig.json index 99fbbbf..03e6f29 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,12 +9,12 @@ "isolatedModules": true, "target": "ESNext", "module": "ESNext", - "moduleResolution": "NodeNext", + "moduleResolution": "Bundler", "rootDir": "./src", "outDir": "./dist", "lib": ["ESNext"], "types": ["node", "@cloudflare/workers-types"] }, "exclude": ["node_modules", "**/*.test.ts"], - "include": ["src/index.ts"] + "include": ["src"] } diff --git a/vitest.config.ts b/vitest.config.ts deleted file mode 100644 index d5d5cd3..0000000 --- a/vitest.config.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { defineConfig } from "vitest/dist/config"; - -export default defineConfig({ - test: { - setupFiles: ["./action-env-setup.ts"], - }, -});