mirror of
https://github.com/lune-org/lune.git
synced 2025-05-04 10:43:57 +01:00
Bundle each typedefs file with its respective lune-std crate to fix publishing and cargo-binstall issues
This commit is contained in:
parent
58a65afc2c
commit
b147e83d3c
25 changed files with 148 additions and 108 deletions
|
@ -45,7 +45,7 @@ test-bin *ARGS:
|
|||
fmt:
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
stylua .lune scripts tests types \
|
||||
stylua .lune crates scripts tests \
|
||||
--glob "tests/**/*.luau" \
|
||||
--glob "!tests/roblox/rbx-test-files/**"
|
||||
cargo fmt
|
||||
|
@ -55,7 +55,7 @@ fmt:
|
|||
fmt-check:
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
stylua .lune scripts tests types \
|
||||
stylua .lune crates scripts tests \
|
||||
--glob "tests/**/*.luau" \
|
||||
--glob "!tests/roblox/rbx-test-files/**"
|
||||
cargo fmt --check
|
||||
|
@ -68,7 +68,7 @@ analyze:
|
|||
luau-lsp analyze \
|
||||
--settings=".vscode/settings.json" \
|
||||
--ignore="tests/roblox/rbx-test-files/**" \
|
||||
.lune scripts tests types
|
||||
.lune crates scripts tests
|
||||
|
||||
# Zips up the built binary into a single zip file
|
||||
[no-exit-message]
|
||||
|
|
27
Cargo.lock
generated
27
Cargo.lock
generated
|
@ -1133,12 +1133,6 @@ version = "0.27.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e05e7e6723e3455f4818c7b26e855439f7546cf617ef669d1adedb8669e5cb9"
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
||||
|
||||
[[package]]
|
||||
name = "h2"
|
||||
version = "0.3.26"
|
||||
|
@ -1413,26 +1407,6 @@ dependencies = [
|
|||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "include_dir"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "923d117408f1e49d914f1a379a309cffe4f18c05cf4e3d12e613a15fc81bd0dd"
|
||||
dependencies = [
|
||||
"glob",
|
||||
"include_dir_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "include_dir_macros"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7cab85a7ed0bd5f0e76d93846e0147172bed2e2d3f859bcc33a8d9699cad1a75"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.6.0"
|
||||
|
@ -1599,7 +1573,6 @@ dependencies = [
|
|||
"dialoguer",
|
||||
"directories",
|
||||
"futures-util",
|
||||
"include_dir",
|
||||
"lune-roblox",
|
||||
"lune-std",
|
||||
"lune-utils",
|
||||
|
|
|
@ -10,6 +10,16 @@ mod values;
|
|||
|
||||
pub use self::date_time::DateTime;
|
||||
|
||||
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||
|
||||
/**
|
||||
Returns a string containing type definitions for the `datetime` standard library.
|
||||
*/
|
||||
#[must_use]
|
||||
pub fn typedefs() -> String {
|
||||
TYPEDEFS.to_string()
|
||||
}
|
||||
|
||||
/**
|
||||
Creates the `datetime` standard library module.
|
||||
|
||||
|
|
|
@ -163,11 +163,7 @@ end
|
|||
@param locale -- The locale the time should be formatted in
|
||||
@return string -- The formatting string
|
||||
]=]
|
||||
function DateTime.formatUniversalTime(
|
||||
self: DateTime,
|
||||
formatString: string?,
|
||||
locale: Locale?
|
||||
): string
|
||||
function DateTime.formatUniversalTime(self: DateTime, formatString: string?, locale: Locale?): string
|
||||
return nil :: any
|
||||
end
|
||||
|
|
@ -17,6 +17,16 @@ use self::copy::copy;
|
|||
use self::metadata::FsMetadata;
|
||||
use self::options::FsWriteOptions;
|
||||
|
||||
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||
|
||||
/**
|
||||
Returns a string containing type definitions for the `fs` standard library.
|
||||
*/
|
||||
#[must_use]
|
||||
pub fn typedefs() -> String {
|
||||
TYPEDEFS.to_string()
|
||||
}
|
||||
|
||||
/**
|
||||
Creates the `fs` standard library module.
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
local DateTime = require("./datetime")
|
||||
--!nocheck
|
||||
|
||||
local DateTime = require("@lune/datetime")
|
||||
type DateTime = DateTime.DateTime
|
||||
|
||||
export type MetadataKind = "file" | "dir" | "symlink"
|
|
@ -8,6 +8,16 @@ mod options;
|
|||
|
||||
use self::options::{LuauCompileOptions, LuauLoadOptions};
|
||||
|
||||
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||
|
||||
/**
|
||||
Returns a string containing type definitions for the `luau` standard library.
|
||||
*/
|
||||
#[must_use]
|
||||
pub fn typedefs() -> String {
|
||||
TYPEDEFS.to_string()
|
||||
}
|
||||
|
||||
/**
|
||||
Creates the `luau` standard library module.
|
||||
|
||||
|
|
|
@ -22,6 +22,16 @@ use self::{
|
|||
|
||||
use lune_std_serde::{decode, encode, EncodeDecodeConfig, EncodeDecodeFormat};
|
||||
|
||||
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||
|
||||
/**
|
||||
Returns a string containing type definitions for the `net` standard library.
|
||||
*/
|
||||
#[must_use]
|
||||
pub fn typedefs() -> String {
|
||||
TYPEDEFS.to_string()
|
||||
}
|
||||
|
||||
/**
|
||||
Creates the `net` standard library module.
|
||||
|
||||
|
|
|
@ -22,6 +22,16 @@ mod options;
|
|||
|
||||
use self::options::ProcessSpawnOptions;
|
||||
|
||||
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||
|
||||
/**
|
||||
Returns a string containing type definitions for the `process` standard library.
|
||||
*/
|
||||
#[must_use]
|
||||
pub fn typedefs() -> String {
|
||||
TYPEDEFS.to_string()
|
||||
}
|
||||
|
||||
/**
|
||||
Creates the `process` standard library module.
|
||||
|
||||
|
|
|
@ -10,6 +10,16 @@ mod regex;
|
|||
|
||||
use self::regex::LuaRegex;
|
||||
|
||||
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||
|
||||
/**
|
||||
Returns a string containing type definitions for the `regex` standard library.
|
||||
*/
|
||||
#[must_use]
|
||||
pub fn typedefs() -> String {
|
||||
TYPEDEFS.to_string()
|
||||
}
|
||||
|
||||
/**
|
||||
Creates the `regex` standard library module.
|
||||
|
||||
|
|
|
@ -16,6 +16,16 @@ static REFLECTION_DATABASE: OnceLock<ReflectionDatabase> = OnceLock::new();
|
|||
use lune_utils::TableBuilder;
|
||||
use roblox_install::RobloxStudio;
|
||||
|
||||
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||
|
||||
/**
|
||||
Returns a string containing type definitions for the `roblox` standard library.
|
||||
*/
|
||||
#[must_use]
|
||||
pub fn typedefs() -> String {
|
||||
TYPEDEFS.to_string()
|
||||
}
|
||||
|
||||
/**
|
||||
Creates the `roblox` standard library module.
|
||||
|
||||
|
|
|
@ -183,10 +183,7 @@ export type DataModelMetatable = {
|
|||
|
||||
export type DataModel =
|
||||
Instance
|
||||
& typeof(setmetatable(
|
||||
(nil :: any) :: DataModelProperties,
|
||||
(nil :: any) :: { __index: DataModelMetatable }
|
||||
))
|
||||
& typeof(setmetatable((nil :: any) :: DataModelProperties, (nil :: any) :: { __index: DataModelMetatable }))
|
||||
|
||||
--[=[
|
||||
@class Roblox
|
||||
|
@ -491,11 +488,7 @@ end
|
|||
@param methodName The name of the method to implement.
|
||||
@param callback The function which will be called when the method is called.
|
||||
]=]
|
||||
function roblox.implementMethod(
|
||||
className: string,
|
||||
methodName: string,
|
||||
callback: (instance: Instance, ...any) -> ...any
|
||||
)
|
||||
function roblox.implementMethod(className: string, methodName: string, callback: (instance: Instance, ...any) -> ...any)
|
||||
return nil :: any
|
||||
end
|
||||
|
|
@ -13,6 +13,16 @@ pub use self::compress_decompress::{compress, decompress, CompressDecompressForm
|
|||
pub use self::encode_decode::{decode, encode, EncodeDecodeConfig, EncodeDecodeFormat};
|
||||
pub use self::hash::HashOptions;
|
||||
|
||||
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||
|
||||
/**
|
||||
Returns a string containing type definitions for the `serde` standard library.
|
||||
*/
|
||||
#[must_use]
|
||||
pub fn typedefs() -> String {
|
||||
TYPEDEFS.to_string()
|
||||
}
|
||||
|
||||
/**
|
||||
Creates the `serde` standard library module.
|
||||
|
||||
|
|
|
@ -139,11 +139,7 @@ end
|
|||
@param level The compression level to use, clamped to the format's limits. The best compression level is used by default
|
||||
@return The compressed string
|
||||
]=]
|
||||
function serde.compress(
|
||||
format: CompressDecompressFormat,
|
||||
s: buffer | string,
|
||||
level: number?
|
||||
): string
|
||||
function serde.compress(format: CompressDecompressFormat, s: buffer | string, level: number?): string
|
||||
return nil :: any
|
||||
end
|
||||
|
||||
|
@ -193,11 +189,7 @@ end
|
|||
@param message The message to hash
|
||||
@return The hash as a base64 string
|
||||
]=]
|
||||
function serde.hmac(
|
||||
algorithm: HashAlgorithm,
|
||||
message: string | buffer,
|
||||
secret: string | buffer
|
||||
): string
|
||||
function serde.hmac(algorithm: HashAlgorithm, message: string | buffer, secret: string | buffer): string
|
||||
return nil :: any
|
||||
end
|
||||
|
|
@ -33,6 +33,16 @@ static STDIN: LazyLock<Arc<AsyncMutex<BufReader<Unblock<Stdin>>>>> = LazyLock::n
|
|||
Arc::new(AsyncMutex::new(reader))
|
||||
});
|
||||
|
||||
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||
|
||||
/**
|
||||
Returns a string containing type definitions for the `stdio` standard library.
|
||||
*/
|
||||
#[must_use]
|
||||
pub fn typedefs() -> String {
|
||||
TYPEDEFS.to_string()
|
||||
}
|
||||
|
||||
/**
|
||||
Creates the `stdio` standard library module.
|
||||
|
||||
|
|
|
@ -1,13 +1,4 @@
|
|||
export type Color =
|
||||
"reset"
|
||||
| "black"
|
||||
| "red"
|
||||
| "green"
|
||||
| "yellow"
|
||||
| "blue"
|
||||
| "purple"
|
||||
| "cyan"
|
||||
| "white"
|
||||
export type Color = "reset" | "black" | "red" | "green" | "yellow" | "blue" | "purple" | "cyan" | "white"
|
||||
export type Style = "reset" | "bold" | "dim"
|
||||
|
||||
type PromptFn = (
|
|
@ -10,6 +10,16 @@ use mlua_luau_scheduler::Functions;
|
|||
|
||||
use lune_utils::TableBuilder;
|
||||
|
||||
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||
|
||||
/**
|
||||
Returns a string containing type definitions for the `task` standard library.
|
||||
*/
|
||||
#[must_use]
|
||||
pub fn typedefs() -> String {
|
||||
TYPEDEFS.to_string()
|
||||
}
|
||||
|
||||
/**
|
||||
Creates the `task` standard library module.
|
||||
|
||||
|
|
|
@ -58,11 +58,7 @@ end
|
|||
@param functionOrThread The function or thread to delay
|
||||
@return The thread that will be delayed
|
||||
]=]
|
||||
function task.delay<T...>(
|
||||
duration: number,
|
||||
functionOrThread: thread | (T...) -> ...any,
|
||||
...: T...
|
||||
): thread
|
||||
function task.delay<T...>(duration: number, functionOrThread: thread | (T...) -> ...any, ...: T...): thread
|
||||
return nil :: any
|
||||
end
|
||||
|
|
@ -61,6 +61,29 @@ impl LuneStandardLibrary {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Returns type definitions for the library.
|
||||
*/
|
||||
#[must_use]
|
||||
#[rustfmt::skip]
|
||||
#[allow(unreachable_patterns)]
|
||||
pub fn typedefs(&self) -> String {
|
||||
match self {
|
||||
#[cfg(feature = "datetime")] Self::DateTime => lune_std_datetime::typedefs(),
|
||||
#[cfg(feature = "fs")] Self::Fs => lune_std_fs::typedefs(),
|
||||
#[cfg(feature = "luau")] Self::Luau => lune_std_luau::typedefs(),
|
||||
#[cfg(feature = "net")] Self::Net => lune_std_net::typedefs(),
|
||||
#[cfg(feature = "task")] Self::Task => lune_std_task::typedefs(),
|
||||
#[cfg(feature = "process")] Self::Process => lune_std_process::typedefs(),
|
||||
#[cfg(feature = "regex")] Self::Regex => lune_std_regex::typedefs(),
|
||||
#[cfg(feature = "serde")] Self::Serde => lune_std_serde::typedefs(),
|
||||
#[cfg(feature = "stdio")] Self::Stdio => lune_std_stdio::typedefs(),
|
||||
#[cfg(feature = "roblox")] Self::Roblox => lune_std_roblox::typedefs(),
|
||||
|
||||
_ => unreachable!("no standard library enabled"),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Creates the Lua module for the library.
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ std = [
|
|||
"std-task",
|
||||
]
|
||||
|
||||
cli = ["dep:clap", "dep:include_dir", "dep:rustyline", "dep:zip_next"]
|
||||
cli = ["dep:clap", "dep:rustyline", "dep:zip_next"]
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
@ -76,6 +76,5 @@ lune-utils = { version = "0.1.3", path = "../lune-utils" }
|
|||
### CLI
|
||||
|
||||
clap = { optional = true, version = "4.1", features = ["derive"] }
|
||||
include_dir = { optional = true, version = "0.7", features = ["glob"] }
|
||||
rustyline = { optional = true, version = "14.0" }
|
||||
zip_next = { optional = true, version = "1.1" }
|
||||
|
|
|
@ -1,21 +1,15 @@
|
|||
use std::{
|
||||
borrow::BorrowMut, collections::HashMap, env::current_dir, io::ErrorKind, path::PathBuf,
|
||||
process::ExitCode,
|
||||
};
|
||||
use std::{borrow::BorrowMut, env::current_dir, io::ErrorKind, path::PathBuf, process::ExitCode};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use clap::Parser;
|
||||
use directories::UserDirs;
|
||||
use futures_util::future::try_join_all;
|
||||
use include_dir::{include_dir, Dir};
|
||||
use thiserror::Error;
|
||||
use tokio::fs;
|
||||
|
||||
// TODO: Use a library that supports json with comments since VSCode settings may contain comments
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
pub(crate) static TYPEDEFS_DIR: Dir<'_> = include_dir!("types");
|
||||
|
||||
pub(crate) static SETTING_NAME_MODE: &str = "luau-lsp.require.mode";
|
||||
pub(crate) static SETTING_NAME_ALIASES: &str = "luau-lsp.require.directoryAliases";
|
||||
|
||||
|
@ -25,7 +19,7 @@ pub struct SetupCommand {}
|
|||
|
||||
impl SetupCommand {
|
||||
pub async fn run(self) -> Result<ExitCode> {
|
||||
generate_typedef_files_from_definitions(&TYPEDEFS_DIR)
|
||||
generate_typedef_files_from_definitions()
|
||||
.await
|
||||
.expect("Failed to generate typedef files");
|
||||
|
||||
|
@ -142,31 +136,11 @@ fn add_values_to_vscode_settings_json(value: JsonValue) -> JsonValue {
|
|||
settings_json
|
||||
}
|
||||
|
||||
async fn generate_typedef_files_from_definitions(dir: &Dir<'_>) -> Result<String> {
|
||||
let contents = read_typedefs_dir_contents(dir);
|
||||
write_typedef_files(contents).await
|
||||
}
|
||||
|
||||
fn read_typedefs_dir_contents(dir: &Dir<'_>) -> HashMap<String, Vec<u8>> {
|
||||
let mut definitions = HashMap::new();
|
||||
|
||||
for entry in dir.find("*.luau").unwrap() {
|
||||
let entry_file = entry.as_file().unwrap();
|
||||
let entry_name = entry_file.path().file_name().unwrap().to_string_lossy();
|
||||
|
||||
let typedef_name = entry_name.trim_end_matches(".luau");
|
||||
let typedef_contents = entry_file.contents().to_vec();
|
||||
|
||||
definitions.insert(typedef_name.to_string(), typedef_contents);
|
||||
}
|
||||
|
||||
definitions
|
||||
}
|
||||
|
||||
async fn write_typedef_files(typedef_files: HashMap<String, Vec<u8>>) -> Result<String> {
|
||||
async fn generate_typedef_files_from_definitions() -> Result<String> {
|
||||
let version_string = env!("CARGO_PKG_VERSION");
|
||||
let mut dirs_to_write = Vec::new();
|
||||
let mut files_to_write = Vec::new();
|
||||
|
||||
// Create the typedefs dir in the users cache dir
|
||||
let cache_dir = UserDirs::new()
|
||||
.context("Failed to find user home directory")?
|
||||
|
@ -175,13 +149,14 @@ async fn write_typedef_files(typedef_files: HashMap<String, Vec<u8>>) -> Result<
|
|||
.join(".typedefs")
|
||||
.join(version_string);
|
||||
dirs_to_write.push(cache_dir.clone());
|
||||
|
||||
// Make typedef files
|
||||
for (builtin_name, builtin_typedef) in typedef_files {
|
||||
let path = cache_dir
|
||||
.join(builtin_name.to_ascii_lowercase())
|
||||
.with_extension("luau");
|
||||
files_to_write.push((builtin_name.to_lowercase(), path, builtin_typedef));
|
||||
for builtin in lune_std::LuneStandardLibrary::ALL {
|
||||
let name = builtin.name().to_lowercase();
|
||||
let path = cache_dir.join(&name).with_extension("luau");
|
||||
files_to_write.push((name, path, builtin.typedefs()));
|
||||
}
|
||||
|
||||
// Write all dirs and files only when we know generation was successful
|
||||
let futs_dirs = dirs_to_write
|
||||
.drain(..)
|
||||
|
|
Loading…
Add table
Reference in a new issue