@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
|
@@ -51,65 +51,58 @@ var import_promises = require("fs/promises");
|
|
|
51
51
|
var import_node_fs = require("fs");
|
|
52
52
|
var import_node_path = __toESM(require("path"), 1);
|
|
53
53
|
var import_node_url = require("url");
|
|
54
|
-
var
|
|
54
|
+
var import_node_module = require("module");
|
|
55
55
|
async function cleanup(projectDirectory) {
|
|
56
56
|
const filePath = import_node_path.default.join(projectDirectory, "eventcatalog.config.mjs");
|
|
57
57
|
if ((0, import_node_fs.existsSync)(filePath)) {
|
|
58
58
|
await (0, import_promises.rm)(filePath);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
var linkNodeModulesIntoTempDirectory = async ({ projectDirectory, tempDir }) => {
|
|
76
|
-
const nodeModulesDirectory = findNodeModulesDirectory(projectDirectory);
|
|
77
|
-
if (!nodeModulesDirectory) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
await (0, import_promises.symlink)(nodeModulesDirectory, import_node_path.default.join(tempDir, "node_modules"), "dir");
|
|
61
|
+
var hidesConfigModuleTypeWarning = false;
|
|
62
|
+
var loads = 0;
|
|
63
|
+
var hideConfigModuleTypeWarning = () => {
|
|
64
|
+
if (hidesConfigModuleTypeWarning) return;
|
|
65
|
+
hidesConfigModuleTypeWarning = true;
|
|
66
|
+
const emitWarning = process.emitWarning;
|
|
67
|
+
process.emitWarning = function(warning, ...args) {
|
|
68
|
+
const code = typeof args[0] === "object" ? args[0]?.code : args[1];
|
|
69
|
+
const message = typeof warning === "string" ? warning : warning?.message;
|
|
70
|
+
if (code === "MODULE_TYPELESS_PACKAGE_JSON" && message?.includes("eventcatalog.config.js")) return;
|
|
71
|
+
return emitWarning.call(this, warning, ...args);
|
|
72
|
+
};
|
|
81
73
|
};
|
|
82
|
-
var
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
74
|
+
var AS_MODULE_QUERY = "eventcatalog-config-as-module";
|
|
75
|
+
var loadsMarkedConfigsAsModules = false;
|
|
76
|
+
var loadMarkedConfigsAsModules = () => {
|
|
77
|
+
if (loadsMarkedConfigsAsModules) return;
|
|
78
|
+
loadsMarkedConfigsAsModules = true;
|
|
79
|
+
const hook = `export async function load(url, context, nextLoad) {
|
|
80
|
+
return nextLoad(url, url.includes('${AS_MODULE_QUERY}=') ? { ...context, format: 'module' } : context);
|
|
81
|
+
}`;
|
|
82
|
+
(0, import_node_module.register)(`data:text/javascript,${encodeURIComponent(hook)}`);
|
|
83
|
+
};
|
|
84
|
+
var isCommonJSPackage = async (projectDirectory) => {
|
|
85
|
+
try {
|
|
86
|
+
const packageJson = JSON.parse(await (0, import_promises.readFile)(import_node_path.default.join(projectDirectory, "package.json"), "utf-8"));
|
|
87
|
+
return packageJson?.type === "commonjs";
|
|
88
|
+
} catch {
|
|
89
|
+
return false;
|
|
86
90
|
}
|
|
87
|
-
const tempDir = await (0, import_promises.mkdtemp)(import_node_path.default.join((0, import_node_os.tmpdir)(), "eventcatalog-config-"));
|
|
88
|
-
await linkNodeModulesIntoTempDirectory({ projectDirectory, tempDir });
|
|
89
|
-
return tempDir;
|
|
90
91
|
};
|
|
91
92
|
var getEventCatalogConfigFile = async (projectDirectory) => {
|
|
92
|
-
let tempDir;
|
|
93
93
|
try {
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
configFilePath = import_node_path.default.join(tempDir, "eventcatalog.config.mjs");
|
|
100
|
-
await (0, import_promises.copyFile)(import_node_path.default.join(projectDirectory, "eventcatalog.config.js"), configFilePath);
|
|
101
|
-
}
|
|
102
|
-
const configFileURL = `${(0, import_node_url.pathToFileURL)(configFilePath).href}?t=${Date.now()}`;
|
|
94
|
+
hideConfigModuleTypeWarning();
|
|
95
|
+
const asModule = await isCommonJSPackage(projectDirectory);
|
|
96
|
+
if (asModule) loadMarkedConfigsAsModules();
|
|
97
|
+
const configFileURL = (0, import_node_url.pathToFileURL)(import_node_path.default.join(projectDirectory, "eventcatalog.config.js")).href;
|
|
98
|
+
const query = `${asModule ? AS_MODULE_QUERY : "loaded"}=${Date.now()}-${loads++}`;
|
|
103
99
|
const config = await import(
|
|
104
100
|
/* @vite-ignore */
|
|
105
|
-
configFileURL
|
|
101
|
+
`${configFileURL}?${query}`
|
|
106
102
|
);
|
|
107
103
|
return config.default;
|
|
108
104
|
} finally {
|
|
109
105
|
await cleanup(projectDirectory);
|
|
110
|
-
if (tempDir) {
|
|
111
|
-
await (0, import_promises.rm)(tempDir, { recursive: true, force: true });
|
|
112
|
-
}
|
|
113
106
|
}
|
|
114
107
|
};
|
|
115
108
|
|
|
@@ -633,7 +626,7 @@ var createFileSystemSourceProvider = (projectDirectory) => ({
|
|
|
633
626
|
// src/federation/github-source-provider.ts
|
|
634
627
|
var import_node_child_process = require("child_process");
|
|
635
628
|
var import_promises7 = __toESM(require("fs/promises"), 1);
|
|
636
|
-
var
|
|
629
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
637
630
|
var import_node_path7 = __toESM(require("path"), 1);
|
|
638
631
|
var import_node_util = require("util");
|
|
639
632
|
var import_sdk2 = __toESM(require("@eventcatalog/sdk"), 1);
|
|
@@ -690,7 +683,7 @@ var getGitEnvironment = (token) => {
|
|
|
690
683
|
var createCheckout = (executeFile, token) => async (source, ref, callback) => {
|
|
691
684
|
const { owner, repository } = parseGitHubSource(source);
|
|
692
685
|
const catalogPath = import_node_path7.default.posix.normalize(source.path ?? ".");
|
|
693
|
-
const directory = await import_promises7.default.mkdtemp(import_node_path7.default.join(
|
|
686
|
+
const directory = await import_promises7.default.mkdtemp(import_node_path7.default.join(import_node_os.default.tmpdir(), "eventcatalog-federation-"));
|
|
694
687
|
const env = getGitEnvironment(token);
|
|
695
688
|
try {
|
|
696
689
|
const git = (args) => executeFile("git", args, { cwd: directory, env, encoding: "utf8" });
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
FederationConflictError,
|
|
3
3
|
FederationDiagnosticError,
|
|
4
4
|
federateCatalog
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-QJ7KKN2D.js";
|
|
6
6
|
import "../chunk-WRNH5C3U.js";
|
|
7
7
|
import "../chunk-5EPNFDT5.js";
|
|
8
8
|
import "../chunk-A2RZR3U4.js";
|
|
@@ -10,7 +10,7 @@ import "../chunk-R7Z5ALYI.js";
|
|
|
10
10
|
import "../chunk-JJPB6EOZ.js";
|
|
11
11
|
import "../chunk-SDZQJTJW.js";
|
|
12
12
|
import "../chunk-352FGP6W.js";
|
|
13
|
-
import "../chunk-
|
|
13
|
+
import "../chunk-4G7FSRPN.js";
|
|
14
14
|
export {
|
|
15
15
|
FederationConflictError,
|
|
16
16
|
FederationDiagnosticError,
|
package/dist/generate.cjs
CHANGED
|
@@ -46,65 +46,58 @@ var import_promises = require("fs/promises");
|
|
|
46
46
|
var import_node_fs = require("fs");
|
|
47
47
|
var import_node_path = __toESM(require("path"), 1);
|
|
48
48
|
var import_node_url = require("url");
|
|
49
|
-
var
|
|
49
|
+
var import_node_module = require("module");
|
|
50
50
|
async function cleanup(projectDirectory) {
|
|
51
51
|
const filePath = import_node_path.default.join(projectDirectory, "eventcatalog.config.mjs");
|
|
52
52
|
if ((0, import_node_fs.existsSync)(filePath)) {
|
|
53
53
|
await (0, import_promises.rm)(filePath);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
var
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
56
|
+
var hidesConfigModuleTypeWarning = false;
|
|
57
|
+
var loads = 0;
|
|
58
|
+
var hideConfigModuleTypeWarning = () => {
|
|
59
|
+
if (hidesConfigModuleTypeWarning) return;
|
|
60
|
+
hidesConfigModuleTypeWarning = true;
|
|
61
|
+
const emitWarning = process.emitWarning;
|
|
62
|
+
process.emitWarning = function(warning, ...args) {
|
|
63
|
+
const code = typeof args[0] === "object" ? args[0]?.code : args[1];
|
|
64
|
+
const message = typeof warning === "string" ? warning : warning?.message;
|
|
65
|
+
if (code === "MODULE_TYPELESS_PACKAGE_JSON" && message?.includes("eventcatalog.config.js")) return;
|
|
66
|
+
return emitWarning.call(this, warning, ...args);
|
|
67
|
+
};
|
|
69
68
|
};
|
|
70
|
-
var
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
var AS_MODULE_QUERY = "eventcatalog-config-as-module";
|
|
70
|
+
var loadsMarkedConfigsAsModules = false;
|
|
71
|
+
var loadMarkedConfigsAsModules = () => {
|
|
72
|
+
if (loadsMarkedConfigsAsModules) return;
|
|
73
|
+
loadsMarkedConfigsAsModules = true;
|
|
74
|
+
const hook = `export async function load(url, context, nextLoad) {
|
|
75
|
+
return nextLoad(url, url.includes('${AS_MODULE_QUERY}=') ? { ...context, format: 'module' } : context);
|
|
76
|
+
}`;
|
|
77
|
+
(0, import_node_module.register)(`data:text/javascript,${encodeURIComponent(hook)}`);
|
|
76
78
|
};
|
|
77
|
-
var
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return
|
|
79
|
+
var isCommonJSPackage = async (projectDirectory) => {
|
|
80
|
+
try {
|
|
81
|
+
const packageJson = JSON.parse(await (0, import_promises.readFile)(import_node_path.default.join(projectDirectory, "package.json"), "utf-8"));
|
|
82
|
+
return packageJson?.type === "commonjs";
|
|
83
|
+
} catch {
|
|
84
|
+
return false;
|
|
81
85
|
}
|
|
82
|
-
const tempDir = await (0, import_promises.mkdtemp)(import_node_path.default.join((0, import_node_os.tmpdir)(), "eventcatalog-config-"));
|
|
83
|
-
await linkNodeModulesIntoTempDirectory({ projectDirectory, tempDir });
|
|
84
|
-
return tempDir;
|
|
85
86
|
};
|
|
86
87
|
var getEventCatalogConfigFile = async (projectDirectory) => {
|
|
87
|
-
let tempDir;
|
|
88
88
|
try {
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
configFilePath = import_node_path.default.join(tempDir, "eventcatalog.config.mjs");
|
|
95
|
-
await (0, import_promises.copyFile)(import_node_path.default.join(projectDirectory, "eventcatalog.config.js"), configFilePath);
|
|
96
|
-
}
|
|
97
|
-
const configFileURL = `${(0, import_node_url.pathToFileURL)(configFilePath).href}?t=${Date.now()}`;
|
|
89
|
+
hideConfigModuleTypeWarning();
|
|
90
|
+
const asModule = await isCommonJSPackage(projectDirectory);
|
|
91
|
+
if (asModule) loadMarkedConfigsAsModules();
|
|
92
|
+
const configFileURL = (0, import_node_url.pathToFileURL)(import_node_path.default.join(projectDirectory, "eventcatalog.config.js")).href;
|
|
93
|
+
const query = `${asModule ? AS_MODULE_QUERY : "loaded"}=${Date.now()}-${loads++}`;
|
|
98
94
|
const config = await import(
|
|
99
95
|
/* @vite-ignore */
|
|
100
|
-
configFileURL
|
|
96
|
+
`${configFileURL}?${query}`
|
|
101
97
|
);
|
|
102
98
|
return config.default;
|
|
103
99
|
} finally {
|
|
104
100
|
await cleanup(projectDirectory);
|
|
105
|
-
if (tempDir) {
|
|
106
|
-
await (0, import_promises.rm)(tempDir, { recursive: true, force: true });
|
|
107
|
-
}
|
|
108
101
|
}
|
|
109
102
|
};
|
|
110
103
|
|
|
@@ -112,7 +105,7 @@ var getEventCatalogConfigFile = async (projectDirectory) => {
|
|
|
112
105
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
113
106
|
|
|
114
107
|
// package.json
|
|
115
|
-
var version = "5.0.0-beta.
|
|
108
|
+
var version = "5.0.0-beta.27";
|
|
116
109
|
|
|
117
110
|
// src/constants.ts
|
|
118
111
|
var VERSION = version;
|
|
@@ -226,10 +219,12 @@ var generate = async (PROJECT_DIRECTORY) => {
|
|
|
226
219
|
for (const { plugin } of errors) {
|
|
227
220
|
logger.error(` - ${plugin}`, "generator");
|
|
228
221
|
}
|
|
222
|
+
process.exitCode = 1;
|
|
229
223
|
}
|
|
230
224
|
} catch (error) {
|
|
231
225
|
console.error(error);
|
|
232
226
|
await cleanup(PROJECT_DIRECTORY);
|
|
227
|
+
process.exitCode = 1;
|
|
233
228
|
}
|
|
234
229
|
};
|
|
235
230
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/generate.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
generate
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-I6CBMGUM.js";
|
|
4
|
+
import "./chunk-ILPH363P.js";
|
|
5
|
+
import "./chunk-YGUOLT7F.js";
|
|
6
|
+
import "./chunk-4G7FSRPN.js";
|
|
7
7
|
export {
|
|
8
8
|
generate
|
|
9
9
|
};
|
|
@@ -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
|
|
package/dist/utils/cli-logger.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { readFile, rm
|
|
1
|
+
import { readFile, rm } 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
|
export async function cleanup(projectDirectory) {
|
|
8
8
|
const filePath = path.join(projectDirectory, 'eventcatalog.config.mjs');
|
|
@@ -11,75 +11,73 @@ export 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
|
export 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
|
};
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
},
|
|
8
8
|
"license": "BUSL-1.1",
|
|
9
9
|
"type": "module",
|
|
10
|
-
"version": "5.0.0-beta.
|
|
10
|
+
"version": "5.0.0-beta.27",
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
@@ -142,8 +142,8 @@
|
|
|
142
142
|
"yjs": "^13.6.33",
|
|
143
143
|
"zod": "^4.3.6",
|
|
144
144
|
"@eventcatalog/linter": "1.2.0-beta.4",
|
|
145
|
-
"@eventcatalog/
|
|
146
|
-
"@eventcatalog/
|
|
145
|
+
"@eventcatalog/sdk": "2.30.0-beta.1",
|
|
146
|
+
"@eventcatalog/visualiser": "^5.0.0-beta.6"
|
|
147
147
|
},
|
|
148
148
|
"devDependencies": {
|
|
149
149
|
"@astrojs/check": "^0.9.10",
|