1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_UTILS_JSI_MODULE_SEARCHER_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_UTILS_JSI_MODULE_SEARCHER_H 18 19 #include <string> 20 21 namespace OHOS::Ace::Framework { 22 class JsiModuleSearcher final { 23 public: 24 explicit JsiModuleSearcher(const std::string& bundleName, const std::string& assetPath); 25 ~JsiModuleSearcher() = default; 26 27 JsiModuleSearcher(const JsiModuleSearcher&) = default; 28 JsiModuleSearcher(JsiModuleSearcher&&) = default; 29 JsiModuleSearcher& operator=(const JsiModuleSearcher&) = default; 30 JsiModuleSearcher& operator=(JsiModuleSearcher&&) = default; 31 32 std::string operator()(const std::string& curJsModulePath, const std::string& newJsModuleUri) const; 33 34 private: 35 static void FixExtName(std::string& path); 36 std::string GetInstallPath(const std::string& curJsModulePath, bool module = true) const; 37 std::string MakeNewJsModulePath(const std::string& curJsModulePath, const std::string& newJsModuleUri) const; 38 std::string FindNpmPackageInPath(const std::string& npmPath) const; 39 std::string FindNpmPackageInTopLevel( 40 const std::string& moduleInstallPath, const std::string& npmPackage, size_t start = 0) const; 41 std::string FindNpmPackage(const std::string& curJsModulePath, const std::string& npmPackage) const; 42 std::string ParseOhmUri(const std::string& curJsModulePath, const std::string& newJsModuleUri) const; 43 44 std::string bundleName_; 45 std::string bundleInstallPath_; 46 }; 47 } // namespace OHOS::Ace::Framework 48 49 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_UTILS_JSI_MODULE_SEARCHER_H