@bleedingdev/modern-js-code-tools 3.9.0-ultramodern.23 → 3.9.0-ultramodern.24

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.
@@ -49,9 +49,13 @@ var traverse_default = /*#__PURE__*/ __webpack_require__.n(traverse_namespaceObj
49
49
  const types_namespaceObject = require("@babel/types");
50
50
  const consumerParserPlugins = (filePath)=>/\.[jt]sx$/u.test(filePath) ? [
51
51
  "typescript",
52
+ 'decorators',
53
+ 'decoratorAutoAccessors',
52
54
  'jsx'
53
55
  ] : [
54
- "typescript"
56
+ "typescript",
57
+ 'decorators',
58
+ 'decoratorAutoAccessors'
55
59
  ];
56
60
  class SourceSyntaxError extends Error {
57
61
  }
@@ -84,7 +88,7 @@ function traverseSource(file, visitor) {
84
88
  traverse_default()(file, visitor, program.scope, void 0, program);
85
89
  }
86
90
  function unwrapExpression(node, includeAssertions = false) {
87
- while(types_namespaceObject.isTSAsExpression(node) || types_namespaceObject.isParenthesizedExpression(node) || types_namespaceObject.isTSSatisfiesExpression(node) || includeAssertions && (types_namespaceObject.isTSTypeAssertion(node) || types_namespaceObject.isTSNonNullExpression(node)))node = node.expression;
91
+ while(types_namespaceObject.isTSAsExpression(node) || types_namespaceObject.isParenthesizedExpression(node) || types_namespaceObject.isTSSatisfiesExpression(node) || includeAssertions && (types_namespaceObject.isTSTypeAssertion(node) || types_namespaceObject.isTSNonNullExpression(node) || types_namespaceObject.isTSInstantiationExpression(node)))node = node.expression;
88
92
  return node;
89
93
  }
90
94
  exports.SourceSyntaxError = __webpack_exports__.SourceSyntaxError;
@@ -6,9 +6,9 @@ const flags = [
6
6
  '--baseline-package-directory',
7
7
  '--rules'
8
8
  ];
9
- async function loadContractRules(file) {
9
+ async function loadSourceRules(file) {
10
10
  const rules = (await import(pathToFileURL(node_path.resolve(file)).href)).default;
11
- if (!Array.isArray(rules) || !rules.every((rule)=>'function' == typeof rule)) throw new Error(`${file}: default export must be an array of contract rule functions, e.g. \`export default [myRule]\``);
11
+ if (!Array.isArray(rules) || !rules.every((rule)=>'function' == typeof rule)) throw new Error(`${file}: default export must be an array of source rule functions, e.g. \`export default [myRule]\``);
12
12
  return rules;
13
13
  }
14
14
  async function runMicroVerticalApiCheckCli(args = process.argv.slice(2), filesOnly = false) {
@@ -18,7 +18,7 @@ async function runMicroVerticalApiCheckCli(args = process.argv.slice(2), filesOn
18
18
  for(let index = 0; index < args.length; index += 1){
19
19
  const argument = args[index];
20
20
  if ('--help' === argument || '-h' === argument) {
21
- console.log(`${filesOnly ? 'modern-api-check-files' : 'modern-api-check'} [--workspace-root <path>] [--baseline-package-directory <path>] [--rules <module>]...\n${filesOnly ? 'Checks consumer files, contracts, package exports and owner identity. Does not analyze runtime topology; run the strict Effect source phase separately.' : 'Checks consumer files, contracts, package exports, owner identity and runtime topology once per API entry.'}\n--rules loads a module whose default export is an array of contract rules; each rule receives the module graph of every API contract.\nWorkspace defaults to ULTRAMODERN_WORKSPACE_ROOT then cwd. Exit codes: 0 valid, 1 consumer violation, 2 tool/configuration failure.`);
21
+ console.log(`${filesOnly ? 'modern-api-check-files' : 'modern-api-check'} [--workspace-root <path>] [--baseline-package-directory <path>] [--rules <module>]...\n${filesOnly ? 'Checks consumer files, contracts, package exports and owner identity. Does not analyze runtime topology; run the strict Effect source phase separately.' : 'Checks consumer files, contracts, package exports, owner identity and runtime topology once per API entry.'}\n--rules loads a module whose default export is an array of source rules; each rule runs once per workspace source file with the shared module graph.\nWorkspace defaults to ULTRAMODERN_WORKSPACE_ROOT then cwd. Exit codes: 0 valid, 1 consumer violation, 2 tool/configuration failure.`);
22
22
  return 0;
23
23
  }
24
24
  if (!flags.includes(argument ?? '') || !args[index + 1] || args[index + 1]?.startsWith('--')) {
@@ -30,9 +30,9 @@ async function runMicroVerticalApiCheckCli(args = process.argv.slice(2), filesOn
30
30
  else if ('--rules' === argument) ruleFiles.push(value);
31
31
  else baselinePackageDirectory = value;
32
32
  }
33
- const contractRules = [];
33
+ const sourceRules = [];
34
34
  for (const file of ruleFiles)try {
35
- contractRules.push(...await loadContractRules(file));
35
+ sourceRules.push(...await loadSourceRules(file));
36
36
  } catch (error) {
37
37
  console.error(`API tool error: --rules ${error instanceof Error ? error.message : String(error)}`);
38
38
  return 2;
@@ -40,7 +40,7 @@ async function runMicroVerticalApiCheckCli(args = process.argv.slice(2), filesOn
40
40
  const result = (filesOnly ? checkMicroVerticalApiConsumerFiles : checkMicroVerticalApiBoundaries)({
41
41
  workspaceRoot,
42
42
  baselinePackageDirectory,
43
- contractRules
43
+ sourceRules
44
44
  });
45
45
  for (const diagnostic of result.diagnostics)console.error(`API violation: ${diagnostic}`);
46
46
  for (const error of result.toolErrors)console.error(`API tool error: ${error}`);
@@ -453,7 +453,13 @@ const configuredMicroVerticalApiStem = (verticalPath, verticals)=>{
453
453
  };
454
454
  const microVerticalApiBaselineViolation = (stem, filePath, expectation)=>{
455
455
  try {
456
- const graph = createModuleGraph(filePath);
456
+ const modules = createModuleGraph();
457
+ const graph = {
458
+ ...modules,
459
+ root: modules.module(filePath)
460
+ };
461
+ const [mutation] = graph.root.mutations;
462
+ if (mutation) return `MicroVertical root contract must be valid TypeScript syntax (contract bindings must be immutable at ${mutation.start})`;
457
463
  if (!baselinePublicIdentityIsExact(filePath, expectation)) return 'MicroVertical baseline imports must resolve the exact framework owner public export and schema identity';
458
464
  return validateParsedContract(graph, stem, expectation);
459
465
  } catch (error) {
@@ -408,27 +408,6 @@ function check(options, topology) {
408
408
  const violation = microVerticalApiBaselineViolation(stem, absolute(contract), expectation);
409
409
  if (violation) diagnostics.push(`${contract}: ${violation}`);
410
410
  }
411
- if (options.contractRules?.length && exists(contract)) {
412
- let graph;
413
- try {
414
- graph = createModuleGraph(absolute(contract));
415
- } catch (error) {
416
- if (!(error instanceof SourceSyntaxError)) throw error;
417
- diagnostics.push(`${contract}: contract rules need a parseable contract with immutable bindings (${error.message})`);
418
- }
419
- if (graph) {
420
- const context = {
421
- appPath,
422
- protocol: rpc ? 'rpc' : 'rest',
423
- graph
424
- };
425
- for (const rule of options.contractRules)guarded(`${contract} (rule ${rule.name || 'anonymous'})`, ()=>{
426
- const messages = rule(context);
427
- if (!Array.isArray(messages) || !messages.every((message)=>'string' == typeof message)) throw new Error('contract rule must return an array of violation messages (return [] when the contract passes)');
428
- for (const message of messages)diagnostics.push(`${contract}: ${message}`);
429
- });
430
- }
431
- }
432
411
  if (client) {
433
412
  const relativeContract = node_path.posix.relative(node_path.posix.dirname(client), contract);
434
413
  moduleShape(client, [
@@ -488,6 +467,27 @@ function check(options, topology) {
488
467
  ]
489
468
  ]);
490
469
  });
470
+ const sourceRules = options.sourceRules ?? [];
471
+ const graph = createModuleGraph();
472
+ for (const file of sourceRules.length ? sourceFiles : [])if (/\.[cm]?[jt]sx?$/u.test(file)) guarded(file, ()=>{
473
+ let module;
474
+ try {
475
+ module = graph.module(absolute(file));
476
+ } catch (error) {
477
+ if (!(error instanceof SourceSyntaxError)) throw error;
478
+ diagnostics.push(`${file}: source rules need parseable source (${error.message})`);
479
+ return;
480
+ }
481
+ for (const rule of sourceRules){
482
+ const messages = rule({
483
+ file,
484
+ module,
485
+ graph
486
+ });
487
+ if (!Array.isArray(messages) || !messages.every((message)=>'string' == typeof message)) throw new Error(`rule ${rule.name || 'anonymous'} must return an array of violation messages (return [] when the file passes)`);
488
+ for (const message of messages)diagnostics.push(`${file}: ${message}`);
489
+ }
490
+ });
491
491
  const shell = 'apps/shell-super-app';
492
492
  const verticals = apps.filter((app)=>app.path.startsWith('verticals/') && apiApp(app));
493
493
  if (exists(shell) && verticals.length) {