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

Add export package-information command #4298

Merged
merged 14 commits into from
Mar 22, 2025
7 changes: 7 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ jobs:
working-directory: ./test/project_erlang_windows
if: ${{ runner.os == 'Windows' && matrix.run-integration-tests }}

- name: test/project_erlang export package-information
run: |
gleam export package-information --out="gleam.json"
cat gleam.json
working-directory: ./test/project_erlang
if: ${{ matrix.run-integration-tests }}

- name: test/external_only_javascript
run: ./test.sh
working-directory: ./test/external_only_javascript
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
- `entrypoint.ps1` for PowerShell
([Greg Burri](https://github.com/ummon))

- `gleam export` now takes a `package-information` option to export the
project's `gleam.toml` as a JSON file.
([Rodrigo Álvarez](https://github.com/Papipo))

### Language server

- The language server now allows renaming of functions, constants,
Expand Down
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[workspace]
resolver = "2"
members = [
"gleam-bin",
"compiler-cli",
"compiler-core",
"compiler-wasm",
"test-helpers-rs",
"test-output",
"test-package-compiler",
"test-project-compiler",
"gleam-bin",
"compiler-cli",
"compiler-core",
"compiler-wasm",
"test-helpers-rs",
"test-output",
"test-package-compiler",
"test-project-compiler",
]

# common dependencies
Expand Down
7 changes: 7 additions & 0 deletions compiler-cli/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,10 @@ pub fn package_interface(paths: &ProjectPaths, out: Utf8PathBuf) -> Result<()> {
crate::fs::write_outputs_under(&[out], paths.root())?;
Ok(())
}

pub fn package_information(paths: &ProjectPaths, out: Utf8PathBuf) -> Result<()> {
let config = crate::config::root_config(paths)?;
let out = gleam_core::docs::generate_json_package_information(out, config);
crate::fs::write_outputs_under(&[out], paths.root())?;
Ok(())
}
10 changes: 10 additions & 0 deletions compiler-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ pub enum ExportTarget {
/// The path to write the JSON file to
output: Utf8PathBuf,
},
/// Package information (gleam.toml) in JSON format
PackageInformation {
#[arg(long = "out", required = true)]
/// The path to write the JSON file to
output: Utf8PathBuf,
},
}

#[derive(Args, Debug, Clone)]
Expand Down Expand Up @@ -663,6 +669,10 @@ fn parse_and_run_command() -> Result<(), Error> {
let paths = find_project_paths()?;
export::package_interface(&paths, output)
}
Command::Export(ExportTarget::PackageInformation { output }) => {
let paths = find_project_paths()?;
export::package_information(&paths, output)
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler-cli/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use gleam_core::{
Error, Result,
analyse::TargetSupport,
build::{Codegen, Compile, Mode, Options, Package, Target},
config::{PackageConfig, SpdxLicense},
config::{GleamVersion, PackageConfig, SpdxLicense},
docs::DocContext,
error::{SmallVersion, wrap},
hex,
Expand Down Expand Up @@ -307,7 +307,7 @@ fn do_build_hex_tarball(paths: &ProjectPaths, config: &mut PackageConfig) -> Res
std::cmp::max(minimum_required_version, Version::new(1, 0, 0));
let inferred_version_range =
pubgrub::range::Range::higher_than(minimum_required_version);
config.gleam_version = Some(inferred_version_range);
config.gleam_version = Some(GleamVersion::from_pubgrub(inferred_version_range));
}
// Otherwise we need to check that the annotated version range is
// correct and includes the minimum required version.
Expand Down
5 changes: 4 additions & 1 deletion compiler-core/src/analyse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ impl<'a, A> ModuleAnalyzer<'a, A> {
let env = Environment::new(
self.ids.clone(),
self.package_config.name.clone(),
self.package_config.gleam_version.clone(),
self.package_config
.gleam_version
.clone()
.map(|version| version.as_pubgrub()),
self.module_name.clone(),
self.target,
self.importable_modules,
Expand Down
Loading
Loading