@adobe/spectrum-tokens 14.1.0 → 14.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # [**@adobe/spectrum-tokens**](https://github.com/adobe/spectrum-design-data)
2
2
 
3
+ ## 14.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#709](https://github.com/adobe/spectrum-design-data/pull/709) [`49ad47b`](https://github.com/adobe/spectrum-design-data/commit/49ad47bea61952f84eb86b214954136049aca376) Thanks [@GarthDB](https://github.com/GarthDB)! - Use dynamic import for prettier in writeJson so the package loads without prettier
8
+ when used outside the monorepo (e.g. spectrum-design-data-mcp via npx).
9
+
10
+ ## 14.2.0
11
+
12
+ ### Minor Changes
13
+
14
+ - [#706](https://github.com/adobe/spectrum-design-data/pull/706) [`c051815`](https://github.com/adobe/spectrum-design-data/commit/c05181505730ec911196c4b6d37d106bccd742e5) Thanks [@GarthDB](https://github.com/GarthDB)! - Add `getTokensByFile()` export (tokens grouped by filename; complement to `getAllTokens()`).
15
+
3
16
  ## 14.1.0
4
17
 
5
18
  ### Minor Changes
@@ -22,7 +35,6 @@
22
35
  <details><summary><strong>Updated Properties (67)</strong></summary>
23
36
 
24
37
  All tokens below had the `renamed` property added to indicate their replacement token name:
25
-
26
38
  - `drop-shadow-color` → `drop-shadow-color-100`
27
39
  - `color-loupe-drop-shadow-color` → `drop-shadow-elevated-color`
28
40
  - `color-handle-drop-shadow-color` → `drop-shadow-color`
package/index.js CHANGED
@@ -12,11 +12,10 @@ governing permissions and limitations under the License.
12
12
 
13
13
  import { glob } from "glob";
14
14
 
15
- import { resolve } from "path";
15
+ import { basename, resolve } from "path";
16
16
  import { readFile } from "fs/promises";
17
17
  import * as url from "url";
18
18
  import { writeFile } from "fs/promises";
19
- import { format } from "prettier";
20
19
 
21
20
  export const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
22
21
 
@@ -28,6 +27,7 @@ export const readJson = async (fileName) =>
28
27
  JSON.parse(await readFile(fileName, "utf8"));
29
28
 
30
29
  export const writeJson = async (fileName, jsonData) => {
30
+ const { format } = await import("prettier");
31
31
  await writeFile(
32
32
  fileName,
33
33
  await format(JSON.stringify(jsonData), { parser: "json-stringify" }),
@@ -45,6 +45,17 @@ export const isDeprecated = (token) =>
45
45
  export const getFileTokens = async (tokenFileName) =>
46
46
  await readJson(resolve(__dirname, "src", tokenFileName));
47
47
 
48
+ export const getTokensByFile = async () => {
49
+ const result = {};
50
+ await Promise.all(
51
+ tokenFileNames.map(async (filePath) => {
52
+ const fileName = basename(filePath);
53
+ result[fileName] = await readJson(filePath);
54
+ }),
55
+ );
56
+ return result;
57
+ };
58
+
48
59
  export const getAllTokens = async () => {
49
60
  return await Promise.all(tokenFileNames.map(getFileTokens)).then(
50
61
  (tokenFileDataAr) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spectrum-tokens",
3
- "version": "14.1.0",
3
+ "version": "14.2.1",
4
4
  "description": "Design tokens for Spectrum, Adobe's design system",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -0,0 +1,53 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import test from "ava";
14
+ import { getAllTokens } from "../index.js";
15
+
16
+ const ALIAS_PATTERN = /^\{([^}]+)\}$/;
17
+
18
+ function collectAliasRefs(obj, path = "") {
19
+ const refs = [];
20
+ if (typeof obj.value === "string") {
21
+ const match = obj.value.match(ALIAS_PATTERN);
22
+ if (match) {
23
+ refs.push({ ref: match[1], path: path || "value" });
24
+ }
25
+ }
26
+ if (obj.sets) {
27
+ for (const [setName, setValue] of Object.entries(obj.sets)) {
28
+ refs.push(...collectAliasRefs(setValue, `${path}sets.${setName}.`));
29
+ }
30
+ }
31
+ return refs;
32
+ }
33
+
34
+ test("every alias reference should resolve to an existing token", async (t) => {
35
+ const tokens = await getAllTokens();
36
+ const allTokenNames = new Set(Object.keys(tokens));
37
+ const invalid = [];
38
+
39
+ for (const [tokenName, token] of Object.entries(tokens)) {
40
+ const refs = collectAliasRefs(token);
41
+ for (const { ref, path } of refs) {
42
+ if (!allTokenNames.has(ref)) {
43
+ invalid.push({ token: tokenName, ref, path });
44
+ }
45
+ }
46
+ }
47
+
48
+ t.deepEqual(
49
+ invalid,
50
+ [],
51
+ `${invalid.length} alias references point to non-existent tokens`,
52
+ );
53
+ });
@@ -0,0 +1,34 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import test from "ava";
14
+ import { getAllTokens } from "../index.js";
15
+
16
+ test("every renamed property should reference an existing token", async (t) => {
17
+ const tokens = await getAllTokens();
18
+ const allTokenNames = new Set(Object.keys(tokens));
19
+ const invalid = [];
20
+
21
+ for (const [tokenName, token] of Object.entries(tokens)) {
22
+ if (Object.hasOwn(token, "renamed")) {
23
+ if (!allTokenNames.has(token.renamed)) {
24
+ invalid.push({ token: tokenName, renamed: token.renamed });
25
+ }
26
+ }
27
+ }
28
+
29
+ t.deepEqual(
30
+ invalid,
31
+ [],
32
+ `${invalid.length} renamed values reference non-existent tokens`,
33
+ );
34
+ });