@genesislcap/ts-builder 14.458.0 → 14.458.1-GENC-0.1

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":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;yBAKrC,KAAK,YAAY;AAAvC,wBAsDE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;yBAMrC,KAAK,YAAY;AAAvC,wBA6DE"}
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ const tslib_1 = require("tslib");
4
4
  const build_kit_1 = require("@genesislcap/build-kit");
5
5
  const consola_1 = tslib_1.__importDefault(require("consola"));
6
6
  const react_wrapper_generator_1 = require("./react-wrapper-generator");
7
+ const resolve_cem_config_path_1 = require("./resolve-cem-config-path");
7
8
  exports.default = (ctx) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
8
9
  const { dirs: { cwd }, cli: { isDev, isBuild, options }, config: { clean, copyAssets }, enable: { apiExtractor, cemAnalyzer }, } = ctx;
9
10
  if (clean) {
@@ -33,7 +34,13 @@ exports.default = (ctx) => tslib_1.__awaiter(void 0, void 0, void 0, function* (
33
34
  if (cemAnalyzer) {
34
35
  consola_1.default.log('\n@custom-elements-manifest/analyzer configuration detected');
35
36
  const cem = yield (0, build_kit_1.resolveBin)('cem', '@custom-elements-manifest/analyzer');
36
- (0, build_kit_1.run)(cwd, `${cem} analyze --config custom-elements-manifest.config.*js`);
37
+ const cemConfigArg = (0, resolve_cem_config_path_1.resolveCEMConfigArg)(cwd);
38
+ if (!cemConfigArg) {
39
+ consola_1.default.warn('CEM config file not found in package root; skipping custom-elements-manifest analyze');
40
+ }
41
+ else {
42
+ (0, build_kit_1.run)(cwd, `${cem} analyze --config ${cemConfigArg}`);
43
+ }
37
44
  }
38
45
  const reactWrappersResult = yield (0, react_wrapper_generator_1.generateReactWrappers)(cwd);
39
46
  if (reactWrappersResult.generated) {
@@ -1 +1 @@
1
- {"version":3,"file":"react-wrapper-generator.d.ts","sourceRoot":"","sources":["../src/react-wrapper-generator.ts"],"names":[],"mappings":"AAyCA,KAAK,cAAc,GAAG;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,SAAS,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AA66B/F,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAwChF"}
1
+ {"version":3,"file":"react-wrapper-generator.d.ts","sourceRoot":"","sources":["../src/react-wrapper-generator.ts"],"names":[],"mappings":"AAyCA,KAAK,cAAc,GAAG;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,SAAS,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AA6gC/F,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAyChF"}
@@ -464,6 +464,83 @@ function mergeFastInheritanceFromManifest(cwd, entries) {
464
464
  });
465
465
  });
466
466
  }
467
+ function createFoundationDeclarationLookup(manifest) {
468
+ var _a, _b;
469
+ const byTag = new Map();
470
+ const byName = new Map();
471
+ for (const mod of (_a = manifest.modules) !== null && _a !== void 0 ? _a : []) {
472
+ for (const decl of (_b = mod.declarations) !== null && _b !== void 0 ? _b : []) {
473
+ if (decl.name)
474
+ byName.set(decl.name, decl);
475
+ if (decl.customElement && decl.tagName)
476
+ byTag.set(decl.tagName, decl);
477
+ }
478
+ }
479
+ return { byTag, byName };
480
+ }
481
+ function resolveDependencyManifestPath(cwd, packageName) {
482
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
483
+ const packageRoot = (0, node_path_1.resolve)(cwd, 'node_modules', packageName);
484
+ const packageJsonPath = (0, node_path_1.resolve)(packageRoot, 'package.json');
485
+ if (!(yield fileExists(packageJsonPath)))
486
+ return null;
487
+ const packageJson = JSON.parse(yield (0, promises_1.readFile)(packageJsonPath, 'utf8'));
488
+ if (typeof packageJson.customElements === 'string' && packageJson.customElements.trim()) {
489
+ const manifestPath = (0, node_path_1.resolve)(packageRoot, packageJson.customElements);
490
+ if (yield fileExists(manifestPath))
491
+ return manifestPath;
492
+ }
493
+ const distManifestPath = (0, node_path_1.resolve)(packageRoot, 'dist/custom-elements.json');
494
+ if (yield fileExists(distManifestPath))
495
+ return distManifestPath;
496
+ const rootManifestPath = (0, node_path_1.resolve)(packageRoot, 'custom-elements.json');
497
+ if (yield fileExists(rootManifestPath))
498
+ return rootManifestPath;
499
+ return null;
500
+ });
501
+ }
502
+ function findFoundationInheritedDeclaration(declaration, lookup) {
503
+ var _a;
504
+ if (declaration.tagName) {
505
+ const byTag = lookup.byTag.get(declaration.tagName);
506
+ if (byTag)
507
+ return byTag;
508
+ }
509
+ const superclassName = (_a = declaration.superclass) === null || _a === void 0 ? void 0 : _a.name;
510
+ if (!superclassName)
511
+ return undefined;
512
+ const byName = lookup.byName.get(superclassName);
513
+ if (byName)
514
+ return byName;
515
+ const normalized = superclassName.replace(/^Foundation(?=[A-Z])/, '').replace(/^foundation/, '');
516
+ if (normalized === superclassName)
517
+ return undefined;
518
+ for (const [name, decl] of lookup.byName) {
519
+ if (decl.customElement && name.toLowerCase() === normalized.toLowerCase()) {
520
+ return decl;
521
+ }
522
+ }
523
+ return undefined;
524
+ }
525
+ function mergeFoundationInheritanceFromManifest(cwd, entries) {
526
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
527
+ const foundationManifestPath = yield resolveDependencyManifestPath(cwd, '@genesislcap/foundation-ui');
528
+ if (!foundationManifestPath)
529
+ return entries;
530
+ const foundationManifest = JSON.parse(yield (0, promises_1.readFile)(foundationManifestPath, 'utf8'));
531
+ const lookup = createFoundationDeclarationLookup(foundationManifest);
532
+ return entries.map((entry) => {
533
+ var _a;
534
+ const { declaration } = entry;
535
+ if (!declaration.tagName || ((_a = declaration.superclass) === null || _a === void 0 ? void 0 : _a.package) !== '@genesislcap/foundation-ui') {
536
+ return entry;
537
+ }
538
+ const inherited = findFoundationInheritedDeclaration(declaration, lookup);
539
+ return inherited
540
+ ? Object.assign(Object.assign({}, entry), { declaration: mergeDeclarationMetadata(declaration, inherited) }) : entry;
541
+ });
542
+ });
543
+ }
467
544
  // ── Wrapper event helpers ─────────────────────────────────────────────────────
468
545
  function buildWrapperEventEntries(declaration) {
469
546
  var _a;
@@ -837,7 +914,8 @@ function generateReactWrappers(cwd) {
837
914
  if (!rawEntries.length) {
838
915
  return { generated: false, reason: 'No custom elements discovered in manifest.' };
839
916
  }
840
- const entries = yield mergeFastInheritanceFromManifest(cwd, rawEntries);
917
+ const afterFast = yield mergeFastInheritanceFromManifest(cwd, rawEntries);
918
+ const entries = yield mergeFoundationInheritanceFromManifest(cwd, afterFast);
841
919
  const hasEvents = entries.some((e) => { var _a; return ((_a = e.declaration.events) !== null && _a !== void 0 ? _a : []).length > 0; });
842
920
  if (!hasEvents) {
843
921
  return { generated: false, reason: 'No custom events found in any element.' };
@@ -0,0 +1,5 @@
1
+ /** Resolves the CEM config file in `cwd`. Shell globs like `config.*js` are unreliable on Windows. */
2
+ export declare function resolveCEMConfigPath(cwd: string): string | null;
3
+ /** Returns the config filename for use with `cem analyze --config` when cwd is the package root. */
4
+ export declare function resolveCEMConfigArg(cwd: string): string | null;
5
+ //# sourceMappingURL=resolve-cem-config-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-cem-config-path.d.ts","sourceRoot":"","sources":["../src/resolve-cem-config-path.ts"],"names":[],"mappings":"AAUA,sGAAsG;AACtG,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM/D;AAED,oGAAoG;AACpG,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG9D"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveCEMConfigPath = resolveCEMConfigPath;
4
+ exports.resolveCEMConfigArg = resolveCEMConfigArg;
5
+ const node_fs_1 = require("node:fs");
6
+ const node_path_1 = require("node:path");
7
+ const CEM_CONFIG_FILENAMES = [
8
+ 'custom-elements-manifest.config.js',
9
+ 'custom-elements-manifest.config.mjs',
10
+ 'custom-elements-manifest.config.cjs',
11
+ 'custom-elements-manifest.config.ts',
12
+ ];
13
+ /** Resolves the CEM config file in `cwd`. Shell globs like `config.*js` are unreliable on Windows. */
14
+ function resolveCEMConfigPath(cwd) {
15
+ for (const name of CEM_CONFIG_FILENAMES) {
16
+ const path = (0, node_path_1.resolve)(cwd, name);
17
+ if ((0, node_fs_1.existsSync)(path))
18
+ return path;
19
+ }
20
+ return null;
21
+ }
22
+ /** Returns the config filename for use with `cem analyze --config` when cwd is the package root. */
23
+ function resolveCEMConfigArg(cwd) {
24
+ const path = resolveCEMConfigPath(cwd);
25
+ return path ? (0, node_path_1.basename)(path) : null;
26
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/ts-builder",
3
3
  "description": "Typescript builder",
4
- "version": "14.458.0",
4
+ "version": "14.458.1-GENC-0.1",
5
5
  "license": "SEE LICENSE IN license.txt",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@custom-elements-manifest/analyzer": "^0.8.2",
20
- "@genesislcap/build-kit": "14.458.0",
20
+ "@genesislcap/build-kit": "14.458.1-GENC-0.1",
21
21
  "consola": "^3.0.2",
22
22
  "copyfiles": "^2.4.1",
23
23
  "pkg-types": "^1.0.2"
@@ -30,5 +30,5 @@
30
30
  "publishConfig": {
31
31
  "access": "public"
32
32
  },
33
- "gitHead": "be04e474ce5154f026d9d01372eec7c6a24b012f"
33
+ "gitHead": "4807180a46cbc61edd0c9d000340abbdf90eb47c"
34
34
  }
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ import type { BuildContext } from '@genesislcap/build-kit';
2
2
  import { rm, run, resolveBin } from '@genesislcap/build-kit';
3
3
  import consola from 'consola';
4
4
  import { generateReactWrappers } from './react-wrapper-generator';
5
+ import { resolveCEMConfigArg } from './resolve-cem-config-path';
5
6
 
6
7
  export default async (ctx: BuildContext) => {
7
8
  const {
@@ -41,7 +42,14 @@ export default async (ctx: BuildContext) => {
41
42
  if (cemAnalyzer) {
42
43
  consola.log('\n@custom-elements-manifest/analyzer configuration detected');
43
44
  const cem = await resolveBin('cem', '@custom-elements-manifest/analyzer');
44
- run(cwd, `${cem} analyze --config custom-elements-manifest.config.*js`);
45
+ const cemConfigArg = resolveCEMConfigArg(cwd);
46
+ if (!cemConfigArg) {
47
+ consola.warn(
48
+ 'CEM config file not found in package root; skipping custom-elements-manifest analyze',
49
+ );
50
+ } else {
51
+ run(cwd, `${cem} analyze --config ${cemConfigArg}`);
52
+ }
45
53
  }
46
54
 
47
55
  const reactWrappersResult = await generateReactWrappers(cwd);
@@ -558,6 +558,102 @@ async function mergeFastInheritanceFromManifest(
558
558
  });
559
559
  }
560
560
 
561
+ function createFoundationDeclarationLookup(manifest: CEMManifest): {
562
+ byTag: Map<string, CEMDeclaration>;
563
+ byName: Map<string, CEMDeclaration>;
564
+ } {
565
+ const byTag = new Map<string, CEMDeclaration>();
566
+ const byName = new Map<string, CEMDeclaration>();
567
+ for (const mod of manifest.modules ?? []) {
568
+ for (const decl of mod.declarations ?? []) {
569
+ if (decl.name) byName.set(decl.name, decl);
570
+ if (decl.customElement && decl.tagName) byTag.set(decl.tagName, decl);
571
+ }
572
+ }
573
+ return { byTag, byName };
574
+ }
575
+
576
+ async function resolveDependencyManifestPath(
577
+ cwd: string,
578
+ packageName: string,
579
+ ): Promise<string | null> {
580
+ const packageRoot = resolve(cwd, 'node_modules', packageName);
581
+ const packageJsonPath = resolve(packageRoot, 'package.json');
582
+ if (!(await fileExists(packageJsonPath))) return null;
583
+
584
+ const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8')) as Record<
585
+ string,
586
+ unknown
587
+ >;
588
+ if (typeof packageJson.customElements === 'string' && packageJson.customElements.trim()) {
589
+ const manifestPath = resolve(packageRoot, packageJson.customElements);
590
+ if (await fileExists(manifestPath)) return manifestPath;
591
+ }
592
+
593
+ const distManifestPath = resolve(packageRoot, 'dist/custom-elements.json');
594
+ if (await fileExists(distManifestPath)) return distManifestPath;
595
+
596
+ const rootManifestPath = resolve(packageRoot, 'custom-elements.json');
597
+ if (await fileExists(rootManifestPath)) return rootManifestPath;
598
+
599
+ return null;
600
+ }
601
+
602
+ function findFoundationInheritedDeclaration(
603
+ declaration: CEMDeclaration,
604
+ lookup: ReturnType<typeof createFoundationDeclarationLookup>,
605
+ ): CEMDeclaration | undefined {
606
+ if (declaration.tagName) {
607
+ const byTag = lookup.byTag.get(declaration.tagName);
608
+ if (byTag) return byTag;
609
+ }
610
+
611
+ const superclassName = declaration.superclass?.name;
612
+ if (!superclassName) return undefined;
613
+
614
+ const byName = lookup.byName.get(superclassName);
615
+ if (byName) return byName;
616
+
617
+ const normalized = superclassName.replace(/^Foundation(?=[A-Z])/, '').replace(/^foundation/, '');
618
+ if (normalized === superclassName) return undefined;
619
+
620
+ for (const [name, decl] of lookup.byName) {
621
+ if (decl.customElement && name.toLowerCase() === normalized.toLowerCase()) {
622
+ return decl;
623
+ }
624
+ }
625
+
626
+ return undefined;
627
+ }
628
+
629
+ async function mergeFoundationInheritanceFromManifest(
630
+ cwd: string,
631
+ entries: CEMElementEntry[],
632
+ ): Promise<CEMElementEntry[]> {
633
+ const foundationManifestPath = await resolveDependencyManifestPath(
634
+ cwd,
635
+ '@genesislcap/foundation-ui',
636
+ );
637
+ if (!foundationManifestPath) return entries;
638
+
639
+ const foundationManifest = JSON.parse(
640
+ await readFile(foundationManifestPath, 'utf8'),
641
+ ) as CEMManifest;
642
+ const lookup = createFoundationDeclarationLookup(foundationManifest);
643
+
644
+ return entries.map((entry) => {
645
+ const { declaration } = entry;
646
+ if (!declaration.tagName || declaration.superclass?.package !== '@genesislcap/foundation-ui') {
647
+ return entry;
648
+ }
649
+
650
+ const inherited = findFoundationInheritedDeclaration(declaration, lookup);
651
+ return inherited
652
+ ? { ...entry, declaration: mergeDeclarationMetadata(declaration, inherited) }
653
+ : entry;
654
+ });
655
+ }
656
+
561
657
  // ── Wrapper event helpers ─────────────────────────────────────────────────────
562
658
 
563
659
  function buildWrapperEventEntries(
@@ -1001,7 +1097,8 @@ export async function generateReactWrappers(cwd: string): Promise<GenerateResult
1001
1097
  return { generated: false, reason: 'No custom elements discovered in manifest.' };
1002
1098
  }
1003
1099
 
1004
- const entries = await mergeFastInheritanceFromManifest(cwd, rawEntries);
1100
+ const afterFast = await mergeFastInheritanceFromManifest(cwd, rawEntries);
1101
+ const entries = await mergeFoundationInheritanceFromManifest(cwd, afterFast);
1005
1102
  const hasEvents = entries.some((e) => (e.declaration.events ?? []).length > 0);
1006
1103
  if (!hasEvents) {
1007
1104
  return { generated: false, reason: 'No custom events found in any element.' };
@@ -0,0 +1,24 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { basename, resolve } from 'node:path';
3
+
4
+ const CEM_CONFIG_FILENAMES = [
5
+ 'custom-elements-manifest.config.js',
6
+ 'custom-elements-manifest.config.mjs',
7
+ 'custom-elements-manifest.config.cjs',
8
+ 'custom-elements-manifest.config.ts',
9
+ ];
10
+
11
+ /** Resolves the CEM config file in `cwd`. Shell globs like `config.*js` are unreliable on Windows. */
12
+ export function resolveCEMConfigPath(cwd: string): string | null {
13
+ for (const name of CEM_CONFIG_FILENAMES) {
14
+ const path = resolve(cwd, name);
15
+ if (existsSync(path)) return path;
16
+ }
17
+ return null;
18
+ }
19
+
20
+ /** Returns the config filename for use with `cem analyze --config` when cwd is the package root. */
21
+ export function resolveCEMConfigArg(cwd: string): string | null {
22
+ const path = resolveCEMConfigPath(cwd);
23
+ return path ? basename(path) : null;
24
+ }
@@ -1 +1 @@
1
- {"root":["./src/index.ts","./src/react-wrapper-generator.ts"],"version":"5.9.2"}
1
+ {"root":["./src/index.ts","./src/react-wrapper-generator.ts","./src/resolve-cem-config-path.ts"],"version":"5.9.2"}