浏览代码

chore(api): remove `type-fest` (#4605)

Lucas Fernandes Nogueira 3 年之前
父节点
当前提交
d5e910ebcc
共有 4 个文件被更改,包括 39 次插入46 次删除
  1. 5 0
      .changes/remove-type-fest.md
  2. 0 3
      tooling/api/package.json
  3. 34 38
      tooling/api/src/os.ts
  4. 0 5
      tooling/api/yarn.lock

+ 5 - 0
.changes/remove-type-fest.md

@@ -0,0 +1,5 @@
+---
+"api": patch
+---
+
+Remove the `type-fest` dependency, changing the OS types to the specific enum instead of allowing any string.

+ 0 - 3
tooling/api/package.json

@@ -67,8 +67,5 @@
     "typedoc": "0.23.5",
     "typedoc-plugin-markdown": "3.13.3",
     "typescript": "4.7.4"
-  },
-  "dependencies": {
-    "type-fest": "2.16.0"
   }
 }

+ 34 - 38
tooling/api/src/os.ts

@@ -23,10 +23,36 @@
  * @module
  */
 
-import { LiteralUnion } from 'type-fest'
 import { isWindows } from './helpers/os-check'
 import { invokeTauriCommand } from './helpers/tauri'
 
+type Platform =
+  | 'linux'
+  | 'darwin'
+  | 'ios'
+  | 'freebsd'
+  | 'dragonfly'
+  | 'netbsd'
+  | 'openbsd'
+  | 'solaris'
+  | 'android'
+  | 'win32'
+
+type OsType = 'Linux' | 'Darwin' | 'Windows_NT'
+
+type Arch =
+  | 'x86'
+  | 'x86_64'
+  | 'arm'
+  | 'aarch64'
+  | 'mips'
+  | 'mips64'
+  | 'powerpc'
+  | 'powerpc64'
+  | 'riscv64'
+  | 's390x'
+  | 'sparc64'
+
 /**
  * The operating system-specific end-of-line marker.
  * - `\n` on POSIX
@@ -43,22 +69,8 @@ const EOL = isWindows() ? '\r\n' : '\n'
  * const platformName = await platform();
  * ```
  */
-async function platform(): Promise<
-  LiteralUnion<
-    | 'linux'
-    | 'darwin'
-    | 'ios'
-    | 'freebsd'
-    | 'dragonfly'
-    | 'netbsd'
-    | 'openbsd'
-    | 'solaris'
-    | 'android'
-    | 'win32',
-    string
-  >
-> {
-  return invokeTauriCommand<string>({
+async function platform(): Promise<Platform> {
+  return invokeTauriCommand<Platform>({
     __tauriModule: 'Os',
     message: {
       cmd: 'platform'
@@ -91,10 +103,8 @@ async function version(): Promise<string> {
  * const osType = await type();
  * ```
  */
-async function type(): Promise<
-  LiteralUnion<'Linux' | 'Darwin' | 'Windows_NT', string>
-> {
-  return invokeTauriCommand<string>({
+async function type(): Promise<OsType> {
+  return invokeTauriCommand<OsType>({
     __tauriModule: 'Os',
     message: {
       cmd: 'osType'
@@ -111,23 +121,8 @@ async function type(): Promise<
  * const archName = await arch();
  * ```
  */
-async function arch(): Promise<
-  LiteralUnion<
-    | 'x86'
-    | 'x86_64'
-    | 'arm'
-    | 'aarch64'
-    | 'mips'
-    | 'mips64'
-    | 'powerpc'
-    | 'powerpc64'
-    | 'riscv64'
-    | 's390x'
-    | 'sparc64',
-    string
-  >
-> {
-  return invokeTauriCommand<string>({
+async function arch(): Promise<Arch> {
+  return invokeTauriCommand<Arch>({
     __tauriModule: 'Os',
     message: {
       cmd: 'arch'
@@ -153,3 +148,4 @@ async function tempdir(): Promise<string> {
 }
 
 export { EOL, platform, version, type, arch, tempdir }
+export type { Platform, OsType, Arch }

+ 0 - 5
tooling/api/yarn.lock

@@ -3255,11 +3255,6 @@ type-check@^0.4.0, type-check@~0.4.0:
   dependencies:
     prelude-ls "^1.2.1"
 
-type-fest@2.16.0:
-  version "2.16.0"
-  resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.16.0.tgz#1250fbd64dafaf4c8e405e393ef3fb16d9651db2"
-  integrity sha512-qpaThT2HQkFb83gMOrdKVsfCN7LKxP26Yq+smPzY1FqoHRjqmjqHXA7n5Gkxi8efirtbeEUxzfEdePthQWCuHw==
-
 type-fest@^0.20.2:
   version "0.20.2"
   resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.20.2.tgz#1bf207f4b28f91583666cb5fbd327887301cd5f4"