A method, device and electronic device for offline deployment of NPM package

By building private NPM warehouses and offline NPM warehouses, the problem of low offline deployment efficiency in the existing technology is solved, and efficient organizational management and collaborative development of NPM packages is realized.

CN119376747BActive Publication Date: 2025-03-28CHINA SURVEY SURVEYING & MAPPING TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411989178.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-31
Publication Date
2025-03-28
Estimated Expiration
2044-12-31

AI Technical Summary

Technical Problem

In the prior art, the method of file copying is used to achieve low offline deployment efficiency of NPM packages, especially when the offline development team is large, it seriously hinders the development process.

Method used

By building the target operating environment, packaging it as a mirror, and building a private NPM warehouse based on the mirror and NPM source, centralized storage and management of development-dependent packages are achieved. According to offline deployment tasks, export offline files from private NPM repository, install dependency packages in offline environments, and build offline NPM repository.

Benefits of technology

It realizes lightweight offline mirroring of NPM packages, improves the efficiency of collaborative development of offline environments, and simplifies the management and sharing of internal dependency packages.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119376747B_ABST
    Figure CN119376747B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a method, device and electronic device for offline deployment of NPM packages. In the method, a target operating environment is constructed, the target operating environment is packaged as a first image, and a private NPM warehouse is constructed based on the first image and at least one NPM source. The private NPM warehouse has import and export functions, and can realize centralized storage and management of development dependency packages; according to the offline deployment task, the offline file corresponding to the offline environment is exported from the private NPM warehouse, and the offline file includes the dependency package corresponding to the NPM package to be offline; after running the first image in the offline environment, the offline file is imported to build an offline NPM warehouse, and the dependency package in the offline NPM warehouse is installed in the offline environment to realize a lightweight offline NPM image, thereby realizing the organization and management of NPM packages in the offline environment collaborative development scenario, and assisting the efficient development of the offline environment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of information systems, and in particular to an NPM package offline deployment method, device, electronic device and medium. Background Art

[0002] Node Package Manager (NPM) is an important tool in the JavaScript programming language ecosystem. It is the default package manager for Node.js, which enables developers to easily manage and share code modules in JavaScript applications. The NPM source is a server address used to store and provide NPM packages. NPM will download the corresponding dependency packages through this source address when installing the package. Unified management of NPM package management tools and NPM sources is very important for development teams. Development teams usually achieve unified management of NPM package management tools and NPM sources online to improve development efficiency and system stability.

[0003] However, when encountering offline collaborative development scenarios, NPM packages need to be deployed offline. Currently, file copying is often used to achieve offline deployment of NPM packages. However, when the offline development team reaches a certain size, the file copying method becomes inefficient and inconvenient, seriously hindering the development process. Summary of the invention

[0004] To this end, the present application provides a method, device and electronic device for offline deployment of NPM packages to solve the problem of low efficiency of offline deployment of NPM packages caused by using file copying in the prior art.

[0005] In order to achieve the above-mentioned objectives, the first aspect of the present application provides an NPM package offline deployment method, the method comprising: building a target operating environment; packaging the target operating environment into a first image; building a private NPM repository based on the first image and at least one NPM source; according to the offline deployment task, exporting offline files corresponding to the offline environment from the private NPM repository, the offline files including dependent packages corresponding to the NPM package to be offline; after running the first image in the offline environment, importing the offline files to build an offline NPM repository; installing the dependent packages in the offline NPM repository in the offline environment.

[0006] According to the first aspect, the offline deployment task includes at least an offline environment identifier and a first project file; according to the offline deployment task, the offline file corresponding to the offline environment is exported from the private NPM repository, including: based on the offline environment identifier, determining the export version type of the dependency package; according to the first project file and version retrieval rules, determining the dependency package required for the project and the specified version information of the dependency package; based on the specified version information and the export version type, obtaining the corresponding version of the dependency package from the private NPM repository as an offline file; exporting the offline file from the private NPM repository.

[0007] According to the first aspect, or any implementation of the first aspect above, before installing the dependent packages in the offline NPM repository in the offline environment, the method also includes: detecting whether the dependent packages in the offline NPM repository cover all the dependent packages required for the offline environment; the step of installing the dependent packages in the offline NPM repository in the offline environment includes: installing the dependent packages in the offline NPM repository in the offline environment when the dependent packages in the offline NPM repository cover all the dependent packages required for the offline environment.

[0008] According to the first aspect, or any implementation of the first aspect above, the method further includes: when the dependency packages in the offline NPM repository cover all the dependency packages required for the non-offline environment, exporting offline supplementary files from the private NPM repository; importing the offline supplementary files into the offline NPM repository, and returning to the step of detecting whether the dependency packages in the offline NPM repository cover all the dependency packages required for the offline environment.

[0009] According to the first aspect, or any implementation of the first aspect above, exporting offline supplementary files from a private NPM repository includes: determining the export version type of the dependency package based on the offline environment identifier; determining the dependency package required for the project and the specified version information of the dependency package based on the second project file and version retrieval rules; obtaining the corresponding version of the dependency package from the private NPM repository based on the specified version information and the export version type; removing the exported dependency packages from the corresponding version of the dependency package based on the historical export information corresponding to the offline deployment task, and using the remaining dependency packages as offline supplementary files; exporting the offline supplementary files from the private NPM repository.

[0010] According to the first aspect, or any implementation method of the first aspect above, building a target operating environment includes: downloading the source code of cnpmcore and cnpmweb from a code hosting platform; building an operating environment based on Docker, docker-compose and source code; configuring import and export functions for the operating environment, and configuring the identity authentication of the operating environment as an identity authentication for the target object to build the target operating environment.

[0011] According to the first aspect, or any implementation of the first aspect above, building a private NPM repository based on the first image and at least one NPM source includes: after running the first image in a production environment, importing NPM packages from at least one NPM source; wherein the at least one NPM source includes at least one open source NPM source and / or at least one private NPM source.

[0012] The second aspect of the present application provides an NPM package offline deployment device, which includes: a first construction module for building a target operating environment; an image packaging module for packaging the target operating environment into a first image; a second construction module for building a private NPM warehouse based on the first image and at least one NPM source; an export module for exporting offline files corresponding to the offline environment from the private NPM warehouse according to the offline deployment task, the offline files including the dependent packages corresponding to the NPM package to be offline; an offline construction module for importing the offline files after running the first image in the offline environment to build an offline NPM warehouse; an offline installation module for installing the dependent packages in the offline NPM warehouse in the offline environment

[0013] The third aspect of the present application provides an electronic device, which includes: one or more processors; a storage device on which one or more programs are stored, and when the one or more programs are executed by one or more processors, the one or more processors implement any one of the methods in the first aspect; one or more I / O interfaces, connected between the processor and the memory, and configured to implement information interaction between the processor and the memory.

[0014] A fourth aspect of the present application provides a computer-readable medium having a computer program stored thereon, which implements any one of the methods in the first aspect when the program is executed by a processor.

[0015] The present application has the following advantages: an embodiment of the present application provides an offline deployment method for NPM packages, in which a target operating environment is first constructed and the target operating environment is packaged as a first image; secondly, based on the first image and at least one NPM source, a private NPM repository is constructed, and the private NPM repository has import and export functions, which can realize centralized storage and management of development dependency packages, so that the team can manage and share internal dependency packages in a safe and controllable manner; then, according to the offline deployment task, the offline file corresponding to the offline environment is exported from the private NPM repository, and the offline file includes the dependency package corresponding to the NPM package to be offline; then, after running the first image in the offline environment, the offline file is imported to build an offline NPM repository, and the dependency package in the offline NPM repository is installed in the offline environment to realize a lightweight offline NPM image, thereby realizing the organization and management of NPM packages in the offline environment collaborative development scenario, and assisting the efficient development of the offline environment. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The accompanying drawings are used to provide further understanding of the present application and constitute a part of the specification. Together with the following specific embodiments, they are used to explain the present application, but do not constitute a limitation to the present application.

[0017] Figure 1 A flowchart of an offline deployment method of an NPM package provided in an embodiment of the present application;

[0018] Figure 2 An example diagram of a web page of a private NPM repository provided in an embodiment of the present application;

[0019] Figure 3 A flowchart of a method for exporting offline files provided in the previous embodiment of the present invention;

[0020] Figure 4 A schematic diagram of the structure of an NPM package offline deployment device provided in an embodiment of the present application;

[0021] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0022] In order to enable those skilled in the art to better understand the technical solutions of the present disclosure, the exemplary embodiments of the present disclosure are described below in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0023] In the absence of conflict, the various embodiments of the present disclosure and the various features therein may be combined with each other.

[0024] As used herein, the term "and / or" includes any and all combinations of one or more of the associated listed items.

[0025] The terms used in this application are only used to describe specific embodiments and are not intended to limit the present application.As used in this application, the singular forms "a", "an" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.

[0026] When the terms “comprising” and / or “made of…” are used in this application, it specifies the existence of the stated features, integers, steps, operations, elements and / or components, but does not exclude the existence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.

[0027] The embodiments described in the present application may be described with reference to plan views and / or cross-sectional views by means of ideal schematic diagrams of the present application. Therefore, the exemplary illustrations may be modified according to manufacturing techniques and / or tolerances.

[0028] Unless otherwise defined, all terms (including technical and scientific terms) used in this application have the same meaning as those commonly understood by those of ordinary skill in the art. It will also be understood that terms such as those defined in commonly used dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and this application, and will not be interpreted as having an idealized or overly formal meaning unless explicitly defined in this application.

[0029] Node Package Manager (NPM) is an important tool in the JavaScript programming language ecosystem. It is the default package manager for Node.js, which enables developers to easily manage and share code modules in JavaScript applications. The NPM source is a server address used to store and provide NPM packages. NPM will download the corresponding dependency packages through this source address when installing the package. Unified management of NPM package management tools and NPM sources is very important for development teams. Development teams usually achieve unified management of NPM package management tools and NPM sources online to improve development efficiency and system stability.

[0030] However, when encountering offline collaborative development scenarios, NPM packages need to be deployed offline. Currently, file copying is often used to achieve offline deployment of NPM packages. However, when the offline development team reaches a certain size, the file copying method becomes inefficient and inconvenient, seriously hindering the development process.

[0031] To this end, an embodiment of the present application provides an offline deployment method for NPM packages. By building a private NPM repository, centralized storage and management of development dependency packages are achieved, allowing the team to manage and share internal dependency packages in a safe and controllable manner. At the same time, convenient import and export functions and lightweight offline NPM images are provided to achieve organizational management of NPM packages in offline collaborative development scenarios, thereby facilitating efficient development in offline environments.

[0032] Figure 1 A flowchart of an offline deployment method of an NPM package provided in an embodiment of the present application. The offline deployment method of the NPM package is applied to an electronic device. Figure 1 As shown, the NPM package offline deployment method includes: steps S101 to S106.

[0033] Step S101, building a target operating environment.

[0034] The target operating environment is the operating environment of the private warehouse of the target object, which can be a person or a team of multiple people.

[0035] In a possible implementation manner provided in an embodiment of the present application, building a target operating environment (the above-mentioned step S101 ) includes: the following steps 1 to 3.

[0036] Step 1: Download the source code of cnpmcore and cnpmweb from the code hosting platform.

[0037] Among them, code hosting platforms such as Github.

[0038] Step 2: Build the operating environment based on Docker, docker-compose and source code.

[0039] Among them, Docker is a set of Platform as a Service (PaaS) products that packages software and its dependencies into containers based on virtualization technology at the operating system level. ‌Docker-Compose is an open source project based on Docker for defining and running multi-container Docker applications.

[0040] Step 3: Configure import and export functions for the operating environment, and configure the identity authentication of the operating environment as the identity authentication for the target object to build the target operating environment.

[0041] In an embodiment of the present application, the electronic device downloads the source code from Github according to the configuration of the target object, builds the operating environment through Docker and docker-compose, including MySQL (a relational database management system), Redis (a memory-based key-value database), MinIO (a distributed object storage system) and Elastic Search (a distributed search and analysis engine), etc., and modifies the configuration items according to the team's private NPM warehouse management requirements, such as transforming the identity authentication into the team's existing identity authentication system.

[0042] Step S102: Pack the target operating environment into a first image.

[0043] Step S103: Building a private NPM repository based on the first image and at least one NPM source.

[0044] Among them, Private NPM Repository is a service for hosting private NPM packages, allowing organizations and teams to store their internally developed NPM packages in a secure, restricted environment for internal use.

[0045] In a possible implementation provided in an embodiment of the present application, a private NPM repository is constructed based on the first image and at least one NPM source (the above step S103), including: after running the first image in a production environment, importing an NPM package from at least one NPM source.

[0046] The at least one NPM source includes at least one open source NPM source and / or at least one private NPM source, which can be a private NPM source of the target object. The production environment refers to the actual system environment used by the end user or customer, which usually includes infrastructure such as servers, databases, networks, etc., where all applications and services run.

[0047] In this step, after the electronic device deploys the image in the production environment, it runs the service and starts the synchronization task to synchronize all packages from the upstream NPM source (open source NPM source). The production environment requires a large object storage space. The first synchronization of the NPM source takes a long time. After the NPM source synchronization is completed, the team NPM source is configured as a private NPM warehouse address, which has the storage management capabilities for external and internal dependent packages.

[0048] Figure 2 This is an example diagram of a web page of a private NPM repository provided in an embodiment of the present application. Figure 2 As shown, the webpage of the private NPM repository includes a site name, such as npmmirror mirror site; a search bar, in which you can enter the NPM package name, author, or keyword information, and click the search control to search for NPM packages; the webpage also includes search records (such as Figure 2 "s3-cnpmcore@1.1.2", "dayjs@1.11.12", "cnpm@9.4.0") below the search bar), site introduction, latest update package, and latest synchronization time.

[0049] Step S104: according to the offline deployment task, export the offline files corresponding to the offline environment from the private NPM repository.

[0050] Among them, the offline deployment task is a task created in the management system corresponding to the private NPM repository when the target object needs to be deployed offline. The offline deployment task contains a task name, a task identifier, an offline environment identifier, and historical export information, wherein the offline environment identifier is used to identify the operating environment for which the offline deployment task is deployed; the historical export information is used to record the offline file list historically exported for the offline deployment task. The offline file includes the dependency package corresponding to the NPM package to be offline. Dependency packages are external resources required for program operation, usually including library files, tools, and frameworks. During the software development process, developers rely on some previously created components and tools to complete their projects more efficiently. These pre-existing tools are called dependencies, and when they are combined together in a pre-packaged manner, dependency packages are formed.

[0051] In a possible implementation provided in an embodiment of the present application, an offline deployment task includes at least an offline environment identifier and a first project file, wherein the first project file is a project configuration file uploaded by a user, such as a package.json file. The package.json file is the configuration file of the project, which defines various configuration information and dependencies of the project. The package.json file is a JSON object that contains various settings for the project, such as the project name, version, dependent packages, script commands, etc. Typically, the dependencies field of the package.json file lists the dependent packages and their version numbers required for the project to run, and the devDependencies field lists the dependent packages required during the development process.

[0052] Figure 3 This is a flowchart of a method for exporting offline files provided in the previous embodiment. Figure 3 As shown, the step of exporting the offline files corresponding to the offline environment from the private NPM repository according to the offline deployment task (the above step S104) includes: the following steps S1041 to S1044.

[0053] Step S1041: Determine the export version type of the dependent package based on the offline environment identifier.

[0054] The offline environment identifier is used to identify the operating environment for which the offline deployment task is deployed.

[0055] It is understandable that different offline environments require different versions of dependency packages to be exported, and the electronic device may be pre-configured with the export version types of dependency packages corresponding to the offline environment. For example, for a certain offline environment, the types of dependency packages that need to be exported are: specified version, specified version latest major version, specified version latest minor version, and latest version within each major version.

[0056] In the embodiment of the present application, the version of the exported dependency package is limited to reduce the amount of data in the offline version as much as possible, while taking into account possible version switching to avoid subsequent repeated import and export of the same dependency.

[0057] Step S1042: Determine the dependent packages required for the project and the specified version information of the dependent packages according to the first project file and version search rules.

[0058] The version search rule is a rule for determining the specified version information according to the version control symbol. The specified version information is the specific version number of the specified version.

[0059] In an embodiment of the present application, determining the dependent packages required for the project and the specified version information of the dependent packages based on the first project file and the version retrieval rule includes: the following steps 1 and 2.

[0060] Step 1: Determine the dependency packages required for the project based on the dependencies field and devDependencies field in the first project file.

[0061] The dependencies field and devDependencies field in the first project file record the dependency packages required by the project.

[0062] Step 2: Based on the version retrieval rules, determine the specified version information from the version number of each dependent package.

[0063] Among them, the version retrieval rules include: the following rules (1)-(6).

[0064] (1) If the version control symbol of the version number contains "space-space" (that is, there are spaces before and after -), the version on the right side of the version number is determined as the specified version.

[0065] (2) In the version control symbols of the version number, if it starts with "(" or "[" and ends with "]", the version on the right side of "]" is determined as the specified version; if it starts with "[" and ends with ")", the version on the left side of "[" is determined as the specified version.

[0066] (3) If the version control symbol of the version number contains "," or "space", multiple versions are split according to the "," or "space" as nodes. For each version, the specified version is determined according to the following rules (4) to (6).

[0067] (4) If the version control symbols in the version number include any of “~”, “^”, “=”, “>=”, or “<=”, or if there is no symbol, the version number is determined to be a specified version.

[0068] (5) If the version control symbol of the version number contains “>” or “<”, the next version closest to the “>” or the previous version closest to the “<” will be determined as the specified version.

[0069] (6) If the version control symbol of the version number contains a wildcard "*", "x" or "X", the latest version is identified as the specified version.

[0070] In an embodiment of the present application, after the electronic device determines the specified version information, it can determine the latest main version of the specified version (excluding test versions such as alpha), the latest sub-version of the specified version (excluding test versions such as alpha), and the latest version in each main version (i.e., the latest version in the historical main version) based on the specified version information.

[0071] Step S1043: Based on the specified version information and the exported version type, obtain the corresponding version of the dependency package from the private NPM repository as an offline file.

[0072] Step S1044: Export offline files from the private NPM repository.

[0073] In the embodiment of the present application, through the above steps S1041-S1044, the electronic device exports offline files from the private NPM repository, and the offline files may include sql statements and tar files. In the export process, the electronic device reduces the amount of offline version data as much as possible by limiting the version, while taking into account possible version switching to avoid repeated import and export of the same dependency in the future.

[0074] It should be noted that when the electronic device exports for the first time, it will export all the dependencies required for the offline environment. If it needs to export offline files later, it will be compared with the historical export tasks and only incrementally exported to reduce the amount of data copied to the offline environment later.

[0075] Step S105: After running the first image in the offline environment, import the offline file to build an offline NPM repository.

[0076] In a possible implementation provided by the embodiment of the present application, an NPM hook is added to the offline developed project, and a script is used to perform a pre-detection before installing the dependent packages. If there are packages missing in the offline NPM warehouse, the missing packages need to be exported before installation. That is, before installing the dependent packages in the offline NPM warehouse in the offline environment, the offline deployment method of the NPM package also includes: detecting whether the dependent packages in the offline NPM warehouse cover all the dependent packages required by the offline environment.

[0077] In this possible implementation, when the dependency packages in the offline NPM repository cover all dependency packages required by the non-offline environment, the electronic device exports offline supplementary files from the private NPM repository, then imports the offline supplementary files into the offline NPM repository, and returns to the step of detecting whether the dependency packages in the offline NPM repository cover all dependency packages required by the offline environment.

[0078] The electronic device exports the offline supplementary file from the private NPM repository, including the following steps 1 to 5.

[0079] Step 1: Determine the export version type of the dependent package based on the offline environment identifier.

[0080] This step is similar to the aforementioned step S1041. Please refer to the detailed description of the aforementioned step S1041, which will not be repeated here.

[0081] Step 2: Determine the dependent packages required for the project and the specified version information of the dependent packages according to the second project file and version search rules.

[0082] It should be noted that the user can select an established offline deployment task and upload a second project file (package.json file) for the offline deployment task so that the electronic device can determine the required dependency packages and specified version information of the dependency packages according to the second project file and version retrieval rules.

[0083] Among them, the step of determining the dependent packages required by the project and the specified version information of the dependent packages according to the project files and version retrieval rules is similar to the aforementioned step S1042. Please refer to the detailed description of the aforementioned step S1042, which will not be repeated here.

[0084] Step 3: Based on the specified version information and exported version type, obtain the corresponding version of the dependency package from the private NPM repository.

[0085] Step 4: Based on the historical export information corresponding to the offline deployment task, remove the exported dependency packages from the dependency packages of the corresponding version, and use the remaining dependency packages as offline supplementary files.

[0086] In this embodiment, the offline NPM repository package is supplemented in an incremental manner to reduce the amount of data exported each time.

[0087] Step 5: Export offline supplementary files from the private NPM repository.

[0088] In this possible implementation, when the dependency packages in the offline NPM repository cover all dependency packages required by the offline environment, the following step S106 is performed.

[0089] Step S106: Install the dependent packages in the offline NPM repository in the offline environment.

[0090] An embodiment of the present application provides an offline deployment method for NPM packages. In the method, a target operating environment is first constructed and the target operating environment is packaged as a first image. Secondly, based on the first image and at least one NPM source, a private NPM repository is constructed. The private NPM repository has import and export functions, which can realize centralized storage and management of development dependency packages, so that the team can manage and share internal dependency packages in a safe and controllable manner; then, according to the offline deployment task, the offline file corresponding to the offline environment is exported from the private NPM repository, and the offline file includes the dependency package corresponding to the NPM package to be offline; then, after running the first image in the offline environment, the offline file is imported to build an offline NPM repository, and the dependency package in the offline NPM repository is installed in the offline environment to realize a lightweight offline NPM image, thereby realizing the organization and management of NPM packages in the offline environment collaborative development scenario, and assisting the efficient development of the offline environment.

[0091] The step division of the above methods is only for clear description. When implemented, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they include the same logical relationship, they are all within the scope of protection of this application; adding insignificant modifications to the algorithm or process or introducing insignificant designs without changing the core design of the algorithm and process are all within the scope of protection of this application.

[0092] In a second aspect, an embodiment of the present application provides an NPM package offline deployment device. Figure 4 A schematic diagram of the structure of an NPM package offline deployment device provided in an embodiment of the present application. Figure 4 As shown, the NPM package offline deployment device includes: a first construction module 41, an image packaging module 42, a second construction module 43, an export module 44, an offline construction module 45 and an offline installation module 46.

[0093] The first building module 41 is used to build a target operating environment.

[0094] The image packaging module 42 is used to package the target operating environment into a first image.

[0095] The second building module 43 is used to build a private NPM repository based on the first image and at least one NPM source.

[0096] The export module 44 is used to export offline files corresponding to the offline environment from the private NPM repository according to the offline deployment task.

[0097] The offline files include the dependency packages corresponding to the NPM packages to be offline.

[0098] The offline construction module 45 imports the offline file to build an offline NPM repository after running the first image in the offline environment.

[0099] The offline installation module 46 installs the dependent packages in the offline NPM repository in the offline environment.

[0100] It should be clear that the present application is not limited to the specific configurations and processes described in the above embodiments and shown in the figures. For the convenience and brevity of description, a detailed description of the known methods is omitted here, and the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, which will not be repeated here.

[0101] An embodiment of the present application provides an NPM package offline deployment device, in which a first construction module is used to build a target operating environment, an image packaging module is used to package the target operating environment into a first image, and a second construction module is used to build a private NPM warehouse based on the first image and at least one NPM source. The private NPM warehouse has import and export functions, which can realize centralized storage and management of development dependency packages, so that the team can manage and share internal dependency packages in a safe and controllable manner; the export module is used to export offline files corresponding to the offline environment from the private NPM warehouse according to the offline deployment task, and the offline files include dependency packages corresponding to the NPM package to be offline; the offline construction module is used to import offline files after running the first image in the offline environment to build an offline NPM warehouse, and the offline installation module is used to install dependency packages in the offline NPM warehouse in the offline environment to realize lightweight offline NPM images, thereby realizing the organization and management of NPM packages in the offline environment collaborative development scenario, and assisting the efficient development of the offline environment.

[0102] It should be noted that the NPM package offline deployment device in this application can include two parts of the device, one part is used to build and manage a private NPM repository, and the other part is used to build an offline NPM repository in an offline environment, and to realize a lightweight offline NPM image based on offline files and offline supplementary files.

[0103] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 5 The electronic device includes: one or more processors 501; a memory 502, on which one or more programs are stored. When the one or more programs are executed by the one or more processors, the one or more processors implement any one of the above-mentioned NPM package offline deployment methods; one or more I / O interfaces 503, connected between the processor and the memory, and configured to realize information interaction between the processor and the memory.

[0104] Among them, the processor 501 is a device with data processing capabilities, including but not limited to a central processing unit (CPU) and the like; the memory 502 is a device with data storage capabilities, including but not limited to random access memory (RAM, more specifically SDRAM, DDR, etc.), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory (FLASH); the I / O interface (read-write interface) 503 is connected between the processor 501 and the memory 502, and can realize information interaction between the processor 501 and the memory 502, including but not limited to a data bus (Bus) and the like.

[0105] In some embodiments, the processor 501 , the memory 502 , and the I / O interface 503 are connected to each other through a bus, and further connected to other components of the computing device.

[0106] This embodiment also provides a computer-readable medium on which a computer program is stored. When the program is executed by a processor, the NPM package offline deployment method provided in this embodiment is implemented. To avoid repeated description, the specific steps of the NPM package offline deployment method are not repeated here.

[0107] It will be appreciated by those skilled in the art that all or some of the steps, systems, and functional modules / units in the methods invented above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In hardware implementations, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or implemented as hardware, or implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or non-transitory medium) and a communication medium (or transient medium). As is well known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer. In addition, it is well known to those skilled in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.

[0108] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0109] Those skilled in the art will understand that although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features from different embodiments is meant to be within the scope of the present embodiment and to form different embodiments.

[0110] It is to be understood that the above embodiments are merely exemplary embodiments used to illustrate the principles of the present application, but the present application is not limited thereto. For those skilled in the art, various modifications and improvements can be made without departing from the spirit and substance of the present application, and these modifications and improvements are also considered to be within the scope of protection of the present application.

Claims

1. A method for offline deployment of NPM packages, characterized in that: The method comprises: Build the target operating environment; Packaging the target operating environment into a first image; Building a private NPM repository based on the first image and at least one NPM source; According to the offline deployment task, export the offline files corresponding to the offline environment from the private NPM repository, where the offline files include the dependent packages corresponding to the NPM packages to be offline; After running the first image in the offline environment, importing the offline file to build an offline NPM repository; Install the dependent package in the offline NPM warehouse in the offline environment; The offline deployment task at least includes an offline environment identifier and a first project file; and exporting an offline file corresponding to the offline environment from a private NPM repository according to the offline deployment task includes: Based on the offline environment identifier, determine the export version type of the dependent package; Determine the dependent packages required by the project and the specified version information of the dependent packages according to the first project file and version search rules; Based on the specified version information and the exported version type, obtain the corresponding version of the dependency package from the private NPM warehouse as the offline file; Export the offline file from the private NPM repository.

2. The method according to claim 1, characterized in that Before installing the dependent package in the offline NPM repository in the offline environment, the method further includes: Detect whether the dependency packages in the offline NPM warehouse cover all dependency packages required by the offline environment; The step of installing the dependent package in the offline NPM warehouse in the offline environment includes: In the case where the dependency packages in the offline NPM warehouse cover all the dependency packages required by the offline environment, the dependency packages in the offline NPM warehouse are installed in the offline environment.

3. The method according to claim 2, characterized in that The method further comprises: In the case where the dependency packages in the offline NPM warehouse do not cover all the dependency packages required by the offline environment, exporting offline supplementary files from the private NPM warehouse; Importing the offline supplementary file into the offline NPM warehouse, and returning to the step of detecting whether the dependent packages in the offline NPM warehouse cover all the dependent packages required by the offline environment.

4. The method according to claim 3, characterized in that: The exporting of offline supplementary files from the private NPM repository includes: Based on the offline environment identifier, determine the export version type of the dependent package; Determine the dependent packages required for the project and the specified version information of the dependent packages according to the second project file and version search rules; Based on the specified version information and the exported version type, obtain the corresponding version of the dependency package from the private NPM repository; Based on the historical export information corresponding to the offline deployment task, the exported dependency packages are removed from the dependency packages of the corresponding version, and the remaining dependency packages are used as the offline supplementary files; Export the offline supplementary file from the private NPM repository.

5. The method according to claim 1, characterized in that The target operating environment is constructed, including: Download the source code of cnpmcore and cnpmweb from the code hosting platform; Build the operating environment based on Docker, docker-compose and the source code; Import and export functions are configured for the operating environment, and identity authentication of the operating environment is configured as identity authentication for a target object, so as to construct the target operating environment.

6. The method according to claim 1, characterized in that The step of building a private NPM repository based on the first image and at least one NPM source includes: After running the first image in the production environment, import the NPM package from the at least one NPM source; wherein the at least one NPM source includes at least one open source NPM source and / or at least one private NPM source.

7. An NPM package offline deployment device, characterized in that: The device comprises: The first building module is used to build a target operating environment; An image packaging module, used to package the target operating environment into a first image; A second building module is used to build a private NPM repository based on the first image and at least one NPM source; An export module is used to export offline files corresponding to the offline environment from a private NPM repository according to an offline deployment task, wherein the offline files include dependent packages corresponding to the NPM package to be offline; An offline construction module, after running the first image in an offline environment, imports the offline file to build an offline NPM repository; An offline installation module is used to install the dependency package in the offline NPM repository in the offline environment; The offline deployment task at least includes an offline environment identifier and a first project file; and exporting an offline file corresponding to the offline environment from a private NPM repository according to the offline deployment task includes: Based on the offline environment identifier, determine the export version type of the dependent package; Determine the dependent packages required by the project and the specified version information of the dependent packages according to the first project file and version search rules; Based on the specified version information and the exported version type, obtain the corresponding version of the dependency package from the private NPM warehouse as the offline file; Export the offline file from the private NPM repository.

8. An electronic device, characterized in that: include: one or more processors; A storage device having one or more programs stored thereon, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6; One or more I / O interfaces are connected between the processor and the memory and are configured to implement information interaction between the processor and the memory.

9. A computer-readable medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method according to any one of claims 1 to 6.