@makoojs/cli 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.CN.md CHANGED
@@ -71,19 +71,21 @@ Makoo 默认扫描项目根目录下的 `injections` 目录。
71
71
  └─ manifest.ts
72
72
  ```
73
73
 
74
- 顶层 `injections/manifest.ts` 用来声明全局注入配置和模块列表。模块级 `injections/<module>/manifest.ts` 可以覆盖或补充单个模块的配置,适合让模块自己维护 `injectAt`、`component`、`framework`、`match` 或生命周期 hooks。
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
- globalInjector: {
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
 
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 global injection config 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.
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
- globalInjector: {
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
 
package/dist/bin.js CHANGED
@@ -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
@@ -1293,12 +1304,12 @@ var InjectionModuleSchema = z2.object({
1293
1304
  timeout: z2.number().optional()
1294
1305
  });
1295
1306
  var InjectionManifestSchema = z2.object({
1296
- globalInjector: InjectorConfigSchema.optional(),
1307
+ injectionDefaults: InjectorConfigSchema.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) {
@@ -1404,20 +1415,19 @@ 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
- runtimeDependencies.add(setupFile);
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 resolveInjector = resolveInjectorConfig({
1418
- ...config.injector,
1419
- ...loadedManifest.manifest.globalInjector
1420
- });
1430
+ const resolveInjector = resolveInjectorConfig(loadedManifest.manifest.injectionDefaults);
1421
1431
  const resolveManifest = resolveInjections(loadedManifest.manifest, {
1422
1432
  root: config.root,
1423
1433
  source: config.source,
@@ -1435,7 +1445,7 @@ async function scanner(config) {
1435
1445
  continue;
1436
1446
  }
1437
1447
  for (const dependency of meta.dependencies) {
1438
- manifestDependencies.add(dependency);
1448
+ moduleManifestDependencies.add(dependency);
1439
1449
  }
1440
1450
  const resolveMeta = resolveInjection(meta.moduleConfig, {
1441
1451
  root: config.root,
@@ -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: { ...config, injector: resolveInjector },
1470
+ config,
1471
+ injector: resolveInjector,
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, injectorDefault) {
1484
+ const { alive, scope, timeout, ...rest } = injection;
1485
+ const injectionDefault = { alive, scope, timeout };
1486
+ const injectorOverrides = {
1487
+ ...alive !== injectorDefault.alive ? { alive } : {},
1488
+ ...scope !== injectorDefault.scope ? { scope } : {},
1489
+ ...timeout !== injectorDefault.timeout ? { timeout } : {}
1490
+ };
1491
+ if (Object.keys(injectorOverrides).length === 0) {
1492
+ return {
1493
+ ...rest,
1494
+ injectionDefault
1495
+ };
1496
+ }
1497
+ return {
1498
+ ...rest,
1499
+ injectionDefault,
1500
+ injectorOverrides
1501
+ };
1502
+ }
1503
+ function formatInspectResult(result) {
1504
+ const { config, injector: injectorDefault, injections } = result;
1505
+ const moduleManifestFiles = [
1506
+ ...new Set(
1507
+ injections.map((injection) => injection.overridePath).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
+ injector: injectorDefault,
1530
+ injections: injections.map(
1531
+ (injection) => formatInspectInjection(injection, injectorDefault)
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
- console.log(colorize("Manifest:", ansi.green));
1474
- console.dir(resolveManifest, {
1475
- depth: null,
1476
- colors: true
1477
- });
1478
- console.log(colorize("Vite Makoo Config:", ansi.cyan));
1479
- console.dir(resolveViteMakooConfig, {
1480
- depth: null,
1481
- colors: true
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
+ ["Injector", inspectResult.injector],
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
@@ -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, ResolvedInjectionModule, ResolvedInjectorConfig } from '../config/types';
2
+ import { ScannerResult } from '../scanner/types';
3
+ type InspectInjectorFields = Pick<ResolvedInjectionModule, 'alive' | 'scope' | 'timeout'>;
4
+ type InspectInjection = Omit<ResolvedInjectionModule, keyof InspectInjectorFields> & {
5
+ injectionDefault: InspectInjectorFields;
6
+ injectorOverrides?: Partial<InspectInjectorFields>;
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
+ injector: ScannerResult['injector'];
28
+ injections: InspectInjection[];
29
+ frameworks: ScannerResult['frameworks'];
30
+ };
31
+ export declare function formatInspectInjection(injection: ResolvedInjectionModule, injectorDefault: ResolvedInjectorConfig): InspectInjection;
32
+ export declare function formatInspectResult(result: ScannerResult): InspectResult;
1
33
  export declare function inspectCommand(): Promise<void>;
34
+ export {};
@@ -84,7 +84,7 @@ export type InjectionModuleConfig = ArtifactOptions & {
84
84
  };
85
85
  export type InjectionManifestRecord = Record<string, Omit<InjectionModuleConfig, 'name'>>;
86
86
  export type InjectionManifest = {
87
- globalInjector?: InjectorConfig;
87
+ injectionDefaults?: InjectorConfig;
88
88
  injections: InjectionModuleConfig[] | InjectionManifestRecord;
89
89
  };
90
90
  export type ResolvedInjectionManifest = InjectionModuleConfig[];
@@ -126,7 +126,6 @@ export type CliConfig = {
126
126
  app: AppConfig;
127
127
  monkey?: MonkeyConfig;
128
128
  source?: SourceConfig;
129
- injector?: InjectorConfig;
130
129
  runtime?: RuntimeConfig;
131
130
  };
132
131
  export type ResolvedConfig = {
@@ -134,7 +133,6 @@ export type ResolvedConfig = {
134
133
  app: AppConfig;
135
134
  monkey: ResolvedMonkeyConfig;
136
135
  source: ResolvedSourceConfig;
137
- injector: ResolvedInjectorConfig;
138
136
  runtime: ResolvedRuntimeConfig;
139
137
  };
140
138
  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.$strip>;
13
+ }, z.core.$loose>;
15
14
  export declare function validateCliConfig(data: unknown): asserts data is z.infer<typeof CliConfigSchema>;