diff --git a/README.md b/README.md index 6dc04fb..e89e1c8 100644 --- a/README.md +++ b/README.md @@ -24,20 +24,17 @@ npm i svelte-kit-cookie-session yarn add svelte-kit-cookie-session ``` - - > :warning: **Because of some vite issues [#14](https://github.com/pixelmund/svelte-kit-cookie-session/issues/14) [#15](https://github.com/pixelmund/svelte-kit-cookie-session/issues/15)**: you should add the following to your `svelte.config`! - ```js const config = { - kit: { - vite: { - optimizeDeps: { - exclude: ['svelte-kit-cookie-session'], - }, + kit: { + vite: { + optimizeDeps: { + exclude: ["svelte-kit-cookie-session"], }, }, + }, }; ``` @@ -94,8 +91,7 @@ Then you can use multiple secrets: ```js export const handle = handleSession({ - secret: - "SOME_COMPLEX_SECRET_AT_LEAST_32_CHARS", + secret: "SOME_COMPLEX_SECRET_AT_LEAST_32_CHARS", }); ``` @@ -126,6 +122,8 @@ Notes: `If the session already exists, the data get's updated but the expiration time stays the same` +`The only way to set the session is setting the locals.session.data to an object` + > src/routes/login.ts ```js @@ -139,6 +137,28 @@ export async function post({ locals, body }) { } ``` +### Accessing The Session + +`After initializing the session, your locals will be filled with a session JS Proxy, this Proxy automatically sets the cookie if you set the locals.session.data to something and receive the current data via locals.session.data only. To see this in action add a console.log(locals.session) it will be empty. Only if you add an console.log(locals.session.data) and access the data it will output the current data. So if you wonder why is my session not filled, this is why` + +> src/routes/api/me.ts + +```js +/** @type {import('@sveltejs/kit').RequestHandler} */ +export async function get({ locals, body }) { + // console.log(locals.session) will be empty + + // Access your data via locals.session.data -> this should always be an object. + const currentUser = locals.session.data?.user; + + return { + body: { + me: currentUser, + }, + }; +} +``` + ### Destroying the Session > src/routes/logout.ts @@ -180,3 +200,29 @@ handleSession({ rolling: true, }); ``` + +### Express/Connect Integration + +This library can integrate with express, polka or any other connect compatible middleware layer. + +```ts +import express from "express"; +import { sessionMiddleware } from "svelte-kit-cookie-session"; + +const app = express(); + +app.use( + sessionMiddleware({ secret: "A_VERY_SECRET_SECRET_AT_LEAST_32_CHARS_LONG" }) +); + +app.get("/", (req, res) => { + const sessionData = req.session.data; + const views = sessionData.views ?? 0; + req.session.data = { views: views + 1 }; + return res.json({ views: req.session.data.views }); +}); + +app.listen(4004, () => { + console.log("Listening on http://localhost:4004"); +}); +``` diff --git a/example/package.json b/example/package.json index 799b169..db2ccef 100644 --- a/example/package.json +++ b/example/package.json @@ -19,6 +19,6 @@ }, "type": "module", "dependencies": { - "svelte-kit-cookie-session": "^1.3.2" + "svelte-kit-cookie-session": "^1.4.0" } } \ No newline at end of file diff --git a/example/pnpm-lock.yaml b/example/pnpm-lock.yaml index 038c7dd..e2b587d 100644 --- a/example/pnpm-lock.yaml +++ b/example/pnpm-lock.yaml @@ -5,13 +5,13 @@ specifiers: '@sveltejs/kit': next svelte: ^3.34.0 svelte-check: ^2.0.0 - svelte-kit-cookie-session: ^1.3.2-0.2 + svelte-kit-cookie-session: ^1.4.0-next.1 svelte-preprocess: ^4.0.0 tslib: ^2.0.0 typescript: ^4.0.0 dependencies: - svelte-kit-cookie-session: 1.3.2-0.2 + svelte-kit-cookie-session: 1.4.0-next.1 devDependencies: '@sveltejs/adapter-node': 1.0.0-next.45 @@ -504,8 +504,8 @@ packages: svelte: 3.38.2 dev: true - /svelte-kit-cookie-session/1.3.2-0.2: - resolution: {integrity: sha512-WW0e3arF4KBhNIcFEp4n60mwBcg96+k7FNA14Vlw+wwQPS4yJoTuOY/Jf6cOybB2/T6i3AjAqxI+5IjuIBMKuw==} + /svelte-kit-cookie-session/1.4.0-next.1: + resolution: {integrity: sha512-RE7ONSfnNGN3xndKgTJ3POpinS85yk0AEWrNw3BKcfjYWgs0eHCdI5kMsiEoCa1ycQeTTjUAZWLyV7oQaMv9Wg==} dev: false /svelte-preprocess/4.7.3_svelte@3.38.2+typescript@4.3.2: diff --git a/loadr.mjs b/loadr.mjs index 1e9fb1f..11cdad6 100644 --- a/loadr.mjs +++ b/loadr.mjs @@ -1 +1 @@ -export const loaders = ['ts-node/esm']; \ No newline at end of file +export const loaders = ['tsm']; \ No newline at end of file diff --git a/package.json b/package.json index 61cef3d..90d65dd 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,24 @@ { "name": "svelte-kit-cookie-session", - "version": "1.3.3", + "version": "1.4.0", "description": "⚒️ Encrypted 'stateless' cookie sessions for SvelteKit", "repository": { "type": "git", "url": "https://github.com/pixelmund/svelte-kit-cookie-session.git" }, "type": "module", - "module": "dist/index.js", - "types": "./dist/index.d.ts", + "main": "dist/cjs/index.js", + "module": "dist/esm/index.js", + "types": "./dist/esm/index.d.ts", "exports": { ".": { - "import": "./dist/index.js" + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" }, "./package.json": "./package.json" }, "scripts": { - "build": "rimraf ./dist && tsc", + "build": "rimraf ./dist && tsc -p tsconfig-cjs.json && tsc -p tsconfig.json && node ./postbuild.mjs", "dev": "tsc -w", "test": "loadr -- uvu tests", "prepublishOnly": "npm run build && npm run test" @@ -38,7 +40,7 @@ "loadr": "^0.1.1", "rimraf": "^3.0.2", "svelte": "^3.35.0", - "ts-node": "^9.1.1", + "tsm": "^2.2.1", "typescript": "^4.2.3", "uvu": "^0.6.0-next.1" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 30f8c25..f560349 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,7 +7,7 @@ specifiers: loadr: ^0.1.1 rimraf: ^3.0.2 svelte: ^3.35.0 - ts-node: ^9.1.1 + tsm: ^2.2.1 typescript: ^4.2.3 uvu: ^0.6.0-next.1 @@ -18,7 +18,7 @@ devDependencies: loadr: 0.1.1 rimraf: 3.0.2 svelte: 3.38.3 - ts-node: 9.1.1_typescript@4.3.5 + tsm: 2.2.1 typescript: 4.3.5 uvu: 0.6.0-next.1 @@ -75,10 +75,6 @@ packages: resolution: {integrity: sha512-bjqH2cX/O33jXT/UmReo2pM7DIJREPMnarixbQ57DOOzzFaI6D2+IcwaJQaJpv0M1E9TIhPCYVxrkcityLjlqA==} dev: true - /arg/4.1.3: - resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==} - dev: true - /balanced-match/1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} dev: true @@ -90,10 +86,6 @@ packages: concat-map: 0.0.1 dev: true - /buffer-from/1.1.1: - resolution: {integrity: sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==} - dev: true - /cheap-watch/1.0.3: resolution: {integrity: sha512-xC5CruMhLzjPwJ5ecUxGu1uGmwJQykUhqd2QrCrYbwvsFYdRyviu6jG9+pccwDXJR/OpmOTOJ9yLFunVgQu9wg==} engines: {node: '>=8'} @@ -107,10 +99,6 @@ packages: resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=} dev: true - /create-require/1.1.1: - resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} - dev: true - /debug/4.3.2: resolution: {integrity: sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==} engines: {node: '>=6.0'} @@ -128,22 +116,177 @@ packages: engines: {node: '>=6'} dev: true - /diff/4.0.2: - resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==} - engines: {node: '>=0.3.1'} - dev: true - /diff/5.0.0: resolution: {integrity: sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==} engines: {node: '>=0.3.1'} dev: true + /esbuild-android-arm64/0.14.1: + resolution: {integrity: sha512-elQd3hTg93nU2GQ5PPCDAFe5+utxZX96RG8RixqIPxf8pzmyIzcpKG76L/9FabPf3LT1z+nLF1sajCU8eVRDyg==} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: true + optional: true + + /esbuild-darwin-64/0.14.1: + resolution: {integrity: sha512-PR3HZgbPRwsQbbOR1fJrfkt/Cs0JDyI3yzOKg2PPWk0H1AseZDBqPUY9b/0+BIjFwA5Jz/aAiq832hppsuJtNw==} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /esbuild-darwin-arm64/0.14.1: + resolution: {integrity: sha512-/fiSSOkOEa3co6yYtwgXouz8jZrG0qnXPEKiktFf2BQE8NON3ARTw43ZegaH+xMRFNgYBJEOOZIdzI3sIFEAxw==} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /esbuild-freebsd-64/0.14.1: + resolution: {integrity: sha512-ZJV+nfa8E8PdXnRc05PO3YMfgSj7Ko+kdHyGDE6OaNo1cO8ZyfacqLaWkY35shDDaeacklhD8ZR4qq5nbJKX1A==} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + + /esbuild-freebsd-arm64/0.14.1: + resolution: {integrity: sha512-6N9zTD+SecJr2g9Ohl9C10WIk5FpQ+52bNamRy0sJoHwP31G5ObzKzq8jAtg1Jeggpu6P8auz3P/UL+3YioSwQ==} + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-32/0.14.1: + resolution: {integrity: sha512-RtPgE6e7WefbAxRjVryisKFJ0nUwR2DMjwmYW/a1a0F1+Ge6FR+RqvgiY0DrM9TtxSUU0eryDXNF4n3UfxX3mg==} + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-64/0.14.1: + resolution: {integrity: sha512-JpxM0ar6Z+2v3vfFrxP7bFb8Wzb6gcGL9MxRqAJplDfGnee8HbfPge6svaazXeX9XJceeEqwxwWGB0qyCcxo7A==} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-arm/0.14.1: + resolution: {integrity: sha512-eBRHexCijAYWzcvQLGHxyxIlYOkYhXvcb/O7HvzJfCAVWCnTx9TxxYJ3UppBC6dDFbAq4HwKhskvmesQdKMeBg==} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-arm64/0.14.1: + resolution: {integrity: sha512-cFbeZf171bIf+PPLlQDBzagK85lCCxxVdMV1IVUA96Y3kvEgqcy2n9mha+QE1M/T+lIOPDsmLRgH1XqMFwLTSg==} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-mips64le/0.14.1: + resolution: {integrity: sha512-UGb+sqHkL7wOQFLH0RoFhcRAlJNqbqs6GtJd1It5jJ2juOGqAkCv8V12aGDX9oRB6a+Om7cdHcH+6AMZ+qlaww==} + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-ppc64le/0.14.1: + resolution: {integrity: sha512-LIHGkGdy9wYlmkkoVHm6feWhkoi4VBXDiEVyNjXEhlzsBcP/CaRy+B8IJulzaU1ALLiGcsCQ2MC5UbFn/iTvmA==} + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-netbsd-64/0.14.1: + resolution: {integrity: sha512-TWc1QIgtPwaK5nC1GT2ASTuy/CJhNKHN4h5PJRP1186VfI+k2uvXakS7bqO/M26F6jAMy8jDeCtilacqpwsvfA==} + cpu: [x64] + os: [netbsd] + requiresBuild: true + dev: true + optional: true + + /esbuild-openbsd-64/0.14.1: + resolution: {integrity: sha512-Z9/Zb77K+pK9s7mAsvwS56K8tCbLvNZ9UI4QVJSYqDgOmmDJOBT4owWnCqZ5cJI+2y4/F9KwCpFFTNUdPglPKA==} + cpu: [x64] + os: [openbsd] + requiresBuild: true + dev: true + optional: true + + /esbuild-sunos-64/0.14.1: + resolution: {integrity: sha512-c4sF8146kNW8529wfkB6vO0ZqPgokyS2hORqKa4p/QKZdp+xrF2NPmvX5aN+Zt14oe6wVZuhYo6LGv7V4Gg04g==} + cpu: [x64] + os: [sunos] + requiresBuild: true + dev: true + optional: true + + /esbuild-windows-32/0.14.1: + resolution: {integrity: sha512-XP8yElaJtLGGjH7D72t5IWtP0jmc1Jqm4IjQARB17l0LTJO/n+N2X64rDWePJv6qimYxa5p2vTjkZc5v+YZTSQ==} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /esbuild-windows-64/0.14.1: + resolution: {integrity: sha512-fe+ShdyfiuGcCEdVKW//6MaM4MwikiWBWSBn8mebNAbjRqicH0injDOFVI7aUovAfrEt7+FGkf402s//hi0BVg==} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /esbuild-windows-arm64/0.14.1: + resolution: {integrity: sha512-wBVakhcIzQ3NZ33DFM6TjIObXPHaXOsqzvPwefXHvwBSC/N/e/g6fBeM7N/Moj3AmxLjKaB+vePvTGdxk6RPCg==} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /esbuild/0.12.15: resolution: {integrity: sha512-72V4JNd2+48eOVCXx49xoSWHgC3/cCy96e7mbXKY+WOWghN00cCmlGnwVLRhRHorvv0dgCyuMYBZlM2xDM5OQw==} hasBin: true requiresBuild: true dev: true + /esbuild/0.14.1: + resolution: {integrity: sha512-J/LhUwELcmz0+CJfiaKzu7Rnj9ffWFLvMx+dKvdOfg+fQmoP6q9glla26LCm9BxpnPUjXChHeubLiMlKab/PYg==} + hasBin: true + requiresBuild: true + optionalDependencies: + esbuild-android-arm64: 0.14.1 + esbuild-darwin-64: 0.14.1 + esbuild-darwin-arm64: 0.14.1 + esbuild-freebsd-64: 0.14.1 + esbuild-freebsd-arm64: 0.14.1 + esbuild-linux-32: 0.14.1 + esbuild-linux-64: 0.14.1 + esbuild-linux-arm: 0.14.1 + esbuild-linux-arm64: 0.14.1 + esbuild-linux-mips64le: 0.14.1 + esbuild-linux-ppc64le: 0.14.1 + esbuild-netbsd-64: 0.14.1 + esbuild-openbsd-64: 0.14.1 + esbuild-sunos-64: 0.14.1 + esbuild-windows-32: 0.14.1 + esbuild-windows-64: 0.14.1 + esbuild-windows-arm64: 0.14.1 + dev: true + /estree-walker/2.0.2: resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} dev: true @@ -215,10 +358,6 @@ packages: sourcemap-codec: 1.4.8 dev: true - /make-error/1.3.6: - resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} - dev: true - /minimatch/3.0.4: resolution: {integrity: sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==} dependencies: @@ -307,18 +446,6 @@ packages: engines: {node: '>=0.10.0'} dev: true - /source-map-support/0.5.19: - resolution: {integrity: sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==} - dependencies: - buffer-from: 1.1.1 - source-map: 0.6.1 - dev: true - - /source-map/0.6.1: - resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} - engines: {node: '>=0.10.0'} - dev: true - /sourcemap-codec/1.4.8: resolution: {integrity: sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==} dev: true @@ -341,20 +468,12 @@ packages: engines: {node: '>=6'} dev: true - /ts-node/9.1.1_typescript@4.3.5: - resolution: {integrity: sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==} - engines: {node: '>=10.0.0'} + /tsm/2.2.1: + resolution: {integrity: sha512-qvJB0baPnxQJolZru11mRgGTdNlx17WqgJnle7eht3Vhb+VUR4/zFA5hFl6NqRe7m8BD9w/6yu0B2XciRrdoJA==} + engines: {node: '>=12'} hasBin: true - peerDependencies: - typescript: '>=2.7' dependencies: - arg: 4.1.3 - create-require: 1.1.1 - diff: 4.0.2 - make-error: 1.3.6 - source-map-support: 0.5.19 - typescript: 4.3.5 - yn: 3.1.1 + esbuild: 0.14.1 dev: true /typescript/4.3.5: @@ -391,8 +510,3 @@ packages: /wrappy/1.0.2: resolution: {integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=} dev: true - - /yn/3.1.1: - resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==} - engines: {node: '>=6'} - dev: true diff --git a/postbuild.mjs b/postbuild.mjs new file mode 100644 index 0000000..f7b7119 --- /dev/null +++ b/postbuild.mjs @@ -0,0 +1,21 @@ +import fs from "fs/promises"; +import path from "path"; + +async function fixUp() { + + const writePackageJson = async (module) => { + let type = 'module'; + + if (module === 'cjs') { + type = 'commonjs'; + } + + await fs.writeFile(path.resolve('dist', module, 'package.json'), JSON.stringify({ type }, null, 2)); + } + + await writePackageJson('esm'); + await writePackageJson('cjs'); + +} + +fixUp() \ No newline at end of file diff --git a/src/connect.ts b/src/connect.ts new file mode 100644 index 0000000..3d3f404 --- /dev/null +++ b/src/connect.ts @@ -0,0 +1,74 @@ +import { initializeSession } from "./initialize.js"; +import type { SessionOptions, Session } from "./initialize"; +import type { IncomingMessage, ServerResponse } from "http"; + +declare global { + namespace Express { + interface Request { + session: Session; + } + } + namespace Polka { + interface Request { + session: Session; + } + } +} + +/** + * This interface allows you to declare additional properties on your session object using [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html). + * + * @example + * declare module 'svelte-kit-cookie-session' { + * interface SessionData { + * views: number; + * } + * } + * + */ +interface SessionData { + [key: string]: any; +} + +export function sessionMiddleware< + Req extends { headers: IncomingMessage["headers"] }, + Res extends ServerResponse, + SessionType = Record +>(options: SessionOptions): (req: Req, res: Res, next: () => void) => any { + return (req, res, next) => { + const session: any = initializeSession( + { cookie: req.headers.cookie! }, + options + ); + + //@ts-ignore + req.session = session; + + const setSessionHeaders = () => { + //@ts-ignore This can exist + const sessionCookie = req.session["set-cookie"]; + + if (sessionCookie && sessionCookie.length > 0) { + const existingSetCookie = res.getHeader("Set-Cookie") as + | string + | string[]; + + if (!existingSetCookie) { + res.setHeader("Set-Cookie", [sessionCookie]); + } else if (typeof existingSetCookie === "string") { + res.setHeader("Set-Cookie", [existingSetCookie, sessionCookie]); + } else { + res.setHeader("Set-Cookie", [...existingSetCookie, sessionCookie]); + } + } + }; + + const end = res.end; + res.end = function (...args: any) { + setSessionHeaders(); + return end.apply(this, args); + }; + + return next(); + }; +} diff --git a/src/index.ts b/src/index.ts index cb787f3..a832e1b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ export { initializeSession } from "./initialize.js"; -export type { Session, SessionOptions } from "./initialize"; +export type { Session, SessionOptions } from "./initialize"; export { handleSession } from "./handle.js"; export { daysToMaxage } from "./utils/cookie.js"; +export { sessionMiddleware } from "./connect.js"; diff --git a/tsconfig-cjs.json b/tsconfig-cjs.json new file mode 100644 index 0000000..5fdba0b --- /dev/null +++ b/tsconfig-cjs.json @@ -0,0 +1,81 @@ +{ + "ts-node": { + "transpileOnly": true, + "compilerOptions": { + "module": "ESNext" + }, + "include": ["tests/**/*"] + }, + "exclude": ["tests/**/*", "example/**/*"], + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Basic Options */ + // "incremental": true, + "moduleResolution": "Node" /* Enable incremental compilation */, + "target": "ES2018" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, + "module": "CommonJS" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, + // "lib": [], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ + "declaration": true /* Generates corresponding '.d.ts' file. */, + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + "sourceMap": false /* Generates corresponding '.map' file. */, + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "./dist/cjs" /* Redirect output structure to the directory. */, + "rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */, + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true /* Enable all strict type-checking options. */, + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "skipLibCheck": true /* Skip type checking of declaration files. */, + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } + } + \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 17fe70d..16d6451 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,7 +23,7 @@ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ "sourceMap": false /* Generates corresponding '.map' file. */, // "outFile": "./", /* Concatenate and emit output to single file. */ - "outDir": "./dist" /* Redirect output structure to the directory. */, + "outDir": "./dist/esm" /* Redirect output structure to the directory. */, "rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */, // "composite": true, /* Enable project compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */