@makoojs/cli 0.3.2 → 0.4.1
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/README.CN.md +303 -260
- package/README.md +303 -260
- package/dist/bin.js +279 -15
- package/dist/command/inspect.d.ts +2 -1
- package/dist/config/resolve.d.ts +4 -1
- package/dist/config/types.d.ts +21 -1
- package/dist/error/{error.d.ts → MakooCliError.d.ts} +13 -1
- package/dist/generator/render/import/importManifest.d.ts +3 -0
- package/dist/generator/render/init/initMakooRuntime.d.ts +3 -2
- package/dist/generator/render/init/registerComp.d.ts +3 -2
- package/dist/generator/render/init/registerListener.d.ts +4 -0
- package/dist/generator/render/util/match.d.ts +1 -0
- package/dist/generator/types.d.ts +6 -0
- package/dist/index.cjs +21 -18
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1005 -917
- package/dist/manifest/index.cjs +1 -0
- package/dist/manifest/index.d.ts +2 -0
- package/dist/manifest/index.js +7 -0
- package/dist/scanner/manifestBinding.d.ts +14 -0
- package/dist/scanner/types.d.ts +25 -1
- package/dist/scanner/validation.d.ts +74 -5
- package/dist/shared/terminalColor.d.ts +1 -0
- package/package.json +9 -4
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/
|
|
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
|
|
753
|
-
constructor(code = ErrorCode.
|
|
777
|
+
var NoEnabledTasksError = class extends MakooError {
|
|
778
|
+
constructor(code = ErrorCode.CLI_NO_ENABLED_TASKS, cause) {
|
|
754
779
|
super(
|
|
755
|
-
"No enabled
|
|
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 = "
|
|
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
|
|
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,17 @@ 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
|
+
capture: z2.boolean().optional(),
|
|
1374
|
+
activitySignal: ActivitySignalSchema.optional()
|
|
1375
|
+
});
|
|
1295
1376
|
var InjectionModuleSchema = z2.object({
|
|
1296
1377
|
name: z2.string().optional(),
|
|
1297
1378
|
injectAt: z2.string(),
|
|
@@ -1301,20 +1382,34 @@ var InjectionModuleSchema = z2.object({
|
|
|
1301
1382
|
match: InjectionMatchSchema.optional(),
|
|
1302
1383
|
alive: z2.boolean().optional(),
|
|
1303
1384
|
scope: z2.enum(["local", "global"]).optional(),
|
|
1304
|
-
timeout: z2.number().optional()
|
|
1385
|
+
timeout: z2.number().optional(),
|
|
1386
|
+
hooks: LifecycleHookMapSchema.optional(),
|
|
1387
|
+
on: InjectionModuleListenerSchema.optional()
|
|
1388
|
+
});
|
|
1389
|
+
var InjectionListenerSchema = InjectionModuleListenerSchema.extend({
|
|
1390
|
+
name: z2.string().optional(),
|
|
1391
|
+
enabled: z2.boolean().optional(),
|
|
1392
|
+
match: InjectionMatchSchema.optional()
|
|
1305
1393
|
});
|
|
1306
1394
|
var InjectionManifestSchema = z2.object({
|
|
1307
1395
|
injectionDefaults: InjectionDefaultsSchema.optional(),
|
|
1308
1396
|
injections: z2.union([
|
|
1309
1397
|
z2.array(InjectionModuleSchema),
|
|
1310
1398
|
z2.record(z2.string(), InjectionModuleSchema.omit({ name: true }))
|
|
1311
|
-
])
|
|
1312
|
-
|
|
1399
|
+
]).optional(),
|
|
1400
|
+
listeners: z2.union([
|
|
1401
|
+
z2.array(InjectionListenerSchema),
|
|
1402
|
+
z2.record(z2.string(), InjectionListenerSchema.omit({ name: true }))
|
|
1403
|
+
]).optional()
|
|
1404
|
+
}).strict().refine((manifest) => manifest.injections || manifest.listeners, {
|
|
1405
|
+
message: "Manifest must define injections or listeners"
|
|
1406
|
+
});
|
|
1313
1407
|
function validateManifest(data, file) {
|
|
1314
1408
|
const result = InjectionManifestSchema.safeParse(data);
|
|
1315
1409
|
if (!result.success) {
|
|
1316
1410
|
throw new ManifestValidationError(file, result.error.issues);
|
|
1317
1411
|
}
|
|
1412
|
+
assertManifestSelectorTargets(result.data, file);
|
|
1318
1413
|
return result.data;
|
|
1319
1414
|
}
|
|
1320
1415
|
function validateModuleMeta(data, file) {
|
|
@@ -1322,8 +1417,37 @@ function validateModuleMeta(data, file) {
|
|
|
1322
1417
|
if (!result.success) {
|
|
1323
1418
|
throw new ManifestValidationError(file, result.error.issues);
|
|
1324
1419
|
}
|
|
1420
|
+
assertSelectorTarget(result.data.injectAt, file, "injectAt");
|
|
1421
|
+
assertSelectorTarget(result.data.on?.listenAt, file, "on.listenAt");
|
|
1325
1422
|
return result.data;
|
|
1326
1423
|
}
|
|
1424
|
+
function assertManifestSelectorTargets(manifest, file) {
|
|
1425
|
+
if (Array.isArray(manifest.injections)) {
|
|
1426
|
+
manifest.injections.forEach((injection, index) => {
|
|
1427
|
+
assertSelectorTarget(injection.injectAt, file, `injections[${index}].injectAt`);
|
|
1428
|
+
assertSelectorTarget(injection.on?.listenAt, file, `injections[${index}].on.listenAt`);
|
|
1429
|
+
});
|
|
1430
|
+
} else if (manifest.injections) {
|
|
1431
|
+
Object.entries(manifest.injections).forEach(([id, injection]) => {
|
|
1432
|
+
assertSelectorTarget(injection.injectAt, file, `injections.${id}.injectAt`);
|
|
1433
|
+
assertSelectorTarget(injection.on?.listenAt, file, `injections.${id}.on.listenAt`);
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
if (Array.isArray(manifest.listeners)) {
|
|
1437
|
+
manifest.listeners.forEach((listener, index) => {
|
|
1438
|
+
assertSelectorTarget(listener.listenAt, file, `listeners[${index}].listenAt`);
|
|
1439
|
+
});
|
|
1440
|
+
} else if (manifest.listeners) {
|
|
1441
|
+
Object.entries(manifest.listeners).forEach(([id, listener]) => {
|
|
1442
|
+
assertSelectorTarget(listener.listenAt, file, `listeners.${id}.listenAt`);
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
function assertSelectorTarget(target, file, path5) {
|
|
1447
|
+
if (target === "document" || target === "window") {
|
|
1448
|
+
throw new UnsupportedSelectorTargetError(file, path5, target);
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1327
1451
|
|
|
1328
1452
|
// src/scanner/load/loadManifes.ts
|
|
1329
1453
|
async function loadManifest(source) {
|
|
@@ -1396,6 +1520,112 @@ async function loadMeta(root) {
|
|
|
1396
1520
|
return null;
|
|
1397
1521
|
}
|
|
1398
1522
|
|
|
1523
|
+
// src/scanner/manifestBinding.ts
|
|
1524
|
+
function buildManifestBindings(options) {
|
|
1525
|
+
const manifestInjectionSources = /* @__PURE__ */ new Map();
|
|
1526
|
+
const moduleInjectionSources = /* @__PURE__ */ new Map();
|
|
1527
|
+
const listenerBindings = /* @__PURE__ */ new Map();
|
|
1528
|
+
const injectionKeys = getCollectionKeys(options.manifest.injections);
|
|
1529
|
+
const listenerKeys = getCollectionKeys(options.manifest.listeners);
|
|
1530
|
+
const injectionConfigs = normalizeInjectionManifest(options.manifest);
|
|
1531
|
+
const listenerConfigs = normalizeListenerManifest(options.manifest);
|
|
1532
|
+
options.manifestInjections.forEach((injection, index) => {
|
|
1533
|
+
manifestInjectionSources.set(injection.moduleId, {
|
|
1534
|
+
config: injectionConfigs[index],
|
|
1535
|
+
binding: {
|
|
1536
|
+
manifestFile: options.manifestFile,
|
|
1537
|
+
valuePath: ["injections", injectionKeys[index]]
|
|
1538
|
+
}
|
|
1539
|
+
});
|
|
1540
|
+
});
|
|
1541
|
+
options.moduleInjections.forEach((injection) => {
|
|
1542
|
+
if (!injection.moduleManifestFile) return;
|
|
1543
|
+
const config = options.moduleInjectionConfigs.get(injection.moduleId);
|
|
1544
|
+
if (!config) {
|
|
1545
|
+
throw new ManifestBindingNotFoundError("injection", injection.moduleId);
|
|
1546
|
+
}
|
|
1547
|
+
moduleInjectionSources.set(injection.moduleId, {
|
|
1548
|
+
config,
|
|
1549
|
+
binding: {
|
|
1550
|
+
manifestFile: injection.moduleManifestFile,
|
|
1551
|
+
valuePath: []
|
|
1552
|
+
}
|
|
1553
|
+
});
|
|
1554
|
+
});
|
|
1555
|
+
options.manifestListeners.forEach((listener, index) => {
|
|
1556
|
+
const baseBinding = {
|
|
1557
|
+
manifestFile: options.manifestFile,
|
|
1558
|
+
valuePath: ["listeners", listenerKeys[index]]
|
|
1559
|
+
};
|
|
1560
|
+
const listenerConfig = listenerConfigs[index];
|
|
1561
|
+
listenerBindings.set(listener.listenerId, {
|
|
1562
|
+
callback: appendValuePath(baseBinding, ["callback"]),
|
|
1563
|
+
activitySignal: listenerConfig.activitySignal ? appendValuePath(baseBinding, ["activitySignal"]) : void 0
|
|
1564
|
+
});
|
|
1565
|
+
});
|
|
1566
|
+
return {
|
|
1567
|
+
injectionDefaults: options.manifest.injectionDefaults?.hooks ? {
|
|
1568
|
+
hooks: {
|
|
1569
|
+
manifestFile: options.manifestFile,
|
|
1570
|
+
valuePath: ["injectionDefaults", "hooks"]
|
|
1571
|
+
}
|
|
1572
|
+
} : void 0,
|
|
1573
|
+
injections: Object.fromEntries(
|
|
1574
|
+
options.enabledInjections.map((injection) => {
|
|
1575
|
+
const manifestSource = manifestInjectionSources.get(injection.moduleId);
|
|
1576
|
+
const moduleSource = moduleInjectionSources.get(injection.moduleId);
|
|
1577
|
+
if (!manifestSource && !moduleSource) {
|
|
1578
|
+
throw new ManifestBindingNotFoundError("injection", injection.moduleId);
|
|
1579
|
+
}
|
|
1580
|
+
return [injection.moduleId, buildInjectionBindings(manifestSource, moduleSource)];
|
|
1581
|
+
})
|
|
1582
|
+
),
|
|
1583
|
+
listeners: selectBindings(
|
|
1584
|
+
options.enabledListeners.map((listener) => listener.listenerId),
|
|
1585
|
+
listenerBindings,
|
|
1586
|
+
"listener"
|
|
1587
|
+
)
|
|
1588
|
+
};
|
|
1589
|
+
}
|
|
1590
|
+
function buildInjectionBindings(manifestSource, moduleSource) {
|
|
1591
|
+
const hooksSource = selectFieldSource("hooks", manifestSource, moduleSource);
|
|
1592
|
+
const onSource = selectFieldSource("on", manifestSource, moduleSource);
|
|
1593
|
+
return {
|
|
1594
|
+
hooks: hooksSource?.config.hooks ? appendValuePath(hooksSource.binding, ["hooks"]) : void 0,
|
|
1595
|
+
on: onSource?.config.on ? {
|
|
1596
|
+
callback: appendValuePath(onSource.binding, ["on", "callback"]),
|
|
1597
|
+
activitySignal: onSource.config.on.activitySignal ? appendValuePath(onSource.binding, ["on", "activitySignal"]) : void 0
|
|
1598
|
+
} : void 0
|
|
1599
|
+
};
|
|
1600
|
+
}
|
|
1601
|
+
function selectFieldSource(field, manifestSource, moduleSource) {
|
|
1602
|
+
if (moduleSource && Object.hasOwn(moduleSource.config, field)) {
|
|
1603
|
+
return moduleSource;
|
|
1604
|
+
}
|
|
1605
|
+
return manifestSource;
|
|
1606
|
+
}
|
|
1607
|
+
function appendValuePath(binding, valuePath) {
|
|
1608
|
+
return {
|
|
1609
|
+
manifestFile: binding.manifestFile,
|
|
1610
|
+
valuePath: [...binding.valuePath, ...valuePath]
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
function getCollectionKeys(collection) {
|
|
1614
|
+
if (!collection) return [];
|
|
1615
|
+
return Array.isArray(collection) ? collection.map((_, index) => index) : Object.keys(collection);
|
|
1616
|
+
}
|
|
1617
|
+
function selectBindings(ids, bindings, kind) {
|
|
1618
|
+
return Object.fromEntries(
|
|
1619
|
+
ids.map((id) => {
|
|
1620
|
+
const binding = bindings.get(id);
|
|
1621
|
+
if (!binding) {
|
|
1622
|
+
throw new ManifestBindingNotFoundError(kind, id);
|
|
1623
|
+
}
|
|
1624
|
+
return [id, binding];
|
|
1625
|
+
})
|
|
1626
|
+
);
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1399
1629
|
// src/scanner/util.ts
|
|
1400
1630
|
function mergeMeta(source, target) {
|
|
1401
1631
|
const targetMap = new Map(target.map((m) => [m.moduleId, m]));
|
|
@@ -1433,11 +1663,19 @@ async function scanner(config) {
|
|
|
1433
1663
|
source: config.source,
|
|
1434
1664
|
injectionDefaults
|
|
1435
1665
|
});
|
|
1666
|
+
const normalizedManifestInjections = normalizeInjectionManifest(loadedManifest.manifest);
|
|
1667
|
+
const manifestInjectionConfigs = new Map(
|
|
1668
|
+
resolveManifest.map((injection, index) => [
|
|
1669
|
+
injection.moduleId,
|
|
1670
|
+
normalizedManifestInjections[index]
|
|
1671
|
+
])
|
|
1672
|
+
);
|
|
1436
1673
|
const folder = readdirSync2(config.source.dir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
1437
1674
|
const isIncluded = picomatch(config.source.include);
|
|
1438
1675
|
const isExcluded = picomatch(config.source.exclude);
|
|
1439
1676
|
const filteredFolders = folder.filter((name) => isIncluded(name) && !isExcluded(name));
|
|
1440
1677
|
const injectionsMeta = [];
|
|
1678
|
+
const moduleInjectionConfigs = /* @__PURE__ */ new Map();
|
|
1441
1679
|
for (const module of filteredFolders) {
|
|
1442
1680
|
const modulePath = path4.join(config.source.dir, module);
|
|
1443
1681
|
const meta = await loadMeta(modulePath);
|
|
@@ -1447,7 +1685,7 @@ async function scanner(config) {
|
|
|
1447
1685
|
for (const dependency of meta.dependencies) {
|
|
1448
1686
|
moduleManifestDependencies.add(dependency);
|
|
1449
1687
|
}
|
|
1450
|
-
const
|
|
1688
|
+
const resolveOptions = {
|
|
1451
1689
|
root: config.root,
|
|
1452
1690
|
source: config.source,
|
|
1453
1691
|
injectionDefaults,
|
|
@@ -1455,26 +1693,50 @@ async function scanner(config) {
|
|
|
1455
1693
|
componentPath: path4.join(modulePath, meta.moduleConfig.component),
|
|
1456
1694
|
fallbackName: module,
|
|
1457
1695
|
moduleManifestFile: meta.moduleManifestFile
|
|
1458
|
-
}
|
|
1696
|
+
};
|
|
1697
|
+
const moduleId = meta.moduleConfig.name || module;
|
|
1698
|
+
const manifestConfig = manifestInjectionConfigs.get(moduleId);
|
|
1699
|
+
const resolveMeta = resolveInjection(
|
|
1700
|
+
manifestConfig ? { ...manifestConfig, ...meta.moduleConfig } : meta.moduleConfig,
|
|
1701
|
+
resolveOptions
|
|
1702
|
+
);
|
|
1459
1703
|
injectionsMeta.push(resolveMeta);
|
|
1704
|
+
moduleInjectionConfigs.set(resolveMeta.moduleId, meta.moduleConfig);
|
|
1460
1705
|
}
|
|
1461
1706
|
const injections = mergeMeta(resolveManifest, injectionsMeta).filter(
|
|
1462
1707
|
(injection) => injection.enabled
|
|
1463
1708
|
);
|
|
1464
|
-
|
|
1465
|
-
|
|
1709
|
+
const resolvedListeners = resolveListeners(loadedManifest.manifest, {
|
|
1710
|
+
root: config.root
|
|
1711
|
+
});
|
|
1712
|
+
const listeners = resolvedListeners.filter((listener) => listener.enabled);
|
|
1713
|
+
if (injections.length === 0 && listeners.length === 0) {
|
|
1714
|
+
throw new NoEnabledTasksError();
|
|
1466
1715
|
}
|
|
1716
|
+
const manifestBindings = buildManifestBindings({
|
|
1717
|
+
manifest: loadedManifest.manifest,
|
|
1718
|
+
manifestFile: loadedManifest.manifestFile,
|
|
1719
|
+
manifestInjections: resolveManifest,
|
|
1720
|
+
moduleInjections: injectionsMeta,
|
|
1721
|
+
moduleInjectionConfigs,
|
|
1722
|
+
manifestListeners: resolvedListeners,
|
|
1723
|
+
enabledInjections: injections,
|
|
1724
|
+
enabledListeners: listeners
|
|
1725
|
+
});
|
|
1467
1726
|
injections.sort((a, b) => a.moduleId.localeCompare(b.moduleId));
|
|
1727
|
+
listeners.sort((a, b) => a.listenerId.localeCompare(b.listenerId));
|
|
1468
1728
|
const frameworks = [...new Set(injections.map((m) => m.framework))];
|
|
1469
1729
|
return {
|
|
1470
1730
|
config,
|
|
1471
1731
|
injectionDefaults,
|
|
1472
1732
|
manifestFile: loadedManifest.manifestFile,
|
|
1733
|
+
manifestBindings,
|
|
1473
1734
|
manifestDependencies: [...manifestDependencies].sort(),
|
|
1474
1735
|
moduleManifestDependencies: [...moduleManifestDependencies].sort(),
|
|
1475
1736
|
runtimeSetupFiles: [...runtimeSetupFiles].sort(),
|
|
1476
1737
|
runtimeDependencies: [...runtimeDependencies].sort(),
|
|
1477
1738
|
injections,
|
|
1739
|
+
listeners,
|
|
1478
1740
|
frameworks
|
|
1479
1741
|
};
|
|
1480
1742
|
}
|
|
@@ -1501,7 +1763,7 @@ function formatInspectInjection(injection, injectionDefaults) {
|
|
|
1501
1763
|
};
|
|
1502
1764
|
}
|
|
1503
1765
|
function formatInspectResult(result) {
|
|
1504
|
-
const { config, injectionDefaults, injections } = result;
|
|
1766
|
+
const { config, injectionDefaults, injections, listeners } = result;
|
|
1505
1767
|
const moduleManifestFiles = [
|
|
1506
1768
|
...new Set(
|
|
1507
1769
|
injections.map((injection) => injection.moduleManifestFile).filter((file) => typeof file === "string")
|
|
@@ -1530,6 +1792,7 @@ function formatInspectResult(result) {
|
|
|
1530
1792
|
injections: injections.map(
|
|
1531
1793
|
(injection) => formatInspectInjection(injection, injectionDefaults)
|
|
1532
1794
|
),
|
|
1795
|
+
listeners,
|
|
1533
1796
|
frameworks: result.frameworks
|
|
1534
1797
|
};
|
|
1535
1798
|
}
|
|
@@ -1544,6 +1807,7 @@ async function inspectCommand() {
|
|
|
1544
1807
|
["Monkey", inspectResult.monkey],
|
|
1545
1808
|
["Injection Defaults", inspectResult.injectionDefaults],
|
|
1546
1809
|
["Injections", inspectResult.injections],
|
|
1810
|
+
["Listeners", inspectResult.listeners],
|
|
1547
1811
|
["Frameworks", inspectResult.frameworks]
|
|
1548
1812
|
];
|
|
1549
1813
|
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;
|
package/dist/config/resolve.d.ts
CHANGED
|
@@ -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;
|
package/dist/config/types.d.ts
CHANGED
|
@@ -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;
|
|
@@ -78,8 +84,14 @@ export type InjectionModuleListenerConfig = {
|
|
|
78
84
|
listenAt: string;
|
|
79
85
|
type: string;
|
|
80
86
|
callback: EventListener;
|
|
87
|
+
capture?: boolean;
|
|
81
88
|
activitySignal?: () => ActivitySignalSource<boolean>;
|
|
82
89
|
};
|
|
90
|
+
export type InjectionListenerConfig = InjectionModuleListenerConfig & {
|
|
91
|
+
name?: string;
|
|
92
|
+
enabled?: boolean;
|
|
93
|
+
match?: InjectionMatchConfig;
|
|
94
|
+
};
|
|
83
95
|
export type InjectionModuleOptions = Partial<Pick<RuntimeInjectionConfig, 'alive' | 'scope' | 'timeout' | 'hooks'>> & {
|
|
84
96
|
on?: InjectionModuleListenerConfig;
|
|
85
97
|
};
|
|
@@ -92,11 +104,14 @@ export type InjectionModuleConfig = InjectionModuleOptions & {
|
|
|
92
104
|
match?: InjectionMatchConfig;
|
|
93
105
|
};
|
|
94
106
|
export type InjectionManifestRecord = Record<string, Omit<InjectionModuleConfig, 'name'>>;
|
|
107
|
+
export type InjectionListenerRecord = Record<string, Omit<InjectionListenerConfig, 'name'>>;
|
|
95
108
|
export type InjectionManifest = {
|
|
96
109
|
injectionDefaults?: InjectionDefaults;
|
|
97
|
-
injections
|
|
110
|
+
injections?: InjectionModuleConfig[] | InjectionManifestRecord;
|
|
111
|
+
listeners?: InjectionListenerConfig[] | InjectionListenerRecord;
|
|
98
112
|
};
|
|
99
113
|
export type ResolvedInjectionManifest = InjectionModuleConfig[];
|
|
114
|
+
export type ResolvedListenerManifest = InjectionListenerConfig[];
|
|
100
115
|
export type ResolvedInjectionModule = Omit<InjectionModuleConfig, 'name' | 'component' | 'framework' | 'enabled' | 'alive' | 'scope' | 'timeout'> & {
|
|
101
116
|
moduleId: string;
|
|
102
117
|
componentPath: string;
|
|
@@ -109,6 +124,11 @@ export type ResolvedInjectionModule = Omit<InjectionModuleConfig, 'name' | 'comp
|
|
|
109
124
|
timeout: ResolvedInjectionDefaults['timeout'];
|
|
110
125
|
match?: InjectionMatchObject;
|
|
111
126
|
};
|
|
127
|
+
export type ResolvedListener = Omit<InjectionListenerConfig, 'name' | 'enabled' | 'match'> & {
|
|
128
|
+
listenerId: string;
|
|
129
|
+
enabled: boolean;
|
|
130
|
+
match?: InjectionMatchObject;
|
|
131
|
+
};
|
|
112
132
|
export type ResolvedMonkeyServerConfig = {
|
|
113
133
|
open: boolean;
|
|
114
134
|
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
|
|
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;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { ResolvedInjectionDefaults } from '../../../config/types';
|
|
2
|
-
import {
|
|
3
|
-
|
|
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 {
|
|
2
|
-
|
|
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;
|