@yahoo/uds-create-config 5.104.1 → 5.105.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.
@@ -1,6 +1,11 @@
1
- import { pathOf } from "../framework/utils/refs.js";
1
+ import { kindOf, memberOf, pathOf } from "../framework/utils/refs.js";
2
2
  //#region src/spec/glyph-jsx.ts
3
3
  const ASSET_KIND = "icon:";
4
+ /** The module a package export imports from, `package:react-native#View` → `react-native`, or
5
+ * `undefined` for anything that is not a package export. */
6
+ function packageModuleOf(type) {
7
+ return kindOf(type) === "package" && memberOf(type) ? pathOf(type) : void 0;
8
+ }
4
9
  /**
5
10
  * The identifier a type is KNOWN AS in JSX — `component:buttons/Primary` → `Primary`.
6
11
  *
@@ -10,6 +15,8 @@ const ASSET_KIND = "icon:";
10
15
  * An intrinsic tag has no kind and no group, so it passes through untouched.
11
16
  */
12
17
  function jsxIdentifier(type) {
18
+ const member = memberOf(type);
19
+ if (member) return member.split("@")[0] ?? member;
13
20
  const path = pathOf(type);
14
21
  return path.slice(path.lastIndexOf("/") + 1);
15
22
  }
@@ -57,4 +64,4 @@ function glyphJsxForm(type) {
57
64
  };
58
65
  }
59
66
  //#endregion
60
- export { glyphJsxForm, glyphMemberOf, jsxIdentifier, parseGlyphType };
67
+ export { glyphJsxForm, glyphMemberOf, jsxIdentifier, packageModuleOf, parseGlyphType };
@@ -1,8 +1,20 @@
1
1
  import { UDS_FORCE_STATES } from "../framework/component-states.js";
2
2
  import "../framework/class-names.js";
3
- import { glyphJsxForm, glyphMemberOf, jsxIdentifier, parseGlyphType } from "./glyph-jsx.js";
3
+ import { glyphJsxForm, glyphMemberOf, jsxIdentifier, packageModuleOf, parseGlyphType } from "./glyph-jsx.js";
4
4
  import { serializeProps } from "@json-render/codegen";
5
5
  //#region src/spec/specToJsx.ts
6
+ function moduleIdentifier(module) {
7
+ return module.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
8
+ }
9
+ /** The tag a package export prints as, imported from its own module: `<View>` from `react-native`,
10
+ * or `<ReactNativeText>` when the spec also holds a component printed `Text`. */
11
+ function packageTag({ ctx, module, name }) {
12
+ const tag = ctx.componentTags.has(name) ? `${moduleIdentifier(module)}${name}` : name;
13
+ const names = ctx.members.get(module) ?? /* @__PURE__ */ new Set();
14
+ names.add(tag === name ? name : `${name} as ${tag}`);
15
+ ctx.members.set(module, names);
16
+ return tag;
17
+ }
6
18
  /** Record a glyph member as imported from the library that lists it, else from the first of `slugs`
7
19
  * whose module is known; `false` when none of them names one. */
8
20
  function importMember({ ctx, slugs, name }) {
@@ -121,7 +133,13 @@ function renderElement(key, spec, depth, ctx, ancestors) {
121
133
  const rendered = fills.map((r) => renderElement(r, spec, 0, ctx, withSelf).trim()).filter(Boolean);
122
134
  slotAttrs.push(`${propName}={<>${rendered.join("")}</>}`);
123
135
  }
124
- const tag = glyphJsxForm(element.type)?.tag ?? jsxIdentifier(element.type);
136
+ const assetForm = glyphJsxForm(element.type);
137
+ const packageModule = packageModuleOf(element.type);
138
+ const tag = packageModule ? packageTag({
139
+ ctx,
140
+ module: packageModule,
141
+ name: jsxIdentifier(element.type)
142
+ }) : assetForm?.tag ?? jsxIdentifier(element.type);
125
143
  const placed = parseGlyphType(element.type);
126
144
  if (placed) importMember({
127
145
  ctx,
@@ -207,7 +225,9 @@ function specToJsx(spec, options) {
207
225
  imports: [],
208
226
  memberImports: {}
209
227
  };
228
+ const componentTypes = [...collectUsedComponentTypes(spec)].filter((type) => packageModuleOf(type) === void 0);
210
229
  const ctx = {
230
+ componentTags: new Set(componentTypes.map((type) => jsxIdentifier(type))),
211
231
  glyphModules: options?.glyphModules,
212
232
  glyphProps: options?.glyphProps,
213
233
  glyphMembers: options?.glyphMembers,
@@ -216,7 +236,7 @@ function specToJsx(spec, options) {
216
236
  };
217
237
  const jsxTree = renderElement(spec.root, spec, 0, ctx, /* @__PURE__ */ new Set());
218
238
  const fromLibraries = new Set([...ctx.members.values()].flatMap((names) => [...names]));
219
- const sortedImports = [...new Set([...collectUsedComponentTypes(spec)].map((type) => glyphJsxForm(type)?.importName ?? jsxIdentifier(type)).filter((name) => !fromLibraries.has(name)))].sort();
239
+ const sortedImports = [...new Set(componentTypes.map((type) => glyphJsxForm(type)?.importName ?? jsxIdentifier(type)).filter((name) => !fromLibraries.has(name)))].sort();
220
240
  const memberImports = Object.fromEntries([...ctx.members.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([module, names]) => [module, [...names].sort()]));
221
241
  if (options?.omitImports) return {
222
242
  jsx: jsxTree,