Repository navigation
Do not glob an HTML entry path that names a file the glob cannot match #45060
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
Open
robobun
wants to merge
11
commits into
main
Choose a base branch
from
robobun/c77894bc/html-entry-literal-path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3b69e30
Do not glob an HTML entry path that names a file the glob cannot match
robobun 8ea84b9
html entry, --check: probe a page path that fits, keep the pages foun…
robobun ef38c0b
html entry: keep each comment to one line
robobun 048ebd7
html entry: define pagesOf with the bindgen
robobun c7b7adf
tsconfig: keep tsc out of the src/cli link
robobun 49aefa7
test: list html_pages.bind.ts as not published, pin the error of a pa…
robobun 14aacb1
html entry: join the page path with join_abs_string_buf_z_checked
robobun 41e32c8
Merge remote-tracking branch 'origin/main' into robobun/c77894bc/html…
robobun f5e2fe8
html entry: search with the walker of Bun.Glob.prototype.scanSync
robobun ca7bb4e
Merge remote-tracking branch 'origin/main' into robobun/c77894bc/html…
robobun 76ba020
ci: retrigger
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import * as b from "../../codegen/bindgen-lib.ts"; | ||
|
|
||
| /** `undefined` if `arg` is the path of a page, else the pages that match the pattern `arg`. A relative path is in `cwd`. */ | ||
| export const pagesOf = b.fn({ | ||
| args: { arg: b.string.utf8, cwd: b.string.utf8 }, | ||
| returns: b.array(b.string.utf8).optional, | ||
| throws: true, | ||
| rustPath: "crate::cli::html_pages::pages_of_from_js", | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| //! Whether an argument of `bun ./index.html './pages/*.html'` is a page or a pattern, for html.ts and `bun --check`. | ||
|
|
||
| use bun_core::strings; | ||
| use bun_paths::{platform::Auto, resolve_path}; | ||
|
|
||
| use crate::api::glob::{Glob, ScanError}; | ||
|
|
||
| /// What an argument names. | ||
| pub(crate) enum Pages { | ||
| /// One page. The argument is its path. | ||
| Named, | ||
| /// The argument is a pattern. | ||
| Matched { | ||
| /// The pages that match it. Each path is absolute or relative to the working directory. | ||
| pages: Vec<Box<[u8]>>, | ||
| /// What ended the search early. `pages` then has those that were found before it. | ||
| error: Option<bun_sys::Error>, | ||
| }, | ||
| } | ||
|
|
||
| /// The pages that the argument `text` names. A relative path is in `cwd`. | ||
| pub(crate) fn pages_of<'a>(cwd: &'a [u8], text: &[u8]) -> Result<Pages, ScanError<'a>> { | ||
| if !strings::contains_any(text, b"*{") { | ||
| return Ok(Pages::Named); | ||
| } | ||
| // Made before the look for a file: it refuses what `Bun.Glob.prototype.scanSync` refuses, such as a NUL byte. | ||
| let mut walker = Glob::scan_sync_walker(text, cwd)?; | ||
| if names_file(cwd, text) { | ||
| return Ok(Pages::Named); | ||
| } | ||
| let walked = walker | ||
| .walk() | ||
| .map_err(|error| ScanError::Runtime(error.into()))?; | ||
| let pages = walker.take_matched_paths(); | ||
| Ok(Pages::Matched { | ||
| pages, | ||
| error: walked.err(), | ||
| }) | ||
| } | ||
|
|
||
| /// Whether `text` is the path of a file that it does not match as a pattern: `{a,b}/x.html` matches `a/x.html`. | ||
| fn names_file(cwd: &[u8], text: &[u8]) -> bool { | ||
| if bun_glob::r#match(text, text).matches() { | ||
| return false; | ||
| } | ||
| let mut buf = bun_paths::path_buffer_pool::get(); | ||
|
claude[bot] marked this conversation as resolved.
Resolved
|
||
| let Some(path) = | ||
| resolve_path::join_abs_string_buf_z_checked::<Auto>(cwd, &mut buf[..], &[text]) | ||
| else { | ||
| return false; | ||
| }; | ||
| matches!( | ||
| bun_sys::exists_at_type(bun_sys::Fd::cwd(), path), | ||
| Ok(bun_sys::ExistsAtType::File) | ||
| ) | ||
| } | ||
|
|
||
| /// `pagesOf` of html_pages.bind.ts, with the errors of `Bun.Glob.prototype.scanSync`. `None` is `undefined`. | ||
| pub(crate) fn pages_of_from_js<'a>( | ||
| arg: &[u8], | ||
| cwd: &'a [u8], | ||
| ) -> Result<Option<Vec<Box<[u8]>>>, ScanError<'a>> { | ||
| match pages_of(cwd, arg)? { | ||
| Pages::Named => Ok(None), | ||
| Pages::Matched { | ||
| error: Some(error), .. | ||
| } => Err(ScanError::Sys(error)), | ||
| Pages::Matched { pages, error: None } => Ok(Some(pages)), | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.