@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/worker-entry.js
CHANGED
|
@@ -88,13 +88,67 @@ import vm from "node:vm";
|
|
|
88
88
|
import * as nodeModule from "node:module";
|
|
89
89
|
|
|
90
90
|
// packages/runtime/src/functions/runtime/exports.ts
|
|
91
|
+
function keepLineCount(matched, lead) {
|
|
92
|
+
const consumed = matched.split("\n").length - 1;
|
|
93
|
+
const kept = lead === "\n" ? 1 : 0;
|
|
94
|
+
return "\n".repeat(Math.max(0, consumed - kept));
|
|
95
|
+
}
|
|
96
|
+
function parseSpecifier(part) {
|
|
97
|
+
const asMatch = /^([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)$/.exec(part);
|
|
98
|
+
if (asMatch !== null) {
|
|
99
|
+
const [, local, exported] = asMatch;
|
|
100
|
+
if (local !== void 0 && exported !== void 0) return [local, exported];
|
|
101
|
+
}
|
|
102
|
+
return /^[A-Za-z_$][\w$]*$/.test(part) ? [part, part] : null;
|
|
103
|
+
}
|
|
104
|
+
function namedImportsToDestructure(clause) {
|
|
105
|
+
const parts = [];
|
|
106
|
+
for (const raw of clause.split(",")) {
|
|
107
|
+
const part = raw.trim();
|
|
108
|
+
if (part === "") continue;
|
|
109
|
+
const spec = parseSpecifier(part);
|
|
110
|
+
if (spec === null) {
|
|
111
|
+
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`);
|
|
112
|
+
}
|
|
113
|
+
parts.push(spec[0] === spec[1] ? spec[0] : `${spec[0]}: ${spec[1]}`);
|
|
114
|
+
}
|
|
115
|
+
return parts;
|
|
116
|
+
}
|
|
117
|
+
function parseExportClause(clause) {
|
|
118
|
+
const entries = [];
|
|
119
|
+
for (const raw of clause.split(",")) {
|
|
120
|
+
const part = raw.trim();
|
|
121
|
+
if (part === "") continue;
|
|
122
|
+
const spec = parseSpecifier(part);
|
|
123
|
+
if (spec === null) {
|
|
124
|
+
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`);
|
|
125
|
+
}
|
|
126
|
+
entries.push({ local: spec[0], exported: spec[1] });
|
|
127
|
+
}
|
|
128
|
+
return entries;
|
|
129
|
+
}
|
|
91
130
|
function transformModule(code) {
|
|
92
131
|
let out = code;
|
|
93
132
|
const named = [];
|
|
133
|
+
const starReexports = [];
|
|
134
|
+
let tempSeq = 0;
|
|
135
|
+
const nextTemp = () => `__adep_reexport_${tempSeq++}`;
|
|
94
136
|
out = out.replace(/(^|\n)(\s*)export\s+default\s+/g, "$1$2module.default = ");
|
|
95
137
|
out = out.replace(
|
|
96
138
|
/import\s*\{([^}]*)\}\s*from\s*(['"][^'"]*['"])[ \t]*;?/g,
|
|
97
|
-
(
|
|
139
|
+
(matched, clause, source) => {
|
|
140
|
+
const parts = namedImportsToDestructure(clause);
|
|
141
|
+
const pad = keepLineCount(matched, "");
|
|
142
|
+
return parts.length === 0 ? `require(${source})${pad}` : `const { ${parts.join(", ")} } = require(${source})${pad}`;
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
out = out.replace(
|
|
146
|
+
/import\s+([A-Za-z_$][\w$]*)\s*,\s*\{([^}]*)\}\s*from\s*(['"][^'"]*['"])[ \t]*;?/g,
|
|
147
|
+
(matched, name, clause, source) => {
|
|
148
|
+
const parts = namedImportsToDestructure(clause);
|
|
149
|
+
const pad = keepLineCount(matched, "");
|
|
150
|
+
return parts.length === 0 ? `const ${name} = require(${source})${pad}` : `const ${name} = require(${source}), { ${parts.join(", ")} } = ${name}${pad}`;
|
|
151
|
+
}
|
|
98
152
|
);
|
|
99
153
|
out = out.replace(
|
|
100
154
|
/import\s*\*\s*as\s*([A-Za-z_$][\w$]*)\s*from\s*(['"][^'"]*['"])[ \t]*;?/g,
|
|
@@ -104,31 +158,76 @@ function transformModule(code) {
|
|
|
104
158
|
/import\s+([A-Za-z_$][\w$]*)\s+from\s*(['"][^'"]*['"])[ \t]*;?/g,
|
|
105
159
|
(_match, name, source) => `const ${name} = require(${source})`
|
|
106
160
|
);
|
|
161
|
+
out = out.replace(
|
|
162
|
+
/(^|\n)([ \t]*)import\s*(['"][^'"]*['"])[ \t]*;?/g,
|
|
163
|
+
(_match, lead, indent, source) => `${lead}${indent}require(${source})`
|
|
164
|
+
);
|
|
165
|
+
out = out.replace(
|
|
166
|
+
/(^|\n)([ \t]*)export\s*\{([^}]*)\}[ \t]*(?:\n[ \t]*(?=from\b))?(?:from\s*(['"][^'"]*['"]))?[ \t]*;?/g,
|
|
167
|
+
(matched, lead, indent, clause, source) => {
|
|
168
|
+
const pad = keepLineCount(matched, lead);
|
|
169
|
+
const entries = parseExportClause(clause);
|
|
170
|
+
if (entries.length === 0) return `${lead}${indent}${pad}`;
|
|
171
|
+
if (source === void 0) {
|
|
172
|
+
named.push(...entries);
|
|
173
|
+
return `${lead}${indent}${pad}`;
|
|
174
|
+
}
|
|
175
|
+
const temp = nextTemp();
|
|
176
|
+
for (const entry of entries) {
|
|
177
|
+
named.push({ local: `${temp}.${entry.local}`, exported: entry.exported });
|
|
178
|
+
}
|
|
179
|
+
return `${lead}${indent}const ${temp} = require(${source})${pad}`;
|
|
180
|
+
}
|
|
181
|
+
);
|
|
182
|
+
out = out.replace(
|
|
183
|
+
/(^|\n)([ \t]*)export\s*\*[ \t]*(?:as[ \t]+([A-Za-z_$][\w$]*)[ \t]*)?\s*from\s*(['"][^'"]*['"])[ \t]*;?/g,
|
|
184
|
+
(matched, lead, indent, ns, source) => {
|
|
185
|
+
const pad = keepLineCount(matched, lead);
|
|
186
|
+
const temp = nextTemp();
|
|
187
|
+
if (ns === void 0) starReexports.push(temp);
|
|
188
|
+
else named.push({ local: temp, exported: ns });
|
|
189
|
+
return `${lead}${indent}const ${temp} = require(${source})${pad}`;
|
|
190
|
+
}
|
|
191
|
+
);
|
|
107
192
|
out = out.replace(
|
|
108
193
|
/export\s+(const|let|var)\s+([A-Za-z_$][\w$]*)/g,
|
|
109
194
|
(_match, kw, name) => {
|
|
110
|
-
named.push(name);
|
|
195
|
+
named.push({ local: name, exported: name });
|
|
111
196
|
return `${kw} ${name}`;
|
|
112
197
|
}
|
|
113
198
|
);
|
|
114
199
|
out = out.replace(
|
|
115
200
|
/export\s+(async\s+)?function\s*\*?\s*([A-Za-z_$][\w$]*)/g,
|
|
116
201
|
(_match, asyncKw, name) => {
|
|
117
|
-
named.push(name);
|
|
202
|
+
named.push({ local: name, exported: name });
|
|
118
203
|
return `${asyncKw ?? ""}function ${name}`;
|
|
119
204
|
}
|
|
120
205
|
);
|
|
121
206
|
out = out.replace(/export\s+class\s+([A-Za-z_$][\w$]*)/g, (_match, name) => {
|
|
122
|
-
named.push(name);
|
|
207
|
+
named.push({ local: name, exported: name });
|
|
123
208
|
return `class ${name}`;
|
|
124
209
|
});
|
|
125
|
-
|
|
210
|
+
for (const temp of starReexports) {
|
|
126
211
|
out += `
|
|
127
|
-
;Object.
|
|
212
|
+
;Object.keys(${temp}).forEach((k) => { if (k !== 'default') exports[k] = ${temp}[k] })`;
|
|
213
|
+
}
|
|
214
|
+
const byExported = /* @__PURE__ */ new Map();
|
|
215
|
+
for (const entry of named) byExported.set(entry.exported, entry.local);
|
|
216
|
+
if (byExported.size > 0) {
|
|
217
|
+
const picks = [...byExported].map(
|
|
218
|
+
([exported, local]) => local === exported ? exported : `${exported}: ${local}`
|
|
219
|
+
);
|
|
220
|
+
out += `
|
|
221
|
+
;Object.assign(exports, { ${picks.join(", ")} })`;
|
|
128
222
|
}
|
|
129
223
|
return out;
|
|
130
224
|
}
|
|
131
225
|
|
|
226
|
+
// packages/runtime/src/shared/regexp.ts
|
|
227
|
+
function escapeRegExp(text) {
|
|
228
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
229
|
+
}
|
|
230
|
+
|
|
132
231
|
// packages/runtime/src/functions/runtime/sandbox.ts
|
|
133
232
|
var bunTranspiler;
|
|
134
233
|
function transpile(code) {
|
|
@@ -147,6 +246,29 @@ function transformExports(code) {
|
|
|
147
246
|
return transformModule(code);
|
|
148
247
|
}
|
|
149
248
|
var SANDBOX_BUILTIN_REJECTED = "FN_SANDBOX_BUILTIN_BLOCKED";
|
|
249
|
+
var REALM_VALUE_KEY = "__adepRealmValue";
|
|
250
|
+
function realmValue(value) {
|
|
251
|
+
return { [REALM_VALUE_KEY]: value };
|
|
252
|
+
}
|
|
253
|
+
function isRealmValue(value) {
|
|
254
|
+
return typeof value === "object" && value !== null && REALM_VALUE_KEY in value;
|
|
255
|
+
}
|
|
256
|
+
function createSandboxContext(sandboxGlobals) {
|
|
257
|
+
const direct = {};
|
|
258
|
+
const realmEntries = {};
|
|
259
|
+
for (const [key, value] of Object.entries(sandboxGlobals)) {
|
|
260
|
+
if (isRealmValue(value)) realmEntries[key] = value[REALM_VALUE_KEY];
|
|
261
|
+
else direct[key] = value;
|
|
262
|
+
}
|
|
263
|
+
const context = vm.createContext(direct, { codeGeneration: { strings: false, wasm: false } });
|
|
264
|
+
if (Object.keys(realmEntries).length > 0) {
|
|
265
|
+
const literal = JSON.stringify(JSON.stringify(realmEntries));
|
|
266
|
+
vm.runInContext(`Object.assign(globalThis, JSON.parse(${literal}))`, context, {
|
|
267
|
+
filename: "<sandbox-realm-globals>"
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
return context;
|
|
271
|
+
}
|
|
150
272
|
function resolveModulePath(fromDir, request, files) {
|
|
151
273
|
if (!request.startsWith("./") && !request.startsWith("../")) return null;
|
|
152
274
|
const base = joinPosix(fromDir, request);
|
|
@@ -170,6 +292,21 @@ function joinPosix(dir, request) {
|
|
|
170
292
|
function normalizePosix(p) {
|
|
171
293
|
return joinPosix("", p);
|
|
172
294
|
}
|
|
295
|
+
function errorLineIn(stack, path) {
|
|
296
|
+
const own = new RegExp(`${escapeRegExp(path)}:(\\d+)`).exec(stack);
|
|
297
|
+
if (own !== null) return own[1];
|
|
298
|
+
return /(?:^|\n):(\d+)(?:\n|$)/.exec(stack)?.[1];
|
|
299
|
+
}
|
|
300
|
+
function syntaxErrorWithLocation(error, path) {
|
|
301
|
+
const rawMessage = error instanceof Error ? error.message : String(error);
|
|
302
|
+
const stack = error.stack;
|
|
303
|
+
const line = typeof stack === "string" ? errorLineIn(stack, path) : void 0;
|
|
304
|
+
const location = line === void 0 ? path : `${path}:${line}`;
|
|
305
|
+
const wrapped = new Error(`\u6E90\u7801\u8BED\u6CD5\u9519\u8BEF\uFF08${location}\uFF09\uFF1A${rawMessage}`, { cause: error });
|
|
306
|
+
const code = error.code;
|
|
307
|
+
if (typeof code === "string") wrapped.code = code;
|
|
308
|
+
return wrapped;
|
|
309
|
+
}
|
|
173
310
|
function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache) {
|
|
174
311
|
const cached = cache.get(path);
|
|
175
312
|
if (cached !== void 0) return cached;
|
|
@@ -203,21 +340,20 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache)
|
|
|
203
340
|
try {
|
|
204
341
|
transformed = transformExports(transpile(source));
|
|
205
342
|
} catch (error) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
throw wrapped;
|
|
214
|
-
}
|
|
215
|
-
const wrapper = vm.runInNewContext(
|
|
216
|
-
`(function (module, exports, require) { ${transformed}
|
|
343
|
+
throw syntaxErrorWithLocation(error, path);
|
|
344
|
+
}
|
|
345
|
+
const context = createSandboxContext(sandboxGlobals);
|
|
346
|
+
let wrapper;
|
|
347
|
+
try {
|
|
348
|
+
wrapper = vm.runInContext(
|
|
349
|
+
`(function (module, exports, require) { ${transformed}
|
|
217
350
|
})`,
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
351
|
+
context,
|
|
352
|
+
{ filename: path }
|
|
353
|
+
);
|
|
354
|
+
} catch (error) {
|
|
355
|
+
throw syntaxErrorWithLocation(error, path);
|
|
356
|
+
}
|
|
221
357
|
wrapper(module, exports, require2);
|
|
222
358
|
if (module.default !== void 0 && exports["default"] === void 0) {
|
|
223
359
|
exports["default"] = module.default;
|
|
@@ -245,6 +381,8 @@ var SandboxFetchError = class extends Error {
|
|
|
245
381
|
}
|
|
246
382
|
};
|
|
247
383
|
var DEFAULT_MAX_RESPONSE_BYTES = 100 * 1024 * 1024;
|
|
384
|
+
var DEFAULT_MAX_REDIRECTS = 5;
|
|
385
|
+
var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
248
386
|
var defaultFetch = (url, init) => (
|
|
249
387
|
// 真实 Response 与内部 ResponseLike 结构性一致;getReader 的多态签名差异属纯类型问题,运行语义等价。
|
|
250
388
|
globalThis.fetch(url, init)
|
|
@@ -283,18 +421,24 @@ function headersToRecord(headers) {
|
|
|
283
421
|
}
|
|
284
422
|
return out;
|
|
285
423
|
}
|
|
286
|
-
function
|
|
287
|
-
const headers = res.headers;
|
|
424
|
+
function headerValue(headers, name) {
|
|
288
425
|
if (headers === void 0 || headers === null) return null;
|
|
426
|
+
let raw;
|
|
289
427
|
if (typeof headers.get === "function") {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
428
|
+
raw = headers.get?.(name);
|
|
429
|
+
} else {
|
|
430
|
+
const record = headers;
|
|
431
|
+
raw = record[name.toLocaleLowerCase()] ?? record[name];
|
|
432
|
+
}
|
|
433
|
+
if (raw === void 0 || raw === null || raw.trim() === "") return null;
|
|
434
|
+
return raw;
|
|
435
|
+
}
|
|
436
|
+
function contentLength(res) {
|
|
437
|
+
const raw = headerValue(
|
|
438
|
+
res.headers,
|
|
439
|
+
"content-length"
|
|
440
|
+
);
|
|
441
|
+
if (raw === null) return null;
|
|
298
442
|
const n = Number(raw);
|
|
299
443
|
return Number.isFinite(n) && n >= 0 ? n : null;
|
|
300
444
|
}
|
|
@@ -374,44 +518,72 @@ function createSandboxFetch(options) {
|
|
|
374
518
|
const fetchImpl = options.fetchImpl ?? defaultFetch;
|
|
375
519
|
const { allowlist, timeoutMs } = options;
|
|
376
520
|
const maxBytes = options.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES;
|
|
377
|
-
|
|
521
|
+
const maxRedirects = Math.max(0, options.maxRedirects ?? DEFAULT_MAX_REDIRECTS);
|
|
522
|
+
const guard = (raw) => {
|
|
378
523
|
let parsed;
|
|
379
524
|
try {
|
|
380
|
-
parsed = new URL(
|
|
525
|
+
parsed = new URL(raw);
|
|
381
526
|
} catch {
|
|
382
|
-
throw new SandboxFetchError("FN_FETCH_INVALID_URL", `cloud.fetch \u6536\u5230\u975E\u6CD5 URL"${
|
|
527
|
+
throw new SandboxFetchError("FN_FETCH_INVALID_URL", `cloud.fetch \u6536\u5230\u975E\u6CD5 URL"${raw}"`);
|
|
383
528
|
}
|
|
384
|
-
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") throw FORBIDDEN(
|
|
385
|
-
if (!isHostAllowed(parsed.hostname, allowlist)) throw FORBIDDEN(
|
|
529
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") throw FORBIDDEN(raw);
|
|
530
|
+
if (!isHostAllowed(parsed.hostname, allowlist)) throw FORBIDDEN(raw);
|
|
531
|
+
return parsed;
|
|
532
|
+
};
|
|
533
|
+
const fetchOnce = async (url, init) => {
|
|
386
534
|
const controller = new AbortController();
|
|
387
535
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
388
536
|
const signals = [controller.signal];
|
|
389
537
|
if (init?.signal !== void 0) signals.push(init.signal);
|
|
390
538
|
const signal = signals.length === 1 ? signals[0] : AbortSignal.any(signals);
|
|
539
|
+
const request = {
|
|
540
|
+
...init,
|
|
541
|
+
signal,
|
|
542
|
+
redirect: "manual"
|
|
543
|
+
};
|
|
391
544
|
try {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
`cloud.fetch \u8BF7\u6C42\u8D85\u65F6\uFF08\u8D85\u8FC7 ${timeoutMs}ms\uFF09`
|
|
400
|
-
);
|
|
401
|
-
}
|
|
402
|
-
if (init?.signal?.aborted === true) {
|
|
403
|
-
throw new SandboxFetchError("FN_FETCH_ABORTED", "cloud.fetch \u8BF7\u6C42\u88AB\u8C03\u7528\u65B9\u4E2D\u6B62");
|
|
404
|
-
}
|
|
405
|
-
throw new SandboxFetchError(
|
|
406
|
-
"FN_FETCH_FAILED",
|
|
407
|
-
`cloud.fetch \u8BF7\u6C42\u5931\u8D25\uFF1A${errorMessageOf(error)}`
|
|
408
|
-
);
|
|
545
|
+
return await fetchImpl(url, request);
|
|
546
|
+
} catch (error) {
|
|
547
|
+
if (controller.signal.aborted) {
|
|
548
|
+
throw new SandboxFetchError("FN_FETCH_TIMEOUT", `cloud.fetch \u8BF7\u6C42\u8D85\u65F6\uFF08\u8D85\u8FC7 ${timeoutMs}ms\uFF09`);
|
|
549
|
+
}
|
|
550
|
+
if (init?.signal?.aborted === true) {
|
|
551
|
+
throw new SandboxFetchError("FN_FETCH_ABORTED", "cloud.fetch \u8BF7\u6C42\u88AB\u8C03\u7528\u65B9\u4E2D\u6B62");
|
|
409
552
|
}
|
|
410
|
-
|
|
553
|
+
throw new SandboxFetchError(
|
|
554
|
+
"FN_FETCH_FAILED",
|
|
555
|
+
`cloud.fetch \u8BF7\u6C42\u5931\u8D25\uFF1A${errorMessageOf(error)}`
|
|
556
|
+
);
|
|
411
557
|
} finally {
|
|
412
558
|
clearTimeout(timer);
|
|
413
559
|
}
|
|
414
560
|
};
|
|
561
|
+
return async (url, init) => {
|
|
562
|
+
let target = guard(url);
|
|
563
|
+
let currentInit = init === void 0 ? void 0 : { ...init };
|
|
564
|
+
let lastRes = null;
|
|
565
|
+
for (let hop = 0; hop <= maxRedirects; hop++) {
|
|
566
|
+
const res = await fetchOnce(target.href, currentInit);
|
|
567
|
+
const location = REDIRECT_STATUSES.has(res.status) ? headerValue(res.headers, "location") : null;
|
|
568
|
+
if (location === null || hop === maxRedirects) {
|
|
569
|
+
lastRes = res;
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
let next;
|
|
573
|
+
try {
|
|
574
|
+
next = new URL(location, target.href);
|
|
575
|
+
} catch {
|
|
576
|
+
lastRes = res;
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
if (res.status !== 307 && res.status !== 308 && currentInit !== void 0) {
|
|
580
|
+
currentInit.method = "GET";
|
|
581
|
+
delete currentInit.body;
|
|
582
|
+
}
|
|
583
|
+
target = guard(next.href);
|
|
584
|
+
}
|
|
585
|
+
return normalizeResponse(lastRes, maxBytes);
|
|
586
|
+
};
|
|
415
587
|
}
|
|
416
588
|
|
|
417
589
|
// packages/runtime/src/shared/capability-keys.ts
|
|
@@ -569,11 +741,6 @@ function splitBareSpecifier(request) {
|
|
|
569
741
|
return request.split("/")[0];
|
|
570
742
|
}
|
|
571
743
|
|
|
572
|
-
// packages/runtime/src/shared/regexp.ts
|
|
573
|
-
function escapeRegExp(text) {
|
|
574
|
-
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
575
|
-
}
|
|
576
|
-
|
|
577
744
|
// packages/runtime/src/functions/runtime/worker-entry.ts
|
|
578
745
|
function errorMessageOf2(error) {
|
|
579
746
|
if (error instanceof Error) return error.message;
|
|
@@ -583,12 +750,35 @@ function errorMessageOf2(error) {
|
|
|
583
750
|
}
|
|
584
751
|
return String(error);
|
|
585
752
|
}
|
|
753
|
+
async function normalizeResultBody(value) {
|
|
754
|
+
if (!(value instanceof Response)) return value;
|
|
755
|
+
const contentType = value.headers.get("content-type") ?? "";
|
|
756
|
+
const text = await value.text();
|
|
757
|
+
let payload = text;
|
|
758
|
+
if (contentType.includes("application/json")) {
|
|
759
|
+
try {
|
|
760
|
+
payload = text === "" ? null : JSON.parse(text);
|
|
761
|
+
} catch {
|
|
762
|
+
payload = text;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
const headers = {};
|
|
766
|
+
value.headers.forEach((headerValue2, key) => {
|
|
767
|
+
headers[key] = headerValue2;
|
|
768
|
+
});
|
|
769
|
+
return { __adepHttp: { status: value.status, body: payload, headers } };
|
|
770
|
+
}
|
|
586
771
|
function firstUserFrame(stack, files) {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
772
|
+
const patterns = Object.keys(files).map(
|
|
773
|
+
(key) => [
|
|
774
|
+
key,
|
|
775
|
+
new RegExp(`(?<![\\w$/.])${escapeRegExp(key)}:(\\d+)(?::(\\d+))?(?::(\\d+))?`)
|
|
776
|
+
]
|
|
777
|
+
);
|
|
778
|
+
for (const line of stack.split("\n")) {
|
|
779
|
+
for (const [key, pattern] of patterns) {
|
|
780
|
+
const match = pattern.exec(line);
|
|
781
|
+
if (match === null) continue;
|
|
592
782
|
return match[2] === void 0 ? `${key}:${match[1]}` : `${key}:${match[1]}:${match[2]}`;
|
|
593
783
|
}
|
|
594
784
|
}
|
|
@@ -599,7 +789,8 @@ function errorMessageWithLocation(error, files) {
|
|
|
599
789
|
const stack = error.stack;
|
|
600
790
|
if (typeof stack !== "string") return message;
|
|
601
791
|
const frame = firstUserFrame(stack, files);
|
|
602
|
-
|
|
792
|
+
if (frame === void 0 || message.includes(`\uFF08${frame}\uFF09`)) return message;
|
|
793
|
+
return `${message}\uFF08${frame}\uFF09`;
|
|
603
794
|
}
|
|
604
795
|
function createBareResolver(deps) {
|
|
605
796
|
const platformRequire = createRequire(import.meta.url);
|
|
@@ -680,7 +871,7 @@ function runWorker(input, port) {
|
|
|
680
871
|
structuredClone
|
|
681
872
|
};
|
|
682
873
|
if (input.env !== void 0) {
|
|
683
|
-
sandboxGlobals["process"] = { env: input.env };
|
|
874
|
+
sandboxGlobals["process"] = realmValue({ env: input.env });
|
|
684
875
|
}
|
|
685
876
|
if (input.fetch !== void 0) {
|
|
686
877
|
const sandboxFetch = createSandboxFetch({
|
|
@@ -712,8 +903,20 @@ function runWorker(input, port) {
|
|
|
712
903
|
const result = Promise.resolve(handler(ctx));
|
|
713
904
|
void result.then(
|
|
714
905
|
(value) => {
|
|
715
|
-
|
|
716
|
-
|
|
906
|
+
return normalizeResultBody(value).then(
|
|
907
|
+
(body) => {
|
|
908
|
+
port.postMessage({ type: "result", body: body === void 0 ? null : body });
|
|
909
|
+
return void 0;
|
|
910
|
+
},
|
|
911
|
+
(error) => {
|
|
912
|
+
port.postMessage({
|
|
913
|
+
type: "error",
|
|
914
|
+
message: `\u51FD\u6570\u8FD4\u56DE\u7684 Response \u89E3\u5305\u5931\u8D25\uFF1A${errorMessageOf2(error)}`,
|
|
915
|
+
code: "FN_RESPONSE_UNWRAP_FAILED"
|
|
916
|
+
});
|
|
917
|
+
return void 0;
|
|
918
|
+
}
|
|
919
|
+
);
|
|
717
920
|
},
|
|
718
921
|
(error) => {
|
|
719
922
|
port.postMessage({
|
package/package.json
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://gitcode.com/yunqiang_wu/ai-yunke.git"
|
|
7
7
|
},
|
|
8
|
-
"homepage": "https://adep.
|
|
8
|
+
"homepage": "https://adep.top",
|
|
9
9
|
"bugs": "https://gitcode.com/yunqiang_wu/ai-yunke/issues",
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.4.1",
|
|
11
11
|
"type": "module",
|
|
12
12
|
"description": "`adep` 命令行工具包位:登录 / 初始化 / 本地调试 / 部署 / 数据库维护 / 云存储 / 静态托管 / 微前端组件(widget),实现见任务单 CLI-001 ~ CLI-003 与 FE-002;子路径 `@adep/cli/vite` 提供云函数 vite 插件(CLI-014)",
|
|
13
13
|
"bin": {
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
"esbuild": "0.25.12",
|
|
31
31
|
"yaml": "2.9.1",
|
|
32
32
|
"zod": "^4.4.3",
|
|
33
|
-
"@adep/cf-compat": "0.1.
|
|
34
|
-
"@adep/runtime": "0.3.
|
|
35
|
-
"@adep/
|
|
36
|
-
"@adep/
|
|
33
|
+
"@adep/cf-compat": "0.1.2",
|
|
34
|
+
"@adep/runtime": "0.3.3",
|
|
35
|
+
"@adep/crypto": "0.1.1",
|
|
36
|
+
"@adep/vite-plugin": "0.1.9"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@adep/types": "0.3.
|
|
39
|
+
"@adep/types": "0.3.1"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"test": "vitest run",
|
|
@@ -3,10 +3,10 @@ Pod::Spec.new do |s|
|
|
|
3
3
|
s.version = '0.1.0'
|
|
4
4
|
s.summary = 'AgentDeploy mobile shell native bridge (APP-009)'
|
|
5
5
|
s.description = 'Native-side permission gate + ownerKey Keychain storage + native capability invoke routing'
|
|
6
|
-
s.homepage = 'https://adep.
|
|
6
|
+
s.homepage = 'https://adep.top'
|
|
7
7
|
s.license = 'MIT'
|
|
8
8
|
s.author = 'AgentDeploy'
|
|
9
|
-
s.source = { :git => 'https://adep.
|
|
9
|
+
s.source = { :git => 'https://adep.top/adep-bridge.git', :tag => s.version.to_s }
|
|
10
10
|
s.ios.deployment_target = '13.0'
|
|
11
11
|
s.source_files = 'Sources/**/*.swift'
|
|
12
12
|
s.swift_version = '5.1'
|