@react-native-oh/react-native-harmony-cli 0.0.37 → 0.0.40-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 (84) hide show
  1. package/dist/autolinking/Autolinking.js +14 -11
  2. package/dist/codegen/generators/UberGeneratorV1.js +9 -2
  3. package/dist/codegen/generators/UberGeneratorV2.js +8 -1
  4. package/dist/commands/codegen-harmony.js +16 -5
  5. package/dist/commands/run-harmony.js +0 -2
  6. package/dist/core/ProjectDependenciesManager.js +5 -7
  7. package/dist/simulator/LaunchSimulator.js +9 -2
  8. package/harmony/rnoh-hvigor-plugin-0.3.0.tgz +0 -0
  9. package/package.json +10 -2
  10. package/.prettierrc +0 -6
  11. package/src/assetResolver.ts +0 -134
  12. package/src/autolinking/Autolinking.test.ts +0 -483
  13. package/src/autolinking/Autolinking.ts +0 -382
  14. package/src/autolinking/index.ts +0 -8
  15. package/src/codegen/core/CodeGenerator.ts +0 -16
  16. package/src/codegen/core/CodegenError.ts +0 -10
  17. package/src/codegen/core/EventUtils.ts +0 -23
  18. package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -82
  19. package/src/codegen/core/TypeAnnotationToTS.ts +0 -195
  20. package/src/codegen/core/UberSchema.ts +0 -152
  21. package/src/codegen/core/index.ts +0 -12
  22. package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +0 -124
  23. package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +0 -128
  24. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +0 -122
  25. package/src/codegen/generators/CppComponentCodeGenerator.ts +0 -95
  26. package/src/codegen/generators/LibGlueCodeGenerator.ts +0 -98
  27. package/src/codegen/generators/NativeModuleCodeGenerator.ts +0 -124
  28. package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -57
  29. package/src/codegen/generators/UberGeneratorV1.ts +0 -75
  30. package/src/codegen/generators/UberGeneratorV2.ts +0 -114
  31. package/src/codegen/generators/index.ts +0 -15
  32. package/src/codegen/index.ts +0 -9
  33. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -128
  34. package/src/codegen/templates/BasePackageHTemplate.ts +0 -159
  35. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +0 -63
  36. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +0 -121
  37. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -222
  38. package/src/codegen/templates/IndexTSTemplate.ts +0 -62
  39. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +0 -150
  40. package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -61
  41. package/src/codegen/templates/TurboModuleHTemplate.ts +0 -42
  42. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -101
  43. package/src/codegen/templates/index.ts +0 -16
  44. package/src/commands/bundle-harmony.ts +0 -134
  45. package/src/commands/codegen-harmony.ts +0 -297
  46. package/src/commands/codegen-lib-harmony.ts +0 -389
  47. package/src/commands/create-metro-host-constants.ts +0 -55
  48. package/src/commands/index.ts +0 -16
  49. package/src/commands/init.ts +0 -755
  50. package/src/commands/link-harmony.ts +0 -102
  51. package/src/commands/pack-harmony.ts +0 -128
  52. package/src/commands/run-harmony.ts +0 -506
  53. package/src/commands/types.ts +0 -21
  54. package/src/commands/unpack-harmony.ts +0 -238
  55. package/src/commands/verify-package-harmony.ts +0 -113
  56. package/src/core/AbsolutePath.ts +0 -66
  57. package/src/core/CodegenConfig.ts +0 -67
  58. package/src/core/DescriptiveError.ts +0 -68
  59. package/src/core/FileSystem.ts +0 -57
  60. package/src/core/OHPackageJSON5.ts +0 -30
  61. package/src/core/PackageJSON.ts +0 -104
  62. package/src/core/ProjectDependenciesManager.ts +0 -103
  63. package/src/core/ValidationError.ts +0 -8
  64. package/src/core/ValueObject.ts +0 -9
  65. package/src/core/fs.ts +0 -38
  66. package/src/core/index.ts +0 -17
  67. package/src/index.ts +0 -33
  68. package/src/io/CliExecutor.ts +0 -69
  69. package/src/io/Logger.ts +0 -112
  70. package/src/io/RealFS.ts +0 -62
  71. package/src/io/TarGz.ts +0 -33
  72. package/src/io/__fixtures__.ts +0 -139
  73. package/src/io/fsUtils.ts +0 -44
  74. package/src/io/index.ts +0 -11
  75. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -35
  76. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -31
  77. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -25
  78. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -54
  79. package/src/package-verifier/checks/index.ts +0 -11
  80. package/src/package-verifier/index.ts +0 -9
  81. package/src/package-verifier/types.ts +0 -19
  82. package/src/package-verifier/verify-package.ts +0 -123
  83. package/src/simulator/LaunchSimulator.ts +0 -352
  84. package/src/simulator/index.ts +0 -8
@@ -1,104 +0,0 @@
1
- /**
2
- * Copyright (c) 2024-2025 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
- */
7
- import { AbsolutePath } from './AbsolutePath';
8
- import { CodegenConfig, RawCodegenConfig } from './CodegenConfig';
9
- import { DescriptiveError } from './DescriptiveError';
10
- import { FS } from './FileSystem';
11
-
12
- type RawAutolinkingConfig = {
13
- etsPackageClassName?: string;
14
- cppPackageClassName?: string;
15
- cmakeLibraryTargetName?: string;
16
- ohPackageName?: string;
17
- };
18
-
19
- export class PackageJSON {
20
- static fromProjectRootPath(
21
- fs: FS,
22
- packageRootPath: AbsolutePath,
23
- projectRootPath: AbsolutePath
24
- ) {
25
- const packageJSONPath = packageRootPath.copyWithNewSegment('package.json');
26
- if (!fs.existsSync(packageJSONPath)) {
27
- throw new DescriptiveError({
28
- whatHappened: "Couldn't find 'package.json'",
29
- whatCanUserDo: [
30
- 'Check if the path to project root is correct',
31
- 'Try changing working directory to project root',
32
- ],
33
- extraData: packageJSONPath.getValue(),
34
- });
35
- }
36
- try {
37
- return new PackageJSON(
38
- JSON.parse(fs.readTextSync(packageJSONPath).toString()),
39
- packageRootPath,
40
- projectRootPath
41
- );
42
- } catch (err) {
43
- throw new DescriptiveError({
44
- whatHappened: "Couldn't parse package.json",
45
- extraData: { packageJSONPath, err },
46
- });
47
- }
48
- }
49
-
50
- private constructor(
51
- private rawPackageJSON: Record<string, any>,
52
- private packageRootPath: AbsolutePath,
53
- private projectRootPath: AbsolutePath
54
- ) {}
55
-
56
- get name(): string {
57
- return this.rawPackageJSON.name;
58
- }
59
-
60
- get version(): string {
61
- return this.rawPackageJSON.version;
62
- }
63
-
64
- get harmony():
65
- | undefined
66
- | {
67
- alias?: string;
68
- codegenConfig?: RawCodegenConfig | RawCodegenConfig[];
69
- autolinking?: RawAutolinkingConfig | null | true;
70
- } {
71
- return this.rawPackageJSON.harmony;
72
- }
73
-
74
- getCodegenConfigs(): CodegenConfig[] {
75
- /**
76
- * Shared codegenConfig is not used on purpose. Android, iOS and other platforms shouldn't
77
- * generate code for harmony-specific packages. The shape of this codegenConfig is different
78
- * that the shape of the shared config, to allow specifying which specific turbo modules or
79
- * fabric components should be code generated.
80
- */
81
- const rawCodegenConfig = this.rawPackageJSON.harmony?.codegenConfig;
82
- if (!rawCodegenConfig) {
83
- return [];
84
- }
85
- if (Array.isArray(rawCodegenConfig)) {
86
- return rawCodegenConfig.map((config) =>
87
- CodegenConfig.fromRawCodegenConfig(
88
- config,
89
- this.packageRootPath,
90
- this.projectRootPath,
91
- this.name
92
- )
93
- );
94
- }
95
- return [
96
- CodegenConfig.fromRawCodegenConfig(
97
- rawCodegenConfig,
98
- this.packageRootPath,
99
- this.projectRootPath,
100
- this.name
101
- ),
102
- ];
103
- }
104
- }
@@ -1,103 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 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
- */
7
-
8
- import { AbsolutePath } from './AbsolutePath';
9
- import { PackageJSON } from './PackageJSON';
10
- import { FS } from '../core';
11
-
12
- export class ProjectDependency {
13
- constructor(
14
- private fs: FS,
15
- private packageRootPath: AbsolutePath,
16
- private projectRootPath: AbsolutePath
17
- ) {}
18
-
19
- getRootPath() {
20
- return this.packageRootPath;
21
- }
22
-
23
- getCodegenConfigs() {
24
- return this.readPackageJSON().getCodegenConfigs();
25
- }
26
-
27
- getHarFilePath(): AbsolutePath | null {
28
- const packageHarmonyPath =
29
- this.packageRootPath.copyWithNewSegment('harmony');
30
- if (!this.fs.existsSync(packageHarmonyPath)) {
31
- return null;
32
- }
33
-
34
- const harFilePaths = this.fs.findFilePathsWithExtensions(
35
- packageHarmonyPath,
36
- ['har']
37
- );
38
- if (harFilePaths.length !== 1) {
39
- return null;
40
- }
41
- return harFilePaths[0];
42
- }
43
-
44
- readPackageJSON() {
45
- return PackageJSON.fromProjectRootPath(
46
- this.fs,
47
- this.packageRootPath,
48
- this.projectRootPath
49
- );
50
- }
51
- }
52
-
53
- export class ProjectDependenciesManager {
54
- constructor(private fs: FS, private projectRootPath: AbsolutePath) {}
55
-
56
- async forEachAsync(
57
- cb: (dependency: ProjectDependency) => Promise<void> | void
58
- ) {
59
- await this.forEachDependencyInDirectory(
60
- cb,
61
- this.projectRootPath.copyWithNewSegment('node_modules')
62
- );
63
- }
64
-
65
- private async forEachDependencyInDirectory(
66
- cb: (dependency: ProjectDependency) => Promise<void> | void,
67
- directoryPath: AbsolutePath
68
- ) {
69
- if (!this.fs.existsSync(directoryPath)) {
70
- return;
71
- }
72
- for (let dirent of this.fs.readDirentsSync(directoryPath)) {
73
- if (dirent.isDirectory()) {
74
- if (dirent.name.startsWith('.')) {
75
- continue;
76
- } else if (dirent.name.startsWith('@')) {
77
- await this.forEachDependencyInDirectory(
78
- cb,
79
- directoryPath.copyWithNewSegment(dirent.name)
80
- );
81
- } else {
82
- const potentialDependencyRootPath = directoryPath.copyWithNewSegment(
83
- dirent.name
84
- );
85
- if (
86
- !this.fs.existsSync(
87
- potentialDependencyRootPath.copyWithNewSegment('package.json')
88
- )
89
- ) {
90
- continue;
91
- }
92
- await cb(
93
- new ProjectDependency(
94
- this.fs,
95
- potentialDependencyRootPath,
96
- this.projectRootPath
97
- )
98
- );
99
- }
100
- }
101
- }
102
- }
103
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 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
- */
7
-
8
- export class ValidationError extends Error {}
@@ -1,9 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 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
- */
7
-
8
- /** https://en.wikipedia.org/wiki/Value_object */
9
- export interface ValueObject {}
package/src/core/fs.ts DELETED
@@ -1,38 +0,0 @@
1
- /**
2
- * Copyright (c) 2024-2025 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
- */
7
-
8
- import fs from 'node:fs';
9
- import { AbsolutePath } from './AbsolutePath';
10
- import { DescriptiveError } from './DescriptiveError';
11
-
12
- export function maybeMakeDirectories(path: AbsolutePath): void {
13
- if (!fs.existsSync(path.getValue())) {
14
- fs.mkdirSync(path.getValue(), { recursive: true });
15
- }
16
- }
17
-
18
- export function maybeRemoveFilesInDirectory(path: AbsolutePath): void {
19
- if (!fs.existsSync(path.getValue())) {
20
- return;
21
- }
22
- if (!fs.lstatSync(path.getValue()).isDirectory()) {
23
- throw new DescriptiveError({
24
- whatHappened:
25
- "Tried to remove all files from a path that doesn't point to a directory",
26
- whatCanUserDo: [`Verify path: ${path.getValue()}`],
27
- });
28
- }
29
- const fileOrDirNames = fs.readdirSync(path.getValue());
30
- fileOrDirNames.forEach((fileOrDirName) => {
31
- const maybeFilePath = path.copyWithNewSegment(fileOrDirName);
32
- if (fs.statSync(maybeFilePath.getValue()).isDirectory()) {
33
- return;
34
- } else {
35
- fs.unlinkSync(maybeFilePath.getValue());
36
- }
37
- });
38
- }
package/src/core/index.ts DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 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
- */
7
-
8
- export * from './AbsolutePath';
9
- export * from './ValidationError';
10
- export * from './DescriptiveError';
11
- export * from './ValueObject';
12
- export * from './PackageJSON';
13
- export * from './ProjectDependenciesManager';
14
- export * from './CodegenConfig';
15
- export * from './fs';
16
- export * from './OHPackageJSON5';
17
- export * from './FileSystem';
package/src/index.ts DELETED
@@ -1,33 +0,0 @@
1
- /**
2
- * Copyright (c) 2024-2025 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
- */
7
-
8
- import { Config, Command } from '@react-native-community/cli-types';
9
- import {
10
- commandBundleHarmony,
11
- commandPackHarmony,
12
- commandUnpackHarmony,
13
- commandCreateMetroConstantsHarmony,
14
- commandCodegenHarmony,
15
- commandVerifyPackageHarmony,
16
- commandCodegenLibHarmony,
17
- commandLinkHarmony,
18
- commandRunHarmony,
19
- } from './commands';
20
-
21
- export const config = {
22
- commands: [
23
- commandBundleHarmony,
24
- commandPackHarmony,
25
- commandUnpackHarmony,
26
- commandCreateMetroConstantsHarmony,
27
- commandCodegenHarmony,
28
- commandVerifyPackageHarmony,
29
- commandCodegenLibHarmony,
30
- commandLinkHarmony,
31
- commandRunHarmony,
32
- ] as Command[],
33
- } satisfies Partial<Config>;
@@ -1,69 +0,0 @@
1
- /**
2
- * Copyright (c) 2024-2025 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
- */
7
-
8
- import { AbsolutePath } from '../core';
9
- import { spawn } from 'node:child_process';
10
-
11
- export type CliOptions = {
12
- args: string[];
13
- cwd?: AbsolutePath;
14
- onArgsStringified?: (commandWithArgs: string) => void;
15
- onStdout?: (data: string) => void;
16
- onStderr?: (data: string) => void;
17
- shell?: boolean;
18
- };
19
-
20
- export abstract class CliExecutor {
21
- abstract run(command: string, options?: CliOptions): Promise<string>;
22
- }
23
-
24
- export class RealCliExecutor extends CliExecutor {
25
- async run(command: string, options?: CliOptions): Promise<string> {
26
- return new Promise((resolve, reject) => {
27
- let commandWithArgs = command;
28
- let argStrings: string[] = [];
29
- if (options?.args) {
30
- argStrings = options.args;
31
- commandWithArgs += ' ' + argStrings.join(' ');
32
- }
33
- options?.onArgsStringified?.(commandWithArgs);
34
- const process = spawn(command, argStrings, {
35
- cwd: options?.cwd?.toString(),
36
- shell: options?.shell ? true : false,
37
- });
38
-
39
- let stdout = '';
40
- let stderr = '';
41
-
42
- process.stdout.on('data', (data) => {
43
- const output = data.toString();
44
- stdout += output;
45
- options?.onStdout?.(output);
46
- });
47
-
48
- process.stderr.on('data', (data) => {
49
- const output = data.toString();
50
- stderr += output;
51
- options?.onStderr?.(output);
52
- });
53
-
54
- process.on('error', (error) => {
55
- reject(error);
56
- });
57
-
58
- process.on('close', (code) => {
59
- if (code === 0) {
60
- resolve(stdout);
61
- } else {
62
- reject(
63
- new Error(`Command failed with code ${code}\nStderr: ${stderr}`)
64
- );
65
- }
66
- });
67
- });
68
- }
69
- }
package/src/io/Logger.ts DELETED
@@ -1,112 +0,0 @@
1
- /**
2
- * Copyright (c) 2024-2025 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
- */
7
-
8
- import chalk from 'chalk';
9
- import { DescriptiveError } from '../core';
10
- import { getLoader, logger as LOGGER } from '@react-native-community/cli-tools';
11
- import process from 'node:process';
12
- export class Logger {
13
- private loader = getLoader({
14
- interval: process.stdout.isTTY ? undefined : 0,
15
- });
16
- private logger = LOGGER;
17
- private isLoaderActive = false;
18
-
19
- start(prepareMsg: (styles: typeof chalk) => string) {
20
- this.loader.start(prepareMsg(chalk));
21
- this.isLoaderActive = true;
22
- return (options?: { persist?: boolean }) => {
23
- this.isLoaderActive = false;
24
- if (options?.persist) {
25
- console.log({ loader: this.loader });
26
- this.loader.stopAndPersist();
27
- } else {
28
- this.loader.stop();
29
- }
30
- };
31
- }
32
-
33
- info(prepareMsg: (styles: typeof chalk) => string) {
34
- const info = (msg: string) => {
35
- this.isLoaderActive ? this.loader.info(msg) : this.logger.info(msg);
36
- };
37
- info(prepareMsg(chalk));
38
- }
39
-
40
- succeed(prepareMsg: (styles: typeof chalk) => string) {
41
- const succeed = (msg: string) =>
42
- this.isLoaderActive ? this.loader.succeed(msg) : this.logger.success(msg);
43
- succeed(prepareMsg(chalk));
44
- }
45
-
46
- warn(prepareMsg: (styles: typeof chalk) => string) {
47
- const warn = (msg: string) =>
48
- this.isLoaderActive ? this.loader.warn(msg) : this.logger.warn(msg);
49
- warn(prepareMsg(chalk));
50
- }
51
-
52
- debug(prepareMsg: (styles: typeof chalk) => string) {
53
- if (this.isLoaderActive) {
54
- clearLine(process.stdout);
55
- moveCursor(process.stdout, 0);
56
- console.debug(prepareMsg(chalk));
57
- this.loader.render();
58
- } else {
59
- console.debug(prepareMsg(chalk));
60
- }
61
- }
62
-
63
- descriptiveError(error: DescriptiveError) {
64
- const lines: string[] = [];
65
- if (error.isUnexpected() && error.stack) {
66
- lines.push('');
67
- lines.push(chalk.bold('Stack'));
68
- error.stack.split('\n').forEach((line) => lines.push(chalk.gray(line)));
69
- }
70
- const details = error.getDetails();
71
- if (details) {
72
- lines.push('');
73
- lines.push(chalk.bold('Details'));
74
- details.split('\n').forEach((line) => lines.push(line));
75
- }
76
- lines.push('');
77
- lines.push(`${error.getMessage()}`);
78
- const suggestions = error.getSuggestions();
79
-
80
- if (suggestions.length > 0) {
81
- lines.push('');
82
- lines.push(chalk.bold(`Suggestions`));
83
- suggestions.forEach((suggestion) => {
84
- lines.push('• ' + suggestion);
85
- });
86
- }
87
-
88
- if (this.isLoaderActive) {
89
- this.loader.fail(lines.join('\n').trim());
90
- } else {
91
- this.logger.error(lines.join('\n').trim());
92
- }
93
- }
94
- }
95
-
96
- const clearLine = (stream: NodeJS.WriteStream): void => {
97
- if (stream.clearLine) {
98
- stream.clearLine(0);
99
- } else {
100
- process.stdout.write(
101
- '\r' + ' '.repeat(process.stdout.columns || 80) + '\r'
102
- );
103
- }
104
- };
105
-
106
- const moveCursor = (stream: NodeJS.WriteStream, x: number): void => {
107
- if (stream.cursorTo) {
108
- stream.cursorTo(x);
109
- } else {
110
- process.stdout.write('\r');
111
- }
112
- };
package/src/io/RealFS.ts DELETED
@@ -1,62 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 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
- */
7
-
8
- import { AbsolutePath } from '../core';
9
- import { Dirent, FS } from '../core/FileSystem';
10
- import fs, { Dirent as NodeFSDirent } from 'node:fs';
11
-
12
- class RealFSDirent extends Dirent {
13
- constructor(private nodeFSDirent: NodeFSDirent) {
14
- super();
15
- }
16
-
17
- isDirectory(): boolean {
18
- return this.nodeFSDirent.isDirectory();
19
- }
20
-
21
- get name(): string {
22
- return this.nodeFSDirent.name;
23
- }
24
- }
25
-
26
- export class RealFS extends FS {
27
- existsSync(path: AbsolutePath): boolean {
28
- return fs.existsSync(path.toString());
29
- }
30
-
31
- readTextSync(path: AbsolutePath): string {
32
- return fs.readFileSync(path.toString()).toString();
33
- }
34
-
35
- async readText(path: AbsolutePath): Promise<string> {
36
- return new Promise((resolve, reject) => {
37
- fs.readFile(path.toString(), undefined, (err, data) => {
38
- if (err) {
39
- reject(err);
40
- return;
41
- }
42
- resolve(data.toString());
43
- });
44
- });
45
- }
46
-
47
- writeTextSync(path: AbsolutePath, data: string): void {
48
- fs.writeFileSync(path.toString(), data);
49
- }
50
-
51
- readDirentsSync(
52
- path: AbsolutePath,
53
- options?: { recursive?: boolean | undefined } | undefined
54
- ): Dirent[] {
55
- return fs
56
- .readdirSync(path.toString(), {
57
- withFileTypes: true,
58
- recursive: options?.recursive,
59
- })
60
- .map((rawDirent) => new RealFSDirent(rawDirent));
61
- }
62
- }
package/src/io/TarGz.ts DELETED
@@ -1,33 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 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
- */
7
-
8
- import fs from 'node:fs';
9
- import zlib from 'zlib';
10
- import tar from 'tar';
11
- import { AbsolutePath } from '../core';
12
-
13
- export function unpackTarGz(
14
- archivePath: AbsolutePath,
15
- outputDirPath: AbsolutePath
16
- ) {
17
- if (!fs.existsSync(outputDirPath.getValue())) {
18
- fs.mkdirSync(outputDirPath.getValue(), { recursive: true });
19
- }
20
- const readStream = fs.createReadStream(archivePath.getValue());
21
- const writeStream = tar.extract({
22
- cwd: outputDirPath.getValue(),
23
- });
24
- readStream.pipe(zlib.createGunzip()).pipe(writeStream);
25
- return new Promise((resolve, reject) => {
26
- writeStream.on('finish', () => {
27
- resolve(undefined);
28
- });
29
- writeStream.on('error', (err) => {
30
- reject(err);
31
- });
32
- });
33
- }