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

feat(logger): Add dual exports with esmodule support on Logger #1734

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ site
tmp

# TS build files
tsconfig.tsbuildinfo
tsconfig.tsbuildinfo
tsconfig.esm.tsbuildinfo
65 changes: 14 additions & 51 deletions package-lock.json

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

36 changes: 18 additions & 18 deletions packages/logger/README.md
dreamorosi marked this conversation as resolved.
Show resolved Hide resolved
dreamorosi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ You can use the library in both TypeScript and JavaScript code bases.

## Features

* **[Tracer](https://docs.powertools.aws.dev/lambda-typescript/latest/core/tracer/)** - Utilities to trace Lambda function handlers, and both synchronous and asynchronous functions
* **[Logger](https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/)** - Structured logging made easier, and a middleware to enrich log items with key details of the Lambda context
* **[Metrics](https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/)** - Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF)
* **[Parameters](https://docs.powertools.aws.dev/lambda-typescript/latest/utilities/parameters/)** - High-level functions to retrieve one or more parameters from AWS SSM, Secrets Manager, AppConfig, and DynamoDB
- **[Tracer](https://docs.powertools.aws.dev/lambda-typescript/latest/core/tracer/)** - Utilities to trace Lambda function handlers, and both synchronous and asynchronous functions
- **[Logger](https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/)** - Structured logging made easier, and a middleware to enrich log items with key details of the Lambda context
- **[Metrics](https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/)** - Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF)
- **[Parameters](https://docs.powertools.aws.dev/lambda-typescript/latest/utilities/parameters/)** - High-level functions to retrieve one or more parameters from AWS SSM, Secrets Manager, AppConfig, and DynamoDB

## Getting started

Find the complete project's [documentation here](https://docs.powertools.aws.dev/lambda-typescript).

### Installation

The Powertools for AWS Lambda (TypeScript) utilities follow a modular approach, similar to the official [AWS SDK v3 for JavaScript](https://github.com/aws/aws-sdk-js-v3).
The Powertools for AWS Lambda (TypeScript) utilities follow a modular approach, similar to the official [AWS SDK v3 for JavaScript](https://github.com/aws/aws-sdk-js-v3).

Each TypeScript utility is installed as standalone npm package.

Expand All @@ -60,8 +60,8 @@ Or refer to the installation guide of each utility:

### Examples

* [CDK](https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/examples/cdk)
* [SAM](https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/examples/sam)
- [CDK](https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/examples/cdk)
- [SAM](https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/examples/sam)

### Serverless TypeScript Demo application

Expand All @@ -79,8 +79,8 @@ Help us prioritize upcoming functionalities or utilities by [upvoting existing R

## Connect

* **Powertools for AWS Lambda on Discord**: `#typescript` - **[Invite link](https://discord.gg/B8zZKbbyET)**
* **Email**: [email protected]
- **Powertools for AWS Lambda on Discord**: `#typescript` - **[Invite link](https://discord.gg/B8zZKbbyET)**
- **Email**: [email protected]

## How to support Powertools for AWS Lambda (TypeScript)?

Expand All @@ -90,15 +90,15 @@ Knowing which companies are using this library is important to help prioritize t

The following companies, among others, use Powertools:

* [Hashnode](https://hashnode.com/)
* [Trek10](https://www.trek10.com/)
* [Elva](https://elva-group.com)
* [globaldatanet](https://globaldatanet.com/)
* [Bailey Nelson](https://www.baileynelson.com.au)
* [Perfect Post](https://www.perfectpost.fr)
* [Sennder](https://sennder.com/)
* [Certible](https://www.certible.com/)
* [tecRacer GmbH & Co. KG](https://www.tecracer.com/)
- [Hashnode](https://hashnode.com/)
- [Trek10](https://www.trek10.com/)
- [Elva](https://elva-group.com)
- [globaldatanet](https://globaldatanet.com/)
- [Bailey Nelson](https://www.baileynelson.com.au)
- [Perfect Post](https://www.perfectpost.fr)
- [Sennder](https://sennder.com/)
- [Certible](https://www.certible.com/)
- [tecRacer GmbH & Co. KG](https://www.tecracer.com/)

### Sharing your work

Expand Down
12 changes: 10 additions & 2 deletions packages/logger/jest.config.js → packages/logger/jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ module.exports = {
color: 'cyan',
},
runner: 'groups',
preset: 'ts-jest',
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'^.+\\.ts?$': 'ts-jest',
'^.+\\.[tj]sx?$': [
'ts-jest',
{
useESM: true,
},
],
},
moduleFileExtensions: ['js', 'ts'],
collectCoverageFrom: ['**/src/**/*.ts', '!**/node_modules/**'],
Expand Down
24 changes: 20 additions & 4 deletions packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,35 @@
"test:e2e:nodejs18x": "RUNTIME=nodejs18x jest --group=e2e",
"test:e2e": "jest --group=e2e",
"watch": "jest --watch --group=unit",
"build": "tsc --build --force",
"build:cjs": "tsc --build --force",
"build:esm": "tsc --project tsconfig.esm.json",
"build": "npm run build:esm & npm run build:cjs",
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
"lint-fix": "eslint --fix --ext .ts,.js --no-error-on-unmatched-pattern .",
"prebuild": "rimraf ./lib",
"postbuild": "node ./scripts/buildExportPackageJson.js",
"prepack": "node ../../.github/scripts/release_patch_package_json.js ."
dreamorosi marked this conversation as resolved.
Show resolved Hide resolved
},
"lint-staged": {
"*.{js,ts}": "npm run lint-fix"
},
"homepage": "https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/packages/logger#readme",
"license": "MIT-0",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"type": "module",
"exports": {
"node": {
"require": {
"types": "./lib/index.d.ts",
dreamorosi marked this conversation as resolved.
Show resolved Hide resolved
"default": "./lib/cjs/index.js"
},
"import": {
"types": "./lib/index.d.ts",
"default": "./lib/esm/index.js"
}
}
},
"types": "./lib/cjs/index.d.ts",
"main": "./lib/cjs/index.js",
"devDependencies": {
"@aws-lambda-powertools/testing-utils": "file:../testing",
"@types/lodash.merge": "^4.6.7"
Expand Down Expand Up @@ -64,4 +80,4 @@
"serverless",
"nodejs"
]
}
}
19 changes: 19 additions & 0 deletions packages/logger/scripts/buildExportPackageJson.js
dreamorosi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';

const __dirname = fileURLToPath(new URL('.', import.meta.url));

const cjsPackageJson = '{ "type": "commonjs" }';
writeFileSync(
join(__dirname, '..', 'lib', 'cjs', 'package.json'),
cjsPackageJson,
'utf-8'
);

const esmPackageJson = '{ "type": "module" }';
writeFileSync(
join(__dirname, '..', 'lib', 'esm', 'package.json'),
esmPackageJson,
'utf-8'
);
Loading