From 0e4d1cb5f9a3645f6da480b2b8540568fa69d675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 27 Mar 2024 17:51:52 +0000 Subject: [PATCH] feat(init): use jsr specifier for @std/assert (#23073) This commit changes "deno init" subcommand to use "jsr:" specifier for standard library "assert" module. It is unversioned, but we will change it to `@^1` once `@std/assert` release version 1.0. This allows us to start decoupling `deno` and `deno_std` release. The release scripts have been updated to take that into account. --- cli/deno_std.rs | 5 ----- cli/main.rs | 1 - cli/tools/init/mod.rs | 9 +++++---- cli/tools/init/templates/main_test.ts | 2 +- tests/integration/init_tests.rs | 6 +++--- .../@std/assert/0.220.1/assert_equals.ts | 9 +++++++++ .../jsr/registry/@std/assert/0.220.1/mod.ts | 20 +++++++++++++++++++ .../registry/@std/assert/0.220.1_meta.json | 6 ++++++ .../jsr/registry/@std/assert/meta.json | 8 ++++++++ tools/release/01_bump_crate_versions.ts | 19 ------------------ tools/release/02_create_pr.ts | 1 - tools/release/release_doc_template.md | 3 +-- 12 files changed, 53 insertions(+), 36 deletions(-) delete mode 100644 cli/deno_std.rs create mode 100644 tests/testdata/jsr/registry/@std/assert/0.220.1/assert_equals.ts create mode 100644 tests/testdata/jsr/registry/@std/assert/0.220.1/mod.ts create mode 100644 tests/testdata/jsr/registry/@std/assert/0.220.1_meta.json create mode 100644 tests/testdata/jsr/registry/@std/assert/meta.json diff --git a/cli/deno_std.rs b/cli/deno_std.rs deleted file mode 100644 index cef67711d8..0000000000 --- a/cli/deno_std.rs +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. - -// WARNING: Ensure this is the only deno_std version reference as this -// is automatically updated by the version bump workflow. -pub const CURRENT_STD_URL_STR: &str = "https://deno.land/std@0.220.0/"; diff --git a/cli/main.rs b/cli/main.rs index 32e40ff513..ecf171e726 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -4,7 +4,6 @@ mod args; mod auth_tokens; mod cache; mod cdp; -mod deno_std; mod emit; mod errors; mod factory; diff --git a/cli/tools/init/mod.rs b/cli/tools/init/mod.rs index 7222a762f6..fb2e6e7afd 100644 --- a/cli/tools/init/mod.rs +++ b/cli/tools/init/mod.rs @@ -2,7 +2,6 @@ use crate::args::InitFlags; use crate::colors; -use crate::deno_std; use deno_core::anyhow::Context; use deno_core::error::AnyError; use log::info; @@ -46,9 +45,11 @@ pub fn init_project(init_flags: InitFlags) -> Result<(), AnyError> { let main_ts = include_str!("./templates/main.ts"); create_file(&dir, "main.ts", main_ts)?; - let main_test_ts = include_str!("./templates/main_test.ts") - .replace("{CURRENT_STD_URL}", deno_std::CURRENT_STD_URL_STR); - create_file(&dir, "main_test.ts", &main_test_ts)?; + create_file( + &dir, + "main_test.ts", + include_str!("./templates/main_test.ts"), + )?; create_file(&dir, "deno.json", include_str!("./templates/deno.json"))?; info!("✅ {}", colors::green("Project initialized")); diff --git a/cli/tools/init/templates/main_test.ts b/cli/tools/init/templates/main_test.ts index 505b1abb05..26af2582bc 100644 --- a/cli/tools/init/templates/main_test.ts +++ b/cli/tools/init/templates/main_test.ts @@ -1,4 +1,4 @@ -import { assertEquals } from "{CURRENT_STD_URL}assert/mod.ts"; +import { assertEquals } from "jsr:@std/assert"; import { add } from "./main.ts"; Deno.test(function addTest() { diff --git a/tests/integration/init_tests.rs b/tests/integration/init_tests.rs index d3908eae4a..d2a9fa59bc 100644 --- a/tests/integration/init_tests.rs +++ b/tests/integration/init_tests.rs @@ -6,7 +6,7 @@ use util::TestContextBuilder; #[test] fn init_subcommand_without_dir() { - let context = TestContextBuilder::new().use_temp_cwd().build(); + let context = TestContextBuilder::for_jsr().use_temp_cwd().build(); let cwd = context.temp_dir().path(); let output = context.new_command().args("init").split_output().run(); @@ -46,7 +46,7 @@ fn init_subcommand_without_dir() { #[test] fn init_subcommand_with_dir_arg() { - let context = TestContextBuilder::new().use_temp_cwd().build(); + let context = TestContextBuilder::for_jsr().use_temp_cwd().build(); let cwd = context.temp_dir().path(); let output = context @@ -92,7 +92,7 @@ fn init_subcommand_with_dir_arg() { #[test] fn init_subcommand_with_quiet_arg() { - let context = TestContextBuilder::new().use_temp_cwd().build(); + let context = TestContextBuilder::for_jsr().use_temp_cwd().build(); let cwd = context.temp_dir().path(); let output = context diff --git a/tests/testdata/jsr/registry/@std/assert/0.220.1/assert_equals.ts b/tests/testdata/jsr/registry/@std/assert/0.220.1/assert_equals.ts new file mode 100644 index 0000000000..bd58194d01 --- /dev/null +++ b/tests/testdata/jsr/registry/@std/assert/0.220.1/assert_equals.ts @@ -0,0 +1,9 @@ +// deno-lint-ignore-file +export function assertEquals( + actual: T, + expected: T, + msg?: string, + options: { formatter?: (value: unknown) => string } = {}, +) { + return true; +} diff --git a/tests/testdata/jsr/registry/@std/assert/0.220.1/mod.ts b/tests/testdata/jsr/registry/@std/assert/0.220.1/mod.ts new file mode 100644 index 0000000000..2d7913a024 --- /dev/null +++ b/tests/testdata/jsr/registry/@std/assert/0.220.1/mod.ts @@ -0,0 +1,20 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +/** A library of assertion functions. + * If the assertion is false an `AssertionError` will be thrown which will + * result in pretty-printed diff of failing assertion. + * + * This module is browser compatible, but do not rely on good formatting of + * values for AssertionError messages in browsers. + * + * ```ts + * import { assert } from "@std/assert/assert"; + * + * assert("I am truthy"); // Doesn't throw + * assert(false); // Throws `AssertionError` + * ``` + * + * @module + */ + +export * from "./assert_equals.ts"; diff --git a/tests/testdata/jsr/registry/@std/assert/0.220.1_meta.json b/tests/testdata/jsr/registry/@std/assert/0.220.1_meta.json new file mode 100644 index 0000000000..6779281672 --- /dev/null +++ b/tests/testdata/jsr/registry/@std/assert/0.220.1_meta.json @@ -0,0 +1,6 @@ +{ + "exports": { + ".": "./mod.ts", + "./assert_equals": "./assert_equals.ts" + } +} diff --git a/tests/testdata/jsr/registry/@std/assert/meta.json b/tests/testdata/jsr/registry/@std/assert/meta.json new file mode 100644 index 0000000000..4bb721c891 --- /dev/null +++ b/tests/testdata/jsr/registry/@std/assert/meta.json @@ -0,0 +1,8 @@ +{ + "scope": "std", + "name": "assert", + "latest": "0.220.1", + "versions": { + "0.220.1": {} + } +} diff --git a/tools/release/01_bump_crate_versions.ts b/tools/release/01_bump_crate_versions.ts index 4f974e2d51..bef8011ba1 100755 --- a/tools/release/01_bump_crate_versions.ts +++ b/tools/release/01_bump_crate_versions.ts @@ -26,10 +26,6 @@ for (const crate of workspace.getCliDependencyCrates()) { await crate.increment("minor"); } -// update the std version used in the code -$.logStep("Updating std version..."); -await updateStdVersion(); - // update the lock file await workspace.getCliCrate().cargoUpdate("--workspace"); @@ -98,21 +94,6 @@ async function getGitLog() { } } -async function updateStdVersion() { - const compatFilePath = cliCrate.folderPath.join("deno_std.rs"); - const text = await compatFilePath.readText(); - const versionRe = /std@([0-9]+\.[0-9]+\.[0-9]+)/; - const stdVersionText = versionRe.exec(text)?.[1]; - if (stdVersionText == null) { - throw new Error(`Could not find the deno_std version in ${compatFilePath}`); - } - const stdVersion = semver.parse(stdVersionText)!; - const newStdVersion = stdVersion.increment("minor"); - await compatFilePath.writeText( - text.replace(versionRe, `std@${newStdVersion}`), - ); -} - async function bumpCiCacheVersion() { const generateScript = workspace.repo.folderPath.join( ".github/workflows/ci.generate.ts", diff --git a/tools/release/02_create_pr.ts b/tools/release/02_create_pr.ts index af3f81f02d..5ef64cd144 100755 --- a/tools/release/02_create_pr.ts +++ b/tools/release/02_create_pr.ts @@ -36,7 +36,6 @@ function getPrBody() { `Please ensure:\n` + `- [ ] Target branch is correct (\`vX.XX\` if a patch release, \`main\` if minor)\n` + `- [ ] Crate versions are bumped correctly\n` + - `- [ ] deno_std version is incremented in the code (see \`cli/deno_std.rs\`)\n` + `- [ ] Releases.md is updated correctly (think relevancy and remove reverts)\n\n` + `To make edits to this PR:\n` + "```shell\n" + diff --git a/tools/release/release_doc_template.md b/tools/release/release_doc_template.md index d174733a5b..83b5d67664 100644 --- a/tools/release/release_doc_template.md +++ b/tools/release/release_doc_template.md @@ -101,8 +101,7 @@ verify on GitHub that everything looks correct. 1. Checkout the branch the release is being made on. 2. Manually run `./tools/release/01_bump_crate_versions.ts` 1. Ensure the crate versions were bumped correctly - 2. Ensure deno_std version was updated correctly in `cli/deno_std.rs` - 3. Ensure `Releases.md` was updated correctly + 2. Ensure `Releases.md` was updated correctly 3. Open a PR with the changes and continue with the steps below.