Skip to content

feat: Typescript 1/4 #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@ftrack/api",
"description": "JavaScript API for ftrack.",
"scripts": {
"lint": "eslint . && prettier -c .",
"lint": "tsc && eslint . && prettier -c .",
"test": "vitest --run test && yarn lint",
"build": "vite build",
"prepack": "yarn build",
Expand Down Expand Up @@ -31,8 +31,9 @@
"msw": "^1.0.0",
"prettier": "^2.8.3",
"typescript": "^4.9.5",
"vite": "^4.0.4",
"vitest": "^0.28.3"
"vite": "^4.1.1",
"vite-plugin-dts": "^1.7.2",
"vitest": "^0.28.4"
},
"repository": {
"type": "git",
Expand Down
21 changes: 9 additions & 12 deletions source/error.js → source/error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// :copyright: Copyright (c) 2016 ftrack
/**
* Error namespace
* @namespace error
*/

/**
*
Expand All @@ -12,15 +8,16 @@
* @param {string} name name of error class
* @return {CustomError} Custom error object
*/
function errorFactory(name) {
function CustomError(message, errorCode) {
this.name = name;
this.message = message;
this.errorCode = errorCode;
this.stack = new Error().stack;
}
function errorFactory(name: string) {
class CustomError extends Error {
errorCode?: string;

CustomError.prototype = new Error();
constructor(message: string, errorCode?: string) {
super(message);
this.name = name;
this.errorCode = errorCode;
}
}

return CustomError;
}
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions source/socket.io-websocket-only.cjs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function connect(serverUrl: string, options: any): void;
21 changes: 21 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ESNext", "DOM"],
"moduleResolution": "Node",
"strict": true,
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,
"noEmit": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"skipLibCheck": true,
"allowJs": true
},
"include": ["source"],
"exclude": ["source/socket.io-websocket-only.cjs"]
}
19 changes: 13 additions & 6 deletions vite.config.js → vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
const path = require("path");
const { defineConfig } = require("vite");
const commonjs = require("@rollup/plugin-commonjs");
import { defineConfig, UserConfig } from "vite";
import { InlineConfig } from "vitest";
import path from "path";
import dts from "vite-plugin-dts";
import commonjs from "@rollup/plugin-commonjs";

module.exports = defineConfig({
interface VitestConfigExport extends UserConfig {
test: InlineConfig;
}

export default defineConfig({
build: {
minify: false,
sourcemap: true,
lib: {
entry: path.resolve(__dirname, "source/index.js"),
entry: path.resolve(__dirname, "source/index.ts"),
name: "ftrack-javascript-api",
fileName: (format) => `ftrack-javascript-api.${format}.js`,
},
Expand All @@ -26,6 +32,7 @@ module.exports = defineConfig({
plugins: [commonjs({ include: "./source/socket.io-websocket-only.cjs" })],
},
},
plugins: [dts()],
test: {
environment: "jsdom",
globals: true,
Expand All @@ -34,4 +41,4 @@ module.exports = defineConfig({
fallbackCJS: true,
},
},
});
} as VitestConfigExport);
Loading