mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
fix(core): improve JS ESM detection (#2139)
This commit is contained in:
committed by
GitHub
parent
51a5cfe4b5
commit
4b0ec01880
5
.changes/improve-esm-detection.md
Normal file
5
.changes/improve-esm-detection.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri-codegen": patch
|
||||
---
|
||||
|
||||
Improve ESM detection with regexes.
|
||||
@@ -22,3 +22,4 @@ thiserror = "1"
|
||||
walkdir = "2"
|
||||
zstd = "0.9"
|
||||
kuchiki = "0.8"
|
||||
regex = "1"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
use kuchiki::traits::*;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{quote, ToTokens, TokenStreamExt};
|
||||
use regex::RegexSet;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
ffi::OsStr,
|
||||
@@ -187,11 +188,24 @@ impl EmbeddedAssets {
|
||||
.any(|e| path.extension() == Some(OsStr::new(e)));
|
||||
if is_javascript {
|
||||
let js = String::from_utf8_lossy(&input).into_owned();
|
||||
input = if [
|
||||
"import{", "import*", "import ", "export{", "export*", "export ",
|
||||
]
|
||||
.iter()
|
||||
.any(|t| js.contains(t))
|
||||
input = if RegexSet::new(&[
|
||||
// import keywords
|
||||
"import\\{",
|
||||
"import \\{",
|
||||
"import\\*",
|
||||
"import \\*",
|
||||
"import (\"|');?$",
|
||||
"import\\(",
|
||||
"import (.|\n)+ from (\"|')([A-Za-z\\-]+)(\"|')",
|
||||
// export keywords
|
||||
"export\\{",
|
||||
"export \\{",
|
||||
"export\\*",
|
||||
"export \\*",
|
||||
"export (default|class|let|const|function)",
|
||||
])
|
||||
.unwrap()
|
||||
.is_match(&js)
|
||||
{
|
||||
format!(
|
||||
r#"
|
||||
|
||||
Reference in New Issue
Block a user