firebase-tools 15.28.0 → 15.28.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 +14 -5
- package/lib/deploy/functions/runtimes/dart/features.js +51 -0
- package/lib/deploy/functions/runtimes/dart/index.js +66 -14
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/templates/init/functions/dart/_gitignore +1 -0
|
@@ -33,6 +33,7 @@ const functionsDeployHelper_1 = require("./functionsDeployHelper");
|
|
|
33
33
|
const utils_1 = require("../../utils");
|
|
34
34
|
const triggerSupport_1 = require("./runtimes/dart/triggerSupport");
|
|
35
35
|
const dart_1 = require("./runtimes/dart");
|
|
36
|
+
const features_1 = require("./runtimes/dart/features");
|
|
36
37
|
const prepareFunctionsUpload_1 = require("./prepareFunctionsUpload");
|
|
37
38
|
const prompts_1 = require("./prompts");
|
|
38
39
|
const projectUtils_1 = require("../../projectUtils");
|
|
@@ -297,8 +298,8 @@ async function prepare(context, options, payload) {
|
|
|
297
298
|
const exportType = backend.someEndpoint(wantBackend, (e) => e.platform === "run")
|
|
298
299
|
? "tar.gz"
|
|
299
300
|
: "zip";
|
|
300
|
-
const executablePaths = getExecutablePaths(wantBuilds[codebase].runtime);
|
|
301
|
-
const uploadCfg = stripStaleDartBuildIgnore(wantBuilds[codebase].runtime, localCfg);
|
|
301
|
+
const executablePaths = await getExecutablePaths(wantBuilds[codebase].runtime, sourceDir);
|
|
302
|
+
const uploadCfg = await stripStaleDartBuildIgnore(wantBuilds[codebase].runtime, sourceDir, localCfg);
|
|
302
303
|
const packagedSource = await (0, prepareFunctionsUpload_1.prepareFunctionsUpload)(options.config.projectDir, sourceDir, uploadCfg, [...schPathSet], undefined, { exportType, executablePaths });
|
|
303
304
|
source.functionsSourceV2 = packagedSource?.pathToSource;
|
|
304
305
|
source.functionsSourceV2Hash = packagedSource?.hash;
|
|
@@ -548,14 +549,22 @@ function warnIfDartBackendHasUnsupportedTriggers(want) {
|
|
|
548
549
|
"See https://github.com/firebase/firebase-functions-dart for current trigger support.");
|
|
549
550
|
}
|
|
550
551
|
}
|
|
551
|
-
function getExecutablePaths(runtime) {
|
|
552
|
-
|
|
552
|
+
async function getExecutablePaths(runtime, sourceDir) {
|
|
553
|
+
if (!supported.runtimeIsLanguage(runtime, "dart")) {
|
|
554
|
+
return [];
|
|
555
|
+
}
|
|
556
|
+
const features = await features_1.DartVersionFeatures.detect(sourceDir);
|
|
557
|
+
return features.isNativeAssetsAvailable ? [dart_1.DART_BUNDLE_EXECUTABLE_PATH] : [dart_1.DART_COMPILE_EXE_PATH];
|
|
553
558
|
}
|
|
554
|
-
function stripStaleDartBuildIgnore(runtime, localCfg) {
|
|
559
|
+
async function stripStaleDartBuildIgnore(runtime, sourceDir, localCfg) {
|
|
555
560
|
if (!supported.runtimeIsLanguage(runtime, "dart") ||
|
|
556
561
|
!localCfg.ignore?.some((i) => i === "build" || i === "build/")) {
|
|
557
562
|
return localCfg;
|
|
558
563
|
}
|
|
564
|
+
const features = await features_1.DartVersionFeatures.detect(sourceDir);
|
|
565
|
+
if (!features.isNativeAssetsAvailable) {
|
|
566
|
+
return localCfg;
|
|
567
|
+
}
|
|
559
568
|
return {
|
|
560
569
|
...localCfg,
|
|
561
570
|
ignore: localCfg.ignore.filter((i) => i !== "build" && i !== "build/"),
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DartVersionFeatures = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const MIN_DART_SDK_VERSION = "3.9.0";
|
|
7
|
+
const MIN_DART_SDK_VERSION_NATIVE_ASSETS = "3.13.0";
|
|
8
|
+
class DartVersionFeatures {
|
|
9
|
+
constructor(languageVersion) {
|
|
10
|
+
this.languageVersion = languageVersion;
|
|
11
|
+
}
|
|
12
|
+
static async detect(sourceDir) {
|
|
13
|
+
return new DartVersionFeatures(await readRootLanguageVersion(sourceDir));
|
|
14
|
+
}
|
|
15
|
+
get isNativeAssetsAvailable() {
|
|
16
|
+
return this.atLeast(3, 13);
|
|
17
|
+
}
|
|
18
|
+
get minDartSdkVersion() {
|
|
19
|
+
return this.isNativeAssetsAvailable ? MIN_DART_SDK_VERSION_NATIVE_ASSETS : MIN_DART_SDK_VERSION;
|
|
20
|
+
}
|
|
21
|
+
atLeast(major, minor) {
|
|
22
|
+
if (!this.languageVersion) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const [actualMajor, actualMinor] = this.languageVersion;
|
|
26
|
+
return actualMajor > major || (actualMajor === major && actualMinor >= minor);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.DartVersionFeatures = DartVersionFeatures;
|
|
30
|
+
async function readRootLanguageVersion(sourceDir) {
|
|
31
|
+
const packageConfigPath = path.join(sourceDir, ".dart_tool", "package_config.json");
|
|
32
|
+
let raw;
|
|
33
|
+
try {
|
|
34
|
+
raw = await fs.promises.readFile(packageConfigPath, "utf8");
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const parsed = JSON.parse(raw);
|
|
41
|
+
const root = parsed?.packages?.find((p) => p.rootUri === "../");
|
|
42
|
+
const match = root?.languageVersion ? /^(\d+)\.(\d+)$/.exec(root.languageVersion) : null;
|
|
43
|
+
if (!match) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return [Number(match[1]), Number(match[2])];
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Delegate = exports.DART_BUNDLE_EXECUTABLE_PATH = exports.DART_ENTRY_POINT = void 0;
|
|
3
|
+
exports.Delegate = exports.DART_BUNDLE_EXECUTABLE_PATH = exports.DART_COMPILE_EXE_PATH = exports.DART_ENTRY_POINT = void 0;
|
|
4
4
|
exports.tryCreateDelegate = tryCreateDelegate;
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const path = require("path");
|
|
@@ -14,6 +14,7 @@ const utils_1 = require("../../../../utils");
|
|
|
14
14
|
const registry_1 = require("../../../../emulator/registry");
|
|
15
15
|
const types_1 = require("../../../../emulator/types");
|
|
16
16
|
const experiments = require("../../../../experiments");
|
|
17
|
+
const features_1 = require("./features");
|
|
17
18
|
async function tryCreateDelegate(context) {
|
|
18
19
|
const pubspecYamlPath = path.join(context.sourceDir, "pubspec.yaml");
|
|
19
20
|
if (!(await (0, util_1.promisify)(fs.exists)(pubspecYamlPath))) {
|
|
@@ -30,8 +31,8 @@ async function tryCreateDelegate(context) {
|
|
|
30
31
|
}
|
|
31
32
|
return Promise.resolve(new Delegate(context.projectId, context.sourceDir, runtime));
|
|
32
33
|
}
|
|
33
|
-
const MIN_DART_SDK_VERSION = "3.13.0";
|
|
34
34
|
exports.DART_ENTRY_POINT = "bin/server.dart";
|
|
35
|
+
exports.DART_COMPILE_EXE_PATH = "bin/server";
|
|
35
36
|
exports.DART_BUNDLE_EXECUTABLE_PATH = "build/cli/linux_x64/bundle/bin/server";
|
|
36
37
|
class Delegate {
|
|
37
38
|
constructor(projectId, sourceDir, runtime) {
|
|
@@ -52,18 +53,6 @@ class Delegate {
|
|
|
52
53
|
throw new error_1.FirebaseError(`Could not find a Dart SDK. Make sure the '${this.bin}' command is available on your PATH.`);
|
|
53
54
|
}
|
|
54
55
|
const versionOutput = (result.stdout || result.stderr || "").toString();
|
|
55
|
-
const match = /Dart SDK version:\s*(\d+\.\d+\.\d+)/.exec(versionOutput);
|
|
56
|
-
if (match) {
|
|
57
|
-
const installedVersion = match[1];
|
|
58
|
-
if (installedVersion.localeCompare(MIN_DART_SDK_VERSION, undefined, { numeric: true }) < 0) {
|
|
59
|
-
throw new error_1.FirebaseError(`Dart SDK version ${installedVersion} is not supported. ` +
|
|
60
|
-
`Firebase Functions for Dart requires Dart ${MIN_DART_SDK_VERSION} or later. ` +
|
|
61
|
-
`Please upgrade your Dart SDK.`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
logger_1.logger.debug(`Could not parse Dart SDK version from: ${versionOutput}`);
|
|
66
|
-
}
|
|
67
56
|
const pubspecYamlPath = path.join(this.sourceDir, "pubspec.yaml");
|
|
68
57
|
try {
|
|
69
58
|
await fs.promises.access(pubspecYamlPath, fs.constants.R_OK);
|
|
@@ -108,6 +97,20 @@ class Delegate {
|
|
|
108
97
|
pubGetProcess.on("error", reject);
|
|
109
98
|
});
|
|
110
99
|
}
|
|
100
|
+
const match = /Dart SDK version:\s*(\d+\.\d+\.\d+)/.exec(versionOutput);
|
|
101
|
+
if (match) {
|
|
102
|
+
const installedVersion = match[1];
|
|
103
|
+
const features = await features_1.DartVersionFeatures.detect(this.sourceDir);
|
|
104
|
+
const minVersion = features.minDartSdkVersion;
|
|
105
|
+
if (installedVersion.localeCompare(minVersion, undefined, { numeric: true }) < 0) {
|
|
106
|
+
throw new error_1.FirebaseError(`Dart SDK version ${installedVersion} is not supported. ` +
|
|
107
|
+
`Firebase Functions for Dart requires Dart ${minVersion} or later. ` +
|
|
108
|
+
`Please upgrade your Dart SDK.`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
logger_1.logger.debug(`Could not parse Dart SDK version from: ${versionOutput}`);
|
|
113
|
+
}
|
|
111
114
|
}
|
|
112
115
|
async build() {
|
|
113
116
|
if (Delegate.watchModeActive) {
|
|
@@ -140,6 +143,55 @@ class Delegate {
|
|
|
140
143
|
logger_1.logger.debug("Skipping Dart compilation in emulator mode.");
|
|
141
144
|
return;
|
|
142
145
|
}
|
|
146
|
+
const features = await features_1.DartVersionFeatures.detect(this.sourceDir);
|
|
147
|
+
if (features.isNativeAssetsAvailable) {
|
|
148
|
+
await this.buildCli();
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
await this.compileExe();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async compileExe() {
|
|
155
|
+
const binDir = path.join(this.sourceDir, "bin");
|
|
156
|
+
await fs.promises.mkdir(binDir, { recursive: true });
|
|
157
|
+
(0, utils_1.logLabeledBullet)("functions", "compiling Dart to linux-x64 executable...");
|
|
158
|
+
const compileProcess = spawn(this.bin, [
|
|
159
|
+
"compile",
|
|
160
|
+
"exe",
|
|
161
|
+
this.entryPoint,
|
|
162
|
+
"-o",
|
|
163
|
+
exports.DART_COMPILE_EXE_PATH,
|
|
164
|
+
"--target-os=linux",
|
|
165
|
+
"--target-arch=x64",
|
|
166
|
+
], {
|
|
167
|
+
cwd: this.sourceDir,
|
|
168
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
169
|
+
});
|
|
170
|
+
compileProcess.stdout?.on("data", (chunk) => {
|
|
171
|
+
logger_1.logger.debug(`[dart compile] ${chunk.toString("utf8").trim()}`);
|
|
172
|
+
});
|
|
173
|
+
compileProcess.stderr?.on("data", (chunk) => {
|
|
174
|
+
logger_1.logger.debug(`[dart compile] ${chunk.toString("utf8").trim()}`);
|
|
175
|
+
});
|
|
176
|
+
await new Promise((resolve, reject) => {
|
|
177
|
+
compileProcess.on("exit", (code) => {
|
|
178
|
+
if (code === 0 || code === null) {
|
|
179
|
+
resolve();
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
reject(new error_1.FirebaseError(`Dart compilation failed with exit code ${code}. ` +
|
|
183
|
+
`Make sure your Dart project compiles successfully with: ` +
|
|
184
|
+
`dart compile exe ${this.entryPoint} --target-os=linux --target-arch=x64\n` +
|
|
185
|
+
`If your dependencies require native build hooks (e.g. sqlite3), bump the ` +
|
|
186
|
+
`SDK constraint in your pubspec.yaml's "environment" section to "^3.13.0" or ` +
|
|
187
|
+
`later to use dart build cli instead.`));
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
compileProcess.on("error", reject);
|
|
191
|
+
});
|
|
192
|
+
(0, utils_1.logLabeledBullet)("functions", "Dart compilation complete.");
|
|
193
|
+
}
|
|
194
|
+
async buildCli() {
|
|
143
195
|
(0, utils_1.logLabeledBullet)("functions", "building Dart linux-x64 bundle...");
|
|
144
196
|
const buildProcess = spawn(this.bin, ["build", "cli", "--target", this.entryPoint, "--target-os", "linux", "--target-arch", "x64"], {
|
|
145
197
|
cwd: this.sourceDir,
|