@mndw/cli 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/meta.json +83 -27
  2. package/dist/mndw.js +391 -101
  3. package/host-dev/assets/index-BqQCCILo.css +1 -0
  4. package/host-dev/assets/index-DFVRx7na.js +94 -0
  5. package/host-dev/assets/sandbox-url-D8HO7UBF.js +1 -0
  6. package/host-dev/index.html +3 -3
  7. package/host-dev/shared/mndw-ui@0.2.0.js +1805 -0
  8. package/package.json +18 -14
  9. package/templates/angular/i18n/en.json +4 -9
  10. package/templates/angular/i18n/ru.json +4 -9
  11. package/templates/angular/src/app.component.ts +39 -39
  12. package/templates/angular/src/index.ts +14 -1
  13. package/templates/angular/src/l10n.test.ts +50 -17
  14. package/templates/go/i18n/en.json +1 -1
  15. package/templates/go/i18n/ru.json +1 -1
  16. package/templates/go/src/index.css +4 -20
  17. package/templates/go/src/index.test.ts +12 -24
  18. package/templates/go/src/index.ts +18 -15
  19. package/templates/go/src/l10n.test.ts +37 -23
  20. package/templates/svelte/i18n/en.json +4 -9
  21. package/templates/svelte/i18n/ru.json +4 -9
  22. package/templates/svelte/src/App.svelte +46 -72
  23. package/templates/svelte/src/index.ts +7 -0
  24. package/templates/svelte/src/l10n.test.ts +64 -17
  25. package/templates/svelte/svelte.config.js +7 -0
  26. package/templates/svelte/vitest.config.ts +2 -1
  27. package/templates/vanilla/i18n/en.json +4 -3
  28. package/templates/vanilla/i18n/ru.json +4 -3
  29. package/templates/vanilla/src/index.css +4 -20
  30. package/templates/vanilla/src/index.ts +47 -17
  31. package/templates/vanilla/src/l10n.test.ts +50 -17
  32. package/templates/vue/i18n/en.json +4 -9
  33. package/templates/vue/i18n/ru.json +4 -9
  34. package/templates/vue/src/App.vue +36 -54
  35. package/templates/vue/src/index.ts +7 -0
  36. package/templates/vue/src/l10n.test.ts +50 -17
  37. package/host-dev/assets/index-CJ80zEWN.js +0 -94
  38. package/host-dev/assets/index-DNxACGUr.css +0 -1
  39. package/host-dev/assets/sandbox-url-Dk7HpxDp.js +0 -1
  40. package/host-dev/shared/mndw-ui@0.1.5.js +0 -1782
  41. package/templates/angular/src/table.test.ts +0 -59
  42. package/templates/svelte/src/TableNameCell.svelte +0 -10
  43. package/templates/svelte/src/table.test.ts +0 -53
  44. package/templates/vue/src/TableNameCell.vue +0 -12
  45. package/templates/vue/src/table.test.ts +0 -53
package/dist/mndw.js CHANGED
@@ -1,46 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import {createRequire as __mndwCreateRequire} from "node:module";
3
3
  const require = __mndwCreateRequire(import.meta.url);
4
- var __create = Object.create;
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __commonJS = (cb, mod) => function __require() {
11
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
-
30
- // ../../build/svelte-compiler-options.js
31
- var require_svelte_compiler_options = __commonJS({
32
- "../../build/svelte-compiler-options.js"(exports, module) {
33
- "use strict";
34
- var IGNORED_MNDW_BUTTON_WARNING_CODES = /* @__PURE__ */ new Set([
35
- "a11y_click_events_have_key_events",
36
- "a11y_no_static_element_interactions"
37
- ]);
38
- function isMndwButtonA11yWarning2(warning) {
39
- return IGNORED_MNDW_BUTTON_WARNING_CODES.has(warning.code ?? "") && (warning.message ?? "").includes("<mndw-button>");
40
- }
41
- module.exports = { isMndwButtonA11yWarning: isMndwButtonA11yWarning2 };
42
- }
43
- });
44
4
 
45
5
  // src/index.ts
46
6
  import { Command, Option } from "commander";
@@ -251,7 +211,8 @@ var eventSchema = z.union([
251
211
  available_bytes: nonNegativeInteger,
252
212
  threshold_bytes: nonNegativeInteger
253
213
  }).strict()
254
- )
214
+ ),
215
+ eventBranch("telemetry.gathering_changed", "internal", z.object({ enabled: z.boolean() }).strict())
255
216
  ]).superRefine((event, context) => {
256
217
  const encoded = new TextEncoder().encode(JSON.stringify(event.payload));
257
218
  if (encoded.length > MaxEventPayloadBytes) {
@@ -325,6 +286,150 @@ var backendStatusSchema = z3.preprocess(
325
286
  rejectVariantOnlyFields,
326
287
  z3.discriminatedUnion("state", [blockedStatusSchema, incompatibleStatusSchema, plainStatusSchema])
327
288
  );
289
+ var RETRYABLE_CODES = /* @__PURE__ */ new Set([
290
+ "BACKEND_BUSY",
291
+ "BACKEND_STARTING",
292
+ "BACKEND_UNAVAILABLE",
293
+ "BACKEND_MAINTENANCE",
294
+ "BAD_GATEWAY",
295
+ "SERVER_BUSY",
296
+ "REQUEST_TIMEOUT",
297
+ "SCRIPT_TIMEOUT",
298
+ "STATUS_QUERY_FAILED"
299
+ ]);
300
+ var isRetryable = (code, status) => {
301
+ if (code === "HTTP_ERROR") {
302
+ return status === 408 || status === 425 || status === 429 || status !== void 0 && status >= 500;
303
+ }
304
+ return RETRYABLE_CODES.has(code);
305
+ };
306
+ var BackendError = class extends Error {
307
+ id;
308
+ code;
309
+ status;
310
+ retryable;
311
+ details;
312
+ constructor(message, code, id, options = {}) {
313
+ super(message);
314
+ this.name = "BackendError";
315
+ this.code = code;
316
+ this.id = id;
317
+ this.status = options.status;
318
+ this.retryable = options.retryable ?? isRetryable(code, options.status);
319
+ this.details = options.details;
320
+ }
321
+ };
322
+ var BackendUnknownId = class extends BackendError {
323
+ code;
324
+ constructor(id, options = {}) {
325
+ const code = options.code ?? "UNKNOWN_ID";
326
+ super(`Unknown backend binding id: "${id}"`, code, id, options);
327
+ this.code = code;
328
+ this.name = "BackendUnknownId";
329
+ }
330
+ };
331
+ var BackendNotApproved = class extends BackendError {
332
+ code = "NOT_APPROVED";
333
+ constructor(id, options = {}) {
334
+ super(`Backend "${id}" is not approved`, "NOT_APPROVED", id, options);
335
+ this.name = "BackendNotApproved";
336
+ }
337
+ };
338
+ var BackendDisabled = class extends BackendError {
339
+ code = "DISABLED";
340
+ constructor(id, options = {}) {
341
+ super(`Backend "${id}" is disabled`, "DISABLED", id, options);
342
+ this.name = "BackendDisabled";
343
+ }
344
+ };
345
+ var BackendStarting = class extends BackendError {
346
+ constructor(id, retryAfterSeconds, options = {}) {
347
+ super(`Backend "${id}" is starting`, "BACKEND_STARTING", id, options);
348
+ this.retryAfterSeconds = retryAfterSeconds;
349
+ this.name = "BackendStarting";
350
+ }
351
+ code = "BACKEND_STARTING";
352
+ };
353
+ var BackendUnavailable = class extends BackendError {
354
+ code = "BACKEND_UNAVAILABLE";
355
+ constructor(id, options = {}) {
356
+ super(`Backend "${id}" is unavailable`, "BACKEND_UNAVAILABLE", id, options);
357
+ this.name = "BackendUnavailable";
358
+ }
359
+ };
360
+ var BackendIncompatible = class extends BackendError {
361
+ code = "BACKEND_INCOMPATIBLE";
362
+ constructor(id, options = {}) {
363
+ super(`Backend "${id}" is incompatible`, "BACKEND_INCOMPATIBLE", id, options);
364
+ this.name = "BackendIncompatible";
365
+ }
366
+ };
367
+ var BackendMaintenance = class extends BackendError {
368
+ constructor(id, retryAfterSeconds, options = {}) {
369
+ super(`Backend "${id}" is under maintenance`, "BACKEND_MAINTENANCE", id, options);
370
+ this.retryAfterSeconds = retryAfterSeconds;
371
+ this.name = "BackendMaintenance";
372
+ }
373
+ code = "BACKEND_MAINTENANCE";
374
+ };
375
+ var BackendBlocked = class extends BackendError {
376
+ constructor(id, blockers, retryAfterSeconds, options = {}) {
377
+ super(`Backend "${id}" is blocked on an unmet activation prerequisite`, "BACKEND_BLOCKED", id, options);
378
+ this.blockers = blockers;
379
+ this.retryAfterSeconds = retryAfterSeconds;
380
+ this.name = "BackendBlocked";
381
+ }
382
+ code = "BACKEND_BLOCKED";
383
+ };
384
+ var BackendBadGateway = class extends BackendError {
385
+ code = "BAD_GATEWAY";
386
+ constructor(id, options = {}) {
387
+ super(`Backend "${id}" returned a bad gateway response`, "BAD_GATEWAY", id, options);
388
+ this.name = "BackendBadGateway";
389
+ }
390
+ };
391
+ var parseRetryAfterSeconds = (response) => {
392
+ const raw = response.headers.get("Retry-After");
393
+ if (raw === null || !/^\d+$/.test(raw)) {
394
+ return null;
395
+ }
396
+ const value = Number(raw);
397
+ return Number.isSafeInteger(value) ? value : null;
398
+ };
399
+ var parseBlockers = (detail) => {
400
+ const parsed = z3.array(backendBlockerSchema).safeParse(detail);
401
+ return parsed.success ? parsed.data : [];
402
+ };
403
+ var genericErrorFactory = (code, fallback) => {
404
+ return (id, response, error, options) => new BackendError(
405
+ error.message ?? fallback,
406
+ code,
407
+ id,
408
+ { ...options, status: response.status }
409
+ );
410
+ };
411
+ var ERROR_BY_CODE = {
412
+ DISABLED: (id, _res, _error, options) => new BackendDisabled(id, options),
413
+ NOT_APPROVED: (id, _res, _error, options) => new BackendNotApproved(id, options),
414
+ ROUTE_NOT_FOUND: (id, _res, _error, options) => new BackendUnknownId(id, { ...options, code: "ROUTE_NOT_FOUND" }),
415
+ BACKEND_STARTING: (id, res, _error, options) => new BackendStarting(id, parseRetryAfterSeconds(res), options),
416
+ BACKEND_UNAVAILABLE: (id, _res, _error, options) => new BackendUnavailable(id, options),
417
+ BACKEND_INCOMPATIBLE: (id, _res, _error, options) => new BackendIncompatible(id, options),
418
+ BACKEND_MAINTENANCE: (id, res, _error, options) => new BackendMaintenance(id, parseRetryAfterSeconds(res), options),
419
+ BACKEND_BLOCKED: (id, res, error, options) => new BackendBlocked(id, parseBlockers(error.detail), parseRetryAfterSeconds(res), options),
420
+ BAD_GATEWAY: (id, _res, _error, options) => new BackendBadGateway(id, options),
421
+ BAD_REQUEST: genericErrorFactory("BAD_REQUEST", "Backend request was rejected"),
422
+ INTERNAL: genericErrorFactory("INTERNAL", "Backend request failed"),
423
+ SERVER_BUSY: genericErrorFactory("SERVER_BUSY", "Backend request intake is busy"),
424
+ REQUEST_TIMEOUT: genericErrorFactory("REQUEST_TIMEOUT", "Backend request timed out"),
425
+ SCRIPT_FAILED: genericErrorFactory("SCRIPT_FAILED", "Backend script failed"),
426
+ SCRIPT_TIMEOUT: genericErrorFactory("SCRIPT_TIMEOUT", "Backend script timed out"),
427
+ BACKEND_BUSY: genericErrorFactory("BACKEND_BUSY", "Backend is busy"),
428
+ BACKEND_BODY_TOO_LARGE: genericErrorFactory("BACKEND_BODY_TOO_LARGE", "Backend request body is too large"),
429
+ BACKEND_OUTPUT_TOO_LARGE: genericErrorFactory("BACKEND_OUTPUT_TOO_LARGE", "Backend output is too large"),
430
+ CSRF_REQUIRED: genericErrorFactory("CSRF_REQUIRED", "Backend request requires CSRF protection"),
431
+ UNAUTHORIZED: genericErrorFactory("UNAUTHORIZED", "Backend request is unauthorized")
432
+ };
328
433
 
329
434
  // ../../frontend/sdk-internal/src/manifest-schema.ts
330
435
  var pluginNameSchema = z4.string().regex(/^[a-z0-9][a-z0-9-]*$/, {
@@ -417,7 +522,7 @@ var safeBackendRoutePath = (value) => {
417
522
  const segments = decoded.split("/");
418
523
  return segments.every((segment) => segment.length > 0 && segment !== "." && segment !== "..") && segments[0] !== "_mndw";
419
524
  };
420
- var commandSchema = safeRelativePathSchema.refine(hasFileName, { message: "command must include a file name" }).refine((command) => {
525
+ var commandSchema = safeRelativePathSchema.regex(/^backend\//, { message: "command must start with backend/" }).refine(hasFileName, { message: "command must include a file name" }).refine((command) => {
421
526
  return !command.split("/").some((segment) => segment === "." || segment === "..");
422
527
  }, { message: "command must not contain dot segments" });
423
528
  var literalArgumentSchema = z4.string().min(1).refine((value) => {
@@ -461,7 +566,7 @@ var validateRoutes = (routes, ctx) => {
461
566
  var execBackendSchema = z4.object({
462
567
  kind: z4.literal("exec"),
463
568
  packages: z4.array(packageSchema).optional(),
464
- routes: z4.array(execRouteSchema).min(1)
569
+ routes: z4.array(execRouteSchema).min(1, { message: "backend.routes must contain at least one route" })
465
570
  }).strict().superRefine((backend, ctx) => {
466
571
  validateRoutes(backend.routes, ctx);
467
572
  });
@@ -471,16 +576,23 @@ var serviceBackendSchema = z4.object({
471
576
  command: commandSchema,
472
577
  args: z4.array(literalArgumentSchema).optional(),
473
578
  packages: z4.array(packageSchema).optional(),
474
- routes: z4.array(z4.union([httpRouteSchema, websocketRouteSchema])).min(1)
579
+ routes: z4.array(z4.union([httpRouteSchema, websocketRouteSchema])).min(1, {
580
+ message: "backend.routes must contain at least one route"
581
+ })
475
582
  }).strict().superRefine((backend, ctx) => {
476
583
  validateRoutes(backend.routes, ctx);
477
584
  });
478
585
  var backendSchema = z4.union([execBackendSchema, serviceBackendSchema]);
479
- var gridColumns = z4.number().int().positive().max(12);
586
+ var gridColumns = z4.number().int({ message: "gridColumns must be an integer" }).min(1, { message: "gridColumns must be at least 1" }).max(12, { message: "gridColumns must be at most 12" });
480
587
  var gridRows = z4.number().int().positive();
481
588
  var versionSchema = z4.literal(1).describe("Manifest format version. Must be 1.");
482
589
  var nameSchema = pluginNameSchema.describe("Unique plugin id used as the on-disk folder and URL segment.");
483
- var versionField = z4.string().min(1).describe("Semver-ish version string.");
590
+ var versionField = z4.string().regex(
591
+ /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/,
592
+ {
593
+ message: "version must be valid SemVer (for example, 1.2.3)"
594
+ }
595
+ ).describe("Semantic version of this plugin.");
484
596
  var labelField = z4.string().min(1).describe("Human-readable name shown in the dashboard or navigation.");
485
597
  var entryField = pluginEntrySchema.describe("Relative path to the bundled entry module.");
486
598
  var iconField = z4.string().optional().describe("Optional icon name.");
@@ -601,7 +713,7 @@ var SHARED_DEPENDENCIES = [
601
713
  {
602
714
  specifiers: ["@mndw/ui"],
603
715
  bundle: "mndw-ui",
604
- version: "0.1.5",
716
+ version: "0.2.0",
605
717
  entryPoint: "@mndw/ui",
606
718
  external: ["d3"],
607
719
  framework: "base"
@@ -981,6 +1093,7 @@ function readCliMetadata(metadata) {
981
1093
  packageRange("@mndw/ui-angular", dependencies, devDependencies)
982
1094
  )
983
1095
  };
1096
+ const tsxVersion = dependencies.tsx ?? devDependencies.tsx;
984
1097
  return {
985
1098
  version: parsed.version ?? "0.0.0",
986
1099
  uiRange,
@@ -998,6 +1111,7 @@ function readCliMetadata(metadata) {
998
1111
  "typescript": packageRange("typescript", dependencies, devDependencies)
999
1112
  },
1000
1113
  viteRange: packageRange("vite", dependencies, devDependencies),
1114
+ tsxRange: tsxVersion,
1001
1115
  vitestRange: caretRange("vitest", packageRange("vitest", dependencies, devDependencies)),
1002
1116
  happyDomRange: caretRange("happy-dom", packageRange("happy-dom", dependencies, devDependencies))
1003
1117
  };
@@ -1064,12 +1178,19 @@ function renderTemplateDir(framework, normalized) {
1064
1178
  }
1065
1179
  function renderGoTemplate(normalized) {
1066
1180
  const generatedDevDependencies = buildPackageJson(normalized).devDependencies;
1181
+ const cli = readCliMetadata();
1067
1182
  return walkTemplate(join2(TEMPLATES_DIR, "go"), "").map(({ rel, abs }) => {
1068
1183
  let contents = renderPlaceholders(readFileSync3(abs, "utf8"), normalized);
1069
1184
  if (rel === "package.json") {
1070
1185
  const packageJson = JSON.parse(contents);
1071
1186
  packageJson.devDependencies["@mndw/cli"] = generatedDevDependencies["@mndw/cli"];
1072
1187
  packageJson.devDependencies["@mndw/sdk"] = generatedDevDependencies["@mndw/sdk"];
1188
+ if (cli.tsxRange === void 0) {
1189
+ throw new CliError("CLI package is missing dependency range for tsx");
1190
+ }
1191
+ packageJson.devDependencies.tsx = cli.tsxRange;
1192
+ packageJson.devDependencies.vitest = cli.vitestRange;
1193
+ packageJson.devDependencies["happy-dom"] = cli.happyDomRange;
1073
1194
  contents = `${JSON.stringify(packageJson, null, 2)}
1074
1195
  `;
1075
1196
  }
@@ -2368,7 +2489,7 @@ function angularSandboxPlugin(pluginDir, deps = {}) {
2368
2489
  const relativePath = path.relative(sourceDir, sourcePath);
2369
2490
  return !relativePath.startsWith("..") && path.extname(sourcePath) === ".ts" && !sourcePath.endsWith(".d.ts");
2370
2491
  };
2371
- const transform = (_code, id) => {
2492
+ const transform2 = (_code, id) => {
2372
2493
  const sourcePath = path.resolve(stripQuery(id));
2373
2494
  if (!isSourceFile(sourcePath)) {
2374
2495
  return null;
@@ -2435,7 +2556,7 @@ if (typeof document !== 'undefined') {
2435
2556
  export default css;
2436
2557
  `;
2437
2558
  },
2438
- transform,
2559
+ transform: transform2,
2439
2560
  handleHotUpdate,
2440
2561
  configureServer(server) {
2441
2562
  server.httpServer?.once("close", () => compiler.dispose());
@@ -2458,6 +2579,7 @@ function errorMessage(error) {
2458
2579
 
2459
2580
  // src/dev-server/start.ts
2460
2581
  import { svelte } from "@sveltejs/vite-plugin-svelte";
2582
+ import { mndwSvelteWarningFilter } from "@mndw/sdk/svelte";
2461
2583
  import vue from "@vitejs/plugin-vue";
2462
2584
  import { createServer } from "vite";
2463
2585
 
@@ -2742,7 +2864,7 @@ function sharedExternals(framework) {
2742
2864
 
2743
2865
  // src/dev-server/start.ts
2744
2866
  async function startPluginDevServer(options) {
2745
- const frameworkPlugins = options.framework === "svelte" ? [svelte()] : options.framework === "vue" ? [vue({ isProduction: true })] : options.framework === "angular" ? [angularSandboxPlugin(options.pluginDir)] : [];
2867
+ const frameworkPlugins = options.framework === "svelte" ? [svelte({ compilerOptions: { warningFilter: mndwSvelteWarningFilter } })] : options.framework === "vue" ? [vue({ isProduction: true })] : options.framework === "angular" ? [angularSandboxPlugin(options.pluginDir)] : [];
2746
2868
  const server = await createServer({
2747
2869
  root: options.pluginDir,
2748
2870
  cacheDir: resolve13(options.pluginDir, "node_modules", `.vite-${options.framework}-dev`),
@@ -3329,26 +3451,155 @@ function validatePluginCatalogs(pluginDir, manifest, options) {
3329
3451
  return warnings;
3330
3452
  }
3331
3453
 
3454
+ // src/css-scope-validator.ts
3455
+ import { existsSync as existsSync6, readFileSync as readFileSync10 } from "node:fs";
3456
+ import { join as join11 } from "node:path";
3457
+ import postcss from "postcss";
3458
+ var isKeyframesRule = (name) => {
3459
+ return /^(?:-\w+-)?keyframes$/i.test(name);
3460
+ };
3461
+ var isAtRule = (node) => {
3462
+ return node.type === "atrule";
3463
+ };
3464
+ var hasKeyframesAncestor = (rule) => {
3465
+ let node = rule.parent;
3466
+ while (node !== void 0) {
3467
+ if (isAtRule(node) && isKeyframesRule(node.name)) {
3468
+ return true;
3469
+ }
3470
+ node = node.parent;
3471
+ }
3472
+ return false;
3473
+ };
3474
+ var isRootTokenSelector = (selector) => {
3475
+ return /^:root(?:\[data-theme(?:=(?:"[^"]*"|'[^']*'|[^\]]+))?\])*$/.test(selector);
3476
+ };
3477
+ var skipCssEscape = (selector, index) => {
3478
+ let next = index + 1;
3479
+ if (!/[\da-f]/i.test(selector[next] ?? "")) {
3480
+ return Math.min(next + 1, selector.length);
3481
+ }
3482
+ for (let digits = 0; digits < 6 && /[\da-f]/i.test(selector[next] ?? ""); digits++) {
3483
+ next++;
3484
+ }
3485
+ return next + (/[\s]/.test(selector[next] ?? "") ? 1 : 0);
3486
+ };
3487
+ var firstRootCombinator = (selector, start) => {
3488
+ let brackets = 0;
3489
+ let parentheses = 0;
3490
+ let quote;
3491
+ for (let index = start; index < selector.length; index++) {
3492
+ const character = selector[index];
3493
+ if (character === "\\") {
3494
+ index = skipCssEscape(selector, index) - 1;
3495
+ continue;
3496
+ }
3497
+ if (quote !== void 0) {
3498
+ if (character === quote) {
3499
+ quote = void 0;
3500
+ }
3501
+ continue;
3502
+ }
3503
+ if (selector.startsWith("/*", index)) {
3504
+ const commentEnd = selector.indexOf("*/", index + 2);
3505
+ if (commentEnd === -1) {
3506
+ return void 0;
3507
+ }
3508
+ index = commentEnd + 1;
3509
+ continue;
3510
+ }
3511
+ if (character === '"' || character === "'") {
3512
+ quote = character;
3513
+ continue;
3514
+ }
3515
+ if (character === "[") {
3516
+ brackets++;
3517
+ continue;
3518
+ }
3519
+ if (character === "]" && brackets > 0) {
3520
+ brackets--;
3521
+ continue;
3522
+ }
3523
+ if (character === "(") {
3524
+ parentheses++;
3525
+ continue;
3526
+ }
3527
+ if (character === ")" && parentheses > 0) {
3528
+ parentheses--;
3529
+ continue;
3530
+ }
3531
+ if (brackets > 0 || parentheses > 0) {
3532
+ continue;
3533
+ }
3534
+ if (character !== void 0 && "+~>".includes(character)) {
3535
+ return character;
3536
+ }
3537
+ if (character !== void 0 && /\s/.test(character)) {
3538
+ const next = selector.slice(index).replace(/^(?:\s+|\/\*[\s\S]*?\*\/)+/, "")[0];
3539
+ return next !== void 0 && "+~>".includes(next) ? next : " ";
3540
+ }
3541
+ }
3542
+ return void 0;
3543
+ };
3544
+ var isPluginScoped = (selector, pluginName) => {
3545
+ const prefix = `.${pluginName}`;
3546
+ if (!selector.startsWith(prefix)) {
3547
+ return false;
3548
+ }
3549
+ const boundary = selector[prefix.length];
3550
+ if (boundary !== void 0 && !".#:[".includes(boundary) && !/\s/.test(boundary) && !"><+~".includes(boundary)) {
3551
+ return false;
3552
+ }
3553
+ const combinator = firstRootCombinator(selector, prefix.length);
3554
+ return combinator !== "+" && combinator !== "~";
3555
+ };
3556
+ function findUnscopedCssSelectors(css, pluginName, allowlist = []) {
3557
+ const ignored = new Set(allowlist);
3558
+ const violations = [];
3559
+ postcss.parse(css).walkRules((rule) => {
3560
+ if (hasKeyframesAncestor(rule)) {
3561
+ return;
3562
+ }
3563
+ for (const selector of rule.selectors) {
3564
+ if (!ignored.has(selector) && !isRootTokenSelector(selector) && !isPluginScoped(selector, pluginName)) {
3565
+ violations.push(selector);
3566
+ }
3567
+ }
3568
+ });
3569
+ return violations;
3570
+ }
3571
+ function validatePluginCss(pluginDir, pluginName) {
3572
+ const cssPath = join11(pluginDir, "dist", "index.css");
3573
+ if (!existsSync6(cssPath)) {
3574
+ return [];
3575
+ }
3576
+ const css = readFileSync10(cssPath, "utf8");
3577
+ const packageMetadata = readPluginPackage(pluginDir);
3578
+ const configuredAllowlist = packageMetadata?.mndw?.cssSelectorAllowlist;
3579
+ const allowlist = Array.isArray(configuredAllowlist) ? configuredAllowlist.filter((selector) => typeof selector === "string") : [];
3580
+ return findUnscopedCssSelectors(css, pluginName, allowlist).map((selector) => `CSS selector "${selector}" is not scoped under .${pluginName}`);
3581
+ }
3582
+
3332
3583
  // src/pack.ts
3333
3584
  import { createHash } from "node:crypto";
3334
3585
  import {
3335
3586
  chmodSync as chmodSync2,
3336
- existsSync as existsSync8,
3587
+ existsSync as existsSync9,
3337
3588
  mkdirSync as mkdirSync5,
3338
3589
  mkdtempSync as mkdtempSync4,
3339
- readFileSync as readFileSync10,
3590
+ readFileSync as readFileSync11,
3340
3591
  readdirSync as readdirSync5,
3341
3592
  realpathSync,
3342
3593
  rmSync as rmSync6,
3343
3594
  statSync as statSync5,
3344
3595
  writeFileSync as writeFileSync5
3345
3596
  } from "node:fs";
3346
- import { basename as basename2, dirname as dirname8, extname as extname3, isAbsolute as isAbsolute5, join as join12, relative as relative6, resolve as resolve17, sep as sep4 } from "node:path";
3597
+ import { basename as basename2, dirname as dirname8, extname as extname3, isAbsolute as isAbsolute5, join as join13, relative as relative6, resolve as resolve17, sep as sep4 } from "node:path";
3347
3598
  import crossSpawn4 from "cross-spawn";
3348
- import { build } from "esbuild";
3599
+ import { build, transform } from "esbuild";
3349
3600
  import esbuildSvelte from "esbuild-svelte";
3350
3601
  import vuePlugin from "unplugin-vue/esbuild";
3351
- var import_svelte_compiler_options = __toESM(require_svelte_compiler_options(), 1);
3602
+ import { mndwSvelteWarningFilter as mndwSvelteWarningFilter2 } from "@mndw/sdk/svelte";
3352
3603
 
3353
3604
  // src/angular-compiler.ts
3354
3605
  function compileAngular2(pluginDir, sourceEntry = "src/index.ts") {
@@ -3363,14 +3614,14 @@ function compileAngular2(pluginDir, sourceEntry = "src/index.ts") {
3363
3614
  }
3364
3615
 
3365
3616
  // src/cli-node-paths.ts
3366
- import { existsSync as existsSync6, statSync as statSync4 } from "node:fs";
3367
- import { dirname as dirname7, join as join11, resolve as resolve16 } from "node:path";
3617
+ import { existsSync as existsSync7, statSync as statSync4 } from "node:fs";
3618
+ import { dirname as dirname7, join as join12, resolve as resolve16 } from "node:path";
3368
3619
  function cliNodePaths(root = cliPackageRoot()) {
3369
3620
  const paths = [];
3370
3621
  let directory = resolve16(root);
3371
3622
  for (; ; ) {
3372
- const modules = join11(directory, "node_modules");
3373
- if (existsSync6(modules) && statSync4(modules).isDirectory()) {
3623
+ const modules = join12(directory, "node_modules");
3624
+ if (existsSync7(modules) && statSync4(modules).isDirectory()) {
3374
3625
  paths.push(modules);
3375
3626
  }
3376
3627
  const parent = dirname7(directory);
@@ -3385,11 +3636,11 @@ function packNodePaths(pluginDir, cliRoot = cliPackageRoot()) {
3385
3636
  }
3386
3637
 
3387
3638
  // src/promote-directory.ts
3388
- import { existsSync as existsSync7, renameSync, rmSync as rmSync5 } from "node:fs";
3639
+ import { existsSync as existsSync8, renameSync, rmSync as rmSync5 } from "node:fs";
3389
3640
  function promoteDirectory(source, destination) {
3390
3641
  const backup = `${destination}.previous`;
3391
- const hadExisting = existsSync7(destination);
3392
- const hadBackup = existsSync7(backup);
3642
+ const hadExisting = existsSync8(destination);
3643
+ const hadBackup = existsSync8(backup);
3393
3644
  if (hadExisting && hadBackup) {
3394
3645
  rmSync5(backup, { recursive: true, force: true });
3395
3646
  }
@@ -3410,26 +3661,41 @@ function promoteDirectory(source, destination) {
3410
3661
  }
3411
3662
 
3412
3663
  // src/pack.ts
3664
+ async function sanitizeBundleOutput(contents, loader, production) {
3665
+ if (!production) {
3666
+ return Buffer.from(contents);
3667
+ }
3668
+ const source = Buffer.from(contents).toString("utf8");
3669
+ const result = loader === "js" ? await transform(source, {
3670
+ loader: "js",
3671
+ minify: true,
3672
+ legalComments: "inline",
3673
+ format: "esm",
3674
+ target: "es2022"
3675
+ }) : await transform(source, { loader: "css", minify: true, legalComments: "inline" });
3676
+ return Buffer.from(result.code);
3677
+ }
3413
3678
  async function packPlugin(pluginDir, options = {}) {
3414
3679
  const resolvedDir = resolvePluginDir(pluginDir);
3415
3680
  const { manifest } = readManifest(pluginDir);
3416
3681
  const warnings = validatePluginCatalogs(resolvedDir, manifest, { strict: false });
3417
3682
  const sourceEntry = options.development ? resolveDevelopmentSourceEntry(resolvedDir) : resolveProductionSourceEntry(resolvedDir);
3418
3683
  const framework = detectFramework(resolvedDir);
3419
- const outDir = options.outDir === void 0 ? join12(resolvedDir, "dist") : resolve17(process.cwd(), options.outDir);
3420
- const defaultOutDir = join12(resolvedDir, "dist");
3684
+ const outDir = options.outDir === void 0 ? join13(resolvedDir, "dist") : resolve17(process.cwd(), options.outDir);
3685
+ const defaultOutDir = join13(resolvedDir, "dist");
3421
3686
  if (outDir !== defaultOutDir && pathsOverlap(resolvedDir, outDir)) {
3422
3687
  throw new CliError(`Output directory overlaps plugin source: ${outDir}`);
3423
3688
  }
3424
3689
  let angularCompile;
3425
- const entryPoint = framework === "angular" ? (angularCompile = compileAngular2(resolvedDir, sourceEntry)).entryPath : join12(resolvedDir, sourceEntry);
3690
+ const entryPoint = framework === "angular" ? (angularCompile = compileAngular2(resolvedDir, sourceEntry)).entryPath : join13(resolvedDir, sourceEntry);
3426
3691
  try {
3427
- const styleEntry = angularCompile === void 0 ? void 0 : join12(angularCompile.cacheDir, "styles.css");
3428
- const entryPoints = styleEntry !== void 0 && existsSync8(styleEntry) ? [entryPoint, styleEntry] : [entryPoint];
3692
+ const styleEntry = angularCompile === void 0 ? void 0 : join13(angularCompile.cacheDir, "styles.css");
3693
+ const entryPoints = styleEntry !== void 0 && existsSync9(styleEntry) ? [entryPoint, styleEntry] : [entryPoint];
3429
3694
  const result = await build({
3430
3695
  entryPoints,
3431
3696
  outdir: outDir,
3432
3697
  bundle: true,
3698
+ legalComments: "inline",
3433
3699
  format: "esm",
3434
3700
  platform: "browser",
3435
3701
  target: "es2022",
@@ -3442,16 +3708,17 @@ async function packPlugin(pluginDir, options = {}) {
3442
3708
  esbuildSvelte({
3443
3709
  compilerOptions: {
3444
3710
  css: "external",
3445
- warningFilter: (warning) => !(0, import_svelte_compiler_options.isMndwButtonA11yWarning)(warning)
3711
+ warningFilter: mndwSvelteWarningFilter2
3446
3712
  }
3447
3713
  })
3448
3714
  ] : framework === "vue" ? [vuePlugin({
3715
+ isProduction: !options.development,
3449
3716
  sourceMap: false,
3450
3717
  template: { compilerOptions: { isCustomElement: (tag) => tag.startsWith("mndw-") } }
3451
3718
  })] : []
3452
3719
  });
3453
3720
  const jsOutputs = result.outputFiles.filter((file) => file.path.endsWith(".js"));
3454
- const jsOutput = jsOutputs.find((file) => file.path === join12(outDir, "index.js")) ?? jsOutputs[0];
3721
+ const jsOutput = jsOutputs.find((file) => file.path === join13(outDir, "index.js")) ?? jsOutputs[0];
3455
3722
  if (jsOutput === void 0) {
3456
3723
  throw new CliError("esbuild produced no JavaScript bundle");
3457
3724
  }
@@ -3494,15 +3761,29 @@ async function packPlugin(pluginDir, options = {}) {
3494
3761
  };
3495
3762
  const catalogAssets = collectCatalogAssets(manifest, resolvedDir);
3496
3763
  const workerReferences = collectWorkerReferences(manifest.entry, result.metafile);
3497
- const workerAssets = await buildWorkerAssets(workerReferences, outDir, resolvedDir, framework);
3498
- const mainBundle = rewriteWorkerSpecifiers(jsOutput.contents, workerReferences);
3764
+ const workerAssets = await buildWorkerAssets(
3765
+ workerReferences,
3766
+ outDir,
3767
+ resolvedDir,
3768
+ framework,
3769
+ !options.development
3770
+ );
3771
+ const mainBundle = await sanitizeBundleOutput(
3772
+ rewriteWorkerSpecifiers(jsOutput.contents, workerReferences),
3773
+ "js",
3774
+ !options.development
3775
+ );
3499
3776
  const parent = dirname8(outDir);
3500
3777
  mkdirSync5(parent, { recursive: true });
3501
- const staging = mkdtempSync4(join12(parent, ".mndw-pack-"));
3778
+ const staging = mkdtempSync4(join13(parent, ".mndw-pack-"));
3502
3779
  try {
3503
3780
  writeStaged(staging, manifest.entry, mainBundle);
3504
3781
  if (cssOutput !== void 0) {
3505
- writeStaged(staging, "index.css", Buffer.from(cssOutput.contents));
3782
+ writeStaged(
3783
+ staging,
3784
+ "index.css",
3785
+ await sanitizeBundleOutput(cssOutput.contents, "css", !options.development)
3786
+ );
3506
3787
  }
3507
3788
  writeStaged(staging, "manifest.json", Buffer.from(`${JSON.stringify(manifest, null, 2)}
3508
3789
  `));
@@ -3519,7 +3800,7 @@ async function packPlugin(pluginDir, options = {}) {
3519
3800
  if (isAbsolute5(rel) || rel === ".." || rel.startsWith(`..${sep4}`)) {
3520
3801
  throw new CliError(`esbuild output escapes plugin directory: ${output.path}`);
3521
3802
  }
3522
- writeStaged(staging, rel, Buffer.from(output.contents));
3803
+ writeStaged(staging, rel, await sanitizeBundleOutput(output.contents, "js", !options.development));
3523
3804
  }
3524
3805
  }
3525
3806
  for (const asset of workerAssets) {
@@ -3540,8 +3821,8 @@ async function packPlugin(pluginDir, options = {}) {
3540
3821
  outDir,
3541
3822
  framework,
3542
3823
  manifest,
3543
- manifestPath: join12(outDir, "manifest.json"),
3544
- entryPath: join12(outDir, manifest.entry),
3824
+ manifestPath: join13(outDir, "manifest.json"),
3825
+ entryPath: join13(outDir, manifest.entry),
3545
3826
  warnings
3546
3827
  };
3547
3828
  } finally {
@@ -3572,21 +3853,21 @@ function collectWorkerReferences(manifestEntry, metafile) {
3572
3853
  const outputOwners = /* @__PURE__ */ new Map();
3573
3854
  for (const input of Object.keys(metafile.inputs)) {
3574
3855
  const inputPath = resolve17(process.cwd(), input);
3575
- if (!existsSync8(inputPath)) {
3856
+ if (!existsSync9(inputPath)) {
3576
3857
  continue;
3577
3858
  }
3578
3859
  const realInputPath = realpathSync(inputPath);
3579
- const source = readFileSync10(realInputPath, "utf8");
3860
+ const source = readFileSync11(realInputPath, "utf8");
3580
3861
  for (const match of source.matchAll(WORKER_URL_PATTERN)) {
3581
3862
  const sourceSpecifier = match[2];
3582
3863
  if (!sourceSpecifier?.endsWith(".worker.ts")) {
3583
3864
  continue;
3584
3865
  }
3585
3866
  const sourcePath = resolve17(dirname8(realInputPath), sourceSpecifier);
3586
- if (!existsSync8(sourcePath)) {
3867
+ if (!existsSync9(sourcePath)) {
3587
3868
  throw new CliError(`Missing worker source: ${sourcePath}`);
3588
3869
  }
3589
- const outputRel = join12(dirname8(manifestEntry), `${basename2(sourcePath, extname3(sourcePath))}.js`);
3870
+ const outputRel = join13(dirname8(manifestEntry), `${basename2(sourcePath, extname3(sourcePath))}.js`);
3590
3871
  const previousOwner = outputOwners.get(outputRel);
3591
3872
  if (previousOwner !== void 0 && previousOwner !== sourcePath) {
3592
3873
  throw new CliError(`Worker output path collision: ${outputRel}`);
@@ -3606,7 +3887,7 @@ function collectWorkerReferences(manifestEntry, metafile) {
3606
3887
  }
3607
3888
  return references;
3608
3889
  }
3609
- async function buildWorkerAssets(references, outDir, pluginDir, framework) {
3890
+ async function buildWorkerAssets(references, outDir, pluginDir, framework, production) {
3610
3891
  const assets = [];
3611
3892
  const built = /* @__PURE__ */ new Set();
3612
3893
  for (const reference of references) {
@@ -3629,7 +3910,10 @@ async function buildWorkerAssets(references, outDir, pluginDir, framework) {
3629
3910
  if (output === void 0) {
3630
3911
  throw new CliError(`esbuild produced no JavaScript bundle for worker: ${reference.sourcePath}`);
3631
3912
  }
3632
- assets.push({ rel: reference.outputRel, contents: Buffer.from(output.contents) });
3913
+ assets.push({
3914
+ rel: reference.outputRel,
3915
+ contents: await sanitizeBundleOutput(output.contents, "js", production)
3916
+ });
3633
3917
  built.add(reference.outputRel);
3634
3918
  }
3635
3919
  return assets;
@@ -3664,13 +3948,13 @@ function collectBackendOverrideAssets(manifest, pluginDir, override, auxiliaryAs
3664
3948
  }
3665
3949
  const source = resolve17(file.source);
3666
3950
  const sourceRelative = relative6(sourceRoot, source);
3667
- if (sourceRelative.startsWith("..") || isAbsolute5(sourceRelative) || !existsSync8(source) || !statSync5(source).isFile()) {
3951
+ if (sourceRelative.startsWith("..") || isAbsolute5(sourceRelative) || !existsSync9(source) || !statSync5(source).isFile()) {
3668
3952
  throw new CliError(`Target backend source is outside its build output: ${source}`);
3669
3953
  }
3670
3954
  destinations.add(file.destination);
3671
3955
  return {
3672
3956
  rel: file.destination,
3673
- contents: readFileSync10(source),
3957
+ contents: readFileSync11(source),
3674
3958
  mode: file.mode ?? 493
3675
3959
  };
3676
3960
  });
@@ -3695,7 +3979,7 @@ function collectSourceBackendAsset(rel, pluginDir, declaredBy) {
3695
3979
  if (!stat.isFile()) {
3696
3980
  throw new CliError(`Backend asset is not a regular file: ${source}`);
3697
3981
  }
3698
- return { rel, contents: readFileSync10(source), mode: 493 };
3982
+ return { rel, contents: readFileSync11(source), mode: 493 };
3699
3983
  } catch (error) {
3700
3984
  if (error instanceof CliError) {
3701
3985
  throw error;
@@ -3714,7 +3998,7 @@ function collectCatalogAssets(manifest, pluginDir) {
3714
3998
  if (!stat.isFile()) {
3715
3999
  throw new CliError(`Catalog is not a regular file: ${source}`);
3716
4000
  }
3717
- return { rel, contents: readFileSync10(source) };
4001
+ return { rel, contents: readFileSync11(source) };
3718
4002
  } catch (error) {
3719
4003
  if (error instanceof CliError) {
3720
4004
  throw error;
@@ -3744,14 +4028,14 @@ function pathsOverlap(first, second) {
3744
4028
  }
3745
4029
 
3746
4030
  // src/backend-build-run.ts
3747
- import { readFileSync as readFileSync11 } from "node:fs";
3748
- import { isAbsolute as isAbsolute6, join as join13, resolve as resolve18 } from "node:path";
4031
+ import { readFileSync as readFileSync12 } from "node:fs";
4032
+ import { isAbsolute as isAbsolute6, join as join14, resolve as resolve18 } from "node:path";
3749
4033
  function nonEmptyString2(value) {
3750
4034
  return typeof value === "string" && value.length > 0;
3751
4035
  }
3752
4036
  function readJson(path3, label) {
3753
4037
  try {
3754
- return JSON.parse(readFileSync11(path3, "utf8"));
4038
+ return JSON.parse(readFileSync12(path3, "utf8"));
3755
4039
  } catch (error) {
3756
4040
  throw new CliError(`failed to read ${label} at ${path3}: ${error.message}`);
3757
4041
  }
@@ -3801,8 +4085,8 @@ function isSafeEntryPackage(value) {
3801
4085
  }
3802
4086
  function readBackendBuildConfig(pluginDir) {
3803
4087
  const dir = resolve18(pluginDir);
3804
- const manifestValue = readJson(join13(dir, "manifest.json"), "manifest.json");
3805
- const packageValue = readJson(join13(dir, "package.json"), "package.json");
4088
+ const manifestValue = readJson(join14(dir, "manifest.json"), "manifest.json");
4089
+ const packageValue = readJson(join14(dir, "package.json"), "package.json");
3806
4090
  if (!isRecord4(manifestValue)) {
3807
4091
  throw new CliError(`manifest.json in ${dir} must contain a JSON object`);
3808
4092
  }
@@ -3837,7 +4121,7 @@ function runBuildBackendCommand(options) {
3837
4121
  const config = readBackendBuildConfig(options.pluginDir);
3838
4122
  buildGoBackend({
3839
4123
  plugin: config.plugin,
3840
- backendDir: join13(resolve18(options.pluginDir), "backend"),
4124
+ backendDir: join14(resolve18(options.pluginDir), "backend"),
3841
4125
  binaryName: config.binaryName,
3842
4126
  entryPackage: config.entryPackage,
3843
4127
  target: productTarget,
@@ -3847,8 +4131,8 @@ function runBuildBackendCommand(options) {
3847
4131
  }
3848
4132
 
3849
4133
  // src/zip.ts
3850
- import { mkdirSync as mkdirSync6, readFileSync as readFileSync12, readdirSync as readdirSync6, writeFileSync as writeFileSync6 } from "node:fs";
3851
- import { dirname as dirname9, join as join14, resolve as resolve19 } from "node:path";
4134
+ import { mkdirSync as mkdirSync6, readFileSync as readFileSync13, readdirSync as readdirSync6, writeFileSync as writeFileSync6 } from "node:fs";
4135
+ import { dirname as dirname9, join as join15, resolve as resolve19 } from "node:path";
3852
4136
  import { zipSync } from "fflate";
3853
4137
  function backendCommandPaths(manifest) {
3854
4138
  const backend = manifest.backend;
@@ -3867,12 +4151,12 @@ function collectFiles(dir) {
3867
4151
  if (entry.name.startsWith(".")) {
3868
4152
  continue;
3869
4153
  }
3870
- const absolute = join14(current, entry.name);
4154
+ const absolute = join15(current, entry.name);
3871
4155
  const relative7 = prefix === "" ? entry.name : `${prefix}/${entry.name}`;
3872
4156
  if (entry.isDirectory()) {
3873
4157
  walk2(absolute, relative7);
3874
4158
  } else if (entry.isFile()) {
3875
- files[relative7] = readFileSync12(absolute);
4159
+ files[relative7] = readFileSync13(absolute);
3876
4160
  }
3877
4161
  }
3878
4162
  };
@@ -3891,7 +4175,7 @@ async function zipPlugin(pluginDir, options = {}) {
3891
4175
  const { output, ...packOptions } = options;
3892
4176
  const pack = await packPlugin(pluginDir, packOptions);
3893
4177
  const archive = zipDirectory(pack.outDir, backendCommandPaths(pack.manifest));
3894
- const outputPath = output === void 0 ? join14(resolvePluginDir(pluginDir), `${pack.manifest.name}.zip`) : resolve19(process.cwd(), output);
4178
+ const outputPath = output === void 0 ? join15(resolvePluginDir(pluginDir), `${pack.manifest.name}.zip`) : resolve19(process.cwd(), output);
3895
4179
  mkdirSync6(dirname9(outputPath), { recursive: true });
3896
4180
  writeFileSync6(outputPath, archive);
3897
4181
  return { outputPath, pack };
@@ -3947,6 +4231,7 @@ function createProgram() {
3947
4231
  }
3948
4232
  const warnings = [
3949
4233
  ...result.warnings,
4234
+ ...validatePluginCss(resolvePluginDir(pluginDir), result.manifest.name),
3950
4235
  ...validatePluginCatalogs(resolvePluginDir(pluginDir), result.manifest, {
3951
4236
  strict: options.strict === true
3952
4237
  })
@@ -3986,10 +4271,15 @@ function createProgram() {
3986
4271
  process.stdout.write(`Zipped ${result.pack.manifest.name} \u2192 ${result.outputPath}
3987
4272
  `);
3988
4273
  });
3989
- program.command("build-backend").description(
3990
- "build the current plugin's Go backend (name from manifest.json, binary/entry from package.json mndw.backend)"
3991
- ).allowUnknownOption().allowExcessArguments().action((_options, command) => {
3992
- runBuildBackendCommand({ pluginDir: process.cwd(), args: command.args });
4274
+ program.command("build-backend [plugin-dir]").description(
4275
+ "build a plugin's Go backend (defaults to current directory; name from manifest.json, binary/entry from package.json mndw.backend)"
4276
+ ).allowUnknownOption().allowExcessArguments().action((_pluginDir, _options, command) => {
4277
+ const firstArg = command.args[0];
4278
+ const hasPluginDir = firstArg !== void 0 && !firstArg.startsWith("-");
4279
+ runBuildBackendCommand({
4280
+ pluginDir: resolve20(process.cwd(), hasPluginDir ? firstArg : "."),
4281
+ args: hasPluginDir ? command.args.slice(1) : command.args
4282
+ });
3993
4283
  });
3994
4284
  return program;
3995
4285
  }