firebase-tools 15.30.1 → 15.30.2
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/build.js +44 -12
- package/lib/deploy/functions/params.js +35 -60
- package/lib/deploy/functions/prepare.js +5 -2
- package/lib/emulator/auth/cloudFunctions.js +40 -5
- package/lib/emulator/downloadableEmulatorInfo.json +24 -24
- package/lib/emulator/functionsEmulator.js +13 -4
- package/lib/emulator/functionsEmulatorShared.js +14 -3
- package/lib/experiments.js +1 -1
- package/lib/fsutils.js +20 -2
- package/lib/functions/kits/install.js +142 -75
- package/lib/prompt.js +4 -0
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -24,6 +24,7 @@ exports.validateAndResolveDirectoryKit = validateAndResolveDirectoryKit;
|
|
|
24
24
|
exports.buildAndInstallDirectoryKit = buildAndInstallDirectoryKit;
|
|
25
25
|
exports.findKitConfig = findKitConfig;
|
|
26
26
|
exports.addInstanceToKitConfig = addInstanceToKitConfig;
|
|
27
|
+
exports.revertFunctionsConfig = revertFunctionsConfig;
|
|
27
28
|
exports.scaffoldKit = scaffoldKit;
|
|
28
29
|
exports.addInstanceToKit = addInstanceToKit;
|
|
29
30
|
exports.discoverKitBuild = discoverKitBuild;
|
|
@@ -56,9 +57,10 @@ const iam = require("../../gcp/iam");
|
|
|
56
57
|
const functionsEnv = require("../env");
|
|
57
58
|
const functionsConfig = require("../../functionsConfig");
|
|
58
59
|
const prepare_1 = require("../../deploy/functions/prepare");
|
|
59
|
-
const
|
|
60
|
+
const functional_1 = require("../../functional");
|
|
60
61
|
const env_1 = require("../env");
|
|
61
62
|
const env_2 = require("./env");
|
|
63
|
+
const fsutils_1 = require("../../fsutils");
|
|
62
64
|
exports.TEMPLATES = {
|
|
63
65
|
installation: "init/functions/typescript/index-kit.ts",
|
|
64
66
|
migration: "init/functions/typescript/index-kit-migration.ts",
|
|
@@ -540,6 +542,22 @@ function addInstanceToKitConfig(config, kitId, instanceId, configDirPath) {
|
|
|
540
542
|
target.instances[instanceId] = configDirPath;
|
|
541
543
|
config.writeProjectFile("firebase.json", config.src);
|
|
542
544
|
}
|
|
545
|
+
function revertFunctionsConfig(options) {
|
|
546
|
+
try {
|
|
547
|
+
if (!(0, utils_1.deepEqual)(options.config.src.functions, options.originalFunctions)) {
|
|
548
|
+
if (options.originalFunctions === undefined) {
|
|
549
|
+
delete options.config.src.functions;
|
|
550
|
+
}
|
|
551
|
+
else {
|
|
552
|
+
options.config.src.functions = options.originalFunctions;
|
|
553
|
+
}
|
|
554
|
+
options.config.writeProjectFile("firebase.json", options.config.src);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
catch (err) {
|
|
558
|
+
logger_1.logger.debug(`Failed to revert firebase.json: ${(0, error_1.getErrMsg)(err)}`);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
543
561
|
async function scaffoldKit(options) {
|
|
544
562
|
const paths = await scaffoldKitFiles(options.config, options.kitId, options.instanceId, options.packageName, options.templateType);
|
|
545
563
|
if (options.seedEnv?.envs && Object.keys(options.seedEnv.envs).length > 0) {
|
|
@@ -611,6 +629,12 @@ async function promptAndWriteKitParams(options) {
|
|
|
611
629
|
};
|
|
612
630
|
const rawUserEnvs = functionsEnv.loadUserEnvs(userEnvOpt);
|
|
613
631
|
const { userEnvs, secretRefs } = (0, prepare_1.partitionUserEnvs)(rawUserEnvs);
|
|
632
|
+
const parsedSecretRefs = (0, functional_1.mapObject)(secretRefs, (unparsed) => build.parseSecretRef(unparsed));
|
|
633
|
+
const secretPrefixForInstance = (0, projectConfig_1.addKitPrefix)(options.instanceId);
|
|
634
|
+
for (const secretParam of options.params.filter((p) => params.isSecretParam(p))) {
|
|
635
|
+
secretParam.resourceId = `${secretPrefixForInstance}-${secretParam.name}`;
|
|
636
|
+
}
|
|
637
|
+
build.applyEnvSecretBindingsToParams(options.params, parsedSecretRefs);
|
|
614
638
|
let firebaseConfig = { projectId: options.projectId };
|
|
615
639
|
try {
|
|
616
640
|
firebaseConfig = await functionsConfig.getFirebaseConfig({ projectId: options.projectId });
|
|
@@ -637,9 +661,9 @@ async function printKitFirstDeployReport(options) {
|
|
|
637
661
|
const prefix = (0, projectConfig_1.addKitPrefix)(options.instanceId);
|
|
638
662
|
try {
|
|
639
663
|
discoveredBuild = options.preDiscoveredBuild
|
|
640
|
-
? (0,
|
|
664
|
+
? (0, utils_1.cloneDeep)(options.preDiscoveredBuild)
|
|
641
665
|
: await discoverKitBuild(options, options.absSourcePath);
|
|
642
|
-
build.
|
|
666
|
+
build.applyEndpointPrefix(discoveredBuild, prefix);
|
|
643
667
|
}
|
|
644
668
|
catch (err) {
|
|
645
669
|
logger_1.logger.debug(`Could not discover kit build for reporting: ${(0, error_1.getErrMsg)(err)}`);
|
|
@@ -687,7 +711,8 @@ async function printKitFirstDeployReport(options) {
|
|
|
687
711
|
(0, utils_1.logLabeledWarning)("functions", `${clc.bold("Please review the changes above. If you do not want them applied to your project, uninstall this kit before running firebase deploy.")}`);
|
|
688
712
|
}
|
|
689
713
|
}
|
|
690
|
-
async function addKitInstanceOrConfigureProject(options
|
|
714
|
+
async function addKitInstanceOrConfigureProject(options) {
|
|
715
|
+
const { existingKit, existingFunctionsInfo, createdPaths = [] } = options;
|
|
691
716
|
const projectId = (0, projectUtils_1.getProjectId)(options) || options.projectId;
|
|
692
717
|
const projectAlias = options.rc?.hasProjects && options.project && options.rc.hasProjectAlias(options.project)
|
|
693
718
|
? options.project
|
|
@@ -735,6 +760,9 @@ async function addKitInstanceOrConfigureProject(options, existingKit, existingFu
|
|
|
735
760
|
if (action === "addInstance") {
|
|
736
761
|
resultAction = "addedInstance";
|
|
737
762
|
instanceId = await promptKitInstanceId(options.defaultInstanceId ?? existingKit.kit, existingFunctionsInfo.existingInstanceIds, existingFunctionsInfo.existingCodebases, options.nonInteractive, options.instanceId);
|
|
763
|
+
const expectedConfigDirPath = path.join(exports.FUNCTION_KITS_DIR, existingKit.kit, `config-${instanceId}`);
|
|
764
|
+
absConfigDirPath = options.config.path(expectedConfigDirPath);
|
|
765
|
+
createdPaths.push(absConfigDirPath);
|
|
738
766
|
const result = await addInstanceToKit({
|
|
739
767
|
config: options.config,
|
|
740
768
|
kitId: existingKit.kit,
|
|
@@ -756,6 +784,12 @@ async function addKitInstanceOrConfigureProject(options, existingKit, existingFu
|
|
|
756
784
|
throw new error_1.FirebaseError(`Configuration directory for instance '${instanceId}' not found in kit '${existingKit.kit}'.`);
|
|
757
785
|
}
|
|
758
786
|
absConfigDirPath = options.config.path(configDirPath);
|
|
787
|
+
if (projectId) {
|
|
788
|
+
const envPath = path.join(absConfigDirPath, `.env.${projectId}`);
|
|
789
|
+
if (!(await fs.pathExists(envPath))) {
|
|
790
|
+
createdPaths.push(envPath);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
759
793
|
if (options.seedEnv?.envs && Object.keys(options.seedEnv.envs).length > 0) {
|
|
760
794
|
await fs.ensureDir(absConfigDirPath);
|
|
761
795
|
(0, env_2.seedKitInstanceEnv)({
|
|
@@ -897,80 +931,113 @@ async function installKitOrInstance(options) {
|
|
|
897
931
|
if (options.directory && options.template) {
|
|
898
932
|
throw new error_1.FirebaseError("Cannot specify --template with --directory.");
|
|
899
933
|
}
|
|
900
|
-
const
|
|
901
|
-
const
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
functionsSource: absSourcePath,
|
|
915
|
-
projectDir: options.config.projectDir,
|
|
916
|
-
projectId: options.seedEnv.projectId,
|
|
917
|
-
projectAlias: options.seedEnv.projectAlias,
|
|
918
|
-
envs: options.seedEnv.envs,
|
|
919
|
-
});
|
|
920
|
-
}
|
|
921
|
-
await source.buildAndInstall(absSourcePath);
|
|
922
|
-
const projectId = (0, projectUtils_1.getProjectId)(options) || options.projectId;
|
|
923
|
-
const projectAlias = options.rc?.hasProjects && options.project && options.rc.hasProjectAlias(options.project)
|
|
924
|
-
? options.project
|
|
925
|
-
: undefined;
|
|
926
|
-
if (projectId) {
|
|
927
|
-
fs.ensureFileSync(path.join(absConfigDirPath, `.env.${projectId}`));
|
|
928
|
-
}
|
|
929
|
-
let discoveredBuild;
|
|
930
|
-
const shouldConfigure = options.configure !== false;
|
|
931
|
-
if (shouldConfigure) {
|
|
932
|
-
try {
|
|
933
|
-
discoveredBuild = await discoverKitBuild({ ...options, instanceId }, absSourcePath);
|
|
934
|
+
const originalFunctions = (0, utils_1.cloneDeep)(options.config.src.functions);
|
|
935
|
+
const createdPaths = [];
|
|
936
|
+
let kitId;
|
|
937
|
+
try {
|
|
938
|
+
const existingFunctionsInfo = extractExistingFunctionsInfo(options.config.src.functions);
|
|
939
|
+
const existingKit = findExistingKit(existingFunctionsInfo.existingFunctions, options);
|
|
940
|
+
if (existingKit) {
|
|
941
|
+
kitId = existingKit.kit;
|
|
942
|
+
return await addKitInstanceOrConfigureProject({
|
|
943
|
+
...options,
|
|
944
|
+
existingKit,
|
|
945
|
+
existingFunctionsInfo,
|
|
946
|
+
createdPaths,
|
|
947
|
+
});
|
|
934
948
|
}
|
|
935
|
-
|
|
936
|
-
|
|
949
|
+
const source = options.directory
|
|
950
|
+
? await resolveDirectorySource(options)
|
|
951
|
+
: await resolvePackageSource(options);
|
|
952
|
+
kitId = await promptKitId(source.defaultKitName, existingFunctionsInfo.existingKitIds, options.nonInteractive, options.kitId);
|
|
953
|
+
const instanceId = await promptKitInstanceId(options.defaultInstanceId ?? kitId, existingFunctionsInfo.existingInstanceIds, existingFunctionsInfo.existingCodebases, options.nonInteractive, options.instanceId);
|
|
954
|
+
const isPackageKit = !options.directory;
|
|
955
|
+
const absKitDir = options.config.path(path.join(exports.FUNCTION_KITS_DIR, kitId));
|
|
956
|
+
const expectedConfigDirPath = path.join(exports.FUNCTION_KITS_DIR, kitId, `config-${instanceId}`);
|
|
957
|
+
const absConfigDirPath = options.config.path(expectedConfigDirPath);
|
|
958
|
+
if (isPackageKit) {
|
|
959
|
+
createdPaths.push(absKitDir);
|
|
937
960
|
}
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
961
|
+
else {
|
|
962
|
+
createdPaths.push(absConfigDirPath);
|
|
963
|
+
}
|
|
964
|
+
const setupResult = await source.setup(kitId, instanceId);
|
|
965
|
+
const { sourcePath, configDirPath, absSourcePath } = setupResult;
|
|
966
|
+
if (options.seedEnv?.envs && Object.keys(options.seedEnv.envs).length > 0) {
|
|
967
|
+
(0, env_2.seedKitInstanceEnv)({
|
|
968
|
+
configDir: setupResult.absConfigDirPath,
|
|
969
|
+
functionsSource: absSourcePath,
|
|
970
|
+
projectDir: options.config.projectDir,
|
|
971
|
+
projectId: options.seedEnv.projectId,
|
|
972
|
+
projectAlias: options.seedEnv.projectAlias,
|
|
973
|
+
envs: options.seedEnv.envs,
|
|
949
974
|
});
|
|
950
975
|
}
|
|
976
|
+
await source.buildAndInstall(absSourcePath);
|
|
977
|
+
const projectId = (0, projectUtils_1.getProjectId)(options) || options.projectId;
|
|
978
|
+
const projectAlias = options.rc?.hasProjects && options.project && options.rc.hasProjectAlias(options.project)
|
|
979
|
+
? options.project
|
|
980
|
+
: undefined;
|
|
981
|
+
if (projectId) {
|
|
982
|
+
fs.ensureFileSync(path.join(setupResult.absConfigDirPath, `.env.${projectId}`));
|
|
983
|
+
}
|
|
984
|
+
let discoveredBuild;
|
|
985
|
+
const shouldConfigure = options.configure !== false;
|
|
986
|
+
if (shouldConfigure) {
|
|
987
|
+
try {
|
|
988
|
+
discoveredBuild = await discoverKitBuild({ ...options, instanceId }, absSourcePath);
|
|
989
|
+
}
|
|
990
|
+
catch (err) {
|
|
991
|
+
logger_1.logger.debug(`Could not discover kit build for params prompting: ${(0, error_1.getErrMsg)(err)}`);
|
|
992
|
+
}
|
|
993
|
+
if (discoveredBuild?.params && discoveredBuild.params.length > 0) {
|
|
994
|
+
await promptAndWriteKitParams({
|
|
995
|
+
config: options.config,
|
|
996
|
+
projectId,
|
|
997
|
+
projectAlias,
|
|
998
|
+
absConfigDirPath: setupResult.absConfigDirPath,
|
|
999
|
+
absSourcePath,
|
|
1000
|
+
instanceId,
|
|
1001
|
+
nonInteractive: options.nonInteractive,
|
|
1002
|
+
force: options.force,
|
|
1003
|
+
params: discoveredBuild.params,
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
addKitToConfig(options.config, {
|
|
1008
|
+
kitId,
|
|
1009
|
+
instanceId,
|
|
1010
|
+
packageName: source.sourcePackageName,
|
|
1011
|
+
sourcePath,
|
|
1012
|
+
configDirPath,
|
|
1013
|
+
hasBuildScript: source.hasBuildScript,
|
|
1014
|
+
});
|
|
1015
|
+
(0, utils_1.logLabeledSuccess)("functions", `Function kit ${clc.bold(kitId)} successfully installed.`);
|
|
1016
|
+
await printKitFirstDeployReport({
|
|
1017
|
+
config: options.config,
|
|
1018
|
+
project: options.project,
|
|
1019
|
+
projectId: options.projectId,
|
|
1020
|
+
instanceId,
|
|
1021
|
+
absSourcePath,
|
|
1022
|
+
preDiscoveredBuild: discoveredBuild,
|
|
1023
|
+
});
|
|
1024
|
+
return {
|
|
1025
|
+
action: "installedKit",
|
|
1026
|
+
kitId,
|
|
1027
|
+
instanceId,
|
|
1028
|
+
sourcePath,
|
|
1029
|
+
configDirPath,
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
catch (err) {
|
|
1033
|
+
await Promise.all(createdPaths.map((targetPath) => fs.remove(targetPath).catch((cleanupErr) => {
|
|
1034
|
+
logger_1.logger.debug(`Failed to clean up path '${targetPath}': ${(0, error_1.getErrMsg)(cleanupErr)}`);
|
|
1035
|
+
})));
|
|
1036
|
+
if (kitId) {
|
|
1037
|
+
await (0, fsutils_1.removeDirectoryIfEmpty)(options.config.path(path.join(exports.FUNCTION_KITS_DIR, kitId)));
|
|
1038
|
+
}
|
|
1039
|
+
await (0, fsutils_1.removeDirectoryIfEmpty)(options.config.path(exports.FUNCTION_KITS_DIR));
|
|
1040
|
+
revertFunctionsConfig({ config: options.config, originalFunctions });
|
|
1041
|
+
throw err;
|
|
951
1042
|
}
|
|
952
|
-
addKitToConfig(options.config, {
|
|
953
|
-
kitId,
|
|
954
|
-
instanceId,
|
|
955
|
-
packageName: source.sourcePackageName,
|
|
956
|
-
sourcePath,
|
|
957
|
-
configDirPath,
|
|
958
|
-
hasBuildScript: source.hasBuildScript,
|
|
959
|
-
});
|
|
960
|
-
(0, utils_1.logLabeledSuccess)("functions", `Function kit ${clc.bold(kitId)} successfully installed.`);
|
|
961
|
-
await printKitFirstDeployReport({
|
|
962
|
-
config: options.config,
|
|
963
|
-
project: options.project,
|
|
964
|
-
projectId: options.projectId,
|
|
965
|
-
instanceId,
|
|
966
|
-
absSourcePath,
|
|
967
|
-
preDiscoveredBuild: discoveredBuild,
|
|
968
|
-
});
|
|
969
|
-
return {
|
|
970
|
-
action: "installedKit",
|
|
971
|
-
kitId,
|
|
972
|
-
instanceId,
|
|
973
|
-
sourcePath,
|
|
974
|
-
configDirPath,
|
|
975
|
-
};
|
|
976
1043
|
}
|
package/lib/prompt.js
CHANGED
|
@@ -82,8 +82,12 @@ async function select(opts) {
|
|
|
82
82
|
if (shouldReturn) {
|
|
83
83
|
return value;
|
|
84
84
|
}
|
|
85
|
+
const instructions = typeof opts.instructions === "string"
|
|
86
|
+
? { navigation: opts.instructions, pager: opts.instructions }
|
|
87
|
+
: opts.instructions;
|
|
85
88
|
return inquirer.select({
|
|
86
89
|
...opts,
|
|
90
|
+
instructions,
|
|
87
91
|
loop: false,
|
|
88
92
|
});
|
|
89
93
|
}
|