Skip to content

Commit

Permalink
feat(logger): add esmodule support (#1734)
Browse files Browse the repository at this point in the history
* feat(logger): add esm build output

* fix(Logger): Remove barrel files update references

* test(Logger): update jest/ts-jest to use ESM

* chore(Logger): remove unused lodash.merge

* fix(logger): reinstate lodash.merge

* chore(logger): revert TS assertion

* chore(logger): revert format changes

* chore(logger): update postbuild to remove incremental tsbuildinfo files

* fix(logger): correct reference to types output

* feat(logging): add middleware export

* chore(logger): replace postbuild script with echo statement

* feat(logger): add typesVersions property and barrel files to /types

* chore(logger): file not used, can be added back if needed

* chore(logger): add space back to README

* chore(logger): revert space in README
  • Loading branch information
antstanley authored Oct 11, 2023
1 parent 50aa3e7 commit 0bc7960
Show file tree
Hide file tree
Showing 31 changed files with 179 additions and 146 deletions.
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.

2 changes: 1 addition & 1 deletion packages/logger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ Credits for the Powertools for AWS Lambda (TypeScript) idea go to [DAZN](https:/

## License

This library is licensed under the MIT-0 License. See the LICENSE file.
This library is licensed under the MIT-0 License. See the LICENSE file.
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
44 changes: 40 additions & 4 deletions packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,55 @@
"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 && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
"build:esm": "tsc --project tsconfig.esm.json && echo '{ \"type\": \"module\" }' > lib/esm/package.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": "rimraf ./lib/*.tsbuildinfo",
"prepack": "node ../../.github/scripts/release_patch_package_json.js ."
},
"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": {
".": {
"require": {
"types": "./lib/cjs/index.d.ts",
"default": "./lib/cjs/index.js"
},
"import": {
"types": "./lib/esm/index.d.ts",
"default": "./lib/esm/index.js"
}
},
"./middleware": {
"import": "./lib/esm/middleware/middy.js",
"require": "./lib/cjs/middleware/middy.js"
},
"./types": {
"import": "./lib/esm/types/index.js",
"require": "./lib/cjs/types/index.js"
}
},
"typesVersions": {
"*": {
"middleware": [
"lib/cjs/middleware/middy.d.ts",
"lib/esm/middleware/middy.d.ts"
],
"types": [
"lib/cjs/types/index.d.ts",
"lib/esm/types/index.d.ts"
]
}
},
"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 +100,4 @@
"serverless",
"nodejs"
]
}
}
23 changes: 13 additions & 10 deletions packages/logger/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,29 @@ import { randomInt } from 'node:crypto';
import { Console } from 'node:console';
import type { Context, Handler } from 'aws-lambda';
import { Utility } from '@aws-lambda-powertools/commons';
import { LogFormatterInterface, PowertoolsLogFormatter } from './formatter';
import { LogItem } from './log';
import { PowertoolsLogFormatter } from './formatter/PowertoolsLogFormatter.js';
import { LogFormatterInterface } from './formatter/LogFormatterInterface.js';
import { LogItem } from './log/LogItem.js';
import merge from 'lodash.merge';
import { ConfigServiceInterface, EnvironmentVariablesService } from './config';
import { LogJsonIndent } from './types';
import { ConfigServiceInterface } from './config/ConfigServiceInterface.js';
import { EnvironmentVariablesService } from './config/EnvironmentVariablesService.js';
import { LogJsonIndent } from './types/Logger.js';
import type {
ClassThatLogs,
Environment,
LogAttributes,
LogLevel,
LogLevelThresholds,
} from './types/Log.js';
import type {
ClassThatLogs,
HandlerMethodDecorator,
LambdaFunctionContext,
LogAttributes,
ConstructorOptions,
LogItemExtraInput,
LogItemMessage,
LogLevel,
LogLevelThresholds,
PowertoolLogData,
HandlerOptions,
} from './types';

} from './types/Logger.js';
/**
* ## Intro
* The Logger utility provides an opinionated logger with output structured as JSON.
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/src/config/EnvironmentVariablesService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConfigServiceInterface } from './ConfigServiceInterface';
import { ConfigServiceInterface } from './ConfigServiceInterface.js';
import { EnvironmentVariablesService as CommonEnvironmentVariablesService } from '@aws-lambda-powertools/commons';

/**
Expand Down
2 changes: 0 additions & 2 deletions packages/logger/src/config/index.ts

This file was deleted.

7 changes: 4 additions & 3 deletions packages/logger/src/formatter/LogFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LogFormatterInterface } from '.';
import { LogAttributes, UnformattedAttributes } from '../types';
import { LogItem } from '../log';
import { LogFormatterInterface } from './LogFormatterInterface.js';
import { LogAttributes } from '../types/Log.js';
import { UnformattedAttributes } from '../types/Logger.js';
import { LogItem } from '../log/LogItem.js';

/**
* Typeguard to monkey patch Error to add a cause property.
Expand Down
Loading

0 comments on commit 0bc7960

Please sign in to comment.