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

build: setup build for cjs/esm #344

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
57 changes: 46 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,33 @@
"email": "stuft2@byu.edu"
}
],
"main": "dist/logger.js",
"types": "dist/logger.d.ts",
"type": "module",
"types": "dist/types/logger.d.ts",
"main": "dist/esm/logger.js",
"module": "dist/cjs/logger.js",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/types/logger.d.ts",
"default": "./dist/esm/logger.js"
},
"require": {
"types": "./dist/cjs/types/logger.d.ts",
"default": "./dist/cjs/logger.js"
}
}
},
"files": [
"dist"
],
"scripts": {
"build": "npx rimraf dist && tsc",
"build": "npx rimraf dist && npm run build:cjs && npm run build:esm",
"build:cjs": "tsc -p tsconfig.cjs.json && echo-cli \"{\\\"type\\\": \\\"commonjs\\\"}\" > dist/cjs/package.json",
"build:esm": "tsc -p tsconfig.json",
"coverage": "npm run test -- --coverage || exit 0",
"lint": "npx ts-standard | snazzy",
"lint:fix": "npx ts-standard --fix | snazzy",
"lint": "npx ts-standard . | snazzy",
"lint:fix": "npx ts-standard --fix . | snazzy",
"test": "jest",
"prepublishOnly": "npm run build"
},
Expand All @@ -33,29 +50,47 @@
"pino-http": "^6.6.0"
},
"devDependencies": {
"@tsconfig/node12": "^1.0.11",
"@fastify/pre-commit": "^2.1.0",
"@tsconfig/node18": "^18.2.2",
"@types/jest": "^29.5.0",
"@types/node": "^16.9.1",
"echo-cli": "^2.0.0",
"jest": "^29.5.0",
"lint-staged": "^12.0.2",
"pino-pretty": "^10.0.0",
"snazzy": "^9.0.0",
"ts-jest": "^29.1.0",
"ts-standard": "^12.0.2",
"tsx": "^4.7.0",
"typescript": "^5.0.3"
},
"optionalDependencies": {
"pino-pretty": ">=7"
},
"engines": {
"node": ">=12"
"node": ">=16"
},
"pre-commit": [
"test",
"lint"
],
"jest": {
"moduleNameMapper": {
"^(\\.\\.?\\/.+)\\.js$": "$1"
},
"extensionsToTreatAsEsm": [".ts"],
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
"^.+\\.(js|ts)$": [
"ts-jest",
{
"useESM": true
}
]
}
},
"lint-staged": {
"*.ts": "npm run lint:fix"
"ts-standard": {
"ignore": [
"dist"
]
},
"repository": {
"type": "git",
Expand Down
8 changes: 3 additions & 5 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Logger, LoggerOptions, pino } from 'pino'
import { getLevel, isInstalled, isProduction } from './util'
import { getLevel, isInstalled, isProduction } from './util.js'
import deepmerge from 'deepmerge'

export function ByuLogger (options?: LoggerOptions): Logger {
export default function ByuLogger (options?: LoggerOptions): Logger {
const defaultOptions: LoggerOptions = {
level: getLevel(process.env.NODE_ENV),
messageKey: 'message',
formatters: {
level: level => ({ level }) // display the level not the number value of the level
},
base: { }, // don't display the process pid, nor hostname
base: {}, // don't display the process pid, nor hostname
redact: {
// redact bearer tokens and JWTs
paths: ['req.headers.authorization', 'req.headers.assertion', 'req.headers["x-jwt-assertion"]', 'req.headers["x-jwt-assertion-original"]'],
Expand All @@ -28,5 +28,3 @@ export function ByuLogger (options?: LoggerOptions): Logger {
const opts: LoggerOptions = options == null ? defaultOptions : deepmerge(defaultOptions, options)
return pino(opts)
}

export default ByuLogger
2 changes: 1 addition & 1 deletion test/logger.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ByuLogger } from '../src/logger'
import ByuLogger from '../src/logger'
import { Logger } from 'pino'

const jan1st = new Date(2021, 0, 1)
Expand Down
23 changes: 23 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"lib": [
"DOM",
"es2022"
],
"module": "commonjs",
"target": "es2022",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"importHelpers": true,
"strictNullChecks": true,
"declarationDir": "dist/cjs/types",
"declaration": true,
"outDir": "dist/cjs",
},
"include": [
"src"
]
}
6 changes: 5 additions & 1 deletion tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": [
"test/**/*"
"src/*.ts",
"test/*.ts"
]
}
17 changes: 14 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
{
"extends": "@tsconfig/node12/tsconfig.json",
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strictNullChecks": true,
"skipLibCheck": true,
"esModuleInterop": true,
"importHelpers": true,
"declarationDir": "dist/types",
"declaration": true,
"outDir": "dist"
"outDir": "dist/esm",
"lib": [
"DOM",
"ES2022"
]
},
"include": [
"src/**/*"
"src/*.ts"
]
}
Loading