firebase-tools 10.1.0 → 10.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/deploy/functions/prepare.js +15 -9
- package/lib/deploy/functions/runtimes/golang/index.js +4 -8
- package/lib/deploy/functions/runtimes/index.js +6 -10
- package/lib/deploy/functions/runtimes/node/index.js +5 -9
- package/lib/deploy/functions/runtimes/node/validate.js +2 -1
- package/lib/deploy/functions/validate.js +4 -3
- package/lib/emulator/auth/widget_ui.js +1 -1
- package/npm-shrinkwrap.json +775 -812
- package/package.json +1 -1
- package/standalone/firepit.js +4 -4
|
@@ -16,10 +16,10 @@ const projectUtils_1 = require("../../projectUtils");
|
|
|
16
16
|
const track_1 = require("../../track");
|
|
17
17
|
const runtimes = require("./runtimes");
|
|
18
18
|
const validate = require("./validate");
|
|
19
|
-
const utils = require("../../utils");
|
|
20
19
|
const logger_1 = require("../../logger");
|
|
21
20
|
const triggerRegionHelper_1 = require("./triggerRegionHelper");
|
|
22
21
|
const checkIam_1 = require("./checkIam");
|
|
22
|
+
const error_1 = require("../../error");
|
|
23
23
|
function hasUserConfig(config) {
|
|
24
24
|
return Object.keys(config).length > 1;
|
|
25
25
|
}
|
|
@@ -34,15 +34,23 @@ async function maybeEnableAR(projectId) {
|
|
|
34
34
|
return true;
|
|
35
35
|
}
|
|
36
36
|
async function prepare(context, options, payload) {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
38
|
+
const sourceDirName = options.config.get("functions.source");
|
|
39
|
+
if (!sourceDirName) {
|
|
40
|
+
throw new error_1.FirebaseError(`No functions code detected at default location (./functions), and no functions.source defined in firebase.json`);
|
|
39
41
|
}
|
|
40
|
-
const
|
|
42
|
+
const sourceDir = options.config.path(sourceDirName);
|
|
43
|
+
const delegateContext = {
|
|
44
|
+
projectId,
|
|
45
|
+
sourceDir,
|
|
46
|
+
projectDir: options.config.projectDir,
|
|
47
|
+
runtime: options.config.get("functions.runtime") || "",
|
|
48
|
+
};
|
|
49
|
+
const runtimeDelegate = await runtimes.getRuntimeDelegate(delegateContext);
|
|
41
50
|
logger_1.logger.debug(`Validating ${runtimeDelegate.name} source`);
|
|
42
51
|
await runtimeDelegate.validate();
|
|
43
52
|
logger_1.logger.debug(`Building ${runtimeDelegate.name} source`);
|
|
44
53
|
await runtimeDelegate.build();
|
|
45
|
-
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
46
54
|
const checkAPIsEnabled = await Promise.all([
|
|
47
55
|
ensureApiEnabled.ensure(projectId, "cloudfunctions.googleapis.com", "functions"),
|
|
48
56
|
ensureApiEnabled.check(projectId, "runtimeconfig.googleapis.com", "runtimeconfig", true),
|
|
@@ -54,11 +62,9 @@ async function prepare(context, options, payload) {
|
|
|
54
62
|
const firebaseConfig = await functionsConfig.getFirebaseConfig(options);
|
|
55
63
|
context.firebaseConfig = firebaseConfig;
|
|
56
64
|
const runtimeConfig = await (0, prepareFunctionsUpload_1.getFunctionsConfig)(context);
|
|
57
|
-
utils.assertDefined(options.config.src.functions.source, "Error: 'functions.source' is not defined");
|
|
58
|
-
const source = options.config.src.functions.source;
|
|
59
65
|
const firebaseEnvs = functionsEnv.loadFirebaseEnvs(firebaseConfig, projectId);
|
|
60
66
|
const userEnvOpt = {
|
|
61
|
-
functionsSource:
|
|
67
|
+
functionsSource: sourceDir,
|
|
62
68
|
projectId: projectId,
|
|
63
69
|
projectAlias: options.projectAlias,
|
|
64
70
|
};
|
|
@@ -92,7 +98,7 @@ async function prepare(context, options, payload) {
|
|
|
92
98
|
if (backend.someEndpoint(wantBackend, () => true)) {
|
|
93
99
|
(0, utils_1.logBullet)(clc.cyan.bold("functions:") +
|
|
94
100
|
" preparing " +
|
|
95
|
-
clc.bold(
|
|
101
|
+
clc.bold(sourceDirName) +
|
|
96
102
|
" directory for uploading...");
|
|
97
103
|
}
|
|
98
104
|
if (backend.someEndpoint(wantBackend, (e) => e.platform === "gcfv1")) {
|
|
@@ -10,7 +10,6 @@ const spawn = require("cross-spawn");
|
|
|
10
10
|
const error_1 = require("../../../../error");
|
|
11
11
|
const logger_1 = require("../../../../logger");
|
|
12
12
|
const discovery = require("../discovery");
|
|
13
|
-
const projectUtils_1 = require("../../../../projectUtils");
|
|
14
13
|
const gomod = require("./gomod");
|
|
15
14
|
const VERSION_TO_RUNTIME = {
|
|
16
15
|
"1.13": "go113",
|
|
@@ -19,11 +18,8 @@ exports.ADMIN_SDK = "firebase.google.com/go/v4";
|
|
|
19
18
|
exports.FUNCTIONS_SDK = "github.com/FirebaseExtended/firebase-functions-go";
|
|
20
19
|
exports.FUNCTIONS_CODEGEN = exports.FUNCTIONS_SDK + "/support/codegen";
|
|
21
20
|
exports.FUNCTIONS_RUNTIME = exports.FUNCTIONS_SDK + "/support/runtime";
|
|
22
|
-
async function tryCreateDelegate(context
|
|
23
|
-
const
|
|
24
|
-
const sourceDir = options.config.path(relativeSourceDir);
|
|
25
|
-
const goModPath = path.join(sourceDir, "go.mod");
|
|
26
|
-
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
21
|
+
async function tryCreateDelegate(context) {
|
|
22
|
+
const goModPath = path.join(context.sourceDir, "go.mod");
|
|
27
23
|
let module;
|
|
28
24
|
try {
|
|
29
25
|
const modBuffer = await (0, util_1.promisify)(fs.readFile)(goModPath);
|
|
@@ -33,7 +29,7 @@ async function tryCreateDelegate(context, options) {
|
|
|
33
29
|
logger_1.logger.debug("Customer code is not Golang code (or they aren't using gomod)");
|
|
34
30
|
return;
|
|
35
31
|
}
|
|
36
|
-
let runtime =
|
|
32
|
+
let runtime = context.runtime;
|
|
37
33
|
if (!runtime) {
|
|
38
34
|
if (!module.version) {
|
|
39
35
|
throw new error_1.FirebaseError("Could not detect Golang version from go.mod");
|
|
@@ -43,7 +39,7 @@ async function tryCreateDelegate(context, options) {
|
|
|
43
39
|
}
|
|
44
40
|
runtime = VERSION_TO_RUNTIME[module.version];
|
|
45
41
|
}
|
|
46
|
-
return new Delegate(projectId, sourceDir, runtime, module);
|
|
42
|
+
return new Delegate(context.projectId, context.sourceDir, runtime, module);
|
|
47
43
|
}
|
|
48
44
|
exports.tryCreateDelegate = tryCreateDelegate;
|
|
49
45
|
class Delegate {
|
|
@@ -30,22 +30,18 @@ function getHumanFriendlyRuntimeName(runtime) {
|
|
|
30
30
|
}
|
|
31
31
|
exports.getHumanFriendlyRuntimeName = getHumanFriendlyRuntimeName;
|
|
32
32
|
const factories = [node.tryCreateDelegate, golang.tryCreateDelegate];
|
|
33
|
-
async function getRuntimeDelegate(context
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
throw new error_1.FirebaseError(`No functions code detected at default location (./functions), and no functions.source defined in firebase.json`);
|
|
37
|
-
}
|
|
38
|
-
validate.functionsDirectoryExists(options, sourceDirName);
|
|
39
|
-
const runtime = options.config.get("functions.runtime");
|
|
33
|
+
async function getRuntimeDelegate(context) {
|
|
34
|
+
const { projectDir, sourceDir, runtime } = context;
|
|
35
|
+
validate.functionsDirectoryExists(sourceDir, projectDir);
|
|
40
36
|
if (runtime && !isValidRuntime(runtime)) {
|
|
41
|
-
throw new error_1.FirebaseError(
|
|
37
|
+
throw new error_1.FirebaseError(`Cannot deploy function with runtime ${runtime}`);
|
|
42
38
|
}
|
|
43
39
|
for (const factory of factories) {
|
|
44
|
-
const delegate = await factory(context
|
|
40
|
+
const delegate = await factory(context);
|
|
45
41
|
if (delegate) {
|
|
46
42
|
return delegate;
|
|
47
43
|
}
|
|
48
44
|
}
|
|
49
|
-
throw new error_1.FirebaseError(`Could not detect language for functions at ${
|
|
45
|
+
throw new error_1.FirebaseError(`Could not detect language for functions at ${sourceDir}`);
|
|
50
46
|
}
|
|
51
47
|
exports.getRuntimeDelegate = getRuntimeDelegate;
|
|
@@ -6,26 +6,22 @@ const fs = require("fs");
|
|
|
6
6
|
const path = require("path");
|
|
7
7
|
const error_1 = require("../../../../error");
|
|
8
8
|
const parseRuntimeAndValidateSDK_1 = require("./parseRuntimeAndValidateSDK");
|
|
9
|
-
const projectUtils_1 = require("../../../../projectUtils");
|
|
10
|
-
const validate = require("./validate");
|
|
11
9
|
const logger_1 = require("../../../../logger");
|
|
10
|
+
const validate = require("./validate");
|
|
12
11
|
const versioning = require("./versioning");
|
|
13
12
|
const parseTriggers = require("./parseTriggers");
|
|
14
|
-
async function tryCreateDelegate(context
|
|
15
|
-
const
|
|
16
|
-
const sourceDir = options.config.path(projectRelativeSourceDir);
|
|
17
|
-
const packageJsonPath = path.join(sourceDir, "package.json");
|
|
13
|
+
async function tryCreateDelegate(context) {
|
|
14
|
+
const packageJsonPath = path.join(context.sourceDir, "package.json");
|
|
18
15
|
if (!(await (0, util_1.promisify)(fs.exists)(packageJsonPath))) {
|
|
19
16
|
logger_1.logger.debug("Customer code is not Node");
|
|
20
17
|
return undefined;
|
|
21
18
|
}
|
|
22
|
-
|
|
23
|
-
runtime = (0, parseRuntimeAndValidateSDK_1.getRuntimeChoice)(sourceDir, runtime);
|
|
19
|
+
const runtime = (0, parseRuntimeAndValidateSDK_1.getRuntimeChoice)(context.sourceDir, context.runtime);
|
|
24
20
|
if (!runtime.startsWith("nodejs")) {
|
|
25
21
|
logger_1.logger.debug("Customer has a package.json but did not get a nodejs runtime. This should not happen");
|
|
26
22
|
throw new error_1.FirebaseError(`Unexpected runtime ${runtime}`);
|
|
27
23
|
}
|
|
28
|
-
return new Delegate(
|
|
24
|
+
return new Delegate(context.projectId, context.projectDir, context.sourceDir, runtime);
|
|
29
25
|
}
|
|
30
26
|
exports.tryCreateDelegate = tryCreateDelegate;
|
|
31
27
|
class Delegate {
|
|
@@ -9,7 +9,8 @@ const cjson = require("cjson");
|
|
|
9
9
|
function assertFunctionsSourcePresent(data, sourceDir, projectDir) {
|
|
10
10
|
const indexJsFile = path.join(sourceDir, data.main || "index.js");
|
|
11
11
|
if (!fsutils.fileExistsSync(indexJsFile)) {
|
|
12
|
-
const
|
|
12
|
+
const relativeMainPath = path.relative(projectDir, indexJsFile);
|
|
13
|
+
const msg = `${relativeMainPath} does not exist, can't deploy Cloud Functions`;
|
|
13
14
|
throw new error_1.FirebaseError(msg);
|
|
14
15
|
}
|
|
15
16
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.functionIdsAreValid = exports.functionsDirectoryExists = void 0;
|
|
4
|
+
const path = require("path");
|
|
4
5
|
const clc = require("cli-color");
|
|
5
6
|
const error_1 = require("../../error");
|
|
6
7
|
const fsutils = require("../../fsutils");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
function functionsDirectoryExists(sourceDir, projectDir) {
|
|
9
|
+
if (!fsutils.dirExistsSync(sourceDir)) {
|
|
10
|
+
const sourceDirName = path.relative(projectDir, sourceDir);
|
|
10
11
|
const msg = `could not deploy functions because the ${clc.bold('"' + sourceDirName + '"')} ` +
|
|
11
12
|
`directory was not found. Please create it or specify a different source directory in firebase.json`;
|
|
12
13
|
throw new error_1.FirebaseError(msg);
|