1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-21 23:04:45 -05:00

feat(compile): ability to embed directory in executable (#26939)

This commit is contained in:
David Sherret 2024-11-19 18:20:14 -05:00 committed by GitHub
parent 46b6037644
commit 6b478cd0a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 50 additions and 6 deletions

View file

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

View file

@ -620,9 +620,17 @@ impl<'a> DenoCompileBinaryWriter<'a> {
};
for include_file in include_files {
let path = deno_path_util::url_to_file_path(include_file)?;
vfs
.add_file_at_path(&path)
.with_context(|| format!("Including {}", path.display()))?;
if path.is_dir() {
// TODO(#26941): we should analyze if any of these are
// modules in order to include their dependencies
vfs
.add_dir_recursive(&path)
.with_context(|| format!("Including {}", path.display()))?;
} else {
vfs
.add_file_at_path(&path)
.with_context(|| format!("Including {}", path.display()))?;
}
}
let mut remote_modules_store = RemoteModulesStoreBuilder::default();
let mut code_cache_key_hasher = if self.cli_options.code_cache_enabled() {

View file

@ -0,0 +1,24 @@
{
"tempDir": true,
"steps": [{
"if": "unix",
"args": "compile --allow-read=data --include data --output main main.js",
"output": "[WILDCARD]"
}, {
"if": "unix",
"commandName": "./main",
"args": [],
"output": "output.out",
"exitCode": 0
}, {
"if": "windows",
"args": "compile --allow-read=data --include data --output main.exe main.js",
"output": "[WILDCARD]"
}, {
"if": "windows",
"commandName": "./main.exe",
"args": [],
"output": "output.out",
"exitCode": 0
}]
}

View file

@ -0,0 +1 @@
a

View file

@ -0,0 +1 @@
b

View file

@ -0,0 +1,8 @@
const dataDir = import.meta.dirname + "/data";
const files = Array.from(
Deno.readDirSync(dataDir).map((entry) => dataDir + "/" + entry.name),
);
files.sort();
for (const file of files) {
console.log(Deno.readTextFileSync(file).trim());
}

View file

@ -0,0 +1,2 @@
a
b