From 65f6e0d09ec170d589525ba1f1159f3986766f93 Mon Sep 17 00:00:00 2001 From: Young-Flash Date: Tue, 5 Nov 2024 14:13:05 +0800 Subject: [PATCH] allow alias not set when path provided --- .../fancy_import.in/import004/main/moon.pkg.json | 3 +-- crates/moonbuild/template/pkg.schema.json | 6 ++++-- crates/moonutil/src/package.rs | 14 +++++++------- docs/manual-zh/src/source/pkg_json_schema.html | 6 ++++-- docs/manual/src/source/pkg_json_schema.html | 6 ++++-- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/crates/moon/tests/test_cases/fancy_import.in/import004/main/moon.pkg.json b/crates/moon/tests/test_cases/fancy_import.in/import004/main/moon.pkg.json index c6f47291..9e05c066 100644 --- a/crates/moon/tests/test_cases/fancy_import.in/import004/main/moon.pkg.json +++ b/crates/moon/tests/test_cases/fancy_import.in/import004/main/moon.pkg.json @@ -11,8 +11,7 @@ "alias": "lib3" }, { - "path": "moonbitlang/import004/lib4", - "alias": "" + "path": "moonbitlang/import004/lib4" } ] } \ No newline at end of file diff --git a/crates/moonbuild/template/pkg.schema.json b/crates/moonbuild/template/pkg.schema.json index ba95ab08..e78734e9 100644 --- a/crates/moonbuild/template/pkg.schema.json +++ b/crates/moonbuild/template/pkg.schema.json @@ -253,12 +253,14 @@ { "type": "object", "required": [ - "alias", "path" ], "properties": { "alias": { - "type": "string" + "type": [ + "string", + "null" + ] }, "path": { "type": "string" diff --git a/crates/moonutil/src/package.rs b/crates/moonutil/src/package.rs index 6e354f55..a684f69d 100644 --- a/crates/moonutil/src/package.rs +++ b/crates/moonutil/src/package.rs @@ -145,7 +145,7 @@ pub enum PkgJSONImportItem { String(String), Object { path: String, - alias: String, + alias: Option, value: Option>, }, } @@ -503,13 +503,13 @@ pub fn convert_pkg_json_to_package(j: MoonPkgJSON) -> anyhow::Result { path, alias, value: _, - } => { - if alias.is_empty() { - imports.push(Import::Simple(path)); - } else { - imports.push(Import::Alias { path, alias }) + } => match alias { + None => imports.push(Import::Simple(path)), + Some(alias) if alias.is_empty() => { + imports.push(Import::Simple(path)) } - } + Some(alias) => imports.push(Import::Alias { path, alias }), + }, } } } diff --git a/docs/manual-zh/src/source/pkg_json_schema.html b/docs/manual-zh/src/source/pkg_json_schema.html index 243607bd..1e79bc34 100644 --- a/docs/manual-zh/src/source/pkg_json_schema.html +++ b/docs/manual-zh/src/source/pkg_json_schema.html @@ -291,12 +291,14 @@ { "type": "object", "required": [ - "alias", "path" ], "properties": { "alias": { - "type": "string" + "type": [ + "string", + "null" + ] }, "path": { "type": "string" diff --git a/docs/manual/src/source/pkg_json_schema.html b/docs/manual/src/source/pkg_json_schema.html index 243607bd..1e79bc34 100644 --- a/docs/manual/src/source/pkg_json_schema.html +++ b/docs/manual/src/source/pkg_json_schema.html @@ -291,12 +291,14 @@ { "type": "object", "required": [ - "alias", "path" ], "properties": { "alias": { - "type": "string" + "type": [ + "string", + "null" + ] }, "path": { "type": "string"