@adep/cli 0.3.1 → 0.4.0
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 +14 -5
- package/dist/index.js +628 -379
- package/dist/vite.js +176 -33
- package/dist/worker-entry.js +176 -33
- package/package.json +3 -3
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) {
|
|
@@ -3641,6 +3740,21 @@ function joinPosix(dir, request) {
|
|
|
3641
3740
|
function normalizePosix(p) {
|
|
3642
3741
|
return joinPosix("", p);
|
|
3643
3742
|
}
|
|
3743
|
+
function errorLineIn(stack, path) {
|
|
3744
|
+
const own = new RegExp(`${escapeRegExp(path)}:(\\d+)`).exec(stack);
|
|
3745
|
+
if (own !== null) return own[1];
|
|
3746
|
+
return /(?:^|\n):(\d+)(?:\n|$)/.exec(stack)?.[1];
|
|
3747
|
+
}
|
|
3748
|
+
function syntaxErrorWithLocation(error, path) {
|
|
3749
|
+
const rawMessage = error instanceof Error ? error.message : String(error);
|
|
3750
|
+
const stack = error.stack;
|
|
3751
|
+
const line = typeof stack === "string" ? errorLineIn(stack, path) : void 0;
|
|
3752
|
+
const location = line === void 0 ? path : `${path}:${line}`;
|
|
3753
|
+
const wrapped = new Error(`\u6E90\u7801\u8BED\u6CD5\u9519\u8BEF\uFF08${location}\uFF09\uFF1A${rawMessage}`, { cause: error });
|
|
3754
|
+
const code = error.code;
|
|
3755
|
+
if (typeof code === "string") wrapped.code = code;
|
|
3756
|
+
return wrapped;
|
|
3757
|
+
}
|
|
3644
3758
|
function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache) {
|
|
3645
3759
|
const cached = cache.get(path);
|
|
3646
3760
|
if (cached !== void 0) return cached;
|
|
@@ -3674,21 +3788,19 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache)
|
|
|
3674
3788
|
try {
|
|
3675
3789
|
transformed = transformExports(transpile(source));
|
|
3676
3790
|
} catch (error) {
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
if (typeof code === "string") wrapped.code = code;
|
|
3684
|
-
throw wrapped;
|
|
3685
|
-
}
|
|
3686
|
-
const wrapper = vm.runInNewContext(
|
|
3687
|
-
`(function (module, exports, require) { ${transformed}
|
|
3791
|
+
throw syntaxErrorWithLocation(error, path);
|
|
3792
|
+
}
|
|
3793
|
+
let wrapper;
|
|
3794
|
+
try {
|
|
3795
|
+
wrapper = vm.runInNewContext(
|
|
3796
|
+
`(function (module, exports, require) { ${transformed}
|
|
3688
3797
|
})`,
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3798
|
+
vm.createContext({ ...sandboxGlobals }),
|
|
3799
|
+
{ filename: path }
|
|
3800
|
+
);
|
|
3801
|
+
} catch (error) {
|
|
3802
|
+
throw syntaxErrorWithLocation(error, path);
|
|
3803
|
+
}
|
|
3692
3804
|
wrapper(module, exports, require2);
|
|
3693
3805
|
if (module.default !== void 0 && exports["default"] === void 0) {
|
|
3694
3806
|
exports["default"] = module.default;
|
|
@@ -4158,11 +4270,6 @@ function createChainClient(capability, port, pending, nextId, spec) {
|
|
|
4158
4270
|
return makeRoot(void 0);
|
|
4159
4271
|
}
|
|
4160
4272
|
|
|
4161
|
-
// packages/runtime/src/shared/regexp.ts
|
|
4162
|
-
function escapeRegExp(text) {
|
|
4163
|
-
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4164
|
-
}
|
|
4165
|
-
|
|
4166
4273
|
// packages/runtime/src/functions/runtime/worker-entry.ts
|
|
4167
4274
|
function errorMessageOf2(error) {
|
|
4168
4275
|
if (error instanceof Error) return error.message;
|
|
@@ -4172,12 +4279,35 @@ function errorMessageOf2(error) {
|
|
|
4172
4279
|
}
|
|
4173
4280
|
return String(error);
|
|
4174
4281
|
}
|
|
4282
|
+
async function normalizeResultBody(value) {
|
|
4283
|
+
if (!(value instanceof Response)) return value;
|
|
4284
|
+
const contentType = value.headers.get("content-type") ?? "";
|
|
4285
|
+
const text = await value.text();
|
|
4286
|
+
let payload = text;
|
|
4287
|
+
if (contentType.includes("application/json")) {
|
|
4288
|
+
try {
|
|
4289
|
+
payload = text === "" ? null : JSON.parse(text);
|
|
4290
|
+
} catch {
|
|
4291
|
+
payload = text;
|
|
4292
|
+
}
|
|
4293
|
+
}
|
|
4294
|
+
const headers = {};
|
|
4295
|
+
value.headers.forEach((headerValue, key) => {
|
|
4296
|
+
headers[key] = headerValue;
|
|
4297
|
+
});
|
|
4298
|
+
return { __adepHttp: { status: value.status, body: payload, headers } };
|
|
4299
|
+
}
|
|
4175
4300
|
function firstUserFrame(stack, files) {
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4301
|
+
const patterns = Object.keys(files).map(
|
|
4302
|
+
(key) => [
|
|
4303
|
+
key,
|
|
4304
|
+
new RegExp(`(?<![\\w$/.])${escapeRegExp(key)}:(\\d+)(?::(\\d+))?(?::(\\d+))?`)
|
|
4305
|
+
]
|
|
4306
|
+
);
|
|
4307
|
+
for (const line of stack.split("\n")) {
|
|
4308
|
+
for (const [key, pattern] of patterns) {
|
|
4309
|
+
const match = pattern.exec(line);
|
|
4310
|
+
if (match === null) continue;
|
|
4181
4311
|
return match[2] === void 0 ? `${key}:${match[1]}` : `${key}:${match[1]}:${match[2]}`;
|
|
4182
4312
|
}
|
|
4183
4313
|
}
|
|
@@ -4188,7 +4318,8 @@ function errorMessageWithLocation(error, files) {
|
|
|
4188
4318
|
const stack = error.stack;
|
|
4189
4319
|
if (typeof stack !== "string") return message;
|
|
4190
4320
|
const frame = firstUserFrame(stack, files);
|
|
4191
|
-
|
|
4321
|
+
if (frame === void 0 || message.includes(`\uFF08${frame}\uFF09`)) return message;
|
|
4322
|
+
return `${message}\uFF08${frame}\uFF09`;
|
|
4192
4323
|
}
|
|
4193
4324
|
function createBareResolver(deps) {
|
|
4194
4325
|
const platformRequire = createRequire(import.meta.url);
|
|
@@ -4301,8 +4432,20 @@ function runWorker(input, port) {
|
|
|
4301
4432
|
const result = Promise.resolve(handler(ctx));
|
|
4302
4433
|
void result.then(
|
|
4303
4434
|
(value) => {
|
|
4304
|
-
|
|
4305
|
-
|
|
4435
|
+
return normalizeResultBody(value).then(
|
|
4436
|
+
(body) => {
|
|
4437
|
+
port.postMessage({ type: "result", body: body === void 0 ? null : body });
|
|
4438
|
+
return void 0;
|
|
4439
|
+
},
|
|
4440
|
+
(error) => {
|
|
4441
|
+
port.postMessage({
|
|
4442
|
+
type: "error",
|
|
4443
|
+
message: `\u51FD\u6570\u8FD4\u56DE\u7684 Response \u89E3\u5305\u5931\u8D25\uFF1A${errorMessageOf2(error)}`,
|
|
4444
|
+
code: "FN_RESPONSE_UNWRAP_FAILED"
|
|
4445
|
+
});
|
|
4446
|
+
return void 0;
|
|
4447
|
+
}
|
|
4448
|
+
);
|
|
4306
4449
|
},
|
|
4307
4450
|
(error) => {
|
|
4308
4451
|
port.postMessage({
|
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) {
|
|
@@ -170,6 +269,21 @@ function joinPosix(dir, request) {
|
|
|
170
269
|
function normalizePosix(p) {
|
|
171
270
|
return joinPosix("", p);
|
|
172
271
|
}
|
|
272
|
+
function errorLineIn(stack, path) {
|
|
273
|
+
const own = new RegExp(`${escapeRegExp(path)}:(\\d+)`).exec(stack);
|
|
274
|
+
if (own !== null) return own[1];
|
|
275
|
+
return /(?:^|\n):(\d+)(?:\n|$)/.exec(stack)?.[1];
|
|
276
|
+
}
|
|
277
|
+
function syntaxErrorWithLocation(error, path) {
|
|
278
|
+
const rawMessage = error instanceof Error ? error.message : String(error);
|
|
279
|
+
const stack = error.stack;
|
|
280
|
+
const line = typeof stack === "string" ? errorLineIn(stack, path) : void 0;
|
|
281
|
+
const location = line === void 0 ? path : `${path}:${line}`;
|
|
282
|
+
const wrapped = new Error(`\u6E90\u7801\u8BED\u6CD5\u9519\u8BEF\uFF08${location}\uFF09\uFF1A${rawMessage}`, { cause: error });
|
|
283
|
+
const code = error.code;
|
|
284
|
+
if (typeof code === "string") wrapped.code = code;
|
|
285
|
+
return wrapped;
|
|
286
|
+
}
|
|
173
287
|
function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache) {
|
|
174
288
|
const cached = cache.get(path);
|
|
175
289
|
if (cached !== void 0) return cached;
|
|
@@ -203,21 +317,19 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache)
|
|
|
203
317
|
try {
|
|
204
318
|
transformed = transformExports(transpile(source));
|
|
205
319
|
} catch (error) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
if (typeof code === "string") wrapped.code = code;
|
|
213
|
-
throw wrapped;
|
|
214
|
-
}
|
|
215
|
-
const wrapper = vm.runInNewContext(
|
|
216
|
-
`(function (module, exports, require) { ${transformed}
|
|
320
|
+
throw syntaxErrorWithLocation(error, path);
|
|
321
|
+
}
|
|
322
|
+
let wrapper;
|
|
323
|
+
try {
|
|
324
|
+
wrapper = vm.runInNewContext(
|
|
325
|
+
`(function (module, exports, require) { ${transformed}
|
|
217
326
|
})`,
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
327
|
+
vm.createContext({ ...sandboxGlobals }),
|
|
328
|
+
{ filename: path }
|
|
329
|
+
);
|
|
330
|
+
} catch (error) {
|
|
331
|
+
throw syntaxErrorWithLocation(error, path);
|
|
332
|
+
}
|
|
221
333
|
wrapper(module, exports, require2);
|
|
222
334
|
if (module.default !== void 0 && exports["default"] === void 0) {
|
|
223
335
|
exports["default"] = module.default;
|
|
@@ -569,11 +681,6 @@ function splitBareSpecifier(request) {
|
|
|
569
681
|
return request.split("/")[0];
|
|
570
682
|
}
|
|
571
683
|
|
|
572
|
-
// packages/runtime/src/shared/regexp.ts
|
|
573
|
-
function escapeRegExp(text) {
|
|
574
|
-
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
575
|
-
}
|
|
576
|
-
|
|
577
684
|
// packages/runtime/src/functions/runtime/worker-entry.ts
|
|
578
685
|
function errorMessageOf2(error) {
|
|
579
686
|
if (error instanceof Error) return error.message;
|
|
@@ -583,12 +690,35 @@ function errorMessageOf2(error) {
|
|
|
583
690
|
}
|
|
584
691
|
return String(error);
|
|
585
692
|
}
|
|
693
|
+
async function normalizeResultBody(value) {
|
|
694
|
+
if (!(value instanceof Response)) return value;
|
|
695
|
+
const contentType = value.headers.get("content-type") ?? "";
|
|
696
|
+
const text = await value.text();
|
|
697
|
+
let payload = text;
|
|
698
|
+
if (contentType.includes("application/json")) {
|
|
699
|
+
try {
|
|
700
|
+
payload = text === "" ? null : JSON.parse(text);
|
|
701
|
+
} catch {
|
|
702
|
+
payload = text;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
const headers = {};
|
|
706
|
+
value.headers.forEach((headerValue, key) => {
|
|
707
|
+
headers[key] = headerValue;
|
|
708
|
+
});
|
|
709
|
+
return { __adepHttp: { status: value.status, body: payload, headers } };
|
|
710
|
+
}
|
|
586
711
|
function firstUserFrame(stack, files) {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
712
|
+
const patterns = Object.keys(files).map(
|
|
713
|
+
(key) => [
|
|
714
|
+
key,
|
|
715
|
+
new RegExp(`(?<![\\w$/.])${escapeRegExp(key)}:(\\d+)(?::(\\d+))?(?::(\\d+))?`)
|
|
716
|
+
]
|
|
717
|
+
);
|
|
718
|
+
for (const line of stack.split("\n")) {
|
|
719
|
+
for (const [key, pattern] of patterns) {
|
|
720
|
+
const match = pattern.exec(line);
|
|
721
|
+
if (match === null) continue;
|
|
592
722
|
return match[2] === void 0 ? `${key}:${match[1]}` : `${key}:${match[1]}:${match[2]}`;
|
|
593
723
|
}
|
|
594
724
|
}
|
|
@@ -599,7 +729,8 @@ function errorMessageWithLocation(error, files) {
|
|
|
599
729
|
const stack = error.stack;
|
|
600
730
|
if (typeof stack !== "string") return message;
|
|
601
731
|
const frame = firstUserFrame(stack, files);
|
|
602
|
-
|
|
732
|
+
if (frame === void 0 || message.includes(`\uFF08${frame}\uFF09`)) return message;
|
|
733
|
+
return `${message}\uFF08${frame}\uFF09`;
|
|
603
734
|
}
|
|
604
735
|
function createBareResolver(deps) {
|
|
605
736
|
const platformRequire = createRequire(import.meta.url);
|
|
@@ -712,8 +843,20 @@ function runWorker(input, port) {
|
|
|
712
843
|
const result = Promise.resolve(handler(ctx));
|
|
713
844
|
void result.then(
|
|
714
845
|
(value) => {
|
|
715
|
-
|
|
716
|
-
|
|
846
|
+
return normalizeResultBody(value).then(
|
|
847
|
+
(body) => {
|
|
848
|
+
port.postMessage({ type: "result", body: body === void 0 ? null : body });
|
|
849
|
+
return void 0;
|
|
850
|
+
},
|
|
851
|
+
(error) => {
|
|
852
|
+
port.postMessage({
|
|
853
|
+
type: "error",
|
|
854
|
+
message: `\u51FD\u6570\u8FD4\u56DE\u7684 Response \u89E3\u5305\u5931\u8D25\uFF1A${errorMessageOf2(error)}`,
|
|
855
|
+
code: "FN_RESPONSE_UNWRAP_FAILED"
|
|
856
|
+
});
|
|
857
|
+
return void 0;
|
|
858
|
+
}
|
|
859
|
+
);
|
|
717
860
|
},
|
|
718
861
|
(error) => {
|
|
719
862
|
port.postMessage({
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
},
|
|
8
8
|
"homepage": "https://adep.jajabjbj.top",
|
|
9
9
|
"bugs": "https://gitcode.com/yunqiang_wu/ai-yunke/issues",
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.4.0",
|
|
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,10 +30,10 @@
|
|
|
30
30
|
"esbuild": "0.25.12",
|
|
31
31
|
"yaml": "2.9.1",
|
|
32
32
|
"zod": "^4.4.3",
|
|
33
|
+
"@adep/crypto": "0.1.0",
|
|
33
34
|
"@adep/cf-compat": "0.1.1",
|
|
34
35
|
"@adep/runtime": "0.3.2",
|
|
35
|
-
"@adep/vite-plugin": "0.1.8"
|
|
36
|
-
"@adep/crypto": "0.1.0"
|
|
36
|
+
"@adep/vite-plugin": "0.1.8"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@adep/types": "0.3.0"
|