Skip to content

Commit 1a189a4

Browse files
jimmycallingismya
andauthored
feat: Typescript 1/4 (#67)
* deps: bump vite * build: add external types to socket.io file * build: migrate error to ts * build: enable typescript * fix errorCode typing * Reorder test key in defineConfig --------- Co-authored-by: Lars Johansson <[email protected]>
1 parent d79a416 commit 1a189a4

File tree

7 files changed

+753
-71
lines changed

7 files changed

+753
-71
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@ftrack/api",
33
"description": "JavaScript API for ftrack.",
44
"scripts": {
5-
"lint": "eslint . && prettier -c .",
5+
"lint": "tsc && eslint . && prettier -c .",
66
"test": "vitest --run test && yarn lint",
77
"build": "vite build",
88
"prepack": "yarn build",
@@ -31,8 +31,9 @@
3131
"msw": "^1.0.0",
3232
"prettier": "^2.8.3",
3333
"typescript": "^4.9.5",
34-
"vite": "^4.0.4",
35-
"vitest": "^0.28.3"
34+
"vite": "^4.1.1",
35+
"vite-plugin-dts": "^1.7.2",
36+
"vitest": "^0.28.4"
3637
},
3738
"repository": {
3839
"type": "git",

source/error.js renamed to source/error.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
// :copyright: Copyright (c) 2016 ftrack
2-
/**
3-
* Error namespace
4-
* @namespace error
5-
*/
62

73
/**
84
*
@@ -12,15 +8,16 @@
128
* @param {string} name name of error class
139
* @return {CustomError} Custom error object
1410
*/
15-
function errorFactory(name) {
16-
function CustomError(message, errorCode) {
17-
this.name = name;
18-
this.message = message;
19-
this.errorCode = errorCode;
20-
this.stack = new Error().stack;
21-
}
11+
function errorFactory(name: string) {
12+
class CustomError extends Error {
13+
errorCode?: string;
2214

23-
CustomError.prototype = new Error();
15+
constructor(message: string, errorCode?: string) {
16+
super(message);
17+
this.name = name;
18+
this.errorCode = errorCode;
19+
}
20+
}
2421

2522
return CustomError;
2623
}
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export function connect(serverUrl: string, options: any): void;

tsconfig.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"useDefineForClassFields": true,
5+
"module": "ESNext",
6+
"lib": ["ESNext", "DOM"],
7+
"moduleResolution": "Node",
8+
"strict": true,
9+
"resolveJsonModule": true,
10+
"isolatedModules": true,
11+
"esModuleInterop": true,
12+
"noEmit": true,
13+
"noUnusedLocals": true,
14+
"noUnusedParameters": true,
15+
"noImplicitReturns": true,
16+
"skipLibCheck": true,
17+
"allowJs": true
18+
},
19+
"include": ["source"],
20+
"exclude": ["source/socket.io-websocket-only.cjs"]
21+
}

vite.config.js renamed to vite.config.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
const path = require("path");
2-
const { defineConfig } = require("vite");
3-
const commonjs = require("@rollup/plugin-commonjs");
1+
import { defineConfig, UserConfig } from "vite";
2+
import { InlineConfig } from "vitest";
3+
import path from "path";
4+
import dts from "vite-plugin-dts";
5+
import commonjs from "@rollup/plugin-commonjs";
46

5-
module.exports = defineConfig({
7+
interface VitestConfigExport extends UserConfig {
8+
test: InlineConfig;
9+
}
10+
11+
export default defineConfig({
612
build: {
713
minify: false,
814
sourcemap: true,
915
lib: {
10-
entry: path.resolve(__dirname, "source/index.js"),
16+
entry: path.resolve(__dirname, "source/index.ts"),
1117
name: "ftrack-javascript-api",
1218
fileName: (format) => `ftrack-javascript-api.${format}.js`,
1319
},
@@ -26,6 +32,7 @@ module.exports = defineConfig({
2632
plugins: [commonjs({ include: "./source/socket.io-websocket-only.cjs" })],
2733
},
2834
},
35+
plugins: [dts()],
2936
test: {
3037
environment: "jsdom",
3138
globals: true,
@@ -34,4 +41,4 @@ module.exports = defineConfig({
3441
fallbackCJS: true,
3542
},
3643
},
37-
});
44+
} as VitestConfigExport);

0 commit comments

Comments
 (0)