Skip to content

Commit bf66853

Browse files
committed
feat: remove obsolete parseTriggers fallback
1 parent 8960b47 commit bf66853

File tree

10 files changed

+85
-1757
lines changed

10 files changed

+85
-1757
lines changed

firebase-vscode/webpack.common.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,8 @@ const extensionConfig = {
196196
to: "./schema",
197197
},
198198
// TODO(hlshen): Sanity check if these should be fixed or removed. AFIACT, they exist for functions and hosting deploys, which are not relevant anymore.
199-
// Copy uncompiled JS files called at runtime by
200-
// firebase-tools/src/parseTriggers.ts
201-
// {
202-
// from: "*.js",
203-
// to: "./",
204-
// context: "../src/deploy/functions/runtimes/node",
205-
// },
206-
// // Copy cross-env-shell.js used to run predeploy scripts
207-
// // to ensure they work in Windows
199+
// Copy cross-env-shell.js used to run predeploy scripts
200+
// to ensure they work in Windows
208201
// {
209202
// from: "../node_modules/cross-env/dist",
210203
// to: "./cross-env/dist",

src/deploy/functions/runtimes/node/extractTriggers.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/deploy/functions/runtimes/node/extractTriggers.spec.js

Lines changed: 0 additions & 78 deletions
This file was deleted.

src/deploy/functions/runtimes/node/index.spec.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as versioning from "./versioning";
77
import * as utils from "../../../../utils";
88
import { FirebaseError } from "../../../../error";
99
import { Runtime } from "../supported";
10+
import * as discovery from "../discovery";
1011

1112
const PROJECT_ID = "test-project";
1213
const PROJECT_DIR = "/some/path";
@@ -77,4 +78,62 @@ describe("NodeDelegate", () => {
7778
expect(() => delegate.getNodeBinary()).to.throw(FirebaseError);
7879
});
7980
});
81+
82+
describe("discoverBuild", () => {
83+
let getFunctionsSDKVersionMock: sinon.SinonStub;
84+
let detectFromYamlMock: sinon.SinonStub;
85+
86+
beforeEach(() => {
87+
getFunctionsSDKVersionMock = sinon.stub(versioning, "getFunctionsSDKVersion");
88+
detectFromYamlMock = sinon.stub(discovery, "detectFromYaml");
89+
});
90+
91+
afterEach(() => {
92+
getFunctionsSDKVersionMock.restore();
93+
detectFromYamlMock.restore();
94+
});
95+
96+
it("throws error if SDK version is too old", async () => {
97+
getFunctionsSDKVersionMock.returns("3.19.0");
98+
const delegate = new node.Delegate(
99+
PROJECT_ID,
100+
PROJECT_DIR,
101+
SOURCE_DIR,
102+
"nodejs16" as Runtime,
103+
);
104+
try {
105+
await delegate.discoverBuild({}, {});
106+
throw new Error("Should have thrown");
107+
} catch (err: any) {
108+
expect(err).to.be.instanceOf(FirebaseError);
109+
expect(err.message).to.include("Please update firebase-functions SDK");
110+
}
111+
});
112+
113+
it("proceeds if SDK version is valid", async () => {
114+
getFunctionsSDKVersionMock.returns("4.0.0");
115+
detectFromYamlMock.resolves({ endpoints: {} });
116+
const delegate = new node.Delegate(
117+
PROJECT_ID,
118+
PROJECT_DIR,
119+
SOURCE_DIR,
120+
"nodejs16" as Runtime,
121+
);
122+
await delegate.discoverBuild({}, {});
123+
expect(detectFromYamlMock).to.have.been.called;
124+
});
125+
126+
it("proceeds if SDK version is invalid", async () => {
127+
getFunctionsSDKVersionMock.returns("not-a-version");
128+
detectFromYamlMock.resolves({ endpoints: {} });
129+
const delegate = new node.Delegate(
130+
PROJECT_ID,
131+
PROJECT_DIR,
132+
SOURCE_DIR,
133+
"nodejs16" as Runtime,
134+
);
135+
await delegate.discoverBuild({}, {});
136+
expect(detectFromYamlMock).to.have.been.called;
137+
});
138+
});
80139
});

src/deploy/functions/runtimes/node/index.ts

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { DelegateContext } from "..";
2323
import * as supported from "../supported";
2424
import * as validate from "./validate";
2525
import * as versioning from "./versioning";
26-
import * as parseTriggers from "./parseTriggers";
26+
2727
import { fileExistsSync } from "../../../../fsutils";
2828

2929
// The versions of the Firebase Functions SDK that added support for the container contract.
@@ -292,27 +292,23 @@ export class Delegate {
292292
env: backend.EnvironmentVariables,
293293
): Promise<build.Build> {
294294
if (!semver.valid(this.sdkVersion)) {
295-
logger.debug(
296-
`Could not parse firebase-functions version '${this.sdkVersion}' into semver. Falling back to parseTriggers.`,
297-
);
298-
return parseTriggers.discoverBuild(this.projectId, this.sourceDir, this.runtime, config, env);
299-
}
300-
if (semver.lt(this.sdkVersion, MIN_FUNCTIONS_SDK_VERSION)) {
301-
logLabeledWarning(
302-
"functions",
303-
`You are using an old version of firebase-functions SDK (${this.sdkVersion}). ` +
304-
`Please update firebase-functions SDK to >=${MIN_FUNCTIONS_SDK_VERSION}`,
305-
);
306-
return parseTriggers.discoverBuild(this.projectId, this.sourceDir, this.runtime, config, env);
307-
}
308-
// Perform a check for the minimum SDK version that added annotation support for the `Build.extensions` property
309-
// and log to the user explaining why they need to upgrade their version.
310-
if (semver.lt(this.sdkVersion, MIN_FUNCTIONS_SDK_VERSION_FOR_EXTENSIONS_FEATURES)) {
311-
logLabeledBullet(
312-
"functions",
313-
`You are using a version of firebase-functions SDK (${this.sdkVersion}) that does not have support for the newest Firebase Extensions features. ` +
314-
`Please update firebase-functions SDK to >=${MIN_FUNCTIONS_SDK_VERSION_FOR_EXTENSIONS_FEATURES} to use them correctly`,
315-
);
295+
logger.debug(`Could not parse firebase-functions version '${this.sdkVersion}' into semver.`);
296+
} else {
297+
if (semver.lt(this.sdkVersion, MIN_FUNCTIONS_SDK_VERSION)) {
298+
throw new FirebaseError(
299+
`You are using an old version of firebase-functions SDK (${this.sdkVersion}). ` +
300+
`Please update firebase-functions SDK to >=${MIN_FUNCTIONS_SDK_VERSION}`,
301+
);
302+
}
303+
// Perform a check for the minimum SDK version that added annotation support for the `Build.extensions` property
304+
// and log to the user explaining why they need to upgrade their version.
305+
if (semver.lt(this.sdkVersion, MIN_FUNCTIONS_SDK_VERSION_FOR_EXTENSIONS_FEATURES)) {
306+
logLabeledBullet(
307+
"functions",
308+
`You are using a version of firebase-functions SDK (${this.sdkVersion}) that does not have support for the newest Firebase Extensions features. ` +
309+
`Please update firebase-functions SDK to >=${MIN_FUNCTIONS_SDK_VERSION_FOR_EXTENSIONS_FEATURES} to use them correctly`,
310+
);
311+
}
316312
}
317313
let discovered = await discovery.detectFromYaml(this.sourceDir, this.projectId, this.runtime);
318314
if (!discovered) {

0 commit comments

Comments
 (0)