edgeone 1.0.7 → 1.0.9
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/edgeone-dist/cli.js +148 -30
- package/package.json +1 -1
package/edgeone-dist/cli.js
CHANGED
|
@@ -103299,7 +103299,7 @@ var yargs_default = Yargs;
|
|
|
103299
103299
|
// package.json
|
|
103300
103300
|
var package_default = {
|
|
103301
103301
|
name: "edgeone",
|
|
103302
|
-
version: "1.0.
|
|
103302
|
+
version: "1.0.9",
|
|
103303
103303
|
description: "Command-line interface for TencentCloud Pages Functions",
|
|
103304
103304
|
bin: {
|
|
103305
103305
|
edgeone: "./edgeone-bin/edgeone.js"
|
|
@@ -106855,7 +106855,7 @@ var {
|
|
|
106855
106855
|
var cookie = __toESM(require_dist2());
|
|
106856
106856
|
var getHost = async () => {
|
|
106857
106857
|
const region = await getLoginRegion();
|
|
106858
|
-
if (region === "
|
|
106858
|
+
if (region === "global") {
|
|
106859
106859
|
return "https://edgeone.tencentcloud.com/api/cli/proxy";
|
|
106860
106860
|
}
|
|
106861
106861
|
return "https://edgeone.cloud.tencent.com/api/cli/proxy";
|
|
@@ -106891,6 +106891,7 @@ async function capi(action, params, options, callback) {
|
|
|
106891
106891
|
try {
|
|
106892
106892
|
const res1 = await axios_default.post(
|
|
106893
106893
|
// `https://siaas.cloud.tencent.com/cgi/capi?csrfCode=${await getCsrfCode()}`,
|
|
106894
|
+
// `https://siaas.tencentcloud.com/cgi/capi?csrfCode=${await getCsrfCode()}`,
|
|
106894
106895
|
await getHost(),
|
|
106895
106896
|
JSON.stringify(data.body),
|
|
106896
106897
|
{
|
|
@@ -111309,6 +111310,11 @@ var tefConfRewritesSchema = querySchema.merge(
|
|
|
111309
111310
|
destination: z.string().superRefine(pathMatch)
|
|
111310
111311
|
})
|
|
111311
111312
|
).array();
|
|
111313
|
+
var tefConfCachesSchema = querySchema.merge(
|
|
111314
|
+
z.object({
|
|
111315
|
+
cacheTtl: z.number()
|
|
111316
|
+
})
|
|
111317
|
+
).array();
|
|
111312
111318
|
var tefConfigSchema = z.object({
|
|
111313
111319
|
// name: z.string(),
|
|
111314
111320
|
// main: z.string(),
|
|
@@ -111324,7 +111330,8 @@ var tefConfigSchema = z.object({
|
|
|
111324
111330
|
nodeVersion: z.string().optional().describe("the node version to use."),
|
|
111325
111331
|
headers: tefConfHeadersSchema.optional(),
|
|
111326
111332
|
redirects: tefConfRedirectsSchema.optional(),
|
|
111327
|
-
rewrites: tefConfRewritesSchema.optional()
|
|
111333
|
+
rewrites: tefConfRewritesSchema.optional(),
|
|
111334
|
+
caches: tefConfCachesSchema.optional()
|
|
111328
111335
|
});
|
|
111329
111336
|
var filteredTefConfigSchema = toFilteredSchema(tefConfigSchema);
|
|
111330
111337
|
var symFilteredSchema = Symbol("filteredSchema");
|
|
@@ -113053,8 +113060,12 @@ function isSource(v) {
|
|
|
113053
113060
|
}
|
|
113054
113061
|
if (v.length) {
|
|
113055
113062
|
const arr = v.split("/");
|
|
113056
|
-
const
|
|
113057
|
-
if (
|
|
113063
|
+
const ret1 = arr.some((v2) => v2.includes(":") && (v2.includes("*") || v2.includes(".")));
|
|
113064
|
+
if (ret1) {
|
|
113065
|
+
return Error_Message.char_match;
|
|
113066
|
+
}
|
|
113067
|
+
const ret2 = arr.some((v2) => v2.split(":").length > 2);
|
|
113068
|
+
if (ret2) {
|
|
113058
113069
|
return Error_Message.char_match;
|
|
113059
113070
|
}
|
|
113060
113071
|
}
|
|
@@ -113072,19 +113083,12 @@ function isDestination(v) {
|
|
|
113072
113083
|
if (illegal.test(v)) {
|
|
113073
113084
|
return Error_Message.char_match;
|
|
113074
113085
|
}
|
|
113075
|
-
if (((_a6 = v.match(/\*/g)) == null ? void 0 : _a6.length)
|
|
113086
|
+
if (((_a6 = v.match(/\*/g)) == null ? void 0 : _a6.length) >= 1) {
|
|
113076
113087
|
return Error_Message.char_match;
|
|
113077
113088
|
}
|
|
113078
113089
|
if (/(?<![a-zA-Z0-9_\-/:*.~=?#!$&+,;%@ ]):/.test(v) || /:(?![a-zA-Z0-9]+)/.test(v)) {
|
|
113079
113090
|
return Error_Message.char_match;
|
|
113080
113091
|
}
|
|
113081
|
-
if (v.length) {
|
|
113082
|
-
const arr = v.split("/");
|
|
113083
|
-
const ret = arr.some((v2) => v2.includes(":") && (v2.includes("*") || v2.includes(".")));
|
|
113084
|
-
if (ret) {
|
|
113085
|
-
return Error_Message.char_match;
|
|
113086
|
-
}
|
|
113087
|
-
}
|
|
113088
113092
|
}
|
|
113089
113093
|
function isKey(v) {
|
|
113090
113094
|
if (v.length === 0) {
|
|
@@ -113113,6 +113117,17 @@ function isStatusCode(v) {
|
|
|
113113
113117
|
return Error_Message.value_match;
|
|
113114
113118
|
}
|
|
113115
113119
|
}
|
|
113120
|
+
function isCacheTtl(v) {
|
|
113121
|
+
if (typeof v !== "number") {
|
|
113122
|
+
return Error_Message.value_match;
|
|
113123
|
+
}
|
|
113124
|
+
if (!Number.isInteger(v)) {
|
|
113125
|
+
return Error_Message.value_match;
|
|
113126
|
+
}
|
|
113127
|
+
if (v < 0) {
|
|
113128
|
+
return Error_Message.value_match;
|
|
113129
|
+
}
|
|
113130
|
+
}
|
|
113116
113131
|
function parseSubHeaders(config, path9) {
|
|
113117
113132
|
const result = [];
|
|
113118
113133
|
const message = [];
|
|
@@ -113380,8 +113395,72 @@ function parseRewrites(config, path9) {
|
|
|
113380
113395
|
}
|
|
113381
113396
|
return [result, message];
|
|
113382
113397
|
}
|
|
113398
|
+
function parseCaches(config, path9) {
|
|
113399
|
+
let result = [];
|
|
113400
|
+
const message = [];
|
|
113401
|
+
if (!isArray2(config)) {
|
|
113402
|
+
message.push({
|
|
113403
|
+
path: [...path9],
|
|
113404
|
+
message: Error_Message.invalid_type
|
|
113405
|
+
});
|
|
113406
|
+
return [result, message];
|
|
113407
|
+
}
|
|
113408
|
+
for (const index in config) {
|
|
113409
|
+
const cache = config[index];
|
|
113410
|
+
if (!isObject2(cache)) {
|
|
113411
|
+
message.push({
|
|
113412
|
+
path: [...path9, `[${index}]`],
|
|
113413
|
+
message: Error_Message.invalid_type
|
|
113414
|
+
});
|
|
113415
|
+
continue;
|
|
113416
|
+
}
|
|
113417
|
+
const { source, cacheTtl } = cache;
|
|
113418
|
+
if (!isString2(source)) {
|
|
113419
|
+
message.push({
|
|
113420
|
+
path: [...path9, `[${index}]`, "source"],
|
|
113421
|
+
message: Error_Message.invalid_type
|
|
113422
|
+
});
|
|
113423
|
+
continue;
|
|
113424
|
+
}
|
|
113425
|
+
const source_e = isSource(source);
|
|
113426
|
+
if (source_e) {
|
|
113427
|
+
message.push({
|
|
113428
|
+
path: [...path9, `[${index}]`, "source"],
|
|
113429
|
+
message: source_e
|
|
113430
|
+
});
|
|
113431
|
+
continue;
|
|
113432
|
+
}
|
|
113433
|
+
if (!isNumber2(cacheTtl)) {
|
|
113434
|
+
message.push({
|
|
113435
|
+
path: [...path9, `[${index}]`, "cacheTtl"],
|
|
113436
|
+
message: Error_Message.invalid_type
|
|
113437
|
+
});
|
|
113438
|
+
continue;
|
|
113439
|
+
}
|
|
113440
|
+
const cacheTtl_e = isCacheTtl(cacheTtl);
|
|
113441
|
+
if (cacheTtl_e) {
|
|
113442
|
+
message.push({
|
|
113443
|
+
path: [...path9, `[${index}]`, "cacheTtl"],
|
|
113444
|
+
message: cacheTtl_e
|
|
113445
|
+
});
|
|
113446
|
+
continue;
|
|
113447
|
+
}
|
|
113448
|
+
result.push({
|
|
113449
|
+
source,
|
|
113450
|
+
cacheTtl
|
|
113451
|
+
});
|
|
113452
|
+
}
|
|
113453
|
+
if (result.length > Max_Len) {
|
|
113454
|
+
message.push({
|
|
113455
|
+
path: [...path9],
|
|
113456
|
+
message: Error_Message.max_length
|
|
113457
|
+
});
|
|
113458
|
+
result = result.slice(0, Max_Len);
|
|
113459
|
+
}
|
|
113460
|
+
return [result, message];
|
|
113461
|
+
}
|
|
113383
113462
|
function parse2(config, path9) {
|
|
113384
|
-
const result = { headers: [], redirects: [], rewrites: [] };
|
|
113463
|
+
const result = { headers: [], redirects: [], rewrites: [], caches: [] };
|
|
113385
113464
|
const message = [];
|
|
113386
113465
|
if (!isObject2(config)) {
|
|
113387
113466
|
message.push({
|
|
@@ -113390,20 +113469,22 @@ function parse2(config, path9) {
|
|
|
113390
113469
|
});
|
|
113391
113470
|
return [result, message];
|
|
113392
113471
|
}
|
|
113393
|
-
const { headers = [], redirects = [], rewrites = [] } = config;
|
|
113472
|
+
const { headers = [], redirects = [], rewrites = [], caches = [] } = config;
|
|
113394
113473
|
const [result_h, message_h] = parseHeaders(headers, [...path9, "headers"]);
|
|
113395
113474
|
const [result_r, message_r] = parseRedirects(redirects, [...path9, "redirects"]);
|
|
113396
113475
|
const [result_w, message_w] = parseRewrites(rewrites, [...path9, "rewrites"]);
|
|
113476
|
+
const [result_c, message_c] = parseCaches(caches, [...path9, "caches"]);
|
|
113397
113477
|
result.headers = result_h;
|
|
113398
113478
|
result.redirects = result_r;
|
|
113399
113479
|
result.rewrites = result_w;
|
|
113480
|
+
result.caches = result_c;
|
|
113400
113481
|
const rest_arg = ["outputDirectory", "installCommand", "buildCommand", "nodeVersion"];
|
|
113401
113482
|
for (const key2 in config) {
|
|
113402
113483
|
if (rest_arg.includes(key2) && config[key2]) {
|
|
113403
113484
|
result[key2] = config[key2];
|
|
113404
113485
|
}
|
|
113405
113486
|
}
|
|
113406
|
-
message.push(...message_h, ...message_r, ...message_w);
|
|
113487
|
+
message.push(...message_h, ...message_r, ...message_w, ...message_c);
|
|
113407
113488
|
return [result, message];
|
|
113408
113489
|
}
|
|
113409
113490
|
|
|
@@ -113507,7 +113588,8 @@ async function safeParseTefConfig() {
|
|
|
113507
113588
|
return {
|
|
113508
113589
|
headers: [],
|
|
113509
113590
|
redirects: [],
|
|
113510
|
-
rewrites: []
|
|
113591
|
+
rewrites: [],
|
|
113592
|
+
caches: []
|
|
113511
113593
|
};
|
|
113512
113594
|
if (showError()) {
|
|
113513
113595
|
}
|
|
@@ -113626,6 +113708,7 @@ var path5 = require("path");
|
|
|
113626
113708
|
var esbuild = require("esbuild");
|
|
113627
113709
|
var FUNCTIONPATH = "./functions";
|
|
113628
113710
|
var OUTPUTPATH = "./.edgeone/functions/index.js";
|
|
113711
|
+
var CSSOUTPUTPATH = "./.edgeone/assets/index.css";
|
|
113629
113712
|
var OUTPUTMETA = "./.edgeone/meta.json";
|
|
113630
113713
|
var regex1 = /^\/(?:[^/]+\/)*\[(.+?)\]$/;
|
|
113631
113714
|
var regex2 = /^\/(?:[^/]+\/)*\[\[(.+?)\]\]$/;
|
|
@@ -113668,6 +113751,7 @@ var BuildFunctionGenerator = class {
|
|
|
113668
113751
|
env;
|
|
113669
113752
|
logicText;
|
|
113670
113753
|
bundleText;
|
|
113754
|
+
cssText;
|
|
113671
113755
|
functionList;
|
|
113672
113756
|
functionIndex;
|
|
113673
113757
|
constructor(props) {
|
|
@@ -113675,6 +113759,7 @@ var BuildFunctionGenerator = class {
|
|
|
113675
113759
|
this.env = props.env;
|
|
113676
113760
|
this.logicText = "";
|
|
113677
113761
|
this.bundleText = "";
|
|
113762
|
+
this.cssText = "";
|
|
113678
113763
|
this.functionList = [];
|
|
113679
113764
|
this.functionIndex = 0;
|
|
113680
113765
|
if (!props.env) {
|
|
@@ -113692,9 +113777,31 @@ var BuildFunctionGenerator = class {
|
|
|
113692
113777
|
}
|
|
113693
113778
|
async init() {
|
|
113694
113779
|
await this.readIndexFiles(FUNCTIONPATH);
|
|
113780
|
+
if (this.cssText) {
|
|
113781
|
+
writeFileSync(CSSOUTPUTPATH, this.cssText);
|
|
113782
|
+
}
|
|
113695
113783
|
if (this.logicText) {
|
|
113696
113784
|
this.bundleText = `
|
|
113697
113785
|
let global = globalThis;
|
|
113786
|
+
|
|
113787
|
+
class MessageChannel {
|
|
113788
|
+
constructor() {
|
|
113789
|
+
this.port1 = new MessagePort();
|
|
113790
|
+
this.port2 = new MessagePort();
|
|
113791
|
+
}
|
|
113792
|
+
}
|
|
113793
|
+
class MessagePort {
|
|
113794
|
+
constructor() {
|
|
113795
|
+
this.onmessage = null;
|
|
113796
|
+
}
|
|
113797
|
+
postMessage(data) {
|
|
113798
|
+
if (this.onmessage) {
|
|
113799
|
+
setTimeout(() => this.onmessage({ data }), 0);
|
|
113800
|
+
}
|
|
113801
|
+
}
|
|
113802
|
+
}
|
|
113803
|
+
global.MessageChannel = MessageChannel;
|
|
113804
|
+
|
|
113698
113805
|
let routeParams = {};
|
|
113699
113806
|
let pagesFunctionResponse = null;
|
|
113700
113807
|
async function handleRequest(context){
|
|
@@ -113818,7 +113925,7 @@ var BuildFunctionGenerator = class {
|
|
|
113818
113925
|
let tempResult = stringMap.text;
|
|
113819
113926
|
const onRequestRegex = /onRequest(?![a-zA-Z])/;
|
|
113820
113927
|
if (onRequestRegex.test(tempResult)) {
|
|
113821
|
-
tempResult = stringMap.text.replace(/\}\)\(\)\;\
|
|
113928
|
+
tempResult = stringMap.text.replace(/\}\)\(\)\;\n(\/\*\!(.|\n)*\*\/\n)*responseFoo/, `
|
|
113822
113929
|
pagesFunctionResponse = onRequest;
|
|
113823
113930
|
})();`);
|
|
113824
113931
|
const routeParams = this.matchPath(`${stringMap.path}`);
|
|
@@ -113856,7 +113963,7 @@ var BuildFunctionGenerator = class {
|
|
|
113856
113963
|
}
|
|
113857
113964
|
methodList.forEach((item) => {
|
|
113858
113965
|
if (tempResult.indexOf(item.funcName) > -1) {
|
|
113859
|
-
tempResult = stringMap.text.replace(/\}\)\(\)\;\
|
|
113966
|
+
tempResult = stringMap.text.replace(/\}\)\(\)\;\n(\/\*\!(.|\n)*\*\/\n)*responseFoo/, `
|
|
113860
113967
|
pagesFunctionResponse = ${item.funcName};
|
|
113861
113968
|
})();`);
|
|
113862
113969
|
const routeParams = this.matchPath(stringMap.path);
|
|
@@ -113922,19 +114029,30 @@ var BuildFunctionGenerator = class {
|
|
|
113922
114029
|
const result = esbuild.buildSync({
|
|
113923
114030
|
entryPoints: [filePath],
|
|
113924
114031
|
bundle: true,
|
|
114032
|
+
// minify: true,
|
|
113925
114033
|
// minifyWhitespace: true,
|
|
113926
|
-
|
|
114034
|
+
// outdir: './.tef_dist/assets',
|
|
114035
|
+
write: false,
|
|
113927
114036
|
// 禁止写入文件
|
|
114037
|
+
outfile: "./.tef_dist/assets.js"
|
|
113928
114038
|
});
|
|
113929
|
-
|
|
113930
|
-
|
|
113931
|
-
|
|
113932
|
-
|
|
113933
|
-
|
|
113934
|
-
|
|
113935
|
-
|
|
113936
|
-
|
|
113937
|
-
|
|
114039
|
+
let currentFileInfo;
|
|
114040
|
+
for (let i3 = 0; i3 < result.outputFiles.length; i3++) {
|
|
114041
|
+
if (result.outputFiles[i3].path.indexOf(".css") > -1) {
|
|
114042
|
+
this.cssText += result.outputFiles[i3].text;
|
|
114043
|
+
} else {
|
|
114044
|
+
const regex = /\.(js|ts|cjs|tsx|jsx)$/;
|
|
114045
|
+
const bundledCode = result.outputFiles[i3].text;
|
|
114046
|
+
filePath = filePath.replace(/\\/g, "/");
|
|
114047
|
+
const extractedPath = filePath.replace(/\/index\.(js|ts|cjs|tsx|jsx)/, ".js").replace(regex, "").replace("functions", "");
|
|
114048
|
+
currentFileInfo = {
|
|
114049
|
+
filePath: filePath.replace("functions/", ""),
|
|
114050
|
+
path: extractedPath === "" ? "/" : extractedPath,
|
|
114051
|
+
text: `${bundledCode}responseFoo`
|
|
114052
|
+
};
|
|
114053
|
+
}
|
|
114054
|
+
}
|
|
114055
|
+
return currentFileInfo;
|
|
113938
114056
|
}
|
|
113939
114057
|
};
|
|
113940
114058
|
async function PagesBuild(props) {
|
|
@@ -114525,7 +114643,7 @@ var path6 = require("path");
|
|
|
114525
114643
|
var chokidar = require("chokidar");
|
|
114526
114644
|
var listenFileTypes = ["js", "json", "html", "css", "jsx", "ts", "tsx", "vue", "md", "cjs"];
|
|
114527
114645
|
async function remoteDevServer(jscontent, projectId, metaJSON) {
|
|
114528
|
-
const res = await pagesCapi("
|
|
114646
|
+
const res = await pagesCapi("CreateDebugFunction", {
|
|
114529
114647
|
JSContent: jscontent,
|
|
114530
114648
|
ProjectId: projectId,
|
|
114531
114649
|
MetaData: metaJSON
|