Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compile): ability to embed local data files #26934

Merged

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Nov 19, 2024

This is now trivial to implement due to recent changes.

> deno compile --allow-read=. --include data-file.txt main.js

Then to read:

// main.js
const names = Deno.readTextFileSync(import.meta.dirname + "/data-file.txt");

Slightly annoying to have to give read permissions. I feel like we should allow reading files in the binary by default.

This only applies to files on the filesystem. For remote modules, that's going to have to wait for import ... from "./data.txt" with { "type": "bytes" } or whatever it will be.

Closes #20885

@dsherret dsherret changed the title feat(compile): ability to embed data files feat(compile): ability to embed local data files Nov 19, 2024
vfs
.add_file_at_path(&path)
.with_context(|| format!("Including {}", path.display()))?;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Files are included here.

@@ -212,6 +214,48 @@ fn validate_output_path(output_path: &Path) -> Result<(), AnyError> {
Ok(())
}

fn get_module_roots_and_include_files(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Files are parsed out here. Only local files work.

@bartlomieju
Copy link
Member

Slightly annoying to have to give read permissions. I feel like we should allow reading files in the binary by default.

I agree about that. Any way we can fix it before landing? I guess we'd have to pass additional permissions when embedding metadata into the binary.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, could you open a nascent PR to docs repo to mention this?

@dsherret
Copy link
Member Author

Opened denoland/docs#1164

@dsherret dsherret merged commit 46b6037 into denoland:main Nov 19, 2024
17 checks passed
@dsherret dsherret deleted the feat_compile_ability_include_data_files branch November 19, 2024 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Embed files when using deno compile
2 participants