···6969 spans.
7070 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
71717272-- The compiler now emits a warning when a module in the `src` directory imports
7272+- The compiler now emits an error when a module in the `src` directory imports
7373 a dev dependency.
7474 ([Surya Rose](https://github.com/GearsDatapacks))
7575···8181- `gleam add` now adds `dependencies` and `dev-dependencies` as tables instead
8282 of inline tables if they are missing.
8383 ([Andrey Kozhev](https://github.com/ankddev))
8484-8585-- The build tool now prevents publishing packages and exporting Erlang shipments
8686- when a module in the package's `src` directory imports a dev dependency.
8787- ([Surya Rose](https://github.com/GearsDatapacks))
88848985### Language server
9086
···61616262 if let Err(e) = self.check_for_invalid_imports(module_info, location) {
6363 self.problems.error(e);
6464- return;
6564 }
66656766 if let Err(e) = self.register_module(import, module_info) {
···248247 module_info: &ModuleInterface,
249248 location: SrcSpan,
250249 ) -> Result<(), Error> {
251251- // Files in `src` are not allowed to import dev dependencies. We can't
252252- // raise an error here, as that would be a breaking change, so we must
253253- // raise a warning instead.
254250 if self.origin.is_src()
255251 && self
256252 .environment
257253 .dev_dependencies
258254 .contains(&module_info.package)
259255 {
260260- self.problems.warning(Warning::SrcImportingDevDependency {
256256+ return Err(Error::SrcImportingDevDependency {
261257 importing_module: self.environment.current_module.clone(),
262258 imported_module: module_info.name.clone(),
263259 package: module_info.package.clone(),
···298298 )]
299299 CannotPublishLeakedInternalType { unfinished: Vec<EcoString> },
300300301301- #[error("The modules {modules:?} import dev dependencies cannot be published")]
302302- CannotPublishImportingDevDependency { modules: Vec<EcoString> },
303303-304304- #[error("The modules {modules:?} import dev dependencies cannot be exported")]
305305- CannotExportShipmentImportingDevDependency { modules: Vec<EcoString> },
306306-307301 #[error("Publishing packages to reserve names is not permitted")]
308302 HexPackageSquatting,
309303···10441038Please make sure internal types do not appear in public functions and try again.
10451039",
10461040 unfinished
10471047- .iter()
10481048- .map(|name| format!(" - {}", name.as_str()))
10491049- .join("\n")
10501050- ),
10511051- level: Level::Error,
10521052- hint: None,
10531053- location: None,
10541054- }],
10551055-10561056- Error::CannotPublishImportingDevDependency { modules } => vec![Diagnostic {
10571057- title: "Cannot publish code importing dev dependencies".into(),
10581058- text: wrap_format!(
10591059- "These modules import dev dependencies and cannot be published:
10601060-10611061-{}
10621062-10631063-Dev dependencies are not available for published packages, so publishing code \
10641064-importing them would lead to invalid code when this package is added as a \
10651065-dependency. Please make sure your package does not import dev dependencies and \
10661066-try again.",
10671067- modules
10681068- .iter()
10691069- .map(|name| format!(" - {}", name.as_str()))
10701070- .join("\n")
10711071- ),
10721072- level: Level::Error,
10731073- hint: None,
10741074- location: None,
10751075- }],
10761076-10771077- Error::CannotExportShipmentImportingDevDependency { modules } => vec![Diagnostic {
10781078- title: "Cannot export code importing dev dependencies".into(),
10791079- text: wrap_format!(
10801080- "These modules import dev dependencies and cannot be export \
10811081-as an Erlang shipment:
10821082-10831083-{}
10841084-10851085-Dev dependencies are not available for production builds, so exported code \
10861086-importing them would lead to invalid code when run. Please make sure your \
10871087-package does not import dev dependencies and try again.",
10881088- modules
10891041 .iter()
10901042 .map(|name| format!(" - {}", name.as_str()))
10911043 .join("\n")
···39343886 location: Some(Location {
39353887 label: Label {
39363888 text: Some("You can safely remove this.".to_string()),
38893889+ span: *location,
38903890+ },
38913891+ path: path.clone(),
38923892+ src: src.clone(),
38933893+ extra_labels: vec![],
38943894+ }),
38953895+ },
38963896+38973897+ TypeError::SrcImportingDevDependency {
38983898+ location,
38993899+ importing_module,
39003900+ imported_module,
39013901+ package,
39023902+ } => Diagnostic {
39033903+ title: "App importing dev dependency".to_string(),
39043904+ text: wrap_format!(
39053905+ "The application module `{importing_module}` is \
39063906+importing the module `{imported_module}`, but `{package}`, the package it \
39073907+belongs to, is a dev dependency.
39083908+39093909+Dev dependencies are not included in production builds so application \
39103910+modules should not import them. Perhaps change `{package}` to a regular dependency."
39113911+ ),
39123912+ hint: None,
39133913+ level: Level::Error,
39143914+ location: Some(Location {
39153915+ label: Label {
39163916+ text: None,
39373917 span: *location,
39383918 },
39393919 path: path.clone(),
···11---
22-source: compiler-core/src/type_/tests/warnings.rs
22+source: compiler-core/src/type_/tests/errors.rs
33expression: "\nimport some_module\n\npub fn main() {\n some_module.main()\n}\n"
44---
55----- SOURCE CODE
···1515}
161617171818------ WARNING
1919-warning: App importing dev dependency
2020- ┌─ /src/warning/wrn.gleam:2:1
1818+----- ERROR
1919+error: App importing dev dependency
2020+ ┌─ /src/one/two.gleam:2:1
2121 │
22222 │ import some_module
2323 │ ^^^^^^^^^^^^^^^^^^
24242525-The application module `test_module` is importing the module `some_module`,
2525+The application module `themodule` is importing the module `some_module`,
2626but `dev_dependency`, the package it belongs to, is a dev dependency.
27272828Dev dependencies are not included in production builds so application
2929modules should not import them. Perhaps change `dev_dependency` to a
3030regular dependency.
3131-3232-In a future version of Gleam this may become a compile error.
···13531353 extra_labels: vec![],
13541354 }),
13551355 },
13561356-13571357- type_::Warning::SrcImportingDevDependency {
13581358- location,
13591359- importing_module,
13601360- imported_module,
13611361- package,
13621362- } => {
13631363- let text = wrap(&format!(
13641364- "The application module `{importing_module}` is \
13651365-importing the module `{imported_module}`, but `{package}`, the package it \
13661366-belongs to, is a dev dependency.
13671367-13681368-Dev dependencies are not included in production builds so application \
13691369-modules should not import them. Perhaps change `{package}` to a regular dependency.
13701370-13711371-In a future version of Gleam this may become a compile error."
13721372- ));
13731373- Diagnostic {
13741374- title: "App importing dev dependency".into(),
13751375- text,
13761376- hint: None,
13771377- level: diagnostic::Level::Warning,
13781378- location: Some(Location {
13791379- src: src.clone(),
13801380- path: path.to_path_buf(),
13811381- label: diagnostic::Label {
13821382- text: None,
13831383- span: *location,
13841384- },
13851385- extra_labels: Vec::new(),
13861386- }),
13871387- }
13881388- }
13891356 },
1390135713911358 Warning::DeprecatedEnvironmentVariable { variable } => {
···29293030- [x] Emits warning when used.
31313232-## Development dependencies in `src/` code
3333-3434-Do not allow to use dev dependencies within `src/`.
3535-3636-- [x] Emits warning when used.
3737-- [x] Blocks `gleam export erlang-shipment`.
3838-- [x] Blocks `gleam publish`.
3939-4032## JavaScript runtime error `fn` property
41334234On JavaScript there is a deprecated `fn` property. This was a mistake, it