cloud-run-functions 0.1.3 → 0.1.4
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/dist/chunk-SPF3AMMV.js +82 -0
- package/dist/main.js +21 -2
- package/dist/targets/dev.js +19 -66
- package/package.json +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// node_modules/.pnpm/radashi@12.4.0/node_modules/radashi/dist/radashi.js
|
|
2
|
+
function objectify(array, getKey, getValue = (item) => item) {
|
|
3
|
+
return array.reduce(
|
|
4
|
+
(acc, item) => {
|
|
5
|
+
acc[getKey(item)] = getValue(item);
|
|
6
|
+
return acc;
|
|
7
|
+
},
|
|
8
|
+
{}
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
var TimeoutError = class extends Error {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message ?? "Operation timed out");
|
|
14
|
+
this.name = "TimeoutError";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
function timeout(ms, error) {
|
|
18
|
+
return new Promise(
|
|
19
|
+
(_, reject) => setTimeout(
|
|
20
|
+
() => reject(isFunction(error) ? error() : new TimeoutError(error)),
|
|
21
|
+
ms
|
|
22
|
+
)
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
async function toResult(promise) {
|
|
26
|
+
try {
|
|
27
|
+
const result = await promise;
|
|
28
|
+
return [void 0, result];
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (isError(error)) {
|
|
31
|
+
return [error, void 0];
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function dedent(text, ...values) {
|
|
37
|
+
var _a;
|
|
38
|
+
if (isArray(text)) {
|
|
39
|
+
if (values.length > 0) {
|
|
40
|
+
return dedent(
|
|
41
|
+
text.reduce((acc, input, i) => {
|
|
42
|
+
var _a2;
|
|
43
|
+
let value = String(values[i] ?? "");
|
|
44
|
+
const indent2 = value.includes("\n") && ((_a2 = input.match(/[ \t]*(?=[^\n]*$)/)) == null ? void 0 : _a2[0]);
|
|
45
|
+
if (indent2) {
|
|
46
|
+
value = value.replace(/\n(?=[^\n]*?\S)/g, "\n" + indent2);
|
|
47
|
+
}
|
|
48
|
+
return acc + input + value;
|
|
49
|
+
}, "")
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
text = text[0];
|
|
53
|
+
}
|
|
54
|
+
const indent = values[0] ?? ((_a = text.match(/^[ \t]*(?=\S)/m)) == null ? void 0 : _a[0]);
|
|
55
|
+
const output = indent ? text.replace(new RegExp(`^${indent}`, "gm"), "") : text;
|
|
56
|
+
return output.replace(/^[ \t]*\n|\n[ \t]*$/g, "");
|
|
57
|
+
}
|
|
58
|
+
var isArray = /* @__PURE__ */ (() => Array.isArray)();
|
|
59
|
+
var asyncIteratorSymbol = (
|
|
60
|
+
/* c8 ignore next */
|
|
61
|
+
Symbol.asyncIterator || Symbol.for("Symbol.asyncIterator")
|
|
62
|
+
);
|
|
63
|
+
function isError(value) {
|
|
64
|
+
return isTagged(value, "[object Error]");
|
|
65
|
+
}
|
|
66
|
+
function isFunction(value) {
|
|
67
|
+
return typeof value === "function";
|
|
68
|
+
}
|
|
69
|
+
function isNumber(value) {
|
|
70
|
+
return typeof value === "number" && !Number.isNaN(value);
|
|
71
|
+
}
|
|
72
|
+
function isTagged(value, tag) {
|
|
73
|
+
return Object.prototype.toString.call(value) === tag;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
objectify,
|
|
78
|
+
timeout,
|
|
79
|
+
toResult,
|
|
80
|
+
dedent,
|
|
81
|
+
isNumber
|
|
82
|
+
};
|
package/dist/main.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
objectify
|
|
3
|
+
} from "./chunk-SPF3AMMV.js";
|
|
4
|
+
|
|
1
5
|
// src/main.ts
|
|
2
6
|
import {
|
|
7
|
+
array,
|
|
3
8
|
command,
|
|
9
|
+
multioption,
|
|
4
10
|
option,
|
|
5
11
|
optional,
|
|
6
12
|
positional,
|
|
@@ -22,11 +28,24 @@ var dev = command({
|
|
|
22
28
|
long: "port",
|
|
23
29
|
short: "p",
|
|
24
30
|
description: "The port to use for the development server"
|
|
31
|
+
}),
|
|
32
|
+
define: multioption({
|
|
33
|
+
type: optional(array(string)),
|
|
34
|
+
long: "define",
|
|
35
|
+
short: "d",
|
|
36
|
+
description: "Statically replace specific variables in the source code"
|
|
25
37
|
})
|
|
26
38
|
},
|
|
27
|
-
async handler({ root, port }) {
|
|
39
|
+
async handler({ root, port, define }) {
|
|
28
40
|
const { dev: dev2 } = await import("./tools/dev.js");
|
|
29
|
-
await dev2(root, {
|
|
41
|
+
await dev2(root, {
|
|
42
|
+
port,
|
|
43
|
+
define: define && objectify(
|
|
44
|
+
define.map((d) => d.split(":")),
|
|
45
|
+
([key]) => key,
|
|
46
|
+
([, value]) => value ? isNaN(parseFloat(value)) ? JSON.stringify(value) : value : ""
|
|
47
|
+
)
|
|
48
|
+
});
|
|
30
49
|
}
|
|
31
50
|
});
|
|
32
51
|
var build = command({
|
package/dist/targets/dev.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dedent,
|
|
3
|
+
isNumber,
|
|
4
|
+
timeout,
|
|
5
|
+
toResult
|
|
6
|
+
} from "../chunk-SPF3AMMV.js";
|
|
7
|
+
|
|
1
8
|
// src/targets/dev.ts
|
|
2
9
|
import "source-map-support/register.js";
|
|
3
10
|
import functions from "@google-cloud/functions-framework";
|
|
@@ -8,72 +15,6 @@ import { Module } from "node:module";
|
|
|
8
15
|
import os from "node:os";
|
|
9
16
|
import path3 from "node:path";
|
|
10
17
|
|
|
11
|
-
// node_modules/.pnpm/radashi@12.4.0/node_modules/radashi/dist/radashi.js
|
|
12
|
-
var TimeoutError = class extends Error {
|
|
13
|
-
constructor(message) {
|
|
14
|
-
super(message ?? "Operation timed out");
|
|
15
|
-
this.name = "TimeoutError";
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
function timeout(ms, error) {
|
|
19
|
-
return new Promise(
|
|
20
|
-
(_, reject) => setTimeout(
|
|
21
|
-
() => reject(isFunction(error) ? error() : new TimeoutError(error)),
|
|
22
|
-
ms
|
|
23
|
-
)
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
async function toResult(promise) {
|
|
27
|
-
try {
|
|
28
|
-
const result = await promise;
|
|
29
|
-
return [void 0, result];
|
|
30
|
-
} catch (error) {
|
|
31
|
-
if (isError(error)) {
|
|
32
|
-
return [error, void 0];
|
|
33
|
-
}
|
|
34
|
-
throw error;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function dedent(text, ...values) {
|
|
38
|
-
var _a;
|
|
39
|
-
if (isArray(text)) {
|
|
40
|
-
if (values.length > 0) {
|
|
41
|
-
return dedent(
|
|
42
|
-
text.reduce((acc, input, i) => {
|
|
43
|
-
var _a2;
|
|
44
|
-
let value = String(values[i] ?? "");
|
|
45
|
-
const indent2 = value.includes("\n") && ((_a2 = input.match(/[ \t]*(?=[^\n]*$)/)) == null ? void 0 : _a2[0]);
|
|
46
|
-
if (indent2) {
|
|
47
|
-
value = value.replace(/\n(?=[^\n]*?\S)/g, "\n" + indent2);
|
|
48
|
-
}
|
|
49
|
-
return acc + input + value;
|
|
50
|
-
}, "")
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
text = text[0];
|
|
54
|
-
}
|
|
55
|
-
const indent = values[0] ?? ((_a = text.match(/^[ \t]*(?=\S)/m)) == null ? void 0 : _a[0]);
|
|
56
|
-
const output = indent ? text.replace(new RegExp(`^${indent}`, "gm"), "") : text;
|
|
57
|
-
return output.replace(/^[ \t]*\n|\n[ \t]*$/g, "");
|
|
58
|
-
}
|
|
59
|
-
var isArray = /* @__PURE__ */ (() => Array.isArray)();
|
|
60
|
-
var asyncIteratorSymbol = (
|
|
61
|
-
/* c8 ignore next */
|
|
62
|
-
Symbol.asyncIterator || Symbol.for("Symbol.asyncIterator")
|
|
63
|
-
);
|
|
64
|
-
function isError(value) {
|
|
65
|
-
return isTagged(value, "[object Error]");
|
|
66
|
-
}
|
|
67
|
-
function isFunction(value) {
|
|
68
|
-
return typeof value === "function";
|
|
69
|
-
}
|
|
70
|
-
function isNumber(value) {
|
|
71
|
-
return typeof value === "number" && !Number.isNaN(value);
|
|
72
|
-
}
|
|
73
|
-
function isTagged(value, tag) {
|
|
74
|
-
return Object.prototype.toString.call(value) === tag;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
18
|
// src/common/emptyDir.ts
|
|
78
19
|
import fs from "node:fs";
|
|
79
20
|
function emptyDir(dir) {
|
|
@@ -223,14 +164,26 @@ async function createBuild() {
|
|
|
223
164
|
{
|
|
224
165
|
name: "build-status",
|
|
225
166
|
setup(build) {
|
|
167
|
+
let startTime;
|
|
226
168
|
pendingBuild = Promise.withResolvers();
|
|
227
169
|
build.onStart(() => {
|
|
228
170
|
pendingBuild ??= Promise.withResolvers();
|
|
171
|
+
startTime = Date.now();
|
|
229
172
|
});
|
|
230
173
|
build.onEnd((result) => {
|
|
231
174
|
if (pendingBuild) {
|
|
232
175
|
pendingBuild.resolve(result);
|
|
233
176
|
pendingBuild = void 0;
|
|
177
|
+
console.log(
|
|
178
|
+
`[%s] %s your Cloud Run functions in %sms.`,
|
|
179
|
+
(/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", {
|
|
180
|
+
hour: "2-digit",
|
|
181
|
+
minute: "2-digit",
|
|
182
|
+
hour12: false
|
|
183
|
+
}),
|
|
184
|
+
finishedBuild ? "Rebuilt" : "Built",
|
|
185
|
+
Date.now() - startTime
|
|
186
|
+
);
|
|
234
187
|
}
|
|
235
188
|
finishedBuild = result;
|
|
236
189
|
});
|