Project building processing method and device, computer device and storage medium
By redirecting the module import path in the host project to obtain the source code files of independent functional modules for compilation, the problem of low cross-project build efficiency in the host project is solved, and more efficient project build processing is achieved.
Patent Information
- Application Number
- CN202510663110.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-21
- Publication Date
- 2026-11-24
AI Technical Summary
In existing technologies, cross-project build processes for host projects are inefficient, especially when integrating independent functional modules, where efficient compilation and integration are not possible.
By redirecting the source code path identified by the module import instruction, the source code files of independent functional modules can be directly obtained and compiled. Combined with the results of other instructions in the host project source code, the project build result is generated, avoiding the step of importing the code of independent functional modules into the host project source code.
It improves the efficiency of project building, reduces unnecessary coding import steps, and enhances the overall build speed and efficiency.
Smart Images

Figure CN123157208A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a project construction processing method, apparatus, computer equipment, storage medium, and computer program product. Background Technology
[0002] In the software development field, cross-project builds integrating independently developed Software Development Kits (SDKs) into a host project have become a mainstream architectural pattern. For example, a host project can integrate independent microservice modules such as order services, payment services, and logistics services to build a complete business service. Typically, the host project imports the release packages of these independent functional modules through dependency management tools, and the packaging tool resolves the module paths and compiles the dependency code during the build process. However, the current efficiency of cross-project builds for host projects is relatively low. Summary of the Invention
[0003] Therefore, it is necessary to provide a project construction processing method, apparatus, computer equipment, computer-readable storage medium, and computer program product that can improve the efficiency of project construction processing in response to the above-mentioned technical problems.
[0004] Firstly, this application provides a project construction processing method. The method includes:
[0005] Determine the source code of the host project. If the source code of the host project includes a module import directive, determine the source code path of the independent functional module identified by the module import directive. The source code path is the path that is redirected after mapping the module import path of the independent functional module.
[0006] Obtain the source code files of the independent functional modules from the source code path, compile the source code files, and obtain the compilation results of the independent functional modules;
[0007] Obtain the compilation results for project directives in the host project source code, which include directives in the host project source code excluding module import directives;
[0008] Based on the compilation results of the independent functional modules and the compilation results of the project instructions, the project build result corresponding to the host project source code is generated.
[0009] Secondly, this application also provides a project construction processing apparatus. The apparatus includes:
[0010] The source code path determination module is used to determine the source code of the host project. When the source code of the host project includes a module import instruction, it determines the source code path of the independent functional module identified by the module import instruction. The source code path is a path that is redirected after mapping the module import path of the independent functional module.
[0011] An independent functional module compilation module is used to obtain the source code file of the independent functional module from the source code path, and compile the source code file to obtain the compilation result of the independent functional module;
[0012] The project instruction compilation module is used to obtain the compilation results for the project instructions in the host project source code, wherein the project instructions include instructions in the host project source code other than the module import instructions;
[0013] The compilation result processing module is used to generate the project build result of the host project corresponding to the host project source code based on the compilation results of the independent functional modules and the compilation results of the project instructions.
[0014] In one embodiment, the source code path determination module is further configured to, when the host project source code includes a module import instruction, determine the module import path of the independent functional module identified by the module import instruction; and map the module import path of the independent functional module according to the alias mapping method to obtain the source code path of the independent functional module after redirection.
[0015] In one embodiment, the independent functional module compilation module is further configured to: determine a first module instruction of the independent functional module from the source code file, wherein the first module instruction belongs to the instruction type of an import module; determine the redirected path of the target module identified by the first module instruction, wherein the redirected path is the path in the external dependency package directory of the host project source code to which the target module is redirected; obtain the source code file of the target module from the redirected path, and compile the source code file of the target module to obtain the compilation result of the target module; and obtain the compilation result of the independent functional module based on the compilation result of the target module.
[0016] In one embodiment, the independent functional module compilation module is further configured to determine the initial path of the target module identified by the first module instruction; and redirect the initial path of the target module to the external dependency package directory of the host project source code to obtain the redirected path of the target module.
[0017] In one embodiment, the independent functional module compilation module is further configured to determine the directory tree corresponding to the external dependency package directory of the host project source code; traverse the directory tree sequentially from bottom to top to obtain candidate paths; obtain a target candidate path based on the candidate path including the source code file of the target module and the external dependency package directory; and redirect the initial path of the target module to the target candidate path to obtain the redirected path of the target module.
[0018] In one embodiment, the independent functional module compilation module is further configured to map the initial path of the target module to redirect the initial path of the target module to the target candidate path, thereby obtaining the redirected path of the target module.
[0019] In one embodiment, the apparatus further includes a candidate path matching module, configured to obtain a description file for the external dependency package directory; determine file identifiers of files included in the candidate paths from the description file; match the file identifiers of files included in the candidate paths with the source code files of the target module to obtain a matching result; and determine a candidate path including the source code files of the target module based on the matching result.
[0020] In one embodiment, the candidate path matching module is further configured to convert the file identifier of the file included in the candidate path to obtain the file name of the file included in the candidate path; determine the file name of the source code file of the target module; and perform field matching between the file name of the source code file of the target module and the file name of the file included in the candidate path to obtain a matching result.
[0021] In one embodiment, the independent functional module compilation module is further configured to compile based on the second module instructions of the independent functional module to obtain the compilation result of the second module instructions, wherein the second module instructions do not belong to the instruction type of the import module; and to obtain the compilation result of the independent functional module based on the compilation result of the target module and the compilation result of the second module instructions.
[0022] In one embodiment, the independent functional module compilation module is further configured to determine the request path corresponding to the second module instruction of the independent functional module; determine the concatenation path according to the path type of the request path; obtain the access path of the second module instruction according to the request path and the concatenation path; and compile the second module instruction based on the access path to obtain the compilation result of the second module instruction.
[0023] In one embodiment, the compilation result processing module is further configured to fuse the compilation results of the independent functional modules and the compilation results of the project instructions to obtain the compilation result of the host project source code; and perform post-compilation processing based on the compilation result of the host project source code to generate the project build result of the host project corresponding to the host project source code.
[0024] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps of the above-described project construction and processing method.
[0025] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, implements the steps of the above-described project construction and processing method.
[0026] Fifthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, implements the steps of the above-described project construction and processing method.
[0027] The aforementioned project construction processing method, apparatus, computer equipment, storage medium, and computer program product, for module import instructions included in the host project source code, determine the source code path after mapping and redirecting the module import path of the independent functional module identified by the module import instruction, obtain the source code file of the independent functional module from the source code path, compile it, obtain the compilation result of the independent functional module, and combine it with the compilation results of project instructions in the host project source code other than module import instructions to generate the project construction result of the host project corresponding to the host project source code. In the project construction process, for module import instructions in the host project source code, the source code path after mapping and redirecting the module import path of the independent functional module identified by the module import instruction is determined, and the source code file of the independent functional module is obtained from the source code path and compiled directly, without needing to encode the independent functional module and import it into the host project source code for project construction, thereby improving the efficiency of project construction. Attached Figure Description
[0028] To more clearly illustrate the technical solutions in the embodiments or related technologies of this application, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0029] Figure 1 This is a diagram illustrating the application environment of a project building process method in one embodiment.
[0030] Figure 2 This is a flowchart illustrating the project building process in one embodiment;
[0031] Figure 3 This is a flowchart illustrating the project construction process in yet another embodiment;
[0032] Figure 4 This is a flowchart illustrating the process of building a project based on multiple instructions in one embodiment;
[0033] Figure 5 This is a schematic diagram illustrating the compilation process for source code files in one embodiment;
[0034] Figure 6 This is a schematic diagram illustrating the relationship between the SDK and the host in one embodiment;
[0035] Figure 7 This is a schematic diagram of the SDK construction process in one embodiment;
[0036] Figure 8 A diagram illustrating the time consumption of host construction in the traditional approach;
[0037] Figure 9 This is a flowchart illustrating the module parsing process in one embodiment;
[0038] Figure 10 This is a flowchart illustrating the traversal search module in one embodiment;
[0039] Figure 11 This is a schematic diagram of name length constraints in one embodiment;
[0040] Figure 12 This is a flowchart illustrating the parsing process for the host directory and SDK directory in one embodiment;
[0041] Figure 13 A schematic diagram illustrating the comparison of host construction time in one embodiment;
[0042] Figure 14 A structural block diagram of a project construction processing device in one embodiment;
[0043] Figure 15 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0044] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0045] The project construction efficiency method provided in this application embodiment can be applied to, for example... Figure 1In the application environment shown, terminal 102 communicates with server 104 via a network. A data storage system can store the data that server 104 needs to process. The data storage system can be set up independently, integrated into server 104, or placed in the cloud or on other devices. Terminal 102 can provide a human-computer interaction interface, through which users can build host projects. For example, users can configure host project A through the host project A configuration interface on terminal 102. Independent functional module 1 can be integrated into host project A. Independent functional module 1 may include an independently developed software development kit (SDK) capable of implementing independent microservices, such as order service module, payment service module, logistics service module, editor module, etc. Terminal 102 can generate host project source code for host project A based on the user's configuration and send the host project source code of host project A to server 104.
[0046] During the project building process of host project A based on the host project source code, server 104 can compile the module import instructions and project instructions included in the host project source code separately. For module import instructions, server 104 can determine the source code path of the independent functional module 1 identified by the module import instruction, and obtain the source code file of independent functional module 1 based on the source code path. Server 104 can compile the source code file of independent functional module 1 to obtain compilation result 1 of independent functional module 1. For project instructions, since no other independent functional modules need to be integrated, server 104 can directly compile based on the project instructions to obtain compilation result 2 of the project instructions. Server 104 can generate the project build result of host project A based on compilation result 1 and compilation result 2. For example, server 104 can obtain the compilation result of host project A based on compilation result 1 and compilation result 2, and perform various post-compilation processing such as packaging, optimization, compression, and resource integration based on the compilation result of host project A to generate the project build result of host project A.
[0047] In some embodiments, the build process for the host project can be implemented solely by terminal 102, or jointly by a computer device system consisting of terminal 102 and server 104. Terminal 102 can be, but is not limited to, various desktop computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, smart in-vehicle devices, etc. Portable wearable devices can include smartwatches, smart bracelets, head-mounted devices, etc. Server 104 can be implemented using a standalone server or a server cluster consisting of multiple servers, or it can be a cloud server.
[0048] In one exemplary embodiment, such as Figure 2 As shown, a project building process method is provided. This method is executed by a computer device, specifically a terminal or server, or both. In this embodiment, the method is applied to... Figure 1 Taking the server in the example, the explanation includes the following steps 202 to 208. Wherein:
[0049] Step 202: Determine the host project source code. If the host project source code includes a module import instruction, determine the source code path of the independent functional module identified by the module import instruction. The source code path is the path that is redirected after mapping the module import path of the independent functional module.
[0050] In this context, the host project refers to the project that serves as the main program or runtime environment, often simply called the host. It depends on or integrates other modules, libraries, SDKs (Software Development Kits), etc., to form a complete functional system. In cross-project builds, the host project is the main project that integrates other modules. For example, in a smart spreadsheet application scenario, the host project can be the outer framework of the smart spreadsheet; similarly, in an online shopping platform application scenario, the host project can be the outer framework of the online shopping platform. The host project source code can be the source code of the host project, and project build processes can be performed based on the host project's source code. Module import instructions are instructions that require importing independent functional modules; that is, the host project source code can declare the independent functional modules that need to be imported through module import instructions. Independent functional modules are reusable independent modules, such as SDKs. In cross-project builds, independent functional modules can be integrated by the host project. For example, in a smart spreadsheet application scenario, independent functional modules include the core editor module of the smart spreadsheet; similarly, in an online shopping platform application scenario, independent functional modules include at least one of the following: order service module, payment service module, and logistics service module. The source code path refers to the path where the source code files of an independent functional module are located. Following the source code path allows you to directly obtain the source code files of the independent functional module. The module import path is the import path declared for the independent functional module in the module import directive. It can include path aliases for the independent functional module, or it can include the module name written in the code.
[0051] For example, the server can determine the host project that needs to undergo project build processing and determine the host project's source code. The server can then trigger build processing for the host project based on the host project's source code. Project build refers to the process of converting source code into static resources that can run in a production environment. The source code may include code in formats such as .ts (TypeScript files), .jsx (JavaScript XML files), and .scss (SCSS files); static resources may include .js (JavaScript files), .css (Cascading Style Sheets), and .html (HyperText Markup Language files). In some embodiments, the project build process may include operations such as compiling, packaging, optimizing, and compressing the source code, as well as processing and integrating various resources (such as images, fonts, style sheets, etc.).
[0052] The server can read instructions from the host project's source code. When it reads module import instructions included in the host project's source code, it indicates that an external independent functional module needs to be imported. The server can determine the source code path of the independent functional module identified by the module import instruction. The independent functional module identified by the module import instruction is the independent functional module that needs to be imported into the host project as declared by the module import instruction. For example, the module import instruction can be `import from '@pingtai1 / smartsheet-sdk'`, indicating that the external independent functional module `smartsheet-sdk` needs to be imported. Here, `import` is a keyword used to import variables, functions, classes, or types exported from other modules (files). In the Webpack bundling tool, Webpack parses the `import` statement and bundles the module into the final output. The source code path of the independent functional module can be obtained by mapping and redirecting the module import path for the independent functional module. In front-end development, module redirection is a technique that forcibly changes the module resolution path through configuration. Based on redirection, the module import path can be directly mapped to a specified local source code directory, i.e., redirected to the source code path. In some embodiments, the server can determine the independent functional modules to be imported based on the module import instruction and determine the module import path of the independent functional modules. The server can map the module import path to redirect the module import path to the source code path, so that the source code file of the independent functional module can be directly obtained through the source code path for compilation.
[0053] Step 204: Obtain the source code files of the independent functional modules from the source code path, compile the source code files, and obtain the compilation results of the independent functional modules.
[0054] The source code files can be the code files for independent functional modules, and the compilation result can be obtained by compiling the source code files of the independent functional modules. Optionally, the server can obtain the source code files of the independent functional modules according to the source code path and compile them, such as using tools like TypeScript Compiler (tsc), Babel, or Webpack, to obtain the compilation result of the independent functional modules. In some embodiments, the server can directly access the source code path to obtain the source code files of the independent functional modules and compile them, allowing the server to directly compile the source code files of the independent functional modules without compiling them first and then importing the compilation result into the host project source code. For example, if the source code path of the independent functional module smartsheet-sdk is determined to be ". / smart-sheet / packages / src / index.ts", the server can obtain the source code files of the independent functional module smartsheet-sdk based on this source code path and compile them to obtain the compilation result of the independent functional module smartsheet-sdk.
[0055] Step 206: Obtain the compilation results for project instructions in the host project source code. Project instructions include instructions in the host project source code other than module import instructions.
[0056] Project directives are all directives in the host project source code other than module import directives. Project directives do not need to import independent functional modules; they can handle only internal project dependencies. For example, the server can obtain the compilation results for project directives in the host project source code. In some embodiments, the server can directly perform compilation processing based on project directives in the host project source code, such as performing syntax conversion, module parsing and packaging, code optimization, and artifact generation sequentially to obtain the compilation results for the project directives.
[0057] Step 208: Based on the compilation results of the independent functional modules and the compilation results of the project instructions, generate the project build result of the host project corresponding to the host project source code.
[0058] The project build result refers to the build result obtained by building the host project corresponding to the host project source code. Optionally, the server can generate the project build result of the host project based on the compilation results of independent functional modules and the compilation results of project instructions. In some embodiments, the server can merge the compilation results of independent functional modules and the compilation results of project instructions to obtain the compilation result of the host project corresponding to the host project source code, and then perform various post-compilation processing such as packaging, optimization, compression, and resource integration on the compilation result of the host project to obtain the project build result of the host project.
[0059] In some embodiments, such as Figure 3 As shown, the host project source code can include module import directives that require importing independent functional modules, as well as project directives that do not require importing independent functional modules. For module import directives, the server can determine the source code path of the independent functional module identified by the directive, obtain the source code file of the independent functional module based on the source code path, and compile the source code file of the independent functional module to obtain the compilation result of the independent functional module. For project directives, the server can obtain the compilation result of the project directive, and can directly perform compilation processing on the project directive to obtain the compilation result of the project directive. The server can combine the compilation results of the independent functional modules and the compilation results of the project directives to generate the project build result of the host project.
[0060] In some embodiments, such as Figure 4 As shown, the host project's source code can include N instructions. During the project build process, the server can determine the type of each instruction, such as whether it's a module import instruction (requiring the import of independent functional modules) or a project instruction (not requiring the import of independent functional modules). Module import instructions and project instructions can be compiled in different ways to obtain corresponding compilation results. For example, instruction 1 includes module import instruction 1; the server can obtain source file 1 from the source code path of the independent functional module 1 identified by module import instruction 1 and compile it, thus obtaining compilation result 1 corresponding to instruction 1. Similarly, instruction 3 includes module import instruction 2; the server can obtain source file 2 from the source code path of the independent functional module 2 identified by module import instruction 2 and compile it, thus obtaining compilation result 3 corresponding to instruction 3. Likewise, instruction 2 includes project instruction 1; the server can directly compile based on project instruction 1 to obtain compilation result 2 corresponding to instruction 2. The server can combine the compilation results of each instruction to generate the overall project build result of the host project. For example, the server can generate the overall project build result of the host project based on the N compilation results obtained.
[0061] In the above project build process, for module import directives included in the host project source code, the source code path is determined after mapping and redirection of the module import path for the independent functional module identified by the module import directive. The source code file of the independent functional module is obtained from the source code path and compiled to obtain the compilation result of the independent functional module. This compilation result is then combined with the compilation results of project directives in the host project source code (excluding module import directives) to generate the project build result corresponding to the host project source code. During the project build process, for module import directives in the host project source code, the source code path is determined after mapping and redirection of the module import path for the independent functional module identified by the module import directive. The source code file of the independent functional module is obtained from the source code path and compiled directly, eliminating the need to encode the independent functional module separately and import it into the host project source code for project build, thereby improving the efficiency of project build processing.
[0062] In an exemplary embodiment, when the host project source code includes a module import instruction, determining the source code path of the independent functional module identified by the module import instruction includes: when the host project source code includes a module import instruction, determining the module import path of the independent functional module identified by the module import instruction; mapping the module import path of the independent functional module according to the alias mapping method to obtain the source code path of the independent functional module after redirection.
[0063] The module import path is the import path declared for an independent functional module in the module import directive. It can include path aliases for the independent functional module or the module name written in the code. Alias mapping is a technique that maps module paths to actual file system paths through configuration. Redirection is a technique that forcibly changes the module resolution path through configuration. Redirection can bypass the default lookup logic and directly map the module path to a specified local source code directory, thus determining the redirected source code path. For example, the module import directive can be `import from '@pingtai1t / xtable-core'`, indicating that the external independent functional module `xtable-core` needs to be imported. The module import path for the independent functional module `xtable-core` can be `@pingtai1t / xtable-core`, which is specifically the path alias of the independent functional module `xtable-core`.
[0064] For example, the server can compile instructions in the host project source code. For module import instructions included in the host project source code, the server can determine the module import path of the independent functional module identified by the module import instruction. In some embodiments, the server can directly analyze the module import instructions to determine the module import path of the identified independent functional module from the module import instructions. For example, the module name in the module import instructions can be determined as the module import path of the identified independent functional module. The server can map the module import path of the independent functional module. For example, it can map the module import path of the independent functional module according to the alias mapping method to redirect the module import path of the independent functional module, so as to obtain the source code path of the independent functional module after redirection. For example, for the module import path "@pingtai1t / xtable-core" of the independent functional module xtable-core, after the server performs mapping, the redirected source code path can be the physical path corresponding to the local SDK, specifically ".. / smart-sheet / src / packages / xtable-core / src".
[0065] In this embodiment, for module import instructions in the host project source code, the server maps the module import path of the independent functional module according to the alias mapping method to obtain the source code path of the independent functional module after redirection. This allows the module import path of the independent functional module to be directly mapped to the specified source code path, so that the source code file of the independent functional module can be obtained from the source code path for compilation. During the project build process, the processing of encoding the independent functional module and importing it into the host project source code can be skipped, thereby improving the processing efficiency of project build.
[0066] In one exemplary embodiment, such as Figure 5 As shown, the compilation process for source code files involves compiling the source code files to obtain the compilation results of independent functional modules, including:
[0067] Step 502: Determine the first module instruction of the independent functional module from the source code file. The first module instruction belongs to the instruction type of the imported module.
[0068] The first module directive is an import module directive, meaning that the first module directive of an independent functional module needs to import an external module. For example, the server can determine from the source code file that the first module directive belongs to the import module directive type, indicating that the first module directive needs to import an external module relative to the independent functional module. For instance, the first module directive could be `import React from 'react'`, indicating that the file in the requested path is the module `react`, meaning that when compiling for the independent functional module, the module `react` also needs to be imported.
[0069] Step 504: Determine the redirected path of the target module identified by the first module instruction. The redirected path is the path where the target module is redirected to the external dependency package directory of the host project source code.
[0070] Here, the target module is the module to be imported, identified by the first module directive, and the redirected path is the path that redirects the target module to the external dependency package directory of the host project's source code. The external dependency package directory is the core location in the host project's source code where project dependencies are stored; it may include the `node_modules` directory. By redirecting the target module to be imported to the external dependency package directory of the host project's source code, the source code files of the target module can be obtained and compiled based on the redirected path. For example, if the target module identified by the first module directive is the module `react`, its redirected path could be " / root / a / b / node_modules / react", where `node_modules` can be the external dependency package directory of the host project's source code.
[0071] Optionally, the server can determine the target module identified by the first module instruction. For example, the server can parse the instruction content of the first module instruction to determine the target module. The server can determine the redirected path of the target module, which is the path obtained by redirecting the target module to the external dependency package directory of the host project source code.
[0072] Step 506: Obtain the source code file of the target module from the redirected path, compile the source code file of the target module, and obtain the compilation result of the target module.
[0073] For example, the server can obtain the source code file of the target module according to the redirected path, and compile the obtained source code file to obtain the compilation result of the target module. For instance, the server can obtain the source code file of the target module "react" from the redirected path " / root / a / b / node_modules / react", and compile the source code file to obtain the compilation result of the target module "react".
[0074] Step 508: Based on the compilation results of the target module, obtain the compilation results of the independent functional modules.
[0075] Optionally, the server can obtain the compilation results of the independent functional modules based on the compilation results of the target module. For example, the server can obtain the compilation results of the independent functional modules based on the compilation results of the target module and the compilation results of other instructions in the source code files of the independent functional modules.
[0076] In this embodiment, for a first module instruction that belongs to the instruction type of an import module, the server obtains the source code file of the target module from the path after the first module instruction is redirected, and compiles the source code file of the target module to obtain the compilation result of the independent functional module. Thus, when compiling the source code file of the independent functional module and importing an external target module is required, the source code file can be obtained and compiled based on the path after the target module is redirected, avoiding the target module being re-imported into the source code file of the independent functional module after compilation, which helps to improve the compilation efficiency of the independent functional module.
[0077] In an exemplary embodiment, determining the redirected path of the target module identified by the first module instruction includes: determining the initial path of the target module identified by the first module instruction; redirecting the initial path of the target module to the external dependency package directory of the host project source code to obtain the redirected path of the target module.
[0078] The initial path can be the original path of the target module, such as " / root / a / b / c / scource.js". For example, the server redirects the initial path of the target module to an external dependency directory of the host project's source code, thus obtaining the redirected path of the target module. In some embodiments, the server can map the initial path of the target module to an external dependency directory of the host project's source code to achieve target module redirection and obtain the redirected path. For example, the server can redirect the initial path of the target module " / root / a / b / c / scource.js" of "react" to the "node_modules" directory of the host project's source code, thus obtaining the redirected path of the target module " / root / a / b / node_modules / react".
[0079] In this embodiment, the server redirects the initial path of the target module identified by the first module instruction to the external dependency package directory of the host project source code, thus obtaining the redirected path of the target module. The source code file can be obtained and compiled based on the redirected path of the target module, avoiding the target module being re-imported into the source code file of the independent functional module after compilation, which helps to improve the compilation efficiency of the independent functional module.
[0080] In an exemplary embodiment, redirecting the initial path of the target module to the external dependency package directory of the host project source code to obtain the redirected path of the target module includes: determining the directory tree corresponding to the external dependency package directory of the host project source code; traversing the directory tree sequentially from bottom to top to obtain candidate paths; obtaining the target candidate path based on the candidate paths including the source code files of the target module and the external dependency package directory; and redirecting the initial path of the target module to the target candidate path to obtain the redirected path of the target module.
[0081] The directory tree is a collection of directories related to the target module within the external dependency packages of the host project's source code. Specifically, it is obtained by traversing the external dependency packages from the bottom up based on the target module's initial path. Candidate paths are paths obtained by traversing each level of the directory tree. A candidate path can include at least one, and a determination can be made based on these candidate paths to identify the target candidate path that needs to be redirected for the target module.
[0082] For example, the server can determine the directory tree corresponding to the external dependency package directories of the host project's source code. For instance, the server can construct the directory tree based on the initial path of the target module and traverse the external dependency package directories. The server can traverse the directory tree sequentially from the bottom to the top, obtaining at least one candidate path. The server can then determine whether a candidate path includes the target module's source code files. The server can obtain the target candidate path based on the candidate path containing the target module's source code files and the external dependency package directories. For example, the server can append the external dependency package directories to the candidate path containing the target module's source code files to obtain the target candidate path. The server can redirect the target module's initial path to the target candidate path, thus obtaining the redirected path of the target module. For example, the server can establish a mapping relationship between the target module's initial path and the target candidate path, redirecting the target module's initial path to the target candidate path; specifically, the target candidate path can be used as the redirected path of the target module.
[0083] In this embodiment, the server obtains candidate paths by traversing the directory tree corresponding to the external dependency package directory of the host project source code, and obtains the target candidate path based on the candidate path including the source code file of the target module and the external dependency package directory. By redirecting the initial path of the target module to the target candidate path, the redirected path of the target module is obtained, so that the source code file can be obtained and compiled based on the redirected path of the target module. This avoids the target module being re-imported into the source code file of the independent functional module after compilation, which helps to improve the compilation efficiency of the independent functional module.
[0084] In an exemplary embodiment, redirecting the initial path of the target module to a target candidate path to obtain the redirected path of the target module includes: mapping the initial path of the target module to redirect the initial path of the target module to a target candidate path to obtain the redirected path of the target module.
[0085] Optionally, the server can map the initial path of the target module to redirect it to a target candidate path. For example, the server can establish a mapping relationship between the initial path of the target module and the target candidate path, thereby redirecting the initial path of the target module to the target candidate path and obtaining the redirected path of the target module. In some embodiments, the server can map the initial path of the target module to a dependency path in the host project. For example, when the requested path belongs to the directory of an independent functional module, it can be converted to the corresponding path under the node_modules directory of the host project, thereby enabling the correct referencing of the source code of the independent functional module in the host project.
[0086] In this embodiment, the server maps the initial path of the target module to redirect the initial path of the target module to the target candidate path, thereby obtaining the redirected path of the target module. This allows the source code file to be obtained and compiled based on the redirected path of the target module, avoiding the need for the target module to be re-imported into the source code file of the independent functional module after compilation, which helps to improve the compilation efficiency of the independent functional module.
[0087] In an exemplary embodiment, the project build process further includes: obtaining a description file for an external dependency package directory; determining file identifiers of files included in candidate paths from the description file; matching the file identifiers of files included in candidate paths with the source code files of the target module to obtain a matching result; and determining candidate paths including the source code files of the target module based on the matching result.
[0088] The description file can record the file identifiers of the files included in the candidate paths, such as file IDs (identifiers), which can serve as dependency paths for files. For example, in the package management tool pnpm, the description file can be a pnpm-lock.yaml file. Similarly, the module ID corresponding to the target module react-draggable@3.3.2 could be react-draggable@3.3.2(react-dom@16.14.0)(react@16.14.0). The matching results characterize the degree of correlation between the file identifiers of the files included in the candidate paths and the source code files of the target module.
[0089] For example, the server can obtain a description file for an external dependency package directory. This description file may record file identifiers, such as file IDs, of the files included in each path within the external dependency package directory. The server can determine the file identifiers of the files included in candidate paths from the description file. The server can match the file identifiers of the files included in the candidate paths with the source code files of the target module, for example, by matching the file identifiers of the files included in the candidate paths with the file identifiers of the source code files of the target module, to obtain matching results. Based on each matching result, the server can determine candidate paths that include the source code files of the target module. For example, a matching result that matches indicates that the file identifier of the file included in the candidate path corresponding to that matching result matches the source code file of the target module, meaning that the source code file of the target module exists in the files included in the candidate path, thus allowing the determination of candidate paths that include the source code files of the target module.
[0090] In this embodiment, the server determines the file identifiers of the files included in the candidate paths based on the description file of the external dependency package directory, matches the file identifiers of the files included in the candidate paths with the source code files of the target module, and determines the candidate paths including the source code files of the target module based on the matching results. Thus, the candidate paths including the source code files of the target module can be accurately determined based on the file identifiers included in the description file, which helps to ensure the accuracy of the redirected paths.
[0091] In an exemplary embodiment, matching the file identifiers of the files included in the candidate path with the source code files of the target module to obtain a matching result includes: converting the file identifiers of the files included in the candidate path to obtain the file names of the files included in the candidate path; determining the file name of the source code files of the target module; and performing field matching between the file name of the source code files of the target module and the file names of the files included in the candidate path to obtain a matching result.
[0092] The file identifier can include the file's ID. By converting the file identifier, the filename can be obtained. Optionally, the server can convert the file identifiers of files included in the candidate paths, thereby converting the file identifiers into filenames of the files included in the candidate paths. For example, when the file identifier is used as a dependency path of a file, the dependency path can be converted into a filename. This can be done through character substitution, length truncation, hash suffixes, etc., to convert any dependency path into a safe and unique filename, ensuring normal use in different operating systems and environments. This solves the file naming restrictions, length restrictions, and case sensitivity issues of different operating systems, ensuring that the generated filename can be used normally in various environments. The server can determine the filename of the target module's source code file and match the filename of the target module's source code file with the filenames of files included in the candidate paths to obtain the matching result.
[0093] In this embodiment, the server converts the file identifiers of the files included in the candidate path into file names and matches them with the file names of the source code files of the target module to obtain matching results. This ensures that accurate file names can be obtained through accurate file identifier conversion, thus guaranteeing the accuracy and reliability of the matching results.
[0094] In an exemplary embodiment, the project building process further includes: compiling based on the second module instructions of the independent functional module to obtain the compilation result of the second module instructions, wherein the second module instructions do not belong to the instruction type of the imported module; and obtaining the compilation result of the independent functional module based on the compilation result of the target module, including: obtaining the compilation result of the independent functional module according to the compilation result of the target module and the compilation result of the second module instructions.
[0095] The second module instructions are not of the type of instructions used to import modules; that is, they do not require importing external modules and can be directly compiled. For example, for the second module instructions of an independent functional module, the server can compile based on the second module instructions to obtain the compilation result. In some embodiments, the source code file of the independent functional module may include second module instructions that are not of the type of instructions used to import modules, and the server can directly compile based on these instructions to obtain the compilation result. The server can obtain the compilation result of the independent functional module based on the compilation result of the target module and the compilation result of the second module instructions. For example, the server can merge the compilation results of the target module and the second module instructions to obtain the compilation result of the independent functional module.
[0096] In this embodiment, for second module instructions that do not belong to the instruction type of the import module, the server can compile based on the second module instructions to obtain the compilation result of the second module instructions, and combine it with the compilation result of the target module to obtain the compilation result of the independent functional module. This makes it possible to improve the compilation efficiency of the independent functional module without importing the compilation products of the external module.
[0097] In an exemplary embodiment, compiling based on the second module instructions of an independent functional module to obtain the compilation result of the second module instructions includes: determining the request path corresponding to the second module instructions of the independent functional module; determining the concatenation path according to the path type of the request path; obtaining the access path of the second module instructions according to the request path and the concatenation path; and compiling the second module instructions based on the access path to obtain the compilation result of the second module instructions.
[0098] The request path is the path to the file that the second module instruction needs to access. The concatenated path is determined based on the path type of the request path; different path types can correspond to different concatenated paths. The access path is the path that the second module instruction can access, obtained from the request path and the concatenated path.
[0099] Optionally, the server can determine the request path corresponding to the second module instruction of the independent functional module. For example, the server can parse the second module instruction to obtain the request path from it. The server can determine the path type of the request path, such as root directory path type and relative path type. The server can determine the concatenated path based on the path type. For example, for root directory path type, the concatenated path can be obtained based on the root directory; for relative path type, the server can obtain the concatenated path based on the current path of the file to be accessed by the second module instruction. The server can obtain the access path of the second module instruction based on the request path and the concatenated path. For example, the server can concatenate the concatenated path into the request path to obtain the access path of the second module instruction. The server can compile the second module instruction based on the access path. For example, the server can obtain the file to be compiled by the second module instruction according to the access path and compile the obtained file to obtain the compilation result of the second module instruction.
[0100] In some embodiments, if the request path corresponding to the second module directive begins with " / ", such as / a / b / c, it indicates a file starting with the root directory, meaning the request path type is a root directory path. The server can use the RootsPlugin plugin with Webpack to append the root directory to the file path, resulting in the access path / root / a / b / c. If the request path corresponding to the second module directive begins with ".", such as . / b / c, it indicates a file with a relative path, meaning the request path type is a relative path. The server can use the JoinRequestsPlugin plugin with Webpack to concatenate the concatenated path with the request path, resulting in the access path / root / a / b / c.
[0101] In this embodiment, the server determines the concatenation path according to the path type of the request path corresponding to the second module instruction, obtains the access path based on the concatenation path and the request path, and compiles the second module instruction based on the access path to obtain the compilation result of the second module instruction, which can achieve accurate and reliable compilation processing for the second module instruction.
[0102] In an exemplary embodiment, the project build result of the host project corresponding to the host project source code is generated based on the compilation results of the independent functional modules and the compilation results of the project instructions. This includes: merging the compilation results of the independent functional modules and the compilation results of the project instructions to obtain the compilation result of the host project source code; and performing post-compilation processing based on the compilation result of the host project source code to generate the project build result of the host project corresponding to the host project source code.
[0103] Post-compilation processing refers to the processing performed on the compiled results during the project build process. This can include, but is not limited to, various post-compilation processes such as packaging, optimization, compression, and resource integration. For example, the server can merge the compilation results of independent functional modules and the compilation results of project instructions to obtain the compilation result of the host project source code. The server can then perform post-compilation processing on the compilation result of the host project source code, such as sequentially performing packaging, optimization, compression, and resource integration, thereby generating the project build result of the host project corresponding to the host project source code.
[0104] In this embodiment, the server integrates the compilation results of independent functional modules and the compilation results of project instructions, and then performs post-compilation processing to generate the project build result of the host project. This eliminates the need to encode the independent functional modules and import them into the host project source code for project building, thus improving the efficiency of project building.
[0105] This application also provides an application scenario in which the above-described project building processing method is applied. Specifically, the application of the project building processing method in this scenario is as follows:
[0106] The host project can be an online shopping application. For module import directives included in the host project's source code, the server can determine the redirected source code path after mapping the module import path of the independent functional module identified by the module import directive. The independent functional module can be a mobile payment service module. The server can obtain the source code file of the independent functional module from the source code path, compile it, obtain the compilation result of the independent functional module, and combine it with the compilation results of project directives in the host project's source code other than module import directives to generate the project build result of the host project corresponding to the host project's source code.
[0107] This application also provides an application scenario in which the above-described project building processing method is applied. Specifically, the application of the project building processing method in this scenario is as follows:
[0108] This application scenario involves cross-project front-end application building, specifically the building of a smart spreadsheet front-end project. In this application scenario:
[0109] Host: Generally refers to the main project that integrates other modules when building across projects. For example, in a smart spreadsheet, it is its outer framework.
[0110] SDK: Generally refers to an independent module that is integrated into the host when building across projects. For example, in a smart spreadsheet, it is its core editor module.
[0111] Webpack: A static module bundler for modern JavaScript applications. It treats various resources in a project, such as JavaScript files, CSS files, images, fonts, etc., as modules, analyzes and processes them according to the dependencies between modules, and finally bundles these modules into optimized static resources for efficient loading and running in the browser.
[0112] Module resolution: In the context of build tools like Webpack, resolution refers to the process of converting module import statements (such as import or require) into actual module paths and content. Webpack needs to use resolution to determine the location, dependencies, and correct loading and processing of each module.
[0113] Module redirection: Changes the default resolution path of a module, causing a reference that originally pointed to a certain module to be redirected to another module.
[0114] Build: In web (web page) development, the build process typically includes operations such as compiling, packaging, optimizing, and compressing code, as well as processing and integrating various resources (such as images, fonts, style sheets, etc.).
[0115] Pnpm: A fast and efficient JavaScript package manager, it is an alternative to npm (Node Package Manager) and yarn. Pnpm uses a unique storage and linking mechanism to more effectively manage dependencies in a project, reduce disk space usage, and improve installation speed.
[0116] When building front-end applications across projects, tools like npm linking or rsync are often used to map module artifact paths or copy module artifacts to the host project's node_modules directory, enabling joint debugging and integration. For the npm linking approach, the SDK project needs to build the artifacts first, and then cross-project building is achieved through npm linking's symbolic linking capabilities, but the overall build time is relatively long. For the rsync tool, the SDK project also needs to build the artifacts first, and then cross-project building is achieved through rsync's high-performance copying capabilities, but its overall build time is also relatively long.
[0117] Specifically, in building the front-end project for the smart sheet, the smart-sheet repository first needs to use Lerna to execute `tsc` on each sub-package, escaping TypeScript code into ES6 code. Then, the sheet repository uses `pnpm install` to install the code, and finally, webpack + swc is used to build a distributable code package. Lerna is a tool designed specifically for managing large JavaScript projects (containing multiple sub-packages), optimizing workflows and simplifying the management of multi-package repositories (monorepo). `tsc` is the command-line tool for the TypeScript compiler, used to compile TypeScript code (.ts or .tsx files) into JavaScript code (.js files). It is one of the core tools in the TypeScript ecosystem, responsible for converting typed TypeScript code into JavaScript code that can be executed by browsers or Node.js.
[0118] The pseudocode it executes is as follows:
[0119] In the smartsheet repository, execute `RSYNC=true npm run dev --copy-to-project=.. / sheet`
[0120] In the sheet repository, execute `npm run dev`.
[0121] In this approach, for the smartsheet repository, `npm run dev` triggers Lerna, the project management tool, to execute `tsc` (the command-line tool for the TypeScript compiler), compiling the TypeScript code of all sub-packages. The environment variable `RSYNC=true` enables file synchronization, and the compiled ES6 code is copied to the `.. / sheet` repository (the target path is specified via the `--copy-to-project` parameter). For the sheet repository, `pnpm install` is first executed to install dependencies (including sub-packages synchronized from smart-sheet), and then Webpack + SWC is used to bundle the code, generating a distributable code package (which may include the `dist` directory). This approach is cumbersome for developers, requiring the execution of different commands sequentially in both repository directories; otherwise, a synchronized build process cannot be completed.
[0122] Based on this, the project build process provided in this embodiment is user-friendly for developers. They only need to execute SS_PATH=.. / smart-sheet npm run dev in the sheet repository to achieve linked build. Specifically, it is based on Webpack and its core technology has been improved to achieve fully dynamic redirection capability of module parsing, thereby accelerating the build speed of large-scale front-end applications across projects.
[0123] like Figure 6 As shown, the smart table business scenario is complex, and the SDK kernel module needs to be integrated into multiple hosts, such as the table category, the independent smart table category, and the smart document category. Furthermore, it needs to be independently packaged and provided for cloud function calls to perform cloud tasks such as screenshotting and calculations. The SDK needs to achieve code reuse, dependency management, and update isolation in various scenarios. In practice, this integration mode has a certain impact on development efficiency, as the entire chain involves multiple levels of build tool relays, which is particularly time-consuming in scenarios with frequent code modifications. Specifically, the SDK kernel module needs to run in multiple different host environments, including the table category (basic table functionality), the independent smart table category (enhanced table functionality, which can include advanced calculations and visualizations), and the smart document category (used as part of a document, mixed with text, charts, etc.). In addition, the SDK needs to be packaged into an independent module for cloud function calls to perform tasks such as generating image previews of tables and performing complex formula calculations on the server side.
[0124] like Figure 7 As shown, multiple sub-modules within the SDK, i.e., SKD sub-packages, first need to undergo code transformation using Lerna and TSC (TypeScript) to build ES6 modules. Then, rsync is used to copy the artifacts to the corresponding modules in the host directory's `node_modules`. Finally, the host uses Webpack to perform a full compilation based on the host code and SDK artifacts to generate the final artifacts. Artifacts refer to intermediate or final files generated during the build process. In the SDK build process, artifacts specifically refer to the distributable files generated after compilation and packaging. These files are passed to the next stage for further processing or used directly for deployment. `node_modules` is the directory where Node.js projects store dependency packages; its functions include dependency storage, module resolution, and version isolation. Figure 8 As shown, the complete build time consists of three parts: SDK sub-package build, rsync copy, and host build. The time consumption of the complete build chain was tested. The average time for SDK sub-package build was 130 seconds, the average time for rsync copy was 32 seconds, and the average time for host build was 110 seconds, with a total average time of 272 seconds.
[0125] Since the SDK project itself originates from the host project and is completely identical in its underlying technology stack (e.g., React, TypeScript, Less, Workbench, etc.), the host project can recognize the SDK's source code without modifying any compilation options, and no longer needs its compiled artifacts. In other words, when the SDK is separated from the host project, because the technology stacks are completely identical, the host project can directly recognize and use the SDK's original source code without relying on its compiled artifacts (such as ES6 code). The project build process provided in this embodiment bypasses the SDK sub-package build and rsync copy process, allowing the host project to directly build the SDK's source code, thereby reducing this time-consuming process and improving the efficiency of project build.
[0126] Specifically, the AliasPlugin is first used to map the source code of each npm submodule (e.g., @tencent / xtable-core) to the corresponding physical path in the local SDK (e.g., .. / smart-sheet / src / packages / xtable-core / src). Here, the npm submodule can be a subpackage within the Monorepo architecture. With this configuration, the alias-mapped path will be prioritized for file addressing during the module resolution phase, rather than the normal node_modules dependency lookup process. Figure 9 As shown, in the Webpack source code, module resolution capability is implemented by the `enhanced-resolve` submodule, which controls the entire resolution process. When a developer configures an alias, Webpack will first use the `AliasPlugin` to attempt alias mapping. If the mapping is successful, it will then publish an `internal-resolve` event, thus skipping the `normal-resolve` event—that is, the normal `node_modules` dependency lookup process.
[0127] Furthermore, in the Webpack source code, module resolution capabilities are implemented by the `enhanced-resolve` submodule, which controls the entire resolution process. Webpack first performs pre-resolution processing on the request pathname:
[0128] If the request path starts with " / ", such as / a / b / c, it means that the file starts with the root directory. Webpack will use RootsPlugin to append the root directory to the file path, making it / root / a / b / c.
[0129] If the request path starts with ".", such as . / b / c, it means that the file is a relative path. Webpack will use JoinRequestsPlugin to concatenate the current file path with the request path, resulting in / root / a / b / c.
[0130] If the request path is a module, such as react, Webpack will use a custom plugin, specifically the ModulesInHierarchicalDirectoriesPlugin. Figure 10 As shown, the ModulesInHierarchicalDirectoriesPlugin first traverses the directory tree upwards based on the file path, generating a batch of addrs (relative candidate paths). Specifically, based on sourcee.js, it generates the first candidate path for retrieval: " / root / a / b / c / nede_modules / react"; based on / root / a / b / c, it generates the second candidate path: " / root / a / b / nede_modules / react"; based on / root / a / b, it generates the third candidate path: " / root / a / node_modules / react"; and based on / root / a, it generates the fourth candidate path: " / root / node_modules / react". After generating the addrs, it iterates through the candidate paths using the forEachBail function, performing file system operations on each candidate path to determine if it exists. If it does, it appends "node_modules" to the path and passes it to the hook with target="module", allowing the parsing process to continue downwards. The `ModulesInHierarchicalDirectoriesPlugin` file was added to the host directory, and the plugin was configured in the host Webpack to take precedence over built-in plugins. Subsequently, the code that generates relative candidate paths was modified to map them to the correct `node_modules` path in the host directory. By redirecting dependencies from the SDK directory back to the host's `node_modules` directory, dependency version consistency was ensured.
[0131] Furthermore, the method described above, which directly addresses modules from the `node_modules` directory, has a drawback: because the table host project uses pnpm as its package manager, the name of each module in the `node_modules / .pnpm` directory is not consistent with its original package name. Module addressing can be performed using name prefix matching; however, as... Figure 11As shown, pnpm imposes a 120-character length constraint on sub-package directory names, retaining only the first 93 characters and adding a 27-character hash at the end. If the package name matching the prefix exceeds 120 characters, it will cause the module to fail to be addressed correctly.
[0132] Therefore, it's necessary to obtain the accurate pnpm resolution path. First, parse the pnpm-lock.yaml file, still using name prefix matching to obtain the corresponding actual module ID. For example, the module ID corresponding to react-draggable@3.3.2 is react-draggable@3.3.2(react-dom@16.14.0)(react@16.14.0). Next, in the addressing function within the plugin, implement the logic from the pnpm source code to convert module IDs to file / directory names.
[0133] The project building process provided in this embodiment, such as Figure 12As shown, when the host directory parses the `@tencent / smartsheet-sdk` module, it is directly redirected by AliasPlugin to the source code location in the SDK directory. Conversely, when the source code in the SDK directory parses other modules, it is redirected back to the host's `node_modules` directory by the custom `ModulesInHierarchicalDirectoriesPlugin`, thus enabling direct compilation of SDK source code files. Specifically, for the module import command "import from '@pingtai1 / smartsheet-sdk'", the module import path is determined to be "@pingtai1 / smartsheet-sdk", and the server can directly redirect to the source code location in the SDK directory ". / smart-sheet / packages / src / index.ts" using AliasPlugin. For the first module directive of the `@tencent / smartsheet-sdk` module, "import from '@pingtai1 / chart'", the target module is `@pingtai1 / chart`. This can be redirected back to the host's `node_modules` directory, ". / sheet / node_modules / @pingtai1 / smartsheet-sdk / node_modules", using the custom `ModulesInHierarchicalDirectoriesPlugin`. The resulting redirected path is ". / sheet / node_modules / @pingtai1 / smartsheet-sdk / node_modules / @pingtai1 / chart". This redirected path supports multiple versions of the path. The first module directive of the `@tencent / smartsheet-sdk` module, "import from..." The path '@pingtai1 / workbench' can be redirected back to the host's node_modules directory ". / sheet / node_modules / @pingtai1 / smartsheet-sdk / node_modules" using the custom ModulesInHierarchicalDirectoriesPlugin, resulting in the redirected path ". / sheet / node_modules / @pingtai1 / workbench". This redirected path can use the same version.
[0134] like Figure 13As shown, in the host source code build mode, the average time is 136 seconds. Due to the increased amount of tsc code, this is higher than the original 110-second host build time. However, it saves the majority of time spent on SDK build and rsync synchronization, resulting in an overall time reduction of 50%. Besides the time reduction, the project build processing method provided in this embodiment eliminates the need for developers to execute rsync in the SDK directory for integration testing. They only need to focus on the host's own build execution, significantly improving development efficiency. Furthermore, the project build processing method provided in this embodiment allows the SDK to be independently released while adhering to npm semantic versioning specifications, and also maintains efficient monorepo-style integration testing with the main repository during the development phase, cleverly resolving the paradigm conflict between distributed modules and centralized development.
[0135] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0136] Based on the same inventive concept, this application also provides a project building processing apparatus for implementing the project building processing method described above. The solution provided by this apparatus is similar to the solution described in the above method; therefore, the specific limitations in one or more project building processing apparatus embodiments provided below can be found in the limitations of the project building processing method described above, and will not be repeated here.
[0137] In one exemplary embodiment, such as Figure 14 As shown, a project build processing device 1400 is provided, including: a source code path determination module 1402, an independent function module compilation module 1404, a project instruction compilation module 1406, and a compilation result processing module 1408, wherein:
[0138] The source code path determination module 1402 is used to determine the source code of the host project. When the source code of the host project includes a module import instruction, it determines the source code path of the independent functional module identified by the module import instruction. The source code path is a path that is redirected after mapping the module import path of the independent functional module.
[0139] Independent functional module compilation module 1404 is used to obtain the source code files of independent functional modules from the source code path, compile the source code files, and obtain the compilation results of independent functional modules.
[0140] Project instruction compilation module 1406 is used to obtain the compilation results of project instructions in the host project source code. Project instructions include instructions in the host project source code other than module import instructions.
[0141] The compilation result processing module 1408 is used to generate the project build result of the host project corresponding to the host project source code based on the compilation results of the independent functional modules and the compilation results of the project instructions.
[0142] In some embodiments, the source code path determination module 1402 is further configured to, when the host project source code includes a module import instruction, determine the module import path of the independent functional module identified by the module import instruction; and map the module import path of the independent functional module according to the alias mapping method to obtain the source code path of the independent functional module after redirection.
[0143] In some embodiments, the independent functional module compilation module 1404 is further configured to: determine a first module instruction of the independent functional module from the source code file, wherein the first module instruction belongs to the instruction type of the imported module; determine the redirected path of the target module identified by the first module instruction, wherein the redirected path is the path of the target module redirected to the external dependency package directory of the host project source code; obtain the source code file of the target module from the redirected path, and compile the source code file of the target module to obtain the compilation result of the target module; and obtain the compilation result of the independent functional module based on the compilation result of the target module.
[0144] In some embodiments, the independent functional module compilation module 1404 is further configured to determine the initial path of the target module identified by the first module instruction; redirect the initial path of the target module to the external dependency package directory of the host project source code to obtain the redirected path of the target module.
[0145] In some embodiments, the independent functional module compilation module 1404 is further configured to determine the directory tree corresponding to the external dependency package directory of the host project source code; traverse the directory tree sequentially from bottom to top to obtain candidate paths; obtain the target candidate path based on the candidate path including the source code file of the target module and the external dependency package directory; and redirect the initial path of the target module to the target candidate path to obtain the redirected path of the target module.
[0146] In some embodiments, the independent functional module compilation module 1404 is further configured to map the initial path of the target module to redirect the initial path of the target module to the target candidate path, thereby obtaining the redirected path of the target module.
[0147] In some embodiments, a candidate path matching module is further included, which is used to obtain a description file for an external dependency package directory; determine the file identifier of the file included in the candidate path from the description file; match the file identifier of the file included in the candidate path with the source code file of the target module to obtain a matching result; and determine the candidate path including the source code file of the target module based on the matching result.
[0148] In some embodiments, the candidate path matching module is further configured to convert the file identifier of the file included in the candidate path to obtain the file name of the file included in the candidate path; determine the file name of the source code file of the target module; and perform field matching between the file name of the source code file of the target module and the file name of the file included in the candidate path to obtain the matching result.
[0149] In some embodiments, the independent functional module compilation module 1404 is further configured to compile based on the second module instructions of the independent functional module, obtain the compilation result of the second module instructions, wherein the second module instructions do not belong to the instruction type of the importing module; and obtain the compilation result of the independent functional module based on the compilation result of the target module and the compilation result of the second module instructions.
[0150] In some embodiments, the independent functional module compilation module 1404 is further configured to determine the request path corresponding to the second module instruction of the independent functional module; determine the concatenation path according to the path type of the request path; obtain the access path of the second module instruction according to the request path and the concatenation path; and compile the second module instruction based on the access path to obtain the compilation result of the second module instruction.
[0151] In some embodiments, the compilation result processing module 1408 is further configured to merge the compilation results of independent functional modules and the compilation results of project instructions to obtain the compilation result of the host project source code; perform post-compilation processing based on the compilation result of the host project source code to generate the project build result of the host project corresponding to the host project source code.
[0152] The modules in the aforementioned project's processing device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the computer device's memory as software, so that the processor can invoke and execute the operations corresponding to each module.
[0153] In one exemplary embodiment, a computer device is provided, which may be a server or a terminal, and its internal structure diagram may be as follows. Figure 15As shown, this computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operating system and computer programs stored in the non-volatile storage media. The database stores various data such as host project source code, source code paths, module import paths, source code files, project instructions, compilation results, and project build results. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communication with external terminals via a network connection. When the computer program is executed by the processor, it implements a project build processing method.
[0154] Those skilled in the art will understand that Figure 15 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0155] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.
[0156] In one embodiment, a computer-readable storage medium is provided storing a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0157] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0158] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0159] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments described above. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, etc., and are not limited to these.
[0160] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0161] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A project construction processing method, characterized in that, The method includes: Determine the source code of the host project. If the source code of the host project includes a module import instruction, determine the source code path of the independent functional module identified by the module import instruction. The source code path is a path that is redirected after mapping the module import path of the independent functional module. Obtain the source code file of the independent functional module from the source code path, and compile the source code file to obtain the compilation result of the independent functional module; Obtain the compilation result for the project instructions in the host project source code, wherein the project instructions include instructions in the host project source code other than the module import instructions; Based on the compilation results of the independent functional modules and the compilation results of the project instructions, the project build result of the host project corresponding to the host project source code is generated.
2. The method according to claim 1, characterized in that, When the host project source code includes a module import instruction, determining the source code path of the independent functional module identified by the module import instruction includes: When the host project source code includes a module import instruction, determine the module import path of the independent functional module identified by the module import instruction; The module import path of the independent functional module is mapped according to the alias mapping method to obtain the source code path of the independent functional module after redirection.
3. The method according to claim 1, characterized in that, The process of compiling the source code file to obtain the compilation result of the independent functional module includes: The first module instruction of the independent functional module is determined from the source code file, and the first module instruction belongs to the instruction type of the imported module; Determine the redirected path of the target module identified by the first module instruction, wherein the redirected path is the path in the external dependency package directory of the host project source code to which the target module is redirected; Obtain the source code file of the target module from the redirected path, and compile the source code file of the target module to obtain the compilation result of the target module; Based on the compilation results of the target module, the compilation results of the independent functional module are obtained.
4. The method according to claim 3, characterized in that, Determining the redirected path of the target module identified by the first module instruction includes: Determine the initial path of the target module identified by the first module instruction; The initial path of the target module is redirected to the external dependency package directory of the host project source code, resulting in the redirected path of the target module.
5. The method according to claim 4, characterized in that, The step of redirecting the initial path of the target module to the external dependency package directory of the host project source code to obtain the redirected path of the target module includes: Determine the directory tree corresponding to the external dependency package directory of the host project source code; Based on the directory tree, candidate paths are obtained by traversing it sequentially from the bottom to the top. The target candidate path is obtained based on the candidate paths including the source code files of the target module and the external dependency package directories; The initial path of the target module is redirected to the target candidate path to obtain the redirected path of the target module.
6. The method according to claim 5, characterized in that, The step of redirecting the initial path of the target module to the target candidate path to obtain the redirected path of the target module includes: The initial path of the target module is mapped to redirect the initial path of the target module to the target candidate path, thereby obtaining the redirected path of the target module.
7. The method according to claim 5, characterized in that, The method further includes: Obtain the description file for the external dependency package directory; Determine the file identifiers of the files included in the candidate paths from the description file; The file identifiers of the files included in the candidate paths are matched with the source code files of the target module to obtain the matching results; Based on the matching results, candidate paths including the source code files of the target module are determined.
8. The method according to claim 7, characterized in that, The step of matching the file identifiers of the files included in the candidate paths with the source code files of the target module to obtain the matching results includes: The file identifiers of the files included in the candidate paths are converted to obtain the file names of the files included in the candidate paths; Determine the filename of the source code file of the target module; The filename of the source code file of the target module is matched with the filename of the file included in the candidate path to obtain the matching result.
9. The method according to claim 3, characterized in that, The method further includes: Compile based on the second module instructions of the independent functional module to obtain the compilation result of the second module instructions, wherein the second module instructions do not belong to the instruction type of the imported module; The compilation results of the independent functional modules obtained based on the compilation results of the target module include: The compilation result of the independent functional module is obtained based on the compilation result of the target module and the compilation result of the second module instructions.
10. The method according to claim 9, characterized in that, The compilation of the second module instructions based on the independent functional module to obtain the compilation result of the second module instructions includes: Determine the request path corresponding to the second module instruction of the independent functional module; The concatenated path is determined based on the path type of the requested path; The access path of the second module instruction is obtained based on the request path and the concatenated path; The second module instructions are compiled based on the access path to obtain the compilation result of the second module instructions.
11. The method according to any one of claims 1 to 10, characterized in that, The step of generating the project build result of the host project corresponding to the host project source code based on the compilation results of the independent functional modules and the compilation results of the project instructions includes: The compilation results of the independent functional modules and the compilation results of the project instructions are combined to obtain the compilation result of the host project source code; Post-compilation processing is performed based on the compilation results of the host project source code to generate the project build result of the host project corresponding to the host project source code.
12. A project construction processing device, characterized in that, The device includes: The source code path determination module is used to determine the source code of the host project. When the source code of the host project includes a module import instruction, it determines the source code path of the independent functional module identified by the module import instruction. The source code path is a path that is redirected after mapping the module import path of the independent functional module. An independent functional module compilation module is used to obtain the source code file of the independent functional module from the source code path, and compile the source code file to obtain the compilation result of the independent functional module; The project instruction compilation module is used to obtain the compilation results for the project instructions in the host project source code, wherein the project instructions include instructions in the host project source code other than the module import instructions; The compilation result processing module is used to generate the project build result of the host project corresponding to the host project source code based on the compilation results of the independent functional modules and the compilation results of the project instructions.
13. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 11.
14. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 11.
15. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 11.
