目录

ohpm convert

Converts a third-party library from npm to ohpm. Due to syntax differences, the conversion only transforms file formats and does not modify the code logic of the original npm package. If code incompatibility errors occur in the converted HAR package, you must adapt the original npm package's code accordingly.

Command Format

ohpm convert [[<@group>/]<pkg>[@<version> | @tag:<tag>]] --registry <string> [--publish]
ohpm convert <node_modules_path> [--publish]
  • @group: namespace of the third-party library. This parameter is optional.
  • pkg: name of the third-party library. This parameter is mandatory.
  • version: version number of the third-party library. This parameter is optional.
  • tag: tag of the third-party library, marking a specific version number. This parameter is optional.

Description

This command is used to convert a package in the specified npm repository or a package in the local node_modules directory to a HAR package that meets the ohpm format requirements and save the HAR package to the current working directory, the converted package can be uploaded to the ohpm-repo private repository or OpenHarmony third-party library central repository.

The ohpm convert command only retains the following fields in package.json of the npm package: name, version, main, types, license, description, author, keywords, homepage, repository, artifactType, dependencies, devDependencies, dynamicDependencies, overrides, scripts, hooks, module, packageType, typesVersions, exports, and jsnext:main. For specific field descriptions, see oh-package.json5.

Options

[h2]registry

You can append the --registry <registry> parameter to the ohpm convert command to specify a repository address for conversion. If the --registry parameter is specified, the ohpm convert command will download the specified package and its dependencies from the remote repository address and then perform the conversion process. If it is not specified, the command will perform the conversion process using the local node_modules directory.

[h2]publish

You can append the --publish parameter to the ohpm convert command. If this parameter is set, confirm that the push package configurations in .ohpmrc are correct before executing the ohpm convert command. After all packages have been converted, the packages will be pushed sequentially according to the configurations in .ohpmrc.

[h2]log_level

In ohpm 6.0.2.636 and later versions, you can append the --log_level <string> parameter to the ohpm convert command to specify the log level (info, debug, warn, or error) for execution of the current command. If this parameter is not set, the log_level setting in the .ohpmrc file is applied.

[h2]debug

In ohpm 6.0.2.636 and later versions, you can append the --debug parameter to the command to set the log level to debug for execution of the current command. This configuration takes effect only on the current command line and does not alter the log level configured in the .ohpmrc file. If this parameter is not set, the log_level setting in the .ohpmrc file is applied.

Example

Converting a Package from the npm Third-Party Library

To convert the axios package from an npm third-party library, run the following command:

ohpm convert axios --registry https://registry.npmjs.org/

Below is an output example:

PS C:\Users\xxxxx\Desktop> ohpm convert axios --registry https://registry.npmjs.org
...
ohpm INFO: > start convert package: asynckit@0.4.0
ohpm INFO: > start convert package: axios@1.6.8
ohpm INFO: > start convert package: combined-stream@1.0.8
...
ohpm INFO: A total of 9 packets are converted successfully.
ohpm INFO: Converted packages are saved to the "C:\Users\xxxxx\Desktop\convert_1712127991590" directory.

Converting a Package in the Local node_modules Directory

After running the npm install uuid command, run the following command to convert the packages in the local node_modules directory:

ohpm convert C:\Users\xxxxx\Desktop\uuidInstallDir\node_modules

Below is an output example:

PS C:\Users\xxxxx\Desktop> ohpm convert C:\Users\xxxxx\Desktop\uuidInstallDir\node_modules
ohpm INFO: > start convert package: uuid
...
ohpm INFO: A total of 1 package(s) are converted successfully.
ohpm INFO: Converted packages are saved to the "C:\Users\xxxxx\Desktop\convert_1712128912583" directory.