Skip to content

Commit 6b478cd

Browse files
authored
feat(compile): ability to embed directory in executable (#26939)
1 parent 46b6037 commit 6b478cd

File tree

7 files changed

+50
-6
lines changed

7 files changed

+50
-6
lines changed

cli/args/flags.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1909,10 +1909,10 @@ On the first invocation with deno will download the proper binary and cache it i
19091909
Arg::new("include")
19101910
.long("include")
19111911
.help(
1912-
cstr!("Includes an additional module or local data file in the compiled executable.
1912+
cstr!("Includes an additional module or file/directory in the compiled executable.
19131913
<p(245)>Use this flag if a dynamically imported module or a web worker main module
1914-
fails to load in the executable or to embed a file in the executable. This flag can
1915-
be passed multiple times, to include multiple additional modules.</>",
1914+
fails to load in the executable or to embed a file or directory in the executable.
1915+
This flag can be passed multiple times, to include multiple additional modules.</>",
19161916
))
19171917
.action(ArgAction::Append)
19181918
.value_hint(ValueHint::FilePath)

cli/standalone/binary.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,17 @@ impl<'a> DenoCompileBinaryWriter<'a> {
620620
};
621621
for include_file in include_files {
622622
let path = deno_path_util::url_to_file_path(include_file)?;
623-
vfs
624-
.add_file_at_path(&path)
625-
.with_context(|| format!("Including {}", path.display()))?;
623+
if path.is_dir() {
624+
// TODO(#26941): we should analyze if any of these are
625+
// modules in order to include their dependencies
626+
vfs
627+
.add_dir_recursive(&path)
628+
.with_context(|| format!("Including {}", path.display()))?;
629+
} else {
630+
vfs
631+
.add_file_at_path(&path)
632+
.with_context(|| format!("Including {}", path.display()))?;
633+
}
626634
}
627635
let mut remote_modules_store = RemoteModulesStoreBuilder::default();
628636
let mut code_cache_key_hasher = if self.cli_options.code_cache_enabled() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"tempDir": true,
3+
"steps": [{
4+
"if": "unix",
5+
"args": "compile --allow-read=data --include data --output main main.js",
6+
"output": "[WILDCARD]"
7+
}, {
8+
"if": "unix",
9+
"commandName": "./main",
10+
"args": [],
11+
"output": "output.out",
12+
"exitCode": 0
13+
}, {
14+
"if": "windows",
15+
"args": "compile --allow-read=data --include data --output main.exe main.js",
16+
"output": "[WILDCARD]"
17+
}, {
18+
"if": "windows",
19+
"commandName": "./main.exe",
20+
"args": [],
21+
"output": "output.out",
22+
"exitCode": 0
23+
}]
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const dataDir = import.meta.dirname + "/data";
2+
const files = Array.from(
3+
Deno.readDirSync(dataDir).map((entry) => dataDir + "/" + entry.name),
4+
);
5+
files.sort();
6+
for (const file of files) {
7+
console.log(Deno.readTextFileSync(file).trim());
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
a
2+
b

0 commit comments

Comments
 (0)