@ucm-kit/adapter-typescript 0.1.33 → 0.1.34

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 (2) hide show
  1. package/README.md +39 -42
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,16 +1,21 @@
1
1
  # @ucm-kit/adapter-typescript
2
2
 
3
3
  Optional adapter for TypeScript repositories that consume UCM contracts. It adds
4
- two capabilities without making
5
- [`@ucm-kit/core`](https://www.npmjs.com/package/@ucm-kit/core) depend on the
6
- TypeScript compiler, a 23 MB dependency no other consumer should pay for.
4
+ static parity between contracts and code, and types generated from the
5
+ contracts. It lives outside
6
+ [`@ucm-kit/core`](https://www.npmjs.com/package/@ucm-kit/core) because it
7
+ depends on the TypeScript compiler, a 23 MB dependency.
7
8
 
8
9
  ```sh
9
- npm install --save-dev @ucm-kit/adapter-typescript@0.1.33 @ucm-kit/cli@0.1.40
10
- npx ucm-typescript
11
- npx --no-install ucm check
10
+ npm install --save-dev @ucm-kit/adapter-typescript@0.1.34 @ucm-kit/cli@0.1.41
11
+ npx ucm-typescript # generates the types from the contracts
12
+ npx --no-install ucm check # checks the contracts, parity included
12
13
  ```
13
14
 
15
+ Requires Node 20 or later, a `tsconfig.json` at the repository root, and a
16
+ `ucm.config.json` or the default paths. If `ucm init` already ran, run it again
17
+ after installing the adapter to receive its templates in `.ucm/gabarits/`.
18
+
14
19
  ## Static parity
15
20
 
16
21
  `ucm check` discovers this package when it is installed in the repository, and
@@ -26,63 +31,55 @@ reported:
26
31
  | Unused enum | An enum prop is declared but never read by the component |
27
32
  | Wrong composition cardinality | A declared dependency is rendered a different number of times than the contract says |
28
33
 
29
- Parity requires a `tsconfig.json` at the root. Props are read with the
30
- TypeScript type checker; compositions are counted by their occurrences in JSX.
31
- The props of `Button.tsx` come from an interface or a type alias named
32
- `ButtonProps`. The component is the function named `Button`, or the file's
33
- default export. A prop counts as read whether it is destructured in the
34
- signature or from `props` in the body.
34
+ Props are read with the TypeScript type checker; compositions are counted by
35
+ their occurrences in JSX. The props of `Button.tsx` come from an interface or a
36
+ type alias named `ButtonProps`. The component is the function named `Button`,
37
+ or the file's default export. A prop counts as read whether it is destructured
38
+ in the signature or from `props` in the body.
35
39
 
36
- Every one of these **warns without blocking**. The gap is in the code, so a
37
- developer closes it. No re-export helps.
40
+ Every gap **warns without blocking**. The gap is in the code, so a developer
41
+ closes it.
38
42
 
39
43
  ## The convention composition counting assumes
40
44
 
41
45
  **Counting is static: a dependency rendered by a loop is not counted.** Keep
42
46
  every occurrence explicit in the source, and neutralise in place the one a given
43
- view does not show, rather than removing it. Without that, a list built with
44
- `.map()` reports a cardinality gap the contract did not intend.
45
-
46
- Nothing enforces the convention. No opt-out exists for a single component. A
47
- warning names what the count did not see, without blocking anything.
47
+ view does not show, rather than removing it. Otherwise a list built with
48
+ `.map()` reports a cardinality gap the contract did not intend. No opt-out
49
+ exists for a single component.
48
50
 
49
51
  ## What it does not measure
50
52
 
51
- Type comparison covers `boolean` props only. An enum is judged on its declared
52
- union, below; `string`, `icon`, `instance-swap` and `slot` props are checked for
53
- presence and never for type.
53
+ Type comparison covers `boolean` props only. `string`, `icon`, `instance-swap`
54
+ and `slot` props are checked for presence and never for type.
54
55
 
55
- Enum values are compared by the **declared union only**. A union smaller than
56
- the contract is reported; a union that accepts more is not, because accepting
57
- more contradicts nothing. On a widened type such as `string`, no value is
58
- resolved and nothing is reported.
56
+ Enum values are compared with the **declared union only**. A union smaller than
57
+ the contract is reported; a union that accepts more is not. On a widened type
58
+ such as `string`, nothing is reported.
59
59
 
60
- What the component does with a value stays outside the static guarantee. A
61
- `switch` with a `default`, a partial mapping table, a value forwarded to a
62
- child, a table held in another file and a business rule that substitutes one
63
- value for another are all legitimate; telling them apart from an oversight would
64
- require the contract to describe behaviour. A contract describes the views that
65
- exist. The logic that picks one stays outside it.
60
+ What the component does with a value is not checked: a `switch` with a
61
+ `default`, a partial mapping table, or a value forwarded to a child all pass. A
62
+ contract describes the views that exist, not the logic that picks one.
66
63
 
67
64
  A prop relayed through `{...rest}` without being read is reported as unused.
68
- Following a spread would mean knowing the child's contract, and the warning
69
- blocks nothing.
70
-
71
- Nothing here executes a render.
72
65
 
73
- None of this exists for a repository without this adapter, so the **absence of
74
- these messages means nothing**. It is a capability of one adapter. The format
75
- guarantees none of it.
66
+ Nothing here executes a render. A repository without this adapter receives none
67
+ of these messages, so their **absence proves nothing** there.
76
68
 
77
69
  ## Generated types
78
70
 
79
71
  ```sh
80
- npx ucm-typescript # writes to src/generated/contracts/
72
+ npx ucm-typescript # writes to src/generated/contracts/
81
73
  npx ucm-typescript --out <dir>
82
74
  ```
83
75
 
84
- It derives the enum unions from the contracts, so that a component's props can
85
- be typed against the contract rather than against a hand-copied list.
76
+ The command reads the contracts under the `components` folder of
77
+ `ucm.config.json`, and writes one `<Component>.ts` per contract that has enum
78
+ props. Each file exports one union per enum prop, such as `ButtonVariant`, and
79
+ `ButtonVariantProps`, the combinations of variant axes that exist in Figma. Type
80
+ a component's props against these unions rather than against a hand-copied
81
+ list, and run the command again after each export. An unreadable contract is
82
+ skipped and named; `ucm check` reports why.
86
83
 
87
84
  ## Status
88
85
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ucm-kit/adapter-typescript",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
4
4
  "description": "Adaptateur TypeScript UCM : parité statique des composants et génération des types dérivés des contrats.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "test": "node scripts/run-tests.cjs"
36
36
  },
37
37
  "dependencies": {
38
- "@ucm-kit/core": "0.1.36",
38
+ "@ucm-kit/core": "0.1.37",
39
39
  "typescript": ">=5.5.0 <6"
40
40
  }
41
41
  }