From 90abd454e1a21859064a04e08c0c73d7f958554f Mon Sep 17 00:00:00 2001 From: Jikun <36817715+cjk7989@users.noreply.github.com> Date: Wed, 8 Nov 2023 23:04:05 +0800 Subject: [PATCH] fix: fix unknown deployment error in Linux (#778) --- src/cli/commands/deploy/deploy.ts | 13 +++---------- src/core/constants.ts | 1 - src/core/deploy-client.ts | 10 ++-------- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/cli/commands/deploy/deploy.ts b/src/cli/commands/deploy/deploy.ts index 9e2c131c..80ed018f 100644 --- a/src/cli/commands/deploy/deploy.ts +++ b/src/cli/commands/deploy/deploy.ts @@ -13,7 +13,7 @@ import { updateSwaCliConfigFile, } from "../../../core"; import { chooseOrCreateProjectDetails, getStaticSiteDeployment } from "../../../core/account"; -import { DEFAULT_RUNTIME_LANGUAGE, STATIC_SITE_CLIENT_WORKING_FOLDER } from "../../../core/constants"; +import { DEFAULT_RUNTIME_LANGUAGE } from "../../../core/constants"; import { cleanUp, getDeployClientPath } from "../../../core/deploy-client"; import { swaCLIEnv } from "../../../core/env"; import { getDefaultVersion } from "../../../core/functions-versions"; @@ -255,11 +255,6 @@ export async function deploy(options: SWACLIConfig) { FUNCTION_LANGUAGE_VERSION: apiVersion, }; - const clientWorkingDir = path.resolve(deployClientEnv.REPOSITORY_BASE ?? "", STATIC_SITE_CLIENT_WORKING_FOLDER); - if (!fs.existsSync(clientWorkingDir)) { - fs.mkdirSync(clientWorkingDir); - } - // set the DEPLOYMENT_ENVIRONMENT env variable only when the user has provided // a deployment environment which is not "production". if (options.env?.toLowerCase() !== "production" && options.env?.toLowerCase() !== "prod") { @@ -280,7 +275,6 @@ export async function deploy(options: SWACLIConfig) { logger.silly(`Deploying using ${cliEnv.SWA_CLI_DEPLOY_BINARY}`); logger.silly(`Deploying using the following options:`); logger.silly({ env: { ...cliEnv, ...deployClientEnv } }); - logger.silly(`StaticSiteClient working directory: ${clientWorkingDir}`); spinner.start(`Preparing deployment. Please wait...`); @@ -288,7 +282,6 @@ export async function deploy(options: SWACLIConfig) { env: { ...swaCLIEnv(cliEnv, deployClientEnv), }, - cwd: clientWorkingDir, }); let projectUrl = ""; @@ -330,7 +323,7 @@ export async function deploy(options: SWACLIConfig) { }); child.on("close", (code) => { - cleanUp(clientWorkingDir); + cleanUp(); if (code === 0) { spinner.succeed(chalk.green(`Project deployed to ${chalk.underline(projectUrl)} 🚀`)); @@ -347,7 +340,7 @@ export async function deploy(options: SWACLIConfig) { ); logGitHubIssueMessageAndExit(); } finally { - cleanUp(clientWorkingDir); + cleanUp(); } } diff --git a/src/core/constants.ts b/src/core/constants.ts index 213e0e78..5c5a88f5 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -8,7 +8,6 @@ export const DEPLOY_BINARY_NAME = "StaticSitesClient"; export const DEPLOY_BINARY_STABLE_TAG = "stable"; export const DEPLOY_FOLDER = path.join(os.homedir(), ".swa", "deploy"); export const STATIC_SITE_CLIENT_RELEASE_METADATA_URL = "https://swalocaldeploy.azureedge.net/downloads/versions.json"; -export const STATIC_SITE_CLIENT_WORKING_FOLDER = "staticsites-cli"; // Data-api-builder related constants export const DATA_API_BUILDER_BINARY_NAME = "DataApiBuilder"; diff --git a/src/core/deploy-client.ts b/src/core/deploy-client.ts index b88388f7..20b704d7 100644 --- a/src/core/deploy-client.ts +++ b/src/core/deploy-client.ts @@ -109,9 +109,9 @@ export async function fetchClientVersionDefinition(releaseVersion: string): Prom // TODO: get StaticSiteClient to remove zip files // TODO: can these ZIPs be created under /tmp? -export function cleanUp(clientWorkingDir: string) { +export function cleanUp() { const clean = (file: string) => { - const filepath = path.join(clientWorkingDir, file); + const filepath = path.join(process.cwd(), file); if (fs.existsSync(filepath)) { try { fs.unlinkSync(filepath); @@ -121,10 +121,4 @@ export function cleanUp(clientWorkingDir: string) { clean(".\\app.zip"); clean(".\\api.zip"); - - if (fs.existsSync(clientWorkingDir)) { - try { - fs.rmdirSync(clientWorkingDir, { recursive: true }); - } catch {} - } }