@cagov/ca-ds 1.0.0 → 1.1.0

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.
Files changed (101) hide show
  1. package/README.md +4 -2
  2. package/THIRD-PARTY-LICENSES.txt +690 -0
  3. package/ca-ds.js +48337 -0
  4. package/package.json +5 -31
  5. package/bin/ca-ds.js +0 -5
  6. package/src/cli/add.js +0 -134
  7. package/src/cli/build.js +0 -15
  8. package/src/cli/diff.js +0 -39
  9. package/src/cli/eject.js +0 -112
  10. package/src/cli/exit.js +0 -22
  11. package/src/cli/format.js +0 -52
  12. package/src/cli/init.js +0 -148
  13. package/src/cli/install.js +0 -178
  14. package/src/cli/items.js +0 -10
  15. package/src/cli/login.js +0 -331
  16. package/src/cli/main.js +0 -108
  17. package/src/cli/new.js +0 -230
  18. package/src/cli/outdated.js +0 -74
  19. package/src/cli/pack.js +0 -75
  20. package/src/cli/preview.js +0 -31
  21. package/src/cli/publish.js +0 -295
  22. package/src/cli/pull.js +0 -208
  23. package/src/cli/remote.js +0 -52
  24. package/src/cli/remove.js +0 -69
  25. package/src/cli/update.js +0 -223
  26. package/src/cli/validate.js +0 -131
  27. package/src/lib/browser.js +0 -12
  28. package/src/lib/build.js +0 -249
  29. package/src/lib/bundle.js +0 -148
  30. package/src/lib/catalog.js +0 -44
  31. package/src/lib/checks.js +0 -31
  32. package/src/lib/collection.js +0 -65
  33. package/src/lib/emblem.js +0 -29
  34. package/src/lib/fixtures.js +0 -59
  35. package/src/lib/floor.js +0 -79
  36. package/src/lib/glyph.js +0 -148
  37. package/src/lib/image.js +0 -138
  38. package/src/lib/json-text.js +0 -213
  39. package/src/lib/keys.js +0 -322
  40. package/src/lib/links.js +0 -321
  41. package/src/lib/markdown.js +0 -408
  42. package/src/lib/merge.js +0 -93
  43. package/src/lib/pack.js +0 -30
  44. package/src/lib/page-schema.js +0 -368
  45. package/src/lib/page.js +0 -372
  46. package/src/lib/patch.js +0 -9
  47. package/src/lib/regions.js +0 -173
  48. package/src/lib/registry.js +0 -371
  49. package/src/lib/release.js +0 -119
  50. package/src/lib/repoints.js +0 -120
  51. package/src/lib/resolve.js +0 -32
  52. package/src/lib/schema.js +0 -28
  53. package/src/lib/serial.js +0 -4
  54. package/src/lib/serialize.js +0 -444
  55. package/src/lib/structured.js +0 -72
  56. package/src/lib/system.js +0 -13
  57. package/src/lib/targets.js +0 -85
  58. package/src/lib/terms.js +0 -11
  59. package/src/lib/token-view.js +0 -289
  60. package/src/lib/tokens.js +0 -247
  61. package/src/lib/version.js +0 -34
  62. package/src/preview/frame.js +0 -75
  63. package/src/preview/pages.js +0 -128
  64. package/src/preview/screenshots.js +0 -72
  65. package/src/preview/server.js +0 -378
  66. package/src/preview/shell.js +0 -153
  67. package/src/schema/a11y.schema.json +0 -56
  68. package/src/schema/collection.lock.schema.json +0 -58
  69. package/src/schema/collection.schema.json +0 -65
  70. package/src/schema/composition.schema.json +0 -98
  71. package/src/schema/contract.schema.json +0 -116
  72. package/src/schema/interface.schema.json +0 -257
  73. package/src/schema/item.schema.json +0 -362
  74. package/src/schema/release.schema.json +0 -39
  75. package/src/schema/system.schema.json +0 -75
  76. package/src/schema/variants.schema.json +0 -60
  77. package/src/validate/collection.js +0 -19
  78. package/src/validate/collisions.js +0 -124
  79. package/src/validate/context.js +0 -357
  80. package/src/validate/facts.js +0 -253
  81. package/src/validate/files.js +0 -103
  82. package/src/validate/findings.js +0 -19
  83. package/src/validate/glyphs.js +0 -126
  84. package/src/validate/html.js +0 -215
  85. package/src/validate/imports.js +0 -29
  86. package/src/validate/index.js +0 -75
  87. package/src/validate/item.js +0 -47
  88. package/src/validate/links.js +0 -113
  89. package/src/validate/manifest.js +0 -147
  90. package/src/validate/media.js +0 -65
  91. package/src/validate/page.js +0 -74
  92. package/src/validate/prefixes.js +0 -58
  93. package/src/validate/relations.js +0 -310
  94. package/src/validate/release.js +0 -109
  95. package/src/validate/skill.js +0 -122
  96. package/src/validate/structured.js +0 -335
  97. package/src/validate/tasc.js +0 -80
  98. package/src/validate/template.js +0 -129
  99. package/src/validate/tokens.js +0 -154
  100. package/src/validate/zip.js +0 -40
  101. /package/{src/preview/preview.css → preview.css} +0 -0
@@ -1,154 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { relatedNames, definitions, literalKey, pendingParent, readerScope, tokenNames } from './context.js';
4
- import { lineAt } from './findings.js';
5
- import { declaredFiles, CHECKS } from './item.js';
6
- import { systemProperty } from './prefixes.js';
7
-
8
- export const check = 'tokens';
9
-
10
- const NAME = /--_?ca-[A-Za-z0-9_-]+/g;
11
-
12
- // Ending at ; or }, so neither a selector's pseudo-class nor a media condition matches.
13
- const DECLARATION = /([-\w]+)\s*:\s*([^;{}]+)(?=[;}])/g;
14
- const LITERAL = /#[0-9a-fA-F]{3,8}\b|-?\d*\.?\d+(?:px|rem|em)\b/g;
15
-
16
- // A family's properties match only its tokens, so a margin never flags as a font size.
17
- const FAMILIES = [
18
- [/^(margin|padding|gap|row-gap|column-gap|inset|top|right|bottom|left|(min-|max-)?(width|height|inline-size|block-size))(-|$)/, '--ca-spacing-'],
19
- [/radius/, '--ca-radius-'],
20
- [/^(font-size|line-height|letter-spacing)$/, '--ca-font-'],
21
- ];
22
-
23
- function* literals(css, { byKey, component }, own) {
24
- const code = css.code.replace(/url\([^)]*\)/g, (u) => u.replace(/[^\n]/g, ' '));
25
- for (const d of code.matchAll(DECLARATION)) {
26
- const family = FAMILIES.find(([pattern]) => pattern.test(d[1]))?.[1];
27
- const start = d.index + d[0].indexOf(d[2], d[1].length);
28
- for (const m of d[2].matchAll(LITERAL)) {
29
- const names = (byKey.get(literalKey(m[0])) ?? []).filter((n) => (!component.has(n) || own.has(n)) && (!family || n.startsWith(family)));
30
- if (names.length) yield { literal: m[0], names, line: lineAt(code, start + m.index) + css.offsetLine };
31
- }
32
- }
33
- }
34
-
35
- function literalMessage(literal, names) {
36
- const more = names.length > 1 ? `, and ${names.length - 1} more` : '';
37
- return `\`${literal}\` is a token's value, the one \`${names[0]}\` emits${more}. Reference a \`--ca-*\` custom property instead of the literal.`;
38
- }
39
-
40
- export async function run(item, ctx, { reject, warn }) {
41
- if (!item.manifest) return;
42
- const { properties } = await definitions(item, ctx);
43
- // HTML may set knobs of related items, which may publish after this one. CSS and JS reach only what loads first.
44
- const composed = (await definitions(item, ctx, { related: true })).properties;
45
- const pending = relatedNames(item).filter((n) => n !== item.manifest.name && !ctx.catalog.has(n));
46
- const facts = await ctx.facts(item);
47
- const seen = new Set();
48
- const parent = item.authored == null ? pendingParent(item, ctx) : null;
49
- const undefinedRef = (name, file, line) => {
50
- if (properties.has(name) || seen.has(`${file}\0${name}`)) return;
51
- seen.add(`${file}\0${name}`);
52
- if (parent) warn('undefined', `\`${name}\` is defined by no token and by no item this one is validated with. It may be a knob of \`${parent}\`, up the part's \`partOf\` chain, which isn't published yet.`, { file, line });
53
- else reject('undefined', `\`${name}\` is defined by no token and by no item this one is validated with.`, { file, line });
54
- };
55
-
56
- for (const [path, css] of facts.css) {
57
- for (const r of css.varRefs) if (systemProperty(r.name)) undefinedRef(r.name, path, r.line);
58
- }
59
-
60
- for (const [path, html] of facts.html) {
61
- // A style attribute's --ca-* declaration sets a knob, which must exist.
62
- const local = new Set(html.styles.filter((s) => !s.attribute).flatMap((s) => s.customDecls.map((d) => d.name)));
63
- const checkPage = path.startsWith(`${CHECKS}/`);
64
- const knownTo = (name) => composed.has(name) || local.has(name) || (checkPage && ctx.everyToken.has(name));
65
- for (const s of html.styles) {
66
- const refs = [...s.varRefs, ...(s.attribute ? s.customDecls : [])];
67
- for (const r of refs) {
68
- if (!systemProperty(r.name) || knownTo(r.name)) continue;
69
- if (pending.length === 0) undefinedRef(r.name, path, r.line);
70
- else if (!seen.has(`${path}\0${r.name}`)) {
71
- seen.add(`${path}\0${r.name}`);
72
- const items = `${pending.length > 1 ? 'one of ' : ''}${pending.map((n) => `\`${n}\``).join(', ')}`;
73
- warn('undefined', `\`${r.name}\` is defined by no token and by no item this one is validated with. It may belong to ${items}, which this item's related escalations load and which isn't published yet.`, { file: path, line: r.line });
74
- }
75
- }
76
- }
77
- }
78
-
79
- if (ctx.literals) {
80
- const own = new Set();
81
- for (const f of declaredFiles(item.manifest)) {
82
- if (f.role !== 'tokens' || !item.present.has(f.path)) continue;
83
- try {
84
- for (const n of tokenNames(JSON.parse(readFileSync(join(item.dir, f.path), 'utf8')))) own.add(n);
85
- } catch {
86
- // The files check reports it.
87
- }
88
- }
89
- for (const [path, css] of facts.css) {
90
- for (const f of literals(css, ctx.literals, own)) warn('literal', literalMessage(f.literal, f.names), { file: path, line: f.line });
91
- }
92
- for (const [path, html] of facts.html) {
93
- for (const s of html.styles) {
94
- const css = s.attribute ? { ...s, code: `${s.code};` } : s;
95
- for (const f of literals(css, ctx.literals, own)) warn('literal', literalMessage(f.literal, f.names), { file: path, line: f.line });
96
- }
97
- }
98
- }
99
-
100
- for (const [path, js] of facts.js) {
101
- for (const m of js.code.matchAll(NAME)) undefinedRef(m[0], path, null);
102
- }
103
-
104
- // A declaration defines its name, so a write to a removed knob passes the undefined check and lands here.
105
- const read = new Set();
106
- for (const member of readerScope(item, ctx)) for (const name of await readsOf(member, ctx)) read.add(name);
107
- const unread = new Set();
108
- const declared = [...facts.css].flatMap(([path, css]) => css.customDecls.map((d) => ({ ...d, path })));
109
- for (const [path, html] of facts.html) for (const s of html.styles) declared.push(...s.customDecls.map((d) => ({ ...d, path })));
110
- for (const d of declared) {
111
- if (!systemProperty(d.name) || read.has(d.name) || unread.has(`${d.path}\0${d.name}`)) continue;
112
- unread.add(`${d.path}\0${d.name}`);
113
- warn('unread', `\`${d.name}\` is declared here, and no \`var()\` reads it in the item, the items it's validated with, or the items that depend on it.`, { file: d.path, line: d.line });
114
- }
115
-
116
- if (item.manifest.kind === 'tokens') return;
117
- for (const f of declaredFiles(item.manifest)) {
118
- if (f.role !== 'tokens' || !item.present.has(f.path)) continue;
119
- let json;
120
- try {
121
- json = JSON.parse(readFileSync(join(item.dir, f.path), 'utf8'));
122
- } catch {
123
- continue;
124
- }
125
- const records = tokensOf(json);
126
- const bare = records.filter((r) => typeof r.node.$description !== 'string').map((r) => r.path);
127
- if (bare.length === 0) continue;
128
- const shown = bare.slice(0, SHOWN).map((p) => `\`${p}\``).join(', ');
129
- const more = bare.length > SHOWN ? `, and ${bare.length - SHOWN} more` : '';
130
- warn('description', `${bare.length} of the file's ${records.length} tokens carry no \`$description\`: ${shown}${more}.`, { file: f.path });
131
- }
132
- }
133
-
134
- const SHOWN = 3;
135
-
136
- function tokensOf(json, path = []) {
137
- if (!json || typeof json !== 'object') return [];
138
- if ('$value' in json) return [{ path: path.join('.'), node: json }];
139
- return Object.entries(json).flatMap(([key, value]) => (key.startsWith('$') ? [] : tokensOf(value, [...path, key])));
140
- }
141
-
142
- // A script reads a name anywhere it spells it, through getPropertyValue or a style write.
143
- const reads = new WeakMap();
144
- async function readsOf(member, ctx) {
145
- const facts = await ctx.facts(member);
146
- if (!reads.has(facts)) {
147
- const names = new Set();
148
- for (const css of facts.css.values()) for (const r of css.varRefs) names.add(r.name);
149
- for (const html of facts.html.values()) for (const s of html.styles) for (const r of s.varRefs) names.add(r.name);
150
- for (const js of facts.js.values()) for (const m of js.code.matchAll(NAME)) names.add(m[0]);
151
- reads.set(facts, names);
152
- }
153
- return reads.get(facts);
154
- }
@@ -1,40 +0,0 @@
1
- import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync, existsSync, readdirSync } from 'node:fs';
2
- import { tmpdir } from 'node:os';
3
- import { dirname, join, posix } from 'node:path';
4
- import { unzipSync } from 'fflate';
5
-
6
- export function unpack(zipPath) {
7
- return unpackBytes(readFileSync(zipPath));
8
- }
9
-
10
- // maxBytes caps the entries' declared uncompressed total, so an upload can't expand past it.
11
- export function unpackBytes(bytes, { maxBytes = Infinity } = {}) {
12
- let total = 0;
13
- const entries = unzipSync(bytes, {
14
- filter: (file) => {
15
- total += file.originalSize;
16
- if (total > maxBytes) throw new Error(`The archive expands past ${maxBytes} bytes.`);
17
- return true;
18
- },
19
- });
20
- const base = mkdtempSync(join(tmpdir(), 'ca-validate-'));
21
- const cleanup = () => rmSync(base, { recursive: true, force: true });
22
- try {
23
- for (const [name, bytes] of Object.entries(entries)) {
24
- const path = posix.normalize(name);
25
- if (path.startsWith('../') || posix.isAbsolute(path)) throw new Error(`The archive entry ${name} escapes the archive.`);
26
- if (name.endsWith('/')) continue;
27
- mkdirSync(dirname(join(base, path)), { recursive: true });
28
- writeFileSync(join(base, path), bytes);
29
- }
30
- if (existsSync(join(base, 'item.json'))) return { dir: base, cleanup };
31
- const top = readdirSync(base, { withFileTypes: true }).filter((e) => !e.name.startsWith('.'));
32
- if (top.length === 1 && top[0].isDirectory() && existsSync(join(base, top[0].name, 'item.json'))) {
33
- return { dir: join(base, top[0].name), cleanup };
34
- }
35
- throw new Error('The archive holds no item.json at its root or in its one top-level folder.');
36
- } catch (err) {
37
- cleanup();
38
- throw err;
39
- }
40
- }
File without changes