@makoojs/cli 0.1.1 → 0.3.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/README.CN.md +6 -10
- package/README.md +6 -10
- package/dist/bin.js +120 -45
- package/dist/command/_util.d.ts +0 -8
- package/dist/command/inspect.d.ts +33 -0
- package/dist/config/defaults.d.ts +2 -2
- package/dist/config/resolve.d.ts +3 -3
- package/dist/config/types.d.ts +20 -13
- package/dist/config/validation.d.ts +1 -2
- package/dist/generator/render/import/importMakooRuntime.d.ts +1 -0
- package/dist/generator/render/init/initMakooRuntime.d.ts +3 -0
- package/dist/generator/render/run/renderMakooStart.d.ts +1 -0
- package/dist/index.cjs +24 -15
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1363 -1309
- package/dist/scanner/types.d.ts +5 -2
- package/dist/scanner/validation.d.ts +6 -6
- package/dist/shared/terminalColor.d.ts +8 -0
- package/dist/vitePlugin/hmrController.d.ts +2 -0
- package/dist/vitePlugin/types.d.ts +6 -0
- package/dist/vitePlugin/watchList.d.ts +2 -1
- package/package.json +2 -2
- package/dist/generator/render/import/importInjector.d.ts +0 -1
- package/dist/generator/render/init/initInjector.d.ts +0 -3
- package/dist/generator/render/run/renderInjectorRun.d.ts +0 -1
package/README.CN.md
CHANGED
|
@@ -71,19 +71,21 @@ Makoo 默认扫描项目根目录下的 `injections` 目录。
|
|
|
71
71
|
└─ manifest.ts
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
顶层 `injections/manifest.ts`
|
|
74
|
+
顶层 `injections/manifest.ts` 用来声明 manifest 级的注入默认值和模块列表。模块级 `injections/<module>/manifest.ts` 可以覆盖或补充单个模块的配置,适合让模块自己维护 `injectAt`、`component`、`framework`、`match` 或生命周期 hooks。
|
|
75
75
|
|
|
76
76
|
## Manifest 基础
|
|
77
77
|
|
|
78
78
|
`@makoojs/cli` 导出 `defineInjections()` 和 `defineInjection()`,用于给 manifest 提供类型约束。
|
|
79
79
|
|
|
80
|
+
`injectionDefaults` 用来定义当前 manifest 下共享的注入运行时默认值。模块没有显式配置时,会继承这里的 `alive`、`scope`、`timeout` 和 `hooks`;模块自己写了这些字段时,则以模块配置为准。
|
|
81
|
+
|
|
80
82
|
对象形式适合多数项目:
|
|
81
83
|
|
|
82
84
|
```ts
|
|
83
85
|
import { defineInjections } from '@makoojs/cli';
|
|
84
86
|
|
|
85
87
|
export default defineInjections({
|
|
86
|
-
|
|
88
|
+
injectionDefaults: {
|
|
87
89
|
alive: false,
|
|
88
90
|
scope: 'local',
|
|
89
91
|
timeout: 5000
|
|
@@ -183,11 +185,6 @@ makoo({
|
|
|
183
185
|
include: ['*'],
|
|
184
186
|
exclude: []
|
|
185
187
|
},
|
|
186
|
-
injector: {
|
|
187
|
-
alive: false,
|
|
188
|
-
scope: 'local',
|
|
189
|
-
timeout: 5000
|
|
190
|
-
},
|
|
191
188
|
runtime: {
|
|
192
189
|
setup: ['./injections/vue-setup.ts']
|
|
193
190
|
},
|
|
@@ -203,7 +200,6 @@ makoo({
|
|
|
203
200
|
| --- | --- |
|
|
204
201
|
| `app` | 用于生成 userscript 的 `name`、`version`、`description` |
|
|
205
202
|
| `source` | 控制扫描哪些 injection 模块目录 |
|
|
206
|
-
| `injector` | 传给 `@makoojs/core` 的全局注入默认值 |
|
|
207
203
|
| `runtime` | 控制 Makoo 生成入口里的运行时前置 setup import |
|
|
208
204
|
| `monkey` | 大多数配置会透传给 [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) |
|
|
209
205
|
|
|
@@ -241,7 +237,7 @@ Makoo 的 Vite 插件会在启动和构建时执行以下流程:
|
|
|
241
237
|
3. 读取模块级 `manifest.ts`,并与顶层 manifest 合并。
|
|
242
238
|
4. 解析组件路径、模块 ID、framework、match、alive、scope、timeout 等配置。
|
|
243
239
|
5. 根据实际使用到的 framework 生成 adapter import。
|
|
244
|
-
6. 生成虚拟入口,创建
|
|
240
|
+
6. 生成虚拟入口,创建 Makoo runtime,声明任务并执行 `start()`。
|
|
245
241
|
7. 把虚拟入口交给 [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) 打包成 userscript。
|
|
246
242
|
|
|
247
243
|
如果没有找到顶层 manifest、没有可用注入模块,或无法推断 framework,CLI 会抛出 Makoo 自己的错误类型,方便定位问题。
|
|
@@ -263,7 +259,7 @@ Makoo 的 Vite 插件会在启动和构建时执行以下流程:
|
|
|
263
259
|
|
|
264
260
|
## Runtime Setup
|
|
265
261
|
|
|
266
|
-
`runtime.setup` 用来导入一批只负责副作用初始化的运行时文件。它们会在 Makoo 初始化 adapter
|
|
262
|
+
`runtime.setup` 用来导入一批只负责副作用初始化的运行时文件。它们会在 Makoo 初始化 adapter、声明 injection、执行 `makoo.start(...)` 前进入最终 userscript bundle。
|
|
267
263
|
|
|
268
264
|
这个能力适合注册 Vue 插件、初始化 GM helper、导入全局样式或执行埋点初始化。
|
|
269
265
|
|
package/README.md
CHANGED
|
@@ -71,19 +71,21 @@ Makoo scans the `injections` directory under the project root by default.
|
|
|
71
71
|
└─ manifest.ts
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
The top-level `injections/manifest.ts` declares
|
|
74
|
+
The top-level `injections/manifest.ts` declares manifest-scoped injection defaults and the module list. A module-level `injections/<module>/manifest.ts` can override or add config for a single module, which is useful when a module should own fields such as `injectAt`, `component`, `framework`, `match`, or lifecycle hooks.
|
|
75
75
|
|
|
76
76
|
## Manifest Basics
|
|
77
77
|
|
|
78
78
|
`@makoojs/cli` exports `defineInjections()` and `defineInjection()` to provide type constraints for manifests.
|
|
79
79
|
|
|
80
|
+
`injectionDefaults` defines shared injection runtime defaults for the current manifest. Modules inherit `alive`, `scope`, `timeout`, and `hooks` from it unless they override those fields themselves.
|
|
81
|
+
|
|
80
82
|
Object form is suitable for most projects:
|
|
81
83
|
|
|
82
84
|
```ts
|
|
83
85
|
import { defineInjections } from '@makoojs/cli';
|
|
84
86
|
|
|
85
87
|
export default defineInjections({
|
|
86
|
-
|
|
88
|
+
injectionDefaults: {
|
|
87
89
|
alive: false,
|
|
88
90
|
scope: 'local',
|
|
89
91
|
timeout: 5000
|
|
@@ -183,11 +185,6 @@ makoo({
|
|
|
183
185
|
include: ['*'],
|
|
184
186
|
exclude: []
|
|
185
187
|
},
|
|
186
|
-
injector: {
|
|
187
|
-
alive: false,
|
|
188
|
-
scope: 'local',
|
|
189
|
-
timeout: 5000
|
|
190
|
-
},
|
|
191
188
|
runtime: {
|
|
192
189
|
setup: ['./injections/vue-setup.ts']
|
|
193
190
|
},
|
|
@@ -203,7 +200,6 @@ makoo({
|
|
|
203
200
|
| --- | --- |
|
|
204
201
|
| `app` | Generates userscript `name`, `version`, and `description` |
|
|
205
202
|
| `source` | Controls which injection module directories are scanned |
|
|
206
|
-
| `injector` | Global injection defaults passed to `@makoojs/core` |
|
|
207
203
|
| `runtime` | Controls runtime setup imports in the Makoo-generated entry |
|
|
208
204
|
| `monkey` | Most options are passed through to [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) |
|
|
209
205
|
|
|
@@ -241,7 +237,7 @@ Makoo's Vite plugin runs this flow during dev startup and build:
|
|
|
241
237
|
3. Read module-level `manifest.ts` files and merge them with the top-level manifest.
|
|
242
238
|
4. Resolve component paths, module IDs, framework, match, alive, scope, timeout, and related config.
|
|
243
239
|
5. Generate adapter imports based on the frameworks actually used.
|
|
244
|
-
6. Generate a virtual entry, create
|
|
240
|
+
6. Generate a virtual entry, create a Makoo runtime, declare tasks, and call `start()`.
|
|
245
241
|
7. Hand the virtual entry to [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) so it can be bundled as a userscript.
|
|
246
242
|
|
|
247
243
|
If the top-level manifest is missing, no enabled injection modules are found, or the framework cannot be inferred, the CLI throws Makoo's own error types to make the issue easier to locate.
|
|
@@ -263,7 +259,7 @@ Structural changes update the virtual entry. Changes inside regular components k
|
|
|
263
259
|
|
|
264
260
|
## Runtime Setup
|
|
265
261
|
|
|
266
|
-
`runtime.setup` imports side-effect-only runtime files before Makoo initializes adapters,
|
|
262
|
+
`runtime.setup` imports side-effect-only runtime files before Makoo initializes adapters, declares injections, and calls `makoo.start(...)`.
|
|
267
263
|
|
|
268
264
|
Use it to register Vue plugins, initialize GM helpers, import global styles, or run analytics setup.
|
|
269
265
|
|
package/dist/bin.js
CHANGED
|
@@ -641,7 +641,7 @@ var DEFAULT_SOURCE_CONFIG = {
|
|
|
641
641
|
exclude: [],
|
|
642
642
|
manifest: DEFAULT_MANIFEST_FILE_NAME
|
|
643
643
|
};
|
|
644
|
-
var
|
|
644
|
+
var DEFAULT_INJECTION_DEFAULTS = {
|
|
645
645
|
alive: false,
|
|
646
646
|
scope: "local",
|
|
647
647
|
timeout: 5e3,
|
|
@@ -785,14 +785,6 @@ import { fileURLToPath } from "url";
|
|
|
785
785
|
import { ErrorCode as ErrorCode2 } from "@makoojs/core";
|
|
786
786
|
import { createJiti } from "jiti";
|
|
787
787
|
import { loadConfigFromFile } from "vite";
|
|
788
|
-
var ansi = {
|
|
789
|
-
reset: "\x1B[0m",
|
|
790
|
-
bold: "\x1B[1m",
|
|
791
|
-
cyan: "\x1B[36m",
|
|
792
|
-
green: "\x1B[32m",
|
|
793
|
-
dim: "\x1B[2m"
|
|
794
|
-
};
|
|
795
|
-
var colorize = (value, ...codes) => `${codes.join("")}${value}${ansi.reset}`;
|
|
796
788
|
async function loadCliVersion(cliVersionCache2) {
|
|
797
789
|
if (cliVersionCache2) {
|
|
798
790
|
return cliVersionCache2;
|
|
@@ -950,6 +942,18 @@ async function buildCommand() {
|
|
|
950
942
|
|
|
951
943
|
// src/command/dev.ts
|
|
952
944
|
import { createServer } from "vite";
|
|
945
|
+
|
|
946
|
+
// src/shared/terminalColor.ts
|
|
947
|
+
var ansi = {
|
|
948
|
+
reset: "\x1B[0m",
|
|
949
|
+
bold: "\x1B[1m",
|
|
950
|
+
cyan: "\x1B[36m",
|
|
951
|
+
green: "\x1B[32m",
|
|
952
|
+
dim: "\x1B[2m"
|
|
953
|
+
};
|
|
954
|
+
var colorize = (value, ...codes) => `${codes.join("")}${value}${ansi.reset}`;
|
|
955
|
+
|
|
956
|
+
// src/command/dev.ts
|
|
953
957
|
var cliVersionCache = null;
|
|
954
958
|
async function printDevBanner(server) {
|
|
955
959
|
const cliVersion = await loadCliVersion(cliVersionCache);
|
|
@@ -1019,8 +1023,15 @@ var CliConfigSchema = z.object({
|
|
|
1019
1023
|
app: AppConfigSchema,
|
|
1020
1024
|
monkey: MonkeyConfigSchema.optional(),
|
|
1021
1025
|
source: z.object({}).passthrough().optional(),
|
|
1022
|
-
injector: z.object({}).passthrough().optional(),
|
|
1023
1026
|
runtime: z.object({}).passthrough().optional()
|
|
1027
|
+
}).loose().superRefine((value, context) => {
|
|
1028
|
+
if ("injector" in value) {
|
|
1029
|
+
context.addIssue({
|
|
1030
|
+
code: z.ZodIssueCode.custom,
|
|
1031
|
+
path: ["injector"],
|
|
1032
|
+
message: "injector is not supported in vite config; use manifest injectionDefaults instead"
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1024
1035
|
});
|
|
1025
1036
|
|
|
1026
1037
|
// src/config/resolve.ts
|
|
@@ -1110,18 +1121,18 @@ var resolveSourceConfig = (config, root) => {
|
|
|
1110
1121
|
manifest: DEFAULT_MANIFEST_FILE_NAME
|
|
1111
1122
|
};
|
|
1112
1123
|
};
|
|
1113
|
-
var
|
|
1124
|
+
var resolveInjectionDefaults = (config) => {
|
|
1114
1125
|
return {
|
|
1115
|
-
alive: config?.alive ??
|
|
1116
|
-
scope: config?.scope ??
|
|
1117
|
-
timeout: config?.timeout ??
|
|
1126
|
+
alive: config?.alive ?? DEFAULT_INJECTION_DEFAULTS.alive,
|
|
1127
|
+
scope: config?.scope ?? DEFAULT_INJECTION_DEFAULTS.scope,
|
|
1128
|
+
timeout: config?.timeout ?? DEFAULT_INJECTION_DEFAULTS.timeout,
|
|
1118
1129
|
hooks: config?.hooks
|
|
1119
1130
|
};
|
|
1120
1131
|
};
|
|
1121
1132
|
var resolveInjection = (config, options) => {
|
|
1122
1133
|
const root = resolveProjectRoot(options.root);
|
|
1123
1134
|
const source = options.source ?? resolveSourceConfig(void 0, root);
|
|
1124
|
-
const
|
|
1135
|
+
const injectionDefaults = options.injectionDefaults ?? resolveInjectionDefaults(void 0);
|
|
1125
1136
|
const componentBaseDir = options.moduleDir ? resolveFileSystemPath(root, options.moduleDir) : source.dir;
|
|
1126
1137
|
if (!options.componentPath) {
|
|
1127
1138
|
throw new ComponentNotFoundError(config.name ?? config.injectAt);
|
|
@@ -1151,18 +1162,18 @@ var resolveInjection = (config, options) => {
|
|
|
1151
1162
|
options.index
|
|
1152
1163
|
);
|
|
1153
1164
|
const framework = resolveFramework(config.framework, componentPath);
|
|
1154
|
-
const
|
|
1165
|
+
const moduleManifestFile = options.moduleManifestFile ? resolveFileSystemPath(root, options.moduleManifestFile) : void 0;
|
|
1155
1166
|
return {
|
|
1156
1167
|
...rest,
|
|
1157
1168
|
moduleId,
|
|
1158
1169
|
componentPath,
|
|
1159
1170
|
framework,
|
|
1160
1171
|
moduleDir,
|
|
1161
|
-
|
|
1172
|
+
moduleManifestFile,
|
|
1162
1173
|
enabled: config.enabled ?? true,
|
|
1163
|
-
alive: config.alive ??
|
|
1164
|
-
scope: config.scope ??
|
|
1165
|
-
timeout: config.timeout ??
|
|
1174
|
+
alive: config.alive ?? injectionDefaults.alive,
|
|
1175
|
+
scope: config.scope ?? injectionDefaults.scope,
|
|
1176
|
+
timeout: config.timeout ?? injectionDefaults.timeout,
|
|
1166
1177
|
match: resolveMatchConfig(config.match)
|
|
1167
1178
|
};
|
|
1168
1179
|
};
|
|
@@ -1173,7 +1184,7 @@ var resolveInjections = (injections, options) => {
|
|
|
1173
1184
|
(injection, index) => resolveInjection(injection, {
|
|
1174
1185
|
root,
|
|
1175
1186
|
source: options.source,
|
|
1176
|
-
|
|
1187
|
+
injectionDefaults: options.injectionDefaults,
|
|
1177
1188
|
componentPath: resolvePath(options.source.dir, injection.component),
|
|
1178
1189
|
// `index` was a name of element
|
|
1179
1190
|
index
|
|
@@ -1268,7 +1279,7 @@ var HookSchema = z2.union([z2.function(), z2.array(z2.function())]);
|
|
|
1268
1279
|
var LifecycleHookMapSchema = z2.record(z2.string(), HookSchema).refine((obj) => Object.keys(obj).every((k) => ObserveEventNameSchema.safeParse(k).success), {
|
|
1269
1280
|
message: "Invalid hook event name"
|
|
1270
1281
|
});
|
|
1271
|
-
var
|
|
1282
|
+
var InjectionDefaultsSchema = z2.object({
|
|
1272
1283
|
alive: z2.boolean().optional(),
|
|
1273
1284
|
scope: z2.enum(["local", "global"]).optional(),
|
|
1274
1285
|
timeout: z2.number().optional(),
|
|
@@ -1293,12 +1304,12 @@ var InjectionModuleSchema = z2.object({
|
|
|
1293
1304
|
timeout: z2.number().optional()
|
|
1294
1305
|
});
|
|
1295
1306
|
var InjectionManifestSchema = z2.object({
|
|
1296
|
-
|
|
1307
|
+
injectionDefaults: InjectionDefaultsSchema.optional(),
|
|
1297
1308
|
injections: z2.union([
|
|
1298
1309
|
z2.array(InjectionModuleSchema),
|
|
1299
1310
|
z2.record(z2.string(), InjectionModuleSchema.omit({ name: true }))
|
|
1300
1311
|
])
|
|
1301
|
-
});
|
|
1312
|
+
}).strict();
|
|
1302
1313
|
function validateManifest(data, file) {
|
|
1303
1314
|
const result = InjectionManifestSchema.safeParse(data);
|
|
1304
1315
|
if (!result.success) {
|
|
@@ -1374,7 +1385,7 @@ async function loadMeta(root) {
|
|
|
1374
1385
|
);
|
|
1375
1386
|
}
|
|
1376
1387
|
return {
|
|
1377
|
-
|
|
1388
|
+
moduleManifestFile: fullPath,
|
|
1378
1389
|
moduleConfig: validateModuleMeta(raw, fullPath),
|
|
1379
1390
|
dependencies: collectDependencies(fullPath, {
|
|
1380
1391
|
root: path3.resolve(root, "..", "..")
|
|
@@ -1404,24 +1415,23 @@ async function scanner(config) {
|
|
|
1404
1415
|
throw new ManifestNotFoundError(config.source.dir);
|
|
1405
1416
|
}
|
|
1406
1417
|
const manifestDependencies = new Set(loadedManifest.dependencies);
|
|
1418
|
+
const moduleManifestDependencies = /* @__PURE__ */ new Set();
|
|
1419
|
+
const runtimeSetupFiles = /* @__PURE__ */ new Set();
|
|
1407
1420
|
const runtimeDependencies = /* @__PURE__ */ new Set();
|
|
1408
1421
|
for (const setupFile of config.runtime.setup) {
|
|
1409
1422
|
if (!existsSync5(setupFile)) {
|
|
1410
1423
|
throw new RuntimeSetupNotFoundError(setupFile);
|
|
1411
1424
|
}
|
|
1412
|
-
|
|
1425
|
+
runtimeSetupFiles.add(setupFile);
|
|
1413
1426
|
for (const dependency of collectDependencies(setupFile, { root: config.root })) {
|
|
1414
1427
|
runtimeDependencies.add(dependency);
|
|
1415
1428
|
}
|
|
1416
1429
|
}
|
|
1417
|
-
const
|
|
1418
|
-
...config.injector,
|
|
1419
|
-
...loadedManifest.manifest.globalInjector
|
|
1420
|
-
});
|
|
1430
|
+
const injectionDefaults = resolveInjectionDefaults(loadedManifest.manifest.injectionDefaults);
|
|
1421
1431
|
const resolveManifest = resolveInjections(loadedManifest.manifest, {
|
|
1422
1432
|
root: config.root,
|
|
1423
1433
|
source: config.source,
|
|
1424
|
-
|
|
1434
|
+
injectionDefaults
|
|
1425
1435
|
});
|
|
1426
1436
|
const folder = readdirSync2(config.source.dir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
1427
1437
|
const isIncluded = picomatch(config.source.include);
|
|
@@ -1435,16 +1445,16 @@ async function scanner(config) {
|
|
|
1435
1445
|
continue;
|
|
1436
1446
|
}
|
|
1437
1447
|
for (const dependency of meta.dependencies) {
|
|
1438
|
-
|
|
1448
|
+
moduleManifestDependencies.add(dependency);
|
|
1439
1449
|
}
|
|
1440
1450
|
const resolveMeta = resolveInjection(meta.moduleConfig, {
|
|
1441
1451
|
root: config.root,
|
|
1442
1452
|
source: config.source,
|
|
1443
|
-
|
|
1453
|
+
injectionDefaults,
|
|
1444
1454
|
moduleDir: modulePath,
|
|
1445
1455
|
componentPath: path4.join(modulePath, meta.moduleConfig.component),
|
|
1446
1456
|
fallbackName: module,
|
|
1447
|
-
|
|
1457
|
+
moduleManifestFile: meta.moduleManifestFile
|
|
1448
1458
|
});
|
|
1449
1459
|
injectionsMeta.push(resolveMeta);
|
|
1450
1460
|
}
|
|
@@ -1457,9 +1467,12 @@ async function scanner(config) {
|
|
|
1457
1467
|
injections.sort((a, b) => a.moduleId.localeCompare(b.moduleId));
|
|
1458
1468
|
const frameworks = [...new Set(injections.map((m) => m.framework))];
|
|
1459
1469
|
return {
|
|
1460
|
-
config
|
|
1470
|
+
config,
|
|
1471
|
+
injectionDefaults,
|
|
1461
1472
|
manifestFile: loadedManifest.manifestFile,
|
|
1462
1473
|
manifestDependencies: [...manifestDependencies].sort(),
|
|
1474
|
+
moduleManifestDependencies: [...moduleManifestDependencies].sort(),
|
|
1475
|
+
runtimeSetupFiles: [...runtimeSetupFiles].sort(),
|
|
1463
1476
|
runtimeDependencies: [...runtimeDependencies].sort(),
|
|
1464
1477
|
injections,
|
|
1465
1478
|
frameworks
|
|
@@ -1467,19 +1480,81 @@ async function scanner(config) {
|
|
|
1467
1480
|
}
|
|
1468
1481
|
|
|
1469
1482
|
// src/command/inspect.ts
|
|
1483
|
+
function formatInspectInjection(injection, injectionDefaults) {
|
|
1484
|
+
const { alive, scope, timeout, ...rest } = injection;
|
|
1485
|
+
const resolvedInjectionDefaults = { alive, scope, timeout };
|
|
1486
|
+
const injectionDefaultsOverrides = {
|
|
1487
|
+
...alive !== injectionDefaults.alive ? { alive } : {},
|
|
1488
|
+
...scope !== injectionDefaults.scope ? { scope } : {},
|
|
1489
|
+
...timeout !== injectionDefaults.timeout ? { timeout } : {}
|
|
1490
|
+
};
|
|
1491
|
+
if (Object.keys(injectionDefaultsOverrides).length === 0) {
|
|
1492
|
+
return {
|
|
1493
|
+
...rest,
|
|
1494
|
+
injectionDefaults: resolvedInjectionDefaults
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
return {
|
|
1498
|
+
...rest,
|
|
1499
|
+
injectionDefaults: resolvedInjectionDefaults,
|
|
1500
|
+
injectionDefaultsOverrides
|
|
1501
|
+
};
|
|
1502
|
+
}
|
|
1503
|
+
function formatInspectResult(result) {
|
|
1504
|
+
const { config, injectionDefaults, injections } = result;
|
|
1505
|
+
const moduleManifestFiles = [
|
|
1506
|
+
...new Set(
|
|
1507
|
+
injections.map((injection) => injection.moduleManifestFile).filter((file) => typeof file === "string")
|
|
1508
|
+
)
|
|
1509
|
+
].sort();
|
|
1510
|
+
return {
|
|
1511
|
+
project: {
|
|
1512
|
+
root: config.root,
|
|
1513
|
+
app: config.app
|
|
1514
|
+
},
|
|
1515
|
+
source: {
|
|
1516
|
+
config: config.source,
|
|
1517
|
+
manifestFile: result.manifestFile,
|
|
1518
|
+
moduleManifestFiles,
|
|
1519
|
+
dependencies: {
|
|
1520
|
+
manifest: result.manifestDependencies,
|
|
1521
|
+
moduleManifests: result.moduleManifestDependencies
|
|
1522
|
+
}
|
|
1523
|
+
},
|
|
1524
|
+
runtime: {
|
|
1525
|
+
setupFiles: result.runtimeSetupFiles,
|
|
1526
|
+
dependencies: result.runtimeDependencies
|
|
1527
|
+
},
|
|
1528
|
+
monkey: config.monkey,
|
|
1529
|
+
injectionDefaults,
|
|
1530
|
+
injections: injections.map(
|
|
1531
|
+
(injection) => formatInspectInjection(injection, injectionDefaults)
|
|
1532
|
+
),
|
|
1533
|
+
frameworks: result.frameworks
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1470
1536
|
async function inspectCommand() {
|
|
1471
1537
|
const resolveViteMakooConfig = await loadMakooConfig();
|
|
1472
1538
|
const resolveManifest = await scanner(resolveViteMakooConfig);
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1539
|
+
const inspectResult = formatInspectResult(resolveManifest);
|
|
1540
|
+
const sections = [
|
|
1541
|
+
["Project", inspectResult.project],
|
|
1542
|
+
["Source", inspectResult.source],
|
|
1543
|
+
["Runtime", inspectResult.runtime],
|
|
1544
|
+
["Monkey", inspectResult.monkey],
|
|
1545
|
+
["Injection Defaults", inspectResult.injectionDefaults],
|
|
1546
|
+
["Injections", inspectResult.injections],
|
|
1547
|
+
["Frameworks", inspectResult.frameworks]
|
|
1548
|
+
];
|
|
1549
|
+
console.log(colorize("Makoo Inspect", ansi.bold, ansi.green));
|
|
1550
|
+
for (const [label, value] of sections) {
|
|
1551
|
+
console.log(`
|
|
1552
|
+
${colorize(label, ansi.cyan)}`);
|
|
1553
|
+
console.dir(value, {
|
|
1554
|
+
depth: null,
|
|
1555
|
+
colors: true
|
|
1556
|
+
});
|
|
1557
|
+
}
|
|
1483
1558
|
}
|
|
1484
1559
|
|
|
1485
1560
|
// src/command/bin.ts
|
package/dist/command/_util.d.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
import { ResolvedConfig } from '../config/types';
|
|
2
|
-
export declare const ansi: {
|
|
3
|
-
readonly reset: "\u001B[0m";
|
|
4
|
-
readonly bold: "\u001B[1m";
|
|
5
|
-
readonly cyan: "\u001B[36m";
|
|
6
|
-
readonly green: "\u001B[32m";
|
|
7
|
-
readonly dim: "\u001B[2m";
|
|
8
|
-
};
|
|
9
|
-
export declare const colorize: (value: string, ...codes: string[]) => string;
|
|
10
2
|
export declare function loadCliVersion(cliVersionCache: string | null): Promise<string>;
|
|
11
3
|
export declare function loadMakooConfig(): Promise<ResolvedConfig>;
|
|
12
4
|
export declare function getExtName(framework: string): string | null;
|
|
@@ -1 +1,34 @@
|
|
|
1
|
+
import { ResolvedConfig, ResolvedInjectionDefaults, ResolvedInjectionModule } from '../config/types';
|
|
2
|
+
import { ScannerResult } from '../scanner/types';
|
|
3
|
+
type InspectInjectionDefaultsFields = Pick<ResolvedInjectionModule, 'alive' | 'scope' | 'timeout'>;
|
|
4
|
+
type InspectInjection = Omit<ResolvedInjectionModule, keyof InspectInjectionDefaultsFields> & {
|
|
5
|
+
injectionDefaults: InspectInjectionDefaultsFields;
|
|
6
|
+
injectionDefaultsOverrides?: Partial<InspectInjectionDefaultsFields>;
|
|
7
|
+
};
|
|
8
|
+
type InspectResult = {
|
|
9
|
+
project: {
|
|
10
|
+
root: ResolvedConfig['root'];
|
|
11
|
+
app: ResolvedConfig['app'];
|
|
12
|
+
};
|
|
13
|
+
source: {
|
|
14
|
+
config: ResolvedConfig['source'];
|
|
15
|
+
manifestFile: ScannerResult['manifestFile'];
|
|
16
|
+
moduleManifestFiles: string[];
|
|
17
|
+
dependencies: {
|
|
18
|
+
manifest: ScannerResult['manifestDependencies'];
|
|
19
|
+
moduleManifests: ScannerResult['moduleManifestDependencies'];
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
runtime: {
|
|
23
|
+
setupFiles: ScannerResult['runtimeSetupFiles'];
|
|
24
|
+
dependencies: ScannerResult['runtimeDependencies'];
|
|
25
|
+
};
|
|
26
|
+
monkey: ResolvedConfig['monkey'];
|
|
27
|
+
injectionDefaults: ScannerResult['injectionDefaults'];
|
|
28
|
+
injections: InspectInjection[];
|
|
29
|
+
frameworks: ScannerResult['frameworks'];
|
|
30
|
+
};
|
|
31
|
+
export declare function formatInspectInjection(injection: ResolvedInjectionModule, injectionDefaults: ResolvedInjectionDefaults): InspectInjection;
|
|
32
|
+
export declare function formatInspectResult(result: ScannerResult): InspectResult;
|
|
1
33
|
export declare function inspectCommand(): Promise<void>;
|
|
34
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InjectionDefaults, MonkeyBuildConfig, MonkeyConfig, MonkeyServerConfig, ResolvedRuntimeConfig } from './types';
|
|
2
2
|
export declare const SOURCE_EXTENSIONS: string[];
|
|
3
3
|
export declare const ESM_IMPORT_RE: RegExp;
|
|
4
4
|
export declare const CJS_IMPORT_RE: RegExp;
|
|
@@ -17,7 +17,7 @@ export declare const DEFAULT_SOURCE_CONFIG: {
|
|
|
17
17
|
manifest: string;
|
|
18
18
|
};
|
|
19
19
|
export declare const DEFAULT_RUNTIME_CONFIG: ResolvedRuntimeConfig;
|
|
20
|
-
export declare const
|
|
20
|
+
export declare const DEFAULT_INJECTION_DEFAULTS: Required<InjectionDefaults>;
|
|
21
21
|
export declare const DEFAULT_MONKEY_SERVER_CONFIG: Required<MonkeyServerConfig>;
|
|
22
22
|
export declare const DEFAULT_MONKEY_BUILD_CONFIG: Pick<Required<MonkeyBuildConfig>, 'metaFileName' | 'autoGrant'>;
|
|
23
23
|
export declare const DEFAULT_MONKEY_CONFIG: Pick<MonkeyConfig, 'align' | 'styleImport'> & {
|
package/dist/config/resolve.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { MonkeyOption } from 'vite-plugin-monkey';
|
|
2
|
-
import { AppConfig, CliConfig, InjectionManifest, InjectionModuleConfig,
|
|
2
|
+
import { AppConfig, CliConfig, InjectionDefaults, InjectionManifest, InjectionModuleConfig, MonkeyConfig, ResolveConfigOptions, ResolvedConfig, ResolvedInjectionDefaults, ResolvedInjectionManifest, ResolvedInjectionModule, ResolvedMonkeyBuildConfig, ResolvedMonkeyConfig, ResolvedMonkeyServerConfig, ResolvedRuntimeConfig, ResolvedSourceConfig, ResolveInjectionOptions, RuntimeConfig, SourceConfig } from './types';
|
|
3
3
|
export declare const normalizeInjectionManifest: (injections: InjectionManifest | undefined) => ResolvedInjectionManifest;
|
|
4
4
|
export declare const resolveAppConfig: (config: AppConfig) => AppConfig;
|
|
5
5
|
export declare const resolveSourceConfig: (config: SourceConfig | undefined, root: string) => ResolvedSourceConfig;
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const resolveInjectionDefaults: (config: InjectionDefaults | undefined) => ResolvedInjectionDefaults;
|
|
7
7
|
export declare const resolveRuntimeConfig: (config: RuntimeConfig | undefined, root: string) => ResolvedRuntimeConfig;
|
|
8
8
|
export declare const resolveMonkeyServerConfig: (config: MonkeyConfig | undefined) => ResolvedMonkeyServerConfig;
|
|
9
9
|
export declare const resolveMonkeyBuildConfig: (app: AppConfig, config: MonkeyConfig | undefined) => ResolvedMonkeyBuildConfig;
|
|
@@ -11,7 +11,7 @@ export declare const resolveMonkeyConfig: (app: AppConfig, config: MonkeyConfig
|
|
|
11
11
|
export declare const resolveInjection: (config: InjectionModuleConfig, options: ResolveInjectionOptions) => ResolvedInjectionModule;
|
|
12
12
|
export declare const resolveInjections: (injections: InjectionManifest | undefined, options: ResolveConfigOptions & {
|
|
13
13
|
source: ResolvedSourceConfig;
|
|
14
|
-
|
|
14
|
+
injectionDefaults: ResolvedInjectionDefaults;
|
|
15
15
|
}) => ResolvedInjectionModule[];
|
|
16
16
|
export declare const resolveConfig: (config: CliConfig, root?: string) => ResolvedConfig;
|
|
17
17
|
export declare function resolveMonkeyPluginOptions(config: ResolvedConfig, override?: Partial<MonkeyOption>): MonkeyOption;
|
package/dist/config/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ActivitySignalSource, LifecycleHookMap, InjectionConfig as RuntimeInjectionConfig } from '../../../../../core';
|
|
2
2
|
import { ExternalGlobals, ExternalResource, MonkeyOption, MonkeyUserScript } from 'vite-plugin-monkey';
|
|
3
3
|
export type StrictShape<Shape, Value extends Shape> = Value & Record<Exclude<keyof Value, keyof Shape>, never>;
|
|
4
4
|
export type Thenable<T> = T | Promise<T>;
|
|
@@ -9,11 +9,11 @@ export type ResolveConfigOptions = {
|
|
|
9
9
|
export type ResolveInjectionOptions = {
|
|
10
10
|
root?: string;
|
|
11
11
|
source?: ResolvedSourceConfig;
|
|
12
|
-
|
|
12
|
+
injectionDefaults?: ResolvedInjectionDefaults;
|
|
13
13
|
moduleId?: string;
|
|
14
14
|
moduleDir?: string;
|
|
15
15
|
componentPath?: string;
|
|
16
|
-
|
|
16
|
+
moduleManifestFile?: string;
|
|
17
17
|
fallbackName?: string;
|
|
18
18
|
index?: number;
|
|
19
19
|
};
|
|
@@ -63,8 +63,8 @@ export type ResolvedSourceConfig = {
|
|
|
63
63
|
exclude: string[];
|
|
64
64
|
manifest: string;
|
|
65
65
|
};
|
|
66
|
-
export type
|
|
67
|
-
export type
|
|
66
|
+
export type InjectionDefaults = Partial<Pick<RuntimeInjectionConfig, 'alive' | 'scope' | 'timeout' | 'hooks'>>;
|
|
67
|
+
export type ResolvedInjectionDefaults = Pick<RuntimeInjectionConfig, 'alive' | 'scope' | 'timeout'> & {
|
|
68
68
|
hooks?: LifecycleHookMap;
|
|
69
69
|
};
|
|
70
70
|
export type InjectionFramework = 'auto' | 'Vue' | 'React';
|
|
@@ -74,7 +74,16 @@ export type InjectionMatchObject = {
|
|
|
74
74
|
exclude?: string[];
|
|
75
75
|
};
|
|
76
76
|
export type InjectionMatchConfig = string[] | InjectionMatchObject;
|
|
77
|
-
export type
|
|
77
|
+
export type InjectionModuleListenerConfig = {
|
|
78
|
+
listenAt: string;
|
|
79
|
+
type: string;
|
|
80
|
+
callback: EventListener;
|
|
81
|
+
activitySignal?: () => ActivitySignalSource<boolean>;
|
|
82
|
+
};
|
|
83
|
+
export type InjectionModuleOptions = Partial<Pick<RuntimeInjectionConfig, 'alive' | 'scope' | 'timeout' | 'hooks'>> & {
|
|
84
|
+
on?: InjectionModuleListenerConfig;
|
|
85
|
+
};
|
|
86
|
+
export type InjectionModuleConfig = InjectionModuleOptions & {
|
|
78
87
|
name?: string;
|
|
79
88
|
injectAt: string;
|
|
80
89
|
component: string;
|
|
@@ -84,7 +93,7 @@ export type InjectionModuleConfig = ArtifactOptions & {
|
|
|
84
93
|
};
|
|
85
94
|
export type InjectionManifestRecord = Record<string, Omit<InjectionModuleConfig, 'name'>>;
|
|
86
95
|
export type InjectionManifest = {
|
|
87
|
-
|
|
96
|
+
injectionDefaults?: InjectionDefaults;
|
|
88
97
|
injections: InjectionModuleConfig[] | InjectionManifestRecord;
|
|
89
98
|
};
|
|
90
99
|
export type ResolvedInjectionManifest = InjectionModuleConfig[];
|
|
@@ -93,11 +102,11 @@ export type ResolvedInjectionModule = Omit<InjectionModuleConfig, 'name' | 'comp
|
|
|
93
102
|
componentPath: string;
|
|
94
103
|
framework: ResolvedInjectionFramework;
|
|
95
104
|
moduleDir: string;
|
|
96
|
-
|
|
105
|
+
moduleManifestFile?: string;
|
|
97
106
|
enabled: boolean;
|
|
98
|
-
alive:
|
|
99
|
-
scope:
|
|
100
|
-
timeout:
|
|
107
|
+
alive: ResolvedInjectionDefaults['alive'];
|
|
108
|
+
scope: ResolvedInjectionDefaults['scope'];
|
|
109
|
+
timeout: ResolvedInjectionDefaults['timeout'];
|
|
101
110
|
match?: InjectionMatchObject;
|
|
102
111
|
};
|
|
103
112
|
export type ResolvedMonkeyServerConfig = {
|
|
@@ -126,7 +135,6 @@ export type CliConfig = {
|
|
|
126
135
|
app: AppConfig;
|
|
127
136
|
monkey?: MonkeyConfig;
|
|
128
137
|
source?: SourceConfig;
|
|
129
|
-
injector?: InjectorConfig;
|
|
130
138
|
runtime?: RuntimeConfig;
|
|
131
139
|
};
|
|
132
140
|
export type ResolvedConfig = {
|
|
@@ -134,7 +142,6 @@ export type ResolvedConfig = {
|
|
|
134
142
|
app: AppConfig;
|
|
135
143
|
monkey: ResolvedMonkeyConfig;
|
|
136
144
|
source: ResolvedSourceConfig;
|
|
137
|
-
injector: ResolvedInjectorConfig;
|
|
138
145
|
runtime: ResolvedRuntimeConfig;
|
|
139
146
|
};
|
|
140
147
|
export type MonkeyUserscriptOption = NonNullable<MonkeyOption['userscript']>;
|
|
@@ -9,7 +9,6 @@ export declare const CliConfigSchema: z.ZodObject<{
|
|
|
9
9
|
server: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
10
10
|
}, z.core.$loose>>;
|
|
11
11
|
source: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
12
|
-
injector: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
13
12
|
runtime: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
14
|
-
}, z.core.$
|
|
13
|
+
}, z.core.$loose>;
|
|
15
14
|
export declare function validateCliConfig(data: unknown): asserts data is z.infer<typeof CliConfigSchema>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function renderImportMakooRuntime(): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function renderMakooStart(instanceName: string): string;
|