Dependent loading method and device for NodeJS environment, equipment and medium

Through event hooks, merging dependency configuration items and dynamically installing third-party packages, the compatibility problem of NodeJS module in different version environments is solved, simplifying operations and improving adaptation efficiency.

CN119003033APending Publication Date: 2024-11-22SHENZHEN LEXIN SOFTWARE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411107250.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-13
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

During the development of NodeJS module, when different version branches are required, static installation of the specified version of third-party dependency packages leads to complex operations and inefficient compatibility adaptation.

Method used

Use the event hook to obtain the current dependency configuration file of the NodeJS module to be loaded, merge the default dependency configuration items and the current version dependency configuration items, dynamically install the third-party dependency package, update the NodeJS module to be loaded, and realize the third-party dependency package loading of the NodeJS running environment.

Benefits of technology

Simplifies the operation process, improves the efficiency of version compatibility, and makes developments not need to consider the operating environment. Dynamic installation of dependency packages improves module compatibility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119003033A_ABST
    Figure CN119003033A_ABST
Patent Text Reader

Abstract

The invention discloses a dependent loading method and device for a NodeJS environment, equipment and a medium. The method comprises the following steps: acquiring a NodeJS module to be loaded and an event hook; obtaining a current dependency configuration file in the NodeJS module to be loaded through the event hook, obtaining a default dependency configuration item from the current dependency configuration file, and obtaining a current version dependency configuration item from the current dependency configuration file through the event hook; merging the default dependency configuration item and the current version dependency configuration item to obtain a merged configuration item; the event hook is updated to the NodeJS module to be loaded, and the event hook is deleted, so that the NodeJS module to be loaded is updated and executed, and third-party dependent package loading is completed. According to the embodiment of the invention, the operation environment does not need to be considered when the NodeJS module is developed, and the third-party dependency package of the corresponding version is dynamically installed according to the operation environment when the NodeJS module is installed, so that the operation process is simplified, and the version compatibility efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of backend development, and in particular to a dependency loading method, device, equipment and medium in a NodeJS environment. Background Art

[0002] Node.JS is an open source, cross-platform JavaScript runtime environment, and it has released multiple versions. Due to the differences in the features of each Node.JS version, when developing each version of a Node.JS module and relying on an external third-party dependency package, the general operation is to statically install a specified version of the dependency package to ensure that the current development environment can run normally. When the developed Node.JS module needs to run in more version environments, if the dependent third-party dependency package is not supported, the application cannot run in the Node.JS module. That is, when the developed Node.JS module needs to maintain different version branches, it is also necessary to statically install the specified version of the third-party dependency package according to the corresponding operating environment of the Node.JS module, and then release the version after verification. The above process is achieved by manually statically installing the specified version of the third-party dependency package, which not only makes the operation complicated, but also leads to low compatibility adaptation efficiency of the Node.JS module. Summary of the invention

[0003] The embodiments of the present invention provide a dependency loading method, device, equipment and medium for a NodeJS environment, aiming to solve the problem in the prior art that when a developed Node.JS module needs to maintain different version branches, a third-party dependency package of a specified version needs to be statically installed according to the operating environment corresponding to the Node.JS module. Manually statically installing the third-party dependency package of a specified version not only leads to complicated operations, but also leads to low compatibility adaptation efficiency of the Node.JS module.

[0004] In a first aspect, an embodiment of the present invention provides a method for loading dependencies in a NodeJS environment, which includes:

[0005] In response to a NodeJS module loading instruction, obtaining a NodeJS module to be loaded and an event hook corresponding to the NodeJS module loading instruction;

[0006] Obtaining the current dependency configuration file in the NodeJS module to be loaded through the event hook, obtaining the default dependency configuration item from the current dependency configuration file, and obtaining the current version dependency configuration item from the current dependency configuration file through the event hook;

[0007] Merging the default dependency configuration item and the current version dependency configuration item to obtain a merged configuration item;

[0008] Updating the merged configuration item into the NodeJS module to be loaded and deleting the event hook to update the NodeJS module to be loaded;

[0009] The third-party dependency package loading of the NodeJS operating environment is completed by executing the merged configuration item in the NodeJS module to be loaded.

[0010] In a second aspect, an embodiment of the present invention further provides a dependency loading device for a NodeJS environment, which includes:

[0011] An event hook acquisition unit, configured to respond to a NodeJS module loading instruction and acquire a NodeJS module to be loaded and an event hook corresponding to the NodeJS module loading instruction;

[0012] A configuration item acquisition unit, used to acquire the current dependency configuration file in the NodeJS module to be loaded through the event hook, acquire the default dependency configuration item from the current dependency configuration file, and acquire the current version dependency configuration item from the current dependency configuration file through the event hook;

[0013] A configuration item merging unit, used to merge the default dependency configuration item and the current version dependency configuration item to obtain a merged configuration item;

[0014] An updating unit, configured to update the merged configuration item into the NodeJS module to be loaded and delete the event hook, so as to update the NodeJS module to be loaded;

[0015] The execution control unit is used to complete the loading of the third-party dependency package of the NodeJS operating environment by executing the merged configuration items in the NodeJS module to be loaded.

[0016] In a third aspect, an embodiment of the present invention further provides a computer device, which includes a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the method described in the first aspect is implemented.

[0017] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the method described in the first aspect above can be implemented.

[0018] The embodiment of the present invention provides a dependency loading method, device, equipment and medium of a NodeJS environment, the method comprising: in response to a NodeJS module loading instruction, obtaining a NodeJS module to be loaded and an event hook corresponding to the NodeJS module loading instruction; obtaining a current dependency configuration file in the NodeJS module to be loaded through an event hook, and obtaining a default dependency configuration item from the current dependency configuration file; obtaining a current version dependency configuration item corresponding to the NodeJS module to be loaded through an event hook; merging the default dependency configuration item and the current version dependency configuration item to obtain a merged configuration item; updating the merged configuration item to the NodeJS module to be loaded and deleting the event hook to update the NodeJS module to be loaded; and completing the loading of a third-party dependency package of the NodeJS operating environment by executing the NodeJS module to be loaded. The embodiment of the present invention realizes that there is no need to consider the operating environment when developing the NodeJS module, and the corresponding version of the third-party dependency package is dynamically installed according to the operating environment when the NodeJS module is installed, which not only simplifies the operation process, but also improves the efficiency of version compatibility. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.

[0020] Figure 1 A schematic diagram of an application scenario of a dependency loading method for a NodeJS environment provided by an embodiment of the present invention;

[0021] Figure 2 A schematic diagram of a flow chart of a method for loading dependencies in a NodeJS environment provided by an embodiment of the present invention;

[0022] Figure 3 A schematic diagram of a sub-process of a method for loading dependencies in a NodeJS environment provided by an embodiment of the present invention;

[0023] Figure 4 Another sub-flow diagram of the dependency loading method of the NodeJS environment provided by an embodiment of the present invention;

[0024] Figure 5 A schematic block diagram of a dependency loading device for a NodeJS environment provided by an embodiment of the present invention;

[0025] Figure 6 A schematic block diagram of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0026] 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 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.

[0027] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.

[0028] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0029] It should be further understood that the term "and / or" used in the present description and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0030] Please also refer to Figure 1 and Figure 2 ,in Figure 1 This is a schematic diagram of a scenario of a method for loading dependencies in a NodeJS environment according to an embodiment of the present invention. Figure 2 Schematic diagram of the process of the dependency loading method of the NodeJS environment provided by the embodiment of the present invention. Figure 1 As shown, the dependency loading method of the NodeJS environment provided in the embodiment of the present invention is applied to the server 10 , and the NodeJS module published in the server 10 can be sent to the user terminal 20 that is communicatively connected to the server 10 .

[0031] like Figure 2 As shown, the method includes the following steps S110-S150.

[0032] S110. In response to a NodeJS module loading instruction, obtain a to-be-loaded NodeJS module and an event hook corresponding to the NodeJS module loading instruction.

[0033] In this embodiment, the technical solution is described with the server as the execution subject. When the developer develops and loads the NodeJS module on the server, the back-end device, he first manually selects the NodeJS module to be loaded on the interactive interface or automatically selects the NodeJS module to be loaded by the preset script, and then obtains the event hook pre-configured in the NodeJS module to be loaded. The function of the event hook is to dynamically install the third-party dependency package according to the operating environment of the NodeJS module to be loaded when the NodeJS module to be loaded is installed, so as to solve the version compatibility problem of the NodeJS module to be loaded.

[0034] Among them, the NodeJS module to be loaded will be released in the form of an NPM package (the full name of NPM is Node Package Manager, which means Node package manager). The configured event hook can be regarded as an installation pre-script defined by the preinstall field, and the event hook is set in the package.json file of the NPM package.

[0035] In one embodiment, before step S110, the method further includes:

[0036] The NodeJS module to be loaded and the event hook configuration item in the NodeJS module to be loaded are obtained, and the event hook is started based on the event hook configuration item.

[0037] In this embodiment, the package configuration file (i.e., package.json file) of the NodeJS module to be loaded includes at least a script configuration item (i.e., Scripts configuration item), and the event hook configuration item is configured in the script configuration item. When the NodeJS module to be loaded is selected for installation, the event hook configuration item in the NodeJS module to be loaded is first obtained to start the event hook based on the event hook configuration item. Afterwards, the event hook dynamically installs the third-party dependency package according to the operating environment of the NodeJS module to be loaded.

[0038] S120. Obtain the current dependency configuration file in the NodeJS module to be loaded through the event hook, obtain the default dependency configuration item from the current dependency configuration file, and obtain the current version dependency configuration item from the current dependency configuration file through the event hook.

[0039] In this embodiment, when the event hook is started, the current dependency configuration file in the NodeJS module to be loaded is first obtained. In addition to the default dependency configuration items, the current dependency configuration file also includes the current version dependency configuration items corresponding to the current NodeJS operating environment (there are two corresponding cases, one is that the current version dependency configuration item exists, that is, it is not an empty object, and the other is that the current version dependency configuration item does not exist, that is, it is an empty object). After the event hook obtains the current dependency configuration file, the default dependency configuration item can be directly obtained from it, so as to obtain the third-party dependency package of the specified default version based on the default dependency configuration item.

[0040] In one embodiment, if Figure 3 As shown, step S120 includes:

[0041] S121, obtaining an event hook script corresponding to the event hook;

[0042] S122. Obtain the current dependency configuration file from the NodeJS module to be loaded based on the event hook script.

[0043] In this embodiment, when the event hook script corresponding to the event hook is obtained in the backend device of the server, and the event hook script is first used as a dependency processing program; then the current dependency configuration file is automatically obtained from multiple files in the NodeJS module to be loaded based on the execution of the dependency processing program; then the dependency processing program obtains the current dependency-related configuration items in the current dependency configuration file, such as the production environment dependency configuration items, for the final automatic installation of the dependency configuration. Of course, the current dependency-related configuration items obtained at this time have not been used for execution to perform dependency configuration, and the current version dependency configuration items are required to be subsequently.

[0044] The event hook can also be understood as a pre-loading event hook in the NodeJS module to be loaded. Because its function is to dynamically install third-party dependency packages according to the operating environment of the NodeJS module to be loaded, it also needs to obtain the current version dependency configuration items corresponding to the NodeJS module to be loaded, and combine it with the default dependency configuration items obtained previously to jointly determine the dynamic installation of third-party dependency packages.

[0045] In one embodiment, if Figure 3 As shown, after step S122 in step S120, the following steps are further included:

[0046] S123. Based on the event hook script, obtain the current NodeJS version of the running environment corresponding to the NodeJS module to be loaded, and obtain the current version dependency configuration item corresponding to the current NodeJS version.

[0047] In this embodiment, the event hook script is used to obtain the operating environment corresponding to the NodeJS module to be loaded, so as to obtain the current NodeJS version based on the current operating environment. Since the version dependency configuration items corresponding to multiple NodeJS versions are also pre-stored in the server, after the current NodeJS version is determined, the current version dependency configuration item corresponding to the current NodeJS version can be determined accordingly. It can be seen that based on the automatic execution of the event hook script, the automatic and accurate acquisition of the current version dependency configuration item is achieved.

[0048] S130: Merge the default dependency configuration item and the current version dependency configuration item to obtain a merged configuration item.

[0049] In this embodiment, after obtaining the default dependency configuration item and the current version dependency configuration item corresponding to the NodeJS module to be loaded in the backend device (i.e., the server), the two need to be merged to obtain a merged configuration item obtained after the merging process. Of course, the above merging process is not a simple combination of the data of the two dependency configuration items, but needs to be processed according to certain preset rules.

[0050] In one embodiment, as a first embodiment of step S130, as Figure 4 As shown, step S130 includes:

[0051] S131. If it is determined that the current version dependency configuration item is not an empty object, obtain the current version production environment dependency configuration item, the current version development environment dependency configuration item, the current version execution script configuration item, and the current version installation instruction configuration item corresponding to the current version dependency configuration item;

[0052] S132, obtaining a default production environment dependency configuration item, a default development environment dependency configuration item, a default execution script configuration item, and a default installation instruction configuration item corresponding to the default dependency configuration item;

[0053] S133. Merge the current version production environment dependency configuration item with the default production environment dependency configuration item, merge the current version development environment dependency configuration item with the default development environment dependency configuration item, merge the current version execution script configuration item with the default execution script configuration item, and merge the current version installation instruction configuration item with the default installation instruction configuration item to form the merged configuration item.

[0054] In this embodiment, as the first embodiment of step S130, when it is determined that the current version dependency configuration item is not an empty object, it means that the current version dependency configuration item corresponding to the current NodeJS version is obtained from the version dependency configuration items corresponding to multiple NodeJS versions pre-stored in the server. At this time, the current version dependency configuration item needs to be obtained by event hook parsing to at least obtain the current version production environment dependency configuration item, the current version development environment dependency configuration item, the current version execution script configuration item and the current version installation instruction configuration item included therein.

[0055] Similarly, the default dependency configuration items need to be obtained by event hook parsing to obtain at least the default production environment dependency configuration items, the default development environment dependency configuration items, the default execution script configuration items and the default installation instruction configuration items included therein.

[0056] After completing the acquisition of detailed configuration information of the above two dependency configuration items, finally, according to the preset rules, the current version production environment dependency configuration item and the default production environment dependency configuration item are merged to obtain the first merged configuration item, the current version development environment dependency configuration item and the default development environment dependency configuration item are merged to obtain the second merged configuration item, the current version execution script configuration item and the default execution script configuration item are merged to obtain the third merged configuration item, and the current version installation instruction configuration item and the default installation instruction configuration item are merged to obtain the fourth merged configuration item, so that the merged configuration item is composed of the above four merged configuration items (i.e., the first merged configuration item-the fourth merged configuration item). It can be seen that the automatic merging of the default dependency configuration item and the current version dependency configuration item is realized based on the event hook, and a merged configuration item that can obtain multi-version third-party dependency packages to improve the version compatibility of the NodeJS module to be loaded is obtained.

[0057] In one embodiment, as a second embodiment of step S130, step S130 includes:

[0058] If it is determined that the current version dependency configuration item is an empty object, the default production environment dependency configuration item, the default development environment dependency configuration item, the default execution script configuration item and the default installation instruction configuration item corresponding to the default dependency configuration item are obtained and constitute the merged configuration item.

[0059] In this embodiment, as the second embodiment of step S130, when it is determined that the current version dependency configuration item is an empty object, one of the reasons is that the current NodeJS version of the operating environment corresponding to the NodeJS module to be loaded is the same as the NodeJS version corresponding to the NodeJS module to be loaded, and there is no need to obtain the current version dependency configuration item corresponding to the current NodeJS version from the version dependency configuration items corresponding to the multiple NodeJS versions pre-stored in the server; another reason is that the current version dependency configuration item corresponding to the current NodeJS version is not obtained from the version dependency configuration items corresponding to the multiple NodeJS versions pre-stored in the server. However, as long as it is determined that the current version dependency configuration item is an empty object, the default production environment dependency configuration item, the default development environment dependency configuration item, the default execution script configuration item and the default installation instruction configuration item included in the default dependency configuration item are directly used to form the merged configuration item. It can be seen that based on the event hook, at least the default dependency configuration item is used as a non-empty configuration item to obtain a third-party dependency package that is compatible with the current NodeJS version.

[0060] S140: Update the merged configuration item into the NodeJS module to be loaded and delete the event hook to update the NodeJS module to be loaded.

[0061] In this embodiment, after the merged configuration item is obtained, its ultimate goal is to be updated to the current dependency configuration file in the NodeJS module to be loaded. After completing the above process of updating the current dependency configuration file, the event hook needs to be deleted to avoid the impact of the event hook on the installation process of the third-party dependency package. After completing the above two processes, the updated NodeJS module to be loaded can be obtained.

[0062] S150: Complete the loading of the third-party dependency package of the NodeJS operating environment by executing the merged configuration item in the NodeJS module to be loaded.

[0063] In this embodiment, the obtained merged configuration item is mainly used for automatic execution, thereby completing the dynamic installation of the third-party dependency package corresponding to the current operating environment of the NodeJS module to be loaded, without suspending other operations before installing the NodeJS module to be loaded to statically install the third-party dependency package. By automatically executing the merged configuration item, the third-party dependency package loading of the NodeJS operating environment can be completed.

[0064] In one embodiment, step S150 includes:

[0065] The operation of the merged configuration item in the NodeJS module to be loaded is triggered based on the installation instruction configuration item in the NodeJS module to be loaded, so as to complete the loading of the third-party dependency package of the NodeJS operating environment.

[0066] In this embodiment, since the installation instruction configuration item is also encapsulated in the NodeJS module to be loaded, the installation instruction configuration item can trigger the generation of the installation instruction, so that the installation instruction triggers the automatic operation of the merged configuration item in the NodeJS module to be loaded, so as to complete the dynamic installation of the third-party dependency package of the NodeJS operating environment. After that, other configuration items in the NodeJS module to be loaded are executed to finally complete the complete installation of the entire NodeJS module to be loaded.

[0067] It can be seen that the implementation example of the method realizes that there is no need to consider the operating environment when developing the NodeJS module. When the NodeJS module is installed, the corresponding version of the third-party dependency package is dynamically installed according to the operating environment, which not only simplifies the operation process, but also improves the efficiency of version compatibility.

[0068] Figure 5 Schematic diagram of a NodeJS environment dependency loading device provided by an embodiment of the present invention. Figure 5 As shown, corresponding to the above NodeJS environment dependency loading method, the present invention also provides a NodeJS environment dependency loading device 100. The NodeJS environment dependency loading device 100 includes a unit for executing the above NodeJS environment dependency loading method. Figure 5 The dependency loading device 100 of the NodeJS environment includes: an event hook acquisition unit 110, a configuration item acquisition unit 120, a configuration item merging unit 130, an updating unit 140 and an execution control unit 150.

[0069] The event hook acquisition unit 110 is used to respond to a NodeJS module loading instruction and acquire a NodeJS module to be loaded and an event hook corresponding to the NodeJS module loading instruction.

[0070] In this embodiment, the technical solution is described with the server as the execution subject. When the developer develops and loads the NodeJS module on the server, the back-end device, he first manually selects the NodeJS module to be loaded on the interactive interface or automatically selects the NodeJS module to be loaded by the preset script, and then obtains the event hook pre-configured in the NodeJS module to be loaded. The function of the event hook is to dynamically install the third-party dependency package according to the operating environment of the NodeJS module to be loaded when the NodeJS module to be loaded is installed, so as to solve the version compatibility problem of the NodeJS module to be loaded.

[0071] Among them, the NodeJS module to be loaded will be released in the form of an NPM package (the full name of NPM is Node Package Manager, which means Node package manager). The configured event hook can be regarded as an installation pre-script defined by the preinstall field, and the event hook is set in the package.json file of the NPM package.

[0072] In one embodiment, the dependency loading device 100 of the NodeJS environment further includes:

[0073] The event hook starting unit is used to obtain the NodeJS module to be loaded and the event hook configuration item in the NodeJS module to be loaded, and start the event hook based on the event hook configuration item.

[0074] In this embodiment, the package configuration file (i.e., package.json file) of the NodeJS module to be loaded includes at least a script configuration item (i.e., Scripts configuration item), and the event hook configuration item is configured in the script configuration item. When the NodeJS module to be loaded is selected for installation, the event hook configuration item in the NodeJS module to be loaded is first obtained to start the event hook based on the event hook configuration item. Afterwards, the event hook dynamically installs the third-party dependency package according to the operating environment of the NodeJS module to be loaded.

[0075] The configuration item acquisition unit 120 is used to obtain the current dependency configuration file in the NodeJS module to be loaded through the event hook, obtain the default dependency configuration item from the current dependency configuration file, and obtain the current version dependency configuration item from the current dependency configuration file through the event hook.

[0076] In this embodiment, when the event hook is started, the current dependency configuration file in the NodeJS module to be loaded is first obtained. In addition to the default dependency configuration items, the current dependency configuration file also includes the current version dependency configuration items corresponding to the current NodeJS operating environment (there are two corresponding cases, one is that the current version dependency configuration item exists, that is, it is not an empty object, and the other is that the current version dependency configuration item does not exist, that is, it is an empty object). After the event hook obtains the current dependency configuration file, the default dependency configuration item can be directly obtained from it, so as to obtain the third-party dependency package of the specified default version based on the default dependency configuration item.

[0077] In one embodiment, the configuration item acquisition unit 120 is used to:

[0078] Obtaining the event hook script corresponding to the event hook;

[0079] The current dependency configuration file is obtained from the NodeJS module to be loaded based on the event hook script.

[0080] In this embodiment, when the event hook script corresponding to the event hook is obtained in the backend device of the server, and the event hook script is first used as a dependency processing program; then the current dependency configuration file is automatically obtained from multiple files in the NodeJS module to be loaded based on the execution of the dependency processing program; then the dependency processing program obtains the current dependency-related configuration items in the current dependency configuration file, such as the production environment dependency configuration items, for the final automatic installation of the dependency configuration. Of course, the current dependency-related configuration items obtained at this time have not been used for execution to perform dependency configuration, and the current version dependency configuration items are required to be subsequently.

[0081] The event hook can also be understood as a pre-loading event hook in the NodeJS module to be loaded. Because its function is to dynamically install third-party dependency packages according to the operating environment of the NodeJS module to be loaded, it also needs to obtain the current version dependency configuration items corresponding to the NodeJS module to be loaded, and combine it with the default dependency configuration items obtained previously to jointly determine the dynamic installation of third-party dependency packages.

[0082] In one embodiment, the configuration item obtaining unit 120 is further configured to:

[0083] Based on the event hook script, the current NodeJS version of the running environment corresponding to the NodeJS module to be loaded is obtained, and the current version dependency configuration item corresponding to the current NodeJS version is obtained.

[0084] In this embodiment, the event hook script is used to obtain the operating environment corresponding to the NodeJS module to be loaded, so as to obtain the current NodeJS version based on the current operating environment. Since the version dependency configuration items corresponding to multiple NodeJS versions are also pre-stored in the server, after the current NodeJS version is determined, the current version dependency configuration item corresponding to the current NodeJS version can be determined accordingly. It can be seen that based on the automatic execution of the event hook script, the automatic and accurate acquisition of the current version dependency configuration item is achieved.

[0085] The configuration item merging unit 130 is used to merge the default dependency configuration item and the current version dependency configuration item to obtain a merged configuration item.

[0086] In this embodiment, after obtaining the default dependency configuration item and the current version dependency configuration item corresponding to the NodeJS module to be loaded in the backend device (i.e., the server), the two need to be merged to obtain a merged configuration item obtained after the merging process. Of course, the above merging process is not a simple combination of the data of the two dependency configuration items, but needs to be processed according to certain preset rules.

[0087] In one embodiment, as a first embodiment of the configuration item merging unit 130, the configuration item merging unit 130 is used to:

[0088] If it is determined that the current version dependency configuration item is not an empty object, then obtain the current version production environment dependency configuration item, the current version development environment dependency configuration item, the current version execution script configuration item and the current version installation instruction configuration item corresponding to the current version dependency configuration item;

[0089] Obtain the default production environment dependency configuration item, the default development environment dependency configuration item, the default execution script configuration item, and the default installation instruction configuration item corresponding to the default dependency configuration item;

[0090] Merge the current version production environment dependency configuration item with the default production environment dependency configuration item, merge the current version development environment dependency configuration item with the default development environment dependency configuration item, merge the current version execution script configuration item with the default execution script configuration item, and merge the current version installation instruction configuration item with the default installation instruction configuration item to form the merged configuration item.

[0091] In this embodiment, as the first embodiment of the configuration item merging unit 130, when it is determined that the current version dependency configuration item is not an empty object, it means that the current version dependency configuration item corresponding to the current NodeJS version is obtained from the version dependency configuration items corresponding to multiple NodeJS versions pre-stored in the server. At this time, the current version dependency configuration item needs to be obtained by event hook parsing to at least obtain the current version production environment dependency configuration item, the current version development environment dependency configuration item, the current version execution script configuration item and the current version installation instruction configuration item included therein.

[0092] Similarly, the default dependency configuration items need to be obtained by event hook parsing to obtain at least the default production environment dependency configuration items, the default development environment dependency configuration items, the default execution script configuration items and the default installation instruction configuration items included therein.

[0093] After completing the acquisition of detailed configuration information of the above two dependency configuration items, finally, according to the preset rules, the current version production environment dependency configuration item and the default production environment dependency configuration item are merged to obtain the first merged configuration item, the current version development environment dependency configuration item and the default development environment dependency configuration item are merged to obtain the second merged configuration item, the current version execution script configuration item and the default execution script configuration item are merged to obtain the third merged configuration item, and the current version installation instruction configuration item and the default installation instruction configuration item are merged to obtain the fourth merged configuration item, so that the merged configuration item is composed of the above four merged configuration items (i.e., the first merged configuration item-the fourth merged configuration item). It can be seen that the automatic merging of the default dependency configuration item and the current version dependency configuration item is realized based on the event hook, and a merged configuration item that can obtain multi-version third-party dependency packages to improve the version compatibility of the NodeJS module to be loaded is obtained.

[0094] In one embodiment, as a second embodiment of the configuration item merging unit 130, the configuration item merging unit 130 is configured to:

[0095] If it is determined that the current version dependency configuration item is an empty object, the default production environment dependency configuration item, the default development environment dependency configuration item, the default execution script configuration item and the default installation instruction configuration item corresponding to the default dependency configuration item are obtained and constitute the merged configuration item.

[0096] In this embodiment, as the second embodiment of the configuration item merging unit 130, when it is determined that the current version dependency configuration item is an empty object, one of the reasons is that the current NodeJS version of the operating environment corresponding to the NodeJS module to be loaded is the same as the NodeJS version corresponding to the NodeJS module to be loaded, and there is no need to obtain the current version dependency configuration item corresponding to the current NodeJS version from the version dependency configuration items corresponding to the multiple NodeJS versions pre-stored in the server; another reason is that the current version dependency configuration item corresponding to the current NodeJS version is not obtained from the version dependency configuration items corresponding to the multiple NodeJS versions pre-stored in the server. However, as long as it is determined that the current version dependency configuration item is an empty object, the default production environment dependency configuration item, the default development environment dependency configuration item, the default execution script configuration item and the default installation instruction configuration item included in the default dependency configuration item are directly used to form the merged configuration item. It can be seen that based on the event hook, at least the default dependency configuration item is used as a non-empty configuration item to obtain a third-party dependency package that is compatible with the current NodeJS version.

[0097] The updating unit 140 is used to update the merged configuration item into the NodeJS module to be loaded and delete the event hook to update the NodeJS module to be loaded.

[0098] In this embodiment, after the merged configuration item is obtained, its ultimate goal is to be updated to the current dependency configuration file in the NodeJS module to be loaded. After completing the above process of updating the current dependency configuration file, the event hook needs to be deleted to avoid the impact of the event hook on the installation process of the third-party dependency package. After completing the above two processes, the updated NodeJS module to be loaded can be obtained.

[0099] The execution control unit 150 is used to complete the loading of the third-party dependency package of the NodeJS operating environment by executing the merged configuration item in the NodeJS module to be loaded.

[0100] In this embodiment, the obtained merged configuration item is mainly used for automatic execution, thereby completing the dynamic installation of the third-party dependency package corresponding to the current operating environment of the NodeJS module to be loaded, without suspending other operations before installing the NodeJS module to be loaded to statically install the third-party dependency package. By automatically executing the merged configuration item, the third-party dependency package loading of the NodeJS operating environment can be completed.

[0101] In one embodiment, the execution control unit 150 is configured to:

[0102] The operation of the merged configuration item in the NodeJS module to be loaded is triggered based on the installation instruction configuration item in the NodeJS module to be loaded, so as to complete the loading of the third-party dependency package of the NodeJS operating environment.

[0103] In this embodiment, since the installation instruction configuration item is also encapsulated in the NodeJS module to be loaded, the installation instruction configuration item can trigger the generation of the installation instruction, so that the installation instruction triggers the automatic operation of the merged configuration item in the NodeJS module to be loaded, so as to complete the dynamic installation of the third-party dependency package of the NodeJS operating environment. After that, other configuration items in the NodeJS module to be loaded are executed to finally complete the complete installation of the entire NodeJS module to be loaded.

[0104] It can be seen that the implementation of the embodiment of the device realizes that there is no need to consider the operating environment when developing the NodeJS module. When the NodeJS module is installed, the corresponding version of the third-party dependency package is dynamically installed according to the operating environment, which not only simplifies the operation process, but also improves the efficiency of version compatibility.

[0105] The dependency loading device of the NodeJS environment can be implemented in the form of a computer program. The computer program can be Figure 6 Runs on the computer device shown.

[0106] See also Figure 6 , Figure 6 The present invention provides a schematic block diagram of a computer device provided by an embodiment of the present invention. The computer device integrates any NodeJS environment dependency loading device provided by an embodiment of the present invention.

[0107] See also Figure 6 The computer device 400 includes a processor 402 , a memory and a network interface 405 connected via a system bus 401 , wherein the memory may include a storage medium 403 and an internal memory 404 .

[0108] The storage medium 403 can store an operating system 4031 and a computer program 4032. The computer program 4032 includes program instructions, and when the program instructions are executed, the processor 402 can execute a dependency loading method of a NodeJS environment.

[0109] The processor 402 is used to provide computing and control capabilities to support the operation of the entire computer device.

[0110] The internal memory 404 provides an environment for the operation of the computer program 4032 in the storage medium 403. When the computer program 4032 is executed by the processor 402, the processor 402 can execute the above-mentioned NodeJS environment dependency loading method.

[0111] The network interface 405 is used to communicate with other devices over the network. Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present invention, and does not constitute a limitation on the computer device to which the solution of the present invention is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0112] The processor 402 is used to run the computer program 4032 stored in the memory to implement the following steps:

[0113] In response to a NodeJS module loading instruction, obtaining a NodeJS module to be loaded and an event hook corresponding to the NodeJS module loading instruction;

[0114] Obtaining the current dependency configuration file in the NodeJS module to be loaded through the event hook, obtaining the default dependency configuration item from the current dependency configuration file, and obtaining the current version dependency configuration item from the current dependency configuration file through the event hook;

[0115] Merging the default dependency configuration item and the current version dependency configuration item to obtain a merged configuration item;

[0116] Updating the merged configuration item into the NodeJS module to be loaded and deleting the event hook to update the NodeJS module to be loaded;

[0117] The third-party dependency package loading of the NodeJS operating environment is completed by executing the merged configuration item in the NodeJS module to be loaded.

[0118] It should be understood that in the embodiment of the present invention, the processor 402 may be a central processing unit (CPU), and the processor 402 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0119] It can be understood by those skilled in the art that all or part of the processes in the method for implementing the above embodiment can be completed by instructing the relevant hardware through a computer program. The computer program includes program instructions, and the computer program can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiment of the above method.

[0120] Therefore, the present invention also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions. When the program instructions are executed by a processor, the processor executes the following steps:

[0121] In response to a NodeJS module loading instruction, obtaining a NodeJS module to be loaded and an event hook corresponding to the NodeJS module loading instruction;

[0122] Obtaining the current dependency configuration file in the NodeJS module to be loaded through the event hook, obtaining the default dependency configuration item from the current dependency configuration file, and obtaining the current version dependency configuration item from the current dependency configuration file through the event hook;

[0123] Merging the default dependency configuration item and the current version dependency configuration item to obtain a merged configuration item;

[0124] Updating the merged configuration item into the NodeJS module to be loaded and deleting the event hook to update the NodeJS module to be loaded;

[0125] The third-party dependency package loading of the NodeJS operating environment is completed by executing the merged configuration item in the NodeJS module to be loaded.

[0126] The storage medium may be any computer-readable storage medium that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a magnetic disk, or an optical disk.

[0127] Those of ordinary skill 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, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. 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 to be beyond the scope of the present invention.

[0128] In the several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of each unit is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.

[0129] The steps in the method of the embodiment of the present invention can be adjusted in order, combined and deleted according to actual needs. The units in the device of the embodiment of the present invention can be combined, divided and deleted according to actual needs. In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0130] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention is essentially 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, including a number of instructions for a computer device (which can be a personal computer, terminal, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention.

[0131] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A method for loading dependencies in a NodeJS environment, characterized in that: include: In response to a NodeJS module loading instruction, obtaining a NodeJS module to be loaded and an event hook corresponding to the NodeJS module loading instruction; Obtaining the current dependency configuration file in the NodeJS module to be loaded through the event hook, obtaining the default dependency configuration item from the current dependency configuration file, and obtaining the current version dependency configuration item from the current dependency configuration file through the event hook; Merging the default dependency configuration item and the current version dependency configuration item to obtain a merged configuration item; Updating the merged configuration item into the NodeJS module to be loaded and deleting the event hook to update the NodeJS module to be loaded; The third-party dependency package loading of the NodeJS operating environment is completed by executing the merged configuration item in the NodeJS module to be loaded.

2. The method according to claim 1, characterized in that The obtaining of the to-be-loaded NodeJS module and the event hook corresponding to the NodeJS module loading instruction comprises: The NodeJS module to be loaded and the event hook configuration item in the NodeJS module to be loaded are obtained, and the event hook is started based on the event hook configuration item.

3. The method according to claim 1, characterized in that The obtaining the current dependency configuration file in the to-be-loaded NodeJS module through the event hook includes: Obtaining the event hook script corresponding to the event hook; The current dependency configuration file is obtained from the NodeJS module to be loaded based on the event hook script.

4. The method according to claim 3, characterized in that The obtaining, through the event hook, the current version dependency configuration item corresponding to the NodeJS module to be loaded includes: Based on the event hook script, the current NodeJS version of the running environment corresponding to the NodeJS module to be loaded is obtained, and the current version dependency configuration item corresponding to the current NodeJS version is obtained.

5. The method according to claim 1, characterized in that The step of merging the default dependency configuration item and the current version dependency configuration item to obtain a merged configuration item includes: If it is determined that the current version dependency configuration item is not an empty object, then obtain the current version production environment dependency configuration item, the current version development environment dependency configuration item, the current version execution script configuration item and the current version installation instruction configuration item corresponding to the current version dependency configuration item; Obtain the default production environment dependency configuration item, the default development environment dependency configuration item, the default execution script configuration item, and the default installation instruction configuration item corresponding to the default dependency configuration item; Merge the current version production environment dependency configuration item with the default production environment dependency configuration item, merge the current version development environment dependency configuration item with the default development environment dependency configuration item, merge the current version execution script configuration item with the default execution script configuration item, and merge the current version installation instruction configuration item with the default installation instruction configuration item to form the merged configuration item.

6. The method according to claim 1, characterized in that The step of merging the default dependency configuration item and the current version dependency configuration item to obtain a merged configuration item includes: If it is determined that the current version dependency configuration item is an empty object, the default production environment dependency configuration item, the default development environment dependency configuration item, the default execution script configuration item and the default installation instruction configuration item corresponding to the default dependency configuration item are obtained and constitute the merged configuration item.

7. The method according to claim 1, characterized in that The step of executing the merged configuration item in the NodeJS module to be loaded to complete the loading of the third-party dependency package of the NodeJS operating environment includes: The operation of the merged configuration item in the NodeJS module to be loaded is triggered based on the installation instruction configuration item in the NodeJS module to be loaded, so as to complete the loading of the third-party dependency package of the NodeJS operating environment.

8. A dependency loading device for a NodeJS environment, characterized in that: include: An event hook acquisition unit, configured to respond to a NodeJS module loading instruction and acquire a NodeJS module to be loaded and an event hook corresponding to the NodeJS module loading instruction; A first configuration item acquisition unit, configured to acquire a current dependency configuration file in the to-be-loaded NodeJS module through the event hook, and acquire a default dependency configuration item from the current dependency configuration file; A second configuration item acquisition unit, used to acquire the current version dependency configuration item corresponding to the NodeJS module to be loaded through the event hook; A configuration item merging unit, used to merge the default dependency configuration item and the current version dependency configuration item to obtain a merged configuration item; An updating unit, configured to update the merged configuration item into the NodeJS module to be loaded and delete the event hook, so as to update the NodeJS module to be loaded; The execution control unit is used to complete the loading of the third-party dependency package of the NodeJS operating environment by executing the merged configuration item in the NodeJS module to be loaded.

9. A computer device, characterized in that: The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the dependency loading method of the NodeJS environment as described in any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the method for loading dependencies in a NodeJS environment as described in any one of claims 1 to 7 can be implemented.