@yumerijs/core 3.0.5 → 3.0.7

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/core.d.ts CHANGED
@@ -15,6 +15,7 @@ export interface Plugin {
15
15
  apply?: (ctx: Context, config: Config) => Promise<void> | void;
16
16
  disable?: (ctx: Context) => Promise<void> | void;
17
17
  depend?: Array<string>;
18
+ optional?: Array<string>;
18
19
  provide?: Array<string>;
19
20
  render?: string;
20
21
  config?: Schema<any>;
@@ -25,6 +26,7 @@ type PluginModuleLike = Plugin | PluginConstructor | ((ctx: Context, config: Con
25
26
  apply?: ((ctx: Context, config: Config) => Promise<void> | void);
26
27
  disable?: (ctx: Context) => Promise<void> | void;
27
28
  depend?: Array<string>;
29
+ optional?: Array<string>;
28
30
  provide?: Array<string>;
29
31
  render?: string;
30
32
  config?: Schema<any>;
package/dist/core.js CHANGED
@@ -20,6 +20,8 @@ function mergePluginMeta(target, source) {
20
20
  return target;
21
21
  if (target.depend == null && Array.isArray(source.depend))
22
22
  target.depend = source.depend;
23
+ if (target.optional == null && Array.isArray(source.optional))
24
+ target.optional = source.optional;
23
25
  if (target.provide == null && Array.isArray(source.provide))
24
26
  target.provide = source.provide;
25
27
  if (target.render == null && typeof source.render === 'string')
@@ -175,9 +177,9 @@ export class Core {
175
177
  const plugin = resolvePluginModule(module, context, config);
176
178
  const shortName = this.getShortPluginName(context.pluginname);
177
179
  context.module = plugin;
178
- // 自动依赖注入
179
- const depend = plugin.depend || [];
180
- for (const name of depend) {
180
+ // 自动依赖注入:必需依赖始终由 loader 保证,optional 仅在已提供时注入。
181
+ const dependencies = [...(plugin.depend || []), ...(plugin.optional || [])];
182
+ for (const name of dependencies) {
181
183
  const component = this.getComponent(name);
182
184
  if (component) {
183
185
  context.inject(name, component);
package/dist/logger.d.ts CHANGED
@@ -25,5 +25,12 @@ export declare class Logger {
25
25
  info(...args: any[]): void;
26
26
  warn(...args: any[]): void;
27
27
  error(...args: any[]): void;
28
+ /**
29
+ * Display an interactive prompt and resolve with the entered text.
30
+ * The answer is deliberately not added to the log stream because it may be sensitive.
31
+ */
32
+ input(question: string): Promise<string>;
33
+ /** Alias for input(), for callers that prefer prompt terminology. */
34
+ prompt(question: string): Promise<string>;
28
35
  }
29
36
  export {};
package/dist/logger.js CHANGED
@@ -4,6 +4,8 @@
4
4
  * WindyPear-Team All right reserved
5
5
  **/
6
6
  import * as pcc from 'picocolors';
7
+ import { createInterface } from 'readline/promises';
8
+ import { stdin, stdout } from 'process';
7
9
  const { createColors } = pcc;
8
10
  const pc = createColors();
9
11
  export class Logger {
@@ -70,4 +72,26 @@ export class Logger {
70
72
  error(...args) {
71
73
  this.log('E', ...args);
72
74
  }
75
+ /**
76
+ * Display an interactive prompt and resolve with the entered text.
77
+ * The answer is deliberately not added to the log stream because it may be sensitive.
78
+ */
79
+ async input(question) {
80
+ if (!stdin.isTTY || !stdout.isTTY) {
81
+ throw new Error('Logger input requires an interactive terminal.');
82
+ }
83
+ const readline = createInterface({ input: stdin, output: stdout });
84
+ const timestamp = this.getTimestamp();
85
+ const prefix = `${pc.gray(timestamp)} [${pc.cyan('I')}] ${this.titleColor(this.title)} `;
86
+ try {
87
+ return await readline.question(`${prefix}${question}`);
88
+ }
89
+ finally {
90
+ readline.close();
91
+ }
92
+ }
93
+ /** Alias for input(), for callers that prefer prompt terminology. */
94
+ async prompt(question) {
95
+ return await this.input(question);
96
+ }
73
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yumerijs/core",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "description": "Core module for yumeri",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",