@eventcatalog/core 4.7.3 → 4.7.5
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 +1 -1
- package/dist/analytics/log-build.js +3 -3
- package/dist/{chunk-SMDTRRED.js → chunk-2BYTIH4L.js} +1 -1
- package/dist/chunk-A2RZR3U4.js +29 -0
- package/dist/{chunk-XXJX3WWF.js → chunk-EUZT4RKY.js} +1 -1
- package/dist/chunk-GYYYAUJD.js +276 -0
- package/dist/chunk-JJPB6EOZ.js +159 -0
- package/dist/{chunk-GINIJSFI.js → chunk-QJRY6Q7S.js} +1 -1
- package/dist/{chunk-IALEXWSE.js → chunk-QQPH6RCB.js} +24 -1
- package/dist/chunk-SDZQJTJW.js +90 -0
- package/dist/chunk-WRNH5C3U.js +118 -0
- package/dist/{chunk-V4FAVGI7.js → chunk-ZBPMCEXS.js} +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/constants.js +1 -1
- package/dist/eventcatalog.cjs +707 -255
- package/dist/eventcatalog.config.d.cts +12 -6
- package/dist/eventcatalog.config.d.ts +12 -6
- package/dist/eventcatalog.js +42 -42
- package/dist/federation/diagnostics.cjs +187 -0
- package/dist/federation/diagnostics.d.cts +23 -0
- package/dist/federation/diagnostics.d.ts +23 -0
- package/dist/federation/diagnostics.js +14 -0
- package/dist/federation/federate.cjs +605 -174
- package/dist/federation/federate.d.cts +8 -1
- package/dist/federation/federate.d.ts +8 -1
- package/dist/federation/federate.js +8 -2
- package/dist/federation/filesystem-source-provider.cjs +124 -0
- package/dist/federation/filesystem-source-provider.d.cts +7 -0
- package/dist/federation/filesystem-source-provider.d.ts +7 -0
- package/dist/federation/filesystem-source-provider.js +6 -0
- package/dist/federation/output-transaction.cjs +152 -0
- package/dist/federation/output-transaction.d.cts +3 -0
- package/dist/federation/output-transaction.d.ts +3 -0
- package/dist/federation/output-transaction.js +6 -0
- package/dist/federation/source-provider.cjs +265 -0
- package/dist/federation/source-provider.d.cts +11 -0
- package/dist/federation/source-provider.d.ts +11 -0
- package/dist/federation/source-provider.js +8 -0
- package/dist/generate.cjs +24 -1
- package/dist/generate.js +3 -3
- package/dist/utils/cli-logger.cjs +24 -1
- package/dist/utils/cli-logger.d.cts +6 -0
- package/dist/utils/cli-logger.d.ts +6 -0
- package/dist/utils/cli-logger.js +2 -2
- package/package.json +3 -3
- package/dist/chunk-ZR6AH5Z2.js +0 -204
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ResolvedGraph, HydrateResult, Conflict } from '@eventcatalog/sdk';
|
|
2
2
|
import { FederationSourceConfig } from '../eventcatalog.config.cjs';
|
|
3
|
+
import { FederationDiagnostic } from './diagnostics.cjs';
|
|
3
4
|
import { PublicAssetCompositionResult } from './public-assets.cjs';
|
|
4
5
|
import { FederationSourceProvider } from './types.cjs';
|
|
5
6
|
|
|
@@ -38,6 +39,7 @@ type FederationProgressEvent = {
|
|
|
38
39
|
} | {
|
|
39
40
|
type: 'resolved';
|
|
40
41
|
graph: ResolvedGraph;
|
|
42
|
+
diagnostics: FederationDiagnostic[];
|
|
41
43
|
} | {
|
|
42
44
|
type: 'hydrating';
|
|
43
45
|
outDir: string;
|
|
@@ -60,6 +62,7 @@ type FederateCatalogResult = {
|
|
|
60
62
|
sources: number;
|
|
61
63
|
resources: number;
|
|
62
64
|
graph: ResolvedGraph;
|
|
65
|
+
diagnostics: FederationDiagnostic[];
|
|
63
66
|
hydrate: HydrateResult;
|
|
64
67
|
public: PublicAssetCompositionResult;
|
|
65
68
|
outDir: string;
|
|
@@ -76,6 +79,10 @@ declare class FederationConflictError extends Error {
|
|
|
76
79
|
conflicts: Conflict[];
|
|
77
80
|
constructor(conflicts: Conflict[]);
|
|
78
81
|
}
|
|
82
|
+
declare class FederationDiagnosticError extends Error {
|
|
83
|
+
diagnostics: FederationDiagnostic[];
|
|
84
|
+
constructor(diagnostics: FederationDiagnostic[]);
|
|
85
|
+
}
|
|
79
86
|
declare const federateCatalog: (projectDirectory: string, options?: FederateCatalogOptions) => Promise<FederateCatalogResult | null>;
|
|
80
87
|
|
|
81
|
-
export { type FederateCatalogResult, FederationConflictError, type FederationProgressEvent, federateCatalog };
|
|
88
|
+
export { type FederateCatalogResult, FederationConflictError, FederationDiagnosticError, type FederationProgressEvent, federateCatalog };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ResolvedGraph, HydrateResult, Conflict } from '@eventcatalog/sdk';
|
|
2
2
|
import { FederationSourceConfig } from '../eventcatalog.config.js';
|
|
3
|
+
import { FederationDiagnostic } from './diagnostics.js';
|
|
3
4
|
import { PublicAssetCompositionResult } from './public-assets.js';
|
|
4
5
|
import { FederationSourceProvider } from './types.js';
|
|
5
6
|
|
|
@@ -38,6 +39,7 @@ type FederationProgressEvent = {
|
|
|
38
39
|
} | {
|
|
39
40
|
type: 'resolved';
|
|
40
41
|
graph: ResolvedGraph;
|
|
42
|
+
diagnostics: FederationDiagnostic[];
|
|
41
43
|
} | {
|
|
42
44
|
type: 'hydrating';
|
|
43
45
|
outDir: string;
|
|
@@ -60,6 +62,7 @@ type FederateCatalogResult = {
|
|
|
60
62
|
sources: number;
|
|
61
63
|
resources: number;
|
|
62
64
|
graph: ResolvedGraph;
|
|
65
|
+
diagnostics: FederationDiagnostic[];
|
|
63
66
|
hydrate: HydrateResult;
|
|
64
67
|
public: PublicAssetCompositionResult;
|
|
65
68
|
outDir: string;
|
|
@@ -76,6 +79,10 @@ declare class FederationConflictError extends Error {
|
|
|
76
79
|
conflicts: Conflict[];
|
|
77
80
|
constructor(conflicts: Conflict[]);
|
|
78
81
|
}
|
|
82
|
+
declare class FederationDiagnosticError extends Error {
|
|
83
|
+
diagnostics: FederationDiagnostic[];
|
|
84
|
+
constructor(diagnostics: FederationDiagnostic[]);
|
|
85
|
+
}
|
|
79
86
|
declare const federateCatalog: (projectDirectory: string, options?: FederateCatalogOptions) => Promise<FederateCatalogResult | null>;
|
|
80
87
|
|
|
81
|
-
export { type FederateCatalogResult, FederationConflictError, type FederationProgressEvent, federateCatalog };
|
|
88
|
+
export { type FederateCatalogResult, FederationConflictError, FederationDiagnosticError, type FederationProgressEvent, federateCatalog };
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
FederationConflictError,
|
|
3
|
+
FederationDiagnosticError,
|
|
3
4
|
federateCatalog
|
|
4
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-GYYYAUJD.js";
|
|
6
|
+
import "../chunk-WRNH5C3U.js";
|
|
7
|
+
import "../chunk-5EPNFDT5.js";
|
|
8
|
+
import "../chunk-A2RZR3U4.js";
|
|
5
9
|
import "../chunk-R7Z5ALYI.js";
|
|
10
|
+
import "../chunk-JJPB6EOZ.js";
|
|
11
|
+
import "../chunk-SDZQJTJW.js";
|
|
6
12
|
import "../chunk-352FGP6W.js";
|
|
7
|
-
import "../chunk-5EPNFDT5.js";
|
|
8
13
|
import "../chunk-6QENHZZP.js";
|
|
9
14
|
export {
|
|
10
15
|
FederationConflictError,
|
|
16
|
+
FederationDiagnosticError,
|
|
11
17
|
federateCatalog
|
|
12
18
|
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/federation/filesystem-source-provider.ts
|
|
31
|
+
var filesystem_source_provider_exports = {};
|
|
32
|
+
__export(filesystem_source_provider_exports, {
|
|
33
|
+
createFileSystemSourceProvider: () => createFileSystemSourceProvider
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(filesystem_source_provider_exports);
|
|
36
|
+
var import_node_crypto = require("crypto");
|
|
37
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
38
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
39
|
+
var import_sdk = __toESM(require("@eventcatalog/sdk"), 1);
|
|
40
|
+
var FILESYSTEM_SOURCE_PREFIX = "file:";
|
|
41
|
+
var isWithinDirectory = (directory, target) => {
|
|
42
|
+
const relativePath = import_node_path.default.relative(directory, target);
|
|
43
|
+
return relativePath === "" || !relativePath.startsWith(`..${import_node_path.default.sep}`) && relativePath !== ".." && !import_node_path.default.isAbsolute(relativePath);
|
|
44
|
+
};
|
|
45
|
+
var assertPortableRelativePath = (filePath, label, allowRoot = true) => {
|
|
46
|
+
const portablePath = filePath.replaceAll("\\", "/");
|
|
47
|
+
const normalizedPath = import_node_path.default.posix.normalize(portablePath);
|
|
48
|
+
const isUnsafe = filePath.includes("\\") || filePath.includes("\0") || import_node_path.default.posix.isAbsolute(normalizedPath) || /^[a-zA-Z]:\//.test(normalizedPath) || normalizedPath === ".." || normalizedPath.startsWith("../") || !allowRoot && (normalizedPath === "." || normalizedPath === "");
|
|
49
|
+
if (isUnsafe) throw new Error(`${label} "${filePath}" escapes its filesystem source`);
|
|
50
|
+
return normalizedPath;
|
|
51
|
+
};
|
|
52
|
+
var getSourceRoot = (projectDirectory, source) => {
|
|
53
|
+
if (!source.source.startsWith(FILESYSTEM_SOURCE_PREFIX)) {
|
|
54
|
+
throw new Error(`Unsupported federation source "${source.source}". Expected file:path/to/catalog.`);
|
|
55
|
+
}
|
|
56
|
+
const locator = source.source.slice(FILESYSTEM_SOURCE_PREFIX.length);
|
|
57
|
+
if (!locator.trim()) throw new Error(`Filesystem federation source "${source.id}" requires a path after "file:".`);
|
|
58
|
+
return import_node_path.default.resolve(projectDirectory, locator);
|
|
59
|
+
};
|
|
60
|
+
var getCatalogDirectory = async (projectDirectory, source) => {
|
|
61
|
+
if (source.ref) throw new Error(`Filesystem federation source "${source.id}" does not support "ref".`);
|
|
62
|
+
const sourceRoot = getSourceRoot(projectDirectory, source);
|
|
63
|
+
const catalogPath = assertPortableRelativePath(source.path ?? ".", "Catalog path");
|
|
64
|
+
const catalogDirectory = import_node_path.default.resolve(sourceRoot, ...catalogPath.split("/"));
|
|
65
|
+
if (!isWithinDirectory(sourceRoot, catalogDirectory)) {
|
|
66
|
+
throw new Error(`Catalog path "${source.path}" escapes source "${source.id}"`);
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
const [realSourceRoot, realCatalogDirectory] = await Promise.all([import_promises.default.realpath(sourceRoot), import_promises.default.realpath(catalogDirectory)]);
|
|
70
|
+
if (!isWithinDirectory(realSourceRoot, realCatalogDirectory)) {
|
|
71
|
+
throw new Error(`Catalog path "${source.path}" escapes source "${source.id}"`);
|
|
72
|
+
}
|
|
73
|
+
if (!(await import_promises.default.stat(realCatalogDirectory)).isDirectory()) {
|
|
74
|
+
throw new Error(`Filesystem federation source "${source.id}" is not a directory: ${catalogDirectory}`);
|
|
75
|
+
}
|
|
76
|
+
return realCatalogDirectory;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (error.code === "ENOENT") {
|
|
79
|
+
throw new Error(`Filesystem federation source "${source.id}" does not exist: ${catalogDirectory}`, { cause: error });
|
|
80
|
+
}
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var getArtifactPath = async (catalogDirectory, source, artifactPath) => {
|
|
85
|
+
const normalizedPath = assertPortableRelativePath(artifactPath, "Federated artifact path", false);
|
|
86
|
+
const filePath = import_node_path.default.resolve(catalogDirectory, ...normalizedPath.split("/"));
|
|
87
|
+
if (!isWithinDirectory(catalogDirectory, filePath)) {
|
|
88
|
+
throw new Error(`Federated artifact path "${artifactPath}" escapes source "${source.id}"`);
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
const realFilePath = await import_promises.default.realpath(filePath);
|
|
92
|
+
if (!isWithinDirectory(catalogDirectory, realFilePath)) {
|
|
93
|
+
throw new Error(`Federated artifact path "${artifactPath}" escapes source "${source.id}"`);
|
|
94
|
+
}
|
|
95
|
+
return realFilePath;
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (error.code === "ENOENT") {
|
|
98
|
+
throw new Error(`Federated artifact not found for "${source.id}": ${artifactPath}`, { cause: error });
|
|
99
|
+
}
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var createFileSystemSourceProvider = (projectDirectory) => ({
|
|
104
|
+
async resolve(source) {
|
|
105
|
+
const catalogDirectory = await getCatalogDirectory(projectDirectory, source);
|
|
106
|
+
const localIndex = await (0, import_sdk.default)(catalogDirectory).buildIndex({
|
|
107
|
+
source: source.id,
|
|
108
|
+
commit: "local",
|
|
109
|
+
includeFederated: false
|
|
110
|
+
});
|
|
111
|
+
const snapshot = (0, import_node_crypto.createHash)("sha256").update(JSON.stringify(localIndex)).digest("hex").slice(0, 12);
|
|
112
|
+
const index = { ...localIndex, commit: `local:${snapshot}` };
|
|
113
|
+
const bytes = Buffer.from(JSON.stringify(index));
|
|
114
|
+
return { bytes, index, commit: index.commit, generated: true };
|
|
115
|
+
},
|
|
116
|
+
async fetchContent({ source, path: artifactPath }) {
|
|
117
|
+
const catalogDirectory = await getCatalogDirectory(projectDirectory, source);
|
|
118
|
+
return import_promises.default.readFile(await getArtifactPath(catalogDirectory, source, artifactPath));
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
createFileSystemSourceProvider
|
|
124
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FederationSourceProvider } from './types.cjs';
|
|
2
|
+
import '@eventcatalog/sdk';
|
|
3
|
+
import '../eventcatalog.config.cjs';
|
|
4
|
+
|
|
5
|
+
declare const createFileSystemSourceProvider: (projectDirectory: string) => FederationSourceProvider;
|
|
6
|
+
|
|
7
|
+
export { createFileSystemSourceProvider };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FederationSourceProvider } from './types.js';
|
|
2
|
+
import '@eventcatalog/sdk';
|
|
3
|
+
import '../eventcatalog.config.js';
|
|
4
|
+
|
|
5
|
+
declare const createFileSystemSourceProvider: (projectDirectory: string) => FederationSourceProvider;
|
|
6
|
+
|
|
7
|
+
export { createFileSystemSourceProvider };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/federation/output-transaction.ts
|
|
31
|
+
var output_transaction_exports = {};
|
|
32
|
+
__export(output_transaction_exports, {
|
|
33
|
+
withFederationOutputTransaction: () => withFederationOutputTransaction
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(output_transaction_exports);
|
|
36
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
37
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
38
|
+
var getSafePublicPath = (publicDirectory, relativePath) => {
|
|
39
|
+
const normalizedPath = import_node_path.default.posix.normalize(relativePath);
|
|
40
|
+
const unsafe = relativePath.length === 0 || relativePath.includes("\0") || relativePath.includes("\\") || import_node_path.default.posix.isAbsolute(relativePath) || /^[a-zA-Z]:\//.test(relativePath) || normalizedPath !== relativePath || normalizedPath === ".." || normalizedPath.startsWith("../");
|
|
41
|
+
if (unsafe) return void 0;
|
|
42
|
+
const destinationPath = import_node_path.default.resolve(publicDirectory, relativePath);
|
|
43
|
+
const relativeDestinationPath = import_node_path.default.relative(publicDirectory, destinationPath);
|
|
44
|
+
return relativeDestinationPath !== "" && relativeDestinationPath !== ".." && !relativeDestinationPath.startsWith(`..${import_node_path.default.sep}`) && !import_node_path.default.isAbsolute(relativeDestinationPath) ? destinationPath : void 0;
|
|
45
|
+
};
|
|
46
|
+
var beginFederationOutputTransaction = async (projectDirectory, outDir, relativePublicPaths) => {
|
|
47
|
+
const transactionDirectory = await import_promises.default.mkdtemp(import_node_path.default.join(projectDirectory, ".eventcatalog-federation-transaction-"));
|
|
48
|
+
const previousOutDir = import_node_path.default.join(transactionDirectory, "federated");
|
|
49
|
+
const publicBackupDirectory = import_node_path.default.join(transactionDirectory, "public");
|
|
50
|
+
const publicDirectory = import_node_path.default.resolve(projectDirectory, "public");
|
|
51
|
+
const publicSnapshots = [];
|
|
52
|
+
const missingPublicDirectories = /* @__PURE__ */ new Set();
|
|
53
|
+
let hadPreviousOutDir = false;
|
|
54
|
+
try {
|
|
55
|
+
for (const relativePath of new Set(relativePublicPaths)) {
|
|
56
|
+
const destinationPath = getSafePublicPath(publicDirectory, relativePath);
|
|
57
|
+
if (!destinationPath) continue;
|
|
58
|
+
try {
|
|
59
|
+
const stat = await import_promises.default.lstat(destinationPath);
|
|
60
|
+
if (!stat.isFile()) continue;
|
|
61
|
+
const backupPath = import_node_path.default.join(publicBackupDirectory, `${publicSnapshots.length}`);
|
|
62
|
+
await import_promises.default.mkdir(import_node_path.default.dirname(backupPath), { recursive: true });
|
|
63
|
+
await import_promises.default.copyFile(destinationPath, backupPath);
|
|
64
|
+
publicSnapshots.push({ backupPath, destinationPath, state: "file" });
|
|
65
|
+
} catch (error) {
|
|
66
|
+
const code = error.code;
|
|
67
|
+
if (code === "ENOTDIR") continue;
|
|
68
|
+
if (code !== "ENOENT") throw error;
|
|
69
|
+
publicSnapshots.push({ destinationPath, state: "missing" });
|
|
70
|
+
let directory = import_node_path.default.dirname(destinationPath);
|
|
71
|
+
while (directory !== publicDirectory) {
|
|
72
|
+
try {
|
|
73
|
+
await import_promises.default.lstat(directory);
|
|
74
|
+
break;
|
|
75
|
+
} catch (directoryError) {
|
|
76
|
+
const directoryCode = directoryError.code;
|
|
77
|
+
if (directoryCode === "ENOTDIR") break;
|
|
78
|
+
if (directoryCode !== "ENOENT") throw directoryError;
|
|
79
|
+
missingPublicDirectories.add(directory);
|
|
80
|
+
directory = import_node_path.default.dirname(directory);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
await import_promises.default.rename(outDir, previousOutDir);
|
|
87
|
+
hadPreviousOutDir = true;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (error.code !== "ENOENT") throw error;
|
|
90
|
+
}
|
|
91
|
+
} catch (error) {
|
|
92
|
+
await import_promises.default.rm(transactionDirectory, { recursive: true, force: true });
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
commit: async () => {
|
|
97
|
+
await import_promises.default.rm(transactionDirectory, { recursive: true, force: true }).catch(() => void 0);
|
|
98
|
+
},
|
|
99
|
+
rollback: async () => {
|
|
100
|
+
const rollbackErrors = [];
|
|
101
|
+
const attempt = async (operation) => {
|
|
102
|
+
try {
|
|
103
|
+
await operation();
|
|
104
|
+
} catch (error) {
|
|
105
|
+
rollbackErrors.push(error);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
await attempt(() => import_promises.default.rm(outDir, { recursive: true, force: true }));
|
|
109
|
+
if (hadPreviousOutDir) await attempt(() => import_promises.default.rename(previousOutDir, outDir));
|
|
110
|
+
for (const snapshot of publicSnapshots) {
|
|
111
|
+
if (snapshot.state === "missing") {
|
|
112
|
+
await attempt(() => import_promises.default.rm(snapshot.destinationPath, { force: true }));
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
await attempt(async () => {
|
|
116
|
+
await import_promises.default.mkdir(import_node_path.default.dirname(snapshot.destinationPath), { recursive: true });
|
|
117
|
+
await import_promises.default.copyFile(snapshot.backupPath, snapshot.destinationPath);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
for (const directory of [...missingPublicDirectories].sort((left, right) => right.length - left.length)) {
|
|
121
|
+
await attempt(async () => {
|
|
122
|
+
try {
|
|
123
|
+
await import_promises.default.rmdir(directory);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (!["ENOENT", "ENOTEMPTY"].includes(error.code ?? "")) throw error;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
await attempt(() => import_promises.default.rm(transactionDirectory, { recursive: true, force: true }));
|
|
130
|
+
if (rollbackErrors.length > 0) throw new AggregateError(rollbackErrors, "Failed to restore the previous federation output");
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
var withFederationOutputTransaction = async (projectDirectory, outDir, relativePublicPaths, update) => {
|
|
135
|
+
const transaction = await beginFederationOutputTransaction(projectDirectory, outDir, relativePublicPaths);
|
|
136
|
+
try {
|
|
137
|
+
const result = await update();
|
|
138
|
+
await transaction.commit();
|
|
139
|
+
return result;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
try {
|
|
142
|
+
await transaction.rollback();
|
|
143
|
+
} catch (rollbackError) {
|
|
144
|
+
throw new AggregateError([error, rollbackError], "Federation failed and the previous output could not be restored");
|
|
145
|
+
}
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
150
|
+
0 && (module.exports = {
|
|
151
|
+
withFederationOutputTransaction
|
|
152
|
+
});
|