embedex 0.18.2 → 0.18.3
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/README.md +1 -1
- package/package.json +1 -1
- package/src/bin/processResult.js +69 -11
- package/src/bin/processResult.js.map +1 -1
- package/src/lib/embed.d.ts +5 -0
- package/src/lib/embed.js +55 -1
- package/src/lib/embed.js.map +1 -1
- package/src/lib/internal/createSourceMap.d.ts +6 -0
- package/src/lib/internal/createSourceMap.js +20 -6
- package/src/lib/internal/createSourceMap.js.map +1 -1
- package/src/lib/internal/dependencyGraph.d.ts +41 -0
- package/src/lib/internal/dependencyGraph.js +159 -0
- package/src/lib/internal/dependencyGraph.js.map +1 -0
- package/src/lib/internal/processDestinations.d.ts +1 -0
- package/src/lib/internal/processDestinations.js +94 -21
- package/src/lib/internal/processDestinations.js.map +1 -1
- package/src/lib/types.d.ts +14 -2
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ npm install --global embedex
|
|
|
33
33
|
1. Add a source file to the `./examples` directory (configurable). The first line is a comma-separated list of destination file paths to embed the source's file contents into. `./examples/greeter.ts`:
|
|
34
34
|
|
|
35
35
|
```ts
|
|
36
|
-
// README.md,src/greeter.ts
|
|
36
|
+
// embedex: README.md,src/greeter.ts
|
|
37
37
|
import { greet } from "@my-scope/greeter";
|
|
38
38
|
|
|
39
39
|
greet("world");
|
package/package.json
CHANGED
package/src/bin/processResult.js
CHANGED
|
@@ -8,6 +8,14 @@ const yoctocolors_cjs_1 = tslib_1.__importDefault(require("yoctocolors-cjs"));
|
|
|
8
8
|
function dim(...messages) {
|
|
9
9
|
return yoctocolors_cjs_1.default.dim(messages.join(" "));
|
|
10
10
|
}
|
|
11
|
+
function formatOutput(params) {
|
|
12
|
+
const coloredCode = (params.isError ? yoctocolors_cjs_1.default.red : yoctocolors_cjs_1.default.green)(params.code);
|
|
13
|
+
const grayDetail = yoctocolors_cjs_1.default.gray(params.detail);
|
|
14
|
+
if (params.destination) {
|
|
15
|
+
return `${coloredCode} ${yoctocolors_cjs_1.default.gray(params.destination)} -> ${grayDetail}`;
|
|
16
|
+
}
|
|
17
|
+
return `${coloredCode} ${grayDetail}`;
|
|
18
|
+
}
|
|
11
19
|
function processResult(params) {
|
|
12
20
|
const { check, result, cwd, verbose } = params;
|
|
13
21
|
const { embeds, sources, destinations } = result;
|
|
@@ -26,24 +34,69 @@ function processResult(params) {
|
|
|
26
34
|
for (const embed of embeds) {
|
|
27
35
|
const { code, paths } = embed;
|
|
28
36
|
const { destination, sources } = paths;
|
|
29
|
-
const toOutput = createToOutput({
|
|
30
|
-
code,
|
|
31
|
-
paths: { destination: relative(destination), sources: sources.map((path) => relative(path)) },
|
|
32
|
-
});
|
|
33
|
-
// eslint-disable-next-line default-case -- ignore so we get @typescript-eslint/switch-exhaustiveness-check
|
|
34
37
|
switch (code) {
|
|
35
|
-
case "
|
|
36
|
-
|
|
38
|
+
case "INVALID_SOURCE": {
|
|
39
|
+
const { invalidSources } = embed;
|
|
40
|
+
const joined = invalidSources.map((path) => relative(path)).join(", ");
|
|
41
|
+
output.push({
|
|
42
|
+
code,
|
|
43
|
+
isError: true,
|
|
44
|
+
message: formatOutput({
|
|
45
|
+
code,
|
|
46
|
+
isError: true,
|
|
47
|
+
destination: relative(destination),
|
|
48
|
+
detail: `missing: ${joined}`,
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
37
51
|
break;
|
|
38
52
|
}
|
|
39
|
-
case "
|
|
40
|
-
|
|
53
|
+
case "UNREFERENCED_SOURCE": {
|
|
54
|
+
const { unreferencedSources } = embed;
|
|
55
|
+
const joined = unreferencedSources.map((path) => relative(path)).join(", ");
|
|
56
|
+
output.push({
|
|
57
|
+
code,
|
|
58
|
+
isError: true,
|
|
59
|
+
message: formatOutput({
|
|
60
|
+
code,
|
|
61
|
+
isError: true,
|
|
62
|
+
destination: relative(destination),
|
|
63
|
+
detail: `not referenced: ${joined}`,
|
|
64
|
+
}),
|
|
65
|
+
});
|
|
41
66
|
break;
|
|
42
67
|
}
|
|
68
|
+
case "CIRCULAR_DEPENDENCY": {
|
|
69
|
+
const { cycle } = embed;
|
|
70
|
+
const cycleMessage = cycle.map((path) => relative(path)).join(" → ");
|
|
71
|
+
output.push({
|
|
72
|
+
code,
|
|
73
|
+
isError: true,
|
|
74
|
+
message: formatOutput({
|
|
75
|
+
code,
|
|
76
|
+
isError: true,
|
|
77
|
+
detail: cycleMessage,
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case "NO_CHANGE":
|
|
83
|
+
case "NO_MATCH":
|
|
43
84
|
case "UPDATE": {
|
|
44
|
-
|
|
85
|
+
const toOutput = createToOutput({
|
|
86
|
+
code,
|
|
87
|
+
paths: {
|
|
88
|
+
destination: relative(destination),
|
|
89
|
+
sources: sources.map((path) => relative(path)),
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
const isError = code === "NO_MATCH" || (code === "UPDATE" && check);
|
|
93
|
+
output.push(toOutput({ isError }));
|
|
45
94
|
break;
|
|
46
95
|
}
|
|
96
|
+
default: {
|
|
97
|
+
const exhaustiveCheck = code;
|
|
98
|
+
throw new Error(`Unhandled embed code: ${String(exhaustiveCheck)}`);
|
|
99
|
+
}
|
|
47
100
|
}
|
|
48
101
|
}
|
|
49
102
|
return output.sort((a, b) => a.code.localeCompare(b.code));
|
|
@@ -54,7 +107,12 @@ function createToOutput(params) {
|
|
|
54
107
|
return ({ isError }) => ({
|
|
55
108
|
code,
|
|
56
109
|
isError,
|
|
57
|
-
message:
|
|
110
|
+
message: formatOutput({
|
|
111
|
+
code,
|
|
112
|
+
isError,
|
|
113
|
+
destination,
|
|
114
|
+
detail: sources.length > 0 ? sources.join(", ") : "—",
|
|
115
|
+
}),
|
|
58
116
|
});
|
|
59
117
|
}
|
|
60
118
|
//# sourceMappingURL=processResult.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processResult.js","sourceRoot":"","sources":["../../../../../packages/embedex/src/bin/processResult.ts"],"names":[],"mappings":";;AAYA,kBAEC;
|
|
1
|
+
{"version":3,"file":"processResult.js","sourceRoot":"","sources":["../../../../../packages/embedex/src/bin/processResult.ts"],"names":[],"mappings":";;AAYA,kBAEC;AAkBD,sCAuGC;;AAvID,yCAAqD;AAErD,8EAAqC;AAUrC,SAAgB,GAAG,CAAC,GAAG,QAAkB;IACvC,OAAO,yBAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACxC,CAAC;AAED,SAAS,YAAY,CAAC,MAKrB;IACC,MAAM,WAAW,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,yBAAM,CAAC,GAAG,CAAC,CAAC,CAAC,yBAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC9E,MAAM,UAAU,GAAG,yBAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAE9C,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,OAAO,GAAG,WAAW,IAAI,yBAAM,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,UAAU,EAAE,CAAC;IAC9E,CAAC;IAED,OAAO,GAAG,WAAW,IAAI,UAAU,EAAE,CAAC;AACxC,CAAC;AAED,SAAgB,aAAa,CAAC,MAK7B;IACC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAC/C,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;IAEjD,SAAS,QAAQ,CAAC,IAAY;QAC5B,OAAO,IAAA,oBAAY,EAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,SAAS,MAAM,CAAC,IAA6E;QAC3F,MAAM,KAAK,GAAG,cAAc,IAAI,IAAI,CAAC,CAAC,CAA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|
|
|
1
1
|
import { type EmbedParams, type EmbedResult } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Embed sources into destinations.
|
|
4
|
+
*
|
|
5
|
+
* Processes destinations in dependency order to handle chained embeds correctly.
|
|
6
|
+
* For example, if A.ts embeds into B.md, and B.md embeds into C.md, then:
|
|
7
|
+
* 1. B.md is processed first (A.ts content is embedded)
|
|
8
|
+
* 2. C.md is processed second (updated B.md content is embedded)
|
|
4
9
|
*/
|
|
5
10
|
export declare function embed(params: Readonly<EmbedParams>): Promise<EmbedResult>;
|
package/src/lib/embed.js
CHANGED
|
@@ -4,15 +4,69 @@ exports.embed = embed;
|
|
|
4
4
|
const promises_1 = require("node:fs/promises");
|
|
5
5
|
const createDestinationMap_1 = require("./internal/createDestinationMap");
|
|
6
6
|
const createSourceMap_1 = require("./internal/createSourceMap");
|
|
7
|
+
const dependencyGraph_1 = require("./internal/dependencyGraph");
|
|
7
8
|
const processDestinations_1 = require("./internal/processDestinations");
|
|
8
9
|
/**
|
|
9
10
|
* Embed sources into destinations.
|
|
11
|
+
*
|
|
12
|
+
* Processes destinations in dependency order to handle chained embeds correctly.
|
|
13
|
+
* For example, if A.ts embeds into B.md, and B.md embeds into C.md, then:
|
|
14
|
+
* 1. B.md is processed first (A.ts content is embedded)
|
|
15
|
+
* 2. C.md is processed second (updated B.md content is embedded)
|
|
10
16
|
*/
|
|
11
17
|
async function embed(params) {
|
|
12
18
|
const { sourcesGlob, cwd, write } = params;
|
|
13
19
|
const sourceMap = await (0, createSourceMap_1.createSourceMap)({ cwd, sourcesGlob });
|
|
14
20
|
const destinationMap = await (0, createDestinationMap_1.createDestinationMap)({ sourceMap });
|
|
15
|
-
|
|
21
|
+
// Build dependency graph to determine processing order
|
|
22
|
+
const graph = (0, dependencyGraph_1.buildDependencyGraph)({ destinationMap });
|
|
23
|
+
// Check for circular dependencies
|
|
24
|
+
const circularDependency = (0, dependencyGraph_1.detectCircularDependency)(graph);
|
|
25
|
+
if (circularDependency) {
|
|
26
|
+
const { cycle } = circularDependency;
|
|
27
|
+
/* istanbul ignore next - cycle[0] is always defined in practice */
|
|
28
|
+
const destination = cycle[0] ?? "";
|
|
29
|
+
const embed = {
|
|
30
|
+
code: "CIRCULAR_DEPENDENCY",
|
|
31
|
+
paths: { destination, sources: [] },
|
|
32
|
+
cycle,
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
embeds: [embed],
|
|
36
|
+
sources: [...sourceMap.entries()].map(([path, { destinations }]) => ({ path, destinations })),
|
|
37
|
+
destinations: [...destinationMap.entries()].map(([path, { sources }]) => ({
|
|
38
|
+
path,
|
|
39
|
+
sources: [...sources],
|
|
40
|
+
})),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// Get topological sort order for processing
|
|
44
|
+
const sortedDestinations = (0, dependencyGraph_1.topologicalSort)(graph);
|
|
45
|
+
// Process destinations in dependency order, tracking updated content
|
|
46
|
+
const updatedContentMap = new Map();
|
|
47
|
+
const embeds = [];
|
|
48
|
+
for (const destinationPath of sortedDestinations) {
|
|
49
|
+
const destinationEntry = destinationMap.get(destinationPath);
|
|
50
|
+
/* istanbul ignore next */
|
|
51
|
+
if (!destinationEntry) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const [embed] = (0, processDestinations_1.processDestinations)({
|
|
55
|
+
cwd,
|
|
56
|
+
sourceMap,
|
|
57
|
+
destinationMap: new Map([[destinationPath, destinationEntry]]),
|
|
58
|
+
updatedContentMap,
|
|
59
|
+
});
|
|
60
|
+
/* istanbul ignore next */
|
|
61
|
+
if (!embed) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
embeds.push(embed);
|
|
65
|
+
// Track updated content for chained embeds
|
|
66
|
+
if (embed.code === "UPDATE") {
|
|
67
|
+
updatedContentMap.set(destinationPath, embed.updatedContent);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
16
70
|
await Promise.all(embeds.map(async (embed) => {
|
|
17
71
|
if (write && embed.code === "UPDATE") {
|
|
18
72
|
await (0, promises_1.writeFile)(embed.paths.destination, embed.updatedContent);
|
package/src/lib/embed.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../../../../../packages/embedex/src/lib/embed.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../../../../../packages/embedex/src/lib/embed.ts"],"names":[],"mappings":";;AAoBA,sBA+EC;AAnGD,+CAA6C;AAE7C,0EAAuE;AACvE,gEAA6D;AAC7D,gEAIoC;AACpC,wEAAqE;AAGrE;;;;;;;GAOG;AACI,KAAK,UAAU,KAAK,CAAC,MAA6B;IACvD,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,SAAS,GAAG,MAAM,IAAA,iCAAe,EAAC,EAAE,GAAG,EAAE,WAAW,EAAE,CAAC,CAAC;IAC9D,MAAM,cAAc,GAAG,MAAM,IAAA,2CAAoB,EAAC,EAAE,SAAS,EAAE,CAAC,CAAC;IAEjE,uDAAuD;IACvD,MAAM,KAAK,GAAG,IAAA,sCAAoB,EAAC,EAAE,cAAc,EAAE,CAAC,CAAC;IAEvD,kCAAkC;IAClC,MAAM,kBAAkB,GAAG,IAAA,0CAAwB,EAAC,KAAK,CAAC,CAAC;IAC3D,IAAI,kBAAkB,EAAE,CAAC;QACvB,MAAM,EAAE,KAAK,EAAE,GAAG,kBAAkB,CAAC;QACrC,mEAAmE;QACnE,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACnC,MAAM,KAAK,GAAU;YACnB,IAAI,EAAE,qBAAqB;YAC3B,KAAK,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,EAAE;YACnC,KAAK;SACN,CAAC;QACF,OAAO;YACL,MAAM,EAAE,CAAC,KAAK,CAAC;YACf,OAAO,EAAE,CAAC,GAAG,SAA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AC,cAAc,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IAED,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACzB,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACrC,MAAM,IAAA,oBAAS,EAAC,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;QACjE,CAAC;IACH,CAAC,CAAC,CACH,CAAC;IAEF,OAAO;QACL,MAAM;QACN,OAAO,EAAE,CAAC,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;QAC7F,YAAY,EAAE,CAAC,GAAG,cAAc,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;YACxE,IAAI;YACJ,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC;SACtB,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { type SourceMap } from "./types";
|
|
2
|
+
export declare const SOURCE_MARKER_PREFIX = "// embedex: ";
|
|
3
|
+
/**
|
|
4
|
+
* Strips the source marker line from content if it exists.
|
|
5
|
+
* This is needed when a file that is both a source and destination gets updated.
|
|
6
|
+
*/
|
|
7
|
+
export declare function stripSourceMarker(content: string): string;
|
|
2
8
|
export declare function createSourceMap(params: Readonly<{
|
|
3
9
|
cwd: string;
|
|
4
10
|
sourcesGlob: string;
|
|
@@ -1,27 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SOURCE_MARKER_PREFIX = void 0;
|
|
4
|
+
exports.stripSourceMarker = stripSourceMarker;
|
|
3
5
|
exports.createSourceMap = createSourceMap;
|
|
4
6
|
const promises_1 = require("node:fs/promises");
|
|
5
7
|
const node_path_1 = require("node:path");
|
|
6
8
|
const glob_1 = require("glob");
|
|
7
|
-
|
|
9
|
+
exports.SOURCE_MARKER_PREFIX = "// embedex: ";
|
|
10
|
+
/**
|
|
11
|
+
* Strips the source marker line from content if it exists.
|
|
12
|
+
* This is needed when a file that is both a source and destination gets updated.
|
|
13
|
+
*/
|
|
14
|
+
function stripSourceMarker(content) {
|
|
15
|
+
const [first, ...rest] = content.split("\n");
|
|
16
|
+
if (first?.startsWith(exports.SOURCE_MARKER_PREFIX)) {
|
|
17
|
+
return rest.join("\n");
|
|
18
|
+
}
|
|
19
|
+
return content;
|
|
20
|
+
}
|
|
8
21
|
async function createSourceMap(params) {
|
|
9
22
|
const { cwd, sourcesGlob } = params;
|
|
10
23
|
const sourceMap = new Map();
|
|
11
24
|
const paths = await (0, glob_1.glob)(sourcesGlob, { absolute: true, cwd, nodir: true });
|
|
12
|
-
|
|
25
|
+
await Promise.all(paths.map(async (path) => {
|
|
13
26
|
const content = await (0, promises_1.readFile)(path, "utf8");
|
|
14
27
|
const [first, ...rest] = content.split("\n");
|
|
15
|
-
if (first?.startsWith(SOURCE_MARKER_PREFIX)) {
|
|
28
|
+
if (first?.startsWith(exports.SOURCE_MARKER_PREFIX)) {
|
|
16
29
|
sourceMap.set(path, {
|
|
17
30
|
content: rest.join("\n"),
|
|
18
31
|
destinations: first
|
|
19
|
-
.replace(SOURCE_MARKER_PREFIX, "")
|
|
32
|
+
.replace(exports.SOURCE_MARKER_PREFIX, "")
|
|
20
33
|
.split(",")
|
|
21
|
-
.
|
|
34
|
+
.filter((t) => t.length > 0)
|
|
35
|
+
.map((t) => (0, node_path_1.resolve)(cwd, t.trim())),
|
|
22
36
|
});
|
|
23
37
|
}
|
|
24
|
-
}
|
|
38
|
+
}));
|
|
25
39
|
return sourceMap;
|
|
26
40
|
}
|
|
27
41
|
//# sourceMappingURL=createSourceMap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSourceMap.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib/internal/createSourceMap.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createSourceMap.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib/internal/createSourceMap.ts"],"names":[],"mappings":";;;AAcA,8CAOC;AAED,0CAyBC;AAhDD,+CAA4C;AAC5C,yCAAoC;AAEpC,+BAA4B;AAKf,QAAA,oBAAoB,GAAG,cAAc,CAAC;AAEnD;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,OAAe;IAC/C,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,KAAK,EAAE,UAAU,CAAC,4BAAoB,CAAC,EAAE,CAAC;QAC5C,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAEM,KAAK,UAAU,eAAe,CACnC,MAAsD;IAEtD,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IACpC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAsB,CAAC;IAChD,MAAM,KAAK,GAAG,MAAM,IAAA,WAAI,EAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAE5E,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACvB,MAAM,OAAO,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC7C,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,KAAK,EAAE,UAAU,CAAC,4BAAoB,CAAC,EAAE,CAAC;YAC5C,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE;gBAClB,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;gBACxB,YAAY,EAAE,KAAK;qBAChB,OAAO,CAAC,4BAAoB,EAAE,EAAE,CAAC;qBACjC,KAAK,CAAC,GAAG,CAAC;qBACV,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;qBAC3B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,mBAAO,EAAC,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;aACtC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { DestinationPath } from "../types";
|
|
2
|
+
import type { DestinationMap } from "./types";
|
|
3
|
+
export interface DependencyGraph {
|
|
4
|
+
dependencies: Map<DestinationPath, Set<DestinationPath>>;
|
|
5
|
+
destinations: Set<DestinationPath>;
|
|
6
|
+
}
|
|
7
|
+
interface CircularDependencyError {
|
|
8
|
+
cycle: DestinationPath[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Builds a dependency graph from source and destination maps.
|
|
12
|
+
*
|
|
13
|
+
* A destination B depends on destination A if:
|
|
14
|
+
* - B references A as a source in an embedex tag
|
|
15
|
+
* - A is also a destination (i.e., gets content embedded from other sources)
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // If A.ts embeds into B.md, and B.md embeds into C.md:
|
|
19
|
+
* // - B depends on A (must process A before B)
|
|
20
|
+
* // - C depends on B (must process B before C)
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildDependencyGraph(params: Readonly<{
|
|
23
|
+
destinationMap: Readonly<DestinationMap>;
|
|
24
|
+
}>): DependencyGraph;
|
|
25
|
+
/**
|
|
26
|
+
* Detects if there's a circular dependency in the graph.
|
|
27
|
+
*
|
|
28
|
+
* Uses depth-first search with cycle detection.
|
|
29
|
+
*
|
|
30
|
+
* @returns CircularDependencyError if a cycle exists, undefined otherwise
|
|
31
|
+
*/
|
|
32
|
+
export declare function detectCircularDependency(graph: Readonly<DependencyGraph>): CircularDependencyError | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Performs topological sort on the dependency graph using Kahn's algorithm.
|
|
35
|
+
*
|
|
36
|
+
* Returns destinations in an order such that if A depends on B, B appears before A.
|
|
37
|
+
*
|
|
38
|
+
* @throws Error if the graph has a cycle (should check with detectCircularDependency first)
|
|
39
|
+
*/
|
|
40
|
+
export declare function topologicalSort(graph: Readonly<DependencyGraph>): DestinationPath[];
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildDependencyGraph = buildDependencyGraph;
|
|
4
|
+
exports.detectCircularDependency = detectCircularDependency;
|
|
5
|
+
exports.topologicalSort = topologicalSort;
|
|
6
|
+
/**
|
|
7
|
+
* Builds a dependency graph from source and destination maps.
|
|
8
|
+
*
|
|
9
|
+
* A destination B depends on destination A if:
|
|
10
|
+
* - B references A as a source in an embedex tag
|
|
11
|
+
* - A is also a destination (i.e., gets content embedded from other sources)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // If A.ts embeds into B.md, and B.md embeds into C.md:
|
|
15
|
+
* // - B depends on A (must process A before B)
|
|
16
|
+
* // - C depends on B (must process B before C)
|
|
17
|
+
*/
|
|
18
|
+
function buildDependencyGraph(params) {
|
|
19
|
+
const { destinationMap } = params;
|
|
20
|
+
const destinations = new Set(destinationMap.keys());
|
|
21
|
+
const dependencies = new Map();
|
|
22
|
+
// Initialize empty dependency sets for all destinations
|
|
23
|
+
for (const destination of destinations) {
|
|
24
|
+
dependencies.set(destination, new Set());
|
|
25
|
+
}
|
|
26
|
+
// Build dependencies: for each destination, find which other destinations it depends on
|
|
27
|
+
for (const [destinationPath, { sources }] of destinationMap.entries()) {
|
|
28
|
+
for (const sourcePath of sources) {
|
|
29
|
+
// If this source is also a destination, then destinationPath depends on it
|
|
30
|
+
if (destinations.has(sourcePath)) {
|
|
31
|
+
dependencies.get(destinationPath).add(sourcePath);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return { dependencies, destinations };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Detects if there's a circular dependency in the graph.
|
|
39
|
+
*
|
|
40
|
+
* Uses depth-first search with cycle detection.
|
|
41
|
+
*
|
|
42
|
+
* @returns CircularDependencyError if a cycle exists, undefined otherwise
|
|
43
|
+
*/
|
|
44
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
45
|
+
function detectCircularDependency(graph) {
|
|
46
|
+
const { dependencies, destinations } = graph;
|
|
47
|
+
// Track visited state: 0 = unvisited, 1 = visiting (in current path), 2 = visited (fully processed)
|
|
48
|
+
const visited = new Map();
|
|
49
|
+
for (const destination of destinations) {
|
|
50
|
+
visited.set(destination, 0);
|
|
51
|
+
}
|
|
52
|
+
const path = [];
|
|
53
|
+
let cycleNode;
|
|
54
|
+
function hasCycle(node) {
|
|
55
|
+
const state = visited.get(node);
|
|
56
|
+
if (state === 1) {
|
|
57
|
+
// Found a cycle - node is in current path
|
|
58
|
+
cycleNode = node;
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
if (state === 2) {
|
|
62
|
+
// Already fully processed this node
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
// Mark as visiting
|
|
66
|
+
visited.set(node, 1);
|
|
67
|
+
path.push(node);
|
|
68
|
+
// Check all dependencies
|
|
69
|
+
const deps = dependencies.get(node);
|
|
70
|
+
/* istanbul ignore next */
|
|
71
|
+
if (deps) {
|
|
72
|
+
for (const dependency of deps) {
|
|
73
|
+
if (hasCycle(dependency)) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Mark as fully visited
|
|
79
|
+
visited.set(node, 2);
|
|
80
|
+
path.pop();
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
// Check each node (to handle disconnected components)
|
|
84
|
+
for (const destination of destinations) {
|
|
85
|
+
if (visited.get(destination) === 0 && hasCycle(destination)) {
|
|
86
|
+
// Extract the cycle from the path
|
|
87
|
+
// cycleNode is the node that was already being visited when we encountered it again
|
|
88
|
+
/* istanbul ignore next */
|
|
89
|
+
if (!cycleNode) {
|
|
90
|
+
return { cycle: [] };
|
|
91
|
+
}
|
|
92
|
+
// Find where this node first appeared in the path
|
|
93
|
+
const cycleStart = path.indexOf(cycleNode);
|
|
94
|
+
// The cycle is from cycleStart to the end, plus the cycleNode again to show the loop
|
|
95
|
+
const cycle = [...path.slice(cycleStart), cycleNode];
|
|
96
|
+
return { cycle };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Performs topological sort on the dependency graph using Kahn's algorithm.
|
|
103
|
+
*
|
|
104
|
+
* Returns destinations in an order such that if A depends on B, B appears before A.
|
|
105
|
+
*
|
|
106
|
+
* @throws Error if the graph has a cycle (should check with detectCircularDependency first)
|
|
107
|
+
*/
|
|
108
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
109
|
+
function topologicalSort(graph) {
|
|
110
|
+
const { dependencies, destinations } = graph;
|
|
111
|
+
// Calculate in-degree (number of dependencies) for each node
|
|
112
|
+
const inDegree = new Map();
|
|
113
|
+
for (const destination of destinations) {
|
|
114
|
+
inDegree.set(destination, dependencies.get(destination).size);
|
|
115
|
+
}
|
|
116
|
+
// Build reverse adjacency map: for each node, track which nodes depend on it
|
|
117
|
+
// This allows O(out-degree) updates instead of O(E) per dequeue
|
|
118
|
+
const dependents = new Map();
|
|
119
|
+
for (const destination of destinations) {
|
|
120
|
+
dependents.set(destination, new Set());
|
|
121
|
+
}
|
|
122
|
+
for (const [destination, deps] of dependencies.entries()) {
|
|
123
|
+
for (const dependency of deps) {
|
|
124
|
+
dependents.get(dependency).add(destination);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Queue of nodes with no dependencies
|
|
128
|
+
const queue = [];
|
|
129
|
+
for (const [destination, degree] of inDegree.entries()) {
|
|
130
|
+
if (degree === 0) {
|
|
131
|
+
queue.push(destination);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const result = [];
|
|
135
|
+
// Process nodes with no dependencies
|
|
136
|
+
while (queue.length > 0) {
|
|
137
|
+
const current = queue.shift();
|
|
138
|
+
result.push(current);
|
|
139
|
+
// For each node that depends on current, decrease its in-degree
|
|
140
|
+
const nodeDependents = dependents.get(current);
|
|
141
|
+
/* istanbul ignore next */
|
|
142
|
+
if (nodeDependents) {
|
|
143
|
+
for (const dependent of nodeDependents) {
|
|
144
|
+
const newDegree = inDegree.get(dependent) - 1;
|
|
145
|
+
inDegree.set(dependent, newDegree);
|
|
146
|
+
if (newDegree === 0) {
|
|
147
|
+
queue.push(dependent);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// If we didn't process all nodes, there's a cycle
|
|
153
|
+
/* istanbul ignore next */
|
|
154
|
+
if (result.length !== destinations.size) {
|
|
155
|
+
throw new Error("Graph has a cycle - should be detected before calling topologicalSort");
|
|
156
|
+
}
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=dependencyGraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependencyGraph.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib/internal/dependencyGraph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AC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAsB,EAAE,CAAC;IAErC,qCAAqC;IACrC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,EAAG,CAAC;QAC/B,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAErB,gEAAgE;QAChE,MAAM,cAAc,GAAG,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC/C,0BAA0B;QAC1B,IAAI,cAAc,EAAE,CAAC;YACnB,KAAK,MAAM,SAAS,IAAI,cAAc,EAAE,CAAC;gBACvC,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAE,GAAG,CAAC,CAAC;gBAC/C,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;gBAEnC,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;oBACpB,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBACxB,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,kDAAkD;IAClD,0BAA0B;IAC1B,IAAI,MAAM,CAAC,MAAM,KAAK,YAAY,CAAC,IAAI,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAC;IAC3F,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.processDestinations = processDestinations;
|
|
4
4
|
const node_path_1 = require("node:path");
|
|
5
|
+
const createSourceMap_1 = require("./createSourceMap");
|
|
5
6
|
const CODE_FENCE_ID_BY_FILE_EXTENSION = {
|
|
6
7
|
cjs: "js",
|
|
7
8
|
cts: "ts",
|
|
@@ -14,47 +15,113 @@ const CODE_FENCE_ID_BY_FILE_EXTENSION = {
|
|
|
14
15
|
ts: "ts",
|
|
15
16
|
tsx: "ts",
|
|
16
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* A regex to match the embedex tag.
|
|
20
|
+
*
|
|
21
|
+
* Matching groups:
|
|
22
|
+
* 1. The block's prefix
|
|
23
|
+
* 2. The source file path
|
|
24
|
+
*/
|
|
25
|
+
const REGEX = /^(.*)<embedex source="(.+?)">\r?\n[\S\s]*?<\/embedex>/gm;
|
|
17
26
|
function processDestinations(params) {
|
|
18
|
-
const { cwd, destinationMap, sourceMap } = params;
|
|
27
|
+
const { cwd, destinationMap, sourceMap, updatedContentMap } = params;
|
|
19
28
|
const result = [];
|
|
20
29
|
for (const entry of destinationMap.entries()) {
|
|
21
|
-
|
|
30
|
+
const childParams = { cwd, entry, sourceMap };
|
|
31
|
+
/* istanbul ignore else */
|
|
32
|
+
if (updatedContentMap) {
|
|
33
|
+
childParams.updatedContentMap = updatedContentMap;
|
|
34
|
+
}
|
|
35
|
+
result.push(processDestination(childParams));
|
|
22
36
|
}
|
|
23
37
|
return result;
|
|
24
38
|
}
|
|
39
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
25
40
|
function processDestination(params) {
|
|
26
|
-
const { cwd, sourceMap, entry } = params;
|
|
27
|
-
const [destination, { content, sources }] = entry;
|
|
41
|
+
const { cwd, sourceMap, entry, updatedContentMap } = params;
|
|
42
|
+
const [destination, { content: originalContent, sources }] = entry;
|
|
43
|
+
// Use updated content if available (from earlier processing in dependency order),
|
|
44
|
+
// otherwise use the original content from disk
|
|
45
|
+
// Strip source marker from updated content to ensure clean processing
|
|
46
|
+
/* istanbul ignore next - defensive: destination typically not in updatedContentMap during processing */
|
|
47
|
+
let content = updatedContentMap?.has(destination)
|
|
48
|
+
? (0, createSourceMap_1.stripSourceMarker)(updatedContentMap.get(destination))
|
|
49
|
+
: originalContent;
|
|
50
|
+
// Normalize CRLF to LF to ensure consistent processing across platforms
|
|
51
|
+
content = content.replaceAll("\r\n", "\n");
|
|
28
52
|
function absolutePath(path) {
|
|
29
|
-
return (0, node_path_1.
|
|
53
|
+
return (0, node_path_1.resolve)(cwd, path);
|
|
54
|
+
}
|
|
55
|
+
// First, check for invalid source references and collect referenced sources
|
|
56
|
+
const allEmbedexTags = [...content.matchAll(REGEX)];
|
|
57
|
+
const invalidSources = [];
|
|
58
|
+
const referencedSources = new Set();
|
|
59
|
+
for (const match of allEmbedexTags) {
|
|
60
|
+
const sourcePath = match[2];
|
|
61
|
+
/* istanbul ignore next */
|
|
62
|
+
if (sourcePath) {
|
|
63
|
+
const absoluteSourcePath = absolutePath(sourcePath);
|
|
64
|
+
if (sources.has(absoluteSourcePath)) {
|
|
65
|
+
referencedSources.add(absoluteSourcePath);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
invalidSources.push(absoluteSourcePath);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (invalidSources.length > 0) {
|
|
73
|
+
return {
|
|
74
|
+
code: "INVALID_SOURCE",
|
|
75
|
+
paths: { destination, sources: [] },
|
|
76
|
+
invalidSources,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// Check for unreferenced sources (sources that declare this destination but have no embedex tag)
|
|
80
|
+
const unreferencedSources = [];
|
|
81
|
+
for (const source of sources) {
|
|
82
|
+
if (!referencedSources.has(source)) {
|
|
83
|
+
unreferencedSources.push(source);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (unreferencedSources.length > 0) {
|
|
87
|
+
return {
|
|
88
|
+
code: "UNREFERENCED_SOURCE",
|
|
89
|
+
paths: { destination, sources: [] },
|
|
90
|
+
unreferencedSources,
|
|
91
|
+
};
|
|
30
92
|
}
|
|
31
93
|
const matches = matchAll({ content, exists: (source) => sources.has(absolutePath(source)) });
|
|
94
|
+
/* istanbul ignore next */
|
|
32
95
|
if (matches.length === 0) {
|
|
33
96
|
return { code: "NO_MATCH", paths: { destination, sources: [] } };
|
|
34
97
|
}
|
|
98
|
+
// Deduplicate matches to avoid replacing identical tags multiple times with replaceAll
|
|
99
|
+
const uniqueMatches = [...new Map(matches.map((m) => [m.fullMatch, m])).values()];
|
|
35
100
|
let updatedContent = content;
|
|
36
|
-
for (const { fullMatch, prefix, sourcePath } of
|
|
37
|
-
const
|
|
38
|
-
|
|
101
|
+
for (const { fullMatch, prefix, sourcePath } of uniqueMatches) {
|
|
102
|
+
const absoluteSourcePath = absolutePath(sourcePath);
|
|
103
|
+
const sourceFromMap = sourceMap.get(absoluteSourcePath);
|
|
104
|
+
// If the source is also a destination that was updated earlier, use its updated content
|
|
105
|
+
// and strip the source marker line if present
|
|
106
|
+
let sourceContent = updatedContentMap?.get(absoluteSourcePath) ?? sourceFromMap.content;
|
|
107
|
+
if (updatedContentMap?.has(absoluteSourcePath)) {
|
|
108
|
+
sourceContent = (0, createSourceMap_1.stripSourceMarker)(sourceContent);
|
|
109
|
+
}
|
|
110
|
+
// Normalize CRLF to LF to ensure consistent processing
|
|
111
|
+
sourceContent = sourceContent.replaceAll("\r\n", "\n");
|
|
112
|
+
updatedContent = updatedContent.replaceAll(fullMatch, createReplacement({ content: sourceContent, sourcePath, prefix }));
|
|
39
113
|
}
|
|
40
|
-
const paths = { sources:
|
|
114
|
+
const paths = { sources: uniqueMatches.map((m) => absolutePath(m.sourcePath)), destination };
|
|
41
115
|
return content === updatedContent
|
|
42
116
|
? { code: "NO_CHANGE", paths }
|
|
43
117
|
: { code: "UPDATE", paths, updatedContent };
|
|
44
118
|
}
|
|
45
|
-
/**
|
|
46
|
-
* A regex to match the embedex tag.
|
|
47
|
-
*
|
|
48
|
-
* Matching groups:
|
|
49
|
-
* 1. The block's prefix
|
|
50
|
-
* 2. The source file path
|
|
51
|
-
*/
|
|
52
|
-
const REGEX = /^(.*)<embedex source="(.+?)">\n[\S\s]*?<\/embedex>/gm;
|
|
53
119
|
function matchAll(params) {
|
|
54
120
|
const { content, exists } = params;
|
|
55
121
|
return [...content.matchAll(REGEX)]
|
|
56
122
|
.map((match) => {
|
|
57
123
|
const [fullMatch, prefix, sourcePath] = match;
|
|
124
|
+
/* istanbul ignore next */
|
|
58
125
|
return isDefined(fullMatch) &&
|
|
59
126
|
isDefined(prefix) &&
|
|
60
127
|
isDefined(sourcePath) &&
|
|
@@ -69,12 +136,18 @@ function createReplacement(params) {
|
|
|
69
136
|
const contentHasCodeFence = content.includes("```");
|
|
70
137
|
const backticks = contentHasCodeFence ? "````" : "```";
|
|
71
138
|
const codeFenceId = CODE_FENCE_ID_BY_FILE_EXTENSION[(0, node_path_1.extname)(sourcePath).slice(1)];
|
|
72
|
-
|
|
139
|
+
// Only escape */ when embedding into comment blocks (e.g., JSDoc)
|
|
140
|
+
// to prevent breaking the comment. Don't escape in Markdown.
|
|
141
|
+
const isInCommentBlock = /^\s*\*/.test(prefix);
|
|
142
|
+
let processedContent = content.trimEnd();
|
|
143
|
+
if (isInCommentBlock) {
|
|
144
|
+
processedContent = processedContent.replaceAll("*/", "*\\/");
|
|
145
|
+
}
|
|
73
146
|
// For markdown files, strip nested embedex tags to prevent recursive processing
|
|
74
147
|
if (codeFenceId === "") {
|
|
75
148
|
processedContent = processedContent
|
|
76
|
-
.replaceAll(/^(.*)<embedex source=".+?">\n([\S\s]*?)<\/embedex>/gm, (_match, _prefix, content) => {
|
|
77
|
-
const lines = content.split(
|
|
149
|
+
.replaceAll(/^(.*)<embedex source=".+?">\r?\n([\S\s]*?)<\/embedex>/gm, (_match, _prefix, content) => {
|
|
150
|
+
const lines = content.split(/\r?\n/);
|
|
78
151
|
// Remove leading blank lines
|
|
79
152
|
while (lines.length > 0 && lines[0]?.trim() === "") {
|
|
80
153
|
lines.shift();
|
|
@@ -88,7 +161,7 @@ function createReplacement(params) {
|
|
|
88
161
|
})
|
|
89
162
|
.trim();
|
|
90
163
|
}
|
|
91
|
-
const contentLines = processedContent.split(
|
|
164
|
+
const contentLines = processedContent.split(/\r?\n/);
|
|
92
165
|
const lines = [
|
|
93
166
|
`<embedex source="${sourcePath}">`,
|
|
94
167
|
"",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processDestinations.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib/internal/processDestinations.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"processDestinations.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib/internal/processDestinations.ts"],"names":[],"mappings":";;AA4BA,kDA2BC;AAvDD,yCAA6C;AAG7C,uDAAsD;AAGtD,MAAM,+BAA+B,GAAqC;IACxE,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,EAAE,EAAE,IAAI;IACR,GAAG,EAAE,IAAI;IACT,EAAE,EAAE,EAAE;IACN,GAAG,EAAE,EAAE;IACP,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,EAAE,EAAE,IAAI;IACR,GAAG,EAAE,IAAI;CACD,CAAC;AAEX;;;;;;GAMG;AACH,MAAM,KAAK,GAAG,yDAAyD,CAAC;AAExE,SAAgB,mBAAmB,CACjC,MAKE;IAEF,MAAM,EAAE,GAAG,EAAE,cAAc,EAAE,SAAS,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAErE,MAAM,MAAM,GAAY,EAAE,CAAC;IAC3B,KAAK,MAAM,KAAK,IAAI,cAAc,CAAC,OAAO,EAAE,EAAE,CAAC;QAC7C,MAAM,WAAW,GAKb,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;QAC9B,0BAA0B;QAC1B,IAAI,iBAAiB,EAAE,CAAC;YACtB,WAAW,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QACpD,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,wDAAwD;AACxD,SAAS,kBAAkB,CAAC,MAK3B;IACC,MAAM,EAAE,GAAG,EAAE,SAAS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|
8
|
-
export type Code = "NO_CHANGE" | "NO_MATCH" | "UPDATE";
|
|
8
|
+
export type Code = "NO_CHANGE" | "NO_MATCH" | "UPDATE" | "INVALID_SOURCE" | "UNREFERENCED_SOURCE" | "CIRCULAR_DEPENDENCY";
|
|
9
9
|
export interface Result {
|
|
10
10
|
code: Code;
|
|
11
11
|
paths: {
|
|
@@ -23,7 +23,19 @@ export type Updated = Result & {
|
|
|
23
23
|
code: "UPDATE";
|
|
24
24
|
updatedContent: string;
|
|
25
25
|
};
|
|
26
|
-
export type
|
|
26
|
+
export type InvalidSource = Result & {
|
|
27
|
+
code: "INVALID_SOURCE";
|
|
28
|
+
invalidSources: string[];
|
|
29
|
+
};
|
|
30
|
+
export type UnreferencedSource = Result & {
|
|
31
|
+
code: "UNREFERENCED_SOURCE";
|
|
32
|
+
unreferencedSources: string[];
|
|
33
|
+
};
|
|
34
|
+
export type CircularDependency = Result & {
|
|
35
|
+
code: "CIRCULAR_DEPENDENCY";
|
|
36
|
+
cycle: string[];
|
|
37
|
+
};
|
|
38
|
+
export type Embed = NoMatch | Updated | NoChange | InvalidSource | UnreferencedSource | CircularDependency;
|
|
27
39
|
export interface EmbedResult {
|
|
28
40
|
embeds: Embed[];
|
|
29
41
|
sources: Array<{
|