[ENHANCEMENT] Distributable Bundle with Rollup and ESBuild (#11)

* ⚰️ Remove `package-lock.json` to avoid conflicts with Yarn

* ⚰️ Remove `jwt.ts`

* 🏗️ Setup Rollup with entry module `package.json` files and use named exports exclusively for compatibility with CommonJS

* ⬆️ Use `file:..` instead of `link:..` in demo app to test local installation

* 🏷️ Export types as individual files to avoid protected access errors

* 🚨 Explicit `export types`

* 💚 Use ESBuild to bundle with Rollup, update Rollup deps and types

* 🐛 Remove usage of SvelteKit modules

Disable implicitly updating session, routing and getting redirect URL from SvelteKit modules due to missing exports.
This commit is contained in:
Dan6erbond 2021-05-23 17:32:42 +02:00 committed by GitHub
parent 5d1802fea4
commit 591bfbbbc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 165 additions and 1806 deletions

View File

@ -34,6 +34,6 @@
"@fontsource/inter": "^4.3.0",
"clsx": "^1.1.1",
"prismjs": "^1.23.0",
"svelte-kit-auth": "link:../"
"svelte-kit-auth": "file:../"
}
}

View File

@ -1,4 +1,4 @@
import SvelteKitAuth from "svelte-kit-auth";
import { SvelteKitAuth } from "svelte-kit-auth";
import {
FacebookAuthProvider,
GoogleOAuthProvider,

View File

@ -1,8 +1,12 @@
<script lang="ts">
import "../app.postcss";
import { page, session } from "$app/stores";
import { signOut } from "svelte-kit-auth/client";
import { signOut as authSignOut } from "svelte-kit-auth/client";
import clsx from "clsx";
function signOut() {
authSignOut().then(session.set);
}
</script>
<svelte:head>
@ -191,7 +195,7 @@
"items-center",
"flex-col",
"bg-orange-600",
"text-white"
"text-white",
)}
>
<span>© RaviAnand M, 2021</span>

View File

@ -2189,9 +2189,17 @@ svelte-hmr@^0.14.2:
resolved "https://registry.yarnpkg.com/svelte-hmr/-/svelte-hmr-0.14.4.tgz#b7ef2bfeef23916e0e912828c50645ca572ac355"
integrity sha512-kItFF7vqzStckSigoFmMnxJpTOdB9TWnQAW6Js+yAB4277tLbJIIE5KBlGHNmJNpA7MguqidsPB27Uw5UzQPCA==
"svelte-kit-auth@link:..":
version "0.0.0"
uid ""
"svelte-kit-auth@file:..":
version "1.0.0"
dependencies:
cookie "^0.4.1"
jsonwebtoken "^8.5.1"
"svelte-kit-auth@file:../":
version "1.0.0"
dependencies:
cookie "^0.4.1"
jsonwebtoken "^8.5.1"
svelte-preprocess@^4.7.1:
version "4.7.3"

5
client/package.json Normal file
View File

@ -0,0 +1,5 @@
{
"internal": true,
"main": "../dist/client/index.js",
"types": "../dist/client/index.d.ts"
}

1756
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -9,19 +9,15 @@
"./client": "./dist/client/index.js",
"./providers": "./dist/providers/index.js"
},
"typesVersions": {
"*": {
"client": [
"./dist/client/index.d.ts"
],
"providers": [
"./dist/providers/index.d.ts"
]
}
},
"files": [
"dist",
"client",
"providers",
"README.md"
],
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch",
"build": "rollup --config",
"dev": "rollup --config --watch",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "prettier --check --plugin-search-dir=. . && eslint --ignore-path .gitignore .",
"format": "prettier --write --plugin-search-dir=. ."
@ -48,15 +44,23 @@
"jsonwebtoken": "^8.5.1"
},
"devDependencies": {
"@rollup/plugin-typescript": "^8.2.1",
"@sveltejs/kit": "^1.0.0-next.107",
"@types/jsonwebtoken": "^8.5.1",
"@typescript-eslint/eslint-plugin": "^4.23.0",
"@typescript-eslint/parser": "^4.23.0",
"esbuild": "^0.12.1",
"eslint": "^7.26.0",
"eslint-config-prettier": "^8.3.0",
"prettier": "^2.3.0",
"rollup": "^2.48.0",
"rollup-plugin-esbuild": "^4.2.3",
"rollup-plugin-multi-input": "^1.3.0",
"svelte": "^3.38.2",
"tslib": "^2.2.0",
"typescript": "^4.2.4"
},
"peerDependencies": {
"@sveltejs/kit": "next"
}
}

5
providers/package.json Normal file
View File

@ -0,0 +1,5 @@
{
"internal": true,
"main": "../dist/providers/index.js",
"types": "../dist/providers/index.d.ts"
}

28
rollup.config.js Normal file
View File

@ -0,0 +1,28 @@
import multiInput from "rollup-plugin-multi-input";
import packageJson from "./package.json";
import esbuild from "rollup-plugin-esbuild";
const globals = {
...packageJson.dependencies,
...packageJson.devDependencies,
};
export default [
{
input: ["src/**/*.ts"],
output: {
dir: "dist",
sourcemap: true,
format: "cjs",
},
plugins: [
esbuild(),
multiInput(),
],
external: [
...Object.keys(globals),
"@sveltejs/kit/assets/runtime/app/navigation",
"@sveltejs/kit/assets/runtime/app/stores",
],
},
];

View File

@ -1,5 +1,5 @@
import { goto } from "$app/navigation";
import { page } from "$app/stores";
/* import { goto } from "@sveltejs/kit/assets/runtime/app/navigation";
import { page } from "@sveltejs/kit/assets/runtime/app/stores"; */
import type { Page } from "@sveltejs/kit";
interface SignInConfig {
@ -24,7 +24,7 @@ export async function signIn(provider: string, data?: any, config?: SignInConfig
redirectUrl = config.redirectUrl;
} else {
let $val: Page | undefined;
page.subscribe(($) => ($val = $))();
/* page.subscribe(($) => ($val = $))(); */
if ($val) {
redirectUrl = `${$val.host}${$val.path}?${$val.query}`;
}
@ -36,5 +36,5 @@ export async function signIn(provider: string, data?: any, config?: SignInConfig
const query = new URLSearchParams(queryData);
const path = `/api/auth/login/${provider}?${query}`;
return await goto(path);
return path; // await goto(path);
}

View File

@ -1,12 +1,15 @@
import { session as session$ } from "$app/stores";
/* import { session as session$ } from "$app/stores"; */
export async function signOut() {
const res = await fetch("/api/auth/signout", { method: "POST" });
let res = await fetch("/api/auth/signout", { method: "POST" });
const { signout } = await res.json();
fetch("/api/auth/session")
.then((res) => res.json())
.then(session$.set);
if (!signout) {
throw new Error("Sign out not successful!");
}
return signout === true;
res = await fetch("/api/auth/session");
const session = await res.json();
return session;
}

View File

@ -1,7 +1,4 @@
import { Auth } from "./auth";
export { JWT, Session, User } from "./interfaces";
export { Provider } from "./providers";
export { CallbackResult, Profile } from "./types";
export default Auth;
export { Auth as SvelteKitAuth } from "./auth";
export type { JWT, Session, User } from "./interfaces";
export * as Providers from "./providers";
export type { CallbackResult, Profile } from "./types";

View File

View File

@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "es2017",
"module": "es6",
"moduleResolution": "node",
"strict": true,
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"noImplicitAny": false,
"declaration": true,
"removeComments": true,
@ -13,9 +13,9 @@
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true
"outDir": "./dist"
},
"exclude": ["node_modules", "dist", "app"]
"include": ["src/**/*"],
"exclude": ["**/node_modules", "**/dist", "./app", "**/*.md", "**/rollup.config.js"]
}

View File

@ -59,6 +59,23 @@
"@nodelib/fs.scandir" "2.1.4"
fastq "^1.6.0"
"@rollup/plugin-typescript@^8.2.1":
version "8.2.1"
resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-8.2.1.tgz#f1a32d4030cc83432ce36a80a922280f0f0b5d44"
integrity sha512-Qd2E1pleDR4bwyFxqbjt4eJf+wB0UKVMLc7/BAFDGVdAXQMCsD4DUv5/7/ww47BZCYxWtJqe1Lo0KVNswBJlRw==
dependencies:
"@rollup/pluginutils" "^3.1.0"
resolve "^1.17.0"
"@rollup/pluginutils@^3.1.0":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b"
integrity sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==
dependencies:
"@types/estree" "0.0.39"
estree-walker "^1.0.1"
picomatch "^2.2.2"
"@rollup/pluginutils@^4.1.0":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-4.1.0.tgz#0dcc61c780e39257554feb7f77207dceca13c838"
@ -91,6 +108,11 @@
source-map "^0.7.3"
svelte-hmr "^0.14.2"
"@types/estree@0.0.39":
version "0.0.39"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==
"@types/json-schema@^7.0.3":
version "7.0.7"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad"
@ -178,10 +200,6 @@
"@typescript-eslint/types" "4.24.0"
eslint-visitor-keys "^2.0.0"
"SvelteKitAuth@link:../":
version "0.0.0"
uid ""
acorn-jsx@^5.3.1:
version "5.3.1"
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.1.tgz#fc8661e11b7ac1539c47dbfea2e72b3af34d267b"
@ -344,6 +362,11 @@ cookie@^0.4.1:
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.1.tgz#afd713fe26ebd21ba95ceb61f9a8116e50a537d1"
integrity sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==
core-js@^3.1.3:
version "3.12.1"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.12.1.tgz#6b5af4ff55616c08a44d386f1f510917ff204112"
integrity sha512-Ne9DKPHTObRuB09Dru5AjwKjY4cJHVGu+y5f7coGn1E9Grkc3p2iBwE9AI/nJzsE29mQF7oq+mhYYRqOMFN1Bw==
cross-spawn@^7.0.2:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
@ -410,6 +433,11 @@ esbuild@^0.11.23:
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.11.23.tgz#c42534f632e165120671d64db67883634333b4b8"
integrity sha512-iaiZZ9vUF5wJV8ob1tl+5aJTrwDczlvGP0JoMmnpC2B0ppiMCu8n8gmy5ZTGl5bcG081XBVn+U+jP+mPFm5T5Q==
esbuild@^0.12.1:
version "0.12.1"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.12.1.tgz#f652d5b3b9432dbb42fc2c034ddd62360296e03d"
integrity sha512-WfQ00MKm/Y4ysz1u9PCUAsV66k5lbrcEvS6aG9jhBIavpB94FBdaWeBkaZXxCZB4w+oqh+j4ozJFWnnFprOXbg==
escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
@ -526,6 +554,11 @@ estraverse@^5.1.0, estraverse@^5.2.0:
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.2.0.tgz#307df42547e6cc7324d3cf03c155d5cdb8c53880"
integrity sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ==
estree-walker@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-1.0.1.tgz#31bc5d612c96b704106b477e6dd5d8aa138cb700"
integrity sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==
estree-walker@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-2.0.2.tgz#52f010178c2a4c117a7757cfe942adb7d2da4cac"
@ -541,7 +574,7 @@ fast-deep-equal@^3.1.1:
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==
fast-glob@^3.1.1:
fast-glob@^3.0.0, fast-glob@^3.1.1:
version "3.2.5"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.5.tgz#7939af2a656de79a4f1901903ee8adcaa7cb9661"
integrity sha512-2DtFcgT68wiTTiwZ2hNdJfcHNke9XOfnwmBRWXhmeKM8rF0TGwmC/Qto3S7RoZKp5cilZbxzO5iTNTQsJ+EeDg==
@ -754,6 +787,11 @@ isexe@^2.0.0:
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
joycon@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/joycon/-/joycon-3.0.1.tgz#9074c9b08ccf37a6726ff74a18485f85efcaddaf"
integrity sha512-SJcJNBg32dGgxhPtM0wQqxqV0ax9k/9TaUskGDSJkSFSQOEWWvQ3zzWdGQRIUry2j1zA5+ReH13t0Mf3StuVZA==
js-tokens@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
@ -782,6 +820,11 @@ json-stable-stringify-without-jsonify@^1.0.1:
resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=
jsonc-parser@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.0.0.tgz#abdd785701c7e7eaca8a9ec8cf070ca51a745a22"
integrity sha512-fQzRfAbIBnR0IQvftw9FJveWiHp72Fg20giDrHz6TdfB12UH/uue0D3hm57UB5KgAVuniLMCaS8P1IMj9NR7cA==
jsonwebtoken@^8.5.1:
version "8.5.1"
resolved "https://registry.yarnpkg.com/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz#00e71e0b8df54c2121a1f26137df2280673bcc0d"
@ -868,7 +911,7 @@ lodash.truncate@^4.4.2:
resolved "https://registry.yarnpkg.com/lodash.truncate/-/lodash.truncate-4.4.2.tgz#5a350da0b1113b837ecfffd5812cbe58d6eae193"
integrity sha1-WjUNoLERO4N+z//VgSy+WNbq4ZM=
lodash@^4.17.15, lodash@^4.17.21:
lodash@^4.17.11, lodash@^4.17.15, lodash@^4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
@ -1030,7 +1073,7 @@ resolve-from@^4.0.0:
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6"
integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==
resolve@^1.19.0:
resolve@^1.17.0, resolve@^1.19.0:
version "1.20.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"
integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==
@ -1050,7 +1093,25 @@ rimraf@^3.0.2:
dependencies:
glob "^7.1.3"
rollup@^2.38.5:
rollup-plugin-esbuild@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/rollup-plugin-esbuild/-/rollup-plugin-esbuild-4.2.3.tgz#3d719e58e7a5f84515fe52a58d35bc97a9e7e12c"
integrity sha512-GWyDUPv79Iw4uQdizD7ch7yA+wiB9W4Ye01RmO/kuF3yjybluJT5rbmLAnyv3kWmOF8suOjf+TvvBCXEj6qSAw==
dependencies:
"@rollup/pluginutils" "^4.1.0"
joycon "^3.0.1"
jsonc-parser "^3.0.0"
rollup-plugin-multi-input@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-multi-input/-/rollup-plugin-multi-input-1.3.0.tgz#b4e765486281584caad6210d8ac662b94f1ecfd7"
integrity sha512-pxyrDxxTONfmTVZUPSQgMLDuY8jzCSCRe2NnEjAt0AZYHrH5lgnkEXqekFTGH4An8xNeLRkfuFRGW+GnaCNobA==
dependencies:
core-js "^3.1.3"
fast-glob "^3.0.0"
lodash "^4.17.11"
rollup@^2.38.5, rollup@^2.48.0:
version "2.48.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.48.0.tgz#fceb01ed771f991f29f7bd2ff7838146e55acb74"
integrity sha512-wl9ZSSSsi5579oscSDYSzGn092tCS076YB+TQrzsGuSfYyJeep8eEWj0eaRjuC5McuMNmcnR8icBqiE/FWNB1A==