firebase-tools 12.1.0 → 12.2.0

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isEndpointFiltered = exports.isCodebaseFiltered = exports.groupEndpointsByCodebase = exports.targetCodebases = exports.getFunctionLabel = exports.getEndpointFilters = exports.parseFunctionSelector = exports.endpointMatchesFilter = exports.endpointMatchesAnyFilter = void 0;
3
+ exports.isEndpointFiltered = exports.isCodebaseFiltered = exports.groupEndpointsByCodebase = exports.targetCodebases = exports.getFunctionLabel = exports.getHumanFriendlyPlatformName = exports.getEndpointFilters = exports.parseFunctionSelector = exports.endpointMatchesFilter = exports.endpointMatchesAnyFilter = void 0;
4
4
  const backend = require("./backend");
5
5
  const projectConfig_1 = require("../../functions/projectConfig");
6
6
  function endpointMatchesAnyFilter(endpoint, filters) {
@@ -67,6 +67,13 @@ function getEndpointFilters(options) {
67
67
  return filters;
68
68
  }
69
69
  exports.getEndpointFilters = getEndpointFilters;
70
+ function getHumanFriendlyPlatformName(platform) {
71
+ if (platform === "gcfv1") {
72
+ return "1st Gen";
73
+ }
74
+ return "2nd Gen";
75
+ }
76
+ exports.getHumanFriendlyPlatformName = getHumanFriendlyPlatformName;
70
77
  function getFunctionLabel(fn) {
71
78
  let id = `${fn.id}(${fn.region})`;
72
79
  if (fn.codebase && fn.codebase !== projectConfig_1.DEFAULT_CODEBASE) {
@@ -25,6 +25,7 @@ const utils = require("../../../utils");
25
25
  const services = require("../services");
26
26
  const v1_1 = require("../../../functions/events/v1");
27
27
  const checkIam_1 = require("../checkIam");
28
+ const functionsDeployHelper_1 = require("../functionsDeployHelper");
28
29
  const gcfV1PollerOptions = {
29
30
  apiOrigin: api_1.functionsOrigin,
30
31
  apiVersion: gcf.API_VERSION,
@@ -536,8 +537,9 @@ class Fabricator {
536
537
  }
537
538
  logOpStart(op, endpoint) {
538
539
  const runtime = (0, runtimes_1.getHumanFriendlyRuntimeName)(endpoint.runtime);
540
+ const platform = (0, functionsDeployHelper_1.getHumanFriendlyPlatformName)(endpoint.platform);
539
541
  const label = helper.getFunctionLabel(endpoint);
540
- utils.logLabeledBullet("functions", `${op} ${runtime} function ${clc.bold(label)}...`);
542
+ utils.logLabeledBullet("functions", `${op} ${runtime} (${platform}) function ${clc.bold(label)}...`);
541
543
  }
542
544
  logOpSuccess(op, endpoint) {
543
545
  utils.logSuccess(this.getLogSuccessMessage(op, endpoint));
@@ -18,9 +18,9 @@ const EMULATOR_INSTANCE_KILL_TIMEOUT = 4000;
18
18
  const CACHE_DIR = process.env.FIREBASE_EMULATORS_PATH || path.join(os.homedir(), ".cache", "firebase", "emulators");
19
19
  const EMULATOR_UPDATE_DETAILS = {
20
20
  database: {
21
- version: "4.11.0",
22
- expectedSize: 34318940,
23
- expectedChecksum: "311609538bd65666eb724ef47c2e6466",
21
+ version: "4.11.2",
22
+ expectedSize: 34495935,
23
+ expectedChecksum: "2fd771101c0e1f7898c04c9204f2ce63",
24
24
  },
25
25
  firestore: {
26
26
  version: "1.17.4",
@@ -332,7 +332,12 @@ class FunctionsEmulator {
332
332
  this.logger.logLabeled("ERROR", "functions", `Failed to load function definition from source: ${e}`);
333
333
  return;
334
334
  }
335
- this.workerPools[emulatableBackend.codebase].refresh();
335
+ if (this.debugMode) {
336
+ this.workerPools[emulatableBackend.codebase].exit();
337
+ }
338
+ else {
339
+ this.workerPools[emulatableBackend.codebase].refresh();
340
+ }
336
341
  this.blockingFunctionsConfig = {};
337
342
  const toSetup = triggerDefinitions.filter((definition) => {
338
343
  if (force) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ɵcodegenFunctionsDirectory = exports.ɵcodegenPublicDirectory = exports.getDevModeHandle = exports.build = exports.init = exports.discover = exports.docsUrl = exports.type = exports.support = exports.name = void 0;
3
+ exports.ɵcodegenFunctionsDirectory = exports.shouldUseDevModeHandle = exports.getValidBuildTargets = exports.ɵcodegenPublicDirectory = exports.getDevModeHandle = exports.build = exports.init = exports.discover = exports.docsUrl = exports.type = exports.support = exports.name = void 0;
4
4
  const path_1 = require("path");
5
5
  const child_process_1 = require("child_process");
6
6
  const cross_spawn_1 = require("cross-spawn");
@@ -43,8 +43,8 @@ async function init(setup, config) {
43
43
  }
44
44
  }
45
45
  exports.init = init;
46
- async function build(dir) {
47
- const { targets, serverTarget, serveOptimizedImages, locales } = await (0, utils_2.getBuildConfig)(dir);
46
+ async function build(dir, configuration) {
47
+ const { targets, serverTarget, serveOptimizedImages, locales, baseHref } = await (0, utils_2.getBuildConfig)(dir, configuration);
48
48
  await (0, utils_1.warnIfCustomBuildScript)(dir, exports.name, DEFAULT_BUILD_SCRIPT);
49
49
  for (const target of targets) {
50
50
  const cli = (0, utils_1.getNodeModuleBin)("ng", dir);
@@ -56,15 +56,23 @@ async function build(dir) {
56
56
  throw new error_1.FirebaseError(`Unable to build ${target}`);
57
57
  }
58
58
  const wantsBackend = !!serverTarget || serveOptimizedImages;
59
+ const rewrites = serverTarget
60
+ ? []
61
+ : [
62
+ {
63
+ source: path_1.posix.join(baseHref, "**"),
64
+ destination: path_1.posix.join(baseHref, "index.html"),
65
+ },
66
+ ];
59
67
  const i18n = !!locales;
60
- return { wantsBackend, i18n };
68
+ return { wantsBackend, i18n, rewrites };
61
69
  }
62
70
  exports.build = build;
63
- async function getDevModeHandle(dir) {
71
+ async function getDevModeHandle(dir, configuration) {
64
72
  const { targetStringFromTarget } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect");
65
- const { serveTarget } = await (0, utils_2.getContext)(dir);
73
+ const { serveTarget } = await (0, utils_2.getContext)(dir, configuration);
66
74
  if (!serveTarget)
67
- return;
75
+ throw new Error("Could not find the serveTarget");
68
76
  const host = new Promise((resolve) => {
69
77
  const cli = (0, utils_1.getNodeModuleBin)("ng", dir);
70
78
  const serve = (0, cross_spawn_1.spawn)(cli, ["run", targetStringFromTarget(serveTarget), "--host", "localhost"], {
@@ -83,8 +91,8 @@ async function getDevModeHandle(dir) {
83
91
  return (0, utils_1.simpleProxy)(await host);
84
92
  }
85
93
  exports.getDevModeHandle = getDevModeHandle;
86
- async function ɵcodegenPublicDirectory(sourceDir, destDir) {
87
- const { outputPath, baseHref, defaultLocale, locales } = await (0, utils_2.getBrowserConfig)(sourceDir);
94
+ async function ɵcodegenPublicDirectory(sourceDir, destDir, configuration) {
95
+ const { outputPath, baseHref, defaultLocale, locales } = await (0, utils_2.getBrowserConfig)(sourceDir, configuration);
88
96
  await (0, promises_1.mkdir)((0, path_1.join)(destDir, baseHref), { recursive: true });
89
97
  if (locales) {
90
98
  await Promise.all([
@@ -102,11 +110,33 @@ async function ɵcodegenPublicDirectory(sourceDir, destDir) {
102
110
  }
103
111
  }
104
112
  exports.ɵcodegenPublicDirectory = ɵcodegenPublicDirectory;
105
- async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
113
+ async function getValidBuildTargets(purpose, dir) {
114
+ const validTargetNames = new Set(["development", "production"]);
115
+ try {
116
+ const { workspaceProject, browserTarget, serverTarget, serveTarget } = await (0, utils_2.getContext)(dir);
117
+ const { target } = ((purpose === "serve" && serveTarget) || serverTarget || browserTarget);
118
+ const workspaceTarget = workspaceProject.targets.get(target);
119
+ Object.keys(workspaceTarget.configurations || {}).forEach((it) => validTargetNames.add(it));
120
+ }
121
+ catch (e) {
122
+ }
123
+ const allTargets = await (0, utils_2.getAllTargets)(purpose, dir);
124
+ return [...validTargetNames, ...allTargets];
125
+ }
126
+ exports.getValidBuildTargets = getValidBuildTargets;
127
+ async function shouldUseDevModeHandle(targetOrConfiguration, dir) {
128
+ const { serveTarget } = await (0, utils_2.getContext)(dir, targetOrConfiguration);
129
+ if (!serveTarget)
130
+ return false;
131
+ return serveTarget.configuration !== "production";
132
+ }
133
+ exports.shouldUseDevModeHandle = shouldUseDevModeHandle;
134
+ async function ɵcodegenFunctionsDirectory(sourceDir, destDir, configuration) {
106
135
  var _a;
107
136
  var _b;
108
- const { packageJson, serverOutputPath, browserOutputPath, defaultLocale, serverLocales, browserLocales, bundleDependencies, externalDependencies, baseHref: baseUrl, serveOptimizedImages, } = await (0, utils_2.getServerConfig)(sourceDir);
137
+ const { packageJson, serverOutputPath, browserOutputPath, defaultLocale, serverLocales, browserLocales, bundleDependencies, externalDependencies, baseHref: baseUrl, serveOptimizedImages, } = await (0, utils_2.getServerConfig)(sourceDir, configuration);
109
138
  const dotEnv = { __NG_BROWSER_OUTPUT_PATH__: browserOutputPath };
139
+ let rewriteSource = undefined;
110
140
  await Promise.all([
111
141
  serverOutputPath
112
142
  ? (0, promises_1.mkdir)((0, path_1.join)(destDir, serverOutputPath), { recursive: true }).then(() => (0, fs_extra_1.copy)((0, path_1.join)(sourceDir, serverOutputPath), (0, path_1.join)(destDir, serverOutputPath)))
@@ -157,7 +187,8 @@ exports.handle = function(req,res) {
157
187
  }
158
188
  else {
159
189
  bootstrapScript = `exports.handle = (res, req) => req.sendStatus(404);\n`;
190
+ rewriteSource = path_1.posix.join(baseUrl, "__image__");
160
191
  }
161
- return { bootstrapScript, packageJson, baseUrl, dotEnv };
192
+ return { bootstrapScript, packageJson, baseUrl, dotEnv, rewriteSource };
162
193
  }
163
194
  exports.ɵcodegenFunctionsDirectory = ɵcodegenFunctionsDirectory;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBuildConfig = exports.getServerConfig = exports.getBrowserConfig = exports.getContext = void 0;
3
+ exports.getBuildConfig = exports.getServerConfig = exports.getBrowserConfig = exports.getContext = exports.getAllTargets = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  const error_1 = require("../../error");
6
6
  const path_1 = require("path");
@@ -49,7 +49,46 @@ async function localesForTarget(dir, architectHost, target, workspaceProject) {
49
49
  (0, utils_1.validateLocales)(locales);
50
50
  return { locales, defaultLocale };
51
51
  }
52
- async function getContext(dir) {
52
+ const DEV_SERVER_TARGETS = [
53
+ "@angular-devkit/build-angular:dev-server",
54
+ "@nguniversal/builders:ssr-dev-server",
55
+ ];
56
+ function getValidBuilders(purpose) {
57
+ return [
58
+ "@angular/fire:deploy",
59
+ "@angular-devkit/build-angular:browser",
60
+ "@nguniversal/builders:prerender",
61
+ ...(purpose === "deploy" ? [] : DEV_SERVER_TARGETS),
62
+ ];
63
+ }
64
+ async function getAllTargets(purpose, dir) {
65
+ const validBuilders = getValidBuilders(purpose);
66
+ const { NodeJsAsyncHost } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/core/node");
67
+ const { workspaces } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/core");
68
+ const { targetStringFromTarget } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect");
69
+ const host = workspaces.createWorkspaceHost(new NodeJsAsyncHost());
70
+ const { workspace } = await workspaces.readWorkspace(dir, host);
71
+ const targets = [];
72
+ workspace.projects.forEach((projectDefinition, project) => {
73
+ if (projectDefinition.extensions.projectType !== "application")
74
+ return;
75
+ projectDefinition.targets.forEach((targetDefinition, target) => {
76
+ if (!validBuilders.includes(targetDefinition.builder))
77
+ return;
78
+ const configurations = Object.keys(targetDefinition.configurations || {});
79
+ if (!configurations.includes("production"))
80
+ configurations.push("production");
81
+ if (!configurations.includes("development"))
82
+ configurations.push("development");
83
+ configurations.forEach((configuration) => {
84
+ targets.push(targetStringFromTarget({ project, target, configuration }));
85
+ });
86
+ });
87
+ });
88
+ return targets;
89
+ }
90
+ exports.getAllTargets = getAllTargets;
91
+ async function getContext(dir, targetOrConfiguration) {
53
92
  const { NodeJsAsyncHost } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/core/node");
54
93
  const { workspaces } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/core");
55
94
  const { WorkspaceNodeModulesArchitectHost } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect/node");
@@ -59,12 +98,26 @@ async function getContext(dir) {
59
98
  const { workspace } = await workspaces.readWorkspace(dir, host);
60
99
  const architectHost = new WorkspaceNodeModulesArchitectHost(workspace, dir);
61
100
  const architect = new Architect(architectHost);
62
- let project = globalThis.NG_DEPLOY_PROJECT;
101
+ let overrideTarget;
102
+ let project;
63
103
  let browserTarget;
64
104
  let serverTarget;
65
105
  let prerenderTarget;
66
106
  let serveTarget;
67
107
  let serveOptimizedImages = false;
108
+ let deployTargetName;
109
+ let configuration = undefined;
110
+ if (targetOrConfiguration) {
111
+ try {
112
+ overrideTarget = targetFromTargetString(targetOrConfiguration);
113
+ configuration = overrideTarget.configuration;
114
+ project = overrideTarget.project;
115
+ }
116
+ catch (e) {
117
+ deployTargetName = "deploy";
118
+ configuration = targetOrConfiguration;
119
+ }
120
+ }
68
121
  if (!project) {
69
122
  const angularJson = parse(await host.readFile((0, path_1.join)(dir, "angular.json")));
70
123
  project = angularJson.defaultProject;
@@ -79,11 +132,25 @@ async function getContext(dir) {
79
132
  project = apps[0];
80
133
  }
81
134
  if (!project)
82
- throw new error_1.FirebaseError("Unable to determine the application to deploy, you should use `ng deploy` via @angular/fire.");
135
+ throw new error_1.FirebaseError("Unable to determine the application to deploy, specify a target via the FIREBASE_FRAMEWORKS_BUILD_TARGET environment variable");
83
136
  const workspaceProject = workspace.projects.get(project);
84
137
  if (!workspaceProject)
85
138
  throw new error_1.FirebaseError(`No project ${project} found.`);
86
- const deployTargetDefinition = workspaceProject.targets.get("deploy");
139
+ if (overrideTarget) {
140
+ const target = workspaceProject.targets.get(overrideTarget.target);
141
+ const builder = target.builder;
142
+ if (builder === "@angular/fire:deploy")
143
+ deployTargetName = overrideTarget.target;
144
+ if (builder === "@angular-devkit/build-angular:browser")
145
+ browserTarget = overrideTarget;
146
+ if (builder === "@nguniversal/builders:prerender")
147
+ prerenderTarget = overrideTarget;
148
+ if (typeof builder === "string" && DEV_SERVER_TARGETS.includes(builder))
149
+ serveTarget = overrideTarget;
150
+ }
151
+ const deployTargetDefinition = deployTargetName
152
+ ? workspaceProject.targets.get(deployTargetName)
153
+ : undefined;
87
154
  if ((deployTargetDefinition === null || deployTargetDefinition === void 0 ? void 0 : deployTargetDefinition.builder) === "@angular/fire:deploy") {
88
155
  const options = deployTargetDefinition.options;
89
156
  if (typeof (options === null || options === void 0 ? void 0 : options.prerenderTarget) === "string")
@@ -107,76 +174,57 @@ async function getContext(dir) {
107
174
  console.warn("Treating the application as fully rendered. Add a serverTarget to your deploy target in angular.json to utilize server-side rendering.");
108
175
  }
109
176
  }
110
- else if (workspaceProject.targets.has("prerender")) {
111
- const target = workspaceProject.targets.get("prerender");
112
- const configurations = Object.keys(target.configurations);
113
- const configuration = configurations.includes("production")
114
- ? "production"
115
- : target.defaultConfiguration;
116
- if (!configuration)
117
- throw new Error("No production or default configuration found for prerender.");
118
- if (configuration !== "production")
119
- console.warn(`Using ${configuration} configuration for the prerender, we suggest adding a production target.`);
120
- prerenderTarget = { project, target: "prerender", configuration };
121
- const production = await architectHost.getOptionsForTarget(prerenderTarget);
122
- if (typeof (production === null || production === void 0 ? void 0 : production.browserTarget) !== "string")
177
+ if (!overrideTarget && !prerenderTarget && workspaceProject.targets.has("prerender")) {
178
+ const { defaultConfiguration = "production" } = workspaceProject.targets.get("prerender");
179
+ prerenderTarget = { project, target: "prerender", configuration: defaultConfiguration };
180
+ }
181
+ if (serveTarget) {
182
+ const options = await architectHost.getOptionsForTarget(serveTarget);
183
+ if (typeof (options === null || options === void 0 ? void 0 : options.browserTarget) !== "string")
184
+ throw new Error(`${serveTarget.target} browserTarget expected to be string, check your angular.json.`);
185
+ browserTarget = targetFromTargetString(options.browserTarget);
186
+ if (options === null || options === void 0 ? void 0 : options.serverTarget) {
187
+ if (typeof options.serverTarget !== "string")
188
+ throw new Error(`${serveTarget.target} serverTarget expected to be string, check your angular.json.`);
189
+ serverTarget = targetFromTargetString(options.serverTarget);
190
+ }
191
+ }
192
+ else if (prerenderTarget) {
193
+ const options = await architectHost.getOptionsForTarget(prerenderTarget);
194
+ if (typeof (options === null || options === void 0 ? void 0 : options.browserTarget) !== "string")
123
195
  throw new Error("Prerender browserTarget expected to be string, check your angular.json.");
124
- browserTarget = targetFromTargetString(production.browserTarget);
125
- if (typeof (production === null || production === void 0 ? void 0 : production.serverTarget) !== "string")
196
+ browserTarget = targetFromTargetString(options.browserTarget);
197
+ if (typeof (options === null || options === void 0 ? void 0 : options.serverTarget) !== "string")
126
198
  throw new Error("Prerender serverTarget expected to be string, check your angular.json.");
127
- serverTarget = targetFromTargetString(production.serverTarget);
199
+ serverTarget = targetFromTargetString(options.serverTarget);
200
+ }
201
+ if (!browserTarget && workspaceProject.targets.has("build")) {
202
+ const { defaultConfiguration = "production" } = workspaceProject.targets.get("build");
203
+ browserTarget = { project, target: "build", configuration: defaultConfiguration };
204
+ }
205
+ if (!serverTarget && workspaceProject.targets.has("server")) {
206
+ const { defaultConfiguration = "production" } = workspaceProject.targets.get("server");
207
+ serverTarget = { project, target: "server", configuration: defaultConfiguration };
128
208
  }
129
- else {
130
- if (workspaceProject.targets.has("build")) {
131
- const target = workspaceProject.targets.get("build");
132
- const configurations = Object.keys(target.configurations);
133
- const configuration = configurations.includes("production")
134
- ? "production"
135
- : target.defaultConfiguration;
136
- if (!configuration)
137
- throw new Error("No production or default configuration found for build.");
138
- if (configuration !== "production")
139
- console.warn(`Using ${configuration} configuration for the browser deploy, we suggest adding a production target.`);
140
- browserTarget = { project, target: "build", configuration };
209
+ if (!serveTarget) {
210
+ if (serverTarget && workspaceProject.targets.has("serve-ssr")) {
211
+ const { defaultConfiguration = "development" } = workspaceProject.targets.get("serve-ssr");
212
+ serveTarget = { project, target: "serve-ssr", configuration: defaultConfiguration };
141
213
  }
142
- if (workspaceProject.targets.has("server")) {
143
- const target = workspaceProject.targets.get("server");
144
- const configurations = Object.keys(target.configurations);
145
- const configuration = configurations.includes("production")
146
- ? "production"
147
- : target.defaultConfiguration;
148
- if (!configuration)
149
- throw new Error("No production or default configutation found for server.");
150
- if (configuration !== "production")
151
- console.warn(`Using ${configuration} configuration for the server deploy, we suggest adding a production target.`);
152
- serverTarget = { project, target: "server", configuration };
214
+ else if (workspaceProject.targets.has("serve")) {
215
+ const { defaultConfiguration = "development" } = workspaceProject.targets.get("serve");
216
+ serveTarget = { project, target: "serve", configuration: defaultConfiguration };
153
217
  }
154
218
  }
155
- if (serverTarget && workspaceProject.targets.has("serve-ssr")) {
156
- const target = workspaceProject.targets.get("serve-ssr");
157
- const configurations = Object.keys(target.configurations);
158
- const configuration = configurations.includes("development")
159
- ? "development"
160
- : target.defaultConfiguration;
161
- if (!configuration)
162
- throw new Error("No development or default configutation found for serve-ssr.");
163
- if (configuration !== "development")
164
- console.warn(`Using ${configuration} configuration for the local server, we suggest adding a development target.`);
165
- serveTarget = { project, target: "serve-ssr", configuration };
166
- }
167
- else if (workspaceProject.targets.has("serve")) {
219
+ if (configuration) {
220
+ if (prerenderTarget)
221
+ prerenderTarget.configuration = configuration;
168
222
  if (serverTarget)
169
- console.warn(`No server-ssr target found.`);
170
- const target = workspaceProject.targets.get("serve");
171
- const configurations = Object.keys(target.configurations);
172
- const configuration = configurations.includes("development")
173
- ? "development"
174
- : target.defaultConfiguration;
175
- if (!configuration)
176
- throw new Error("No development or default configutation found for serve.");
177
- if (configuration !== "development")
178
- console.warn(`Using ${configuration} configuration for the local server, we suggest adding a development target.`);
179
- serveTarget = { project, target: "serve", configuration };
223
+ serverTarget.configuration = configuration;
224
+ if (browserTarget)
225
+ browserTarget.configuration = configuration;
226
+ if (serveTarget)
227
+ serveTarget.configuration = configuration;
180
228
  }
181
229
  if (!browserTarget)
182
230
  throw new error_1.FirebaseError(`No browser target on ${project}`);
@@ -184,7 +232,7 @@ async function getContext(dir) {
184
232
  if (!browserTargetOptions) {
185
233
  throw new error_1.FirebaseError(`Couldn't find options for ${targetStringFromTarget(browserTarget)}.`);
186
234
  }
187
- const baseHref = browserTargetOptions.baseHref || "";
235
+ const baseHref = browserTargetOptions.baseHref || "/";
188
236
  if (typeof baseHref !== "string") {
189
237
  throw new error_1.FirebaseError(`baseHref on ${targetStringFromTarget(browserTarget)} was not a string`);
190
238
  }
@@ -202,8 +250,8 @@ async function getContext(dir) {
202
250
  };
203
251
  }
204
252
  exports.getContext = getContext;
205
- async function getBrowserConfig(sourceDir) {
206
- const { architectHost, browserTarget, baseHref, workspaceProject } = await getContext(sourceDir);
253
+ async function getBrowserConfig(sourceDir, configuration) {
254
+ const { architectHost, browserTarget, baseHref, workspaceProject } = await getContext(sourceDir, configuration);
207
255
  const { locales, defaultLocale } = await localesForTarget(sourceDir, architectHost, browserTarget, workspaceProject);
208
256
  const browserTargetOptions = await architectHost.getOptionsForTarget(browserTarget);
209
257
  if (typeof (browserTargetOptions === null || browserTargetOptions === void 0 ? void 0 : browserTargetOptions.outputPath) !== "string")
@@ -212,9 +260,9 @@ async function getBrowserConfig(sourceDir) {
212
260
  return { locales, baseHref, outputPath, defaultLocale };
213
261
  }
214
262
  exports.getBrowserConfig = getBrowserConfig;
215
- async function getServerConfig(sourceDir) {
263
+ async function getServerConfig(sourceDir, configuration) {
216
264
  var _a;
217
- const { architectHost, host, serverTarget, browserTarget, baseHref, workspaceProject, serveOptimizedImages, } = await getContext(sourceDir);
265
+ const { architectHost, host, serverTarget, browserTarget, baseHref, workspaceProject, serveOptimizedImages, } = await getContext(sourceDir, configuration);
218
266
  const browserTargetOptions = await architectHost.getOptionsForTarget(browserTarget);
219
267
  if (typeof (browserTargetOptions === null || browserTargetOptions === void 0 ? void 0 : browserTargetOptions.outputPath) !== "string")
220
268
  throw new Error("browserTarget output path is not a string");
@@ -259,13 +307,14 @@ async function getServerConfig(sourceDir) {
259
307
  };
260
308
  }
261
309
  exports.getServerConfig = getServerConfig;
262
- async function getBuildConfig(sourceDir) {
310
+ async function getBuildConfig(sourceDir, configuration) {
263
311
  const { targetStringFromTarget } = (0, utils_1.relativeRequire)(sourceDir, "@angular-devkit/architect");
264
- const { browserTarget, prerenderTarget, serverTarget, architectHost, workspaceProject, serveOptimizedImages, } = await getContext(sourceDir);
312
+ const { browserTarget, baseHref, prerenderTarget, serverTarget, architectHost, workspaceProject, serveOptimizedImages, } = await getContext(sourceDir, configuration);
265
313
  const targets = (prerenderTarget ? [prerenderTarget] : [browserTarget, serverTarget].filter((it) => !!it)).map((it) => targetStringFromTarget(it));
266
314
  const locales = await localesForTarget(sourceDir, architectHost, browserTarget, workspaceProject);
267
315
  return {
268
316
  targets,
317
+ baseHref,
269
318
  serverTarget,
270
319
  locales,
271
320
  serveOptimizedImages,
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebFrameworks = exports.I18N_ROOT = exports.ALLOWED_SSR_REGIONS = exports.DEFAULT_REGION = exports.VALID_LOCALE_FORMATS = exports.VALID_ENGINES = exports.NODE_VERSION = exports.SHARP_VERSION = exports.FIREBASE_ADMIN_VERSION = exports.FIREBASE_FUNCTIONS_VERSION = exports.FIREBASE_FRAMEWORKS_VERSION = exports.MAILING_LIST_URL = exports.FEATURE_REQUEST_URL = exports.FILE_BUG_URL = exports.DEFAULT_DOCS_URL = exports.SupportLevelWarnings = exports.NPM_COMMAND_TIMEOUT_MILLIES = void 0;
3
+ exports.DEFAULT_SHOULD_USE_DEV_MODE_HANDLE = exports.GET_DEFAULT_BUILD_TARGETS = exports.WebFrameworks = exports.I18N_ROOT = exports.ALLOWED_SSR_REGIONS = exports.DEFAULT_REGION = exports.VALID_LOCALE_FORMATS = exports.VALID_ENGINES = exports.NODE_VERSION = exports.SHARP_VERSION = exports.FIREBASE_ADMIN_VERSION = exports.FIREBASE_FUNCTIONS_VERSION = exports.FIREBASE_FRAMEWORKS_VERSION = exports.MAILING_LIST_URL = exports.FEATURE_REQUEST_URL = exports.FILE_BUG_URL = exports.DEFAULT_DOCS_URL = exports.SupportLevelWarnings = exports.NPM_COMMAND_TIMEOUT_MILLIES = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
6
  const clc = require("colorette");
@@ -21,7 +21,7 @@ exports.FIREBASE_FUNCTIONS_VERSION = "^4.3.0";
21
21
  exports.FIREBASE_ADMIN_VERSION = "^11.0.1";
22
22
  exports.SHARP_VERSION = "^0.32.1";
23
23
  exports.NODE_VERSION = parseInt(process.versions.node, 10);
24
- exports.VALID_ENGINES = { node: [16, 18] };
24
+ exports.VALID_ENGINES = { node: [16, 18, 20] };
25
25
  exports.VALID_LOCALE_FORMATS = [/^ALL_[a-z]+$/, /^[a-z]+_ALL$/, /^[a-z]+(_[a-z]+)?$/];
26
26
  exports.DEFAULT_REGION = "us-central1";
27
27
  exports.ALLOWED_SSR_REGIONS = [
@@ -43,3 +43,11 @@ exports.WebFrameworks = Object.fromEntries((0, fs_1.readdirSync)(__dirname)
43
43
  }
44
44
  })
45
45
  .filter(([, obj]) => obj && obj.name && obj.discover && obj.build && obj.type !== undefined && obj.support));
46
+ function GET_DEFAULT_BUILD_TARGETS() {
47
+ return Promise.resolve(["production", "development"]);
48
+ }
49
+ exports.GET_DEFAULT_BUILD_TARGETS = GET_DEFAULT_BUILD_TARGETS;
50
+ function DEFAULT_SHOULD_USE_DEV_MODE_HANDLE(target) {
51
+ return Promise.resolve(target === "development");
52
+ }
53
+ exports.DEFAULT_SHOULD_USE_DEV_MODE_HANDLE = DEFAULT_SHOULD_USE_DEV_MODE_HANDLE;
@@ -21,10 +21,10 @@ async function getConfig(root) {
21
21
  async function discover(dir) {
22
22
  if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "package.json"))))
23
23
  return;
24
- const { serveDir } = await getConfig(dir);
25
- if (!serveDir)
24
+ const { serveDir: publicDirectory } = await getConfig(dir);
25
+ if (!publicDirectory)
26
26
  return;
27
- return { mayWantBackend: true };
27
+ return { mayWantBackend: true, publicDirectory };
28
28
  }
29
29
  exports.discover = discover;
30
30
  async function build(cwd) {
@@ -88,7 +88,7 @@ async function getBootstrapScript(root, _bootstrapScript = "", _entry) {
88
88
  async function ɵcodegenFunctionsDirectory(root, dest) {
89
89
  const bootstrapScript = await getBootstrapScript(root);
90
90
  if (!bootstrapScript)
91
- return;
91
+ throw new Error("Cloud not find bootstrapScript");
92
92
  await (0, promises_1.mkdir)(dest, { recursive: true });
93
93
  const { packageJson } = await getConfig(root);
94
94
  const packResults = (0, child_process_1.execSync)(`npm pack ${root} --json`, { cwd: dest });
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebFrameworks = void 0;
4
+ const angular = require("./angular");
5
+ const astro = require("./astro");
6
+ const express = require("./express");
7
+ const lit = require("./lit");
8
+ const next = require("./next");
9
+ const nuxt = require("./nuxt");
10
+ const nuxt2 = require("./nuxt2");
11
+ const preact = require("./preact");
12
+ const svelte = require("./svelte");
13
+ const svelekit = require("./sveltekit");
14
+ const react = require("./react");
15
+ const vite = require("./vite");
16
+ exports.WebFrameworks = {
17
+ angular,
18
+ astro,
19
+ express,
20
+ lit,
21
+ next,
22
+ nuxt,
23
+ nuxt2,
24
+ preact,
25
+ svelte,
26
+ svelekit,
27
+ react,
28
+ vite,
29
+ };
@@ -60,14 +60,14 @@ async function discover(dir, warn = true) {
60
60
  }
61
61
  exports.discover = discover;
62
62
  const BUILD_MEMO = new Map();
63
- function memoizeBuild(dir, build, deps) {
63
+ function memoizeBuild(dir, build, deps, target) {
64
64
  const key = [dir, ...deps];
65
65
  for (const existingKey of BUILD_MEMO.keys()) {
66
66
  if ((0, util_1.isDeepStrictEqual)(existingKey, key)) {
67
67
  return BUILD_MEMO.get(existingKey);
68
68
  }
69
69
  }
70
- const value = build(dir);
70
+ const value = build(dir, target);
71
71
  BUILD_MEMO.set(key, value);
72
72
  return value;
73
73
  }
@@ -188,14 +188,17 @@ async function prepareFrameworks(targetNames, context, options, emulators = [])
188
188
  throw new error_1.FirebaseError((0, utils_1.frameworksCallToAction)("Unable to detect the web framework in use, check firebase-debug.log for more info."));
189
189
  }
190
190
  const { framework, mayWantBackend, publicDirectory } = results;
191
- const { build, ɵcodegenPublicDirectory, ɵcodegenFunctionsDirectory: codegenProdModeFunctionsDirectory, getDevModeHandle, name, support, docsUrl, } = constants_2.WebFrameworks[framework];
191
+ const { build, ɵcodegenPublicDirectory, ɵcodegenFunctionsDirectory: codegenProdModeFunctionsDirectory, getDevModeHandle, name, support, docsUrl, getValidBuildTargets = constants_2.GET_DEFAULT_BUILD_TARGETS, shouldUseDevModeHandle = constants_2.DEFAULT_SHOULD_USE_DEV_MODE_HANDLE, } = constants_2.WebFrameworks[framework];
192
192
  console.log(`\n${(0, utils_1.frameworksCallToAction)(constants_2.SupportLevelWarnings[support](name), docsUrl, " ")}\n`);
193
- const isDevMode = context._name === "serve" || context._name === "emulators:start";
194
193
  const hostingEmulatorInfo = emulators.find((e) => e.name === types_1.Emulators.HOSTING);
195
- const devModeHandle = isDevMode &&
196
- getDevModeHandle &&
197
- (await getDevModeHandle(getProjectPath(), hostingEmulatorInfo));
194
+ const buildTargetPurpose = context._name === "deploy" ? "deploy" : context._name === "emulators:exec" ? "test" : "serve";
195
+ const validBuildTargets = await getValidBuildTargets(buildTargetPurpose, getProjectPath());
196
+ const frameworksBuildTarget = (0, utils_1.getFrameworksBuildTarget)(buildTargetPurpose, validBuildTargets);
197
+ const useDevModeHandle = await shouldUseDevModeHandle(frameworksBuildTarget, getProjectPath());
198
198
  let codegenFunctionsDirectory;
199
+ const devModeHandle = useDevModeHandle &&
200
+ getDevModeHandle &&
201
+ (await getDevModeHandle(getProjectPath(), frameworksBuildTarget, hostingEmulatorInfo));
199
202
  if (devModeHandle) {
200
203
  config.public = (0, path_1.relative)(projectRoot, publicDirectory);
201
204
  options.frameworksDevModeHandle = devModeHandle;
@@ -204,7 +207,8 @@ async function prepareFrameworks(targetNames, context, options, emulators = [])
204
207
  }
205
208
  }
206
209
  else {
207
- const { wantsBackend = false, rewrites = [], redirects = [], headers = [], trailingSlash, i18n = false, } = (await memoizeBuild(getProjectPath(), build, [firebaseDefaults])) || {};
210
+ const buildResult = await memoizeBuild(getProjectPath(), build, [firebaseDefaults, frameworksBuildTarget], frameworksBuildTarget);
211
+ const { wantsBackend = false, rewrites = [], redirects = [], headers = [], trailingSlash, i18n = false, } = buildResult || {};
208
212
  config.rewrites.push(...rewrites);
209
213
  config.redirects.push(...redirects);
210
214
  config.headers.push(...headers);
@@ -214,7 +218,7 @@ async function prepareFrameworks(targetNames, context, options, emulators = [])
214
218
  if (await (0, fs_extra_1.pathExists)(hostingDist))
215
219
  await (0, promises_1.rm)(hostingDist, { recursive: true });
216
220
  await (0, fs_extra_1.mkdirp)(hostingDist);
217
- await ɵcodegenPublicDirectory(getProjectPath(), hostingDist, {
221
+ await ɵcodegenPublicDirectory(getProjectPath(), hostingDist, frameworksBuildTarget, {
218
222
  project,
219
223
  site,
220
224
  });
@@ -269,15 +273,18 @@ async function prepareFrameworks(targetNames, context, options, emulators = [])
269
273
  else {
270
274
  await (0, fs_extra_1.mkdirp)(functionsDist);
271
275
  }
272
- const { packageJson, bootstrapScript, frameworksEntry = framework, baseUrl = "", dotEnv = {}, } = await codegenFunctionsDirectory(getProjectPath(), functionsDist);
273
- config.rewrites.push({
274
- source: path_1.posix.normalize(path_1.posix.join(baseUrl, "**")),
275
- function: {
276
- functionId,
277
- region: ssrRegion,
278
- pinTag: experiments.isEnabled("pintags"),
276
+ const { packageJson, bootstrapScript, frameworksEntry = framework, baseUrl = "", dotEnv = {}, rewriteSource = path_1.posix.join(baseUrl, "**"), } = await codegenFunctionsDirectory(getProjectPath(), functionsDist, frameworksBuildTarget);
277
+ config.rewrites = [
278
+ {
279
+ source: rewriteSource,
280
+ function: {
281
+ functionId,
282
+ region: ssrRegion,
283
+ pinTag: experiments.isEnabled("pintags"),
284
+ },
279
285
  },
280
- });
286
+ ...config.rewrites,
287
+ ];
281
288
  process.env.__FIREBASE_FRAMEWORKS_ENTRY__ = frameworksEntry;
282
289
  packageJson.main = "server.js";
283
290
  packageJson.dependencies || (packageJson.dependencies = {});
@@ -312,7 +319,7 @@ async function prepareFrameworks(targetNames, context, options, emulators = [])
312
319
  cwd: functionsDist,
313
320
  });
314
321
  if (result.status !== 0)
315
- throw new Error(`Error running \`npm pack\` at ${path}`);
322
+ throw new error_1.FirebaseError(`Error running \`npm pack\` at ${path}`);
316
323
  const { filename } = JSON.parse(result.stdout.toString())[0];
317
324
  packageJson.dependencies[name] = `file:${filename}`;
318
325
  }
@@ -368,10 +375,6 @@ ${firebaseDefaults ? `__FIREBASE_DEFAULTS__=${JSON.stringify(firebaseDefaults)}\
368
375
  if (await (0, fs_extra_1.pathExists)(functionsDist)) {
369
376
  await (0, promises_1.rm)(functionsDist, { recursive: true });
370
377
  }
371
- config.rewrites.push({
372
- source: "**",
373
- destination: "/index.html",
374
- });
375
378
  }
376
379
  if (firebaseDefaults) {
377
380
  const encodedDefaults = Buffer.from(JSON.stringify(firebaseDefaults)).toString("base64url");
@@ -379,7 +382,7 @@ ${firebaseDefaults ? `__FIREBASE_DEFAULTS__=${JSON.stringify(firebaseDefaults)}\
379
382
  const sameSite = "Strict";
380
383
  const path = `/`;
381
384
  config.headers.push({
382
- source: "**/*.js",
385
+ source: "**/*.[jt]s",
383
386
  headers: [
384
387
  {
385
388
  key: "Set-Cookie",
@@ -175,7 +175,7 @@ async function init(setup, config) {
175
175
  (0, child_process_1.execSync)(`npx --yes create-next-app@latest -e hello-world ${setup.hosting.source} --use-npm ${language === "TypeScript" ? "--ts" : "--js"}`, { stdio: "inherit", cwd: config.projectDir });
176
176
  }
177
177
  exports.init = init;
178
- async function ɵcodegenPublicDirectory(sourceDir, destDir, context) {
178
+ async function ɵcodegenPublicDirectory(sourceDir, destDir, _, context) {
179
179
  const { distDir, i18n, basePath } = await getConfig(sourceDir);
180
180
  let matchingI18nDomain = undefined;
181
181
  if (i18n === null || i18n === void 0 ? void 0 : i18n.domains) {
@@ -348,7 +348,7 @@ async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
348
348
  return { packageJson, frameworksEntry: "next.js", basePath };
349
349
  }
350
350
  exports.ɵcodegenFunctionsDirectory = ɵcodegenFunctionsDirectory;
351
- async function getDevModeHandle(dir, hostingEmulatorInfo) {
351
+ async function getDevModeHandle(dir, _, hostingEmulatorInfo) {
352
352
  if (!hostingEmulatorInfo) {
353
353
  if (await (0, utils_2.isUsingMiddleware)(dir, true)) {
354
354
  throw new error_1.FirebaseError(`${clc.bold("firebase serve")} does not support Next.js Middleware. Please use ${clc.bold("firebase emulators:start")} instead.`);
@@ -12,6 +12,7 @@ exports.name = "Nuxt";
12
12
  exports.support = "experimental";
13
13
  exports.type = 4;
14
14
  const utils_3 = require("./utils");
15
+ const error_1 = require("../../error");
15
16
  const DEFAULT_BUILD_SCRIPT = ["nuxt build", "nuxi build"];
16
17
  async function discover(dir) {
17
18
  if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "package.json"))))
@@ -22,39 +23,49 @@ async function discover(dir) {
22
23
  return;
23
24
  if (nuxtVersion && (0, semver_1.lt)(nuxtVersion, "3.0.0-0"))
24
25
  return;
25
- const { dir: { public: publicDirectory }, } = await getConfig(dir);
26
- return { publicDirectory, mayWantBackend: true };
26
+ const { dir: { public: publicDirectory }, ssr: mayWantBackend, } = await getConfig(dir);
27
+ return { publicDirectory, mayWantBackend };
27
28
  }
28
29
  exports.discover = discover;
29
- async function build(root) {
30
- const { buildNuxt } = await (0, utils_1.relativeRequire)(root, "@nuxt/kit");
31
- const nuxtApp = await getNuxt3App(root);
32
- await (0, utils_1.warnIfCustomBuildScript)(root, exports.name, DEFAULT_BUILD_SCRIPT);
33
- await buildNuxt(nuxtApp);
34
- return { wantsBackend: true };
35
- }
36
- exports.build = build;
37
- async function getNuxt3App(cwd) {
38
- const { loadNuxt } = await (0, utils_1.relativeRequire)(cwd, "@nuxt/kit");
39
- return await loadNuxt({
30
+ async function build(cwd) {
31
+ await (0, utils_1.warnIfCustomBuildScript)(cwd, exports.name, DEFAULT_BUILD_SCRIPT);
32
+ const cli = (0, utils_1.getNodeModuleBin)("nuxt", cwd);
33
+ const { ssr: wantsBackend, app: { baseURL }, } = await getConfig(cwd);
34
+ const command = wantsBackend ? ["build"] : ["generate"];
35
+ const build = (0, cross_spawn_1.sync)(cli, command, {
40
36
  cwd,
41
- overrides: {
42
- nitro: { preset: "node" },
43
- },
37
+ stdio: "inherit",
38
+ env: Object.assign(Object.assign({}, process.env), { NITRO_PRESET: "node" }),
44
39
  });
40
+ if (build.status !== 0)
41
+ throw new error_1.FirebaseError("Was unable to build your Nuxt application.");
42
+ const rewrites = wantsBackend
43
+ ? []
44
+ : [
45
+ {
46
+ source: path_1.posix.join(baseURL, "**"),
47
+ destination: path_1.posix.join(baseURL, "200.html"),
48
+ },
49
+ ];
50
+ return { wantsBackend, rewrites };
45
51
  }
52
+ exports.build = build;
46
53
  async function ɵcodegenPublicDirectory(root, dest) {
54
+ const { app: { baseURL }, } = await getConfig(root);
47
55
  const distPath = (0, path_1.join)(root, ".output", "public");
48
- await (0, fs_extra_1.copy)(distPath, dest);
56
+ const fullDest = (0, path_1.join)(dest, baseURL);
57
+ await (0, fs_extra_1.mkdirp)(fullDest);
58
+ await (0, fs_extra_1.copy)(distPath, fullDest);
49
59
  }
50
60
  exports.ɵcodegenPublicDirectory = ɵcodegenPublicDirectory;
51
- async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
61
+ async function ɵcodegenFunctionsDirectory(sourceDir) {
62
+ const serverDir = (0, path_1.join)(sourceDir, ".output", "server");
52
63
  const packageJsonBuffer = await (0, promises_1.readFile)((0, path_1.join)(sourceDir, "package.json"));
53
64
  const packageJson = JSON.parse(packageJsonBuffer.toString());
54
- const outputPackageJsonBuffer = await (0, promises_1.readFile)((0, path_1.join)(sourceDir, ".output", "server", "package.json"));
55
- const outputPackageJson = JSON.parse(outputPackageJsonBuffer.toString());
56
- await (0, fs_extra_1.copy)((0, path_1.join)(sourceDir, ".output", "server"), destDir);
57
- return { packageJson: Object.assign(Object.assign({}, packageJson), outputPackageJson), frameworksEntry: "nuxt3" };
65
+ packageJson.dependencies || (packageJson.dependencies = {});
66
+ packageJson.dependencies["nitro-output"] = `file:${serverDir}`;
67
+ const { app: { baseURL: baseUrl }, } = await getConfig(sourceDir);
68
+ return { packageJson, frameworksEntry: "nitro", baseUrl };
58
69
  }
59
70
  exports.ɵcodegenFunctionsDirectory = ɵcodegenFunctionsDirectory;
60
71
  async function getDevModeHandle(cwd) {
@@ -1,85 +1,78 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ɵcodegenFunctionsDirectory = exports.ɵcodegenPublicDirectory = exports.build = exports.discover = exports.type = exports.support = exports.name = void 0;
3
+ exports.getDevModeHandle = exports.ɵcodegenFunctionsDirectory = exports.ɵcodegenPublicDirectory = exports.build = exports.discover = exports.type = exports.support = exports.name = void 0;
4
4
  const fs_extra_1 = require("fs-extra");
5
5
  const promises_1 = require("fs/promises");
6
6
  const path_1 = require("path");
7
7
  const semver_1 = require("semver");
8
8
  const utils_1 = require("../utils");
9
9
  const utils_2 = require("../nuxt/utils");
10
+ const utils_3 = require("../utils");
11
+ const cross_spawn_1 = require("cross-spawn");
10
12
  exports.name = "Nuxt";
11
13
  exports.support = "experimental";
12
14
  exports.type = 2;
13
- async function discover(dir) {
14
- if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "package.json"))))
15
+ async function getAndLoadNuxt(options) {
16
+ const nuxt = await (0, utils_1.relativeRequire)(options.rootDir, "nuxt/dist/nuxt.js");
17
+ const app = await nuxt.loadNuxt(options);
18
+ await app.ready();
19
+ return { app, nuxt };
20
+ }
21
+ async function discover(rootDir) {
22
+ if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(rootDir, "package.json"))))
15
23
  return;
16
- const nuxtVersion = (0, utils_2.getNuxtVersion)(dir);
17
- const anyConfigFileExists = await (0, utils_2.nuxtConfigFilesExist)(dir);
18
- if (!anyConfigFileExists && !nuxtVersion)
24
+ const nuxtVersion = (0, utils_2.getNuxtVersion)(rootDir);
25
+ if (!nuxtVersion || (nuxtVersion && (0, semver_1.gte)(nuxtVersion, "3.0.0-0")))
19
26
  return;
20
- if (nuxtVersion && (0, semver_1.lt)(nuxtVersion, "3.0.0-0"))
21
- return { mayWantBackend: true };
27
+ const { app } = await getAndLoadNuxt({ rootDir, for: "build" });
28
+ return { mayWantBackend: true, publicDirectory: app.options.dir.static };
22
29
  }
23
30
  exports.discover = discover;
24
- async function getNuxtApp(cwd) {
25
- return await (0, utils_1.relativeRequire)(cwd, "nuxt/dist/nuxt.js");
26
- }
27
- async function build(root) {
28
- const nuxt = await getNuxtApp(root);
29
- const nuxtApp = await nuxt.loadNuxt({
30
- for: "build",
31
- rootDir: root,
32
- });
33
- const { options: { ssr, target }, } = await nuxt.build(nuxtApp);
34
- if (ssr === true && target === "server") {
35
- return { wantsBackend: true };
36
- }
37
- else {
38
- if (ssr === false && target === "static") {
39
- console.log("Firebase: Nuxt 2: Static target is not supported with `ssr: false`. Please use `target: 'server'` in your `nuxt.config.js` file.");
40
- console.log("Firebase: Nuxt 2: Bundling only for client side.\n");
41
- }
42
- await buildAndGenerate(nuxt, root);
43
- return { wantsBackend: false };
44
- }
45
- }
46
- exports.build = build;
47
- async function buildAndGenerate(nuxt, root) {
48
- const nuxtApp = await nuxt.loadNuxt({
49
- for: "start",
50
- rootDir: root,
51
- });
52
- const builder = await nuxt.getBuilder(nuxtApp);
53
- const generator = new nuxt.Generator(nuxtApp, builder);
31
+ async function build(rootDir) {
32
+ const { app, nuxt } = await getAndLoadNuxt({ rootDir, for: "build" });
33
+ const { options: { ssr, target }, } = app;
34
+ const cwd = process.cwd();
35
+ process.chdir(rootDir);
36
+ await nuxt.build(app);
37
+ const { app: generateApp } = await getAndLoadNuxt({ rootDir, for: "start" });
38
+ const builder = await nuxt.getBuilder(generateApp);
39
+ const generator = new nuxt.Generator(generateApp, builder);
54
40
  await generator.generate({ build: false, init: true });
41
+ process.chdir(cwd);
42
+ const wantsBackend = ssr && target === "server";
43
+ const rewrites = wantsBackend ? [] : [{ source: "**", destination: "/200.html" }];
44
+ return { wantsBackend, rewrites };
55
45
  }
56
- async function ɵcodegenPublicDirectory(root, dest) {
57
- var _a, _b;
58
- const nuxt = await getNuxtApp(root);
59
- const nuxtConfig = await nuxt.loadNuxtConfig();
60
- const { ssr, target } = nuxtConfig;
61
- if (!(ssr === true && target === "server")) {
62
- const source = ((_a = nuxtConfig === null || nuxtConfig === void 0 ? void 0 : nuxtConfig.generate) === null || _a === void 0 ? void 0 : _a.dir) !== undefined
63
- ? (0, path_1.join)(root, (_b = nuxtConfig === null || nuxtConfig === void 0 ? void 0 : nuxtConfig.generate) === null || _b === void 0 ? void 0 : _b.dir)
64
- : (0, path_1.join)(root, "dist");
65
- await (0, fs_extra_1.copy)(source, dest);
66
- }
67
- const staticPath = (0, path_1.join)(root, "static");
68
- if (await (0, fs_extra_1.pathExists)(staticPath)) {
69
- await (0, fs_extra_1.copy)(staticPath, dest);
70
- }
46
+ exports.build = build;
47
+ async function ɵcodegenPublicDirectory(rootDir, dest) {
48
+ const { app: { options }, } = await getAndLoadNuxt({ rootDir, for: "build" });
49
+ await (0, fs_extra_1.copy)(options.generate.dir, dest);
71
50
  }
72
51
  exports.ɵcodegenPublicDirectory = ɵcodegenPublicDirectory;
73
- async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
74
- const packageJsonBuffer = await (0, promises_1.readFile)((0, path_1.join)(sourceDir, "package.json"));
52
+ async function ɵcodegenFunctionsDirectory(rootDir, destDir) {
53
+ const packageJsonBuffer = await (0, promises_1.readFile)((0, path_1.join)(rootDir, "package.json"));
75
54
  const packageJson = JSON.parse(packageJsonBuffer.toString());
76
- const nuxt = await getNuxtApp(sourceDir);
77
- const nuxtConfig = await nuxt.loadNuxtConfig();
78
- await (0, fs_extra_1.copy)((0, path_1.join)(sourceDir, ".nuxt"), (0, path_1.join)(destDir, ".nuxt"));
79
- if (!nuxtConfig.ssr) {
80
- const nuxtConfigFile = nuxtConfig._nuxtConfigFile.split("/").pop();
81
- await (0, fs_extra_1.copy)(nuxtConfig._nuxtConfigFile, (0, path_1.join)(destDir, nuxtConfigFile));
82
- }
55
+ const { app: { options }, } = await getAndLoadNuxt({ rootDir, for: "build" });
56
+ const { buildDir, _nuxtConfigFile: configFilePath } = options;
57
+ await (0, fs_extra_1.copy)(buildDir, (0, path_1.join)(destDir, (0, path_1.relative)(rootDir, buildDir)));
58
+ await (0, fs_extra_1.copy)(configFilePath, (0, path_1.join)(destDir, (0, path_1.basename)(configFilePath)));
83
59
  return { packageJson: Object.assign({}, packageJson), frameworksEntry: "nuxt" };
84
60
  }
85
61
  exports.ɵcodegenFunctionsDirectory = ɵcodegenFunctionsDirectory;
62
+ async function getDevModeHandle(cwd) {
63
+ const host = new Promise((resolve) => {
64
+ const cli = (0, utils_1.getNodeModuleBin)("nuxt", cwd);
65
+ const serve = (0, cross_spawn_1.spawn)(cli, ["dev"], { cwd });
66
+ serve.stdout.on("data", (data) => {
67
+ process.stdout.write(data);
68
+ const match = data.toString().match(/(http:\/\/.+:\d+)/);
69
+ if (match)
70
+ resolve(match[1]);
71
+ });
72
+ serve.stderr.on("data", (data) => {
73
+ process.stderr.write(data);
74
+ });
75
+ });
76
+ return (0, utils_3.simpleProxy)(await host);
77
+ }
78
+ exports.getDevModeHandle = getDevModeHandle;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateLocales = exports.frameworksCallToAction = exports.conjoinOptions = exports.relativeRequire = exports.findDependency = exports.getNodeModuleBin = exports.getNpmRoot = exports.simpleProxy = exports.warnIfCustomBuildScript = exports.readJSON = exports.isUrl = void 0;
3
+ exports.getFrameworksBuildTarget = exports.validateLocales = exports.frameworksCallToAction = exports.conjoinOptions = exports.relativeRequire = exports.findDependency = exports.getNodeModuleBin = exports.getNpmRoot = exports.simpleProxy = exports.warnIfCustomBuildScript = exports.readJSON = exports.isUrl = void 0;
4
4
  const fs_extra_1 = require("fs-extra");
5
5
  const path_1 = require("path");
6
6
  const promises_1 = require("fs/promises");
@@ -37,7 +37,8 @@ function simpleProxy(hostOrRequestHandler) {
37
37
  return async (originalReq, originalRes, next) => {
38
38
  const { method, headers, url: path } = originalReq;
39
39
  if (!method || !path) {
40
- return originalRes.end();
40
+ originalRes.end();
41
+ return;
41
42
  }
42
43
  const firebaseDefaultsJSON = process.env.__FIREBASE_DEFAULTS__;
43
44
  const authTokenSyncURL = firebaseDefaultsJSON && JSON.parse(firebaseDefaultsJSON)._authTokenSyncURL;
@@ -174,3 +175,30 @@ function validateLocales(locales = []) {
174
175
  }
175
176
  }
176
177
  exports.validateLocales = validateLocales;
178
+ function getFrameworksBuildTarget(purpose, validOptions) {
179
+ const frameworksBuild = process.env.FIREBASE_FRAMEWORKS_BUILD_TARGET;
180
+ if (frameworksBuild) {
181
+ if (!validOptions.includes(frameworksBuild)) {
182
+ throw new error_1.FirebaseError(`Invalid value for FIREBASE_FRAMEWORKS_BUILD_TARGET environment variable: ${frameworksBuild}. Valid values are: ${validOptions.join(", ")}`);
183
+ }
184
+ return frameworksBuild;
185
+ }
186
+ else if (process.env.NODE_ENV) {
187
+ switch (process.env.NODE_ENV) {
188
+ case "development":
189
+ return "development";
190
+ case "production":
191
+ case "test":
192
+ return "production";
193
+ default:
194
+ throw new error_1.FirebaseError(`We cannot infer your build target from a non-standard NODE_ENV. Please set the FIREBASE_FRAMEWORKS_BUILD_TARGET environment variable. Valid values are: ${validOptions.join(", ")}`);
195
+ }
196
+ }
197
+ else if (purpose !== "serve") {
198
+ return "production";
199
+ }
200
+ else {
201
+ return "development";
202
+ }
203
+ }
204
+ exports.getFrameworksBuildTarget = getFrameworksBuildTarget;
@@ -62,6 +62,7 @@ async function build(root) {
62
62
  process.chdir(root);
63
63
  await build({ root, mode: "production" });
64
64
  process.chdir(cwd);
65
+ return { rewrites: [{ source: "**", destination: "/index.html" }] };
65
66
  }
66
67
  exports.build = build;
67
68
  async function ɵcodegenPublicDirectory(root, dest) {
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.endpointFromFunction = exports.functionFromEndpoint = exports.deleteFunction = exports.updateFunction = exports.listAllFunctions = exports.listFunctions = exports.getFunction = exports.createFunction = exports.generateUploadUrl = exports.mebibytes = exports.API_VERSION = void 0;
4
- const clc = require("colorette");
5
4
  const apiv2_1 = require("../apiv2");
6
5
  const error_1 = require("../error");
7
6
  const api_1 = require("../api");
@@ -14,6 +13,7 @@ const utils = require("../utils");
14
13
  const projectConfig = require("../functions/projectConfig");
15
14
  const constants_1 = require("../functions/constants");
16
15
  exports.API_VERSION = "v2";
16
+ const DEFAULT_MAX_INSTANCE_COUNT = 100;
17
17
  const client = new apiv2_1.Client({
18
18
  urlPrefix: api_1.functionsV2Origin,
19
19
  auth: true,
@@ -48,22 +48,32 @@ function mebibytes(memory) {
48
48
  return bytes / (1 << 20);
49
49
  }
50
50
  exports.mebibytes = mebibytes;
51
- function functionsOpLogReject(funcName, type, err) {
52
- var _a, _b, _c, _d;
53
- utils.logWarning(clc.bold(clc.yellow("functions:")) + ` ${err === null || err === void 0 ? void 0 : err.message}`);
54
- if (((_b = (_a = err === null || err === void 0 ? void 0 : err.context) === null || _a === void 0 ? void 0 : _a.response) === null || _b === void 0 ? void 0 : _b.statusCode) === 429) {
55
- utils.logWarning(`${clc.bold(clc.yellow("functions:"))} got "Quota Exceeded" error while trying to ${type} ${funcName}. Waiting to retry...`);
56
- }
57
- else if (err === null || err === void 0 ? void 0 : err.message.includes("If you recently started to use Eventarc, it may take a few minutes before all necessary permissions are propagated to the Service Agent")) {
58
- utils.logWarning(`${clc.bold(clc.yellow("functions:"))} since this is your first time using functions v2, we need a little bit longer to finish setting everything up, please retry the deployment in a few minutes.`);
51
+ function functionsOpLogReject(func, type, err) {
52
+ var _a, _b, _c, _d, _e, _f;
53
+ if ((_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.includes("maxScale may not exceed")) {
54
+ const maxInstances = func.serviceConfig.maxInstanceCount || DEFAULT_MAX_INSTANCE_COUNT;
55
+ utils.logLabeledWarning("functions", `Your current project quotas don't allow for the current max instances setting of ${maxInstances}. ` +
56
+ "Either reduce this function's maximum instances, or request a quota increase on the underlying Cloud Run service " +
57
+ "at https://cloud.google.com/run/quotas.");
58
+ const suggestedFix = func.buildConfig.runtime.startsWith("python")
59
+ ? "firebase_functions.options.set_global_options(max_instances=10)"
60
+ : "setGlobalOptions({maxInstances: 10})";
61
+ utils.logLabeledWarning("functions", `You can adjust the max instances value in your function's runtime options:\n\t${suggestedFix}`);
59
62
  }
60
63
  else {
61
- utils.logWarning(clc.bold(clc.yellow("functions:")) + " failed to " + type + " function " + funcName);
64
+ utils.logLabeledWarning("functions", `${err === null || err === void 0 ? void 0 : err.message}`);
65
+ if (((_c = (_b = err === null || err === void 0 ? void 0 : err.context) === null || _b === void 0 ? void 0 : _b.response) === null || _c === void 0 ? void 0 : _c.statusCode) === 429) {
66
+ utils.logLabeledWarning("functions", `Got "Quota Exceeded" error while trying to ${type} ${func.name}. Waiting to retry...`);
67
+ }
68
+ else if ((_d = err === null || err === void 0 ? void 0 : err.message) === null || _d === void 0 ? void 0 : _d.includes("If you recently started to use Eventarc, it may take a few minutes before all necessary permissions are propagated to the Service Agent")) {
69
+ utils.logLabeledWarning("functions", `Since this is your first time using 2nd gen functions, we need a little bit longer to finish setting everything up. Retry the deployment in a few minutes.`);
70
+ }
71
+ utils.logLabeledWarning("functions", ` failed to ${type} function ${func.name}`);
62
72
  }
63
- throw new error_1.FirebaseError(`Failed to ${type} function ${funcName}`, {
73
+ throw new error_1.FirebaseError(`Failed to ${type} function ${func.name}`, {
64
74
  original: err,
65
- status: (_d = (_c = err === null || err === void 0 ? void 0 : err.context) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.statusCode,
66
- context: { function: funcName },
75
+ status: (_f = (_e = err === null || err === void 0 ? void 0 : err.context) === null || _e === void 0 ? void 0 : _e.response) === null || _f === void 0 ? void 0 : _f.statusCode,
76
+ context: { function: func.name },
67
77
  });
68
78
  }
69
79
  async function generateUploadUrl(projectId, location) {
@@ -86,7 +96,7 @@ async function createFunction(cloudFunction) {
86
96
  return res.body;
87
97
  }
88
98
  catch (err) {
89
- throw functionsOpLogReject(cloudFunction.name, "create", err);
99
+ throw functionsOpLogReject(cloudFunction, "create", err);
90
100
  }
91
101
  }
92
102
  exports.createFunction = createFunction;
@@ -144,7 +154,7 @@ async function updateFunction(cloudFunction) {
144
154
  return res.body;
145
155
  }
146
156
  catch (err) {
147
- throw functionsOpLogReject(cloudFunction.name, "update", err);
157
+ throw functionsOpLogReject(cloudFunction, "update", err);
148
158
  }
149
159
  }
150
160
  exports.updateFunction = updateFunction;
@@ -154,7 +164,7 @@ async function deleteFunction(cloudFunction) {
154
164
  return res.body;
155
165
  }
156
166
  catch (err) {
157
- throw functionsOpLogReject(cloudFunction, "update", err);
167
+ throw functionsOpLogReject({ name: cloudFunction }, "update", err);
158
168
  }
159
169
  }
160
170
  exports.deleteFunction = deleteFunction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-tools",
3
- "version": "12.1.0",
3
+ "version": "12.2.0",
4
4
  "description": "Command-Line Interface for Firebase",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {