Detailed Description
Exemplary embodiments of the present invention will now be described with reference to the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding, and are to be considered merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
FIG. 1 is a schematic diagram of the main steps of a method of modifying a dependent packet download address according to an embodiment of the present invention. As shown in fig. 1, the method for modifying the download address of the dependent packet according to the embodiment of the present invention mainly includes the following steps S101 to S104.
Step S101: acquiring the address of the mirror image warehouse according to the address modification instruction;
step S102: acquiring a dependence package identifier of a download address to be modified from a dependence package management file;
step S103: according to the identification of the dependent packet and the address of the mirror image warehouse, acquiring the download address of the dependent packet in the mirror image warehouse from the mirror image warehouse;
step S104: the download address of the dependent package in the dependent package management file is modified using the download address of the dependent package in the mirror repository.
The address modification instruction is used for triggering an address modification operation, and the address modification instruction includes information such as instruction parameters (including parameter names and parameter values), and parameter values can be default. For example: for the address modification instruction 'jonef-fix-region=http:// npm-regions.aa.com- @ aa: region=http:// other-npm.aa.com', "jonef-fix" denotes the instruction itself, "-region" and "- @ aa: region" are parameter names of instruction parameters, "=" denotes parameter values of instruction parameters, namely: the address of the repository is mirrored. "@ aa: the name of a dependent package or dependent module in the registry" @ aa "means that if this dependent package or dependent module starts with" @ aa/", this dependent package or dependent module should be downloaded from the mirrored repository address" http:// other-npm.aa.com "specified after" = ", where" @ aa "can generally be replaced by others as needed, such as" @ vue "," @ act ", etc. The "- @ aa: region" parameter has a higher priority than the "-" region "parameter, and can be set or default according to the needs of the actual application. The "- -registry" parameter is used to specify the mirrored repository address of dependent packages or dependent modules that are not specifically specified (e.g., registry pertains to the specific specification above @ aa: registry), and this parameter may be default according to actual needs.
According to one embodiment of the present invention, step S101 may specifically be performed when acquiring the mirrored repository address according to the address modification instruction, as follows:
step S1011: acquiring instruction parameters according to the address modification instruction;
step S1012: if the instruction parameter comprises the mirror image warehouse address, acquiring the mirror image warehouse address from the instruction parameter;
step S1013: otherwise, the mirror warehouse address is obtained from the configuration file.
In the embodiment of the invention, the instruction parameter can be firstly obtained from the address modification instruction, whether the instruction parameter comprises the mirror image warehouse address or not can be judged, and if the mirror image warehouse address is not specified in the instruction, the available mirror image warehouse address can be obtained from the configuration file. Wherein the profile is one provided by the publisher or user. The publisher configures a profile suitable for most users as a default configuration, and the user can specify the desired profile address by using the "- -config" parameter, for example: jonefe-fix-config = http:// xxx. Bb. Com/myconfig, if the "- -config" parameter is specified, the address specified by that parameter is used to retrieve the configuration file without using the default configuration. Whether the mirror warehouse address is acquired through the address modification instruction or the configuration file, the acquired mirror warehouse address can be one or more, and the mirror warehouse address can be configured through the address modification instruction or the configuration file according to requirements.
According to another embodiment of the present invention, when the step S102 obtains the dependency package identifier of the download address to be modified from the dependency package management file, the following steps may be specifically performed:
step S1021: acquiring the download addresses of all the dependent packets from the dependent packet management file;
step S1022: comparing and matching the obtained download addresses of all the dependent packets with the addresses of the mirror image warehouse;
step S1023: and taking the dependent packet which is not matched with the address of the mirror warehouse as the dependent packet of the download address to be modified, and acquiring the dependent packet identification of the download address to be modified.
The dependency package management file records the identification information, the download address, the version information, the version update time of the package or the module on which the project depends, and other related information such as the dependency or the association relationship among the dependency packages or the modules. And loading the dependency package management file of the item and traversing to obtain the download addresses of all the dependency packages or modules recorded in the dependency package management file.
When the download address of the dependent packet is compared and matched with the address of the mirror warehouse, whether the download address is matched with the address of the mirror warehouse is judged mainly through an address domain name and a port number. For example: the dependency package management file lockfile records that the download address of a certain dependency package is http:// a.com/test/test.tgz, and the domain name is "a.com", and the port number is the default port number 80 of the http protocol. Assume that the domain name of the available mirrored repository address acquired according to step S101 is "b.com", and the port number is also the default http protocol port 80. Then the download address of the dependent packet is considered to be not matched to the address of the mirrored repository because the domain names "a.com" and "b.com" of the two are not identical. Likewise, if the port numbers do not match, the download address of the dependent packet is also considered to not match both the address of the mirrored repository. If the domain name and port number are the same, then the two are considered to match.
In addition, according to the foregoing description, there may be a plurality of obtained image warehouse addresses, in this case, the address of each image warehouse and the download address of the dependent packet are respectively compared, so long as there is a match between the address of any image warehouse and the download address of the dependent packet, the match is considered, otherwise, the match is considered.
According to the steps, all the dependent packets which are not matched with the addresses of the mirror warehouse can be obtained, the dependent packets are used as the dependent packets of the download address to be modified, and the dependent packet identification of the download address to be modified is obtained. Then, the dependent packets of the download address to be modified can be processed.
According to another embodiment of the present invention, step S103 may specifically be performed when obtaining the download address of the dependent packet in the mirror repository from the mirror repository according to the dependent packet identifier and the address of the mirror repository, where the step may be performed according to the following steps:
step S1031: acquiring metadata of the dependent package from the mirror image warehouse according to the dependent package identification and the address of the mirror image warehouse;
step S1033: and acquiring the download address of the dependent packet in the mirror image warehouse according to the metadata of the dependent packet.
Since there may be one or more dependent packets whose download addresses are to be modified, the above-described step S1031 and step S1033 may be performed for each dependent packet, respectively, when the download address of the dependent packet in the mirror repository is acquired.
And obtaining the mirror image warehouse and information thereof according to the address of the mirror image warehouse. And then according to the identification of the dependent package, obtaining the metadata of the dependent package from the mirror image warehouse. The metadata of the dependent package comprises information such as the name, short description, label, author, readme, LICENSE code LICENSE, source code address, all version lists, download address and release time of each version, the dependent package list of the package itself, package file check code and the like of the dependent package. In the technical scheme of the invention, the information which is mainly concerned is the download address which depends on the specific version of the packet.
And then, obtaining the download address of the dependent packet in the mirror image warehouse according to the metadata of the dependent packet.
According to another embodiment of the present invention, step S102 may further obtain the version number of the dependent package from the dependent package management file when obtaining the dependent package identifier of the download address to be modified from the dependent package management file. In addition, in step S103, when the download address of the dependent packet in the mirror warehouse is obtained from the mirror warehouse according to the dependent packet identifier and the address of the mirror warehouse, the specific steps may be:
step S1032: acquiring metadata of the dependent package from the mirror image warehouse according to the dependent package identification and the address of the mirror image warehouse;
step S1034: and obtaining the download address of the dependent packet of the corresponding version in the mirror image warehouse according to the version number of the dependent packet and the metadata of the dependent packet.
And obtaining the download address of the dependent package of the version corresponding to the version number in the mirror image warehouse from the metadata of the dependent package according to the version number of the dependent package.
After obtaining the download addresses of all the dependent packets needing to be modified in the download address in the mirror image warehouse, the download addresses of the dependent packets in the dependent packet management file loadfile can be modified. When the download addresses of the dependent packages in the dependency package management file lockfile are modified, because the lockfile is a text file, when a download address modification instruction of the dependent package is executed, the file is read into a memory, the original download address of the dependent package is modified into a new download address (namely, the download address of the dependent package in a mirror warehouse) in the memory, and then data in the memory is written into the lockfile file, so that the dependency package management file lockfile in the project is updated.
FIG. 2 is a schematic diagram of an implementation flow of one embodiment of the present invention. As shown in fig. 2, in this embodiment, a main implementation flow of modifying the download address of a dependent package in a dependent package management file lockfile of an item is shown, including the following steps:
step S201: acquiring the mirror warehouse address, which can be performed by the previous steps S1011 to S1003;
step S202: detecting and collecting the dependent packets to be processed in the lockfile file, wherein the detection and collection processes of the dependent packets can be realized by referring to steps S1021 to S1023, the dependent packets to be processed are the dependent packets to be subjected to download address modification, and information such as the dependent packet identifiers, version numbers and the like of the dependent packets is acquired;
step S203: downloading the metadata of the dependent package, wherein the metadata of the dependent package can be downloaded from the mirror image warehouse according to the identification of the dependent package;
step S204: the download address of the dependent packet of the appointed version in the mirror image warehouse is obtained, and the download address of the dependent packet of the appointed version in the mirror image warehouse can be obtained from the metadata according to the identification and the version number of the dependent packet;
step S205: replacing the download address of the dependent package in the lock file, and replacing the download address of the dependent package in the lock file by using the download address of the dependent package in the mirror warehouse of the specified version acquired in step S204.
The implementation of the present invention is described below with reference to a specific embodiment. Suppose that information of 3 dependent packages is recorded in a lockfile of an item, as follows:
1. the dependency package identified (e.g., as the name of the package) as yalist has a version number of: 2.1.2, the download address is: https:// registry, npmjs. Org/yalist/-/yalist-2.1.2. Tgz, the domain name of the download address is: https:// registry.
2. The dependency package identified as ansi-styles has a version number of: 2.2.1, the download address is: https:// registry, npmjs, org/onsi-styles/-/onsi-styles-2.2.1. Tgz, the domain name of the download address is: https:// registry.
3. The dependency package identified as yauzl, version number is: 2.4.1, the download address is: https:// registry, npmjs, org/yauzl/-/yauzl-2.4.1.Tgz; the domain name of the download address is: https:// registry.
When receiving a dependent packet download address modification instruction sent by a user: the following operations will be performed when joinefe-fix—region=http:// mirrors.cc.com:
1. calling an interface for accessing a file system provided by Nodejs, reading a lockfile file, such as a file "package-lock. JSON", wherein the file is a file conforming to the JSON specification, analyzing the file according to the JSON specification, obtaining three dependency packages and identifiers, version numbers, downloading addresses, domain name information and the like thereof, recording the three dependency packages in a memory, and accessing the memory information through a variable of programming language;
2. the command line parameters are read and then the available mirrored repository addresses are obtained as: http:// mirrors.cc.com. Comparing and matching the mirror image warehouse address with the download addresses of the 3 dependent packets obtained in the step 1, wherein the domain names of the download addresses of the 3 dependent packets are different from the domain name of the mirror image warehouse address, and the download address needs to be modified;
3. the three dependent packets are processed separately, the data is traversed and each dependent packet is acquired and then processed. Taking the yallist dependency package as an example, the network interface provided by Nodejs is used for accessing http:// mirrors.cc.com/yallist, and then data which also accords with the JSON specification can be obtained, and the data is called metadata of the yallist package, wherein information such as download addresses corresponding to different versions of the yallist package is included. Similarly, since the metadata is also a text file in JSON format, it is known from the JSON specification that the download address of this version 2.1.2 of the yalist package in the mirror repository is: http:// mirrors.cc.com 8888/api/npm/npm/yalist/-/yalist-2.1.2. Tgz. According to the same method, the download addresses of other dependent packets in the mirror warehouse can be obtained;
4. in step 1, the original download address of each dependent packet is recorded in the memory, the original download address of the dependent packet in the memory is deleted, and then the download address of the dependent packet in the mirror warehouse is written in, so that the information in the memory is updated. And then, the updated information (such as identification, version number, download address, domain name information and the like) of the dependent package is written into the original package-lock.json file by calling the interface of the NodeJS write file, so that the package-lock.json file can be updated, and the download address of the dependent package is modified.
Fig. 3 is a schematic diagram of main modules of an apparatus for modifying a packet-dependent download address according to an embodiment of the present invention. As shown in fig. 3, an apparatus 300 for modifying a download address of a dependency packet according to an embodiment of the present invention mainly includes a repository address acquisition module 301, a dependency packet acquisition module 302, a download address acquisition module 303, and a download address modification module 304.
A repository address obtaining module 301, configured to obtain an address of the mirrored repository according to the address modification instruction;
the dependent package obtaining module 302 is configured to obtain a dependent package identifier of a download address to be modified from a dependent package management file;
a download address obtaining module 303, configured to obtain, from the mirror warehouse, a download address of the dependent packet in the mirror warehouse according to the dependent packet identifier and an address of the mirror warehouse;
and the download address modification module 304 is configured to modify the download address of the dependent packet in the dependent packet management file by using the download address of the dependent packet in the mirror repository.
According to one embodiment of the invention, the repository address acquisition module 301 may also be configured to:
acquiring instruction parameters according to the address modification instruction;
if the instruction parameter comprises the mirror image warehouse address, acquiring the mirror image warehouse address from the instruction parameter;
otherwise, the mirror warehouse address is obtained from the configuration file.
According to another embodiment of the present invention, the dependency package acquisition module 302 may also be configured to:
acquiring the download addresses of all the dependent packets from the dependent packet management file;
comparing and matching the obtained download addresses of all the dependent packets with the addresses of the mirror image warehouse;
and taking the dependent packet which is not matched with the address of the mirror warehouse as the dependent packet of the download address to be modified, and acquiring the dependent packet identification of the download address to be modified.
According to yet another embodiment of the present invention, the download address acquisition module 303 may also be configured to:
acquiring metadata of the dependent packet from the mirror warehouse according to the dependent packet identifier and the address of the mirror warehouse;
and acquiring the download address of the dependent packet in the mirror warehouse according to the metadata of the dependent packet.
According to yet another embodiment of the present invention, the dependency package acquisition module 302 may also be configured to:
acquiring the version number of the dependent package from a dependent package management file;
and, the download address acquisition module 303 may also be configured to:
acquiring metadata of the dependent packet from the mirror warehouse according to the dependent packet identifier and the address of the mirror warehouse;
and acquiring the download address of the dependent package of the corresponding version in the mirror image warehouse according to the version number of the dependent package and the metadata of the dependent package.
According to the technical scheme of the embodiment of the invention, the address of the mirror image warehouse is obtained through modifying the instruction according to the address; obtaining a dependence package identifier of the download address to be modified from the dependence package management file; then obtaining the download address of the dependent packet in the mirror image warehouse from the mirror image warehouse; and finally, modifying the download address of the dependent package in the dependent package management file by using the download address of the dependent package in the mirror image warehouse, so that a series of operations of detecting the lock file, acquiring the reliable download address of the dependent package from the mirror image warehouse, modifying the download address of the dependent package in the lock file and the like are automatically processed according to the address modification instruction, and therefore, the mirror image source of the Npm dependent package is safely and quickly replaced under the condition that all the dependent package versions of the project are unchanged, the accuracy and the reliability are high, and the normal operation of the system is ensured.
Fig. 4 illustrates an exemplary system architecture 400 of a method of modifying a dependent packet download address or an apparatus of modifying a dependent packet download address to which embodiments of the present invention may be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. The network 404 is used as a medium to provide communication links between the terminal devices 401, 402, 403 and the server 405. The network 404 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
A user may interact with the server 405 via the network 404 using the terminal devices 401, 402, 403 to receive or send messages or the like. Various communication client applications, such as shopping class applications, web browser applications, search class applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only) may be installed on the terminal devices 401, 402, 403.
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 405 may be a server providing various services, such as a background management server (by way of example only) providing support for shopping-type websites browsed by users using the terminal devices 401, 402, 403. The background management server may analyze and process the received data such as the product information query request, and feedback the processing result (e.g., the target push information, the product information—only an example) to the terminal device.
It should be noted that, the method for modifying the download address of the dependent packet according to the embodiment of the present invention is generally performed by the server 405, and accordingly, the device for modifying the download address of the dependent packet is generally disposed in the server 405.
It should be understood that the number of terminal devices, networks and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 5, there is illustrated a schematic diagram of a computer system 500 suitable for use in implementing a terminal device or server in accordance with an embodiment of the present invention. The terminal device or server shown in fig. 5 is only an example, and should not impose any limitation on the functions and scope of use of the embodiments of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 502 or a program loaded from a storage section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other through a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input section 506 including a keyboard, a mouse, and the like; an output portion 507 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker, and the like; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The drive 510 is also connected to the I/O interface 505 as needed. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as needed so that a computer program read therefrom is mounted into the storage section 508 as needed.
In particular, according to embodiments of the present disclosure, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 509, and/or installed from the removable media 511. The above-described functions defined in the system of the present invention are performed when the computer program is executed by a Central Processing Unit (CPU) 501.
The computer readable medium shown in the present invention may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units or modules involved in the embodiments of the present invention may be implemented in software or in hardware. The described units or modules may also be provided in a processor, for example, as: a processor includes a warehouse address acquisition module, a dependency package acquisition module, a download address acquisition module, and a download address modification module. Where the names of the units or modules do not in some way constitute a limitation of the unit or module itself, for example, the repository address acquisition module may also be described as "a module for acquiring the address of a mirrored repository according to an address modification instruction".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be present alone without being fitted into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to include: acquiring the address of the mirror image warehouse according to the address modification instruction; acquiring a dependence package identifier of a download address to be modified from a dependence package management file; acquiring a download address of the dependent packet in the mirror image warehouse from the mirror image warehouse according to the dependent packet identifier and the address of the mirror image warehouse; and modifying the download address of the dependent package in the dependent package management file by using the download address of the dependent package in the mirror warehouse.
According to the technical scheme of the embodiment of the invention, the address of the mirror image warehouse is obtained through modifying the instruction according to the address; obtaining a dependence package identifier of the download address to be modified from the dependence package management file; then obtaining the download address of the dependent packet in the mirror image warehouse from the mirror image warehouse; and finally, modifying the download address of the dependent package in the dependent package management file by using the download address of the dependent package in the mirror image warehouse, so that a series of operations of detecting the lock file, acquiring the reliable download address of the dependent package from the mirror image warehouse, modifying the download address of the dependent package in the lock file and the like are automatically processed according to the address modification instruction, and therefore, the mirror image source of the Npm dependent package is safely and quickly replaced under the condition that all the dependent package versions of the project are unchanged, the accuracy and the reliability are high, and the normal operation of the system is ensured.
The above embodiments do not limit the scope of the present invention. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives can occur depending upon design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of the present invention.