Skip to content

Commit c2faf2e

Browse files
authored
fix: move types to separate package to prevent unnecessary CLI dependencies (#4241)
1 parent ba0fc4a commit c2faf2e

File tree

32 files changed

+156
-81
lines changed

32 files changed

+156
-81
lines changed

.changeset/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"@digdir/designsystemet",
1313
"@digdir/designsystemet-css",
1414
"@digdir/designsystemet-theme",
15+
"@digdir/designsystemet-types",
1516
"@digdir/designsystemet-react"
1617
]
1718
],

.changeset/great-kiwis-grow.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@digdir/designsystemet-react": minor
3+
"@digdir/designsystemet-theme": minor
4+
"@digdir/designsystemet-types": minor
5+
"@digdir/designsystemet": minor
6+
---
7+
8+
Move submodule `@digdir/designsystemet/types` to a new package `@digdir/designsystemet-types` and change all references.
9+
10+
After re-running `tokens build` downstream, this removes transitive dependencies on runtime dependencies on CLI tools like `commander` and `style-dictionary` which are never used in runtime, but are required for the CLI to function. It also makes code which doesn't use the CLI unaffected by our node version limitations (currently >= 22 due to `style-dictionary`).
11+
12+
`@digdir/designsystemet/types` is preserved for now as a deprecated re-export of `@digdir/designsystemet-types` to avoid breaking people's builds.

.github/workflows/check-cli-node-compatibility.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
run: pnpm install
2727

2828
- name: build cli
29-
run: pnpm --filter "@digdir/designsystemet" build
29+
run: pnpm --filter "@digdir/designsystemet..." build
3030

3131
- name: upload dist
3232
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ import { Button } from '@digdir/designsystemet-react';
8080

8181
#### 1.3 Typescript
8282

83-
Types for your theme can be found under `@digdir/designsystemet/types` when combined with the generated types file, `types.d.ts`, for your theme.
83+
Types for your theme can be found under `@digdir/designsystemet-types` when combined with the generated types file, `types.d.ts`, for your theme.
8484

8585
Add the following to your `tsconfig.json`
8686
```jsonc

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
},
6464
"dependencies": {
6565
"@commander-js/extra-typings": "^14.0.0",
66+
"@digdir/designsystemet-types": "workspace:^",
6667
"@tokens-studio/sd-transforms": "1.3.0",
6768
"apca-w3": "^0.1.9",
6869
"change-case": "^5.4.4",

packages/cli/src/tokens/process/output/declarations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ function createColorTypeDeclaration(colors: string[]) {
2828

2929
const typeDeclaration = `
3030
/* ${defaultFileHeader} */
31-
import type {} from '@digdir/designsystemet/types';
31+
import type {} from '@digdir/designsystemet-types';
3232
3333
// Augment types based on theme
34-
declare module '@digdir/designsystemet/types' {
34+
declare module '@digdir/designsystemet-types' {
3535
export interface ColorDefinitions {
3636
${colors.map((color) => ` ${color.includes('-') ? `'${color}'` : color}: never;`).join('\n')}
3737
}

packages/cli/src/types.ts

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,6 @@
1-
// This file defines public types used in the Designsystemet
2-
3-
// EmptyObject implementation from https://github.com/sindresorhus/type-fest/blob/main/source/empty-object.d.ts
4-
declare const emptyObjectSymbol: unique symbol;
5-
type EmptyObject = { [emptyObjectSymbol]?: never };
6-
7-
/**
8-
* Base interface for available colors in Designsystemet.
9-
* The CLI will generate augmentations of this interface to allow
10-
* type safety of custom color names.
11-
*/
12-
13-
// biome-ignore lint/suspicious/noEmptyInterface: used for interface augmentation
14-
export interface ColorDefinitions {}
15-
// biome-ignore lint/suspicious/noEmptyInterface: used for interface augmentation
16-
export interface SeverityColorDefinitions {}
17-
18-
/**
19-
* If {@link ColorDefinitions} or {@link SeverityColorDefinitions} has been extended to include color names, return T,
20-
* otherwise return the arbitrary string type.
1+
/*!
2+
* This file is deprecated and will be removed in a future release.
3+
* Use @digdir/designsystemet-types instead
214
*/
22-
type ColorWithFallback<T> = ColorDefinitions extends EmptyObject ? string : T;
235

24-
/**
25-
* Represents the available severity colors for the Designsystemet variables.
26-
* These are predefined colors that can be used to indicate different levels of severity.
27-
* - `'info'`: Use the info color.
28-
* - `'success'`: Use the success color.
29-
* - `'warning'`: Use the warning color.
30-
* - `'danger'`: Use the danger color.
31-
*/
32-
export type SeverityColors = ColorWithFallback<keyof SeverityColorDefinitions>;
33-
/**
34-
* Represents the available color options for the Designsystemet variables.
35-
*
36-
* These are augmented based on your theme configuration.
37-
*
38-
* Consist of both main and support colors
39-
* @link https://theme.designsystemet.no
40-
*/
41-
export type Color = ColorWithFallback<keyof ColorDefinitions>;
42-
/**
43-
* Represents the recommended size options for the Designsystemet variables.
44-
* - `'sm'`: Use the small size.
45-
* - `'md'`: Use the medium size.
46-
* - `'lg'`: Use the large size.
47-
*/
48-
export type Size = 'sm' | 'md' | 'lg';
49-
/**
50-
* Represents the available color scheme options for the Designsystemet variables.
51-
* - `'light'`: Use the light color scheme.
52-
* - `'dark'`: Use the dark color scheme.
53-
* - `'auto'`: Automatically select the color scheme based on system preferences.
54-
*/
55-
export type ColorScheme = 'light' | 'dark' | 'auto';
6+
export * from '@digdir/designsystemet-types';

packages/react/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"access": "public"
4343
},
4444
"dependencies": {
45+
"@digdir/designsystemet-types": "workspace:^",
4546
"@floating-ui/dom": "^1.7.4",
4647
"@floating-ui/react": "0.26.23",
4748
"@navikt/aksel-icons": "^7.33.3",

packages/react/react-types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Color, ColorScheme, Size } from '@digdir/designsystemet/types';
1+
import type { Color, ColorScheme, Size } from '@digdir/designsystemet-types';
22

33
declare global {
44
namespace React {

packages/react/src/colors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export type {
22
Color,
33
SeverityColors,
4-
} from '@digdir/designsystemet/types';
4+
} from '@digdir/designsystemet-types';

0 commit comments

Comments
 (0)