Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to rollup #1

Merged
merged 23 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/sveltekit-mal-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "sveltekit-mal-auth",
"version": "0.1.0",
"type": "module",
"private": true,
"scripts": {
"dev": "vite dev",
Expand All @@ -13,8 +14,8 @@
"format": "prettier --plugin-search-dir . --write ."
},
"dependencies": {
"@animelist/auth-sveltekit": "*",
"@animelist/client": "*",
"@animelist/auth-sveltekit": "workspace:*",
"@animelist/client": "workspace:*",
"svelte": "^4.0.5"
},
"devDependencies": {
Expand All @@ -38,6 +39,5 @@
"vite": "^4.4.2",
"vite-plugin-node-polyfills": "^0.15.0",
"vitest": "^0.34.0"
},
"type": "module"
}
}
15 changes: 1 addition & 14 deletions examples/sveltekit-mal-auth/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@ import { nodePolyfills } from 'vite-plugin-node-polyfills';
import dotenv from 'dotenv';
dotenv.config();

const defineProcessEnv = () => {
const definedEnvs = Object.fromEntries(
Object.entries(process.env || {}).map(([key, value]) => [
`process.env.${key}`,
JSON.stringify(value)
])
);

return definedEnvs;
};

export default defineConfig({
plugins: [sveltekit(), nodePolyfills()],
server: {
Expand All @@ -23,9 +12,7 @@ export default defineConfig({
test: {
include: ['src/**/*.{test,spec}.{js,ts}']
},
//define: defineProcessEnv()
define: {
'process.versions': JSON.stringify(process.versions),
...defineProcessEnv()
'process.versions': JSON.stringify(process.versions)
}
});
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "0.0.1-alpha.8",
"version": "0.0.1-alpha.11",
"npmClient": "pnpm"
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@
"pnpm": ">=8.0.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.2",
"@types/fs-extra": "^11.0.2",
"@types/glob": "^8.1.0",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"esbuild": "^0.19.3",
"eslint": "^8.49.0",
"fs-extra": "^11.1.1",
"glob": "^10.3.7",
"lerna": "^7.3.0",
"prettier-eslint": "^15.0.1",
"rimraf": "^5.0.1",
"rollup": "^4.0.0",
"rollup-plugin-node-externals": "^6.1.2",
"rollup-plugin-swc3": "^0.10.1",
"tsx": "^3.13.0",
"typescript": "^5.2.2"
},
Expand All @@ -30,6 +33,7 @@
"clean:dist": "rimraf --glob packages/**/dist/",
"clean:node_modules": "rimraf --glob packages/**/node_modules",
"clean": "tsx ./scripts/cleanUpEntrypoints.ts && npm run clean:dist && npm run clean:node_modules",
"clean:all": "pnpm clean && pnpm clean:root",
"build": "npx lerna run --scope '@animelist/*' build",
"entrypoints": "npx lerna run --scope '@animelist/*' entrypoints",
"typecheck": "npx lerna run --scope '@animelist/*' typecheck",
Expand Down
11 changes: 0 additions & 11 deletions packages/animelist-auth-next/esbuild.mts

This file was deleted.

8 changes: 3 additions & 5 deletions packages/animelist-auth-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@animelist/auth-next",
"version": "0.0.1-alpha.8",
"version": "0.0.1-alpha.11",
"description": "Integration with the @animelist/auth for NextJS",
"author": "Freddy L.",
"main": "index.js",
Expand All @@ -9,10 +9,9 @@
"scripts": {
"typecheck": "tsc --noEmit",
"lint": "eslint ./src",
"clean:lib": "rimraf server client && rimraf index.js index.js.map index.mjs index.mjs.map index.d.ts index.d.ts.map",
"clean:lib": "rimraf dist server client index.js index.mjs index.d.ts index.d.ts.map",
"build:types": "tsc --emitDeclarationOnly",
"build:lib": "tsx esbuild.mts",
"build": "rimraf dist && pnpm clean:lib && pnpm build:types && pnpm build:lib && npx ncp dist .",
"build": "pnpm clean:lib && pnpm build:types && rollup --config rollup.config.ts --configPlugin rollup-plugin-swc3 && npx ncp dist .",
"prepublishOnly": "pnpm build"
},
"repository": {
Expand All @@ -39,7 +38,6 @@
},
"devDependencies": {
"@types/react": "^18.2.22",
"esbuild": "^0.19.3",
"eslint": "^8.49.0",
"ncp": "^2.0.0",
"next": "^13.5.2",
Expand Down
12 changes: 12 additions & 0 deletions packages/animelist-auth-next/rollup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import path from "path";
import { fileURLToPath } from "url";
import { rollupConfig } from "../../scripts/rollupConfig";

const packageDir = path.dirname(fileURLToPath(import.meta.url));

export default function rollup() {
return rollupConfig({
input: ["src/**/*.ts", "src/**/*.tsx"],
packageDir,
});
}
67 changes: 32 additions & 35 deletions packages/animelist-auth-next/src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
// We just reexports here
export { createMyAnimeListFetchHandler } from "@animelist/auth/server";

export {
type UserSession,
type Cookies
} from "@animelist/auth/common";
export { type UserSession, type Cookies } from "@animelist/auth/common";

import {
getServerSession as getAuthServerSession,
getRequiredServerSession as getAuthRequiredServerSession,
getServerSession as getAuthServerSession,
getRequiredServerSession as getAuthRequiredServerSession,
} from "@animelist/auth/common";
import { type GetMyUserInfoOptions, MALClient } from "@animelist/client";
import { type ReadonlyRequestCookies } from "next/dist/server/web/spec-extension/adapters/request-cookies"
import { type RequestCookies } from "next/dist/compiled/@edge-runtime/cookies";

// We adapt the `getServerSession` functions to use the NextJS cookies.

type NextCookies = Pick<RequestCookies, "get" | "getAll" | "has">;

/**
* Verify the session and return the MyAnimeList refresh token and user id.
* @param cookies The cookies to extract the user token.
* @returns The user refresh token and user id.
*/
export async function getServerSession(cookies: ReadonlyRequestCookies) {
return await getAuthServerSession({
get: (name) => cookies.get(name)?.value,
delete: () => { },
set: () => { },
});
export async function getServerSession(cookies: NextCookies) {
return await getAuthServerSession({
get: (name) => cookies.get(name)?.value,
});
}

/**
Expand All @@ -34,37 +31,37 @@ export async function getServerSession(cookies: ReadonlyRequestCookies) {
* @param message The error message to show when the user is not authenticated. Defaults to `"unable to get user session"`.
* @returns The user refresh token and id.
*/
export async function getRequiredServerSession(cookies: ReadonlyRequestCookies) {
return await getAuthRequiredServerSession({
get: (name) => cookies.get(name)?.value,
delete: () => { },
set: () => { },
});
export async function getRequiredServerSession(cookies: NextCookies) {
return await getAuthRequiredServerSession({
get: (name) => cookies.get(name)?.value,
});
}

/**
* Fetches the user using the token in the session cookies.
*
*
* @remarks This function will make a request each time to fetch the user,
* if you want to check if the user is logged prefer to use `getServerSession` or `getRequiredServerSession` instead,
* or add a caching logic on top of this function.
*
* if you want to check if the user is logged prefer to use `getServerSession` or `getRequiredServerSession` instead.
*
* @param cookies The cookies to extract the user token.
* @param options Additional options to pass to retrieve the user.
* @returns The current user if found.
*/
export async function getUser(cookies: ReadonlyRequestCookies, options?: GetMyUserInfoOptions) {
const session = await getServerSession(cookies);
export async function getUser(
cookies: NextCookies,
options?: GetMyUserInfoOptions
) {
const session = await getServerSession(cookies);

if (session == null) {
return undefined;
}
if (session == null) {
return undefined;
}

const client = new MALClient({ accessToken: session.accessToken });
const user = await client.getMyUserInfo(options);
const client = new MALClient({ accessToken: session.accessToken });
const user = await client.getMyUserInfo(options);

return {
user,
accessToken: session.accessToken,
}
}
return {
user,
accessToken: session.accessToken,
};
}
16 changes: 7 additions & 9 deletions packages/animelist-auth-sveltekit/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
{
"name": "@animelist/auth-sveltekit",
"version": "0.0.1-alpha.8",
"version": "0.0.1-alpha.11",
"description": "Integration with the @animelist/auth for SvelteKit",
"author": "Freddy L.",
"type": "module",
"module": "dist/index.mjs",
"module": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"typecheck": "tsc --noEmit",
"lint": "eslint ./src",
"entrypoints": "tsx entrypoints.script.mts",
"build:types": "tsc --emitDeclarationOnly",
"build:lib": "tsx esbuild.mts",
"build:svelte": "svelte-package -i src/client -o dist/client",
"build": "rimraf dist && pnpm build:types && pnpm build:lib && pnpm entrypoints",
"build": "rimraf dist && pnpm build:types && rollup --config rollup.config.ts --configPlugin rollup-plugin-swc3 && pnpm entrypoints",
"prepublishOnly": "pnpm build"
},
"repository": {
Expand Down Expand Up @@ -49,12 +47,12 @@
"exports": {
"./package.json": "./package.json",
"./client": {
"import": "./dist/client/index.mjs",
"default": "./dist/client/index.mjs"
"import": "./dist/client/index.js",
"default": "./dist/client/index.js"
},
"./server": {
"import": "./dist/server/index.mjs",
"default": "./dist/server/index.mjs"
"import": "./dist/server/index.js",
"default": "./dist/server/index.js"
}
},
"files": [
Expand Down
18 changes: 18 additions & 0 deletions packages/animelist-auth-sveltekit/rollup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import path from "path";
import { fileURLToPath } from "url";
import { rollupConfig } from "../../scripts/rollupConfig";

const packageDir = path.dirname(fileURLToPath(import.meta.url));

export default function rollup() {
return rollupConfig({
input: ["src/**/*.ts"],
exclude: ["**/*.test.ts"],
formats: ["esm"],
packageDir,
esmOutputOverride: {
entryFileNames: "[name].js",
chunkFileNames: "[name]-[hash].js",
},
});
}
3 changes: 1 addition & 2 deletions packages/animelist-auth-sveltekit/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ export {
* Fetches the user using the token in the session cookies.
*
* @remarks This function will make a request each time to fetch the user,
* if you want to check if the user is logged prefer to use `getServerSession` or `getRequiredServerSession` instead,
* or add a caching logic on top of this function.
* if you want to check if the user is logged prefer to use `getServerSession` or `getRequiredServerSession` instead.
*
* @param cookies The cookies to extract the user token.
* @param options Additional options to pass to retrieve the user.
Expand Down
11 changes: 0 additions & 11 deletions packages/animelist-auth/esbuild.mts

This file was deleted.

10 changes: 3 additions & 7 deletions packages/animelist-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@animelist/auth",
"version": "0.0.1-alpha.8",
"version": "0.0.1-alpha.11",
"description": "Provides an API to authenticate users with `MyAnimeList`",
"author": "Freddy L.",
"license": "MIT",
Expand All @@ -11,8 +11,7 @@
"lint": "eslint ./src",
"entrypoints": "tsx entrypoints.script.mts",
"build:types": "tsc --emitDeclarationOnly",
"build:lib": "tsx esbuild.mts",
"build": "rimraf dist && pnpm build:types && pnpm build:lib && pnpm entrypoints",
"build": "rimraf dist && pnpm build:types && rollup --config rollup.config.ts --configPlugin rollup-plugin-swc3 && pnpm entrypoints",
"prepublishOnly": "pnpm build"
},
"main": "dist/index.js",
Expand All @@ -35,21 +34,18 @@
"@animelist/client": "workspace:*",
"@animelist/core": "workspace:*",
"cookie": "^0.5.0",
"crypto-es": "2.0.4",
"jose": "^4.15.2",
"zod": "3.22.2"
},
"devDependencies": {
"@types/cookie": "^0.5.2",
"@types/node": "20.6.2",
"dotenv": "^16.3.1",
"esbuild": "^0.19.3",
"eslint": "^8.49.0",
"typescript": "^5.2.2",
"vitest": "^0.34.4"
},
"peerDependencies": {
"crypto-es": "2.0.4"
},
"publishConfig": {
"access": "public"
},
Expand Down
13 changes: 13 additions & 0 deletions packages/animelist-auth/rollup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import path from "path";
import { fileURLToPath } from "url";
import { rollupConfig } from "../../scripts/rollupConfig";

const packageDir = path.dirname(fileURLToPath(import.meta.url));

export default function rollup() {
return rollupConfig({
input: ["src/**/*.ts"],
exclude: ["**/*.test.ts"],
packageDir,
});
}
Loading