Project code packaging method, device, terminal equipment and storage medium

By determining the dependency mapping path of the third-party library and performing address replacement processing in the software project code packaging process, the problems of low development efficiency, reference errors and coding difficulties in the existing technology are solved, and efficient and accurate project code packaging is achieved.

CN114416057BActive Publication Date: 2025-08-19PING AN PAY ELECTRONIC PAYMENT CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210059385.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-19
Publication Date
2025-08-19
Estimated Expiration
2042-01-19

AI Technical Summary

Technical Problem

In the process of packaging software project code, the existing technology has problems such as low development efficiency, easy reference errors, poor adaptability and difficult coding. Especially when loading third-party libraries on demand, developers need to specify detailed addresses and cannot handle path replacement in nested directories.

Method used

By traversing the code of the third-party library, determine the dependency mapping path of the target variable and save it in the configuration file, traverse the import statements in the project, and replace the address according to the configuration file. Only the files contained in the imported variables in the third-party library are packaged into the project, avoiding the full packaging of the third-party library.

Benefits of technology

It reduces the redundancy of the project, improves development efficiency, reduces coding difficulty, avoids reference errors, and enhances adaptability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114416057B_ABST
    Figure CN114416057B_ABST
Patent Text Reader

Abstract

The present application is applicable to the field of software development technology, and provides a project code packaging method, apparatus and terminal device, the method comprising: traversing all codes of a third-party library, determining the dependency mapping path of the target variable of the third-party library, and saving the dependency mapping path of the target variable of the third-party library in a configuration file of the third-party library; upon receiving a project code packaging instruction, traversing all import statements in the project, and determining the import variables existing in the project; performing address replacement processing on the import variables according to the configuration file of the third-party library; and packaging the project code after the address replacement processing, wherein only the file containing the import variable in the third-party library needs to be packaged into the project, which can reduce the redundancy of the project, and there is no need to create a directory according to the prescribed rules when writing the code of the third-party library, thereby effectively reducing the coding difficulty.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of software development technology, and in particular relates to a project code packaging method, apparatus, terminal device, and computer-readable storage medium. Background Art

[0002] In the daily development of software projects, with the increasing complexity of functions and the development of framework technologies, project completion has become increasingly dependent on the reference of third-party libraries. When packaging software project code, it is often necessary to package third-party libraries together. This results in redundant code being packaged into the project, resulting in excessive project file size, which affects user access speed and system performance.

[0003] Existing project code packaging methods propose a method for loading third-party libraries on demand. However, this requires developers to specify the detailed addresses of the imported variables when writing code. This requires developers to be very clear about the directories corresponding to the third-party library's exported functions, leading to problems such as low development efficiency. Furthermore, after iterations of the third-party library, changes in the reference path can also cause reference errors. Existing methods also provide a method for loading and packaging third-party libraries on demand using a third-party library-specific packaging optimization plugin. However, this method can only map paths within a single directory and cannot handle path replacement within nested directories. Furthermore, when developing third-party libraries, it is necessary to create directories according to the packaging optimization plugin's rules, which increases coding difficulty.

[0004] In summary, the current method of loading third-party libraries on demand has the problems of low development efficiency, prone to reference errors, poor adaptability and high coding difficulty. Summary of the Invention

[0005] The embodiments of the present application provide a project code packaging method, apparatus, terminal device and computer-readable storage medium, which can solve the problems of low development efficiency, easy reference errors, poor adaptability and high coding difficulty in the current method of loading third-party libraries on demand.

[0006] In a first aspect, an embodiment of the present application provides a project code packaging method, comprising:

[0007] Traversing all codes of the third-party library, determining a dependency mapping path of a target variable of the third-party library, and saving the dependency mapping path of the target variable of the third-party library in a configuration file of the third-party library;

[0008] Upon receiving a project code packaging instruction, traverse all import statements in the project to determine the import variables existing in the project;

[0009] Performing address replacement processing on the imported variable according to the configuration file of the third-party library;

[0010] Package the project code after address replacement.

[0011] In an implementation of the first aspect, traversing all codes of the third-party library to determine a dependency mapping path of a target variable of the third-party library, and saving the dependency mapping path of the target variable of the third-party library in a configuration file of the third-party library, includes:

[0012] Traversing all codes in the third-party library to determine an abstract syntax tree corresponding to the third-party library;

[0013] Collect all variables of the third-party library according to the abstract syntax tree classification to obtain an import statement variable set, a type definition statement variable set, and an export statement variable set;

[0014] Determining a target variable according to the import statement variable set, the type definition statement variable set, and the export statement variable set;

[0015] Get the dependency mapping path of the target variable.

[0016] In an implementation of the first aspect, determining the target variable according to the import statement variable set, the type definition statement variable set, and the export statement variable set includes:

[0017] Traverse the variables in the import statement variable set to determine whether there is a variable in the export statement variable set with the same name as the variable in the import statement variable set;

[0018] If there is a variable in the export statement variable set with the same name as the variable in the import statement variable set, then obtain the path of the variable and determine whether the path of the variable in the import statement is consistent with the path of the variable in the export statement;

[0019] If the path of the variable in the import statement is consistent with the path of the variable in the export statement, deleting the variable from the export statement variable set;

[0020] Traverse the variables in the type definition statement variable set to determine whether there is a variable in the export statement variable set with the same name as the variable in the type definition statement variable set;

[0021] If there is a variable in the export statement variable set with the same name as the variable in the type definition statement variable set, then obtain the path of the variable and determine whether the path of the variable in the type definition statement is consistent with the path of the variable in the export statement;

[0022] If the path of the variable in the type definition statement is consistent with the path of the variable in the export statement, the variable is deleted from the export statement variable set.

[0023] In an implementation of the first aspect, when multiple third-party libraries are referenced during project development, traversing all codes of the third-party libraries to determine dependency mapping paths of target variables of the third-party libraries, and saving the dependency mapping paths of the target variables of the third-party libraries in configuration files of the third-party libraries, includes:

[0024] When loading a third-party library, the dependency collection command is automatically executed to generate a configuration file for the loaded third-party library.

[0025] In an implementation of the first aspect, upon receiving the project code packaging instruction, traversing all import statements in the project to determine the import variables present in the project includes:

[0026] Traversing all codes in the project, identifying import statements whose reference paths are the library names of the third-party libraries;

[0027] Variables in the import statement are identified to obtain the import variables.

[0028] In an implementation of the first aspect, upon receiving the project code packaging instruction, traversing all import statements in the project to determine the import variables present in the project includes:

[0029] Determine the library names of all third-party libraries referenced by the project;

[0030] Identify the import statements whose reference paths are the library names of various third-party libraries;

[0031] Variables in the import statement are identified to obtain the import variables.

[0032] In an implementation of the first aspect, performing address replacement processing on the imported variable according to the configuration file of the third-party library includes:

[0033] Determine the dependency mapping path corresponding to the imported variable according to the configuration file;

[0034] The original address of the imported variable in the project is replaced with the dependency mapping path corresponding to the imported variable.

[0035] In a second aspect, an embodiment of the present application provides a project code packaging device, comprising:

[0036] a dependency determination unit, configured to traverse all codes of a third-party library and determine a dependency mapping path of a target variable of the third-party library, so as to save the dependency mapping path of the target variable of the third-party library in a configuration file of the third-party library;

[0037] A variable determination unit is configured to, upon receiving a project code packaging instruction, traverse all import statements in the project and determine the import variables existing in the project;

[0038] An address replacement unit, configured to perform address replacement processing on the imported variable according to a configuration file of the third-party library;

[0039] The packaging unit is used to package the project code after the address replacement processing.

[0040] In a third aspect, an embodiment of the present application provides a terminal device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the project code packaging method as described in any one of the first aspects above are implemented.

[0041] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the steps of the project code packaging method as described in any one of the first aspects above.

[0042] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when running on a terminal device, enables the terminal device to execute the project code packaging method described in any one of the first aspects above.

[0043] Compared with the prior art, the embodiments of the present application have the following beneficial effects:

[0044] A project code packaging method proposed in this embodiment does not need to package the entire third-party library into the project. It only needs to package the imported variable and the file containing the variable in the third-party library into the project, which can reduce the redundancy of the project. In addition, the detailed replacement address of the imported variable can be determined based on the dependency mapping path of the variable in the configuration file. When writing the code of the third-party library, there is no need to create a directory according to the prescribed rules, which effectively reduces the coding difficulty and solves the problems of low development efficiency, easy reference errors, poor adaptability and high coding difficulty in the current method of loading third-party libraries on demand. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments or descriptions of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0046] Figure 1 This is a schematic diagram of the implementation flow of the project code packaging method provided in one embodiment of the present application;

[0047] Figure 2 This is a schematic diagram of a specific implementation flow of S11 in the project code packaging method provided in one embodiment of the present application;

[0048] Figure 3 This is a schematic diagram of a specific implementation flow of S13 in the project code packaging method provided in one embodiment of the present application;

[0049] Figure 4 This is a schematic diagram of the structure of a project code packaging device provided in one embodiment of the present application;

[0050] Figure 5 It is a structural diagram of a terminal device provided in one embodiment of the present application. DETAILED DESCRIPTION

[0051] In the following description, specific details such as specific system structures and techniques are provided for purposes of illustration rather than limitation to facilitate a thorough understanding of the embodiments of the present application. However, it will be apparent to those skilled in the art that the present application may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid obscuring the description of the present application with unnecessary detail.

[0052] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or collections thereof.

[0053] It will also be understood that the term "and / or" used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.

[0054] As used in this specification and the appended claims, the term "if" can be interpreted as "when" or "upon" or "in response to determining" or "in response to detecting," depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "upon determination" or "in response to determining" or "upon detection of [described condition or event]" or "in response to detecting [described condition or event]," depending on the context.

[0055] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0056] References to "one embodiment" or "some embodiments" in this specification mean that a particular feature, structure, or characteristic described in conjunction with that embodiment is included in one or more embodiments of the present application. Thus, phrases such as "in one embodiment," "in some embodiments," "in other embodiments," and "in other embodiments" appearing in various places in this specification do not necessarily refer to the same embodiment, but rather mean "one or more but not all embodiments," unless otherwise specifically emphasized. The terms "including," "comprising," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized.

[0057] See also Figure 1 , Figure 1 This is a flowchart for implementing a project code packaging method provided in one embodiment of the present application. In this embodiment of the present application, the execution subject of the above project code packaging method can be a terminal device or a server, etc., which has data processing capabilities. The above terminal device can be a smart phone, tablet computer, desktop computer, smart wearable device, etc., which has data processing capabilities. The above server can be a traditional server or a cloud server, which is not limited by this application.

[0058] like Figure 1 As shown, the project code packaging method provided in one embodiment of the present application may include S11 to S13, which are detailed as follows:

[0059] In S11 , all codes of the third-party library are traversed to determine the dependency mapping path of the target variable of the third-party library, so as to save the dependency mapping path of the target variable of the third-party library in a configuration file of the third-party library.

[0060] In the embodiments of the present application, the third-party library refers to a third-party code library referenced during the project code development process. When the project code needs to be packaged, the project code can first determine the third-party library referenced by the project code, and then traverse all the code of the third-party library to determine the dependency mapping path of the target variable of the third-party library, that is, determine the specific location of the source file containing the target variable in the third-party library.

[0061] In a specific application, the specific location of the source file containing the target variable in the third-party library can be represented in the form of a storage path.

[0062] In an embodiment of the present application, after determining the dependency mapping path of the target variable, a configuration file is generated, and the dependency mapping path of the target variable is saved in the configuration file of the third-party library. When packaging the project code, the storage location of the source file containing the target variable can be determined by accessing the configuration file, thereby packaging the source file containing the target variable into the project without specifying a specific file path or requiring the developer to create a directory according to the rules of the packaging optimization plug-in.

[0063] In specific applications, in order to reduce the storage space occupied by the configuration file and improve the reading and writing efficiency of the configuration file, the configuration file of the above third-party library can be stored in the JSON file format.

[0064] In the embodiment of the present application, the target variable refers to a variable that only exists in the export statement of the third-party library.

[0065] Since there are many variables in the third-party library, not all of these variables are variables in the export statement. Therefore, in order to determine the target variable, you can first determine all the variables from all the codes of the third-party library, and then judge whether these variables only exist in the export statement. If the same variable also exists in the import statement or type definition statement, then when determining the dependency mapping path, the same variable will be exported in different source files, resulting in the path being specified to a non-source file, resulting in redundant packaging code. To avoid this situation, you need to delete the variables in the import statement and type definition statement of the third-party library that are the same as the export statement.

[0066] See also Figure 2 , Figure 2 The specific implementation process of S11 in the project code packaging method provided in the embodiment of the present application is shown. Figure 2 As shown, in the embodiment of the present application, the above S11 may include the following steps:

[0067] S111: traverse all codes in the third-party library and determine the abstract syntax tree corresponding to the third-party library;

[0068] S112: Collect all variables of the third-party library according to the abstract syntax tree classification to obtain an import statement variable set, a type definition statement variable set, and an export statement variable set;

[0069] S113: Determine the target variable according to the import statement variable set, the type definition statement variable set, and the export statement variable set;

[0070] S114: Obtain the dependency mapping path of the target variable.

[0071] In an embodiment of the present application, in order to determine the target variable and avoid packaging errors, the abstract syntax tree corresponding to the third-party library is determined by traversing the third-party library, and then all variables of the third-party library are determined from the abstract syntax data.

[0072] It should be noted that the Abstract Syntax Tree (AST), or simply Syntax Tree, is an abstract representation of the grammatical structure of source code. It represents the grammatical structure of a programming language in a tree-like form, with each node in the tree representing a structure in the source code.

[0073] In the specific implementation, the types of various statements can be determined through the abstract syntax tree, and then all variables of the third-party library can be classified and collected.

[0074] In the specific implementation, the import statements, export statements and type definition statements in the third-party library can be determined through the abstract syntax tree, and then the import statements, export statements and type definition statements can be traversed to find the variables in the import statements, export statements and type definition statements. The variables in the import statements are grouped into the import statement variable set, the variables in the export statements are grouped into the export statement variable set, and the variables in the type definition variable statements are grouped into the type definition statement variable set.

[0075] In a specific implementation, when traversing the code to determine the abstract syntax tree, three preset hook functions can be executed, where the first hook function is used to collect variables in export statements, the second hook function is used to collect variables in import statements, and the third hook function is used to collect variables in type definition statements. Therefore, the three collected variable sets are unrelated.

[0076] In a specific implementation, the above-mentioned hook function can also directly determine the path corresponding to the variables in each variable set, that is, the dependency mapping path of each variable can also be directly obtained. That is, when the first hook function is executed, the variables in the export statement will be grouped into the export statement variable set, and the dependency mapping path corresponding to each variable in the export statement variable set will be determined. When the second hook function is executed, the variables in the import statement will be grouped into the import statement variable set, and the dependency mapping path corresponding to each variable in the import statement variable set will be determined. When the third hook function is executed, the variables in the type definition statement will be grouped into the type definition statement variable set, and the dependency mapping path corresponding to each variable in the type definition statement variable set will be determined. Therefore, after determining the target variable, the dependency mapping path of the target variable can be determined.

[0077] In one embodiment of the present application, the above S113 specifically includes the following steps:

[0078] Traverse the variables in the import statement variable set to determine whether there is a variable in the export statement variable set with the same name as the variable in the import statement variable set;

[0079] If there is a variable in the export statement variable set with the same name as the variable in the import statement variable set, then obtain the path of the variable and determine whether the path of the variable in the import statement is consistent with the path of the variable in the export statement;

[0080] If the path of the variable in the import statement is consistent with the path of the variable in the export statement, delete the variable from the export statement variable set;

[0081] Traverse the variables in the type definition statement variable set to determine whether there is a variable in the export statement variable set with the same name as the variable in the type definition statement variable set;

[0082] If there is a variable in the export statement variable set with the same name as the variable in the type definition statement variable set, then obtain the path of the variable and determine whether the path of the variable in the type definition statement is consistent with the path of the variable in the export statement;

[0083] If the path of the variable in the type definition statement is consistent with the path of the variable in the export statement, the variable is deleted from the export statement variable set.

[0084] In an embodiment of the present application, to avoid the situation where variables from source files of other third-party libraries are imported and then exported, it is necessary to first delete the variables that exist in both the export statement and the import statement (with the same variable name) under the same path. This way, the generated configuration file will not contain the mapping dependencies of these variables, which can effectively avoid packaging errors. For variables in type definition statements, the paths of these variables do not need to be replaced during packaging. Replacing them will cause packaging errors. These variables only define certain variables and have no actual application. To avoid packaging errors caused by replacement, these variables also need to be deleted from the export statement variable set.

[0085] The variables in the export statement variable set after deleting the above two types of variables are the target variables.

[0086] It should be noted that if the variable in the import statement has the same name as the variable in the export statement but a different path, then the variable is not the variable that needs to be deleted, so it will not be deleted.

[0087] For variables in type definition statements, if they are not in the same path, it will not affect subsequent code packaging. Therefore, if the paths are different, there is no need to delete the variables.

[0088] In one embodiment of the present application, when multiple third-party libraries are referenced during project development, the above S11 may include the following steps:

[0089] When loading a third-party library, the dependency collection command is automatically executed to generate a configuration file for the loaded third-party library.

[0090] In an embodiment of the present application, when loading a third-party library, the dependency collection command is automatically triggered and executed to determine the dependency mapping path of the target variable in the third-party library. The dependency mapping path is then saved in a configuration file to obtain the configuration file of the third-party library. By executing the above-mentioned dependency collection command for all third-party libraries referenced by the project, the configuration file of each third-party library can be obtained.

[0091] In specific applications, when running project code, if a third-party library is referenced, the third-party library will be loaded during the execution process, triggering a dependency collection command, which enables the terminal device to automatically execute the dependency collection command and generate a configuration file corresponding to the loaded third-party library. After generating the configuration file for the third-party library, the terminal device can store the configuration file in a preset storage location so that the configuration file can be directly called to determine the variable dependency mapping path when packaging the project.

[0092] The above dependency collection command is used to trigger the terminal device to traverse all codes of the third-party library, determine the dependency mapping path of the target variable, and generate a configuration file based on the mapping relationship between the target variable and the dependency mapping path of the target variable.

[0093] In specific applications, different third-party libraries will generate different configuration files. The configuration files can be named after the library name of the third-party library to determine the correspondence between the third-party library and the configuration file.

[0094] In S12 , when the project code packaging instruction is received, all import statements in the project are traversed to determine the import variables existing in the project.

[0095] In an embodiment of the present application, the above-mentioned project code packaging instruction can be initiated by the developer through the development software, and the terminal device will automatically execute S12-S14 when receiving the project packaging instruction to realize the packaging of the project code.

[0096] In the embodiment of the present application, the imported variable is a variable that references a third-party library.

[0097] It's important to note that an import statement is a program statement that imports a package or variable. For example, an import statement includes the dependencies of the imported package or variable, specifically the library on which the imported variable depends. When writing an import statement, developers need to include the library name of the variable. This allows them to determine which variables in the project belong to third-party libraries by accessing all import statements in the project.

[0098] It should also be noted that since this embodiment has determined the dependency mapping path of the target variable in the third-party library through the configuration file, during the project development process, if it is necessary to reference the third-party library, it is only necessary to uniformly write the referenced path as the library name of the third-party library to improve development efficiency, without specifying the specific path of the variable.

[0099] For example, if the library name of the third-party library is "thirdLibrary", the reference path of the import statement can be uniformly written as "thirdLibrary".

[0100] In an implementation of the present application, the above S12 may include the following steps:

[0101] Traverse all the codes in the project and identify the import statements whose reference path is the library name of the third-party library;

[0102] Identify variables in import statements and get imported variables.

[0103] In a specific application, taking the third-party library named "thirdLibrary" as an example, by traversing all the codes in the project, matching the statement with the reference path "thirdLibrary", and obtaining the imported variable name, the imported variable that references the third-party library in the project is obtained.

[0104] It should be noted that if multiple third-party libraries are introduced during the project development process, it is necessary to determine the import variables corresponding to the introduced third-party libraries respectively.

[0105] In an implementation of the present application, the above S12 may further include:

[0106] Determine the library names of all third-party libraries referenced by the project;

[0107] Identify the import statements whose reference paths are the library names of various third-party libraries;

[0108] Identify variables in import statements and get imported variables.

[0109] In specific applications, first determine the library names of all third-party libraries referenced by the project, then traverse all the codes in the project, identify the import statements whose reference paths are the library names of all the above third-party libraries, and then determine the variable names of the variables in the import statements, so that the imported variables of all third-party libraries can be determined.

[0110] In S13: address replacement processing is performed on the imported variable according to the configuration file of the third-party library.

[0111] In specific applications, the configuration file of the above-mentioned third-party library is used to describe the mapping relationship between the target variable in the third library and the reference path corresponding to the target variable, that is, according to the variable name, the dependent mapping path of the variable corresponding to the variable name in the third-party library can be determined, that is, the storage location of the source file containing the variable can be determined.

[0112] In specific applications, after the terminal device determines the imported variables in the project, in order to effectively package the source files corresponding to the imported variables into the project, it is necessary to determine the specific storage location of the source files of the imported variables in the third-party library according to the configuration file in S11.

[0113] In specific applications, the terminal device will first determine the configuration file of the third-party library corresponding to the imported variable based on the imported variable, then call the configuration file, and determine the storage path of the source file containing the imported variable based on the mapping relationship between the target variable and the reference path corresponding to the target variable in the configuration file. Then, the reference path (i.e., the third-party library name) originally written by the developer is replaced with the storage path of the source file of the imported variable to achieve address replacement.

[0114] See also Figure 3 , Figure 3 The specific implementation process of S13 in the code packaging method provided in the embodiment of the present application is shown. Figure 3 As shown, in one implementation, the above S13 may include the following steps:

[0115] S131: Determine the dependency mapping path corresponding to the imported variable according to the configuration file;

[0116] S132: Replace the original address of the imported variable in the project with the dependency mapping path corresponding to the imported variable.

[0117] In the specific implementation, the dependency mapping path of the imported variable is first determined from the configuration file, that is, the specific location of the source file containing the imported variable in the third-party library, and then the original third-party library name is replaced with the specific location to complete the address replacement process.

[0118] For example, assuming that the imported variable variate1 is a variable that references the third-party library thirdLibrary1, when performing address replacement, the terminal device will call the configuration file corresponding to the third-party library thirdLibrary1, and then query the target variable variate1 with the same name as the imported variable variate1 from the configuration file, and then determine the dependency mapping path of variate1 based on the mapping relationship. Assuming that the dependency mapping path is thirdLibrary1\\LogisticRegression\\1\\.txt', after determining the dependency mapping path, the terminal device will replace the original address "thirdLibrary1" of the imported variable variate1 in the project with "thirdLibrary1\\LogisticRegression\\1\\.txt'".

[0119] In S14: the project code after the address replacement process is packaged.

[0120] In an embodiment of the present application, after replacing the address, the address of the imported variable is already its detailed address in the third-party library. Therefore, when packaging the project code, the terminal device will directly package the source file corresponding to the detailed address in the third-party library, instead of packaging the entire third-party library. This can reduce the size of the packaged file and avoid inserting useless code into the project.

[0121] As can be seen from the above, the project code packaging method proposed in this embodiment does not need to package the entire third-party library into the project. It only needs to package the imported variable and the file containing the variable in the third-party library into the project, which can reduce the redundancy of the project. In addition, the detailed replacement address of the imported variable can be determined based on the dependency mapping path of the variable in the configuration file. When writing the code of the third-party library, there is no need to create a directory according to the prescribed rules, which effectively reduces the coding difficulty and solves the problems of low development efficiency, easy reference errors, poor adaptability and high coding difficulty in the current method of loading third-party libraries on demand.

[0122] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0123] Corresponding to the project code packaging method described in the above embodiment, Figure 4 The structural block diagram of the project code packaging device provided by an embodiment of the present application is shown. For the sake of convenience, only the parts related to the embodiment of the present application are shown. Figure 4 The project code packaging device 40 includes: a dependency determination unit 41, a variable determination unit 42, an address replacement unit 43 and a packaging unit 44.

[0124] The dependency determination unit 41 is used to traverse all codes of the third-party library, determine the dependency mapping path of the target variable of the third-party library, and save the dependency mapping path of the target variable of the third-party library in the configuration file of the third-party library.

[0125] The variable determination unit 42 is configured to, upon receiving a project code packaging instruction, traverse all import statements in the project and determine the import variables existing in the project.

[0126] The address replacement unit 43 is used to perform address replacement processing on the imported variable according to the configuration file of the third-party library.

[0127] The packaging unit 44 is used to package the project code after the address replacement process.

[0128] In one embodiment of the present application, the dependency determination unit 41 may include an abstract syntax tree determination unit, a classification collection unit, a target variable determination unit, and a dependency path determination unit.

[0129] The abstract syntax tree determining unit is used to traverse all codes in the third-party library and determine an abstract syntax tree corresponding to the third-party library.

[0130] The classification collection unit is used to classify and collect all variables of the third-party library according to the abstract syntax tree to obtain an import statement variable set, a type definition statement variable set and an export statement variable set.

[0131] The target variable determination unit is configured to determine a target variable according to the import statement variable set, the type definition statement variable set, and the export statement variable set.

[0132] The dependency path determining unit is used to obtain the dependency mapping path of the target variable.

[0133] In one embodiment of the present application, the target variable determination unit is specifically configured to traverse the variables in the import statement variable set and determine whether there is a variable in the export statement variable set with the same name as the variable in the import statement variable set; if there is a variable in the export statement variable set with the same name as the variable in the import statement variable set, obtain the path of the variable and determine whether the path of the variable in the import statement is consistent with the path of the variable in the export statement; if the path of the variable in the import statement is consistent with the path of the variable in the export statement, delete the variable from the export statement variable set;

[0134] Traverse the variables in the type definition statement variable set and determine whether there is a variable in the export statement variable set with the same name as the variable in the type definition statement variable set; if there is a variable in the export statement variable set with the same name as the variable in the type definition statement variable set, obtain the path of the variable and determine whether the path of the variable in the type definition statement is consistent with the path of the variable in the export statement; if the path of the variable in the type definition statement is consistent with the path of the variable in the export statement, delete the variable from the export statement variable set.

[0135] In one embodiment of the present application, when multiple third-party libraries are referenced during project development, the dependency determination unit is specifically used to automatically execute the dependency collection command when loading the third-party library and generate a configuration file for the loaded third-party library.

[0136] In one embodiment of the present application, the variable identification unit 42 includes a first identification unit and a second identification unit.

[0137] The first identification unit is used to traverse all codes in the project and identify import statements whose reference paths are the library names of the third-party libraries.

[0138] The second recognition unit is used to recognize variables in the import statement to obtain the import variables.

[0139] In one embodiment of the present application, the variable identification unit 42 includes a library name determination unit, a third identification unit, and a fourth identification unit.

[0140] The library name determination unit is used to determine the library names of all third-party libraries referenced by the project.

[0141] The third identification unit is used to respectively identify the import statements whose reference paths are the library names of the third-party libraries;

[0142] The fourth identification unit is used to identify the variables in the import statement to obtain the import variables.

[0143] In one embodiment of the present application, the address replacement unit 43 includes: an address determination unit and a replacement unit.

[0144] The address determination unit is used to determine the dependency mapping path corresponding to the imported variable according to the configuration file.

[0145] The replacing unit is used to replace the original address of the imported variable in the project with the dependency mapping path corresponding to the imported variable.

[0146] From the above, it can be seen that a project code packaging device provided by an embodiment of the present application also does not need to package the entire third-party library into the project. It only needs to package the imported variable and the file containing the variable in the third-party library into the project, which can reduce the redundancy of the project, and only needs to determine the detailed replacement address of the imported variable according to the dependency mapping path of the variable in the configuration file. When writing the code of the third-party library, there is no need to create a directory according to the prescribed rules, which effectively reduces the coding difficulty and solves the problems of low development efficiency, easy reference errors, poor adaptability and high coding difficulty in the current method of loading third-party libraries on demand.

[0147] Figure 5 This is a schematic diagram of the structure of a terminal device provided in one embodiment of the present application. Figure 5 As shown, the terminal device 5 of this embodiment includes: at least one processor 50 ( Figure 5 Only one is shown in the figure) a processor, a memory 51, and a computer program 52 stored in the memory 51 and executable on the at least one processor 50. When the processor 50 executes the computer program 52, the steps of any one of the above-mentioned project code packaging method embodiments are implemented.

[0148] Those skilled in the art will understand that Figure 5 It is only an example of the terminal device 5 and does not constitute a limitation on the terminal device 5. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, it may also include input and output devices, network access devices, etc.

[0149] The processor 50 may be a central processing unit (CPU), or may be another general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. A general-purpose processor may be a microprocessor or any conventional processor.

[0150] In some embodiments, the memory 51 may be an internal storage unit of the terminal device 5, such as a hard drive or memory of the terminal device 5. In other embodiments, the memory 51 may also be an external storage device of the terminal device 5, such as a plug-in hard drive, a Smart Media Card (SMC), a Secure Digital (SD) card, a flash memory card, etc. equipped on the terminal device 5. Furthermore, the memory 51 may include both an internal storage unit of the terminal device 5 and an external storage device. The memory 51 is used to store an operating system, application programs, a boot loader, data, and other programs, such as the program code of the computer program. The memory 51 may also be used to temporarily store data that has been output or is about to be output.

[0151] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any one of the above-mentioned project code packaging method embodiments can be implemented.

[0152] An embodiment of the present application provides a computer program product. When the computer program product is run on a terminal device, the terminal device can implement the steps of any of the above-mentioned project code packaging method embodiments when executing the computer program product.

[0153] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of this application. Their specific functions and technical effects can be found in the method embodiment section and will not be repeated here.

[0154] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any one of the above-mentioned project code packaging method embodiments can be implemented.

[0155] An embodiment of the present application provides a computer program product. When the computer program product is run on a terminal device, the terminal device can implement the steps of any of the above-mentioned project code packaging method embodiments when executing the computer program product.

[0156] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated into a first processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0157] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant description of other embodiments.

[0158] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0159] In the embodiments provided in the present application, it should be understood that the disclosed project code packaging device and method can be implemented in other ways. For example, the device / terminal equipment embodiments described above are merely schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0160] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0161] The above-described embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present application, and should all be included in the scope of protection of the present application.

Claims

1. A project code packaging method, characterized in that: include: Traversing all codes of the third-party library, determining a dependency mapping path of a target variable of the third-party library, and saving the dependency mapping path of the target variable of the third-party library in a configuration file of the third-party library; Upon receiving a project code packaging instruction, traverse all import statements in the project to determine the import variables existing in the project; Performing address replacement processing on the imported variable according to the configuration file of the third-party library; Package the project code after address replacement.

2. The project code packaging method according to claim 1, characterized in that: The traversing all codes of the third-party library to determine the dependency mapping path of the target variable of the third-party library, and saving the dependency mapping path of the target variable of the third-party library in a configuration file of the third-party library, includes: Traversing all codes in the third-party library to determine an abstract syntax tree corresponding to the third-party library; Collect all variables of the third-party library according to the abstract syntax tree classification to obtain an import statement variable set, a type definition statement variable set, and an export statement variable set; Determine a target variable according to the import statement variable set, the type definition statement variable set, and the export statement variable set; Get the dependency mapping path of the target variable.

3. The project code packaging method according to claim 2, characterized in that: The determining of the target variable according to the import statement variable set, the type definition statement variable set, and the export statement variable set includes: Traverse the variables in the import statement variable set to determine whether there is a variable in the export statement variable set with the same name as the variable in the import statement variable set; If there is a variable in the export statement variable set with the same name as the variable in the import statement variable set, then obtain the path of the variable and determine whether the path of the variable in the import statement is consistent with the path of the variable in the export statement; If the path of the variable in the import statement is consistent with the path of the variable in the export statement, deleting the variable from the export statement variable set; Traverse the variables in the type definition statement variable set to determine whether there is a variable in the export statement variable set with the same name as the variable in the type definition statement variable set; If there is a variable in the export statement variable set with the same name as the variable in the type definition statement variable set, then obtain the path of the variable and determine whether the path of the variable in the type definition statement is consistent with the path of the variable in the export statement; If the path of the variable in the type definition statement is consistent with the path of the variable in the export statement, the variable is deleted from the export statement variable set.

4. The project code packaging method according to claim 1, wherein: When multiple third-party libraries are referenced during project development, traversing all codes of the third-party libraries to determine the dependency mapping paths of the target variables of the third-party libraries and saving the dependency mapping paths of the target variables of the third-party libraries in the configuration files of the third-party libraries includes: When loading a third-party library, the dependency collection command is automatically executed to generate a configuration file for the loaded third-party library.

5. The project code packaging method according to claim 1, wherein: When receiving the project code packaging instruction, traversing all import statements in the project to determine the import variables existing in the project includes: Traversing all codes in the project, identifying import statements whose reference paths are the library names of the third-party libraries; Variables in the import statement are identified to obtain the import variables.

6. The project code packaging method according to claim 1, characterized in that: When receiving the project code packaging instruction, traversing all import statements in the project to determine the import variables existing in the project includes: Determine the library names of all third-party libraries referenced by the project; Identify the import statements whose reference paths are the library names of various third-party libraries; Variables in the import statement are identified to obtain the import variables.

7. The project code packaging method according to claim 1, wherein: The performing address replacement processing on the imported variable according to the configuration file of the third-party library includes: Determine the dependency mapping path corresponding to the imported variable according to the configuration file; The original address of the imported variable in the project is replaced with the dependency mapping path corresponding to the imported variable.

8. A project code packaging device, characterized in that: include: a dependency determination unit, configured to traverse all codes of a third-party library and determine a dependency mapping path of a target variable of the third-party library, so as to save the dependency mapping path of the target variable of the third-party library in a configuration file of the third-party library; A variable determination unit is configured to, upon receiving a project code packaging instruction, traverse all import statements in the project and determine the import variables existing in the project; An address replacement unit, configured to perform address replacement processing on the imported variable according to a configuration file of the third-party library; The packaging unit is used to package the project code after the address replacement processing.

9. A terminal device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the project code packaging method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the project code packaging method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Method for packaging Vue project based on programming language and electronic device

    CN110007954A

  • Method and equipment for constructing vuejs project webpack

    CN112199080A