Skip to content

Commit

Permalink
feat: adding auth-common to monorepo (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
aversini authored Jun 15, 2024
1 parent 937770e commit 055844a
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"packages/auth-provider": "1.0.0"
"packages/auth-provider": "1.0.0",
"packages/auth-common": "0.0.0"
}
3 changes: 3 additions & 0 deletions packages/auth-common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @versini/auth-common

This package provides common utilities and constants for both the client and server side of the authentication system.
32 changes: 32 additions & 0 deletions packages/auth-common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@versini/auth-common",
"version": "0.0.0",
"license": "MIT",
"author": "Arno Versini",
"publishConfig": {
"access": "public"
},
"homepage": "https://github.com/aversini/auth-client",
"repository": {
"type": "git",
"url": "[email protected]:aversini/auth-client.git"
},
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": ["dist"],
"scripts": {
"build:check": "tsc",
"build:js": "vite build",
"build:types": "tsup",
"build": "npm-run-all --serial clean build:check build:js build:types",
"clean": "rimraf dist tmp",
"dev:js": "vite build --watch --mode development",
"dev:types": "tsup --watch src",
"dev": "npm-run-all clean --parallel dev:js dev:types",
"lint": "biome lint src",
"start": "static-server dist --port 5173",
"test:watch": "vitest",
"test": "vitest run"
}
}
3 changes: 3 additions & 0 deletions packages/auth-common/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const AUTH_TYPES = {
ID_TOKEN: "id_token",
};
1 change: 1 addition & 0 deletions packages/auth-common/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
26 changes: 26 additions & 0 deletions packages/auth-common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
"types": ["vitest/globals", "@testing-library/jest-dom"],

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
10 changes: 10 additions & 0 deletions packages/auth-common/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["./vite.config.ts", "./vitest.setup.ts"]
}
12 changes: 12 additions & 0 deletions packages/auth-common/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from "tsup";

export default defineConfig({
format: "esm",
entry: {
index: "src/components/index.ts",
},
outDir: "dist",
dts: {
only: true,
},
});
75 changes: 75 additions & 0 deletions packages/auth-common/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { resolve } from "node:path";

import fs from "fs-extra";
import { defineConfig } from "vite";

import { externalDependencies } from "../../configuration/vite.common";

const packageJson = fs.readJSONSync("package.json");
const copyrightYear = new Date(Date.now()).getFullYear();
const buildTime = new Date()
.toLocaleString("en-US", {
timeZone: "America/New_York",
timeZoneName: "short",
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
})
.replace(/,/g, "");
const banner = `/*!
${packageJson.name} v${packageJson.version}
© ${copyrightYear} gizmette.com
*/
try {
if (!window.__VERSINI_AUTH_COMMON__) {
window.__VERSINI_AUTH_COMMON__ = {
version: "${packageJson.version}",
buildTime: "${buildTime}",
homepage: "${packageJson.homepage}",
license: "${packageJson.license}",
};
}
} catch (error) {
// nothing to declare officer
}
`;

export default defineConfig(() => {
return {
build: {
copyPublicDir: false,
lib: {
entry: resolve(__dirname, "src/components/index.ts"),
formats: ["es"],
name: "AuthCommon",
},
rollupOptions: {
input: {
index: resolve(__dirname, "src/components/index.ts"),
},
treeshake: "smallest",
external: externalDependencies,
output: {
compact: true,
minifyInternalExports: false,
assetFileNames: "style[extname]",
entryFileNames: "[name].js",
chunkFileNames: "chunks/[name].[hash].js",
banner: (module) => {
if (module?.facadeModuleId?.endsWith("src/components/index.ts")) {
return banner;
}
},
},
},
},
esbuild: {
supported: {
"top-level-await": true,
},
},
plugins: [],
};
});
28 changes: 28 additions & 0 deletions packages/auth-common/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/// <reference types="vitest" />

import { defineConfig, mergeConfig } from "vitest/config";

import viteConfig from "./vite.config";

export default defineConfig((configEnv) =>
mergeConfig(
viteConfig(configEnv),
defineConfig({
test: {
globals: true,
setupFiles: ["./vitest.setup.ts"],
environment: "happy-dom",
coverage: {
include: ["src/**/*.ts", "src/**/*.tsx", "!src/style.ts"],
provider: "v8",
thresholds: {
statements: 100,
branches: 100,
functions: 100,
lines: 100,
},
},
},
}),
),
);
17 changes: 17 additions & 0 deletions packages/auth-common/vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import "@testing-library/jest-dom/vitest";

import util from "node:util";

const originalConsoleError = console.error;
console.error = (...args: any) => {
const message = util.format(...args);
if (
/(Warning: validateDOMNesting|Invalid prop|Failed prop type|React does not recognize|Unknown event handler property)/gi.test(
message,
)
) {
throw new Error(message);
} else {
originalConsoleError.apply(console, [...args]);
}
};
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion release-please-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"packages": {
"packages/auth-provider": {}
"packages/auth-provider": {},
"packages/auth-common": {}
}
}

0 comments on commit 055844a

Please sign in to comment.