@makoojs/cli 0.3.1 → 0.4.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/dist/bin.js CHANGED
@@ -652,7 +652,7 @@ var DEFAULT_MONKEY_SERVER_CONFIG = {
652
652
  prefix: "server:"
653
653
  };
654
654
 
655
- // src/error/error.ts
655
+ // src/error/MakooCliError.ts
656
656
  import { relative } from "path";
657
657
  import process3 from "process";
658
658
  import { ErrorCode, MakooError } from "@makoojs/core";
@@ -727,6 +727,31 @@ var ManifestNotFoundError = class extends MakooError {
727
727
  this.name = "ManifestNotFoundError";
728
728
  }
729
729
  };
730
+ var ManifestBindingNotFoundError = class extends MakooError {
731
+ constructor(kind, id, code = ErrorCode.CLI_MANIFEST_BINDING_NOT_FOUND, cause) {
732
+ const path5 = kind === "injectionDefaults" ? `${kind}.${id}` : `${kind}s.${id}`;
733
+ const label = kind === "injectionDefaults" ? "injection defaults" : kind;
734
+ super(
735
+ `Missing manifest binding for ${label} "${id}"`,
736
+ [{ path: path5, message: "could not resolve manifest source" }],
737
+ code,
738
+ cause
739
+ );
740
+ this.name = "ManifestBindingNotFoundError";
741
+ }
742
+ };
743
+ var UnsupportedSelectorTargetError = class extends MakooError {
744
+ constructor(file, path5, target, code = ErrorCode.CLI_SELECTOR_TARGET_UNSUPPORTED, cause) {
745
+ const rel = relative(process3.cwd(), file);
746
+ super(
747
+ `Unsupported selector target "${target}" in manifest at ${rel}`,
748
+ [{ path: path5, message: "must be a CSS selector; document and window are not supported" }],
749
+ code,
750
+ cause
751
+ );
752
+ this.name = "UnsupportedSelectorTargetError";
753
+ }
754
+ };
730
755
  var ManifestLoadError = class extends MakooError {
731
756
  constructor(path5, code = ErrorCode.CLI_MANIFEST_LOAD_FAIL, cause) {
732
757
  super(
@@ -749,15 +774,15 @@ var ModuleManifestLoadError = class extends MakooError {
749
774
  this.name = "ModuleManifestLoadError";
750
775
  }
751
776
  };
752
- var NoEnabledInjectionsError = class extends MakooError {
753
- constructor(code = ErrorCode.CLI_NO_ENABLED_INJECTIONS, cause) {
777
+ var NoEnabledTasksError = class extends MakooError {
778
+ constructor(code = ErrorCode.CLI_NO_ENABLED_TASKS, cause) {
754
779
  super(
755
- "No enabled injections \u2014 all injections are disabled or filtered out",
780
+ "No enabled tasks \u2014 all injections and listeners are disabled or filtered out",
756
781
  void 0,
757
782
  code,
758
783
  cause
759
784
  );
760
- this.name = "NoEnabledInjectionsError";
785
+ this.name = "NoEnabledTasksError";
761
786
  }
762
787
  };
763
788
  function formatZodPath(path5) {
@@ -862,7 +887,7 @@ async function updateManifest(moduleName, updateData) {
862
887
  const newManifestPath = join(sourcePath, "manifest.ts");
863
888
  await writeFile(
864
889
  newManifestPath,
865
- `import { defineInjections } from "@makoojs/cli";
890
+ `import { defineInjections } from "@makoojs/cli/manifest";
866
891
  export default defineInjections(${JSON.stringify(merged, null, 2)})
867
892
  `,
868
893
  "utf-8"
@@ -948,6 +973,7 @@ var ansi = {
948
973
  reset: "\x1B[0m",
949
974
  bold: "\x1B[1m",
950
975
  cyan: "\x1B[36m",
976
+ deepPink: "\x1B[38;5;162m",
951
977
  green: "\x1B[32m",
952
978
  dim: "\x1B[2m"
953
979
  };
@@ -1100,6 +1126,15 @@ var deriveInjectionModuleId = (config, moduleDir, componentPath, fallbackName, i
1100
1126
  }
1101
1127
  return `injection-${typeof index === "number" ? index + 1 : 1}`;
1102
1128
  };
1129
+ var deriveListenerId = (config, fallbackName, index) => {
1130
+ if (config.name) {
1131
+ return config.name;
1132
+ }
1133
+ if (fallbackName) {
1134
+ return fallbackName;
1135
+ }
1136
+ return `listener-${typeof index === "number" ? index + 1 : 1}`;
1137
+ };
1103
1138
  var normalizeInjectionManifest = (injections) => {
1104
1139
  const items = injections?.injections;
1105
1140
  if (!items) {
@@ -1113,6 +1148,19 @@ var normalizeInjectionManifest = (injections) => {
1113
1148
  ...config
1114
1149
  }));
1115
1150
  };
1151
+ var normalizeListenerManifest = (manifest) => {
1152
+ const items = manifest?.listeners;
1153
+ if (!items) {
1154
+ return [];
1155
+ }
1156
+ if (Array.isArray(items)) {
1157
+ return items;
1158
+ }
1159
+ return Object.entries(items).map(([name, config]) => ({
1160
+ name,
1161
+ ...config
1162
+ }));
1163
+ };
1116
1164
  var resolveSourceConfig = (config, root) => {
1117
1165
  return {
1118
1166
  dir: resolveFileSystemPath(root, DEFAULT_SOURCE_CONFIG.dir),
@@ -1191,6 +1239,27 @@ var resolveInjections = (injections, options) => {
1191
1239
  })
1192
1240
  );
1193
1241
  };
1242
+ var resolveListener = (config, options) => {
1243
+ const { name: _name, enabled: _enabled, match: _match, ...rest } = config;
1244
+ void _name;
1245
+ void _enabled;
1246
+ void _match;
1247
+ return {
1248
+ ...rest,
1249
+ listenerId: options.listenerId ?? deriveListenerId(config, options.fallbackName, options.index),
1250
+ enabled: config.enabled ?? true,
1251
+ match: resolveMatchConfig(config.match)
1252
+ };
1253
+ };
1254
+ var resolveListeners = (manifest, options) => {
1255
+ const normalizedListeners = normalizeListenerManifest(manifest);
1256
+ return normalizedListeners.map(
1257
+ (listener, index) => resolveListener(listener, {
1258
+ root: options.root,
1259
+ index
1260
+ })
1261
+ );
1262
+ };
1194
1263
 
1195
1264
  // src/scanner/collectDependenics.ts
1196
1265
  import { existsSync as existsSync3, readFileSync, statSync } from "fs";
@@ -1275,7 +1344,8 @@ import { createJiti as createJiti2 } from "jiti";
1275
1344
  import { OBSERVE_EVENT_NAMES } from "@makoojs/core";
1276
1345
  import { z as z2 } from "zod";
1277
1346
  var ObserveEventNameSchema = z2.enum(OBSERVE_EVENT_NAMES);
1278
- var HookSchema = z2.union([z2.function(), z2.array(z2.function())]);
1347
+ var ObserveHookSchema = z2.custom((value) => typeof value === "function");
1348
+ var HookSchema = z2.union([ObserveHookSchema, z2.array(ObserveHookSchema)]);
1279
1349
  var LifecycleHookMapSchema = z2.record(z2.string(), HookSchema).refine((obj) => Object.keys(obj).every((k) => ObserveEventNameSchema.safeParse(k).success), {
1280
1350
  message: "Invalid hook event name"
1281
1351
  });
@@ -1292,6 +1362,16 @@ var InjectionMatchSchema = z2.union([
1292
1362
  exclude: z2.array(z2.string()).optional()
1293
1363
  })
1294
1364
  ]);
1365
+ var EventListenerSchema = z2.custom((value) => typeof value === "function");
1366
+ var ActivitySignalSchema = z2.custom(
1367
+ (value) => typeof value === "function"
1368
+ );
1369
+ var InjectionModuleListenerSchema = z2.object({
1370
+ listenAt: z2.string(),
1371
+ type: z2.string(),
1372
+ callback: EventListenerSchema,
1373
+ activitySignal: ActivitySignalSchema.optional()
1374
+ });
1295
1375
  var InjectionModuleSchema = z2.object({
1296
1376
  name: z2.string().optional(),
1297
1377
  injectAt: z2.string(),
@@ -1301,20 +1381,34 @@ var InjectionModuleSchema = z2.object({
1301
1381
  match: InjectionMatchSchema.optional(),
1302
1382
  alive: z2.boolean().optional(),
1303
1383
  scope: z2.enum(["local", "global"]).optional(),
1304
- timeout: z2.number().optional()
1384
+ timeout: z2.number().optional(),
1385
+ hooks: LifecycleHookMapSchema.optional(),
1386
+ on: InjectionModuleListenerSchema.optional()
1387
+ });
1388
+ var InjectionListenerSchema = InjectionModuleListenerSchema.extend({
1389
+ name: z2.string().optional(),
1390
+ enabled: z2.boolean().optional(),
1391
+ match: InjectionMatchSchema.optional()
1305
1392
  });
1306
1393
  var InjectionManifestSchema = z2.object({
1307
1394
  injectionDefaults: InjectionDefaultsSchema.optional(),
1308
1395
  injections: z2.union([
1309
1396
  z2.array(InjectionModuleSchema),
1310
1397
  z2.record(z2.string(), InjectionModuleSchema.omit({ name: true }))
1311
- ])
1312
- }).strict();
1398
+ ]).optional(),
1399
+ listeners: z2.union([
1400
+ z2.array(InjectionListenerSchema),
1401
+ z2.record(z2.string(), InjectionListenerSchema.omit({ name: true }))
1402
+ ]).optional()
1403
+ }).strict().refine((manifest) => manifest.injections || manifest.listeners, {
1404
+ message: "Manifest must define injections or listeners"
1405
+ });
1313
1406
  function validateManifest(data, file) {
1314
1407
  const result = InjectionManifestSchema.safeParse(data);
1315
1408
  if (!result.success) {
1316
1409
  throw new ManifestValidationError(file, result.error.issues);
1317
1410
  }
1411
+ assertManifestSelectorTargets(result.data, file);
1318
1412
  return result.data;
1319
1413
  }
1320
1414
  function validateModuleMeta(data, file) {
@@ -1322,8 +1416,37 @@ function validateModuleMeta(data, file) {
1322
1416
  if (!result.success) {
1323
1417
  throw new ManifestValidationError(file, result.error.issues);
1324
1418
  }
1419
+ assertSelectorTarget(result.data.injectAt, file, "injectAt");
1420
+ assertSelectorTarget(result.data.on?.listenAt, file, "on.listenAt");
1325
1421
  return result.data;
1326
1422
  }
1423
+ function assertManifestSelectorTargets(manifest, file) {
1424
+ if (Array.isArray(manifest.injections)) {
1425
+ manifest.injections.forEach((injection, index) => {
1426
+ assertSelectorTarget(injection.injectAt, file, `injections[${index}].injectAt`);
1427
+ assertSelectorTarget(injection.on?.listenAt, file, `injections[${index}].on.listenAt`);
1428
+ });
1429
+ } else if (manifest.injections) {
1430
+ Object.entries(manifest.injections).forEach(([id, injection]) => {
1431
+ assertSelectorTarget(injection.injectAt, file, `injections.${id}.injectAt`);
1432
+ assertSelectorTarget(injection.on?.listenAt, file, `injections.${id}.on.listenAt`);
1433
+ });
1434
+ }
1435
+ if (Array.isArray(manifest.listeners)) {
1436
+ manifest.listeners.forEach((listener, index) => {
1437
+ assertSelectorTarget(listener.listenAt, file, `listeners[${index}].listenAt`);
1438
+ });
1439
+ } else if (manifest.listeners) {
1440
+ Object.entries(manifest.listeners).forEach(([id, listener]) => {
1441
+ assertSelectorTarget(listener.listenAt, file, `listeners.${id}.listenAt`);
1442
+ });
1443
+ }
1444
+ }
1445
+ function assertSelectorTarget(target, file, path5) {
1446
+ if (target === "document" || target === "window") {
1447
+ throw new UnsupportedSelectorTargetError(file, path5, target);
1448
+ }
1449
+ }
1327
1450
 
1328
1451
  // src/scanner/load/loadManifes.ts
1329
1452
  async function loadManifest(source) {
@@ -1396,6 +1519,112 @@ async function loadMeta(root) {
1396
1519
  return null;
1397
1520
  }
1398
1521
 
1522
+ // src/scanner/manifestBinding.ts
1523
+ function buildManifestBindings(options) {
1524
+ const manifestInjectionSources = /* @__PURE__ */ new Map();
1525
+ const moduleInjectionSources = /* @__PURE__ */ new Map();
1526
+ const listenerBindings = /* @__PURE__ */ new Map();
1527
+ const injectionKeys = getCollectionKeys(options.manifest.injections);
1528
+ const listenerKeys = getCollectionKeys(options.manifest.listeners);
1529
+ const injectionConfigs = normalizeInjectionManifest(options.manifest);
1530
+ const listenerConfigs = normalizeListenerManifest(options.manifest);
1531
+ options.manifestInjections.forEach((injection, index) => {
1532
+ manifestInjectionSources.set(injection.moduleId, {
1533
+ config: injectionConfigs[index],
1534
+ binding: {
1535
+ manifestFile: options.manifestFile,
1536
+ valuePath: ["injections", injectionKeys[index]]
1537
+ }
1538
+ });
1539
+ });
1540
+ options.moduleInjections.forEach((injection) => {
1541
+ if (!injection.moduleManifestFile) return;
1542
+ const config = options.moduleInjectionConfigs.get(injection.moduleId);
1543
+ if (!config) {
1544
+ throw new ManifestBindingNotFoundError("injection", injection.moduleId);
1545
+ }
1546
+ moduleInjectionSources.set(injection.moduleId, {
1547
+ config,
1548
+ binding: {
1549
+ manifestFile: injection.moduleManifestFile,
1550
+ valuePath: []
1551
+ }
1552
+ });
1553
+ });
1554
+ options.manifestListeners.forEach((listener, index) => {
1555
+ const baseBinding = {
1556
+ manifestFile: options.manifestFile,
1557
+ valuePath: ["listeners", listenerKeys[index]]
1558
+ };
1559
+ const listenerConfig = listenerConfigs[index];
1560
+ listenerBindings.set(listener.listenerId, {
1561
+ callback: appendValuePath(baseBinding, ["callback"]),
1562
+ activitySignal: listenerConfig.activitySignal ? appendValuePath(baseBinding, ["activitySignal"]) : void 0
1563
+ });
1564
+ });
1565
+ return {
1566
+ injectionDefaults: options.manifest.injectionDefaults?.hooks ? {
1567
+ hooks: {
1568
+ manifestFile: options.manifestFile,
1569
+ valuePath: ["injectionDefaults", "hooks"]
1570
+ }
1571
+ } : void 0,
1572
+ injections: Object.fromEntries(
1573
+ options.enabledInjections.map((injection) => {
1574
+ const manifestSource = manifestInjectionSources.get(injection.moduleId);
1575
+ const moduleSource = moduleInjectionSources.get(injection.moduleId);
1576
+ if (!manifestSource && !moduleSource) {
1577
+ throw new ManifestBindingNotFoundError("injection", injection.moduleId);
1578
+ }
1579
+ return [injection.moduleId, buildInjectionBindings(manifestSource, moduleSource)];
1580
+ })
1581
+ ),
1582
+ listeners: selectBindings(
1583
+ options.enabledListeners.map((listener) => listener.listenerId),
1584
+ listenerBindings,
1585
+ "listener"
1586
+ )
1587
+ };
1588
+ }
1589
+ function buildInjectionBindings(manifestSource, moduleSource) {
1590
+ const hooksSource = selectFieldSource("hooks", manifestSource, moduleSource);
1591
+ const onSource = selectFieldSource("on", manifestSource, moduleSource);
1592
+ return {
1593
+ hooks: hooksSource?.config.hooks ? appendValuePath(hooksSource.binding, ["hooks"]) : void 0,
1594
+ on: onSource?.config.on ? {
1595
+ callback: appendValuePath(onSource.binding, ["on", "callback"]),
1596
+ activitySignal: onSource.config.on.activitySignal ? appendValuePath(onSource.binding, ["on", "activitySignal"]) : void 0
1597
+ } : void 0
1598
+ };
1599
+ }
1600
+ function selectFieldSource(field, manifestSource, moduleSource) {
1601
+ if (moduleSource && Object.hasOwn(moduleSource.config, field)) {
1602
+ return moduleSource;
1603
+ }
1604
+ return manifestSource;
1605
+ }
1606
+ function appendValuePath(binding, valuePath) {
1607
+ return {
1608
+ manifestFile: binding.manifestFile,
1609
+ valuePath: [...binding.valuePath, ...valuePath]
1610
+ };
1611
+ }
1612
+ function getCollectionKeys(collection) {
1613
+ if (!collection) return [];
1614
+ return Array.isArray(collection) ? collection.map((_, index) => index) : Object.keys(collection);
1615
+ }
1616
+ function selectBindings(ids, bindings, kind) {
1617
+ return Object.fromEntries(
1618
+ ids.map((id) => {
1619
+ const binding = bindings.get(id);
1620
+ if (!binding) {
1621
+ throw new ManifestBindingNotFoundError(kind, id);
1622
+ }
1623
+ return [id, binding];
1624
+ })
1625
+ );
1626
+ }
1627
+
1399
1628
  // src/scanner/util.ts
1400
1629
  function mergeMeta(source, target) {
1401
1630
  const targetMap = new Map(target.map((m) => [m.moduleId, m]));
@@ -1433,11 +1662,19 @@ async function scanner(config) {
1433
1662
  source: config.source,
1434
1663
  injectionDefaults
1435
1664
  });
1665
+ const normalizedManifestInjections = normalizeInjectionManifest(loadedManifest.manifest);
1666
+ const manifestInjectionConfigs = new Map(
1667
+ resolveManifest.map((injection, index) => [
1668
+ injection.moduleId,
1669
+ normalizedManifestInjections[index]
1670
+ ])
1671
+ );
1436
1672
  const folder = readdirSync2(config.source.dir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
1437
1673
  const isIncluded = picomatch(config.source.include);
1438
1674
  const isExcluded = picomatch(config.source.exclude);
1439
1675
  const filteredFolders = folder.filter((name) => isIncluded(name) && !isExcluded(name));
1440
1676
  const injectionsMeta = [];
1677
+ const moduleInjectionConfigs = /* @__PURE__ */ new Map();
1441
1678
  for (const module of filteredFolders) {
1442
1679
  const modulePath = path4.join(config.source.dir, module);
1443
1680
  const meta = await loadMeta(modulePath);
@@ -1447,7 +1684,7 @@ async function scanner(config) {
1447
1684
  for (const dependency of meta.dependencies) {
1448
1685
  moduleManifestDependencies.add(dependency);
1449
1686
  }
1450
- const resolveMeta = resolveInjection(meta.moduleConfig, {
1687
+ const resolveOptions = {
1451
1688
  root: config.root,
1452
1689
  source: config.source,
1453
1690
  injectionDefaults,
@@ -1455,26 +1692,50 @@ async function scanner(config) {
1455
1692
  componentPath: path4.join(modulePath, meta.moduleConfig.component),
1456
1693
  fallbackName: module,
1457
1694
  moduleManifestFile: meta.moduleManifestFile
1458
- });
1695
+ };
1696
+ const moduleId = meta.moduleConfig.name || module;
1697
+ const manifestConfig = manifestInjectionConfigs.get(moduleId);
1698
+ const resolveMeta = resolveInjection(
1699
+ manifestConfig ? { ...manifestConfig, ...meta.moduleConfig } : meta.moduleConfig,
1700
+ resolveOptions
1701
+ );
1459
1702
  injectionsMeta.push(resolveMeta);
1703
+ moduleInjectionConfigs.set(resolveMeta.moduleId, meta.moduleConfig);
1460
1704
  }
1461
1705
  const injections = mergeMeta(resolveManifest, injectionsMeta).filter(
1462
1706
  (injection) => injection.enabled
1463
1707
  );
1464
- if (injections.length === 0) {
1465
- throw new NoEnabledInjectionsError();
1708
+ const resolvedListeners = resolveListeners(loadedManifest.manifest, {
1709
+ root: config.root
1710
+ });
1711
+ const listeners = resolvedListeners.filter((listener) => listener.enabled);
1712
+ if (injections.length === 0 && listeners.length === 0) {
1713
+ throw new NoEnabledTasksError();
1466
1714
  }
1715
+ const manifestBindings = buildManifestBindings({
1716
+ manifest: loadedManifest.manifest,
1717
+ manifestFile: loadedManifest.manifestFile,
1718
+ manifestInjections: resolveManifest,
1719
+ moduleInjections: injectionsMeta,
1720
+ moduleInjectionConfigs,
1721
+ manifestListeners: resolvedListeners,
1722
+ enabledInjections: injections,
1723
+ enabledListeners: listeners
1724
+ });
1467
1725
  injections.sort((a, b) => a.moduleId.localeCompare(b.moduleId));
1726
+ listeners.sort((a, b) => a.listenerId.localeCompare(b.listenerId));
1468
1727
  const frameworks = [...new Set(injections.map((m) => m.framework))];
1469
1728
  return {
1470
1729
  config,
1471
1730
  injectionDefaults,
1472
1731
  manifestFile: loadedManifest.manifestFile,
1732
+ manifestBindings,
1473
1733
  manifestDependencies: [...manifestDependencies].sort(),
1474
1734
  moduleManifestDependencies: [...moduleManifestDependencies].sort(),
1475
1735
  runtimeSetupFiles: [...runtimeSetupFiles].sort(),
1476
1736
  runtimeDependencies: [...runtimeDependencies].sort(),
1477
1737
  injections,
1738
+ listeners,
1478
1739
  frameworks
1479
1740
  };
1480
1741
  }
@@ -1501,7 +1762,7 @@ function formatInspectInjection(injection, injectionDefaults) {
1501
1762
  };
1502
1763
  }
1503
1764
  function formatInspectResult(result) {
1504
- const { config, injectionDefaults, injections } = result;
1765
+ const { config, injectionDefaults, injections, listeners } = result;
1505
1766
  const moduleManifestFiles = [
1506
1767
  ...new Set(
1507
1768
  injections.map((injection) => injection.moduleManifestFile).filter((file) => typeof file === "string")
@@ -1530,6 +1791,7 @@ function formatInspectResult(result) {
1530
1791
  injections: injections.map(
1531
1792
  (injection) => formatInspectInjection(injection, injectionDefaults)
1532
1793
  ),
1794
+ listeners,
1533
1795
  frameworks: result.frameworks
1534
1796
  };
1535
1797
  }
@@ -1544,6 +1806,7 @@ async function inspectCommand() {
1544
1806
  ["Monkey", inspectResult.monkey],
1545
1807
  ["Injection Defaults", inspectResult.injectionDefaults],
1546
1808
  ["Injections", inspectResult.injections],
1809
+ ["Listeners", inspectResult.listeners],
1547
1810
  ["Frameworks", inspectResult.frameworks]
1548
1811
  ];
1549
1812
  console.log(colorize("Makoo Inspect", ansi.bold, ansi.green));
@@ -1,4 +1,4 @@
1
- import { ResolvedConfig, ResolvedInjectionDefaults, ResolvedInjectionModule } from '../config/types';
1
+ import { ResolvedConfig, ResolvedInjectionDefaults, ResolvedInjectionModule, ResolvedListener } from '../config/types';
2
2
  import { ScannerResult } from '../scanner/types';
3
3
  type InspectInjectionDefaultsFields = Pick<ResolvedInjectionModule, 'alive' | 'scope' | 'timeout'>;
4
4
  type InspectInjection = Omit<ResolvedInjectionModule, keyof InspectInjectionDefaultsFields> & {
@@ -26,6 +26,7 @@ type InspectResult = {
26
26
  monkey: ResolvedConfig['monkey'];
27
27
  injectionDefaults: ScannerResult['injectionDefaults'];
28
28
  injections: InspectInjection[];
29
+ listeners: ResolvedListener[];
29
30
  frameworks: ScannerResult['frameworks'];
30
31
  };
31
32
  export declare function formatInspectInjection(injection: ResolvedInjectionModule, injectionDefaults: ResolvedInjectionDefaults): InspectInjection;
@@ -1,6 +1,7 @@
1
1
  import { MonkeyOption } from 'vite-plugin-monkey';
2
- import { AppConfig, CliConfig, InjectionDefaults, InjectionManifest, InjectionModuleConfig, MonkeyConfig, ResolveConfigOptions, ResolvedConfig, ResolvedInjectionDefaults, ResolvedInjectionManifest, ResolvedInjectionModule, ResolvedMonkeyBuildConfig, ResolvedMonkeyConfig, ResolvedMonkeyServerConfig, ResolvedRuntimeConfig, ResolvedSourceConfig, ResolveInjectionOptions, RuntimeConfig, SourceConfig } from './types';
2
+ import { AppConfig, CliConfig, InjectionDefaults, InjectionListenerConfig, InjectionManifest, InjectionModuleConfig, MonkeyConfig, ResolveConfigOptions, ResolvedConfig, ResolvedInjectionDefaults, ResolvedInjectionManifest, ResolvedInjectionModule, ResolvedListener, ResolvedListenerManifest, ResolvedMonkeyBuildConfig, ResolvedMonkeyConfig, ResolvedMonkeyServerConfig, ResolvedRuntimeConfig, ResolvedSourceConfig, ResolveInjectionOptions, ResolveListenerOptions, RuntimeConfig, SourceConfig } from './types';
3
3
  export declare const normalizeInjectionManifest: (injections: InjectionManifest | undefined) => ResolvedInjectionManifest;
4
+ export declare const normalizeListenerManifest: (manifest: InjectionManifest | undefined) => ResolvedListenerManifest;
4
5
  export declare const resolveAppConfig: (config: AppConfig) => AppConfig;
5
6
  export declare const resolveSourceConfig: (config: SourceConfig | undefined, root: string) => ResolvedSourceConfig;
6
7
  export declare const resolveInjectionDefaults: (config: InjectionDefaults | undefined) => ResolvedInjectionDefaults;
@@ -13,5 +14,7 @@ export declare const resolveInjections: (injections: InjectionManifest | undefin
13
14
  source: ResolvedSourceConfig;
14
15
  injectionDefaults: ResolvedInjectionDefaults;
15
16
  }) => ResolvedInjectionModule[];
17
+ export declare const resolveListener: (config: InjectionListenerConfig, options: ResolveListenerOptions) => ResolvedListener;
18
+ export declare const resolveListeners: (manifest: InjectionManifest | undefined, options: ResolveConfigOptions) => ResolvedListener[];
16
19
  export declare const resolveConfig: (config: CliConfig, root?: string) => ResolvedConfig;
17
20
  export declare function resolveMonkeyPluginOptions(config: ResolvedConfig, override?: Partial<MonkeyOption>): MonkeyOption;
@@ -17,6 +17,12 @@ export type ResolveInjectionOptions = {
17
17
  fallbackName?: string;
18
18
  index?: number;
19
19
  };
20
+ export type ResolveListenerOptions = {
21
+ root?: string;
22
+ listenerId?: string;
23
+ fallbackName?: string;
24
+ index?: number;
25
+ };
20
26
  export type MonkeyGenerateContext = {
21
27
  userscript: string;
22
28
  mode: MonkeyMode;
@@ -80,6 +86,11 @@ export type InjectionModuleListenerConfig = {
80
86
  callback: EventListener;
81
87
  activitySignal?: () => ActivitySignalSource<boolean>;
82
88
  };
89
+ export type InjectionListenerConfig = InjectionModuleListenerConfig & {
90
+ name?: string;
91
+ enabled?: boolean;
92
+ match?: InjectionMatchConfig;
93
+ };
83
94
  export type InjectionModuleOptions = Partial<Pick<RuntimeInjectionConfig, 'alive' | 'scope' | 'timeout' | 'hooks'>> & {
84
95
  on?: InjectionModuleListenerConfig;
85
96
  };
@@ -92,11 +103,14 @@ export type InjectionModuleConfig = InjectionModuleOptions & {
92
103
  match?: InjectionMatchConfig;
93
104
  };
94
105
  export type InjectionManifestRecord = Record<string, Omit<InjectionModuleConfig, 'name'>>;
106
+ export type InjectionListenerRecord = Record<string, Omit<InjectionListenerConfig, 'name'>>;
95
107
  export type InjectionManifest = {
96
108
  injectionDefaults?: InjectionDefaults;
97
- injections: InjectionModuleConfig[] | InjectionManifestRecord;
109
+ injections?: InjectionModuleConfig[] | InjectionManifestRecord;
110
+ listeners?: InjectionListenerConfig[] | InjectionListenerRecord;
98
111
  };
99
112
  export type ResolvedInjectionManifest = InjectionModuleConfig[];
113
+ export type ResolvedListenerManifest = InjectionListenerConfig[];
100
114
  export type ResolvedInjectionModule = Omit<InjectionModuleConfig, 'name' | 'component' | 'framework' | 'enabled' | 'alive' | 'scope' | 'timeout'> & {
101
115
  moduleId: string;
102
116
  componentPath: string;
@@ -109,6 +123,11 @@ export type ResolvedInjectionModule = Omit<InjectionModuleConfig, 'name' | 'comp
109
123
  timeout: ResolvedInjectionDefaults['timeout'];
110
124
  match?: InjectionMatchObject;
111
125
  };
126
+ export type ResolvedListener = Omit<InjectionListenerConfig, 'name' | 'enabled' | 'match'> & {
127
+ listenerId: string;
128
+ enabled: boolean;
129
+ match?: InjectionMatchObject;
130
+ };
112
131
  export type ResolvedMonkeyServerConfig = {
113
132
  open: boolean;
114
133
  prefix: string | ((name: string) => string) | false;
@@ -34,13 +34,25 @@ export declare class SourceDirNotFoundError extends MakooError {
34
34
  export declare class ManifestNotFoundError extends MakooError {
35
35
  constructor(dir: string, code?: string, cause?: Error);
36
36
  }
37
+ export declare class ManifestBindingNotFoundError extends MakooError {
38
+ constructor(kind: 'injectionDefaults' | 'injection' | 'listener', id: string, code?: string, cause?: Error);
39
+ }
40
+ export declare class ManifestImportNotFoundError extends MakooError {
41
+ constructor(manifestFile: string, code?: string, cause?: Error);
42
+ }
43
+ export declare class UnsupportedSelectorTargetError extends MakooError {
44
+ constructor(file: string, path: string, target: string, code?: string, cause?: Error);
45
+ }
46
+ export declare class FunctionSerializationError extends MakooError {
47
+ constructor(code?: string, cause?: Error);
48
+ }
37
49
  export declare class ManifestLoadError extends MakooError {
38
50
  constructor(path: string, code?: string, cause?: Error);
39
51
  }
40
52
  export declare class ModuleManifestLoadError extends MakooError {
41
53
  constructor(path: string, code?: string, cause?: Error);
42
54
  }
43
- export declare class NoEnabledInjectionsError extends MakooError {
55
+ export declare class NoEnabledTasksError extends MakooError {
44
56
  constructor(code?: string, cause?: Error);
45
57
  }
46
58
  export declare function toMakooIssue(issue: ValidationIssue): MakooIssue;
@@ -0,0 +1,3 @@
1
+ import { ScannerManifestBindings } from '../../../scanner/types';
2
+ import { RenderImportManifestResult } from '../../types';
3
+ export declare function renderImportManifest(bindings: ScannerManifestBindings): RenderImportManifestResult;
@@ -1,3 +1,4 @@
1
1
  import { ResolvedInjectionDefaults } from '../../../config/types';
2
- import { RenderInitResult } from '../../types';
3
- export declare function renderInitMakooRuntime(frameworks: string[], injectionDefaults: ResolvedInjectionDefaults): RenderInitResult;
2
+ import { ScannerManifestBindings } from '../../../scanner/types';
3
+ import { RenderInitResult, RenderManifestReference } from '../../types';
4
+ export declare function renderInitMakooRuntime(frameworks: string[], injectionDefaults: ResolvedInjectionDefaults, manifestBinding: ScannerManifestBindings['injectionDefaults'], renderManifestReference: RenderManifestReference): RenderInitResult;
@@ -1,2 +1,3 @@
1
- import { Component, RenderInitResult } from '../../../generator/types';
2
- export declare function renderRegisterComponent(instanceName: string, components: Component[]): RenderInitResult;
1
+ import { ScannerManifestBindings } from '../../../scanner/types';
2
+ import { Component, RenderInitResult, RenderManifestReference } from '../../types';
3
+ export declare function renderRegisterComponent(instanceName: string, components: Component[], manifestBindings: ScannerManifestBindings['injections'], renderManifestReference: RenderManifestReference): RenderInitResult;
@@ -0,0 +1,4 @@
1
+ import { ResolvedListener } from '../../../config/types';
2
+ import { ScannerManifestBindings } from '../../../scanner/types';
3
+ import { RenderInitResult, RenderManifestReference } from '../../types';
4
+ export declare function renderRegisterListener(instanceName: string, listeners: ResolvedListener[], manifestBindings: ScannerManifestBindings['listeners'], renderManifestReference: RenderManifestReference): RenderInitResult;
@@ -0,0 +1 @@
1
+ export declare const renderMatchUrlHelper: () => string;
@@ -1,4 +1,5 @@
1
1
  import { ResolvedInjectionModule } from '../config/types';
2
+ import { ManifestBinding } from '../scanner/types';
2
3
  export type RenderImportResult = {
3
4
  code: string;
4
5
  importsName: string[];
@@ -19,3 +20,8 @@ export type GeneratorResult = {
19
20
  code: string;
20
21
  instanceName: string;
21
22
  };
23
+ export type RenderImportManifestResult = {
24
+ code: string;
25
+ renderReference: RenderManifestReference;
26
+ };
27
+ export type RenderManifestReference = (binding: ManifestBinding) => string;