@hyperweb/telescope 1.17.3 → 1.17.4

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
@@ -747,7 +747,6 @@ See [Helper Functions Configuration](#helper-functions-configuration) for more i
747
747
  | ------------------------------ | -------------------------------------------------------------- | ---------- |
748
748
  | `bundle.enabled` | Bundle all files into a scoped index file | `true` |
749
749
  | `bundle.type` | Bundle type: "namespace" or "module" | `"namespace"` |
750
- > **Warning:** This option is not recommended. It will generate a bundle file that exports all the types and functions under one namespace. This will make the bundle file very large and hard to maintain. e.g. using `cosmos.bank.v1beta1.MsgSend` might be intuitive, but it will also include `cosmos.gov.v1beta1.*` and other types in the final bundle file. So use this option with caution.
751
750
 
752
751
  ### MCP Server
753
752
 
@@ -3,11 +3,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.plugin = void 0;
4
4
  const ast_1 = require("@cosmology/ast");
5
5
  const utils_1 = require("@cosmology/utils");
6
+ /**
7
+ * Process noAlias configuration to create a map of names to their first package
8
+ * This ensures that only the first occurrence of a name skips aliasing
9
+ */
10
+ const processNoAliasConfig = (noAlias) => {
11
+ if (!noAlias || noAlias.length === 0) {
12
+ return new Map();
13
+ }
14
+ const nameToFirstPackage = new Map();
15
+ for (const entry of noAlias) {
16
+ if (!nameToFirstPackage.has(entry.name)) {
17
+ nameToFirstPackage.set(entry.name, entry.package);
18
+ }
19
+ }
20
+ return nameToFirstPackage;
21
+ };
22
+ /**
23
+ * Check if a package/name combination should skip aliasing
24
+ */
25
+ const shouldSkipAlias = (pkg, name, nameToFirstPackage) => {
26
+ const firstPackage = nameToFirstPackage.get(name);
27
+ return firstPackage === pkg;
28
+ };
6
29
  const plugin = (builder, bundler) => {
7
30
  if (!builder.options.bundle.enabled) {
8
31
  return;
9
32
  }
10
33
  let prog = [];
34
+ // Process noAlias configuration once at the beginning
35
+ const nameToFirstPackage = processNoAliasConfig(builder.options.bundle.noAlias);
11
36
  if (builder.options.bundle.type === "namespace") {
12
37
  const importPaths = (0, utils_1.duplicateImportPathsWithExt)(bundler.bundle.importPaths, builder.options.restoreImportExtension);
13
38
  // [x] bundle
@@ -44,17 +69,24 @@ const plugin = (builder, bundler) => {
44
69
  const duplicatedType = duplicatedTypeNames.find((type) => type === identifier);
45
70
  if (duplicatedType) {
46
71
  let alias;
47
- if (exportObj.isHelperFunc) {
48
- alias = (0, utils_1.makeAliasNameWithPackageAtEnd)({
49
- package: exportObj.pkg,
50
- name: identifier,
51
- });
72
+ // Check if this package/name combination should skip aliasing
73
+ if (shouldSkipAlias(exportObj.pkg, identifier, nameToFirstPackage)) {
74
+ alias = identifier; // Use original name, no alias
52
75
  }
53
76
  else {
54
- alias = (0, utils_1.makeAliasName)({
55
- package: exportObj.pkg,
56
- name: identifier,
57
- });
77
+ // Generate alias as usual
78
+ if (exportObj.isHelperFunc) {
79
+ alias = (0, utils_1.makeAliasNameWithPackageAtEnd)({
80
+ package: exportObj.pkg,
81
+ name: identifier,
82
+ });
83
+ }
84
+ else {
85
+ alias = (0, utils_1.makeAliasName)({
86
+ package: exportObj.pkg,
87
+ name: identifier,
88
+ });
89
+ }
58
90
  }
59
91
  return { name: identifier, alias: alias };
60
92
  }
@@ -1,10 +1,35 @@
1
1
  import { exportAllFromRelPath, exportTypesWithAlias, recursiveModuleBundle, } from "@cosmology/ast";
2
2
  import { duplicateImportPathsWithExt, makeAliasName, makeAliasNameWithPackageAtEnd, } from "@cosmology/utils";
3
+ /**
4
+ * Process noAlias configuration to create a map of names to their first package
5
+ * This ensures that only the first occurrence of a name skips aliasing
6
+ */
7
+ const processNoAliasConfig = (noAlias) => {
8
+ if (!noAlias || noAlias.length === 0) {
9
+ return new Map();
10
+ }
11
+ const nameToFirstPackage = new Map();
12
+ for (const entry of noAlias) {
13
+ if (!nameToFirstPackage.has(entry.name)) {
14
+ nameToFirstPackage.set(entry.name, entry.package);
15
+ }
16
+ }
17
+ return nameToFirstPackage;
18
+ };
19
+ /**
20
+ * Check if a package/name combination should skip aliasing
21
+ */
22
+ const shouldSkipAlias = (pkg, name, nameToFirstPackage) => {
23
+ const firstPackage = nameToFirstPackage.get(name);
24
+ return firstPackage === pkg;
25
+ };
3
26
  export const plugin = (builder, bundler) => {
4
27
  if (!builder.options.bundle.enabled) {
5
28
  return;
6
29
  }
7
30
  let prog = [];
31
+ // Process noAlias configuration once at the beginning
32
+ const nameToFirstPackage = processNoAliasConfig(builder.options.bundle.noAlias);
8
33
  if (builder.options.bundle.type === "namespace") {
9
34
  const importPaths = duplicateImportPathsWithExt(bundler.bundle.importPaths, builder.options.restoreImportExtension);
10
35
  // [x] bundle
@@ -41,17 +66,24 @@ export const plugin = (builder, bundler) => {
41
66
  const duplicatedType = duplicatedTypeNames.find((type) => type === identifier);
42
67
  if (duplicatedType) {
43
68
  let alias;
44
- if (exportObj.isHelperFunc) {
45
- alias = makeAliasNameWithPackageAtEnd({
46
- package: exportObj.pkg,
47
- name: identifier,
48
- });
69
+ // Check if this package/name combination should skip aliasing
70
+ if (shouldSkipAlias(exportObj.pkg, identifier, nameToFirstPackage)) {
71
+ alias = identifier; // Use original name, no alias
49
72
  }
50
73
  else {
51
- alias = makeAliasName({
52
- package: exportObj.pkg,
53
- name: identifier,
54
- });
74
+ // Generate alias as usual
75
+ if (exportObj.isHelperFunc) {
76
+ alias = makeAliasNameWithPackageAtEnd({
77
+ package: exportObj.pkg,
78
+ name: identifier,
79
+ });
80
+ }
81
+ else {
82
+ alias = makeAliasName({
83
+ package: exportObj.pkg,
84
+ name: identifier,
85
+ });
86
+ }
55
87
  }
56
88
  return { name: identifier, alias: alias };
57
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperweb/telescope",
3
- "version": "1.17.3",
3
+ "version": "1.17.4",
4
4
  "description": "A TypeScript Transpiler for Cosmos Protobufs",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/hyperweb-io/telescope/tree/master/packages/telescope#readme",
@@ -90,10 +90,10 @@
90
90
  "@babel/parser": "^7.23.6",
91
91
  "@babel/traverse": "7.23.6",
92
92
  "@babel/types": "7.23.6",
93
- "@cosmology/ast": "^1.12.1",
94
- "@cosmology/proto-parser": "^1.11.1",
95
- "@cosmology/types": "^1.13.1",
96
- "@cosmology/utils": "^1.11.1",
93
+ "@cosmology/ast": "^1.12.2",
94
+ "@cosmology/proto-parser": "^1.11.2",
95
+ "@cosmology/types": "^1.13.2",
96
+ "@cosmology/utils": "^1.11.2",
97
97
  "@cosmwasm/ts-codegen": "0.35.7",
98
98
  "@types/parse-package-name": "0.1.0",
99
99
  "case": "1.6.3",
@@ -111,5 +111,5 @@
111
111
  "rimraf": "5.0.0",
112
112
  "yaml": "^2.3.4"
113
113
  },
114
- "gitHead": "a8d5404c05996b49916a64f05586e771d87629dd"
114
+ "gitHead": "21d41a6bf946480c10d5e5c18b76a680f40164e8"
115
115
  }
@@ -11,6 +11,38 @@ import {
11
11
  makeAliasNameWithPackageAtEnd,
12
12
  } from "@cosmology/utils";
13
13
 
14
+ /**
15
+ * Process noAlias configuration to create a map of names to their first package
16
+ * This ensures that only the first occurrence of a name skips aliasing
17
+ */
18
+ const processNoAliasConfig = (noAlias?: Array<{ package: string; name: string }>) => {
19
+ if (!noAlias || noAlias.length === 0) {
20
+ return new Map<string, string>();
21
+ }
22
+
23
+ const nameToFirstPackage = new Map<string, string>();
24
+
25
+ for (const entry of noAlias) {
26
+ if (!nameToFirstPackage.has(entry.name)) {
27
+ nameToFirstPackage.set(entry.name, entry.package);
28
+ }
29
+ }
30
+
31
+ return nameToFirstPackage;
32
+ };
33
+
34
+ /**
35
+ * Check if a package/name combination should skip aliasing
36
+ */
37
+ const shouldSkipAlias = (
38
+ pkg: string,
39
+ name: string,
40
+ nameToFirstPackage: Map<string, string>
41
+ ): boolean => {
42
+ const firstPackage = nameToFirstPackage.get(name);
43
+ return firstPackage === pkg;
44
+ };
45
+
14
46
  export const plugin = (builder: TelescopeBuilder, bundler: Bundler) => {
15
47
  if (!builder.options.bundle.enabled) {
16
48
  return;
@@ -18,6 +50,9 @@ export const plugin = (builder: TelescopeBuilder, bundler: Bundler) => {
18
50
 
19
51
  let prog = [];
20
52
 
53
+ // Process noAlias configuration once at the beginning
54
+ const nameToFirstPackage = processNoAliasConfig((builder.options.bundle as any).noAlias);
55
+
21
56
  if (builder.options.bundle.type === "namespace") {
22
57
  const importPaths = duplicateImportPathsWithExt(
23
58
  bundler.bundle.importPaths,
@@ -67,16 +102,23 @@ export const plugin = (builder: TelescopeBuilder, bundler: Bundler) => {
67
102
  );
68
103
  if (duplicatedType) {
69
104
  let alias: string;
70
- if (exportObj.isHelperFunc) {
71
- alias = makeAliasNameWithPackageAtEnd({
72
- package: exportObj.pkg,
73
- name: identifier,
74
- });
105
+
106
+ // Check if this package/name combination should skip aliasing
107
+ if (shouldSkipAlias(exportObj.pkg, identifier, nameToFirstPackage)) {
108
+ alias = identifier; // Use original name, no alias
75
109
  } else {
76
- alias = makeAliasName({
77
- package: exportObj.pkg,
78
- name: identifier,
79
- });
110
+ // Generate alias as usual
111
+ if (exportObj.isHelperFunc) {
112
+ alias = makeAliasNameWithPackageAtEnd({
113
+ package: exportObj.pkg,
114
+ name: identifier,
115
+ });
116
+ } else {
117
+ alias = makeAliasName({
118
+ package: exportObj.pkg,
119
+ name: identifier,
120
+ });
121
+ }
80
122
  }
81
123
  return { name: identifier, alias: alias };
82
124
  }