mirror of
https://github.com/luau-lang/luau.git
synced 2025-01-09 21:09:10 +00:00
8f94786ceb
Some checks failed
benchmark / callgrind (map[branch:main name:luau-lang/benchmark-data], ubuntu-22.04) (push) Has been cancelled
build / macos (push) Has been cancelled
build / macos-arm (push) Has been cancelled
build / ubuntu (push) Has been cancelled
build / windows (Win32) (push) Has been cancelled
build / windows (x64) (push) Has been cancelled
build / coverage (push) Has been cancelled
build / web (push) Has been cancelled
release / macos (push) Has been cancelled
release / ubuntu (push) Has been cancelled
release / windows (push) Has been cancelled
release / web (push) Has been cancelled
This PR refactors the CLI folder to use the same project split between include and src directories that we have for all the other artifacts in luau. It also includes the require-by-string implementation we already have as a feature of `Luau.CLI.lib`. Both of these changes are targeted at making it easier for embedding projects to setup an effective equivalent to the standalone `luau` executable with whatever runtime libraries they need attached and without having to unnecessarily duplicate code from luau itself.
84 lines
No EOL
2.2 KiB
C++
84 lines
No EOL
2.2 KiB
C++
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
#pragma once
|
|
|
|
#include "Luau/Config.h"
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
class RequireResolver
|
|
{
|
|
public:
|
|
enum class ModuleStatus
|
|
{
|
|
Cached,
|
|
FileRead,
|
|
ErrorReported
|
|
};
|
|
|
|
struct ResolvedRequire
|
|
{
|
|
ModuleStatus status;
|
|
std::string identifier;
|
|
std::string absolutePath;
|
|
std::string sourceCode;
|
|
};
|
|
|
|
struct RequireContext
|
|
{
|
|
virtual ~RequireContext() = default;
|
|
virtual std::string getPath() = 0;
|
|
virtual bool isRequireAllowed() = 0;
|
|
virtual bool isStdin() = 0;
|
|
virtual std::string createNewIdentifer(const std::string& path) = 0;
|
|
};
|
|
|
|
struct CacheManager
|
|
{
|
|
virtual ~CacheManager() = default;
|
|
virtual bool isCached(const std::string& path)
|
|
{
|
|
return false;
|
|
}
|
|
};
|
|
|
|
struct ErrorHandler
|
|
{
|
|
virtual ~ErrorHandler() = default;
|
|
virtual void reportError(const std::string message) {}
|
|
};
|
|
|
|
RequireResolver(std::string pathToResolve, RequireContext& requireContext, CacheManager& cacheManager, ErrorHandler& errorHandler);
|
|
|
|
[[nodiscard]] ResolvedRequire resolveRequire(std::function<void(const ModuleStatus)> completionCallback = nullptr);
|
|
|
|
private:
|
|
std::string pathToResolve;
|
|
|
|
RequireContext& requireContext;
|
|
CacheManager& cacheManager;
|
|
ErrorHandler& errorHandler;
|
|
|
|
ResolvedRequire resolvedRequire;
|
|
bool isRequireResolved = false;
|
|
|
|
Luau::Config config;
|
|
std::string lastSearchedDir;
|
|
bool isConfigFullyResolved = false;
|
|
|
|
[[nodiscard]] bool initialize();
|
|
|
|
ModuleStatus findModule();
|
|
ModuleStatus findModuleImpl();
|
|
|
|
[[nodiscard]] bool resolveAndStoreDefaultPaths();
|
|
std::optional<std::string> getRequiringContextAbsolute();
|
|
std::string getRequiringContextRelative();
|
|
|
|
[[nodiscard]] bool substituteAliasIfPresent(std::string& path);
|
|
std::optional<std::string> getAlias(std::string alias);
|
|
|
|
[[nodiscard]] bool parseNextConfig();
|
|
[[nodiscard]] bool parseConfigInDirectory(const std::string& directory);
|
|
}; |