piral-cli 1.12.4 → 1.12.5-beta.635b7f6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-cli",
3
- "version": "1.12.4",
3
+ "version": "1.12.5-beta.635b7f6",
4
4
  "description": "The standard CLI for creating and building a Piral instance or a Pilet.",
5
5
  "keywords": [
6
6
  "portal",
@@ -73,7 +73,7 @@
73
73
  },
74
74
  "dependencies": {
75
75
  "css-conflict-inspector": "^0.3",
76
- "dets": "^1",
76
+ "dets": "^1.0.2",
77
77
  "kras": "^1.0.1",
78
78
  "open": "^10",
79
79
  "typescript": "^5"
@@ -14,6 +14,11 @@ export interface ValidatPiletOptions {
14
14
  */
15
15
  logLevel?: LogLevels;
16
16
 
17
+ /**
18
+ * Fails validation if configured validators are missing from the loaded rule set.
19
+ */
20
+ strict?: boolean;
21
+
17
22
  /**
18
23
  * Overrides the Piral instance used as validation blueprint for the pilet.
19
24
  */
@@ -23,6 +28,7 @@ export interface ValidatPiletOptions {
23
28
  export const validatePiletDefaults: ValidatPiletOptions = {
24
29
  entry: './src/index',
25
30
  logLevel: LogLevels.info,
31
+ strict: false,
26
32
  app: undefined,
27
33
  };
28
34
 
@@ -30,6 +36,7 @@ export async function validatePilet(baseDir = process.cwd(), options: ValidatPil
30
36
  const {
31
37
  entry = validatePiletDefaults.entry,
32
38
  logLevel = validatePiletDefaults.logLevel,
39
+ strict = validatePiletDefaults.strict,
33
40
  app = validatePiletDefaults.app,
34
41
  } = options;
35
42
 
@@ -79,7 +86,7 @@ export async function validatePilet(baseDir = process.cwd(), options: ValidatPil
79
86
  piletPackage,
80
87
  };
81
88
 
82
- await runRules(rules, context, validators);
89
+ await runRules(rules, context, validators, strict);
83
90
  }
84
91
 
85
92
  ruleSummary(errors, warnings);
@@ -14,15 +14,25 @@ export interface ValidatPiralOptions {
14
14
  * Sets the log level to use (1-5).
15
15
  */
16
16
  logLevel?: LogLevels;
17
+
18
+ /**
19
+ * Fails validation if configured validators are missing from the loaded rule set.
20
+ */
21
+ strict?: boolean;
17
22
  }
18
23
 
19
24
  export const validatePiralDefaults: ValidatPiralOptions = {
20
25
  entry: './',
21
26
  logLevel: LogLevels.info,
27
+ strict: false,
22
28
  };
23
29
 
24
30
  export async function validatePiral(baseDir = process.cwd(), options: ValidatPiralOptions = {}) {
25
- const { entry = validatePiralDefaults.entry, logLevel = validatePiralDefaults.logLevel } = options;
31
+ const {
32
+ entry = validatePiralDefaults.entry,
33
+ logLevel = validatePiralDefaults.logLevel,
34
+ strict = validatePiralDefaults.strict,
35
+ } = options;
26
36
 
27
37
  ensure('baseDir', baseDir, 'string');
28
38
  ensure('entry', entry, 'string');
@@ -56,7 +66,7 @@ export async function validatePiral(baseDir = process.cwd(), options: ValidatPir
56
66
  info,
57
67
  };
58
68
 
59
- await runRules(rules, context, config.validators);
69
+ await runRules(rules, context, config.validators, strict);
60
70
 
61
71
  ruleSummary(errors, warnings);
62
72
  }
package/src/commands.ts CHANGED
@@ -435,13 +435,17 @@ const allCommands: Array<ToolCommand<any>> = [
435
435
  .number('log-level')
436
436
  .describe('log-level', 'Sets the log level to use (1-5).')
437
437
  .default('log-level', apps.validatePiralDefaults.logLevel)
438
+ .boolean('strict')
439
+ .describe('strict', 'Fails validation if configured validators are missing from the loaded rule set.')
440
+ .default('strict', apps.validatePiralDefaults.strict)
438
441
  .string('base')
439
442
  .default('base', process.cwd())
440
443
  .describe('base', 'Sets the base directory. By default the current directory is used.');
441
444
  },
442
445
  run(args) {
443
446
  return apps.validatePiral(args.base as string, {
444
- entry: args.entry as string,
447
+ entry: args.source as string,
448
+ strict: args.strict as boolean,
445
449
  logLevel: args['log-level'] as LogLevels,
446
450
  });
447
451
  },
@@ -900,6 +904,9 @@ const allCommands: Array<ToolCommand<any>> = [
900
904
  .number('log-level')
901
905
  .describe('log-level', 'Sets the log level to use (1-5).')
902
906
  .default('log-level', apps.validatePiletDefaults.logLevel)
907
+ .boolean('strict')
908
+ .describe('strict', 'Fails validation if configured validators are missing from the loaded rule set.')
909
+ .default('strict', apps.validatePiletDefaults.strict)
903
910
  .string('app')
904
911
  .describe('app', 'Sets the name of the Piral instance.')
905
912
  .string('base')
@@ -908,8 +915,9 @@ const allCommands: Array<ToolCommand<any>> = [
908
915
  },
909
916
  run(args) {
910
917
  return apps.validatePilet(args.base as string, {
911
- entry: args.entry as string,
918
+ entry: args.source as string,
912
919
  logLevel: args['log-level'] as LogLevels,
920
+ strict: args.strict as boolean,
913
921
  app: args.app as string,
914
922
  });
915
923
  },
@@ -27,4 +27,24 @@ describe('Rules Module', () => {
27
27
  await runRules([], {} as any, {}).then((result) => expect(result).toBeUndefined());
28
28
  await runRules([rule], {} as any, { test: {} }).then((result) => expect(result).toBeUndefined());
29
29
  });
30
+
31
+ it('warns about missing configured rules by default', async () => {
32
+ const warning = vitest.fn();
33
+ const error = vitest.fn();
34
+
35
+ await runRules([], { warning, error } as any, { missing: {} });
36
+
37
+ expect(warning).toHaveBeenCalledWith('Configured validator(s) could not be loaded: missing');
38
+ expect(error).not.toHaveBeenCalled();
39
+ });
40
+
41
+ it('errors about missing configured rules in strict mode', async () => {
42
+ const warning = vitest.fn();
43
+ const error = vitest.fn();
44
+
45
+ await runRules([], { warning, error } as any, { missing: {} }, true);
46
+
47
+ expect(error).toHaveBeenCalledWith('Configured validator(s) could not be loaded: missing');
48
+ expect(warning).not.toHaveBeenCalled();
49
+ });
30
50
  });
@@ -15,7 +15,21 @@ export async function runRules<T extends RuleContext>(
15
15
  rules: Array<Rule<T>>,
16
16
  context: T,
17
17
  configurations: Record<string, any> = {},
18
+ strict = false,
18
19
  ) {
20
+ const loadedRules = new Set(rules.map(rule => rule.name));
21
+ const missingRules = Object.keys(configurations).filter(name => !loadedRules.has(name));
22
+
23
+ if (missingRules.length > 0) {
24
+ const message = `Configured validator(s) could not be loaded: ${missingRules.join(', ')}`;
25
+
26
+ if (strict) {
27
+ context.error(message);
28
+ } else {
29
+ context.warning(message);
30
+ }
31
+ }
32
+
19
33
  for (const rule of rules) {
20
34
  log('generalDebug_0003', `Running rule "${rule?.name}" ...`);
21
35
  const options = configurations[rule.name];