Skip to content

Commit

Permalink
Fix TS errors, update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
drwpow committed Apr 13, 2023
1 parent 632ce87 commit ecc5389
Show file tree
Hide file tree
Showing 22 changed files with 1,667 additions and 1,740 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-garlics-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cobalt-ui/plugin-js': patch
---

Fix TS inference error with newer versions of TS
10 changes: 10 additions & 0 deletions .changeset/green-ducks-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@cobalt-ui/plugin-sass': patch
'@cobalt-ui/plugin-css': patch
'@cobalt-ui/plugin-js': patch
'@cobalt-ui/utils': patch
'@cobalt-ui/core': patch
'@cobalt-ui/cli': patch
---

Update TS types for 4.7
3 changes: 2 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ module.exports = {
plugins: ['@typescript-eslint', 'prettier'],
rules: {
'no-console': ['error'],
'no-shadow': ['error'],
'no-misleading-character-class': 'off',
'no-prototype-builtins': 'off', // don’t tell me how to JS!
'no-shadow': ['error'],
'no-undef': 'off', // handled by TS
'prefer-const': 'off',
'prefer-template': ['error'], // "+" is for math; templates are for strings
Expand Down
14 changes: 2 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,19 @@ on:

jobs:
lint:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-
- uses: pnpm/action-setup@v2
with:
version: latest
- uses: actions/setup-node@v3
- run: pnpm i
- run: pnpm run lint
test:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-
- uses: pnpm/action-setup@v2
with:
version: latest
Expand Down
14 changes: 7 additions & 7 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
"dev:serve": "astro dev"
},
"devDependencies": {
"@cobalt-ui/cli": "^0.7.4",
"@cobalt-ui/core": "^0.7.4",
"@cobalt-ui/plugin-css": "^1.1.6",
"@cobalt-ui/plugin-sass": "^1.1.4",
"astro": "^2.0.2",
"@cobalt-ui/cli": "*",
"@cobalt-ui/core": "*",
"@cobalt-ui/plugin-css": "*",
"@cobalt-ui/plugin-sass": "*",
"astro": "^2.2.3",
"npm-run-all": "^4.1.5",
"sass": "^1.57.1",
"sass": "^1.62.0",
"shiki": "^0.11.1",
"vite": "^4.0.4"
"vite": "^4.2.1"
}
}
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"dev:plugin-js": "cd packages/plugin-js && npm run dev",
"dev:plugin-sass": "cd packages/plugin-sass && npm run dev",
"lint": "eslint \"packages/**/*.{ts,js,cjs,mjs}\"",
"test": "run-p -s test:*",
"test": "run-p test:*",
"test:cli": "cd packages/cli && npm run test",
"test:core": "cd packages/core && npm run test",
"test:plugin-css": "cd packages/plugin-css && npm run test",
Expand All @@ -40,16 +40,15 @@
},
"devDependencies": {
"@changesets/cli": "^2.26.1",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"del-cli": "^4.0.1",
"esbuild": "^0.17.14",
"eslint": "^8.36.0",
"eslint": "^8.38.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"npm-run-all": "^4.1.5",
"pnpm": "^7.30.5",
"pnpm": "^8.2.0",
"prettier": "^2.8.7",
"typescript": "^5.0.2"
"typescript": "^5.0.4"
}
}
14 changes: 9 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,27 @@
"scripts": {
"build": "tsc",
"dev": "tsc -w",
"test": "vitest run"
"test": "run-p test:js test:ts",
"test:js": "vitest run",
"test:ts": "tsc --noEmit"
},
"dependencies": {
"@cobalt-ui/core": "^0.7.4",
"@cobalt-ui/utils": "^0.5.3",
"@cobalt-ui/core": "*",
"@cobalt-ui/utils": "*",
"@types/csso": "^5.0.0",
"better-color-tools": "^0.10.2",
"chokidar": "^3.5.3",
"dotenv": "^16.0.3",
"number-precision": "^1.6.0",
"piscina": "^3.2.0",
"svgo": "^3.0.2",
"undici": "^5.21.0",
"undici": "^5.21.2",
"yargs-parser": "^21.1.1"
},
"devDependencies": {
"@types/node": "^18.15.11",
"figma-api": "^1.11.0",
"vitest": "^0.29.7"
"npm-run-all": "^4.1.5",
"vitest": "^0.30.1"
}
}
1 change: 1 addition & 0 deletions packages/cli/src/figma/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {FigmaToken, ResolvedConfig, Token} from '@cobalt-ui/core';
import type * as Figma from 'figma-api';
// @ts-expect-error needs https://github.com/piscinajs/piscina/pull/239
import Piscina from 'piscina';
import {fileURLToPath, URL} from 'node:url';
import {collectChildren, collectStylesAndComponents, fetchDoc, padRight} from './util.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/figma/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as Figma from 'figma-api';
import {GetFileResult} from 'figma-api/lib/api-types';
import type {GetFileResult} from 'figma-api/lib/api-types.js';
import {FG_RED, RESET, UNDERLINE} from '@cobalt-ui/utils';
import path from 'node:path';
import {URL} from 'node:url';
Expand Down
15 changes: 9 additions & 6 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,26 @@
"type": "module",
"main": "./dist/index.min.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc && npm run bundle",
"bundle": "esbuild --format=esm --bundle --minify dist/index.js --outfile=dist/index.min.js --sourcemap && cp dist/index.d.ts dist/index.min.d.ts",
"dev": "run-p -s dev:*",
"dev:ts": "tsc --watch",
"dev:bundle": "npm run bundle -- --watch",
"bundle": "esbuild --format=esm --bundle --minify dist/index.js --outfile=dist/index.min.js --sourcemap",
"test": "vitest run"
"test": "run-p -s test:*",
"test:js": "vitest run",
"test:ts": "tsc --noEmit"
},
"dependencies": {
"@cobalt-ui/utils": "^0.5.3",
"@cobalt-ui/utils": "*",
"@types/csso": "^5.0.0",
"better-color-tools": "^0.10.2",
"svgo": "^3.0.2"
},
"devDependencies": {
"@types/node": "^18.15.10",
"vitest": "^0.29.7"
"@types/node": "^18.15.11",
"esbuild": "^0.17.16",
"npm-run-all": "^4.1.5",
"vitest": "^0.30.1"
}
}
15 changes: 9 additions & 6 deletions packages/plugin-css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,29 @@
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc",
"dev": "tsc -w",
"test": "vitest run"
"test": "run-p -s test:*",
"test:js": "vitest run",
"test:ts": "tsc --noEmit"
},
"peerDependencies": {
"@cobalt-ui/cli": "*"
},
"dependencies": {
"@cobalt-ui/utils": "^0.5.3",
"@cobalt-ui/utils": "*",
"@types/csso": "^5.0.0",
"better-color-tools": "^0.10.2",
"mime": "^3.0.0",
"svgo": "^3.0.2"
},
"devDependencies": {
"@cobalt-ui/cli": "^0.7.4",
"@cobalt-ui/core": "^0.7.4",
"@cobalt-ui/cli": "*",
"@cobalt-ui/core": "*",
"@types/mime": "^2.0.3",
"vitest": "^0.29.7"
"@types/node": "^18.15.11",
"npm-run-all": "^4.1.5",
"vitest": "^0.30.1"
}
}
14 changes: 8 additions & 6 deletions packages/plugin-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,25 @@
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc",
"dev": "tsc -w",
"pretest": "co build -c ./test/types.tokens.mjs",
"test": "vitest run"
"test": "run-p -s test:*",
"test:js": "vitest run",
"test:ts": "tsc --noEmit"
},
"peerDependencies": {
"@cobalt-ui/cli": "*"
},
"dependencies": {
"@cobalt-ui/utils": "^0.5.3"
"@cobalt-ui/utils": "*"
},
"devDependencies": {
"@cobalt-ui/cli": "^0.7.4",
"@cobalt-ui/core": "^0.7.4",
"@cobalt-ui/cli": "*",
"@cobalt-ui/core": "*",
"fast-glob": "^3.2.12",
"vitest": "^0.29.7"
"npm-run-all": "^4.1.5",
"vitest": "^0.30.1"
}
}
8 changes: 4 additions & 4 deletions packages/plugin-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const JS_EXT_RE = /\.(mjs|js)$/i;
const JSON_EXT_RE = /\.json$/i;
const SINGLE_QUOTE_RE = /'/g;

export type TransformFn = (token: ParsedToken, mode?: string) => typeof token['$value'];
export type TransformFn = (token: ParsedToken, mode?: string) => (typeof token)['$value'];

export interface Options {
/** output JS? (default: true) */
Expand Down Expand Up @@ -56,7 +56,7 @@ ${indent(`}${indentLv === 0 ? ';' : ''}`, indentLv)}`;
throw new Error(`Could not serialize ${value}`);
}

function defaultTransform(token: ParsedToken, mode?: string): typeof token['$value'] {
function defaultTransform(token: ParsedToken, mode?: string): (typeof token)['$value'] {
if (!mode || !token.$extensions?.mode || !(mode in token.$extensions.mode) || !token.$extensions.mode[mode]) return token.$value;
const modeVal = token.$extensions.mode[mode];
if (typeof modeVal === 'string' || Array.isArray(modeVal)) return modeVal;
Expand Down Expand Up @@ -184,8 +184,8 @@ export function token(tokenID, modeName) {
'',
`export declare const modes: ${ts.modes.length ? `{\n${ts.modes.join('\n')}\n}` : 'Record<string, never>'};`,
'',
`export declare function token(tokenID: keyof typeof tokens, modeName?: never): typeof tokens[tokenID];`,
`export declare function token(tokenID: keyof typeof modes, modeName?: keyof typeof modes[tokenID]): typeof modes[tokenID][modeName];`,
`export declare function token<K extends keyof typeof tokens>(tokenID: K, modeName?: never): typeof tokens[K];`,
`export declare function token<K extends keyof typeof modes, M extends keyof typeof modes[K]>(tokenID: K, modeName: M): typeof modes[K][M];`,
'', // EOF newline
].join('\n'),
},
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-js/test/border/want.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ export declare const modes: {
};
};

export declare function token(tokenID: keyof typeof tokens, modeName?: never): typeof tokens[typeof tokenID];
export declare function token(tokenID: keyof typeof modes, modeName?: keyof typeof modes[typeof tokenID]): typeof modes[typeof tokenID];
export declare function token<K extends keyof typeof tokens>(tokenID: K, modeName?: never): typeof tokens[K];
export declare function token<K extends keyof typeof modes, M extends keyof typeof modes[K]>(tokenID: K, modeName: M): typeof modes[K][M];
4 changes: 2 additions & 2 deletions packages/plugin-js/test/color/want.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ export declare const modes: {
};
};

export declare function token(tokenID: keyof typeof tokens, modeName?: never): typeof tokens[typeof tokenID];
export declare function token(tokenID: keyof typeof modes, modeName?: keyof typeof modes[typeof tokenID]): typeof modes[typeof tokenID];
export declare function token<K extends keyof typeof tokens>(tokenID: K, modeName?: never): typeof tokens[K];
export declare function token<K extends keyof typeof modes, M extends keyof typeof modes[K]>(tokenID: K, modeName: M): typeof modes[K][M];
4 changes: 2 additions & 2 deletions packages/plugin-js/test/transition/want.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,5 @@ export declare const meta: {

export declare const modes: Record<string, never>;

export declare function token(tokenID: keyof typeof tokens, modeName?: never): typeof tokens[typeof tokenID];
export declare function token(tokenID: keyof typeof modes, modeName?: keyof typeof modes[typeof tokenID]): typeof modes[typeof tokenID];
export declare function token<K extends keyof typeof tokens>(tokenID: K, modeName?: never): typeof tokens[K];
export declare function token<K extends keyof typeof modes, M extends keyof typeof modes[K]>(tokenID: K, modeName: M): typeof modes[K][M];
4 changes: 2 additions & 2 deletions packages/plugin-js/test/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export declare const modes: {
};
};

export declare function token(tokenID: keyof typeof tokens, modeName?: never): typeof tokens[typeof tokenID];
export declare function token(tokenID: keyof typeof modes, modeName?: keyof typeof modes[typeof tokenID]): typeof modes[typeof tokenID];
export declare function token<K extends keyof typeof tokens>(tokenID: K, modeName?: never): typeof tokens[K];
export declare function token<K extends keyof typeof modes, M extends keyof typeof modes[K]>(tokenID: K, modeName: M): typeof modes[K][M];
4 changes: 2 additions & 2 deletions packages/plugin-js/test/typography/want.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ export declare const meta: {

export declare const modes: Record<string, never>;

export declare function token(tokenID: keyof typeof tokens, modeName?: never): typeof tokens[typeof tokenID];
export declare function token(tokenID: keyof typeof modes, modeName?: keyof typeof modes[typeof tokenID]): typeof modes[typeof tokenID];
export declare function token<K extends keyof typeof tokens>(tokenID: K, modeName?: never): typeof tokens[K];
export declare function token<K extends keyof typeof modes, M extends keyof typeof modes[K]>(tokenID: K, modeName: M): typeof modes[K][M];
17 changes: 10 additions & 7 deletions packages/plugin-sass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,29 @@
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc",
"dev": "tsc -w",
"test": "vitest run"
"test": "run-p -s test:*",
"test:js": "vitest run",
"test:ts": "tsc --noEmit"
},
"peerDependencies": {
"@cobalt-ui/cli": "*"
},
"dependencies": {
"@cobalt-ui/plugin-css": "^1.1.6",
"@cobalt-ui/utils": "^0.5.3",
"@cobalt-ui/plugin-css": "*",
"@cobalt-ui/utils": "*",
"@types/csso": "^5.0.0",
"mime": "^3.0.0",
"svgo": "^3.0.2"
},
"devDependencies": {
"@cobalt-ui/cli": "^0.7.4",
"@cobalt-ui/core": "^0.7.4",
"@cobalt-ui/cli": "*",
"@cobalt-ui/core": "*",
"@types/mime": "^2.0.3",
"vitest": "^0.29.7"
"@types/node": "^18.15.11",
"npm-run-all": "^4.1.5",
"vitest": "^0.30.1"
}
}
3 changes: 1 addition & 2 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc",
"dev": "tsc -w"
},
"devDependencies": {
"@types/node": "^18.15.10"
"@types/node": "^18.15.11"
}
}
Loading

0 comments on commit ecc5389

Please sign in to comment.