@ubean/cli 0.4.6 → 0.4.8

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.
Files changed (2) hide show
  1. package/dist/cli.js +43 -2
  2. package/package.json +12 -12
package/dist/cli.js CHANGED
@@ -5,7 +5,7 @@ import { extname, normalize, sep } from "node:path";
5
5
  import { getLogger, setDebugLogging } from "@ubean/shared/logger";
6
6
  import { defineCommand, runMain } from "citty";
7
7
  import { BUILTIN_MODULES, isBuiltinDisabled, loadUbeanConfig, resolveModules, resolvePrerenderConfig, resolveSsrConfig } from "@ubean/config";
8
- import { readFile, rm, stat } from "node:fs/promises";
8
+ import { mkdir, readFile, rm, stat, writeFile } from "node:fs/promises";
9
9
  import { pathToFileURL } from "node:url";
10
10
  import { generateOpenApiTypesFromServer, generateTypes } from "@ubean/build/codegen";
11
11
  import { prerender } from "@ubean/build/prerender";
@@ -430,6 +430,33 @@ const buildCommand = {
430
430
  notFoundRoute,
431
431
  expandRoutes
432
432
  });
433
+ if (contentSnapshot) try {
434
+ const contentMod = await import("@ubean/content");
435
+ const searchConfig = contentMod.resolveContentSearchConfig(config.content, { ssg: config.mode === "ssg" });
436
+ const staticDir = resolve(cwd, resolvePrerenderConfig(config.prerender).staticDir);
437
+ if (searchConfig.sections) {
438
+ const payload = contentMod.generateSearchSectionsSnapshot(contentSnapshot);
439
+ await mkdir(staticDir, { recursive: true });
440
+ await writeFile(join(staticDir, "__search.json"), JSON.stringify(payload), "utf-8");
441
+ const sectionCount = Object.values(payload).reduce((sum, sections) => sum + sections.length, 0);
442
+ logger$9.info(`Search: wrote __search.json (${sectionCount} sections)`);
443
+ }
444
+ if (searchConfig.pagefind) {
445
+ const res = await contentMod.runPagefindIndex({
446
+ siteDir: staticDir,
447
+ createIndexOptions: searchConfig.pagefindOptions,
448
+ logger: {
449
+ info: (msg) => logger$9.info(msg),
450
+ warn: (msg) => logger$9.warn(msg)
451
+ }
452
+ });
453
+ if (res.indexed) logger$9.info("Search: pagefind index generated");
454
+ else if (res.reason === "pagefind-not-installed") logger$9.info("Search: pagefind is not installed — skipping index. Run `pnpm add -D pagefind` to enable.");
455
+ else logger$9.warn(`Search: pagefind indexing failed — ${res.error ?? res.reason}`);
456
+ }
457
+ } catch (err) {
458
+ logger$9.warn(`Search index generation skipped: ${err instanceof Error ? err.message : String(err)}`);
459
+ }
433
460
  }
434
461
  if (config.mode === "ssg" && !process.env.UBEAN_KEEP_SSR) {
435
462
  const serverDir = join(cwd, config.build.outputDir, "server");
@@ -1092,6 +1119,20 @@ import("@ubean/devtools").then((mod) => {
1092
1119
  function getCustomTabs() {
1093
1120
  return _customTabsGetter();
1094
1121
  }
1122
+ /**
1123
+ * dev 环境 SecurityHeaders 解析(ADR-0011)。
1124
+ *
1125
+ * ssg 模式默认关闭:静态产物不携带框架注入的安全头(响应头由托管平台
1126
+ * 控制),dev 默认关闭以对齐生产行为,消除「dev 有 CSP / 线上没有」的
1127
+ * 偏差。显式配置(`headers: true` 或对象)仍会被尊重,作为 CSP 调试
1128
+ * 入口。其余模式默认开启不变。
1129
+ */
1130
+ function resolveDevSecurityHeaders(config) {
1131
+ if (config.security === false) return false;
1132
+ if (config.security?.headers === false) return false;
1133
+ if (config.security?.headers !== void 0) return config.security.headers;
1134
+ return config.mode !== "ssg";
1135
+ }
1095
1136
  const devCommand = {
1096
1137
  meta: {
1097
1138
  name: "dev",
@@ -1285,7 +1326,7 @@ async function buildApp(cwd, config) {
1285
1326
  streaming: config.ssr.streaming,
1286
1327
  notFoundPage: result.notFoundPage,
1287
1328
  csrf: config.security === false ? false : config.security?.csrf ?? true,
1288
- securityHeaders: config.security === false ? false : config.security?.headers === false ? false : config.security?.headers ?? true,
1329
+ securityHeaders: resolveDevSecurityHeaders(config),
1289
1330
  dataCache: config.dataCache,
1290
1331
  cache: config.cache,
1291
1332
  seoConventions: { srcDir: resolve(cwd, config.srcDir) }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubean/cli",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "description": "CLI for ubean (ubean-next binary: dev, build, prepare, init, preview, page, env, config, devtools, api/layout/middleware/cron/plugin scaffolds) plus the Vite dev server runner",
5
5
  "bin": {
6
6
  "ubean-next": "./bin/ubean-next.mjs"
@@ -24,15 +24,15 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "@ubean/app": "0.4.6",
28
- "@ubean/build": "0.4.6",
29
- "@ubean/client": "0.4.6",
30
- "@ubean/config": "0.4.6",
31
- "@ubean/i18n": "0.4.6",
32
- "@ubean/islands": "0.4.6",
33
- "@ubean/preset": "0.4.6",
34
- "@ubean/scan": "0.4.6",
35
- "@ubean/shared": "0.4.6",
27
+ "@ubean/app": "0.4.8",
28
+ "@ubean/build": "0.4.8",
29
+ "@ubean/client": "0.4.8",
30
+ "@ubean/config": "0.4.8",
31
+ "@ubean/i18n": "0.4.8",
32
+ "@ubean/islands": "0.4.8",
33
+ "@ubean/preset": "0.4.8",
34
+ "@ubean/scan": "0.4.8",
35
+ "@ubean/shared": "0.4.8",
36
36
  "citty": "^0.2.2",
37
37
  "kolorist": "^1.8.0",
38
38
  "pathe": "^2.0.3"
@@ -45,8 +45,8 @@
45
45
  "vite-plus": "0.3.1"
46
46
  },
47
47
  "peerDependencies": {
48
- "@ubean/content": "0.4.6",
49
- "@ubean/devtools": "0.4.6",
48
+ "@ubean/content": "0.4.8",
49
+ "@ubean/devtools": "0.4.8",
50
50
  "@vitejs/plugin-vue": "^6.0.8",
51
51
  "vite": "npm:@voidzero-dev/vite-plus-core@0.3.1"
52
52
  },