diff --git a/.circleci/doUnitTests.sh b/.circleci/doUnitTests.sh index e880670e1..a59e4a916 100755 --- a/.circleci/doUnitTests.sh +++ b/.circleci/doUnitTests.sh @@ -18,6 +18,15 @@ then fi coreFree=$(echo $coreFree | jq .core | tr -d '"') +cd .. +./test/testExports.sh +if [[ $? -ne 0 ]] +then + echo "export test failed... exiting!" + exit 1 +fi +cd .circleci + ./setupAndTestWithFreeCore.sh $coreFree $coreDriverVersion if [[ $? -ne 0 ]] then diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index da1c80b1c..314efe946 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -36,6 +36,7 @@ - [ ] If have added a new web framework, update the `add-ts-no-check.js` file to include that - [ ] If added a new recipe / api interface, then make sure that the implementation of it uses NON arrow functions only (like `someFunc: function () {..}`). - [ ] If added a new recipe, then make sure to expose it inside the recipe folder present in the root of this repo. We also need to expose its types. +- [ ] If added a new entry point, then make sure that it is importable by adding it to the `exports` in `package.json` ## Remaining TODOs for this PR diff --git a/.gitignore b/.gitignore index d13b6071e..a5e771d2c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,6 @@ releasePassword .tmp .idea /test_report +/temp_test_exports +/temp_* /.nyc_output \ No newline at end of file diff --git a/.npmignore b/.npmignore index 683ee5888..c87e7731c 100644 --- a/.npmignore +++ b/.npmignore @@ -18,4 +18,5 @@ examples/ add-ts-no-check.js docs/ .prettierignore -updateLibInExample \ No newline at end of file +updateLibInExample +testExports.sh \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index c5bd65564..76a1adc0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +## [19.0.0] - 2024-06-10 + +### Breaking changes + +- Defined the entry points of the library using the "exports" field in package.json to make ESM imports more comfortable. This can cause some issues for applications using directory imports from the `lib/build` directory. In those cases we recommend adding `index.js` to the import path. + ## [18.0.0] - 2024-05-23 ### Breaking change diff --git a/lib/build/version.d.ts b/lib/build/version.d.ts index a9d18f5e9..09065b34b 100644 --- a/lib/build/version.d.ts +++ b/lib/build/version.d.ts @@ -1,4 +1,4 @@ // @ts-nocheck -export declare const version = "18.0.0"; +export declare const version = "19.0.0"; export declare const cdiSupported: string[]; export declare const dashboardVersion = "0.11"; diff --git a/lib/build/version.js b/lib/build/version.js index 2c6882e5d..c922e6bb9 100644 --- a/lib/build/version.js +++ b/lib/build/version.js @@ -15,7 +15,7 @@ exports.dashboardVersion = exports.cdiSupported = exports.version = void 0; * License for the specific language governing permissions and limitations * under the License. */ -exports.version = "18.0.0"; +exports.version = "19.0.0"; exports.cdiSupported = ["5.0"]; // Note: The actual script import for dashboard uses v{DASHBOARD_VERSION} exports.dashboardVersion = "0.11"; diff --git a/lib/ts/version.ts b/lib/ts/version.ts index 92e4d0f9a..e2c1d5d52 100644 --- a/lib/ts/version.ts +++ b/lib/ts/version.ts @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -export const version = "18.0.0"; +export const version = "19.0.0"; export const cdiSupported = ["5.0"]; diff --git a/package-lock.json b/package-lock.json index 98af715e6..d4f1b4611 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "supertokens-node", - "version": "18.0.0", + "version": "19.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "supertokens-node", - "version": "18.0.0", + "version": "19.0.0", "license": "Apache-2.0", "dependencies": { "content-type": "^1.0.5", diff --git a/package.json b/package.json index 2d99ff715..8f5377af5 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { "name": "supertokens-node", - "version": "18.0.0", + "version": "19.0.0", "description": "NodeJS driver for SuperTokens core", "main": "index.js", "scripts": { "test": "TEST_MODE=testing npx mocha --node-option no-experimental-fetch -r test/fetch-polyfill.mjs --timeout 500000", + "test-exports": "./test/testExports.sh", "build-check": "cd lib && npx tsc -p tsconfig.json --noEmit && cd ../test/with-typescript && npm run build", "build": "cd lib && rm -rf build && npx tsc -p tsconfig.json && cd ../test/with-typescript && npm run build && cd ../.. && npm run post-build", "pretty": "npx pretty-quick .", @@ -27,6 +28,84 @@ "type": "git", "url": "git+https://github.com/supertokens/supertokens-node.git" }, + "exports": { + ".": { + "types": "./index.d.ts", + "default": "./index.js" + }, + "./index": { + "types": "./index.d.ts", + "default": "./index.js" + }, + "./index.js": { + "types": "./index.d.ts", + "default": "./index.js" + }, + "./framework/*": { + "types": "./framework/*/index.d.ts", + "default": "./framework/*/index.js" + }, + "./framework/*/index": { + "types": "./framework/*/index.d.ts", + "default": "./framework/*/index.js" + }, + "./framework/*/index.js": { + "types": "./framework/*/index.d.ts", + "default": "./framework/*/index.js" + }, + "./nextjs": { + "types": "./nextjs/index.d.ts", + "default": "./nextjs/index.js" + }, + "./nextjs/index": { + "types": "./nextjs/index.d.ts", + "default": "./nextjs/index.js" + }, + "./nextjs/index.js": { + "types": "./nextjs/index.d.ts", + "default": "./nextjs/index.js" + }, + "./types": { + "types": "./types/index.d.ts", + "default": "./types/index.js" + }, + "./types/index": { + "types": "./types/index.d.ts", + "default": "./types/index.js" + }, + "./types/index.js": { + "types": "./types/index.d.ts", + "default": "./types/index.js" + }, + "./lib/*": { + "types": "./lib/*.d.ts", + "default": "./lib/*.js" + }, + "./lib/*.js": { + "types": "./lib/*.d.ts", + "default": "./lib/*.js" + }, + "./recipe/*": { + "types": "./recipe/*/index.d.ts", + "default": "./recipe/*/index.js" + }, + "./recipe/*/index": { + "types": "./recipe/*/index.d.ts", + "default": "./recipe/*/index.js" + }, + "./recipe/*/index.js": { + "types": "./recipe/*/index.d.ts", + "default": "./recipe/*/index.js" + }, + "./recipe/session/claims": { + "types": "./recipe/session/claims.d.ts", + "default": "./recipe/session/claims.js" + }, + "./recipe/session/claims.js": { + "types": "./recipe/session/claims.d.ts", + "default": "./recipe/session/claims.js" + } + }, "author": "rishabhpoddar", "license": "Apache-2.0", "bugs": { diff --git a/recipe/thirdparty/emaildelivery/index.d.ts b/recipe/thirdparty/emaildelivery/index.d.ts deleted file mode 100644 index 30bed2519..000000000 --- a/recipe/thirdparty/emaildelivery/index.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -export * from "../../../lib/build/recipe/thirdparty/emaildelivery/services"; -/** - * 'export *' does not re-export a default. - * import NextJS from "supertokens-node/nextjs"; - * the above import statement won't be possible unless either - * - user add "esModuleInterop": true in their tsconfig.json file - * - we do the following change: - */ -import * as _default from "../../../lib/build/recipe/thirdparty/emaildelivery/services"; -export default _default; diff --git a/recipe/thirdparty/emaildelivery/index.js b/recipe/thirdparty/emaildelivery/index.js deleted file mode 100644 index e0c46c07f..000000000 --- a/recipe/thirdparty/emaildelivery/index.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict"; -function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; -} -exports.__esModule = true; -__export(require("../../../lib/build/recipe/thirdparty/emaildelivery/services")); diff --git a/test/testExports.sh b/test/testExports.sh new file mode 100755 index 000000000..67196888c --- /dev/null +++ b/test/testExports.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +TEST_PROJECT_DIR=./temp_test_exports + +mkdir -p $TEST_PROJECT_DIR + +npm pack || exit $? + +mv supertokens-node-*.tgz $TEST_PROJECT_DIR +cd $TEST_PROJECT_DIR + +npm init -y || exit $? + +rm -f index.mjs +touch index.mjs +# We test that all JS files we publish are importable without an extension +tar -t -f ./supertokens-node* | grep \\.js$ | sed 's/^package\/\(.*\)\.js$/import \"supertokens-node\/\1\";/' >> index.mjs +# We test that all JS files we publish are importable with the JS extension +tar -t -f ./supertokens-node* | grep \\.js$ | sed 's/^package\/\(.*\)\.js$/import \"supertokens-node\/\1\.js";/' >> index.mjs +# We test that all folders that have an index.js (outside of /lib/build) are importable as folders. +tar -t -f --exclude package/lib/build ./supertokens-node* | grep package/.*/index\\.js$ | sed 's/^package\/\(.*\)\/index\.js$/import \"supertokens-node\/\1\";/' >> index.mjs +# We also test that the sdk itself is importable +echo 'import "supertokens-node";' >> index.mjs + +mkdir -p node_modules/supertokens-node + +tar -xvvf supertokens-node-*.tgz --strip-components=1 -C node_modules/supertokens-node package + +node index.mjs +EXIT_CODE=$? + +cd .. +rm -rf $TEST_PROJECT_DIR +exit $EXIT_CODE +