File processing method and device of applet, electronic equipment and storage medium
By generating hash objects to identify file dependencies in the mini-program and automatically repackaging them, the reliability issues caused by the mini-program's main package exceeding the size limit are resolved. This achieves accurate repackaging of dependent files and deletion of redundant files, thereby improving the operational reliability of the mini-program.
Patent Information
- Application Number
- CN202411120010.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-14
- Publication Date
- 2025-12-16
- Estimated Expiration
- 2044-08-14
AI Technical Summary
When the main package size of an existing mini-program exceeds the limit, the manual sub-package method is prone to errors, resulting in low operational reliability.
By generating hash objects, file dependencies are identified, and the paths of files that are dependent on by subpackages in the main package are automatically updated to the subpackage paths. Undependent files are deleted, and file write operations are performed using the updated hash objects, thus achieving automatic subpackaging of dependent files.
This reduces the error rate of dependency file sub-packages, lowers the chance of the main package size exceeding the limit, and improves the reliability of the mini-program.
Smart Images

Figure CN119025138B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a file processing method, apparatus, electronic device and storage medium for a small program. Background Technology
[0002] With the continuous development of the internet, mini-program technology has been incorporated into the daily services of various platforms. A mini-program is a lightweight application that can be used without downloading. To ensure smooth operation, a feature supporting sub-package loading has been introduced, which divides the mini-program into a main package and sub-packages. Users can load the sub-packages as needed, and the size of the main package and sub-packages is limited.
[0003] Public methods within the main package can be used in subpackages. As the mini-program iterates, the number of public methods in the main package increases. When the main package's size exceeds the limit, manual subpackage splitting is currently used. This involves copying the code from the main package to the subpackage in question. If multiple subpackages are using the same method, multiple copies of the code need to be made to the corresponding subpackages. Manual subpackage splitting is prone to errors, leading to lower reliability of the mini-program. Summary of the Invention
[0004] The main objective of this application is to provide a file processing method, apparatus, electronic device, and storage medium for mini-programs, aiming to improve the operational reliability of mini-programs.
[0005] To achieve the above objectives, a first aspect of this application proposes a file processing method for a mini-program, the method comprising:
[0006] Obtain a first hash object, wherein the first hash object includes key-value pairs corresponding to each file in the mini-program; the key in each key-value pair indicates the file path of the file, and the value in each key-value pair indicates the file content of the file;
[0007] Determine the file dependencies between the main package and sub-packages in the aforementioned mini-program;
[0008] Based on the file dependency relationships, determine the dependent files in the main package that are depended upon by the subpackage;
[0009] An update operation is performed on the first hash object, wherein the update operation includes: updating the path indicated by the key in the key-value pair corresponding to the dependent file in the first hash object to the path of the subpackage that depends on the dependent file;
[0010] Delete the file in the mini-program, and use the key-value pairs in the updated first hash object to perform the file write operation of the mini-program.
[0011] In some embodiments, after determining the file dependencies between the main package and sub-packages in the mini-program, the method further includes:
[0012] Based on the file dependencies, determine the files in the main package that are not dependent on.
[0013] After performing the file write operation of the mini-program using the key-value pairs in the updated first hash object, the method further includes:
[0014] Remove the undependent files from the applet.
[0015] In some embodiments, after determining the file dependencies between the main package and sub-packages in the mini-program, the method further includes:
[0016] Based on the file dependencies, determine the files in the main package that are not dependent on.
[0017] The update operation further includes:
[0018] Delete the key-value pairs in the first hash object that correspond to the undependent file.
[0019] In some embodiments, determining the file dependencies between the main package and sub-packages in the mini-program includes:
[0020] A second hash object is generated, wherein the second hash object includes key-value pairs corresponding to each JSON file in the mini-program; the key in each key-value pair indicates the file path of the JSON file, and the value in each key-value pair indicates the file content of the JSON file; the second hash object records the dependency relationship of each file in the mini-program through the file content indicated by the value of each key-value pair;
[0021] Analyze the global configuration file of the mini-program to identify the file package to which each file in the mini-program belongs, wherein the file package is the main package or a sub-package;
[0022] Based on the second hash object and the file packages to which each file in the mini-program belongs, the file dependencies between the main package and the sub-packages are determined.
[0023] In some embodiments, after determining the dependent files in the main package that the subpackage depends on based on the file dependencies, and before performing an update operation on the first hash object, the method further includes:
[0024] Generate a third hash object, wherein the third hash object includes key-value pairs corresponding to the dependent file; the key of the key-value pair corresponding to the dependent file indicates the path of the subpackage that depends on the dependent file, and the value of the key-value pair corresponding to the dependent file indicates the file path of the dependent file;
[0025] The step of updating the path indicated by the key in the key-value pair corresponding to each dependent file in the first hash object to the path of the subpackage that depends on the dependent file includes:
[0026] Update the value of the key in the key-value pair corresponding to the dependent file in the first hash object to the value of the key in the key-value pair corresponding to the dependent file in the third hash object.
[0027] In some embodiments, updating the path indicated by the key in the key-value pair corresponding to each dependent file in the first hash object to the path of the subpackage that depends on the dependent file includes:
[0028] Update the file paths of the dependent files in the main package to the paths of the subpackages that depend on the dependent files;
[0029] Using the updated paths of each dependent file in the main package, update the value of the key in the key-value pair corresponding to each dependent file in the first hash object.
[0030] In some embodiments, updating the file path of the dependent file in the main package to the path of the subpackage that depends on the dependent file includes:
[0031] Determine the file type corresponding to the dependent file;
[0032] By using the path modification method corresponding to the file type, the file path of the dependent file is updated to the path of the subpackage that depends on the dependent file.
[0033] To achieve the above objectives, a second aspect of this application provides a file processing apparatus for a mini-program, the apparatus comprising:
[0034] The acquisition module is used to acquire a first hash object, wherein the first hash object includes key-value pairs corresponding to each file in the mini-program; the key in each key-value pair indicates the file path of the file, and the value in each key-value pair indicates the file content of the file;
[0035] The first determining module is used to determine the file dependencies between the main package and sub-packages in the mini-program;
[0036] The second determining module is used to determine the dependent files in the main package that are depended on by the subpackage based on the file dependency relationship;
[0037] An update module is used to perform an update operation on the first hash object, wherein the update operation includes: updating the path indicated by the key in the key-value pair corresponding to the dependent file in the first hash object to the path of the subpackage that depends on the dependent file;
[0038] The execution module is used to delete files in the mini-program and perform file writing operations in the mini-program using key-value pairs in the updated first hash object.
[0039] To achieve the above objectives, a third aspect of the present application provides an electronic device, the electronic device including a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the method described in the first aspect.
[0040] To achieve the above objectives, a fourth aspect of the present application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described in the first aspect.
[0041] In this embodiment, a first hash object is provided, comprising key-value pairs corresponding to each file in the mini-program. In the first hash object, the key in each key-value pair indicates the file path of the file, and the value indicates the file content. After determining the file dependencies between the main package and sub-packages in the mini-program and identifying the dependent files that the sub-packages depend on in the main package, an update operation can be performed on the first hash object. This updates the path indicated by the key in each key-value pair corresponding to the dependent file in the first hash object to the path of the sub-package that depends on that dependent file. Then, the file in the mini-program is deleted, and the file write operation of the mini-program is performed using the key-value pairs in the updated first hash object. In this way, the dependent file will be written to the sub-package that depends on that dependent file, realizing automatic sub-packaging of dependent files. This reduces the error rate of sub-packaging of dependent files, thereby improving the reliability of sub-packaging and ultimately improving the operational reliability of the mini-program. Attached Figure Description
[0042] Figure 1 This is one of the flowcharts of the file processing method for the applet provided in the embodiments of this application;
[0043] Figure 2 This is the second flowchart of the file processing method for the mini-program provided in the embodiments of this application;
[0044] Figure 3 This is the third flowchart of the file processing method for the mini-program provided in the embodiments of this application;
[0045] Figure 4 This is the fourth flowchart of the file processing method for the mini-program provided in the embodiments of this application;
[0046] Figure 5 This is a schematic diagram of the structure of the file processing device for the mini-program provided in the embodiments of this application;
[0047] Figure 6 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0048] 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.
[0049] It should be noted that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, and the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0050] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0051] Artificial intelligence (AI) is a new branch of computer science that studies, develops, and applies theories, methods, technologies, and systems to simulate, extend, and expand human intelligence. It aims to understand the essence of intelligence and produce intelligent machines that can react in a way similar to human intelligence. Research in this field includes robotics, speech recognition, image recognition, natural language processing, and expert systems. AI can simulate the information processes of human consciousness and thought. Furthermore, AI utilizes digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceiving the environment, acquiring knowledge, and using that knowledge to achieve optimal results.
[0052] Natural Language Processing (NLP): NLP uses computers to process, understand, and utilize human language (such as Chinese and English). NLP is a branch of artificial intelligence and an interdisciplinary field of computer science and linguistics, often referred to as computational linguistics. NLP includes syntactic analysis, semantic analysis, and discourse understanding. It is commonly used in machine translation, handwritten and printed character recognition, speech recognition and text-to-speech conversion, intent recognition, information extraction and filtering, text classification and clustering, sentiment analysis, and opinion mining. It involves data mining, machine learning, knowledge acquisition, knowledge engineering, artificial intelligence research, and linguistic research related to language computation.
[0053] Information extraction is a text processing technique that extracts factual information such as entities, relationships, and events from natural language text and outputs it as structured data. Information extraction is a technique for extracting specific information from text data. Text data is composed of specific units, such as sentences, paragraphs, and chapters. Text information is composed of smaller, specific units, such as characters, words, phrases, sentences, paragraphs, or combinations of these units. Extracting noun phrases, names of people, and place names from text data is an example of text information extraction. Of course, text information extraction techniques can extract information of various types.
[0054] Image captioning generates natural language descriptions for images, helping applications understand the semantics expressed in the image's visual scene. For example, image captioning can convert image retrieval into text retrieval, classify images, and improve retrieval results. While people can often describe the details of an image's visual scene with a quick glance, automatically adding descriptions to images is a comprehensive and challenging computer vision task, requiring the conversion of complex information contained in the image into natural language descriptions. Compared to ordinary computer vision tasks, image captioning not only requires identifying objects in an image but also associating the identified objects with natural semantics and describing them in natural language. Therefore, image captioning requires extracting deep features from the image, associating them with semantic features, and converting them to generate descriptions.
[0055] The embodiments of this application can acquire and process relevant data based on artificial intelligence technology. AI refers to the theories, methods, technologies, and application systems that utilize digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results.
[0056] Foundational technologies for artificial intelligence generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies mainly encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.
[0057] The file processing method for the mini-program provided in this application embodiment can be applied to electronic devices such as terminals or servers, and can be executed by the electronic device or software or plug-ins in the electronic device. In some embodiments, the terminal can be a smartphone, tablet computer, laptop computer, desktop computer, etc.; the server can be configured as an independent physical server, or as a server cluster or distributed system composed of multiple physical servers, or as a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the file processing method of the mini-program, etc., but is not limited to the above forms.
[0058] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0059] It should be noted that in all specific embodiments of this application, when processing data related to user identity or characteristics, such as user information, user behavior data, user historical data, and user location information, user permission or consent is obtained first. Furthermore, the collection, use, and processing of this data comply with relevant laws, regulations, and standards. In addition, when embodiments of this application require access to sensitive personal information of users, separate permission or consent from the user is obtained through pop-ups or redirects to confirmation pages. Only after obtaining the user's separate permission or consent is the necessary user-related data required for the proper functioning of these embodiments acquired.
[0060] The following describes the file processing method of the mini-program provided in this application embodiment with reference to specific embodiments.
[0061] like Figure 1 As shown, the file processing method of the applet in this application embodiment may include the following steps:
[0062] Step 101: Obtain a first hash object, wherein the first hash object includes key-value pairs corresponding to each file in the mini-program; the key in each key-value pair indicates the file path of the file, and the value in each key-value pair indicates the file content of the file.
[0063] In this embodiment, a first hash object (file_contents) is provided, which includes key-value pairs corresponding to each file in the mini-program. In the first hash object, for each file, the key of its corresponding key-value pair indicates the current file path of that file, and the value of its corresponding key-value pair indicates the current file content of that file.
[0064] It is understandable that when a file in the mini-program is updated, the first hash object can be updated accordingly. Furthermore, updating a file in the mini-program can include at least one of the following: adding or removing files from the mini-program; changing the storage location of files in the mini-program; or changing the content of files in the mini-program.
[0065] In practice, the mini-program can be traversed to identify various files within it, such as js, json, wxml, wxss, and other resource files; then, based on the identified files, the first hash object can be constructed or updated.
[0066] Step 102: Determine the file dependencies between the main package and sub-packages in the mini-program.
[0067] In practice, dependency analysis can be performed on files within the main package and sub-packages of the mini-program to obtain the file dependencies between the main package and sub-packages. This application does not limit the method of performing dependency analysis on files; any method that can be used for dependency analysis falls within the protection scope of this application.
[0068] In a mini-program, the file dependencies between the main package and sub-packages can indicate at least one of the following:
[0069] Files in the main package that are dependent on the main package file;
[0070] Files that the subpackaged files in the main package depend on;
[0071] Files that are not dependent on in the main package.
[0072] In the embodiments of this application, dependency can also be understood as reference or use.
[0073] In one example, assume the mini-program includes a main package, sub-package 1, and sub-package 2. The main package includes files a, b, c, and d; sub-package 1 includes files e and f; and sub-package 2 includes file g.
[0074] If file a is dependent on files d and f; file b is dependent on file c; and file c is dependent on files f and g, then file a is a file in the main package that is dependent on by both main package files and subpackage files; file b is a file in the main package that is dependent on by the main package files; file c is a file in the main package that is dependent on by the subpackage files; and file d is a file in the main package that is not dependent on.
[0075] Step 103: Based on the file dependency relationship, determine the dependency files in the main package that are depended on by the subpackage.
[0076] In this embodiment of the application, in order to reduce the size of the main package, the files that the subpackaged files in the main package depend on, as indicated in the file dependency relationship, can be identified as dependent files that the subpackaged files in the main package depend on. Then, by executing steps 104 and 105, these dependent files are moved from the main package to the subpackage.
[0077] In practical applications, the number of dependent files can be greater than or equal to one. Each dependent file can be depended upon by at least one subpackage file. Furthermore, this at least one subpackage file can belong to the same subpackage or different subpackages. The subpackage files that depend on different dependent files can be the same or different, depending on the actual situation. This application does not limit this.
[0078] Step 104: Perform an update operation on the first hash object, wherein the update operation includes: updating the path indicated by the key in the key-value pair corresponding to the dependent file in the first hash object to the path of the subpackage that depends on the dependent file.
[0079] In this embodiment of the application, dependent files can be moved from the main package to the sub-package by maintaining a first hash object.
[0080] In practice, to move a dependency file from the main package to a subpackage, the path indicated by the key in the key-value pair corresponding to the dependency file in the first hash object can be updated from the current storage location of the dependency file to the path of the subpackage to which the subpackage file that depends on the dependency file belongs.
[0081] It is understandable that if a certain dependency file is depended on by files in n sub-packages, in order to maintain the normal operation of the mini-program, the dependency file needs to be moved to these n sub-packages. Therefore, after updating the first hash object, the key in the key-value pair corresponding to the dependency file indicates the address of the n sub-packages, where n is a positive integer.
[0082] Step 105: Delete the file in the mini-program, and use the key-value pairs in the updated first hash object to perform the file write operation of the mini-program.
[0083] As can be seen from the foregoing, the first hash object includes key-value pairs corresponding to each file in the mini-program, and the key in each key-value pair indicates the file path of the file, and the value indicates the file content of the file. Therefore, in this embodiment of the application, the updated first hash object can be used to perform file writing operations in the mini-program, overwriting or creating new files.
[0084] To move dependent files from the main package to the subpackage, in some embodiments, the dependent files can be first deleted from the mini-program, and then the dependent files can be rewritten in the mini-program using the key-value pairs of the dependent files in the updated first hash object. In other embodiments, all files in the mini-program can be deleted, and then the files in the mini-program can be rewritten using the updated first hash object. Compared to the latter, the former only processes the dependent files in the mini-program, thus reducing the number of files processed. Compared to the former, the latter does not need to distinguish between dependent files and other files, thus reducing the number of file processing steps.
[0085] It is understandable that, since the key-value pairs of the dependent files in the updated first hash object indicate the path to the corresponding sub-package, the dependent files will be written to the corresponding sub-package. In this way, the accuracy of the movement of dependent files can be guaranteed.
[0086] The file processing method for mini-programs in this embodiment includes a first hash object containing key-value pairs corresponding to each file in the mini-program. In the first hash object, the key in each key-value pair indicates the file path of that file, and the value indicates the file content. After determining the file dependencies between the main package and sub-packages in the mini-program and identifying the dependent files that the sub-packages depend on in the main package, an update operation can be performed on the first hash object. This updates the path indicated by the key in each key-value pair corresponding to the dependent file in the first hash object to the path of the sub-package that depends on that dependent file. Then, the file in the mini-program is deleted. Using the updated key-value pairs in the first hash object, a file write operation is performed in the mini-program. In this way, the dependent file will be written to the sub-package that depends on it, achieving automatic sub-packaging of dependent files. This reduces the error rate of dependent file sub-packaging, thereby improving the reliability of sub-packaging and ultimately improving the operational reliability of the mini-program. Furthermore, automatic sub-packaging of dependent files reduces the probability of the main package exceeding its size limit.
[0087] The file processing method of the applet in this application embodiment, in some embodiments, such as Figure 2 As shown, the following steps may be included:
[0088] Step 201: Obtain a first hash object, wherein the first hash object includes key-value pairs corresponding to each file in the mini-program; the key in each key-value pair indicates the file path of the file, and the value in each key-value pair indicates the file content of the file.
[0089] Step 202: Determine the file dependencies between the main package and sub-packages in the mini-program.
[0090] Step 203: Based on the file dependency relationship, determine the dependency files in the main package that are depended on by the subpackage.
[0091] For details on the implementation of steps 201 to 203, please refer to steps 101 to 103, which will not be repeated here.
[0092] Step 204: Based on the file dependency relationship, determine the files in the main package that are not dependent on.
[0093] In this embodiment, to further reduce the size of the main package, redundant files in the main package can be further deleted. In this embodiment, files in the main package that are not dependent on can be identified as redundant files.
[0094] In practice, files that are not depended on in the main package as indicated in the file dependency relationship can be identified as files that are not depended on in the main package. It can be understood that the number of files that are not depended on can be greater than or equal to 1.
[0095] The execution order of steps 203 and 204 is not limited in this application embodiment. It can be determined based on actual needs, and this application embodiment does not limit it.
[0096] Step 205: Perform an update operation on the first hash object, wherein the update operation includes: updating the path indicated by the key in the key-value pair corresponding to the dependent file in the first hash object to the path of the subpackage that depends on the dependent file.
[0097] Step 206: Delete the file in the mini-program, and use the key-value pairs in the updated first hash object to perform the file write operation of the mini-program.
[0098] For details on the implementation of steps 205 and 206, please refer to steps 104 and 105, which will not be repeated here.
[0099] Step 207: Delete the undependent files from the applet.
[0100] After identifying the undependencies in the main package, these files can be removed. This further reduces the likelihood of the main package exceeding its size limit, thereby improving the reliability of the mini-program.
[0101] The embodiments of this application do not limit the execution order of steps 205 and 206 for automatically subpackaging dependent files, and step 207 for automatically deleting redundant files. The specific execution order can be determined based on actual needs, and the embodiments of this application do not limit it.
[0102] As mentioned above, the file write operation of a mini-program can write files that include only dependent files or all files of the mini-program. When the file write operation only writes dependent files, steps 205 and 206 for automatic dependency file splitting, and step 207 for automatic deletion of redundant files, can be executed in parallel or sequentially. When the file write operation includes all files of the mini-program, the deletion operation for files not included in the dependency can be performed after the file write operation is completed.
[0103] Understandable, compared to Figure 1 Example, Figure 2 The embodiment can further remove redundant files in the main package. Thus, through this embodiment, both automatic subpackaging of dependent files and deletion of redundant files can be achieved, thereby reducing the probability of the main package size exceeding the limit and improving the reliability of the mini-program.
[0104] The file processing method of the applet in this application embodiment, in some embodiments, such as Figure 3 As shown. Figure 3 Examples and Figure 2 The main difference between the embodiments lies in the method of deleting undependent files. Figure 2 In this embodiment, the deletion of files not dependent on can be implemented independently of the first hash object; while Figure 3 In this embodiment, the deletion of files not dependent on can be implemented based on the first hash object, as detailed below.
[0105] like Figure 3 As shown, the file processing method of the applet in this application embodiment may include the following steps:
[0106] Step 301: Obtain a first hash object, wherein the first hash object includes key-value pairs corresponding to each file in the mini-program; the key in each key-value pair indicates the file path of the file, and the value in each key-value pair indicates the file content of the file.
[0107] Step 302: Determine the file dependencies between the main package and sub-packages in the mini-program.
[0108] Step 303: Based on the file dependency relationship, determine the dependency files in the main package that are depended on by the subpackage.
[0109] Step 304: Based on the file dependency relationship, determine the files in the main package that are not dependent on.
[0110] For details on the implementation of steps 301 to 304, please refer to steps 101 to 104, which will not be repeated here.
[0111] Step 305: Perform an update operation on the first hash object, wherein the update operation includes: updating the path indicated by the key in the key-value pair corresponding to the dependent file in the first hash object to the path of the subpackage that depends on the dependent file; deleting the key-value pair corresponding to the undependent file in the first hash object.
[0112] Compared to step 205, step 305 further includes updating the first hash object by deleting key-value pairs corresponding to files that are not dependent on it. In other words, the updated first hash object does not include key-value pairs corresponding to files that are not dependent on it in the main package.
[0113] Step 306: Delete the file in the mini-program, and use the key-value pairs in the updated first hash object to perform the file write operation of the mini-program.
[0114] In step 306, to delete the undependent files in the main package, all files in the mini-program can be deleted. Then, using the updated first hash object, the files are rewritten in the mini-program. It can be understood that since the updated first hash object does not include the key-value pairs corresponding to the undependent files in the main package, the files rewritten based on the updated first hash object will not include the undependent files in the main package, thus achieving the deletion of the undependent files. In this way, compared to... Figure 2 Example, Figure 3 The implementation does not require additional separate deletion operations for undependent files, thereby reducing the operational burden.
[0115] In this embodiment, for redundant files, the corresponding key-value pairs can be deleted from the first hash object, and then the updated first hash object can be used to rewrite the file of the applet to achieve automatic deletion of files that are not dependent on. In this way, the file processing steps can be reduced while minimizing the size of the main package, thereby reducing the running burden.
[0116] In some embodiments, step 102 may include:
[0117] A second hash object is generated, wherein the second hash object includes key-value pairs corresponding to each JSON file in the mini-program; the key in each key-value pair indicates the file path of the JSON file, and the value in each key-value pair indicates the file content of the JSON file; the second hash object records the dependency relationship of each file in the mini-program through the file content indicated by the value of each key-value pair;
[0118] Analyze the global configuration file of the mini-program to identify the file package to which each file in the mini-program belongs, wherein the file package is the main package or a sub-package;
[0119] Based on the second hash object and the file packages to which each file in the mini-program belongs, the file dependencies between the main package and the sub-packages are determined.
[0120] Considering that the content of the JSON file records the dependencies between various components, and that components consist of JS, JSON, WXML, and WXSS files, the dependencies between files in the mini-program can be determined through the content of the JSON file. Based on this, in this embodiment, a second hash object (file_dependencies) can be generated, containing key-value pairs corresponding to each JSON file in the mini-program. This second hash object records the file dependencies. In the second hash object, the key in each key-value pair indicates the file path of the JSON file, and the value indicates the file content of the JSON file.
[0121] Additionally, the global configuration file (app.json) of the mini-program can be analyzed to distinguish and mark information about the main packages (main_packages) and sub-packages (sub_packages), such as the file information included in the main packages and sub-packages. Based on the global configuration file, the relationship between files and sub-packages in the mini-program can be determined.
[0122] Then, the dependencies between files in the mini-program and the relationship between files and sub-packages in the mini-program can be determined based on the second hash object, and the file dependencies between the main package and sub-packages can be determined.
[0123] In this embodiment, the dependencies between files in the mini-program are determined by a second hash object that includes key-value pairs corresponding to each JSON file in the mini-program. The relationship between files and sub-packages in the mini-program is determined by analyzing the global configuration file of the mini-program. In this way, the file dependencies between the main package and sub-packages can be determined. This can improve the reliability of determining the file dependencies between the main package and sub-packages, thereby improving the operational reliability of the mini-program.
[0124] The following explains the update of the path indicated by the key in the key-value pairs corresponding to the dependent files in the first hash object.
[0125] In some embodiments, after determining the dependent files in the main package that are depended by the subpackage based on the file dependency relationship, and before performing an update operation on the first hash object, the method further includes:
[0126] Generate a third hash object, wherein the third hash object includes key-value pairs corresponding to the dependent file; the key of the key-value pair corresponding to the dependent file indicates the path of the subpackage that depends on the dependent file, and the value of the key-value pair corresponding to the dependent file indicates the file path of the dependent file;
[0127] The step of updating the path indicated by the key in the key-value pair corresponding to each dependent file in the first hash object to the path of the subpackage that depends on the dependent file includes:
[0128] Update the value of the key in the key-value pair corresponding to the dependent file in the first hash object to the value of the key in the key-value pair corresponding to the dependent file in the third hash object.
[0129] In some embodiments of this application, a third hash object (sub_outside_packages) can be further generated. This third hash object records relevant information about dependent files, such as the subpackage information corresponding to the dependent file. A subpackage corresponding to a certain dependent file can be understood as the subpackage to which the subpackage file that depends on that dependent file belongs. Then, the path information of the dependent files is updated using the relevant information about dependent files recorded in the third hash object.
[0130] In this embodiment, the third hash object may include key-value pairs corresponding to the dependent files. In the third hash object, the key in the key-value pair corresponding to a certain dependent file indicates the path of the subpackage to which the subpackage file that depends on the dependent file belongs, and the value indicates the file path of the dependent file.
[0131] Since the keys in the key-value pairs corresponding to the dependent files in the third hash object indicate the paths of their corresponding sub-packages, in this embodiment, the file paths of the dependent files can be updated by adjusting the values of the keys in the key-value pairs corresponding to the dependent files in the first hash object to match the values of the keys in the key-value pairs corresponding to the dependent files in the third hash object. This improves the reliability of updating the file paths of the dependent files.
[0132] In other embodiments, updating the path indicated by the key in the key-value pair corresponding to each dependent file in the first hash object to the path of the subpackage that depends on the dependent file includes:
[0133] Update the file paths of the dependent files in the main package to the paths of the subpackages that depend on the dependent files;
[0134] Using the updated paths of each dependent file in the main package, update the value of the key in the key-value pair corresponding to each dependent file in the first hash object.
[0135] In this embodiment, the file path of the dependent file can first be updated from the current file path to the path of its corresponding subpackage. Then, the value of the key in the key-value pair corresponding to the dependent file in the first hash object is updated using the updated path of the dependent file, so that the value of the key in the key-value pair corresponding to the dependent file in the first hash object indicates the updated path of the dependent file.
[0136] In specific implementations, in some embodiments, after determining the dependent files and their corresponding subpackages, the file paths of the dependent files in the main package can be directly updated to the paths of the subpackages that depend on the dependent files. In other embodiments, the file paths of the dependent files in the main package can be updated to the paths of the subpackages that depend on the dependent files based on a third hash object.
[0137] In this embodiment, the value of the key in the key-value pair corresponding to the dependent file in the first hash object is directly updated using the updated path of the dependent file, which simplifies the update of the file path of the dependent file.
[0138] Further, updating the file path of the dependent file in the main package to the path of the subpackage that depends on the dependent file includes:
[0139] Determine the file type corresponding to the dependent file;
[0140] By using the path modification method corresponding to the file type, the file path of the dependent file is updated to the path of the subpackage that depends on the dependent file.
[0141] In this embodiment, further considering that there are many different file types and the path modification methods for different file types may be different, in order to improve the reliability of updating the file paths of dependent files, the file type corresponding to each dependent file can be determined first, and then the path modification method corresponding to the file type of the dependent file can be used to update the file path.
[0142] Optionally, for JSON files, the path can be modified by changing the `usingComponents` field to point to a new relative path. For JavaScript files, the path can be modified by using `@babel / traverse` to traverse the Abstract Syntax Tree (AST) and replace the file path. For WXML and WXSS files, path replacement can be performed by comparing paths.
[0143] In this embodiment, for each dependent file, the file path is updated using the path modification method corresponding to its file type. This can improve the reliability of the file path update for dependent files.
[0144] It should be noted that each embodiment and implementation method in this application can be implemented independently or in combination without conflict with each other. The specific implementation method can be determined according to actual needs, and this application does not limit it.
[0145] To facilitate understanding, the following example is provided.
[0146] In this scenario embodiment, such as Figure 4 As shown, the following steps may be included:
[0147] Initial scan: Traverse the mini-program file package, identify configuration and resource files such as js, .json, wxml, wxss, etc., and construct a hash object file_contents, where the key is the file path and the value is the file content.
[0148] Dependency extraction: Filter all .json files from file_contents, parse these files to extract the dependencies between components, and form a new hash object file_dependencies to record the dependencies of each file.
[0149] Package structure identification: Analyze app.json to distinguish and mark the information of the main package (main_packages) and subpackages (sub_packages).
[0150] Dependency resolution: Based on file_dependencies and information about the main packages and subpackages, recursively analyze the dependencies of files within the main packages and subpackages, identify main package files that are not depended on by other files, and generate a list of redundant files (main_unused_packages), as well as main package files that are depended on by subpackage files, and generate sub_outside_packages.
[0151] File migration and processing: Move the main package dependency files listed in `sub_outside_packages` to the corresponding subpackage folders. Update the path information of these files based on `sub_outside_packages`. For JSON files, directly modify the `usingComponents` field to point to the new relative path; for JS files, use `@babel / traverse` to traverse the AST and replace the file paths; for WXML and WXSS files, directly replace the paths.
[0152] Content Update and Write: Update the information in file_contents based on the processed content. Then, iterate through file_contents and perform file write operations based on the latest key-value pairs, overwriting or creating new configuration and resource files.
[0153] Redundant file cleanup: Based on main_unused_packages, safely delete these files that are no longer needed.
[0154] In this scenario embodiment, the above method can be executed by the mini-program's automatic package splitting plugin, such as... Figure 4 As shown, the automatic package splitting plugin for mini programs can include a scanner, an analyzer, a resolver, a mover, and a cleaner.
[0155] In this embodiment, the mini-program automatic sub-package plugin only requires writing code once to achieve automatic sub-package of dependent files and automatic cleaning of redundant files. The code is highly maintainable, effectively avoiding repetitive code writing and reducing the chance of errors. In addition, the calling relationship between the main package and sub-packages is clear, and it can automatically remove and optimize unreferenced redundant code, reducing the overall code size.
[0156] Please see Figure 5 This application also provides a file processing device for a mini-program, which can implement the above-described file processing method for the mini-program. The device includes:
[0157] The acquisition module 501 is used to acquire a first hash object, wherein the first hash object includes key-value pairs corresponding to each file in the applet; the key in each key-value pair indicates the file path of the file, and the value in each key-value pair indicates the file content of the file;
[0158] The first determining module 502 is used to determine the file dependency relationship between the main package and sub-packages in the mini-program;
[0159] The second determining module 503 is used to determine the dependent files in the main package that are depended on by the subpackage based on the file dependency relationship;
[0160] The update module 504 is used to perform an update operation on the first hash object, wherein the update operation includes: updating the path indicated by the key in the key-value pair corresponding to the dependent file in the first hash object to the path of the subpackage that depends on the dependent file;
[0161] The execution module 505 is used to delete files in the mini-program and perform file writing operations in the mini-program using key-value pairs in the updated first hash object.
[0162] The file processing device for the applet in this application embodiment can implement each step of the above-described file processing method for applets and achieve the same beneficial effects, which will not be repeated here.
[0163] This application also provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the file processing method of the aforementioned applet. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.
[0164] Please see Figure 6 , Figure 6 The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes:
[0165] The processor 601 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application.
[0166] The memory 602 can be implemented as a read-only memory (ROM), static storage device, dynamic storage device, or random access memory (RAM). The memory 602 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 602, and the processor 601 calls and executes the file processing method of the applet in the embodiments of this application.
[0167] The input / output interface 603 is used to implement information input and output.
[0168] The communication interface 604 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).
[0169] Bus 605 transmits information between various components of the device (e.g., processor 601, memory 602, input / output interface 603, and communication interface 604).
[0170] The processor 601, memory 602, input / output interface 603 and communication interface 604 are connected to each other within the device via bus 605.
[0171] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the file processing method of the aforementioned applet.
[0172] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0173] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0174] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.
[0175] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0176] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.
[0177] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0178] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0179] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0180] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0181] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0182] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0183] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.
Claims
1. An applet file processing method characterized by comprising: The method comprises: obtaining a first hash object, wherein the first hash object comprises key-value pairs corresponding to files in the small program; the key in the key-value pair corresponding to each file indicates the file path of the file, and the value in the key-value pair corresponding to each file indicates the file content of the file; determining the file dependency relationship between the main package and the sub-package in the small program; determining the dependent file in the main package that is dependent on the sub-package according to the file dependency relationship; performing an update operation on the first hash object, wherein the update operation comprises: updating the path indicated by the key in the key-value pair corresponding to the dependent file in the first hash object to the path of the sub-package dependent on the dependent file; deleting the files in the small program, and performing a file write operation of the small program by using the key-value pairs in the updated first hash object; after determining the dependent file in the main package that is dependent on the sub-package according to the file dependency relationship, and before performing the update operation on the first hash object, the method further comprises: generating a third hash object, wherein the third hash object comprises key-value pairs corresponding to the dependent file; the key of the key-value pair corresponding to the dependent file indicates the path of the sub-package dependent on the dependent file, and the value of the key-value pair corresponding to the dependent file indicates the file path of the dependent file; updating the path indicated by the key in the key-value pair corresponding to each dependent file in the first hash object to the path of the sub-package dependent on the dependent file comprises: updating the value of the key in the key-value pair corresponding to the dependent file in the first hash object to the value of the key in the key-value pair corresponding to the dependent file in the third hash object.
2. The method of claim 1, wherein, after determining the file dependency relationship between the main package and the sub-package in the small program, the method further comprises: determining the un-dependent file in the main package according to the file dependency relationship; after performing the file write operation of the small program by using the key-value pairs in the updated first hash object, the method further comprises: deleting the un-dependent file from the small program.
3. The method of claim 1, wherein, after determining the file dependency relationship between the main package and the sub-package in the small program, the method further comprises: determining the un-dependent file in the main package according to the file dependency relationship; wherein the update operation further comprises: deleting the key-value pair corresponding to the un-dependent file in the first hash object.
4. The method of claim 1, wherein, determining the file dependency relationship between the main package and the sub-package in the small program comprises: generating a second hash object, wherein the second hash object comprises key-value pairs corresponding to each json file in the small program; the key in the key-value pair corresponding to each json file indicates the file path of the json file, and the value in the key-value pair corresponding to each json file indicates the file content of the json file; the second hash object records the dependency relationship between each file in the small program through the file content indicated by the value in each key-value pair; analyzing the global configuration file of the small program to identify the file package to which each file in the small program belongs, wherein the file package is a main package or a sub-package; According to the second hash object and file packages to which each file in the applet belongs, a file dependency relationship between the main package and the sub-package is determined.
5. The method of claim 1, wherein, The updating of the path indicated by the key in the key-value pair corresponding to each dependent file in the first hash object to the path of the sub-package dependent on the dependent file comprises: updating the file path of the dependent file in the main package to the path of the sub-package dependent on the dependent file; The updating of the file path of the dependent file in the main package to the path of the sub-package dependent on the dependent file comprises:
6. The method of claim 5, wherein, determining a file type corresponding to the dependent file; updating the file path of the dependent file to the path of the sub-package dependent on the dependent file by using a path modification manner corresponding to the file type. The apparatus comprises:
7. An applet file processing apparatus characterized by comprising: an obtaining module configured to obtain a first hash object, wherein the first hash object comprises key-value pairs corresponding to each file in the applet; the key in the key-value pair corresponding to each file indicates a file path of the file, and the value in the key-value pair corresponding to each file indicates file content of the file; a first determining module configured to determine a file dependency relationship between a main package and a sub-package in the applet; a second determining module configured to determine, according to the file dependency relationship, a dependent file in the main package dependent on the sub-package; an updating module configured to perform an updating operation on the first hash object, wherein the updating operation comprises updating, in the first hash object, a path indicated by the key in the key-value pair corresponding to the dependent file to a path of the sub-package dependent on the dependent file; an executing module configured to delete files in the applet and perform a file writing operation of the applet by using the key-value pairs in the updated first hash object; after the determination, according to the file dependency relationship, of the dependent file in the main package dependent on the sub-package, and before the performance of the updating operation on the first hash object, the method further comprises: generating a third hash object, wherein the third hash object comprises key-value pairs corresponding to the dependent file; the key in the key-value pair corresponding to the dependent file indicates the path of the sub-package dependent on the dependent file, and the value in the key-value pair corresponding to the dependent file indicates the file path of the dependent file; The updating of the path indicated by the key in the key-value pair corresponding to each dependent file in the first hash object to the path of the sub-package dependent on the dependent file comprises: updating, in the first hash object, the value of the key in the key-value pair corresponding to the dependent file to the value of the key in the key-value pair corresponding to the dependent file in the third hash object. The electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the file processing method of the applet in any one of claims 1 to 6 when executing the computer program.
8. An electronic device, comprising: The computer program is executed by the processor to implement the file processing method of the applet in any one of claims 1 to 6.
9. A computer-readable storage medium storing a computer program, the computer program comprising instructions that, when executed by a computer, cause the computer to perform the method of any one of claims 1 to 8.
Citation Information
Patent Citations
Applet local compiling method, device and equipment and computer readable storage medium
CN114003234A