@react-native-oh/react-native-harmony-cli 0.0.24 → 0.0.26-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.
Files changed (109) hide show
  1. package/.prettierrc +6 -6
  2. package/dist/assetResolver.js +1 -23
  3. package/dist/codegen/core/CodeGenerator.js +2 -0
  4. package/dist/codegen/core/UberSchema.js +35 -9
  5. package/dist/codegen/core/index.js +1 -1
  6. package/dist/codegen/generators/{ComponentCodeGenerator.js → ComponentCodeGeneratorArkTS.js} +12 -4
  7. package/dist/codegen/generators/ComponentCodeGeneratorCAPI.js +79 -0
  8. package/dist/codegen/generators/GlueCodeGenerator.js +60 -0
  9. package/dist/codegen/generators/NativeModuleCodeGenerator.js +14 -6
  10. package/dist/codegen/generators/UberGeneratorV1.js +49 -0
  11. package/dist/codegen/generators/UberGeneratorV2.js +60 -0
  12. package/dist/codegen/generators/index.js +5 -2
  13. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +103 -0
  14. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +42 -36
  15. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +45 -36
  16. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +135 -127
  17. package/dist/codegen/templates/GeneratedPackageHTemplate.js +101 -0
  18. package/dist/codegen/templates/IndexTSTemplate.js +23 -5
  19. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +88 -82
  20. package/dist/codegen/templates/TurboModuleCppTemplate.js +26 -18
  21. package/dist/codegen/templates/TurboModuleHTemplate.js +27 -17
  22. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +37 -27
  23. package/dist/codegen/templates/index.js +1 -0
  24. package/dist/commands/codegen-harmony.js +99 -14
  25. package/dist/commands/index.js +1 -0
  26. package/dist/commands/verify-package-harmony.js +127 -0
  27. package/dist/core/AbsolutePath.js +6 -0
  28. package/dist/core/CodegenConfig.js +8 -4
  29. package/dist/core/OHPackageJSON5.js +23 -0
  30. package/dist/core/PackageJSON.js +8 -3
  31. package/dist/core/ProjectDependenciesManager.js +2 -2
  32. package/dist/core/index.js +1 -0
  33. package/dist/index.js +1 -0
  34. package/dist/io/TarGz.js +28 -0
  35. package/dist/io/index.js +1 -0
  36. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +38 -0
  37. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +32 -0
  38. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +26 -0
  39. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +51 -0
  40. package/dist/package-verifier/checks/index.js +20 -0
  41. package/dist/package-verifier/index.js +18 -0
  42. package/dist/package-verifier/types.js +2 -0
  43. package/dist/package-verifier/verify-package.js +100 -0
  44. package/jest.config.js +5 -5
  45. package/package.json +57 -52
  46. package/react-native.config.js +10 -10
  47. package/src/assetResolver.ts +21 -44
  48. package/src/codegen/core/CodeGenerator.ts +9 -0
  49. package/src/codegen/core/CodegenError.ts +3 -3
  50. package/src/codegen/core/EventUtils.ts +18 -18
  51. package/src/codegen/core/TypeAnnotationToTS.test.ts +75 -75
  52. package/src/codegen/core/TypeAnnotationToTS.ts +188 -188
  53. package/src/codegen/core/UberSchema.ts +142 -99
  54. package/src/codegen/core/index.ts +5 -5
  55. package/src/codegen/generators/{ComponentCodeGenerator.ts → ComponentCodeGeneratorArkTS.ts} +112 -98
  56. package/src/codegen/generators/ComponentCodeGeneratorCAPI.ts +114 -0
  57. package/src/codegen/generators/GlueCodeGenerator.ts +109 -0
  58. package/src/codegen/generators/NativeModuleCodeGenerator.ts +115 -95
  59. package/src/codegen/generators/UberGeneratorV1.ts +64 -0
  60. package/src/codegen/generators/UberGeneratorV2.ts +91 -0
  61. package/src/codegen/generators/index.ts +6 -3
  62. package/src/codegen/index.ts +2 -2
  63. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +116 -0
  64. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +55 -49
  65. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +93 -85
  66. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +210 -202
  67. package/src/codegen/templates/GeneratedPackageHTemplate.ts +107 -0
  68. package/src/codegen/templates/IndexTSTemplate.ts +53 -33
  69. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +130 -124
  70. package/src/codegen/templates/TurboModuleCppTemplate.ts +54 -47
  71. package/src/codegen/templates/TurboModuleHTemplate.ts +35 -26
  72. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +90 -81
  73. package/src/codegen/templates/index.ts +9 -8
  74. package/src/commands/bundle-harmony.ts +203 -202
  75. package/src/commands/codegen-harmony.ts +272 -143
  76. package/src/commands/create-metro-host-constants.ts +48 -48
  77. package/src/commands/index.ts +6 -5
  78. package/src/commands/pack-harmony.ts +121 -121
  79. package/src/commands/unpack-harmony.ts +231 -231
  80. package/src/commands/verify-package-harmony.ts +106 -0
  81. package/src/core/AbsolutePath.ts +50 -43
  82. package/src/core/CodegenConfig.ts +62 -54
  83. package/src/core/DescriptiveError.ts +61 -61
  84. package/src/core/OHPackageJSON5.ts +23 -0
  85. package/src/core/PackageJSON.ts +75 -63
  86. package/src/core/ProjectDependenciesManager.ts +77 -77
  87. package/src/core/ValidationError.ts +1 -1
  88. package/src/core/ValueObject.ts +2 -2
  89. package/src/core/fs.ts +31 -31
  90. package/src/core/index.ts +9 -8
  91. package/src/index.ts +20 -18
  92. package/src/io/Logger.ts +68 -68
  93. package/src/io/TarGz.ts +26 -0
  94. package/src/io/fsUtils.ts +24 -24
  95. package/src/io/index.ts +3 -2
  96. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +28 -0
  97. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +24 -0
  98. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +18 -0
  99. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +47 -0
  100. package/src/package-verifier/checks/index.ts +4 -0
  101. package/src/package-verifier/index.ts +2 -0
  102. package/src/package-verifier/types.ts +12 -0
  103. package/src/package-verifier/verify-package.ts +117 -0
  104. package/tsconfig.build.json +6 -6
  105. package/tsconfig.json +2 -2
  106. package/dist/codegen/core/Codegen.js +0 -35
  107. package/dist/codegen/generators/PackageCodeGenerator.js +0 -52
  108. package/src/codegen/core/Codegen.ts +0 -44
  109. package/src/codegen/generators/PackageCodeGenerator.ts +0 -73
package/package.json CHANGED
@@ -1,52 +1,57 @@
1
- {
2
- "name": "@react-native-oh/react-native-harmony-cli",
3
- "version": "0.0.24",
4
- "description": "",
5
- "publishConfig": {
6
- "registry": "https://registry.npmjs.org/",
7
- "access": "public"
8
- },
9
- "scripts": {
10
- "build": "tsc --outDir dist -p tsconfig.build.json",
11
- "prepack": "npm run build",
12
- "verify": "tsc --noEmit && npm run test",
13
- "test": "npm run build && jest",
14
- "test:codegen": "jest ./src/codegen/.* && npm run build && jest tests/codegen.*",
15
- "rn": "npm run build && react-native",
16
- "prepublishOnly": "npm run verify"
17
- },
18
- "keywords": [],
19
- "author": "",
20
- "license": "ISC",
21
- "peerDependencies": {
22
- "metro": "*"
23
- },
24
- "main": "dist/index.js",
25
- "devDependencies": {
26
- "@react-native-community/cli-types": "^11.3.0",
27
- "@types/fs-extra": "^11.0.1",
28
- "@types/jest": "^29.5.1",
29
- "@types/mustache": "^4.2.5",
30
- "@types/tar": "^6.1.5",
31
- "@types/tmp": "^0.2.3",
32
- "directory-tree": "^3.5.1",
33
- "execa": "npm:@esm2cjs/execa@^6.1.1-cjs.1",
34
- "jest": "^29.5.0",
35
- "react-native": "^0.72.0",
36
- "tmp": "^0.2.1",
37
- "ts-jest": "^29.1.0",
38
- "ts-node": "^10.9.1",
39
- "typescript": "^5.0.4"
40
- },
41
- "dependencies": {
42
- "@react-native/codegen": "0.74.0",
43
- "@tsconfig/recommended": "^1.0.2",
44
- "chalk": "^4",
45
- "fs-extra": "^11.1.1",
46
- "glob": "^10.2.6",
47
- "ignore": "^5.2.4",
48
- "json5": "^2.2.3",
49
- "mustache": "^4.2.0",
50
- "tar": "^6.1.15"
51
- }
52
- }
1
+ {
2
+ "name": "@react-native-oh/react-native-harmony-cli",
3
+ "version": "0.0.26-1",
4
+ "description": "",
5
+ "publishConfig": {
6
+ "registry": "https://registry.npmjs.org/",
7
+ "access": "public"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc --outDir dist -p tsconfig.build.json",
11
+ "prepack": "npm run build",
12
+ "verify": "tsc --noEmit && npm run test",
13
+ "test": "npm run build && jest",
14
+ "test:codegen": "jest ./src/codegen/.* && npm run build && jest tests/codegen.*",
15
+ "rn": "npm run build && react-native",
16
+ "prepublishOnly": "npm run verify"
17
+ },
18
+ "keywords": [],
19
+ "author": "",
20
+ "license": "ISC",
21
+ "peerDependencies": {
22
+ "metro": "*"
23
+ },
24
+ "main": "dist/index.js",
25
+ "devDependencies": {
26
+ "@react-native-community/cli-types": "^11.3.0",
27
+ "@types/adm-zip": "^0.5.5",
28
+ "@types/fs-extra": "^11.0.1",
29
+ "@types/jest": "^29.5.1",
30
+ "@types/jszip": "^3.4.1",
31
+ "@types/mustache": "^4.2.5",
32
+ "@types/tar": "^6.1.5",
33
+ "@types/tmp": "^0.2.3",
34
+ "directory-tree": "^3.5.1",
35
+ "execa": "npm:@esm2cjs/execa@^6.1.1-cjs.1",
36
+ "jest": "^29.5.0",
37
+ "react-native": "^0.72.0",
38
+ "ts-jest": "^29.1.0",
39
+ "ts-node": "^10.9.1",
40
+ "typescript": "^5.0.4"
41
+ },
42
+ "dependencies": {
43
+ "@react-native-community/cli-tools": "^13.6.5",
44
+ "@react-native/codegen": "0.74.0",
45
+ "@tsconfig/recommended": "^1.0.2",
46
+ "adm-zip": "^0.5.12",
47
+ "case": "^1.6.3",
48
+ "chalk": "^4",
49
+ "fs-extra": "^11.1.1",
50
+ "glob": "^10.2.6",
51
+ "ignore": "^5.2.4",
52
+ "json5": "^2.2.3",
53
+ "mustache": "^4.2.0",
54
+ "tar": "^6.1.15",
55
+ "tmp": "^0.2.1"
56
+ }
57
+ }
@@ -1,10 +1,10 @@
1
- const { config: harmonyConfig } = require('./dist');
2
-
3
- /**
4
- * @type {import("@react-native-community/cli-types").Config}
5
- */
6
- const config = {
7
- commands: harmonyConfig.commands,
8
- };
9
-
10
- module.exports = config;
1
+ const { config: harmonyConfig } = require('./dist');
2
+
3
+ /**
4
+ * @type {import("@react-native-community/cli-types").Config}
5
+ */
6
+ const config = {
7
+ commands: harmonyConfig.commands,
8
+ };
9
+
10
+ module.exports = config;
@@ -1,44 +1,21 @@
1
- import type { AssetData } from 'metro';
2
-
3
- export type Asset = AssetData;
4
-
5
- /*
6
- cyrb53 (c) 2018 bryc (github.com/bryc)
7
- License: Public domain. Attribution appreciated.
8
- A fast and simple 53-bit string hash function with decent collision resistance.
9
- Largely inspired by MurmurHash2/3, but with a focus on speed/simplicity.
10
- */
11
- function cyrb53(str: string, seed = 0) {
12
- let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
13
- for(let i = 0, ch; i < str.length; i++) {
14
- ch = str.charCodeAt(i);
15
- h1 = Math.imul(h1 ^ ch, 2654435761);
16
- h2 = Math.imul(h2 ^ ch, 1597334677);
17
- }
18
- h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
19
- h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
20
- h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
21
- h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
22
- return 4294967296 * (2097151 & h2) + (h1 >>> 0);
23
- };
24
-
25
-
26
- export function getAssetDestRelativePath(asset: Asset): string {
27
- const fileName = getResourceIdentifier(asset);
28
- return `${fileName}.${asset.type}`;
29
- }
30
-
31
- function getResourceIdentifier(asset: Asset): string {
32
- const folderPath = getBasePath(asset);
33
- const fullAssetPath = `${folderPath}/${asset.name}.${asset.type}`.toLowerCase();
34
- const assetPathHash = cyrb53(fullAssetPath);
35
- return assetPathHash.toString(16);
36
- }
37
-
38
- function getBasePath(asset: Asset): string {
39
- let basePath = asset.httpServerLocation;
40
- if (basePath[0] === '/') {
41
- basePath = basePath.substr(1);
42
- }
43
- return basePath;
44
- }
1
+ import type { AssetData } from 'metro';
2
+
3
+ export type Asset = AssetData;
4
+
5
+ export function getAssetDestRelativePath(asset: Asset): string {
6
+ const fileName = getResourceIdentifier(asset);
7
+ return `${fileName}.${asset.type}`;
8
+ }
9
+
10
+ function getResourceIdentifier(asset: Asset): string {
11
+ const folderPath = getBasePath(asset);
12
+ return `${folderPath}/${asset.name}`.slice('assets/'.length);
13
+ }
14
+
15
+ function getBasePath(asset: Asset): string {
16
+ let basePath = asset.httpServerLocation;
17
+ if (basePath[0] === '/') {
18
+ basePath = basePath.substr(1);
19
+ }
20
+ return basePath;
21
+ }
@@ -0,0 +1,9 @@
1
+ import { AbsolutePath } from '../../core';
2
+ import { SpecSchema } from './UberSchema';
3
+
4
+ type FileContent = string;
5
+ export interface CodeGenerator<T> {
6
+ generate(data: T): Map<AbsolutePath, FileContent>;
7
+ }
8
+
9
+ export interface SpecCodeGenerator extends CodeGenerator<SpecSchema> {}
@@ -1,3 +1,3 @@
1
- import { DescriptiveError } from '../../core';
2
-
3
- export class CodegenError extends DescriptiveError {}
1
+ import { DescriptiveError } from '../../core';
2
+
3
+ export class CodegenError extends DescriptiveError {}
@@ -1,18 +1,18 @@
1
- import { CodegenError } from './CodegenError';
2
-
3
- export function createEventNameFromEventHandlerName(
4
- eventHandlerName: string
5
- ): string {
6
- const eventName = eventHandlerName.replace('on', '');
7
- if (eventName.length === 0) {
8
- throw new CodegenError({
9
- whatHappened: `Received invalid event handler name: ${eventHandlerName}`,
10
- whatCanUserDo: {
11
- default: [
12
- 'Change your event listener name to match naming convention "onEventName" e.g. "onPress"',
13
- ],
14
- },
15
- });
16
- }
17
- return eventName.charAt(0).toLowerCase() + eventName.slice(1);
18
- }
1
+ import { CodegenError } from './CodegenError';
2
+
3
+ export function createEventNameFromEventHandlerName(
4
+ eventHandlerName: string
5
+ ): string {
6
+ const eventName = eventHandlerName.replace('on', '');
7
+ if (eventName.length === 0) {
8
+ throw new CodegenError({
9
+ whatHappened: `Received invalid event handler name: ${eventHandlerName}`,
10
+ whatCanUserDo: {
11
+ default: [
12
+ 'Change your event listener name to match naming convention "onEventName" e.g. "onPress"',
13
+ ],
14
+ },
15
+ });
16
+ }
17
+ return eventName.charAt(0).toLowerCase() + eventName.slice(1);
18
+ }
@@ -1,75 +1,75 @@
1
- import { TypeAnnotationToTS, TypeAnnotation } from './TypeAnnotationToTS';
2
-
3
- function convert(typeAnnotation: TypeAnnotation) {
4
- return new TypeAnnotationToTS().convert(typeAnnotation);
5
- }
6
-
7
- it('should convert boolean prop correctly', () => {
8
- const result = convert({
9
- type: 'BooleanTypeAnnotation',
10
- });
11
-
12
- expect(result).toBe('boolean');
13
- });
14
-
15
- it('should convert string prop correctly', () => {
16
- const result = convert({
17
- type: 'StringTypeAnnotation',
18
- });
19
-
20
- expect(result).toBe('string');
21
- });
22
-
23
- it('should convert double prop correctly', () => {
24
- const result = convert({
25
- type: 'DoubleTypeAnnotation',
26
- });
27
-
28
- expect(result).toBe('number');
29
- });
30
-
31
- it('should convert float prop correctly', () => {
32
- const result = convert({
33
- type: 'FloatTypeAnnotation',
34
- });
35
-
36
- expect(result).toBe('number');
37
- });
38
-
39
- it('should convert object prop correctly', () => {
40
- const result = convert({
41
- type: 'ObjectTypeAnnotation',
42
- properties: [
43
- {
44
- typeAnnotation: { type: 'BooleanTypeAnnotation' },
45
- name: 'booleanTest',
46
- optional: false,
47
- },
48
- {
49
- typeAnnotation: { type: 'ObjectTypeAnnotation', properties: [] },
50
- name: 'objectTest',
51
- optional: true,
52
- },
53
- ],
54
- });
55
-
56
- expect(result).toBe('{booleanTest: boolean, objectTest?: {}}');
57
- });
58
-
59
- it('should convert array correctly', () => {
60
- const result = convert({
61
- type: 'ObjectTypeAnnotation',
62
- properties: [
63
- {
64
- typeAnnotation: {
65
- type: 'ArrayTypeAnnotation',
66
- elementType: { type: 'StringTypeAnnotation' },
67
- },
68
- name: 'arrayTest',
69
- optional: false,
70
- },
71
- ],
72
- });
73
-
74
- expect(result).toBe('{arrayTest: string[]}');
75
- });
1
+ import { TypeAnnotationToTS, TypeAnnotation } from './TypeAnnotationToTS';
2
+
3
+ function convert(typeAnnotation: TypeAnnotation) {
4
+ return new TypeAnnotationToTS().convert(typeAnnotation);
5
+ }
6
+
7
+ it('should convert boolean prop correctly', () => {
8
+ const result = convert({
9
+ type: 'BooleanTypeAnnotation',
10
+ });
11
+
12
+ expect(result).toBe('boolean');
13
+ });
14
+
15
+ it('should convert string prop correctly', () => {
16
+ const result = convert({
17
+ type: 'StringTypeAnnotation',
18
+ });
19
+
20
+ expect(result).toBe('string');
21
+ });
22
+
23
+ it('should convert double prop correctly', () => {
24
+ const result = convert({
25
+ type: 'DoubleTypeAnnotation',
26
+ });
27
+
28
+ expect(result).toBe('number');
29
+ });
30
+
31
+ it('should convert float prop correctly', () => {
32
+ const result = convert({
33
+ type: 'FloatTypeAnnotation',
34
+ });
35
+
36
+ expect(result).toBe('number');
37
+ });
38
+
39
+ it('should convert object prop correctly', () => {
40
+ const result = convert({
41
+ type: 'ObjectTypeAnnotation',
42
+ properties: [
43
+ {
44
+ typeAnnotation: { type: 'BooleanTypeAnnotation' },
45
+ name: 'booleanTest',
46
+ optional: false,
47
+ },
48
+ {
49
+ typeAnnotation: { type: 'ObjectTypeAnnotation', properties: [] },
50
+ name: 'objectTest',
51
+ optional: true,
52
+ },
53
+ ],
54
+ });
55
+
56
+ expect(result).toBe('{booleanTest: boolean, objectTest?: {}}');
57
+ });
58
+
59
+ it('should convert array correctly', () => {
60
+ const result = convert({
61
+ type: 'ObjectTypeAnnotation',
62
+ properties: [
63
+ {
64
+ typeAnnotation: {
65
+ type: 'ArrayTypeAnnotation',
66
+ elementType: { type: 'StringTypeAnnotation' },
67
+ },
68
+ name: 'arrayTest',
69
+ optional: false,
70
+ },
71
+ ],
72
+ });
73
+
74
+ expect(result).toBe('{arrayTest: string[]}');
75
+ });