Skip to content

Commit 2fd6b6b

Browse files
committed
fix: missing ts declarations
1 parent 96b3133 commit 2fd6b6b

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

.changeset/fuzzy-apples-refuse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rhds/tokens": patch
3+
---
4+
5+
Added missing typescript type declarations

lib/actions/write-es-map-declaration.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,46 @@
11
import type { Action } from 'style-dictionary/types';
22

3-
import { readFile, writeFile, rm } from 'node:fs/promises';
4-
5-
import { fileURLToPath } from 'node:url';
3+
import { writeFile, rm } from 'node:fs/promises';
64

75
const rel = (path: string) => new URL(path, import.meta.url);
8-
const PACKAGE_JSON_URL = rel('../../package.json');
9-
const TOKENS_DECL_CONTENT = 'export declare const tokens: Map<`--rh-${string}`, string|number>;';
10-
const TOKENS_DECL_URLS = [
11-
rel('../../js/tokens.d.ts'),
12-
rel('../../js/tokens.d.cts'),
13-
];
6+
7+
const files = new Map([
8+
[
9+
rel('../../js/tokens.d.ts'),
10+
'export declare const tokens: Map<`--rh-${string}`, string|number>;',
11+
],
12+
[
13+
rel('../../js/meta.d.ts'),
14+
`interface DesignToken {
15+
value?: any;
16+
$value?: any;
17+
type?: string;
18+
$type?: string;
19+
$description?: string;
20+
name?: string;
21+
comment?: string;
22+
themeable?: boolean;
23+
attributes?: Record<string, unknown>;
24+
[key: string]: any;
25+
}
26+
27+
export declare const tokens: Map<\`--rh-\${string}\`, DesignToken>;
28+
`,
29+
],
30+
]);
1431

1532
/**
1633
* Write declaration file for JS token map
1734
*/
1835
export const writeEsMapDeclaration: Action = {
1936
name: 'writeEsMapDeclaration',
2037
async do() {
21-
for (const url of TOKENS_DECL_URLS) {
22-
await writeFile(url, TOKENS_DECL_CONTENT, 'utf8');
38+
for (const [url, content] of files) {
39+
await writeFile(url, content, 'utf8');
2340
}
2441
},
2542
async undo() {
26-
for (const url of TOKENS_DECL_URLS) {
43+
for (const [url] of files) {
2744
await rm(url);
2845
}
2946
},

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
},
2424
"./meta.js": {
2525
"import": "./js/meta.js",
26-
"require": "./js/meta.cjs"
26+
"require": "./js/meta.cjs",
27+
"types": "./js/meta.d.ts"
2728
},
2829
"./json/*": {
2930
"require": "./json/*"

0 commit comments

Comments
 (0)