这是indexloc提供的服务,不要输入任何密码
Skip to content

fix use of normalizedHostingConfigs when it is called repeatedly #2748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixes issue in `hosting:channel` commands where a Firebase Hosting target may cause configuration parsing issues (#2746).
56 changes: 53 additions & 3 deletions scripts/hosting-tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ echo "Running with Application Creds: ${GOOGLE_APPLICATION_CREDENTIALS}"

echo "Target project: ${FBTOOLS_TARGET_PROJECT}"

echo "Initalizing some variables..."
echo "Initializing some variables..."
DATE="$(date)"
echo "Variables initalized..."

Expand All @@ -25,7 +25,7 @@ echo "Installing firebase-tools..."
npm link
echo "Installed firebase-tools: $(which firebase)"

echo "Initalizing temp directory..."
echo "Initializing temp directory..."
cd "${TEMP_DIR}"
cat > "firebase.json" <<- EOM
{
Expand All @@ -42,7 +42,7 @@ EOM
mkdir "public"
touch "public/${TARGET_FILE}"
echo "${DATE}" > "public/${TARGET_FILE}"
echo "Initalized temp directory."
echo "Initialized temp directory."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initalize me cap'n!


echo "Testing local serve..."
PORT=8685
Expand Down Expand Up @@ -72,3 +72,53 @@ sleep 5
VALUE="$(curl https://${FBTOOLS_TARGET_PROJECT}.web.app/${TARGET_FILE})"
test "${DATE}" = "${VALUE}" || (echo "Expected ${VALUE} to equal ${DATE}." && false)
echo "Tested hosting deployment."

# Test more complex scenarios:
echo "Creating second temp directory..."
TEMP_DIR="$(mktemp -d)"
echo "Created second temp directory: ${TEMP_DIR}"

echo "Initializing a new date..."
DATE="$(date)"
echo "Initialized a new date."

echo "Initializing second temp directory..."
cd "${TEMP_DIR}"
cat > "firebase.json" <<- EOM
{
"hosting": [
{
"target": "customtarget",
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
]
}
EOM
mkdir "public"
touch "public/${TARGET_FILE}"
echo "${DATE}" > "public/${TARGET_FILE}"
echo "Setting targets..."
firebase use --add "${FBTOOLS_TARGET_PROJECT}"
firebase target:apply hosting customtarget "${FBTOOLS_TARGET_PROJECT}"
echo "Set targets."
echo "Initialized second temp directory."

echo "Testing hosting deployment by target..."
firebase deploy --only hosting:customtarget --project "${FBTOOLS_TARGET_PROJECT}"
sleep 5
VALUE="$(curl https://${FBTOOLS_TARGET_PROJECT}.web.app/${TARGET_FILE})"
test "${DATE}" = "${VALUE}" || (echo "Expected ${VALUE} to equal ${DATE}." && false)
echo "Tested hosting deployment by target."

echo "Testing hosting channel deployment by target..."
firebase hosting:channel:deploy mychannel --only customtarget --project "${FBTOOLS_TARGET_PROJECT}" --json | tee output.json
sleep 5
CHANNEL_URL=$(cat output.json | jq -r ".result.customtarget.url")
VALUE="$(curl ${CHANNEL_URL}/${TARGET_FILE})"
test "${DATE}" = "${VALUE}" || (echo "Expected ${VALUE} to equal ${DATE}." && false)
echo "Tested hosting channel deployment by target."
3 changes: 2 additions & 1 deletion src/hosting/normalizedHostingConfigs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { bold } from "cli-color";
import { cloneDeep } from "lodash";

import { FirebaseError } from "../error";

Expand Down Expand Up @@ -65,7 +66,7 @@ export function normalizedHostingConfigs(
cmdOptions: any, // eslint-disable-line @typescript-eslint/no-explicit-any
options: { resolveTargets?: boolean } = {}
): HostingConfig[] {
let configs = cmdOptions.config.get("hosting");
let configs = cloneDeep(cmdOptions.config.get("hosting"));
if (!configs) {
return [];
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/hosting/normalizedHostingConfigs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ describe("normalizedHostingConfigs", () => {
);
});

it("should not modify the config when resolving targets", () => {
const singleHostingConfig = { target: "target" };
const cmdConfig = {
site: "default-site",
config: { get: () => singleHostingConfig },
rc: { requireTarget: () => ["default-site"] },
};
normalizedHostingConfigs(cmdConfig, { resolveTargets: true });
expect(singleHostingConfig).to.deep.equal({ target: "target" });
});

describe("without an only parameter", () => {
const DEFAULT_SITE = "default-hosting-site";
const baseConfig = { public: "public", ignore: ["firebase.json"] };
Expand Down