Skip to content
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
41 changes: 41 additions & 0 deletions schema/firebase-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,34 @@
],
"type": "object"
},
"RunSingle": {
"additionalProperties": false,
"properties": {
"ignore": {
"items": {
"type": "string"
},
"type": "array"
},
"localBuild": {
"type": "boolean"
},
"region": {
"type": "string"
},
"rootDir": {
"type": "string"
},
"serviceId": {
"type": "string"
}
},
"required": [
"region",
"serviceId"
],
"type": "object"
},
"StorageSingle": {
"additionalProperties": false,
"properties": {
Expand Down Expand Up @@ -2008,6 +2036,19 @@
"remoteconfig": {
"$ref": "#/definitions/RemoteConfigConfig"
},
"run": {
"anyOf": [
{
"$ref": "#/definitions/RunSingle"
},
{
"items": {
"$ref": "#/definitions/RunSingle"
},
"type": "array"
}
]
},
"storage": {
"anyOf": [
{
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,24 @@
"apphosting",
"auth",
"ailogic",
"run",
];

public options: any;

Check warning on line 40 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type
public projectDir: string;
public data: any = {};

Check warning on line 42 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type
public defaults: any = {};

Check warning on line 43 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type
public notes: any = {};

Check warning on line 44 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type

private _src: any;

Check warning on line 46 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type

/**
* @param src incoming firebase.json source, parsed by not validated.
* @param options command-line options.
*/
constructor(src: any, options: any = {}) {

Check warning on line 52 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type

Check warning on line 52 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type
this.options = options;

Check warning on line 53 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe assignment of an `any` value
this.projectDir = this.options.projectDir || detectProjectRoot(this.options);

Check warning on line 54 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe member access .projectDir on an `any` value

Check warning on line 54 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe assignment of an `any` value
this._src = src;

if (this._src.firebase) {
Expand Down
13 changes: 13 additions & 0 deletions src/firebaseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,18 @@ export type AppHostingMultiple = AppHostingSingle[];

export type AppHostingConfig = AppHostingSingle | AppHostingMultiple;

export interface RunSingle {
serviceId: string;
region: string;
rootDir?: string;
ignore?: string[];
localBuild?: boolean;
}

export type RunMultiple = RunSingle[];

export type RunConfig = RunSingle | RunMultiple;

export interface AuthConfig {
providers?: {
anonymous?: boolean;
Expand All @@ -392,4 +404,5 @@ export type FirebaseConfig = {
dataconnect?: DataConnectConfig;
apphosting?: AppHostingConfig;
auth?: AuthConfig;
run?: RunConfig;
};
81 changes: 81 additions & 0 deletions src/firebaseConfigValidate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,87 @@ describe("firebaseConfigValidate", () => {
expect(isValid).to.be.true;
});

function expectValidationError(
config: unknown,
keyword: string,
instancePath: string,
params: Record<string, unknown>,
): void {
const validator = getValidator();
expect(validator(config)).to.be.false;
expect(
(validator.errors ?? []).some(
(e) =>
e.keyword === keyword &&
e.instancePath === instancePath &&
Object.entries(params).every(([k, v]) => e.params[k] === v),
),
).to.be.true;
}

it("should accept a valid run config", () => {
const config: FirebaseConfig = {
run: [
{
serviceId: "my-service",
region: "us-central1",
rootDir: ".",
},
],
};

const validator = getValidator();
expect(validator(config)).to.be.true;
});
Comment thread
falahat marked this conversation as resolved.

it("should accept a single-object run config", () => {
const config: FirebaseConfig = {
run: {
serviceId: "my-service",
region: "us-central1",
localBuild: true,
},
};

const validator = getValidator();
expect(validator(config)).to.be.true;
});

it("should reject a run config missing serviceId", () => {
expectValidationError(
{ run: [{ region: "us-central1", rootDir: "." }] },
"required",
"/run/0",
{
missingProperty: "serviceId",
},
);
});

it("should reject a run config missing region", () => {
expectValidationError({ run: { serviceId: "my-service" } }, "required", "/run", {
missingProperty: "region",
});
});

it("should reject a run config with an unknown field", () => {
expectValidationError(
{ run: { serviceId: "my-service", region: "us-central1", bananas: true } },
"additionalProperties",
"/run",
{ additionalProperty: "bananas" },
);
});

it("should reject a run config with an incorrect type", () => {
expectValidationError(
{ run: { serviceId: "my-service", region: "us-central1", localBuild: "yes" } },
"type",
"/run/localBuild",
{ type: "boolean" },
);
});

it("should report an extra top-level field", () => {
// This config has an extra 'bananas' top-level property
const config = {
Expand Down
Loading