@adep/cli 0.3.1 → 0.4.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/README.md +16 -7
- package/dist/index.js +703 -394
- package/dist/vite.js +270 -67
- package/dist/worker-entry.js +270 -67
- package/package.json +7 -7
- package/templates/app-mobile/plugins/adep-bridge/ios/AdepBridge.podspec +2 -2
package/dist/vite.js
CHANGED
|
@@ -3559,13 +3559,67 @@ import vm from "node:vm";
|
|
|
3559
3559
|
import * as nodeModule from "node:module";
|
|
3560
3560
|
|
|
3561
3561
|
// packages/runtime/src/functions/runtime/exports.ts
|
|
3562
|
+
function keepLineCount(matched, lead) {
|
|
3563
|
+
const consumed = matched.split("\n").length - 1;
|
|
3564
|
+
const kept = lead === "\n" ? 1 : 0;
|
|
3565
|
+
return "\n".repeat(Math.max(0, consumed - kept));
|
|
3566
|
+
}
|
|
3567
|
+
function parseSpecifier(part) {
|
|
3568
|
+
const asMatch = /^([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)$/.exec(part);
|
|
3569
|
+
if (asMatch !== null) {
|
|
3570
|
+
const [, local, exported] = asMatch;
|
|
3571
|
+
if (local !== void 0 && exported !== void 0) return [local, exported];
|
|
3572
|
+
}
|
|
3573
|
+
return /^[A-Za-z_$][\w$]*$/.test(part) ? [part, part] : null;
|
|
3574
|
+
}
|
|
3575
|
+
function namedImportsToDestructure(clause) {
|
|
3576
|
+
const parts = [];
|
|
3577
|
+
for (const raw of clause.split(",")) {
|
|
3578
|
+
const part = raw.trim();
|
|
3579
|
+
if (part === "") continue;
|
|
3580
|
+
const spec = parseSpecifier(part);
|
|
3581
|
+
if (spec === null) {
|
|
3582
|
+
throw new Error(`\u4E0D\u652F\u6301\u7684\u5177\u540D\u5BFC\u5165\u5F62\u6001\uFF1A"${part}"\uFF08\u6C99\u7BB1\u5B50\u96C6\u4EC5\u63A5\u53D7 a \u6216 a as b\uFF09`);
|
|
3583
|
+
}
|
|
3584
|
+
parts.push(spec[0] === spec[1] ? spec[0] : `${spec[0]}: ${spec[1]}`);
|
|
3585
|
+
}
|
|
3586
|
+
return parts;
|
|
3587
|
+
}
|
|
3588
|
+
function parseExportClause(clause) {
|
|
3589
|
+
const entries = [];
|
|
3590
|
+
for (const raw of clause.split(",")) {
|
|
3591
|
+
const part = raw.trim();
|
|
3592
|
+
if (part === "") continue;
|
|
3593
|
+
const spec = parseSpecifier(part);
|
|
3594
|
+
if (spec === null) {
|
|
3595
|
+
throw new Error(`\u4E0D\u652F\u6301\u7684\u518D\u5BFC\u51FA\u5B50\u53E5\uFF1A"${part}"\uFF08\u6C99\u7BB1\u5B50\u96C6\u4EC5\u63A5\u53D7 a \u6216 a as b\uFF09`);
|
|
3596
|
+
}
|
|
3597
|
+
entries.push({ local: spec[0], exported: spec[1] });
|
|
3598
|
+
}
|
|
3599
|
+
return entries;
|
|
3600
|
+
}
|
|
3562
3601
|
function transformModule(code) {
|
|
3563
3602
|
let out = code;
|
|
3564
3603
|
const named = [];
|
|
3604
|
+
const starReexports = [];
|
|
3605
|
+
let tempSeq = 0;
|
|
3606
|
+
const nextTemp = () => `__adep_reexport_${tempSeq++}`;
|
|
3565
3607
|
out = out.replace(/(^|\n)(\s*)export\s+default\s+/g, "$1$2module.default = ");
|
|
3566
3608
|
out = out.replace(
|
|
3567
3609
|
/import\s*\{([^}]*)\}\s*from\s*(['"][^'"]*['"])[ \t]*;?/g,
|
|
3568
|
-
(
|
|
3610
|
+
(matched, clause, source) => {
|
|
3611
|
+
const parts = namedImportsToDestructure(clause);
|
|
3612
|
+
const pad = keepLineCount(matched, "");
|
|
3613
|
+
return parts.length === 0 ? `require(${source})${pad}` : `const { ${parts.join(", ")} } = require(${source})${pad}`;
|
|
3614
|
+
}
|
|
3615
|
+
);
|
|
3616
|
+
out = out.replace(
|
|
3617
|
+
/import\s+([A-Za-z_$][\w$]*)\s*,\s*\{([^}]*)\}\s*from\s*(['"][^'"]*['"])[ \t]*;?/g,
|
|
3618
|
+
(matched, name, clause, source) => {
|
|
3619
|
+
const parts = namedImportsToDestructure(clause);
|
|
3620
|
+
const pad = keepLineCount(matched, "");
|
|
3621
|
+
return parts.length === 0 ? `const ${name} = require(${source})${pad}` : `const ${name} = require(${source}), { ${parts.join(", ")} } = ${name}${pad}`;
|
|
3622
|
+
}
|
|
3569
3623
|
);
|
|
3570
3624
|
out = out.replace(
|
|
3571
3625
|
/import\s*\*\s*as\s*([A-Za-z_$][\w$]*)\s*from\s*(['"][^'"]*['"])[ \t]*;?/g,
|
|
@@ -3575,31 +3629,76 @@ function transformModule(code) {
|
|
|
3575
3629
|
/import\s+([A-Za-z_$][\w$]*)\s+from\s*(['"][^'"]*['"])[ \t]*;?/g,
|
|
3576
3630
|
(_match, name, source) => `const ${name} = require(${source})`
|
|
3577
3631
|
);
|
|
3632
|
+
out = out.replace(
|
|
3633
|
+
/(^|\n)([ \t]*)import\s*(['"][^'"]*['"])[ \t]*;?/g,
|
|
3634
|
+
(_match, lead, indent, source) => `${lead}${indent}require(${source})`
|
|
3635
|
+
);
|
|
3636
|
+
out = out.replace(
|
|
3637
|
+
/(^|\n)([ \t]*)export\s*\{([^}]*)\}[ \t]*(?:\n[ \t]*(?=from\b))?(?:from\s*(['"][^'"]*['"]))?[ \t]*;?/g,
|
|
3638
|
+
(matched, lead, indent, clause, source) => {
|
|
3639
|
+
const pad = keepLineCount(matched, lead);
|
|
3640
|
+
const entries = parseExportClause(clause);
|
|
3641
|
+
if (entries.length === 0) return `${lead}${indent}${pad}`;
|
|
3642
|
+
if (source === void 0) {
|
|
3643
|
+
named.push(...entries);
|
|
3644
|
+
return `${lead}${indent}${pad}`;
|
|
3645
|
+
}
|
|
3646
|
+
const temp = nextTemp();
|
|
3647
|
+
for (const entry of entries) {
|
|
3648
|
+
named.push({ local: `${temp}.${entry.local}`, exported: entry.exported });
|
|
3649
|
+
}
|
|
3650
|
+
return `${lead}${indent}const ${temp} = require(${source})${pad}`;
|
|
3651
|
+
}
|
|
3652
|
+
);
|
|
3653
|
+
out = out.replace(
|
|
3654
|
+
/(^|\n)([ \t]*)export\s*\*[ \t]*(?:as[ \t]+([A-Za-z_$][\w$]*)[ \t]*)?\s*from\s*(['"][^'"]*['"])[ \t]*;?/g,
|
|
3655
|
+
(matched, lead, indent, ns, source) => {
|
|
3656
|
+
const pad = keepLineCount(matched, lead);
|
|
3657
|
+
const temp = nextTemp();
|
|
3658
|
+
if (ns === void 0) starReexports.push(temp);
|
|
3659
|
+
else named.push({ local: temp, exported: ns });
|
|
3660
|
+
return `${lead}${indent}const ${temp} = require(${source})${pad}`;
|
|
3661
|
+
}
|
|
3662
|
+
);
|
|
3578
3663
|
out = out.replace(
|
|
3579
3664
|
/export\s+(const|let|var)\s+([A-Za-z_$][\w$]*)/g,
|
|
3580
3665
|
(_match, kw, name) => {
|
|
3581
|
-
named.push(name);
|
|
3666
|
+
named.push({ local: name, exported: name });
|
|
3582
3667
|
return `${kw} ${name}`;
|
|
3583
3668
|
}
|
|
3584
3669
|
);
|
|
3585
3670
|
out = out.replace(
|
|
3586
3671
|
/export\s+(async\s+)?function\s*\*?\s*([A-Za-z_$][\w$]*)/g,
|
|
3587
3672
|
(_match, asyncKw, name) => {
|
|
3588
|
-
named.push(name);
|
|
3673
|
+
named.push({ local: name, exported: name });
|
|
3589
3674
|
return `${asyncKw ?? ""}function ${name}`;
|
|
3590
3675
|
}
|
|
3591
3676
|
);
|
|
3592
3677
|
out = out.replace(/export\s+class\s+([A-Za-z_$][\w$]*)/g, (_match, name) => {
|
|
3593
|
-
named.push(name);
|
|
3678
|
+
named.push({ local: name, exported: name });
|
|
3594
3679
|
return `class ${name}`;
|
|
3595
3680
|
});
|
|
3596
|
-
|
|
3681
|
+
for (const temp of starReexports) {
|
|
3682
|
+
out += `
|
|
3683
|
+
;Object.keys(${temp}).forEach((k) => { if (k !== 'default') exports[k] = ${temp}[k] })`;
|
|
3684
|
+
}
|
|
3685
|
+
const byExported = /* @__PURE__ */ new Map();
|
|
3686
|
+
for (const entry of named) byExported.set(entry.exported, entry.local);
|
|
3687
|
+
if (byExported.size > 0) {
|
|
3688
|
+
const picks = [...byExported].map(
|
|
3689
|
+
([exported, local]) => local === exported ? exported : `${exported}: ${local}`
|
|
3690
|
+
);
|
|
3597
3691
|
out += `
|
|
3598
|
-
;Object.assign(exports, { ${
|
|
3692
|
+
;Object.assign(exports, { ${picks.join(", ")} })`;
|
|
3599
3693
|
}
|
|
3600
3694
|
return out;
|
|
3601
3695
|
}
|
|
3602
3696
|
|
|
3697
|
+
// packages/runtime/src/shared/regexp.ts
|
|
3698
|
+
function escapeRegExp(text) {
|
|
3699
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3700
|
+
}
|
|
3701
|
+
|
|
3603
3702
|
// packages/runtime/src/functions/runtime/sandbox.ts
|
|
3604
3703
|
var bunTranspiler;
|
|
3605
3704
|
function transpile(code) {
|
|
@@ -3618,6 +3717,29 @@ function transformExports(code) {
|
|
|
3618
3717
|
return transformModule(code);
|
|
3619
3718
|
}
|
|
3620
3719
|
var SANDBOX_BUILTIN_REJECTED = "FN_SANDBOX_BUILTIN_BLOCKED";
|
|
3720
|
+
var REALM_VALUE_KEY = "__adepRealmValue";
|
|
3721
|
+
function realmValue(value) {
|
|
3722
|
+
return { [REALM_VALUE_KEY]: value };
|
|
3723
|
+
}
|
|
3724
|
+
function isRealmValue(value) {
|
|
3725
|
+
return typeof value === "object" && value !== null && REALM_VALUE_KEY in value;
|
|
3726
|
+
}
|
|
3727
|
+
function createSandboxContext(sandboxGlobals) {
|
|
3728
|
+
const direct = {};
|
|
3729
|
+
const realmEntries = {};
|
|
3730
|
+
for (const [key, value] of Object.entries(sandboxGlobals)) {
|
|
3731
|
+
if (isRealmValue(value)) realmEntries[key] = value[REALM_VALUE_KEY];
|
|
3732
|
+
else direct[key] = value;
|
|
3733
|
+
}
|
|
3734
|
+
const context = vm.createContext(direct, { codeGeneration: { strings: false, wasm: false } });
|
|
3735
|
+
if (Object.keys(realmEntries).length > 0) {
|
|
3736
|
+
const literal = JSON.stringify(JSON.stringify(realmEntries));
|
|
3737
|
+
vm.runInContext(`Object.assign(globalThis, JSON.parse(${literal}))`, context, {
|
|
3738
|
+
filename: "<sandbox-realm-globals>"
|
|
3739
|
+
});
|
|
3740
|
+
}
|
|
3741
|
+
return context;
|
|
3742
|
+
}
|
|
3621
3743
|
function resolveModulePath(fromDir, request, files) {
|
|
3622
3744
|
if (!request.startsWith("./") && !request.startsWith("../")) return null;
|
|
3623
3745
|
const base = joinPosix(fromDir, request);
|
|
@@ -3641,6 +3763,21 @@ function joinPosix(dir, request) {
|
|
|
3641
3763
|
function normalizePosix(p) {
|
|
3642
3764
|
return joinPosix("", p);
|
|
3643
3765
|
}
|
|
3766
|
+
function errorLineIn(stack, path) {
|
|
3767
|
+
const own = new RegExp(`${escapeRegExp(path)}:(\\d+)`).exec(stack);
|
|
3768
|
+
if (own !== null) return own[1];
|
|
3769
|
+
return /(?:^|\n):(\d+)(?:\n|$)/.exec(stack)?.[1];
|
|
3770
|
+
}
|
|
3771
|
+
function syntaxErrorWithLocation(error, path) {
|
|
3772
|
+
const rawMessage = error instanceof Error ? error.message : String(error);
|
|
3773
|
+
const stack = error.stack;
|
|
3774
|
+
const line = typeof stack === "string" ? errorLineIn(stack, path) : void 0;
|
|
3775
|
+
const location = line === void 0 ? path : `${path}:${line}`;
|
|
3776
|
+
const wrapped = new Error(`\u6E90\u7801\u8BED\u6CD5\u9519\u8BEF\uFF08${location}\uFF09\uFF1A${rawMessage}`, { cause: error });
|
|
3777
|
+
const code = error.code;
|
|
3778
|
+
if (typeof code === "string") wrapped.code = code;
|
|
3779
|
+
return wrapped;
|
|
3780
|
+
}
|
|
3644
3781
|
function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache) {
|
|
3645
3782
|
const cached = cache.get(path);
|
|
3646
3783
|
if (cached !== void 0) return cached;
|
|
@@ -3674,21 +3811,20 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache)
|
|
|
3674
3811
|
try {
|
|
3675
3812
|
transformed = transformExports(transpile(source));
|
|
3676
3813
|
} catch (error) {
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
throw wrapped;
|
|
3685
|
-
}
|
|
3686
|
-
const wrapper = vm.runInNewContext(
|
|
3687
|
-
`(function (module, exports, require) { ${transformed}
|
|
3814
|
+
throw syntaxErrorWithLocation(error, path);
|
|
3815
|
+
}
|
|
3816
|
+
const context = createSandboxContext(sandboxGlobals);
|
|
3817
|
+
let wrapper;
|
|
3818
|
+
try {
|
|
3819
|
+
wrapper = vm.runInContext(
|
|
3820
|
+
`(function (module, exports, require) { ${transformed}
|
|
3688
3821
|
})`,
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3822
|
+
context,
|
|
3823
|
+
{ filename: path }
|
|
3824
|
+
);
|
|
3825
|
+
} catch (error) {
|
|
3826
|
+
throw syntaxErrorWithLocation(error, path);
|
|
3827
|
+
}
|
|
3692
3828
|
wrapper(module, exports, require2);
|
|
3693
3829
|
if (module.default !== void 0 && exports["default"] === void 0) {
|
|
3694
3830
|
exports["default"] = module.default;
|
|
@@ -3863,6 +3999,8 @@ var SandboxFetchError = class extends Error {
|
|
|
3863
3999
|
}
|
|
3864
4000
|
};
|
|
3865
4001
|
var DEFAULT_MAX_RESPONSE_BYTES = 100 * 1024 * 1024;
|
|
4002
|
+
var DEFAULT_MAX_REDIRECTS = 5;
|
|
4003
|
+
var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
3866
4004
|
var defaultFetch = (url, init) => (
|
|
3867
4005
|
// 真实 Response 与内部 ResponseLike 结构性一致;getReader 的多态签名差异属纯类型问题,运行语义等价。
|
|
3868
4006
|
globalThis.fetch(url, init)
|
|
@@ -3901,18 +4039,24 @@ function headersToRecord(headers) {
|
|
|
3901
4039
|
}
|
|
3902
4040
|
return out;
|
|
3903
4041
|
}
|
|
3904
|
-
function
|
|
3905
|
-
const headers = res.headers;
|
|
4042
|
+
function headerValue(headers, name) {
|
|
3906
4043
|
if (headers === void 0 || headers === null) return null;
|
|
4044
|
+
let raw;
|
|
3907
4045
|
if (typeof headers.get === "function") {
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
const
|
|
3911
|
-
|
|
3912
|
-
}
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
4046
|
+
raw = headers.get?.(name);
|
|
4047
|
+
} else {
|
|
4048
|
+
const record = headers;
|
|
4049
|
+
raw = record[name.toLocaleLowerCase()] ?? record[name];
|
|
4050
|
+
}
|
|
4051
|
+
if (raw === void 0 || raw === null || raw.trim() === "") return null;
|
|
4052
|
+
return raw;
|
|
4053
|
+
}
|
|
4054
|
+
function contentLength(res) {
|
|
4055
|
+
const raw = headerValue(
|
|
4056
|
+
res.headers,
|
|
4057
|
+
"content-length"
|
|
4058
|
+
);
|
|
4059
|
+
if (raw === null) return null;
|
|
3916
4060
|
const n = Number(raw);
|
|
3917
4061
|
return Number.isFinite(n) && n >= 0 ? n : null;
|
|
3918
4062
|
}
|
|
@@ -3992,44 +4136,72 @@ function createSandboxFetch(options) {
|
|
|
3992
4136
|
const fetchImpl = options.fetchImpl ?? defaultFetch;
|
|
3993
4137
|
const { allowlist, timeoutMs } = options;
|
|
3994
4138
|
const maxBytes = options.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES;
|
|
3995
|
-
|
|
4139
|
+
const maxRedirects = Math.max(0, options.maxRedirects ?? DEFAULT_MAX_REDIRECTS);
|
|
4140
|
+
const guard = (raw) => {
|
|
3996
4141
|
let parsed;
|
|
3997
4142
|
try {
|
|
3998
|
-
parsed = new URL(
|
|
4143
|
+
parsed = new URL(raw);
|
|
3999
4144
|
} catch {
|
|
4000
|
-
throw new SandboxFetchError("FN_FETCH_INVALID_URL", `cloud.fetch \u6536\u5230\u975E\u6CD5 URL"${
|
|
4145
|
+
throw new SandboxFetchError("FN_FETCH_INVALID_URL", `cloud.fetch \u6536\u5230\u975E\u6CD5 URL"${raw}"`);
|
|
4001
4146
|
}
|
|
4002
|
-
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") throw FORBIDDEN(
|
|
4003
|
-
if (!isHostAllowed(parsed.hostname, allowlist)) throw FORBIDDEN(
|
|
4147
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") throw FORBIDDEN(raw);
|
|
4148
|
+
if (!isHostAllowed(parsed.hostname, allowlist)) throw FORBIDDEN(raw);
|
|
4149
|
+
return parsed;
|
|
4150
|
+
};
|
|
4151
|
+
const fetchOnce = async (url, init) => {
|
|
4004
4152
|
const controller = new AbortController();
|
|
4005
4153
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
4006
4154
|
const signals = [controller.signal];
|
|
4007
4155
|
if (init?.signal !== void 0) signals.push(init.signal);
|
|
4008
4156
|
const signal = signals.length === 1 ? signals[0] : AbortSignal.any(signals);
|
|
4157
|
+
const request = {
|
|
4158
|
+
...init,
|
|
4159
|
+
signal,
|
|
4160
|
+
redirect: "manual"
|
|
4161
|
+
};
|
|
4009
4162
|
try {
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
`cloud.fetch \u8BF7\u6C42\u8D85\u65F6\uFF08\u8D85\u8FC7 ${timeoutMs}ms\uFF09`
|
|
4018
|
-
);
|
|
4019
|
-
}
|
|
4020
|
-
if (init?.signal?.aborted === true) {
|
|
4021
|
-
throw new SandboxFetchError("FN_FETCH_ABORTED", "cloud.fetch \u8BF7\u6C42\u88AB\u8C03\u7528\u65B9\u4E2D\u6B62");
|
|
4022
|
-
}
|
|
4023
|
-
throw new SandboxFetchError(
|
|
4024
|
-
"FN_FETCH_FAILED",
|
|
4025
|
-
`cloud.fetch \u8BF7\u6C42\u5931\u8D25\uFF1A${errorMessageOf(error)}`
|
|
4026
|
-
);
|
|
4163
|
+
return await fetchImpl(url, request);
|
|
4164
|
+
} catch (error) {
|
|
4165
|
+
if (controller.signal.aborted) {
|
|
4166
|
+
throw new SandboxFetchError("FN_FETCH_TIMEOUT", `cloud.fetch \u8BF7\u6C42\u8D85\u65F6\uFF08\u8D85\u8FC7 ${timeoutMs}ms\uFF09`);
|
|
4167
|
+
}
|
|
4168
|
+
if (init?.signal?.aborted === true) {
|
|
4169
|
+
throw new SandboxFetchError("FN_FETCH_ABORTED", "cloud.fetch \u8BF7\u6C42\u88AB\u8C03\u7528\u65B9\u4E2D\u6B62");
|
|
4027
4170
|
}
|
|
4028
|
-
|
|
4171
|
+
throw new SandboxFetchError(
|
|
4172
|
+
"FN_FETCH_FAILED",
|
|
4173
|
+
`cloud.fetch \u8BF7\u6C42\u5931\u8D25\uFF1A${errorMessageOf(error)}`
|
|
4174
|
+
);
|
|
4029
4175
|
} finally {
|
|
4030
4176
|
clearTimeout(timer);
|
|
4031
4177
|
}
|
|
4032
4178
|
};
|
|
4179
|
+
return async (url, init) => {
|
|
4180
|
+
let target = guard(url);
|
|
4181
|
+
let currentInit = init === void 0 ? void 0 : { ...init };
|
|
4182
|
+
let lastRes = null;
|
|
4183
|
+
for (let hop = 0; hop <= maxRedirects; hop++) {
|
|
4184
|
+
const res = await fetchOnce(target.href, currentInit);
|
|
4185
|
+
const location = REDIRECT_STATUSES.has(res.status) ? headerValue(res.headers, "location") : null;
|
|
4186
|
+
if (location === null || hop === maxRedirects) {
|
|
4187
|
+
lastRes = res;
|
|
4188
|
+
break;
|
|
4189
|
+
}
|
|
4190
|
+
let next;
|
|
4191
|
+
try {
|
|
4192
|
+
next = new URL(location, target.href);
|
|
4193
|
+
} catch {
|
|
4194
|
+
lastRes = res;
|
|
4195
|
+
break;
|
|
4196
|
+
}
|
|
4197
|
+
if (res.status !== 307 && res.status !== 308 && currentInit !== void 0) {
|
|
4198
|
+
currentInit.method = "GET";
|
|
4199
|
+
delete currentInit.body;
|
|
4200
|
+
}
|
|
4201
|
+
target = guard(next.href);
|
|
4202
|
+
}
|
|
4203
|
+
return normalizeResponse(lastRes, maxBytes);
|
|
4204
|
+
};
|
|
4033
4205
|
}
|
|
4034
4206
|
|
|
4035
4207
|
// packages/runtime/src/functions/runtime/flat-rpc-proxy.ts
|
|
@@ -4158,11 +4330,6 @@ function createChainClient(capability, port, pending, nextId, spec) {
|
|
|
4158
4330
|
return makeRoot(void 0);
|
|
4159
4331
|
}
|
|
4160
4332
|
|
|
4161
|
-
// packages/runtime/src/shared/regexp.ts
|
|
4162
|
-
function escapeRegExp(text) {
|
|
4163
|
-
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4164
|
-
}
|
|
4165
|
-
|
|
4166
4333
|
// packages/runtime/src/functions/runtime/worker-entry.ts
|
|
4167
4334
|
function errorMessageOf2(error) {
|
|
4168
4335
|
if (error instanceof Error) return error.message;
|
|
@@ -4172,12 +4339,35 @@ function errorMessageOf2(error) {
|
|
|
4172
4339
|
}
|
|
4173
4340
|
return String(error);
|
|
4174
4341
|
}
|
|
4342
|
+
async function normalizeResultBody(value) {
|
|
4343
|
+
if (!(value instanceof Response)) return value;
|
|
4344
|
+
const contentType = value.headers.get("content-type") ?? "";
|
|
4345
|
+
const text = await value.text();
|
|
4346
|
+
let payload = text;
|
|
4347
|
+
if (contentType.includes("application/json")) {
|
|
4348
|
+
try {
|
|
4349
|
+
payload = text === "" ? null : JSON.parse(text);
|
|
4350
|
+
} catch {
|
|
4351
|
+
payload = text;
|
|
4352
|
+
}
|
|
4353
|
+
}
|
|
4354
|
+
const headers = {};
|
|
4355
|
+
value.headers.forEach((headerValue2, key) => {
|
|
4356
|
+
headers[key] = headerValue2;
|
|
4357
|
+
});
|
|
4358
|
+
return { __adepHttp: { status: value.status, body: payload, headers } };
|
|
4359
|
+
}
|
|
4175
4360
|
function firstUserFrame(stack, files) {
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4361
|
+
const patterns = Object.keys(files).map(
|
|
4362
|
+
(key) => [
|
|
4363
|
+
key,
|
|
4364
|
+
new RegExp(`(?<![\\w$/.])${escapeRegExp(key)}:(\\d+)(?::(\\d+))?(?::(\\d+))?`)
|
|
4365
|
+
]
|
|
4366
|
+
);
|
|
4367
|
+
for (const line of stack.split("\n")) {
|
|
4368
|
+
for (const [key, pattern] of patterns) {
|
|
4369
|
+
const match = pattern.exec(line);
|
|
4370
|
+
if (match === null) continue;
|
|
4181
4371
|
return match[2] === void 0 ? `${key}:${match[1]}` : `${key}:${match[1]}:${match[2]}`;
|
|
4182
4372
|
}
|
|
4183
4373
|
}
|
|
@@ -4188,7 +4378,8 @@ function errorMessageWithLocation(error, files) {
|
|
|
4188
4378
|
const stack = error.stack;
|
|
4189
4379
|
if (typeof stack !== "string") return message;
|
|
4190
4380
|
const frame = firstUserFrame(stack, files);
|
|
4191
|
-
|
|
4381
|
+
if (frame === void 0 || message.includes(`\uFF08${frame}\uFF09`)) return message;
|
|
4382
|
+
return `${message}\uFF08${frame}\uFF09`;
|
|
4192
4383
|
}
|
|
4193
4384
|
function createBareResolver(deps) {
|
|
4194
4385
|
const platformRequire = createRequire(import.meta.url);
|
|
@@ -4269,7 +4460,7 @@ function runWorker(input, port) {
|
|
|
4269
4460
|
structuredClone
|
|
4270
4461
|
};
|
|
4271
4462
|
if (input.env !== void 0) {
|
|
4272
|
-
sandboxGlobals["process"] = { env: input.env };
|
|
4463
|
+
sandboxGlobals["process"] = realmValue({ env: input.env });
|
|
4273
4464
|
}
|
|
4274
4465
|
if (input.fetch !== void 0) {
|
|
4275
4466
|
const sandboxFetch = createSandboxFetch({
|
|
@@ -4301,8 +4492,20 @@ function runWorker(input, port) {
|
|
|
4301
4492
|
const result = Promise.resolve(handler(ctx));
|
|
4302
4493
|
void result.then(
|
|
4303
4494
|
(value) => {
|
|
4304
|
-
|
|
4305
|
-
|
|
4495
|
+
return normalizeResultBody(value).then(
|
|
4496
|
+
(body) => {
|
|
4497
|
+
port.postMessage({ type: "result", body: body === void 0 ? null : body });
|
|
4498
|
+
return void 0;
|
|
4499
|
+
},
|
|
4500
|
+
(error) => {
|
|
4501
|
+
port.postMessage({
|
|
4502
|
+
type: "error",
|
|
4503
|
+
message: `\u51FD\u6570\u8FD4\u56DE\u7684 Response \u89E3\u5305\u5931\u8D25\uFF1A${errorMessageOf2(error)}`,
|
|
4504
|
+
code: "FN_RESPONSE_UNWRAP_FAILED"
|
|
4505
|
+
});
|
|
4506
|
+
return void 0;
|
|
4507
|
+
}
|
|
4508
|
+
);
|
|
4306
4509
|
},
|
|
4307
4510
|
(error) => {
|
|
4308
4511
|
port.postMessage({
|