diff --git a/package.json b/package.json index cf379a5..ca91f34 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "LICENSE", "README.MD" ], - "main": "./build/index.js", + "main": "./build/cjs/index.js", + "module": "./build/es/index.js", "keywords": [ "node", "http", diff --git a/scripts/build.sh b/scripts/build.sh index 6d7644e..5756a59 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,10 +1,14 @@ #!/bin/bash +rm -rf ./build +rm -rf ./build-tmp tsc --project tsconfig-build.json -ncc build ./build-tmp/index.js -o ./build +ncc build ./build-tmp/index.js -o ./build/cjs cat ./build-tmp/index.d.ts >> ./build-tmp/codes.d.ts # Because we are concatting .d.ts files, we need to remove all imports of codes.ts from index.ts sed -i.old '/^import/d' ./build-tmp/codes.d.ts # as well as exports that already exist within codes.ts sed -i.old '/^export { StatusCodes, ReasonPhrases, }/d;' ./build-tmp/codes.d.ts -mv ./build-tmp/codes.d.ts ./build/index.d.ts +mv ./build-tmp/codes.d.ts ./build/cjs/index.d.ts rm -rf ./build-tmp +tsc --project tsconfig-build.json +mv ./build-tmp ./build/es/ diff --git a/src/index.ts b/src/index.ts index 9397acf..344ba79 100644 --- a/src/index.ts +++ b/src/index.ts @@ -323,3 +323,61 @@ export const UNSUPPORTED_MEDIA_TYPE = 415; * * */ export const USE_PROXY = 305; + +export default { + ACCEPTED, + BAD_GATEWAY, + BAD_REQUEST, + CONFLICT, + CONTINUE, + CREATED, + EXPECTATION_FAILED, + FORBIDDEN, + GATEWAY_TIMEOUT, + GONE, + HTTP_VERSION_NOT_SUPPORTED, + IM_A_TEAPOT, + INSUFFICIENT_SPACE_ON_RESOURCE, + INSUFFICIENT_STORAGE, + INTERNAL_SERVER_ERROR, + LENGTH_REQUIRED, + LOCKED, + METHOD_FAILURE, + METHOD_NOT_ALLOWED, + MOVED_PERMANENTLY, + MOVED_TEMPORARILY, + MULTI_STATUS, + MULTIPLE_CHOICES, + NETWORK_AUTHENTICATION_REQUIRED, + NO_CONTENT, + NON_AUTHORITATIVE_INFORMATION, + NOT_ACCEPTABLE, + NOT_FOUND, + NOT_IMPLEMENTED, + NOT_MODIFIED, + OK, + PARTIAL_CONTENT, + PAYMENT_REQUIRED, + PERMANENT_REDIRECT, + PRECONDITION_FAILED, + PRECONDITION_REQUIRED, + PROCESSING, + PROXY_AUTHENTICATION_REQUIRED, + REQUEST_HEADER_FIELDS_TOO_LARGE, + REQUEST_TIMEOUT, + REQUEST_TOO_LONG, + REQUEST_URI_TOO_LONG, + REQUESTED_RANGE_NOT_SATISFIABLE, + RESET_CONTENT, + SEE_OTHER, + SERVICE_UNAVAILABLE, + SWITCHING_PROTOCOLS, + TEMPORARY_REDIRECT, + TOO_MANY_REQUESTS, + UNAUTHORIZED, + UNPROCESSABLE_ENTITY, + UNSUPPORTED_MEDIA_TYPE, + USE_PROXY, + getStatusText, + getStatusCode, +};