Skip to content

Commit 4be9f71

Browse files
committed
Typescript support
1 parent 33ce42a commit 4be9f71

30 files changed

+6869
-5388
lines changed

.babelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
{
22
"presets": [
3+
"@babel/typescript",
34
[
45
"@babel/env",
56
{
7+
"targets": "> 0.25%, not dead",
68
"modules": false
79
}
810
]
11+
],
12+
"plugins": [
13+
"@babel/plugin-proposal-class-properties",
14+
"@babel/plugin-proposal-object-rest-spread",
15+
"@babel/plugin-syntax-dynamic-import"
916
]
1017
}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ samples/sample-app/node_modules/*
66
dist
77
.nyc_output
88
coverage.lcov
9-
coverage
9+
coverage
10+
out-tsc

package-lock.json

Lines changed: 5929 additions & 5052 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,35 @@
1313
"devDependencies": {
1414
"@babel/cli": "^7.10.5",
1515
"@babel/core": "^7.10.5",
16+
"@babel/plugin-proposal-class-properties": "^7.13.0",
17+
"@babel/plugin-proposal-object-rest-spread": "^7.14.4",
1618
"@babel/preset-env": "^7.10.4",
19+
"@babel/preset-typescript": "^7.13.0",
1720
"@rollup/plugin-babel": "^5.2.0",
1821
"@rollup/plugin-commonjs": "^14.0.0",
1922
"@rollup/plugin-json": "^4.1.0",
2023
"@rollup/plugin-node-resolve": "^8.4.0",
24+
"@rollup/plugin-typescript": "^8.2.1",
25+
"@types/node": "^15.6.1",
2126
"chai": "^4.2.0",
2227
"codecov": "^3.8.0",
28+
"deepmerge": "^4.2.2",
2329
"esm": "^3.2.25",
2430
"formdata-node": "2.1.0",
2531
"mocha": "^7.0.1",
2632
"nyc": "^15.1.0",
2733
"rollup": "^2.22.0",
34+
"rollup-plugin-cleanup": "^3.2.1",
2835
"rollup-plugin-terser": "^6.1.0",
29-
"sinon": "^8.1.1"
36+
"rollup-plugin-typescript2": "^0.30.0",
37+
"sinon": "^8.1.1",
38+
"ts-node": "^10.0.0",
39+
"typescript": "^4.3.2"
3040
},
3141
"scripts": {
3242
"dev": "rollup -c -w",
3343
"build": "rm -rf dist*;rollup -c",
34-
"test": "export NODE_ENV=test && nyc ./node_modules/mocha/bin/mocha --coverage -r esm --exit -t 40000 test/*.js;ex=$? ; unset NODE_ENV ; exit $ex;",
44+
"test": "export NODE_ENV=test && tsc && nyc ./node_modules/mocha/bin/mocha --coverage -r esm --exit -t 40000 test/*.js;ex=$? ; unset NODE_ENV ; exit $ex;",
3545
"startSampleApp": "yarn build && cd samples/sample-app/ && yarn install && node index.js",
3646
"report-coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov"
3747
},
@@ -57,5 +67,11 @@
5767
"bugs": {
5868
"url": "https://github.com/imagekit-developer/imagekit-javascript/issues"
5969
},
60-
"homepage": "https://github.com/imagekit-developer/imagekit-javascript#readme"
70+
"homepage": "https://github.com/imagekit-developer/imagekit-javascript#readme",
71+
"dependencies": {
72+
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
73+
"@babel/plugin-transform-typescript": "^7.14.4",
74+
"babel-plugin-transform-class-properties": "^6.24.1",
75+
"rollup-plugin-commonjs": "^10.1.0"
76+
}
6177
}

rollup.config.js

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,51 @@
1-
import babel from '@rollup/plugin-babel';
2-
import json from '@rollup/plugin-json';
3-
import pkg from './package.json';
1+
import babel from "@rollup/plugin-babel";
2+
import json from "@rollup/plugin-json";
3+
import pkg from "./package.json";
44
import { terser } from "rollup-plugin-terser";
5+
import cleanup from "rollup-plugin-cleanup";
6+
import typescript from "@rollup/plugin-typescript";
7+
import { nodeResolve } from "@rollup/plugin-node-resolve";
8+
import commonjs from "rollup-plugin-commonjs";
59

610
export default [
7-
// browser-friendly UMD build
8-
{
9-
input: 'src/index.js',
10-
output: {
11-
name: 'ImageKit',
12-
file: pkg.browser,
13-
format: 'umd'
14-
},
15-
plugins: [
16-
babel(),
17-
json(),
18-
terser()
19-
]
20-
},
21-
// CommonJS (for Node) and ES module (for bundlers) build.
22-
// (We could have three entries in the configuration array
23-
// instead of two, but it's quicker to generate multiple
24-
// builds from a single configuration where possible, using
25-
// an array for the `output` option, where we can specify
26-
// `file` and `format` for each target)
27-
{
28-
input: 'src/index.js',
29-
output: [
30-
{ file: pkg.main, format: 'cjs' },
31-
{ file: pkg.module, format: 'es' }
32-
],
33-
plugins: [
34-
json()
35-
]
36-
}
37-
];
11+
// browser-friendly UMD build
12+
{
13+
input: "src/index.ts",
14+
output: {
15+
name: "ImageKit",
16+
file: pkg.browser,
17+
format: "umd",
18+
sourceMap: true,
19+
},
20+
plugins: [
21+
nodeResolve({ extensions: [".ts"] }),
22+
json(),
23+
babel({
24+
extensions: [".ts"],
25+
}),
26+
terser(),
27+
cleanup(),
28+
],
29+
},
30+
// CommonJS (for Node) and ES module (for bundlers) build.
31+
// (We could have three entries in the configuration array
32+
// instead of two, but it's quicker to generate multiple
33+
// builds from a single configuration where possible, using
34+
// an array for the `output` option, where we can specify
35+
// `file` and `format` for each target)
36+
{
37+
input: "src/index.ts",
38+
output: [
39+
{ file: pkg.main, format: "cjs", exports: "default" },
40+
{ file: pkg.module, format: "es", exports: "default" },
41+
],
42+
plugins: [
43+
nodeResolve({ extensions: [".ts"] }),
44+
json(),
45+
babel({
46+
extensions: [".ts"],
47+
}),
48+
cleanup(),
49+
],
50+
},
51+
];

src/constants/errorMessages.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/constants/errorMessages.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default {
2+
MANDATORY_INITIALIZATION_MISSING: { message: "Missing urlEndpoint during SDK initialization", help: "" },
3+
INVALID_TRANSFORMATION_POSITION: { message: "Invalid transformationPosition parameter", help: "" },
4+
PRIVATE_KEY_CLIENT_SIDE: { message: "privateKey should not be passed on the client side", help: "" },
5+
MISSING_UPLOAD_DATA: { message: "Missing data for upload", help: "" },
6+
MISSING_UPLOAD_FILE_PARAMETER: { message: "Missing file parameter for upload", help: "" },
7+
MISSING_UPLOAD_FILENAME_PARAMETER: { message: "Missing fileName parameter for upload", help: "" },
8+
MISSING_AUTHENTICATION_ENDPOINT: { message: "Missing authentication endpoint for upload", help: "" },
9+
AUTH_ENDPOINT_TIMEOUT: { message: "The authenticationEndpoint you provided timed out in 60 seconds", help: "" },
10+
AUTH_ENDPOINT_NETWORK_ERROR: { message: "Request to authenticationEndpoint failed due to network error", help: "" },
11+
UPLOAD_ENDPOINT_NETWORK_ERROR: {
12+
message: "Request to ImageKit upload endpoint failed due to network error",
13+
help: "",
14+
},
15+
INVALID_UPLOAD_OPTIONS: { message: "Invalid uploadOptions parameter", help: "" },
16+
};

src/constants/supportedTransforms.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)