@eventcatalog/core 5.0.0-beta.26 → 5.0.0-beta.27
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/analytics/analytics.cjs +1 -1
- package/dist/analytics/analytics.js +2 -2
- package/dist/analytics/log-build.cjs +35 -42
- package/dist/analytics/log-build.js +4 -4
- package/dist/{chunk-RFIXKATC.js → chunk-4G7FSRPN.js} +35 -42
- package/dist/{chunk-TMCBFXNE.js → chunk-EFBDR7JJ.js} +1 -1
- package/dist/{chunk-O2ZA26FX.js → chunk-I6CBMGUM.js} +4 -2
- package/dist/{chunk-LBHPRPYB.js → chunk-ILPH363P.js} +1 -1
- package/dist/{chunk-MDWB5HLO.js → chunk-NKNOXQ62.js} +1 -1
- package/dist/{chunk-W4RMG6EP.js → chunk-P5IFIKG6.js} +2 -2
- package/dist/{chunk-36RYTYT5.js → chunk-PD7KTSYN.js} +1 -1
- package/dist/{chunk-KHACCTW2.js → chunk-QJ7KKN2D.js} +1 -1
- package/dist/{chunk-M4TIQ4Z6.js → chunk-YGUOLT7F.js} +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/constants.js +1 -1
- package/dist/eventcatalog-config-file-utils.cjs +34 -41
- package/dist/eventcatalog-config-file-utils.d.cts +56 -58
- package/dist/eventcatalog-config-file-utils.d.ts +56 -58
- package/dist/eventcatalog-config-file-utils.js +1 -1
- package/dist/eventcatalog.cjs +49 -54
- package/dist/eventcatalog.js +10 -10
- package/dist/features.cjs +34 -41
- package/dist/features.js +2 -2
- package/dist/federation/federate.cjs +37 -44
- package/dist/federation/federate.js +2 -2
- package/dist/generate.cjs +37 -42
- package/dist/generate.js +4 -4
- package/dist/resolve-catalog-dependencies.cjs +34 -41
- package/dist/resolve-catalog-dependencies.js +2 -2
- package/dist/utils/cli-logger.cjs +1 -1
- package/dist/utils/cli-logger.js +2 -2
- package/eventcatalog/integrations/config-loader.mjs +56 -58
- package/package.json +3 -3
|
@@ -45,65 +45,58 @@ var import_promises = require("fs/promises");
|
|
|
45
45
|
var import_node_fs = require("fs");
|
|
46
46
|
var import_node_path = __toESM(require("path"), 1);
|
|
47
47
|
var import_node_url = require("url");
|
|
48
|
-
var
|
|
48
|
+
var import_node_module = require("module");
|
|
49
49
|
async function cleanup(projectDirectory) {
|
|
50
50
|
const filePath = import_node_path.default.join(projectDirectory, "eventcatalog.config.mjs");
|
|
51
51
|
if ((0, import_node_fs.existsSync)(filePath)) {
|
|
52
52
|
await (0, import_promises.rm)(filePath);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
55
|
+
var hidesConfigModuleTypeWarning = false;
|
|
56
|
+
var loads = 0;
|
|
57
|
+
var hideConfigModuleTypeWarning = () => {
|
|
58
|
+
if (hidesConfigModuleTypeWarning) return;
|
|
59
|
+
hidesConfigModuleTypeWarning = true;
|
|
60
|
+
const emitWarning = process.emitWarning;
|
|
61
|
+
process.emitWarning = function(warning, ...args) {
|
|
62
|
+
const code = typeof args[0] === "object" ? args[0]?.code : args[1];
|
|
63
|
+
const message = typeof warning === "string" ? warning : warning?.message;
|
|
64
|
+
if (code === "MODULE_TYPELESS_PACKAGE_JSON" && message?.includes("eventcatalog.config.js")) return;
|
|
65
|
+
return emitWarning.call(this, warning, ...args);
|
|
66
|
+
};
|
|
68
67
|
};
|
|
69
|
-
var
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
var AS_MODULE_QUERY = "eventcatalog-config-as-module";
|
|
69
|
+
var loadsMarkedConfigsAsModules = false;
|
|
70
|
+
var loadMarkedConfigsAsModules = () => {
|
|
71
|
+
if (loadsMarkedConfigsAsModules) return;
|
|
72
|
+
loadsMarkedConfigsAsModules = true;
|
|
73
|
+
const hook = `export async function load(url, context, nextLoad) {
|
|
74
|
+
return nextLoad(url, url.includes('${AS_MODULE_QUERY}=') ? { ...context, format: 'module' } : context);
|
|
75
|
+
}`;
|
|
76
|
+
(0, import_node_module.register)(`data:text/javascript,${encodeURIComponent(hook)}`);
|
|
75
77
|
};
|
|
76
|
-
var
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return
|
|
78
|
+
var isCommonJSPackage = async (projectDirectory) => {
|
|
79
|
+
try {
|
|
80
|
+
const packageJson = JSON.parse(await (0, import_promises.readFile)(import_node_path.default.join(projectDirectory, "package.json"), "utf-8"));
|
|
81
|
+
return packageJson?.type === "commonjs";
|
|
82
|
+
} catch {
|
|
83
|
+
return false;
|
|
80
84
|
}
|
|
81
|
-
const tempDir = await (0, import_promises.mkdtemp)(import_node_path.default.join((0, import_node_os.tmpdir)(), "eventcatalog-config-"));
|
|
82
|
-
await linkNodeModulesIntoTempDirectory({ projectDirectory, tempDir });
|
|
83
|
-
return tempDir;
|
|
84
85
|
};
|
|
85
86
|
var getEventCatalogConfigFile = async (projectDirectory) => {
|
|
86
|
-
let tempDir;
|
|
87
87
|
try {
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
configFilePath = import_node_path.default.join(tempDir, "eventcatalog.config.mjs");
|
|
94
|
-
await (0, import_promises.copyFile)(import_node_path.default.join(projectDirectory, "eventcatalog.config.js"), configFilePath);
|
|
95
|
-
}
|
|
96
|
-
const configFileURL = `${(0, import_node_url.pathToFileURL)(configFilePath).href}?t=${Date.now()}`;
|
|
88
|
+
hideConfigModuleTypeWarning();
|
|
89
|
+
const asModule = await isCommonJSPackage(projectDirectory);
|
|
90
|
+
if (asModule) loadMarkedConfigsAsModules();
|
|
91
|
+
const configFileURL = (0, import_node_url.pathToFileURL)(import_node_path.default.join(projectDirectory, "eventcatalog.config.js")).href;
|
|
92
|
+
const query = `${asModule ? AS_MODULE_QUERY : "loaded"}=${Date.now()}-${loads++}`;
|
|
97
93
|
const config = await import(
|
|
98
94
|
/* @vite-ignore */
|
|
99
|
-
configFileURL
|
|
95
|
+
`${configFileURL}?${query}`
|
|
100
96
|
);
|
|
101
97
|
return config.default;
|
|
102
98
|
} finally {
|
|
103
99
|
await cleanup(projectDirectory);
|
|
104
|
-
if (tempDir) {
|
|
105
|
-
await (0, import_promises.rm)(tempDir, { recursive: true, force: true });
|
|
106
|
-
}
|
|
107
100
|
}
|
|
108
101
|
};
|
|
109
102
|
|
|
@@ -176,7 +169,7 @@ var verifyRequiredFieldsAreInCatalogConfigFile = async (projectDirectory) => {
|
|
|
176
169
|
var import_os = __toESM(require("os"), 1);
|
|
177
170
|
|
|
178
171
|
// package.json
|
|
179
|
-
var version = "5.0.0-beta.
|
|
172
|
+
var version = "5.0.0-beta.27";
|
|
180
173
|
|
|
181
174
|
// src/constants.ts
|
|
182
175
|
var VERSION = version;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
log_build_default
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-P5IFIKG6.js";
|
|
4
4
|
import "../chunk-AWOO63ME.js";
|
|
5
5
|
import "../chunk-ZAZHAVKB.js";
|
|
6
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-EFBDR7JJ.js";
|
|
7
7
|
import "../chunk-CPW6G62V.js";
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
8
|
+
import "../chunk-YGUOLT7F.js";
|
|
9
|
+
import "../chunk-4G7FSRPN.js";
|
|
10
10
|
export {
|
|
11
11
|
log_build_default as default
|
|
12
12
|
};
|
|
@@ -5,69 +5,62 @@ import { v4 as uuidV4 } from "uuid";
|
|
|
5
5
|
import matter from "gray-matter";
|
|
6
6
|
|
|
7
7
|
// eventcatalog/integrations/config-loader.mjs
|
|
8
|
-
import { readFile, rm
|
|
8
|
+
import { readFile, rm } from "fs/promises";
|
|
9
9
|
import { existsSync } from "fs";
|
|
10
10
|
import path from "path";
|
|
11
11
|
import { pathToFileURL } from "url";
|
|
12
|
-
import {
|
|
12
|
+
import { register } from "module";
|
|
13
13
|
async function cleanup(projectDirectory) {
|
|
14
14
|
const filePath = path.join(projectDirectory, "eventcatalog.config.mjs");
|
|
15
15
|
if (existsSync(filePath)) {
|
|
16
16
|
await rm(filePath);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
19
|
+
var hidesConfigModuleTypeWarning = false;
|
|
20
|
+
var loads = 0;
|
|
21
|
+
var hideConfigModuleTypeWarning = () => {
|
|
22
|
+
if (hidesConfigModuleTypeWarning) return;
|
|
23
|
+
hidesConfigModuleTypeWarning = true;
|
|
24
|
+
const emitWarning = process.emitWarning;
|
|
25
|
+
process.emitWarning = function(warning, ...args) {
|
|
26
|
+
const code = typeof args[0] === "object" ? args[0]?.code : args[1];
|
|
27
|
+
const message = typeof warning === "string" ? warning : warning?.message;
|
|
28
|
+
if (code === "MODULE_TYPELESS_PACKAGE_JSON" && message?.includes("eventcatalog.config.js")) return;
|
|
29
|
+
return emitWarning.call(this, warning, ...args);
|
|
30
|
+
};
|
|
32
31
|
};
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
var AS_MODULE_QUERY = "eventcatalog-config-as-module";
|
|
33
|
+
var loadsMarkedConfigsAsModules = false;
|
|
34
|
+
var loadMarkedConfigsAsModules = () => {
|
|
35
|
+
if (loadsMarkedConfigsAsModules) return;
|
|
36
|
+
loadsMarkedConfigsAsModules = true;
|
|
37
|
+
const hook = `export async function load(url, context, nextLoad) {
|
|
38
|
+
return nextLoad(url, url.includes('${AS_MODULE_QUERY}=') ? { ...context, format: 'module' } : context);
|
|
39
|
+
}`;
|
|
40
|
+
register(`data:text/javascript,${encodeURIComponent(hook)}`);
|
|
39
41
|
};
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return
|
|
42
|
+
var isCommonJSPackage = async (projectDirectory) => {
|
|
43
|
+
try {
|
|
44
|
+
const packageJson = JSON.parse(await readFile(path.join(projectDirectory, "package.json"), "utf-8"));
|
|
45
|
+
return packageJson?.type === "commonjs";
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
44
48
|
}
|
|
45
|
-
const tempDir = await mkdtemp(path.join(tmpdir(), "eventcatalog-config-"));
|
|
46
|
-
await linkNodeModulesIntoTempDirectory({ projectDirectory, tempDir });
|
|
47
|
-
return tempDir;
|
|
48
49
|
};
|
|
49
50
|
var getEventCatalogConfigFile = async (projectDirectory) => {
|
|
50
|
-
let tempDir;
|
|
51
51
|
try {
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
configFilePath = path.join(tempDir, "eventcatalog.config.mjs");
|
|
58
|
-
await copyFile(path.join(projectDirectory, "eventcatalog.config.js"), configFilePath);
|
|
59
|
-
}
|
|
60
|
-
const configFileURL = `${pathToFileURL(configFilePath).href}?t=${Date.now()}`;
|
|
52
|
+
hideConfigModuleTypeWarning();
|
|
53
|
+
const asModule = await isCommonJSPackage(projectDirectory);
|
|
54
|
+
if (asModule) loadMarkedConfigsAsModules();
|
|
55
|
+
const configFileURL = pathToFileURL(path.join(projectDirectory, "eventcatalog.config.js")).href;
|
|
56
|
+
const query = `${asModule ? AS_MODULE_QUERY : "loaded"}=${Date.now()}-${loads++}`;
|
|
61
57
|
const config = await import(
|
|
62
58
|
/* @vite-ignore */
|
|
63
|
-
configFileURL
|
|
59
|
+
`${configFileURL}?${query}`
|
|
64
60
|
);
|
|
65
61
|
return config.default;
|
|
66
62
|
} finally {
|
|
67
63
|
await cleanup(projectDirectory);
|
|
68
|
-
if (tempDir) {
|
|
69
|
-
await rm(tempDir, { recursive: true, force: true });
|
|
70
|
-
}
|
|
71
64
|
}
|
|
72
65
|
};
|
|
73
66
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
logger
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ILPH363P.js";
|
|
4
4
|
import {
|
|
5
5
|
cleanup,
|
|
6
6
|
getEventCatalogConfigFile
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-4G7FSRPN.js";
|
|
8
8
|
|
|
9
9
|
// src/generate.js
|
|
10
10
|
import path from "path";
|
|
@@ -54,10 +54,12 @@ var generate = async (PROJECT_DIRECTORY) => {
|
|
|
54
54
|
for (const { plugin } of errors) {
|
|
55
55
|
logger.error(` - ${plugin}`, "generator");
|
|
56
56
|
}
|
|
57
|
+
process.exitCode = 1;
|
|
57
58
|
}
|
|
58
59
|
} catch (error) {
|
|
59
60
|
console.error(error);
|
|
60
61
|
await cleanup(PROJECT_DIRECTORY);
|
|
62
|
+
process.exitCode = 1;
|
|
61
63
|
}
|
|
62
64
|
};
|
|
63
65
|
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "./chunk-ZAZHAVKB.js";
|
|
9
9
|
import {
|
|
10
10
|
raiseEvent
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-EFBDR7JJ.js";
|
|
12
12
|
import {
|
|
13
13
|
TELEMETRY_REQUEST_TIMEOUT_MS,
|
|
14
14
|
isTelemetryDisabled
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
import {
|
|
17
17
|
getEventCatalogConfigFile,
|
|
18
18
|
verifyRequiredFieldsAreInCatalogConfigFile
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-4G7FSRPN.js";
|
|
20
20
|
|
|
21
21
|
// src/analytics/log-build.js
|
|
22
22
|
var isMCPEnabled = (configFile) => configFile.output === "server" && (configFile.mcp?.enabled ?? true);
|
package/dist/constants.cjs
CHANGED
package/dist/constants.js
CHANGED
|
@@ -48,65 +48,58 @@ var import_promises = require("fs/promises");
|
|
|
48
48
|
var import_node_fs = require("fs");
|
|
49
49
|
var import_node_path = __toESM(require("path"), 1);
|
|
50
50
|
var import_node_url = require("url");
|
|
51
|
-
var
|
|
51
|
+
var import_node_module = require("module");
|
|
52
52
|
async function cleanup(projectDirectory) {
|
|
53
53
|
const filePath = import_node_path.default.join(projectDirectory, "eventcatalog.config.mjs");
|
|
54
54
|
if ((0, import_node_fs.existsSync)(filePath)) {
|
|
55
55
|
await (0, import_promises.rm)(filePath);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
58
|
+
var hidesConfigModuleTypeWarning = false;
|
|
59
|
+
var loads = 0;
|
|
60
|
+
var hideConfigModuleTypeWarning = () => {
|
|
61
|
+
if (hidesConfigModuleTypeWarning) return;
|
|
62
|
+
hidesConfigModuleTypeWarning = true;
|
|
63
|
+
const emitWarning = process.emitWarning;
|
|
64
|
+
process.emitWarning = function(warning, ...args) {
|
|
65
|
+
const code = typeof args[0] === "object" ? args[0]?.code : args[1];
|
|
66
|
+
const message = typeof warning === "string" ? warning : warning?.message;
|
|
67
|
+
if (code === "MODULE_TYPELESS_PACKAGE_JSON" && message?.includes("eventcatalog.config.js")) return;
|
|
68
|
+
return emitWarning.call(this, warning, ...args);
|
|
69
|
+
};
|
|
71
70
|
};
|
|
72
|
-
var
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
var AS_MODULE_QUERY = "eventcatalog-config-as-module";
|
|
72
|
+
var loadsMarkedConfigsAsModules = false;
|
|
73
|
+
var loadMarkedConfigsAsModules = () => {
|
|
74
|
+
if (loadsMarkedConfigsAsModules) return;
|
|
75
|
+
loadsMarkedConfigsAsModules = true;
|
|
76
|
+
const hook = `export async function load(url, context, nextLoad) {
|
|
77
|
+
return nextLoad(url, url.includes('${AS_MODULE_QUERY}=') ? { ...context, format: 'module' } : context);
|
|
78
|
+
}`;
|
|
79
|
+
(0, import_node_module.register)(`data:text/javascript,${encodeURIComponent(hook)}`);
|
|
78
80
|
};
|
|
79
|
-
var
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return
|
|
81
|
+
var isCommonJSPackage = async (projectDirectory) => {
|
|
82
|
+
try {
|
|
83
|
+
const packageJson = JSON.parse(await (0, import_promises.readFile)(import_node_path.default.join(projectDirectory, "package.json"), "utf-8"));
|
|
84
|
+
return packageJson?.type === "commonjs";
|
|
85
|
+
} catch {
|
|
86
|
+
return false;
|
|
83
87
|
}
|
|
84
|
-
const tempDir = await (0, import_promises.mkdtemp)(import_node_path.default.join((0, import_node_os.tmpdir)(), "eventcatalog-config-"));
|
|
85
|
-
await linkNodeModulesIntoTempDirectory({ projectDirectory, tempDir });
|
|
86
|
-
return tempDir;
|
|
87
88
|
};
|
|
88
89
|
var getEventCatalogConfigFile = async (projectDirectory) => {
|
|
89
|
-
let tempDir;
|
|
90
90
|
try {
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
configFilePath = import_node_path.default.join(tempDir, "eventcatalog.config.mjs");
|
|
97
|
-
await (0, import_promises.copyFile)(import_node_path.default.join(projectDirectory, "eventcatalog.config.js"), configFilePath);
|
|
98
|
-
}
|
|
99
|
-
const configFileURL = `${(0, import_node_url.pathToFileURL)(configFilePath).href}?t=${Date.now()}`;
|
|
91
|
+
hideConfigModuleTypeWarning();
|
|
92
|
+
const asModule = await isCommonJSPackage(projectDirectory);
|
|
93
|
+
if (asModule) loadMarkedConfigsAsModules();
|
|
94
|
+
const configFileURL = (0, import_node_url.pathToFileURL)(import_node_path.default.join(projectDirectory, "eventcatalog.config.js")).href;
|
|
95
|
+
const query = `${asModule ? AS_MODULE_QUERY : "loaded"}=${Date.now()}-${loads++}`;
|
|
100
96
|
const config = await import(
|
|
101
97
|
/* @vite-ignore */
|
|
102
|
-
configFileURL
|
|
98
|
+
`${configFileURL}?${query}`
|
|
103
99
|
);
|
|
104
100
|
return config.default;
|
|
105
101
|
} finally {
|
|
106
102
|
await cleanup(projectDirectory);
|
|
107
|
-
if (tempDir) {
|
|
108
|
-
await (0, import_promises.rm)(tempDir, { recursive: true, force: true });
|
|
109
|
-
}
|
|
110
103
|
}
|
|
111
104
|
};
|
|
112
105
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { rm, readFile
|
|
1
|
+
import { rm, readFile } from 'node:fs/promises';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
|
-
import {
|
|
5
|
+
import { register } from 'node:module';
|
|
6
6
|
|
|
7
7
|
async function cleanup(projectDirectory) {
|
|
8
8
|
const filePath = path.join(projectDirectory, 'eventcatalog.config.mjs');
|
|
@@ -11,76 +11,74 @@ async function cleanup(projectDirectory) {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
14
|
+
let hidesConfigModuleTypeWarning = false;
|
|
15
|
+
let loads = 0;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Node loads an eventcatalog.config.js that uses import/export as an ES module even when the catalog's
|
|
19
|
+
* package.json has no "type": "module" (a new catalog's doesn't), and warns that it had to detect it.
|
|
20
|
+
* That warning, for the config file only, is hidden: the catalog doesn't need to change anything.
|
|
21
|
+
*/
|
|
22
|
+
const hideConfigModuleTypeWarning = () => {
|
|
23
|
+
if (hidesConfigModuleTypeWarning) return;
|
|
24
|
+
hidesConfigModuleTypeWarning = true;
|
|
25
|
+
|
|
26
|
+
const emitWarning = process.emitWarning;
|
|
27
|
+
process.emitWarning = function (warning, ...args) {
|
|
28
|
+
const code = typeof args[0] === 'object' ? args[0]?.code : args[1];
|
|
29
|
+
const message = typeof warning === 'string' ? warning : warning?.message;
|
|
30
|
+
if (code === 'MODULE_TYPELESS_PACKAGE_JSON' && message?.includes('eventcatalog.config.js')) return;
|
|
31
|
+
return emitWarning.call(this, warning, ...args);
|
|
32
|
+
};
|
|
32
33
|
};
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
// Marks a config URL Node should load as an ES module, whatever the catalog's package.json says
|
|
36
|
+
const AS_MODULE_QUERY = 'eventcatalog-config-as-module';
|
|
37
|
+
let loadsMarkedConfigsAsModules = false;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Node won't load a config written with import/export in a catalog whose package.json has
|
|
41
|
+
* "type": "commonjs". A loader hook loads that config file (and only it) as an ES module.
|
|
42
|
+
*/
|
|
43
|
+
const loadMarkedConfigsAsModules = () => {
|
|
44
|
+
if (loadsMarkedConfigsAsModules) return;
|
|
45
|
+
loadsMarkedConfigsAsModules = true;
|
|
46
|
+
const hook = `export async function load(url, context, nextLoad) {
|
|
47
|
+
return nextLoad(url, url.includes('${AS_MODULE_QUERY}=') ? { ...context, format: 'module' } : context);
|
|
48
|
+
}`;
|
|
49
|
+
register(`data:text/javascript,${encodeURIComponent(hook)}`);
|
|
42
50
|
};
|
|
43
51
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Loads the catalog's eventcatalog.config.js from where it is, so paths it builds from its own location
|
|
54
|
+
* (`import.meta.url`, `import.meta.dirname`) and its relative imports point into the catalog. It was
|
|
55
|
+
* loaded from a copy in a temporary folder before, which broke them (e.g. the paths to a generator's specs).
|
|
56
|
+
*/
|
|
57
|
+
const isCommonJSPackage = async (projectDirectory) => {
|
|
58
|
+
try {
|
|
59
|
+
const packageJson = JSON.parse(await readFile(path.join(projectDirectory, 'package.json'), 'utf-8'));
|
|
60
|
+
return packageJson?.type === 'commonjs';
|
|
61
|
+
} catch {
|
|
62
|
+
return false;
|
|
49
63
|
}
|
|
50
|
-
|
|
51
|
-
const tempDir = await mkdtemp(path.join(tmpdir(), 'eventcatalog-config-'));
|
|
52
|
-
await linkNodeModulesIntoTempDirectory({ projectDirectory, tempDir });
|
|
53
|
-
return tempDir;
|
|
54
64
|
};
|
|
55
65
|
|
|
56
66
|
const getEventCatalogConfigFile = async (projectDirectory) => {
|
|
57
|
-
let tempDir;
|
|
58
|
-
|
|
59
67
|
try {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
68
|
+
hideConfigModuleTypeWarning();
|
|
69
|
+
// A catalog's config is an ES module, as it always was (with "type": "commonjs" it was loaded from an .mjs copy)
|
|
70
|
+
const asModule = await isCommonJSPackage(projectDirectory);
|
|
71
|
+
if (asModule) loadMarkedConfigsAsModules();
|
|
64
72
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
tempDir = await createTemporaryConfigDirectory(projectDirectory);
|
|
70
|
-
configFilePath = path.join(tempDir, 'eventcatalog.config.mjs');
|
|
71
|
-
await copyFile(path.join(projectDirectory, 'eventcatalog.config.js'), configFilePath);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const configFileURL = `${pathToFileURL(configFilePath).href}?t=${Date.now()}`;
|
|
75
|
-
const config = await import(/* @vite-ignore */ configFileURL);
|
|
73
|
+
const configFileURL = pathToFileURL(path.join(projectDirectory, 'eventcatalog.config.js')).href;
|
|
74
|
+
// A new URL each time, so a changed config is loaded again (not `?t=`: Vite drops it as its own timestamp)
|
|
75
|
+
const query = `${asModule ? AS_MODULE_QUERY : 'loaded'}=${Date.now()}-${loads++}`;
|
|
76
|
+
const config = await import(/* @vite-ignore */ `${configFileURL}?${query}`);
|
|
76
77
|
|
|
77
78
|
return config.default;
|
|
78
79
|
} finally {
|
|
80
|
+
// Earlier versions loaded a copy from eventcatalog.config.mjs in the catalog: remove one left behind
|
|
79
81
|
await cleanup(projectDirectory);
|
|
80
|
-
|
|
81
|
-
if (tempDir) {
|
|
82
|
-
await rm(tempDir, { recursive: true, force: true });
|
|
83
|
-
}
|
|
84
82
|
}
|
|
85
83
|
};
|
|
86
84
|
|