summaryrefslogtreecommitdiff
path: root/core/extensions.rs
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2023-02-08 22:40:18 +0100
committerGitHub <noreply@github.com>2023-02-08 22:40:18 +0100
commit286e5d0be9bb11a69d55f0eedd4a6678b0d48e7d (patch)
tree37399e924de155fbcbeab975222bdb16f257e228 /core/extensions.rs
parentbef50416b92a3ed7bf44b361fc5360f9a52c83e6 (diff)
refactor: internal runtime code TS support (#17672)
This is a proof of concept for being able to snapshot TypeScript files. Currently only a single runtime file is authored in TypeScript - "runtime/js/01_version.ts". Not needed infrastructure was removed from "core/snapshot_util.rs". --------- Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'core/extensions.rs')
-rw-r--r--core/extensions.rs32
1 files changed, 30 insertions, 2 deletions
diff --git a/core/extensions.rs b/core/extensions.rs
index e08e8c566..16cca924d 100644
--- a/core/extensions.rs
+++ b/core/extensions.rs
@@ -6,6 +6,7 @@ use std::rc::Rc;
use std::task::Context;
use v8::fast_api::FastFunction;
+#[derive(Clone, Debug)]
pub struct ExtensionFileSource {
pub specifier: String,
pub code: &'static str,
@@ -244,8 +245,9 @@ impl ExtensionBuilder {
}
}
}
-/// Helps embed JS files in an extension. Returns Vec<(&'static str, &'static str)>
-/// representing the filename and source code.
+
+/// Helps embed JS files in an extension. Returns a vector of
+/// `ExtensionFileSource`, that represent the filename and source code.
///
/// Example:
/// ```ignore
@@ -265,3 +267,29 @@ macro_rules! include_js_files {
]
};
}
+
+/// Helps embed JS files in an extension. Returns a vector of
+/// `ExtensionFileSource`, that represent the filename and source code.
+/// Additional "dir" option is required, that specifies which directory in the
+/// crate root contains the listed files. "dir" option will be prepended to
+/// each file name.
+///
+/// Example:
+/// ```ignore
+/// include_js_files_dir!(
+/// dir "example",
+/// "01_hello.js",
+/// "02_goodbye.js",
+/// )
+/// ```
+#[macro_export]
+macro_rules! include_js_files_dir {
+ (dir $dir:literal, $($file:literal,)+) => {
+ vec![
+ $($crate::ExtensionFileSource {
+ specifier: concat!($dir, "/", $file).to_string(),
+ code: include_str!(concat!($dir, "/", $file)),
+ },)+
+ ]
+ };
+}