embedex 0.18.2 → 1.0.0

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 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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "embedex",
3
3
  "description": "Embed shared text and code snippets from source files into destination files.",
4
- "version": "0.18.2",
4
+ "version": "1.0.0",
5
5
  "bin": {
6
6
  "embedex": "./src/bin/cli.js"
7
7
  },
@@ -3,16 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dim = dim;
4
4
  exports.processResult = processResult;
5
5
  const tslib_1 = require("tslib");
6
- const node_path_1 = require("node:path");
6
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
7
7
  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;
14
- function relative(path) {
15
- return (0, node_path_1.relative)(cwd, path);
22
+ function relative(filePath) {
23
+ return node_path_1.default.relative(cwd, filePath);
16
24
  }
17
25
  function format(item) {
18
26
  const items = "destinations" in item ? item.destinations : item.sources;
@@ -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 "NO_CHANGE": {
36
- output.push(toOutput({ isError: false }));
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 "NO_MATCH": {
40
- output.push(toOutput({ isError: true }));
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
- output.push(toOutput({ isError: check }));
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: `${yoctocolors_cjs_1.default.green(code)} ${yoctocolors_cjs_1.default.gray(destination)} -> ${yoctocolors_cjs_1.default.gray(sources.join(", "))}`,
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;AAED,sCAoDC;;AApED,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,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,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,C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BACR,MAAM,eAAe,GAAU,IAAI,CAAC;gBACpC,MAAM,IAAI,KAAK,CAAC,yBAAyB,MAAM,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;YACtE,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,cAAc,CAAC,MAAsD;IAC5E,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IAC/B,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAEvC,OAAO,CAAC,EAAE,OAAO,EAAwB,EAAE,EAAE,CAAC,CAAC;QAC7C,IAAI;QACJ,OAAO;QACP,OAAO,EAAE,YAAY,CAAC;YACpB,IAAI;YACJ,OAAO;YACP,WAAW;YACX,MAAM,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG;SACtD,CAAC;KACH,CAAC,CAAC;AACL,CAAC"}
package/src/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export * from "./lib/embed";
2
- export * from "./lib/types";
2
+ export type * from "./lib/types";
package/src/index.js CHANGED
@@ -2,5 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./lib/embed"), exports);
5
- tslib_1.__exportStar(require("./lib/types"), exports);
6
5
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/embedex/src/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,sDAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/embedex/src/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B"}
@@ -1,5 +1,10 @@
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,65 @@ 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
- const embeds = (0, processDestinations_1.processDestinations)({ cwd, sourceMap, destinationMap });
21
+ // Build dependency graph to determine processing order
22
+ const graph = (0, dependencyGraph_1.buildDependencyGraph)({ destinationMap });
23
+ const circularDependency = (0, dependencyGraph_1.detectCircularDependency)(graph);
24
+ if (circularDependency) {
25
+ const { cycle } = circularDependency;
26
+ /* istanbul ignore next - cycle[0] is always defined in practice */
27
+ const destination = cycle[0] ?? "";
28
+ const embed = {
29
+ code: "CIRCULAR_DEPENDENCY",
30
+ paths: { destination, sources: [] },
31
+ cycle,
32
+ };
33
+ return {
34
+ embeds: [embed],
35
+ sources: [...sourceMap.entries()].map(([path, { destinations }]) => ({ path, destinations })),
36
+ destinations: [...destinationMap.entries()].map(([path, { sources }]) => ({
37
+ path,
38
+ sources: [...sources],
39
+ })),
40
+ };
41
+ }
42
+ // Process destinations in dependency order, tracking updated content
43
+ const updatedContentMap = new Map();
44
+ const embeds = (0, dependencyGraph_1.topologicalSort)(graph).flatMap((destinationPath) => {
45
+ const destinationEntry = destinationMap.get(destinationPath);
46
+ /* istanbul ignore next: sanity check */
47
+ if (!destinationEntry) {
48
+ return [];
49
+ }
50
+ const [embed] = (0, processDestinations_1.processDestinations)({
51
+ cwd,
52
+ sourceMap,
53
+ destinationMap: new Map([[destinationPath, destinationEntry]]),
54
+ updatedContentMap,
55
+ });
56
+ /* istanbul ignore next: sanity check */
57
+ if (!embed) {
58
+ return [];
59
+ }
60
+ // Track updated content for chained embeds
61
+ if (embed.code === "UPDATE") {
62
+ updatedContentMap.set(destinationPath, embed.updatedContent);
63
+ }
64
+ return [embed];
65
+ });
16
66
  await Promise.all(embeds.map(async (embed) => {
17
67
  if (write && embed.code === "UPDATE") {
18
68
  await (0, promises_1.writeFile)(embed.paths.destination, embed.updatedContent);
@@ -1 +1 @@
1
- {"version":3,"file":"embed.js","sourceRoot":"","sources":["../../../../../packages/embedex/src/lib/embed.ts"],"names":[],"mappings":";;AAUA,sBAuBC;AAjCD,+CAA6C;AAE7C,0EAAuE;AACvE,gEAA6D;AAC7D,wEAAqE;AAGrE;;GAEG;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,2CA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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,42 @@
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;
6
+ const tslib_1 = require("tslib");
4
7
  const promises_1 = require("node:fs/promises");
5
- const node_path_1 = require("node:path");
8
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
6
9
  const glob_1 = require("glob");
7
- const SOURCE_MARKER_PREFIX = "// ";
10
+ exports.SOURCE_MARKER_PREFIX = "// embedex: ";
11
+ /**
12
+ * Strips the source marker line from content if it exists.
13
+ * This is needed when a file that is both a source and destination gets updated.
14
+ */
15
+ function stripSourceMarker(content) {
16
+ const [first, ...rest] = content.split("\n");
17
+ if (first?.startsWith(exports.SOURCE_MARKER_PREFIX)) {
18
+ return rest.join("\n");
19
+ }
20
+ return content;
21
+ }
8
22
  async function createSourceMap(params) {
9
23
  const { cwd, sourcesGlob } = params;
10
24
  const sourceMap = new Map();
11
25
  const paths = await (0, glob_1.glob)(sourcesGlob, { absolute: true, cwd, nodir: true });
12
- for await (const path of paths) {
13
- const content = await (0, promises_1.readFile)(path, "utf8");
26
+ await Promise.all(paths.map(async (filePath) => {
27
+ const content = await (0, promises_1.readFile)(filePath, "utf8");
14
28
  const [first, ...rest] = content.split("\n");
15
- if (first?.startsWith(SOURCE_MARKER_PREFIX)) {
16
- sourceMap.set(path, {
29
+ if (first?.startsWith(exports.SOURCE_MARKER_PREFIX)) {
30
+ sourceMap.set(filePath, {
17
31
  content: rest.join("\n"),
18
32
  destinations: first
19
- .replace(SOURCE_MARKER_PREFIX, "")
33
+ .replace(exports.SOURCE_MARKER_PREFIX, "")
20
34
  .split(",")
21
- .map((t) => (0, node_path_1.join)(cwd, t.trim())),
35
+ .filter((t) => t.length > 0)
36
+ .map((t) => node_path_1.default.resolve(cwd, t.trim())),
22
37
  });
23
38
  }
24
- }
39
+ }));
25
40
  return sourceMap;
26
41
  }
27
42
  //# sourceMappingURL=createSourceMap.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createSourceMap.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib/internal/createSourceMap.ts"],"names":[],"mappings":";;AAUA,0CAsBC;AAhCD,+CAA4C;AAC5C,yCAAiC;AAEjC,+BAA4B;AAK5B,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAE5B,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,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC/B,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,oBAAoB,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,oBAAoB,EAAE,EAAE,CAAC;qBACjC,KAAK,CAAC,GAAG,CAAC;qBACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,gBAAI,EAAC,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;aACnC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
1
+ {"version":3,"file":"createSourceMap.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib/internal/createSourceMap.ts"],"names":[],"mappings":";;;AAcA,8CAOC;AAED,0CAyBC;;AAhDD,+CAA4C;AAC5C,kEAA6B;AAE7B,+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,QAAQ,EAAE,EAAE;QAC3B,MAAM,OAAO,GAAG,MAAM,IAAA,mBAAQ,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACjD,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,QAAQ,EAAE;gBACtB,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,mBAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;aAC3C,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,158 @@
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
+ function detectCircularDependency(graph) {
45
+ const { dependencies, destinations } = graph;
46
+ // Track visited state: 0 = unvisited, 1 = visiting (in current path), 2 = visited (fully processed)
47
+ const visited = new Map();
48
+ for (const destination of destinations) {
49
+ visited.set(destination, 0);
50
+ }
51
+ const path = [];
52
+ let cycleNode;
53
+ function hasCycle(node) {
54
+ const state = visited.get(node);
55
+ if (state === 1) {
56
+ // Found a cycle - node is in current path
57
+ cycleNode = node;
58
+ return true;
59
+ }
60
+ if (state === 2) {
61
+ // Already fully processed this node
62
+ return false;
63
+ }
64
+ // Mark as visiting
65
+ visited.set(node, 1);
66
+ path.push(node);
67
+ // Check all dependencies
68
+ const deps = dependencies.get(node);
69
+ /* istanbul ignore next */
70
+ if (deps) {
71
+ for (const dependency of deps) {
72
+ if (hasCycle(dependency)) {
73
+ return true;
74
+ }
75
+ }
76
+ }
77
+ // Mark as fully visited
78
+ visited.set(node, 2);
79
+ path.pop();
80
+ return false;
81
+ }
82
+ // Check each node (to handle disconnected components)
83
+ for (const destination of destinations) {
84
+ if (visited.get(destination) === 0 && hasCycle(destination)) {
85
+ // Extract the cycle from the path
86
+ // cycleNode is the node that was already being visited when we encountered it again
87
+ /* istanbul ignore next */
88
+ if (!cycleNode) {
89
+ return { cycle: [] };
90
+ }
91
+ // Find where this node first appeared in the path
92
+ const cycleStart = path.indexOf(cycleNode);
93
+ // The cycle is from cycleStart to the end, plus the cycleNode again to show the loop
94
+ const cycle = [...path.slice(cycleStart), cycleNode];
95
+ return { cycle };
96
+ }
97
+ }
98
+ return undefined;
99
+ }
100
+ /**
101
+ * Performs topological sort on the dependency graph using Kahn's algorithm.
102
+ *
103
+ * Returns destinations in an order such that if A depends on B, B appears before A.
104
+ *
105
+ * @throws Error if the graph has a cycle (should check with detectCircularDependency first)
106
+ */
107
+ // eslint-disable-next-line sonarjs/cognitive-complexity
108
+ function topologicalSort(graph) {
109
+ const { dependencies, destinations } = graph;
110
+ // Calculate in-degree (number of dependencies) for each node
111
+ const inDegree = new Map();
112
+ for (const destination of destinations) {
113
+ inDegree.set(destination, dependencies.get(destination).size);
114
+ }
115
+ // Build reverse adjacency map: for each node, track which nodes depend on it
116
+ // This allows O(out-degree) updates instead of O(E) per dequeue
117
+ const dependents = new Map();
118
+ for (const destination of destinations) {
119
+ dependents.set(destination, new Set());
120
+ }
121
+ for (const [destination, deps] of dependencies.entries()) {
122
+ for (const dependency of deps) {
123
+ dependents.get(dependency).add(destination);
124
+ }
125
+ }
126
+ // Queue of nodes with no dependencies
127
+ const queue = [];
128
+ for (const [destination, degree] of inDegree.entries()) {
129
+ if (degree === 0) {
130
+ queue.push(destination);
131
+ }
132
+ }
133
+ const result = [];
134
+ // Process nodes with no dependencies
135
+ while (queue.length > 0) {
136
+ const current = queue.shift();
137
+ result.push(current);
138
+ // For each node that depends on current, decrease its in-degree
139
+ const nodeDependents = dependents.get(current);
140
+ /* istanbul ignore next */
141
+ if (nodeDependents) {
142
+ for (const dependent of nodeDependents) {
143
+ const newDegree = inDegree.get(dependent) - 1;
144
+ inDegree.set(dependent, newDegree);
145
+ if (newDegree === 0) {
146
+ queue.push(dependent);
147
+ }
148
+ }
149
+ }
150
+ }
151
+ // If we didn't process all nodes, there's a cycle
152
+ /* istanbul ignore next */
153
+ if (result.length !== destinations.size) {
154
+ throw new Error("Graph has a cycle - should be detected before calling topologicalSort");
155
+ }
156
+ return result;
157
+ }
158
+ //# sourceMappingURL=dependencyGraph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependencyGraph.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib/internal/dependencyGraph.ts"],"names":[],"mappings":";;AA2BA,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AC;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"}
@@ -4,4 +4,5 @@ export declare function processDestinations(params: Readonly<{
4
4
  cwd: string;
5
5
  sourceMap: Readonly<SourceMap>;
6
6
  destinationMap: Readonly<DestinationMap>;
7
+ updatedContentMap?: ReadonlyMap<string, string>;
7
8
  }>): Embed[];
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processDestinations = processDestinations;
4
- const node_path_1 = require("node:path");
4
+ const tslib_1 = require("tslib");
5
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
6
+ const createSourceMap_1 = require("./createSourceMap");
5
7
  const CODE_FENCE_ID_BY_FILE_EXTENSION = {
6
8
  cjs: "js",
7
9
  cts: "ts",
@@ -14,47 +16,113 @@ const CODE_FENCE_ID_BY_FILE_EXTENSION = {
14
16
  ts: "ts",
15
17
  tsx: "ts",
16
18
  };
19
+ /**
20
+ * A regex to match the embedex tag.
21
+ *
22
+ * Matching groups:
23
+ * 1. The block's prefix
24
+ * 2. The source file path
25
+ */
26
+ const REGEX = /^(.*)<embedex source="(.+?)">\r?\n[\S\s]*?<\/embedex>/gm;
17
27
  function processDestinations(params) {
18
- const { cwd, destinationMap, sourceMap } = params;
28
+ const { cwd, destinationMap, sourceMap, updatedContentMap } = params;
19
29
  const result = [];
20
30
  for (const entry of destinationMap.entries()) {
21
- result.push(processDestination({ cwd, entry, sourceMap }));
31
+ const childParams = { cwd, entry, sourceMap };
32
+ /* istanbul ignore else */
33
+ if (updatedContentMap) {
34
+ childParams.updatedContentMap = updatedContentMap;
35
+ }
36
+ result.push(processDestination(childParams));
22
37
  }
23
38
  return result;
24
39
  }
40
+ // eslint-disable-next-line sonarjs/cognitive-complexity
25
41
  function processDestination(params) {
26
- const { cwd, sourceMap, entry } = params;
27
- const [destination, { content, sources }] = entry;
28
- function absolutePath(path) {
29
- return (0, node_path_1.join)(cwd, path);
42
+ const { cwd, sourceMap, entry, updatedContentMap } = params;
43
+ const [destination, { content: originalContent, sources }] = entry;
44
+ // Use updated content if available (from earlier processing in dependency order),
45
+ // otherwise use the original content from disk
46
+ // Strip source marker from updated content to ensure clean processing
47
+ /* istanbul ignore next - defensive: destination typically not in updatedContentMap during processing */
48
+ let content = updatedContentMap?.has(destination)
49
+ ? (0, createSourceMap_1.stripSourceMarker)(updatedContentMap.get(destination))
50
+ : originalContent;
51
+ // Normalize CRLF to LF to ensure consistent processing across platforms
52
+ content = content.replaceAll("\r\n", "\n");
53
+ function absolutePath(filePath) {
54
+ return node_path_1.default.resolve(cwd, filePath);
55
+ }
56
+ // First, check for invalid source references and collect referenced sources
57
+ const allEmbedexTags = [...content.matchAll(REGEX)];
58
+ const invalidSources = [];
59
+ const referencedSources = new Set();
60
+ for (const match of allEmbedexTags) {
61
+ const sourcePath = match[2];
62
+ /* istanbul ignore next */
63
+ if (sourcePath) {
64
+ const absoluteSourcePath = absolutePath(sourcePath);
65
+ if (sources.has(absoluteSourcePath)) {
66
+ referencedSources.add(absoluteSourcePath);
67
+ }
68
+ else {
69
+ invalidSources.push(absoluteSourcePath);
70
+ }
71
+ }
72
+ }
73
+ if (invalidSources.length > 0) {
74
+ return {
75
+ code: "INVALID_SOURCE",
76
+ paths: { destination, sources: [] },
77
+ invalidSources,
78
+ };
79
+ }
80
+ // Check for unreferenced sources (sources that declare this destination but have no embedex tag)
81
+ const unreferencedSources = [];
82
+ for (const source of sources) {
83
+ if (!referencedSources.has(source)) {
84
+ unreferencedSources.push(source);
85
+ }
86
+ }
87
+ if (unreferencedSources.length > 0) {
88
+ return {
89
+ code: "UNREFERENCED_SOURCE",
90
+ paths: { destination, sources: [] },
91
+ unreferencedSources,
92
+ };
30
93
  }
31
94
  const matches = matchAll({ content, exists: (source) => sources.has(absolutePath(source)) });
95
+ /* istanbul ignore next */
32
96
  if (matches.length === 0) {
33
97
  return { code: "NO_MATCH", paths: { destination, sources: [] } };
34
98
  }
99
+ // Deduplicate matches to avoid replacing identical tags multiple times with replaceAll
100
+ const uniqueMatches = [...new Map(matches.map((m) => [m.fullMatch, m])).values()];
35
101
  let updatedContent = content;
36
- for (const { fullMatch, prefix, sourcePath } of matches) {
37
- const { content } = sourceMap.get(absolutePath(sourcePath));
38
- updatedContent = updatedContent.replaceAll(fullMatch, createReplacement({ content, sourcePath, prefix }));
102
+ for (const { fullMatch, prefix, sourcePath } of uniqueMatches) {
103
+ const absoluteSourcePath = absolutePath(sourcePath);
104
+ const sourceFromMap = sourceMap.get(absoluteSourcePath);
105
+ // If the source is also a destination that was updated earlier, use its updated content
106
+ // and strip the source marker line if present
107
+ let sourceContent = updatedContentMap?.get(absoluteSourcePath) ?? sourceFromMap.content;
108
+ if (updatedContentMap?.has(absoluteSourcePath)) {
109
+ sourceContent = (0, createSourceMap_1.stripSourceMarker)(sourceContent);
110
+ }
111
+ // Normalize CRLF to LF to ensure consistent processing
112
+ sourceContent = sourceContent.replaceAll("\r\n", "\n");
113
+ updatedContent = updatedContent.replaceAll(fullMatch, createReplacement({ content: sourceContent, sourcePath, prefix }));
39
114
  }
40
- const paths = { sources: matches.map((m) => absolutePath(m.sourcePath)), destination };
115
+ const paths = { sources: uniqueMatches.map((m) => absolutePath(m.sourcePath)), destination };
41
116
  return content === updatedContent
42
117
  ? { code: "NO_CHANGE", paths }
43
118
  : { code: "UPDATE", paths, updatedContent };
44
119
  }
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
120
  function matchAll(params) {
54
121
  const { content, exists } = params;
55
122
  return [...content.matchAll(REGEX)]
56
123
  .map((match) => {
57
124
  const [fullMatch, prefix, sourcePath] = match;
125
+ /* istanbul ignore next */
58
126
  return isDefined(fullMatch) &&
59
127
  isDefined(prefix) &&
60
128
  isDefined(sourcePath) &&
@@ -68,13 +136,19 @@ function createReplacement(params) {
68
136
  const { content, sourcePath, prefix } = params;
69
137
  const contentHasCodeFence = content.includes("```");
70
138
  const backticks = contentHasCodeFence ? "````" : "```";
71
- const codeFenceId = CODE_FENCE_ID_BY_FILE_EXTENSION[(0, node_path_1.extname)(sourcePath).slice(1)];
72
- let processedContent = content.replaceAll("*/", "*\\/").trimEnd();
139
+ const codeFenceId = CODE_FENCE_ID_BY_FILE_EXTENSION[node_path_1.default.extname(sourcePath).slice(1)];
140
+ // Only escape */ when embedding into comment blocks (e.g., JSDoc)
141
+ // to prevent breaking the comment. Don't escape in Markdown.
142
+ const isInCommentBlock = /^\s*\*/.test(prefix);
143
+ let processedContent = content.trimEnd();
144
+ if (isInCommentBlock) {
145
+ processedContent = processedContent.replaceAll("*/", String.raw `*\/`);
146
+ }
73
147
  // For markdown files, strip nested embedex tags to prevent recursive processing
74
148
  if (codeFenceId === "") {
75
149
  processedContent = processedContent
76
- .replaceAll(/^(.*)<embedex source=".+?">\n([\S\s]*?)<\/embedex>/gm, (_match, _prefix, content) => {
77
- const lines = content.split("\n");
150
+ .replaceAll(/^(.*)<embedex source=".+?">\r?\n([\S\s]*?)<\/embedex>/gm, (_match, _prefix, content) => {
151
+ const lines = content.split(/\r?\n/);
78
152
  // Remove leading blank lines
79
153
  while (lines.length > 0 && lines[0]?.trim() === "") {
80
154
  lines.shift();
@@ -88,7 +162,7 @@ function createReplacement(params) {
88
162
  })
89
163
  .trim();
90
164
  }
91
- const contentLines = processedContent.split("\n");
165
+ const contentLines = processedContent.split(/\r?\n/);
92
166
  const lines = [
93
167
  `<embedex source="${sourcePath}">`,
94
168
  "",
@@ -101,6 +175,7 @@ function createReplacement(params) {
101
175
  return lines.map((line) => `${prefix}${line}`.trimEnd()).join("\n");
102
176
  }
103
177
  function isDefined(value) {
104
- return value !== null && value !== undefined;
178
+ // eslint-disable-next-line no-eq-null, eqeqeq
179
+ return value != null;
105
180
  }
106
181
  //# sourceMappingURL=processDestinations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"processDestinations.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib/internal/processDestinations.ts"],"names":[],"mappings":";;AAkBA,kDAeC;AAjCD,yCAA0C;AAK1C,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,SAAgB,mBAA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CAAC,GAAG,SAAS,GAAG,WAAW,IAAI,EAAE,EAAE,EAAE,GAAG,YAAY,EAAE,SAAS,CAAC,CAAC;QACrE,EAAE;QACF,YAAY;KACb,CAAC;IAEF,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,MAAM,GAAG,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,SAAS,CAAI,KAAoB;IACxC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;AAC/C,CAAC"}
1
+ {"version":3,"file":"processDestinations.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib/internal/processDestinations.ts"],"names":[],"mappings":";;AA4BA,kDA2BC;;AAvDD,kEAA6B;AAG7B,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,iB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AI,CAAC,IAAI,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,SAAS,CAAI,KAAoB;IACxC,8CAA8C;IAC9C,OAAO,KAAK,IAAI,IAAI,CAAC;AACvB,CAAC"}
@@ -5,7 +5,7 @@ export interface EmbedParams {
5
5
  sourcesGlob: string;
6
6
  write: boolean;
7
7
  }
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 Embed = NoMatch | Updated | NoChange;
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<{