@databricks/appkit-ui 0.14.1 → 0.16.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/NOTICE.md +1 -0
- package/dist/cli/commands/plugin/add-resource/add-resource.js +10 -4
- package/dist/cli/commands/plugin/add-resource/add-resource.js.map +1 -1
- package/dist/cli/commands/plugin/create/scaffold.js +10 -16
- package/dist/cli/commands/plugin/create/scaffold.js.map +1 -1
- package/dist/cli/commands/plugin/list/list.js +44 -26
- package/dist/cli/commands/plugin/list/list.js.map +1 -1
- package/dist/cli/commands/plugin/manifest-resolve.js +57 -0
- package/dist/cli/commands/plugin/manifest-resolve.js.map +1 -0
- package/dist/cli/commands/plugin/sync/sync.js +121 -71
- package/dist/cli/commands/plugin/sync/sync.js.map +1 -1
- package/dist/cli/commands/plugin/trusted-js-manifest.js +28 -0
- package/dist/cli/commands/plugin/trusted-js-manifest.js.map +1 -0
- package/dist/cli/commands/plugin/validate/validate.js +32 -14
- package/dist/cli/commands/plugin/validate/validate.js.map +1 -1
- package/dist/js/arrow/arrow-client.d.ts.map +1 -1
- package/dist/js/arrow/index.d.ts +3 -0
- package/dist/js/arrow/lazy-arrow.d.ts +0 -1
- package/dist/js/arrow/lazy-arrow.d.ts.map +1 -1
- package/dist/js/constants.d.ts.map +1 -1
- package/dist/js/index.d.ts +2 -0
- package/dist/js/sse/connect-sse.d.ts +0 -1
- package/dist/js/sse/connect-sse.d.ts.map +1 -1
- package/dist/js/sse/types.d.ts +1 -3
- package/dist/js/sse/types.d.ts.map +1 -1
- package/dist/react/charts/area/index.d.ts +2 -3
- package/dist/react/charts/area/index.d.ts.map +1 -1
- package/dist/react/charts/bar/index.d.ts +2 -3
- package/dist/react/charts/bar/index.d.ts.map +1 -1
- package/dist/react/charts/base.d.ts +2 -2
- package/dist/react/charts/base.d.ts.map +1 -1
- package/dist/react/charts/base.js.map +1 -1
- package/dist/react/charts/chart-error-boundary.js.map +1 -1
- package/dist/react/charts/constants.d.ts.map +1 -1
- package/dist/react/charts/create-chart.d.ts +2 -3
- package/dist/react/charts/create-chart.d.ts.map +1 -1
- package/dist/react/charts/create-chart.js.map +1 -1
- package/dist/react/charts/empty.js.map +1 -1
- package/dist/react/charts/error.js.map +1 -1
- package/dist/react/charts/heatmap/index.d.ts +2 -3
- package/dist/react/charts/heatmap/index.d.ts.map +1 -1
- package/dist/react/charts/index.d.ts +18 -0
- package/dist/react/charts/line/index.d.ts +2 -3
- package/dist/react/charts/line/index.d.ts.map +1 -1
- package/dist/react/charts/loading.js.map +1 -1
- package/dist/react/charts/normalize.d.ts +0 -1
- package/dist/react/charts/normalize.d.ts.map +1 -1
- package/dist/react/charts/options.d.ts.map +1 -1
- package/dist/react/charts/pie/index.d.ts +3 -4
- package/dist/react/charts/pie/index.d.ts.map +1 -1
- package/dist/react/charts/radar/index.d.ts +2 -3
- package/dist/react/charts/radar/index.d.ts.map +1 -1
- package/dist/react/charts/scatter/index.d.ts +2 -3
- package/dist/react/charts/scatter/index.d.ts.map +1 -1
- package/dist/react/charts/theme.d.ts +0 -1
- package/dist/react/charts/theme.d.ts.map +1 -1
- package/dist/react/charts/types.d.ts.map +1 -1
- package/dist/react/charts/utils.d.ts.map +1 -1
- package/dist/react/charts/wrapper.d.ts +2 -2
- package/dist/react/charts/wrapper.d.ts.map +1 -1
- package/dist/react/charts/wrapper.js.map +1 -1
- package/dist/react/genie/genie-chat-input.d.ts +2 -2
- package/dist/react/genie/genie-chat-input.d.ts.map +1 -1
- package/dist/react/genie/genie-chat-input.js.map +1 -1
- package/dist/react/genie/genie-chat-message-list.d.ts +2 -2
- package/dist/react/genie/genie-chat-message-list.d.ts.map +1 -1
- package/dist/react/genie/genie-chat-message-list.js.map +1 -1
- package/dist/react/genie/genie-chat-message.d.ts +2 -2
- package/dist/react/genie/genie-chat-message.d.ts.map +1 -1
- package/dist/react/genie/genie-chat-message.js.map +1 -1
- package/dist/react/genie/genie-chat.d.ts +2 -2
- package/dist/react/genie/genie-chat.d.ts.map +1 -1
- package/dist/react/genie/genie-chat.js.map +1 -1
- package/dist/react/genie/index.d.ts +7 -0
- package/dist/react/genie/types.d.ts +1 -0
- package/dist/react/genie/types.d.ts.map +1 -1
- package/dist/react/genie/use-genie-chat.d.ts +0 -1
- package/dist/react/genie/use-genie-chat.d.ts.map +1 -1
- package/dist/react/hooks/index.d.ts +3 -0
- package/dist/react/hooks/types.d.ts.map +1 -1
- package/dist/react/hooks/use-analytics-query.d.ts +0 -1
- package/dist/react/hooks/use-analytics-query.d.ts.map +1 -1
- package/dist/react/hooks/use-chart-data.d.ts.map +1 -1
- package/dist/react/index.d.ts +5 -0
- package/dist/react/lib/utils.d.ts.map +1 -1
- package/dist/react/portal-container-context.d.ts +0 -1
- package/dist/react/portal-container-context.d.ts.map +1 -1
- package/dist/react/portal-container-context.js.map +1 -1
- package/dist/react/table/data-table.d.ts +2 -3
- package/dist/react/table/data-table.d.ts.map +1 -1
- package/dist/react/table/data-table.js.map +1 -1
- package/dist/react/table/empty.js.map +1 -1
- package/dist/react/table/error.js.map +1 -1
- package/dist/react/table/index.d.ts +1 -0
- package/dist/react/table/loading.js.map +1 -1
- package/dist/react/table/table-wrapper.js.map +1 -1
- package/dist/react/table/types.d.ts +0 -1
- package/dist/react/table/types.d.ts.map +1 -1
- package/dist/react/ui/accordion.d.ts +5 -5
- package/dist/react/ui/accordion.d.ts.map +1 -1
- package/dist/react/ui/accordion.js.map +1 -1
- package/dist/react/ui/alert-dialog.d.ts +12 -12
- package/dist/react/ui/alert-dialog.d.ts.map +1 -1
- package/dist/react/ui/alert-dialog.js.map +1 -1
- package/dist/react/ui/alert.d.ts +4 -4
- package/dist/react/ui/alert.d.ts.map +1 -1
- package/dist/react/ui/alert.js.map +1 -1
- package/dist/react/ui/aspect-ratio.d.ts +2 -2
- package/dist/react/ui/aspect-ratio.d.ts.map +1 -1
- package/dist/react/ui/aspect-ratio.js.map +1 -1
- package/dist/react/ui/avatar.d.ts +4 -4
- package/dist/react/ui/avatar.d.ts.map +1 -1
- package/dist/react/ui/avatar.js.map +1 -1
- package/dist/react/ui/badge.d.ts +2 -2
- package/dist/react/ui/badge.d.ts.map +1 -1
- package/dist/react/ui/badge.js.map +1 -1
- package/dist/react/ui/breadcrumb.d.ts +8 -8
- package/dist/react/ui/breadcrumb.d.ts.map +1 -1
- package/dist/react/ui/breadcrumb.js.map +1 -1
- package/dist/react/ui/button-group.d.ts +6 -6
- package/dist/react/ui/button-group.d.ts.map +1 -1
- package/dist/react/ui/button-group.js.map +1 -1
- package/dist/react/ui/button.d.ts +4 -4
- package/dist/react/ui/button.d.ts.map +1 -1
- package/dist/react/ui/button.js.map +1 -1
- package/dist/react/ui/calendar.d.ts +3 -3
- package/dist/react/ui/calendar.d.ts.map +1 -1
- package/dist/react/ui/calendar.js.map +1 -1
- package/dist/react/ui/card.d.ts +8 -8
- package/dist/react/ui/card.d.ts.map +1 -1
- package/dist/react/ui/card.js.map +1 -1
- package/dist/react/ui/carousel.d.ts +6 -6
- package/dist/react/ui/carousel.d.ts.map +1 -1
- package/dist/react/ui/carousel.js.map +1 -1
- package/dist/react/ui/chart.d.ts +19 -19
- package/dist/react/ui/chart.d.ts.map +1 -1
- package/dist/react/ui/chart.js.map +1 -1
- package/dist/react/ui/checkbox.d.ts +2 -2
- package/dist/react/ui/checkbox.d.ts.map +1 -1
- package/dist/react/ui/checkbox.js.map +1 -1
- package/dist/react/ui/collapsible.d.ts +4 -4
- package/dist/react/ui/collapsible.d.ts.map +1 -1
- package/dist/react/ui/collapsible.js.map +1 -1
- package/dist/react/ui/command.d.ts +10 -10
- package/dist/react/ui/command.d.ts.map +1 -1
- package/dist/react/ui/command.js.map +1 -1
- package/dist/react/ui/context-menu.d.ts +16 -16
- package/dist/react/ui/context-menu.d.ts.map +1 -1
- package/dist/react/ui/context-menu.js.map +1 -1
- package/dist/react/ui/dialog.d.ts +11 -11
- package/dist/react/ui/dialog.d.ts.map +1 -1
- package/dist/react/ui/dialog.js.map +1 -1
- package/dist/react/ui/drawer.d.ts +11 -11
- package/dist/react/ui/drawer.d.ts.map +1 -1
- package/dist/react/ui/drawer.js.map +1 -1
- package/dist/react/ui/dropdown-menu.d.ts +16 -16
- package/dist/react/ui/dropdown-menu.d.ts.map +1 -1
- package/dist/react/ui/dropdown-menu.js.map +1 -1
- package/dist/react/ui/empty.d.ts +9 -9
- package/dist/react/ui/empty.d.ts.map +1 -1
- package/dist/react/ui/empty.js.map +1 -1
- package/dist/react/ui/field.d.ts +13 -13
- package/dist/react/ui/field.d.ts.map +1 -1
- package/dist/react/ui/field.js.map +1 -1
- package/dist/react/ui/form.d.ts +9 -9
- package/dist/react/ui/form.d.ts.map +1 -1
- package/dist/react/ui/form.js.map +1 -1
- package/dist/react/ui/hover-card.d.ts +4 -4
- package/dist/react/ui/hover-card.d.ts.map +1 -1
- package/dist/react/ui/hover-card.js.map +1 -1
- package/dist/react/ui/index.d.ts +53 -0
- package/dist/react/ui/input-group.d.ts +10 -10
- package/dist/react/ui/input-group.d.ts.map +1 -1
- package/dist/react/ui/input-group.js.map +1 -1
- package/dist/react/ui/input-otp.d.ts +5 -5
- package/dist/react/ui/input-otp.d.ts.map +1 -1
- package/dist/react/ui/input-otp.js.map +1 -1
- package/dist/react/ui/input.d.ts +2 -2
- package/dist/react/ui/input.d.ts.map +1 -1
- package/dist/react/ui/input.js.map +1 -1
- package/dist/react/ui/item.d.ts +14 -14
- package/dist/react/ui/item.d.ts.map +1 -1
- package/dist/react/ui/item.js.map +1 -1
- package/dist/react/ui/kbd.d.ts +3 -3
- package/dist/react/ui/kbd.d.ts.map +1 -1
- package/dist/react/ui/kbd.js.map +1 -1
- package/dist/react/ui/label.d.ts +2 -2
- package/dist/react/ui/label.d.ts.map +1 -1
- package/dist/react/ui/label.js.map +1 -1
- package/dist/react/ui/menubar.d.ts +17 -17
- package/dist/react/ui/menubar.d.ts.map +1 -1
- package/dist/react/ui/menubar.js.map +1 -1
- package/dist/react/ui/navigation-menu.d.ts +11 -11
- package/dist/react/ui/navigation-menu.d.ts.map +1 -1
- package/dist/react/ui/navigation-menu.js.map +1 -1
- package/dist/react/ui/pagination.d.ts +8 -8
- package/dist/react/ui/pagination.d.ts.map +1 -1
- package/dist/react/ui/pagination.js.map +1 -1
- package/dist/react/ui/popover.d.ts +5 -5
- package/dist/react/ui/popover.d.ts.map +1 -1
- package/dist/react/ui/popover.js.map +1 -1
- package/dist/react/ui/progress.d.ts +2 -2
- package/dist/react/ui/progress.d.ts.map +1 -1
- package/dist/react/ui/progress.js.map +1 -1
- package/dist/react/ui/radio-group.d.ts +3 -3
- package/dist/react/ui/radio-group.d.ts.map +1 -1
- package/dist/react/ui/radio-group.js.map +1 -1
- package/dist/react/ui/resizable.d.ts +4 -4
- package/dist/react/ui/resizable.d.ts.map +1 -1
- package/dist/react/ui/resizable.js.map +1 -1
- package/dist/react/ui/scroll-area.d.ts +3 -3
- package/dist/react/ui/scroll-area.d.ts.map +1 -1
- package/dist/react/ui/scroll-area.js.map +1 -1
- package/dist/react/ui/select.d.ts +11 -11
- package/dist/react/ui/select.d.ts.map +1 -1
- package/dist/react/ui/select.js.map +1 -1
- package/dist/react/ui/separator.d.ts +2 -2
- package/dist/react/ui/separator.d.ts.map +1 -1
- package/dist/react/ui/separator.js.map +1 -1
- package/dist/react/ui/sheet.d.ts +9 -9
- package/dist/react/ui/sheet.d.ts.map +1 -1
- package/dist/react/ui/sheet.js.map +1 -1
- package/dist/react/ui/sidebar.d.ts +38 -55
- package/dist/react/ui/sidebar.d.ts.map +1 -1
- package/dist/react/ui/sidebar.js.map +1 -1
- package/dist/react/ui/skeleton.d.ts +2 -2
- package/dist/react/ui/skeleton.d.ts.map +1 -1
- package/dist/react/ui/skeleton.js.map +1 -1
- package/dist/react/ui/slider.d.ts +2 -2
- package/dist/react/ui/slider.d.ts.map +1 -1
- package/dist/react/ui/slider.js.map +1 -1
- package/dist/react/ui/sonner.d.ts +2 -2
- package/dist/react/ui/sonner.d.ts.map +1 -1
- package/dist/react/ui/sonner.js.map +1 -1
- package/dist/react/ui/spinner.d.ts +2 -2
- package/dist/react/ui/spinner.d.ts.map +1 -1
- package/dist/react/ui/spinner.js.map +1 -1
- package/dist/react/ui/switch.d.ts +2 -2
- package/dist/react/ui/switch.d.ts.map +1 -1
- package/dist/react/ui/switch.js.map +1 -1
- package/dist/react/ui/table.d.ts +9 -9
- package/dist/react/ui/table.d.ts.map +1 -1
- package/dist/react/ui/table.js.map +1 -1
- package/dist/react/ui/tabs.d.ts +5 -5
- package/dist/react/ui/tabs.d.ts.map +1 -1
- package/dist/react/ui/tabs.js.map +1 -1
- package/dist/react/ui/textarea.d.ts +2 -2
- package/dist/react/ui/textarea.d.ts.map +1 -1
- package/dist/react/ui/textarea.js.map +1 -1
- package/dist/react/ui/toggle-group.d.ts +3 -3
- package/dist/react/ui/toggle-group.d.ts.map +1 -1
- package/dist/react/ui/toggle-group.js.map +1 -1
- package/dist/react/ui/toggle.d.ts +4 -4
- package/dist/react/ui/toggle.d.ts.map +1 -1
- package/dist/react/ui/toggle.js.map +1 -1
- package/dist/react/ui/tooltip.d.ts.map +1 -1
- package/dist/react/ui/tooltip.js.map +1 -1
- package/dist/shared/src/cache.d.ts +1 -0
- package/dist/shared/src/execute.d.ts +1 -0
- package/dist/shared/src/genie.d.ts.map +1 -1
- package/dist/shared/src/index.d.ts +7 -0
- package/dist/shared/src/plugin.d.ts +2 -0
- package/dist/shared/src/sql/helpers.d.ts +0 -1
- package/dist/shared/src/sql/helpers.d.ts.map +1 -1
- package/dist/shared/src/sql/types.d.ts.map +1 -1
- package/dist/shared/src/tunnel.d.ts +1 -0
- package/docs/development/project-setup.md +1 -1
- package/docs/plugins/plugin-management.md +16 -2
- package/package.json +3 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { loadManifestFromFile, resolveManifestInDir } from "../manifest-resolve.js";
|
|
1
2
|
import { formatValidationErrors, validateManifest } from "../validate/validate-manifest.js";
|
|
3
|
+
import { shouldAllowJsManifestForPackage } from "../trusted-js-manifest.js";
|
|
2
4
|
import fs from "node:fs";
|
|
3
5
|
import path from "node:path";
|
|
4
6
|
import { Command } from "commander";
|
|
@@ -28,6 +30,25 @@ function validateManifestWithSchema(obj, sourcePath) {
|
|
|
28
30
|
if (result.errors?.length) console.warn(`Warning: Manifest at ${sourcePath} failed schema validation:\n${formatValidationErrors(result.errors, obj)}`);
|
|
29
31
|
return null;
|
|
30
32
|
}
|
|
33
|
+
/** Safety limit for recursive directory scanning to prevent runaway traversal. */
|
|
34
|
+
const MAX_SCAN_DEPTH = 5;
|
|
35
|
+
/**
|
|
36
|
+
* Load and validate a resolved manifest, returning a TemplatePlugin entry or null.
|
|
37
|
+
* Centralises the resolve → load → validate → build-entry pipeline used by
|
|
38
|
+
* multiple discovery functions.
|
|
39
|
+
*/
|
|
40
|
+
async function loadPluginEntry(resolved, pkg, allowJsManifest) {
|
|
41
|
+
const manifest = validateManifestWithSchema(await loadManifestFromFile(resolved.path, resolved.type, { allowJsManifest }), resolved.path);
|
|
42
|
+
if (!manifest || manifest.hidden) return null;
|
|
43
|
+
return [manifest.name, {
|
|
44
|
+
name: manifest.name,
|
|
45
|
+
displayName: manifest.displayName,
|
|
46
|
+
description: manifest.description,
|
|
47
|
+
package: pkg,
|
|
48
|
+
resources: manifest.resources,
|
|
49
|
+
...manifest.onSetupMessage && { onSetupMessage: manifest.onSetupMessage }
|
|
50
|
+
}];
|
|
51
|
+
}
|
|
31
52
|
/**
|
|
32
53
|
* Known packages that may contain AppKit plugins.
|
|
33
54
|
* Always scanned for manifests, even if not imported in the server file.
|
|
@@ -39,6 +60,12 @@ const KNOWN_PLUGIN_PACKAGES = ["@databricks/appkit"];
|
|
|
39
60
|
*/
|
|
40
61
|
const SERVER_FILE_CANDIDATES = ["server/server.ts", "server/index.ts"];
|
|
41
62
|
/**
|
|
63
|
+
* Conventional directories to scan for local plugin manifests when
|
|
64
|
+
* --local-plugins-dir is not set. Checked in order; each that exists is scanned.
|
|
65
|
+
* Plugins found here are added to the manifest even if not imported in the server.
|
|
66
|
+
*/
|
|
67
|
+
const CONVENTIONAL_LOCAL_PLUGIN_DIRS = ["plugins", "server"];
|
|
68
|
+
/**
|
|
42
69
|
* Find the server entry file by checking candidate paths in order.
|
|
43
70
|
*
|
|
44
71
|
* @param cwd - Current working directory
|
|
@@ -123,100 +150,85 @@ const RESOLVE_EXTENSIONS = [
|
|
|
123
150
|
".jsx"
|
|
124
151
|
];
|
|
125
152
|
/**
|
|
126
|
-
* Resolve a relative import source to the plugin directory containing a manifest
|
|
127
|
-
* Follows the convention that plugins live in
|
|
153
|
+
* Resolve a relative import source to the plugin directory containing a manifest
|
|
154
|
+
* (manifest.json or manifest.js). Follows the convention that plugins live in
|
|
155
|
+
* their own directory with a manifest file.
|
|
128
156
|
*
|
|
129
157
|
* Resolution strategy:
|
|
130
|
-
* 1. If the import path is a directory, look for manifest.json
|
|
131
|
-
* 2. If the import path + extension is a file, look for manifest
|
|
132
|
-
* 3. If the import path is a directory with an index file, look for manifest
|
|
158
|
+
* 1. If the import path is a directory, look for manifest.json/js in it
|
|
159
|
+
* 2. If the import path + extension is a file, look for manifest in its parent directory
|
|
160
|
+
* 3. If the import path is a directory with an index file, look for manifest in that directory
|
|
133
161
|
*
|
|
134
162
|
* @param importSource - The relative import specifier (e.g. "./plugins/my-plugin")
|
|
135
163
|
* @param serverFileDir - Absolute path to the directory containing the server file
|
|
136
|
-
* @returns
|
|
164
|
+
* @returns Resolved manifest file path and type, or null if not found
|
|
137
165
|
*/
|
|
138
|
-
function resolveLocalManifest(importSource, serverFileDir, projectRoot) {
|
|
166
|
+
function resolveLocalManifest(importSource, serverFileDir, allowJsManifest, projectRoot) {
|
|
139
167
|
const resolved = path.resolve(serverFileDir, importSource);
|
|
140
|
-
|
|
168
|
+
const boundary = projectRoot || serverFileDir;
|
|
169
|
+
if (!isWithinDirectory(resolved, boundary)) {
|
|
141
170
|
console.warn(`Warning: Skipping import "${importSource}" — resolves outside the project directory`);
|
|
142
171
|
return null;
|
|
143
172
|
}
|
|
144
|
-
if (fs.existsSync(resolved) && fs.statSync(resolved).isDirectory()) {
|
|
145
|
-
const manifestPath = path.join(resolved, "manifest.json");
|
|
146
|
-
if (fs.existsSync(manifestPath)) return manifestPath;
|
|
147
|
-
}
|
|
173
|
+
if (fs.existsSync(resolved) && fs.statSync(resolved).isDirectory()) return resolveManifestInDir(resolved, { allowJsManifest });
|
|
148
174
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
149
175
|
const filePath = `${resolved}${ext}`;
|
|
150
176
|
if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
|
|
151
177
|
const dir = path.dirname(filePath);
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
break;
|
|
178
|
+
if (!isWithinDirectory(dir, boundary)) return null;
|
|
179
|
+
return resolveManifestInDir(dir, { allowJsManifest });
|
|
155
180
|
}
|
|
156
181
|
}
|
|
157
182
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
158
183
|
const indexPath = path.join(resolved, `index${ext}`);
|
|
159
|
-
if (fs.existsSync(indexPath)) {
|
|
160
|
-
const manifestPath = path.join(resolved, "manifest.json");
|
|
161
|
-
if (fs.existsSync(manifestPath)) return manifestPath;
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
184
|
+
if (fs.existsSync(indexPath)) return resolveManifestInDir(resolved, { allowJsManifest });
|
|
164
185
|
}
|
|
165
186
|
return null;
|
|
166
187
|
}
|
|
167
188
|
/**
|
|
168
189
|
* Discover plugin manifests from local (relative) imports in the server file.
|
|
169
|
-
* Resolves each relative import to a directory and
|
|
190
|
+
* Resolves each relative import to a directory and loads manifest.json or manifest.js.
|
|
170
191
|
*
|
|
171
192
|
* @param relativeImports - Parsed imports with relative sources (starting with . or /)
|
|
172
193
|
* @param serverFileDir - Absolute path to the directory containing the server file
|
|
173
194
|
* @param cwd - Current working directory (for computing relative paths in output)
|
|
174
195
|
* @returns Map of plugin name to template plugin entry for local plugins
|
|
175
196
|
*/
|
|
176
|
-
function discoverLocalPlugins(relativeImports, serverFileDir, cwd) {
|
|
197
|
+
async function discoverLocalPlugins(relativeImports, serverFileDir, cwd, allowJsManifest) {
|
|
177
198
|
const plugins = {};
|
|
178
199
|
for (const imp of relativeImports) {
|
|
179
|
-
const
|
|
180
|
-
if (!
|
|
200
|
+
const resolved = resolveLocalManifest(imp.source, serverFileDir, allowJsManifest, cwd);
|
|
201
|
+
if (!resolved) continue;
|
|
181
202
|
try {
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
if (!manifest || manifest.hidden) continue;
|
|
185
|
-
const relativePath = path.relative(cwd, path.dirname(manifestPath));
|
|
186
|
-
plugins[manifest.name] = {
|
|
187
|
-
name: manifest.name,
|
|
188
|
-
displayName: manifest.displayName,
|
|
189
|
-
description: manifest.description,
|
|
190
|
-
package: `./${relativePath}`,
|
|
191
|
-
resources: manifest.resources,
|
|
192
|
-
...manifest.onSetupMessage && { onSetupMessage: manifest.onSetupMessage }
|
|
193
|
-
};
|
|
203
|
+
const entry = await loadPluginEntry(resolved, `./${path.relative(cwd, path.dirname(resolved.path))}`, allowJsManifest);
|
|
204
|
+
if (entry) plugins[entry[0]] = entry[1];
|
|
194
205
|
} catch (error) {
|
|
195
|
-
console.warn(`Warning: Failed to
|
|
206
|
+
console.warn(`Warning: Failed to load manifest at ${resolved.path}:`, error instanceof Error ? error.message : error);
|
|
196
207
|
}
|
|
197
208
|
}
|
|
198
209
|
return plugins;
|
|
199
210
|
}
|
|
200
211
|
/**
|
|
201
212
|
* Discover plugin manifests from a package's dist folder.
|
|
202
|
-
* Looks for manifest.json
|
|
213
|
+
* Looks for manifest.json or manifest.js in dist/plugins/{plugin-name}/ directories.
|
|
203
214
|
*
|
|
204
215
|
* @param packagePath - Path to the package in node_modules
|
|
205
216
|
* @returns Array of plugin manifests found in the package
|
|
206
217
|
*/
|
|
207
|
-
function discoverPluginManifests(packagePath) {
|
|
218
|
+
async function discoverPluginManifests(packagePath, allowJsManifest) {
|
|
208
219
|
const pluginsDir = path.join(packagePath, "dist", "plugins");
|
|
209
220
|
const manifests = [];
|
|
210
221
|
if (!fs.existsSync(pluginsDir)) return manifests;
|
|
211
222
|
const entries = fs.readdirSync(pluginsDir, { withFileTypes: true });
|
|
212
|
-
for (const entry of entries)
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
223
|
+
for (const entry of entries) {
|
|
224
|
+
if (!entry.isDirectory()) continue;
|
|
225
|
+
const resolved = resolveManifestInDir(path.join(pluginsDir, entry.name), { allowJsManifest });
|
|
226
|
+
if (!resolved) continue;
|
|
227
|
+
try {
|
|
228
|
+
const manifest = validateManifestWithSchema(await loadManifestFromFile(resolved.path, resolved.type, { allowJsManifest }), resolved.path);
|
|
217
229
|
if (manifest) manifests.push(manifest);
|
|
218
230
|
} catch (error) {
|
|
219
|
-
console.warn(`Warning: Failed to
|
|
231
|
+
console.warn(`Warning: Failed to load manifest at ${resolved.path}:`, error instanceof Error ? error.message : error);
|
|
220
232
|
}
|
|
221
233
|
}
|
|
222
234
|
return manifests;
|
|
@@ -228,12 +240,12 @@ function discoverPluginManifests(packagePath) {
|
|
|
228
240
|
* @param packages - Set of npm package names to scan for plugin manifests
|
|
229
241
|
* @returns Map of plugin name to template plugin entry
|
|
230
242
|
*/
|
|
231
|
-
function scanForPlugins(cwd, packages) {
|
|
243
|
+
async function scanForPlugins(cwd, packages, allowJsManifest) {
|
|
232
244
|
const plugins = {};
|
|
233
245
|
for (const packageName of packages) {
|
|
234
246
|
const packagePath = path.join(cwd, "node_modules", packageName);
|
|
235
247
|
if (!fs.existsSync(packagePath)) continue;
|
|
236
|
-
const manifests = discoverPluginManifests(packagePath);
|
|
248
|
+
const manifests = await discoverPluginManifests(packagePath, allowJsManifest || shouldAllowJsManifestForPackage(packageName));
|
|
237
249
|
for (const manifest of manifests) {
|
|
238
250
|
if (manifest.hidden) continue;
|
|
239
251
|
plugins[manifest.name] = {
|
|
@@ -249,35 +261,58 @@ function scanForPlugins(cwd, packages) {
|
|
|
249
261
|
return plugins;
|
|
250
262
|
}
|
|
251
263
|
/**
|
|
252
|
-
*
|
|
253
|
-
*
|
|
264
|
+
* Recursively scan a directory for plugin manifests. Any directory that
|
|
265
|
+
* contains manifest.json or manifest.js is treated as a plugin root; we do
|
|
266
|
+
* not descend into that directory's children. Used for local plugins discovery
|
|
267
|
+
* so nested paths like server/plugins/category/my-plugin are found.
|
|
268
|
+
*/
|
|
269
|
+
async function scanPluginsDirRecursive(dir, cwd, allowJsManifest, depth = 0) {
|
|
270
|
+
const plugins = {};
|
|
271
|
+
if (!fs.existsSync(dir) || depth >= MAX_SCAN_DEPTH) return plugins;
|
|
272
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
273
|
+
for (const entry of entries) {
|
|
274
|
+
if (!entry.isDirectory()) continue;
|
|
275
|
+
const pluginDir = path.join(dir, entry.name);
|
|
276
|
+
const resolved = resolveManifestInDir(pluginDir, { allowJsManifest });
|
|
277
|
+
if (resolved) {
|
|
278
|
+
const pkg = `./${path.relative(cwd, pluginDir)}`;
|
|
279
|
+
try {
|
|
280
|
+
const pluginEntry = await loadPluginEntry(resolved, pkg, allowJsManifest);
|
|
281
|
+
if (pluginEntry) plugins[pluginEntry[0]] = pluginEntry[1];
|
|
282
|
+
} catch (error) {
|
|
283
|
+
console.warn(`Warning: Failed to load manifest at ${resolved.path}:`, error instanceof Error ? error.message : error);
|
|
284
|
+
}
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
Object.assign(plugins, await scanPluginsDirRecursive(pluginDir, cwd, allowJsManifest, depth + 1));
|
|
288
|
+
}
|
|
289
|
+
return plugins;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Scan a directory for plugin manifests in direct subdirectories only.
|
|
293
|
+
* Each subdirectory may contain manifest.json or manifest.js.
|
|
254
294
|
* Used with --plugins-dir to discover plugins from source instead of node_modules.
|
|
255
295
|
*
|
|
256
296
|
* @param dir - Absolute path to the directory containing plugin subdirectories
|
|
257
|
-
* @param packageName - Package name to assign to discovered plugins
|
|
297
|
+
* @param packageName - Package name to assign to discovered plugins (used when cwd is not set)
|
|
298
|
+
* @param cwd - When set, each plugin's package is set to ./<path from cwd to plugin subdir>, e.g. ./server/my-plugin
|
|
258
299
|
* @returns Map of plugin name to template plugin entry
|
|
259
300
|
*/
|
|
260
|
-
function scanPluginsDir(dir, packageName) {
|
|
301
|
+
async function scanPluginsDir(dir, packageName, allowJsManifest, cwd) {
|
|
261
302
|
const plugins = {};
|
|
262
303
|
if (!fs.existsSync(dir)) return plugins;
|
|
263
304
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
264
305
|
for (const entry of entries) {
|
|
265
306
|
if (!entry.isDirectory()) continue;
|
|
266
|
-
const
|
|
267
|
-
|
|
307
|
+
const pluginDir = path.join(dir, entry.name);
|
|
308
|
+
const resolved = resolveManifestInDir(pluginDir, { allowJsManifest });
|
|
309
|
+
if (!resolved) continue;
|
|
310
|
+
const pkg = cwd !== void 0 ? `./${path.relative(cwd, pluginDir)}` : packageName;
|
|
268
311
|
try {
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
if (manifest && !manifest.hidden) plugins[manifest.name] = {
|
|
272
|
-
name: manifest.name,
|
|
273
|
-
displayName: manifest.displayName,
|
|
274
|
-
description: manifest.description,
|
|
275
|
-
package: packageName,
|
|
276
|
-
resources: manifest.resources,
|
|
277
|
-
...manifest.onSetupMessage && { onSetupMessage: manifest.onSetupMessage }
|
|
278
|
-
};
|
|
312
|
+
const pluginEntry = await loadPluginEntry(resolved, pkg, allowJsManifest);
|
|
313
|
+
if (pluginEntry) plugins[pluginEntry[0]] = pluginEntry[1];
|
|
279
314
|
} catch (error) {
|
|
280
|
-
console.warn(`Warning: Failed to
|
|
315
|
+
console.warn(`Warning: Failed to load manifest at ${resolved.path}:`, error instanceof Error ? error.message : error);
|
|
281
316
|
}
|
|
282
317
|
}
|
|
283
318
|
return plugins;
|
|
@@ -309,14 +344,18 @@ function writeManifest(outputPath, { plugins }, options) {
|
|
|
309
344
|
* manifests, then marks plugins that are actually used in the `plugins: [...]`
|
|
310
345
|
* array as requiredByTemplate.
|
|
311
346
|
*/
|
|
312
|
-
function runPluginsSync(options) {
|
|
347
|
+
async function runPluginsSync(options) {
|
|
313
348
|
const cwd = process.cwd();
|
|
349
|
+
const allowJsManifest = Boolean(options.allowJsManifest);
|
|
314
350
|
const outputPath = path.resolve(cwd, options.output || "appkit.plugins.json");
|
|
315
351
|
if (!isWithinDirectory(outputPath, cwd)) {
|
|
316
352
|
console.error(`Error: Output path "${options.output}" resolves outside the project directory.`);
|
|
317
353
|
process.exit(1);
|
|
318
354
|
}
|
|
319
|
-
if (!options.silent)
|
|
355
|
+
if (!options.silent) {
|
|
356
|
+
console.log("Scanning for AppKit plugins...\n");
|
|
357
|
+
if (allowJsManifest) console.warn("Warning: --allow-js-manifest executes manifest.js/manifest.cjs files. Only use with trusted code.");
|
|
358
|
+
}
|
|
320
359
|
const serverFile = findServerFile(cwd);
|
|
321
360
|
let serverImports = [];
|
|
322
361
|
let pluginUsages = /* @__PURE__ */ new Set();
|
|
@@ -337,15 +376,23 @@ function runPluginsSync(options) {
|
|
|
337
376
|
const resolvedDir = path.resolve(cwd, options.pluginsDir);
|
|
338
377
|
const pkgName = options.packageName ?? "@databricks/appkit";
|
|
339
378
|
if (!options.silent) console.log(`Scanning plugins directory: ${options.pluginsDir}`);
|
|
340
|
-
Object.assign(plugins, scanPluginsDir(resolvedDir, pkgName));
|
|
379
|
+
Object.assign(plugins, await scanPluginsDir(resolvedDir, pkgName, allowJsManifest));
|
|
341
380
|
} else {
|
|
342
381
|
const npmPackages = new Set([...KNOWN_PLUGIN_PACKAGES, ...npmImports.map((i) => i.source)]);
|
|
343
|
-
Object.assign(plugins, scanForPlugins(cwd, npmPackages));
|
|
382
|
+
Object.assign(plugins, await scanForPlugins(cwd, npmPackages, allowJsManifest));
|
|
344
383
|
}
|
|
345
384
|
if (serverFile && localImports.length > 0) {
|
|
346
|
-
const localPlugins = discoverLocalPlugins(localImports, path.dirname(serverFile), cwd);
|
|
385
|
+
const localPlugins = await discoverLocalPlugins(localImports, path.dirname(serverFile), cwd, allowJsManifest);
|
|
347
386
|
Object.assign(plugins, localPlugins);
|
|
348
387
|
}
|
|
388
|
+
const localDirsToScan = options.localPluginsDir ? [options.localPluginsDir] : CONVENTIONAL_LOCAL_PLUGIN_DIRS.filter((d) => fs.existsSync(path.join(cwd, d)));
|
|
389
|
+
for (const dir of localDirsToScan) {
|
|
390
|
+
const resolvedDir = path.resolve(cwd, dir);
|
|
391
|
+
if (!fs.existsSync(resolvedDir)) continue;
|
|
392
|
+
if (!options.silent) console.log(`Scanning local plugins directory: ${dir}`);
|
|
393
|
+
const discovered = await scanPluginsDirRecursive(resolvedDir, cwd, allowJsManifest);
|
|
394
|
+
for (const [name, entry] of Object.entries(discovered)) if (!plugins[name]) plugins[name] = entry;
|
|
395
|
+
}
|
|
349
396
|
const pluginCount = Object.keys(plugins).length;
|
|
350
397
|
if (pluginCount === 0) {
|
|
351
398
|
if (options.silent) {
|
|
@@ -353,7 +400,7 @@ function runPluginsSync(options) {
|
|
|
353
400
|
return;
|
|
354
401
|
}
|
|
355
402
|
console.log("No plugins found.");
|
|
356
|
-
if (options.pluginsDir) console.log(`\nNo manifest.json
|
|
403
|
+
if (options.pluginsDir) console.log(`\nNo manifest (${allowJsManifest ? "manifest.json or manifest.js" : "manifest.json"}) found in: ${options.pluginsDir}`);
|
|
357
404
|
else console.log("\nMake sure you have plugin packages installed.");
|
|
358
405
|
process.exit(1);
|
|
359
406
|
}
|
|
@@ -387,7 +434,10 @@ function runPluginsSync(options) {
|
|
|
387
434
|
}
|
|
388
435
|
writeManifest(outputPath, { plugins }, options);
|
|
389
436
|
}
|
|
390
|
-
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)").action(runPluginsSync)
|
|
437
|
+
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)").action((opts) => runPluginsSync(opts).catch((err) => {
|
|
438
|
+
console.error(err);
|
|
439
|
+
process.exit(1);
|
|
440
|
+
}));
|
|
391
441
|
|
|
392
442
|
//#endregion
|
|
393
443
|
export { pluginsSyncCommand };
|
|
@@ -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 type {\n PluginManifest,\n TemplatePlugin,\n TemplatePluginsManifest,\n} from \"../manifest-types\";\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/**\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 * 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.json.\n * Follows the convention that plugins live in their own directory with a manifest.json.\n *\n * Resolution strategy:\n * 1. If the import path is a directory, look for manifest.json directly in it\n * 2. If the import path + extension is a file, look for manifest.json in its parent directory\n * 3. If the import path is a directory with an index file, look for manifest.json 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 Absolute path to manifest.json, or null if not found\n */\nfunction resolveLocalManifest(\n importSource: string,\n serverFileDir: string,\n projectRoot?: string,\n): string | 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 with manifest.json\n // e.g. ./plugins/my-plugin → ./plugins/my-plugin/manifest.json\n if (fs.existsSync(resolved) && fs.statSync(resolved).isDirectory()) {\n const manifestPath = path.join(resolved, \"manifest.json\");\n if (fs.existsSync(manifestPath)) return manifestPath;\n }\n\n // Case 2: Import path + extension resolves to a file\n // e.g. ./plugins/my-plugin → ./plugins/my-plugin.ts\n // Look for manifest.json in the same directory\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 const manifestPath = path.join(dir, \"manifest.json\");\n if (fs.existsSync(manifestPath)) return manifestPath;\n break;\n }\n }\n\n // Case 3: Import path is a directory with an index file\n // e.g. ./plugins/my-plugin → ./plugins/my-plugin/index.ts\n for (const ext of RESOLVE_EXTENSIONS) {\n const indexPath = path.join(resolved, `index${ext}`);\n if (fs.existsSync(indexPath)) {\n const manifestPath = path.join(resolved, \"manifest.json\");\n if (fs.existsSync(manifestPath)) return manifestPath;\n break;\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 looks for manifest.json.\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 */\nfunction discoverLocalPlugins(\n relativeImports: ParsedImport[],\n serverFileDir: string,\n cwd: string,\n): TemplatePluginsManifest[\"plugins\"] {\n const plugins: TemplatePluginsManifest[\"plugins\"] = {};\n\n for (const imp of relativeImports) {\n const manifestPath = resolveLocalManifest(imp.source, serverFileDir, cwd);\n if (!manifestPath) continue;\n\n try {\n const content = fs.readFileSync(manifestPath, \"utf-8\");\n const parsed = JSON.parse(content);\n const manifest = validateManifestWithSchema(parsed, manifestPath);\n if (!manifest || manifest.hidden) continue;\n\n const relativePath = path.relative(cwd, path.dirname(manifestPath));\n\n plugins[manifest.name] = {\n name: manifest.name,\n displayName: manifest.displayName,\n description: manifest.description,\n package: `./${relativePath}`,\n resources: manifest.resources,\n ...(manifest.onSetupMessage && {\n onSetupMessage: manifest.onSetupMessage,\n }),\n };\n } catch (error) {\n console.warn(\n `Warning: Failed to parse manifest at ${manifestPath}:`,\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 files 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 */\nfunction discoverPluginManifests(packagePath: string): 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()) {\n const manifestPath = path.join(pluginsDir, entry.name, \"manifest.json\");\n if (fs.existsSync(manifestPath)) {\n try {\n const content = fs.readFileSync(manifestPath, \"utf-8\");\n const parsed = JSON.parse(content);\n const manifest = validateManifestWithSchema(parsed, manifestPath);\n if (manifest) {\n manifests.push(manifest);\n }\n } catch (error) {\n console.warn(\n `Warning: Failed to parse manifest at ${manifestPath}:`,\n error instanceof Error ? error.message : error,\n );\n }\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 */\nfunction scanForPlugins(\n cwd: string,\n packages: Iterable<string>,\n): 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 manifests = discoverPluginManifests(packagePath);\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 };\n }\n }\n\n return plugins;\n}\n\n/**\n * Scan a directory for plugin manifests in direct subdirectories.\n * Each subdirectory is expected to contain a manifest.json file.\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\n * @returns Map of plugin name to template plugin entry\n */\nfunction scanPluginsDir(\n dir: string,\n packageName: string,\n): 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 manifestPath = path.join(dir, entry.name, \"manifest.json\");\n if (!fs.existsSync(manifestPath)) continue;\n\n try {\n const content = fs.readFileSync(manifestPath, \"utf-8\");\n const parsed = JSON.parse(content);\n const manifest = validateManifestWithSchema(parsed, manifestPath);\n if (manifest && !manifest.hidden) {\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 };\n }\n } catch (error) {\n console.warn(\n `Warning: Failed to parse manifest at ${manifestPath}:`,\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 },\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 if (options.write) {\n fs.writeFileSync(\n outputPath,\n `${JSON.stringify(templateManifest, null, 2)}\\n`,\n );\n if (!options.silent) {\n console.log(`\\n✓ Wrote ${outputPath}`);\n }\n } else if (!options.silent) {\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(JSON.stringify(templateManifest, null, 2));\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 */\nfunction runPluginsSync(options: {\n write?: boolean;\n output?: string;\n silent?: boolean;\n requirePlugins?: string;\n pluginsDir?: string;\n packageName?: string;\n}) {\n const cwd = process.cwd();\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) {\n console.log(\"Scanning for AppKit plugins...\\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) {\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) {\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) {\n console.log(`Scanning plugins directory: ${options.pluginsDir}`);\n }\n Object.assign(plugins, scanPluginsDir(resolvedDir, pkgName));\n } else {\n const npmPackages = new Set([\n ...KNOWN_PLUGIN_PACKAGES,\n ...npmImports.map((i) => i.source),\n ]);\n Object.assign(plugins, scanForPlugins(cwd, npmPackages));\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 = discoverLocalPlugins(localImports, serverFileDir, cwd);\n Object.assign(plugins, localPlugins);\n }\n\n const pluginCount = Object.keys(plugins).length;\n\n if (pluginCount === 0) {\n if (options.silent) {\n writeManifest(outputPath, { plugins: {} }, options);\n return;\n }\n console.log(\"No plugins found.\");\n if (options.pluginsDir) {\n console.log(`\\nNo manifest.json files found in: ${options.pluginsDir}`);\n } else {\n console.log(\"\\nMake sure you have plugin packages installed.\");\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) {\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. */\nexport { isWithinDirectory, parseImports, parsePluginUsages };\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 .action(runPluginsSync);\n"],"mappings":";;;;;;;;;;;;;;;AAsBA,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;;;;;;AAOT,MAAM,wBAAwB,CAAC,qBAAqB;;;;;AAMpD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,SAAS,UAAU,eAAe,eAC1H;;;AAIL,eAAc,YAAY,EAAE,SAAS,EAAE,QAAQ;;AAMjD,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,OAAO,eAAe"}
|
|
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 },\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 if (options.write) {\n fs.writeFileSync(\n outputPath,\n `${JSON.stringify(templateManifest, null, 2)}\\n`,\n );\n if (!options.silent) {\n console.log(`\\n✓ Wrote ${outputPath}`);\n }\n } else if (!options.silent) {\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(JSON.stringify(templateManifest, null, 2));\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 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) {\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) {\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) {\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) {\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) {\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) {\n writeManifest(outputPath, { plugins: {} }, options);\n return;\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(\"\\nMake sure you have plugin packages installed.\");\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) {\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 .action((opts) =>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
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
//#region src/cli/commands/plugin/trusted-js-manifest.ts
|
|
4
|
+
const TRUSTED_JS_MANIFEST_PACKAGE_PREFIXES = ["@databricks/"];
|
|
5
|
+
function shouldAllowJsManifestForPackage(packageName) {
|
|
6
|
+
return TRUSTED_JS_MANIFEST_PACKAGE_PREFIXES.some((prefix) => packageName.startsWith(prefix));
|
|
7
|
+
}
|
|
8
|
+
function getNodeModulesPackageName(filePath) {
|
|
9
|
+
const parts = path.resolve(filePath).split(path.sep).filter(Boolean);
|
|
10
|
+
const nodeModulesIndex = parts.lastIndexOf("node_modules");
|
|
11
|
+
if (nodeModulesIndex === -1 || nodeModulesIndex + 1 >= parts.length) return null;
|
|
12
|
+
const maybeScope = parts[nodeModulesIndex + 1];
|
|
13
|
+
if (maybeScope.startsWith("@")) {
|
|
14
|
+
const packageName = parts[nodeModulesIndex + 2];
|
|
15
|
+
if (!packageName) return null;
|
|
16
|
+
return `${maybeScope}/${packageName}`;
|
|
17
|
+
}
|
|
18
|
+
return maybeScope;
|
|
19
|
+
}
|
|
20
|
+
function shouldAllowJsManifestForDir(dirPath) {
|
|
21
|
+
const packageName = getNodeModulesPackageName(dirPath);
|
|
22
|
+
if (!packageName) return false;
|
|
23
|
+
return shouldAllowJsManifestForPackage(packageName);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { shouldAllowJsManifestForDir, shouldAllowJsManifestForPackage };
|
|
28
|
+
//# sourceMappingURL=trusted-js-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trusted-js-manifest.js","names":[],"sources":["../../../../src/cli/commands/plugin/trusted-js-manifest.ts"],"sourcesContent":["import path from \"node:path\";\n\nexport const TRUSTED_JS_MANIFEST_PACKAGE_PREFIXES = [\"@databricks/\"];\n\nexport function shouldAllowJsManifestForPackage(packageName: string): boolean {\n return TRUSTED_JS_MANIFEST_PACKAGE_PREFIXES.some((prefix) =>\n packageName.startsWith(prefix),\n );\n}\n\nexport function getNodeModulesPackageName(filePath: string): string | null {\n const parts = path.resolve(filePath).split(path.sep).filter(Boolean);\n const nodeModulesIndex = parts.lastIndexOf(\"node_modules\");\n if (nodeModulesIndex === -1 || nodeModulesIndex + 1 >= parts.length) {\n return null;\n }\n\n const maybeScope = parts[nodeModulesIndex + 1];\n if (maybeScope.startsWith(\"@\")) {\n const packageName = parts[nodeModulesIndex + 2];\n if (!packageName) return null;\n return `${maybeScope}/${packageName}`;\n }\n\n return maybeScope;\n}\n\nexport function shouldAllowJsManifestForDir(dirPath: string): boolean {\n const packageName = getNodeModulesPackageName(dirPath);\n if (!packageName) return false;\n return shouldAllowJsManifestForPackage(packageName);\n}\n"],"mappings":";;;AAEA,MAAa,uCAAuC,CAAC,eAAe;AAEpE,SAAgB,gCAAgC,aAA8B;AAC5E,QAAO,qCAAqC,MAAM,WAChD,YAAY,WAAW,OAAO,CAC/B;;AAGH,SAAgB,0BAA0B,UAAiC;CACzE,MAAM,QAAQ,KAAK,QAAQ,SAAS,CAAC,MAAM,KAAK,IAAI,CAAC,OAAO,QAAQ;CACpE,MAAM,mBAAmB,MAAM,YAAY,eAAe;AAC1D,KAAI,qBAAqB,MAAM,mBAAmB,KAAK,MAAM,OAC3D,QAAO;CAGT,MAAM,aAAa,MAAM,mBAAmB;AAC5C,KAAI,WAAW,WAAW,IAAI,EAAE;EAC9B,MAAM,cAAc,MAAM,mBAAmB;AAC7C,MAAI,CAAC,YAAa,QAAO;AACzB,SAAO,GAAG,WAAW,GAAG;;AAG1B,QAAO;;AAGT,SAAgB,4BAA4B,SAA0B;CACpE,MAAM,cAAc,0BAA0B,QAAQ;AACtD,KAAI,CAAC,YAAa,QAAO;AACzB,QAAO,gCAAgC,YAAY"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { loadManifestFromFile, resolveManifestInDir } from "../manifest-resolve.js";
|
|
1
2
|
import { detectSchemaType, formatValidationErrors, validateManifest, validateTemplateManifest } from "./validate-manifest.js";
|
|
2
3
|
import fs from "node:fs";
|
|
3
4
|
import path from "node:path";
|
|
@@ -5,7 +6,7 @@ import { Command } from "commander";
|
|
|
5
6
|
import process from "node:process";
|
|
6
7
|
|
|
7
8
|
//#region src/cli/commands/plugin/validate/validate.ts
|
|
8
|
-
function resolveManifestPaths(paths, cwd) {
|
|
9
|
+
function resolveManifestPaths(paths, cwd, allowJsManifest) {
|
|
9
10
|
const out = [];
|
|
10
11
|
for (const p of paths) {
|
|
11
12
|
const resolved = path.resolve(cwd, p);
|
|
@@ -14,35 +15,49 @@ function resolveManifestPaths(paths, cwd) {
|
|
|
14
15
|
continue;
|
|
15
16
|
}
|
|
16
17
|
if (fs.statSync(resolved).isDirectory()) {
|
|
17
|
-
const pluginManifest = path.join(resolved, "manifest.json");
|
|
18
|
-
const templateManifest = path.join(resolved, "appkit.plugins.json");
|
|
19
18
|
let found = false;
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const pluginResolved = resolveManifestInDir(resolved, { allowJsManifest });
|
|
20
|
+
if (pluginResolved) {
|
|
21
|
+
out.push(pluginResolved);
|
|
22
22
|
found = true;
|
|
23
23
|
}
|
|
24
|
+
const templateManifest = path.join(resolved, "appkit.plugins.json");
|
|
24
25
|
if (fs.existsSync(templateManifest)) {
|
|
25
|
-
out.push(
|
|
26
|
+
out.push({
|
|
27
|
+
path: templateManifest,
|
|
28
|
+
type: "json"
|
|
29
|
+
});
|
|
26
30
|
found = true;
|
|
27
31
|
}
|
|
28
|
-
if (!found) console.error(`No manifest.json or appkit.plugins.json in directory: ${p}`);
|
|
29
|
-
} else
|
|
32
|
+
if (!found) console.error(`No ${allowJsManifest ? "manifest.json, manifest.js, or" : "manifest.json or"} appkit.plugins.json in directory: ${p}`);
|
|
33
|
+
} else {
|
|
34
|
+
const ext = path.extname(resolved).toLowerCase();
|
|
35
|
+
if (!allowJsManifest && (ext === ".js" || ext === ".cjs")) {
|
|
36
|
+
console.error(`JS manifest provided but disabled by default: ${p}. Re-run with --allow-js-manifest to opt in.`);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
out.push({
|
|
40
|
+
path: resolved,
|
|
41
|
+
type: ext === ".js" || ext === ".cjs" ? "js" : "json"
|
|
42
|
+
});
|
|
43
|
+
}
|
|
30
44
|
}
|
|
31
45
|
return out;
|
|
32
46
|
}
|
|
33
|
-
function runPluginValidate(paths) {
|
|
47
|
+
async function runPluginValidate(paths, options) {
|
|
34
48
|
const cwd = process.cwd();
|
|
35
|
-
const
|
|
49
|
+
const allowJsManifest = Boolean(options.allowJsManifest);
|
|
50
|
+
if (allowJsManifest) console.warn("Warning: --allow-js-manifest executes manifest.js/manifest.cjs files. Only use with trusted code.");
|
|
51
|
+
const manifestPaths = resolveManifestPaths(paths.length > 0 ? paths : ["."], cwd, allowJsManifest);
|
|
36
52
|
if (manifestPaths.length === 0) {
|
|
37
53
|
console.error("No manifest files to validate.");
|
|
38
54
|
process.exit(1);
|
|
39
55
|
}
|
|
40
56
|
let hasFailure = false;
|
|
41
|
-
for (const manifestPath of manifestPaths) {
|
|
57
|
+
for (const { path: manifestPath, type } of manifestPaths) {
|
|
42
58
|
let obj;
|
|
43
59
|
try {
|
|
44
|
-
|
|
45
|
-
obj = JSON.parse(raw);
|
|
60
|
+
obj = await loadManifestFromFile(manifestPath, type, { allowJsManifest });
|
|
46
61
|
} catch (err) {
|
|
47
62
|
console.error(`✗ ${manifestPath}`);
|
|
48
63
|
console.error(` ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -60,7 +75,10 @@ function runPluginValidate(paths) {
|
|
|
60
75
|
}
|
|
61
76
|
process.exit(hasFailure ? 1 : 0);
|
|
62
77
|
}
|
|
63
|
-
const pluginValidateCommand = new Command("validate").description("Validate plugin manifest(s) or template manifests against their JSON schema").argument("[paths...]", "Paths to manifest.json
|
|
78
|
+
const pluginValidateCommand = new Command("validate").description("Validate plugin manifest(s) or template manifests against their JSON schema").argument("[paths...]", "Paths to manifest.json or appkit.plugins.json (or plugin directories); use --allow-js-manifest to include manifest.js").option("--allow-js-manifest", "Allow reading manifest.js/manifest.cjs (executes code; use only with trusted plugins)").action((paths, opts) => runPluginValidate(paths, opts).catch((err) => {
|
|
79
|
+
console.error(err);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}));
|
|
64
82
|
|
|
65
83
|
//#endregion
|
|
66
84
|
export { pluginValidateCommand };
|