diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2023-02-07 20:22:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-07 20:22:46 +0100 |
commit | b4aa1530970f7b9cc4e6f2f27e077852c4e178d3 (patch) | |
tree | 3d008912affe8550692183bd2697a386db5e3c79 /runtime/build.rs | |
parent | 65500f36e870b4ada3996b06aa287e30177d21a3 (diff) |
refactor: Use ES modules for internal runtime code (#17648)
This PR refactors all internal js files (except core) to be written as
ES modules.
`__bootstrap`has been mostly replaced with static imports in form in
`internal:[path to file from repo root]`.
To specify if files are ESM, an `esm` method has been added to
`Extension`, similar to the `js` method.
A new ModuleLoader called `InternalModuleLoader` has been added to
enable the loading of internal specifiers, which is used in all
situations except when a snapshot is only loaded, and not a new one is
created from it.
---------
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'runtime/build.rs')
-rw-r--r-- | runtime/build.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/runtime/build.rs b/runtime/build.rs index 10490a871..bba4394f8 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -5,7 +5,6 @@ use std::env; use std::path::PathBuf; // This is a shim that allows to generate documentation on docs.rs -#[cfg(not(feature = "docsrs"))] mod not_docs { use std::path::Path; @@ -121,7 +120,7 @@ mod not_docs { } } - fn create_runtime_snapshot(snapshot_path: PathBuf, files: Vec<PathBuf>) { + fn create_runtime_snapshot(snapshot_path: PathBuf, esm_files: Vec<PathBuf>) { let extensions_with_js: Vec<Extension> = vec![ deno_webidl::init(), deno_console::init(), @@ -158,7 +157,8 @@ mod not_docs { startup_snapshot: None, extensions: vec![], extensions_with_js, - additional_files: files, + additional_files: vec![], + additional_esm_files: esm_files, compression_cb: Some(Box::new(|vec, snapshot_slice| { lzzzz::lz4_hc::compress_to_vec( snapshot_slice, @@ -172,14 +172,19 @@ mod not_docs { pub fn build_snapshot(runtime_snapshot_path: PathBuf) { #[allow(unused_mut)] - let mut js_files = get_js_files(env!("CARGO_MANIFEST_DIR"), "js"); + let mut esm_files = get_js_files( + env!("CARGO_MANIFEST_DIR"), + "js", + Some(Box::new(|path| !path.ends_with("99_main.js"))), + ); + #[cfg(not(feature = "snapshot_from_snapshot"))] { let manifest = env!("CARGO_MANIFEST_DIR"); let path = PathBuf::from(manifest); - js_files.push(path.join("js").join("99_main.js")); + esm_files.push(path.join("js").join("99_main.js")); } - create_runtime_snapshot(runtime_snapshot_path, js_files); + create_runtime_snapshot(runtime_snapshot_path, esm_files); } } |