From 7b36a85dbae70b8b83a69f08c4983f95e16730e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Thu, 7 May 2026 12:49:48 +0200 Subject: [PATCH] :wrench: Convert tokens lib migration into file migration --- common/src/app/common/files/migrations.cljc | 14 +++++++-- common/src/app/common/types/tokens_lib.cljc | 32 +++------------------ 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index eeb11e9067..9ca673ce72 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -34,7 +34,7 @@ [app.common.types.shape.shadow :as ctss] [app.common.types.shape.text :as ctst] [app.common.types.text :as types.text] - [app.common.types.tokens-lib :as types.tokens-lib] + [app.common.types.tokens-lib :as ctob] [app.common.uuid :as uuid] [clojure.set :as set] [cuerdas.core :as str])) @@ -1599,7 +1599,7 @@ (defmethod migrate-data "0014-fix-tokens-lib-duplicate-ids" [data _] - (d/update-when data :tokens-lib types.tokens-lib/fix-duplicate-token-set-ids)) + (d/update-when data :tokens-lib ctob/fix-duplicate-token-set-ids)) (defmethod migrate-data "0014-clear-components-nil-objects" [data _] @@ -1805,6 +1805,13 @@ {})] (cfcp/sync-component-id-with-ref-shape data libraries))) +(defmethod migrate-data "0021-repair-bad-tokens" + [data _] + (d/update-when data :tokens-lib + #(-> % + (ctob/fix-conflicting-token-names) + (ctob/fix-missing-sets-in-themes)))) + (def available-migrations (into (d/ordered-set) ["legacy-2" @@ -1882,4 +1889,5 @@ "0017-fix-layout-flex-dir" "0018-remove-unneeded-objects-from-components" "0019-fix-missing-swap-slots" - "0020-sync-component-id-with-near-main"])) + "0020-sync-component-id-with-near-main" + "0021-repair-bad-tokens"])) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 177e12ff54..699d1d7d9a 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -2375,9 +2375,7 @@ Will return a value that matches this schema: (migrate-to-v1-2) (migrate-to-v1-3) (migrate-to-v1-4) - (map->tokens-lib) - (fix-conflicting-token-names) - (fix-missing-sets-in-themes))))) + (map->tokens-lib))))) #?(:clj (defn- read-tokens-lib-v1-2 @@ -2392,9 +2390,7 @@ Will return a value that matches this schema: :active-themes active-themes} (migrate-to-v1-3) (migrate-to-v1-4) - (map->tokens-lib) - (fix-conflicting-token-names) - (fix-missing-sets-in-themes))))) + (map->tokens-lib))))) #?(:clj (defn- read-tokens-lib-v1-3 @@ -2409,24 +2405,7 @@ Will return a value that matches this schema: :themes themes :active-themes active-themes} (migrate-to-v1-4) - (map->tokens-lib) - (fix-conflicting-token-names) - (fix-missing-sets-in-themes))))) - -#?(:clj - (defn- read-tokens-lib-v1-4 - "Reads the tokens lib data structure and fix conflicting token names." - [r] - (let [sets (fres/read-object! r) - themes (fres/read-object! r) - active-themes (fres/read-object! r)] - - (-> {:sets sets - :themes themes - :active-themes active-themes} - (map->tokens-lib) - (fix-conflicting-token-names) - (fix-missing-sets-in-themes))))) + (map->tokens-lib))))) #?(:clj (defn- write-tokens-lib @@ -2487,11 +2466,8 @@ Will return a value that matches this schema: {:name "penpot/tokens-lib/v1.3" :rfn read-tokens-lib-v1-3} - {:name "penpot/tokens-lib/v1.4" - :rfn read-tokens-lib-v1-4} - ;; CURRENT TOKENS LIB READER & WRITTER - {:name "penpot/tokens-lib/v1.5" + {:name "penpot/tokens-lib/v1.4" :class TokensLib :wfn write-tokens-lib :rfn read-tokens-lib}))