everything-dev 1.26.1 → 1.27.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.
Files changed (112) hide show
  1. package/dist/api-contract.cjs.map +1 -1
  2. package/dist/api-contract.mjs.map +1 -1
  3. package/dist/cli/catalog.cjs.map +1 -1
  4. package/dist/cli/catalog.mjs.map +1 -1
  5. package/dist/cli/framework-version.cjs.map +1 -1
  6. package/dist/cli/framework-version.mjs.map +1 -1
  7. package/dist/cli/infra.cjs.map +1 -1
  8. package/dist/cli/infra.mjs.map +1 -1
  9. package/dist/cli/init.cjs +121 -113
  10. package/dist/cli/init.cjs.map +1 -1
  11. package/dist/cli/init.d.cts +6 -6
  12. package/dist/cli/init.d.cts.map +1 -1
  13. package/dist/cli/init.d.mts +6 -6
  14. package/dist/cli/init.d.mts.map +1 -1
  15. package/dist/cli/init.mjs +119 -113
  16. package/dist/cli/init.mjs.map +1 -1
  17. package/dist/cli/parse.cjs.map +1 -1
  18. package/dist/cli/parse.mjs.map +1 -1
  19. package/dist/cli/prompts.cjs +1 -1
  20. package/dist/cli/prompts.cjs.map +1 -1
  21. package/dist/cli/prompts.mjs +1 -1
  22. package/dist/cli/prompts.mjs.map +1 -1
  23. package/dist/cli/status.cjs.map +1 -1
  24. package/dist/cli/status.mjs.map +1 -1
  25. package/dist/cli/sync.cjs +42 -92
  26. package/dist/cli/sync.cjs.map +1 -1
  27. package/dist/cli/sync.mjs +45 -95
  28. package/dist/cli/sync.mjs.map +1 -1
  29. package/dist/cli/timing.cjs.map +1 -1
  30. package/dist/cli/timing.mjs.map +1 -1
  31. package/dist/cli/upgrade.cjs +41 -20
  32. package/dist/cli/upgrade.cjs.map +1 -1
  33. package/dist/cli/upgrade.mjs +43 -22
  34. package/dist/cli/upgrade.mjs.map +1 -1
  35. package/dist/cli.cjs +1 -1
  36. package/dist/cli.cjs.map +1 -1
  37. package/dist/cli.mjs +1 -1
  38. package/dist/cli.mjs.map +1 -1
  39. package/dist/components/dev-view.cjs.map +1 -1
  40. package/dist/components/dev-view.mjs.map +1 -1
  41. package/dist/components/streaming-view.cjs.map +1 -1
  42. package/dist/components/streaming-view.mjs.map +1 -1
  43. package/dist/config.cjs.map +1 -1
  44. package/dist/config.mjs.map +1 -1
  45. package/dist/contract.cjs +174 -173
  46. package/dist/contract.cjs.map +1 -1
  47. package/dist/contract.d.cts +10 -10
  48. package/dist/contract.d.cts.map +1 -1
  49. package/dist/contract.d.mts +10 -10
  50. package/dist/contract.d.mts.map +1 -1
  51. package/dist/contract.mjs +2 -1
  52. package/dist/contract.mjs.map +1 -1
  53. package/dist/dev-logs.cjs.map +1 -1
  54. package/dist/dev-logs.mjs.map +1 -1
  55. package/dist/fastkv.cjs.map +1 -1
  56. package/dist/fastkv.mjs.map +1 -1
  57. package/dist/index.cjs +3 -3
  58. package/dist/index.d.cts +1 -1
  59. package/dist/index.d.mts +1 -1
  60. package/dist/index.mjs +1 -1
  61. package/dist/integrity.cjs.map +1 -1
  62. package/dist/integrity.mjs.map +1 -1
  63. package/dist/internal/manifest-normalizer.cjs.map +1 -1
  64. package/dist/internal/manifest-normalizer.mjs.map +1 -1
  65. package/dist/merge.cjs.map +1 -1
  66. package/dist/merge.mjs.map +1 -1
  67. package/dist/near-cli.cjs.map +1 -1
  68. package/dist/near-cli.mjs.map +1 -1
  69. package/dist/orchestrator.cjs.map +1 -1
  70. package/dist/orchestrator.mjs.map +1 -1
  71. package/dist/plugin.cjs +20 -33
  72. package/dist/plugin.cjs.map +1 -1
  73. package/dist/plugin.d.cts +5 -5
  74. package/dist/plugin.d.mts +5 -5
  75. package/dist/plugin.mjs +18 -31
  76. package/dist/plugin.mjs.map +1 -1
  77. package/dist/sdk.cjs +2 -2
  78. package/dist/sdk.d.cts +1 -1
  79. package/dist/sdk.d.mts +1 -1
  80. package/dist/sdk.mjs +1 -1
  81. package/dist/shared.cjs.map +1 -1
  82. package/dist/shared.mjs.map +1 -1
  83. package/dist/types.cjs +184 -184
  84. package/dist/types.cjs.map +1 -1
  85. package/dist/types.d.cts +3 -3
  86. package/dist/types.d.mts +3 -3
  87. package/dist/types.mjs +1 -1
  88. package/dist/types.mjs.map +1 -1
  89. package/dist/ui/types.d.cts +1 -0
  90. package/dist/ui/types.d.cts.map +1 -1
  91. package/dist/ui/types.d.mts +1 -0
  92. package/dist/ui/types.d.mts.map +1 -1
  93. package/dist/utils/banner.cjs.map +1 -1
  94. package/dist/utils/banner.mjs.map +1 -1
  95. package/dist/utils/run.cjs.map +1 -1
  96. package/dist/utils/run.mjs.map +1 -1
  97. package/package.json +2 -2
  98. package/skills/init-upgrade/SKILL.md +22 -16
  99. package/skills/publish-sync/SKILL.md +7 -18
  100. package/src/cli/init.ts +137 -194
  101. package/src/cli/prompts.ts +1 -1
  102. package/src/cli/sync.ts +48 -137
  103. package/src/cli/upgrade.ts +66 -25
  104. package/src/contract.ts +2 -1
  105. package/src/plugin.ts +12 -34
  106. package/src/sdk.ts +1 -1
  107. package/src/types.ts +1 -1
  108. package/src/ui/types.ts +1 -0
  109. package/dist/utils/path-match.cjs +0 -18
  110. package/dist/utils/path-match.cjs.map +0 -1
  111. package/dist/utils/path-match.mjs +0 -17
  112. package/dist/utils/path-match.mjs.map +0 -1
package/dist/cli/sync.cjs CHANGED
@@ -2,30 +2,35 @@ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
2
  const require_merge = require('../merge.cjs');
3
3
  const require_config = require('../config.cjs');
4
4
  const require_infra = require('./infra.cjs');
5
- const require_path_match = require('../utils/path-match.cjs');
6
5
  const require_snapshot = require('./snapshot.cjs');
7
6
  const require_cli_init = require('./init.cjs');
8
7
  let node_fs = require("node:fs");
9
8
  let node_path = require("node:path");
10
9
  let node_crypto = require("node:crypto");
11
- let glob = require("glob");
12
10
 
13
11
  //#region src/cli/sync.ts
14
12
  const FRAMEWORK_OWNED_SYNC_FILES = new Set([
15
13
  ".env.example",
16
14
  ".gitignore",
15
+ "AGENTS.md",
17
16
  "biome.json",
18
17
  "bos.config.json",
18
+ "bunfig.toml",
19
+ "CONTRIBUTING.md",
19
20
  "package.json",
21
+ ".changeset/config.json",
22
+ ".changeset/README.md",
20
23
  "docker-compose.yml",
21
24
  ".github/renovate.json",
22
25
  ".github/workflows/ci.yml",
23
26
  ".github/workflows/release-sync.yml",
27
+ ".opencode/skills/everything-dev/SKILL.md",
24
28
  "ui/package.json",
25
29
  "ui/postcss.config.mjs",
26
30
  "ui/rsbuild.config.ts",
27
31
  "ui/tsconfig.json",
28
32
  "ui/src/app.ts",
33
+ "ui/src/globals.d.ts",
29
34
  "ui/src/hydrate.tsx",
30
35
  "ui/src/lib/api.ts",
31
36
  "ui/src/lib/auth.ts",
@@ -39,19 +44,6 @@ const FRAMEWORK_OWNED_SYNC_FILES = new Set([
39
44
  "api/tsconfig.json",
40
45
  "api/src/lib/auth.ts"
41
46
  ]);
42
- function isFrameworkOwnedSyncFile(filePath) {
43
- return FRAMEWORK_OWNED_SYNC_FILES.has(filePath);
44
- }
45
- function readExcludeFile(filePath) {
46
- if (!(0, node_fs.existsSync)(filePath)) return [];
47
- return (0, node_fs.readFileSync)(filePath, "utf-8").split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
48
- }
49
- async function readTemplatesyncExclude(sourceDir) {
50
- return readExcludeFile((0, node_path.join)(sourceDir, ".templatesync-exclude"));
51
- }
52
- function readLocalSyncExcludes(projectDir) {
53
- return readExcludeFile((0, node_path.join)(projectDir, ".bos", "sync-local-exclude"));
54
- }
55
47
  function computeLocalHash(projectDir, filePath) {
56
48
  const fullPath = (0, node_path.join)(projectDir, filePath);
57
49
  if (!(0, node_fs.existsSync)(fullPath)) return null;
@@ -137,7 +129,15 @@ function mergePackageJson(filePath, local, template) {
137
129
  return merged;
138
130
  }
139
131
  function toDestPath(filePath) {
140
- return filePath.startsWith(".github/templates/") ? filePath.replace(/^\.github\/templates\//, ".github/") : filePath;
132
+ return require_cli_init.sourcePathToDestinationPath(filePath);
133
+ }
134
+ function toSourcePath(sourceDir, destPath) {
135
+ if ((0, node_fs.existsSync)((0, node_path.join)(sourceDir, destPath))) return destPath;
136
+ if (destPath.startsWith(".github/")) {
137
+ const templatePath = destPath.replace(/^\.github\//, ".github/templates/");
138
+ if ((0, node_fs.existsSync)((0, node_path.join)(sourceDir, templatePath))) return templatePath;
139
+ }
140
+ return null;
141
141
  }
142
142
  function writeSyncedFile(sourceDir, projectDir, filePath) {
143
143
  const src = (0, node_path.join)(sourceDir, filePath);
@@ -191,60 +191,25 @@ async function syncTemplate(projectDir, options) {
191
191
  extendsGateway
192
192
  });
193
193
  try {
194
- const patterns = await require_cli_init.readTemplatekeep(sourceDir);
195
- if (patterns.length === 0) return {
196
- status: "error",
197
- updated: [],
198
- skipped: [],
199
- added: [],
200
- error: "No .templatekeep found in template source"
201
- };
202
- const parentExcludes = await readTemplatesyncExclude(sourceDir);
203
- const localExcludes = readLocalSyncExcludes(projectDir);
204
- const excludePatterns = [...parentExcludes, ...localExcludes];
205
- const allTemplateFiles = /* @__PURE__ */ new Set();
206
- for (const pattern of patterns) {
207
- const matches = await (0, glob.glob)(pattern, {
208
- cwd: sourceDir,
209
- nodir: true,
210
- dot: true,
211
- absolute: false
212
- });
213
- for (const match of matches) allTemplateFiles.add(match);
214
- }
215
194
  const childPlugins = localConfig.plugins && typeof localConfig.plugins === "object" ? Object.keys(localConfig.plugins) : [];
216
- const pluginRoutes = {};
217
- const parentRuntime = await require_config.loadConfig({ cwd: sourceDir });
218
- for (const [key, plugin] of Object.entries(parentRuntime?.runtime.plugins ?? {})) if (plugin.routes && plugin.routes.length > 0) pluginRoutes[key] = plugin.routes;
219
- const excludedRoutePatterns = [];
220
- for (const [pluginKey, routePatterns] of Object.entries(pluginRoutes)) if (!childPlugins.includes(pluginKey)) excludedRoutePatterns.push(...routePatterns);
195
+ const withUi = (0, node_fs.existsSync)((0, node_path.join)(projectDir, "ui", "package.json"));
196
+ const withApi = (0, node_fs.existsSync)((0, node_path.join)(projectDir, "api", "package.json"));
197
+ const withHost = (0, node_fs.existsSync)((0, node_path.join)(projectDir, "host", "package.json"));
221
198
  const filteredFiles = /* @__PURE__ */ new Set();
222
- for (const filePath of allTemplateFiles) {
223
- const pluginMatch = filePath.match(/^plugins\/([^/]+)/);
224
- if (pluginMatch && !childPlugins.includes(pluginMatch[1])) continue;
225
- if (require_path_match.isPathExcluded(filePath, excludedRoutePatterns)) continue;
226
- filteredFiles.add(filePath);
227
- }
228
- for (const [pluginKey, routePatterns] of Object.entries(pluginRoutes)) {
229
- if (!childPlugins.includes(pluginKey)) continue;
230
- for (const rp of routePatterns) {
231
- const matches = await (0, glob.glob)(rp, {
232
- cwd: sourceDir,
233
- nodir: true,
234
- dot: true,
235
- absolute: false
236
- });
237
- for (const match of matches) if (!require_path_match.isPathExcluded(match, excludedRoutePatterns)) filteredFiles.add(match);
238
- }
199
+ const destToSource = /* @__PURE__ */ new Map();
200
+ for (const destPath of FRAMEWORK_OWNED_SYNC_FILES) {
201
+ if (destPath.startsWith("ui/") && !withUi) continue;
202
+ if (destPath.startsWith("api/") && !withApi) continue;
203
+ if (destPath.startsWith("host/") && !withHost) continue;
204
+ const sourcePath = toSourcePath(sourceDir, destPath);
205
+ if (!sourcePath) continue;
206
+ filteredFiles.add(sourcePath);
207
+ destToSource.set(destPath, sourcePath);
239
208
  }
240
- const snapshot = await require_snapshot.readSnapshot(projectDir);
241
209
  const updated = [];
242
210
  const skipped = [];
243
211
  const added = [];
244
- for (const filePath of filteredFiles) {
245
- const destPath = toDestPath(filePath);
246
- const frameworkOwned = isFrameworkOwnedSyncFile(destPath);
247
- if (require_path_match.isPathExcluded(destPath, excludePatterns) && !frameworkOwned) continue;
212
+ for (const [destPath, filePath] of destToSource.entries()) {
248
213
  const localHash = computeLocalHash(projectDir, destPath);
249
214
  const sourceContent = (0, node_fs.readFileSync)((0, node_path.join)(sourceDir, filePath));
250
215
  const sourceHash = (0, node_crypto.createHash)("sha256").update(sourceContent).digest("hex").substring(0, 16);
@@ -252,19 +217,7 @@ async function syncTemplate(projectDir, options) {
252
217
  added.push(destPath);
253
218
  continue;
254
219
  }
255
- if (localHash === sourceHash) continue;
256
- if (frameworkOwned) {
257
- updated.push(destPath);
258
- continue;
259
- }
260
- const snapshotHash = snapshot?.files[destPath];
261
- if (snapshotHash === void 0) {
262
- updated.push(destPath);
263
- continue;
264
- }
265
- if (localHash === snapshotHash) updated.push(destPath);
266
- else if (options.force) updated.push(destPath);
267
- else skipped.push(destPath);
220
+ if (localHash !== sourceHash) updated.push(destPath);
268
221
  }
269
222
  if (options.dryRun) return {
270
223
  status: "dry-run",
@@ -272,37 +225,34 @@ async function syncTemplate(projectDir, options) {
272
225
  skipped,
273
226
  added
274
227
  };
275
- const filesToWrite = [...updated, ...added].filter((f) => isFrameworkOwnedSyncFile(f) || !require_path_match.isPathExcluded(f, excludePatterns));
276
- const destToSource = /* @__PURE__ */ new Map();
277
- for (const filePath of filteredFiles) destToSource.set(toDestPath(filePath), filePath);
228
+ const filesToWrite = [...updated, ...added];
278
229
  if (filesToWrite.length > 0) {
279
230
  backupFiles(projectDir, filesToWrite);
280
231
  for (const destPath of filesToWrite) writeSyncedFile(sourceDir, projectDir, destToSource.get(destPath) ?? destPath);
281
232
  }
282
233
  const newSnapshotFiles = {};
283
234
  for (const filePath of filteredFiles) {
284
- const src = (0, node_path.join)(sourceDir, filePath);
285
- if (!(0, node_fs.lstatSync)(src).isFile()) continue;
286
- const content = (0, node_fs.readFileSync)(src);
235
+ const content = (0, node_fs.readFileSync)((0, node_path.join)(sourceDir, filePath));
287
236
  newSnapshotFiles[toDestPath(filePath)] = (0, node_crypto.createHash)("sha256").update(content).digest("hex").substring(0, 16);
288
237
  }
289
238
  await require_snapshot.writeSnapshot(projectDir, {
290
239
  parentRef: `bos://${extendsAccount}/${extendsGateway}`,
291
240
  files: newSnapshotFiles
292
241
  });
242
+ const account = localConfig.account || extendsAccount;
243
+ const domain = localConfig.domain || extendsGateway;
244
+ const overrides = [];
245
+ if (withUi) overrides.push("ui");
246
+ if (withApi) overrides.push("api");
247
+ if (withHost) overrides.push("host");
248
+ if (childPlugins.length > 0) overrides.push("plugins");
293
249
  await require_cli_init.personalizeConfig(projectDir, {
294
250
  extendsAccount,
295
251
  extendsGateway,
296
- account: localConfig.account || extendsAccount,
297
- domain: localConfig.domain || extendsGateway,
252
+ account,
253
+ domain,
254
+ overrides,
298
255
  plugins: childPlugins,
299
- pluginRoutes,
300
- overrides: [
301
- "ui",
302
- "api",
303
- "host",
304
- "plugins"
305
- ],
306
256
  workspaceOpts: { sourceDir },
307
257
  mode: "sync"
308
258
  });
@@ -1 +1 @@
1
- {"version":3,"file":"sync.cjs","names":["mergeBosConfigWithTemplate","isPlainObjectFromMerge","resolveExtendsRef","resolveSourceDir","readTemplatekeep","loadConfig","isPathExcluded","readSnapshot","writeSnapshot","personalizeConfig","runBunInstall","runTypesGen"],"sources":["../../src/cli/sync.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport {\n copyFileSync,\n existsSync,\n lstatSync,\n mkdirSync,\n readFileSync,\n writeFileSync,\n} from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { glob } from \"glob\";\nimport { loadConfig } from \"../config\";\nimport type { SyncOptions, SyncResult } from \"../contract\";\nimport {\n isPlainObject as isPlainObjectFromMerge,\n mergeBosConfigWithTemplate,\n resolveExtendsRef,\n} from \"../merge\";\nimport { isPathExcluded } from \"../utils/path-match\";\nimport { writeGeneratedInfra } from \"./infra\";\nimport {\n personalizeConfig,\n readTemplatekeep,\n resolveSourceDir,\n runBunInstall,\n runTypesGen,\n} from \"./init\";\nimport { readSnapshot, writeSnapshot } from \"./snapshot\";\n\nconst FRAMEWORK_OWNED_SYNC_FILES = new Set([\n \".env.example\",\n \".gitignore\",\n \"biome.json\",\n \"bos.config.json\",\n \"package.json\",\n \"docker-compose.yml\",\n \".github/renovate.json\",\n \".github/workflows/ci.yml\",\n \".github/workflows/release-sync.yml\",\n \"ui/package.json\",\n \"ui/postcss.config.mjs\",\n \"ui/rsbuild.config.ts\",\n \"ui/tsconfig.json\",\n \"ui/src/app.ts\",\n \"ui/src/hydrate.tsx\",\n \"ui/src/lib/api.ts\",\n \"ui/src/lib/auth.ts\",\n \"ui/src/router.server.tsx\",\n \"ui/src/router.tsx\",\n \"ui/src/routes/__root.tsx\",\n \"api/package.json\",\n \"api/plugin.dev.ts\",\n \"api/rspack.config.js\",\n \"api/tsconfig.contract.json\",\n \"api/tsconfig.json\",\n \"api/src/lib/auth.ts\",\n]);\n\ntype PackageJson = Record<string, unknown>;\n\nexport function isFrameworkOwnedSyncFile(filePath: string): boolean {\n return FRAMEWORK_OWNED_SYNC_FILES.has(filePath);\n}\n\nfunction readExcludeFile(filePath: string): string[] {\n if (!existsSync(filePath)) return [];\n const content = readFileSync(filePath, \"utf-8\");\n return content\n .split(\"\\n\")\n .map((line) => line.trim())\n .filter((line) => line.length > 0 && !line.startsWith(\"#\"));\n}\n\nexport async function readTemplatesyncExclude(sourceDir: string): Promise<string[]> {\n return readExcludeFile(join(sourceDir, \".templatesync-exclude\"));\n}\n\nexport function readLocalSyncExcludes(projectDir: string): string[] {\n return readExcludeFile(join(projectDir, \".bos\", \"sync-local-exclude\"));\n}\n\nfunction computeLocalHash(projectDir: string, filePath: string): string | null {\n const fullPath = join(projectDir, filePath);\n if (!existsSync(fullPath)) return null;\n try {\n const content = readFileSync(fullPath);\n return createHash(\"sha256\").update(content).digest(\"hex\").substring(0, 16);\n } catch {\n return null;\n }\n}\n\nfunction backupFiles(projectDir: string, filePaths: string[]): string | null {\n const filesToBackup = filePaths.filter((f) => existsSync(join(projectDir, f)));\n if (filesToBackup.length === 0) return null;\n\n const timestamp = new Date().toISOString().replace(/[:.]/g, \"-\");\n const backupDir = join(projectDir, \".bos\", \"sync-backup\", timestamp);\n\n for (const filePath of filesToBackup) {\n const src = join(projectDir, filePath);\n const dest = join(backupDir, filePath);\n mkdirSync(dirname(dest), { recursive: true });\n copyFileSync(src, dest);\n }\n\n return backupDir;\n}\n\nfunction mergeStringMaps(\n local: Record<string, string> | undefined,\n template: Record<string, string> | undefined,\n): Record<string, string> | undefined {\n if (!local && !template) return undefined;\n\n const merged: Record<string, string> = { ...(local ?? {}) };\n for (const [name, value] of Object.entries(template ?? {})) {\n merged[name] = value;\n }\n\n return Object.keys(merged).length > 0 ? merged : undefined;\n}\n\nfunction mergeWorkspacePackages(local: unknown, template: unknown): string[] | undefined {\n const localPackages = Array.isArray(local) ? local : [];\n const templatePackages = Array.isArray(template) ? template : [];\n if (localPackages.length === 0 && templatePackages.length === 0) return undefined;\n\n const ordered = new Set<string>();\n for (const entry of templatePackages) {\n if (typeof entry === \"string\" && entry.length > 0) ordered.add(entry);\n }\n for (const entry of localPackages) {\n if (typeof entry === \"string\" && entry.length > 0) ordered.add(entry);\n }\n\n return ordered.size > 0 ? [...ordered] : undefined;\n}\n\nexport function mergePackageJson(\n filePath: string,\n local: PackageJson,\n template: PackageJson,\n): PackageJson {\n const merged: PackageJson = { ...local, ...template };\n\n if (filePath === \"package.json\") {\n for (const key of [\"name\", \"private\", \"version\"] as const) {\n if (key in local) {\n merged[key] = local[key];\n }\n }\n } else if (\"version\" in local) {\n merged.version = local.version;\n }\n\n for (const depField of [\n \"dependencies\",\n \"devDependencies\",\n \"peerDependencies\",\n \"overrides\",\n ] as const) {\n const localDeps = local[depField] as Record<string, string> | undefined;\n const templateDeps = template[depField] as Record<string, string> | undefined;\n\n const mergedDeps = mergeStringMaps(localDeps, templateDeps);\n if (mergedDeps) {\n merged[depField] = mergedDeps;\n } else {\n delete merged[depField];\n }\n }\n\n if (\n (local.scripts && typeof local.scripts === \"object\") ||\n (template.scripts && typeof template.scripts === \"object\")\n ) {\n const mergedScripts = mergeStringMaps(\n local.scripts as Record<string, string> | undefined,\n template.scripts as Record<string, string> | undefined,\n );\n if (mergedScripts) {\n merged.scripts = mergedScripts;\n } else {\n delete merged.scripts;\n }\n }\n\n if (\n (local.workspaces && typeof local.workspaces === \"object\") ||\n (template.workspaces && typeof template.workspaces === \"object\")\n ) {\n const localWorkspaces = (local.workspaces ?? {}) as {\n packages?: string[];\n catalog?: Record<string, string>;\n };\n const templateWorkspaces = (template.workspaces ?? {}) as {\n packages?: string[];\n catalog?: Record<string, string>;\n };\n\n const mergedWorkspaces: { packages?: string[]; catalog?: Record<string, string> } = {\n ...localWorkspaces,\n ...templateWorkspaces,\n };\n\n const mergedPackages = mergeWorkspacePackages(\n localWorkspaces.packages,\n templateWorkspaces.packages,\n );\n if (mergedPackages) {\n mergedWorkspaces.packages = mergedPackages;\n } else {\n delete mergedWorkspaces.packages;\n }\n\n const mergedCatalog = mergeStringMaps(localWorkspaces.catalog, templateWorkspaces.catalog);\n if (mergedCatalog) {\n mergedWorkspaces.catalog = mergedCatalog;\n } else {\n delete mergedWorkspaces.catalog;\n }\n\n if (Object.keys(mergedWorkspaces).length > 0) {\n merged.workspaces = mergedWorkspaces;\n } else {\n delete merged.workspaces;\n }\n }\n\n return merged;\n}\n\nfunction toDestPath(filePath: string): string {\n return filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n}\n\nfunction writeSyncedFile(sourceDir: string, projectDir: string, filePath: string): void {\n const src = join(sourceDir, filePath);\n const destPath = filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n const dest = join(projectDir, destPath);\n mkdirSync(dirname(dest), { recursive: true });\n\n if (filePath.endsWith(\"bos.config.json\")) {\n const localContent = existsSync(dest) ? readFileSync(dest, \"utf-8\") : null;\n const templateContent = readFileSync(src, \"utf-8\");\n\n if (localContent) {\n const local = JSON.parse(localContent) as Record<string, unknown>;\n const template = JSON.parse(templateContent) as Record<string, unknown>;\n const merged = mergeBosConfigWithTemplate(local, template);\n writeFileSync(dest, `${JSON.stringify(merged, null, 2)}\\n`);\n return;\n }\n }\n\n if (filePath.endsWith(\"package.json\")) {\n const localContent = existsSync(dest) ? readFileSync(dest, \"utf-8\") : null;\n const templateContent = readFileSync(src, \"utf-8\");\n\n if (localContent) {\n const local = JSON.parse(localContent) as Record<string, unknown>;\n const template = JSON.parse(templateContent) as Record<string, unknown>;\n const merged = mergePackageJson(destPath, local, template);\n writeFileSync(dest, `${JSON.stringify(merged, null, 2)}\\n`);\n return;\n }\n }\n\n writeFileSync(dest, readFileSync(src));\n}\n\nexport async function syncTemplate(projectDir: string, options: SyncOptions): Promise<SyncResult> {\n // Sync reads the raw bos.config.json (not the resolved config) because it needs\n // the user's explicit local settings: their extends ref, selected plugins, etc.\n // The resolved config is the merged result and would include inherited parent\n // values that the user didn't explicitly choose, which would break sync filtering.\n const localConfig = JSON.parse(\n readFileSync(join(projectDir, \"bos.config.json\"), \"utf-8\"),\n ) as Record<string, unknown>;\n\n let extendsRef: string | undefined;\n if (typeof localConfig.extends === \"string\") {\n extendsRef = localConfig.extends;\n } else if (isPlainObjectFromMerge(localConfig.extends)) {\n extendsRef = resolveExtendsRef(localConfig.extends as Record<string, string>, \"production\");\n }\n if (!extendsRef?.startsWith(\"bos://\")) {\n return {\n status: \"error\",\n updated: [],\n skipped: [],\n added: [],\n error: \"No extends field found in bos.config.json — cannot determine parent\",\n };\n }\n\n const extendsMatch = extendsRef.match(/^bos:\\/\\/([^/]+)\\/(.+)$/);\n if (!extendsMatch) {\n return {\n status: \"error\",\n updated: [],\n skipped: [],\n added: [],\n error: `Invalid extends reference: ${extendsRef}`,\n };\n }\n\n const extendsAccount = extendsMatch[1];\n const extendsGateway = extendsMatch[2];\n\n const { sourceDir, cleanup } = await resolveSourceDir({\n extendsAccount,\n extendsGateway,\n });\n\n try {\n const patterns = await readTemplatekeep(sourceDir);\n if (patterns.length === 0) {\n return {\n status: \"error\",\n updated: [],\n skipped: [],\n added: [],\n error: \"No .templatekeep found in template source\",\n };\n }\n\n const parentExcludes = await readTemplatesyncExclude(sourceDir);\n const localExcludes = readLocalSyncExcludes(projectDir);\n const excludePatterns = [...parentExcludes, ...localExcludes];\n\n const allTemplateFiles = new Set<string>();\n for (const pattern of patterns) {\n const matches = await glob(pattern, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n allTemplateFiles.add(match);\n }\n }\n\n const childPlugins =\n localConfig.plugins && typeof localConfig.plugins === \"object\"\n ? Object.keys(localConfig.plugins as Record<string, unknown>)\n : [];\n\n const pluginRoutes: Record<string, string[]> = {};\n const parentRuntime = await loadConfig({ cwd: sourceDir });\n for (const [key, plugin] of Object.entries(parentRuntime?.runtime.plugins ?? {})) {\n if (plugin.routes && plugin.routes.length > 0) {\n pluginRoutes[key] = plugin.routes;\n }\n }\n\n const excludedRoutePatterns: string[] = [];\n for (const [pluginKey, routePatterns] of Object.entries(pluginRoutes)) {\n if (!childPlugins.includes(pluginKey)) {\n excludedRoutePatterns.push(...routePatterns);\n }\n }\n\n const filteredFiles = new Set<string>();\n for (const filePath of allTemplateFiles) {\n const pluginMatch = filePath.match(/^plugins\\/([^/]+)/);\n if (pluginMatch && !childPlugins.includes(pluginMatch[1])) continue;\n if (isPathExcluded(filePath, excludedRoutePatterns)) continue;\n filteredFiles.add(filePath);\n }\n\n for (const [pluginKey, routePatterns] of Object.entries(pluginRoutes)) {\n if (!childPlugins.includes(pluginKey)) continue;\n for (const rp of routePatterns) {\n const matches = await glob(rp, {\n cwd: sourceDir,\n nodir: true,\n dot: true,\n absolute: false,\n });\n for (const match of matches) {\n if (!isPathExcluded(match, excludedRoutePatterns)) {\n filteredFiles.add(match);\n }\n }\n }\n }\n\n const snapshot = await readSnapshot(projectDir);\n\n const updated: string[] = [];\n const skipped: string[] = [];\n const added: string[] = [];\n\n for (const filePath of filteredFiles) {\n const destPath = toDestPath(filePath);\n const frameworkOwned = isFrameworkOwnedSyncFile(destPath);\n if (isPathExcluded(destPath, excludePatterns) && !frameworkOwned) continue;\n\n const localHash = computeLocalHash(projectDir, destPath);\n const sourceContent = readFileSync(join(sourceDir, filePath));\n const sourceHash = createHash(\"sha256\").update(sourceContent).digest(\"hex\").substring(0, 16);\n\n if (localHash === null) {\n added.push(destPath);\n continue;\n }\n\n if (localHash === sourceHash) continue;\n\n if (frameworkOwned) {\n updated.push(destPath);\n continue;\n }\n\n const snapshotHash = snapshot?.files[destPath];\n\n if (snapshotHash === undefined) {\n updated.push(destPath);\n continue;\n }\n\n if (localHash === snapshotHash) {\n updated.push(destPath);\n } else {\n if (options.force) {\n updated.push(destPath);\n } else {\n skipped.push(destPath);\n }\n }\n }\n\n if (options.dryRun) {\n return {\n status: \"dry-run\",\n updated,\n skipped,\n added,\n };\n }\n\n const filesToWrite = [...updated, ...added].filter(\n (f) => isFrameworkOwnedSyncFile(f) || !isPathExcluded(f, excludePatterns),\n );\n\n const destToSource = new Map<string, string>();\n for (const filePath of filteredFiles) {\n destToSource.set(toDestPath(filePath), filePath);\n }\n\n if (filesToWrite.length > 0) {\n backupFiles(projectDir, filesToWrite);\n\n for (const destPath of filesToWrite) {\n const sourcePath = destToSource.get(destPath) ?? destPath;\n writeSyncedFile(sourceDir, projectDir, sourcePath);\n }\n }\n\n const newSnapshotFiles: Record<string, string> = {};\n for (const filePath of filteredFiles) {\n const src = join(sourceDir, filePath);\n const stat = lstatSync(src);\n if (!stat.isFile()) continue;\n const content = readFileSync(src);\n newSnapshotFiles[toDestPath(filePath)] = createHash(\"sha256\")\n .update(content)\n .digest(\"hex\")\n .substring(0, 16);\n }\n\n await writeSnapshot(projectDir, {\n parentRef: `bos://${extendsAccount}/${extendsGateway}`,\n files: newSnapshotFiles,\n });\n\n const account = (localConfig.account as string) || extendsAccount;\n const domain = (localConfig.domain as string) || extendsGateway;\n\n await personalizeConfig(projectDir, {\n extendsAccount,\n extendsGateway,\n account,\n domain,\n plugins: childPlugins,\n pluginRoutes,\n overrides: [\"ui\", \"api\", \"host\", \"plugins\"],\n workspaceOpts: { sourceDir },\n mode: \"sync\",\n });\n\n const syncedConfig = await loadConfig({ cwd: projectDir });\n if (syncedConfig?.runtime) {\n writeGeneratedInfra(projectDir, syncedConfig.runtime);\n }\n\n if (!options.noInstall) {\n await runBunInstall(projectDir);\n await runTypesGen(projectDir);\n }\n\n return {\n status: \"synced\",\n updated,\n skipped,\n added,\n };\n } finally {\n await cleanup();\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA6BA,MAAM,6BAA6B,IAAI,IAAI;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAIF,SAAgB,yBAAyB,UAA2B;AAClE,QAAO,2BAA2B,IAAI,SAAS;;AAGjD,SAAS,gBAAgB,UAA4B;AACnD,KAAI,yBAAY,SAAS,CAAE,QAAO,EAAE;AAEpC,kCAD6B,UAAU,QAAQ,CAE5C,MAAM,KAAK,CACX,KAAK,SAAS,KAAK,MAAM,CAAC,CAC1B,QAAQ,SAAS,KAAK,SAAS,KAAK,CAAC,KAAK,WAAW,IAAI,CAAC;;AAG/D,eAAsB,wBAAwB,WAAsC;AAClF,QAAO,oCAAqB,WAAW,wBAAwB,CAAC;;AAGlE,SAAgB,sBAAsB,YAA8B;AAClE,QAAO,oCAAqB,YAAY,QAAQ,qBAAqB,CAAC;;AAGxE,SAAS,iBAAiB,YAAoB,UAAiC;CAC7E,MAAM,+BAAgB,YAAY,SAAS;AAC3C,KAAI,yBAAY,SAAS,CAAE,QAAO;AAClC,KAAI;EACF,MAAM,oCAAuB,SAAS;AACtC,qCAAkB,SAAS,CAAC,OAAO,QAAQ,CAAC,OAAO,MAAM,CAAC,UAAU,GAAG,GAAG;SACpE;AACN,SAAO;;;AAIX,SAAS,YAAY,YAAoB,WAAoC;CAC3E,MAAM,gBAAgB,UAAU,QAAQ,kDAAsB,YAAY,EAAE,CAAC,CAAC;AAC9E,KAAI,cAAc,WAAW,EAAG,QAAO;CAGvC,MAAM,gCAAiB,YAAY,QAAQ,gCADzB,IAA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yB,EAAE,IAAI,CAACA,kCAAe,GAAG,gBAAgB,CAC1E;EAED,MAAM,+BAAe,IAAI,KAAqB;AAC9C,OAAK,MAAM,YAAY,cACrB,cAAa,IAAI,WAAW,SAAS,EAAE,SAAS;AAGlD,MAAI,aAAa,SAAS,GAAG;AAC3B,eAAY,YAAY,aAAa;AAErC,QAAK,MAAM,YAAY,aAErB,iBAAgB,WAAW,YADR,aAAa,IAAI,SAAS,IAAI,SACC;;EAItD,MAAM,mBAA2C,EAAE;AACnD,OAAK,MAAM,YAAY,eAAe;GACpC,MAAM,0BAAW,WAAW,SAAS;AAErC,OAAI,wBADmB,IAAI,CACjB,QAAQ,CAAE;GACpB,MAAM,oCAAuB,IAAI;AACjC,oBAAiB,WAAW,SAAS,gCAAe,SAAS,CAC1D,OAAO,QAAQ,CACf,OAAO,MAAM,CACb,UAAU,GAAG,GAAG;;AAGrB,QAAME,+BAAc,YAAY;GAC9B,WAAW,SAAS,eAAe,GAAG;GACtC,OAAO;GACR,CAAC;AAKF,QAAMC,mCAAkB,YAAY;GAClC;GACA;GACA,SANe,YAAY,WAAsB;GAOjD,QANc,YAAY,UAAqB;GAO/C,SAAS;GACT;GACA,WAAW;IAAC;IAAM;IAAO;IAAQ;IAAU;GAC3C,eAAe,EAAE,WAAW;GAC5B,MAAM;GACP,CAAC;EAEF,MAAM,eAAe,MAAMJ,0BAAW,EAAE,KAAK,YAAY,CAAC;AAC1D,MAAI,cAAc,QAChB,mCAAoB,YAAY,aAAa,QAAQ;AAGvD,MAAI,CAAC,QAAQ,WAAW;AACtB,SAAMK,+BAAc,WAAW;AAC/B,SAAMC,6BAAY,WAAW;;AAG/B,SAAO;GACL,QAAQ;GACR;GACA;GACA;GACD;WACO;AACR,QAAM,SAAS"}
1
+ {"version":3,"file":"sync.cjs","names":["sourcePathToDestinationPath","mergeBosConfigWithTemplate","isPlainObjectFromMerge","resolveExtendsRef","resolveSourceDir","writeSnapshot","personalizeConfig","loadConfig","runBunInstall","runTypesGen"],"sources":["../../src/cli/sync.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { loadConfig } from \"../config\";\nimport type { SyncOptions, SyncResult } from \"../contract\";\nimport {\n isPlainObject as isPlainObjectFromMerge,\n mergeBosConfigWithTemplate,\n resolveExtendsRef,\n} from \"../merge\";\nimport { writeGeneratedInfra } from \"./infra\";\nimport {\n personalizeConfig,\n resolveSourceDir,\n runBunInstall,\n runTypesGen,\n sourcePathToDestinationPath,\n} from \"./init\";\nimport { writeSnapshot } from \"./snapshot\";\n\nconst FRAMEWORK_OWNED_SYNC_FILES = new Set([\n \".env.example\",\n \".gitignore\",\n \"AGENTS.md\",\n \"biome.json\",\n \"bos.config.json\",\n \"bunfig.toml\",\n \"CONTRIBUTING.md\",\n \"package.json\",\n \".changeset/config.json\",\n \".changeset/README.md\",\n \"docker-compose.yml\",\n \".github/renovate.json\",\n \".github/workflows/ci.yml\",\n \".github/workflows/release-sync.yml\",\n \".opencode/skills/everything-dev/SKILL.md\",\n \"ui/package.json\",\n \"ui/postcss.config.mjs\",\n \"ui/rsbuild.config.ts\",\n \"ui/tsconfig.json\",\n \"ui/src/app.ts\",\n \"ui/src/globals.d.ts\",\n \"ui/src/hydrate.tsx\",\n \"ui/src/lib/api.ts\",\n \"ui/src/lib/auth.ts\",\n \"ui/src/router.server.tsx\",\n \"ui/src/router.tsx\",\n \"ui/src/routes/__root.tsx\",\n \"api/package.json\",\n \"api/plugin.dev.ts\",\n \"api/rspack.config.js\",\n \"api/tsconfig.contract.json\",\n \"api/tsconfig.json\",\n \"api/src/lib/auth.ts\",\n]);\n\ntype PackageJson = Record<string, unknown>;\n\nexport function isFrameworkOwnedSyncFile(filePath: string): boolean {\n return FRAMEWORK_OWNED_SYNC_FILES.has(filePath);\n}\n\nfunction computeLocalHash(projectDir: string, filePath: string): string | null {\n const fullPath = join(projectDir, filePath);\n if (!existsSync(fullPath)) return null;\n try {\n const content = readFileSync(fullPath);\n return createHash(\"sha256\").update(content).digest(\"hex\").substring(0, 16);\n } catch {\n return null;\n }\n}\n\nfunction backupFiles(projectDir: string, filePaths: string[]): string | null {\n const filesToBackup = filePaths.filter((f) => existsSync(join(projectDir, f)));\n if (filesToBackup.length === 0) return null;\n\n const timestamp = new Date().toISOString().replace(/[:.]/g, \"-\");\n const backupDir = join(projectDir, \".bos\", \"sync-backup\", timestamp);\n\n for (const filePath of filesToBackup) {\n const src = join(projectDir, filePath);\n const dest = join(backupDir, filePath);\n mkdirSync(dirname(dest), { recursive: true });\n copyFileSync(src, dest);\n }\n\n return backupDir;\n}\n\nfunction mergeStringMaps(\n local: Record<string, string> | undefined,\n template: Record<string, string> | undefined,\n): Record<string, string> | undefined {\n if (!local && !template) return undefined;\n\n const merged: Record<string, string> = { ...(local ?? {}) };\n for (const [name, value] of Object.entries(template ?? {})) {\n merged[name] = value;\n }\n\n return Object.keys(merged).length > 0 ? merged : undefined;\n}\n\nfunction mergeWorkspacePackages(local: unknown, template: unknown): string[] | undefined {\n const localPackages = Array.isArray(local) ? local : [];\n const templatePackages = Array.isArray(template) ? template : [];\n if (localPackages.length === 0 && templatePackages.length === 0) return undefined;\n\n const ordered = new Set<string>();\n for (const entry of templatePackages) {\n if (typeof entry === \"string\" && entry.length > 0) ordered.add(entry);\n }\n for (const entry of localPackages) {\n if (typeof entry === \"string\" && entry.length > 0) ordered.add(entry);\n }\n\n return ordered.size > 0 ? [...ordered] : undefined;\n}\n\nexport function mergePackageJson(\n filePath: string,\n local: PackageJson,\n template: PackageJson,\n): PackageJson {\n const merged: PackageJson = { ...local, ...template };\n\n if (filePath === \"package.json\") {\n for (const key of [\"name\", \"private\", \"version\"] as const) {\n if (key in local) {\n merged[key] = local[key];\n }\n }\n } else if (\"version\" in local) {\n merged.version = local.version;\n }\n\n for (const depField of [\n \"dependencies\",\n \"devDependencies\",\n \"peerDependencies\",\n \"overrides\",\n ] as const) {\n const localDeps = local[depField] as Record<string, string> | undefined;\n const templateDeps = template[depField] as Record<string, string> | undefined;\n\n const mergedDeps = mergeStringMaps(localDeps, templateDeps);\n if (mergedDeps) {\n merged[depField] = mergedDeps;\n } else {\n delete merged[depField];\n }\n }\n\n if (\n (local.scripts && typeof local.scripts === \"object\") ||\n (template.scripts && typeof template.scripts === \"object\")\n ) {\n const mergedScripts = mergeStringMaps(\n local.scripts as Record<string, string> | undefined,\n template.scripts as Record<string, string> | undefined,\n );\n if (mergedScripts) {\n merged.scripts = mergedScripts;\n } else {\n delete merged.scripts;\n }\n }\n\n if (\n (local.workspaces && typeof local.workspaces === \"object\") ||\n (template.workspaces && typeof template.workspaces === \"object\")\n ) {\n const localWorkspaces = (local.workspaces ?? {}) as {\n packages?: string[];\n catalog?: Record<string, string>;\n };\n const templateWorkspaces = (template.workspaces ?? {}) as {\n packages?: string[];\n catalog?: Record<string, string>;\n };\n\n const mergedWorkspaces: { packages?: string[]; catalog?: Record<string, string> } = {\n ...localWorkspaces,\n ...templateWorkspaces,\n };\n\n const mergedPackages = mergeWorkspacePackages(\n localWorkspaces.packages,\n templateWorkspaces.packages,\n );\n if (mergedPackages) {\n mergedWorkspaces.packages = mergedPackages;\n } else {\n delete mergedWorkspaces.packages;\n }\n\n const mergedCatalog = mergeStringMaps(localWorkspaces.catalog, templateWorkspaces.catalog);\n if (mergedCatalog) {\n mergedWorkspaces.catalog = mergedCatalog;\n } else {\n delete mergedWorkspaces.catalog;\n }\n\n if (Object.keys(mergedWorkspaces).length > 0) {\n merged.workspaces = mergedWorkspaces;\n } else {\n delete merged.workspaces;\n }\n }\n\n return merged;\n}\n\nfunction toDestPath(filePath: string): string {\n return sourcePathToDestinationPath(filePath);\n}\n\nfunction toSourcePath(sourceDir: string, destPath: string): string | null {\n const directPath = join(sourceDir, destPath);\n if (existsSync(directPath)) {\n return destPath;\n }\n\n if (destPath.startsWith(\".github/\")) {\n const templatePath = destPath.replace(/^\\.github\\//, \".github/templates/\");\n if (existsSync(join(sourceDir, templatePath))) {\n return templatePath;\n }\n }\n\n return null;\n}\n\nfunction writeSyncedFile(sourceDir: string, projectDir: string, filePath: string): void {\n const src = join(sourceDir, filePath);\n const destPath = filePath.startsWith(\".github/templates/\")\n ? filePath.replace(/^\\.github\\/templates\\//, \".github/\")\n : filePath;\n const dest = join(projectDir, destPath);\n mkdirSync(dirname(dest), { recursive: true });\n\n if (filePath.endsWith(\"bos.config.json\")) {\n const localContent = existsSync(dest) ? readFileSync(dest, \"utf-8\") : null;\n const templateContent = readFileSync(src, \"utf-8\");\n\n if (localContent) {\n const local = JSON.parse(localContent) as Record<string, unknown>;\n const template = JSON.parse(templateContent) as Record<string, unknown>;\n const merged = mergeBosConfigWithTemplate(local, template);\n writeFileSync(dest, `${JSON.stringify(merged, null, 2)}\\n`);\n return;\n }\n }\n\n if (filePath.endsWith(\"package.json\")) {\n const localContent = existsSync(dest) ? readFileSync(dest, \"utf-8\") : null;\n const templateContent = readFileSync(src, \"utf-8\");\n\n if (localContent) {\n const local = JSON.parse(localContent) as Record<string, unknown>;\n const template = JSON.parse(templateContent) as Record<string, unknown>;\n const merged = mergePackageJson(destPath, local, template);\n writeFileSync(dest, `${JSON.stringify(merged, null, 2)}\\n`);\n return;\n }\n }\n\n writeFileSync(dest, readFileSync(src));\n}\n\nexport async function syncTemplate(projectDir: string, options: SyncOptions): Promise<SyncResult> {\n // Sync reads the raw bos.config.json (not the resolved config) because it needs\n // the user's explicit local settings: their extends ref, selected plugins, etc.\n // The resolved config is the merged result and would include inherited parent\n // values that the user didn't explicitly choose, which would break sync filtering.\n const localConfig = JSON.parse(\n readFileSync(join(projectDir, \"bos.config.json\"), \"utf-8\"),\n ) as Record<string, unknown>;\n\n let extendsRef: string | undefined;\n if (typeof localConfig.extends === \"string\") {\n extendsRef = localConfig.extends;\n } else if (isPlainObjectFromMerge(localConfig.extends)) {\n extendsRef = resolveExtendsRef(localConfig.extends as Record<string, string>, \"production\");\n }\n if (!extendsRef?.startsWith(\"bos://\")) {\n return {\n status: \"error\",\n updated: [],\n skipped: [],\n added: [],\n error: \"No extends field found in bos.config.json — cannot determine parent\",\n };\n }\n\n const extendsMatch = extendsRef.match(/^bos:\\/\\/([^/]+)\\/(.+)$/);\n if (!extendsMatch) {\n return {\n status: \"error\",\n updated: [],\n skipped: [],\n added: [],\n error: `Invalid extends reference: ${extendsRef}`,\n };\n }\n\n const extendsAccount = extendsMatch[1];\n const extendsGateway = extendsMatch[2];\n\n const { sourceDir, cleanup } = await resolveSourceDir({\n extendsAccount,\n extendsGateway,\n });\n\n try {\n const childPlugins =\n localConfig.plugins && typeof localConfig.plugins === \"object\"\n ? Object.keys(localConfig.plugins as Record<string, unknown>)\n : [];\n const withUi = existsSync(join(projectDir, \"ui\", \"package.json\"));\n const withApi = existsSync(join(projectDir, \"api\", \"package.json\"));\n const withHost = existsSync(join(projectDir, \"host\", \"package.json\"));\n\n const filteredFiles = new Set<string>();\n const destToSource = new Map<string, string>();\n for (const destPath of FRAMEWORK_OWNED_SYNC_FILES) {\n if (destPath.startsWith(\"ui/\") && !withUi) continue;\n if (destPath.startsWith(\"api/\") && !withApi) continue;\n if (destPath.startsWith(\"host/\") && !withHost) continue;\n const sourcePath = toSourcePath(sourceDir, destPath);\n if (!sourcePath) continue;\n filteredFiles.add(sourcePath);\n destToSource.set(destPath, sourcePath);\n }\n\n const updated: string[] = [];\n const skipped: string[] = [];\n const added: string[] = [];\n\n for (const [destPath, filePath] of destToSource.entries()) {\n const localHash = computeLocalHash(projectDir, destPath);\n const sourceContent = readFileSync(join(sourceDir, filePath));\n const sourceHash = createHash(\"sha256\").update(sourceContent).digest(\"hex\").substring(0, 16);\n\n if (localHash === null) {\n added.push(destPath);\n continue;\n }\n\n if (localHash !== sourceHash) {\n updated.push(destPath);\n }\n }\n\n if (options.dryRun) {\n return {\n status: \"dry-run\",\n updated,\n skipped,\n added,\n };\n }\n\n const filesToWrite = [...updated, ...added];\n\n if (filesToWrite.length > 0) {\n backupFiles(projectDir, filesToWrite);\n\n for (const destPath of filesToWrite) {\n const sourcePath = destToSource.get(destPath) ?? destPath;\n writeSyncedFile(sourceDir, projectDir, sourcePath);\n }\n }\n\n const newSnapshotFiles: Record<string, string> = {};\n for (const filePath of filteredFiles) {\n const src = join(sourceDir, filePath);\n const content = readFileSync(src);\n newSnapshotFiles[toDestPath(filePath)] = createHash(\"sha256\")\n .update(content)\n .digest(\"hex\")\n .substring(0, 16);\n }\n\n await writeSnapshot(projectDir, {\n parentRef: `bos://${extendsAccount}/${extendsGateway}`,\n files: newSnapshotFiles,\n });\n\n const account = (localConfig.account as string) || extendsAccount;\n const domain = (localConfig.domain as string) || extendsGateway;\n const overrides: Array<\"ui\" | \"api\" | \"host\" | \"plugins\"> = [];\n if (withUi) overrides.push(\"ui\");\n if (withApi) overrides.push(\"api\");\n if (withHost) overrides.push(\"host\");\n if (childPlugins.length > 0) overrides.push(\"plugins\");\n\n await personalizeConfig(projectDir, {\n extendsAccount,\n extendsGateway,\n account,\n domain,\n overrides,\n plugins: childPlugins,\n workspaceOpts: { sourceDir },\n mode: \"sync\",\n });\n\n const syncedConfig = await loadConfig({ cwd: projectDir });\n if (syncedConfig?.runtime) {\n writeGeneratedInfra(projectDir, syncedConfig.runtime);\n }\n\n if (!options.noInstall) {\n await runBunInstall(projectDir);\n await runTypesGen(projectDir);\n }\n\n return {\n status: \"synced\",\n updated,\n skipped,\n added,\n };\n } finally {\n await cleanup();\n }\n}\n"],"mappings":";;;;;;;;;;;AAoBA,MAAM,6BAA6B,IAAI,IAAI;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAQF,SAAS,iBAAiB,YAAoB,UAAiC;CAC7E,MAAM,+BAAgB,YAAY,SAAS;AAC3C,KAAI,yBAAY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,MAAMC,0BAAW,EAAE,KAAK,YAAY,CAAC;AAC1D,MAAI,cAAc,QAChB,mCAAoB,YAAY,aAAa,QAAQ;AAGvD,MAAI,CAAC,QAAQ,WAAW;AACtB,SAAMC,+BAAc,WAAW;AAC/B,SAAMC,6BAAY,WAAW;;AAG/B,SAAO;GACL,QAAQ;GACR;GACA;GACA;GACD;WACO;AACR,QAAM,SAAS"}
package/dist/cli/sync.mjs CHANGED
@@ -1,30 +1,35 @@
1
1
  import { isPlainObject, mergeBosConfigWithTemplate, resolveExtendsRef } from "../merge.mjs";
2
2
  import { loadConfig } from "../config.mjs";
3
3
  import { writeGeneratedInfra } from "./infra.mjs";
4
- import { isPathExcluded } from "../utils/path-match.mjs";
5
- import { readSnapshot, writeSnapshot } from "./snapshot.mjs";
6
- import { personalizeConfig, readTemplatekeep, resolveSourceDir, runBunInstall, runTypesGen } from "./init.mjs";
7
- import { copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
+ import { writeSnapshot } from "./snapshot.mjs";
5
+ import { personalizeConfig, resolveSourceDir, runBunInstall, runTypesGen, sourcePathToDestinationPath } from "./init.mjs";
6
+ import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
8
7
  import { dirname, join } from "node:path";
9
8
  import { createHash } from "node:crypto";
10
- import { glob } from "glob";
11
9
 
12
10
  //#region src/cli/sync.ts
13
11
  const FRAMEWORK_OWNED_SYNC_FILES = new Set([
14
12
  ".env.example",
15
13
  ".gitignore",
14
+ "AGENTS.md",
16
15
  "biome.json",
17
16
  "bos.config.json",
17
+ "bunfig.toml",
18
+ "CONTRIBUTING.md",
18
19
  "package.json",
20
+ ".changeset/config.json",
21
+ ".changeset/README.md",
19
22
  "docker-compose.yml",
20
23
  ".github/renovate.json",
21
24
  ".github/workflows/ci.yml",
22
25
  ".github/workflows/release-sync.yml",
26
+ ".opencode/skills/everything-dev/SKILL.md",
23
27
  "ui/package.json",
24
28
  "ui/postcss.config.mjs",
25
29
  "ui/rsbuild.config.ts",
26
30
  "ui/tsconfig.json",
27
31
  "ui/src/app.ts",
32
+ "ui/src/globals.d.ts",
28
33
  "ui/src/hydrate.tsx",
29
34
  "ui/src/lib/api.ts",
30
35
  "ui/src/lib/auth.ts",
@@ -38,19 +43,6 @@ const FRAMEWORK_OWNED_SYNC_FILES = new Set([
38
43
  "api/tsconfig.json",
39
44
  "api/src/lib/auth.ts"
40
45
  ]);
41
- function isFrameworkOwnedSyncFile(filePath) {
42
- return FRAMEWORK_OWNED_SYNC_FILES.has(filePath);
43
- }
44
- function readExcludeFile(filePath) {
45
- if (!existsSync(filePath)) return [];
46
- return readFileSync(filePath, "utf-8").split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
47
- }
48
- async function readTemplatesyncExclude(sourceDir) {
49
- return readExcludeFile(join(sourceDir, ".templatesync-exclude"));
50
- }
51
- function readLocalSyncExcludes(projectDir) {
52
- return readExcludeFile(join(projectDir, ".bos", "sync-local-exclude"));
53
- }
54
46
  function computeLocalHash(projectDir, filePath) {
55
47
  const fullPath = join(projectDir, filePath);
56
48
  if (!existsSync(fullPath)) return null;
@@ -136,7 +128,15 @@ function mergePackageJson(filePath, local, template) {
136
128
  return merged;
137
129
  }
138
130
  function toDestPath(filePath) {
139
- return filePath.startsWith(".github/templates/") ? filePath.replace(/^\.github\/templates\//, ".github/") : filePath;
131
+ return sourcePathToDestinationPath(filePath);
132
+ }
133
+ function toSourcePath(sourceDir, destPath) {
134
+ if (existsSync(join(sourceDir, destPath))) return destPath;
135
+ if (destPath.startsWith(".github/")) {
136
+ const templatePath = destPath.replace(/^\.github\//, ".github/templates/");
137
+ if (existsSync(join(sourceDir, templatePath))) return templatePath;
138
+ }
139
+ return null;
140
140
  }
141
141
  function writeSyncedFile(sourceDir, projectDir, filePath) {
142
142
  const src = join(sourceDir, filePath);
@@ -190,60 +190,25 @@ async function syncTemplate(projectDir, options) {
190
190
  extendsGateway
191
191
  });
192
192
  try {
193
- const patterns = await readTemplatekeep(sourceDir);
194
- if (patterns.length === 0) return {
195
- status: "error",
196
- updated: [],
197
- skipped: [],
198
- added: [],
199
- error: "No .templatekeep found in template source"
200
- };
201
- const parentExcludes = await readTemplatesyncExclude(sourceDir);
202
- const localExcludes = readLocalSyncExcludes(projectDir);
203
- const excludePatterns = [...parentExcludes, ...localExcludes];
204
- const allTemplateFiles = /* @__PURE__ */ new Set();
205
- for (const pattern of patterns) {
206
- const matches = await glob(pattern, {
207
- cwd: sourceDir,
208
- nodir: true,
209
- dot: true,
210
- absolute: false
211
- });
212
- for (const match of matches) allTemplateFiles.add(match);
213
- }
214
193
  const childPlugins = localConfig.plugins && typeof localConfig.plugins === "object" ? Object.keys(localConfig.plugins) : [];
215
- const pluginRoutes = {};
216
- const parentRuntime = await loadConfig({ cwd: sourceDir });
217
- for (const [key, plugin] of Object.entries(parentRuntime?.runtime.plugins ?? {})) if (plugin.routes && plugin.routes.length > 0) pluginRoutes[key] = plugin.routes;
218
- const excludedRoutePatterns = [];
219
- for (const [pluginKey, routePatterns] of Object.entries(pluginRoutes)) if (!childPlugins.includes(pluginKey)) excludedRoutePatterns.push(...routePatterns);
194
+ const withUi = existsSync(join(projectDir, "ui", "package.json"));
195
+ const withApi = existsSync(join(projectDir, "api", "package.json"));
196
+ const withHost = existsSync(join(projectDir, "host", "package.json"));
220
197
  const filteredFiles = /* @__PURE__ */ new Set();
221
- for (const filePath of allTemplateFiles) {
222
- const pluginMatch = filePath.match(/^plugins\/([^/]+)/);
223
- if (pluginMatch && !childPlugins.includes(pluginMatch[1])) continue;
224
- if (isPathExcluded(filePath, excludedRoutePatterns)) continue;
225
- filteredFiles.add(filePath);
226
- }
227
- for (const [pluginKey, routePatterns] of Object.entries(pluginRoutes)) {
228
- if (!childPlugins.includes(pluginKey)) continue;
229
- for (const rp of routePatterns) {
230
- const matches = await glob(rp, {
231
- cwd: sourceDir,
232
- nodir: true,
233
- dot: true,
234
- absolute: false
235
- });
236
- for (const match of matches) if (!isPathExcluded(match, excludedRoutePatterns)) filteredFiles.add(match);
237
- }
198
+ const destToSource = /* @__PURE__ */ new Map();
199
+ for (const destPath of FRAMEWORK_OWNED_SYNC_FILES) {
200
+ if (destPath.startsWith("ui/") && !withUi) continue;
201
+ if (destPath.startsWith("api/") && !withApi) continue;
202
+ if (destPath.startsWith("host/") && !withHost) continue;
203
+ const sourcePath = toSourcePath(sourceDir, destPath);
204
+ if (!sourcePath) continue;
205
+ filteredFiles.add(sourcePath);
206
+ destToSource.set(destPath, sourcePath);
238
207
  }
239
- const snapshot = await readSnapshot(projectDir);
240
208
  const updated = [];
241
209
  const skipped = [];
242
210
  const added = [];
243
- for (const filePath of filteredFiles) {
244
- const destPath = toDestPath(filePath);
245
- const frameworkOwned = isFrameworkOwnedSyncFile(destPath);
246
- if (isPathExcluded(destPath, excludePatterns) && !frameworkOwned) continue;
211
+ for (const [destPath, filePath] of destToSource.entries()) {
247
212
  const localHash = computeLocalHash(projectDir, destPath);
248
213
  const sourceContent = readFileSync(join(sourceDir, filePath));
249
214
  const sourceHash = createHash("sha256").update(sourceContent).digest("hex").substring(0, 16);
@@ -251,19 +216,7 @@ async function syncTemplate(projectDir, options) {
251
216
  added.push(destPath);
252
217
  continue;
253
218
  }
254
- if (localHash === sourceHash) continue;
255
- if (frameworkOwned) {
256
- updated.push(destPath);
257
- continue;
258
- }
259
- const snapshotHash = snapshot?.files[destPath];
260
- if (snapshotHash === void 0) {
261
- updated.push(destPath);
262
- continue;
263
- }
264
- if (localHash === snapshotHash) updated.push(destPath);
265
- else if (options.force) updated.push(destPath);
266
- else skipped.push(destPath);
219
+ if (localHash !== sourceHash) updated.push(destPath);
267
220
  }
268
221
  if (options.dryRun) return {
269
222
  status: "dry-run",
@@ -271,37 +224,34 @@ async function syncTemplate(projectDir, options) {
271
224
  skipped,
272
225
  added
273
226
  };
274
- const filesToWrite = [...updated, ...added].filter((f) => isFrameworkOwnedSyncFile(f) || !isPathExcluded(f, excludePatterns));
275
- const destToSource = /* @__PURE__ */ new Map();
276
- for (const filePath of filteredFiles) destToSource.set(toDestPath(filePath), filePath);
227
+ const filesToWrite = [...updated, ...added];
277
228
  if (filesToWrite.length > 0) {
278
229
  backupFiles(projectDir, filesToWrite);
279
230
  for (const destPath of filesToWrite) writeSyncedFile(sourceDir, projectDir, destToSource.get(destPath) ?? destPath);
280
231
  }
281
232
  const newSnapshotFiles = {};
282
233
  for (const filePath of filteredFiles) {
283
- const src = join(sourceDir, filePath);
284
- if (!lstatSync(src).isFile()) continue;
285
- const content = readFileSync(src);
234
+ const content = readFileSync(join(sourceDir, filePath));
286
235
  newSnapshotFiles[toDestPath(filePath)] = createHash("sha256").update(content).digest("hex").substring(0, 16);
287
236
  }
288
237
  await writeSnapshot(projectDir, {
289
238
  parentRef: `bos://${extendsAccount}/${extendsGateway}`,
290
239
  files: newSnapshotFiles
291
240
  });
241
+ const account = localConfig.account || extendsAccount;
242
+ const domain = localConfig.domain || extendsGateway;
243
+ const overrides = [];
244
+ if (withUi) overrides.push("ui");
245
+ if (withApi) overrides.push("api");
246
+ if (withHost) overrides.push("host");
247
+ if (childPlugins.length > 0) overrides.push("plugins");
292
248
  await personalizeConfig(projectDir, {
293
249
  extendsAccount,
294
250
  extendsGateway,
295
- account: localConfig.account || extendsAccount,
296
- domain: localConfig.domain || extendsGateway,
251
+ account,
252
+ domain,
253
+ overrides,
297
254
  plugins: childPlugins,
298
- pluginRoutes,
299
- overrides: [
300
- "ui",
301
- "api",
302
- "host",
303
- "plugins"
304
- ],
305
255
  workspaceOpts: { sourceDir },
306
256
  mode: "sync"
307
257
  });