Skip to content

Commit d48e681

Browse files
PgBiellpil
authored andcommitted
accept .gitignored and hidden files on publish
also affects the formatter
1 parent 2e2bda5 commit d48e681

File tree

4 files changed

+34
-28
lines changed

4 files changed

+34
-28
lines changed

compiler-cli/src/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn unformatted_files(files: Vec<String>) -> Result<Vec<Unformatted>> {
7979
})?;
8080

8181
if path.is_dir() {
82-
for path in crate::fs::gleam_files_excluding_gitignore(&path) {
82+
for path in crate::fs::gleam_files(&path) {
8383
format_file(&mut problem_files, path)?;
8484
}
8585
} else {

compiler-cli/src/fs.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,14 @@ fn is_gleam_build_dir(e: &ignore::DirEntry) -> bool {
389389
parent_path.join("gleam.toml").exists()
390390
}
391391

392-
pub fn gleam_files_excluding_gitignore(dir: &Utf8Path) -> impl Iterator<Item = Utf8PathBuf> + '_ {
392+
/// Walks through all Gleam module files in the directory, even if ignored,
393+
/// except for those in the `build/` directory. Excludes any Gleam files within
394+
/// invalid module paths, for example if they or a folder they're in contain a
395+
/// dot or a hyphen within their names.
396+
pub fn gleam_files(dir: &Utf8Path) -> impl Iterator<Item = Utf8PathBuf> + '_ {
393397
ignore::WalkBuilder::new(dir)
394398
.follow_links(true)
395-
.require_git(false)
399+
.standard_filters(false)
396400
.filter_entry(|e| !is_gleam_build_dir(e))
397401
.build()
398402
.filter_map(Result::ok)
@@ -402,10 +406,12 @@ pub fn gleam_files_excluding_gitignore(dir: &Utf8Path) -> impl Iterator<Item = U
402406
.filter(move |d| is_gleam_path(d, dir))
403407
}
404408

405-
pub fn native_files_excluding_gitignore(dir: &Utf8Path) -> impl Iterator<Item = Utf8PathBuf> + '_ {
409+
/// Walks through all native files in the directory, such as `.mjs` and `.erl`,
410+
/// even if ignored.
411+
pub fn native_files(dir: &Utf8Path) -> impl Iterator<Item = Utf8PathBuf> + '_ {
406412
ignore::WalkBuilder::new(dir)
407413
.follow_links(true)
408-
.require_git(false)
414+
.standard_filters(false)
409415
.filter_entry(|e| !is_gleam_build_dir(e))
410416
.build()
411417
.filter_map(Result::ok)
@@ -418,19 +424,19 @@ pub fn native_files_excluding_gitignore(dir: &Utf8Path) -> impl Iterator<Item =
418424
})
419425
}
420426

421-
pub fn private_files_excluding_gitignore(dir: &Utf8Path) -> impl Iterator<Item = Utf8PathBuf> + '_ {
427+
/// Walks through all files in the directory, even if ignored.
428+
pub fn private_files(dir: &Utf8Path) -> impl Iterator<Item = Utf8PathBuf> + '_ {
422429
ignore::WalkBuilder::new(dir)
423430
.follow_links(true)
424-
.require_git(false)
431+
.standard_filters(false)
425432
.build()
426433
.filter_map(Result::ok)
427434
.filter(|e| e.file_type().map(|t| t.is_file()).unwrap_or(false))
428435
.map(ignore::DirEntry::into_path)
429436
.map(|pb| Utf8PathBuf::from_path_buf(pb).expect("Non Utf-8 Path"))
430437
}
431438

432-
/// Walks through Erlang files in the directory. Does not exclude files ignored
433-
/// through `.gitignore`.
439+
/// Walks through all `.erl` and `.hrl` files in the directory, even if ignored.
434440
pub fn erlang_files(dir: &Utf8Path) -> impl Iterator<Item = Utf8PathBuf> + '_ {
435441
ignore::WalkBuilder::new(dir)
436442
.follow_links(true)

compiler-cli/src/fs/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn exclude_build_dir() {
7373
let gleam_file = path.join("b/build/f.gleam").to_path_buf();
7474
super::write(&gleam_file, "").unwrap();
7575

76-
let files = super::gleam_files_excluding_gitignore(path).collect::<Vec<_>>();
76+
let files = super::gleam_files(path).collect::<Vec<_>>();
7777

7878
assert_eq!(files, vec![gleam_file]);
7979
}

compiler-cli/src/publish.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,11 @@ fn contents_tarball(
470470

471471
fn project_files(base_path: &Utf8Path) -> Result<Vec<Utf8PathBuf>> {
472472
let src = base_path.join(Utf8Path::new("src"));
473-
let mut files: Vec<Utf8PathBuf> = fs::gleam_files_excluding_gitignore(&src)
474-
.chain(fs::native_files_excluding_gitignore(&src))
473+
let mut files: Vec<Utf8PathBuf> = fs::gleam_files(&src)
474+
.chain(fs::native_files(&src))
475475
.collect();
476476
let private = base_path.join(Utf8Path::new("priv"));
477-
let mut private_files: Vec<Utf8PathBuf> =
478-
fs::private_files_excluding_gitignore(&private).collect();
477+
let mut private_files: Vec<Utf8PathBuf> = fs::private_files(&private).collect();
479478
files.append(&mut private_files);
480479
let mut add = |path| {
481480
let path = base_path.join(path);
@@ -789,22 +788,33 @@ fn exported_project_files_test() {
789788
"README.md",
790789
"README.txt",
791790
"gleam.toml",
791+
"priv/ignored",
792792
"priv/wibble",
793793
"priv/wobble.js",
794+
"src/.hidden/hidden_ffi.erl",
795+
"src/.hidden/hidden_ffi.mjs",
796+
"src/.hidden_ffi.erl",
797+
"src/.hidden_ffi.mjs",
794798
"src/exported.gleam",
795799
"src/exported_ffi.erl",
796800
"src/exported_ffi.ex",
797801
"src/exported_ffi.hrl",
798802
"src/exported_ffi.js",
799803
"src/exported_ffi.mjs",
800804
"src/exported_ffi.ts",
805+
"src/ignored.gleam",
806+
"src/ignored_ffi.erl",
807+
"src/ignored_ffi.mjs",
801808
"src/nested/exported.gleam",
802809
"src/nested/exported_ffi.erl",
803810
"src/nested/exported_ffi.ex",
804811
"src/nested/exported_ffi.hrl",
805812
"src/nested/exported_ffi.js",
806813
"src/nested/exported_ffi.mjs",
807814
"src/nested/exported_ffi.ts",
815+
"src/nested/ignored.gleam",
816+
"src/nested/ignored_ffi.erl",
817+
"src/nested/ignored_ffi.mjs",
808818
];
809819

810820
let unexported_project_files = &[
@@ -813,20 +823,9 @@ fn exported_project_files_test() {
813823
".gitignore",
814824
"build/",
815825
"ignored.txt",
816-
"priv/ignored",
817-
"src/.hidden/hidden.gleam",
818-
"src/.hidden/hidden_ffi.erl",
819-
"src/.hidden/hidden_ffi.mjs",
820-
"src/.hidden.gleam",
821-
"src/.hidden_ffi.erl",
822-
"src/.hidden_ffi.mjs",
823-
"src/also-ignored.gleam",
824-
"src/ignored.gleam",
825-
"src/ignored_ffi.mjs",
826-
"src/ignored_ffi.erl",
827-
"src/nested/ignored.gleam",
828-
"src/nested/ignored_ffi.erl",
829-
"src/nested/ignored_ffi.mjs",
826+
"src/.hidden/hidden.gleam", // Not a valid Gleam module path
827+
"src/.hidden.gleam", // Not a valid Gleam module name
828+
"src/also-ignored.gleam", // Not a valid Gleam module name
830829
"test/exported_test.gleam",
831830
"test/exported_test_ffi.erl",
832831
"test/exported_test_ffi.ex",
@@ -847,6 +846,7 @@ fn exported_project_files_test() {
847846
"test/nested/ignored.gleam",
848847
"test/nested/ignored_test_ffi.erl",
849848
"test/nested/ignored_test_ffi.mjs",
849+
"unrelated-file.txt",
850850
];
851851

852852
let gitignore = "ignored*

0 commit comments

Comments
 (0)