A method, product, device and medium for introducing dependency package
By generating dependency supplier files, only the target functions required by the front-end project are retained, which solves the problems of excessive node_modules folder size and low performance of the development environment caused by the traditional dependency package management method, and achieves streamlined introduction and efficient storage of dependency packages. Improved development efficiency.
Patent Information
- Application Number
- CN202410924960.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-11
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-07-11
AI Technical Summary
The traditional dependency package management method causes the node_modules folder to be too large and the performance of the development environment to be low, affecting development efficiency.
By initializing the front-end project, generating index files, obtaining and processing dependent packages, retaining only the target functions required by the project, and generating dependent supplier files, streamlined introduction and compressed storage of dependent packages are achieved.
Significantly reduces the local disk size occupied by dependent packages, reduces file retrieval overhead, and improves development environment performance and efficiency.
Smart Images

Figure CN118467031B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software development, and in particular to a method, product, device and medium for introducing a dependency package. Background Art
[0002] Dependency packages refer to other software packages or libraries that a project or program needs to use in software development. In the traditional dependency package management method based on the node package manager (npm) tool and the node_modules folder, after using the npm installation command, the source code of all dependency packages will be downloaded and installed.
[0003] However, the source code of the dependency packages is not necessary for all developers. After installing all the dependency packages, the complete source code of all the dependency packages is stored in the node_modules folder. For a medium-to-large front-end project, its dependency packages have nested dependencies. For example, project A depends on dependency packages B and C, and dependency packages B and C each depend on dependency packages D, E, F, G, etc. This phenomenon of nested dependencies will cause hundreds or thousands of dependency packages to be stored in the node_modules folder of a project, the folder size is bloated, and the file structure is complex and trivial, which will reduce the overall performance of the development environment and affect development efficiency.
[0004] In view of the above problems, how to solve the unreasonable way of introducing dependent packages in current front-end projects, which leads to excessive size of node_modules folder and reduces the overall performance and development efficiency of the development environment, is an urgent problem to be solved by technicians in this field. Summary of the invention
[0005] The purpose of the present invention is to provide a method, product, device and medium for introducing dependency packages to solve the problem that the current front-end project introduces dependency packages in an unreasonable way, resulting in a large size of the node_modules folder, which reduces the overall performance and development efficiency of the development environment.
[0006] In order to solve the above technical problems, the present invention provides a method for introducing a dependency package, comprising:
[0007] Initialize the front-end project and generate the front-end project code and index file; wherein the index file contains the information of each dependent package required by the front-end project;
[0008] Obtain the dependency packages required for the front-end project according to the index file;
[0009] Determine each target dependency package introduced by the front-end project code in each dependency package;
[0010] Processing each of the target dependency packages respectively to retain only the target functions required by the front-end project in each of the target dependency packages;
[0011] A dependent supplier file is generated based on the processed target dependent packages, so that the front-end project can introduce the target functions in the dependent supplier file.
[0012] On the one hand, the step of obtaining the dependent packages required by the front-end project according to the index file includes:
[0013] Get and execute the dependent package installation command;
[0014] Determine the name and version number of each dependent package required for the front-end project according to the index file;
[0015] Each dependent package is retrieved and downloaded according to its name and version number.
[0016] On the other hand, before retrieving and downloading each of the dependent packages according to the name and version number of each of the dependent packages, and after determining the name and version number of each of the dependent packages required for the front-end project according to the index file, the method further includes:
[0017] Deduplication processing is performed on each of the dependent packages according to the name and version number of each dependent package;
[0018] Generate a dependency package list based on the name and version number of each dependency package after deduplication processing, so as to facilitate retrieval and download of each dependency package according to the dependency package list;
[0019] Among them, the hierarchical relationship of each dependent package in the dependent package list is the same.
[0020] On the other hand, the retrieving and downloading each dependent package according to the name and version number of each dependent package includes:
[0021] Initiate retrieval of each dependent package in the dependent package list;
[0022] Determine whether the dependent package in the dependent package list can be retrieved in the local server;
[0023] If the dependent package can be retrieved in the local server, the supplier file corresponding to the dependent package in the local server is returned to the user's local computer for download;
[0024] If the dependent package cannot be retrieved in the local server, the dependent package is retrieved and downloaded from the public dependent package management warehouse according to the name and version number of the dependent package;
[0025] If the dependent package cannot be retrieved in the public dependent package management repository, the downloading of the dependent package is skipped and a warning message is output.
[0026] On the other hand, determining each target dependent package introduced by the front-end project code in each dependent package includes:
[0027] Initiate a static scan of the front-end project code;
[0028] Determine the source of each function in the front-end project code in turn;
[0029] When it is confirmed that the source of the current function is introduced externally, the current function is determined to be the target function;
[0030] Determine that the dependency package corresponding to the target function is the target dependency package.
[0031] On the other hand, the processing of each of the target dependency packages respectively to retain only the target functions required by the front-end project in each of the target dependency packages includes:
[0032] Initiate static scanning of each target dependency package;
[0033] Delete all functions in the target dependency packages except the corresponding target function.
[0034] On the other hand, generating a dependent supplier file based on each of the processed target dependent packages includes:
[0035] Generate an initial file based on each of the target dependency packages;
[0036] Encapsulating scope for the first-level dependency package in each of the target dependency packages;
[0037] Compressing the data in each of the scopes;
[0038] The dependent supplier file is generated based on the compressed initial file.
[0039] On the other hand, the compressing the data in each of the scopes includes:
[0040] Remove whitespace characters from the data in the scope;
[0041] Encapsulates internal variable and function names in the scope's data.
[0042] On the other hand, the front-end project introduces each of the target functions in the dependent vendor file, including:
[0043] The front-end project determines each of the scopes in the dependent supplier file;
[0044] The front-end project introduces the target function under the scope according to the determined scope.
[0045] On the other hand, after retrieving and downloading the dependency package in the public dependency package management repository according to the name and version number of the dependency package, the method further includes:
[0046] Packing and compressing the source code of the dependent package;
[0047] Generate a corresponding supplier file based on the processed dependency package;
[0048] Delete the source code of the dependent package;
[0049] The vendor files and their corresponding names and version numbers are stored on a local server.
[0050] On the other hand, if the dependent package cannot be retrieved in the public dependent package management repository, the method further includes:
[0051] Checking the version number of the dependent package, and determining whether the dependent package is a specific version according to the version number of the dependent package;
[0052] If it is confirmed that the dependent package is a specific version, the version range of the dependent package is modified, and the process returns to the step of retrieving and downloading the dependent package in the public dependent package management repository according to the name and version number of the dependent package.
[0053] On the other hand, it also includes:
[0054] Get the dependency package editing command;
[0055] The index file is edited based on the dependency package editing command to add and / or delete and / or modify the dependency packages required by the front-end project.
[0056] In order to solve the above technical problem, the present invention also provides a computer program product, including a computer program / instruction, which implements the steps of the above-mentioned dependent package introduction method when executed by a processor.
[0057] In order to solve the above technical problems, the present invention also provides a dependency package introduction device, comprising:
[0058] Memory for storing computer programs;
[0059] A processor is used to implement the steps of the above-mentioned dependent package introduction method when executing the computer program.
[0060] In order to solve the above technical problem, the present invention also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above-mentioned dependency package introduction method are implemented.
[0061] The dependency package introduction method provided by the present invention initializes the front-end project and generates the front-end project code and index file; wherein the index file contains the information of each dependency package required by the front-end project; obtains each dependency package required by the front-end project according to the index file; determines each target dependency package introduced by the front-end project code in each dependency package; processes each target dependency package respectively to retain only the target functions required by the front-end project in each target dependency package; generates a dependency supplier file based on each processed target dependency package, so that the front-end project can introduce each target function in the dependency supplier file. The beneficial effect of the present invention is that a large number of trivial dependency packages are integrated into a dependency supplier file. Compared with the traditional npm tool and the node_modules folder management dependency package method, the present solution can greatly reduce the local disk size occupied by the dependency package in the introduction of the dependency package of the front-end project; at the same time, in the process of generating the dependency supplier file, only the target function required by the front-end project is retained for each target dependency package, further reducing the volume of the dependency supplier file, reducing the file retrieval overhead of the local development environment, greatly improving the performance of the local development environment, and improving the development efficiency.
[0062] On the other hand, this solution obtains and executes the dependency package installation command, determines the name and version number of each dependency package required by the front-end project according to the index file, and retrieves and downloads each dependency package according to the name and version number of each dependency package, so as to realize accurate download of the dependency package. Deduplication is performed on each dependency package according to the name and version number of each dependency package; based on the name and version number of each dependency package after deduplication, a dependency package list is generated to facilitate retrieval and download of each dependency package according to the dependency package list, which can effectively reduce the retrieval overhead of the local development environment and improve the efficiency of retrieval and download. The retrieval and download of the dependency packages in the dependency list are realized through the local server and the public npm warehouse, so as to facilitate the introduction of the target dependency package by the front-end project. Start static scanning of the front-end project code; determine the source of each function in the front-end project code in turn; when it is confirmed that the source of the current function is externally introduced, determine the current function as the target function; determine the dependency package corresponding to the target function as the target dependency package, and realize the determination of the target dependency package. Start static scanning of each target dependency package, delete other functions except the corresponding target function in each target dependency package, reduce the file size, and save storage space. Generate initial files based on each target dependency package; encapsulate scopes for the first-level dependency packages in each target dependency package; compress the data in each scope; generate dependency vendor files based on the compressed initial files, thereby realizing the generation of dependency vendor files for the convenience of introducing front-end projects. By deleting blank characters in the scope data and compressing the internal variables and function names in the scope data, the data in the scope is compressed. When the user needs to modify the required dependency, the dependency package editing command can be obtained, and the index file can be edited based on the dependency package editing command, including adding dependency packages and / or deleting dependency packages and / or modifying the version of dependency packages, and then the modified index file is uploaded to complete the modification of the dependency.
[0063] In addition, the present invention also provides a dependency package introduction device, a computer program product and a medium, with the same effects as above. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] In order to more clearly illustrate the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0065] Figure 1 A flowchart of a method for importing a dependency package provided by an embodiment of the present invention;
[0066] Figure 2 A schematic diagram of a traditional dependency package dependency relationship provided by an embodiment of the present invention;
[0067] Figure 3 A schematic diagram of dependency relationships of dependent packages after deduplication processing provided by an embodiment of the present invention;
[0068] Figure 4 A schematic diagram of introducing a target function into a front-end project provided by an embodiment of the present invention;
[0069] Figure 5 A schematic diagram of a dependency package importing device provided by an embodiment of the present invention;
[0070] Figure 6 A schematic diagram of a dependency package introduction device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0071] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0072] The core of the present invention is to provide a method, product, device and medium for introducing dependency packages to solve the problem that the current front-end project's way of introducing dependency packages is unreasonable, resulting in a large size of the node_modules folder, which reduces the overall performance and development efficiency of the development environment.
[0073] In order to enable those skilled in the art to better understand the scheme of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0074] In the traditional npm tool and node_modules folder dependency package management method, after using the npm install command, all dependent source codes will be downloaded and installed, but not all developers need complete source codes. This results in the node_modules folder possibly storing a large number of dependent packages, and the file structure is complex, affecting the development environment performance and development efficiency. In order to solve the above problems, the present invention provides a method for introducing dependent packages.
[0075] Figure 1 A flowchart of a method for importing a dependency package provided by an embodiment of the present invention. Figure 1 As shown, the method includes:
[0076] S10: Initialize the front-end project and generate the front-end project code and index files.
[0077] Among them, the index file contains information about each dependent package required by the front-end project.
[0078] First, initialize the front-end project, which includes creating the project directory structure, initializing the package manager, installing development tools, configuring the build script, and setting up code version control. At the same time, you need to generate the front-end project code and index files.
[0079] It should be noted that the index file is package.json, which declares the information of each dependent package required by the front-end project. In this embodiment, there is no restriction on the information content of the dependent package involved, for example, it can be specifically the name, version information or source, depending on the specific implementation situation.
[0080] S11: Get the dependency packages required by the front-end project according to the index file.
[0081] It should be noted that since the dependency package is a third-party tool or component code package required for the front-end project, the dependency package generally does not exist locally on the user and needs to be obtained from the outside. Therefore, the dependency packages required by the front-end project are further obtained based on the information of the dependency packages required by the front-end project in the index file. In this embodiment, there is no restriction on the specific method of obtaining each dependency package; for example, it can be obtained through the npm tool, or from other storage media that store dependency packages, depending on the specific implementation situation.
[0082] S12: Determine each target dependency package introduced by the front-end project code in each dependency package.
[0083] S13: Process each target dependency package separately to retain only the target functions required by the front-end project in each target dependency package.
[0084] Furthermore, in order to introduce dependency packages into the front-end project, it is also necessary to determine the target dependency packages that the front-end project code needs to introduce in each dependency package, and process each target dependency package separately to retain only the target functions required by the front-end project in each target dependency package. It should be noted that the specific process of determining the target dependency packages that the front-end project code needs to introduce in each dependency package is not limited in this embodiment.
[0085] It is worth noting that the dependency package required by the front-end project may contain multiple functions, which are specifically embodied as different methods or different objects, but not every function is required by the front-end project. Take the dependency package for mathematical operations as an example: Assuming that the dependency package can provide four functions of addition, addition, multiplication and division, among which addition and addition are required by the front-end project, and multiplication and division are not required by the front-end project, when the front-end project introduces the dependency package, if all the functions of the dependency package are introduced, the functions of non-required multiplication and division will be introduced, which undoubtedly increases the file volume and wastes storage space meaninglessly. Therefore, in this embodiment, after confirming each target dependency package, each target dependency package needs to be processed, so as to retain only the target functions required by the front-end project in each target dependency package. In this embodiment, the specific process of processing the target dependency package is not limited, and it depends on the specific implementation situation.
[0086] S14: Generate a dependency vendor file based on the processed target dependency packages, so that the front-end project can introduce various target functions in the dependency vendor file.
[0087] Finally, after obtaining the processed target dependency packages, a dependent vendor (vendors) file is generated based on the processed target dependency packages. It can be understood that the dependent vendors file is a file generated after packaging each target dependency package. After the dependent vendors file is generated, the front-end project can download the dependent vendors file to the local computer, and further introduce the target function corresponding to the target dependency package in the dependent vendors file, thereby completing the dependent installation. In this embodiment, there is no restriction on the way the front-end project introduces the target function, which depends on the specific implementation situation.
[0088] In this embodiment, a large number of trivial dependency packages are integrated into a dependency vendor file. Compared with the traditional npm tool and node_modules folder management method of dependency packages, this solution can greatly reduce the local disk size occupied by dependency packages when introducing dependency packages in front-end projects. At the same time, in the process of generating dependency vendor files, only the target functions required by the front-end project are retained for each target dependency package, which further reduces the size of the dependency vendor file, reduces the file retrieval overhead of the local development environment, greatly improves the performance of the local development environment, and improves development efficiency.
[0089] Based on the above embodiments, in some embodiments, the dependent packages required by the front-end project are obtained according to the index file, including:
[0090] S111: Obtain and execute dependent package installation commands;
[0091] S112: Determine the names and version numbers of the dependent packages required by the front-end project according to the index file;
[0092] S113: Retrieve and download each dependent package according to its name and version number.
[0093] First, obtain and execute the dependency package installation command, determine the name and version number of each dependency package required by the front-end project according to the index file, and further search and download each dependency package according to the name and version number of each dependency package. It should be noted that in this embodiment, there is no restriction on the source and method of searching and downloading the dependency package.
[0094] In this embodiment, by obtaining and executing the dependency package installation command, determining the name and version number of each dependency package required for the front-end project according to the index file, and retrieving and downloading each dependency package according to the name and version number of each dependency package, accurate downloading of the dependency package can be achieved.
[0095] Based on the above embodiments, in some embodiments, before searching and downloading each dependent package according to the name and version number of each dependent package, after determining the name and version number of each dependent package required by the front-end project according to the index file, the method further includes:
[0096] S114: De-duplicate each dependent package according to its name and version number.
[0097] S115: Generate a dependency package list based on the names and version numbers of the dependency packages after deduplication processing, so as to facilitate retrieval and download of the dependency packages according to the dependency package list.
[0098] Among them, the hierarchical relationship of each dependent package in the dependent package list is the same.
[0099] Figure 2 A schematic diagram of the traditional dependency relationship of dependency packages provided in an embodiment of the present invention. Figure 2 As shown in the figure, in the traditional dependency relationship of dependency packages, multiple first-level dependency packages (dependency package A, dependency package B, dependency package C and dependency package D) referenced by the front-end project have lower-level dependency packages (dependency package AA, dependency package AB, dependency package BA, ..., dependency package CA), and there are duplications in the lower-level dependency packages; if each dependency package is retrieved and downloaded based on the traditional dependency relationship, the complex hierarchical relationship will undoubtedly increase the retrieval overhead of the local development environment.
[0100] Therefore, this solution specifically performs deduplication processing on each dependent package according to the name and version number of each dependent package, that is, removes duplicate dependent packages from all dependent packages. Further, based on the name and version number of each dependent package after deduplication processing, a dependent package list is generated. Figure 3A schematic diagram of the dependency relationship of dependent packages after deduplication processing provided by an embodiment of the present invention. Figure 3 As shown in the figure, there are no duplicate dependency packages in the dependency list, and each dependency package has the same hierarchical relationship. Retrieving and downloading each dependency package based on the dependency list can effectively reduce the retrieval overhead of the local development environment and improve the efficiency of retrieval and downloading.
[0101] Based on the above embodiments, in some embodiments, each dependent package is retrieved and downloaded according to the name and version number of each dependent package, including:
[0102] S116: Start searching for each dependent package in the dependent package list;
[0103] S117: Determine whether the dependent package in the dependent package list can be retrieved in the local server; if the dependent package can be retrieved in the local server, proceed to step S118; if the dependent package cannot be retrieved in the local server, proceed to step S119;
[0104] S118: Return the supplier file corresponding to the dependent package in the local server to the user's local computer for download;
[0105] S119: searching and downloading the dependent package in the public dependent package management repository according to the name and version number of the dependent package;
[0106] S120: If the dependent package cannot be retrieved in the public dependent package management repository, the downloading of the dependent package is skipped and an alarm message is output.
[0107] In a specific implementation, in order to retrieve and download the dependent packages, the retrieval of each dependent package in the dependent package list is specifically started. It is determined whether the dependent packages in the dependent package list can be retrieved in the local server. It should be noted that there is space for storing dependent packages in the local server, which may contain previously stored dependent packages, so the dependent packages are first obtained from the local server.
[0108] If the dependency package can be retrieved in the local server, the vendors file corresponding to the dependency package in the local server will be returned to the user's local computer for download. If the dependency package cannot be retrieved in the local server, it means that the local server does not contain the dependency package in the dependency package list. It is necessary to retrieve and download the dependency package in the public dependency package management warehouse, that is, the public npm warehouse, according to the name of the dependency package and its version number. It is understandable that the public npm warehouse is a central repository for storing and distributing JavaScript packages in the Node.js ecosystem; it contains a large number of dependency packages that can be used by developers to build and expand applications or projects.
[0109] It should be noted that if the dependency package cannot be retrieved in the public npm repository, the download of the dependency package will be skipped and an alarm message will be output. Based on the alarm message, the user can check the dependency packages required by the front-end project to confirm whether the corresponding dependency packages are really needed; if it is confirmed that the corresponding dependency packages are not needed, the search process will be terminated; if it is confirmed that the corresponding dependency packages are needed, measures need to be taken to re-retrieve and download the corresponding dependency packages to avoid defects in the front-end project due to missing dependency packages.
[0110] In this embodiment, the retrieval and downloading of the dependency packages in the dependency list are implemented through the local server and the public npm repository, so as to facilitate the introduction of the target dependency packages by the front-end project.
[0111] Based on the above embodiments, in some embodiments, each target dependency package introduced by the front-end project code is determined in each dependency package, including:
[0112] S121: Start static scanning of the front-end project code;
[0113] S122: Determine the source of each function in the front-end project code in turn;
[0114] S123: When it is confirmed that the source of the current function is externally introduced, the current function is determined to be a target function;
[0115] S124: Determine the dependency package corresponding to the target function as the target dependency package.
[0116] In order to determine the target dependency packages introduced by the front-end project code, you first need to start a static scan of the front-end project code. During the scanning process, the sources of each function in the front-end project code are determined in turn. It can be understood that each function is specifically embodied as a method or object. When the source of the scanned function is externally introduced, the current function is determined to be the target function, and the dependency package corresponding to the target function is determined to be the target dependency package. In this way, the determination of each target dependency package introduced by the front-end project code is realized.
[0117] Based on the above embodiments, in some embodiments, each target dependency package is processed separately to retain only the target functions required by the front-end project in each target dependency package, including:
[0118] S131: Start static scanning of each target dependent package.
[0119] S132: Delete other functions in each target dependency package except the corresponding target function.
[0120] In order to retain only the target functions required by the front-end project in each target dependency package, in the specific implementation, after the target dependency package is confirmed, a static scan of each target dependency package is started. In the static scan, other functions except the corresponding target functions in each target dependency package are deleted. Take the dependency package for mathematical operations as an example: assuming that the dependency package can provide four functions of addition, addition, multiplication and division, among which addition and addition are required by the front-end project, and multiplication and division are not required by the front-end project, then in this embodiment, the functions of multiplication and division in the dependency package are deleted.
[0121] In this embodiment, a static scan of each target dependency package is started, and other functions except the corresponding target function in each target dependency package are deleted, thereby reducing the file size and saving storage space.
[0122] Based on the above embodiments, in some embodiments, generating a dependent supplier file based on each processed target dependent package includes:
[0123] S141: Generate initial files based on each target dependency package;
[0124] S142: Encapsulate scope for the first-level dependency package in each target dependency package;
[0125] S143: compressing the data in each scope;
[0126] S144: Generate a vendor-dependent file based on the compressed initial file.
[0127] In order to generate the vendors dependency file, after completing the static scan of all target dependency packages, all target dependency packages are put into an initial file, and the scope of the first-level dependency package in each target dependency package is encapsulated so that there will be no naming conflicts in the methods or objects exposed. Furthermore, while ensuring that the names of the exposed methods or objects remain unchanged, the data in each scope is compressed to further reduce the file size and save storage space. Finally, the vendors dependency file is generated based on the compressed initial file.
[0128] It should be noted that in this embodiment, there is no restriction on the way of compressing data in each scope, which depends on the specific implementation situation.
[0129] In this embodiment, an initial file is generated based on each target dependency package; a scope is encapsulated for the first-level dependency package in each target dependency package; the data in each scope is compressed; and a dependent supplier file is generated based on the compressed initial file, thereby realizing the generation of the dependent supplier file to facilitate the introduction of the front-end project.
[0130] Based on the above embodiments, in some embodiments, data in each scope is compressed, including:
[0131] S145: Delete blank characters in the scope data;
[0132] S146: Compresses the internal variables and function names in the scope's data.
[0133] In order to achieve data compression within the scope, in this embodiment, blank characters in the data of the scope are specifically deleted, including deleting space characters and newline characters; at the same time, internal variables and function names in the data of the scope are compressed, and specifically single letters or single letters carrying special symbols are used to name the internal variables and function names, thereby achieving compression of the data in the scope.
[0134] Based on the above embodiments, in some embodiments, the front-end project will rely on the introduction of various target functions in the supplier file, including:
[0135] S151: The front-end project determines the scopes in the dependent vendor file;
[0136] S152: The front-end project introduces the target function under the scope according to the determined scope.
[0137] Figure 4 A schematic diagram of introducing target functions into a front-end project provided by an embodiment of the present invention. Based on the above embodiment, in order to enable the front-end project to smoothly introduce the target functions of each target dependency package, such as Figure 4 As shown, in the specific implementation, the front-end project specifically determines the scopes in the dependent vendors file, and further introduces methods or objects according to the determined scopes, thereby completing the dependent installation.
[0138] In order to facilitate the next front-end project development, based on the above embodiments, in some embodiments, after searching and downloading the dependent package in the public dependent package management warehouse according to the name and version number of the dependent package, it also includes:
[0139] S161: Pack and compress the source code of the dependent package;
[0140] S162: Generate a corresponding supplier file based on the processed dependency package;
[0141] S163: Delete the source code of the dependent package;
[0142] S164: Store the vendor file and its corresponding name and version number in the local server.
[0143] In a specific implementation, after retrieving and downloading the dependent package from the public npm repository according to the name and version number of the dependent package, the dependent package obtained is actually the source code of the dependent package, not the corresponding vendors file. In order to avoid retrieving and downloading the dependent package from the public npm repository again during the next front-end project development, thereby reducing development efficiency, the source code of the dependent package is packaged and compressed in this embodiment. It can be understood that the process of packaging and compressing the source code of the dependent package is the same as the data compression process in the above embodiment, and will not be repeated in this embodiment.
[0144] After further processing, the dependent package generates the corresponding vendors file and deletes the source code of the dependent package, thereby saving storage space. Finally, the vendors file and its corresponding name and version number are stored on the local server to facilitate subsequent retrieval and download of the same dependent package, without repeated retrieval and packaging, which improves the efficiency of front-end project development.
[0145] Based on the above embodiments, in some embodiments, if the dependent package cannot be retrieved in the public dependent package management repository, the method further includes:
[0146] S165: Check the version number of the dependent package, and determine whether the dependent package is a specific version according to the version number of the dependent package; if it is confirmed that the dependent package is a specific version, proceed to step S166;
[0147] S166: Modify the version range of the dependent package, and return to the step of retrieving and downloading the dependent package in the public dependent package management repository according to the name of the dependent package and its version number.
[0148] In a specific implementation, if the dependent package cannot be retrieved in the public npm warehouse, and it is confirmed that the dependent package is indispensable, in order to prevent defects in the front-end project, it is necessary to try to obtain the dependent package again. Specifically, first check the version number of the dependent package, and determine whether the dependent package is a specific version based on the version number of the dependent package; if it is confirmed that the dependent package is a specific version, it is considered that the current version requirements for the dependent package are too strict, resulting in the public npm warehouse not containing the specific version of the dependent package due to version upgrades, and thus the corresponding dependent package cannot be provided. At this time, modify the version range of the dependent package, use a looser version range, and return to the step of retrieving and downloading the dependent package in the public dependent package management warehouse according to the name of the dependent package and its version number, so as to retrieve and download the dependent package again through the public npm warehouse. It should be noted that in this embodiment, there is no restriction on the specific version of the dependent package, which depends on the specific implementation situation.
[0149] If it is confirmed that the dependent package is not a specific version, then the reason for the failure to retrieve the dependent package may not be related to the version number; possible reasons include that the current version of the dependent package has not been published to the public npm repository, or there is a problem during the publishing process; it may also be that the dependent package in the public npm repository is a third-party image, which cannot be retrieved and downloaded. In the above cases, you can choose to contact the developer of the dependent package to obtain the corresponding dependent package, or switch to the official image of the developer of the dependent package, so as to finally obtain the dependent package to avoid affecting the development of the front-end project.
[0150] Based on the above embodiments, in some embodiments, the following further includes:
[0151] S15: Get the dependent package editing command;
[0152] S16: Edit the index file based on the dependency package editing command to add and / or delete and / or modify the dependency packages required by the front-end project.
[0153] In a specific implementation, when the user needs to modify the required dependency, the user can obtain the dependency package editing command and edit the index file based on the dependency package editing command, including adding dependency packages and / or deleting dependency packages and / or modifying the version of the dependency package, and then upload the modified index file and repeat the steps of the above embodiment to complete the dependency modification.
[0154] In the above embodiment, the dependent package introduction method is described in detail, and the present invention further provides a computer program product, including a computer program / instruction. When the computer program / instruction is executed by a processor, the steps of the dependent package introduction method are implemented.
[0155] Since the embodiments of the product part correspond to the embodiments of the method part, please refer to the description of the embodiments of the method part for the embodiments of the product part, which will not be repeated here.
[0156] In addition, the present invention also provides a dependent package introduction device. Figure 5 A schematic diagram of a dependency package import device provided by an embodiment of the present invention. Figure 5 As shown, the device comprises:
[0157] Initialization module 10, used to initialize the front-end project and generate the front-end project code and index file; wherein the index file contains the information of each dependent package required by the front-end project;
[0158] The acquisition module 11 is used to obtain the dependent packages required by the front-end project according to the index file;
[0159] A determination module 12 is used to determine each target dependency package introduced by the front-end project code in each dependency package;
[0160] The processing module 13 is used to process each target dependency package respectively to retain only the target functions required by the front-end project in each target dependency package;
[0161] The generation module 14 is used to generate a dependency supplier file based on the processed target dependency packages, so that the front-end project can introduce various target functions in the dependency supplier file.
[0162] In some embodiments, the acquisition module 11 includes:
[0163] The first acquisition submodule is used to obtain and execute the dependent package installation command;
[0164] The first determination submodule is used to determine the names and version numbers of the dependent packages required by the front-end project according to the index file;
[0165] The first search and download submodule is used to search and download each dependent package according to the name and version number of each dependent package.
[0166] In some embodiments, it also includes:
[0167] The deduplication submodule is used to deduplicate each dependent package according to its name and version number;
[0168] The first generation submodule is used to generate a dependency package list based on the name and version number of each dependency package after deduplication processing, so as to facilitate retrieval and download of each dependency package according to the dependency package list;
[0169] Among them, the hierarchical relationship of each dependent package in the dependent package list is the same.
[0170] In some embodiments, the first retrieval download submodule includes:
[0171] A first starter module is used to start searching for each dependent package in the dependent package list;
[0172] The first judgment submodule is used to judge whether the dependent package in the dependent package list can be retrieved in the local server; if the dependent package can be retrieved in the local server, the first download submodule is triggered; if the dependent package cannot be retrieved in the local server, the second download submodule is triggered;
[0173] The first download submodule is used to return the supplier file corresponding to the dependent package in the local server to the user's local computer for download;
[0174] The second download submodule is used to retrieve and download the dependent package in the public dependent package management warehouse according to the name and version number of the dependent package;
[0175] The alarm submodule is used to skip downloading the dependency package and output an alarm message if the dependency package cannot be retrieved in the public dependency package management repository.
[0176] In some embodiments, the determination module 12 includes:
[0177] The second starter module is used to start a static scan of the front-end project code;
[0178] The second determination submodule is used to sequentially determine the source of each function in the front-end project code;
[0179] A third determination submodule is used to determine the current function as a target function when it is confirmed that the source of the current function is externally introduced;
[0180] The fourth determination submodule is used to determine that the dependency package corresponding to the target function is the target dependency package.
[0181] In some embodiments, the processing module 13 includes:
[0182] The third starter module is used to start static scanning of each target dependency package;
[0183] The first deletion submodule is used to delete other functions in each target dependency package except the corresponding target function.
[0184] In some embodiments, the generating module 14 includes:
[0185] The second generation submodule is used to generate initial files based on each target dependency package;
[0186] The encapsulation submodule is used to encapsulate the scope of the first-level dependency package in each target dependency package;
[0187] A first compression submodule, used for compressing data in each scope;
[0188] The third generation submodule is used to generate a dependent supplier file based on the compressed initial file.
[0189] In some embodiments, the first compression submodule includes:
[0190] The second deletion submodule is used to delete blank characters in the data of the scope;
[0191] The second compression submodule is used to compress internal variables and function names in the scoped data.
[0192] In some embodiments, the front-end project will introduce various target functions in the dependency supplier file. Specifically, the front-end project determines the various scopes in the dependency supplier file, and introduces the target functions under the scope according to the determined scope.
[0193] In some embodiments, it also includes:
[0194] The third compression submodule is used to package and compress the source code of the dependent package;
[0195] The fourth generation submodule is used to generate a corresponding supplier file based on the processed dependency package;
[0196] The third is to delete the submodule, which is used to delete the source code of the dependent package;
[0197] The first storage submodule is used to store the supplier file and its corresponding name and version number in the local server.
[0198] In some embodiments, it also includes:
[0199] The second judgment submodule is used to check the version number of the dependent package and determine whether the dependent package is a specific version according to the version number of the dependent package; if it is confirmed that the dependent package is a specific version, the modification submodule is triggered;
[0200] The modification submodule is used to modify the version range of the dependent package, and returns to the step of retrieving and downloading the dependent package in the public dependent package management repository according to the name of the dependent package and its version number.
[0201] In some embodiments, it also includes:
[0202] The second acquisition submodule is used to obtain the dependent package editing command;
[0203] The editing submodule is used to edit the index file based on the dependency package editing command to add and / or delete and / or modify the dependency packages required by the front-end project.
[0204] Figure 6 A schematic diagram of a device for importing dependency packages provided by an embodiment of the present invention. Figure 6 As shown, the dependent packages introduced into the device include:
[0205] A memory 20, used for storing computer programs;
[0206] The processor 21 is used to implement the steps of the dependency package importing method mentioned in the above embodiment when executing the computer program.
[0207] The dependency package introduction device provided in this embodiment may include but is not limited to a smart phone, a tablet computer, a laptop computer, or a desktop computer.
[0208] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 can be implemented in at least one hardware form of a digital signal processor (DSP), a field programmable gate array (FPGA), and a programmable logic array (PLA). The processor 21 may also include a main processor and a coprocessor. The main processor is a processor for processing data in an awake state, also known as a central processing unit (CPU); the coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 21 may be integrated with a graphics processing unit (GPU), and the GPU is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may also include an artificial intelligence (AI) processor, which is used to process computing operations related to machine learning.
[0209] The memory 20 may include one or more computer-readable storage media, which may be non-transitory. The memory 20 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 20 is at least used to store the following computer program 201, wherein, after the computer program is loaded and executed by the processor 21, it can implement the relevant steps of the dependency package introduction method disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory 20 may also include an operating system 202 and data 203, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 202 may include Windows, Unix, Linux, etc. Data 203 may include but is not limited to data involved in the dependency package introduction method.
[0210] In some embodiments, the dependency package importing device may also include a display screen 22 , an input and output interface 23 , a communication interface 24 , a power supply 25 , and a communication bus 26 .
[0211] Those skilled in the art will understand that Figure 6 The structure shown in does not constitute a limitation on the dependent package introduction device and may include more or fewer components than shown in the figure.
[0212] Finally, the present invention also provides an embodiment corresponding to a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps recorded in the above method embodiment are implemented.
[0213] It is understandable that if the method in the above embodiment is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium to execute all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc. Various media that can store program codes.
[0214] The above is a detailed introduction to a dependency package introduction method, product, device and medium provided by the present invention. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the embodiments can refer to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can refer to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principle of the present invention, several improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the scope of protection of the present invention.
[0215] It should also be noted that, in this specification, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
Claims
1. A method for introducing dependent packages, It is characterized in that include: Initialize the front-end project and generate the front-end project code and index file; wherein the index file contains the information of each dependent package required by the front-end project; Obtain the dependency packages required for the front-end project according to the index file; Determine each target dependency package introduced by the front-end project code in each dependency package; Processing each of the target dependency packages respectively to retain only the target functions required by the front-end project in each of the target dependency packages; Generate a dependent supplier file based on the processed target dependent packages, so that the front-end project can introduce each target function in the dependent supplier file; The step of generating a dependent supplier file based on each of the processed target dependent packages includes: Generate an initial file based on each of the target dependency packages; Encapsulating scope for the first-level dependency package in each of the target dependency packages; Compressing the data in each of the scopes, specifically deleting blank characters in the data in the scopes, and compressing internal variables and function names in the data in the scopes; The dependent supplier file is generated based on the compressed initial file.
2. The method for introducing a dependency package according to claim 1, It is characterized in that The step of obtaining the dependent packages required for the front-end project according to the index file includes: Get and execute the dependent package installation command; Determine the name and version number of each dependent package required for the front-end project according to the index file; Each dependent package is retrieved and downloaded according to its name and version number.
3. The method for introducing a dependency package according to claim 2, It is characterized in that Before retrieving and downloading each of the dependent packages according to the name and version number of each of the dependent packages, and after determining the name and version number of each of the dependent packages required for the front-end project according to the index file, the method further includes: Deduplication processing is performed on each of the dependent packages according to the name and version number of each dependent package; Generate a dependency package list based on the name and version number of each dependency package after deduplication processing, so as to facilitate retrieval and download of each dependency package according to the dependency package list; Among them, the hierarchical relationship of each dependent package in the dependent package list is the same.
4. The method for introducing a dependency package according to claim 3, It is characterized in that The retrieving and downloading each dependent package according to the name and version number of each dependent package includes: Initiate retrieval of each dependent package in the dependent package list; Determine whether the dependent package in the dependent package list can be retrieved in the local server; If the dependent package can be retrieved in the local server, the supplier file corresponding to the dependent package in the local server is returned to the user's local computer for download; If the dependent package cannot be retrieved in the local server, the dependent package is retrieved and downloaded from the public dependent package management warehouse according to the name and version number of the dependent package; If the dependent package cannot be retrieved in the public dependent package management repository, the downloading of the dependent package is skipped and a warning message is output.
5. The method for introducing a dependency package according to claim 1, It is characterized in that Determining each target dependency package introduced by the front-end project code in each dependency package includes: Initiate a static scan of the front-end project code; Determine the source of each function in the front-end project code in turn; When it is confirmed that the source of the current function is introduced externally, the current function is determined to be the target function; Determine that the dependency package corresponding to the target function is the target dependency package.
6. The method for introducing a dependency package according to claim 5, It is characterized in that The processing of each of the target dependency packages respectively to retain only the target functions required by the front-end project in each of the target dependency packages includes: Initiate static scanning of each target dependency package; Delete all functions in the target dependency packages except the corresponding target function.
7. The method for introducing a dependency package according to claim 1, It is characterized in that The front-end project introduces each of the target functions in the dependent vendor file, including: The front-end project determines each of the scopes in the dependent supplier file; The front-end project introduces the target function under the scope according to the determined scope.
8. The method for introducing a dependency package according to claim 4, It is characterized in that After retrieving and downloading the dependent package in the public dependent package management warehouse according to the name and version number of the dependent package, the method further includes: Packing and compressing the source code of the dependent package; Generate a corresponding supplier file based on the processed dependency package; Delete the source code of the dependent package; The vendor files and their corresponding names and version numbers are stored on a local server.
9. The method for introducing a dependency package according to claim 4, It is characterized in that If the dependency package cannot be retrieved in the public dependency package management repository, the following also includes: Checking the version number of the dependent package, and determining whether the dependent package is a specific version according to the version number of the dependent package; If it is confirmed that the dependent package is a specific version, the version range of the dependent package is modified, and the process returns to the step of retrieving and downloading the dependent package in the public dependent package management repository according to the name of the dependent package and its version number.
10. The method for importing a dependency package according to any one of claims 1 to 9, It is characterized in that Also includes: Get the dependency package editing command; The index file is edited based on the dependency package editing command to add and / or delete and / or modify the dependency packages required by the front-end project.
11. A computer program product comprising a computer program / instructions, It is characterized in that When the computer program / instruction is executed by a processor, the steps of the dependent package importing method described in any one of claims 1 to 10 are implemented.
12. A dependency package is introduced into the device, It is characterized in that include: Memory for storing computer programs; A processor, used to implement the steps of the dependent package importing method as described in any one of claims 1 to 10 when executing the computer program.
13. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the dependent package importing method according to any one of claims 1 to 10 are implemented.
