diff --git a/.devcontainer/cargo/devcontainer.json b/.devcontainer/cargo/devcontainer.json index 752e33c..9747933 100644 --- a/.devcontainer/cargo/devcontainer.json +++ b/.devcontainer/cargo/devcontainer.json @@ -10,7 +10,7 @@ "version": "lts" } }, - "onCreateCommand": "node scripts/prepare-demo.mjs cargo", + "onCreateCommand": ".devcontainer/cargo/setup.sh", "waitFor": "onCreateCommand", "customizations": { "vscode": { diff --git a/.devcontainer/cargo/setup.sh b/.devcontainer/cargo/setup.sh new file mode 100755 index 0000000..79e1765 --- /dev/null +++ b/.devcontainer/cargo/setup.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Creation-time setup for the Rust demo Codespace. +# +# Drift's Rust surface diff shells out to `cargo public-api`, which reads +# rustdoc's unstable JSON output and so needs the nightly toolchain. Drift will +# install both itself on first analysis (`tools.autoInstall` defaults to true), +# but `cargo install cargo-public-api` compiles from source — several minutes +# with the Drift panel apparently frozen. Doing it here moves that wait into +# the Codespace build, where it belongs. +# +# cargo-public-api is pinned; the nightly channel is not, matching what Drift's +# own auto-install does (`rustup toolchain install nightly --profile minimal`). +set -euo pipefail + +CARGO_PUBLIC_API_VERSION="0.52.0" + +echo "==> Installing nightly toolchain (required by cargo public-api)" +rustup toolchain install nightly --profile minimal + +echo "==> Installing cargo-public-api $CARGO_PUBLIC_API_VERSION" +cargo install cargo-public-api --locked --version "$CARGO_PUBLIC_API_VERSION" + +echo "==> Preparing the Rust demo" +node scripts/prepare-demo.mjs cargo + +echo "==> Rust demo ready" diff --git a/.devcontainer/vcpkg/devcontainer.json b/.devcontainer/vcpkg/devcontainer.json index 7085aa8..fc65ccb 100644 --- a/.devcontainer/vcpkg/devcontainer.json +++ b/.devcontainer/vcpkg/devcontainer.json @@ -42,7 +42,7 @@ "codespaces": { "openFiles": [ "demos/vcpkg/DEMO.md", - "demos/vcpkg/src/main.cpp", + "demos/vcpkg/src/tests.cpp", "demos/vcpkg/vcpkg.json" ] } diff --git a/README.md b/README.md index 2865c57..6407107 100644 --- a/README.md +++ b/README.md @@ -1,55 +1,60 @@ # Drift demos -Example projects for Drift's **Try Drift in your browser** experience. Each one -is a tiny real project pinned to an old version of a real dependency, with -source code that uses APIs the newer version breaks. +Small example projects for trying [Drift](https://github.com/trydrift/drift) in +the browser. Each one is pinned to an old version of a real dependency and uses +an API the newer version breaks. -Open one in a Codespace and Drift is already installed, the upgrade is already -applied, and there is something real for it to find. +Open one in a Codespace: Drift is installed, the upgrade is already applied, and +there is something real for it to find. -## How it works +## How the demo state works -Each demo is committed at the **old** dependency version, with source code that -was correct for it. Codespace creation edits the manifest to the **new** version -and leaves the source alone: +Each demo is committed at the **old** dependency version, with source that was +correct for it. Codespace creation edits the manifest to the **new** version and +leaves the source alone: ``` committed: dependency@OLD + source written for OLD after setup: dependency@NEW + source written for OLD ← Drift analyses this ``` -`git status` in a fresh Codespace shows only the manifest as modified. Every -breaking usage in the source is marked with a `BREAKING` comment explaining what -changed and why it no longer works. +`git status` in a fresh Codespace shows only the manifest as modified. Each +breaking usage carries a `BREAKING` comment naming the change. -## The demos - -| Ecosystem | Language | Dependency | Upgrade | -| --- | --- | --- | --- | -| `npm` | JavaScript / TypeScript | `axios` | 0.21.4 → 1.7.7 | -| `pypi` | Python | `werkzeug` | 2.0.3 → 2.1.0 | -| `go` | Go | `golang.org/x/exp` | 2023-05 → 2023-10 | -| `cargo` | Rust | `clap` | 2.34.0 → 4.5.4 | -| `maven` | Java / Kotlin / Scala | `com.google.guava:guava` | 20.0 → 21.0 | -| `rubygems` | Ruby | `rack` | 3.0.0 → 3.1.0 | -| `nuget` | .NET | `AutoMapper` | 8.1.1 → 9.0.0 | -| `packagist` | PHP | `monolog/monolog` | 2.9.3 → 3.5.0 | -| `hex` | Elixir / Erlang | `plug` | 1.13.6 → 1.15.0 | -| `pub` | Dart / Flutter | `dio` | 4.0.6 → 5.0.0 | -| `swift` | Swift | `Alamofire` | 4.9.1 → 5.9.1 | -| `cocoapods` | CocoaPods | `Alamofire` | 4.9.1 → 5.9.1 | -| `opam` | OCaml | `lwt` | 4.5.0 → 5.7.0 | -| `conan` | C / C++ (Conan) | `fmt` | 9.1.0 → 10.2.1 | -| `vcpkg` | C / C++ (vcpkg) | `spdlog` | 1.11.0 → 1.14.1 | -| `arduino` | Arduino / PlatformIO | `ArduinoJson` | 5.13.5 → 6.21.3 | - -## Launching one +Demos aim for **1–3 clear, documented breaks** — one indisputable example beats +several arguable ones. -``` -https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2F%2Fdevcontainer.json -``` +## The demos -Requires a GitHub account, and runs on your own GitHub Codespaces allowance. + + +| Ecosystem | Language | Dependency | Upgrade | Try | +| --- | --- | --- | --- | --- | +| `npm` | JavaScript / TypeScript | `axios` | 0.21.4 → 1.7.7 | [Open](https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fnpm%2Fdevcontainer.json) | +| `pypi` | Python | `werkzeug` | 2.0.3 → 2.1.0 | [Open](https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fpypi%2Fdevcontainer.json) | +| `go` | Go | `golang.org/x/exp` | 2023-05-22 → 2023-10-06 | [Open](https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fgo%2Fdevcontainer.json) | +| `cargo` | Rust | `clap` | 2.34.0 → 4.5.4 | [Open](https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fcargo%2Fdevcontainer.json) | +| `maven` | Java / Kotlin / Scala | `com.google.guava:guava` | 20.0 → 21.0 | [Open](https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fmaven%2Fdevcontainer.json) | +| `rubygems` | Ruby | `rack` | 3.0.0 → 3.1.0 | [Open](https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Frubygems%2Fdevcontainer.json) | +| `nuget` | .NET | `AutoMapper` | 8.1.1 → 9.0.0 | [Open](https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fnuget%2Fdevcontainer.json) | +| `packagist` | PHP | `monolog/monolog` | 2.9.3 → 3.5.0 | [Open](https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fpackagist%2Fdevcontainer.json) | +| `hex` | Elixir / Erlang | `plug` | 1.13.6 → 1.15.0 | [Open](https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fhex%2Fdevcontainer.json) | +| `pub` | Dart / Flutter | `dio` | 4.0.6 → 5.0.0 | [Open](https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fpub%2Fdevcontainer.json) | +| `swift` | Swift | `https://github.com/Alamofire/Alamofire` | 4.9.1 → 5.9.1 | [Open](https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fswift%2Fdevcontainer.json) | +| `cocoapods` | CocoaPods | `Alamofire` | 4.9.1 → 5.9.1 | [Open](https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fcocoapods%2Fdevcontainer.json) | +| `opam` | OCaml | `lwt` | 4.5.0 → 5.7.0 | [Open](https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fopam%2Fdevcontainer.json) | +| `conan` | C / C++ (Conan) | `fmt` | 9.1.0 → 10.2.1 | [Open](https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fconan%2Fdevcontainer.json) | +| `vcpkg` | C / C++ (vcpkg) | `catch2` | 2.13.9 → 3.5.2 | [Open](https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fvcpkg%2Fdevcontainer.json) | +| `arduino` | Arduino / PlatformIO | `bblanchon/ArduinoJson` | 5.13.5 → 6.21.3 | [Open](https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Farduino%2Fdevcontainer.json) | + + + +Launching one requires a GitHub account and uses your own GitHub Codespaces +allowance. + +> These are prepared fixtures. No demo has been smoke-tested in a real Codespace +> yet, and the `drift.drift` Marketplace install cannot be verified until the +> extension is published. ## Layout @@ -58,7 +63,7 @@ demos// ├── DEMO.md generated from the BREAKING comments in the source ├── demo.json dependency, versions, and the manifest edit ├── pinned to the old version -└── uses APIs the new version breaks +└── uses an API the new version breaks ``` ## Scripts @@ -68,9 +73,6 @@ node scripts/prepare-demo.mjs # apply the upgrade (what the Codesp node scripts/reset-demo.mjs # put the manifest back node scripts/sync-devcontainers.mjs # regenerate .devcontainer/* node scripts/make-demo-docs.mjs # regenerate DEMO.md files +node scripts/make-readme.mjs # regenerate the table above node scripts/check-demos.mjs # sanity check, no toolchains needed ``` - -## Drift - -https://github.com/trydrift/drift diff --git a/demos/arduino/DEMO.md b/demos/arduino/DEMO.md index d5dcacf..fe1716d 100644 --- a/demos/arduino/DEMO.md +++ b/demos/arduino/DEMO.md @@ -6,7 +6,7 @@ The Codespace upgraded it to **6.21.3** and left the source code alone, so `src/main.cpp` is now written against an API that no longer exists. That is the situation Drift is built to analyse. -5 breaking changes in this demo: +The 5 breaking changes in this demo: 1. StaticJsonBuffer was removed in ArduinoJson 6, replaced by StaticJsonDocument. The buffer/document split is gone entirely. 2. JsonObject was a reference type created from the buffer in v5 (`JsonObject& root = jsonBuffer.createObject()`). In v6 it is a value type obtained from a document with `doc.to()`. diff --git a/demos/cargo/DEMO.md b/demos/cargo/DEMO.md index 0f48a49..0f6be5d 100644 --- a/demos/cargo/DEMO.md +++ b/demos/cargo/DEMO.md @@ -6,7 +6,7 @@ The Codespace upgraded it to **4.5.4** and left the source code alone, so `src/main.rs` is now written against an API that no longer exists. That is the situation Drift is built to analyse. -5 breaking changes in this demo: +The 5 breaking changes in this demo: 1. `clap::App` was renamed to `clap::Command` in clap 3 and the old name was removed in clap 4. This import no longer resolves. 2. `clap::SubCommand` was removed in clap 3 — subcommands are just `Command` values now, built with `Command::new(..)`. diff --git a/demos/cocoapods/DEMO.md b/demos/cocoapods/DEMO.md index 98fd5c8..404972b 100644 --- a/demos/cocoapods/DEMO.md +++ b/demos/cocoapods/DEMO.md @@ -6,7 +6,7 @@ The Codespace upgraded it to **5.9.1** and left the source code alone, so `DriftDemo/NetworkService.swift` is now written against an API that no longer exists. That is the situation Drift is built to analyse. -5 breaking changes in this demo: +The 5 breaking changes in this demo: 1. SessionManager was removed in Alamofire 5, replaced by Session/AF. 2. Alamofire 5 removed the SessionDelegate hooks that were assigned like this; retry and adapt are handled by a RequestInterceptor now. diff --git a/demos/conan/DEMO.md b/demos/conan/DEMO.md index 2e9c9e2..22f07a8 100644 --- a/demos/conan/DEMO.md +++ b/demos/conan/DEMO.md @@ -6,11 +6,9 @@ The Codespace upgraded it to **10.2.1** and left the source code alone, so `src/main.cpp` is now written against an API that no longer exists. That is the situation Drift is built to analyse. -3 breaking changes in this demo: +The breaking change in this demo: -1. fmt 10 made compile-time format-string checking the default for fmt::format. A runtime std::string as the format argument is now a compile error unless you wrap it in fmt::runtime(..). -2. fmt::join moved out of into in fmt 10, so this no longer resolves with the headers included above. -3. fmt::print(FILE*, ..) with a non-constexpr format string is affected by the same compile-time checking change as fmt::format above. +1. fmt 10.0.0 "removed deprecated implicit conversions for enums and conversions to primitive types for compatibility with std::format and to prevent potential ODR violations. Use `format_as` instead." ## Try it diff --git a/demos/conan/src/main.cpp b/demos/conan/src/main.cpp index 5bb9d9b..fc47763 100644 --- a/demos/conan/src/main.cpp +++ b/demos/conan/src/main.cpp @@ -1,35 +1,27 @@ #include -#include #include -#include // This file is written against fmt 9.1. -// The Codespace upgraded the dependency to fmt 10.2 without touching this -// code. fmt 10 tightened its API considerably, so every marked call below -// stopped compiling. +// The Codespace upgraded the dependency to fmt 10.2 without touching this code. -std::string report(const std::string& name, int count) { - // ── BREAKING 1 ──────────────────────────────────────────────────────── - // fmt 10 made compile-time format-string checking the default for - // fmt::format. A runtime std::string as the format argument is now a - // compile error unless you wrap it in fmt::runtime(..). - std::string pattern = "{}: {} items\n"; - return fmt::format(pattern, name, count); -} +// An ordinary unscoped enum, formatted directly. +enum LogLevel { Debug, Info, Warning, Error }; -std::string join_names(const std::vector& names) { - // ── BREAKING 2 ──────────────────────────────────────────────────────── - // fmt::join moved out of into in fmt 10, so - // this no longer resolves with the headers included above. - return fmt::format("{}", fmt::join(names, ", ")); +// ── BREAKING ────────────────────────────────────────────────────────────── +// fmt 10.0.0 "removed deprecated implicit conversions for enums and +// conversions to primitive types for compatibility with std::format and to +// prevent potential ODR violations. Use `format_as` instead." +// +// In fmt 9 an unscoped enum was implicitly mapped to its underlying integer, +// so this compiled and printed "level=2". In fmt 10 that conversion is gone +// and LogLevel has no formatter, so this is a compile error until the project +// adds `auto format_as(LogLevel l) { return fmt::underlying(l); }`. +std::string describe(LogLevel level) { + return fmt::format("level={}", level); } int main() { - // ── BREAKING 3 ──────────────────────────────────────────────────────── - // fmt::print(FILE*, ..) with a non-constexpr format string is affected by - // the same compile-time checking change as fmt::format above. - fmt::print(stdout, report("widgets", 3)); - fmt::print("{}\n", join_names({"ada", "grace"})); + fmt::print("{}\n", describe(Warning)); return 0; } diff --git a/demos/go/DEMO.md b/demos/go/DEMO.md index ffdf6f8..c8770cc 100644 --- a/demos/go/DEMO.md +++ b/demos/go/DEMO.md @@ -6,7 +6,7 @@ The Codespace upgraded it to **v0.0.0-20231006140011-7918f672742d** and left the `main.go` is now written against an API that no longer exists. That is the situation Drift is built to analyse. -4 breaking changes in this demo: +The 4 breaking changes in this demo: 1. slices.SortFunc took `func(a, b E) bool` (a "less" predicate). It now takes `func(a, b E) int` (a "compare" function, like cmp.Compare). 2. Same change for the stable variant. diff --git a/demos/hex/DEMO.md b/demos/hex/DEMO.md index 277eb24..de8bf5e 100644 --- a/demos/hex/DEMO.md +++ b/demos/hex/DEMO.md @@ -6,11 +6,9 @@ The Codespace upgraded it to **1.15.0** and left the source code alone, so `lib/server.ex` is now written against an API that no longer exists. That is the situation Drift is built to analyse. -3 breaking changes in this demo: +The breaking change in this demo: -1. Plug.Adapters.Cowboy2 was removed in Plug 1.15. It had been a deprecated shim for the separate :plug_cowboy package since Plug 1.7. -2. Plug.Adapters.Test.Conn was removed in the same sweep; the test helper is Plug.Test now. -3. Plug.Parsers.JSON was removed — JSON parsing goes through Plug.Parsers with a :json_decoder option. +1. Plug.Adapters.Cowboy2 was removed in Plug 1.15. It had been a deprecated shim for the separate :plug_cowboy package since Plug 1.7, and lib/plug/adapters/cowboy2.ex is simply gone from the 1.15 release, so this call raises UndefinedFunctionError. ## Try it diff --git a/demos/hex/lib/server.ex b/demos/hex/lib/server.ex index e09736e..3bcfd86 100644 --- a/demos/hex/lib/server.ex +++ b/demos/hex/lib/server.ex @@ -3,28 +3,15 @@ defmodule DriftDemo.Server do HTTP entry point. This module is written against Plug 1.13. The Codespace upgraded the - dependency to Plug 1.15 without touching this code, so every marked call - below refers to something that no longer exists. + dependency to Plug 1.15 without touching this code. """ - # ── BREAKING 1 ────────────────────────────────────────────────────────── + # ── BREAKING ──────────────────────────────────────────────────────────── # Plug.Adapters.Cowboy2 was removed in Plug 1.15. It had been a deprecated - # shim for the separate :plug_cowboy package since Plug 1.7. + # shim for the separate :plug_cowboy package since Plug 1.7, and + # lib/plug/adapters/cowboy2.ex is simply gone from the 1.15 release, so this + # call raises UndefinedFunctionError. def child_spec(port) do Plug.Adapters.Cowboy2.child_spec(scheme: :http, plug: __MODULE__, options: [port: port]) end - - # ── BREAKING 2 ────────────────────────────────────────────────────────── - # Plug.Adapters.Test.Conn was removed in the same sweep; the test helper is - # Plug.Test now. - def test_conn(method, path) do - Plug.Adapters.Test.Conn.conn(%Plug.Conn{}, method, path, nil) - end - - # ── BREAKING 3 ────────────────────────────────────────────────────────── - # Plug.Parsers.JSON was removed — JSON parsing goes through - # Plug.Parsers with a :json_decoder option. - def parser_opts do - [parsers: [Plug.Parsers.JSON], pass: ["application/json"]] - end end diff --git a/demos/maven/DEMO.md b/demos/maven/DEMO.md index 866ebaf..38bf084 100644 --- a/demos/maven/DEMO.md +++ b/demos/maven/DEMO.md @@ -6,7 +6,7 @@ The Codespace upgraded it to **21.0** and left the source code alone, so `src/main/java/com/example/demo/Config.java` is now written against an API that no longer exists. That is the situation Drift is built to analyse. -4 breaking changes in this demo: +The 4 breaking changes in this demo: 1. Objects.firstNonNull was removed in Guava 21. It moved to MoreObjects.firstNonNull back in Guava 18 and the old alias is now gone. 2. Objects.toStringHelper was removed in Guava 21 for the same reason — it is MoreObjects.toStringHelper now. diff --git a/demos/npm/DEMO.md b/demos/npm/DEMO.md index 6c20c1d..9547671 100644 --- a/demos/npm/DEMO.md +++ b/demos/npm/DEMO.md @@ -6,7 +6,7 @@ The Codespace upgraded it to **1.7.7** and left the source code alone, so `src/api-client.ts` is now written against an API that no longer exists. That is the situation Drift is built to analyse. -3 breaking changes in this demo: +The 3 breaking changes in this demo: 1. `AxiosTransformer` was removed in axios 1.0. Response transformers are now typed as `AxiosResponseTransformer` (and request ones as `AxiosRequestTransformer`), so this import no longer resolves at all. 2. `AxiosProxyConfig` used to carry `username` / `password` directly. In axios 1.0 those moved into a nested `auth: { username, password }` object, so these two properties no longer exist on the type. diff --git a/demos/nuget/DEMO.md b/demos/nuget/DEMO.md index 032a599..4758bf5 100644 --- a/demos/nuget/DEMO.md +++ b/demos/nuget/DEMO.md @@ -6,7 +6,7 @@ The Codespace upgraded it to **9.0.0** and left the source code alone, so `Mapping.cs` is now written against an API that no longer exists. That is the situation Drift is built to analyse. -5 breaking changes in this demo: +The 5 breaking changes in this demo: 1. The static Mapper.Initialize was removed in AutoMapper 9. You build a MapperConfiguration and inject IMapper instead. 2. IMapperConfigurationExpression.CreateMissingTypeMaps was removed in AutoMapper 9; every mapping must be declared explicitly. diff --git a/demos/opam/DEMO.md b/demos/opam/DEMO.md index 03e4cee..b2ee598 100644 --- a/demos/opam/DEMO.md +++ b/demos/opam/DEMO.md @@ -6,11 +6,9 @@ The Codespace upgraded it to **5.7.0** and left the source code alone, so `lib/scheduler.ml` is now written against an API that no longer exists. That is the situation Drift is built to analyse. -3 breaking changes in this demo: +The breaking change in this demo: -1. Lwt_sequence was removed from Lwt's public API in Lwt 5.0. It is an internal module now; consumers were told to vendor it. -2. Lwt.wrap1 (and wrap2..wrap7) were removed in Lwt 5.0. -3. Lwt.add_task_l and Lwt.add_task_r were removed in Lwt 5.0 along with the public Lwt_sequence they operated on. +1. Lwt 5.0.0 narrowed [Lwt.async] from [(unit -> _ t) -> unit] to [(unit -> unit t) -> unit]: the callback must now evaluate to [unit Lwt.t] rather than any ['a Lwt.t]. The callback below returns [int Lwt.t], which compiled under Lwt 4 and is a type error under Lwt 5. ## Try it diff --git a/demos/opam/lib/scheduler.ml b/demos/opam/lib/scheduler.ml index 56c2e2b..3587ba7 100644 --- a/demos/opam/lib/scheduler.ml +++ b/demos/opam/lib/scheduler.ml @@ -1,24 +1,14 @@ -(* Task scheduling helpers. +(* Background task helpers. This file is written against Lwt 4.5. The Codespace upgraded the dependency - to Lwt 5.7 without touching this code. Lwt 5.0 removed a batch of APIs that - had been deprecated through the 4.x series, so every marked call below is - gone. *) + to Lwt 5.7 without touching it. *) -(* ── BREAKING 1 ───────────────────────────────────────────────────────── - Lwt_sequence was removed from Lwt's public API in Lwt 5.0. It is an - internal module now; consumers were told to vendor it. *) -let pending : (unit -> unit Lwt.t) Lwt_sequence.t = Lwt_sequence.create () +(* ── BREAKING ─────────────────────────────────────────────────────────── + Lwt 5.0.0 narrowed [Lwt.async] from [(unit -> _ t) -> unit] to + [(unit -> unit t) -> unit]: the callback must now evaluate to [unit Lwt.t] + rather than any ['a Lwt.t]. The callback below returns [int Lwt.t], which + compiled under Lwt 4 and is a type error under Lwt 5. *) +let start_background_count () = + Lwt.async (fun () -> Lwt.return 42) -(* ── BREAKING 2 ───────────────────────────────────────────────────────── - Lwt.wrap1 (and wrap2..wrap7) were removed in Lwt 5.0. *) -let lift_read (read : string -> string) : string -> string Lwt.t = - Lwt.wrap1 read - -(* ── BREAKING 3 ───────────────────────────────────────────────────────── - Lwt.add_task_l and Lwt.add_task_r were removed in Lwt 5.0 along with the - public Lwt_sequence they operated on. *) -let enqueue () = Lwt.add_task_l pending - -let run_all () = - Lwt_sequence.fold_l (fun task acc -> Lwt.bind acc (fun () -> task ())) pending (Lwt.return_unit) +let run () = Lwt_main.run (Lwt.return_unit) diff --git a/demos/packagist/DEMO.md b/demos/packagist/DEMO.md index 58fdb6d..2025913 100644 --- a/demos/packagist/DEMO.md +++ b/demos/packagist/DEMO.md @@ -6,12 +6,10 @@ The Codespace upgraded it to **3.5.0** and left the source code alone, so `src/Logging.php` is now written against an API that no longer exists. That is the situation Drift is built to analyse. -4 breaking changes in this demo: +The 2 breaking changes in this demo: -1. Monolog\Handler\SwiftMailerHandler was deleted in Monolog 3 — SwiftMailer itself is end-of-life, and the handler went with it. -2. Handlers took an int level in Monolog 2 (Logger::WARNING === 300). In Monolog 3 they take a Monolog\Level enum case, and passing an int is a TypeError. -3. Logger::getLevels() was removed in Monolog 3; the Level enum replaces the int/name lookup tables entirely. -4. Logger::getLevelName() was removed for the same reason — a Level enum case knows its own name. +1. Monolog\Handler\SwiftMailerHandler was deleted in Monolog 3 — SwiftMailer itself is end-of-life, and the handler went with it. This class does not exist in 3.x, so resolving the reference below is a fatal error. +2. Logger::getLevels() was removed in Monolog 3. The Level enum replaced the int/name lookup tables, so this static call no longer exists. ## Try it diff --git a/demos/packagist/src/Logging.php b/demos/packagist/src/Logging.php index 8e8a85f..7e72289 100644 --- a/demos/packagist/src/Logging.php +++ b/demos/packagist/src/Logging.php @@ -3,48 +3,26 @@ namespace DriftDemo; use Monolog\Logger; -use Monolog\Handler\StreamHandler; // This file is written against Monolog 2.9. -// The Codespace upgraded the dependency to Monolog 3.0 without touching this -// code. Monolog 3 was a large cleanup, so every marked usage below is broken. +// The Codespace upgraded the dependency to Monolog 3.0 without touching it. // ── BREAKING 1 ──────────────────────────────────────────────────────────── // Monolog\Handler\SwiftMailerHandler was deleted in Monolog 3 — SwiftMailer -// itself is end-of-life, and the handler went with it. +// itself is end-of-life, and the handler went with it. This class does not +// exist in 3.x, so resolving the reference below is a fatal error. use Monolog\Handler\SwiftMailerHandler; class Logging { - public static function build(string $path): Logger - { - $logger = new Logger('app'); - - // ── BREAKING 2 ──────────────────────────────────────────────────── - // Handlers took an int level in Monolog 2 (Logger::WARNING === 300). - // In Monolog 3 they take a Monolog\Level enum case, and passing an - // int is a TypeError. - $logger->pushHandler(new StreamHandler($path, Logger::WARNING)); - - return $logger; - } - - // ── BREAKING 3 ──────────────────────────────────────────────────────── - // Logger::getLevels() was removed in Monolog 3; the Level enum replaces - // the int/name lookup tables entirely. + // ── BREAKING 2 ──────────────────────────────────────────────────────── + // Logger::getLevels() was removed in Monolog 3. The Level enum replaced the + // int/name lookup tables, so this static call no longer exists. public static function levelNames(): array { return array_keys(Logger::getLevels()); } - // ── BREAKING 4 ──────────────────────────────────────────────────────── - // Logger::getLevelName() was removed for the same reason — a Level enum - // case knows its own name. - public static function nameFor(int $level): string - { - return Logger::getLevelName($level); - } - public static function mailHandlerClass(): string { return SwiftMailerHandler::class; diff --git a/demos/pub/DEMO.md b/demos/pub/DEMO.md index f6bc5f0..b0f030a 100644 --- a/demos/pub/DEMO.md +++ b/demos/pub/DEMO.md @@ -6,12 +6,10 @@ The Codespace upgraded it to **5.0.0** and left the source code alone, so `lib/api_client.dart` is now written against an API that no longer exists. That is the situation Drift is built to analyse. -4 breaking changes in this demo: +The 2 breaking changes in this demo: -1. Dio.lock() / unlock() / clear() were removed in Dio 5. Queue control is done with QueuedInterceptor now. -2. connectTimeout / receiveTimeout took an int of milliseconds in Dio 4. In Dio 5 they take a Duration, so an int no longer type-checks. -3. DefaultHttpClientAdapter was removed in Dio 5, replaced by IOHttpClientAdapter. -4. DioError was renamed to DioException in Dio 5. +1. Dio.lock() / unlock() / clear() were removed in Dio 5. Request-queue control is done with QueuedInterceptor now, so these three calls no longer resolve. +2. connectTimeout and receiveTimeout took an int of milliseconds in Dio 4. In Dio 5 they are `Duration?`, so assigning an int no longer type-checks. ## Try it diff --git a/demos/pub/lib/api_client.dart b/demos/pub/lib/api_client.dart index f23d647..fa89618 100644 --- a/demos/pub/lib/api_client.dart +++ b/demos/pub/lib/api_client.dart @@ -3,16 +3,16 @@ import 'package:dio/dio.dart'; /// HTTP client wrapper. /// /// This file is written against Dio 4.0. The Codespace upgraded the dependency -/// to Dio 5.0 without touching this code — Dio 5 was a large API cleanup, so -/// every marked usage below is broken. +/// to Dio 5.0 without touching it. class ApiClient { final Dio _dio = Dio(); /// Hold outgoing requests while the auth token is refreshed. Future refreshToken(Future Function() refresh) async { // ── BREAKING 1 ──────────────────────────────────────────────────────── - // Dio.lock() / unlock() / clear() were removed in Dio 5. Queue control is - // done with QueuedInterceptor now. + // Dio.lock() / unlock() / clear() were removed in Dio 5. Request-queue + // control is done with QueuedInterceptor now, so these three calls no + // longer resolve. _dio.lock(); try { await refresh(); @@ -25,27 +25,9 @@ class ApiClient { /// Configure timeouts. void configureTimeouts() { // ── BREAKING 2 ──────────────────────────────────────────────────────── - // connectTimeout / receiveTimeout took an int of milliseconds in Dio 4. - // In Dio 5 they take a Duration, so an int no longer type-checks. + // connectTimeout and receiveTimeout took an int of milliseconds in Dio 4. + // In Dio 5 they are `Duration?`, so assigning an int no longer type-checks. _dio.options.connectTimeout = 5000; _dio.options.receiveTimeout = 3000; } - - /// Swap in a custom HTTP adapter. - void useCustomAdapter() { - // ── BREAKING 3 ──────────────────────────────────────────────────────── - // DefaultHttpClientAdapter was removed in Dio 5, replaced by - // IOHttpClientAdapter. - _dio.httpClientAdapter = DefaultHttpClientAdapter(); - } - - /// Describe a failure. - String describe(Object error) { - // ── BREAKING 4 ──────────────────────────────────────────────────────── - // DioError was renamed to DioException in Dio 5. - if (error is DioError) { - return 'request failed: ${error.message}'; - } - return 'unknown error'; - } } diff --git a/demos/pypi/DEMO.md b/demos/pypi/DEMO.md index ed9e56e..45c46a0 100644 --- a/demos/pypi/DEMO.md +++ b/demos/pypi/DEMO.md @@ -6,7 +6,7 @@ The Codespace upgraded it to **2.1.0** and left the source code alone, so `src/auth.py` is now written against an API that no longer exists. That is the situation Drift is built to analyse. -4 breaking changes in this demo: +The 4 breaking changes in this demo: 1. `safe_str_cmp` was removed in Werkzeug 2.1. It was deprecated in 2.0 in favour of `hmac.compare_digest`. This import raises ImportError outright. 2. `pbkdf2_hex` and `pbkdf2_bin` were removed in Werkzeug 2.1; hashlib has `pbkdf2_hmac` built in. diff --git a/demos/rubygems/DEMO.md b/demos/rubygems/DEMO.md index 94cb65b..78cf25e 100644 --- a/demos/rubygems/DEMO.md +++ b/demos/rubygems/DEMO.md @@ -6,7 +6,7 @@ The Codespace upgraded it to **3.1.0** and left the source code alone, so `lib/app.rb` is now written against an API that no longer exists. That is the situation Drift is built to analyse. -3 breaking changes in this demo: +The 3 breaking changes in this demo: 1. Rack::File was removed in Rack 3.1. It had been a deprecated alias of Rack::Files since 2.1. 2. Rack::Chunked was removed in Rack 3.1 — chunked encoding is handled by the server, not by middleware, under the Rack 3 spec. diff --git a/demos/swift/DEMO.md b/demos/swift/DEMO.md index 015e4b9..5754152 100644 --- a/demos/swift/DEMO.md +++ b/demos/swift/DEMO.md @@ -6,7 +6,7 @@ The Codespace upgraded it to **5.9.1** and left the source code alone, so `Sources/DriftDemo/ApiClient.swift` is now written against an API that no longer exists. That is the situation Drift is built to analyse. -4 breaking changes in this demo: +The 4 breaking changes in this demo: 1. SessionManager was removed in Alamofire 5 and replaced by Session, reached through the `AF` global. 2. The top-level Alamofire.request(..) function was removed in Alamofire 5; it is AF.request(..) now. diff --git a/demos/vcpkg/CMakeLists.txt b/demos/vcpkg/CMakeLists.txt index 6d1942d..8bba5f4 100644 --- a/demos/vcpkg/CMakeLists.txt +++ b/demos/vcpkg/CMakeLists.txt @@ -3,7 +3,7 @@ project(drift_demo CXX) set(CMAKE_CXX_STANDARD 17) -find_package(spdlog CONFIG REQUIRED) +find_package(Catch2 CONFIG REQUIRED) -add_executable(drift_demo src/main.cpp) -target_link_libraries(drift_demo PRIVATE spdlog::spdlog) +add_executable(drift_demo_tests src/tests.cpp) +target_link_libraries(drift_demo_tests PRIVATE Catch2::Catch2) diff --git a/demos/vcpkg/DEMO.md b/demos/vcpkg/DEMO.md index 88dc67d..b9b5576 100644 --- a/demos/vcpkg/DEMO.md +++ b/demos/vcpkg/DEMO.md @@ -1,22 +1,21 @@ # Try Drift — C / C++ (vcpkg) -This project depends on `spdlog` **1.11.0**. +This project depends on `catch2` **2.13.9**. -The Codespace upgraded it to **1.14.1** and left the source code alone, so -`src/main.cpp` is now written against an API that no longer exists. That is +The Codespace upgraded it to **3.5.2** and left the source code alone, so +`src/tests.cpp` is now written against an API that no longer exists. That is the situation Drift is built to analyse. -3 breaking changes in this demo: +The 2 breaking changes in this demo: -1. spdlog::set_pattern is fine, but from 1.12 spdlog vendors fmt 10, whose compile-time format checking rejects a runtime std::string as a format string. This call now needs fmt::runtime(..). -2. Same cause: a non-constexpr format string passed to a logging call is a compile error under the bundled fmt 10. -3. spdlog::rotating_logger_mt's max_file_size argument became strongly typed in later 1.x releases; passing a plain signed literal here relies on a conversion that no longer applies cleanly. +1. Catch2 v3 deleted the v2 single header. `catch2/catch.hpp` shipped for the whole 2.x line and does not exist in 3.x at all — the library was split into many headers, and a test file includes `catch2/catch_test_macros.hpp` instead. This include fails outright. +2. CATCH_CONFIG_MAIN is gone in Catch2 v3. Catch2's own migration guide says to "delete TU with CATCH_CONFIG_RUNNER or CATCH_CONFIG_MAIN defined" and link against Catch2::Catch2WithMain instead, so defining it above no longer generates a main(). ## Try it 1. Open the Drift icon in the Activity Bar. -2. Look at what Drift found for `spdlog`. -3. Open `src/main.cpp` and compare against the marked lines. +2. Look at what Drift found for `catch2`. +3. Open `src/tests.cpp` and compare against the marked lines. ```sh git status --short # only the manifest is modified; the source is untouched diff --git a/demos/vcpkg/demo.json b/demos/vcpkg/demo.json index 6ffc9f1..fe64dca 100644 --- a/demos/vcpkg/demo.json +++ b/demos/vcpkg/demo.json @@ -1,9 +1,16 @@ { - "dependency": "spdlog", - "from": "1.11.0", - "to": "1.14.1", + "dependency": "catch2", + "from": "2.13.9", + "to": "3.5.2", "edits": [ - { "file": "vcpkg.json", "find": "\"version\": \"1.11.0\"", "replace": "\"version\": \"1.14.1\"" } + { + "file": "vcpkg.json", + "find": "\"version\": \"2.13.9\"", + "replace": "\"version\": \"3.5.2\"" + } ], - "open": ["src/main.cpp", "vcpkg.json"] + "open": [ + "src/tests.cpp", + "vcpkg.json" + ] } diff --git a/demos/vcpkg/src/main.cpp b/demos/vcpkg/src/main.cpp deleted file mode 100644 index e714eff..0000000 --- a/demos/vcpkg/src/main.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include - -#include - -// This file is written against spdlog 1.11. -// The Codespace upgraded the dependency to spdlog 1.14 without touching this -// code. spdlog 1.12 bundled fmt 10, which turned several previously-accepted -// call shapes into compile errors, so the marked lines below broke. - -void configure() { - // ── BREAKING 1 ──────────────────────────────────────────────────────── - // spdlog::set_pattern is fine, but from 1.12 spdlog vendors fmt 10, whose - // compile-time format checking rejects a runtime std::string as a format - // string. This call now needs fmt::runtime(..). - std::string pattern = "[%Y-%m-%d %H:%M:%S] %v"; - spdlog::set_pattern(pattern); -} - -void log_progress(const std::string& stage, int percent) { - // ── BREAKING 2 ──────────────────────────────────────────────────────── - // Same cause: a non-constexpr format string passed to a logging call is a - // compile error under the bundled fmt 10. - std::string message = "{} is {}% complete"; - spdlog::info(message, stage, percent); -} - -int main() { - configure(); - - // ── BREAKING 3 ──────────────────────────────────────────────────────── - // spdlog::rotating_logger_mt's max_file_size argument became strongly - // typed in later 1.x releases; passing a plain signed literal here relies - // on a conversion that no longer applies cleanly. - auto file_logger = spdlog::rotating_logger_mt("file", "logs/app.log", -1, 3); - - log_progress("indexing", 40); - return 0; -} diff --git a/demos/vcpkg/src/tests.cpp b/demos/vcpkg/src/tests.cpp new file mode 100644 index 0000000..9fc69cb --- /dev/null +++ b/demos/vcpkg/src/tests.cpp @@ -0,0 +1,23 @@ +// ── BREAKING 1 ──────────────────────────────────────────────────────────── +// Catch2 v3 deleted the v2 single header. `catch2/catch.hpp` shipped for the +// whole 2.x line and does not exist in 3.x at all — the library was split into +// many headers, and a test file includes `catch2/catch_test_macros.hpp` +// instead. This include fails outright. +#define CATCH_CONFIG_MAIN +#include + +// ── BREAKING 2 ──────────────────────────────────────────────────────────── +// CATCH_CONFIG_MAIN is gone in Catch2 v3. Catch2's own migration guide says to +// "delete TU with CATCH_CONFIG_RUNNER or CATCH_CONFIG_MAIN defined" and link +// against Catch2::Catch2WithMain instead, so defining it above no longer +// generates a main(). + +// This file is written against Catch2 2.13, installed through vcpkg. +// The Codespace upgraded the dependency to Catch2 3.5 without touching it. + +int add(int a, int b) { return a + b; } + +TEST_CASE("addition works", "[math]") { + REQUIRE(add(2, 2) == 4); + REQUIRE(add(-1, 1) == 0); +} diff --git a/demos/vcpkg/vcpkg.json b/demos/vcpkg/vcpkg.json index 39a1a9d..564b596 100644 --- a/demos/vcpkg/vcpkg.json +++ b/demos/vcpkg/vcpkg.json @@ -2,12 +2,12 @@ "name": "drift-demo", "version": "0.1.0", "dependencies": [ - "spdlog" + "catch2" ], "overrides": [ { - "name": "spdlog", - "version": "1.11.0" + "name": "catch2", + "version": "2.13.9" } ], "builtin-baseline": "3508985146f1b1d248c67ead13f8f54be5b4f5da" diff --git a/docs/browser-demo.md b/docs/browser-demo.md index b3dfb95..f4840e7 100644 --- a/docs/browser-demo.md +++ b/docs/browser-demo.md @@ -5,17 +5,25 @@ How the "Try Drift in your browser" demos are built and launched. ## The model Each demo lives at `demos//` and is committed at the **old** -dependency version, with source code valid against it. A per-ecosystem -devcontainer applies `demos//.drift-demo/upgrade.patch` **once, at -creation time**, which moves only dependency metadata to the **new** version. -The application source is never touched. +dependency version, with source code valid against it. `demos//demo.json` +declares the upgrade as a literal find/replace on the manifest — deliberately not +a patch file, since a demo upgrade is one version string and a plain replacement +can't go stale the way a diff can. A per-ecosystem devcontainer applies that edit +**once, at creation time**, via `node scripts/prepare-demo.mjs `. The +application source is never touched. Drift then analyses an ordinary uncommitted manifest change — the exact situation a developer is in mid-upgrade. Nothing in Drift knows this is a demo. ## Devcontainer lifecycle -`onCreateCommand` runs the prepare step: +`onCreateCommand` runs the prepare step — `node scripts/prepare-demo.mjs +` for most demos, or a longer `setup` command from +`scripts/lib/devcontainer-spec.mjs` for the few that need something installed +first (a package manager, or — for Cargo — the nightly toolchain and +`cargo-public-api` that Drift's Rust surface diff needs, provisioned up front so +the panel isn't blank for minutes on first analysis; see +`.devcontainer/cargo/setup.sh`): ``` node scripts/prepare-demo.mjs @@ -52,20 +60,19 @@ and the manifest. ## Deep links -GitHub's standard Codespaces deep link, one per devcontainer: +Every demo's launch link is GitHub's standard Codespaces deep link for its +devcontainer: -| Ecosystem | Link | -| --- | --- | -| npm | `https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fnpm%2Fdevcontainer.json` | -| pypi | `https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fpypi%2Fdevcontainer.json` | -| go | `https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fgo%2Fdevcontainer.json` | -| cargo | `https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fcargo%2Fdevcontainer.json` | -| maven | `https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2Fmaven%2Fdevcontainer.json` | +``` +https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=.devcontainer%2F%2Fdevcontainer.json +``` -These must be confirmed against the link GitHub generates from its own -Codespaces create flow before they are wired into the website (#7). They have -not been exercised end to end yet — that waits on the extension being published -to the Marketplace. +The README's demo table carries the full set, generated by +`node scripts/make-readme.mjs` so it can't drift from the devcontainers that +actually exist. They have not been exercised end to end yet — that waits on the +extension being published to the Marketplace, at which point a manual smoke +test through the real Codespaces create flow should confirm the link shape +still matches. ## Cost diff --git a/scripts/check-demos.mjs b/scripts/check-demos.mjs index d0bd59a..63bcd76 100644 --- a/scripts/check-demos.mjs +++ b/scripts/check-demos.mjs @@ -5,11 +5,15 @@ // node scripts/check-demos.mjs import { spawnSync } from 'node:child_process'; -import { existsSync } from 'node:fs'; +import { existsSync, readFileSync } from 'node:fs'; import { join } from 'node:path'; import { REPO_ROOT, allDemos, KNOWN_ECOSYSTEMS } from './lib/demo-config.mjs'; +// Same marker `make-demo-docs.mjs` looks for: a ruled comment line reading +// `── BREAKING ──` or `── BREAKING 2 ──`. +const BREAKING_MARKER = /──\s*BREAKING(\s+\d+)?\s*──/; + const demos = allDemos(); let failures = 0; @@ -18,7 +22,14 @@ const check = (ok, label) => { if (!ok) failures += 1; }; -process.stdout.write(`${demos.length} of ${KNOWN_ECOSYSTEMS.length} ecosystems have a demo\n\n`); +process.stdout.write(`${demos.length} of ${KNOWN_ECOSYSTEMS.length} ecosystems have a demo\n`); +check(demos.length === KNOWN_ECOSYSTEMS.length, `exactly ${KNOWN_ECOSYSTEMS.length} known ecosystems have a demo`); + +const devcontainerCount = KNOWN_ECOSYSTEMS.filter((eco) => + existsSync(join(REPO_ROOT, '.devcontainer', eco, 'devcontainer.json')), +).length; +check(devcontainerCount === KNOWN_ECOSYSTEMS.length, `exactly ${KNOWN_ECOSYSTEMS.length} devcontainers exist`); +process.stdout.write('\n'); for (const demo of demos) { process.stdout.write(`${demo.ecosystem}\n`); @@ -30,6 +41,14 @@ for (const demo of demos) { existsSync(join(REPO_ROOT, '.devcontainer', demo.ecosystem, 'devcontainer.json')), 'devcontainer exists', ); + check(demo.edits.length >= 1, 'demo.json declares at least one edit'); + + const sourceFile = demo.open[0]; + const sourcePath = join(REPO_ROOT, demo.dir, sourceFile); + check( + existsSync(sourcePath) && BREAKING_MARKER.test(readFileSync(sourcePath, 'utf8')), + `${sourceFile} has at least one BREAKING marker`, + ); const prepared = spawnSync('node', ['scripts/prepare-demo.mjs', demo.ecosystem], { cwd: REPO_ROOT, @@ -55,7 +74,7 @@ for (const demo of demos) { check(afterReset === '', 'reset restores the baseline'); } -for (const script of ['sync-devcontainers.mjs', 'make-demo-docs.mjs']) { +for (const script of ['sync-devcontainers.mjs', 'make-demo-docs.mjs', 'make-readme.mjs']) { const r = spawnSync('node', [`scripts/${script}`, '--check'], { cwd: REPO_ROOT, encoding: 'utf8' }); process.stdout.write(r.stdout ?? ''); check(r.status === 0, `${script} output is up to date`); diff --git a/scripts/lib/devcontainer-spec.mjs b/scripts/lib/devcontainer-spec.mjs index fdb73d7..1582ecb 100644 --- a/scripts/lib/devcontainer-spec.mjs +++ b/scripts/lib/devcontainer-spec.mjs @@ -28,7 +28,13 @@ export const ECOSYSTEM_CONTAINERS = { // x/exp only ships pseudo-versions, which Drift reads as a patch move. settings: { 'drift.analysis.includePatch': true }, }, - cargo: { image: 'mcr.microsoft.com/devcontainers/rust:1-1-bookworm' }, + cargo: { + image: 'mcr.microsoft.com/devcontainers/rust:1-1-bookworm', + // Drift's Rust surface diff needs `cargo public-api` + nightly, which it + // would otherwise compile from source on first analysis. Provisioned up + // front so the panel is not blank for minutes. See setup.sh. + setup: '.devcontainer/cargo/setup.sh', + }, maven: { image: 'mcr.microsoft.com/devcontainers/java:1-21-bookworm', features: { 'ghcr.io/devcontainers/features/java:1': { version: 'none', installMaven: true } }, diff --git a/scripts/make-demo-docs.mjs b/scripts/make-demo-docs.mjs index 8fef56b..c05ce2f 100644 --- a/scripts/make-demo-docs.mjs +++ b/scripts/make-demo-docs.mjs @@ -20,17 +20,23 @@ for (const demo of allDemos()) { // explaining it. Pull those out so the guide lists the real ones. const breaks = []; const lines = source.split('\n'); + // `#` only counts as a comment marker when it is followed by whitespace or + // nothing — otherwise it matches C/C++ preprocessor directives (`#define`, + // `#include`) immediately following a `//`-comment BREAKING block, and those + // get swallowed into the explanation text instead of ending it. + const COMMENT_LINE = /^\s*(\/\/|#(?=\s|$)|--)/; for (let i = 0; i < lines.length; i += 1) { - if (!/BREAKING\s+\d+/.test(lines[i])) continue; + // The marker is a ruled comment line: `── BREAKING ──` or `── BREAKING 2 ──`. + if (!/──\s*BREAKING(\s+\d+)?\s*──/.test(lines[i])) continue; // Consume the explanation that follows the marker. Line-comment languages // end it at the first non-comment or blank line; OCaml's block comments // have no per-line marker, so there the block ends at `*)`. - const blockComment = !/^\s*(\/\/|#|--)/.test(lines[i + 1] ?? ''); + const blockComment = !COMMENT_LINE.test(lines[i + 1] ?? ''); const text = []; for (let j = i + 1; j < lines.length; j += 1) { const raw = lines[j]; const closes = blockComment && /\*\)/.test(raw); - if (!blockComment && (!/^\s*(\/\/|#|--)/.test(raw) || raw.trim().replace(/^\s*(\/\/|#|--)\s?/, '') === '')) break; + if (!blockComment && (!COMMENT_LINE.test(raw) || raw.trim().replace(/^\s*(\/\/|#|--)\s?/, '') === '')) break; const stripped = raw .replace(/\*\)\s*$/, '') .replace(/^\s*(\/\/|#|--|\(\*)?\s?/, '') @@ -50,7 +56,7 @@ The Codespace upgraded it to **${demo.to}** and left the source code alone, so \`${sourceFile}\` is now written against an API that no longer exists. That is the situation Drift is built to analyse. -${breaks.length} breaking change${breaks.length === 1 ? '' : 's'} in this demo: +${breaks.length === 1 ? 'The breaking change' : `The ${breaks.length} breaking changes`} in this demo: ${breaks.map((b, i) => `${i + 1}. ${b}`).join('\n')} diff --git a/scripts/make-readme.mjs b/scripts/make-readme.mjs new file mode 100644 index 0000000..4a4003e --- /dev/null +++ b/scripts/make-readme.mjs @@ -0,0 +1,50 @@ +#!/usr/bin/env node +// Regenerate the demo table in README.md from the demos themselves, so the +// versions and the launch links cannot drift from what is committed. +// +// node scripts/make-readme.mjs [--check] + +import { readFileSync, writeFileSync } from 'node:fs'; +import { join } from 'node:path'; + +import { REPO_ROOT, allDemos } from './lib/demo-config.mjs'; + +const START = ''; +const END = ''; + +/** Go pseudo-versions are unreadable in a table; show the date they encode. */ +function short(version) { + const pseudo = version.match(/^v0\.0\.0-(\d{4})(\d{2})(\d{2})\d{6}-[0-9a-f]+$/); + return pseudo ? `${pseudo[1]}-${pseudo[2]}-${pseudo[3]}` : version; +} + +const rows = allDemos().map((demo) => { + const path = encodeURIComponent(`.devcontainer/${demo.ecosystem}/devcontainer.json`); + const url = `https://codespaces.new/trydrift/demo?quickstart=1&devcontainer_path=${path}`; + return `| \`${demo.ecosystem}\` | ${demo.label} | \`${demo.dependency}\` | ${short(demo.from)} → ${short(demo.to)} | [Open](${url}) |`; +}); + +const table = [ + START, + '', + '| Ecosystem | Language | Dependency | Upgrade | Try |', + '| --- | --- | --- | --- | --- |', + ...rows, + '', + END, +].join('\n'); + +const path = join(REPO_ROOT, 'README.md'); +const current = readFileSync(path, 'utf8'); +const updated = current.replace(new RegExp(`${START}[\\s\\S]*?${END}`), table); + +if (updated === current) { + process.stdout.write('README table is up to date.\n'); + process.exit(0); +} +if (process.argv.includes('--check')) { + process.stderr.write('README demo table is out of date — run: node scripts/make-readme.mjs\n'); + process.exit(1); +} +writeFileSync(path, updated); +process.stdout.write(`✓ README demo table (${rows.length} demos)\n`);