Skip to content

Commit

Permalink
Merge pull request #22 from alchemisten/feature/optimized-output
Browse files Browse the repository at this point in the history
Merge branch "feature/optimized output" into develop
  • Loading branch information
vspdi authored Jun 11, 2024
2 parents 8a6170b + 31752e8 commit 5a08f9b
Show file tree
Hide file tree
Showing 33 changed files with 3,718 additions and 4,302 deletions.
58 changes: 17 additions & 41 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,24 @@
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nx/typescript", "prettier"],
"plugins": ["prettier"],
"files": [
"*.ts",
"*.tsx"
],
"extends": [
"plugin:@nx/typescript",
"@schablone/eslint-config",
"prettier"
],
"plugins": [
"prettier"
],
"rules": {
"import/prefer-default-export": "off",
"no-await-in-loop": "off",
"no-cond-assign": "off",
"no-console": "off",
"no-restricted-imports": [
"error",
{
"patterns": ["@material-ui/core/*/*", "!@material-ui/core/styles", "@mui/core/*/*", "!@mui/core/styles"]
}
],
"no-restricted-syntax": "off",
"no-return-await": "off",
"no-useless-constructor": "off",
"sort-imports": [
"warn",
{
"ignoreCase": true,
"ignoreDeclarationSort": true,
"ignoreMemberSort": false
}
],
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/explicit-member-accessibility": [
"warn",
{
"accessibility": "explicit"
}
],
"prettier/prettier": [
"warn",
{
"printWidth": 120,
"semi": true,
"singleQuote": true,
"tabWidth": 2
}
]
"import/no-extraneous-dependencies": "off",
"max-classes-per-file": "off"
},
"parserOptions": {
"project": ["tsconfig.*?.json"]
}
},
{
Expand Down
10 changes: 3 additions & 7 deletions apps/logging-react-test/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/logging-react-test/src",
"projectType": "application",
"tags": [],
"targets": {
"build": {
"executor": "@nx/vite:build",
Expand Down Expand Up @@ -61,18 +62,13 @@
}
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/logging-react-test/**/*.{ts,tsx,js,jsx}"]
}
"executor": "@nx/eslint:lint"
},
"serve-static": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "logging-react-test:build"
}
}
},
"tags": []
}
}
66 changes: 33 additions & 33 deletions apps/logging-react-test/src/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ConsoleTransport, LoggerOptions, LogLevel, LogOptions } from '@schablone/logging';
import type { LoggerOptions, LogLevel, LogOptions } from '@schablone/logging';
import { ConsoleTransport } from '@schablone/logging';
import { SentryBrowserTransport } from '@schablone/logging-transport-sentry-browser';
import { environment } from '../environments/environment';
import { LoggingProvider, useLogger } from '@schablone/logging-react';
import { environment } from '../environments/environment';

const mainLoggerOptions: LoggerOptions = {
environment: 'local',
Expand Down Expand Up @@ -30,13 +31,40 @@ if (environment.sentryDsn) {
transportLogOptions: {
tags: { transport: 'SentryTransport' },
},
})
}),
);
} else {
// eslint-disable-next-line no-console
console.warn('No NX_SENTRY_DSN configured, sentry transport not added', environment);
}

export function App() {
const LowerLevelWithOwnLogger = () => {
const { logger } = useLogger();
const handleClick = () => {
logger.warn('Warning from the lower level with custom provider');
};

return (
<button type="button" onClick={handleClick}>
Warn Lower
</button>
);
};

const LowerLevelWithParentLogger = () => {
const { logger } = useLogger();
const handleClick = () => {
logger.warn('Warning from the lower level with parent logger');
};

return (
<button type="button" onClick={handleClick}>
Warn Lower
</button>
);
};

export const App = () => {
const { logger } = useLogger();
const lowerLevelOptions: LoggerOptions = {
globalLogOptions: {
Expand Down Expand Up @@ -95,35 +123,9 @@ export function App() {
</div>
</>
);
}

const LowerLevelWithOwnLogger = () => {
const { logger } = useLogger();
const handleClick = () => {
logger.warn('Warning from the lower level with custom provider');
};

return (
<button type="button" onClick={handleClick}>
Warn Lower
</button>
);
};

const LowerLevelWithParentLogger = () => {
const { logger } = useLogger();
const handleClick = () => {
logger.warn('Warning from the lower level with parent logger');
};

return (
<button type="button" onClick={handleClick}>
Warn Lower
</button>
);
};

const AppRoot = () => {
export const AppRoot = () => {
const { logger } = useLogger();
const handleClick = () => {
logger.warn('Logging without a provider');
Expand All @@ -144,5 +146,3 @@ const AppRoot = () => {
</div>
);
};

export default AppRoot;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const environment = {
production: true,
sentryDsn: process.env['NX_SENTRY_DSN'],
sentryDsn: process.env.NX_SENTRY_DSN,
};
2 changes: 1 addition & 1 deletion apps/logging-react-test/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

export const environment = {
production: false,
sentryDsn: process.env['NX_SENTRY_DSN'],
sentryDsn: process.env.NX_SENTRY_DSN,
};
6 changes: 3 additions & 3 deletions apps/logging-react-test/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { StrictMode } from 'react';
import * as ReactDOM from 'react-dom/client';

import App from './app/app';
import { AppRoot } from './app/app';

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(
<StrictMode>
<App />
</StrictMode>
<AppRoot />
</StrictMode>,
);
13 changes: 13 additions & 0 deletions apps/logging-react-test/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
export default ({ mode }: { mode: string }) => {
const env = loadEnv(mode, process.cwd(), '');
return defineConfig({
root: __dirname,
build: {
outDir: '../../dist/apps/logging-react-test',
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
},
},
cacheDir: '../../node_modules/.vite/logging-react-test',

define: {
Expand All @@ -30,6 +38,11 @@ export default ({ mode }: { mode: string }) => {
// },

test: {
reporters: ['default'],
coverage: {
reportsDirectory: '../../coverage/apps/logging-react-test',
provider: 'v8',
},
globals: true,
cache: {
dir: '../../node_modules/.vitest',
Expand Down
3 changes: 2 additions & 1 deletion libs/logging-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"@schablone/logging": "__root_version__",
"react": "^18.2.0",
"tslib": "^2.6.2"
}
},
"types": "./src/index.d.ts"
}
9 changes: 2 additions & 7 deletions libs/logging-react/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,13 @@
]
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/logging-react/**/*.{ts,tsx,js,jsx}"]
}
"executor": "@nx/eslint:lint"
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/libs/logging-react"],
"options": {
"jestConfig": "libs/logging-react/jest.config.ts",
"passWithNoTests": true
"jestConfig": "libs/logging-react/jest.config.ts"
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions libs/logging-react/src/provider/logging-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { createContext, FC, PropsWithChildren, useContext, useMemo } from 'react';
import { ILogger, LoggerFactory, LoggerOptions } from '@schablone/logging';
import type { FC, PropsWithChildren } from 'react';
import { createContext, useContext, useMemo } from 'react';
import type { ILogger, LoggerOptions } from '@schablone/logging';
import { LoggerFactory } from '@schablone/logging';

const defaultLogger: ILogger = LoggerFactory({});

Expand Down
4 changes: 4 additions & 0 deletions libs/logging-react/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import dts from 'vite-plugin-dts';
import { joinPathFragments } from '@nx/devkit';

export default defineConfig({
root: __dirname,
cacheDir: '../../node_modules/.vite/logging-react',

plugins: [
Expand All @@ -30,6 +31,9 @@ export default defineConfig({
// Configuration for building your library.
// See: https://vitejs.dev/guide/build.html#library-mode
build: {
outDir: '../../dist/libs/logging-react',
reportCompressedSize: true,
commonjsOptions: { transformMixedEsModules: true },
lib: {
// Could also be a dictionary or array of multiple entry points.
entry: 'src/index.ts',
Expand Down
3 changes: 2 additions & 1 deletion libs/logging-transport-sentry-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"@schablone/logging": "__root_version__",
"@sentry/browser": "^7.74.1",
"tslib": "^2.6.2"
}
},
"types": "./src/index.d.ts"
}
13 changes: 4 additions & 9 deletions libs/logging-transport-sentry-browser/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/logging-transport-sentry-browser/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nx/js:tsc",
Expand All @@ -26,20 +27,14 @@
]
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/logging-transport-sentry-browser/**/*.ts"]
}
"executor": "@nx/eslint:lint"
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/libs/logging-transport-sentry-browser"],
"options": {
"jestConfig": "libs/logging-transport-sentry-browser/jest.config.ts",
"passWithNoTests": true
"jestConfig": "libs/logging-transport-sentry-browser/jest.config.ts"
}
}
},
"tags": []
}
}
14 changes: 4 additions & 10 deletions libs/logging-transport-sentry-browser/src/sentry.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import {
deepmerge,
Environment,
ExecutionContext,
GlobalLogOptions,
SentryTransport,
SentryTransportOptions,
} from '@schablone/logging';
import type { Environment, ExecutionContext, GlobalLogOptions, SentryTransportOptions } from '@schablone/logging';
import { deepmerge, SentryTransport } from '@schablone/logging';
import * as SentryBrowser from '@sentry/browser';
import { BrowserOptions } from '@sentry/browser';
import type { BrowserOptions } from '@sentry/browser';

export class SentryBrowserTransport extends SentryTransport {
public constructor(options: SentryTransportOptions) {
Expand All @@ -25,7 +19,7 @@ export class SentryBrowserTransport extends SentryTransport {
protected setupImpl(
executionContext: ExecutionContext,
environment: Environment,
globalLogOptions: GlobalLogOptions
globalLogOptions: GlobalLogOptions,
): void {
this.environment = environment;
this.executionContext = executionContext;
Expand Down
3 changes: 2 additions & 1 deletion libs/logging-transport-sentry-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"@schablone/logging": "__root_version__",
"@sentry/node": "^7.74.1",
"tslib": "^2.6.2"
}
},
"types": "./src/index.d.ts"
}
Loading

0 comments on commit 5a08f9b

Please sign in to comment.