Skip to content

Commit 95a2a21

Browse files
committed
adding esm support and improved types
1 parent ff68298 commit 95a2a21

File tree

15 files changed

+420
-167
lines changed

15 files changed

+420
-167
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ node_modules
44
coverage.lcov
55
coverage
66
.DS_Store
7-
dist
7+
dist*

index.ts

Lines changed: 266 additions & 138 deletions
Large diffs are not rendered by default.

libs/interfaces/IKCallback.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export interface IKCallback<T, E extends Error = Error> {
22
(err: E | null, response: T): void;
3+
(err: E, response: T | null): void;
34
}

libs/interfaces/IKResponse.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
interface ResponseMetadata {
2+
statusCode: number;
3+
headers: Record<string, string | number | boolean>;
4+
}
5+
6+
type IKResponse<T> = T extends Error
7+
? T & { $ResponseMetadata?: ResponseMetadata }
8+
: T & { $ResponseMetadata: ResponseMetadata };
9+
10+
export default IKResponse;

libs/upload/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import respond from "../../utils/respond";
44
import request from "../../utils/request";
55
import { IKCallback } from "../interfaces/IKCallback";
66
import { ImageKitOptions, UploadOptions, UploadResponse } from "../interfaces";
7-
const FormData = require('form-data');
7+
import FormData from "form-data";
88

99
type Modify<T, R> = Omit<T, keyof R> & R;
1010
type FormDataOptions = Modify<

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
"name": "imagekit",
33
"version": "3.2.5",
44
"description": "Offical NodeJS SDK for ImageKit.io integration",
5-
"main": "dist/index.js",
6-
"types": "dist/index.d.ts",
5+
"main": "./dist/cjs/index.js",
6+
"types": "./dist/types/index.d.ts",
7+
"module": "./dist/esm/index.js",
78
"scripts": {
8-
"compile": "rm -rf dist* && tsc",
9+
"compile": "concurrently 'yarn:compile:cjs' 'yarn:compile:esm' 'yarn:compile:types'",
10+
"compile:cjs": "rm -rf dist/cjs & tsc -p tsconfig.cjs.json",
11+
"compile:esm": "rm -rf dist/esm & tsc -p tsconfig.esm.json",
12+
"compile:types": "rm -rf dist/types & tsc -p tsconfig.types.json",
913
"test": "export NODE_ENV=test; nyc ./node_modules/mocha/bin/mocha --exit -t 40000 tests/*.js;ex=$?;unset NODE_ENV; exit $ex;",
1014
"report-coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
1115
"prepack": "npm run compile"
@@ -37,6 +41,7 @@
3741
"babel-plugin-replace-ts-export-assignment": "^0.0.2",
3842
"chai": "^4.2.0",
3943
"codecov": "^3.8.0",
44+
"concurrently": "^7.2.2",
4045
"mocha": "^8.1.1",
4146
"nock": "^13.2.7",
4247
"nyc": "^15.1.0",

sample/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import ImageKit from "../index";
2+
3+
const CONFIG_OPTIONS = {
4+
publicKey: "your_public_api_key",
5+
privateKey: "your_private_api_key",
6+
urlEndpoint: "https://ik.imagekit.io/your_imagekit_id/",
7+
};
8+
9+
const imagekit = new ImageKit(CONFIG_OPTIONS);
10+
11+
// imagekit.createCustomMetadataField({
12+
// label: "test", name: "test", schema: {
13+
// type: "Text",
14+
// minLength: 1,
15+
// maxLength: 5
16+
// } })

tsconfig.cjs.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig",
3+
"compilerOptions": {
4+
"target": "ES2018",
5+
"module": "commonjs",
6+
"outDir": "dist/cjs",
7+
}
8+
}

tsconfig.esm.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./tsconfig",
3+
"compilerOptions": {
4+
"target": "es5",
5+
"module": "esnext",
6+
"moduleResolution": "node",
7+
"lib": ["dom", "es5", "es2015.promise", "es2015.collection", "es2015.iterable", "es2015.symbol.wellknown"],
8+
"outDir": "dist/esm",
9+
}
10+
}

tsconfig.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
// "allowJs": true, /* Allow javascript files to be compiled. */
1111
// "checkJs": true, /* Report errors in .js files. */
1212
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
13-
"declaration": true, /* Generates corresponding '.d.ts' file. */
13+
// "declaration": true, /* Generates corresponding '.d.ts' file. */
1414
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
1515
// "sourceMap": true, /* Generates corresponding '.map' file. */
1616
// "outFile": "./", /* Concatenate and emit output to single file. */
17-
"outDir": "./dist", /* Redirect output structure to the directory. */
17+
// "outDir": "./dist", /* Redirect output structure to the directory. */
1818
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
1919
// "composite": true, /* Enable project compilation */
2020
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
2121
// "removeComments": true, /* Do not emit comments to output. */
2222
// "noEmit": true, /* Do not emit outputs. */
23-
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
24-
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
23+
"importHelpers": true, /* Import emit helpers from 'tslib'. */
24+
"downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
2525
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
2626

2727
/* Strict Type-Checking Options */

0 commit comments

Comments
 (0)