@eventcatalog/core 2.8.6 → 2.8.8

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.
@@ -0,0 +1,29 @@
1
+ name: Tests e2e
2
+ on:
3
+ pull_request:
4
+ branches: [ main, master ]
5
+ jobs:
6
+ test:
7
+ timeout-minutes: 60
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/checkout@v4
11
+ - uses: actions/setup-node@v4
12
+ with:
13
+ node-version: lts/*
14
+ - name: Install dependencies
15
+ run: npm ci
16
+ - name: Install Playwright Browsers
17
+ run: npx playwright install --with-deps
18
+ - name: Build catalog
19
+ shell: bash
20
+ run: |
21
+ cp $PROJECT_DIR/eventcatalog.config.js $CATALOG_DIR/eventcatalog.config.js
22
+ cp $PROJECT_DIR/eventcatalog.styles.css $CATALOG_DIR/eventcatalog.styles.css
23
+ npm run build
24
+ env:
25
+ PROJECT_DIR: ./examples/default/
26
+ CATALOG_DIR: ./
27
+ NODE_ENV: CI # Skip analytics
28
+ - name: Run tests
29
+ run: npm run test:e2e
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @eventcatalog/core
2
2
 
3
+ ## 2.8.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 3d3f56e: chore(core): changed the way eventcatalog file is now imported into the project
8
+
9
+ ## 2.8.7
10
+
11
+ ### Patch Changes
12
+
13
+ - ce04693: fix(core): fixed visualization node graph for domains, reduced overlapping
14
+
3
15
  ## 2.8.6
4
16
 
5
17
  ### Patch Changes
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "url": "https://github.com/event-catalog/eventcatalog.git"
7
7
  },
8
8
  "type": "module",
9
- "version": "2.8.6",
9
+ "version": "2.8.8",
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
@@ -20,6 +20,7 @@
20
20
  "prepublishOnly": "npm run build:bin",
21
21
  "test": "vitest --config vitest.config.ts",
22
22
  "test:ci": "node scripts/ci/test.js",
23
+ "test:e2e": "playwright test",
23
24
  "start": "astro dev",
24
25
  "build": "npm run scripts:hydrate-content && node scripts/analytics/log-build.js && astro build",
25
26
  "build:cd": "node scripts/build-ci.js",
@@ -52,6 +53,7 @@
52
53
  "@types/diff": "^5.2.2",
53
54
  "@types/lodash.merge": "4.6.9",
54
55
  "@types/node": "^20.14.2",
56
+ "@types/semver": "^7.5.8",
55
57
  "astro": "^4.16.5",
56
58
  "astro-expressive-code": "^0.36.1",
57
59
  "astro-pagefind": "^1.6.0",
@@ -77,11 +79,11 @@
77
79
  "tailwindcss": "^3.4.3",
78
80
  "typescript": "^5.4.5",
79
81
  "unist-util-visit": "^5.0.0",
80
- "uuid": "^10.0.0",
81
- "@types/semver": "^7.5.8"
82
+ "uuid": "^10.0.0"
82
83
  },
83
84
  "devDependencies": {
84
85
  "@changesets/cli": "^2.27.5",
86
+ "@playwright/test": "^1.48.1",
85
87
  "@types/react": "^18.3.3",
86
88
  "@types/react-dom": "^18.3.0",
87
89
  "prettier": "^3.3.3",
@@ -1,38 +1,13 @@
1
1
  import { readFile, writeFile, rm } from 'node:fs/promises';
2
- import { existsSync } from 'fs';
2
+ import { existsSync } from 'node:fs';
3
+ import { copyFile } from 'node:fs/promises';
3
4
  import path from 'node:path';
4
5
  import { v4 as uuidV4 } from 'uuid';
5
6
  import { pathToFileURL } from 'url';
7
+ import { tmpdir } from 'node:os';
6
8
 
7
- // * Very strange behavior when importing ESM files from catalogs into core.
8
- // * Core (node) does not know how to handle ESM files, so we have to try and convert them.
9
- // *
10
- // * This needs sorting out! Sorry if you are reading this, but it unblocked me for now!
11
- // * @param {*} content
12
- // * @returns
13
- // */
14
- function convertESMtoCJS(content) {
15
- // Replace import statements with require
16
- content = content.replace(/import\s+([a-zA-Z0-9{},\s*]+)\s+from\s+['"]([^'"]+)['"];/g, (match, imports, modulePath) => {
17
- return `const ${imports.trim()} = require('${modulePath}');`;
18
- });
19
-
20
- // Replace export default with module.exports
21
- content = content.replace(/export\s+default\s+/g, 'module.exports = ');
22
-
23
- // Replace named exports with module.exports
24
- content = content.replace(/export\s+{([^}]+)}/g, (match, exports) => {
25
- return `module.exports = {${exports.trim()}};`;
26
- });
27
-
28
- // Remove declarations of __filename and __dirname
29
- content = content.replace(/^\s*(const|let|var)\s+__(filename|dirname)\s+=\s+.*;?\s*$/gm, '');
30
-
31
- return content;
32
- }
33
-
34
- export async function cleanup(projectDirectory) {
35
- const filePath = path.join(projectDirectory, 'eventcatalog.config.cjs');
9
+ export async function cleanup() {
10
+ const filePath = path.join(tmpdir(), 'eventcatalog.config.mjs');
36
11
  if (existsSync(filePath)) {
37
12
  await rm(filePath);
38
13
  }
@@ -40,25 +15,20 @@ export async function cleanup(projectDirectory) {
40
15
 
41
16
  export const getEventCatalogConfigFile = async (projectDirectory) => {
42
17
  try {
43
- const rawFile = await readFile(path.join(projectDirectory, 'eventcatalog.config.js'), 'utf8');
44
-
45
- // Have to conver the ESM to CJS...
46
- const configAsCommonJS = convertESMtoCJS(rawFile);
18
+ let configFilePath = path.join(projectDirectory, 'eventcatalog.config.js');
47
19
 
48
- await writeFile(path.join(projectDirectory, 'eventcatalog.config.cjs'), configAsCommonJS);
20
+ const packageJson = await import(/* @vite-ignore */ path.join(projectDirectory, 'package.json'));
21
+ if (packageJson.default?.type !== 'module') {
22
+ await copyFile(configFilePath, path.join(tmpdir(), 'eventcatalog.config.mjs'));
23
+ configFilePath = path.join(tmpdir(), 'eventcatalog.config.mjs');
24
+ }
49
25
 
50
- const configFilePath = path.join(projectDirectory, 'eventcatalog.config.cjs');
51
26
  const configFileURL = pathToFileURL(configFilePath).href;
52
- const configAsCJS = await import(/* @vite-ignore */ configFileURL);
53
-
54
- // Clean up?
55
- await writeFile(path.join(projectDirectory, 'eventcatalog.config.js'), rawFile);
56
-
57
- await cleanup(projectDirectory);
27
+ const config = await import(/* @vite-ignore */ configFileURL);
58
28
 
59
- return configAsCJS.default;
60
- } catch (error) {
61
- await cleanup(projectDirectory);
29
+ return config.default;
30
+ } finally {
31
+ await cleanup();
62
32
  }
63
33
  };
64
34
 
@@ -92,10 +62,8 @@ export const writeEventCatalogConfigFile = async (projectDirectory, newConfig) =
92
62
 
93
63
  // Write the updated content back to the file
94
64
  await writeFile(configFilePath, content);
95
-
96
- await cleanup(projectDirectory);
97
- } catch (error) {
98
- await cleanup(projectDirectory);
65
+ } finally {
66
+ await cleanup();
99
67
  }
100
68
  };
101
69
 
@@ -1,19 +1,11 @@
1
1
  import { getCollection } from 'astro:content';
2
- import dagre from 'dagre';
2
+ import { createDagreGraph, calculatedNodes } from '@utils/node-graph-utils/utils';
3
3
  import { getNodesAndEdges as getServicesNodeAndEdges } from '../services/node-graph';
4
4
  import merge from 'lodash.merge';
5
5
  import { getItemsFromCollectionByIdAndSemverOrLatest } from '@utils/collections/util';
6
6
 
7
7
  type DagreGraph = any;
8
8
 
9
- // Creates a new dagre graph
10
- export const getDagreGraph = () => {
11
- const graph = new dagre.graphlib.Graph({ compound: true });
12
- graph.setGraph({ rankdir: 'LR', ranksep: 200, nodesep: 100 });
13
- graph.setDefaultEdgeLabel(() => ({}));
14
- return graph;
15
- };
16
-
17
9
  interface Props {
18
10
  id: string;
19
11
  version: string;
@@ -22,7 +14,7 @@ interface Props {
22
14
  }
23
15
 
24
16
  export const getNodesAndEdges = async ({ id, version, defaultFlow, mode = 'simple' }: Props) => {
25
- const flow = defaultFlow || getDagreGraph();
17
+ const flow = defaultFlow || createDagreGraph({ ranksep: 360, nodesep: 50, edgesep: 50 });
26
18
  let nodes = new Map(),
27
19
  edges = new Map();
28
20
 
@@ -73,7 +65,7 @@ export const getNodesAndEdges = async ({ id, version, defaultFlow, mode = 'simpl
73
65
  }
74
66
 
75
67
  return {
76
- nodes: [...nodes.values()],
68
+ nodes: calculatedNodes(flow, Array.from(nodes.values())),
77
69
  edges: [...edges.values()],
78
70
  };
79
71
  };
@@ -2,8 +2,6 @@ import type { CollectionEntry } from 'astro:content';
2
2
  import type { Node } from 'reactflow';
3
3
  import dagre from 'dagre';
4
4
 
5
- type DagreGraph = any;
6
-
7
5
  export const generateIdForNode = (node: CollectionEntry<'events' | 'services' | 'commands'>) => {
8
6
  return `${node.data.id}-${node.data.version}`;
9
7
  };
@@ -23,9 +21,9 @@ export const calculatedNodes = (flow: dagre.graphlib.Graph, nodes: Node[]) => {
23
21
  };
24
22
 
25
23
  // Creates a new dagre graph
26
- export const createDagreGraph = ({ ranksep = 180, nodesep = 50 }: any) => {
24
+ export const createDagreGraph = ({ ranksep = 180, nodesep = 50, ...rest }: any) => {
27
25
  const graph = new dagre.graphlib.Graph({ compound: true });
28
- graph.setGraph({ rankdir: 'LR', ranksep, nodesep });
26
+ graph.setGraph({ rankdir: 'LR', ranksep, nodesep, ...rest });
29
27
  graph.setDefaultEdgeLabel(() => ({}));
30
28
  return graph;
31
29
  };