@databricks/appkit-ui 0.27.1 → 0.29.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/CLAUDE.md +1 -0
- package/dist/cli/commands/plugin/create/create.js +18 -0
- package/dist/cli/commands/plugin/create/create.js.map +1 -1
- package/dist/cli/commands/plugin/create/scaffold.js +1 -0
- package/dist/cli/commands/plugin/create/scaffold.js.map +1 -1
- package/dist/cli/commands/plugin/index.js +5 -2
- package/dist/cli/commands/plugin/index.js.map +1 -1
- package/dist/cli/commands/plugin/list/list.js +6 -0
- package/dist/cli/commands/plugin/list/list.js.map +1 -1
- package/dist/cli/commands/plugin/promote/promote.js +314 -0
- package/dist/cli/commands/plugin/promote/promote.js.map +1 -0
- package/dist/cli/commands/plugin/sync/sync.js +24 -4
- package/dist/cli/commands/plugin/sync/sync.js.map +1 -1
- package/dist/js/beta.d.ts +1 -0
- package/dist/js/beta.js +0 -0
- package/dist/react/beta.d.ts +1 -0
- package/dist/react/beta.js +0 -0
- package/dist/schemas/plugin-manifest.generated.d.ts +4 -0
- package/dist/schemas/plugin-manifest.generated.d.ts.map +1 -1
- package/dist/schemas/plugin-manifest.schema.json +6 -0
- package/dist/schemas/template-plugins.schema.json +7 -1
- package/dist/shared/src/agent.d.ts +1 -0
- package/dist/shared/src/index.d.ts +1 -0
- package/dist/shared/src/plugin.d.ts +1 -1
- package/docs/api/appkit/Interface.PluginManifest.md +19 -1
- package/docs/plugins/custom-plugins.md +1 -1
- package/docs/plugins/execution-context.md +13 -1
- package/docs/plugins/stability.md +156 -0
- package/llms.txt +1 -0
- package/package.json +3 -1
- package/sbom.cdx.json +1 -1
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { resolveManifestInDir } from "../manifest-resolve.js";
|
|
2
|
+
import { shouldAllowJsManifestForDir } from "../trusted-js-manifest.js";
|
|
3
|
+
import { isWithinDirectory } from "../sync/sync.js";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { Command } from "commander";
|
|
7
|
+
import process from "node:process";
|
|
8
|
+
|
|
9
|
+
//#region src/cli/commands/plugin/promote/promote.ts
|
|
10
|
+
const TIER_ORDER = {
|
|
11
|
+
beta: 0,
|
|
12
|
+
ga: 1
|
|
13
|
+
};
|
|
14
|
+
const IMPORT_PATH_MAP = {
|
|
15
|
+
beta: "/beta",
|
|
16
|
+
ga: ""
|
|
17
|
+
};
|
|
18
|
+
/** Aligned with sync.ts and list.ts; keep all plugin-tree walks at the same cap. */
|
|
19
|
+
const MAX_SCAN_DEPTH = 5;
|
|
20
|
+
/**
|
|
21
|
+
* Directories that should never be walked when discovering plugin manifests
|
|
22
|
+
* or rewriting imports. Mirrors common build/output trees.
|
|
23
|
+
*/
|
|
24
|
+
const SKIP_DIRECTORIES = new Set([
|
|
25
|
+
"node_modules",
|
|
26
|
+
"dist",
|
|
27
|
+
"build",
|
|
28
|
+
"out",
|
|
29
|
+
".git",
|
|
30
|
+
".turbo",
|
|
31
|
+
".next",
|
|
32
|
+
".nuxt",
|
|
33
|
+
".cache",
|
|
34
|
+
".svelte-kit",
|
|
35
|
+
".vite",
|
|
36
|
+
".parcel-cache",
|
|
37
|
+
"coverage"
|
|
38
|
+
]);
|
|
39
|
+
/**
|
|
40
|
+
* Plugin name charset accepted by the promote command. Mirrors npm package
|
|
41
|
+
* naming (lowercase, dashes, underscores, dots, optional @scope/) and explicitly
|
|
42
|
+
* forbids path separators, traversal, and NUL — so the name cannot escape its
|
|
43
|
+
* intended directory when used in path.join().
|
|
44
|
+
*/
|
|
45
|
+
const PLUGIN_NAME_PATTERN = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/i;
|
|
46
|
+
function validatePluginName(pluginName) {
|
|
47
|
+
if (!pluginName || pluginName.includes("\0") || pluginName.includes("..")) throw new Error(`Invalid plugin name "${pluginName}". Plugin names must not contain "..", or null bytes.`);
|
|
48
|
+
if (pluginName.includes("\\")) throw new Error(`Invalid plugin name "${pluginName}". Plugin names must not contain backslashes.`);
|
|
49
|
+
if (pluginName.includes("/") && !pluginName.startsWith("@")) throw new Error(`Invalid plugin name "${pluginName}". Plugin names must not contain "/" unless they are a scoped package (e.g. @scope/name).`);
|
|
50
|
+
if (!PLUGIN_NAME_PATTERN.test(pluginName)) throw new Error(`Invalid plugin name "${pluginName}". Expected lowercase alphanumeric with optional dashes, underscores, dots, or @scope/ prefix.`);
|
|
51
|
+
}
|
|
52
|
+
function isStability(value) {
|
|
53
|
+
return value === "beta" || value === "ga";
|
|
54
|
+
}
|
|
55
|
+
function findPluginManifest(pluginName, cwd) {
|
|
56
|
+
for (const dir of [
|
|
57
|
+
"plugins",
|
|
58
|
+
"server",
|
|
59
|
+
"."
|
|
60
|
+
]) {
|
|
61
|
+
const result = scanDirForPlugin(path.resolve(cwd, dir), pluginName, cwd, 0);
|
|
62
|
+
if (result) return {
|
|
63
|
+
manifestPath: result,
|
|
64
|
+
isLocal: true
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const nodeModulesDir = path.join(cwd, "node_modules", "@databricks/appkit");
|
|
68
|
+
if (fs.existsSync(nodeModulesDir)) {
|
|
69
|
+
const pluginsDir = path.join(nodeModulesDir, "dist", "plugins");
|
|
70
|
+
if (fs.existsSync(pluginsDir)) {
|
|
71
|
+
const manifestPath = path.resolve(pluginsDir, pluginName, "manifest.json");
|
|
72
|
+
if (isWithinDirectory(manifestPath, pluginsDir) && fs.existsSync(manifestPath)) return {
|
|
73
|
+
manifestPath,
|
|
74
|
+
isLocal: false
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
function scanDirForPlugin(dir, pluginName, cwd, depth) {
|
|
81
|
+
if (depth >= MAX_SCAN_DEPTH) return null;
|
|
82
|
+
let stat;
|
|
83
|
+
try {
|
|
84
|
+
stat = fs.statSync(dir);
|
|
85
|
+
} catch {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
if (!stat.isDirectory()) return null;
|
|
89
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
90
|
+
for (const entry of entries) {
|
|
91
|
+
if (!entry.isDirectory()) continue;
|
|
92
|
+
if (SKIP_DIRECTORIES.has(entry.name)) continue;
|
|
93
|
+
if (entry.isSymbolicLink()) continue;
|
|
94
|
+
const childPath = path.join(dir, entry.name);
|
|
95
|
+
const resolved = resolveManifestInDir(childPath, { allowJsManifest: shouldAllowJsManifestForDir(childPath) });
|
|
96
|
+
if (resolved) {
|
|
97
|
+
try {
|
|
98
|
+
const obj = loadManifestFromFileSync(resolved.path);
|
|
99
|
+
if (obj && typeof obj === "object" && "name" in obj && obj.name === pluginName) return resolved.path;
|
|
100
|
+
} catch {}
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const deeper = scanDirForPlugin(childPath, pluginName, cwd, depth + 1);
|
|
104
|
+
if (deeper) return deeper;
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
function loadManifestFromFileSync(filePath) {
|
|
109
|
+
const raw = fs.readFileSync(filePath, "utf-8");
|
|
110
|
+
return JSON.parse(raw);
|
|
111
|
+
}
|
|
112
|
+
function escapeRegex(s) {
|
|
113
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Convert a kebab-case manifest name to its camelCase JS identifier form
|
|
117
|
+
* (e.g. `vector-search` -> `vectorSearch`). Mirrors the convention used by
|
|
118
|
+
* first-party plugin index files: a manifest's `name` field may be
|
|
119
|
+
* kebab-case (the schema permits `^[a-z][a-z0-9-]*$`), but the actual
|
|
120
|
+
* exported binding is always a JS identifier. We try both forms when
|
|
121
|
+
* matching specifiers in user code.
|
|
122
|
+
*/
|
|
123
|
+
function manifestNameToBinding(pluginName) {
|
|
124
|
+
return pluginName.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Returns true when the named import specifier `spec` resolves to either
|
|
128
|
+
* `pluginName` itself or its kebab-to-camelCase JS-identifier form.
|
|
129
|
+
* Handles the `name`, `name as alias`, and inline-type (`type name`,
|
|
130
|
+
* `type name as alias`) forms. Matches on the imported binding before any
|
|
131
|
+
* `as` rename so a promotion finds the right specifier regardless of how
|
|
132
|
+
* the user aliased it.
|
|
133
|
+
*/
|
|
134
|
+
function specifierMatchesPlugin(spec, pluginName) {
|
|
135
|
+
const head = spec.replace(/^type\s+/, "").trim().split(/\s+as\s+/)[0]?.trim();
|
|
136
|
+
if (!head) return false;
|
|
137
|
+
return head === pluginName || head === manifestNameToBinding(pluginName);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Rewrite imports of `pluginName` from `<pkg><oldSuffix>` to `<pkg><newSuffix>`
|
|
141
|
+
* across one file, leaving every OTHER specifier on the same import line at
|
|
142
|
+
* its original source. The naïve `split/join` approach this replaced was
|
|
143
|
+
* promoting *every* beta specifier in the file along with the targeted
|
|
144
|
+
* plugin — a bug because beta specifiers don't exist at the GA subpath.
|
|
145
|
+
*
|
|
146
|
+
* Behaviour:
|
|
147
|
+
* - If the targeted plugin is the only specifier on an import line, the
|
|
148
|
+
* line's source is rewritten to the new path.
|
|
149
|
+
* - If the import has multiple specifiers, the targeted one is moved to a
|
|
150
|
+
* newly-emitted import line at the new source, and the original import
|
|
151
|
+
* keeps the remaining specifiers at the old source.
|
|
152
|
+
* - Imports that don't reference `pluginName` are left untouched.
|
|
153
|
+
*
|
|
154
|
+
* Multi-line specifier lists, type-only imports (`import type { ... }`),
|
|
155
|
+
* inline-type specifiers (`import { type Foo }`), and `as`-aliased
|
|
156
|
+
* specifiers are all preserved through the rewrite.
|
|
157
|
+
*/
|
|
158
|
+
function rewriteImportsInFile(filePath, pluginName, oldSuffix, newSuffix, dryRun) {
|
|
159
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
160
|
+
const packages = [
|
|
161
|
+
"@databricks/appkit",
|
|
162
|
+
"@databricks/appkit-ui/js",
|
|
163
|
+
"@databricks/appkit-ui/react"
|
|
164
|
+
];
|
|
165
|
+
let updated = content;
|
|
166
|
+
let changed = false;
|
|
167
|
+
for (const pkg of packages) {
|
|
168
|
+
const oldPath = `${pkg}${oldSuffix}`;
|
|
169
|
+
const newPath = `${pkg}${newSuffix}`;
|
|
170
|
+
const importRe = new RegExp(`import\\s+(type\\s+)?\\{([^}]*)\\}\\s*from\\s*(["'])${escapeRegex(oldPath)}\\3\\s*;?`, "g");
|
|
171
|
+
updated = updated.replace(importRe, (full, typeKeyword, specifiers, quote) => {
|
|
172
|
+
const specList = specifiers.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
173
|
+
const promotedSpec = specList.find((s) => specifierMatchesPlugin(s, pluginName));
|
|
174
|
+
if (!promotedSpec) return full;
|
|
175
|
+
const remaining = specList.filter((s) => !specifierMatchesPlugin(s, pluginName));
|
|
176
|
+
changed = true;
|
|
177
|
+
const tk = typeKeyword ?? "";
|
|
178
|
+
const promotedImport = `import ${tk}{ ${promotedSpec} } from ${quote}${newPath}${quote};`;
|
|
179
|
+
if (remaining.length === 0) return promotedImport;
|
|
180
|
+
return `${`import ${tk}{ ${remaining.join(", ")} } from ${quote}${oldPath}${quote};`}\n${promotedImport}`;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if (!changed) return null;
|
|
184
|
+
if (!dryRun) fs.writeFileSync(filePath, updated);
|
|
185
|
+
return {
|
|
186
|
+
file: filePath,
|
|
187
|
+
from: oldSuffix || "(root)",
|
|
188
|
+
to: newSuffix || "(root)"
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function findTsFiles(dir, projectRoot, depth = 0) {
|
|
192
|
+
if (depth >= MAX_SCAN_DEPTH) return [];
|
|
193
|
+
const results = [];
|
|
194
|
+
let entries;
|
|
195
|
+
try {
|
|
196
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
197
|
+
} catch {
|
|
198
|
+
return results;
|
|
199
|
+
}
|
|
200
|
+
for (const entry of entries) {
|
|
201
|
+
const fullPath = path.join(dir, entry.name);
|
|
202
|
+
if (entry.isSymbolicLink()) continue;
|
|
203
|
+
if (entry.isDirectory()) {
|
|
204
|
+
if (SKIP_DIRECTORIES.has(entry.name)) continue;
|
|
205
|
+
if (!isWithinDirectory(fullPath, projectRoot)) continue;
|
|
206
|
+
results.push(...findTsFiles(fullPath, projectRoot, depth + 1));
|
|
207
|
+
} else if (entry.name.endsWith(".ts") || entry.name.endsWith(".tsx")) results.push(fullPath);
|
|
208
|
+
}
|
|
209
|
+
return results;
|
|
210
|
+
}
|
|
211
|
+
async function runPromote(pluginName, options) {
|
|
212
|
+
validatePluginName(pluginName);
|
|
213
|
+
const cwd = process.cwd();
|
|
214
|
+
if (!isStability(options.to)) {
|
|
215
|
+
console.error(`Invalid target tier "${options.to}". Must be one of: beta, ga.`);
|
|
216
|
+
process.exit(1);
|
|
217
|
+
}
|
|
218
|
+
const target = options.to;
|
|
219
|
+
const found = findPluginManifest(pluginName, cwd);
|
|
220
|
+
if (!found) {
|
|
221
|
+
console.error(`Plugin "${pluginName}" not found. Searched local dirs (plugins, server, .) and node_modules.`);
|
|
222
|
+
process.exit(1);
|
|
223
|
+
}
|
|
224
|
+
const { manifestPath, isLocal } = found;
|
|
225
|
+
if (!isLocal && !options.allowInstalled) {
|
|
226
|
+
console.error(`Plugin "${pluginName}" was only found under node_modules (${path.relative(cwd, manifestPath)}).\nRefusing to mutate an installed package — re-install would overwrite the change.\nPass --allow-installed to override (advanced; not recommended).`);
|
|
227
|
+
process.exit(1);
|
|
228
|
+
}
|
|
229
|
+
let raw;
|
|
230
|
+
try {
|
|
231
|
+
const parsed = loadManifestFromFileSync(manifestPath);
|
|
232
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
233
|
+
console.error(`Manifest at ${path.relative(cwd, manifestPath)} is not a JSON object.`);
|
|
234
|
+
process.exit(1);
|
|
235
|
+
}
|
|
236
|
+
raw = parsed;
|
|
237
|
+
} catch (err) {
|
|
238
|
+
console.error(`Failed to read manifest at ${path.relative(cwd, manifestPath)}: ${err instanceof Error ? err.message : String(err)}`);
|
|
239
|
+
process.exit(1);
|
|
240
|
+
}
|
|
241
|
+
const rawStability = raw.stability ?? "ga";
|
|
242
|
+
if (!isStability(rawStability)) {
|
|
243
|
+
console.error(`Manifest at ${path.relative(cwd, manifestPath)} has an invalid stability value "${String(rawStability)}". Must be one of: beta, ga (or omitted for ga).`);
|
|
244
|
+
process.exit(1);
|
|
245
|
+
}
|
|
246
|
+
const currentStability = rawStability;
|
|
247
|
+
if (currentStability === target) {
|
|
248
|
+
console.error(`Plugin "${pluginName}" is already at "${target}". Nothing to do.`);
|
|
249
|
+
process.exit(1);
|
|
250
|
+
}
|
|
251
|
+
if (TIER_ORDER[target] <= TIER_ORDER[currentStability]) {
|
|
252
|
+
console.error(`Cannot demote "${pluginName}" from "${currentStability}" to "${target}". Promotion is one-way only.`);
|
|
253
|
+
process.exit(1);
|
|
254
|
+
}
|
|
255
|
+
const prefix = options.dryRun ? "[dry-run] " : "";
|
|
256
|
+
if (target === "ga") delete raw.stability;
|
|
257
|
+
else raw.stability = target;
|
|
258
|
+
if (!options.dryRun) fs.writeFileSync(manifestPath, `${JSON.stringify(raw, null, 2)}\n`);
|
|
259
|
+
console.log(`${prefix}Updated manifest: ${path.relative(cwd, manifestPath)} (${currentStability} → ${target})`);
|
|
260
|
+
const importRewrites = [];
|
|
261
|
+
if (!options.skipImports) {
|
|
262
|
+
const oldSuffix = IMPORT_PATH_MAP[currentStability];
|
|
263
|
+
const newSuffix = IMPORT_PATH_MAP[target];
|
|
264
|
+
const tsFiles = findTsFiles(cwd, cwd);
|
|
265
|
+
for (const file of tsFiles) {
|
|
266
|
+
const result = rewriteImportsInFile(file, pluginName, oldSuffix, newSuffix, Boolean(options.dryRun));
|
|
267
|
+
if (result) {
|
|
268
|
+
importRewrites.push(result);
|
|
269
|
+
console.log(`${prefix}Rewritten imports in: ${path.relative(cwd, file)}`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (importRewrites.length === 0) console.log(`${prefix}No import paths to rewrite.`);
|
|
273
|
+
}
|
|
274
|
+
if (!options.skipSync && !options.dryRun) {
|
|
275
|
+
const generatorPath = path.join(cwd, "tools", "generate-plugin-entries.ts");
|
|
276
|
+
if (fs.existsSync(generatorPath)) {
|
|
277
|
+
console.log(`\n${prefix}Regenerating manifest-derived artifacts...`);
|
|
278
|
+
const { execSync } = await import("node:child_process");
|
|
279
|
+
try {
|
|
280
|
+
execSync("pnpm run generate:types", {
|
|
281
|
+
cwd,
|
|
282
|
+
stdio: "inherit"
|
|
283
|
+
});
|
|
284
|
+
} catch {
|
|
285
|
+
console.error("Error: post-promote 'generate:types' failed. Manifest was updated, but generated barrels and docs banners may be stale. Run 'pnpm run generate:types' manually.");
|
|
286
|
+
process.exit(1);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
console.log(`\n${prefix}Running plugin sync...`);
|
|
290
|
+
const { execSync } = await import("node:child_process");
|
|
291
|
+
const syncCommand = fs.existsSync(generatorPath) ? "pnpm run sync:template" : "npx appkit plugin sync --write";
|
|
292
|
+
try {
|
|
293
|
+
execSync(syncCommand, {
|
|
294
|
+
cwd,
|
|
295
|
+
stdio: "inherit"
|
|
296
|
+
});
|
|
297
|
+
} catch {
|
|
298
|
+
console.error(`Error: post-promote sync ('${syncCommand}') failed. Manifest and imports were updated, but the synced plugin manifest may be stale. Run '${syncCommand}' manually.`);
|
|
299
|
+
process.exit(1);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
console.log(`\n${prefix}Promotion complete: ${pluginName} ${currentStability} → ${target}`);
|
|
303
|
+
if (importRewrites.length > 0) console.log(` ${importRewrites.length} file(s) with import rewrites`);
|
|
304
|
+
}
|
|
305
|
+
const pluginPromoteCommand = new Command("promote").description("Promote a plugin to a higher stability tier").argument("<plugin-name>", "Plugin name to promote").requiredOption("--to <tier>", "Target stability tier (beta, ga)").option("--dry-run", "Show what would change without modifying files").option("--skip-imports", "Only update manifest, skip import path rewriting").option("--skip-sync", "Don't auto-run plugin sync after promotion").option("--allow-installed", "Allow promoting a plugin that lives only under node_modules (advanced)").action((pluginName, opts) => runPromote(pluginName, opts).catch((err) => {
|
|
306
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
307
|
+
console.error(`Error: ${message}`);
|
|
308
|
+
if (process.env.DEBUG) console.error(err);
|
|
309
|
+
process.exit(1);
|
|
310
|
+
}));
|
|
311
|
+
|
|
312
|
+
//#endregion
|
|
313
|
+
export { pluginPromoteCommand };
|
|
314
|
+
//# sourceMappingURL=promote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promote.js","names":[],"sources":["../../../../../src/cli/commands/plugin/promote/promote.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport process from \"node:process\";\nimport { Command } from \"commander\";\nimport { resolveManifestInDir } from \"../manifest-resolve\";\nimport { isWithinDirectory } from \"../sync/sync\";\nimport { shouldAllowJsManifestForDir } from \"../trusted-js-manifest\";\n\ntype Stability = \"beta\" | \"ga\";\n\nconst TIER_ORDER: Record<Stability, number> = {\n beta: 0,\n ga: 1,\n};\n\nconst IMPORT_PATH_MAP: Record<Stability, string> = {\n beta: \"/beta\",\n ga: \"\",\n};\n\n/** Aligned with sync.ts and list.ts; keep all plugin-tree walks at the same cap. */\nconst MAX_SCAN_DEPTH = 5;\n\n/**\n * Directories that should never be walked when discovering plugin manifests\n * or rewriting imports. Mirrors common build/output trees.\n */\nconst SKIP_DIRECTORIES = new Set([\n \"node_modules\",\n \"dist\",\n \"build\",\n \"out\",\n \".git\",\n \".turbo\",\n \".next\",\n \".nuxt\",\n \".cache\",\n \".svelte-kit\",\n \".vite\",\n \".parcel-cache\",\n \"coverage\",\n]);\n\n/**\n * Plugin name charset accepted by the promote command. Mirrors npm package\n * naming (lowercase, dashes, underscores, dots, optional @scope/) and explicitly\n * forbids path separators, traversal, and NUL — so the name cannot escape its\n * intended directory when used in path.join().\n */\nconst PLUGIN_NAME_PATTERN =\n /^(?:@[a-z0-9][a-z0-9._-]*\\/)?[a-z0-9][a-z0-9._-]*$/i;\n\nfunction validatePluginName(pluginName: string): void {\n if (!pluginName || pluginName.includes(\"\\0\") || pluginName.includes(\"..\")) {\n throw new Error(\n `Invalid plugin name \"${pluginName}\". Plugin names must not contain \"..\", or null bytes.`,\n );\n }\n // Backslash is never allowed (treated as a path separator on Windows).\n if (pluginName.includes(\"\\\\\")) {\n throw new Error(\n `Invalid plugin name \"${pluginName}\". Plugin names must not contain backslashes.`,\n );\n }\n // Forward slash is only allowed inside the @scope/name form.\n if (pluginName.includes(\"/\") && !pluginName.startsWith(\"@\")) {\n throw new Error(\n `Invalid plugin name \"${pluginName}\". Plugin names must not contain \"/\" unless they are a scoped package (e.g. @scope/name).`,\n );\n }\n if (!PLUGIN_NAME_PATTERN.test(pluginName)) {\n throw new Error(\n `Invalid plugin name \"${pluginName}\". Expected lowercase alphanumeric with optional dashes, underscores, dots, or @scope/ prefix.`,\n );\n }\n}\n\nfunction isStability(value: unknown): value is Stability {\n return value === \"beta\" || value === \"ga\";\n}\n\nfunction findPluginManifest(\n pluginName: string,\n cwd: string,\n): { manifestPath: string; isLocal: boolean } | null {\n const dirsToScan = [\"plugins\", \"server\", \".\"];\n\n for (const dir of dirsToScan) {\n const absDir = path.resolve(cwd, dir);\n const result = scanDirForPlugin(absDir, pluginName, cwd, 0);\n if (result) return { manifestPath: result, isLocal: true };\n }\n\n // node_modules fallback. Validate and bound to the dist/plugins subtree to\n // make sure a malicious or typo'd name cannot escape via path.join.\n const nodeModulesDir = path.join(cwd, \"node_modules\", \"@databricks/appkit\");\n if (fs.existsSync(nodeModulesDir)) {\n const pluginsDir = path.join(nodeModulesDir, \"dist\", \"plugins\");\n if (fs.existsSync(pluginsDir)) {\n const manifestPath = path.resolve(\n pluginsDir,\n pluginName,\n \"manifest.json\",\n );\n if (\n isWithinDirectory(manifestPath, pluginsDir) &&\n fs.existsSync(manifestPath)\n ) {\n return { manifestPath, isLocal: false };\n }\n }\n }\n\n return null;\n}\n\nfunction scanDirForPlugin(\n dir: string,\n pluginName: string,\n cwd: string,\n depth: number,\n): string | null {\n if (depth >= MAX_SCAN_DEPTH) return null;\n let stat: fs.Stats;\n try {\n stat = fs.statSync(dir);\n } catch {\n return null;\n }\n if (!stat.isDirectory()) return null;\n\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n if (SKIP_DIRECTORIES.has(entry.name)) continue;\n if (entry.isSymbolicLink()) continue;\n const childPath = path.join(dir, entry.name);\n const allowJs = shouldAllowJsManifestForDir(childPath);\n const resolved = resolveManifestInDir(childPath, {\n allowJsManifest: allowJs,\n });\n\n if (resolved) {\n try {\n const obj = loadManifestFromFileSync(resolved.path);\n if (\n obj &&\n typeof obj === \"object\" &&\n \"name\" in obj &&\n (obj as { name: string }).name === pluginName\n ) {\n return resolved.path;\n }\n } catch {\n // skip unreadable / invalid manifest\n }\n continue;\n }\n\n const deeper = scanDirForPlugin(childPath, pluginName, cwd, depth + 1);\n if (deeper) return deeper;\n }\n return null;\n}\n\nfunction loadManifestFromFileSync(filePath: string): unknown {\n const raw = fs.readFileSync(filePath, \"utf-8\");\n return JSON.parse(raw);\n}\n\nfunction escapeRegex(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\n/**\n * Convert a kebab-case manifest name to its camelCase JS identifier form\n * (e.g. `vector-search` -> `vectorSearch`). Mirrors the convention used by\n * first-party plugin index files: a manifest's `name` field may be\n * kebab-case (the schema permits `^[a-z][a-z0-9-]*$`), but the actual\n * exported binding is always a JS identifier. We try both forms when\n * matching specifiers in user code.\n */\nfunction manifestNameToBinding(pluginName: string): string {\n return pluginName.replace(/-+([a-z0-9])/g, (_, c: string) => c.toUpperCase());\n}\n\n/**\n * Returns true when the named import specifier `spec` resolves to either\n * `pluginName` itself or its kebab-to-camelCase JS-identifier form.\n * Handles the `name`, `name as alias`, and inline-type (`type name`,\n * `type name as alias`) forms. Matches on the imported binding before any\n * `as` rename so a promotion finds the right specifier regardless of how\n * the user aliased it.\n */\nfunction specifierMatchesPlugin(spec: string, pluginName: string): boolean {\n const stripped = spec.replace(/^type\\s+/, \"\").trim();\n const head = stripped.split(/\\s+as\\s+/)[0]?.trim();\n if (!head) return false;\n return head === pluginName || head === manifestNameToBinding(pluginName);\n}\n\n/**\n * Rewrite imports of `pluginName` from `<pkg><oldSuffix>` to `<pkg><newSuffix>`\n * across one file, leaving every OTHER specifier on the same import line at\n * its original source. The naïve `split/join` approach this replaced was\n * promoting *every* beta specifier in the file along with the targeted\n * plugin — a bug because beta specifiers don't exist at the GA subpath.\n *\n * Behaviour:\n * - If the targeted plugin is the only specifier on an import line, the\n * line's source is rewritten to the new path.\n * - If the import has multiple specifiers, the targeted one is moved to a\n * newly-emitted import line at the new source, and the original import\n * keeps the remaining specifiers at the old source.\n * - Imports that don't reference `pluginName` are left untouched.\n *\n * Multi-line specifier lists, type-only imports (`import type { ... }`),\n * inline-type specifiers (`import { type Foo }`), and `as`-aliased\n * specifiers are all preserved through the rewrite.\n */\nfunction rewriteImportsInFile(\n filePath: string,\n pluginName: string,\n oldSuffix: string,\n newSuffix: string,\n dryRun: boolean,\n): { file: string; from: string; to: string } | null {\n const content = fs.readFileSync(filePath, \"utf-8\");\n\n const packages = [\n \"@databricks/appkit\",\n \"@databricks/appkit-ui/js\",\n \"@databricks/appkit-ui/react\",\n ];\n let updated = content;\n let changed = false;\n\n for (const pkg of packages) {\n const oldPath = `${pkg}${oldSuffix}`;\n const newPath = `${pkg}${newSuffix}`;\n\n // Match: `import [type] { ...specifiers... } from \"<oldPath>\";`\n // - `[^}]*` lets the specifier list span newlines (safe — TS imports\n // don't have nested braces inside the specifier list).\n // - Captures the `type ` keyword (if any), the specifier body, and\n // the surrounding quote style so we can preserve them on output.\n const importRe = new RegExp(\n `import\\\\s+(type\\\\s+)?\\\\{([^}]*)\\\\}\\\\s*from\\\\s*([\"'])${escapeRegex(oldPath)}\\\\3\\\\s*;?`,\n \"g\",\n );\n\n updated = updated.replace(\n importRe,\n (full, typeKeyword, specifiers, quote) => {\n const specList: string[] = specifiers\n .split(\",\")\n .map((s: string) => s.trim())\n .filter((s: string) => s.length > 0);\n\n const promotedSpec = specList.find((s) =>\n specifierMatchesPlugin(s, pluginName),\n );\n if (!promotedSpec) {\n // Plugin not in this import — leave it alone.\n return full;\n }\n\n const remaining = specList.filter(\n (s) => !specifierMatchesPlugin(s, pluginName),\n );\n changed = true;\n\n const tk = typeKeyword ?? \"\";\n const promotedImport = `import ${tk}{ ${promotedSpec} } from ${quote}${newPath}${quote};`;\n\n if (remaining.length === 0) {\n // Only specifier — just rewrite the source.\n return promotedImport;\n }\n\n const remainingImport = `import ${tk}{ ${remaining.join(\", \")} } from ${quote}${oldPath}${quote};`;\n return `${remainingImport}\\n${promotedImport}`;\n },\n );\n }\n\n if (!changed) return null;\n\n if (!dryRun) {\n fs.writeFileSync(filePath, updated);\n }\n\n return {\n file: filePath,\n from: oldSuffix || \"(root)\",\n to: newSuffix || \"(root)\",\n };\n}\n\nfunction findTsFiles(dir: string, projectRoot: string, depth = 0): string[] {\n if (depth >= MAX_SCAN_DEPTH) return [];\n\n const results: string[] = [];\n let entries: fs.Dirent[];\n try {\n entries = fs.readdirSync(dir, { withFileTypes: true });\n } catch {\n return results;\n }\n\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n if (entry.isSymbolicLink()) continue;\n if (entry.isDirectory()) {\n if (SKIP_DIRECTORIES.has(entry.name)) continue;\n // Boundary check to ensure recursion stays inside the project root,\n // even if a future change introduces a symlink-following path.\n if (!isWithinDirectory(fullPath, projectRoot)) continue;\n results.push(...findTsFiles(fullPath, projectRoot, depth + 1));\n } else if (entry.name.endsWith(\".ts\") || entry.name.endsWith(\".tsx\")) {\n results.push(fullPath);\n }\n }\n\n return results;\n}\n\nasync function runPromote(\n pluginName: string,\n options: {\n to: string;\n dryRun?: boolean;\n skipImports?: boolean;\n skipSync?: boolean;\n allowInstalled?: boolean;\n },\n): Promise<void> {\n validatePluginName(pluginName);\n\n const cwd = process.cwd();\n\n if (!isStability(options.to)) {\n console.error(\n `Invalid target tier \"${options.to}\". Must be one of: beta, ga.`,\n );\n process.exit(1);\n }\n const target: Stability = options.to;\n\n const found = findPluginManifest(pluginName, cwd);\n if (!found) {\n console.error(\n `Plugin \"${pluginName}\" not found. Searched local dirs (plugins, server, .) and node_modules.`,\n );\n process.exit(1);\n }\n\n const { manifestPath, isLocal } = found;\n\n if (!isLocal && !options.allowInstalled) {\n console.error(\n `Plugin \"${pluginName}\" was only found under node_modules (${path.relative(cwd, manifestPath)}).\\n` +\n `Refusing to mutate an installed package — re-install would overwrite the change.\\n` +\n `Pass --allow-installed to override (advanced; not recommended).`,\n );\n process.exit(1);\n }\n\n let raw: Record<string, unknown>;\n try {\n const parsed = loadManifestFromFileSync(manifestPath);\n if (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n console.error(\n `Manifest at ${path.relative(cwd, manifestPath)} is not a JSON object.`,\n );\n process.exit(1);\n }\n raw = parsed as Record<string, unknown>;\n } catch (err) {\n console.error(\n `Failed to read manifest at ${path.relative(cwd, manifestPath)}: ${err instanceof Error ? err.message : String(err)}`,\n );\n process.exit(1);\n }\n\n const rawStability = raw.stability ?? \"ga\";\n if (!isStability(rawStability)) {\n console.error(\n `Manifest at ${path.relative(cwd, manifestPath)} has an invalid stability value \"${String(rawStability)}\". ` +\n `Must be one of: beta, ga (or omitted for ga).`,\n );\n process.exit(1);\n }\n const currentStability: Stability = rawStability;\n\n if (currentStability === target) {\n console.error(\n `Plugin \"${pluginName}\" is already at \"${target}\". Nothing to do.`,\n );\n process.exit(1);\n }\n\n if (TIER_ORDER[target] <= TIER_ORDER[currentStability]) {\n console.error(\n `Cannot demote \"${pluginName}\" from \"${currentStability}\" to \"${target}\". Promotion is one-way only.`,\n );\n process.exit(1);\n }\n\n const prefix = options.dryRun ? \"[dry-run] \" : \"\";\n\n if (target === \"ga\") {\n delete raw.stability;\n } else {\n raw.stability = target;\n }\n\n if (!options.dryRun) {\n fs.writeFileSync(manifestPath, `${JSON.stringify(raw, null, 2)}\\n`);\n }\n console.log(\n `${prefix}Updated manifest: ${path.relative(cwd, manifestPath)} (${currentStability} → ${target})`,\n );\n\n const importRewrites: { file: string; from: string; to: string }[] = [];\n if (!options.skipImports) {\n const oldSuffix = IMPORT_PATH_MAP[currentStability];\n const newSuffix = IMPORT_PATH_MAP[target];\n\n const tsFiles = findTsFiles(cwd, cwd);\n for (const file of tsFiles) {\n const result = rewriteImportsInFile(\n file,\n pluginName,\n oldSuffix,\n newSuffix,\n Boolean(options.dryRun),\n );\n if (result) {\n importRewrites.push(result);\n console.log(\n `${prefix}Rewritten imports in: ${path.relative(cwd, file)}`,\n );\n }\n }\n\n if (importRewrites.length === 0) {\n console.log(`${prefix}No import paths to rewrite.`);\n }\n }\n\n if (!options.skipSync && !options.dryRun) {\n // Monorepo-only: regenerate every artifact derived from plugin\n // manifests (ga/beta export barrels AND the per-plugin docs-page\n // stability banner) so all manifest-derived layers move together.\n // No-op outside the AppKit monorepo (third-party plugin projects don't\n // ship the generators).\n const generatorPath = path.join(cwd, \"tools\", \"generate-plugin-entries.ts\");\n if (fs.existsSync(generatorPath)) {\n console.log(`\\n${prefix}Regenerating manifest-derived artifacts...`);\n const { execSync } = await import(\"node:child_process\");\n try {\n execSync(\"pnpm run generate:types\", { cwd, stdio: \"inherit\" });\n } catch {\n console.error(\n `Error: post-promote 'generate:types' failed. ` +\n `Manifest was updated, but generated barrels and docs banners may be stale. ` +\n `Run 'pnpm run generate:types' manually.`,\n );\n process.exit(1);\n }\n }\n\n console.log(`\\n${prefix}Running plugin sync...`);\n const { execSync } = await import(\"node:child_process\");\n // Monorepo flavor: the AppKit monorepo's `pnpm sync:template` script\n // points sync at `template/appkit.plugins.json` (the file shipped to\n // consumers and read by the Go init template), not the project-root\n // default. Detect the monorepo via the same generator-path probe used\n // above and prefer the script when available so the manifest, the\n // synced template, and the runtime barrels stay aligned.\n const syncCommand = fs.existsSync(generatorPath)\n ? \"pnpm run sync:template\"\n : \"npx appkit plugin sync --write\";\n try {\n execSync(syncCommand, {\n cwd,\n stdio: \"inherit\",\n });\n } catch {\n console.error(\n `Error: post-promote sync ('${syncCommand}') failed. ` +\n `Manifest and imports were updated, but the synced plugin manifest ` +\n `may be stale. Run '${syncCommand}' manually.`,\n );\n process.exit(1);\n }\n }\n\n console.log(\n `\\n${prefix}Promotion complete: ${pluginName} ${currentStability} → ${target}`,\n );\n if (importRewrites.length > 0) {\n console.log(` ${importRewrites.length} file(s) with import rewrites`);\n }\n}\n\n/** Exported for testing. */\nexport {\n PLUGIN_NAME_PATTERN,\n TIER_ORDER,\n IMPORT_PATH_MAP,\n SKIP_DIRECTORIES,\n isStability,\n validatePluginName,\n rewriteImportsInFile,\n runPromote,\n};\n\nexport const pluginPromoteCommand = new Command(\"promote\")\n .description(\"Promote a plugin to a higher stability tier\")\n .argument(\"<plugin-name>\", \"Plugin name to promote\")\n .requiredOption(\"--to <tier>\", \"Target stability tier (beta, ga)\")\n .option(\"--dry-run\", \"Show what would change without modifying files\")\n .option(\"--skip-imports\", \"Only update manifest, skip import path rewriting\")\n .option(\"--skip-sync\", \"Don't auto-run plugin sync after promotion\")\n .option(\n \"--allow-installed\",\n \"Allow promoting a plugin that lives only under node_modules (advanced)\",\n )\n .action((pluginName, opts) =>\n runPromote(pluginName, opts).catch((err) => {\n const message = err instanceof Error ? err.message : String(err);\n console.error(`Error: ${message}`);\n if (process.env.DEBUG) console.error(err);\n process.exit(1);\n }),\n );\n"],"mappings":";;;;;;;;;AAUA,MAAM,aAAwC;CAC5C,MAAM;CACN,IAAI;CACL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SAAQ,KAAK,EAAE;EACf,CACH"}
|
|
@@ -46,7 +46,8 @@ async function loadPluginEntry(resolved, pkg, allowJsManifest) {
|
|
|
46
46
|
description: manifest.description,
|
|
47
47
|
package: pkg,
|
|
48
48
|
resources: manifest.resources,
|
|
49
|
-
...manifest.onSetupMessage && { onSetupMessage: manifest.onSetupMessage }
|
|
49
|
+
...manifest.onSetupMessage && { onSetupMessage: manifest.onSetupMessage },
|
|
50
|
+
...manifest.stability && manifest.stability !== "ga" && { stability: manifest.stability }
|
|
50
51
|
}];
|
|
51
52
|
}
|
|
52
53
|
/**
|
|
@@ -254,7 +255,8 @@ async function scanForPlugins(cwd, packages, allowJsManifest) {
|
|
|
254
255
|
description: manifest.description,
|
|
255
256
|
package: packageName,
|
|
256
257
|
resources: manifest.resources,
|
|
257
|
-
...manifest.onSetupMessage && { onSetupMessage: manifest.onSetupMessage }
|
|
258
|
+
...manifest.onSetupMessage && { onSetupMessage: manifest.onSetupMessage },
|
|
259
|
+
...manifest.stability && manifest.stability !== "ga" && { stability: manifest.stability }
|
|
258
260
|
};
|
|
259
261
|
}
|
|
260
262
|
}
|
|
@@ -323,7 +325,7 @@ async function scanPluginsDir(dir, packageName, allowJsManifest, cwd) {
|
|
|
323
325
|
function writeManifest(outputPath, { plugins }, options) {
|
|
324
326
|
const templateManifest = {
|
|
325
327
|
$schema: "https://databricks.github.io/appkit/schemas/template-plugins.schema.json",
|
|
326
|
-
version: "1.
|
|
328
|
+
version: "1.1",
|
|
327
329
|
plugins
|
|
328
330
|
};
|
|
329
331
|
const serialized = JSON.stringify(templateManifest, null, 2);
|
|
@@ -429,6 +431,7 @@ async function runPluginsSync(options) {
|
|
|
429
431
|
for (const name of explicitNames) if (plugins[name]) plugins[name].requiredByTemplate = true;
|
|
430
432
|
else if (!options.silent) console.warn(`Warning: --require-plugins referenced "${name}" but no such plugin was discovered`);
|
|
431
433
|
}
|
|
434
|
+
for (const plugin of Object.values(plugins)) if (plugin.requiredByTemplate && plugin.stability && plugin.stability !== "ga") plugin.requiredByTemplate = void 0;
|
|
432
435
|
if (!options.silent && !options.json) {
|
|
433
436
|
console.log(`\nFound ${pluginCount} plugin(s):`);
|
|
434
437
|
for (const [name, manifest] of Object.entries(plugins)) {
|
|
@@ -438,6 +441,23 @@ async function runPluginsSync(options) {
|
|
|
438
441
|
console.log(` ${manifest.requiredByTemplate ? "●" : "○"} ${manifest.displayName} (${name}) from ${manifest.package}${resourceInfo}${mandatoryTag}`);
|
|
439
442
|
}
|
|
440
443
|
}
|
|
444
|
+
if (!options.silent && fs.existsSync(outputPath)) try {
|
|
445
|
+
const oldRaw = fs.readFileSync(outputPath, "utf-8");
|
|
446
|
+
const oldManifest = JSON.parse(oldRaw);
|
|
447
|
+
const oldNames = new Set(Object.keys(oldManifest.plugins ?? {}));
|
|
448
|
+
const newNames = new Set(Object.keys(plugins));
|
|
449
|
+
for (const name of oldNames) {
|
|
450
|
+
if (newNames.has(name)) continue;
|
|
451
|
+
const oldPlugin = oldManifest.plugins?.[name];
|
|
452
|
+
if (!oldPlugin || typeof oldPlugin !== "object") continue;
|
|
453
|
+
const envVars = [];
|
|
454
|
+
for (const res of [...oldPlugin.resources?.required ?? [], ...oldPlugin.resources?.optional ?? []]) if (res?.fields) {
|
|
455
|
+
for (const field of Object.values(res.fields)) if (field?.env) envVars.push(field.env);
|
|
456
|
+
}
|
|
457
|
+
const envInfo = envVars.length > 0 ? ` The following resource env vars may be orphaned: ${envVars.join(", ")}` : "";
|
|
458
|
+
console.warn(`Warning: Plugin "${name}" was removed.${envInfo}`);
|
|
459
|
+
}
|
|
460
|
+
} catch {}
|
|
441
461
|
writeManifest(outputPath, { plugins }, options);
|
|
442
462
|
}
|
|
443
463
|
const pluginsSyncCommand = new Command("sync").description("Sync plugin manifests from installed packages into appkit.plugins.json").option("-w, --write", "Write the manifest file").option("-o, --output <path>", "Output file path (default: ./appkit.plugins.json)").option("-s, --silent", "Suppress output and never exit with error (for use in predev/prebuild hooks)").option("--require-plugins <names>", "Comma-separated plugin names to mark as requiredByTemplate (e.g. server,analytics)").option("--plugins-dir <path>", "Scan this directory for plugin subdirectories with manifest.json (instead of node_modules)").option("--package-name <name>", "Package name to assign to plugins found via --plugins-dir (default: @databricks/appkit)").option("--local-plugins-dir <path>", "Also scan this directory for local plugin manifests (default: plugins, server)").option("--allow-js-manifest", "Allow reading manifest.js/manifest.cjs (executes code; use only with trusted plugins)").option("--json", "Output manifest as JSON to stdout").addHelpText("after", `
|
|
@@ -453,5 +473,5 @@ Examples:
|
|
|
453
473
|
}));
|
|
454
474
|
|
|
455
475
|
//#endregion
|
|
456
|
-
export { pluginsSyncCommand };
|
|
476
|
+
export { isWithinDirectory, pluginsSyncCommand };
|
|
457
477
|
//# sourceMappingURL=sync.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.js","names":[],"sources":["../../../../../src/cli/commands/plugin/sync/sync.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { Lang, parse, type SgNode } from \"@ast-grep/napi\";\nimport { Command } from \"commander\";\nimport {\n loadManifestFromFile,\n type ResolvedManifest,\n resolveManifestInDir,\n} from \"../manifest-resolve\";\nimport type {\n PluginManifest,\n TemplatePlugin,\n TemplatePluginsManifest,\n} from \"../manifest-types\";\nimport { shouldAllowJsManifestForPackage } from \"../trusted-js-manifest\";\nimport {\n formatValidationErrors,\n validateManifest,\n} from \"../validate/validate-manifest\";\n\n/**\n * Checks whether a resolved file path is within a given directory boundary.\n * Uses path.resolve + startsWith to prevent directory traversal.\n *\n * @param filePath - The path to check (will be resolved to absolute)\n * @param boundary - The directory that must contain filePath\n * @returns true if filePath is inside boundary (or equal to it)\n */\nfunction isWithinDirectory(filePath: string, boundary: string): boolean {\n const resolvedPath = path.resolve(filePath);\n const resolvedBoundary = path.resolve(boundary);\n // Append separator to avoid prefix false-positives (e.g. /foo-bar matching /foo)\n return (\n resolvedPath === resolvedBoundary ||\n resolvedPath.startsWith(`${resolvedBoundary}${path.sep}`)\n );\n}\n\n/**\n * Validates a parsed JSON object against the plugin-manifest JSON schema.\n * Returns the manifest if valid, or null and logs schema errors.\n */\nfunction validateManifestWithSchema(\n obj: unknown,\n sourcePath: string,\n): PluginManifest | null {\n const result = validateManifest(obj);\n if (result.valid && result.manifest) return result.manifest;\n if (result.errors?.length) {\n console.warn(\n `Warning: Manifest at ${sourcePath} failed schema validation:\\n${formatValidationErrors(result.errors, obj)}`,\n );\n }\n return null;\n}\n\n/** Safety limit for recursive directory scanning to prevent runaway traversal. */\nconst MAX_SCAN_DEPTH = 5;\n\n/**\n * Load and validate a resolved manifest, returning a TemplatePlugin entry or null.\n * Centralises the resolve → load → validate → build-entry pipeline used by\n * multiple discovery functions.\n */\nasync function loadPluginEntry(\n resolved: ResolvedManifest,\n pkg: string,\n allowJsManifest: boolean,\n): Promise<[string, TemplatePlugin] | null> {\n const parsed = await loadManifestFromFile(resolved.path, resolved.type, {\n allowJsManifest,\n });\n const manifest = validateManifestWithSchema(parsed, resolved.path);\n if (!manifest || manifest.hidden) return null;\n\n return [\n manifest.name,\n {\n name: manifest.name,\n displayName: manifest.displayName,\n description: manifest.description,\n package: pkg,\n resources: manifest.resources,\n ...(manifest.onSetupMessage && {\n onSetupMessage: manifest.onSetupMessage,\n }),\n },\n ];\n}\n\n/**\n * Known packages that may contain AppKit plugins.\n * Always scanned for manifests, even if not imported in the server file.\n */\nconst KNOWN_PLUGIN_PACKAGES = [\"@databricks/appkit\"];\n\n/**\n * Candidate paths for the server entry file, relative to cwd.\n * Checked in order; the first that exists is used.\n */\nconst SERVER_FILE_CANDIDATES = [\"server/server.ts\", \"server/index.ts\"];\n\n/**\n * Conventional directories to scan for local plugin manifests when\n * --local-plugins-dir is not set. Checked in order; each that exists is scanned.\n * Plugins found here are added to the manifest even if not imported in the server.\n */\nconst CONVENTIONAL_LOCAL_PLUGIN_DIRS = [\"plugins\", \"server\"];\n\n/**\n * Find the server entry file by checking candidate paths in order.\n *\n * @param cwd - Current working directory\n * @returns Absolute path to the server file, or null if none found\n */\nfunction findServerFile(cwd: string): string | null {\n for (const candidate of SERVER_FILE_CANDIDATES) {\n const fullPath = path.join(cwd, candidate);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n return null;\n}\n\n/**\n * Represents a single named import extracted from the server file.\n */\ninterface ParsedImport {\n /** The imported name (or local alias if renamed) */\n name: string;\n /** The original exported name (differs from name when using `import { foo as bar }`) */\n originalName: string;\n /** The module specifier (package name or relative path) */\n source: string;\n}\n\n/**\n * Extract all named imports from the AST root using structural node traversal.\n * Handles single/double quotes, multiline imports, and aliased imports.\n *\n * @param root - AST root node\n * @returns Array of parsed imports with name, original name, and source\n */\nfunction parseImports(root: SgNode): ParsedImport[] {\n const imports: ParsedImport[] = [];\n\n // Find all import_statement nodes in the AST\n const importStatements = root.findAll({\n rule: { kind: \"import_statement\" },\n });\n\n for (const stmt of importStatements) {\n // Extract the module specifier (the string node, e.g. '@databricks/appkit')\n const sourceNode = stmt.find({ rule: { kind: \"string\" } });\n if (!sourceNode) continue;\n\n // Strip surrounding quotes from the string node text\n const source = sourceNode.text().replace(/^['\"]|['\"]$/g, \"\");\n\n // Find named_imports block: { createApp, analytics, server }\n const namedImports = stmt.find({ rule: { kind: \"named_imports\" } });\n if (!namedImports) continue;\n\n // Extract each import_specifier\n const specifiers = namedImports.findAll({\n rule: { kind: \"import_specifier\" },\n });\n\n for (const specifier of specifiers) {\n const children = specifier.children();\n if (children.length >= 3) {\n // Aliased import: `foo as bar` — children are [name, \"as\", alias]\n const originalName = children[0].text();\n const localName = children[children.length - 1].text();\n imports.push({ name: localName, originalName, source });\n } else {\n // Simple import: `foo`\n const name = specifier.text();\n imports.push({ name, originalName: name, source });\n }\n }\n }\n\n return imports;\n}\n\n/**\n * Extract local names of plugins actually used in the `plugins: [...]` array\n * passed to `createApp()`. Uses structural AST traversal to find `pair` nodes\n * with key \"plugins\" and array values containing call expressions.\n *\n * @param root - AST root node\n * @returns Set of local variable names used as plugin calls in the plugins array\n */\nfunction parsePluginUsages(root: SgNode): Set<string> {\n const usedNames = new Set<string>();\n\n // Find all property pairs in the AST\n const pairs = root.findAll({ rule: { kind: \"pair\" } });\n\n for (const pair of pairs) {\n // Check if the property key is \"plugins\"\n const key = pair.find({ rule: { kind: \"property_identifier\" } });\n if (!key || key.text() !== \"plugins\") continue;\n\n // Find the array value\n const arrayNode = pair.find({ rule: { kind: \"array\" } });\n if (!arrayNode) continue;\n\n // Iterate direct children of the array to find call expressions\n for (const child of arrayNode.children()) {\n if (child.kind() === \"call_expression\") {\n // The callee is the first child (the identifier being called)\n const callee = child.children()[0];\n if (callee?.kind() === \"identifier\") {\n usedNames.add(callee.text());\n }\n }\n }\n }\n\n return usedNames;\n}\n\n/**\n * File extensions to try when resolving a relative import to a file path.\n */\nconst RESOLVE_EXTENSIONS = [\".ts\", \".tsx\", \".js\", \".jsx\"];\n\n/**\n * Resolve a relative import source to the plugin directory containing a manifest\n * (manifest.json or manifest.js). Follows the convention that plugins live in\n * their own directory with a manifest file.\n *\n * Resolution strategy:\n * 1. If the import path is a directory, look for manifest.json/js in it\n * 2. If the import path + extension is a file, look for manifest in its parent directory\n * 3. If the import path is a directory with an index file, look for manifest in that directory\n *\n * @param importSource - The relative import specifier (e.g. \"./plugins/my-plugin\")\n * @param serverFileDir - Absolute path to the directory containing the server file\n * @returns Resolved manifest file path and type, or null if not found\n */\nfunction resolveLocalManifest(\n importSource: string,\n serverFileDir: string,\n allowJsManifest: boolean,\n projectRoot?: string,\n): ResolvedManifest | null {\n const resolved = path.resolve(serverFileDir, importSource);\n\n // Security: Reject paths that escape the project root\n const boundary = projectRoot || serverFileDir;\n if (!isWithinDirectory(resolved, boundary)) {\n console.warn(\n `Warning: Skipping import \"${importSource}\" — resolves outside the project directory`,\n );\n return null;\n }\n\n // Case 1: Import path is a directory\n if (fs.existsSync(resolved) && fs.statSync(resolved).isDirectory()) {\n return resolveManifestInDir(resolved, { allowJsManifest });\n }\n\n // Case 2: Import path + extension resolves to a file — manifest in parent dir\n for (const ext of RESOLVE_EXTENSIONS) {\n const filePath = `${resolved}${ext}`;\n if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {\n const dir = path.dirname(filePath);\n if (!isWithinDirectory(dir, boundary)) return null;\n return resolveManifestInDir(dir, { allowJsManifest });\n }\n }\n\n // Case 3: Import path is a directory with an index file\n for (const ext of RESOLVE_EXTENSIONS) {\n const indexPath = path.join(resolved, `index${ext}`);\n if (fs.existsSync(indexPath)) {\n return resolveManifestInDir(resolved, { allowJsManifest });\n }\n }\n\n return null;\n}\n\n/**\n * Discover plugin manifests from local (relative) imports in the server file.\n * Resolves each relative import to a directory and loads manifest.json or manifest.js.\n *\n * @param relativeImports - Parsed imports with relative sources (starting with . or /)\n * @param serverFileDir - Absolute path to the directory containing the server file\n * @param cwd - Current working directory (for computing relative paths in output)\n * @returns Map of plugin name to template plugin entry for local plugins\n */\nasync function discoverLocalPlugins(\n relativeImports: ParsedImport[],\n serverFileDir: string,\n cwd: string,\n allowJsManifest: boolean,\n): Promise<TemplatePluginsManifest[\"plugins\"]> {\n const plugins: TemplatePluginsManifest[\"plugins\"] = {};\n\n for (const imp of relativeImports) {\n const resolved = resolveLocalManifest(\n imp.source,\n serverFileDir,\n allowJsManifest,\n cwd,\n );\n if (!resolved) continue;\n\n try {\n const relativePath = path.relative(cwd, path.dirname(resolved.path));\n const entry = await loadPluginEntry(\n resolved,\n `./${relativePath}`,\n allowJsManifest,\n );\n if (entry) plugins[entry[0]] = entry[1];\n } catch (error) {\n console.warn(\n `Warning: Failed to load manifest at ${resolved.path}:`,\n error instanceof Error ? error.message : error,\n );\n }\n }\n\n return plugins;\n}\n\n/**\n * Discover plugin manifests from a package's dist folder.\n * Looks for manifest.json or manifest.js in dist/plugins/{plugin-name}/ directories.\n *\n * @param packagePath - Path to the package in node_modules\n * @returns Array of plugin manifests found in the package\n */\nasync function discoverPluginManifests(\n packagePath: string,\n allowJsManifest: boolean,\n): Promise<PluginManifest[]> {\n const pluginsDir = path.join(packagePath, \"dist\", \"plugins\");\n const manifests: PluginManifest[] = [];\n\n if (!fs.existsSync(pluginsDir)) {\n return manifests;\n }\n\n const entries = fs.readdirSync(pluginsDir, { withFileTypes: true });\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n const resolved = resolveManifestInDir(path.join(pluginsDir, entry.name), {\n allowJsManifest,\n });\n if (!resolved) continue;\n\n try {\n const parsed = await loadManifestFromFile(resolved.path, resolved.type, {\n allowJsManifest,\n });\n const manifest = validateManifestWithSchema(parsed, resolved.path);\n if (manifest) {\n manifests.push(manifest);\n }\n } catch (error) {\n console.warn(\n `Warning: Failed to load manifest at ${resolved.path}:`,\n error instanceof Error ? error.message : error,\n );\n }\n }\n\n return manifests;\n}\n\n/**\n * Scan node_modules for packages with plugin manifests.\n *\n * @param cwd - Current working directory to search from\n * @param packages - Set of npm package names to scan for plugin manifests\n * @returns Map of plugin name to template plugin entry\n */\nasync function scanForPlugins(\n cwd: string,\n packages: Iterable<string>,\n allowJsManifest: boolean,\n): Promise<TemplatePluginsManifest[\"plugins\"]> {\n const plugins: TemplatePluginsManifest[\"plugins\"] = {};\n\n for (const packageName of packages) {\n const packagePath = path.join(cwd, \"node_modules\", packageName);\n if (!fs.existsSync(packagePath)) {\n continue;\n }\n\n const allowJsForPackage =\n allowJsManifest || shouldAllowJsManifestForPackage(packageName);\n\n const manifests = await discoverPluginManifests(\n packagePath,\n allowJsForPackage,\n );\n for (const manifest of manifests) {\n if (manifest.hidden) continue;\n plugins[manifest.name] = {\n name: manifest.name,\n displayName: manifest.displayName,\n description: manifest.description,\n package: packageName,\n resources: manifest.resources,\n ...(manifest.onSetupMessage && {\n onSetupMessage: manifest.onSetupMessage,\n }),\n } satisfies TemplatePlugin;\n }\n }\n\n return plugins;\n}\n\n/**\n * Recursively scan a directory for plugin manifests. Any directory that\n * contains manifest.json or manifest.js is treated as a plugin root; we do\n * not descend into that directory's children. Used for local plugins discovery\n * so nested paths like server/plugins/category/my-plugin are found.\n */\nasync function scanPluginsDirRecursive(\n dir: string,\n cwd: string,\n allowJsManifest: boolean,\n depth = 0,\n): Promise<TemplatePluginsManifest[\"plugins\"]> {\n const plugins: TemplatePluginsManifest[\"plugins\"] = {};\n if (!fs.existsSync(dir) || depth >= MAX_SCAN_DEPTH) return plugins;\n\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n\n const pluginDir = path.join(dir, entry.name);\n const resolved = resolveManifestInDir(pluginDir, { allowJsManifest });\n\n if (resolved) {\n const pkg = `./${path.relative(cwd, pluginDir)}`;\n try {\n const pluginEntry = await loadPluginEntry(\n resolved,\n pkg,\n allowJsManifest,\n );\n if (pluginEntry) plugins[pluginEntry[0]] = pluginEntry[1];\n } catch (error) {\n console.warn(\n `Warning: Failed to load manifest at ${resolved.path}:`,\n error instanceof Error ? error.message : error,\n );\n }\n continue;\n }\n\n Object.assign(\n plugins,\n await scanPluginsDirRecursive(pluginDir, cwd, allowJsManifest, depth + 1),\n );\n }\n\n return plugins;\n}\n\n/**\n * Scan a directory for plugin manifests in direct subdirectories only.\n * Each subdirectory may contain manifest.json or manifest.js.\n * Used with --plugins-dir to discover plugins from source instead of node_modules.\n *\n * @param dir - Absolute path to the directory containing plugin subdirectories\n * @param packageName - Package name to assign to discovered plugins (used when cwd is not set)\n * @param cwd - When set, each plugin's package is set to ./<path from cwd to plugin subdir>, e.g. ./server/my-plugin\n * @returns Map of plugin name to template plugin entry\n */\nasync function scanPluginsDir(\n dir: string,\n packageName: string,\n allowJsManifest: boolean,\n cwd?: string,\n): Promise<TemplatePluginsManifest[\"plugins\"]> {\n const plugins: TemplatePluginsManifest[\"plugins\"] = {};\n\n if (!fs.existsSync(dir)) return plugins;\n\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n\n const pluginDir = path.join(dir, entry.name);\n const resolved = resolveManifestInDir(pluginDir, { allowJsManifest });\n if (!resolved) continue;\n\n const pkg =\n cwd !== undefined ? `./${path.relative(cwd, pluginDir)}` : packageName;\n\n try {\n const pluginEntry = await loadPluginEntry(resolved, pkg, allowJsManifest);\n if (pluginEntry) plugins[pluginEntry[0]] = pluginEntry[1];\n } catch (error) {\n console.warn(\n `Warning: Failed to load manifest at ${resolved.path}:`,\n error instanceof Error ? error.message : error,\n );\n }\n }\n\n return plugins;\n}\n\n/**\n * Write (or preview) the template plugins manifest to disk.\n */\nfunction writeManifest(\n outputPath: string,\n { plugins }: { plugins: TemplatePluginsManifest[\"plugins\"] },\n options: { write?: boolean; silent?: boolean; json?: boolean },\n) {\n const templateManifest: TemplatePluginsManifest = {\n $schema:\n \"https://databricks.github.io/appkit/schemas/template-plugins.schema.json\",\n version: \"1.0\",\n plugins,\n };\n\n const serialized = JSON.stringify(templateManifest, null, 2);\n\n if (options.json) {\n console.log(serialized);\n }\n\n if (options.write) {\n fs.writeFileSync(outputPath, `${serialized}\\n`);\n if (!options.silent && !options.json) {\n console.log(`\\n✓ Wrote ${outputPath}`);\n }\n } else if (!options.silent && !options.json) {\n console.log(\"\\nTo write the manifest, run:\");\n console.log(\" npx appkit plugin sync --write\\n\");\n console.log(\"Preview:\");\n console.log(\"─\".repeat(60));\n console.log(serialized);\n console.log(\"─\".repeat(60));\n }\n}\n\n/**\n * Run the plugin sync command.\n * Parses the server entry file to discover which packages to scan for plugin\n * manifests, then marks plugins that are actually used in the `plugins: [...]`\n * array as requiredByTemplate.\n */\nasync function runPluginsSync(options: {\n write?: boolean;\n output?: string;\n silent?: boolean;\n json?: boolean;\n requirePlugins?: string;\n pluginsDir?: string;\n packageName?: string;\n localPluginsDir?: string;\n allowJsManifest?: boolean;\n}): Promise<void> {\n const cwd = process.cwd();\n const allowJsManifest = Boolean(options.allowJsManifest);\n const outputPath = path.resolve(cwd, options.output || \"appkit.plugins.json\");\n\n // Security: Reject output paths that escape the project root\n if (!isWithinDirectory(outputPath, cwd)) {\n console.error(\n `Error: Output path \"${options.output}\" resolves outside the project directory.`,\n );\n process.exit(1);\n }\n\n if (!options.silent && !options.json) {\n console.log(\"Scanning for AppKit plugins...\\n\");\n if (allowJsManifest) {\n console.warn(\n \"Warning: --allow-js-manifest executes manifest.js/manifest.cjs files. Only use with trusted code.\",\n );\n }\n }\n\n // Step 1: Parse server file to discover imports and plugin usages\n const serverFile = findServerFile(cwd);\n let serverImports: ParsedImport[] = [];\n let pluginUsages = new Set<string>();\n\n if (serverFile) {\n if (!options.silent && !options.json) {\n const relativePath = path.relative(cwd, serverFile);\n console.log(`Server entry file: ${relativePath}`);\n }\n\n const content = fs.readFileSync(serverFile, \"utf-8\");\n const lang = serverFile.endsWith(\".tsx\") ? Lang.Tsx : Lang.TypeScript;\n const ast = parse(lang, content);\n const root = ast.root();\n\n serverImports = parseImports(root);\n pluginUsages = parsePluginUsages(root);\n } else if (!options.silent && !options.json) {\n console.log(\n \"No server entry file found. Checked:\",\n SERVER_FILE_CANDIDATES.join(\", \"),\n );\n }\n\n // Step 2: Split imports into npm packages and local (relative) imports\n const npmImports = serverImports.filter(\n (i) => !i.source.startsWith(\".\") && !i.source.startsWith(\"/\"),\n );\n const localImports = serverImports.filter(\n (i) => i.source.startsWith(\".\") || i.source.startsWith(\"/\"),\n );\n\n // Step 3: Scan for plugin manifests (--plugins-dir or node_modules)\n const plugins: TemplatePluginsManifest[\"plugins\"] = {};\n\n if (options.pluginsDir) {\n const resolvedDir = path.resolve(cwd, options.pluginsDir);\n const pkgName = options.packageName ?? \"@databricks/appkit\";\n if (!options.silent && !options.json) {\n console.log(`Scanning plugins directory: ${options.pluginsDir}`);\n }\n Object.assign(\n plugins,\n await scanPluginsDir(resolvedDir, pkgName, allowJsManifest),\n );\n } else {\n const npmPackages = new Set([\n ...KNOWN_PLUGIN_PACKAGES,\n ...npmImports.map((i) => i.source),\n ]);\n Object.assign(\n plugins,\n await scanForPlugins(cwd, npmPackages, allowJsManifest),\n );\n }\n\n // Step 4: Discover local plugin manifests from relative imports\n if (serverFile && localImports.length > 0) {\n const serverFileDir = path.dirname(serverFile);\n const localPlugins = await discoverLocalPlugins(\n localImports,\n serverFileDir,\n cwd,\n allowJsManifest,\n );\n Object.assign(plugins, localPlugins);\n }\n\n // Step 4b: Discover local plugins from conventional directory (or --local-plugins-dir).\n // These are included even when not imported in the server.\n const localDirsToScan: string[] = options.localPluginsDir\n ? [options.localPluginsDir]\n : CONVENTIONAL_LOCAL_PLUGIN_DIRS.filter((d) =>\n fs.existsSync(path.join(cwd, d)),\n );\n for (const dir of localDirsToScan) {\n const resolvedDir = path.resolve(cwd, dir);\n if (!fs.existsSync(resolvedDir)) continue;\n if (!options.silent && !options.json) {\n console.log(`Scanning local plugins directory: ${dir}`);\n }\n const discovered = await scanPluginsDirRecursive(\n resolvedDir,\n cwd,\n allowJsManifest,\n );\n for (const [name, entry] of Object.entries(discovered)) {\n if (!plugins[name]) plugins[name] = entry;\n }\n }\n\n const pluginCount = Object.keys(plugins).length;\n\n if (pluginCount === 0) {\n if (options.silent || options.json) {\n writeManifest(outputPath, { plugins: {} }, options);\n if (options.silent) return;\n process.exit(1);\n }\n console.log(\"No plugins found.\");\n if (options.pluginsDir) {\n console.log(\n `\\nNo manifest (${allowJsManifest ? \"manifest.json or manifest.js\" : \"manifest.json\"}) found in: ${options.pluginsDir}`,\n );\n } else {\n console.log(\n \"\\nMake sure you have plugin packages installed, or specify a directory:\",\n );\n console.log(\" appkit plugin sync --plugins-dir <path>\");\n }\n process.exit(1);\n }\n\n // Step 5: Mark plugins that are imported AND used in the plugins array as mandatory.\n // For npm imports, match by package name + plugin name.\n // For local imports, resolve both paths to absolute and compare.\n const serverFileDir = serverFile ? path.dirname(serverFile) : cwd;\n\n for (const imp of serverImports) {\n if (!pluginUsages.has(imp.name)) continue;\n\n const isLocal = imp.source.startsWith(\".\") || imp.source.startsWith(\"/\");\n let plugin: TemplatePlugin | undefined;\n\n if (isLocal) {\n // Resolve the import source to an absolute path from the server file directory\n const resolvedImportDir = path.resolve(serverFileDir, imp.source);\n plugin = Object.values(plugins).find((p) => {\n if (!p.package.startsWith(\".\")) return false;\n const resolvedPluginDir = path.resolve(cwd, p.package);\n return (\n resolvedPluginDir === resolvedImportDir && p.name === imp.originalName\n );\n });\n } else {\n // npm import: direct string comparison\n plugin = Object.values(plugins).find(\n (p) => p.package === imp.source && p.name === imp.originalName,\n );\n }\n\n if (plugin) {\n plugin.requiredByTemplate = true;\n }\n }\n\n // Step 6: Apply explicit --require-plugins overrides\n if (options.requirePlugins) {\n const explicitNames = options.requirePlugins\n .split(\",\")\n .map((s) => s.trim())\n .filter(Boolean);\n for (const name of explicitNames) {\n if (plugins[name]) {\n plugins[name].requiredByTemplate = true;\n } else if (!options.silent) {\n console.warn(\n `Warning: --require-plugins referenced \"${name}\" but no such plugin was discovered`,\n );\n }\n }\n }\n\n if (!options.silent && !options.json) {\n console.log(`\\nFound ${pluginCount} plugin(s):`);\n for (const [name, manifest] of Object.entries(plugins)) {\n const resourceCount =\n manifest.resources.required.length + manifest.resources.optional.length;\n const resourceInfo =\n resourceCount > 0 ? ` [${resourceCount} resource(s)]` : \"\";\n const mandatoryTag = manifest.requiredByTemplate ? \" (mandatory)\" : \"\";\n console.log(\n ` ${manifest.requiredByTemplate ? \"●\" : \"○\"} ${manifest.displayName} (${name}) from ${manifest.package}${resourceInfo}${mandatoryTag}`,\n );\n }\n }\n\n writeManifest(outputPath, { plugins }, options);\n}\n\n/** Exported for testing: path boundary check, AST parsing, trust checks. */\nexport {\n isWithinDirectory,\n parseImports,\n parsePluginUsages,\n shouldAllowJsManifestForPackage,\n};\n\nexport const pluginsSyncCommand = new Command(\"sync\")\n .description(\n \"Sync plugin manifests from installed packages into appkit.plugins.json\",\n )\n .option(\"-w, --write\", \"Write the manifest file\")\n .option(\n \"-o, --output <path>\",\n \"Output file path (default: ./appkit.plugins.json)\",\n )\n .option(\n \"-s, --silent\",\n \"Suppress output and never exit with error (for use in predev/prebuild hooks)\",\n )\n .option(\n \"--require-plugins <names>\",\n \"Comma-separated plugin names to mark as requiredByTemplate (e.g. server,analytics)\",\n )\n .option(\n \"--plugins-dir <path>\",\n \"Scan this directory for plugin subdirectories with manifest.json (instead of node_modules)\",\n )\n .option(\n \"--package-name <name>\",\n \"Package name to assign to plugins found via --plugins-dir (default: @databricks/appkit)\",\n )\n .option(\n \"--local-plugins-dir <path>\",\n \"Also scan this directory for local plugin manifests (default: plugins, server)\",\n )\n .option(\n \"--allow-js-manifest\",\n \"Allow reading manifest.js/manifest.cjs (executes code; use only with trusted plugins)\",\n )\n .option(\"--json\", \"Output manifest as JSON to stdout\")\n .addHelpText(\n \"after\",\n `\nExamples:\n $ appkit plugin sync\n $ appkit plugin sync --write\n $ appkit plugin sync --write --require-plugins server,analytics\n $ appkit plugin sync --write --plugins-dir src/plugins --package-name @my/pkg\n $ appkit plugin sync --json\n $ appkit plugin sync --silent`,\n )\n .action((opts) =>\n runPluginsSync(opts).catch((err) => {\n console.error(err);\n process.exit(1);\n }),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;AA4BA,SAAS,kBAAkB,UAAkB,UAA2B;CACtE,MAAM,eAAe,KAAK,QAAQ,SAAS;CAC3C,MAAM,mBAAmB,KAAK,QAAQ,SAAS;AAE/C,QACE,iBAAiB,oBACjB,aAAa,WAAW,GAAG,mBAAmB,KAAK,MAAM;;;;;;AAQ7D,SAAS,2BACP,KACA,YACuB;CACvB,MAAM,SAAS,iBAAiB,IAAI;AACpC,KAAI,OAAO,SAAS,OAAO,SAAU,QAAO,OAAO;AACnD,KAAI,OAAO,QAAQ,OACjB,SAAQ,KACN,wBAAwB,WAAW,8BAA8B,uBAAuB,OAAO,QAAQ,IAAI,GAC5G;AAEH,QAAO;;;AAIT,MAAM,iBAAiB;;;;;;AAOvB,eAAe,gBACb,UACA,KACA,iBAC0C;CAI1C,MAAM,WAAW,2BAHF,MAAM,qBAAqB,SAAS,MAAM,SAAS,MAAM,EACtE,iBACD,CAAC,EACkD,S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,QAAQ,OAClB,SAAQ,KACN,0CAA0C,KAAK,qCAChD;;AAKP,KAAI,CAAC,QAAQ,UAAU,CAAC,QAAQ,MAAM;AACpC,UAAQ,IAAI,WAAW,YAAY,aAAa;AAChD,OAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,QAAQ,EAAE;GACtD,MAAM,gBACJ,SAAS,UAAU,SAAS,SAAS,SAAS,UAAU,SAAS;GACnE,MAAM,eACJ,gBAAgB,IAAI,KAAK,cAAc,iBAAiB;GAC1D,MAAM,eAAe,SAAS,qBAAqB,iBAAiB;AACpE,WAAQ,IACN,KAAK,SAAS,qBAAqB,MAAM,IAAI,GAAG,SAAS,YAAY,IAAI,KAAK,SAAS,SAAS,UAAU,eAAe,eAC1H;;;AAIL,eAAc,YAAY,EAAE,SAAS,EAAE,QAAQ;;AAWjD,MAAa,qBAAqB,IAAI,QAAQ,OAAO,CAClD,YACC,yEACD,CACA,OAAO,eAAe,0BAA0B,CAChD,OACC,uBACA,oDACD,CACA,OACC,gBACA,+EACD,CACA,OACC,6BACA,qFACD,CACA,OACC,wBACA,6FACD,CACA,OACC,yBACA,0FACD,CACA,OACC,8BACA,iFACD,CACA,OACC,uBACA,wFACD,CACA,OAAO,UAAU,oCAAoC,CACrD,YACC,SACA;;;;;;;iCAQD,CACA,QAAQ,SACP,eAAe,KAAK,CAAC,OAAO,QAAQ;AAClC,SAAQ,MAAM,IAAI;AAClB,SAAQ,KAAK,EAAE;EACf,CACH"}
|
|
1
|
+
{"version":3,"file":"sync.js","names":[],"sources":["../../../../../src/cli/commands/plugin/sync/sync.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { Lang, parse, type SgNode } from \"@ast-grep/napi\";\nimport { Command } from \"commander\";\nimport {\n loadManifestFromFile,\n type ResolvedManifest,\n resolveManifestInDir,\n} from \"../manifest-resolve\";\nimport type {\n PluginManifest,\n TemplatePlugin,\n TemplatePluginsManifest,\n} from \"../manifest-types\";\nimport { shouldAllowJsManifestForPackage } from \"../trusted-js-manifest\";\nimport {\n formatValidationErrors,\n validateManifest,\n} from \"../validate/validate-manifest\";\n\n/**\n * Checks whether a resolved file path is within a given directory boundary.\n * Uses path.resolve + startsWith to prevent directory traversal.\n *\n * @param filePath - The path to check (will be resolved to absolute)\n * @param boundary - The directory that must contain filePath\n * @returns true if filePath is inside boundary (or equal to it)\n */\nfunction isWithinDirectory(filePath: string, boundary: string): boolean {\n const resolvedPath = path.resolve(filePath);\n const resolvedBoundary = path.resolve(boundary);\n // Append separator to avoid prefix false-positives (e.g. /foo-bar matching /foo)\n return (\n resolvedPath === resolvedBoundary ||\n resolvedPath.startsWith(`${resolvedBoundary}${path.sep}`)\n );\n}\n\n/**\n * Validates a parsed JSON object against the plugin-manifest JSON schema.\n * Returns the manifest if valid, or null and logs schema errors.\n */\nfunction validateManifestWithSchema(\n obj: unknown,\n sourcePath: string,\n): PluginManifest | null {\n const result = validateManifest(obj);\n if (result.valid && result.manifest) return result.manifest;\n if (result.errors?.length) {\n console.warn(\n `Warning: Manifest at ${sourcePath} failed schema validation:\\n${formatValidationErrors(result.errors, obj)}`,\n );\n }\n return null;\n}\n\n/** Safety limit for recursive directory scanning to prevent runaway traversal. */\nconst MAX_SCAN_DEPTH = 5;\n\n/**\n * Load and validate a resolved manifest, returning a TemplatePlugin entry or null.\n * Centralises the resolve → load → validate → build-entry pipeline used by\n * multiple discovery functions.\n */\nasync function loadPluginEntry(\n resolved: ResolvedManifest,\n pkg: string,\n allowJsManifest: boolean,\n): Promise<[string, TemplatePlugin] | null> {\n const parsed = await loadManifestFromFile(resolved.path, resolved.type, {\n allowJsManifest,\n });\n const manifest = validateManifestWithSchema(parsed, resolved.path);\n if (!manifest || manifest.hidden) return null;\n\n return [\n manifest.name,\n {\n name: manifest.name,\n displayName: manifest.displayName,\n description: manifest.description,\n package: pkg,\n resources: manifest.resources,\n ...(manifest.onSetupMessage && {\n onSetupMessage: manifest.onSetupMessage,\n }),\n // Narrowing on `!== \"ga\"` removes \"ga\"; the truthy check\n // removes `undefined`. What's left is the non-GA tier set,\n // which TypeScript already knows is assignable to TemplatePlugin's\n // `stability` field — so no cast is needed and adding a future\n // tier (e.g. \"alpha\") flows through type-correctly.\n ...(manifest.stability &&\n manifest.stability !== \"ga\" && {\n stability: manifest.stability,\n }),\n },\n ];\n}\n\n/**\n * Known packages that may contain AppKit plugins.\n * Always scanned for manifests, even if not imported in the server file.\n */\nconst KNOWN_PLUGIN_PACKAGES = [\"@databricks/appkit\"];\n\n/**\n * Candidate paths for the server entry file, relative to cwd.\n * Checked in order; the first that exists is used.\n */\nconst SERVER_FILE_CANDIDATES = [\"server/server.ts\", \"server/index.ts\"];\n\n/**\n * Conventional directories to scan for local plugin manifests when\n * --local-plugins-dir is not set. Checked in order; each that exists is scanned.\n * Plugins found here are added to the manifest even if not imported in the server.\n */\nconst CONVENTIONAL_LOCAL_PLUGIN_DIRS = [\"plugins\", \"server\"];\n\n/**\n * Find the server entry file by checking candidate paths in order.\n *\n * @param cwd - Current working directory\n * @returns Absolute path to the server file, or null if none found\n */\nfunction findServerFile(cwd: string): string | null {\n for (const candidate of SERVER_FILE_CANDIDATES) {\n const fullPath = path.join(cwd, candidate);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n return null;\n}\n\n/**\n * Represents a single named import extracted from the server file.\n */\ninterface ParsedImport {\n /** The imported name (or local alias if renamed) */\n name: string;\n /** The original exported name (differs from name when using `import { foo as bar }`) */\n originalName: string;\n /** The module specifier (package name or relative path) */\n source: string;\n}\n\n/**\n * Extract all named imports from the AST root using structural node traversal.\n * Handles single/double quotes, multiline imports, and aliased imports.\n *\n * @param root - AST root node\n * @returns Array of parsed imports with name, original name, and source\n */\nfunction parseImports(root: SgNode): ParsedImport[] {\n const imports: ParsedImport[] = [];\n\n // Find all import_statement nodes in the AST\n const importStatements = root.findAll({\n rule: { kind: \"import_statement\" },\n });\n\n for (const stmt of importStatements) {\n // Extract the module specifier (the string node, e.g. '@databricks/appkit')\n const sourceNode = stmt.find({ rule: { kind: \"string\" } });\n if (!sourceNode) continue;\n\n // Strip surrounding quotes from the string node text\n const source = sourceNode.text().replace(/^['\"]|['\"]$/g, \"\");\n\n // Find named_imports block: { createApp, analytics, server }\n const namedImports = stmt.find({ rule: { kind: \"named_imports\" } });\n if (!namedImports) continue;\n\n // Extract each import_specifier\n const specifiers = namedImports.findAll({\n rule: { kind: \"import_specifier\" },\n });\n\n for (const specifier of specifiers) {\n const children = specifier.children();\n if (children.length >= 3) {\n // Aliased import: `foo as bar` — children are [name, \"as\", alias]\n const originalName = children[0].text();\n const localName = children[children.length - 1].text();\n imports.push({ name: localName, originalName, source });\n } else {\n // Simple import: `foo`\n const name = specifier.text();\n imports.push({ name, originalName: name, source });\n }\n }\n }\n\n return imports;\n}\n\n/**\n * Extract local names of plugins actually used in the `plugins: [...]` array\n * passed to `createApp()`. Uses structural AST traversal to find `pair` nodes\n * with key \"plugins\" and array values containing call expressions.\n *\n * @param root - AST root node\n * @returns Set of local variable names used as plugin calls in the plugins array\n */\nfunction parsePluginUsages(root: SgNode): Set<string> {\n const usedNames = new Set<string>();\n\n // Find all property pairs in the AST\n const pairs = root.findAll({ rule: { kind: \"pair\" } });\n\n for (const pair of pairs) {\n // Check if the property key is \"plugins\"\n const key = pair.find({ rule: { kind: \"property_identifier\" } });\n if (!key || key.text() !== \"plugins\") continue;\n\n // Find the array value\n const arrayNode = pair.find({ rule: { kind: \"array\" } });\n if (!arrayNode) continue;\n\n // Iterate direct children of the array to find call expressions\n for (const child of arrayNode.children()) {\n if (child.kind() === \"call_expression\") {\n // The callee is the first child (the identifier being called)\n const callee = child.children()[0];\n if (callee?.kind() === \"identifier\") {\n usedNames.add(callee.text());\n }\n }\n }\n }\n\n return usedNames;\n}\n\n/**\n * File extensions to try when resolving a relative import to a file path.\n */\nconst RESOLVE_EXTENSIONS = [\".ts\", \".tsx\", \".js\", \".jsx\"];\n\n/**\n * Resolve a relative import source to the plugin directory containing a manifest\n * (manifest.json or manifest.js). Follows the convention that plugins live in\n * their own directory with a manifest file.\n *\n * Resolution strategy:\n * 1. If the import path is a directory, look for manifest.json/js in it\n * 2. If the import path + extension is a file, look for manifest in its parent directory\n * 3. If the import path is a directory with an index file, look for manifest in that directory\n *\n * @param importSource - The relative import specifier (e.g. \"./plugins/my-plugin\")\n * @param serverFileDir - Absolute path to the directory containing the server file\n * @returns Resolved manifest file path and type, or null if not found\n */\nfunction resolveLocalManifest(\n importSource: string,\n serverFileDir: string,\n allowJsManifest: boolean,\n projectRoot?: string,\n): ResolvedManifest | null {\n const resolved = path.resolve(serverFileDir, importSource);\n\n // Security: Reject paths that escape the project root\n const boundary = projectRoot || serverFileDir;\n if (!isWithinDirectory(resolved, boundary)) {\n console.warn(\n `Warning: Skipping import \"${importSource}\" — resolves outside the project directory`,\n );\n return null;\n }\n\n // Case 1: Import path is a directory\n if (fs.existsSync(resolved) && fs.statSync(resolved).isDirectory()) {\n return resolveManifestInDir(resolved, { allowJsManifest });\n }\n\n // Case 2: Import path + extension resolves to a file — manifest in parent dir\n for (const ext of RESOLVE_EXTENSIONS) {\n const filePath = `${resolved}${ext}`;\n if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {\n const dir = path.dirname(filePath);\n if (!isWithinDirectory(dir, boundary)) return null;\n return resolveManifestInDir(dir, { allowJsManifest });\n }\n }\n\n // Case 3: Import path is a directory with an index file\n for (const ext of RESOLVE_EXTENSIONS) {\n const indexPath = path.join(resolved, `index${ext}`);\n if (fs.existsSync(indexPath)) {\n return resolveManifestInDir(resolved, { allowJsManifest });\n }\n }\n\n return null;\n}\n\n/**\n * Discover plugin manifests from local (relative) imports in the server file.\n * Resolves each relative import to a directory and loads manifest.json or manifest.js.\n *\n * @param relativeImports - Parsed imports with relative sources (starting with . or /)\n * @param serverFileDir - Absolute path to the directory containing the server file\n * @param cwd - Current working directory (for computing relative paths in output)\n * @returns Map of plugin name to template plugin entry for local plugins\n */\nasync function discoverLocalPlugins(\n relativeImports: ParsedImport[],\n serverFileDir: string,\n cwd: string,\n allowJsManifest: boolean,\n): Promise<TemplatePluginsManifest[\"plugins\"]> {\n const plugins: TemplatePluginsManifest[\"plugins\"] = {};\n\n for (const imp of relativeImports) {\n const resolved = resolveLocalManifest(\n imp.source,\n serverFileDir,\n allowJsManifest,\n cwd,\n );\n if (!resolved) continue;\n\n try {\n const relativePath = path.relative(cwd, path.dirname(resolved.path));\n const entry = await loadPluginEntry(\n resolved,\n `./${relativePath}`,\n allowJsManifest,\n );\n if (entry) plugins[entry[0]] = entry[1];\n } catch (error) {\n console.warn(\n `Warning: Failed to load manifest at ${resolved.path}:`,\n error instanceof Error ? error.message : error,\n );\n }\n }\n\n return plugins;\n}\n\n/**\n * Discover plugin manifests from a package's dist folder.\n * Looks for manifest.json or manifest.js in dist/plugins/{plugin-name}/ directories.\n *\n * @param packagePath - Path to the package in node_modules\n * @returns Array of plugin manifests found in the package\n */\nasync function discoverPluginManifests(\n packagePath: string,\n allowJsManifest: boolean,\n): Promise<PluginManifest[]> {\n const pluginsDir = path.join(packagePath, \"dist\", \"plugins\");\n const manifests: PluginManifest[] = [];\n\n if (!fs.existsSync(pluginsDir)) {\n return manifests;\n }\n\n const entries = fs.readdirSync(pluginsDir, { withFileTypes: true });\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n const resolved = resolveManifestInDir(path.join(pluginsDir, entry.name), {\n allowJsManifest,\n });\n if (!resolved) continue;\n\n try {\n const parsed = await loadManifestFromFile(resolved.path, resolved.type, {\n allowJsManifest,\n });\n const manifest = validateManifestWithSchema(parsed, resolved.path);\n if (manifest) {\n manifests.push(manifest);\n }\n } catch (error) {\n console.warn(\n `Warning: Failed to load manifest at ${resolved.path}:`,\n error instanceof Error ? error.message : error,\n );\n }\n }\n\n return manifests;\n}\n\n/**\n * Scan node_modules for packages with plugin manifests.\n *\n * @param cwd - Current working directory to search from\n * @param packages - Set of npm package names to scan for plugin manifests\n * @returns Map of plugin name to template plugin entry\n */\nasync function scanForPlugins(\n cwd: string,\n packages: Iterable<string>,\n allowJsManifest: boolean,\n): Promise<TemplatePluginsManifest[\"plugins\"]> {\n const plugins: TemplatePluginsManifest[\"plugins\"] = {};\n\n for (const packageName of packages) {\n const packagePath = path.join(cwd, \"node_modules\", packageName);\n if (!fs.existsSync(packagePath)) {\n continue;\n }\n\n const allowJsForPackage =\n allowJsManifest || shouldAllowJsManifestForPackage(packageName);\n\n const manifests = await discoverPluginManifests(\n packagePath,\n allowJsForPackage,\n );\n for (const manifest of manifests) {\n if (manifest.hidden) continue;\n plugins[manifest.name] = {\n name: manifest.name,\n displayName: manifest.displayName,\n description: manifest.description,\n package: packageName,\n resources: manifest.resources,\n ...(manifest.onSetupMessage && {\n onSetupMessage: manifest.onSetupMessage,\n }),\n ...(manifest.stability &&\n manifest.stability !== \"ga\" && {\n stability: manifest.stability,\n }),\n } satisfies TemplatePlugin;\n }\n }\n\n return plugins;\n}\n\n/**\n * Recursively scan a directory for plugin manifests. Any directory that\n * contains manifest.json or manifest.js is treated as a plugin root; we do\n * not descend into that directory's children. Used for local plugins discovery\n * so nested paths like server/plugins/category/my-plugin are found.\n */\nasync function scanPluginsDirRecursive(\n dir: string,\n cwd: string,\n allowJsManifest: boolean,\n depth = 0,\n): Promise<TemplatePluginsManifest[\"plugins\"]> {\n const plugins: TemplatePluginsManifest[\"plugins\"] = {};\n if (!fs.existsSync(dir) || depth >= MAX_SCAN_DEPTH) return plugins;\n\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n\n const pluginDir = path.join(dir, entry.name);\n const resolved = resolveManifestInDir(pluginDir, { allowJsManifest });\n\n if (resolved) {\n const pkg = `./${path.relative(cwd, pluginDir)}`;\n try {\n const pluginEntry = await loadPluginEntry(\n resolved,\n pkg,\n allowJsManifest,\n );\n if (pluginEntry) plugins[pluginEntry[0]] = pluginEntry[1];\n } catch (error) {\n console.warn(\n `Warning: Failed to load manifest at ${resolved.path}:`,\n error instanceof Error ? error.message : error,\n );\n }\n continue;\n }\n\n Object.assign(\n plugins,\n await scanPluginsDirRecursive(pluginDir, cwd, allowJsManifest, depth + 1),\n );\n }\n\n return plugins;\n}\n\n/**\n * Scan a directory for plugin manifests in direct subdirectories only.\n * Each subdirectory may contain manifest.json or manifest.js.\n * Used with --plugins-dir to discover plugins from source instead of node_modules.\n *\n * @param dir - Absolute path to the directory containing plugin subdirectories\n * @param packageName - Package name to assign to discovered plugins (used when cwd is not set)\n * @param cwd - When set, each plugin's package is set to ./<path from cwd to plugin subdir>, e.g. ./server/my-plugin\n * @returns Map of plugin name to template plugin entry\n */\nasync function scanPluginsDir(\n dir: string,\n packageName: string,\n allowJsManifest: boolean,\n cwd?: string,\n): Promise<TemplatePluginsManifest[\"plugins\"]> {\n const plugins: TemplatePluginsManifest[\"plugins\"] = {};\n\n if (!fs.existsSync(dir)) return plugins;\n\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n\n const pluginDir = path.join(dir, entry.name);\n const resolved = resolveManifestInDir(pluginDir, { allowJsManifest });\n if (!resolved) continue;\n\n const pkg =\n cwd !== undefined ? `./${path.relative(cwd, pluginDir)}` : packageName;\n\n try {\n const pluginEntry = await loadPluginEntry(resolved, pkg, allowJsManifest);\n if (pluginEntry) plugins[pluginEntry[0]] = pluginEntry[1];\n } catch (error) {\n console.warn(\n `Warning: Failed to load manifest at ${resolved.path}:`,\n error instanceof Error ? error.message : error,\n );\n }\n }\n\n return plugins;\n}\n\n/**\n * Write (or preview) the template plugins manifest to disk.\n */\nfunction writeManifest(\n outputPath: string,\n { plugins }: { plugins: TemplatePluginsManifest[\"plugins\"] },\n options: { write?: boolean; silent?: boolean; json?: boolean },\n) {\n const templateManifest: TemplatePluginsManifest = {\n $schema:\n \"https://databricks.github.io/appkit/schemas/template-plugins.schema.json\",\n version: \"1.1\",\n plugins,\n };\n\n const serialized = JSON.stringify(templateManifest, null, 2);\n\n if (options.json) {\n console.log(serialized);\n }\n\n if (options.write) {\n fs.writeFileSync(outputPath, `${serialized}\\n`);\n if (!options.silent && !options.json) {\n console.log(`\\n✓ Wrote ${outputPath}`);\n }\n } else if (!options.silent && !options.json) {\n console.log(\"\\nTo write the manifest, run:\");\n console.log(\" npx appkit plugin sync --write\\n\");\n console.log(\"Preview:\");\n console.log(\"─\".repeat(60));\n console.log(serialized);\n console.log(\"─\".repeat(60));\n }\n}\n\n/**\n * Run the plugin sync command.\n * Parses the server entry file to discover which packages to scan for plugin\n * manifests, then marks plugins that are actually used in the `plugins: [...]`\n * array as requiredByTemplate.\n */\nasync function runPluginsSync(options: {\n write?: boolean;\n output?: string;\n silent?: boolean;\n json?: boolean;\n requirePlugins?: string;\n pluginsDir?: string;\n packageName?: string;\n localPluginsDir?: string;\n allowJsManifest?: boolean;\n}): Promise<void> {\n const cwd = process.cwd();\n const allowJsManifest = Boolean(options.allowJsManifest);\n const outputPath = path.resolve(cwd, options.output || \"appkit.plugins.json\");\n\n // Security: Reject output paths that escape the project root\n if (!isWithinDirectory(outputPath, cwd)) {\n console.error(\n `Error: Output path \"${options.output}\" resolves outside the project directory.`,\n );\n process.exit(1);\n }\n\n if (!options.silent && !options.json) {\n console.log(\"Scanning for AppKit plugins...\\n\");\n if (allowJsManifest) {\n console.warn(\n \"Warning: --allow-js-manifest executes manifest.js/manifest.cjs files. Only use with trusted code.\",\n );\n }\n }\n\n // Step 1: Parse server file to discover imports and plugin usages\n const serverFile = findServerFile(cwd);\n let serverImports: ParsedImport[] = [];\n let pluginUsages = new Set<string>();\n\n if (serverFile) {\n if (!options.silent && !options.json) {\n const relativePath = path.relative(cwd, serverFile);\n console.log(`Server entry file: ${relativePath}`);\n }\n\n const content = fs.readFileSync(serverFile, \"utf-8\");\n const lang = serverFile.endsWith(\".tsx\") ? Lang.Tsx : Lang.TypeScript;\n const ast = parse(lang, content);\n const root = ast.root();\n\n serverImports = parseImports(root);\n pluginUsages = parsePluginUsages(root);\n } else if (!options.silent && !options.json) {\n console.log(\n \"No server entry file found. Checked:\",\n SERVER_FILE_CANDIDATES.join(\", \"),\n );\n }\n\n // Step 2: Split imports into npm packages and local (relative) imports\n const npmImports = serverImports.filter(\n (i) => !i.source.startsWith(\".\") && !i.source.startsWith(\"/\"),\n );\n const localImports = serverImports.filter(\n (i) => i.source.startsWith(\".\") || i.source.startsWith(\"/\"),\n );\n\n // Step 3: Scan for plugin manifests (--plugins-dir or node_modules)\n const plugins: TemplatePluginsManifest[\"plugins\"] = {};\n\n if (options.pluginsDir) {\n const resolvedDir = path.resolve(cwd, options.pluginsDir);\n const pkgName = options.packageName ?? \"@databricks/appkit\";\n if (!options.silent && !options.json) {\n console.log(`Scanning plugins directory: ${options.pluginsDir}`);\n }\n Object.assign(\n plugins,\n await scanPluginsDir(resolvedDir, pkgName, allowJsManifest),\n );\n } else {\n const npmPackages = new Set([\n ...KNOWN_PLUGIN_PACKAGES,\n ...npmImports.map((i) => i.source),\n ]);\n Object.assign(\n plugins,\n await scanForPlugins(cwd, npmPackages, allowJsManifest),\n );\n }\n\n // Step 4: Discover local plugin manifests from relative imports\n if (serverFile && localImports.length > 0) {\n const serverFileDir = path.dirname(serverFile);\n const localPlugins = await discoverLocalPlugins(\n localImports,\n serverFileDir,\n cwd,\n allowJsManifest,\n );\n Object.assign(plugins, localPlugins);\n }\n\n // Step 4b: Discover local plugins from conventional directory (or --local-plugins-dir).\n // These are included even when not imported in the server.\n const localDirsToScan: string[] = options.localPluginsDir\n ? [options.localPluginsDir]\n : CONVENTIONAL_LOCAL_PLUGIN_DIRS.filter((d) =>\n fs.existsSync(path.join(cwd, d)),\n );\n for (const dir of localDirsToScan) {\n const resolvedDir = path.resolve(cwd, dir);\n if (!fs.existsSync(resolvedDir)) continue;\n if (!options.silent && !options.json) {\n console.log(`Scanning local plugins directory: ${dir}`);\n }\n const discovered = await scanPluginsDirRecursive(\n resolvedDir,\n cwd,\n allowJsManifest,\n );\n for (const [name, entry] of Object.entries(discovered)) {\n if (!plugins[name]) plugins[name] = entry;\n }\n }\n\n const pluginCount = Object.keys(plugins).length;\n\n if (pluginCount === 0) {\n if (options.silent || options.json) {\n writeManifest(outputPath, { plugins: {} }, options);\n if (options.silent) return;\n process.exit(1);\n }\n console.log(\"No plugins found.\");\n if (options.pluginsDir) {\n console.log(\n `\\nNo manifest (${allowJsManifest ? \"manifest.json or manifest.js\" : \"manifest.json\"}) found in: ${options.pluginsDir}`,\n );\n } else {\n console.log(\n \"\\nMake sure you have plugin packages installed, or specify a directory:\",\n );\n console.log(\" appkit plugin sync --plugins-dir <path>\");\n }\n process.exit(1);\n }\n\n // Step 5: Mark plugins that are imported AND used in the plugins array as mandatory.\n // For npm imports, match by package name + plugin name.\n // For local imports, resolve both paths to absolute and compare.\n const serverFileDir = serverFile ? path.dirname(serverFile) : cwd;\n\n for (const imp of serverImports) {\n if (!pluginUsages.has(imp.name)) continue;\n\n const isLocal = imp.source.startsWith(\".\") || imp.source.startsWith(\"/\");\n let plugin: TemplatePlugin | undefined;\n\n if (isLocal) {\n // Resolve the import source to an absolute path from the server file directory\n const resolvedImportDir = path.resolve(serverFileDir, imp.source);\n plugin = Object.values(plugins).find((p) => {\n if (!p.package.startsWith(\".\")) return false;\n const resolvedPluginDir = path.resolve(cwd, p.package);\n return (\n resolvedPluginDir === resolvedImportDir && p.name === imp.originalName\n );\n });\n } else {\n // npm import: direct string comparison\n plugin = Object.values(plugins).find(\n (p) => p.package === imp.source && p.name === imp.originalName,\n );\n }\n\n if (plugin) {\n plugin.requiredByTemplate = true;\n }\n }\n\n // Step 6: Apply explicit --require-plugins overrides\n if (options.requirePlugins) {\n const explicitNames = options.requirePlugins\n .split(\",\")\n .map((s) => s.trim())\n .filter(Boolean);\n for (const name of explicitNames) {\n if (plugins[name]) {\n plugins[name].requiredByTemplate = true;\n } else if (!options.silent) {\n console.warn(\n `Warning: --require-plugins referenced \"${name}\" but no such plugin was discovered`,\n );\n }\n }\n }\n\n // Step 6b: Strip requiredByTemplate for non-GA plugins\n for (const plugin of Object.values(plugins)) {\n if (\n plugin.requiredByTemplate &&\n plugin.stability &&\n plugin.stability !== \"ga\"\n ) {\n plugin.requiredByTemplate = undefined;\n }\n }\n\n if (!options.silent && !options.json) {\n console.log(`\\nFound ${pluginCount} plugin(s):`);\n for (const [name, manifest] of Object.entries(plugins)) {\n const resourceCount =\n manifest.resources.required.length + manifest.resources.optional.length;\n const resourceInfo =\n resourceCount > 0 ? ` [${resourceCount} resource(s)]` : \"\";\n const mandatoryTag = manifest.requiredByTemplate ? \" (mandatory)\" : \"\";\n console.log(\n ` ${manifest.requiredByTemplate ? \"●\" : \"○\"} ${manifest.displayName} (${name}) from ${manifest.package}${resourceInfo}${mandatoryTag}`,\n );\n }\n }\n\n // Step 7: Detect orphaned resources from removed plugins\n if (!options.silent && fs.existsSync(outputPath)) {\n try {\n const oldRaw = fs.readFileSync(outputPath, \"utf-8\");\n const oldManifest = JSON.parse(oldRaw) as TemplatePluginsManifest;\n const oldNames = new Set(Object.keys(oldManifest.plugins ?? {}));\n const newNames = new Set(Object.keys(plugins));\n for (const name of oldNames) {\n if (newNames.has(name)) continue;\n const oldPlugin = oldManifest.plugins?.[name];\n if (!oldPlugin || typeof oldPlugin !== \"object\") continue;\n const envVars: string[] = [];\n for (const res of [\n ...(oldPlugin.resources?.required ?? []),\n ...(oldPlugin.resources?.optional ?? []),\n ]) {\n if (res?.fields) {\n for (const field of Object.values(res.fields)) {\n if (field?.env) envVars.push(field.env);\n }\n }\n }\n const envInfo =\n envVars.length > 0\n ? ` The following resource env vars may be orphaned: ${envVars.join(\", \")}`\n : \"\";\n console.warn(`Warning: Plugin \"${name}\" was removed.${envInfo}`);\n }\n } catch {\n // Ignore parse errors on existing manifest\n }\n }\n\n writeManifest(outputPath, { plugins }, options);\n}\n\n/** Exported for testing: path boundary check, AST parsing, trust checks. */\nexport {\n isWithinDirectory,\n parseImports,\n parsePluginUsages,\n shouldAllowJsManifestForPackage,\n};\n\nexport const pluginsSyncCommand = new Command(\"sync\")\n .description(\n \"Sync plugin manifests from installed packages into appkit.plugins.json\",\n )\n .option(\"-w, --write\", \"Write the manifest file\")\n .option(\n \"-o, --output <path>\",\n \"Output file path (default: ./appkit.plugins.json)\",\n )\n .option(\n \"-s, --silent\",\n \"Suppress output and never exit with error (for use in predev/prebuild hooks)\",\n )\n .option(\n \"--require-plugins <names>\",\n \"Comma-separated plugin names to mark as requiredByTemplate (e.g. server,analytics)\",\n )\n .option(\n \"--plugins-dir <path>\",\n \"Scan this directory for plugin subdirectories with manifest.json (instead of node_modules)\",\n )\n .option(\n \"--package-name <name>\",\n \"Package name to assign to plugins found via --plugins-dir (default: @databricks/appkit)\",\n )\n .option(\n \"--local-plugins-dir <path>\",\n \"Also scan this directory for local plugin manifests (default: plugins, server)\",\n )\n .option(\n \"--allow-js-manifest\",\n \"Allow reading manifest.js/manifest.cjs (executes code; use only with trusted plugins)\",\n )\n .option(\"--json\", \"Output manifest as JSON to stdout\")\n .addHelpText(\n \"after\",\n `\nExamples:\n $ appkit plugin sync\n $ appkit plugin sync --write\n $ appkit plugin sync --write --require-plugins server,analytics\n $ appkit plugin sync --write --plugins-dir src/plugins --package-name @my/pkg\n $ appkit plugin sync --json\n $ appkit plugin sync --silent`,\n )\n .action((opts) =>\n runPluginsSync(opts).catch((err) => {\n console.error(err);\n process.exit(1);\n }),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;AA4BA,SAAS,kBAAkB,UAAkB,UAA2B;CACtE,MAAM,eAAe,KAAK,QAAQ,SAAS;CAC3C,MAAM,mBAAmB,KAAK,QAAQ,SAAS;AAE/C,QACE,iBAAiB,oBACjB,aAAa,WAAW,GAAG,mBAAmB,KAAK,MAAM;;;;;;AAQ7D,SAAS,2BACP,KACA,YACuB;CACvB,MAAM,SAAS,iBAAiB,IAAI;AACpC,KAAI,OAAO,SAAS,OAAO,SAAU,QAAO,OAAO;AACnD,KAAI,OAAO,QAAQ,OACjB,SAAQ,KACN,w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