carragom
carragom2mo ago

Deno compile with --include

Hi, playing around with deno compile --include following the docs probably doing something wrong but not sure what. Help appreciated, using v2.5.3. I have the following names.tsv
John Doe
Jane Smith
Alice Jones
John Doe
Jane Smith
Alice Jones
cli.ts
if (import.meta.main) {
const names = Deno.readTextFileSync(import.meta.dirname + "/names.tsv");
console.debug(names);
}
if (import.meta.main) {
const names = Deno.readTextFileSync(import.meta.dirname + "/names.tsv");
console.debug(names);
}
After compiling the file with deno compile cli.ts --include names.tsv and running the resulting binary and get this error:
error: Uncaught (in promise) NotFound: path not found: readfile '/tmp/deno-compile-deno-embed/names.tsv'
const names = Deno.readTextFileSync(import.meta.dirname + "/names.tsv");
^
at Object.readTextFileSync (ext:deno_fs/30_fs.js:771:10)
at file:///tmp/deno-compile-deno-embed/cli.ts:2:22
error: Uncaught (in promise) NotFound: path not found: readfile '/tmp/deno-compile-deno-embed/names.tsv'
const names = Deno.readTextFileSync(import.meta.dirname + "/names.tsv");
^
at Object.readTextFileSync (ext:deno_fs/30_fs.js:771:10)
at file:///tmp/deno-compile-deno-embed/cli.ts:2:22
Deno
deno compile, standalone executables
Compile your code into a standalone executable
4 Replies
carragom
carragomOP2mo ago
Found the problem, seems like command line parsing is a bit buggy here and the order does alter the result - deno compile cli.ts --include names.tsv. Generates the executable without warnings or errors but silently ignores the --include names.tsv parameter. This should work as expected or throw an error when parsing arguments. - deno compile --include names.tsv cli.ts. Generates the executable and actually includes the asset into the binary.
Leokuma
Leokuma2mo ago
That's the intended behavior. When you pass the arguments after cli.ts, the arguments are passed to cli.ts, not to deno compile. It's the same as the difference between deno run --allow-all cli.ts and deno run cli.ts --allow-all
carragom
carragomOP2mo ago
Thanks for the clarification. It's working as intended then. It's weird though to pass parameters to something I'm compiling but I suppose there might be a use case for that.
Leokuma
Leokuma2mo ago
I think nowadays there's a native API that allows us to check from code whether the app is running as a script or as binary, but in the past we didn't have that. So one example usage would be to do something like deno compile cli.ts --compiled, and then inside the code we would do something like if (Deno.args.get('compiled')) because we wanted the binary version to behave differently

Did you find this page helpful?