@react-native-oh/react-native-harmony-cli 0.77.64 → 0.77.71
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/dist/autolinking/Autolinking.js +141 -23
- package/dist/core/ProjectDependenciesManager.js +20 -1
- package/harmony/rnoh-hvigor-plugin-0.77.71.tgz +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/00a68392 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/0544a6cc +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/0f36b2db +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/12f23f1e +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/13d95d98 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1629e86b +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/180c8379 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1a697147 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1a8271b1 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1b7fa689 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/255a9f13 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/268d155b +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/27db9aa4 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/28db79ed +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2dc2bbcb +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2df5f8c5 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2f88aedb +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/31b3a7ea +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/36335b1c +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/38fca641 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/397722eb +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/397b6432 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/3b17421f +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/454f5e18 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/45ec6cce +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/482d51b1 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4ac5cd67 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4d40499a +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4dcad919 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4fc31929 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/54edc8f5 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/558a5405 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/58d2b670 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/5ec7feca +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/62180f3e +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/63981360 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/64096c89 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/64af560b +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6585e783 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6954304f +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/69fd6235 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6d3a0478 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6e131db7 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/778cd8f1 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/788206b6 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7882dc26 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7b3c14f7 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7cdfe667 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8048c487 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8332d9a3 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/84e5b603 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/854d8127 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/88c97376 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/90d5f644 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/967e25ac +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/969896c2 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/9790193e +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/97ae40c5 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/9a5bf482 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a07adeb9 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a427f355 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a9dd7eb7 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a9e9d79e +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ab920855 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ab9e3038 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/af054988 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/afe03e51 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b3b83913 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b4db7b4d +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b5225355 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b8c00f06 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b917a081 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b9e2f3bd +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/bd70db0e +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/bdbda648 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/be1e5469 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c9462295 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ca6e5efa +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/caf52beb +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/cb268960 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/cca16b15 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/cfc1c937 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d10e6e05 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d172fc04 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d4e94e50 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d59f8d2c +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/da964053 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e0bb712a +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e3e6ca34 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e50f7385 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f1a1d282 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f2514c3c +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f66207cf +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f8d129ce +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/fb1e9558 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ff7e3608 +0 -0
- package/package.json +4 -4
- package/src/autolinking/Autolinking.test.ts +237 -0
- package/src/autolinking/Autolinking.ts +223 -39
- package/src/core/PackageJSON.ts +19 -1
- package/src/core/ProjectDependenciesManager.ts +25 -7
- package/harmony/rnoh-hvigor-plugin-0.77.64.tgz +0 -0
|
@@ -570,3 +570,240 @@ it('should preserve comments in oh-package.json5', async () => {
|
|
|
570
570
|
// Verify new dependency is added
|
|
571
571
|
expect(ohPackageContent).toContain('@rnoh/test-package');
|
|
572
572
|
});
|
|
573
|
+
|
|
574
|
+
it('should support custom mainHarPath for HAR scanning', async () => {
|
|
575
|
+
const { runAutolinking, memFS } = createAutolinking({
|
|
576
|
+
fsStructure: {
|
|
577
|
+
...baseFileStructure,
|
|
578
|
+
node_modules: {
|
|
579
|
+
'custom-path-package': {
|
|
580
|
+
'custom_harmony': {
|
|
581
|
+
'custom.har': '',
|
|
582
|
+
'subdir': {
|
|
583
|
+
'nested.har': '',
|
|
584
|
+
},
|
|
585
|
+
},
|
|
586
|
+
'package.json': JSON.stringify({
|
|
587
|
+
name: 'custom-path-package',
|
|
588
|
+
harmony: {
|
|
589
|
+
autolinking: {
|
|
590
|
+
mainHarPath: 'custom_harmony',
|
|
591
|
+
},
|
|
592
|
+
},
|
|
593
|
+
}),
|
|
594
|
+
},
|
|
595
|
+
},
|
|
596
|
+
},
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
const output = await runAutolinking();
|
|
600
|
+
|
|
601
|
+
const ohPackageContent = memFS.readTextSync(output.ohPackagePath);
|
|
602
|
+
// Should find both HAR files in custom_harmony directory (recursive scan)
|
|
603
|
+
expect(ohPackageContent).toContain('@rnoh/custom-path-package--custom');
|
|
604
|
+
expect(ohPackageContent).toContain('@rnoh/custom-path-package--nested');
|
|
605
|
+
expect(ohPackageContent).toContain('custom_harmony/custom.har');
|
|
606
|
+
expect(ohPackageContent).toContain('custom_harmony/subdir/nested.har');
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
it('should support multiple HARs with ohPackageName array mapping', async () => {
|
|
610
|
+
const { runAutolinking, memFS } = createAutolinking({
|
|
611
|
+
fsStructure: {
|
|
612
|
+
...baseFileStructure,
|
|
613
|
+
node_modules: {
|
|
614
|
+
'multi-har-package': {
|
|
615
|
+
harmony: {
|
|
616
|
+
'core.har': '',
|
|
617
|
+
'ui.har': '',
|
|
618
|
+
},
|
|
619
|
+
'package.json': JSON.stringify({
|
|
620
|
+
name: 'multi-har-package',
|
|
621
|
+
harmony: {
|
|
622
|
+
autolinking: {
|
|
623
|
+
ohPackageName: [
|
|
624
|
+
{ harName: 'core.har', packageName: '@rnoh/multi-har--core' },
|
|
625
|
+
{ harName: 'ui.har', packageName: '@rnoh/multi-har--ui' },
|
|
626
|
+
],
|
|
627
|
+
etsPackageClassName: 'MultiHarPackage',
|
|
628
|
+
cppPackageClassName: 'MultiHarPackage',
|
|
629
|
+
cmakeLibraryTargetName: 'rnoh__multi_har',
|
|
630
|
+
},
|
|
631
|
+
},
|
|
632
|
+
}),
|
|
633
|
+
},
|
|
634
|
+
},
|
|
635
|
+
},
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
const output = await runAutolinking();
|
|
639
|
+
|
|
640
|
+
const ohPackageContent = memFS.readTextSync(output.ohPackagePath);
|
|
641
|
+
// Both HARs should be in oh-package.json5 with their custom package names
|
|
642
|
+
expect(ohPackageContent).toContain('@rnoh/multi-har--core');
|
|
643
|
+
expect(ohPackageContent).toContain('@rnoh/multi-har--ui');
|
|
644
|
+
expect(ohPackageContent).toContain('harmony/core.har');
|
|
645
|
+
expect(ohPackageContent).toContain('harmony/ui.har');
|
|
646
|
+
|
|
647
|
+
// ETS template should use shared package class name
|
|
648
|
+
const etsContent = memFS.readTextSync(output.etsRNOHPackagesFactoryPath);
|
|
649
|
+
expect(etsContent).toContain('import MultiHarPackage from \'@rnoh/multi-har--core\'');
|
|
650
|
+
expect(etsContent).toContain('new MultiHarPackage(ctx)');
|
|
651
|
+
|
|
652
|
+
// C++ template should use shared package class name
|
|
653
|
+
const cppContent = memFS.readTextSync(output.cppRNOHPackagesFactoryPath);
|
|
654
|
+
expect(cppContent).toContain('#include "MultiHarPackage.h"');
|
|
655
|
+
expect(cppContent).toContain('std::make_shared<rnoh::MultiHarPackage>(ctx)');
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
it('should use default naming with suffix for unmatched HARs when ohPackageName is array', async () => {
|
|
659
|
+
const { runAutolinking, memFS } = createAutolinking({
|
|
660
|
+
fsStructure: {
|
|
661
|
+
...baseFileStructure,
|
|
662
|
+
node_modules: {
|
|
663
|
+
'partial-mapping-package': {
|
|
664
|
+
harmony: {
|
|
665
|
+
'matched.har': '',
|
|
666
|
+
'unmatched.har': '',
|
|
667
|
+
},
|
|
668
|
+
'package.json': JSON.stringify({
|
|
669
|
+
name: 'partial-mapping-package',
|
|
670
|
+
harmony: {
|
|
671
|
+
autolinking: {
|
|
672
|
+
ohPackageName: [
|
|
673
|
+
{ harName: 'matched.har', packageName: '@rnoh/partial--matched' },
|
|
674
|
+
// unmatched.har is not in the mapping, should use default name with suffix
|
|
675
|
+
],
|
|
676
|
+
},
|
|
677
|
+
},
|
|
678
|
+
}),
|
|
679
|
+
},
|
|
680
|
+
},
|
|
681
|
+
},
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
const output = await runAutolinking();
|
|
685
|
+
|
|
686
|
+
const ohPackageContent = memFS.readTextSync(output.ohPackagePath);
|
|
687
|
+
// matched.har should use custom package name
|
|
688
|
+
expect(ohPackageContent).toContain('@rnoh/partial--matched');
|
|
689
|
+
// unmatched.har should use default naming with suffix
|
|
690
|
+
expect(ohPackageContent).toContain('@rnoh/partial-mapping-package--unmatched');
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
it('should support remote dependency with version field', async () => {
|
|
694
|
+
const { runAutolinking, memFS } = createAutolinking({
|
|
695
|
+
fsStructure: {
|
|
696
|
+
...baseFileStructure,
|
|
697
|
+
node_modules: {
|
|
698
|
+
'remote-lib': {
|
|
699
|
+
harmony: {
|
|
700
|
+
'remote.har': '',
|
|
701
|
+
},
|
|
702
|
+
'package.json': JSON.stringify({
|
|
703
|
+
name: 'remote-lib',
|
|
704
|
+
harmony: {
|
|
705
|
+
autolinking: {
|
|
706
|
+
ohPackageName: [
|
|
707
|
+
{ harName: 'remote.har', packageName: '@ohos/remote-lib', version: '1.0.0' }
|
|
708
|
+
],
|
|
709
|
+
etsPackageClassName: 'RemoteLibPackage',
|
|
710
|
+
cppPackageClassName: 'RemoteLibPackage',
|
|
711
|
+
},
|
|
712
|
+
},
|
|
713
|
+
}),
|
|
714
|
+
},
|
|
715
|
+
},
|
|
716
|
+
},
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
const output = await runAutolinking();
|
|
720
|
+
|
|
721
|
+
const ohPackageContent = memFS.readTextSync(output.ohPackagePath);
|
|
722
|
+
// Should use version number instead of file: path
|
|
723
|
+
expect(ohPackageContent).toContain('"@ohos/remote-lib": "1.0.0"');
|
|
724
|
+
expect(ohPackageContent).not.toContain('file:');
|
|
725
|
+
|
|
726
|
+
// ETS and C++ templates should still work correctly
|
|
727
|
+
const etsContent = memFS.readTextSync(output.etsRNOHPackagesFactoryPath);
|
|
728
|
+
expect(etsContent).toContain('import RemoteLibPackage from \'@ohos/remote-lib\'');
|
|
729
|
+
|
|
730
|
+
const cppContent = memFS.readTextSync(output.cppRNOHPackagesFactoryPath);
|
|
731
|
+
expect(cppContent).toContain('#include "RemoteLibPackage.h"');
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
it('should support mixed local and remote dependencies in same package', async () => {
|
|
735
|
+
const { runAutolinking, memFS } = createAutolinking({
|
|
736
|
+
fsStructure: {
|
|
737
|
+
...baseFileStructure,
|
|
738
|
+
node_modules: {
|
|
739
|
+
'mixed-deps-package': {
|
|
740
|
+
harmony: {
|
|
741
|
+
'local.har': '',
|
|
742
|
+
'remote.har': '',
|
|
743
|
+
},
|
|
744
|
+
'package.json': JSON.stringify({
|
|
745
|
+
name: 'mixed-deps-package',
|
|
746
|
+
harmony: {
|
|
747
|
+
autolinking: {
|
|
748
|
+
ohPackageName: [
|
|
749
|
+
// Local dependency (no version)
|
|
750
|
+
{ harName: 'local.har', packageName: '@rnoh/mixed--local' },
|
|
751
|
+
// Remote dependency (with version)
|
|
752
|
+
{ harName: 'remote.har', packageName: '@ohos/mixed--remote', version: '2.0.0' }
|
|
753
|
+
],
|
|
754
|
+
etsPackageClassName: 'MixedDepsPackage',
|
|
755
|
+
cppPackageClassName: 'MixedDepsPackage',
|
|
756
|
+
},
|
|
757
|
+
},
|
|
758
|
+
}),
|
|
759
|
+
},
|
|
760
|
+
},
|
|
761
|
+
},
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
const output = await runAutolinking();
|
|
765
|
+
|
|
766
|
+
const ohPackageContent = memFS.readTextSync(output.ohPackagePath);
|
|
767
|
+
// Local dependency should use file: path
|
|
768
|
+
expect(ohPackageContent).toContain('"@rnoh/mixed--local": "file:');
|
|
769
|
+
expect(ohPackageContent).toContain('harmony/local.har');
|
|
770
|
+
// Remote dependency should use version number
|
|
771
|
+
expect(ohPackageContent).toContain('"@ohos/mixed--remote": "2.0.0"');
|
|
772
|
+
});
|
|
773
|
+
|
|
774
|
+
it('should support multiple remote dependencies', async () => {
|
|
775
|
+
const { runAutolinking, memFS } = createAutolinking({
|
|
776
|
+
fsStructure: {
|
|
777
|
+
...baseFileStructure,
|
|
778
|
+
node_modules: {
|
|
779
|
+
'multi-remote-package': {
|
|
780
|
+
harmony: {
|
|
781
|
+
'core.har': '',
|
|
782
|
+
'ui.har': '',
|
|
783
|
+
},
|
|
784
|
+
'package.json': JSON.stringify({
|
|
785
|
+
name: 'multi-remote-package',
|
|
786
|
+
harmony: {
|
|
787
|
+
autolinking: {
|
|
788
|
+
ohPackageName: [
|
|
789
|
+
{ harName: 'core.har', packageName: '@ohos/multi--core', version: '^1.0.0' },
|
|
790
|
+
{ harName: 'ui.har', packageName: '@ohos/multi--ui', version: '^2.0.0' }
|
|
791
|
+
],
|
|
792
|
+
etsPackageClassName: 'MultiRemotePackage',
|
|
793
|
+
cppPackageClassName: 'MultiRemotePackage',
|
|
794
|
+
},
|
|
795
|
+
},
|
|
796
|
+
}),
|
|
797
|
+
},
|
|
798
|
+
},
|
|
799
|
+
},
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
const output = await runAutolinking();
|
|
803
|
+
|
|
804
|
+
const ohPackageContent = memFS.readTextSync(output.ohPackagePath);
|
|
805
|
+
// Both should use version numbers
|
|
806
|
+
expect(ohPackageContent).toContain('"@ohos/multi--core": "^1.0.0"');
|
|
807
|
+
expect(ohPackageContent).toContain('"@ohos/multi--ui": "^2.0.0"');
|
|
808
|
+
expect(ohPackageContent).not.toContain('file:');
|
|
809
|
+
});
|
|
@@ -32,13 +32,51 @@ export type AutolinkingConfig = {
|
|
|
32
32
|
includedNpmPackageNames: Set<string>;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* ohPackageName 数组配置项类型
|
|
37
|
+
* 用于将 HAR 文件名映射到指定的 ohPackage 名
|
|
38
|
+
*/
|
|
39
|
+
type OhPackageNameMapping = {
|
|
40
|
+
harName: string;
|
|
41
|
+
packageName: string;
|
|
42
|
+
/**
|
|
43
|
+
* 可选版本号,指定后使用远程依赖(版本号)而非本地依赖(file: 路径)
|
|
44
|
+
*/
|
|
45
|
+
version?: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* ohPackageName 支持的类型
|
|
50
|
+
* - string: 所有 HAR 共用同一个包名(兼容旧格式)
|
|
51
|
+
* - OhPackageNameMapping[]: 每个 HAR 可以有独立的包名
|
|
52
|
+
*/
|
|
53
|
+
type OhPackageNameConfig = string | OhPackageNameMapping[];
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 解析后的 HAR 配置
|
|
57
|
+
* 每个 HAR 文件对应一个 ResolvedHar
|
|
58
|
+
*/
|
|
59
|
+
type ResolvedHar = {
|
|
60
|
+
harFilePathRelativeToHarmony: string;
|
|
61
|
+
ohPackageName: string;
|
|
62
|
+
/**
|
|
63
|
+
* 可选版本号,有值时使用远程依赖(版本号)而非本地依赖(file: 路径)
|
|
64
|
+
*/
|
|
65
|
+
version?: string;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 可链接的库配置
|
|
70
|
+
* 支持单个或多个 HAR 文件
|
|
71
|
+
*/
|
|
35
72
|
type AutolinkableLibrary = {
|
|
36
73
|
npmPackageName: string;
|
|
37
|
-
|
|
74
|
+
// 解析后的 HAR 配置数组(支持多个 HAR)
|
|
75
|
+
resolvedHars: ResolvedHar[];
|
|
76
|
+
// 以下配置所有 HAR 共享
|
|
38
77
|
etsRNOHPackageClassName?: string;
|
|
39
78
|
cppRNOHPackageClassName?: string;
|
|
40
79
|
cmakeLibraryTargetName?: string;
|
|
41
|
-
ohPackageName?: string;
|
|
42
80
|
};
|
|
43
81
|
|
|
44
82
|
type AutolinkingInput = {
|
|
@@ -156,36 +194,52 @@ export class Autolinking {
|
|
|
156
194
|
const skippedLibraryNpmPackageNames: string[] = [];
|
|
157
195
|
await new ProjectDependenciesManager(this.fs, projectRootPath).forEachAsync(
|
|
158
196
|
(dependency) => {
|
|
159
|
-
|
|
197
|
+
// 读取 package.json 配置
|
|
198
|
+
const packageJson = dependency.readPackageJSON();
|
|
199
|
+
const providedAutolinkingConfig = packageJson.harmony?.autolinking;
|
|
200
|
+
|
|
201
|
+
// 解析 autolinking 配置
|
|
202
|
+
const autolinkingConfig =
|
|
203
|
+
providedAutolinkingConfig === true ? {} : providedAutolinkingConfig;
|
|
204
|
+
|
|
205
|
+
// 获取自定义的 HAR 扫描路径
|
|
206
|
+
const mainHarPath = autolinkingConfig?.mainHarPath;
|
|
207
|
+
|
|
208
|
+
// 扫描 HAR 文件
|
|
209
|
+
const harFilePaths = dependency.getHarFilePaths(mainHarPath);
|
|
160
210
|
if (harFilePaths.length === 0) {
|
|
161
211
|
return;
|
|
162
212
|
}
|
|
163
213
|
nodeModuleHarPaths.push(...harFilePaths);
|
|
164
|
-
|
|
165
|
-
|
|
214
|
+
|
|
215
|
+
// 检查是否应该跳过该包
|
|
166
216
|
if (
|
|
167
217
|
providedAutolinkingConfig === undefined ||
|
|
168
218
|
providedAutolinkingConfig === null ||
|
|
169
219
|
(config.excludedNpmPackageNames.has(packageJson.name) &&
|
|
170
220
|
config.excludedNpmPackageNames.size > 0) ||
|
|
171
221
|
(!config.includedNpmPackageNames.has(packageJson.name) &&
|
|
172
|
-
config.includedNpmPackageNames.size > 0)
|
|
173
|
-
harFilePaths.length !== 1
|
|
222
|
+
config.includedNpmPackageNames.size > 0)
|
|
174
223
|
) {
|
|
175
224
|
skippedLibraryNpmPackageNames.push(packageJson.name);
|
|
176
225
|
return;
|
|
177
226
|
}
|
|
178
|
-
|
|
179
|
-
|
|
227
|
+
|
|
228
|
+
// 解析 ohPackageName 配置,生成每个 HAR 对应的包名
|
|
229
|
+
const ohPackageNameConfig = autolinkingConfig?.ohPackageName as OhPackageNameConfig | undefined;
|
|
230
|
+
const resolvedHars = this.resolveHarPackageNames(
|
|
231
|
+
harFilePaths,
|
|
232
|
+
ohPackageNameConfig,
|
|
233
|
+
packageJson.name,
|
|
234
|
+
harmonyProjectPath
|
|
235
|
+
);
|
|
236
|
+
|
|
180
237
|
autolinkableLibraries.push({
|
|
181
238
|
npmPackageName: packageJson.name,
|
|
239
|
+
resolvedHars,
|
|
182
240
|
etsRNOHPackageClassName: autolinkingConfig?.etsPackageClassName,
|
|
183
241
|
cppRNOHPackageClassName: autolinkingConfig?.cppPackageClassName,
|
|
184
242
|
cmakeLibraryTargetName: autolinkingConfig?.cmakeLibraryTargetName,
|
|
185
|
-
ohPackageName: autolinkingConfig?.ohPackageName,
|
|
186
|
-
harFilePathRelativeToHarmony: harFilePaths[0]
|
|
187
|
-
.relativeTo(harmonyProjectPath)
|
|
188
|
-
.toString(),
|
|
189
243
|
});
|
|
190
244
|
}
|
|
191
245
|
);
|
|
@@ -216,8 +270,79 @@ export class Autolinking {
|
|
|
216
270
|
};
|
|
217
271
|
}
|
|
218
272
|
|
|
273
|
+
/**
|
|
274
|
+
* 解析 HAR 文件的 ohPackage 名称
|
|
275
|
+
* @param harFilePaths HAR 文件路径列表
|
|
276
|
+
* @param ohPackageNameConfig ohPackageName 配置(字符串或数组)
|
|
277
|
+
* @param npmPackageName npm 包名
|
|
278
|
+
* @param harmonyProjectPath Harmony 项目路径
|
|
279
|
+
*/
|
|
280
|
+
private resolveHarPackageNames(
|
|
281
|
+
harFilePaths: AbsolutePath[],
|
|
282
|
+
ohPackageNameConfig: OhPackageNameConfig | undefined,
|
|
283
|
+
npmPackageName: string,
|
|
284
|
+
harmonyProjectPath: AbsolutePath
|
|
285
|
+
): ResolvedHar[] {
|
|
286
|
+
// 默认的 ohPackage 名称
|
|
287
|
+
const defaultOhPackageName = this.npmPackageNameToOHPackageName(npmPackageName);
|
|
288
|
+
|
|
289
|
+
// 构建 HAR 文件名到路径的映射
|
|
290
|
+
const harPathMap = new Map<string, AbsolutePath>();
|
|
291
|
+
for (const harPath of harFilePaths) {
|
|
292
|
+
const harFileName = pathUtils.basename(harPath.toString());
|
|
293
|
+
harPathMap.set(harFileName, harPath);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// 辅助函数:创建 ResolvedHar
|
|
297
|
+
const createResolvedHar = (harPath: AbsolutePath, ohPkgName: string, version?: string): ResolvedHar => ({
|
|
298
|
+
harFilePathRelativeToHarmony: harPath.relativeTo(harmonyProjectPath).toString(),
|
|
299
|
+
ohPackageName: ohPkgName,
|
|
300
|
+
version,
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
const result: ResolvedHar[] = [];
|
|
304
|
+
const processedHarNames = new Set<string>();
|
|
305
|
+
|
|
306
|
+
// 1. 如果是数组配置,按照配置顺序处理
|
|
307
|
+
if (Array.isArray(ohPackageNameConfig)) {
|
|
308
|
+
for (const mapping of ohPackageNameConfig) {
|
|
309
|
+
const harPath = harPathMap.get(mapping.harName);
|
|
310
|
+
if (harPath) {
|
|
311
|
+
result.push(createResolvedHar(harPath, mapping.packageName, mapping.version));
|
|
312
|
+
processedHarNames.add(mapping.harName);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// 2. 处理未在配置中指定的 HAR(按文件系统扫描顺序)
|
|
318
|
+
for (const harPath of harFilePaths) {
|
|
319
|
+
const harFileName = pathUtils.basename(harPath.toString());
|
|
320
|
+
if (processedHarNames.has(harFileName)) {
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// 如果是字符串格式,所有 HAR 共用
|
|
325
|
+
if (typeof ohPackageNameConfig === 'string') {
|
|
326
|
+
const suffix = harFilePaths.length > 1
|
|
327
|
+
? '--' + pathUtils.basename(harFileName, '.har')
|
|
328
|
+
: '';
|
|
329
|
+
result.push(createResolvedHar(harPath, ohPackageNameConfig + suffix));
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// 默认命名规则
|
|
334
|
+
const suffix = harFilePaths.length > 1
|
|
335
|
+
? '--' + pathUtils.basename(harFileName, '.har')
|
|
336
|
+
: '';
|
|
337
|
+
result.push(createResolvedHar(harPath, defaultOhPackageName + suffix));
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return result;
|
|
341
|
+
}
|
|
342
|
+
|
|
219
343
|
evaluate(input: AutolinkingInput): AutolinkingOutput {
|
|
220
|
-
|
|
344
|
+
// 处理库配置,应用默认值
|
|
345
|
+
const autolinkableLibraries: (Required<Omit<AutolinkableLibrary, 'resolvedHars'>> & { resolvedHars: ResolvedHar[] })[] =
|
|
221
346
|
input.autolinkableLibraries.map((lib) => {
|
|
222
347
|
return {
|
|
223
348
|
...lib,
|
|
@@ -230,9 +355,7 @@ export class Autolinking {
|
|
|
230
355
|
cmakeLibraryTargetName:
|
|
231
356
|
lib.cmakeLibraryTargetName ??
|
|
232
357
|
this.npmPackageNameToCMakeLibraryTargetName(lib.npmPackageName),
|
|
233
|
-
|
|
234
|
-
lib.ohPackageName ??
|
|
235
|
-
this.npmPackageNameToOHPackageName(lib.npmPackageName),
|
|
358
|
+
resolvedHars: lib.resolvedHars,
|
|
236
359
|
};
|
|
237
360
|
});
|
|
238
361
|
autolinkableLibraries.sort((a, b) => {
|
|
@@ -240,14 +363,18 @@ export class Autolinking {
|
|
|
240
363
|
if (a.npmPackageName > b.npmPackageName) return 1;
|
|
241
364
|
return 0;
|
|
242
365
|
});
|
|
366
|
+
|
|
243
367
|
const ohPackage = JSON5.parse(input.ohPackagePathAndContent[1]);
|
|
244
|
-
const autolinkableHarFilePathsRelativeToHarmony = autolinkableLibraries.map(
|
|
245
|
-
(lib) => lib.harFilePathRelativeToHarmony
|
|
246
|
-
);
|
|
247
368
|
const unmanagedNativeDependencySpecifierByName: Record<
|
|
248
369
|
string,
|
|
249
370
|
DependencySpecifier
|
|
250
371
|
> = {};
|
|
372
|
+
|
|
373
|
+
// 收集所有配置了 autolinking 的 npm 包名
|
|
374
|
+
const autolinkedNpmPackageNames = new Set(
|
|
375
|
+
autolinkableLibraries.map(lib => lib.npmPackageName)
|
|
376
|
+
);
|
|
377
|
+
|
|
251
378
|
Object.entries<DependencySpecifier>(ohPackage.dependencies).forEach(
|
|
252
379
|
([name, dependencySpecifier]) => {
|
|
253
380
|
if (
|
|
@@ -256,31 +383,53 @@ export class Autolinking {
|
|
|
256
383
|
dependencySpecifier.includes('node_modules')
|
|
257
384
|
)
|
|
258
385
|
) {
|
|
386
|
+
// 不是 file:node_modules 格式 → 非托管,保留
|
|
259
387
|
unmanagedNativeDependencySpecifierByName[name] = dependencySpecifier;
|
|
260
388
|
} else {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
)
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
input.
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
dependencySpecifier;
|
|
389
|
+
// 是 file:node_modules 格式,判断对应的 npm 包是否配置了 autolinking
|
|
390
|
+
const npmPackageName = this.extractNpmPackageNameFromPath(dependencySpecifier);
|
|
391
|
+
|
|
392
|
+
if (!npmPackageName || !autolinkedNpmPackageNames.has(npmPackageName)) {
|
|
393
|
+
// 没有配置 autolinking → 需要检查 HAR 文件是否实际存在
|
|
394
|
+
const harPath = dependencySpecifier.replace('file:', '');
|
|
395
|
+
const normalizedHarPath = pathUtils.normalize(harPath);
|
|
396
|
+
// 依赖路径是相对于 harmony 项目的,oh-package.json5 所在目录就是 harmony 项目目录
|
|
397
|
+
const harmonyProjectPath = input.ohPackagePathAndContent[0].getDirectoryPath();
|
|
398
|
+
const absoluteHarPath = harmonyProjectPath.copyWithNewSegment(normalizedHarPath);
|
|
399
|
+
|
|
400
|
+
if (this.fs.existsSync(absoluteHarPath)) {
|
|
401
|
+
// HAR 文件存在 → 非托管,保留原依赖
|
|
402
|
+
unmanagedNativeDependencySpecifierByName[name] = dependencySpecifier;
|
|
403
|
+
}
|
|
404
|
+
// HAR 文件不存在 → 不保留(清理无效依赖)
|
|
275
405
|
}
|
|
406
|
+
// 如果配置了 autolinking → 不保留(后面会用新生成的值替换)
|
|
276
407
|
}
|
|
277
408
|
}
|
|
278
409
|
);
|
|
410
|
+
|
|
411
|
+
// 为每个 HAR 生成依赖条目
|
|
279
412
|
const managedNativeDependencySpecifierByName: Record<string, string> = {};
|
|
280
413
|
for (const library of autolinkableLibraries) {
|
|
281
|
-
|
|
282
|
-
|
|
414
|
+
for (const har of library.resolvedHars) {
|
|
415
|
+
// 如果有 version 字段,使用版本号(远程依赖);否则使用 file: 路径(本地依赖)
|
|
416
|
+
managedNativeDependencySpecifierByName[har.ohPackageName] =
|
|
417
|
+
har.version ??
|
|
418
|
+
`file:${har.harFilePathRelativeToHarmony}`.split(pathUtils.sep).join('/');
|
|
419
|
+
}
|
|
283
420
|
}
|
|
421
|
+
|
|
422
|
+
// 为模板准备数据:每个库需要生成 import 语句
|
|
423
|
+
// 由于所有 HAR 共享同一个 Package 类名,每个库只需要一个 import
|
|
424
|
+
const templateLibraries = autolinkableLibraries.map((lib) => {
|
|
425
|
+
// 使用第一个 HAR 的 ohPackageName 作为 import 来源
|
|
426
|
+
const primaryOhPackageName = lib.resolvedHars[0]?.ohPackageName ?? '';
|
|
427
|
+
return {
|
|
428
|
+
...lib,
|
|
429
|
+
ohPackageName: primaryOhPackageName,
|
|
430
|
+
};
|
|
431
|
+
});
|
|
432
|
+
|
|
284
433
|
return {
|
|
285
434
|
skippedLibraryNpmPackageNames: input.skippedLibraryNpmPackageNames,
|
|
286
435
|
linkedLibraryNpmPackageNames: autolinkableLibraries.map(
|
|
@@ -290,19 +439,19 @@ export class Autolinking {
|
|
|
290
439
|
cppRNOHPackagesFactoryPathAndContent: [
|
|
291
440
|
input.cppRNOHPackagesFactoryPath,
|
|
292
441
|
Mustache.render(CPP_RNOH_PACKAGES_FACTORY_TEMPLATE, {
|
|
293
|
-
libraries:
|
|
442
|
+
libraries: templateLibraries,
|
|
294
443
|
}),
|
|
295
444
|
],
|
|
296
445
|
etsRNOHPackagesFactoryPathAndContent: [
|
|
297
446
|
input.etsRNOHPackagesFactoryPath,
|
|
298
447
|
Mustache.render(ETS_RNOH_PACKAGES_FACTORY_TEMPLATE, {
|
|
299
|
-
libraries:
|
|
448
|
+
libraries: templateLibraries,
|
|
300
449
|
}),
|
|
301
450
|
],
|
|
302
451
|
cmakeAutolinkingPathAndContent: [
|
|
303
452
|
input.cmakeAutolinkingPath,
|
|
304
453
|
Mustache.render(CMAKE_AUTOLINKING_TEMPLATE, {
|
|
305
|
-
libraries:
|
|
454
|
+
libraries: templateLibraries,
|
|
306
455
|
}),
|
|
307
456
|
],
|
|
308
457
|
ohPackagePathAndContent: [
|
|
@@ -348,6 +497,41 @@ export class Autolinking {
|
|
|
348
497
|
return '@rnoh/' + Case.kebab(fullNpmPackageName);
|
|
349
498
|
}
|
|
350
499
|
|
|
500
|
+
/**
|
|
501
|
+
* 从依赖路径中提取 npm 包名
|
|
502
|
+
* @param dependencySpecifier 依赖路径,如 "file:../node_modules/@scope/package/harmony/xxx.har"
|
|
503
|
+
* @returns npm 包名,如 "@scope/package";如果无法解析则返回 null
|
|
504
|
+
*/
|
|
505
|
+
private extractNpmPackageNameFromPath(dependencySpecifier: string): string | null {
|
|
506
|
+
// 移除 file: 前缀
|
|
507
|
+
const path = dependencySpecifier.replace(/^file:/, '');
|
|
508
|
+
|
|
509
|
+
// 查找 node_modules 后面的部分
|
|
510
|
+
const nodeModulesIndex = path.indexOf('node_modules/');
|
|
511
|
+
if (nodeModulesIndex === -1) {
|
|
512
|
+
return null;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const afterNodeModules = path.substring(nodeModulesIndex + 'node_modules/'.length);
|
|
516
|
+
|
|
517
|
+
// 检查是否是 scoped package (@scope/package)
|
|
518
|
+
if (afterNodeModules.startsWith('@')) {
|
|
519
|
+
const parts = afterNodeModules.split('/');
|
|
520
|
+
if (parts.length >= 2) {
|
|
521
|
+
return `${parts[0]}/${parts[1]}`; // @scope/package
|
|
522
|
+
}
|
|
523
|
+
} else {
|
|
524
|
+
// 非 scoped package
|
|
525
|
+
const firstSlash = afterNodeModules.indexOf('/');
|
|
526
|
+
if (firstSlash !== -1) {
|
|
527
|
+
return afterNodeModules.substring(0, firstSlash);
|
|
528
|
+
}
|
|
529
|
+
return afterNodeModules || null;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
return null;
|
|
533
|
+
}
|
|
534
|
+
|
|
351
535
|
saveAndLogOutput(output: AutolinkingOutput) {
|
|
352
536
|
const pathAndContentPairs: [AbsolutePath, string][] = [];
|
|
353
537
|
pathAndContentPairs.push(output.etsRNOHPackagesFactoryPathAndContent);
|
package/src/core/PackageJSON.ts
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Huawei Technologies Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
1
7
|
import { AbsolutePath } from './AbsolutePath';
|
|
2
8
|
import { CodegenConfig, RawCodegenConfig } from './CodegenConfig';
|
|
3
9
|
import { DescriptiveError } from './DescriptiveError';
|
|
4
10
|
import { FS } from './FileSystem';
|
|
5
11
|
|
|
12
|
+
/**
|
|
13
|
+
* ohPackageName 数组配置项类型
|
|
14
|
+
* 用于将 HAR 文件名映射到指定的 ohPackage 名
|
|
15
|
+
*/
|
|
16
|
+
type OhPackageNameMapping = {
|
|
17
|
+
harName: string;
|
|
18
|
+
packageName: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
6
21
|
type RawAutolinkingConfig = {
|
|
7
22
|
etsPackageClassName?: string;
|
|
8
23
|
cppPackageClassName?: string;
|
|
9
24
|
cmakeLibraryTargetName?: string;
|
|
10
|
-
ohPackageName
|
|
25
|
+
// ohPackageName 支持字符串(兼容旧格式)或数组(多 HAR 匹配)
|
|
26
|
+
ohPackageName?: string | OhPackageNameMapping[];
|
|
27
|
+
// HAR 扫描根目录(相对于包根目录),默认为 'harmony'
|
|
28
|
+
mainHarPath?: string;
|
|
11
29
|
};
|
|
12
30
|
|
|
13
31
|
export class PackageJSON {
|