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

Fix generation of package interface when modules are cached #4252

Merged
merged 8 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@
private type used in the same module it's defined in.
([Giacomo Cavalieri](https://github.com/giacomocavalieri))

- Fixed a bug where `gleam export package-interface` would not properly generate
the package interface file if some modules were cached.
([Surya Rose](https://github.com/GearsDatapacks))

## v1.8.1 - 2025-02-11

### Bug fixes
Expand Down
13 changes: 12 additions & 1 deletion compiler-cli/src/docs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::time::{Instant, SystemTime};

use camino::{Utf8Path, Utf8PathBuf};
use ecow::EcoString;

use crate::{cli, fs::ProjectIO, http::HttpClient};
use gleam_core::{
Expand All @@ -13,6 +14,7 @@ use gleam_core::{
hex,
io::HttpClient as _,
paths::ProjectPaths,
type_,
};

pub fn remove(package: String, version: String) -> Result<()> {
Expand Down Expand Up @@ -60,7 +62,13 @@ pub fn build(paths: &ProjectPaths, options: BuildOptions) -> Result<()> {
},
crate::build::download_dependencies(paths, cli::Reporter::new())?,
)?;
let outputs = build_documentation(paths, &config, &mut built.root_package, DocContext::Build)?;
let outputs = build_documentation(
paths,
&config,
&mut built.root_package,
DocContext::Build,
&built.module_interfaces,
)?;

// Write
crate::fs::delete_directory(&out)?;
Expand Down Expand Up @@ -100,6 +108,7 @@ pub(crate) fn build_documentation(
config: &PackageConfig,
compiled: &mut Package,
is_hex_publish: DocContext,
cached_modules: &im::HashMap<EcoString, type_::ModuleInterface>,
) -> Result<Vec<gleam_core::io::OutputFile>, Error> {
compiled.attach_doc_and_module_comments();
cli::print_generating_documentation();
Expand All @@ -122,6 +131,7 @@ pub(crate) fn build_documentation(
outputs.push(gleam_core::docs::generate_json_package_interface(
Utf8PathBuf::from("package-interface.json"),
compiled,
cached_modules,
));
Ok(outputs)
}
Expand Down Expand Up @@ -155,6 +165,7 @@ pub fn publish(paths: &ProjectPaths) -> Result<()> {
&config,
&mut built.root_package,
DocContext::HexPublish,
&built.module_interfaces,
)?;
let archive = crate::fs::create_tar_archive(outputs)?;

Expand Down
6 changes: 5 additions & 1 deletion compiler-cli/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ pub fn package_interface(paths: &ProjectPaths, out: Utf8PathBuf) -> Result<()> {
)?;
built.root_package.attach_doc_and_module_comments();

let out = gleam_core::docs::generate_json_package_interface(out, &built.root_package);
let out = gleam_core::docs::generate_json_package_interface(
out,
&built.root_package,
&built.module_interfaces,
);
crate::fs::write_outputs_under(&[out], paths.root())?;
Ok(())
}
6 changes: 6 additions & 0 deletions compiler-cli/src/publish.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use camino::{Utf8Path, Utf8PathBuf};
use ecow::EcoString;
use flate2::{Compression, write::GzEncoder};
use gleam_core::{
Error, Result,
Expand All @@ -10,6 +11,7 @@ use gleam_core::{
hex,
paths::{self, ProjectPaths},
requirement::Requirement,
type_,
};
use hexpm::version::{Range, Version};
use itertools::Itertools;
Expand All @@ -32,6 +34,7 @@ pub fn command(paths: &ProjectPaths, replace: bool, i_am_sure: bool) -> Result<(

let Tarball {
mut compile_result,
cached_modules,
data: package_tarball,
src_files_added,
generated_files_added,
Expand All @@ -46,6 +49,7 @@ pub fn command(paths: &ProjectPaths, replace: bool, i_am_sure: bool) -> Result<(
&config,
&mut compile_result,
DocContext::HexPublish,
&cached_modules,
)?)?;

// Ask user if this is correct
Expand Down Expand Up @@ -256,6 +260,7 @@ core team.\n",

struct Tarball {
compile_result: Package,
cached_modules: im::HashMap<EcoString, type_::ModuleInterface>,
data: Vec<u8>,
src_files_added: Vec<Utf8PathBuf>,
generated_files_added: Vec<(Utf8PathBuf, String)>,
Expand Down Expand Up @@ -372,6 +377,7 @@ fn do_build_hex_tarball(paths: &ProjectPaths, config: &mut PackageConfig) -> Res
tracing::info!("Generated package Hex release tarball");
Ok(Tarball {
compile_result: built.root_package,
cached_modules: built.module_interfaces,
data: tarball,
src_files_added: src_files,
generated_files_added: generated_files,
Expand Down
Loading
Loading