@adobe/spectrum-tokens 14.2.1 → 14.2.3
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 +19 -0
- package/README.md +10 -0
- package/moon.yml +39 -1
- package/naming-exceptions.json +1170 -0
- package/package.json +6 -1
- package/schemas/token-file.json +33 -0
- package/schemas/token-types/multiplier.json +1 -2
- package/snapshots/validation-snapshot.json +1363 -0
- package/test/packageExports.test.js +72 -0
- package/test/tokenSchemaValidator.test.js +22 -16
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2026 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 { access, readFile } from "fs/promises";
|
|
15
|
+
import { fileURLToPath } from "url";
|
|
16
|
+
import path from "path";
|
|
17
|
+
|
|
18
|
+
const packageJsonPath = fileURLToPath(
|
|
19
|
+
new URL("../package.json", import.meta.url),
|
|
20
|
+
);
|
|
21
|
+
const pkgDir = path.dirname(packageJsonPath);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Resolve a subpath like ./dist/json/variables.json against the
|
|
25
|
+
* "./dist/*" -> "./dist/*" export pattern (Node replaces * with the suffix).
|
|
26
|
+
*/
|
|
27
|
+
function resolveDistStarSubpath(request) {
|
|
28
|
+
if (!request.startsWith("./dist/")) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const suffix = request.slice("./dist/".length);
|
|
32
|
+
return `./dist/${suffix}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
test("package.json exports preserve backward-compatible entry points", async (t) => {
|
|
36
|
+
const pkg = JSON.parse(await readFile(packageJsonPath, { encoding: "utf8" }));
|
|
37
|
+
const { exports } = pkg;
|
|
38
|
+
|
|
39
|
+
t.truthy(exports, "exports field must be defined");
|
|
40
|
+
t.is(exports["."], "./index.js", "main entry export");
|
|
41
|
+
t.is(
|
|
42
|
+
exports["./schemas/token-file.json"],
|
|
43
|
+
"./schemas/token-file.json",
|
|
44
|
+
"token-file schema export",
|
|
45
|
+
);
|
|
46
|
+
t.is(
|
|
47
|
+
exports["./dist/*"],
|
|
48
|
+
"./dist/*",
|
|
49
|
+
"dist wildcard export required for @adobe/spectrum-tokens/dist/json/variables.json",
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("dist/json/variables.json maps through ./dist/* export and exists after build", async (t) => {
|
|
54
|
+
const pkg = JSON.parse(await readFile(packageJsonPath, { encoding: "utf8" }));
|
|
55
|
+
const { exports } = pkg;
|
|
56
|
+
|
|
57
|
+
t.is(exports["./dist/*"], "./dist/*");
|
|
58
|
+
|
|
59
|
+
const consumerSubpath = "./dist/json/variables.json";
|
|
60
|
+
const resolvedTarget = resolveDistStarSubpath(consumerSubpath);
|
|
61
|
+
t.is(
|
|
62
|
+
resolvedTarget,
|
|
63
|
+
"./dist/json/variables.json",
|
|
64
|
+
"subpath should map to dist/json/variables.json under ./dist/* pattern",
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const absolutePath = path.join(pkgDir, "dist/json/variables.json");
|
|
68
|
+
await t.notThrowsAsync(
|
|
69
|
+
async () => access(absolutePath),
|
|
70
|
+
"dist/json/variables.json must exist (buildTokens runs before test)",
|
|
71
|
+
);
|
|
72
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright
|
|
2
|
+
Copyright 2026 Adobe. All rights reserved.
|
|
3
3
|
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
5
|
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
@@ -38,6 +38,10 @@ test.before(async (t) => {
|
|
|
38
38
|
);
|
|
39
39
|
t.context.schemaIds = schemaIds;
|
|
40
40
|
|
|
41
|
+
const tokenFileSchema = await readJSON("schemas/token-file.json");
|
|
42
|
+
ajv.addSchema(tokenFileSchema, tokenFileSchema["$id"]);
|
|
43
|
+
t.context.tokenFileSchemaId = tokenFileSchema["$id"];
|
|
44
|
+
|
|
41
45
|
const tokenFilesNames = await glob("src/*.json");
|
|
42
46
|
t.context.tokenFiles = await Promise.all(
|
|
43
47
|
tokenFilesNames.map(async (tokenFile) => {
|
|
@@ -46,21 +50,9 @@ test.before(async (t) => {
|
|
|
46
50
|
);
|
|
47
51
|
});
|
|
48
52
|
|
|
49
|
-
test("
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
53
|
-
type: "object",
|
|
54
|
-
patternProperties: {
|
|
55
|
-
"^(?:(?:[a-z]|\\d)+-?)*(?:[a-z]|\\d)+$": {
|
|
56
|
-
anyOf: t.context.schemaIds.map((schemaId) => ({ $ref: schemaId })),
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
} catch (error) {
|
|
61
|
-
console.log(error);
|
|
62
|
-
}
|
|
63
|
-
t.pass();
|
|
53
|
+
test("token-file schema compiles", (t) => {
|
|
54
|
+
const validate = ajv.getSchema(t.context.tokenFileSchemaId);
|
|
55
|
+
t.truthy(validate, "token-file schema should be registered");
|
|
64
56
|
});
|
|
65
57
|
|
|
66
58
|
test("Every token should have a $schema property", (t) => {
|
|
@@ -95,3 +87,17 @@ test("Every token schema should validate against the definition", (t) => {
|
|
|
95
87
|
});
|
|
96
88
|
t.deepEqual(errors, []);
|
|
97
89
|
});
|
|
90
|
+
|
|
91
|
+
test("Every token file validates against token-file.json", (t) => {
|
|
92
|
+
const errors = [];
|
|
93
|
+
t.context.tokenFiles.forEach((tokenFileObj) => {
|
|
94
|
+
if (!ajv.validate(t.context.tokenFileSchemaId, tokenFileObj.data)) {
|
|
95
|
+
t.log(`${tokenFileObj.fileName} failed token-file validation.`);
|
|
96
|
+
errors.push({
|
|
97
|
+
fileName: tokenFileObj.fileName,
|
|
98
|
+
errors: ajv.errors,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
t.deepEqual(errors, []);
|
|
103
|
+
});
|