mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
feat(compile): ability to embed directory in executable (#26939)
This commit is contained in:
parent
46b6037644
commit
6b478cd0a3
7 changed files with 50 additions and 6 deletions
|
@ -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)
|
||||
|
|
|
@ -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() {
|
||||
|
|
24
tests/specs/compile/include_folder/__test__.jsonc
Normal file
24
tests/specs/compile/include_folder/__test__.jsonc
Normal 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
|
||||
}]
|
||||
}
|
1
tests/specs/compile/include_folder/data/a.txt
Normal file
1
tests/specs/compile/include_folder/data/a.txt
Normal file
|
@ -0,0 +1 @@
|
|||
a
|
1
tests/specs/compile/include_folder/data/b.txt
Normal file
1
tests/specs/compile/include_folder/data/b.txt
Normal file
|
@ -0,0 +1 @@
|
|||
b
|
8
tests/specs/compile/include_folder/main.js
Normal file
8
tests/specs/compile/include_folder/main.js
Normal 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());
|
||||
}
|
2
tests/specs/compile/include_folder/output.out
Normal file
2
tests/specs/compile/include_folder/output.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
a
|
||||
b
|
Loading…
Reference in a new issue