Skip to content

Commit 7910bb2

Browse files
authored
Lift GCF 2nd gen naming restrictions (#5690)
Fixes #5695
1 parent 18c03e7 commit 7910bb2

File tree

3 files changed

+10
-25
lines changed

3 files changed

+10
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
- Propagates page token from ListDocumentsResponse to GetOrListDocumentsResponse in Firestore emulator.
33
- Fixes an issue where Secret Manager secrets were tagged incorrectly (#5704).
44
- Fix bug where Custom Event channels weren't automatically crated on function deploys (#5700)
5+
- Lift GCF 2nd gen naming restrictions (#5690)

src/deploy/functions/validate.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -198,27 +198,15 @@ export function functionsDirectoryExists(sourceDir: string, projectDir: string):
198198
* @throws { FirebaseError } Function names must be valid.
199199
*/
200200
export function functionIdsAreValid(functions: { id: string; platform: string }[]): void {
201-
const v1FunctionName = /^[a-zA-Z][a-zA-Z0-9_-]{0,62}$/;
202-
const invalidV1Ids = functions.filter((fn) => {
203-
return fn.platform === "gcfv1" && !v1FunctionName.test(fn.id);
204-
});
205-
if (invalidV1Ids.length !== 0) {
201+
// TODO: cannot end with a _ or -
202+
const functionName = /^[a-zA-Z][a-zA-Z0-9_-]{0,62}$/;
203+
const invalidIds = functions.filter((fn) => !functionName.test(fn.id));
204+
if (invalidIds.length !== 0) {
206205
const msg =
207-
`${invalidV1Ids.map((f) => f.id).join(", ")} function name(s) can only contain letters, ` +
206+
`${invalidIds.map((f) => f.id).join(", ")} function name(s) can only contain letters, ` +
208207
`numbers, hyphens, and not exceed 62 characters in length`;
209208
throw new FirebaseError(msg);
210209
}
211-
212-
const v2FunctionName = /^[a-z][a-z0-9-]{0,62}$/;
213-
const invalidV2Ids = functions.filter((fn) => {
214-
return fn.platform === "gcfv2" && !v2FunctionName.test(fn.id);
215-
});
216-
if (invalidV2Ids.length !== 0) {
217-
const msg =
218-
`${invalidV2Ids.map((f) => f.id).join(", ")} v2 function name(s) can only contain lower ` +
219-
`case letters, numbers, hyphens, and not exceed 62 characters in length`;
220-
throw new FirebaseError(msg);
221-
}
222210
}
223211

224212
/**

src/test/deploy/functions/validate.spec.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ describe("validate", () => {
8282
id: "my-function$%#",
8383
platform: "gcfv1",
8484
},
85-
{
86-
id: "my-function-2",
87-
platform: "gcfv2",
88-
},
8985
];
9086

9187
expect(() => {
@@ -103,18 +99,18 @@ describe("validate", () => {
10399
}).to.throw(FirebaseError);
104100
});
105101

106-
it("should throw error on capital letters in v2 function names", () => {
102+
it("should not throw error on capital letters in v2 function names", () => {
107103
const functions = [{ id: "Hi", platform: "gcfv2" }];
108104
expect(() => {
109105
validate.functionIdsAreValid(functions);
110-
}).to.throw(FirebaseError);
106+
}).to.not.throw();
111107
});
112108

113-
it("should throw error on underscores in v2 function names", () => {
109+
it("should not throw error on underscores in v2 function names", () => {
114110
const functions = [{ id: "o_O", platform: "gcfv2" }];
115111
expect(() => {
116112
validate.functionIdsAreValid(functions);
117-
}).to.throw(FirebaseError);
113+
}).to.not.throw();
118114
});
119115
});
120116

0 commit comments

Comments
 (0)