@intentius/chant 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.
@@ -1 +1 @@
1
- {"version":3,"file":"collect.d.ts","sourceRoot":"","sources":["../../src/discovery/collect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAM9D;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAAC,GACjE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAoEzB"}
1
+ {"version":3,"file":"collect.d.ts","sourceRoot":"","sources":["../../src/discovery/collect.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAkB9D;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAAC,GACjE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAqEzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant",
3
- "version": "0.18.2",
3
+ "version": "0.18.3",
4
4
  "description": "Declarative infrastructure-as-code toolkit — TypeScript on Node.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://intentius.io/chant",
@@ -301,3 +301,25 @@ describe("collectEntities with composites", () => {
301
301
  expect(entities.has("myComp")).toBe(false);
302
302
  });
303
303
  });
304
+
305
+ describe("collectEntities — default exports (op files)", () => {
306
+ test("two files with `export default` do not collide (keyed per file)", () => {
307
+ const apply = createMockEntity("Temporal::Op");
308
+ const reconcile = createMockEntity("Temporal::Op");
309
+ const result = collectEntities([
310
+ { file: "ops/apply.op.ts", exports: { default: apply } },
311
+ { file: "ops/reconcile.op.ts", exports: { default: reconcile } },
312
+ ]);
313
+ expect(result.size).toBe(2);
314
+ // keyed by file basename (sans .op.ts), not the literal "default"
315
+ expect(result.get("apply")).toBe(apply);
316
+ expect(result.get("reconcile")).toBe(reconcile);
317
+ expect(result.has("default")).toBe(false);
318
+ });
319
+
320
+ test("a single default export is collected (not dropped)", () => {
321
+ const op = createMockEntity("Temporal::Op");
322
+ const result = collectEntities([{ file: "ops/deploy.op.ts", exports: { default: op } }]);
323
+ expect(result.get("deploy")).toBe(op);
324
+ });
325
+ });
@@ -1,9 +1,22 @@
1
+ import { basename } from "node:path";
1
2
  import { isDeclarable, type Declarable } from "../declarable";
2
3
  import { isCompositeInstance, expandComposite } from "../composite";
3
4
  import { isLexiconOutput } from "../lexicon-output";
4
5
  import { DiscoveryError } from "../errors";
5
6
  import { setProvenance } from "../provenance";
6
7
 
8
+ /**
9
+ * The entity key for an export. `export default` is per-module — the `Op` pattern
10
+ * (`export default op`) uses it, and two op files must not collide on the literal
11
+ * name "default". Key a default export by the file's basename so distinct files
12
+ * stay distinct; named exports keep their name. (Serializers that care about the
13
+ * declared name — e.g. the Op serializer — read it from the entity, not this key.)
14
+ */
15
+ function exportKey(rawName: string, file: string): string {
16
+ if (rawName !== "default") return rawName;
17
+ return basename(file).replace(/\.ts$/, "").replace(/\.op$/, "");
18
+ }
19
+
7
20
  /**
8
21
  * Collects all declarable entities from imported modules.
9
22
  * CompositeInstance exports are expanded into individual entities
@@ -21,7 +34,8 @@ export function collectEntities(
21
34
  const entities = new Map<string, Declarable>();
22
35
 
23
36
  for (const { file, exports } of modules) {
24
- for (const [name, value] of Object.entries(exports)) {
37
+ for (const [rawName, value] of Object.entries(exports)) {
38
+ const name = exportKey(rawName, file);
25
39
  if (isDeclarable(value)) {
26
40
  if (entities.has(name)) {
27
41
  // Same object re-exported from multiple files (e.g. re-exports from multiple files) is fine