diff --git a/cli/tests/integration/publish_tests.rs b/cli/tests/integration/publish_tests.rs index a28736fac8..e185065aa5 100644 --- a/cli/tests/integration/publish_tests.rs +++ b/cli/tests/integration/publish_tests.rs @@ -71,6 +71,16 @@ itest!(successful { temp_cwd: true, }); +itest!(config_file_jsonc { + args: "publish --token 'sadfasdf'", + output: "publish/deno_jsonc.out", + cwd: Some("publish/deno_jsonc"), + copy_temp_dir: Some("publish/deno_jsonc"), + envs: env_vars_for_registry(), + http_server: true, + temp_cwd: true, +}); + itest!(workspace_all { args: "publish --token 'sadfasdf'", output: "publish/workspace.out", diff --git a/cli/tests/testdata/publish/deno_jsonc.out b/cli/tests/testdata/publish/deno_jsonc.out new file mode 100644 index 0000000000..2d5e4ffea6 --- /dev/null +++ b/cli/tests/testdata/publish/deno_jsonc.out @@ -0,0 +1,6 @@ +Checking fast check type graph for errors... +Ensuring type checks... +Check file:///[WILDCARD]/publish/deno_jsonc/mod.ts +Publishing @foo/bar@1.0.0 ... +Successfully published @foo/bar@1.0.0 +Visit http://127.0.0.1:4250/@foo/bar@1.0.0 for details diff --git a/cli/tests/testdata/publish/deno_jsonc/deno.jsonc b/cli/tests/testdata/publish/deno_jsonc/deno.jsonc new file mode 100644 index 0000000000..4c9dfb08cc --- /dev/null +++ b/cli/tests/testdata/publish/deno_jsonc/deno.jsonc @@ -0,0 +1,11 @@ +{ + // It's .jsonc file so it can have comments + "name": "@foo/bar", + "version": "1.0.0", + "exports": { + ".": "./mod.ts" + }, + "imports": { + "@std/http": "./std_http.ts" + } +} diff --git a/cli/tests/testdata/publish/deno_jsonc/mod.ts b/cli/tests/testdata/publish/deno_jsonc/mod.ts new file mode 100644 index 0000000000..4bb6da2555 --- /dev/null +++ b/cli/tests/testdata/publish/deno_jsonc/mod.ts @@ -0,0 +1,5 @@ +import http from "@std/http"; + +export function foobar(): { fileServer(): void } { + return http.fileServer; +} diff --git a/cli/tests/testdata/publish/deno_jsonc/std_http.ts b/cli/tests/testdata/publish/deno_jsonc/std_http.ts new file mode 100644 index 0000000000..9d57b36f34 --- /dev/null +++ b/cli/tests/testdata/publish/deno_jsonc/std_http.ts @@ -0,0 +1,6 @@ +// temp until we get jsr:@std/http in the test server +export default { + fileServer() { + console.log("Hi"); + }, +}; diff --git a/cli/tests/testdata/publish/missing_deno_json.out b/cli/tests/testdata/publish/missing_deno_json.out index adaf33ea8b..adb472c715 100644 --- a/cli/tests/testdata/publish/missing_deno_json.out +++ b/cli/tests/testdata/publish/missing_deno_json.out @@ -1 +1 @@ -error: Failed to read deno.json file at [WILDCARD]missing_deno_json[WILDCARD] \ No newline at end of file +error: Couldn't find a deno.json or a deno.jsonc configuration file in [WILDCARD] \ No newline at end of file diff --git a/cli/tools/registry/mod.rs b/cli/tools/registry/mod.rs index 2be90bf520..d635ccf555 100644 --- a/cli/tools/registry/mod.rs +++ b/cli/tools/registry/mod.rs @@ -819,18 +819,22 @@ pub async fn publish( }); let directory_path = cli_factory.cli_options().initial_cwd(); - // TODO: doesn't handle jsonc - let deno_json_path = directory_path.join("deno.json"); - let deno_json = ConfigFile::read(&deno_json_path).with_context(|| { - format!( - "Failed to read deno.json file at {}", - deno_json_path.display() - ) - })?; + + let cli_options = cli_factory.cli_options(); + let Some(config_file) = cli_options.maybe_config_file() else { + bail!( + "Couldn't find a deno.json or a deno.jsonc configuration file in {}.", + directory_path.display() + ); + }; let (publish_order_graph, prepared_package_by_name) = - prepare_packages_for_publishing(&cli_factory, deno_json, import_map) - .await?; + prepare_packages_for_publishing( + &cli_factory, + config_file.clone(), + import_map, + ) + .await?; if prepared_package_by_name.is_empty() { bail!("No packages to publish");