refactor(starmelon): update v8 dependecy
This commit is contained in:
parent
1c14fc146a
commit
95e21129a8
9 changed files with 894 additions and 338 deletions
|
|
@ -48,7 +48,6 @@ oneshot = "0.1.3"
|
|||
|
||||
# required for livetable derive macro
|
||||
livetable-core = { path = "../../../infra/livetable/core" }
|
||||
cargo-workspace-hack = { version = "0.1", path = "../../../infra/cargo-workspace-hack" }
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
|||
24
elm.json
Normal file
24
elm.json
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"src/reactor/ui"
|
||||
],
|
||||
"elm-version": "0.19.1",
|
||||
"dependencies": {
|
||||
"direct": {
|
||||
"elm/browser": "1.0.2",
|
||||
"elm/core": "1.0.5",
|
||||
"elm/html": "1.0.0",
|
||||
"elm/time": "1.0.0"
|
||||
},
|
||||
"indirect": {
|
||||
"elm/json": "1.1.3",
|
||||
"elm/url": "1.0.0",
|
||||
"elm/virtual-dom": "1.0.2"
|
||||
}
|
||||
},
|
||||
"test-dependencies": {
|
||||
"direct": {},
|
||||
"indirect": {}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
module Main exposing (view, view2, view3, view4, view5, view6, view7, view8, badReturnType, true)
|
||||
module Main exposing (view, view2, view3, view4, view5, view6, view7, view8, badReturnType, true, main)
|
||||
|
||||
import Html exposing (Html, div, text)
|
||||
import Svg exposing (Svg, svg)
|
||||
|
|
@ -6,6 +6,8 @@ import Array exposing (Array)
|
|||
import Bytes exposing (Bytes)
|
||||
import Bytes.Decode
|
||||
|
||||
main = text "main"
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ a : Int
|
||||
|
|
|
|||
187
src/derive/mod.rs
Normal file
187
src/derive/mod.rs
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
use crate::elm;
|
||||
use crate::reporting::{CompilerError, Problem, TypeError};
|
||||
|
||||
use livetable_core::{ColumnDefinition, ColumnType};
|
||||
use std::path::PathBuf;
|
||||
use tracing::info_span;
|
||||
|
||||
pub(crate) fn derive_livetable(
|
||||
file: PathBuf,
|
||||
debug: bool,
|
||||
_output: Option<PathBuf>,
|
||||
verbosity: u64,
|
||||
//sqlite_path: Option<PathBuf>,
|
||||
) -> Result<(), Problem> {
|
||||
// Our first elm make call is where we build the users program. There is a pretty good chance
|
||||
// this won't work.
|
||||
elm::make(&file, debug, verbosity)?;
|
||||
|
||||
// Step 2, find the elm.json and elm-stuff directory
|
||||
let elm_project_dir =
|
||||
elm::find_project_root("elm.json", "./").map_err(CompilerError::MissingElmJson)?;
|
||||
|
||||
let elm_cache_dir = elm_project_dir.join("elm-stuff").join("0.19.1");
|
||||
|
||||
if !elm_cache_dir.is_dir() {
|
||||
return Err(CompilerError::MissingElmStuff(elm_cache_dir).into());
|
||||
}
|
||||
|
||||
// step 2.5 get the module name out of the file.
|
||||
let data = std::fs::read(&file)
|
||||
.map_err(|io_err| CompilerError::ReadInputFailed(io_err, file.clone()))?;
|
||||
|
||||
let entrypoint = elmi::ModuleNameCanonical {
|
||||
package: elmi::PackageName::new("author", "project"),
|
||||
module: crate::elm::parse_module_name(&data)?,
|
||||
};
|
||||
|
||||
// step 3 find all the filepaths in the elm-stuff/0.19.1/* folder
|
||||
let interfaces = elm::load_interfaces(&elm_cache_dir)?;
|
||||
|
||||
// Step 5, check for the desired function
|
||||
let span = info_span!("resolved target function");
|
||||
let timing_guard = span.enter();
|
||||
|
||||
let mut targets = Vec::new();
|
||||
|
||||
match interfaces.get(&entrypoint) {
|
||||
Some(interface) => {
|
||||
// todo search over the interface.values for something that has the type of derive
|
||||
// macro
|
||||
for (_key, annotation) in interface.values.iter() {
|
||||
let elmi::CannonicalAnnotation(free_vars, tipe) = annotation;
|
||||
match tipe {
|
||||
elmi::Type::TType(module_name, name, args)
|
||||
if module_name == "author/project/LiveTable.Derive"
|
||||
&& name == "DeriveEditor" =>
|
||||
{
|
||||
if args.len() != 1 {
|
||||
// We probably have a version mismatch of the tool and library. But I
|
||||
// don't have any way of telling right now.
|
||||
panic!(
|
||||
"todo I don't understand how to parse the LiveTable Derive library"
|
||||
);
|
||||
}
|
||||
targets.push(resolve_table_argument(&args[0])?);
|
||||
if !free_vars.is_empty() {
|
||||
// We can't have free vars because that means we can't derive the serialize and
|
||||
// deserialize functions without concreate types. The table editor component is
|
||||
// not generic.
|
||||
//panic!("todo we can't have free vars in livetable derive macro");
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
if targets.is_empty() {
|
||||
return Err(CompilerError::MissingLiveTableDeriveMacroTarget(
|
||||
file.clone(),
|
||||
entrypoint.clone(),
|
||||
)
|
||||
.into());
|
||||
};
|
||||
//match interface.values.get(&entrypoint.1) {
|
||||
//Some(annotation) => {
|
||||
// let elmi::CannonicalAnnotation(_free_vars, tipe) = annotation;
|
||||
|
||||
// if is_astrid_pages_route(tipe) {
|
||||
// ExecutionMode::AstridPagesRoute
|
||||
// } else {
|
||||
// let (input_type, output_type) = scripting::resolve_function_type(tipe)?;
|
||||
// ExecutionMode::Scripting(input_type, output_type)
|
||||
// }
|
||||
//}
|
||||
//None => return Err(CompilerError::BadImport(entrypoint).into()),
|
||||
}
|
||||
None => return Err(CompilerError::MissingModuleTypeInformation(entrypoint).into()),
|
||||
}
|
||||
drop(timing_guard);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn resolve_table_argument(tipe: &elmi::Type) -> Result<i32, TypeError> {
|
||||
let mut columns = Vec::new();
|
||||
match tipe {
|
||||
// The `fields` field of TAlias is empty if it aliasing a record.
|
||||
elmi::Type::TAlias(_module_name, _type_name, _fields, ref alias) => match &**alias {
|
||||
elmi::AliasType::Filled(elmi::Type::TRecord(fields, _name)) => {
|
||||
//eprintln!("has field {} with type {:?}", field_name, field_type.tipe);
|
||||
eprintln!("todo resolve this type");
|
||||
// It seems the source_order is always 0. Not sure if there is a bug in my
|
||||
// deserializing code or if Evan stopped saving this value but kept the file
|
||||
// format.
|
||||
for (field_name, field_type) in fields.iter() {
|
||||
// check that column is acceptable
|
||||
match &*field_type.tipe {
|
||||
elmi::Type::TType(module_name, name, _args) => {
|
||||
if module_name == "elm/core/Basics" && name == "Bool" {
|
||||
columns.push(ColumnDefinition {
|
||||
name: field_name.to_string(),
|
||||
tipe: ColumnType::Bool,
|
||||
sync_protocol_identifier: field_name.to_string(),
|
||||
});
|
||||
} else if module_name == "elm/core/Basics" && name == "Int" {
|
||||
columns.push(ColumnDefinition {
|
||||
name: field_name.to_string(),
|
||||
tipe: ColumnType::BigInteger,
|
||||
sync_protocol_identifier: field_name.to_string(),
|
||||
});
|
||||
} else if module_name == "elm/core/String" && name == "String" {
|
||||
columns.push(ColumnDefinition {
|
||||
name: field_name.to_string(),
|
||||
tipe: ColumnType::String,
|
||||
sync_protocol_identifier: field_name.to_string(),
|
||||
});
|
||||
} else if module_name == "author/project/LiveTable.Types"
|
||||
&& name == "Email"
|
||||
{
|
||||
columns.push(ColumnDefinition {
|
||||
name: field_name.to_string(),
|
||||
tipe: ColumnType::Email,
|
||||
sync_protocol_identifier: field_name.to_string(),
|
||||
});
|
||||
} else if module_name == "elm/bytes/Bytes" && name == "Bytes" {
|
||||
} else if module_name == "author/project/LiveTable.Types"
|
||||
&& name == "Attachment"
|
||||
{
|
||||
} else {
|
||||
eprintln!("don't support field type yet {:?}\n\n", field_type.tipe);
|
||||
//return Err(TypeError::OutputTypeNotSupported(tipe.clone()));
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
eprintln!("don't support type yet {:?}\n\n", field_type.tipe);
|
||||
//return Err(TypeError::CantEvalType(tipe.clone()))
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(3)
|
||||
}
|
||||
elmi::AliasType::Filled(_tipe) => {
|
||||
// TODO correct error type
|
||||
Err(TypeError::CantEvalHoleyAlias)
|
||||
}
|
||||
elmi::AliasType::Holey(_) => Err(TypeError::CantEvalHoleyAlias),
|
||||
},
|
||||
_ => Err(TypeError::OutputTypeNotSupported(tipe.clone())),
|
||||
}
|
||||
}
|
||||
|
||||
//ColumnType::MaybeBool => Maybe Bool,
|
||||
//ColumnType::MaybeBigInteger => Maybe Int,
|
||||
//ColumnType::MaybeString => Maybe String,
|
||||
//ColumnType::Email => String,
|
||||
//ColumnType::MaybeEmail => Maybe String,
|
||||
//ColumnType::Url => String,
|
||||
//ColumnType::MaybeUrl => Maybe String,
|
||||
//ColumnType::Float => Float,
|
||||
//ColumnType::MaybeFloat => Maybe Float,
|
||||
//ColumnType::Double => Float,
|
||||
//ColumnType::MaybeDouble => Maybe Float,
|
||||
//ColumnType::Timestamp => #(posix_type.clone()),
|
||||
//ColumnType::MaybeTimestamp => Maybe #(posix_type.clone()),
|
||||
//ColumnType::ExactlyOneAttachment => LiveTable.Attachment,
|
||||
//ColumnType::MaybeAttachment => Maybe LiveTable.Attachment,
|
||||
//ColumnType::ListAttachment => List LiveTable.Attachment,
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::exec::astrid_pages::OutputType;
|
||||
use genco_extra::elm::Tokens;
|
||||
use genco::tokens::quoted;
|
||||
use genco_extra::elm::Tokens;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// I manually made this derived deserialize implementation match the elm json encoder output. The
|
||||
|
|
|
|||
|
|
@ -205,26 +205,26 @@ mod runtime {
|
|||
let options = WorkerOptions {
|
||||
bootstrap: BootstrapOptions {
|
||||
args: vec![],
|
||||
apply_source_maps: false,
|
||||
cpu_count: 1,
|
||||
debug_flag: false,
|
||||
enable_testing_features: false,
|
||||
is_tty: false,
|
||||
location: None,
|
||||
no_color: false,
|
||||
is_tty: false,
|
||||
runtime_version: "0.50.0".to_string(),
|
||||
ts_version: "2.0.0".to_string(),
|
||||
unstable: false,
|
||||
user_agent: "starmelon".to_string(),
|
||||
},
|
||||
extensions: extensions,
|
||||
unsafely_ignore_certificate_errors: None,
|
||||
root_cert_store: None,
|
||||
user_agent: "hello_runtime".to_string(),
|
||||
seed: None,
|
||||
module_loader,
|
||||
create_web_worker_cb,
|
||||
web_worker_preload_module_cb,
|
||||
js_error_create_fn: None,
|
||||
format_js_error_fn: None,
|
||||
source_map_getter: None,
|
||||
maybe_inspector_server: None,
|
||||
should_break_on_first_statement: false,
|
||||
get_error_class_fn: Some(&get_error_class_name),
|
||||
|
|
@ -233,6 +233,7 @@ mod runtime {
|
|||
broadcast_channel: InMemoryBroadcastChannel::default(),
|
||||
shared_array_buffer_store: None,
|
||||
compiled_wasm_module_store: None,
|
||||
stdio: deno_runtime::ops::io::Stdio::default(),
|
||||
};
|
||||
|
||||
let main_module = deno_core::resolve_path(path_str)?;
|
||||
|
|
@ -311,7 +312,7 @@ mod runtime {
|
|||
//let code = if let Some((ref source, _)) = is_data_uri {
|
||||
// source.to_string()
|
||||
//} else {
|
||||
let code = self.0.to_string();
|
||||
let code: Box<[u8]> = self.0.as_bytes().into();
|
||||
//};
|
||||
async move {
|
||||
//if is_data_uri.is_none() && module_specifier.to_string() != SPECIFIER {
|
||||
|
|
|
|||
36
src/reactor/ui/Router.elm
Normal file
36
src/reactor/ui/Router.elm
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
module Router exposing (fmain, Table)
|
||||
|
||||
import Html exposing (Html, text, div)
|
||||
import Time exposing (Posix)
|
||||
import Foo
|
||||
|
||||
fmain =
|
||||
text "Hello world"
|
||||
|
||||
type alias Table =
|
||||
{ target: String
|
||||
, path: String
|
||||
, start : Posix
|
||||
, end : Posix
|
||||
, status : Status
|
||||
}
|
||||
|
||||
type Status
|
||||
= Published
|
||||
| Draft
|
||||
|
||||
|
||||
-- You could write the type out for this, but it does not matter.
|
||||
--deriveTableEditor =
|
||||
-- DeriveTableEditor
|
||||
-- { containerAttributes =
|
||||
-- [ Livetable.Attributes.rename "foobar"
|
||||
-- ]
|
||||
-- , fieldAttributes =
|
||||
-- { target = [ columnName "Page" ]
|
||||
-- , path = [ columnName "Target"]
|
||||
-- , start = [ columnName "Start" ]
|
||||
-- , end = [ columnName "End" ]
|
||||
-- , status = [ columnName "Status" ]
|
||||
-- }
|
||||
-- }
|
||||
|
|
@ -256,7 +256,8 @@ impl CompilerError {
|
|||
vcat([to_message_bar(title, ""), Doc::text(""), message])
|
||||
}
|
||||
}
|
||||
|
||||
// Here is an example of an error message
|
||||
// ```
|
||||
// -- MODULE NAME MISMATCH ------------------------------ src/reactor/ui/Router.elm
|
||||
//
|
||||
// It looks like this module name is out of sync:
|
||||
|
|
@ -272,6 +273,7 @@ impl CompilerError {
|
|||
// easier to explore unfamiliar codebases! So if you want to keep the current
|
||||
// module name, try renaming the file instead.
|
||||
//
|
||||
// ```
|
||||
|
||||
impl InterpreterError {
|
||||
pub fn to_doc(&self) -> Doc {
|
||||
|
|
|
|||
963
src/transpile.rs
963
src/transpile.rs
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue