@react-native-oh/react-native-harmony-cli 0.0.25 → 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.
- package/.prettierrc +6 -6
- package/jest.config.js +5 -5
- package/package.json +57 -56
- package/react-native.config.js +10 -10
- package/src/assetResolver.ts +21 -44
- package/src/codegen/core/CodeGenerator.ts +9 -0
- package/src/codegen/core/CodegenError.ts +3 -3
- package/src/codegen/core/EventUtils.ts +18 -18
- package/src/codegen/core/TypeAnnotationToTS.test.ts +75 -75
- package/src/codegen/core/TypeAnnotationToTS.ts +188 -188
- package/src/codegen/core/UberSchema.ts +142 -99
- package/src/codegen/core/index.ts +5 -5
- package/src/codegen/generators/{ComponentCodeGenerator.ts → ComponentCodeGeneratorArkTS.ts} +112 -98
- package/src/codegen/generators/ComponentCodeGeneratorCAPI.ts +114 -0
- package/src/codegen/generators/GlueCodeGenerator.ts +109 -0
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +115 -95
- package/src/codegen/generators/UberGeneratorV1.ts +64 -0
- package/src/codegen/generators/UberGeneratorV2.ts +91 -0
- package/src/codegen/generators/index.ts +6 -3
- package/src/codegen/index.ts +2 -2
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +116 -0
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +55 -49
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +93 -85
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +210 -202
- package/src/codegen/templates/GeneratedPackageHTemplate.ts +107 -0
- package/src/codegen/templates/IndexTSTemplate.ts +53 -33
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +130 -124
- package/src/codegen/templates/TurboModuleCppTemplate.ts +54 -47
- package/src/codegen/templates/TurboModuleHTemplate.ts +35 -26
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +90 -81
- package/src/codegen/templates/index.ts +9 -8
- package/src/commands/bundle-harmony.ts +203 -203
- package/src/commands/codegen-harmony.ts +272 -143
- package/src/commands/create-metro-host-constants.ts +48 -48
- package/src/commands/index.ts +6 -6
- package/src/commands/pack-harmony.ts +121 -121
- package/src/commands/unpack-harmony.ts +231 -231
- package/src/commands/verify-package-harmony.ts +106 -106
- package/src/core/AbsolutePath.ts +50 -43
- package/src/core/CodegenConfig.ts +62 -54
- package/src/core/DescriptiveError.ts +61 -61
- package/src/core/OHPackageJSON5.ts +23 -23
- package/src/core/PackageJSON.ts +75 -63
- package/src/core/ProjectDependenciesManager.ts +77 -77
- package/src/core/ValidationError.ts +1 -1
- package/src/core/ValueObject.ts +2 -2
- package/src/core/fs.ts +31 -31
- package/src/core/index.ts +9 -9
- package/src/index.ts +20 -20
- package/src/io/Logger.ts +68 -68
- package/src/io/TarGz.ts +26 -26
- package/src/io/fsUtils.ts +24 -24
- package/src/io/index.ts +3 -3
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +28 -28
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +24 -24
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +18 -18
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +47 -47
- package/src/package-verifier/checks/index.ts +4 -4
- package/src/package-verifier/index.ts +2 -2
- package/src/package-verifier/types.ts +12 -12
- package/src/package-verifier/verify-package.ts +117 -117
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +2 -2
- package/dist/assetResolver.js +0 -41
- package/dist/codegen/core/Codegen.js +0 -35
- package/dist/codegen/core/CodegenError.js +0 -7
- package/dist/codegen/core/EventUtils.js +0 -19
- package/dist/codegen/core/TypeAnnotationToTS.js +0 -132
- package/dist/codegen/core/UberSchema.js +0 -74
- package/dist/codegen/core/index.js +0 -21
- package/dist/codegen/generators/ComponentCodeGenerator.js +0 -66
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +0 -64
- package/dist/codegen/generators/PackageCodeGenerator.js +0 -52
- package/dist/codegen/generators/index.js +0 -19
- package/dist/codegen/index.js +0 -18
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +0 -55
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +0 -78
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +0 -181
- package/dist/codegen/templates/IndexTSTemplate.js +0 -31
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +0 -117
- package/dist/codegen/templates/TurboModuleCppTemplate.js +0 -45
- package/dist/codegen/templates/TurboModuleHTemplate.js +0 -32
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +0 -64
- package/dist/codegen/templates/index.js +0 -24
- package/dist/commands/bundle-harmony.js +0 -179
- package/dist/commands/codegen-harmony.js +0 -110
- package/dist/commands/create-metro-host-constants.js +0 -61
- package/dist/commands/index.js +0 -22
- package/dist/commands/pack-harmony.js +0 -100
- package/dist/commands/unpack-harmony.js +0 -184
- package/dist/commands/verify-package-harmony.js +0 -127
- package/dist/core/AbsolutePath.js +0 -41
- package/dist/core/CodegenConfig.js +0 -53
- package/dist/core/DescriptiveError.js +0 -49
- package/dist/core/OHPackageJSON5.js +0 -23
- package/dist/core/PackageJSON.js +0 -53
- package/dist/core/ProjectDependenciesManager.js +0 -70
- package/dist/core/ValidationError.js +0 -6
- package/dist/core/ValueObject.js +0 -2
- package/dist/core/fs.js +0 -36
- package/dist/core/index.js +0 -25
- package/dist/index.js +0 -14
- package/dist/io/Logger.js +0 -71
- package/dist/io/TarGz.js +0 -28
- package/dist/io/fsUtils.js +0 -23
- package/dist/io/index.js +0 -19
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +0 -38
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +0 -32
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +0 -26
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +0 -51
- package/dist/package-verifier/checks/index.js +0 -20
- package/dist/package-verifier/index.js +0 -18
- package/dist/package-verifier/types.js +0 -2
- package/dist/package-verifier/verify-package.js +0 -100
- package/src/codegen/core/Codegen.ts +0 -44
- package/src/codegen/generators/PackageCodeGenerator.ts +0 -73
package/src/core/AbsolutePath.ts
CHANGED
|
@@ -1,43 +1,50 @@
|
|
|
1
|
-
import pathUtils from 'node:path';
|
|
2
|
-
import { ValueObject } from './ValueObject';
|
|
3
|
-
|
|
4
|
-
export class AbsolutePath implements ValueObject {
|
|
5
|
-
static fromSegments(...segments: string[]) {
|
|
6
|
-
return new AbsolutePath(pathUtils.join(...segments));
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
private value: string = '';
|
|
10
|
-
constructor(path: string) {
|
|
11
|
-
this.value = pathUtils.resolve(path);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
getValue(): string {
|
|
15
|
-
return this.value;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
copyWithNewSegment(...relativePath: string[]): AbsolutePath {
|
|
19
|
-
return new AbsolutePath(pathUtils.join(this.getValue(), ...relativePath));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
getExtension(): string | null {
|
|
23
|
-
const maybeExtWithDot = pathUtils.extname(this.value);
|
|
24
|
-
if (maybeExtWithDot) {
|
|
25
|
-
return maybeExtWithDot.substring(1);
|
|
26
|
-
}
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
pathUtils.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
1
|
+
import pathUtils from 'node:path';
|
|
2
|
+
import { ValueObject } from './ValueObject';
|
|
3
|
+
|
|
4
|
+
export class AbsolutePath implements ValueObject {
|
|
5
|
+
static fromSegments(...segments: string[]) {
|
|
6
|
+
return new AbsolutePath(pathUtils.join(...segments));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
private value: string = '';
|
|
10
|
+
constructor(path: string) {
|
|
11
|
+
this.value = pathUtils.resolve(path);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getValue(): string {
|
|
15
|
+
return this.value;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
copyWithNewSegment(...relativePath: string[]): AbsolutePath {
|
|
19
|
+
return new AbsolutePath(pathUtils.join(this.getValue(), ...relativePath));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getExtension(): string | null {
|
|
23
|
+
const maybeExtWithDot = pathUtils.extname(this.value);
|
|
24
|
+
if (maybeExtWithDot) {
|
|
25
|
+
return maybeExtWithDot.substring(1);
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getDirectoryPath(): AbsolutePath {
|
|
31
|
+
const dirPath = pathUtils.extname(this.value)
|
|
32
|
+
? pathUtils.dirname(this.value)
|
|
33
|
+
: this.value;
|
|
34
|
+
return new AbsolutePath(dirPath);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
relativeTo(absolutePath: AbsolutePath): RelativePath {
|
|
38
|
+
return new RelativePath(
|
|
39
|
+
pathUtils.relative(absolutePath.getValue(), this.value)
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
class RelativePath implements ValueObject {
|
|
45
|
+
constructor(private value: string) {}
|
|
46
|
+
|
|
47
|
+
getValue() {
|
|
48
|
+
return this.value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,54 +1,62 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import { AbsolutePath } from './AbsolutePath';
|
|
3
|
-
import { findFilePathsWithExtensions } from '../io';
|
|
4
|
-
import { DescriptiveError } from './DescriptiveError';
|
|
5
|
-
|
|
6
|
-
export type RawCodegenConfig = {
|
|
7
|
-
specPaths: string[];
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { AbsolutePath } from './AbsolutePath';
|
|
3
|
+
import { findFilePathsWithExtensions } from '../io';
|
|
4
|
+
import { DescriptiveError } from './DescriptiveError';
|
|
5
|
+
|
|
6
|
+
export type RawCodegenConfig = {
|
|
7
|
+
specPaths: string[];
|
|
8
|
+
version?: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export class CodegenConfig {
|
|
12
|
+
static fromRawCodegenConfig(
|
|
13
|
+
rawCodegenConfig: RawCodegenConfig,
|
|
14
|
+
packageRootPath: AbsolutePath,
|
|
15
|
+
projectRootPath: AbsolutePath,
|
|
16
|
+
packageName: string
|
|
17
|
+
) {
|
|
18
|
+
const SUPPORTED_SPEC_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx'];
|
|
19
|
+
const specPaths = (rawCodegenConfig.specPaths ?? []).map((rawSpecPath) => {
|
|
20
|
+
if (rawSpecPath.startsWith('~')) {
|
|
21
|
+
return projectRootPath.copyWithNewSegment(rawSpecPath.replace('~', ''));
|
|
22
|
+
} else {
|
|
23
|
+
return packageRootPath.copyWithNewSegment(rawSpecPath);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
const specFilePaths = specPaths.flatMap((specPath) => {
|
|
27
|
+
if (!fs.existsSync(specPath.getValue())) {
|
|
28
|
+
throw new DescriptiveError({
|
|
29
|
+
whatHappened: `No such file or directory: ${specPath.getValue()}`,
|
|
30
|
+
whatCanUserDo: {
|
|
31
|
+
default: [
|
|
32
|
+
`Please verify "${packageName}/package.json::harmony::codegenConfig". If you are not the maintainer of this package, please report this problem to the package maintainer.`,
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (fs.lstatSync(specPath.getValue()).isDirectory()) {
|
|
38
|
+
return findFilePathsWithExtensions(specPath, SUPPORTED_SPEC_EXTENSIONS);
|
|
39
|
+
} else {
|
|
40
|
+
const ext = specPath.getExtension();
|
|
41
|
+
if (ext && SUPPORTED_SPEC_EXTENSIONS.includes(ext)) {
|
|
42
|
+
return [specPath];
|
|
43
|
+
}
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return new CodegenConfig(specFilePaths, rawCodegenConfig.version ?? 1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private constructor(
|
|
51
|
+
private specFilePaths: AbsolutePath[],
|
|
52
|
+
private version: number
|
|
53
|
+
) {}
|
|
54
|
+
|
|
55
|
+
getSpecFilePaths(): AbsolutePath[] {
|
|
56
|
+
return this.specFilePaths;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
getVersion(): number {
|
|
60
|
+
return this.version;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
export class DescriptiveError extends Error {
|
|
2
|
-
constructor(
|
|
3
|
-
private data:
|
|
4
|
-
| {
|
|
5
|
-
whatHappened: string;
|
|
6
|
-
whatCanUserDo: {
|
|
7
|
-
default?: string[];
|
|
8
|
-
rnAppDeveloper?: string[];
|
|
9
|
-
rnPackageDeveloper?: string[];
|
|
10
|
-
};
|
|
11
|
-
extraData?: any;
|
|
12
|
-
}
|
|
13
|
-
| {
|
|
14
|
-
whatHappened: string;
|
|
15
|
-
unexpected: true;
|
|
16
|
-
extraData?: any;
|
|
17
|
-
}
|
|
18
|
-
) {
|
|
19
|
-
super(data.whatHappened);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
isUnexpected(): boolean {
|
|
23
|
-
return 'unexpected' in this.data;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
getMessage(): string {
|
|
27
|
-
return this.data.whatHappened;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
getSuggestionsByRole() {
|
|
31
|
-
if ('whatCanUserDo' in this.data) {
|
|
32
|
-
return this.data.whatCanUserDo;
|
|
33
|
-
} else {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
getDetails(): string {
|
|
39
|
-
if (!this.data.extraData) {
|
|
40
|
-
return '';
|
|
41
|
-
}
|
|
42
|
-
if (typeof this.data.extraData === 'string') {
|
|
43
|
-
return this.data.extraData.trim();
|
|
44
|
-
}
|
|
45
|
-
if (this.data.extraData instanceof Error) {
|
|
46
|
-
let lines = [
|
|
47
|
-
`${this.data.extraData.name}: ${this.data.extraData.message}`,
|
|
48
|
-
];
|
|
49
|
-
for (let stackEntry of (this.data.extraData.stack ?? '').split('\n')) {
|
|
50
|
-
lines.push('');
|
|
51
|
-
lines.push(stackEntry);
|
|
52
|
-
}
|
|
53
|
-
return lines.join('\n');
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
return JSON.stringify(this.data.extraData, null, 2);
|
|
57
|
-
} catch (err) {
|
|
58
|
-
return '';
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
1
|
+
export class DescriptiveError extends Error {
|
|
2
|
+
constructor(
|
|
3
|
+
private data:
|
|
4
|
+
| {
|
|
5
|
+
whatHappened: string;
|
|
6
|
+
whatCanUserDo: {
|
|
7
|
+
default?: string[];
|
|
8
|
+
rnAppDeveloper?: string[];
|
|
9
|
+
rnPackageDeveloper?: string[];
|
|
10
|
+
};
|
|
11
|
+
extraData?: any;
|
|
12
|
+
}
|
|
13
|
+
| {
|
|
14
|
+
whatHappened: string;
|
|
15
|
+
unexpected: true;
|
|
16
|
+
extraData?: any;
|
|
17
|
+
}
|
|
18
|
+
) {
|
|
19
|
+
super(data.whatHappened);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
isUnexpected(): boolean {
|
|
23
|
+
return 'unexpected' in this.data;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getMessage(): string {
|
|
27
|
+
return this.data.whatHappened;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getSuggestionsByRole() {
|
|
31
|
+
if ('whatCanUserDo' in this.data) {
|
|
32
|
+
return this.data.whatCanUserDo;
|
|
33
|
+
} else {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getDetails(): string {
|
|
39
|
+
if (!this.data.extraData) {
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
if (typeof this.data.extraData === 'string') {
|
|
43
|
+
return this.data.extraData.trim();
|
|
44
|
+
}
|
|
45
|
+
if (this.data.extraData instanceof Error) {
|
|
46
|
+
let lines = [
|
|
47
|
+
`${this.data.extraData.name}: ${this.data.extraData.message}`,
|
|
48
|
+
];
|
|
49
|
+
for (let stackEntry of (this.data.extraData.stack ?? '').split('\n')) {
|
|
50
|
+
lines.push('');
|
|
51
|
+
lines.push(stackEntry);
|
|
52
|
+
}
|
|
53
|
+
return lines.join('\n');
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
return JSON.stringify(this.data.extraData, null, 2);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import json5 from 'json5';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import { AbsolutePath } from './AbsolutePath';
|
|
4
|
-
|
|
5
|
-
export class OHPackageJSON5 {
|
|
6
|
-
static fromPath(ohPackageJson5Path: AbsolutePath) {
|
|
7
|
-
return new OHPackageJSON5(
|
|
8
|
-
json5.parse(
|
|
9
|
-
fs.readFileSync(ohPackageJson5Path.getValue(), { encoding: 'utf-8' })
|
|
10
|
-
)
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
private constructor(private rawData: Record<string, any>) {}
|
|
15
|
-
|
|
16
|
-
get name(): string {
|
|
17
|
-
return this.rawData['name'];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
get version(): string {
|
|
21
|
-
return this.rawData['version'];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
1
|
+
import json5 from 'json5';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { AbsolutePath } from './AbsolutePath';
|
|
4
|
+
|
|
5
|
+
export class OHPackageJSON5 {
|
|
6
|
+
static fromPath(ohPackageJson5Path: AbsolutePath) {
|
|
7
|
+
return new OHPackageJSON5(
|
|
8
|
+
json5.parse(
|
|
9
|
+
fs.readFileSync(ohPackageJson5Path.getValue(), { encoding: 'utf-8' })
|
|
10
|
+
)
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
private constructor(private rawData: Record<string, any>) {}
|
|
15
|
+
|
|
16
|
+
get name(): string {
|
|
17
|
+
return this.rawData['name'];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get version(): string {
|
|
21
|
+
return this.rawData['version'];
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/core/PackageJSON.ts
CHANGED
|
@@ -1,63 +1,75 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { AbsolutePath } from './AbsolutePath';
|
|
3
|
-
import { CodegenConfig } from './CodegenConfig';
|
|
4
|
-
import { DescriptiveError } from './DescriptiveError';
|
|
5
|
-
|
|
6
|
-
export class PackageJSON {
|
|
7
|
-
static fromProjectRootPath(
|
|
8
|
-
packageRootPath: AbsolutePath,
|
|
9
|
-
projectRootPath: AbsolutePath
|
|
10
|
-
) {
|
|
11
|
-
const packageJSONPath = packageRootPath.copyWithNewSegment('package.json');
|
|
12
|
-
if (!fs.existsSync(packageJSONPath.getValue())) {
|
|
13
|
-
throw new DescriptiveError({
|
|
14
|
-
whatHappened: "Couldn't find 'package.json'",
|
|
15
|
-
whatCanUserDo: {
|
|
16
|
-
default: [
|
|
17
|
-
'Check if the path to project root is correct',
|
|
18
|
-
'Try changing working directory to project root',
|
|
19
|
-
],
|
|
20
|
-
},
|
|
21
|
-
extraData: packageJSONPath.getValue(),
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
return new PackageJSON(
|
|
25
|
-
JSON.parse(fs.readFileSync(packageJSONPath.getValue()).toString()),
|
|
26
|
-
packageRootPath,
|
|
27
|
-
projectRootPath
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
private constructor(
|
|
32
|
-
private rawPackageJSON: Record<string, any>,
|
|
33
|
-
private packageRootPath: AbsolutePath,
|
|
34
|
-
private projectRootPath: AbsolutePath
|
|
35
|
-
) {}
|
|
36
|
-
|
|
37
|
-
get name(): string {
|
|
38
|
-
return this.rawPackageJSON.name;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get version(): string {
|
|
42
|
-
return this.rawPackageJSON.version;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Shared codegenConfig is not used on purpose. Android, iOS and other platforms shouldn't
|
|
48
|
-
* generate code for harmony-specific packages. The shape of this codegenConfig is different
|
|
49
|
-
* that the shape of the shared config, to allow specifying which specific turbo modules or
|
|
50
|
-
* fabric components should be code generated.
|
|
51
|
-
*/
|
|
52
|
-
const rawCodegenConfig = this.rawPackageJSON.harmony?.codegenConfig;
|
|
53
|
-
if (!rawCodegenConfig) {
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
rawCodegenConfig
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { AbsolutePath } from './AbsolutePath';
|
|
3
|
+
import { CodegenConfig } from './CodegenConfig';
|
|
4
|
+
import { DescriptiveError } from './DescriptiveError';
|
|
5
|
+
|
|
6
|
+
export class PackageJSON {
|
|
7
|
+
static fromProjectRootPath(
|
|
8
|
+
packageRootPath: AbsolutePath,
|
|
9
|
+
projectRootPath: AbsolutePath
|
|
10
|
+
) {
|
|
11
|
+
const packageJSONPath = packageRootPath.copyWithNewSegment('package.json');
|
|
12
|
+
if (!fs.existsSync(packageJSONPath.getValue())) {
|
|
13
|
+
throw new DescriptiveError({
|
|
14
|
+
whatHappened: "Couldn't find 'package.json'",
|
|
15
|
+
whatCanUserDo: {
|
|
16
|
+
default: [
|
|
17
|
+
'Check if the path to project root is correct',
|
|
18
|
+
'Try changing working directory to project root',
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
extraData: packageJSONPath.getValue(),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return new PackageJSON(
|
|
25
|
+
JSON.parse(fs.readFileSync(packageJSONPath.getValue()).toString()),
|
|
26
|
+
packageRootPath,
|
|
27
|
+
projectRootPath
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private constructor(
|
|
32
|
+
private rawPackageJSON: Record<string, any>,
|
|
33
|
+
private packageRootPath: AbsolutePath,
|
|
34
|
+
private projectRootPath: AbsolutePath
|
|
35
|
+
) {}
|
|
36
|
+
|
|
37
|
+
get name(): string {
|
|
38
|
+
return this.rawPackageJSON.name;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get version(): string {
|
|
42
|
+
return this.rawPackageJSON.version;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getCodegenConfigs(): CodegenConfig[] {
|
|
46
|
+
/**
|
|
47
|
+
* Shared codegenConfig is not used on purpose. Android, iOS and other platforms shouldn't
|
|
48
|
+
* generate code for harmony-specific packages. The shape of this codegenConfig is different
|
|
49
|
+
* that the shape of the shared config, to allow specifying which specific turbo modules or
|
|
50
|
+
* fabric components should be code generated.
|
|
51
|
+
*/
|
|
52
|
+
const rawCodegenConfig = this.rawPackageJSON.harmony?.codegenConfig;
|
|
53
|
+
if (!rawCodegenConfig) {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
if (Array.isArray(rawCodegenConfig)) {
|
|
57
|
+
return rawCodegenConfig.map((config) =>
|
|
58
|
+
CodegenConfig.fromRawCodegenConfig(
|
|
59
|
+
config,
|
|
60
|
+
this.packageRootPath,
|
|
61
|
+
this.projectRootPath,
|
|
62
|
+
this.name
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return [
|
|
67
|
+
CodegenConfig.fromRawCodegenConfig(
|
|
68
|
+
rawCodegenConfig,
|
|
69
|
+
this.packageRootPath,
|
|
70
|
+
this.projectRootPath,
|
|
71
|
+
this.name
|
|
72
|
+
),
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import { AbsolutePath } from './AbsolutePath';
|
|
3
|
-
import { PackageJSON } from './PackageJSON';
|
|
4
|
-
|
|
5
|
-
export class ProjectDependency {
|
|
6
|
-
constructor(
|
|
7
|
-
private packageRootPath: AbsolutePath,
|
|
8
|
-
private projectRootPath: AbsolutePath
|
|
9
|
-
) {}
|
|
10
|
-
|
|
11
|
-
getRootPath() {
|
|
12
|
-
return this.packageRootPath;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return this.readPackageJSON().
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
readPackageJSON() {
|
|
20
|
-
return PackageJSON.fromProjectRootPath(
|
|
21
|
-
this.packageRootPath,
|
|
22
|
-
this.projectRootPath
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class ProjectDependenciesManager {
|
|
28
|
-
constructor(private projectRootPath: AbsolutePath) {}
|
|
29
|
-
|
|
30
|
-
async forEachAsync(
|
|
31
|
-
cb: (dependency: ProjectDependency) => Promise<void> | void
|
|
32
|
-
) {
|
|
33
|
-
await this.forEachDependencyInDirectory(
|
|
34
|
-
cb,
|
|
35
|
-
this.projectRootPath.copyWithNewSegment('node_modules')
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
private async forEachDependencyInDirectory(
|
|
40
|
-
cb: (dependency: ProjectDependency) => Promise<void> | void,
|
|
41
|
-
directoryPath: AbsolutePath
|
|
42
|
-
) {
|
|
43
|
-
if (!fs.existsSync(directoryPath.getValue())) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
for (let dirOrFileName of fs.readdirSync(directoryPath.getValue())) {
|
|
47
|
-
const potentialDependencyRootPath =
|
|
48
|
-
directoryPath.copyWithNewSegment(dirOrFileName);
|
|
49
|
-
if (fs.lstatSync(potentialDependencyRootPath.getValue()).isDirectory()) {
|
|
50
|
-
if (dirOrFileName.startsWith('.')) {
|
|
51
|
-
continue;
|
|
52
|
-
} else if (dirOrFileName.startsWith('@')) {
|
|
53
|
-
await this.forEachDependencyInDirectory(
|
|
54
|
-
cb,
|
|
55
|
-
directoryPath.copyWithNewSegment(dirOrFileName)
|
|
56
|
-
);
|
|
57
|
-
} else {
|
|
58
|
-
if (
|
|
59
|
-
!fs.existsSync(
|
|
60
|
-
potentialDependencyRootPath
|
|
61
|
-
.copyWithNewSegment('package.json')
|
|
62
|
-
.getValue()
|
|
63
|
-
)
|
|
64
|
-
) {
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
await cb(
|
|
68
|
-
new ProjectDependency(
|
|
69
|
-
potentialDependencyRootPath,
|
|
70
|
-
this.projectRootPath
|
|
71
|
-
)
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { AbsolutePath } from './AbsolutePath';
|
|
3
|
+
import { PackageJSON } from './PackageJSON';
|
|
4
|
+
|
|
5
|
+
export class ProjectDependency {
|
|
6
|
+
constructor(
|
|
7
|
+
private packageRootPath: AbsolutePath,
|
|
8
|
+
private projectRootPath: AbsolutePath
|
|
9
|
+
) {}
|
|
10
|
+
|
|
11
|
+
getRootPath() {
|
|
12
|
+
return this.packageRootPath;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getCodegenConfigs() {
|
|
16
|
+
return this.readPackageJSON().getCodegenConfigs();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
readPackageJSON() {
|
|
20
|
+
return PackageJSON.fromProjectRootPath(
|
|
21
|
+
this.packageRootPath,
|
|
22
|
+
this.projectRootPath
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class ProjectDependenciesManager {
|
|
28
|
+
constructor(private projectRootPath: AbsolutePath) {}
|
|
29
|
+
|
|
30
|
+
async forEachAsync(
|
|
31
|
+
cb: (dependency: ProjectDependency) => Promise<void> | void
|
|
32
|
+
) {
|
|
33
|
+
await this.forEachDependencyInDirectory(
|
|
34
|
+
cb,
|
|
35
|
+
this.projectRootPath.copyWithNewSegment('node_modules')
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private async forEachDependencyInDirectory(
|
|
40
|
+
cb: (dependency: ProjectDependency) => Promise<void> | void,
|
|
41
|
+
directoryPath: AbsolutePath
|
|
42
|
+
) {
|
|
43
|
+
if (!fs.existsSync(directoryPath.getValue())) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
for (let dirOrFileName of fs.readdirSync(directoryPath.getValue())) {
|
|
47
|
+
const potentialDependencyRootPath =
|
|
48
|
+
directoryPath.copyWithNewSegment(dirOrFileName);
|
|
49
|
+
if (fs.lstatSync(potentialDependencyRootPath.getValue()).isDirectory()) {
|
|
50
|
+
if (dirOrFileName.startsWith('.')) {
|
|
51
|
+
continue;
|
|
52
|
+
} else if (dirOrFileName.startsWith('@')) {
|
|
53
|
+
await this.forEachDependencyInDirectory(
|
|
54
|
+
cb,
|
|
55
|
+
directoryPath.copyWithNewSegment(dirOrFileName)
|
|
56
|
+
);
|
|
57
|
+
} else {
|
|
58
|
+
if (
|
|
59
|
+
!fs.existsSync(
|
|
60
|
+
potentialDependencyRootPath
|
|
61
|
+
.copyWithNewSegment('package.json')
|
|
62
|
+
.getValue()
|
|
63
|
+
)
|
|
64
|
+
) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
await cb(
|
|
68
|
+
new ProjectDependency(
|
|
69
|
+
potentialDependencyRootPath,
|
|
70
|
+
this.projectRootPath
|
|
71
|
+
)
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|