@adep/cli 0.1.10 → 0.1.11
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 +2 -0
- package/dist/index.js +2845 -2362
- package/dist/vite.js +56 -3
- package/package.json +4 -3
package/dist/vite.js
CHANGED
|
@@ -2664,6 +2664,18 @@ function resolveFunctionEntry(files, fnName) {
|
|
|
2664
2664
|
if (files[directory] !== void 0) return directory;
|
|
2665
2665
|
return void 0;
|
|
2666
2666
|
}
|
|
2667
|
+
function listFunctionNames(files) {
|
|
2668
|
+
const names = /* @__PURE__ */ new Set();
|
|
2669
|
+
for (const key of Object.keys(files)) {
|
|
2670
|
+
const parts = key.split("/");
|
|
2671
|
+
if (parts.length === 1 && parts[0] !== void 0 && parts[0].endsWith(".ts")) {
|
|
2672
|
+
names.add(parts[0].slice(0, -3));
|
|
2673
|
+
} else if (parts.length === 2 && parts[1] === "index.ts" && parts[0] !== void 0) {
|
|
2674
|
+
names.add(parts[0]);
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
return [...names];
|
|
2678
|
+
}
|
|
2667
2679
|
function createSimInvokeHandler(options) {
|
|
2668
2680
|
return async (method, args) => {
|
|
2669
2681
|
if (method !== "invoke") {
|
|
@@ -3956,6 +3968,27 @@ if (workerPort !== null && workerData !== void 0) {
|
|
|
3956
3968
|
// packages/cli/src/dev-shared.ts
|
|
3957
3969
|
import { readdir as readdir2, readFile as readFile5 } from "node:fs/promises";
|
|
3958
3970
|
import { join as join8 } from "node:path";
|
|
3971
|
+
|
|
3972
|
+
// packages/runtime/src/shared/function-source.ts
|
|
3973
|
+
var SHARED_SOURCE_ROOT = "functions/_shared/";
|
|
3974
|
+
var FUNCTION_SHARED_DIR = "_shared/";
|
|
3975
|
+
function mergeSharedSource(files, shared) {
|
|
3976
|
+
const merged = { ...files };
|
|
3977
|
+
for (const file of shared) {
|
|
3978
|
+
if (!file.path.startsWith(SHARED_SOURCE_ROOT)) continue;
|
|
3979
|
+
const rel = file.path.slice(SHARED_SOURCE_ROOT.length);
|
|
3980
|
+
if (rel === "") continue;
|
|
3981
|
+
merged[`${FUNCTION_SHARED_DIR}${rel}`] = file.content;
|
|
3982
|
+
}
|
|
3983
|
+
return merged;
|
|
3984
|
+
}
|
|
3985
|
+
|
|
3986
|
+
// shared/shared-source.ts
|
|
3987
|
+
var FUNCTION_SHARED_DIR2 = "_shared";
|
|
3988
|
+
var SHARED_SOURCE_ROOT2 = `functions/${FUNCTION_SHARED_DIR2}/`;
|
|
3989
|
+
var FUNCTION_SHARED_MAX_TOTAL_BYTES = 256 * 1024;
|
|
3990
|
+
|
|
3991
|
+
// packages/cli/src/dev-shared.ts
|
|
3959
3992
|
var BEARER_TOKEN_RE = /^Bearer\s+(.+)$/i;
|
|
3960
3993
|
function bearerUserResolverFromEnv() {
|
|
3961
3994
|
const raw = process.env.ADEP_AUTH_ISSUER;
|
|
@@ -3983,9 +4016,11 @@ function createBearerUserResolver(issuer) {
|
|
|
3983
4016
|
}
|
|
3984
4017
|
};
|
|
3985
4018
|
}
|
|
4019
|
+
function isRuntimeSource(name) {
|
|
4020
|
+
return (name.endsWith(".ts") || name.endsWith(".js")) && !name.endsWith(".d.ts") && !name.endsWith(".test.ts");
|
|
4021
|
+
}
|
|
3986
4022
|
async function collectFunctions(dir) {
|
|
3987
4023
|
const files = {};
|
|
3988
|
-
const isRuntimeSource = (name) => (name.endsWith(".ts") || name.endsWith(".js")) && !name.endsWith(".d.ts") && !name.endsWith(".test.ts");
|
|
3989
4024
|
const walk = async (sub, prefix) => {
|
|
3990
4025
|
let entries;
|
|
3991
4026
|
try {
|
|
@@ -4006,6 +4041,24 @@ async function collectFunctions(dir) {
|
|
|
4006
4041
|
await walk(dir, "");
|
|
4007
4042
|
return files;
|
|
4008
4043
|
}
|
|
4044
|
+
function mergeSharedIntoFunctions(files) {
|
|
4045
|
+
const shared = [];
|
|
4046
|
+
for (const [path, content] of Object.entries(files)) {
|
|
4047
|
+
if (!path.startsWith(`${FUNCTION_SHARED_DIR2}/`)) continue;
|
|
4048
|
+
shared.push({
|
|
4049
|
+
path: `${SHARED_SOURCE_ROOT2}${path.slice(FUNCTION_SHARED_DIR2.length + 1)}`,
|
|
4050
|
+
content
|
|
4051
|
+
});
|
|
4052
|
+
}
|
|
4053
|
+
if (shared.length === 0) return files;
|
|
4054
|
+
const inFunction = mergeSharedSource({}, shared);
|
|
4055
|
+
const out = { ...files };
|
|
4056
|
+
for (const name of listFunctionNames(files)) {
|
|
4057
|
+
if (name.startsWith("_") || files[`${name}/index.ts`] === void 0) continue;
|
|
4058
|
+
for (const [rel, content] of Object.entries(inFunction)) out[`${name}/${rel}`] = content;
|
|
4059
|
+
}
|
|
4060
|
+
return out;
|
|
4061
|
+
}
|
|
4009
4062
|
function bodyOf(req) {
|
|
4010
4063
|
return new Promise((resolveBody, rejectBody) => {
|
|
4011
4064
|
const chunks = [];
|
|
@@ -4123,7 +4176,7 @@ async function startDevServer(options) {
|
|
|
4123
4176
|
log
|
|
4124
4177
|
});
|
|
4125
4178
|
await ensureGitignore(cwd);
|
|
4126
|
-
let files = await collectFunctions(functionsDir);
|
|
4179
|
+
let files = mergeSharedIntoFunctions(await collectFunctions(functionsDir));
|
|
4127
4180
|
let env = {
|
|
4128
4181
|
...config.environment,
|
|
4129
4182
|
...await loadSimEnv(cwd).catch(() => ({}))
|
|
@@ -4201,7 +4254,7 @@ async function startDevServer(options) {
|
|
|
4201
4254
|
};
|
|
4202
4255
|
const reload = async () => {
|
|
4203
4256
|
const [nextFiles, envText2] = await Promise.all([
|
|
4204
|
-
collectFunctions(functionsDir),
|
|
4257
|
+
collectFunctions(functionsDir).then(mergeSharedIntoFunctions),
|
|
4205
4258
|
readFile6(join9(cwd, ".env.local"), "utf8").catch(() => "")
|
|
4206
4259
|
]);
|
|
4207
4260
|
files = nextFiles;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adep/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "`adep` 命令行工具包位:登录 / 初始化 / 本地调试 / 部署 / 数据库维护 / 云存储 / 静态托管 / 微前端组件(widget),实现见任务单 CLI-001 ~ CLI-003 与 FE-002;子路径 `@adep/cli/vite` 提供云函数 vite 插件(CLI-014)",
|
|
6
6
|
"bin": {
|
|
@@ -21,15 +21,16 @@
|
|
|
21
21
|
"commander": "14.0.2",
|
|
22
22
|
"esbuild": "0.25.12",
|
|
23
23
|
"@adep/cf-compat": "0.1.1",
|
|
24
|
-
"@adep/vite-plugin": "0.1.
|
|
24
|
+
"@adep/vite-plugin": "0.1.5"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@adep/runtime": "0.2.
|
|
27
|
+
"@adep/runtime": "0.2.5",
|
|
28
28
|
"@adep/types": "0.2.3"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"test": "vitest run",
|
|
32
32
|
"init": "bun run src/index.ts init --template fullstack example1",
|
|
33
|
+
"gen:templates": "bun run scripts/build-templates.mjs",
|
|
33
34
|
"build": "bun run ../../scripts/build-package.ts cli"
|
|
34
35
|
}
|
|
35
36
|
}
|