@browsersync/bslive 0.0.9 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/Cargo.toml +3 -2
  2. package/bslive/src/lib.rs +8 -3
  3. package/bsnext/src/main.rs +9 -3
  4. package/crates/bsnext_client/generated/dto.ts +33 -2
  5. package/crates/bsnext_client/generated/schema.ts +52 -2
  6. package/crates/bsnext_client/{dist → inject/dist}/index.js +105 -58
  7. package/crates/bsnext_client/inject/package.json +12 -0
  8. package/crates/bsnext_client/{ts → inject/src}/index.ts +2 -2
  9. package/crates/bsnext_client/package-lock.json +89 -3
  10. package/crates/bsnext_client/package.json +4 -2
  11. package/crates/bsnext_client/src/lib.rs +10 -0
  12. package/crates/bsnext_client/tsconfig.json +8 -2
  13. package/crates/bsnext_client/ui/dist/index.css +78 -0
  14. package/crates/bsnext_client/ui/dist/index.js +997 -0
  15. package/crates/bsnext_client/{index.html → ui/index.html} +8 -4
  16. package/crates/bsnext_client/ui/input.yml +19 -0
  17. package/crates/bsnext_client/ui/package.json +18 -0
  18. package/crates/bsnext_client/ui/src/components/bs-debug.ts +27 -0
  19. package/crates/bsnext_client/ui/src/components/bs-header.ts +33 -0
  20. package/crates/bsnext_client/ui/src/components/bs-icon.ts +101 -0
  21. package/crates/bsnext_client/ui/src/components/bs-server-detail.ts +21 -0
  22. package/crates/bsnext_client/ui/src/components/bs-server-identity.ts +24 -0
  23. package/crates/bsnext_client/ui/src/components/bs-server-list.ts +39 -0
  24. package/crates/bsnext_client/ui/src/index.ts +39 -0
  25. package/crates/bsnext_client/ui/styles/base.css.ts +17 -0
  26. package/crates/bsnext_client/ui/styles/reset.css +52 -0
  27. package/crates/bsnext_client/ui/styles/style.css +29 -0
  28. package/crates/bsnext_client/ui/svg/wordmark-white.svg +38 -0
  29. package/crates/bsnext_core/Cargo.toml +1 -0
  30. package/crates/bsnext_core/src/common_layers.rs +62 -0
  31. package/crates/bsnext_core/src/dir_loader.rs +1 -1
  32. package/crates/bsnext_core/src/dto.rs +62 -2
  33. package/crates/bsnext_core/src/lib.rs +1 -0
  34. package/crates/bsnext_core/src/not_found/mod.rs +0 -1
  35. package/crates/bsnext_core/src/not_found/not_found_service.rs +5 -11
  36. package/crates/bsnext_core/src/raw_loader.rs +4 -34
  37. package/crates/bsnext_core/src/server/handler_listen.rs +10 -4
  38. package/crates/bsnext_core/src/server/router/assets.rs +39 -0
  39. package/crates/bsnext_core/src/server/router/mod.rs +15 -4
  40. package/crates/bsnext_core/src/server/router/pub_api.rs +39 -0
  41. package/crates/bsnext_core/src/server/router/snapshots/bsnext_core__server__router__tests__test__handlers.snap +9 -0
  42. package/crates/bsnext_core/src/server/router/tests.rs +11 -6
  43. package/crates/bsnext_core/src/server/state.rs +4 -0
  44. package/crates/bsnext_core/src/servers_supervisor/get_servers_handler.rs +3 -2
  45. package/crates/bsnext_core/src/servers_supervisor/start_handler.rs +5 -1
  46. package/crates/bsnext_fs/src/actor.rs +2 -1
  47. package/crates/bsnext_fs/src/filter.rs +14 -5
  48. package/crates/bsnext_fs/src/test/mod.rs +1 -1
  49. package/crates/bsnext_fs/src/watch_path_handler.rs +1 -1
  50. package/crates/bsnext_fs/src/watcher.rs +2 -1
  51. package/crates/bsnext_input/Cargo.toml +3 -0
  52. package/crates/bsnext_input/src/input_test/mod.rs +34 -0
  53. package/crates/bsnext_input/src/input_test/snapshots/bsnext_input__input_test__deserialize_3_headers.snap +29 -0
  54. package/crates/bsnext_input/src/input_test/snapshots/bsnext_input__input_test__deserialize_3_headers_control.snap +25 -0
  55. package/crates/bsnext_input/src/route.rs +4 -0
  56. package/crates/bsnext_output/src/pretty.rs +1 -1
  57. package/crates/bsnext_system/Cargo.toml +1 -1
  58. package/crates/bsnext_system/src/args.rs +5 -2
  59. package/crates/bsnext_system/src/monitor_any_watchables.rs +20 -14
  60. package/crates/bsnext_system/src/start_kind/snapshots/bsnext_system__start_kind__start_from_paths__test__test-2.snap +2 -1
  61. package/crates/bsnext_system/src/start_kind/snapshots/bsnext_system__start_kind__start_from_paths__test__test.snap +2 -1
  62. package/crates/bsnext_tracing/src/lib.rs +42 -4
  63. package/examples/kitchen-sink/input.yml +1 -1
  64. package/input.yml +8 -0
  65. package/package.json +17 -17
  66. package/crates/bsnext_client/style.css +0 -3
  67. package/crates/bsnext_core/src/not_found/not_found.html +0 -20
  68. package/crates/bsnext_core/src/not_found/route_list.rs +0 -49
  69. /package/crates/bsnext_client/{ts → inject/src}/console.ts +0 -0
@@ -0,0 +1,25 @@
1
+ ---
2
+ source: crates/bsnext_input/src/input_test/mod.rs
3
+ expression: c
4
+ ---
5
+ Config {
6
+ items: [
7
+ Route {
8
+ path: "/api",
9
+ cors_opts: None,
10
+ delay_opts: None,
11
+ watch_opts: Bool(
12
+ true,
13
+ ),
14
+ kind: Json {
15
+ json: JsonWrapper(
16
+ Array [
17
+ Number(1),
18
+ Number(2),
19
+ ],
20
+ ),
21
+ },
22
+ headers: None,
23
+ },
24
+ ],
25
+ }
@@ -1,3 +1,4 @@
1
+ use std::collections::BTreeMap;
1
2
  use std::fmt::{Display, Formatter};
2
3
  use std::hash::{Hash, Hasher};
3
4
  use std::ops::Deref;
@@ -16,6 +17,7 @@ pub struct Route {
16
17
  pub watch_opts: WatchOpts,
17
18
  #[serde(flatten)]
18
19
  pub kind: RouteKind,
20
+ pub headers: Option<BTreeMap<String, String>>,
19
21
  }
20
22
 
21
23
  impl Default for Route {
@@ -28,6 +30,7 @@ impl Default for Route {
28
30
  delay_opts: None,
29
31
  cors_opts: None,
30
32
  watch_opts: Default::default(),
33
+ headers: None,
31
34
  }
32
35
  }
33
36
  }
@@ -137,6 +140,7 @@ pub enum FilterKind {
137
140
  StringGlob(String),
138
141
  Extension { ext: String },
139
142
  Glob { glob: String },
143
+ List(Vec<FilterKind>),
140
144
  }
141
145
 
142
146
  #[derive(
@@ -38,7 +38,7 @@ pub fn print_file_changed<W: Write>(w: &mut W, evt: &FileChanged) -> anyhow::Res
38
38
 
39
39
  pub fn print_files_changed<W: Write>(w: &mut W, evt: &FilesChangedDTO) -> anyhow::Result<()> {
40
40
  match evt.paths.len() {
41
- 0 | 1 | 2 => {
41
+ 0..=2 => {
42
42
  writeln!(w, "[multi-change] {}", short_file_list(&evt.paths))?;
43
43
  }
44
44
  3.. => {
@@ -26,4 +26,4 @@ random_word = { workspace = true }
26
26
  tempfile = { workspace = true }
27
27
 
28
28
  [dev-dependencies]
29
- insta = { version = "1.38.0", features = ["yaml"] }
29
+ insta = { workspace = true }
@@ -7,6 +7,10 @@ pub struct Args {
7
7
  #[arg(short, long, value_enum)]
8
8
  pub log_level: Option<LogLevel>,
9
9
 
10
+ /// output internal logs to bslive.log in the current directory
11
+ #[arg(long, name = "write-log")]
12
+ pub write_log: bool,
13
+
10
14
  #[arg(short, long, value_enum)]
11
15
  pub format: Option<OutputFormat>,
12
16
 
@@ -37,7 +41,6 @@ pub struct Args {
37
41
  #[arg(short, long)]
38
42
  pub port: Option<u16>,
39
43
 
40
- /// Paths to watch, incompatible with `-i` option
41
- #[arg(trailing_var_arg = true, allow_hyphen_values = true, long)]
44
+ /// Paths to serve + possibly watch, incompatible with `-i` option
42
45
  pub paths: Vec<String>,
43
46
  }
@@ -54,20 +54,11 @@ impl actix::Handler<MonitorAnyWatchables> for BsSystem {
54
54
  };
55
55
 
56
56
  if let Some(opts) = &watchable.spec_opts() {
57
- // todo: handle the specs here!
58
- if let Some(filter) = &opts.filter {
59
- let f = match filter {
60
- FilterKind::Extension { ext } => Filter::Extension {
61
- ext: ext.to_string(),
62
- },
63
- FilterKind::StringGlob(glob) => Filter::Glob {
64
- glob: glob.to_owned(),
65
- },
66
- FilterKind::Glob { glob } => Filter::Glob {
67
- glob: glob.to_owned(),
68
- },
69
- };
70
- input_watcher.with_filter(f);
57
+ if let Some(filter_kind) = &opts.filter {
58
+ let filters = convert(&filter_kind);
59
+ for filter in filters {
60
+ input_watcher.with_filter(filter);
61
+ }
71
62
  }
72
63
  }
73
64
 
@@ -98,6 +89,21 @@ impl actix::Handler<MonitorAnyWatchables> for BsSystem {
98
89
  }
99
90
  }
100
91
 
92
+ fn convert(fk: &FilterKind) -> Vec<Filter> {
93
+ match fk {
94
+ FilterKind::StringGlob(sg) => vec![Filter::Glob {
95
+ glob: sg.to_string(),
96
+ }],
97
+ FilterKind::Extension { ext } => vec![Filter::Extension {
98
+ ext: ext.to_string(),
99
+ }],
100
+ FilterKind::Glob { glob } => vec![Filter::Glob {
101
+ glob: glob.to_string(),
102
+ }],
103
+ FilterKind::List(items) => items.into_iter().flat_map(convert).collect::<Vec<_>>(),
104
+ }
105
+ }
106
+
101
107
  #[derive(actix::Message)]
102
108
  #[rtype(result = "()")]
103
109
  struct DropMonitor(AnyWatchable);
@@ -1,5 +1,5 @@
1
1
  ---
2
- source: bsnext_system/src/start_kind/start_from_paths.rs
2
+ source: crates/bsnext_system/src/start_kind/start_from_paths.rs
3
3
  expression: input
4
4
  ---
5
5
  servers:
@@ -8,4 +8,5 @@ servers:
8
8
  - path: /
9
9
  watch: true
10
10
  dir: "."
11
+ headers: ~
11
12
  watchers: []
@@ -1,5 +1,5 @@
1
1
  ---
2
- source: bsnext_system/src/start_kind/start_from_paths.rs
2
+ source: crates/bsnext_system/src/start_kind/start_from_paths.rs
3
3
  expression: input
4
4
  ---
5
5
  Input {
@@ -21,6 +21,7 @@ Input {
21
21
  dir: ".",
22
22
  },
23
23
  ),
24
+ headers: None,
24
25
  },
25
26
  ],
26
27
  watchers: [],
@@ -1,4 +1,5 @@
1
1
  use std::fmt::{Display, Formatter};
2
+ use std::fs::File;
2
3
  use tracing_subscriber::layer::SubscriberExt;
3
4
  use tracing_subscriber::util::SubscriberInitExt;
4
5
 
@@ -33,6 +34,12 @@ pub enum OutputFormat {
33
34
  Normal,
34
35
  }
35
36
 
37
+ #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
38
+ pub enum WriteOption {
39
+ File,
40
+ None,
41
+ }
42
+
36
43
  impl Display for OutputFormat {
37
44
  fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
38
45
  match self {
@@ -47,7 +54,11 @@ impl Default for OutputFormat {
47
54
  Self::Normal
48
55
  }
49
56
  }
50
- pub fn init_tracing(log_level: Option<LogLevel>, format: Option<OutputFormat>) {
57
+ pub fn init_tracing(
58
+ log_level: Option<LogLevel>,
59
+ format: Option<OutputFormat>,
60
+ write_option: WriteOption,
61
+ ) {
51
62
  let log_level = log_level.unwrap_or(LogLevel::Error);
52
63
  let level = log_level.to_string();
53
64
  let lines = [
@@ -59,8 +70,8 @@ pub fn init_tracing(log_level: Option<LogLevel>, format: Option<OutputFormat>) {
59
70
  ];
60
71
  let debug_str = lines.join(",");
61
72
 
62
- match format.unwrap_or_default() {
63
- OutputFormat::Json => {
73
+ match (format.unwrap_or_default(), write_option) {
74
+ (OutputFormat::Json, WriteOption::None) => {
64
75
  let fmt_layer = tracing_subscriber::fmt::layer()
65
76
  .without_time()
66
77
  .json()
@@ -73,7 +84,21 @@ pub fn init_tracing(log_level: Option<LogLevel>, format: Option<OutputFormat>) {
73
84
  .with(fmt_layer)
74
85
  .init();
75
86
  }
76
- OutputFormat::Normal => {
87
+ (OutputFormat::Json, WriteOption::File) => {
88
+ let file = File::create("bslive.log").expect("create bslive.log");
89
+ let fmt_layer = tracing_subscriber::fmt::layer()
90
+ .json()
91
+ .with_ansi(false)
92
+ .with_writer(file);
93
+ tracing_subscriber::registry()
94
+ .with(
95
+ tracing_subscriber::EnvFilter::try_from_default_env()
96
+ .unwrap_or_else(|_| debug_str.into()),
97
+ )
98
+ .with(fmt_layer)
99
+ .init();
100
+ }
101
+ (OutputFormat::Normal, WriteOption::None) => {
77
102
  let fmt_layer = tracing_subscriber::fmt::layer()
78
103
  .without_time()
79
104
  .with_file(false);
@@ -85,5 +110,18 @@ pub fn init_tracing(log_level: Option<LogLevel>, format: Option<OutputFormat>) {
85
110
  .with(fmt_layer)
86
111
  .init();
87
112
  }
113
+ (OutputFormat::Normal, WriteOption::File) => {
114
+ let file = File::create("bslive.log").expect("create bslive.log");
115
+ let fmt_layer = tracing_subscriber::fmt::layer()
116
+ .with_ansi(false)
117
+ .with_writer(file);
118
+ tracing_subscriber::registry()
119
+ .with(
120
+ tracing_subscriber::EnvFilter::try_from_default_env()
121
+ .unwrap_or_else(|_| debug_str.into()),
122
+ )
123
+ .with(fmt_layer)
124
+ .init();
125
+ }
88
126
  };
89
127
  }
@@ -35,7 +35,7 @@ servers:
35
35
  - path: /other
36
36
  dir: ./examples
37
37
  - path: /index.html
38
- dir: ./index.html
38
+ dir: examples/kitchen-sink/input.html
39
39
  - path: /start
40
40
  html: <p>helldsosss wosrld</p>
41
41
  - path: /ws.js
package/input.yml ADDED
@@ -0,0 +1,8 @@
1
+ servers:
2
+ - bind_address: 0.0.0.0:3000
3
+ routes:
4
+ - path: /
5
+ watch: true
6
+ dir: .
7
+ headers: null
8
+ watchers: []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browsersync/bslive",
3
- "version": "0.0.9",
3
+ "version": "0.0.14",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "bin": {
@@ -47,21 +47,21 @@
47
47
  "version": "napi version"
48
48
  },
49
49
  "optionalDependencies": {
50
- "@browsersync/bslive-win32-x64-msvc": "0.0.9",
51
- "@browsersync/bslive-darwin-x64": "0.0.9",
52
- "@browsersync/bslive-linux-x64-gnu": "0.0.9",
53
- "@browsersync/bslive-darwin-arm64": "0.0.9",
54
- "@browsersync/bslive-android-arm64": "0.0.9",
55
- "@browsersync/bslive-linux-arm64-gnu": "0.0.9",
56
- "@browsersync/bslive-linux-arm64-musl": "0.0.9",
57
- "@browsersync/bslive-win32-arm64-msvc": "0.0.9",
58
- "@browsersync/bslive-linux-arm-gnueabihf": "0.0.9",
59
- "@browsersync/bslive-linux-arm-musleabihf": "0.0.9",
60
- "@browsersync/bslive-linux-x64-musl": "0.0.9",
61
- "@browsersync/bslive-freebsd-x64": "0.0.9",
62
- "@browsersync/bslive-win32-ia32-msvc": "0.0.9",
63
- "@browsersync/bslive-android-arm-eabi": "0.0.9",
64
- "@browsersync/bslive-darwin-universal": "0.0.9",
65
- "@browsersync/bslive-linux-riscv64-gnu": "0.0.9"
50
+ "@browsersync/bslive-win32-x64-msvc": "0.0.14",
51
+ "@browsersync/bslive-darwin-x64": "0.0.14",
52
+ "@browsersync/bslive-linux-x64-gnu": "0.0.14",
53
+ "@browsersync/bslive-darwin-arm64": "0.0.14",
54
+ "@browsersync/bslive-android-arm64": "0.0.14",
55
+ "@browsersync/bslive-linux-arm64-gnu": "0.0.14",
56
+ "@browsersync/bslive-linux-arm64-musl": "0.0.14",
57
+ "@browsersync/bslive-win32-arm64-msvc": "0.0.14",
58
+ "@browsersync/bslive-linux-arm-gnueabihf": "0.0.14",
59
+ "@browsersync/bslive-linux-arm-musleabihf": "0.0.14",
60
+ "@browsersync/bslive-linux-x64-musl": "0.0.14",
61
+ "@browsersync/bslive-freebsd-x64": "0.0.14",
62
+ "@browsersync/bslive-win32-ia32-msvc": "0.0.14",
63
+ "@browsersync/bslive-android-arm-eabi": "0.0.14",
64
+ "@browsersync/bslive-darwin-universal": "0.0.14",
65
+ "@browsersync/bslive-linux-riscv64-gnu": "0.0.14"
66
66
  }
67
67
  }
@@ -1,3 +0,0 @@
1
- body {
2
- background: green;
3
- }
@@ -1,20 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport"
6
- content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
8
- <title>BSNEXT</title>
9
- <style>
10
- pre {
11
- width: 100%;
12
- overflow-x: auto;
13
- }
14
- </style>
15
- </head>
16
- <body>
17
- <h2>No routes were matched - here's what's available on this address:</h2>
18
- {{route_list}}
19
- </body>
20
- </html>
@@ -1,49 +0,0 @@
1
- use bsnext_input::route::{DirRoute, ProxyRoute, Route, RouteKind};
2
- use htmlescape::encode_minimal;
3
-
4
- pub fn create_route_list_html(routes: &[Route]) -> String {
5
- let wrapper = include_str!("not_found.html");
6
- let mut markup = String::from("<table>");
7
- markup.push_str(
8
- r##"
9
- <thead>
10
- <tr>
11
- <td>Path</td>
12
- <td>Kind</td>
13
- </tr>
14
- </thead>
15
- "##,
16
- );
17
- for x in routes.iter() {
18
- let mut item = String::from("<tr>");
19
- let kind = match &x.kind {
20
- RouteKind::Html { .. } => String::from("RouteKind::Html"),
21
- RouteKind::Json { .. } => String::from("RouteKind::Json"),
22
- RouteKind::Raw { .. } => String::from("RouteKind::Raw"),
23
- RouteKind::Sse { .. } => String::from("RouteKind::Sse"),
24
- RouteKind::Proxy(ProxyRoute { proxy }) => {
25
- format!("RouteKind::Proxy('{}')", proxy)
26
- }
27
- RouteKind::Dir(DirRoute { dir }) => {
28
- format!("RouteKind::Dir('{}')", dir.clone())
29
- }
30
- };
31
- item.push_str(
32
- format!(
33
- "<td><a href='{}'><code>{}</code></a></td>\
34
- \
35
- <td><small>{}</small></td>",
36
- x.path, x.path, kind
37
- )
38
- .as_str(),
39
- );
40
- item.push_str("</tr>");
41
- markup.push_str(item.as_str());
42
- }
43
- markup.push_str("</table>");
44
- markup.push_str("<pre><code>");
45
- let json = serde_json::to_string_pretty(routes).expect("serde");
46
- markup.push_str(&encode_minimal(&json));
47
- markup.push_str("</pre></code>");
48
- wrapper.replace("{{route_list}}", markup.as_str())
49
- }