@react-native-oh/react-native-harmony-cli 0.0.24 → 0.0.26

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 (105) hide show
  1. package/.prettierrc +6 -6
  2. package/jest.config.js +5 -5
  3. package/package.json +57 -52
  4. package/react-native.config.js +10 -10
  5. package/src/assetResolver.ts +21 -44
  6. package/src/codegen/core/CodeGenerator.ts +9 -0
  7. package/src/codegen/core/CodegenError.ts +3 -3
  8. package/src/codegen/core/EventUtils.ts +18 -18
  9. package/src/codegen/core/TypeAnnotationToTS.test.ts +75 -75
  10. package/src/codegen/core/TypeAnnotationToTS.ts +188 -188
  11. package/src/codegen/core/UberSchema.ts +142 -99
  12. package/src/codegen/core/index.ts +5 -5
  13. package/src/codegen/generators/{ComponentCodeGenerator.ts → ComponentCodeGeneratorArkTS.ts} +112 -98
  14. package/src/codegen/generators/ComponentCodeGeneratorCAPI.ts +114 -0
  15. package/src/codegen/generators/GlueCodeGenerator.ts +109 -0
  16. package/src/codegen/generators/NativeModuleCodeGenerator.ts +115 -95
  17. package/src/codegen/generators/UberGeneratorV1.ts +64 -0
  18. package/src/codegen/generators/UberGeneratorV2.ts +91 -0
  19. package/src/codegen/generators/index.ts +6 -3
  20. package/src/codegen/index.ts +2 -2
  21. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +116 -0
  22. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +55 -49
  23. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +93 -85
  24. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +210 -202
  25. package/src/codegen/templates/GeneratedPackageHTemplate.ts +107 -0
  26. package/src/codegen/templates/IndexTSTemplate.ts +53 -33
  27. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +130 -124
  28. package/src/codegen/templates/TurboModuleCppTemplate.ts +54 -47
  29. package/src/codegen/templates/TurboModuleHTemplate.ts +35 -26
  30. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +90 -81
  31. package/src/codegen/templates/index.ts +9 -8
  32. package/src/commands/bundle-harmony.ts +203 -202
  33. package/src/commands/codegen-harmony.ts +272 -143
  34. package/src/commands/create-metro-host-constants.ts +48 -48
  35. package/src/commands/index.ts +6 -5
  36. package/src/commands/pack-harmony.ts +121 -121
  37. package/src/commands/unpack-harmony.ts +231 -231
  38. package/src/commands/verify-package-harmony.ts +106 -0
  39. package/src/core/AbsolutePath.ts +50 -43
  40. package/src/core/CodegenConfig.ts +62 -54
  41. package/src/core/DescriptiveError.ts +61 -61
  42. package/src/core/OHPackageJSON5.ts +23 -0
  43. package/src/core/PackageJSON.ts +75 -63
  44. package/src/core/ProjectDependenciesManager.ts +77 -77
  45. package/src/core/ValidationError.ts +1 -1
  46. package/src/core/ValueObject.ts +2 -2
  47. package/src/core/fs.ts +31 -31
  48. package/src/core/index.ts +9 -8
  49. package/src/index.ts +20 -18
  50. package/src/io/Logger.ts +68 -68
  51. package/src/io/TarGz.ts +26 -0
  52. package/src/io/fsUtils.ts +24 -24
  53. package/src/io/index.ts +3 -2
  54. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +28 -0
  55. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +24 -0
  56. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +18 -0
  57. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +47 -0
  58. package/src/package-verifier/checks/index.ts +4 -0
  59. package/src/package-verifier/index.ts +2 -0
  60. package/src/package-verifier/types.ts +12 -0
  61. package/src/package-verifier/verify-package.ts +117 -0
  62. package/tsconfig.build.json +6 -6
  63. package/tsconfig.json +2 -2
  64. package/dist/assetResolver.js +0 -41
  65. package/dist/codegen/core/Codegen.js +0 -35
  66. package/dist/codegen/core/CodegenError.js +0 -7
  67. package/dist/codegen/core/EventUtils.js +0 -19
  68. package/dist/codegen/core/TypeAnnotationToTS.js +0 -132
  69. package/dist/codegen/core/UberSchema.js +0 -74
  70. package/dist/codegen/core/index.js +0 -21
  71. package/dist/codegen/generators/ComponentCodeGenerator.js +0 -66
  72. package/dist/codegen/generators/NativeModuleCodeGenerator.js +0 -64
  73. package/dist/codegen/generators/PackageCodeGenerator.js +0 -52
  74. package/dist/codegen/generators/index.js +0 -19
  75. package/dist/codegen/index.js +0 -18
  76. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +0 -55
  77. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +0 -78
  78. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +0 -181
  79. package/dist/codegen/templates/IndexTSTemplate.js +0 -31
  80. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +0 -117
  81. package/dist/codegen/templates/TurboModuleCppTemplate.js +0 -45
  82. package/dist/codegen/templates/TurboModuleHTemplate.js +0 -32
  83. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +0 -64
  84. package/dist/codegen/templates/index.js +0 -24
  85. package/dist/commands/bundle-harmony.js +0 -179
  86. package/dist/commands/codegen-harmony.js +0 -110
  87. package/dist/commands/create-metro-host-constants.js +0 -61
  88. package/dist/commands/index.js +0 -21
  89. package/dist/commands/pack-harmony.js +0 -100
  90. package/dist/commands/unpack-harmony.js +0 -184
  91. package/dist/core/AbsolutePath.js +0 -41
  92. package/dist/core/CodegenConfig.js +0 -53
  93. package/dist/core/DescriptiveError.js +0 -49
  94. package/dist/core/PackageJSON.js +0 -53
  95. package/dist/core/ProjectDependenciesManager.js +0 -70
  96. package/dist/core/ValidationError.js +0 -6
  97. package/dist/core/ValueObject.js +0 -2
  98. package/dist/core/fs.js +0 -36
  99. package/dist/core/index.js +0 -24
  100. package/dist/index.js +0 -13
  101. package/dist/io/Logger.js +0 -71
  102. package/dist/io/fsUtils.js +0 -23
  103. package/dist/io/index.js +0 -18
  104. package/src/codegen/core/Codegen.ts +0 -44
  105. package/src/codegen/generators/PackageCodeGenerator.ts +0 -73
package/.prettierrc CHANGED
@@ -1,6 +1,6 @@
1
- {
2
- "trailingComma": "es5",
3
- "tabWidth": 2,
4
- "semi": true,
5
- "singleQuote": true
6
- }
1
+ {
2
+ "trailingComma": "es5",
3
+ "tabWidth": 2,
4
+ "semi": true,
5
+ "singleQuote": true
6
+ }
package/jest.config.js CHANGED
@@ -1,5 +1,5 @@
1
- /** @type {import('ts-jest').JestConfigWithTsJest} */
2
- module.exports = {
3
- preset: 'ts-jest',
4
- testEnvironment: 'node',
5
- };
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} */
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'node',
5
+ };
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",
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
+ });