Skip to content

Commit 5a4127f

Browse files
committed
chore(esm): Improved Support for ES Modules
1 parent 2fb7af9 commit 5a4127f

File tree

7 files changed

+128
-10
lines changed

7 files changed

+128
-10
lines changed

.npmignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@ babel-register.js
99
.vscode
1010
.DS_Store
1111
.mocharc.json
12-
.nycrc
12+
.nycrc
13+
libs
14+
utils
15+
tsconfig*
16+
fixup.sh
17+
index.ts

fixup.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cat >dist/cjs/package.json <<!EOF
2+
{
3+
"type": "commonjs"
4+
}
5+
!EOF
6+
7+
cat >dist/esm/package.json <<!EOF
8+
{
9+
"type": "module"
10+
}
11+
!EOF

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
"version": "4.0.0",
44
"description": "Offical NodeJS SDK for ImageKit.io integration",
55
"main": "./dist/cjs/index.js",
6-
"types": "./dist/types/index.d.ts",
76
"module": "./dist/esm/index.js",
7+
"exports": {
8+
"import": "./dist/esm/index.js",
9+
"require": "./dist/cjs/index.js"
10+
},
811
"scripts": {
9-
"compile": "concurrently 'yarn:compile:cjs' 'yarn:compile:esm' 'yarn:compile:types'",
12+
"compile": "concurrently 'yarn:compile:cjs' 'yarn:compile:esm' 'yarn:compile:types' && yarn compile:fixup",
13+
"compile:fixup": "./fixup.sh",
1014
"compile:cjs": "rm -rf dist/cjs & tsc -p tsconfig.cjs.json",
1115
"compile:esm": "rm -rf dist/esm & tsc -p tsconfig.esm.json",
1216
"compile:types": "rm -rf dist/types & tsc -p tsconfig.types.json",
@@ -35,14 +39,19 @@
3539
"@babel/preset-env": "^7.14.5",
3640
"@babel/preset-typescript": "^7.14.5",
3741
"@babel/register": "^7.14.5",
42+
"@types/chai": "^4.3.1",
43+
"@types/concurrently": "^7.0.0",
3844
"@types/lodash": "^4.14.170",
45+
"@types/mocha": "^9.1.1",
3946
"@types/node": "^15.12.2",
4047
"@types/request": "^2.48.5",
48+
"@types/sinon": "^10.0.12",
4149
"@types/uuid": "^8.3.4",
4250
"babel-plugin-replace-ts-export-assignment": "^0.0.2",
4351
"chai": "^4.2.0",
4452
"codecov": "^3.8.0",
4553
"concurrently": "6.5.1",
54+
"install-types": "^2.0.1",
4655
"mocha": "^8.1.1",
4756
"nock": "^13.2.7",
4857
"nyc": "^15.1.0",

tsconfig.cjs.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
"target": "ES2018",
55
"module": "commonjs",
66
"outDir": "dist/cjs",
7-
}
7+
"declaration": true,
8+
},
9+
"include": ["index.ts", "libs/**/*", "utils/*", "test/*", "types/*"],
10+
"exclude": ["node_modules", "dist"],
811
}

tsconfig.esm.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"moduleResolution": "node",
77
"lib": ["dom", "es5", "es2015.promise", "es2015.collection", "es2015.iterable", "es2015.symbol.wellknown"],
88
"outDir": "dist/esm",
9+
"declaration": true,
910
}
1011
}

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
4848
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
4949
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
50-
// "typeRoots": [], /* List of folders to include type definitions from. */
50+
"typeRoots": ["./types"], /* List of folders to include type definitions from. */
5151
// "types": [], /* Type declaration files to be included in compilation. */
5252
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
5353
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
@@ -69,6 +69,6 @@
6969
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
7070
"resolveJsonModule": true
7171
},
72-
"include": ["index.ts", "libs/**/*", "utils/*", "test/*"],
72+
"include": ["index.ts", "libs/**/*", "utils/*", "test/*", "types/*"],
7373
"exclude": ["node_modules", "dist"]
7474
}

yarn.lock

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,11 +1059,28 @@
10591059
resolved "https://registry.yarnpkg.com/@types/caseless/-/caseless-0.12.2.tgz#f65d3d6389e01eeb458bd54dc8f52b95a9463bc8"
10601060
integrity sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==
10611061

1062+
"@types/chai@^4.3.1":
1063+
version "4.3.1"
1064+
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.1.tgz#e2c6e73e0bdeb2521d00756d099218e9f5d90a04"
1065+
integrity sha512-/zPMqDkzSZ8t3VtxOa4KPq7uzzW978M9Tvh+j7GHKuo6k6GTLxPJ4J5gE5cjfJ26pnXst0N5Hax8Sr0T2Mi9zQ==
1066+
1067+
"@types/concurrently@^7.0.0":
1068+
version "7.0.0"
1069+
resolved "https://registry.yarnpkg.com/@types/concurrently/-/concurrently-7.0.0.tgz#745fea75f46dd1f28174b8f921afadde3d5bcddf"
1070+
integrity sha512-pUOv0XBVexkfVOLWwzh8CMK7b+dnXGvq+/sJKfcws6b0vuMqNw8UeZUiaO9mWxfyS0eYGQyxg+J9EpVRxUCunA==
1071+
dependencies:
1072+
concurrently "*"
1073+
10621074
"@types/lodash@^4.14.170":
10631075
version "4.14.182"
10641076
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.182.tgz#05301a4d5e62963227eaafe0ce04dd77c54ea5c2"
10651077
integrity sha512-/THyiqyQAP9AfARo4pF+aCGcyiQ94tX/Is2I7HofNRqoYLgN1PBoOWu2/zTA5zMxzP5EFutMtWtGAFRKUe961Q==
10661078

1079+
"@types/mocha@^9.1.1":
1080+
version "9.1.1"
1081+
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-9.1.1.tgz#e7c4f1001eefa4b8afbd1eee27a237fee3bf29c4"
1082+
integrity sha512-Z61JK7DKDtdKTWwLeElSEBcWGRLY8g95ic5FoQqI9CMx0ns/Ghep3B4DfcEimiKMvtamNVULVNKEsiwV3aQmXw==
1083+
10671084
"@types/node@*":
10681085
version "18.0.0"
10691086
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.0.0.tgz#67c7b724e1bcdd7a8821ce0d5ee184d3b4dd525a"
@@ -1084,6 +1101,18 @@
10841101
"@types/tough-cookie" "*"
10851102
form-data "^2.5.0"
10861103

1104+
"@types/sinon@^10.0.12":
1105+
version "10.0.12"
1106+
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-10.0.12.tgz#fb7009ea71f313a9da4644ba73b94e44d6b84f7f"
1107+
integrity sha512-uWf4QJ4oky/GckJ1MYQxU52cgVDcXwBhDkpvLbi4EKoLPqLE4MOH6T/ttM33l3hi0oZ882G6oIzWv/oupRYSxQ==
1108+
dependencies:
1109+
"@types/sinonjs__fake-timers" "*"
1110+
1111+
"@types/sinonjs__fake-timers@*":
1112+
version "8.1.2"
1113+
resolved "https://registry.yarnpkg.com/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.2.tgz#bf2e02a3dbd4aecaf95942ecd99b7402e03fad5e"
1114+
integrity sha512-9GcLXF0/v3t80caGs5p2rRfkB+a8VBGLJZVih6CNFkx8IZ994wiKKLSRs9nuFwk1HevWs/1mnUmkApGrSGsShA==
1115+
10871116
"@types/tough-cookie@*":
10881117
version "4.0.2"
10891118
resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.2.tgz#6286b4c7228d58ab7866d19716f3696e03a09397"
@@ -1336,7 +1365,7 @@ chai@^4.2.0:
13361365
pathval "^1.1.1"
13371366
type-detect "^4.0.5"
13381367

1339-
chalk@^2.0.0:
1368+
chalk@^2.0.0, chalk@^2.4.2:
13401369
version "2.4.2"
13411370
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
13421371
integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==
@@ -1477,6 +1506,21 @@ [email protected]:
14771506
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
14781507
integrity sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==
14791508

1509+
concurrently@*:
1510+
version "7.2.2"
1511+
resolved "https://registry.yarnpkg.com/concurrently/-/concurrently-7.2.2.tgz#4ad4a4dfd3945f668d727379de2a29502e6a531c"
1512+
integrity sha512-DcQkI0ruil5BA/g7Xy3EWySGrFJovF5RYAYxwGvv9Jf9q9B1v3jPFP2tl6axExNf1qgF30kjoNYrangZ0ey4Aw==
1513+
dependencies:
1514+
chalk "^4.1.0"
1515+
date-fns "^2.16.1"
1516+
lodash "^4.17.21"
1517+
rxjs "^7.0.0"
1518+
shell-quote "^1.7.3"
1519+
spawn-command "^0.0.2-1"
1520+
supports-color "^8.1.0"
1521+
tree-kill "^1.2.2"
1522+
yargs "^17.3.1"
1523+
14801524
14811525
version "6.5.1"
14821526
resolved "https://registry.yarnpkg.com/concurrently/-/concurrently-6.5.1.tgz#4518c67f7ac680cf5c34d5adf399a2a2047edc8c"
@@ -2001,6 +2045,16 @@ inherits@2:
20012045
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
20022046
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
20032047

2048+
install-types@^2.0.1:
2049+
version "2.0.1"
2050+
resolved "https://registry.yarnpkg.com/install-types/-/install-types-2.0.1.tgz#00480ad57befdc346d6414318ac4b73ff78ed814"
2051+
integrity sha512-B8QC2gbT3LyHlPaiA1LIO/gmXbFL61vqI+8KxAPhX3ytmaqfEq+kk5PvfkXcbamoG9MxtCco1ltuVWDA+nKNpw==
2052+
dependencies:
2053+
chalk "^2.4.2"
2054+
lodash "^4.17.15"
2055+
types-directory "^0.34.0"
2056+
yargs "^15.1.0"
2057+
20042058
internal-slot@^1.0.3:
20052059
version "1.0.3"
20062060
resolved "https://registry.yarnpkg.com/internal-slot/-/internal-slot-1.0.3.tgz#7347e307deeea2faac2ac6205d4bc7d34967f59c"
@@ -2817,6 +2871,13 @@ rxjs@^6.6.3:
28172871
dependencies:
28182872
tslib "^1.9.0"
28192873

2874+
rxjs@^7.0.0:
2875+
version "7.5.5"
2876+
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.5.5.tgz#2ebad89af0f560f460ad5cc4213219e1f7dd4e9f"
2877+
integrity sha512-sy+H0pQofO95VDmFLzyaw9xNJU4KTRSwQIGM6+iG3SypAtCiLDzpeG8sJrNCWn2Up9km+KhkvTdbkrdy+yzZdw==
2878+
dependencies:
2879+
tslib "^2.1.0"
2880+
28202881
safe-buffer@^5.1.0:
28212882
version "5.2.1"
28222883
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
@@ -2873,6 +2934,11 @@ shebang-regex@^3.0.0:
28732934
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
28742935
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
28752936

2937+
shell-quote@^1.7.3:
2938+
version "1.7.3"
2939+
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.7.3.tgz#aa40edac170445b9a431e17bb62c0b881b9c4123"
2940+
integrity sha512-Vpfqwm4EnqGdlsBFNmHhxhElJYrdfcxPThu+ryKS5J8L/fhAwLazFZtq+S+TWZ9ANj2piSQLGj6NQg+lKPmxrw==
2941+
28762942
side-channel@^1.0.4:
28772943
version "1.0.4"
28782944
resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf"
@@ -2954,7 +3020,7 @@ stream-events@^1.0.5:
29543020
is-fullwidth-code-point "^2.0.0"
29553021
strip-ansi "^4.0.0"
29563022

2957-
string-width@^4.1.0, string-width@^4.2.0:
3023+
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
29583024
version "4.2.3"
29593025
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
29603026
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -3083,7 +3149,7 @@ tslib@^1.9.0:
30833149
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
30843150
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
30853151

3086-
tslib@^2.4.0:
3152+
tslib@^2.1.0, tslib@^2.4.0:
30873153
version "2.4.0"
30883154
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3"
30893155
integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==
@@ -3105,6 +3171,11 @@ typedarray-to-buffer@^3.1.5:
31053171
dependencies:
31063172
is-typedarray "^1.0.0"
31073173

3174+
types-directory@^0.34.0:
3175+
version "0.34.0"
3176+
resolved "https://registry.yarnpkg.com/types-directory/-/types-directory-0.34.0.tgz#f9bfc20366972aba1ec278aa42ca1d39b4e12c54"
3177+
integrity sha512-mrR0/TgkLZqRUtKwgwUTTg+VCdNfPLlwN1zN07ZKGu9AU8y0zzIF3xMBPYIw4nrJCSSUKCMe9KX4nIL2n8GnaA==
3178+
31083179
typescript@^4.3.2:
31093180
version "4.7.4"
31103181
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235"
@@ -3279,6 +3350,11 @@ yargs-parser@^20.2.2:
32793350
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee"
32803351
integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==
32813352

3353+
yargs-parser@^21.0.0:
3354+
version "21.0.1"
3355+
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.0.1.tgz#0267f286c877a4f0f728fceb6f8a3e4cb95c6e35"
3356+
integrity sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg==
3357+
32823358
32833359
version "2.0.0"
32843360
resolved "https://registry.yarnpkg.com/yargs-unparser/-/yargs-unparser-2.0.0.tgz#f131f9226911ae5d9ad38c432fe809366c2325eb"
@@ -3302,7 +3378,7 @@ [email protected], yargs@^16.2.0:
33023378
y18n "^5.0.5"
33033379
yargs-parser "^20.2.2"
33043380

3305-
yargs@^15.0.2:
3381+
yargs@^15.0.2, yargs@^15.1.0:
33063382
version "15.4.1"
33073383
resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.4.1.tgz#0d87a16de01aee9d8bec2bfbf74f67851730f4f8"
33083384
integrity sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==
@@ -3319,6 +3395,19 @@ yargs@^15.0.2:
33193395
y18n "^4.0.0"
33203396
yargs-parser "^18.1.2"
33213397

3398+
yargs@^17.3.1:
3399+
version "17.5.1"
3400+
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.5.1.tgz#e109900cab6fcb7fd44b1d8249166feb0b36e58e"
3401+
integrity sha512-t6YAJcxDkNX7NFYiVtKvWUz8l+PaKTLiL63mJYWR2GnHq2gjEWISzsLp9wg3aY36dY1j+gfIEL3pIF+XlJJfbA==
3402+
dependencies:
3403+
cliui "^7.0.2"
3404+
escalade "^3.1.1"
3405+
get-caller-file "^2.0.5"
3406+
require-directory "^2.1.1"
3407+
string-width "^4.2.3"
3408+
y18n "^5.0.5"
3409+
yargs-parser "^21.0.0"
3410+
33223411
yocto-queue@^0.1.0:
33233412
version "0.1.0"
33243413
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"

0 commit comments

Comments
 (0)